Example #1
0
 def get_display(my):
     widget = DivWdg()
     table = Table()
     table.add_attr('class','scraper')
     table.add_row()
     tb = TextWdg('title_box')
     tb.add_attr('id','title_box')
     multiple_titles = None
     print "MY.TITLE_OF_SHOW = %s" % my.title_of_show
     if my.title_of_show not in [None,'']:
         tb.set_value(my.title_of_show)
         #poster_url_text = my.get_poster_url(my.title_of_show)
         #poster_url = poster_url_text.split('=')[1]
         multiple_titles = my.get_multiple_title_info(my.title_of_show)
     print "MULTIPLE_TITLES = %s" % multiple_titles
     tb.add_behavior(my.get_search())
     table.add_cell(tb)
     if multiple_titles not in [None,''] and len(multiple_titles) > 0:
         for m in multiple_titles:
             table.add_row()
             table.add_cell('<img src="%s"/>' % m['TopLevel']['poster'])
             mkeys = m.keys()
             for k in mkeys: 
                 table.add_row()
                 table.add_cell('<b><u>%s</u></b>' % k)
                 dudes = m[k]
                 dkeys = dudes.keys()
                 for d in dkeys:
                     table.add_row()
                     table.add_cell('%s: %s' % (d, dudes[d])) 
     widget.add(table)
     return widget
Example #2
0
    def get_display(my):
        sobject = my.get_current_sobject()
        key = sobject.get_value("key")
        options = sobject.get_value("options")
        type = sobject.get_value("type")

        # get the value of the users preferences
        search = Search("sthpw/pref_setting")
        search.add_user_filter()
        search.add_filter("key", key)
        pref_setting = search.get_sobject()
        if pref_setting:
            value = pref_setting.get_value("value")
        else:
            value = ""

        div = DivWdg()

        element_name = "%s_%s" % (my.get_name(), sobject.get_id() )
      
        script = '''var server = TacticServerStub.get();
                var value = bvr.src_el.value;
                if (!value) return;

                spt.app_busy.show("Saving", "Saving Preference for [%s]");

                setTimeout( function() {
                    try{
                        server.execute_cmd('tactic.ui.table.SetPreferenceCmd', {key: '%s', value: value});
                    }catch(e){
                        spt.alert(spt.exception.handler(e));
                    }
                        
                    spt.app_busy.hide() 
                        
                    }, 200);'''%(key, key)

        if key in ['skin', 'palette', 'js_logging_level']:
            script = '''%s; spt.app_busy.show('Reloading Page ...'); setTimeout('spt.refresh_page()', 200);'''%script

        if type == "sequence":
            from pyasm.prod.web import SelectWdg
            select = SelectWdg(element_name)
            select.add_behavior({'type': "change", 
                'cbjs_action': script})

            select.set_option("values",options)
            if value:
                select.set_value(value)
            div.add(select)
        else:
            text = TextWdg(element_name)
            text.add_behavior({'type': "blur", 
                'cbjs_action': script})
            if value:
                text.set_value(value)
            div.add(text)
     
        return div
Example #3
0
 def get_display(my):   
     from tactic.ui.widget import SObjectCheckinHistoryWdg
     my.code = str(my.kwargs.get('source_code'))
     my.sk = my.server.build_search_key('twog/source',my.code)
     my.movement_code = str(my.kwargs.get('movement_code'))
     ms = MovementScripts(movement_code=my.movement_code)
     clients_expr = "@SOBJECT(twog/client['@ORDER_BY','name desc'])" 
     clients = my.server.eval(clients_expr)
     client_sel = '<select class="REPLACE_ME"><option value="">--Select--</option>'
     for client in clients:
         client_sel = '%s<option value="%s">%s</option>' % (client_sel, client.get('code'), client.get('name'))
     client_sel = '%s</select>' % client_sel
     existing_expr = "@SOBJECT(twog/outside_barcode['source_code','%s'])" % my.code
     existing = my.server.eval(existing_expr)
     count = 0
     table = Table()
     table.add_attr('class','movement_outside_barcodes')
     for obc in existing:
         table.add_row()
         barcode_text_wdg = TextWdg('outside_barcode_insert_%s' % count)
         barcode_text_wdg.set_value(obc.get('barcode'))
         barcode_text_wdg.add_attr('curr_code',obc.get('code'))
         table.add_cell(barcode_text_wdg)
         new_sel = client_sel
         new_sel2 = new_sel.replace('REPLACE_ME','outside_client_%s' % count)
         found = new_sel2.find('"%s"' % obc.get('client_code'))
         if found > 0:
             part1 = new_sel2[:found]
             part2 = new_sel2[found:]
             found2 = part2.find('>')
             if found2 > 0:
                 good2 = part2[found2:]
                 new_sel2 = '%s"%s" selected="selected"%s' % (part1, obc.get('client_code'),good2)
         table.add_cell(new_sel2)
         count = count + 1
     additional_count = [1, 2, 3, 4, 5]
     for n in additional_count:
         table.add_row()
         barcode_text_wdg = TextWdg('outside_barcode_insert_%s' % count)
         barcode_text_wdg.add_attr('curr_code','')
         table.add_cell(barcode_text_wdg)
         new_sel = client_sel
         new_sel = new_sel.replace('REPLACE_ME','outside_client_%s' % count)
         table.add_cell(new_sel)
         count = count + 1
     table.add_row()
     save_tbl = Table()
     save_tbl.add_row()
     s1 = save_tbl.add_cell(' ')
     s1.add_attr('width','100%s' % '%')
     save_cell = table.add_cell('<input type="button" value="Save All"/>')
     save_cell.add_attr('align','center')
     save_cell.add_behavior(ms.get_save_outside_barcodes_behavior(my.code))
     s2 = save_tbl.add_cell(' ')
     s2.add_attr('width','100%s' % '%')
     ss = table.add_cell(save_tbl)
     ss.add_attr('colspan','2')
     ss.add_attr('align','center')
     return table
Example #4
0
 def get_display(my):
     div = SpanWdg()
     div.add(" is ")
     text = TextWdg("year")
     value = my.values.get("year")
     if value:
         text.set_value(value)
     div.add(text)
     return div
Example #5
0
    def get_display(my):
        sobject = my.get_current_sobject()
        key = sobject.get_value("key")
        options = sobject.get_value("options")
        type = sobject.get_value("type")

        # get the value of the users preferences
        search = Search("sthpw/pref_setting")
        search.add_user_filter()
        search.add_filter("key", key)
        pref_setting = search.get_sobject()
        if pref_setting:
            value = pref_setting.get_value("value")
        else:
            value = ""

        div = DivWdg()

        element_name = "%s_%s" % (my.get_name(), sobject.get_id())

        script = '''var server = TacticServerStub.get();
                var value = bvr.src_el.value;
                if (!value) return;

                spt.app_busy.show("Saving", "Saving Preference for [%s]");

                setTimeout( function() {
                    try{
                        server.execute_cmd('tactic.ui.table.SetPreferenceCmd', {key: '%s', value: value});
                    }catch(e){
                        spt.alert(spt.exception.handler(e));
                    }
                        
                    spt.app_busy.hide() 
                        
                    }, 200);''' % (key, key)

        if key in ['skin', 'palette', 'js_logging_level']:
            script = '''%s; spt.app_busy.show('Reloading Page ...'); setTimeout('spt.refresh_page()', 200);''' % script

        if type == "sequence":
            from pyasm.prod.web import SelectWdg
            select = SelectWdg(element_name)
            select.add_behavior({'type': "change", 'cbjs_action': script})

            select.set_option("values", options)
            if value:
                select.set_value(value)
            div.add(select)
        else:
            text = TextWdg(element_name)
            text.add_behavior({'type': "blur", 'cbjs_action': script})
            if value:
                text.set_value(value)
            div.add(text)

        return div
Example #6
0
 def get_display(self):
     div = SpanWdg()
     div.add(" is ")
     text = TextWdg("year")
     value = self.values.get("year")
     if value:
         text.set_value(value)
     div.add(text)
     return div
 def txtbox(my, name, val, code, old_val, width='200px', js='no'):
     txt = TextWdg(name)
     txt.add_attr('id', name)
     txt.add_attr('code', code)
     txt.add_attr('old_val', old_val)
     txt.add_style('width: %s;' % width)
     txt.set_value(val)
     if js == 'yes':
         txt.add_behavior(my.get_nums_only())
     return txt
 def txtbox(my, name, val, code, old_val, width='200px', js='no'):
     txt = TextWdg(name)
     txt.add_attr('id', name)
     txt.add_attr('code', code)
     txt.add_attr('old_val', old_val)
     txt.add_style('width: %s;' % width)
     txt.set_value(val)
     if js == 'yes':
         txt.add_behavior(my.get_nums_only())
     return txt
Example #9
0
 def get_display(my):
     from pyasm.search import Search
     #from tactic_client_lib import TacticServerStub
     barcode = ''
     sources = []
     bad_sources = []
     if 'barcode' in my.kwargs.keys():
         barcode = my.kwargs.get('barcode')
         tracker_s = Search("twog/location_tracker")
         tracker_s.add_filter('location_barcode',barcode)
         trackers = tracker_s.get_sobjects()
         #print "BARCODE = %s" % barcode
         #print "LEN TRACKERS = %s" % len(trackers)
         for t in trackers:
             tdate = t.get('timestamp')
             source_barcode = t.get('source_barcode')
             other_tracks = Search("twog/location_tracker")
             other_tracks.add_filter('source_barcode',source_barcode)
             other_tracks.add_filter('timestamp',tdate, op=">")
             others = other_tracks.get_sobjects()
             if len(others) == 0:
                 source_s = Search("twog/source")
                 source_s.add_filter('barcode',source_barcode)
                 source = source_s.get_sobject()
                 if source:
                     if source.get_value('in_house') in [True,'true','True',1,'1']:
                         sources.append(source)
                 else:
                     bad_sources.append({'barcode': source_barcode, 'title': 'UNKNOWN SOURCE'})
     
     table = Table()
     table.add_attr('class','location_inventory_wdg')
     table.add_row()
     bc = TextWdg('nextbc')
     bc.add_attr('id', 'location_inventory_txtbox')
     bc.add_behavior(my.get_entry_bvr())
     bc.set_value(barcode)
     table.add_cell(bc)
     #print "LEN SOURCES = %s" % len(sources)
     if len(sources) > 0:
         table.add_row()
         table.add_cell("<b>TOTAL: %s (UNKNOWN: %s)</b>" % (len(sources), len(bad_sources)))
     for source in sources:
         table.add_row()
         table.add_cell('Barcode: %s, Code: %s, Name: %s: %s' % (source.get_value('barcode'), source.get_code(), source.get_value('title'), source.get_value('episode')))
     if len(bad_sources) > 0:
         table.add_row()
         table.add_cell("<b>UNKNOWN SOURCES</b>")
         for b in bad_sources:
             table.add_row()
             table.add_cell('Barcode: %s, Name: %s' % (b.get('barcode'), b.get('title')))
     widget = DivWdg()
     widget.add(table)
     return widget
Example #10
0
    def get_display(self):
        name = self.get_name()

        # get the sobject required by this input
        sobject = self.get_current_sobject()

        widget = DivWdg()

        # add an advanced widget
        text = TextWdg("%s" % name)
        text.set_attr("size", 90)
        value = sobject.get_value(name)
        text.set_value(value)
        div = DivWdg()
        #div.add("Advanced: ")
        div.add(text)
        widget.add(div)

        return widget
Example #11
0
    def get_display(my):
        name = my.get_name()

        # get the sobject required by this input
        sobject = my.get_current_sobject()

        widget = DivWdg()

        # add an advanced widget
        text = TextWdg("%s" % name)
        text.set_attr("size", 90)
        value = sobject.get_value(name)
        text.set_value(value)
        div = DivWdg()
        # div.add("Advanced: ")
        div.add(text)
        widget.add(div)

        return widget
Example #12
0
    def get_display(my):
        from tactic_client_lib import TacticServerStub
        login = Environment.get_login()
        user_name = login.get_login()
        user_name = user_name.replace('.','')
        barcodes = []
        complete = False
        errors = ''
        first_loc_num1 = 5660
        last_loc_num1 = 5991
        first_loc_num2 = 6020
        last_loc_num2 = 6037
        if 'barcodes' in my.kwargs.keys():
            barcodes = my.kwargs.get('barcodes').split(',') 
        if 'complete' in my.kwargs.keys():
            complete = my.kwargs.get('complete')
        if 'errors' in my.kwargs.keys():
            errors = my.kwargs.get('errors')
        table = Table()
        table.add_attr('id','tracker_%s' % user_name) 
        table.add_attr('class','tracker_%s' % user_name) 
        if errors not in [None,'']:
            table.add_row()
            csp1 = table.add_cell(errors)
            csp1.add_attr('colspan','2')
        count = 0
        if complete:
            server = TacticServerStub.get()
            t2 = Table()
            for bc in barcodes:
                if 'EMP' in bc:
                    that_user = server.eval("@SOBJECT(sthpw/login['barcode','%s'])" % bc)
                    if that_user:
                        that_user = that_user[0]
                    else:
                        that_user = {'login': '******'}
                    t2.add_row()
                    t2.add_cell('USER: '******'login'))
                    t2.add_cell('BARCODE: %s' % bc)
            for bc in barcodes:
                bc_num = 555555555
                if '2G' in bc:
                    bc_num = bc.replace('2G','').replace('A','').replace('B','').replace('C','').replace('V','')
                    bc_num = int(bc_num)
                if (bc_num >= first_loc_num1 and bc_num <= last_loc_num1) or (bc_num >= first_loc_num2 and bc_num <= last_loc_num2):
                    that_location = server.eval("@SOBJECT(twog/inhouse_locations['barcode','%s'])" % bc)
                    if that_location:
                        that_location = that_location[0]
                    else:
                        that_location = {'name': 'UNKNOWN LOCATION'}
                    t2.add_row()
                    t2.add_cell('LOCATION: ')
                    t2.add_cell(that_location.get('name'))
                    t2.add_cell('BARCODE: %s' % bc)
            for bc in barcodes:
                bc_num = 555555555
                if '2G' in bc:
                    bc_num = bc.replace('2G','').replace('A','').replace('B','').replace('C','').replace('V','')
                    bc_num = int(bc_num)
                #if 'LOC' not in bc and 'EMP' not in bc:
                if not ((bc_num >= first_loc_num1 and bc_num <= last_loc_num1) or (bc_num >= first_loc_num2 and bc_num <= last_loc_num2)) and 'EMP' not in bc:
                    that_src = server.eval("@SOBJECT(twog/source['barcode','%s'])" % bc)
                    if that_src:
                        that_src = that_src[0]
                    else:
                        that_src = {'title': 'UNKNOWN SOURCE', 'episode': '', 'season': '', 'part': ''}
                    full_name = that_src.get('title')
                    if that_src.get('episode') not in [None,'']:
                        full_name = '%s EPISODE: %s' % (full_name, that_src.get('episode'))
                    if that_src.get('season') not in [None,'']:
                        full_name = '%s SEASON: %s' % (full_name, that_src.get('season'))
                    if that_src.get('part') not in [None,'']: 
                        full_name = '%s PART: %s' % (full_name, that_src.get('part'))
                    t2.add_row()
                    t2.add_cell('SOURCE: ')
                    t2.add_cell(full_name)
                    t2.add_cell('BARCODE: %s' % bc)
            table.add_row()
            csp2 = table.add_cell(t2)
            csp2.add_attr('colspan','2')
        else:                
            for bc in barcodes:
                table.add_row()
                table.add_cell('BARCODE: ')
                oldtxt = TextWdg('oldtxt')
                oldtxt.set_attr('id', 'txt_%s' % count)
                oldtxt.set_value(bc)
                table.add_cell(oldtxt)
                count = count + 1
            
        table.add_row()
        nextbc = TextWdg('nextbc')
        nextbc.add_attr('id', 'txt_%s' % count)
        nextbc.add_behavior(my.get_entry_bvr(user_name))
        table.add_cell('Barcode: ')
        table.add_cell(nextbc)

        widget = DivWdg()
        widget.add(table)
        widget.add_behavior(my.get_on_load_js(count))
        return widget
Example #13
0
    def get_display(self):

        top_wdg = DivWdg()
        top_wdg.add_style("color: black")
        top_wdg.add_style("width: 350px")
        top_wdg.add_style("margin-top: 10px")
        top_wdg.add_style("padding: 10px")
        top_wdg.add_border()
        title = DivWdg()
        title.add_style("color: black")
        title.add_style("margin-top: -22px")

        top_wdg.add(title)
        #if not self.name_string:
        #    title.add('No database column')
        #    return top_wdg
        
        title.add("Widget Definition")

        widget_types = {
            'foreign_key': 'tactic.ui.table.ForeignKeyElementWdg',
            'button': 'tactic.ui.table.ButtonElementWdg',
            'expression': 'tactic.ui.table.ExpressionElementWdg'
        }


        web = WebContainer.get_web()
        config_string = web.get_form_value("config_xml")
        if not config_string:
            config_string = '<config/>'
        xml = Xml()
        xml.read_string(config_string)

        #print "config_string: ", config_string

        # get values from the config file
        element_name = xml.get_value('element/@name')

        config = WidgetConfig.get(view='element',xml='<config><element>%s</element></config>' % config_string)
        display_options = config.get_display_options(element_name)


        title = xml.get_value('element/@title')
        display_handler = xml.get_value('element/display/@class')
        if not display_handler:
            display_handler = 'tactic.ui.panel.TypeTableElementWdg'

        widget_name = xml.get_value('element/display/@widget')
        if not widget_name:
            widget_name = 'custom'

 
        custom_table = Table()
        custom_table.add_style("color: black")
        top_wdg.add(custom_table)

        name_text = DivWdg()
        name_text.add_style("color: black")
        name_text.add(element_name)
        custom_table.add_row()
        custom_table.add_cell("Name: ")
        custom_table.add_cell(name_text)



        # add title
        custom_table.add_row()
        title_wdg = TextWdg("custom_title")
        title_wdg.set_value(title)
        title_wdg.add_attr("size", "50")
        custom_table.add_cell( "Title: " )
        custom_table.add_cell( title_wdg )

        # add description
        #custom_table.add_row()
        #description_wdg = TextAreaWdg("custom_description")
        #td = custom_table.add_cell( "Description: " )
        #td.add_style("vertical-align: top")
        #custom_table.add_cell( description_wdg )


        type_select = SelectWdg("custom_type")
        #type_select.add_empty_option("-- Select --")

        type_select.set_option("values", "string|integer|float|boolean|currency|date|foreign_key|link|list|button|custom")
        type_select.set_option("labels", "String(db)|Integer(db)|Float(db)|Boolean(db)|Currency(db)|Date(db)|Foreign Key|Link|List|Button|Custom")
        type_select.set_value(widget_name)

        #type_select.set_option("values", "string|integer|float|boolean|currency|date|link|list|foreign_key|button|empty")
        #type_select.set_option("labels", "String|Integer|Float|Boolean|Currency|Date|Link|List|Foreign Key|Button|Empty")
        custom_table.add_row()
        td = custom_table.add_cell("Widget Type: ")
        td.add_style("vertical-align: top")
        td = custom_table.add_cell(type_select)
        type_select.add_event("onchange", "spt.CustomProject.property_type_select_cbk(this)")


        td.add(HtmlElement.br())
        display_handler_text = TextWdg("display_handler")
        display_handler_text.add_attr("size", "50")
        display_handler_text.set_value(display_handler)
        td.add(display_handler_text)



        # extra info for foreign key
        custom_table.add_row()
        div = DivWdg()
        div.add_class("foreign_key_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())



        # extra info for foreign key
        custom_table.add_row()
        div = DivWdg()
        div.add_class("foreign_key_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Relate to: ")
        search_type_select = SearchTypeSelectWdg("foreign_key_search_select", mode=SearchTypeSelectWdg.CURRENT_PROJECT)
        div.add(search_type_select)
        td.add(div)



        # extra info for list
        custom_table.add_row()
        div = DivWdg()
        div.add_class("list_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Values: ")
        search_type_text = TextWdg("list_values")
        div.add(search_type_text)
        td.add(div)




        # extra info for button
        custom_table.add_row()
        div = DivWdg()
        div.add_style("color: black")
        div.add_class("button_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")

        #class_path = "tactic.ui.table.ButtonElementWdg"
        class_path = display_handler
        button = Common.create_from_class_path(class_path)
        args_keys = button.get_args_keys()


        div.add("Options")
        div.add(HtmlElement.br())

        for key in args_keys.keys():
            option_name_text = HiddenWdg("option_name")
            option_name_text.set_value(key)
            div.add(option_name_text)

            div.add("%s: " % key)
            div.add(" &nbsp; &nbsp;")

            input = button.get_input_by_arg_key(key)

            value = display_options.get(key)
            if value:
                input.set_value(value)

            div.add(input)
            div.add(HtmlElement.br())
        td.add(div)






        # is searchable checkbox
        #custom_table.add_row()
        #current_searchable_wdg = CheckboxWdg("is_searchable")
        #current_view_wdg.set_checked()
        #custom_table.add_cell("Searchable? ")
        #td = custom_table.add_cell(current_searchable_wdg)

        custom_table.close_tbody()


        return top_wdg
Example #14
0
    def get_new_definition_wdg(self):
        detail_wdg = DivWdg()
        detail_wdg.add_style("color: black")
        detail_wdg.add_style("width: 350px")
        detail_wdg.add_style("margin-top: 10px")
        detail_wdg.add_style("padding: 10px")
        detail_wdg.add_border()
        title = DivWdg()
        title.add_style("color: black")
        title.add("Column Definition")
        title.add_style("margin-top: -22px")
        detail_wdg.add(title)


        # add a name entry
        title = SpanWdg()
        detail_wdg.add("Name: ")
        detail_wdg.add(title)
        input = SpanWdg()
        input.add_style('padding-top: 6px')
        input.set_id("config_element_name")
        text = TextWdg('column_name')
        text.set_value(self.name_string)
        input.add(text)
        detail_wdg.add(input)
        hidden = HiddenWdg('target_search_type', self.search_type)
        detail_wdg.add(hidden)

        detail_wdg.add(HtmlElement.br(2))

        # add data_type entry
        data_type = SpanWdg()
        default_data_types = ['varchar(256)','varchar', 'character', 'text', 'integer', 'float', 'boolean', 'timestamp', 'Other...']
        select = SelectWdg('config_data_type', label ='Data Type: ')
        #detail_wdg.add(": ")
        select.set_option('values', default_data_types )
        select.set_value(self.data_type_string)
        
        select.add_behavior({'type': 'change', 
            'cbjs_action': "if (bvr.src_el.value=='Other...') {spt.show('config_data_type_custom');}\
                    else {spt.hide('config_data_type_custom');}"})
        data_type.add(select) 

        text = TextWdg('config_data_type_custom')
        span = SpanWdg("Other: ", css='med')
        span.add(text)
        span.set_id('config_data_type_custom')
        span.add_style('display','none')
        text.set_value(self.data_type_string)

        data_type.add("<br/>")
        data_type.add(span)
        detail_wdg.add(data_type)
            
        detail_wdg.add("<br/>")
        # add a nullable entry
        nullable = DivWdg()
        checkbox = CheckboxWdg('config_nullable', label ='Allow null(empty) value: ')
        nullable.add(checkbox)

        if self.nullable_string in ['True', 'true']:
            checkbox.set_checked()
        
        detail_wdg.add(nullable)

        return detail_wdg
Example #15
0
    def get_display(my):


        show_context = my.get_option('context') == 'true'

        top = DivWdg()
        # put in a js callback to determine the to use.
        top.add_class("spt_input_top")


        context_list = []

        my.pipeline_codes = []
        my.pipelines = []
        my.in_edit_wdg = False

        parent_key = my.get_option("parent_key")
        if not parent_key:
            state = my.get_state()
            parent_key = state.get("parent_key")


        if parent_key:
            parent = Search.get_by_search_key(parent_key)
            pipeline_code = parent.get_value("pipeline_code", no_exception=True)
            if pipeline_code:
                top.add_attr("spt_cbjs_get_input_key", "return '%s'" % pipeline_code)

        else:
            # This is quite slow, but it works
            #top.add_attr("spt_cbjs_get_input_key", "var server=TacticServerStub.get(); var parent_key = cell_to_edit.getParent('.spt_table_tbody').getAttribute('spt_parent_key'); var parent = server.get_by_search_key(parent_key); return parent.pipeline_code")

            # ProcessElementWdg's handle_td() sets the spt_pipeline_code attribute
            top.add_attr("spt_cbjs_get_input_key", "return cell_to_edit.getAttribute('spt_pipeline_code')")


        # Need to import this dynamically
        from tactic.ui.panel import EditWdg
        # This is only executed for the popup edit widget
        if hasattr(my, 'parent_wdg') and isinstance(my.get_parent_wdg(), EditWdg):
            my.in_edit_wdg = True
            sobject = my.get_current_sobject()
            parent = sobject.get_parent()
            if not parent:
                parent_key = my.get_option('parent_key')
                if parent_key:
                    parent = SearchKey.get_by_search_key(parent_key)

            if parent:
                if not parent.has_value('pipeline_code'):

                    name = my.get_input_name()
                    text = TextWdg(name)
                    top.add(text)

                    sobject = my.get_current_sobject()
                    name = my.get_name()
                    value = sobject.get_value(name)
                    text.set_value(value)

                    return top
                    #raise TacticException('[%s] needs a pipeline_code attribute to insert task.'%parent.get_code())
                
                pipe_code = parent.get_value('pipeline_code')
                if pipe_code:
                    my.pipeline_codes  = [pipe_code]
                    my.pipelines = [Pipeline.get_by_code(pipe_code)]
        else:

            # just get all of the pipelines
            # Cannot use expression here, because entries are added to the
            # result ... this causes further queries to return with the
            # added entries
            #my.pipelines = Search.eval("@SOBJECT(sthpw/pipeline)")
            search = Search("sthpw/pipeline")
            my.pipelines = search.get_sobjects()

            my.pipeline_codes = [x.get_code() for x in my.pipelines]

            # add the default
            my.pipeline_codes.append("")
            my.pipelines.append(None)


        for i, pipeline_code in enumerate(my.pipeline_codes):
            pipeline = my.pipelines[i]
            div = DivWdg()
            top.add(div)
            div.add_class("spt_input_option")
            div.add_attr("spt_input_key", pipeline_code)

            name = my.get_input_name()

            # If the pipeline code is empty, make it free form (for now)
            if not pipeline_code:
                text = TextWdg(name)
                div.add(text)
                continue


            
            select = SelectWdg(name)
            select.add_empty_option("-- Select a %s --" % my.get_name() )

            # TODO: make spt.dg_table.select_wdg_clicked keyboard action free so it won't interfere with
            # normal usage of the select
            if not my.in_edit_wdg:
                select.add_behavior( { 'type': 'click',
                   'cbjs_action': 'spt.dg_table.select_wdg_clicked( evt, bvr.src_el );'
                } )
            

            # get the sub-pipeline processes as well
            processes = pipeline.get_processes(recurse=True)
            values = []
            labels = []
            for process in processes:
                is_sub_pipeline = False
                if process.is_from_sub_pipeline():
                    process_name  = process.get_full_name()
                    is_sub_pipeline = True
                else:
                    process_name  = process.get_name()

                # show context instead
                if show_context:
                    output_contexts = pipeline.get_output_contexts(process.get_name())
                    for context in output_contexts:
                        values.append(context)
                        if is_sub_pipeline:
                            #label = process_name
                            label = context
                        else:
                            label = context
                        labels.append(label)
                else:
                    values.append(process_name)
                    labels.append(process_name)

            select.set_option("values", values) 
            select.set_option("labels", labels) 
            
            div.add(select)

            # there is only 1 select for EditWdg
            if hasattr(my, 'parent_wdg') and isinstance(my.get_parent_wdg(), EditWdg):
                sobject = my.get_current_sobject()
                # this could be either process or context
                name = my.get_name()
                value = sobject.get_value(name)
                # special case to append a context with subcontext so it will stay selected in EditWdg
                if name == 'context' and value.find('/') != -1:
                    select.append_option(value, value)
                if value:
                    select.set_value(value)



        return top
Example #16
0
    def get_display(self):
        top = DivWdg()

        element_name = self.kwargs.get('element_name')

        config_view = self.kwargs.get("config_view")
        display_class = config_view.get_display_handler(element_name)
        display_options = config_view.get_display_options(element_name)
        element_attr = config_view.get_element_attributes(element_name)

        name = element_attr.get('name')
        edit = element_attr.get('edit')
        title = element_attr.get('title')
        width = element_attr.get('width')

        # add the name
        from pyasm.web import Table
        table = Table()
        top.add(table)

        table.add_row()
        td = table.add_cell("Name: ")
        td.add_style("padding: 5px")
        name_text = SpanWdg(name)
        name_text.add_style('font-weight: bold')
        name_text.add_attr("size", "50")
        table.add_cell(name_text)

        table.add_row_cell("<br/>Element Attributes:<br/>")

        # add the title
        table.add_row()
        td = table.add_cell("Title: ")
        td.add_style("padding: 5px")
        title_text = TextWdg("title")
        title_text.add_attr("size", "50")
        if title:
            title_text.set_value(title)
        table.add_cell(title_text)

        # add the width
        table.add_row()
        td = table.add_cell("Width: ")
        td.add_style("padding: 5px")
        width_text = TextWdg("width")
        if width:
            width_text.set_value(width)
        width_text.add_attr("size", "50")
        table.add_cell(width_text)

        # add the editable
        table.add_row()
        td = table.add_cell("Editable: ")
        td.add_style("padding: 5px")
        editable_text = CheckboxWdg("editable")
        editable_text.add_attr("size", "50")
        table.add_cell(editable_text)

        table.add_row_cell("<br/>Display:<br/>")

        # add the widget
        table.add_row()
        td = table.add_cell("Widget: ")
        td.add_style("padding: 5px")
        widget_select = SelectWdg("widget")
        options = ['Expression']
        widget_select.set_option("values", options)
        widget_select.add_empty_option("-- Select --")
        #widget_select.set_value(display_class)
        table.add_cell(widget_select)

        table.add_row_cell("&nbsp;&nbsp;&nbsp;&nbsp;- or -")

        # add the class
        table.add_row()
        td = table.add_cell("Class Name: ")
        td.add_style("padding: 5px")
        class_text = TextWdg("class_name")
        class_text.set_value(display_class)
        class_text.add_attr("size", "50")
        table.add_cell(class_text)

        # introspect the widget
        if not display_class:
            display_class = "pyasm.widget.SimpleTableElementWdg"
        #display_class = "tactic.ui.panel.ViewPanelWdg"

        from pyasm.common import Common
        import_stmt = Common.get_import_from_class_path(display_class)
        if import_stmt:
            exec(import_stmt)
        else:
            exec("from pyasm.widget import %s" % display_class)
        try:
            options = eval("%s.get_args_options()" % display_class)
        except AttributeError:
            try:
                info = eval("%s.get_args_keys()" % display_class)
            except AttributeError:
                return top

            options = []
            for key, description in info.items():
                option = {
                    'name': key,
                    'type': 'TextWdg',
                    'description': description
                }
                options.append(option)
        '''
        options = [
        {
            'name': 'expression',
            'type': 'TextWdg',
            'size': '50'
        },
        ]
        '''

        if options:
            top.add("<br/>Widget Options:<br/>")

        table = Table()
        top.add(table)

        for option in options:
            table.add_row()

            name = option.get('name')
            title = name
            type = option.get('type')

            td = table.add_cell("%s: " % title)
            td.add_style("padding: 5px")

            value = display_options.get(name)

            if type == 'SelectWdg':
                edit_wdg = SelectWdg("%s|value" % name)
                edit_wdg.add_style("width: 250px")
                edit_wdg.add_empty_option('-- Select --')
                values = option.get('values')
                edit_wdg.set_option('values', values)
                if value:
                    edit_wdg.set_value(value)
            elif type == 'TextAreaWdg':
                edit_wdg = TextAreaWdg("%s|value" % name)
                if value:
                    edit_wdg.set_value(value)
                edit_wdg.add_attr("cols", "60")
                edit_wdg.add_attr("rows", "3")
            else:
                edit_wdg = TextWdg("%s|value" % name)
                if value:
                    edit_wdg.set_value(value)
                edit_wdg.add_style("width: 250px")

            table.add_cell(edit_wdg)

        return top
    def get_simple_definition_wdg(my):

        detail_wdg = DivWdg()
        detail_wdg.add_color("color", "color")
        detail_wdg.add_style("width: 350px")
        detail_wdg.add_style("margin-top: 10px")
        detail_wdg.add_style("padding: 10px")
        detail_wdg.add_border()
        title = DivWdg()
        title.add_style("margin-top: -23px")
        detail_wdg.add(title)
        if not my.name_string:
            title.add('No database column')
            return detail_wdg

        title.add("Column Definition")

        # add a name entry
        detail_wdg.add("<br/>")
        title = SpanWdg()
        detail_wdg.add("Name: ")
        detail_wdg.add(title)
        input = SpanWdg()
        input.add_style('padding-top: 6px')
        input.set_id("config_element_name")
        input.add(HtmlElement.b(my.name_string))
        detail_wdg.add(input)
        hidden = HiddenWdg('column_name', my.name_string)
        detail_wdg.add(hidden)
        hidden = HiddenWdg('target_search_type', my.search_type)
        detail_wdg.add(hidden)

        detail_wdg.add(HtmlElement.br(2))

        # add data_type entry
        data_type = SpanWdg()
        default_data_types = [
            'varchar(256)', 'varchar', 'character', 'text', 'integer', 'float',
            'boolean', 'timestamp', 'Other...'
        ]
        select = SelectWdg('config_data_type', label='Data Type: ')
        #detail_wdg.add(": ")
        select.set_option('values', default_data_types)
        select.set_value(my.data_type_string)

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            "if (bvr.src_el.value=='Other...') {spt.show('config_data_type_custom');}\
                    else {spt.hide('config_data_type_custom');}"
        })
        data_type.add(select)

        text = TextWdg('config_data_type_custom')
        span = SpanWdg("Other: ", css='med')
        span.add(text)
        span.set_id('config_data_type_custom')
        span.add_style('display', 'none')
        text.set_value(my.data_type_string)

        data_type.add("<br/>")
        data_type.add(span)
        detail_wdg.add(data_type)

        detail_wdg.add("<br/>")
        # add a nullable entry
        nullable = SpanWdg()
        checkbox = CheckboxWdg('config_nullable',
                               label='Allow null(empty) value: ')
        #detail_wdg.add(": ")
        nullable.add(checkbox)

        if my.nullable_string in ['True', 'true']:
            checkbox.set_checked()

        detail_wdg.add(nullable)

        #constraint = DivWdg()
        #detail_wdg.add(constraint)
        #constraint.add_style("margin-top: 10px")
        #constraint.add("Constraint: ")
        #select = SelectWdg("config_constraint")
        #constraint.add(select)
        #select.set_option("values", "unique|indexed")
        #select.add_empty_option("-- None --")

        button_div = DivWdg()
        button_div.add_style("text-align: center")

        button_div.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
spt.manage_search_type = {};

spt.manage_search_type.change_column_cbk = function(bvr) {
    var class_name = 'tactic.ui.panel.AlterSearchTypeCbk';
    var options ={
        'alter_mode': bvr.alter_mode,
        'title': bvr.title
    };

    try {
        var server = TacticServerStub.get();
        var panel = $('search_type_detail');
        if (! panel.getAttribute("spt_class_name") ) {
            panel = panel.getParent(".spt_panel");
        }
        var values = spt.api.Utility.get_input_values(panel);
        rtn = server.execute_cmd(class_name, options, values);
        if (bvr.alter_mode == 'Remove Column')
            spt.info("Column [" + bvr.column + "] has been deleted.");
        else if (bvr.alter_mode == 'Modify Column')
            spt.notify.show_message("Column [" + bvr.column + "] has been modified.");
    }
    catch (e) {
        spt.alert(spt.exception.handler(e));
    }
    var view = 'db_column';
    spt.panel.refresh("ManageSearchTypeMenuWdg_" + view);
    var view = 'definition';
    spt.panel.refresh("ManageSearchTypeMenuWdg_" + view);
}


            '''
        })

        detail_wdg.add(button_div)
        button_div.add("<hr/><br/>")
        if my.is_new_column:
            button = ActionButtonWdg(title="Commit")
            #button = ProdIconButtonWdg("Commit New Column")
            button.add_behavior({"type": "click_up",
                "cbjs_action": "spt.manage_search_type.change_column_cbk(bvr)", \

                        "alter_mode": my.ADD_COLUMN})
            button_div.add(button)
        else:

            table = Table()
            button_div.add(table)
            table.add_row()
            table.center()

            button = ActionButtonWdg(title="Modify")
            #button = ProdIconButtonWdg("Modify Column")
            button.add_behavior({
                "type": "click_up",
                "cbjs_action":
                '''spt.manage_search_type.change_column_cbk(bvr);
                           ''',
                "alter_mode": my.MODIFY_COLUMN,
                "column": my.name_string,
                "title": my.title_string
            })
            table.add_cell(button)

            button = ActionButtonWdg(title="Delete")
            #button = ProdIconButtonWdg("Delete Column")
            #button.add_style('background-color: #BF462E')
            button.add_behavior({
                "type": "click_up",
                "cbjs_action": '''
                
                var yes = function() {
                    spt.manage_search_type.change_column_cbk(bvr);
                    
                }
                spt.confirm("Are you sure you wish to delete this column?", yes) 
                ''',
                "alter_mode": my.REMOVE_COLUMN,
                "column": my.name_string
            })
            table.add_cell(button)
            button_div.add(HiddenWdg('delete_column'))
            button_div.add(HiddenWdg('modify_column'))

        return detail_wdg
Example #18
0
    def get_display(my):

        data = my.kwargs.get('kwargs')
        if data:
            data = jsonloads(data)
            my.kwargs.update(data)


        my.search_type = my.kwargs.get("search_type")

        my.x_axis = my.kwargs.get("x_axis")
        if not my.x_axis:
            my.x_axis = 'code'

        my.y_axis = my.kwargs.get("y_axis")
        if type(my.y_axis) == types.ListType:
            my.y_axis = "|".join( my.y_axis )

        my.chart_type = my.kwargs.get("chart_type")
        if not my.chart_type:
            my.chart_type = 'bar'

        # get any search keys if any are passed in
        my.search_keys = my.kwargs.get("search_keys")


        top = DivWdg()
        top.add_class("spt_chart_builder")
        top.add_color("background", "background")
        top.add_border()



        from tactic.ui.app import HelpButtonWdg
        help_button = HelpButtonWdg(alias='charting')
        top.add( help_button )
        help_button.add_style("float: right")

        


        project = Project.get()
        search_types = project.get_search_types(include_sthpw=True)
        search_types = [x.get_value("search_type") for x in search_types]

        build_div = DivWdg()

        from pyasm.widget import SwapDisplayWdg
        swap_wdg = SwapDisplayWdg.get_triangle_wdg()
        swap_script = swap_wdg.get_swap_script()
        build_div.add(swap_wdg)

        build_div.add("<b>Chart Specifications</b>")
        build_div.add_style("margin-bottom: 5px")
        build_div.add_style("height: 25px")
        build_div.add_style("padding-top: 5px")
        build_div.add_gradient("background", "background", -10)
        build_div.add_color("color", "color")


        build_div.add_class("hand")
        build_div.add_class("SPT_DTS")
        top.add(build_div)
        build_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_chart_builder");
            var spec = top.getElement(".spt_chart_spec");
            //spt.api.toggle_show_hide(spec);
            spt.toggle_show_hide(spec);
            %s;
            ''' % swap_script
        } )

        spec_div = DivWdg()
        spec_div.add_color("color", "color3")
        spec_div.add_color("background", "background3")
        spec_div.add_class("spt_chart_spec")
        spec_div.add_border()
        spec_div.add_style("padding: 10px")
        spec_div.add_style("margin: 5px")
        spec_div.add_style("display: none")
        top.add(spec_div)

        table = Table()
        table.add_color("color", "color3")
        spec_div.add(table)

        # add the search type selector
        table.add_row()
        table.add_cell("Search Type: ")

        search_type_div = DivWdg()
        search_type_select = TextWdg("search_type")
        search_type_select.set_value(my.search_type)
        #search_type_select.set_option("values", search_types)
        search_type_div.add(search_type_select)
        table.add_cell(search_type_div)

        # add the chart type selector
        table.add_row()
        table.add_cell("Chart Type: ")

        type_div = DivWdg()
        #type_div.add_style("padding: 3px")
        type_select = SelectWdg("chart_type")
        type_select.set_option("values", "line|bar|area")
        if my.chart_type:
            type_select.set_value(my.chart_type)
        type_div.add(type_select)
        table.add_cell(type_div)

        # add the chart type selector
        table.add_row()
        table.add_cell("X-Axis: ")

        # need to find all expression widgets or use get_text_value()?
        x_axis_div = DivWdg()
        x_axis_text = TextWdg("x_axis")
        x_axis_text.set_value("code")
        x_axis_div.add(x_axis_text)
        table.add_cell(x_axis_div)



        # add the chart type selector
        table.add_row()
        td = table.add_cell("Y-Axis: ")
        td.add_style("vertical-align: top")

        y_axis_div = DivWdg()
        #y_axis_text = TextWdg("y_axis")
        #if my.y_axis:
        #    y_axis_text.set_value(my.y_axis)
        #y_axis_div.add(y_axis_text)
        td = table.add_cell(y_axis_div)

        # add in a list of entries
        from tactic.ui.container import DynamicListWdg
        list_wdg = DynamicListWdg()
        for value in my.y_axis.split("|"):
            item = TextWdg("y_axis")
            item.set_value(value, set_form_value=False)
            list_wdg.add_item(item)
        y_axis_div.add(list_wdg)



        spec_div.add("<br/>")
        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title="Refresh")
        spec_div.add(button)
        spec_div.add(HtmlElement.br(2))
        button.add_style("float: left")

        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_chart_builder");
        var chart = top.getElement(".spt_chart");
        var values = spt.api.get_input_values(top);
        //var values = spt.api.Utility.get_input_values(top);
        spt.panel.refresh(chart, values);
        '''
        } )

        #TODO: provide a field for user to type in the chart name
        """

        button = ActionButtonWdg(title="Save")
        spec_div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_chart_builder");
        var chart = top.getElement(".spt_chart");
        var values = spt.api.get_input_values(top);

        var login = '******';
        var search_type = 'SideBarWdg';
        var side_bar_view = 'project_view';
        var unique_el_name = 'chart_test'

        var kwargs = {};
        kwargs['login'] = null;
        //if (save_as_personal) 
        //    kwargs['login'] = login;
        kwargs['class_name'] = 'tactic.ui.chart.ChartBuilderWdg';

        var display_options = {};
        display_options['search_type'] = 'prod/asset'
        kwargs['display_options'] = display_options;
 
        kwargs['unique'] = true;
        //if (new_title)
        //    kwargs['element_attrs'] = {'title': new_title}; 

        var server = TacticServerStub.get()
        server.add_config_element(search_type, side_bar_view, unique_el_name, kwargs);
        spt.panel.refresh("side_bar");
        '''
        } )
        """

        width = '600px'
        kwargs = {
            'y_axis': my.y_axis,
            'chart_type': my.chart_type,
            'search_type': my.search_type,
            'width': width,
            'search_keys': my.search_keys
        }

        chart_div = DivWdg()
        chart = BarChartWdg(**kwargs)

        chart_div.add(chart)
        top.add(chart_div)


        #from chart2_wdg import SampleSObjectChartWdg
        #chart = SampleSObjectChartWdg(**kwargs)
        #chart_div.add(chart)





        return top
Example #19
0
    def get_display(self):
        element_name = self.kwargs.get("element_name")
        element_id = self.kwargs.get("element_id")
        display_handler = self.kwargs.get("display_handler")
        display_options = self.kwargs.get("display_options")

        top = self.top
        top.add_class("spt_freeform_attr_top")
        top.add_style("padding: 10px")

        action_wdg = DivWdg()
        top.add(action_wdg)
        #action_wdg.add_gradient("background", "background", -10)

        delete = ActionButtonWdg(title='Remove', tip='Remove from Canvas')
        action_wdg.add(delete)
        delete.add_style("float: right")
        delete.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''

        var attr_top = bvr.src_el.getParent(".spt_freeform_attr_top");
        var values = spt.api.get_input_values(attr_top, null, false);
        var top = bvr.src_el.getParent(".spt_freeform_top");
        var canvas_top = top.getElement(".spt_freeform_canvas_top");
        var canvas = canvas_top.getElement(".spt_freeform_canvas");
        spt.freeform.init(canvas);

        var element_id = values.element_id;

        var element = null;
        var elements = spt.freeform.get_elements();
        for (var i = 0; i < elements.length; i++) {
            if ( elements[i].getAttribute("spt_element_id") == element_id) {
                element = elements[i];
            }
        }

        if (element == null) {
            alert("Element "+element_id+" does not exist on canvas");
            return;
        }

        element.destroy()
        '''
        })

        update = ActionButtonWdg(title='Update')
        action_wdg.add(update)

        update.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var attr_top = bvr.src_el.getParent(".spt_freeform_attr_top");
        var values = spt.api.get_input_values(attr_top, null, false);
        var top = bvr.src_el.getParent(".spt_freeform_top");
        var canvas_top = top.getElement(".spt_freeform_canvas_top");
        var canvas = canvas_top.getElement(".spt_freeform_canvas");
        spt.freeform.init(canvas);

        var element_id = values.element_id;

        var element = null;
        var elements = spt.freeform.get_elements();
        for (var i = 0; i < elements.length; i++) {
            if ( elements[i].getAttribute("spt_element_id") == element_id) {
                element = elements[i];
            }
        }

        if (element == null) {
            alert("Element "+element_id+" does not exist on canvas");
            return;
        }

        element.setAttribute("spt_element_name", values["element_name"]);
        for (var name in values) {

            if (name.substr(0,3) == 'opt') {
                var parts = name.split("|");
                var attr_name = parts[1];
                var value = values[name];
                if (typeof(element.attrs) == 'undefined') {
                    element.attrs = {};
                }
                element.attrs[attr_name] = value;

            }
        }

        // set the values
        element.element_settings = values;

        // load the widget
        var class_name = values['xxx_option|display_class'];

        var kwargs = {};
        for (key in values) {
            var parts = key.split("|");
            if (parts[0] == 'option') {
                kwargs[parts[1]] = values[key];
            }

        }

        var server = TacticServerStub.get();
        var html = server.get_widget(class_name, {args: kwargs});

        var element_name = values['element_name'];
        var el = spt.freeform.get_element(element_name);
        var content = el.getElement(".spt_element_content");
        spt.behavior.replace_inner_html(content, html);




        '''
        })

        top.add("<hr/>")

        table = Table()
        top.add(table)
        table.add_color("color", "color")
        table.add_style("width: 100%")
        table.add_style("margin: 10px")

        table.add_row()
        td = table.add_cell()
        td.add("Name:")
        td.add_style("width: 150px")
        td = table.add_cell()
        #td.add(element_name)
        hidden = TextWdg("element_name")
        hidden.set_value(element_name)
        td.add(hidden)
        hidden = HiddenWdg("element_id")
        hidden.set_value(element_id)
        td.add(hidden)

        widget_key = ''
        display_class = display_handler

        from tactic.ui.manager import WidgetClassSelectorWdg

        class_labels = ['-- Class Path--']
        class_values = ['__class__']

        # add the widget information
        #class_labels = ['Raw Data', 'Formatted', 'Expression', 'Expression Value', 'Button', 'Link', 'Gantt', 'Hidden Row', 'Custom Layout', '-- Class Path --']
        #class_values = ['raw_data', 'format', 'expression', 'expression_value', 'button', 'link', 'gantt', 'hidden_row', 'custom_layout', '__class__']
        widget_class_wdg = WidgetClassSelectorWdg(
            widget_key=widget_key,
            display_class=display_class,
            display_options=display_options,
            class_labels=class_labels,
            class_values=class_values,
            prefix='option')
        top.add(widget_class_wdg)

        return top
Example #20
0
    def get_display(my):

        show_context = my.get_option('context') == 'true'

        top = DivWdg()
        # put in a js callback to determine the to use.
        top.add_class("spt_input_top")

        context_list = []

        my.pipeline_codes = []
        my.pipelines = []
        my.in_edit_wdg = False

        parent_key = my.get_option("parent_key")
        if not parent_key:
            state = my.get_state()
            parent_key = state.get("parent_key")

        if parent_key:
            parent = Search.get_by_search_key(parent_key)
            pipeline_code = parent.get_value("pipeline_code",
                                             no_exception=True)
            if pipeline_code:
                top.add_attr("spt_cbjs_get_input_key",
                             "return '%s'" % pipeline_code)

        else:
            # This is quite slow, but it works
            #top.add_attr("spt_cbjs_get_input_key", "var server=TacticServerStub.get(); var parent_key = cell_to_edit.getParent('.spt_table_tbody').getAttribute('spt_parent_key'); var parent = server.get_by_search_key(parent_key); return parent.pipeline_code")

            # ProcessElementWdg's handle_td() sets the spt_pipeline_code attribute
            top.add_attr(
                "spt_cbjs_get_input_key",
                "return cell_to_edit.getAttribute('spt_pipeline_code')")

        # Need to import this dynamically
        from tactic.ui.panel import EditWdg
        # This is only executed for the popup edit widget
        if hasattr(my, 'parent_wdg') and isinstance(my.get_parent_wdg(),
                                                    EditWdg):
            my.in_edit_wdg = True
            sobject = my.get_current_sobject()
            parent = sobject.get_parent()
            if not parent:
                parent_key = my.get_option('parent_key')
                if parent_key:
                    parent = SearchKey.get_by_search_key(parent_key)

            if parent:
                if not parent.has_value('pipeline_code'):

                    name = my.get_input_name()
                    text = TextWdg(name)
                    top.add(text)

                    sobject = my.get_current_sobject()
                    name = my.get_name()
                    value = sobject.get_value(name)
                    text.set_value(value)

                    return top
                    #raise TacticException('[%s] needs a pipeline_code attribute to insert task.'%parent.get_code())

                pipe_code = parent.get_value('pipeline_code')
                if pipe_code:
                    my.pipeline_codes = [pipe_code]
                    my.pipelines = [Pipeline.get_by_code(pipe_code)]
        else:

            # just get all of the pipelines
            # Cannot use expression here, because entries are added to the
            # result ... this causes further queries to return with the
            # added entries
            #my.pipelines = Search.eval("@SOBJECT(sthpw/pipeline)")
            search = Search("sthpw/pipeline")
            my.pipelines = search.get_sobjects()

            my.pipeline_codes = [x.get_code() for x in my.pipelines]

            # add the default
            my.pipeline_codes.append("")
            my.pipelines.append(None)

        for i, pipeline_code in enumerate(my.pipeline_codes):
            pipeline = my.pipelines[i]
            div = DivWdg()
            top.add(div)
            div.add_class("spt_input_option")
            div.add_attr("spt_input_key", pipeline_code)

            name = my.get_input_name()

            # If the pipeline code is empty, make it free form (for now)
            if not pipeline_code:
                text = TextWdg(name)
                div.add(text)
                continue

            select = SelectWdg(name)
            select.add_empty_option("-- Select a %s --" % my.get_name())

            # TODO: make spt.dg_table.select_wdg_clicked keyboard action free so it won't interfere with
            # normal usage of the select
            if not my.in_edit_wdg:
                select.add_behavior({
                    'type':
                    'click',
                    'cbjs_action':
                    'spt.dg_table.select_wdg_clicked( evt, bvr.src_el );'
                })

            if not pipeline:
                continue
            # get the sub-pipeline processes as well
            processes = pipeline.get_processes(recurse=True)
            values = []
            labels = []
            for process in processes:
                is_sub_pipeline = False
                if process.is_from_sub_pipeline():
                    process_name = process.get_full_name()
                    is_sub_pipeline = True
                else:
                    process_name = process.get_name()

                # show context instead
                if show_context:
                    output_contexts = pipeline.get_output_contexts(
                        process.get_name())
                    for context in output_contexts:
                        values.append(context)
                        if is_sub_pipeline:
                            #label = process_name
                            label = context
                        else:
                            label = context
                        labels.append(label)
                else:
                    values.append(process_name)
                    labels.append(process_name)

            select.set_option("values", values)
            select.set_option("labels", labels)

            div.add(select)

            # there is only 1 select for EditWdg
            if hasattr(my, 'parent_wdg') and isinstance(
                    my.get_parent_wdg(), EditWdg):
                sobject = my.get_current_sobject()
                # this could be either process or context
                name = my.get_name()
                value = sobject.get_value(name)
                # special case to append a context with subcontext so it will stay selected in EditWdg
                if name == 'context' and value.find('/') != -1:
                    select.append_option(value, value)
                if value:
                    select.set_value(value)

        return top
Example #21
0
    def handle_simple_mode(self, custom_table, mode):

        tbody = custom_table.add_tbody()
        tbody.add_class("spt_custom_simple")
        if mode != 'simple':
            tbody.add_style('display: none')

        name_text = TextWdg("custom_name")
        name_text.add_class("spt_input")
        tr = custom_table.add_row()
        tr.add_color("background", "background", -7)
        td = custom_table.add_cell("Name: ")
        td.add_style("min-width: 150px")
        custom_table.add_cell(name_text)

        # add title
        custom_table.add_row()
        title_wdg = TextWdg("custom_title")
        title_wdg.add_attr("size", "50")
        custom_table.add_cell("Title: ")
        custom_table.add_cell(title_wdg)

        # add description
        tr = custom_table.add_row()
        tr.add_color("background", "background", -7)
        description_wdg = TextAreaWdg("custom_description")
        custom_table.add_cell("Description: ")
        custom_table.add_cell(description_wdg)

        type_select = SelectWdg("custom_type")
        type_select.add_class("spt_input")
        #type_select.add_empty_option("-- Select --")
        type_select.set_option(
            "values",
            "string|text|integer|float|boolean|currency|date|foreign_key|list|button|empty"
        )
        type_select.set_option(
            "labels",
            "String(db)|Text(db)|Integer(db)|Float(db)|Boolean(db)|Currency(db)|Date(db)|Foreign Key(db)|List(db)|Button|Empty"
        )
        #type_select.set_option("labels", "String|Integer|Boolean|Currency|Timestamp|Link|Foreign Key|List|Checkbox|Text|Number|Date|Date Range")
        tr = custom_table.add_row()
        custom_table.add_cell("Property Type: ")
        td = custom_table.add_cell(type_select)
        type_select.add_event(
            "onchange",
            "spt.custom_property_adder.property_type_select_cbk(this)")

        # extra info for foreign key
        custom_table.add_row()
        div = DivWdg()
        div.add_class("foreign_key_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Relate to: ")
        search_type_select = SearchTypeSelectWdg(
            "foreign_key_search_select",
            mode=SearchTypeSelectWdg.CURRENT_PROJECT)
        div.add(search_type_select)
        td.add(div)

        # extra info for list
        custom_table.add_row()
        div = DivWdg()
        div.add_class("list_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Values: ")
        search_type_text = TextWdg("list_values")
        div.add(search_type_text)
        td.add(div)

        # extra info for button
        custom_table.add_row()
        div = DivWdg()
        div.add_class("button_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")

        class_path = "tactic.ui.table.ButtonElementWdg"
        button = Common.create_from_class_path(class_path)
        args_keys = button.get_args_keys()

        div.add("Options")
        div.add(HtmlElement.br())

        for key in args_keys.keys():
            div.add("Name: ")
            option_name_text = TextWdg("option_name")
            option_name_text.add_attr("readonly", "true")
            option_name_text.set_value(key)
            div.add(option_name_text)

            div.add(" &nbsp; ")

            div.add("Value: ")
            input = button.get_input_by_arg_key(key)
            div.add(input)

            #option_value_text = TextWdg("option_value")
            #div.add(option_value_text)
            div.add(HtmlElement.br())
        td.add(div)

        # is searchable checkbox
        tr = custom_table.add_row()
        tr.add_color("background", "background", -7)
        current_searchable_wdg = CheckboxWdg("is_searchable")
        #current_view_wdg.set_checked()
        custom_table.add_cell("Is Searchable? ")
        td = custom_table.add_cell(current_searchable_wdg)

        custom_table.close_tbody()
    def get_scale_wdg(my):

        if my.scale_called == True:
            return None
        my.scale_called = True

        show_scale = my.kwargs.get("show_scale")

        div = DivWdg()
        if show_scale in [False, 'false']:
            div.add_style("display: none")
        div.add_style("padding: 5px")
        div.add_class("spt_table_search")
        hidden = HiddenWdg("prefix", "tile_layout")
        div.add(hidden)
        div.add_behavior( {
            'type': 'load',
            'scale_prefix':  my.scale_prefix,
            'default_scale': my.scale,
            'aspect_ratio': my.aspect_ratio,
            'cbjs_action': '''
spt.tile_layout = {}
spt.tile_layout.layout = null;

spt.tile_layout.set_layout = function(layout) {
    if (!layout.hasClass("spt_layout")) {
        layout = layout.getParent(".spt_layout");
    }
    spt.tile_layout.layout = layout;
    return layout;
}

spt.tile_layout.get_scale = function() {
    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    var value = scale_value.value;
    value = parseInt(value);
    return value;
}


spt.tile_layout.set_scale = function(scale) {

    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    scale_value.value = scale;

    var size_x = bvr.aspect_ratio[0]*scale/100;
    var size_y = bvr.aspect_ratio[1]*scale/100;

    //var top = bvr.src_el.getParent(".spt_tile_layout_top");
    var top = spt.tile_layout.layout;
    var els = top.getElements(".spt_tile_content");
    for (var i = 0; i < els.length; i++) {
        var el = els[i];
        el.setStyle( "width",  size_x);
        el.setStyle( "height", size_y);
    }

    var container_id = "tile_layout::scale"+bvr.scale_prefix;
    spt.container.set_value( container_id, scale);
}


spt.tile_layout.drag_start_x = null;
spt.tile_layout.drag_start_value = null;

spt.tile_layout.drag_setup = function(evt, bvr, mouse_411) {
    spt.tile_layout.set_layout(bvr.src_el);
    spt.tile_layout.drag_start_x = mouse_411.curr_x;
    var src_el = spt.behavior.get_bvr_src( bvr );
    if (!src_el.value) {
        src_el.value = 0;
    }
    spt.tile_layout.drag_start_value = src_el.value;
    src_el.focus();
    src_el.select();
}
spt.tile_layout.drag_motion = function(evt, bvr, mouse_411) {
    var start_value = spt.tile_layout.drag_start_value; 
    if (isNaN(parseInt(start_value))) {
        return;
    }
    var dx = mouse_411.curr_x - spt.tile_layout.drag_start_x;
    var increment = parseInt(dx / 5);
    var multiplier;
    if (increment < 0)
        multiplier = 0.975;
    else
        multiplier = 1 / 0.975;
    increment = Math.abs(increment);
    var scale = spt.tile_layout.drag_start_value;
    for (var i = 0; i < increment; i++) {
        scale = scale * multiplier;
    }
    if (scale > 400)
        scale = 400;
    scale = parseInt(scale);
    spt.tile_layout.set_scale(scale);

}
spt.tile_layout.setup_control = function() {
   var slider = spt.tile_layout.layout.getElement('.spt_slider');
   var container_id = "tile_layout::scale"+bvr.scale_prefix;
   var initial_value = spt.container.get_value(container_id) ?  spt.container.get_value(container_id) : bvr.default_scale;

   spt.tile_layout.set_scale(initial_value);
   new Slider(slider, slider.getElement('.knob'), {
    range: [30, 400],
    steps: 74,
    initialStep: initial_value,
    onChange: function(value){
      if (value) spt.tile_layout.set_scale(value);
    }
  });
}



spt.tile_layout.image_drag_setup = function(evt, bvr, mouse_411) {
    bvr.use_copy = true;
    bvr.use_delta = true;
    //bvr.border_color = border_color;
    bvr.dx = 10;
    bvr.dy = 10;
    bvr.drop_code = 'DROP_ROW';
    bvr.accepted_search_type = bvr.search_type;


}

spt.tile_layout.image_drag_motion = function(evt, bvr, mouse_411) {

    spt.mouse._smart_default_drag_motion(evt, bvr, mouse_411);
    var target_el = spt.get_event_target(evt);
    target_el = spt.mouse.check_parent(target_el, bvr.drop_code);
    if (target_el) {
        var orig_border_color = target_el.getStyle('border-color');
        var orig_border_style = target_el.getStyle('border-style');
        target_el.setStyle('border','dashed 2px ' + bvr.border_color);
        if (!target_el.getAttribute('orig_border_color')) {
            target_el.setAttribute('orig_border_color', orig_border_color);
            target_el.setAttribute('orig_border_style', orig_border_style);
        }
    }

}

spt.tile_layout.image_drag_action = function(evt, bvr, mouse_411) {
    if (spt.drop) {

        spt.drop.sobject_drop_action(evt, bvr);
    }
    else {
        if( bvr._drag_copy_el ) {
            spt.behavior.destroy_element(bvr._drag_copy_el);
        }
    }
}

        ''' } )


        scale = my.kwargs.get("scale")


        div.add_behavior( {
        'type': 'load',
        'scale': scale,
        'cbjs_action': '''
        spt.tile_layout.set_layout(bvr.src_el);

        spt.tile_layout.setup_control();

        if (bvr.scale) {
            spt.tile_layout.set_scale(bvr.scale);
        }
      
        '''
        } )

        table = Table()
        div.add(table)
        table.add_row()

        """
        # TO BE DELETED
        less_div = DivWdg()
        less_div.add("<input type='button' value='&lt;&lt;'/>")
        table.add_cell(less_div)

        less_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale * 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )
        """

        dark_color = div.get_color("background", -5)
        light_color = div.get_color('color')
        med_color = div.get_color('color2')
        
        slider_div = DivWdg(css='spt_slider')
        slider_div.add_styles('valign: bottom; background: %s; height: 6px; width: 100px;'% light_color)
        knob_div = DivWdg(css='knob')
        knob_div.add_behavior({'type':'click',
                'cbjs_action': 'spt.tile_layout.set_layout(bvr.src_el)'
                })
        knob_div.add_styles('background: %s; bottom: 4px;\
                height: 16px; width: 12px; border-radius: 6px 6px 0 0;\
                border: 1px %s solid'\
                %(dark_color, med_color ))
        slider_div.add(knob_div)
        td = table.add_cell(slider_div)
        value_wdg = TextWdg("scale")
        value_wdg.add_class("spt_scale_value")
        td = table.add_cell(value_wdg)
        td.add("&nbsp;%")

        td.add_style("padding: 3px 8px")

        """
        # TO BE DELETED
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix("tile_layout")
        if data_list:
            data = data_list[0]
        else:
            data = {}
        my.scale = data.get("scale")
        if my.scale == None:
            my.scale = my.kwargs.get("scale")
        """
        if my.scale:
            value_wdg.set_value(my.scale)
        value_wdg.add_style("width: 28px")
        value_wdg.add_style("text-align: center")
        value_wdg.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )
        value_wdg.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        if (!value) {
            value = 100;
        }
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )



 
        value_wdg.add_behavior( {
            'type': 'smart_drag',
            'bvr_match_class': 'spt_scale_value',
            'ignore_default_motion' : True,
            "cbjs_setup": 'spt.tile_layout.drag_setup( evt, bvr, mouse_411 );',
            "cbjs_motion": 'spt.tile_layout.drag_motion( evt, bvr, mouse_411 );'
        } )

        
        """
        # TO BE DELETED
        more_div = DivWdg()
        more_div.add("<input type='button' value='&gt;&gt;'/>")
        table.add_cell(more_div)

        more_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale / 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )

        """


       

        return div
Example #23
0
    def get_display(self):

        top = DivWdg()
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("min-width: 600px")

        os_name = os.name

        top.set_unique_id()
        top.add_smart_style("spt_info_title", "background", self.top.get_color("background3"))
        top.add_smart_style("spt_info_title", "padding", "3px")
        top.add_smart_style("spt_info_title", "font-weight", "bold")




        # server
        title_div = DivWdg()
        top.add(title_div)
        title_div.add("Server")
        title_div.add_class("spt_info_title")


        os_div = DivWdg()
        top.add(os_div)

        os_info = platform.uname()
        try:
            os_login = os.getlogin()
        except Exception:
            os_login = os.environ.get("LOGNAME")

        table = Table()
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        os_div.add(table)

        for i, title in enumerate(['OS','Node Name','Release','Version','Machine']):
            table.add_row()
            td = table.add_cell("%s: " % title)
            td.add_style("width: 150px")
            table.add_cell( os_info[i] )

        table.add_row()
        table.add_cell("CPU Count: ")
        try :
            import multiprocessing
            table.add_cell( multiprocessing.cpu_count() )
        except (ImportError,  NotImplementedError):
            table.add_cell( "n/a" )


        table.add_row()
        table.add_cell("Login: "******"Python")
        title_div.add_class("spt_info_title")


        table = Table()
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        top.add(table)
        table.add_row()
        td = table.add_cell("Version: ")
        td.add_style("width: 150px")
        table.add_cell( sys.version )


        # client
        title_div = DivWdg()
        top.add(title_div)
        title_div.add("Client")
        title_div.add_class("spt_info_title")

        web = WebContainer.get_web()
        user_agent = web.get_env("HTTP_USER_AGENT")

        table = Table()
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        top.add(table)
        table.add_row()
        td = table.add_cell("User Agent: ")
        td.add_style("width: 150px")
        table.add_cell( user_agent )

        table.add_row()
        td = table.add_cell("TACTIC User: "******"Performance Test")
        title_div.add_class("spt_info_title")

        performance_wdg = PerformanceWdg()
        top.add(performance_wdg)

      
        top.add('<br/>')

        # mail server
        title_div = DivWdg()
        top.add(title_div)
        title_div.add("Mail Server")
        title_div.add_class("spt_info_title")

        table = Table(css='email_server')
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        top.add(table)
        table.add_row()
        td = table.add_cell("Server: ")
        td.add_style("width: 150px")
        mailserver = Config.get_value("services", "mailserver")
        has_mailserver = True
        if mailserver:
            table.add_cell( mailserver )
        else:
            table.add_cell("None configured")
            has_mailserver = False

        login = Login.get_by_login('admin')
        login_email = login.get_value('email')
        table.add_row()
        td = table.add_cell("From: ")
        td.add_style("width: 150px")
        text = TextWdg('email_from')
        text.set_attr('size', '40')
        text.set_value(login_email)
        text.add_class('email_from')
        table.add_cell(text)
        
        table.add_row()
        td = table.add_cell("To: ")
        td.add_style("width: 150px")
        text = TextWdg('email_to')
        text.set_attr('size', '40')
        text.add_class('email_to')
        text.set_value(login_email)
        table.add_cell(text)


        button = ActionButtonWdg(title='Email Send Test')
        table.add_row_cell('<br/>')
        table.add_row()

        table.add_cell(button)
        button.add_style("float: right")
        button.add_behavior( {
        'type': 'click_up',
        'has_mailserver': has_mailserver,
        'cbjs_action': '''
             if (!bvr.has_mailserver) {
                spt.alert('You have to fill in mailserver and possibly other mail related options in the TACTIC config file to send email.');
                return;
            }
             var s = TacticServerStub.get();
             try {

                spt.app_busy.show('Sending email'); 
                var from_txt = bvr.src_el.getParent('.email_server').getElement('.email_from');
                var to_txt = bvr.src_el.getParent('.email_server').getElement('.email_to');
                
                var rtn = s.execute_cmd('pyasm.command.EmailTriggerTestCmd', 
                {'sender_email': from_txt.value,
                 'recipient_emails': to_txt.value.split(','),
                 'msg': 'Simple Email Test by TACTIC'}
                 );
                 if (rtn.status == 'OK') {
                    spt.info("Email sent successfully to " + to_txt.value)
                 }
             } catch(e) {
                spt.alert(spt.exception.handler(e));
             }
             spt.app_busy.hide();


        '''
        })

    
    
        top.add('<br/>')
        self.handle_directories(top)


        #table.add_row()
        #td = table.add_cell("TACTIC User: ")
        #table.add_cell( web.get_user_name() )

        top.add('<br/>')
        top.add(DivWdg('Link Test', css='spt_info_title'))
        top.add('<br/>')
        top.add(LinkLoadTestWdg())

        top.add('<br/>')
        self.handle_python_script_test(top)
        top.add('<br/>')
        self.handle_sidebar_clear(top)



        return top
Example #24
0
 def txtbox(my, name, val, width='200px'):
     txt = TextWdg(name)
     txt.add_attr('id',name)
     txt.add_style('width: %s;' % width)
     txt.set_value(val)
     return txt
Example #25
0
    def get_display(my):
        my.icon_string = my.get_value("icon")
        my.icon_label = my.get_value("label")

        top = DivWdg()
        top.add_class("spt_icon_chooser_top")

        # FIXME: this is being generated every time .... where to put is?
        icon_chooser = IconChooserWdg(is_popup=True)
        top.add(icon_chooser)

        icon_entry_text = TextWdg(my.get_input_name())
        icon_entry_text.set_option("size", "30")
        #icon_entry_text.set_attr("disabled", "disabled")
        icon_entry_text.add_class("SPT_ICON_ENTRY_TEXT")

        button = ActionButtonWdg(title='Choose', tip='Click to select an icon')

        icon_img = HtmlElement.img()
        icon_img.add_class("SPT_ICON_IMG")

        if my.icon_string:
            # icon_path = IconWdg.icons.get(my.icon_string)
            icon_path = IconWdg.get_icon_path(my.icon_string)
            if icon_path:
                # icon = IconWdg( my.icon_string, icon_path, right_margin='0px' )
                icon_img.set_attr("src", icon_path)
            else:
                icon_img.set_attr("src", IconWdg.get_icon_path("TRANSPARENT"))

            icon_entry_text.set_value(my.icon_string)
        else:
            icon_entry_text.set_value("")
            icon_img.set_attr("src", IconWdg.get_icon_path("TRANSPARENT"))

        named_event_name = "ICON_CHOOSER_SELECTION_MADE"
        icon_entry_text.add_behavior({
            'type':
            'listen',
            'event_name':
            named_event_name,
            'cbjs_action':
            '''
                var top = $("IconChooserPopup");
                var chooser = spt.get_element(top, ".SPT_ICON_CHOOSER_WRAPPER_DIV");
                //var chooser = spt.get_cousin( bvr.src_el,
                //    ".spt_icon_chooser_top", ".SPT_ICON_CHOOSER_WRAPPER_DIV" );

                var icon_name = chooser.getProperty("spt_icon_selected");
                var icon_path = chooser.getProperty("spt_icon_path");
                // bvr.src_el.innerHTML = icon_name;
                bvr.src_el.value = icon_name;
                if( spt.is_hidden( bvr.src_el ) ) { spt.show( bvr.src_el ); }
                var img_el = spt.get_cousin( bvr.src_el,
                    ".spt_icon_chooser_top", ".SPT_ICON_IMG" );
                if( icon_path ) {
                    img_el.setProperty("src", icon_path);
                } else {
                    img_el.setProperty("src","/context/icons/common/transparent_pixel.gif");
                }
           '''
        })

        top.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            'spt.popup.open( "IconChooserPopup", false);'
        })

        #top.add( my.icon_label )
        spacing = "<img src='%s' style='width: %spx;' />" % (
            IconWdg.get_icon_path("TRANSPARENT"), 3)

        #button.add_behavior( {'type': 'click_up', 'cbjs_action': 'spt.popup.open( "IconChooserPopup", false);' } )
        #top.add( button )
        #button.add_style("float: right")
        #button.add_style("margin-top: -3px")

        top.add(icon_img)
        top.add(spacing)
        top.add(icon_entry_text)

        return top
Example #26
0
    def get_display(self):
        top = DivWdg()
        top.add_class("ad_input_top")

        name = self.get_name()
        text = TextWdg(self.get_input_name())

        # get the login
        sobject = self.get_current_sobject()
        client = sobject.get_value("contact_name")
        print "client: ", client
        if client:
            login_sobj = Login.get_by_code(client)
        else:
            login_sobj = Environment.get_login()

        # build the display_name
        login = login_sobj.get_value("login")
        display_name = login_sobj.get_value("display_name")
        if not display_name:
            display_name = "%s %s" % (user.get('first_name'),
                                      user.get('last_name'))
        display_name = display_name.replace('"', "'")

        print "login: "******"spt_ad_input")
        if login:
            hidden.set_value(login)
        top.add(hidden)

        # copy over some options
        #text.set_options( self.options.copy() )
        if login:
            text.set_value(display_name)
        text.set_option("read_only", "true")
        text.add_class("spt_ad_display")
        top.add(text)

        top.add("&nbsp;&nbsp;")

        groups_str = self.get_option("groups_allowed_to_search")
        if groups_str:
            stmt = 'groups_list = %s' % groups_str
            exec stmt
        else:
            groups_list = None

        allow_search = True

        if groups_list:
            allow_search = False
            login_in_group_list = Search.eval(
                "@SOBJECT(sthpw/login_in_group['login','=','%s'])" % login)
            for login_in_group in login_in_group_list:
                group = login_in_group.get_value("login_group")
                if group in groups_list:
                    allow_search = True
                    break

        if login == 'admin':
            allow_search = True

        if allow_search:
            button = IconButtonWdg('Search for User', IconWdg.USER)
            #button = ButtonWdg()
            button.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                var top = bvr.src_el.getParent('.ad_input_top');
                var content = top.getElement('.ad_input_content');
                spt.toggle_show_hide(content);
                '''
            })
            top.add(button)

        ad_top = DivWdg()
        ad_top.add_class("ad_input_content")
        ad_top.add_style("display: none")
        ad_top.add_style("position: absolute")
        ad_top.add_style("background: #222")
        ad_top.add_style("min-width: 300px")
        ad_top.add_style("border: solid 1px #000")
        ad_top.add_style("padding: 20px")

        cbjs_action = '''
        var value = bvr.src_el.getAttribute('spt_input_value');
        var display_value = bvr.src_el.getAttribute('spt_display_value');
        var phone_number = bvr.src_el.getAttribute('spt_phone_number');
        var email = bvr.src_el.getAttribute('spt_mail');

        var top = bvr.src_el.getParent('.ad_input_top');
        var content = top.getElement('.ad_input_content');
        var input = top.getElement('.spt_ad_input');
        var display = top.getElement('.spt_ad_display');
        input.value = value;
        display.value = display_value;

        server = TacticServerStub.get()
        server.execute_cmd("tactic.active_directory.ADCacheUserCbk", {login: value})

        spt.toggle_show_hide(content);

        '''
        ad_search_wdg = ADSearchWdg(cbjs_action=cbjs_action)
        ad_top.add(ad_search_wdg)

        top.add(ad_top)

        return top
Example #27
0
    def get_set_limit_wdg(my):
        limit_content = DivWdg()
        limit_content.add_style("font-size: 10px")
        #limit_content.add_style("padding", "5px")
        #limit_content.add_border()

        limit_content.add("Show ")

        limit_select = SelectWdg("limit_select")
        limit_select.add_class("spt_search_limit_select")
        limit_select.set_option("values", "10|20|50|100|200|Custom")
        limit_select.add_style("font-size: 10px")
        limit_content.add(limit_select)
        limit_content.add(" items per page<br/>")

        if my.search_limit in [10,20,50,100,200]:
            limit_select.set_value(my.search_limit)
            is_custom = False
        else:
            limit_select.set_value("Custom")
            is_custom = True

        limit_select.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_search_limit_top");
            var value = bvr.src_el.value;
            var custom = top.getElement(".spt_search_limit_custom");
            if (value == 'Custom') {
                custom.setStyle("display", "");
            }
            else {
                custom.setStyle("display", "none");
            }

            '''
        } )


        custom_limit = DivWdg()
        limit_content.add(custom_limit)
        custom_limit.add_class("spt_search_limit_custom")
        custom_limit.add("<br/>Custom: ")
        text = TextWdg("custom_limit")
        text.add_class("spt_search_limit_custom_text")
        text.add_style("width: 50px")
        if not is_custom:
            custom_limit.add_style("display: none")
        else:
            text.set_value(my.search_limit)
        custom_limit.add(text)
        text.add(" items")
        behavior = {
                'type': 'keydown',
                'cbjs_action': '''
                 if (evt.key=='enter') {
                    // register this as changed item
                    var value = bvr.src_el.value;
                    if (isNaN(value) || value.test(/[\.-]/)) {
                        spt.error('You have to use an integer.');
                    }
                }
        '''}

        
        text.add_behavior(behavior)

        return limit_content
Example #28
0
    def get_display(self):

        category = "FreeformWdg"

        search_type = self.get_value("search_type")
        if not search_type:
            search_type = "sthpw/login"

        view = self.get_value("view")
        if not view:
            view = 'freeform'

        search = Search("config/widget_config")
        search.add_filter("search_type", search_type)
        search.add_filter("view", view)
        config_sobj = search.get_sobject()
        if config_sobj:
            config_xml = config_sobj.get_value("config")
        else:
            config_xml = "<config/>"

        top = self.top
        self.set_as_panel(top)
        top.add_class("spt_freeform_top")

        inner = DivWdg()
        top.add(inner)

        table = ResizableTableWdg()
        table.add_color("background", "background")
        inner.add(table)
        table.add_row()
        table.set_max_width()

        td = table.add_cell()
        td.add_attr("colspan", "5")
        td.add_color("background", "background3")
        td.add_color("color", "color")
        td.add_style("padding", "10px")

        td.add("Search Type: ")
        select = SelectWdg("search_type")
        project = Project.get()
        search_types = project.get_search_types()
        values = [x.get_base_key() for x in search_types]
        labels = [
            "%s (%s)" % (x.get_title(), x.get_base_key()) for x in search_types
        ]
        select.set_option("values", values)
        select.set_option("labels", labels)
        if search_type:
            select.set_value(search_type)
        td.add(select)
        td.add("&nbsp;" * 10)
        td.add("View: ")
        text = TextWdg("view")
        td.add(text)
        if view:
            text.set_value(view)

        button = ActionButtonWdg(title="Load")
        button.add_style("float: left")
        td.add(button)
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        spt.app_busy.show("Loading View");
        var top = bvr.src_el.getParent(".spt_freeform_top");
        spt.panel.refresh(top);
        spt.app_busy.hide();
        '''
        })

        table.add_row()

        left = table.add_cell()
        left.add_style("vertical-align: top")
        left.add_border()
        left.add_color("color", "color")
        left.add_color("background", "background")
        left.add_style("min-width: 150px")

        left_div = DivWdg()
        left.add(left_div)
        left_div.add_style("min-height: 300px")
        left_div.add_style("min-width: 150px")
        left_div.add_style("width: 150px")

        title = DivWdg()
        left_div.add(title)
        title.add_style("font-weight: bold")
        title.add_style("font-size: 14px")
        title.add_style("width: 100%")
        title.add("Elements")
        title.add_gradient("background", "background", -5)
        title.add_style("padding: 10px 5px 5px 5px")
        title.add_style("height: 25px")
        title.add_style("margin-bottom: 10px")

        left.add_behavior({
            'type':
            'smart_click_up',
            'bvr_match_class':
            'SPT_ELEMENT_CLICK',
            'cbjs_action':
            r'''
        var top = bvr.src_el.getParent(".spt_freeform_top");
        var template_top = top.getElement(".spt_freeform_template_top");
        var canvas_top = top.getElement(".spt_freeform_canvas_top");
        var canvas = canvas_top.getElement(".spt_freeform_canvas");

        var element_name = bvr.src_el.getAttribute("spt_element_name");

        var template_els = template_top.getElements(".spt_element");
        var els = canvas.getElements(".spt_element");

        // get the highest number
        var number = 0;
        for ( var i = 0; i < els.length; i++) {
            var el = els[i];
            var name = el.getAttribute("spt_element_name");
            var num = name.match(/(\d+)/);
            if (!num)
                continue;
            num = parseInt(num);
            if (num > number) {
                number = num;
            }
        }
        number = number + 1;

        for ( var i = 0; i < template_els.length; i++) {
            var el = template_els[i];
            if (el.getAttribute("spt_element_name") == element_name) {
                var clone = spt.behavior.clone(el);
                canvas.appendChild(clone);
                clone.setStyle("top", "30px");
                clone.setStyle("left", "30px");
                clone.setStyle("position", "absolute");
                var new_name = element_name + number;
                clone.setAttribute("spt_element_name", new_name)
                clone.attrs = {};

                var number = Math.floor(Math.random()*10001)
                clone.setAttribute("spt_element_id", "element"+number);

                spt.freeform.select(clone);


                break;
            }
        }
        '''
        })

        values = [
            'Label', 'Box', 'Text', 'TextArea', 'Button', 'Preview', 'Image',
            'HTML', 'Table', 'Border', 'Custom Layout'
        ]
        names = [
            'label', 'box', 'text', 'textarea', 'button', 'preview', 'image',
            'html', 'table', 'border', 'custom'
        ]
        icons = [IconWdg.VIEW]

        for name, value in zip(names, values):

            element_div = DivWdg()
            left_div.add(element_div)
            element_div.add_style("padding: 3px")
            element_div.add_class("SPT_DTS")
            element_div.add_class("hand")

            icon = IconWdg(name, IconWdg.VIEW)
            element_div.add(icon)

            element_div.add(value)
            element_div.add_class("SPT_ELEMENT_CLICK")
            element_div.add_attr("spt_element_name", name)
            element_div.add_style("padding-left: 10px")

            hover = element_div.get_color("background", -10)
            element_div.add_behavior({
                'type':
                'hover',
                'hover':
                hover,
                'cbjs_action_over':
                '''bvr.src_el.setStyle("background", bvr.hover)''',
                'cbjs_action_out':
                '''bvr.src_el.setStyle("background", "")'''
            })
            element_div.add_class("hand")

            element_div.add_behavior({
                'type':
                'drag',
                "drag_el":
                '@',
                "cb_set_prefix":
                'spt.freeform.create_element_drag'
            })
        """
        button = ActionButtonWdg(title="Save")
        left_div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_freeform_top");
        var canvas_top = top.getElement(".spt_freeform_canvas_top");
        var canvas = canvas_top.getElement(".spt_freeform_canvas");
        spt.freeform.init(canvas);
        var xml = spt.freeform.export();
        var search_type = canvas.getAttribute("spt_search_type");
        var view = canvas.getAttribute("spt_view");
        if (!search_type || !view) {
            alert("Cannot find search type or view");
            return;
        }

        var server = TacticServerStub.get();
        var sobject = server.get_unique_sobject("config/widget_config", {search_type: search_type, view: view} );
        server.update(sobject, {config: xml} );

        '''
        } )
        """

        from tactic.ui.container import DialogWdg
        dialog = DialogWdg(display=False, show_pointer=False)
        dialog.add_title("Properties")
        self.dialog_id = dialog.get_id()
        left.add(dialog)
        attr_div = self.get_attr_wdg()
        dialog.add(attr_div)

        template_div = DivWdg()
        left.add(template_div)
        template_div.add_class("spt_freeform_template_top")
        template_div.add_style("display: none")
        template_config_xml = self.get_template_config_xml()
        freeform_layout = FreeFormCanvasWdg(search_type=search_type,
                                            view="freeform",
                                            config_xml=template_config_xml,
                                            dialog_id=self.dialog_id)
        template_div.add(freeform_layout)

        # handle the canvas
        canvas = table.add_cell(resize=False)
        canvas.add(self.get_action_wdg())
        canvas.add_style("overflow: hidden")

        canvas.add_style("vertical-align: top")
        canvas.add_color("background", "background")
        canvas.add_color("color", "color")

        canvas_div = DivWdg()
        canvas_div.add_style("margin: 20px")
        canvas_div.add_style("width: 90%")
        canvas_div.add_style("min-width: 300px")
        canvas_div.add_style("padding: 10px")
        canvas_div.add_style("height: 100%")
        canvas_div.add_class("spt_freeform_canvas_top")
        canvas.add(canvas_div)
        freeform_layout = FreeFormCanvasWdg(search_type=search_type,
                                            view=view,
                                            config_xml=config_xml,
                                            dialog_id=self.dialog_id)
        canvas_div.add(freeform_layout)

        table.add_resize_row()

        if self.kwargs.get("is_refresh") in [True, "true"]:
            return inner
        else:
            return top
Example #29
0
    def get_display(my):

        web = WebContainer.get_web()
        naming_util = NamingUtil()

        if not my.widget_name:
            my.widget_name = my.get_name()

        # get the sobject required by this input
        sobject = my.get_current_sobject()
        if not sobject:
            sobject = Search.get_by_id(my.search_type, my.search_id)

        if my.new_sample_name:
            my.new_sample_name.replace("//", "/")
        else:
            my.new_sample_name = sobject.get_value(my.widget_name)

        widget = DivWdg()
        widget.set_id("naming")
        widget.add_style("display: block")

        # set the sample text
        div = DivWdg()
        div.add("Sample name: <i>%s</i>" % my.new_sample_name)
        div.add(HtmlElement.br(2))

        new_sample_wdg = ProdIconButtonWdg("Set New Sample")
        new_sample_wdg.add_event("onclick", "toggle_display('generate')")
        div.add(new_sample_wdg)

        generate = DivWdg()
        generate.add(HtmlElement.br())
        generate.set_id("generate")
        generate.add_style("display: none")
        sample_text = TextWdg("new_sample_name")
        sample_text.set_option("size", "30")
        # sample_text.set_persist_on_submit()
        # if my.new_sample_name:
        #    sample_text.set_value(my.new_sample_name)
        generate.add(sample_text)

        button = IconButtonWdg("Generate", IconWdg.REFRESH, long=True)
        on_script = my.setup_ajax("naming")
        button.add_event("onclick", on_script)
        generate.add(button)
        generate.add(HtmlElement.br(2))

        div.add(generate)
        widget.add(div)

        hidden = TextWdg(my.widget_name)
        value = my.naming
        hidden.set_value(my.new_sample_name)
        widget.add(my.widget_name)
        widget.add(hidden)

        # get all of the parts

        # TODO: not sure if this should be dictated by the sample name
        # break up the name into parts
        import re

        if my.new_sample_name:
            tmp = my.new_sample_name.strip("/")
            parts = re.split("[\\/._]", tmp)
            print "parts: ", parts
        else:
            return widget

        # if there is a naming, then populate that
        if my.edit_search_type:
            options = naming_util.get_options(my.edit_search_type)
        else:
            options = naming_util.get_options(sobject.get_value("search_type"))

        table = Table()
        type_values = []
        padding_values = []
        for idx, part in enumerate(parts):
            table.add_row()
            table.add_cell(part)

            type_select = SelectWdg("type_%s" % idx)
            type_select.add_empty_option("-- Explicit --")
            type_select.set_persist_on_submit()
            type_select.set_option("values", "|".join(options))
            type_values.append(type_select.get_value())
            td = table.add_cell(type_select)

        widget.add(table)

        return widget
Example #30
0
    def get_scale_wdg(my):

        if my.scale_called == True:
            return None
        my.scale_called = True

        show_scale = my.kwargs.get("show_scale")

        div = DivWdg()
        if show_scale in [False, 'false']:
            div.add_style("display: none")
        div.add_style("padding: 5px")
        div.add_class("spt_table_search")
        hidden = HiddenWdg("prefix", "tile_layout")
        div.add(hidden)
        div.add_behavior( {
            'type': 'load',
            'scale_prefix':  my.scale_prefix,
            'default_scale': my.scale,
            'aspect_ratio': my.aspect_ratio,
            'cbjs_action': '''
spt.tile_layout = {}
spt.tile_layout.layout = null;

spt.tile_layout.set_layout = function(layout) {
    if (!layout.hasClass("spt_layout")) {
        layout = layout.getParent(".spt_layout");
    }
    spt.tile_layout.layout = layout;
    return layout;
}

spt.tile_layout.get_scale = function() {
    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    var value = scale_value.value;
    value = parseInt(value);
    return value;
}


spt.tile_layout.set_scale = function(scale) {

    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    scale_value.value = scale;

    var size_x = bvr.aspect_ratio[0]*scale/100;
    var size_y = bvr.aspect_ratio[1]*scale/100;

    //var top = bvr.src_el.getParent(".spt_tile_layout_top");
    var top = spt.tile_layout.layout;
    var els = top.getElements(".spt_tile_content");
    for (var i = 0; i < els.length; i++) {
        var el = els[i];
        el.setStyle( "width",  size_x);
        el.setStyle( "height", size_y);
    }

    var container_id = "tile_layout::scale"+bvr.scale_prefix;
    spt.container.set_value( container_id, scale);
}


spt.tile_layout.drag_start_x = null;
spt.tile_layout.drag_start_value = null;

spt.tile_layout.drag_setup = function(evt, bvr, mouse_411) {
    spt.tile_layout.set_layout(bvr.src_el);
    spt.tile_layout.drag_start_x = mouse_411.curr_x;
    var src_el = spt.behavior.get_bvr_src( bvr );
    if (!src_el.value) {
        src_el.value = 0;
    }
    spt.tile_layout.drag_start_value = src_el.value;
    src_el.focus();
    src_el.select();
}
spt.tile_layout.drag_motion = function(evt, bvr, mouse_411) {
    var start_value = spt.tile_layout.drag_start_value; 
    if (isNaN(parseInt(start_value))) {
        return;
    }
    var dx = mouse_411.curr_x - spt.tile_layout.drag_start_x;
    var increment = parseInt(dx / 5);
    var multiplier;
    if (increment < 0)
        multiplier = 0.975;
    else
        multiplier = 1 / 0.975;
    increment = Math.abs(increment);
    var scale = spt.tile_layout.drag_start_value;
    for (var i = 0; i < increment; i++) {
        scale = scale * multiplier;
    }
    if (scale > 400)
        scale = 400;
    scale = parseInt(scale);
    spt.tile_layout.set_scale(scale);

}
spt.tile_layout.setup_control = function() {
   var slider = spt.tile_layout.layout.getElement('.spt_slider');
   var container_id = "tile_layout::scale"+bvr.scale_prefix;
   var initial_value = spt.container.get_value(container_id) ?  spt.container.get_value(container_id) : bvr.default_scale;

   spt.tile_layout.set_scale(initial_value);
   new Slider(slider, slider.getElement('.knob'), {
    range: [30, 400],
    steps: 74,
    initialStep: initial_value,
    onChange: function(value){
      if (value) spt.tile_layout.set_scale(value);
    }
  });
}



spt.tile_layout.image_drag_setup = function(evt, bvr, mouse_411) {
    bvr.use_copy = true;
    bvr.use_delta = true;
    //bvr.border_color = border_color;
    bvr.dx = 10;
    bvr.dy = 10;
    bvr.drop_code = 'DROP_ROW';


}

spt.tile_layout.image_drag_motion = function(evt, bvr, mouse_411) {

    spt.mouse._smart_default_drag_motion(evt, bvr, mouse_411);
    var target_el = spt.get_event_target(evt);
    target_el = spt.mouse.check_parent(target_el, bvr.drop_code);
    if (target_el) {
        var orig_border_color = target_el.getStyle('border-color');
        var orig_border_style = target_el.getStyle('border-style');
        target_el.setStyle('border','dashed 2px ' + bvr.border_color);
        if (!target_el.getAttribute('orig_border_color')) {
            target_el.setAttribute('orig_border_color', orig_border_color);
            target_el.setAttribute('orig_border_style', orig_border_style);
        }
    }

}

spt.tile_layout.image_drag_action = function(evt, bvr, mouse_411) {
    if (spt.drop) {
        spt.drop.sobject_drop_action(evt, bvr);
    }
    else {
        if( bvr._drag_copy_el ) {
            spt.behavior.destroy_element(bvr._drag_copy_el);
        }
    }
}

        ''' } )


        scale = my.kwargs.get("scale")


        div.add_behavior( {
        'type': 'load',
        'scale': scale,
        'cbjs_action': '''
        spt.tile_layout.set_layout(bvr.src_el);

        spt.tile_layout.setup_control();

        if (bvr.scale) {
            spt.tile_layout.set_scale(bvr.scale);
        }
      
        '''
        } )

        table = Table()
        div.add(table)
        table.add_row()

        """
        # TO BE DELETED
        less_div = DivWdg()
        less_div.add("<input type='button' value='&lt;&lt;'/>")
        table.add_cell(less_div)

        less_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale * 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )
        """

        dark_color = div.get_color("background", -5)
        light_color = div.get_color('color')
        med_color = div.get_color('color2')
        
        slider_div = DivWdg(css='spt_slider')
        slider_div.add_styles('valign: bottom; background: %s; height: 6px; width: 100px;'% light_color)
        knob_div = DivWdg(css='knob')
        knob_div.add_behavior({'type':'click',
                'cbjs_action': 'spt.tile_layout.set_layout(bvr.src_el)'
                })
        knob_div.add_styles('background: %s; bottom: 4px;\
                height: 16px; width: 12px; border-radius: 6px 6px 0 0;\
                border: 1px %s solid'\
                %(dark_color, med_color ))
        slider_div.add(knob_div)
        td = table.add_cell(slider_div)
        value_wdg = TextWdg("scale")
        value_wdg.add_class("spt_scale_value")
        td = table.add_cell(value_wdg)
        td.add("&nbsp;%")

        td.add_style("padding: 3px 8px")

        """
        # TO BE DELETED
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix("tile_layout")
        if data_list:
            data = data_list[0]
        else:
            data = {}
        my.scale = data.get("scale")
        if my.scale == None:
            my.scale = my.kwargs.get("scale")
        """
        if my.scale:
            value_wdg.set_value(my.scale)
        value_wdg.add_style("width: 28px")
        value_wdg.add_style("text-align: center")
        value_wdg.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )
        value_wdg.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        if (!value) {
            value = 100;
        }
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )



 
        value_wdg.add_behavior( {
            'type': 'smart_drag',
            'bvr_match_class': 'spt_scale_value',
            'ignore_default_motion' : True,
            "cbjs_setup": 'spt.tile_layout.drag_setup( evt, bvr, mouse_411 );',
            "cbjs_motion": 'spt.tile_layout.drag_motion( evt, bvr, mouse_411 );'
        } )

        
        """
        # TO BE DELETED
        more_div = DivWdg()
        more_div.add("<input type='button' value='&gt;&gt;'/>")
        table.add_cell(more_div)

        more_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale / 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )

        """


       

        return div
Example #31
0
    def handle_simple_mode(my, custom_table, mode):

        tbody = custom_table.add_tbody()
        tbody.add_class("spt_custom_simple")
        if mode != 'simple':
            tbody.add_style('display: none')


        name_text = TextWdg("custom_name")
        name_text.add_class("spt_input")
        tr = custom_table.add_row()
        tr.add_color("background", "background", -7)
        td = custom_table.add_cell("Name: ")
        td.add_style("min-width: 150px")
        custom_table.add_cell(name_text)


        # add title
        custom_table.add_row()
        title_wdg = TextWdg("custom_title")
        title_wdg.add_attr("size", "50")
        custom_table.add_cell( "Title: " )
        custom_table.add_cell( title_wdg )

        # add description
        tr = custom_table.add_row()
        tr.add_color("background", "background", -7)
        description_wdg = TextAreaWdg("custom_description")
        custom_table.add_cell( "Description: " )
        custom_table.add_cell( description_wdg )


        type_select = SelectWdg("custom_type")
        type_select.add_class("spt_input")
        #type_select.add_empty_option("-- Select --")
        type_select.set_option("values", "string|text|integer|float|boolean|currency|date|foreign_key|list|button|empty")
        type_select.set_option("labels", "String(db)|Text(db)|Integer(db)|Float(db)|Boolean(db)|Currency(db)|Date(db)|Foreign Key(db)|List(db)|Button|Empty")
        #type_select.set_option("labels", "String|Integer|Boolean|Currency|Timestamp|Link|Foreign Key|List|Checkbox|Text|Number|Date|Date Range")
        tr = custom_table.add_row()
        custom_table.add_cell("Property Type: ")
        td = custom_table.add_cell(type_select)
        type_select.add_event("onchange", "spt.custom_property_adder.property_type_select_cbk(this)")



        # extra info for foreign key
        custom_table.add_row()
        div = DivWdg()
        div.add_class("foreign_key_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Relate to: ")
        search_type_select = SearchTypeSelectWdg("foreign_key_search_select", mode=SearchTypeSelectWdg.CURRENT_PROJECT)
        div.add(search_type_select)
        td.add(div)



        # extra info for list
        custom_table.add_row()
        div = DivWdg()
        div.add_class("list_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Values: ")
        search_type_text = TextWdg("list_values")
        div.add(search_type_text)
        td.add(div)




        # extra info for button
        custom_table.add_row()
        div = DivWdg()
        div.add_class("button_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")

        class_path = "tactic.ui.table.ButtonElementWdg"
        button = Common.create_from_class_path(class_path)
        args_keys = button.get_args_keys()


        div.add("Options")
        div.add(HtmlElement.br())

        for key in args_keys.keys():
            div.add("Name: ")
            option_name_text = TextWdg("option_name")
            option_name_text.add_attr("readonly", "true")
            option_name_text.set_value(key)
            div.add(option_name_text)

            div.add(" &nbsp; ")

            div.add("Value: ")
            input = button.get_input_by_arg_key(key)
            div.add(input)

            #option_value_text = TextWdg("option_value")
            #div.add(option_value_text)
            div.add(HtmlElement.br())
        td.add(div)






        # is searchable checkbox
        tr = custom_table.add_row()
        tr.add_color("background", "background", -7)
        current_searchable_wdg = CheckboxWdg("is_searchable")
        #current_view_wdg.set_checked()
        custom_table.add_cell("Is Searchable? ")
        td = custom_table.add_cell(current_searchable_wdg)

        custom_table.close_tbody()
Example #32
0
    def get_display(my):

        widget = Widget()

        div = DivWdg(css='spt_ui_options')
        div.set_unique_id()
        table = Table()
        div.add(table)
        table.add_style("margin: 5px 15px")
        table.add_color('color', 'color')

        swap = SwapDisplayWdg()
        #swap.set_off()
        app = WebContainer.get_web().get_selected_app()
        outer_span = SpanWdg()
        outer_span.add_style('float: right')
        span = SpanWdg(app, css='small')
        icon = IconWdg(icon=eval("IconWdg.%s" % app.upper()), width='13px')
        outer_span.add(span)
        outer_span.add(icon)

        title = SpanWdg("Loading Options")
        title.add(outer_span)

        SwapDisplayWdg.create_swap_title(title, swap, div, is_open=False)

        widget.add(swap)
        widget.add(title)
        widget.add(div)

        if not my.hide_instantiation:
            table.add_row()
            table.add_blank_cell()
            div = DivWdg(HtmlElement.b("Instantiation: "))
            table.add_cell(div)
            div = my.get_instantiation_wdg()
            table.add_cell(div)

        setting = my.get_default_setting()
        default_instantiation = setting.get('instantiation')
        default_connection = setting.get('connection')
        default_dependency = setting.get('texture_dependency')

        if not my.hide_connection:
            table.add_row()
            table.add_blank_cell()
            con_div = DivWdg(HtmlElement.b("Connection: "))
            table.add_cell(con_div)
            td = table.add_cell()

            is_unchecked = True
            default_cb = None
            for value in ['http', 'file system']:
                name = my.get_element_name("connection")
                checkbox = CheckboxWdg(name)
                checkbox.set_option("value", value)
                checkbox.set_persistence()
                if value == default_connection:
                    default_cb = checkbox
                if checkbox.is_checked():
                    is_unchecked = False
                checkbox.add_behavior({
                    'type':
                    'click_up',
                    'propagate_evt':
                    True,
                    "cbjs_action":
                    "spt.toggle_checkbox(bvr, '.spt_ui_options', '%s')" % name
                })
                span = SpanWdg(checkbox, css='small')
                span.add(value)

                td.add(span)
            if is_unchecked:
                default_cb.set_checked()

        if not my.hide_dependencies:
            table.add_row()
            table.add_blank_cell()
            div = DivWdg(HtmlElement.b("Texture Dependencies: "))
            table.add_cell(div)
            td = table.add_cell()

            is_unchecked = True
            default_cb = None
            for value in ['as checked in', 'latest', 'current']:
                name = my.get_element_name("dependency")
                checkbox = CheckboxWdg(name)

                checkbox.set_option("value", value)
                checkbox.set_persistence()
                checkbox.add_behavior({
                    'type':
                    'click_up',
                    'propagate_evt':
                    True,
                    "cbjs_action":
                    "spt.toggle_checkbox(bvr, '.spt_ui_options', '%s')" % name
                })
                if value == default_dependency:
                    default_cb = checkbox
                if checkbox.is_checked():
                    is_unchecked = False

                span = SpanWdg(checkbox, css='small')
                span.add(value)
                td.add(span)
            if is_unchecked:
                default_cb.set_checked()

        from connection_select_wdg import ConnectionSelectWdg
        table.add_row()
        table.add_blank_cell()
        div = DivWdg(HtmlElement.b("Connection Type: "))
        table.add_cell(div)
        table.add_cell(ConnectionSelectWdg())

        table.add_row()
        table.add_blank_cell()
        div = DivWdg(HtmlElement.b("Connection Port: "))
        table.add_cell(div)
        port_div = DivWdg()
        port_text = TextWdg("port")
        port_text.set_option('size', '6')
        port_div.add(port_text)
        port_div.add_style("padding-left: 7px")
        port_div.add_style("width: 40px")
        table.add_cell(port_div)

        from pyasm.prod.web import WidgetSettings
        value = WidgetSettings.get_value_by_key("CGApp:connection_port")
        if value:
            port_text.set_value(value)
        elif WebContainer.get_web().get_selected_app() == 'Houdini':
            port_text.set_value("13000")
        else:
            port_text.set_value("4444")

        port_text.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
                var value = bvr.src_el.value;
                value = parseInt(value);
                var kwargs = {
                    'data': value,
                    'key': 'CGApp:connection_port'
                }
                var cmd = "pyasm.web.WidgetSettingSaveCbk"
                var server = TacticServerStub.get();
                server.execute_cmd(cmd, kwargs);

                // FIXME: this is dangerous use of a global var
                app.port = value;
            '''
        })

        return widget
Example #33
0
    def get_set_limit_wdg(my):
        limit_content = DivWdg()
        limit_content.add_style("font-size: 10px")
        #limit_content.add_style("padding", "5px")
        #limit_content.add_border()

        limit_content.add("Show ")

        limit_select = SelectWdg("limit_select")
        limit_select.add_class("spt_search_limit_select")
        limit_select.set_option("values", "10|20|50|100|200|Custom")
        limit_select.add_style("font-size: 10px")
        limit_content.add(limit_select)
        limit_content.add(" items per page<br/>")

        if my.search_limit in [10, 20, 50, 100, 200]:
            limit_select.set_value(my.search_limit)
            is_custom = False
        else:
            limit_select.set_value("Custom")
            is_custom = True

        limit_select.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_search_limit_top");
            var value = bvr.src_el.value;
            var custom = top.getElement(".spt_search_limit_custom");
            if (value == 'Custom') {
                custom.setStyle("display", "");
            }
            else {
                custom.setStyle("display", "none");
            }

            '''
        })

        custom_limit = DivWdg()
        limit_content.add(custom_limit)
        custom_limit.add_class("spt_search_limit_custom")
        custom_limit.add("<br/>Custom: ")
        text = TextWdg("custom_limit")
        text.add_class("spt_search_limit_custom_text")
        text.add_style("width: 50px")
        if not is_custom:
            custom_limit.add_style("display: none")
        else:
            text.set_value(my.search_limit)
        custom_limit.add(text)
        text.add(" items")
        behavior = {
            'type':
            'keydown',
            'cbjs_action':
            '''
                 if (evt.key=='enter') {
                    // register this as changed item
                    var value = bvr.src_el.value;
                    if (isNaN(value) || value.test(/[\.-]/)) {
                        spt.error('You have to use an integer.');
                    }
                }
        '''
        }

        text.add_behavior(behavior)

        return limit_content
Example #34
0
    def get_first_row_wdg(self):

        # read the csv file
        self.file_path = ""

        div = DivWdg()

        div.add(self.get_upload_wdg())

        if not self.search_type:
            return div

        if not self.file_path:
            return div

        if not self.file_path.endswith(".csv"):
            div.add("Uploaded file [%s] is not a csv file" % self.file_path)
            return div

        if not os.path.exists(self.file_path):
            raise Exception("Path '%s' does not exists" % self.file_path)

        div.add(HtmlElement.br(2))

        div.add(
            HtmlElement.
            b("The following is taken from first line in the uploaded csv file.  Select the appropriate column to match."
              ))
        div.add(HtmlElement.br())
        div.add(
            HtmlElement.b(
                "Make sure you have all the required columns** in the csv."))
        option_div = DivWdg()

        option_div.add_style("float: left")
        option_div.add_style("margin-right: 30px")

        option_div.add("<p>3. Parsing Options:</p>")

        self.search_type_obj = SearchType.get(self.search_type)

        # first row and second row
        option_div.add(HtmlElement.br(2))
        option_div.add("Use Title Row: ")
        title_row_checkbox = FilterCheckboxWdg("has_title")
        title_row_checkbox.set_default_checked()
        option_div.add(title_row_checkbox)
        option_div.add(
            HintWdg(
                "Set this to use the first row as a title row to match up columns in the database"
            ))

        option_div.add(HtmlElement.br(2))
        option_div.add("Sample Data Row: ")
        data_row_text = TextWdg("data_row")
        data_row_text.set_attr("size", "3")
        option_div.add(data_row_text)
        option_div.add(
            HintWdg(
                "Set this as a sample data row to match the columns to the database"
            ))

        option_div.add(HtmlElement.br(2))

        div.add(option_div)
        self.has_title = title_row_checkbox.is_checked()

        # parse the first fow
        csv_parser = CsvParser(self.file_path)
        if self.has_title:
            csv_parser.set_has_title_row(True)
        else:
            csv_parser.set_has_title_row(False)
        csv_parser.parse()
        csv_titles = csv_parser.get_titles()
        csv_data = csv_parser.get_data()

        data_row = data_row_text.get_value()
        if not data_row:
            data_row = 0
        else:
            try:
                data_row = int(data_row)
            except ValueError:
                data_row = 0

            if data_row >= len(csv_data):
                data_row = len(csv_data) - 1
        data_row_text.set_value(data_row)

        table = Table()
        table.set_attr("cellpadding", "10")

        table.add_row()
        table.add_header("CSV Column Value")
        table.add_header("TACTIC Column")
        table.add_header("Create New Column")

        columns = self.search_type_obj.get_columns()
        search_type = self.search_type_obj.get_base_search_type()
        sobj = SObjectFactory.create(search_type)
        required_columns = sobj.get_required_columns()

        row = csv_data[data_row]
        labels = []
        for column in columns:
            if column in required_columns:
                label = '%s**' % column
            else:
                label = column
            labels.append(label)

        for j, cell in enumerate(row):
            table.add_row()
            table.add_cell(cell)

            column_select = SelectWdg("column_%s" % j)
            column_select.add_event(
                "onchange",
                "if (this.value!='') {set_display_off('new_column_div_%s')} else {set_display_on('new_column_div_%s')}"
                % (j, j))

            column_select.add_empty_option("-- Select --")
            column_select.set_option("values", columns)
            column_select.set_option("labels", labels)

            # only set the value if it is actually in there
            if csv_titles[j] in columns:
                column_select.set_option("default", csv_titles[j])
            column_select.set_persist_on_submit()
            column_select_value = column_select.get_value()

            display = column_select.get_buffer_display()
            td = table.add_cell(display)

            if csv_titles[j] not in columns:
                td.add(" <b style='color: red'>*</b>")

                # new property
                new_column_div = DivWdg()

                if column_select_value:
                    new_column_div.add_style("display", "none")
                else:
                    new_column_div.add_style("display", "block")

                new_column_div.set_id("new_column_div_%s" % j)

                td = table.add_cell(new_column_div)
                text = TextWdg("new_column_%s" % j)
                text.set_persist_on_submit()

                if self.has_title:
                    text.set_value(csv_titles[j])

                new_column_div.add(" ... or ...")
                new_column_div.add(text)

        self.num_columns = len(row)
        hidden = HiddenWdg("num_columns", self.num_columns)

        # need to somehow specify defaults for columns

        div.add(table)

        div.add("<br/><br/>")

        div.add(self.get_preview_wdg())

        return div
Example #35
0
    def get_display(my):
        sobject = my.get_current_sobject()

        # handle the start and end
        frame_start = sobject.get_value("tc_frame_start")
        frame_end = sobject.get_value("tc_frame_end")

        frame_start_text = TextWdg("tc_frame_start")
        frame_start_text.set_value(frame_start)
        frame_start_text.set_option("size", "2")

        frame_end_text = TextWdg("tc_frame_end")
        frame_end_text.set_value(frame_end)
        frame_end_text.set_option("size", "2")

        # handle the notes
        frame_notes = sobject.get_value("frame_note")
        frame_notes_text = TextAreaWdg("frame_note")
        frame_notes_text.set_value(frame_notes)
        frame_notes_text.set_option("rows", "2")


        # handle the in and out handles
        frame_in = sobject.get_value("frame_in")
        frame_out = sobject.get_value("frame_out")

        frame_in_text = TextWdg("frame_in")
        frame_in_text.set_value(frame_in)
        frame_in_text.set_option("size", "2")

        frame_out_text = TextWdg("frame_out")
        frame_out_text.set_value(frame_out)
        frame_out_text.set_option("size", "2")


        div = DivWdg()


        table = Table()
        div.add(table)
        table.add_row()
        td = table.add_cell("Range:")
        td.add_style("width: 100px")
        td = table.add_cell()
        td.add_style("text-align: right")
        td.add_style("padding: 5px")
        td.add("start: ")
        td.add(frame_start_text)
        td = table.add_cell()
        td.add_style("text-align: right")
        td.add_style("padding: 5px")
        td.add("end: ")
        td.add(frame_end_text)

        table.add_row()
        table.add_cell("Handles:")
        td = table.add_cell()
        td.add_style("text-align: right")
        td.add_style("padding: 5px")
        td.add("in: ")
        td.add(frame_in_text)
        td = table.add_cell()
        td.add_style("text-align: right")
        td.add_style("padding: 5px")
        td.add("out: ")
        td.add(frame_out_text)
        td.add("<br/>")

        table.add_row()
        table.add_cell("Notes:")
        td = table.add_cell(frame_notes_text)
        td.add_style("padding: 5px")
        td.add_attr("colspan", "2")

        return div
Example #36
0
    def get_display(my):
        top = my.top
        top.add_class("spt_script_editor_top")
        """
        top.add_class("SPT_CHANGE")
        top.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            register_change = function(bvr) {
                var change_top = bvr.src_el.getParent(".SPT_CHANGE"); 
                change_top.addClass("SPT_HAS_CHANGES");
                change_top.update_change(change_top, bvr);
            }

            has_changes = function(bvr) {
                var change_top = bvr.src_el.getParent(".SPT_CHANGE"); 
                return change_top.hasClass("SPT_HAS_CHANGES");
            }

            bvr.src_el.update_change = function(top, bvr) {
                change_el = top.getElement(".spt_change_element");
                change_el.setStyle("display", "");
            }
            '''
        } )
        """

        change_div = DivWdg()
        top.add(change_div)
        #change_div.add("CHANGES!!!")
        change_div.add_style("display: none")
        change_div.add_class("spt_change_element")

        top.add_class("spt_panel")
        top.add_class("spt_js_editor")
        top.add_attr("spt_class_name", Common.get_full_class_name(my))
        top.add_color("background", "background")
        top.add_style("padding", "10px")

        div = DivWdg()
        top.add(div)

        # if script_path
        script_path = my.kwargs.get("script_path")
        search_key = my.kwargs.get("search_key")
        if script_path:
            search = Search("config/custom_script")
            dirname = os.path.dirname(script_path)
            basename = os.path.basename(script_path)

            search.add_filter("folder", dirname)
            search.add_filter("title", basename)
            script_sobj = search.get_sobject()
        elif search_key:
            script_sobj = Search.get_by_search_key(search_key)
        else:
            script_sobj = None

        if script_sobj:
            script_code = script_sobj.get_value("code")
            script_folder = script_sobj.get_value("folder")
            script_name = script_sobj.get_value("title")
            script_value = script_sobj.get_value("script")
            script_language = script_sobj.get_value("langauge")
        else:
            script_code = ''
            script_folder = ''
            script_name = ''
            script_value = ''

        editor = AceEditorWdg(custom_script=script_sobj)
        my.editor_id = editor.get_editor_id()

        if not Container.get_dict("JSLibraries", "spt_script_editor"):
            div.add_behavior({
                'type': 'load',
                'cbjs_action': my.get_onload_js()
            })

        # create the insert button
        help_button_wdg = DivWdg()
        div.add(help_button_wdg)
        help_button_wdg.add_style("float: right")
        help_button = ActionButtonWdg(title="?",
                                      tip="Script Editor Help",
                                      size='s')
        help_button_wdg.add(help_button)

        help_button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''spt.help.load_alias("tactic-script-editor")'''
        })

        # create the insert button
        add_button_wdg = DivWdg()
        add_button_wdg.add_style("float: right")
        add_button = ActionButtonWdg(title="Manage")
        add_button.add_behavior({
            'type': 'click_up',
            'cbfn_action': 'spt.popup.get_widget',
            'options': {
                'class_name': 'tactic.ui.panel.ViewPanelWdg',
                'title': 'Manage: [%s]' % my.search_type
            },
            'args': {
                'search_type': my.search_type,
                'view': 'table'
            },
        })

        add_button_wdg.add(add_button)
        div.add(add_button_wdg)

        button_div = editor.get_buttons_wdg()
        div.add(button_div)
        """
        button_div = DivWdg()
        #div.add(button_div)

        button_div.add_style("text-align: left")

        button = ActionButtonWdg(title="Run")
        button.add_style("float: left")
        button.add_style("margin: 0 10 3")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            //var editor = $('shelf_script');
            var value = editAreaLoader.getValue('shelf_script')
            eval( value )
            '''
        } )
        button_div.add(button)


        button = ActionButtonWdg(title="Save")
        button.add_style("float: left")
        button.add_style("margin: 0 10 3")
        #button = ProdIconButtonWdg("Save")
        #button.add_style("margin: 5 10")
        behavior = {
            'type': 'click_up',
            'cbfn_action': 'spt.script_editor.save_script_cbk'
        }
        button.add_behavior(behavior)
        button_div.add(button)


        button = ActionButtonWdg(title="Clear")
        button.add_style("float: left")
        button.add_style("margin: 0 10 3")
        #button = ProdIconButtonWdg("Clear")
        #button.add_style("margin: 5 10")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') );
            editAreaLoader.setValue('shelf_script', '');

            '''
        } )

        button_div.add(button)
        """

        div.add(HtmlElement.br(clear='all'))

        div.add(HtmlElement.hr())

        save_wdg = DivWdg()
        save_wdg.add_style("padding: 2px 5px 6px 5px")
        save_wdg.add_color("background", "background", -5)

        # script code
        save_span = SpanWdg()
        save_span.add("<b>Code: </b>")
        save_wdg.add(save_span)
        save_text = TextWdg("shelf_code")
        save_text.set_value(script_code)
        save_text.add_attr("readonly", "true")
        save_text.set_id("shelf_code")
        save_text.add_class("spt_code")
        save_wdg.add(save_text)

        save_wdg.add("&nbsp;&nbsp;")

        # script name (path??)
        save_span = SpanWdg()
        save_span.add("<b>Script Path: </b>")
        save_wdg.add(save_span)
        save_text = TextWdg("shelf_folder")
        save_text.add_attr("size", "40")
        save_text.set_id("shelf_folder")
        save_text.add_class("spt_folder")
        save_text.set_value(script_folder)
        save_wdg.add(save_text)
        save_wdg.add(" / ")
        save_text = TextWdg("shelf_title")
        save_text.add_attr("size", "40")
        save_text.set_id("shelf_title")
        save_text.add_class("spt_title")
        save_text.set_value(script_name)
        save_wdg.add(save_text)
        div.add(save_wdg)

        from tactic.ui.container import ResizableTableWdg
        table = ResizableTableWdg()
        table.add_row()

        td = table.add_cell(resize=False)
        td.add_style("vertical-align: top")

        td.add(editor)

        text = TextAreaWdg("shelf_script")

        #text.add_behavior( {
        #    'type': 'double_click',
        #    'cbjs_action': '''
        #    var text = $('shelf_script');
        #    editor(text)
        #    '''
        #    } )
        """
        text.set_id("shelf_script")
        text.add_style("width: 550px")
        text.add_style("height: 300px")
        text.add_class("codepress")
        text.add_class("html")
        text.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
            editAreaLoader.init({
                id: "shelf_script", // id of the textarea to transform      
                start_highlight: true,  // if start with highlight
                allow_resize: "both",
                allow_toggle: true,
                word_wrap: true,
                language: "en",
                syntax: "js",   // need to make this setable
                replace_tab_by_spaces: "4",
                font_size: "8",
                toolbar: "search, go_to_line, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, highlight",
                syntax_selection_allow: "js,python"

        });

        '''
        } )

        text.add_style("margin-top: 5px")
        text.add_style("font-family: courier new")
        text.add_style("font-size: 11px")
        text.set_id("shelf_script")
        #text.add_attr("cols", "80")
        #text.add_attr("rows", "20")
        text.add_style("min-height", "400px")
        text.add_style("height", "400px")
        text.add_style("width", "600px")
        text.set_value(script_value)

        td.add(text)
        """

        td = table.add_cell()
        td.add_style('vertical-align: top')
        td.add(my.get_script_wdg())

        table.add_row(resize=False)

        div.add(table)

        if my.kwargs.get("is_refresh"):
            return div
        else:
            return top
Example #37
0
    def get_simple_definition_wdg(self):

        detail_wdg = DivWdg()
        detail_wdg.add_color("color", "color")
        detail_wdg.add_style("width: 350px")
        detail_wdg.add_style("margin-top: 10px")
        detail_wdg.add_style("padding: 10px")
        detail_wdg.add_border()
        title = DivWdg()
        title.add_style("margin-top: -23px")
        detail_wdg.add(title)
        if not self.name_string:
            title.add('No database column')
            return detail_wdg
        
        title.add("Column Definition")
       


        # add a name entry
        detail_wdg.add("<br/>")
        title = SpanWdg()
        detail_wdg.add("Name: ")
        detail_wdg.add(title)
        input = SpanWdg()
        input.add_style('padding-top: 6px')
        input.set_id("config_element_name")
        input.add(HtmlElement.b(self.name_string))
        detail_wdg.add(input)
        hidden = HiddenWdg('column_name', self.name_string)
        detail_wdg.add(hidden)
        hidden = HiddenWdg('target_search_type', self.search_type)
        detail_wdg.add(hidden)

        detail_wdg.add(HtmlElement.br(2))

        # add data_type entry
        data_type = SpanWdg()
        default_data_types = ['varchar(256)','varchar', 'character', 'text', 'integer', 'float', 'boolean', 'timestamp', 'Other...']
        select = SelectWdg('config_data_type', label ='Data Type: ')
        #detail_wdg.add(": ")
        select.set_option('values', default_data_types )
        select.set_value(self.data_type_string)
        
        select.add_behavior({'type': 'change', 
            'cbjs_action': "if (bvr.src_el.value=='Other...') {spt.show('config_data_type_custom');}\
                    else {spt.hide('config_data_type_custom');}"})
        data_type.add(select) 

        text = TextWdg('config_data_type_custom')
        span = SpanWdg("Other: ", css='med')
        span.add(text)
        span.set_id('config_data_type_custom')
        span.add_style('display','none')
        text.set_value(self.data_type_string)

        data_type.add("<br/>")
        data_type.add(span)
        detail_wdg.add(data_type)
            
        detail_wdg.add("<br/>")
        # add a nullable entry
        nullable = SpanWdg()
        checkbox = CheckboxWdg('config_nullable', label ='Allow null(empty) value: ')
        #detail_wdg.add(": ")
        nullable.add(checkbox)
   

        if self.nullable_string in ['True', 'true']:
            checkbox.set_checked()
        
        detail_wdg.add(nullable)


        #constraint = DivWdg()
        #detail_wdg.add(constraint)
        #constraint.add_style("margin-top: 10px")
        #constraint.add("Constraint: ")
        #select = SelectWdg("config_constraint")
        #constraint.add(select)
        #select.set_option("values", "unique|indexed")
        #select.add_empty_option("-- None --")




        button_div = DivWdg()
        button_div.add_style("text-align: center")


        button_div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
spt.manage_search_type = {};

spt.manage_search_type.change_column_cbk = function(bvr) {
    var class_name = 'tactic.ui.panel.AlterSearchTypeCbk';
    var options ={
        'alter_mode': bvr.alter_mode,
        'title': bvr.title
    };

    try {
        var server = TacticServerStub.get();
        var panel = $('search_type_detail');
        if (! panel.getAttribute("spt_class_name") ) {
            panel = panel.getParent(".spt_panel");
        }
        var values = spt.api.Utility.get_input_values(panel);
        rtn = server.execute_cmd(class_name, options, values);
        if (bvr.alter_mode == 'Remove Column')
            spt.info("Column [" + bvr.column + "] has been deleted.");
        else if (bvr.alter_mode == 'Modify Column')
            spt.notify.show_message("Column [" + bvr.column + "] has been modified.");
    }
    catch (e) {
        spt.alert(spt.exception.handler(e));
    }
    var view = 'db_column';
    spt.panel.refresh("ManageSearchTypeMenuWdg_" + view);
    var view = 'definition';
    spt.panel.refresh("ManageSearchTypeMenuWdg_" + view);
}


            '''
        } )


        detail_wdg.add(button_div)
        button_div.add("<hr/><br/>")
        if self.is_new_column:
            button = ActionButtonWdg(title="Commit") 
            #button = ProdIconButtonWdg("Commit New Column")
            button.add_behavior({"type": "click_up", 
                "cbjs_action": "spt.manage_search_type.change_column_cbk(bvr)", \
                        
                        "alter_mode": self.ADD_COLUMN})
            button_div.add(button)
        else:

            table = Table()
            button_div.add(table)
            table.add_row()
            table.center()

            button = ActionButtonWdg(title="Modify") 
            #button = ProdIconButtonWdg("Modify Column")
            button.add_behavior({"type": "click_up", 
            "cbjs_action": '''spt.manage_search_type.change_column_cbk(bvr);
                           ''',
                    "alter_mode": self.MODIFY_COLUMN,
                    "column": self.name_string,
                    "title": self.title_string
                    })
            table.add_cell(button)

            button = ActionButtonWdg(title="Delete") 
            #button = ProdIconButtonWdg("Delete Column")
            #button.add_style('background-color: #BF462E')
            button.add_behavior({"type": "click_up", 
                "cbjs_action": '''
                
                var yes = function() {
                    spt.manage_search_type.change_column_cbk(bvr);
                    
                }
                spt.confirm("Are you sure you wish to delete this column?", yes) 
                ''',
                "alter_mode": self.REMOVE_COLUMN,
                "column": self.name_string
                
                })
            table.add_cell(button)
            button_div.add(HiddenWdg('delete_column'))
            button_div.add(HiddenWdg('modify_column'))

        return detail_wdg
Example #38
0
    def get_scale_wdg(my):

        show_scale = my.kwargs.get("show_scale")

        div = DivWdg()
        if show_scale in [False, 'false']:
            div.add_style("display: none")
        div.add_style("padding: 5px")
        div.add_class("spt_table_search")
        hidden = HiddenWdg("prefix", "tile_layout")
        div.add(hidden)

        div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
spt.tile_layout = {}
spt.tile_layout.layout = null;

spt.tile_layout.set_layout = function(layout) {
    if (!layout.hasClass("spt_layout")) {
        layout = layout.getParent(".spt_layout");
    }
    spt.tile_layout.layout = layout;
    return layout;
}

spt.tile_layout.get_scale = function() {
    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    var value = scale_value.value;
    value = parseInt(value);
    return value;
}


spt.tile_layout.set_scale = function(scale) {

    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    scale_value.value = scale;

    var size_x = 240*scale/100;
    var size_y = 160*scale/100;

    //var top = bvr.src_el.getParent(".spt_tile_layout_top");
    var top = spt.tile_layout.layout;
    var els = top.getElements(".spt_tile_content");
    for (var i = 0; i < els.length; i++) {
        var el = els[i];
        el.setStyle( "width",  size_x);
        el.setStyle( "height", size_y);
    }

    spt.container.set_value("tile_layout::scale", scale);

}


spt.tile_layout.drag_start_x = null;
spt.tile_layout.drag_start_value = null;

spt.tile_layout.drag_setup = function(evt, bvr, mouse_411) {
    spt.tile_layout.set_layout(bvr.src_el);
    spt.tile_layout.drag_start_x = mouse_411.curr_x;
    var src_el = spt.behavior.get_bvr_src( bvr );
    if (!src_el.value) {
        src_el.value = 0;
    }
    spt.tile_layout.drag_start_value = src_el.value;
    src_el.focus();
    src_el.select();
}
spt.tile_layout.drag_motion = function(evt, bvr, mouse_411) {
    var start_value = spt.tile_layout.drag_start_value; 
    if (isNaN(parseInt(start_value))) {
        return;
    }
    var dx = mouse_411.curr_x - spt.tile_layout.drag_start_x;
    var increment = parseInt(dx / 5);
    var multiplier;
    if (increment < 0)
        multiplier = 0.975;
    else
        multiplier = 1 / 0.975;
    increment = Math.abs(increment);
    var scale = spt.tile_layout.drag_start_value;
    for (var i = 0; i < increment; i++) {
        scale = scale * multiplier;
    }
    scale = parseInt(scale);
    spt.tile_layout.set_scale(scale);

}


        ''' } )



        div.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        spt.tile_layout.set_layout(bvr.src_el);
        var scale = spt.container.get_value("tile_layout::scale");
        if (scale) {
            spt.tile_layout.set_scale(scale);
        }
        '''
        } )


        table = Table()
        div.add(table)
        table.add_row()

        less_div = DivWdg()
        less_div.add("<input type='button' value='&lt;&lt;'/>")
        table.add_cell(less_div)

        less_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale * 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )


 
        value_wdg = TextWdg("scale")
        value_wdg.add_class("spt_scale_value")
        td = table.add_cell(value_wdg)
        td.add("&nbsp;%")
        td.add_style("padding: 3px 8px")
        if my.scale:
            value_wdg.set_value(my.scale)
        value_wdg.add_style("width: 24px")
        value_wdg.add_style("text-align: center")
        value_wdg.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )
        value_wdg.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        if (!value) {
            value = 100;
        }
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )



 
        value_wdg.add_behavior( {
            'type': 'smart_drag',
            'bvr_match_class': 'spt_scale_value',
            'ignore_default_motion' : True,
            "cbjs_setup": 'spt.tile_layout.drag_setup( evt, bvr, mouse_411 );',
            "cbjs_motion": 'spt.tile_layout.drag_motion( evt, bvr, mouse_411 );'
        } )



        more_div = DivWdg()
        more_div.add("<input type='button' value='&gt;&gt;'/>")
        table.add_cell(more_div)

        more_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale / 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )



        return div
    def get_display(my):
        widget = DivWdg()
        table = Table()
        table.add_attr('class','client_deliverable_wdg')
        table.add_row()
        table2 = Table()
        table2.add_style('border-spacing: 5px;')
        table2.add_style('border-collapse: separate;')
        table2.add_row()

        c1 = table2.add_cell('Order Code:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('order_code')
        tb1.add_attr('id','order_code')
        tb1.add_attr('disabled','disabled')
        tb1.set_value(my.sob['order_code'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('PO Number:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('po_number')
        tb1.add_attr('id','po_number')
        tb1.add_attr('disabled','disabled')
        tb1.set_value(my.sob['po_number'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Title Code:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('title_code')
        tb1.add_attr('id','title_code')
        tb1.add_attr('disabled','disabled')
        tb1.set_value(my.sob['title_code'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Platform:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('platform')
        tb1.add_attr('id','platform')
        tb1.add_attr('disabled','disabled')
        tb1.set_value(my.sob['platform'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Client:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('client_name')
        tb1.add_attr('id','client_name')
        tb1.add_attr('disabled','disabled')
        tb1.set_value(my.sob['client_name'])
        table2.add_cell(tb1)

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Title Source(s):')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('original_source_code')
        tb1.add_attr('id','original_source_code')
        tb1.add_attr('disabled','disabled')
        tb1.add_style('width','200px')
        tb1.set_value(my.sob['original_source_code'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','2')

        c1 = table2.add_cell('Title Source Barcodes(s):')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('original_source_barcode')
        tb1.add_attr('id','original_source_barcode')
        tb1.add_attr('disabled','disabled')
        tb1.add_style('width','200px')
        tb1.set_value(my.sob['original_source_barcode'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','2')

        c1 = table2.add_cell('Ancestors:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('ancestors')
        tb1.add_attr('id','ancestors')
        tb1.add_attr('disabled','disabled')
        tb1.add_style('width','300px')
        tb1.set_value(my.sob['ancestors'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','3')

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Destination:')
        c1.add_attr('nowrap','nowrap')
        destination_sel = SelectWdg('destination')
        destination_sel.add_attr('id','destination')
        destination_sel.append_option('--Select--','')
        for c in my.all_clients:
            destination_sel.append_option(c.get('name'),c.get('name'))
        if my.sob.get('destination') == None:
            my.sob['destination'] = ''
        destination_sel.set_value(my.sob.get('destination'))
        table2.add_cell(destination_sel)


        if my.sob.get('record_id') in [None,'']:
            next_id_sob = my.server.eval("@SOBJECT(twog/global_resource['name','sony_next_unique_id'])")[0]
            next_id = int(next_id_sob.get('description'))
            my.sob['record_id'] = next_id
            my.server.update(next_id_sob.get('__search_key__'), {'description': next_id + 1}, triggers=False)
        c1 = table2.add_cell('Record ID:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('record_id')
        tb1.add_attr('id','record_id')
        tb1.set_value(my.sob['record_id'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Alpha ID:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('alpha_id')
        tb1.add_attr('id','alpha_id')
        tb1.set_value(my.sob['alpha_id'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Client Barcode:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('client_barcode')
        tb1.add_attr('id','client_barcode')
        tb1.set_value(my.sob['client_barcode'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Release Number:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('release_number')
        tb1.add_attr('id','release_number')
        tb1.set_value(my.sob['release_number'])
        table2.add_cell(tb1)

        table2.add_row()

        c1 = table2.add_cell('Title ID:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('title_id')
        tb1.add_attr('id','title_id')
        tb1.set_value(my.sob['title_id'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Title Name:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('title_name')
        tb1.add_attr('id','title_name')
        tb1.set_value(my.sob['title_name'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Title Type:')
        c1.add_attr('nowrap','nowrap')
        title_type_sel = SelectWdg('title_type')
        title_type_sel.add_attr('id','title_type')
        title_type_sel.append_option('--Select--','')
        for type in my.title_types:
            title_type_sel.append_option(type,type)
        if my.sob.get('title_type') == None:
            my.sob['title_type'] = ''
        title_type_sel.set_value(my.sob.get('title_type'))
        table2.add_cell(title_type_sel)

        c1 = table2.add_cell('Title Comment:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('title_comment')
        tb1.add_attr('id','title_comment')
        tb1.add_style('width','300px')
        tb1.set_value(my.sob['title_comment'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','3')

        table2.add_row()

        c1 = table2.add_cell('Clip Id:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('clip_id')
        tb1.add_attr('id','clip_id')
        tb1.set_value(my.sob['clip_id'])
        table2.add_cell(tb1)

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Trailer Number:')
        c1.add_attr('nowrap','nowrap')
        trailer_number_sel = SelectWdg('trailer_number')
        trailer_number_sel.add_attr('id','trailer_number')
        trailer_number_sel.append_option('--Select--','')
        for number in my.trailer_numbers:
            trailer_number_sel.append_option(number,number)
        if my.sob.get('trailer_number') == None:
            my.sob['trailer_number'] = ''
        trailer_number_sel.set_value(my.sob.get('trailer_number'))
        table2.add_cell(trailer_number_sel)

        c1 = table2.add_cell('Trailer Rev Number:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('trailer_rev_number')
        tb1.add_attr('id','trailer_rev_number')
        tb1.set_value(my.sob['trailer_rev_number'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Trailer Type:')
        c1.add_attr('nowrap','nowrap')
        trailer_type_sel = SelectWdg('trailer_type')
        trailer_type_sel.add_attr('id','trailer_type')
        trailer_type_sel.append_option('--Select--','')
        for type in my.trailer_types:
            trailer_type_sel.append_option(type,type)
        if my.sob.get('trailer_type') == None:
            my.sob['trailer_type'] = ''
        trailer_type_sel.set_value(my.sob.get('trailer_type'))
        table2.add_cell(trailer_type_sel)

        c1 = table2.add_cell('Trailer Version:')
        c1.add_attr('nowrap','nowrap')
        trailer_version_sel = SelectWdg('trailer_version')
        trailer_version_sel.add_attr('id','trailer_version')
        trailer_version_sel.append_option('--Select--','')
        for version in my.trailer_versions:
            trailer_version_sel.append_option(version,version)
        if my.sob.get('trailer_version') == None:
            my.sob['trailer_version'] = ''
        trailer_version_sel.set_value(my.sob.get('trailer_version'))
        table2.add_cell(trailer_version_sel)

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Language Audio:')
        c1.add_attr('nowrap','nowrap')
        language_audio_sel = SelectWdg('language_audio')
        language_audio_sel.append_option('--Select--','')
        for language in my.audio_languages:
            language_audio_sel.append_option(language,language)
        if my.sob.get('language_audio') == None:
            my.sob['language_audio'] = ''
        language_audio_sel.set_value(my.sob.get('language_audio'))
        table2.add_cell(language_audio_sel)

        c1 = table2.add_cell('Language Subtitled:')
        c1.add_attr('nowrap','nowrap')
        language_subtitled_sel = SelectWdg('language_subtitled')
        language_subtitled_sel.add_attr('id','language_subtitled')
        language_subtitled_sel.append_option('--Select--','')
        for language in my.subtitle_languages:
            language_subtitled_sel.append_option(language,language)
        if my.sob.get('language_subtitled') == None:
            my.sob['language_subtitled'] = ''
        language_subtitled_sel.set_value(my.sob.get('language_subtitled'))
        table2.add_cell(language_subtitled_sel)

        c1 = table2.add_cell('Language Text:')
        c1.add_attr('nowrap','nowrap')
        language_text_sel = SelectWdg('language_text')
        language_text_sel.add_attr('id','language_text')
        language_text_sel.append_option('--Select--','')
        for language in my.text_languages:
            language_text_sel.append_option(language,language)
        if my.sob.get('language_text') == None:
            my.sob['language_text'] = ''
        language_text_sel.set_value(my.sob.get('language_text'))
        table2.add_cell(language_text_sel)

        c1 = table2.add_cell('Original Language:')
        c1.add_attr('nowrap','nowrap')
        original_language_sel = SelectWdg('original_language')
        original_language_sel.add_attr('id','original_language')
        original_language_sel.append_option('--Select--','')
        for language in my.original_languages:
            original_language_sel.append_option(language,language)
        if my.sob.get('original_language') == None:
            my.sob['original_language'] = ''
        original_language_sel.set_value(my.sob.get('original_language'))
        table2.add_cell(original_language_sel)

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Source:')
        c1.add_attr('nowrap','nowrap')
        source_sel = SelectWdg('source')
        source_sel.add_attr('id','source')
        source_sel.append_option('--Select--','')
        for s in my.sources:
            source_sel.append_option(s,s)
        if my.sob.get('source') == None:
            my.sob['source'] = ''
        source_sel.set_value(my.sob.get('source'))
        table2.add_cell(source_sel)

        c1 = table2.add_cell('Audio Config:')
        c1.add_attr('nowrap','nowrap')
        audio_config_sel = SelectWdg('audio_config')
        audio_config_sel.add_attr('id','audio_config')
        audio_config_sel.append_option('--Select--','')
        for a in my.audio_configs:
            audio_config_sel.append_option(a,a)
        if my.sob.get('audio_config') == None:
            my.sob['audio_config'] = ''
        audio_config_sel.set_value(my.sob.get('audio_config'))
        table2.add_cell(audio_config_sel)

        c1 = table2.add_cell('Master Audio Config:')
        c1.add_attr('nowrap','nowrap')
        master_audio_config_sel = SelectWdg('master_audio_config')
        master_audio_config_sel.add_attr('id','master_audio_config')
        master_audio_config_sel.append_option('--Select--','')
        for a in my.audio_configs:
            master_audio_config_sel.append_option(a,a)
        if my.sob.get('master_audio_config') == None:
            my.sob['master_audio_config'] = ''
        master_audio_config_sel.set_value(my.sob.get('master_audio_config'))
        table2.add_cell(master_audio_config_sel)
         
        c1 = table2.add_cell('Run Time Calc:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('run_time_calc')
        tb1.add_attr('id','run_time_calc')
        tb1.set_value(my.sob['run_time_calc'])
        #Might want to add the : timestamp js here -- from qc reports
        table2.add_cell(tb1)
   
        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Narrative:')
        c1.add_attr('nowrap','nowrap')
        narrative_sel = SelectWdg('narrative')
        narrative_sel.add_attr('id','narrative')
        narrative_sel.append_option('--Select--','')
        for n in my.narratives:
            narrative_sel.append_option(n,n)
        if my.sob.get('narrative') == None:
            my.sob['narrative'] = ''
        narrative_sel.set_value(my.sob.get('narrative'))
        table2.add_cell(narrative_sel)

        c1 = table2.add_cell('Texted/Textless:')
        c1.add_attr('nowrap','nowrap')
        tt_sel = SelectWdg('texted_textless')
        tt_sel.add_attr('id','texted_textless')
        tt_sel.append_option('--Select--','')
        for t in my.texted_textless:
            tt_sel.append_option(t,t)
        if my.sob.get('texted_textless') == None:
            my.sob['texted_textless'] = ''
        tt_sel.set_value(my.sob.get('texted_textless'))
        table2.add_cell(tt_sel)

        c1 = table2.add_cell('Aspect Ratio:')
        c1.add_attr('nowrap','nowrap')
        aspect_ratio_sel = SelectWdg('aspect_ratio')
        aspect_ratio_sel.add_attr('id','aspect_ratio')
        aspect_ratio_sel.append_option('--Select--','')
        for a in my.aspect_ratios:
            aspect_ratio_sel.append_option(a,a)
        if my.sob.get('aspect_ratio') == None:
            my.sob['aspect_ratio'] = ''
        aspect_ratio_sel.set_value(my.sob.get('aspect_ratio'))
        table2.add_cell(aspect_ratio_sel)

        c1 = table2.add_cell('Standard:')
        c1.add_attr('nowrap','nowrap')
        standard_sel = SelectWdg('standard')
        standard_sel.add_attr('id','standard')
        standard_sel.append_option('--Select--','')
        for s in my.standards:
            standard_sel.append_option(s,s)
        if my.sob.get('standard') == None:
            my.sob['standard'] = ''
        standard_sel.set_value(my.sob.get('standard'))
        table2.add_cell(standard_sel)

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('HD:')
        c1.add_attr('nowrap','nowrap')
        hd_sel = SelectWdg('hd')
        hd_sel.add_attr('id','hd')
        hd_sel.append_option('--Select--','')
        for s in my.hd:
            hd_sel.append_option(s,s)
        if my.sob.get('hd') == None:
            my.sob['hd'] = ''
        hd_sel.set_value(my.sob.get('hd'))
        table2.add_cell(hd_sel)

#        c1 = table2.add_cell('Genre:')
#        c1.add_attr('nowrap','nowrap')
#        tb1 = TextWdg('genre')
#        tb1.add_attr('id','genre')
#        tb1.set_value(my.sob['genre'])
#        table2.add_cell(tb1)

        c1 = table2.add_cell('MPAA:')
        c1.add_attr('nowrap','nowrap')
        mpaa_sel = SelectWdg('mpaa')
        mpaa_sel.add_attr('id','mpaa')
        mpaa_sel.append_option('--Select--','')
        for s in my.mpaa:
            mpaa_sel.append_option(s,s)
        if my.sob.get('mpaa') == None:
            my.sob['mpaa'] = ''
        mpaa_sel.set_value(my.sob.get('mpaa'))
        table2.add_cell(mpaa_sel)

        c1 = table2.add_cell('MPAA Ratings:')
        c1.add_attr('nowrap','nowrap')
        mpaa_ratings_sel = SelectWdg('mpaa_ratings')
        mpaa_ratings_sel.add_attr('id','mpaa_ratings')
        mpaa_ratings_sel.append_option('--Select--','')
        for s in my.mpaa_ratings:
            mpaa_ratings_sel.append_option(s,s)
        if my.sob.get('mpaa_ratings') == None:
            my.sob['mpaa_ratings'] = ''
        mpaa_ratings_sel.set_value(my.sob.get('mpaa_ratings'))
        table2.add_cell(mpaa_ratings_sel)

        table2.add_row()
        table2.add_cell(table2.hr())
#        table2.add_row()
#
#        c1 = table2.add_cell('UK Ratings:')
#        c1.add_attr('nowrap','nowrap')
#        uk_ratings_sel = SelectWdg('uk_ratings')
#        uk_ratings_sel.add_attr('id','uk_ratings')
#        uk_ratings_sel.append_option('--Select--','')
#        for s in my.uk_ratings:
#            uk_ratings_sel.append_option(s,s)
#        if my.sob.get('uk_ratings') == None:
#            my.sob['uk_ratings'] = ''
#        uk_ratings_sel.set_value(my.sob.get('uk_ratings'))
#        table2.add_cell(uk_ratings_sel)
#
#        c1 = table2.add_cell('Australia Ratings:')
#        c1.add_attr('nowrap','nowrap')
#        australia_ratings_sel = SelectWdg('australia_ratings')
#        australia_ratings_sel.add_attr('id','australia_ratings')
#        australia_ratings_sel.append_option('--Select--','')
#        for s in my.australia_ratings:
#            australia_ratings_sel.append_option(s,s)
#        if my.sob.get('australia_ratings') == None:
#            my.sob['australia_ratings'] = ''
#        australia_ratings_sel.set_value(my.sob.get('australia_ratings'))
#        table2.add_cell(australia_ratings_sel)
#
#        c1 = table2.add_cell('Germany Ratings:')
#        c1.add_attr('nowrap','nowrap')
#        germany_ratings_sel = SelectWdg('germany_ratings')
#        germany_ratings_sel.add_attr('id','germany_ratings')
#        germany_ratings_sel.append_option('--Select--','')
#        for s in my.germany_ratings:
#            germany_ratings_sel.append_option(s,s)
#        if my.sob.get('germany_ratings') == None:
#            my.sob['germany_ratings'] = ''
#        germany_ratings_sel.set_value(my.sob.get('germany_ratings'))
#        table2.add_cell(germany_ratings_sel)
#
#        table2.add_row()
#        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Legal Rights:')
        c1.add_attr('nowrap','nowrap')
        legal_rights_sel = SelectWdg('legal_right')
        legal_rights_sel.add_attr('id','legal_right')
        legal_rights_sel.append_option('--Select--','')
        for s in my.legal_rights:
            legal_rights_sel.append_option(s,s)
        if my.sob.get('legal_right') == None:
            my.sob['legal_right'] = ''
        legal_rights_sel.set_value(my.sob.get('legal_right'))
        table2.add_cell(legal_rights_sel)
        

        from tactic.ui.widget import CalendarInputWdg, ActionButtonWdg
        ld = table2.add_cell('Legal Date: ')
        ld.add_attr('nowrap','nowrap')
        legal_date = CalendarInputWdg("legal_date")
        if my.sob.get('legal_date') not in [None,'']:
            legal_date.set_option('default', my.fix_date(my.sob.get('legal_date')))
        legal_date.set_option('show_activator', True)
        legal_date.set_option('show_confirm', False)
        #legal_date.set_option('show_text', True)
        legal_date.set_option('show_today', False)
        #legal_date.set_option('read_only', False)    
        legal_date.add_attr('id','legal_date')
        table2.add_cell(legal_date)

        c1 = table2.add_cell('Legal Comment:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('legal_comment')
        tb1.add_attr('id','legal_comment')
        tb1.add_style('width','300px')
        tb1.set_value(my.sob['legal_comment'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','3')

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('HE Creative Comment:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('he_creative_comment')
        tb1.add_attr('id','he_creative_comment')
        tb1.add_style('width','300px')
        tb1.set_value(my.sob['he_creative_comment'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','3')

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('URL:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('url')
        tb1.add_attr('id','url')
        tb1.add_style('width','300px')
        tb1.set_value(my.sob['url'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','3')

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()
        
        #ta1 = table2.add_cell('Cast Info:')
        #table2.add_row() 
        #ta1 = table2.add_cell('<textarea cols="90" rows="10" class="spt_input" name="cast_info" id="cast_info">%s</textarea>' % my.sob.get('cast_info'))

        #table2.add_row()
        submit = table2.add_cell('<input type="button" value="Submit"/>')
        sk = ''
        if not my.is_insert:
            sk = my.sob.get('__search_key__')
        submit.add_behavior(my.get_submit(sk))
        if not my.is_insert:
            xml = table2.add_cell('<input type="button" value="Generate XML"/>')
            xml.add_behavior(my.get_xml(sk))

         


        table.add_cell(table2)
        widget.add(table)
        return widget
Example #40
0
    def get_display(my):   
        widget = DivWdg()
        widget.add_attr('id','whole_fb_container_%s' % my.custom_top_name)
        if 'dir' in my.kwargs.keys():
            my.dir = my.kwargs.get('dir')
        if 'old_dir' in my.kwargs.keys():
            my.old_dir = my.kwargs.get('old_dir')
        else:
            my.old_dir = my.dir
        if 'mode' in my.kwargs.keys():
            my.mode = my.kwargs.get('mode')
            if my.mode in [None,'']:
                my.mode = 'classic'
        #print "DIR = %s, OLD DIR = %s" % (my.dir, my.old_dir)
        
        err_msg = ''
        if not os.path.isdir(my.dir):
            err_msg = '%s is not a valid directory' % my.dir 
            my.dir = my.old_dir
       
        trimmed_dir = my.dir
        if trimmed_dir[len(trimmed_dir) - 1] == '/' and len(trimmed_dir) > 1:
            trimmed_dir = trimmed_dir[:-1]
        
        prev_dir_s = trimmed_dir.split('/')
        prev_dir_s = prev_dir_s[:-1]
        prev_dir = ''
        
        for ct in range(0,len(prev_dir_s)):
            if prev_dir_s[ct] not in [None,'']:
                if prev_dir == '':
                    prev_dir = '/%s' % prev_dir_s[ct]
                else:   
                    prev_dir = '%s/%s' % (prev_dir, prev_dir_s[ct])
        if prev_dir in [None,'','//']:
            prev_dir = '/'
        #print "PREV DIR = %s" % prev_dir
        
        files_list = []
        dir_list = []
        
        files_dict = {}
        dirs_dict = {}
        
        longest_name_len = 0
        
        for f in os.listdir(my.dir):
            joined = join(my.dir,f)
            if os.path.isfile(joined):
                files_list.append(joined)
                last_modified = 'N/A'
                created = 'N/A'
                size = 'N/A'
                if joined.count('/') > 3:
                    last_modified =  datetime.fromtimestamp(os.path.getmtime(joined)).strftime('%Y-%m-%d %H:%M:%S')
                    created =  datetime.fromtimestamp(os.path.getctime(joined)).strftime('%Y-%m-%d %H:%M:%S')
                    size = my.convertSize(os.path.getsize(joined),'file')
                file_name_s = joined.split('/')
                file_name = file_name_s[len(file_name_s) - 1]
                file_path = joined
                files_dict[joined] = {'last_modified': last_modified, 'created': created, 'size': size, 'name': file_name, 'path': joined}
                if len(file_name) > longest_name_len:
                    longest_name_len = len(file_name)
            
            elif os.path.isdir(joined):
                dir_name_s = joined.split('/')
                dir_name = dir_name_s[len(dir_name_s) - 1]
                if dir_name[0] != '.':
                    dir_list.append(joined)
                    size = 'N/A'
                    created = 'N/A'
                    last_modified = 'N/A'
                   
                    #This is to keep us from calculating the size of the huge base directories
                    #Probably want a way to turn directory sizes on and off
                    if joined.count('/') > 5:
                        last_modified =  datetime.fromtimestamp(os.path.getmtime(joined)).strftime('%Y-%m-%d %H:%M:%S')
                        created =  datetime.fromtimestamp(os.path.getctime(joined)).strftime('%Y-%m-%d %H:%M:%S')
                        prepresize = commands.getoutput('du -s %s' % joined).split()[0]
                        try:
                            presize = float(prepresize)
                            if not math.isnan(presize):
                                size = my.convertSize(float(presize),'dir')
                        except ValueError:
                            print "GOT AN ERROR FOR %s" % joined
                            pass
                    dir_path = joined
                    dirs_dict[joined] = {'size': size, 'created': created, 'last_modified': last_modified, 'name': dir_name, 'path' : dir_path}
                    if len(dir_name) > longest_name_len:
                        longest_name_len = len(dir_name)
        
        #print "LONGEST NAME LEN = %s" % longest_name_len
        name_len = longest_name_len * 10
        
        # Displaying the table of the folders and files 
        top_tbl = Table()
        if err_msg != '':
            top_tbl.add_row()
            top_tbl.add_cell('<b><font color="#FF0000">%s</font></b>' % err_msg)
        top_tbl.add_row()
        dir_path_txt = TextWdg('dir_path')
        dir_path_txt.add_attr('id','dir_path')
        dir_path_txt.set_value(my.dir)
        dir_path_txt.set_option('size','100')
        dir_path_txt.add_behavior(my.change_location(my.old_dir))
        top_tbl.add_cell('Location: ')
        top_tbl.add_cell(dir_path_txt)
        
        div = DivWdg()
        
        back_tbl = Table()
        back_dir = back_tbl.add_cell("<-Back...")
        back_dir.add_attr('dir',prev_dir)
        back_dir.add_style('cursor: pointer;')
        back_dir.add_style('width: %spx;' % name_len)
        back_dir.add_behavior(my.dir_click())
        back_size = back_tbl.add_cell('Size')
        back_size.add_style('width: 100px;')
        back_created = back_tbl.add_cell('Created')
        back_created.add_style('width: 150px;')
        back_modified = back_tbl.add_cell('Last Modified')
        back_modified.add_style('width: 150px;')
        div.add(back_tbl)
    
        content_counter = 0
        dir_list.sort()
        files_list.sort()
        mult_dirs = DivWdg()
        mult_dirs.add_attr('class','DragContainer')
        mult_dirs.add_attr('id','DragContainer1')

        # Getting all the directories displayed, adding drag and drop attributes to each folder 
        for dr in dir_list:
         
            tbl = Table()
            tbl.add_row()
            dir_name = dirs_dict[dr]['name']
            dir_path = dirs_dict[dr]['path']
            FOLDER_ICON = my.folder_icon.replace("TITLE",dir_name)
            lil_tbl = Table()
            lil_tbl.add_row()
            lil_tbl.add_cell(FOLDER_ICON)
            
            directory_div = lil_tbl.add_cell('<b>%s</b>' % dir_name)
            
            if my.mode not in ['select']:
                directory_div.add_behavior(my.drag_controller())
                directory_div.add_style("-khtml-user-drag: element;")
                directory_div.add_attr("draggable", "true")
                directory_div.add_attr("ondragstart", "spt.drag.ondragstart(event, this, {path_name : '%s'}) "% dir_path)
                directory_div.add_attr("ondragover", "spt.drag.allowDrop(event, this)")
                directory_div.add_attr("ondrop", "spt.drag.ondrop(event, this, {destination_location: '%s'})" % dir_path)

            lil_cell = tbl.add_cell(lil_tbl)
            lil_cell.add_attr('name','clickable')
            lil_cell.add_attr('dir',dr)
            lil_cell.add_attr('type','dir')
            lil_cell.add_attr('path_name',dr)
            lil_cell.add_attr('highlight','off')
            #lil_cell.add_attr('class','biotches')
            lil_cell.add_style('cursor: pointer;')
            lil_cell.add_style('width: %spx;' % name_len)
            lil_cell.add_behavior(my.dir_click())
            lil_cell.add_behavior(my.highlighter_ctrl());
            lil_cell.add_behavior(my.hover_highlighter());
            if my.mode in ['select']:
                lil_cell.add_behavior(my.select_fp(my.custom_top_name))
            
            sc = tbl.add_cell('<i>%s</i>' % dirs_dict[dr]['size'])
            sc.add_attr('nowrap','nowrap')
            sc.add_attr('title','Size of Contents')
            sc.add_attr('name','Size of Contents')
            sc.add_style('width: 100px;')
           
            cc = tbl.add_cell(dirs_dict[dr]['created'])
            cc.add_attr('nowrap','nowrap')
            cc.add_attr('title','Created')
            cc.add_attr('name','Created')
            cc.add_style('width: 150px;')
         
            mc = tbl.add_cell(dirs_dict[dr]['last_modified'])
            mc.add_attr('nowrap','nowrap')
            mc.add_attr('title','Last Modified')
            mc.add_attr('name','Last Modified')
            mc.add_style('width: 150px;')
            div_dir = DivWdg()
            div_dir.add(tbl)
            mult_dirs.add(div_dir)
            content_counter = content_counter + 1
        div.add(mult_dirs)
        mult_files = DivWdg()
        mult_files.add_attr('class','DragContainer')
        mult_files.add_attr('id','DragContainer2')
        
        for fl in files_list:
            tbl = Table()
            tbl.add_row()

            file_name = files_dict[fl]['name']
            path_name = files_dict[fl]['path']

            text_wdg_file_name = DivWdg(file_name)
            if my.mode not in ['select']:
                text_wdg_file_name.add_behavior(my.drag_controller())
                text_wdg_file_name.add_style("-khtml-user-drag: element;")
                text_wdg_file_name.add_attr("draggable", "true")
                text_wdg_file_name.add_attr("ondragstart", "spt.drag.ondragstart(event, this, {path_name : '%s'}) "% path_name)
            
            FILE_ICON = my.file_icon.replace("TITLE",file_name)
            lil_tbl = Table()
            lil_tbl.add_row()
            lil_tbl.add_cell(FILE_ICON)
            file_div = lil_tbl.add_cell(text_wdg_file_name)
            lil_cell = tbl.add_cell(lil_tbl)
            lil_cell.add_attr('name','clickable')
            lil_cell.add_attr('file',fl)
            lil_cell.add_attr('type','file')
            lil_cell.add_attr('file_name',file_name)
            lil_cell.add_attr('path_name',path_name)
            lil_cell.add_attr('highlight','off')
            #lil_cell.add_attr('class','biotches')
            lil_cell.add_style('cursor: pointer;')
            lil_cell.add_style('width: %spx;' % name_len)
            lil_cell.add_behavior(my.highlighter_ctrl())
            lil_cell.add_behavior(my.hover_highlighter());
            if my.mode in ['select']:
                lil_cell.add_behavior(my.select_fp(my.custom_top_name))
            else:
                lil_cell.add_behavior(my.select_fp(my.custom_top_name))
             
            sc = tbl.add_cell('<i>%s</i>' % files_dict[fl]['size'])
            sc.add_attr('nowrap','nowrap')
            sc.add_attr('title','Size')
            sc.add_attr('name','Size')
            sc.add_style('width: 100px;')
            cc = tbl.add_cell(files_dict[fl]['created'])
            cc.add_attr('nowrap','nowrap')
            cc.add_attr('title','Created')
            cc.add_attr('name','Created')
            cc.add_style('width: 150px;')
            mc = tbl.add_cell(files_dict[fl]['last_modified'])
            mc.add_attr('nowrap','nowrap')
            mc.add_attr('title','Last Modified')
            mc.add_attr('name','Last Modified')
            mc.add_style('width: 150px;')
            div_fl = DivWdg()
            div_fl.add(tbl)
            mult_files.add(div_fl)
            content_counter = content_counter + 1
        div.add(mult_files)
        widget.add(top_tbl)
        widget.add(div)
        widget.add_behavior(my.click_anywhere())
        return widget 
Example #41
0
    def get_display(my):
        web = WebContainer.get_web()

        top = my.top
        top.add_class("spt_ace_editor_top")

        script = my.kwargs.get("custom_script")
        if script:
            language = script.get_value("language")
        else:
            language = my.kwargs.get("language")
            if not language:
                language = 'javascript'

        code = my.kwargs.get("code")
        if not code:
            code = ""


        show_options = my.kwargs.get("show_options")
        if show_options in ['false', False]:
            show_options = False
        else:
            show_options = True

        options_div = DivWdg()
        top.add(options_div)
        if not show_options:
            options_div.add_style("display: none")
        options_div.add_color("background", "background3")
        options_div.add_border()
        options_div.add_style("text-align: center")
        options_div.add_style("padding: 2px")



        select = SelectWdg("language")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.add_class("spt_language")
        select.set_option("values", "javascript|server_js|python|expression|xml")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var value = bvr.src_el.value;
            spt.ace_editor.set_language(value);

            //register_change(bvr);

            '''
        } )
 
        select = SelectWdg("font_size")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "8 pt|9 pt|10 pt|11 pt|12 pt|14 pt|16 pt")
        select.set_option("values", "8 pt|9pt|10pt|11pt|12pt|14pt|16pt")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'click_up',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var value = bvr.src_el.value;
            $(editor_id).setStyle("font-size", value)
            //editor.resize();
            '''
        } )



        select = SelectWdg("keybinding")
        select.add_style("width: 100px")
        #options_div.add(select)
        select.set_option("labels", "Ace|Vim|Emacs")
        select.set_option("values", "ace|vim|emacs")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var vim = require("ace/keyboard/keybinding/vim").Vim;
            editor.setKeyboardHandler(vim)
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)


        if code:
            load_div = DivWdg()
            top.add(load_div)
            readonly = my.kwargs.get("readonly")
            if readonly in ['true', True]:
                readonly = True
            else:
                readonly = False

            load_div.add_behavior( {
                'type': 'load',
                'code': code,
                'language': language,
                'editor_id': my.get_editor_id(),
                'readonly': readonly,
                'cbjs_action': '''
                spt.ace_editor.set_editor(bvr.editor_id);
                var func = function() {
                    var editor = spt.ace_editor.editor;
                    var document = editor.getSession().getDocument();
                    if (bvr.code) {
                        spt.ace_editor.set_value(bvr.code);
                    }
                    spt.ace_editor.set_language(bvr.language);
                    editor.setReadOnly(bvr.readonly);


                    var session = editor.getSession();
                    //session.setUseWrapMode(true);
                    //session.setWrapLimitRange(120, 120);
                };

                var editor = spt.ace_editor.editor;
                if (!editor) {
                    setTimeout( func, 1000);
                }
                else {
                    func();
                }

                '''
            } )




        # theme
        select = SelectWdg("theme")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "Eclipse|Twilight|TextMate|Vibrant Ink|Merbivore|Clouds")
        select.set_option("values", "eclipse|twilight|textmate|vibrant_ink|merbivore|clouds")
        select.set_value("twilight")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;
            value = bvr.src_el.value;

            editor.setTheme("ace/theme/" + value);
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)




        my.text_area.add_style("margin-top: -1px")
        my.text_area.add_style("margin-bottom: 0px")
        my.text_area.add_color("background", "background")
        my.text_area.add_style("font-family: courier new")
        my.text_area.add_border()
        editor_div.add(my.text_area)
        my.text_area.add_style("position: relative")
        #text_area.add_style("margin: 20px")


        size = web.get_form_value("size")
        if size:
            width, height = size.split(",")
        else:
            width = my.kwargs.get("width")
            if not width:
                width = "650px"
            height = my.kwargs.get("height")
            if not height:
                height = "450px"
        my.text_area.add_style("width: %s" % width)
        my.text_area.add_style("height: %s" % height)



        bottom_div = DivWdg()
        top.add(bottom_div)
        bottom_div.add_color("background", "background3")
        bottom_div.add_border()
        bottom_div.add_style("text-align: center")
        bottom_div.add_style("padding: 2px")
        bottom_div.add_style("height: 20px")

        bottom_title = "Script Editor"
        bottom_div.add(bottom_title)

        icon = IconWdg("Resize Editor", IconWdg.RESIZE_CORNER)
        bottom_div.add(icon)
        icon.add_style("float: right")
        icon.add_style("margin-right: -4px")
        icon.add_style("cursor: se-resize")
        icon.add_behavior( {
            'type': 'drag',
            "cb_set_prefix": 'spt.ace_editor.drag_resize',
        } )


        #hidden = HiddenWdg("size")
        hidden = TextWdg("size")
        bottom_div.add(hidden)
        hidden.add_style("width: 85px")
        hidden.add_style("text-align: center")
        hidden.add_style("float: right")
        hidden.add_class("spt_size")
        hidden.set_value("%s,%s" % (width, height))

        theme = top.get_theme()
        if theme == 'dark':
            theme = 'twilight'
        else:
            theme = 'eclipse'

        print "theme: ", theme

        top.add_behavior( {
            'type': 'load',
            'unique_id': my.unique_id,
            'theme': theme,
            'cbjs_action': '''

if (typeof(ace) == 'undefined') {

// fist time loading
spt.ace_editor = {}
spt.ace_editor.editor = null;
spt.ace_editor.editor_id = bvr.unique_id;
spt.ace_editor.theme = bvr.theme;


spt.ace_editor.set_editor = function(editor_id) {
    spt.ace_editor.editor_id = editor_id;
    spt.ace_editor.editor = $(editor_id).editor;
}

spt.ace_editor.set_editor_top = function(top_el) {
    if (!top_el.hasClass("spt_ace_editor")) {
        top_el = top_el.getElement(".spt_ace_editor");
    }

    var editor_id = top_el.getAttribute("id");
    spt.ace_editor.set_editor(editor_id);
}




spt.ace_editor.get_editor = function() {
    return spt.ace_editor.editor;

}



spt.ace_editor.clear_selection = function() {
    var editor = spt.ace_editor.editor;
    editor.clearSelection();

}



spt.ace_editor.get_selection = function() {
    var editor = spt.ace_editor.editor;
    //return editor.getSelection();
    return editor.getCopyText();
}





spt.ace_editor.get_value = function() {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    var value = document.getValue();
    return value;
}



spt.ace_editor.set_value = function(value) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    document.setValue(value);
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
}

spt.ace_editor.goto_line = function(number) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
 

}


spt.ace_editor.insert = function(value) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertInLine(position, value);
}

 
spt.ace_editor.insert_lines = function(values) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertLines(position.row, values);
}



spt.ace_editor.get_document = function() {
    var document = spt.ace_editor.editor.getSession().getDocument()
    return document;

}




spt.ace_editor.set_language = function(value) {
    if (!value) {
        value = 'javascript';
    }

    var editor = spt.ace_editor.editor;
    var top = $(spt.ace_editor.editor_id).getParent(".spt_ace_editor_top");
    var lang_el = top.getElement(".spt_language");

    for ( var i = 0; i < lang_el.options.length; i++ ) {
        if ( lang_el.options[i].value == value ) {
            lang_el.options[i].selected = true;
            break;
        }
    }



    var session = editor.getSession();
    var mode;
    if (value == 'python') {
        mode = require("ace/mode/python").Mode;
    }
    else if (value == 'xml') {
        mode = require("ace/mode/xml").Mode;
    }
    else if (value == 'expression') {
        mode = require("ace/mode/xml").Mode;
    }
    else {
        mode = require("ace/mode/javascript").Mode;
    }
    session.setMode( new mode() );
}

spt.ace_editor.drag_start_x;
spt.ace_editor.drag_start_y;
spt.ace_editor.drag_size;
spt.ace_editor.drag_editor_el;
spt.ace_editor.drag_size_el;
spt.ace_editor.drag_resize_setup = function(evt, bvr, mouse_411)
{
    var editor = spt.ace_editor.editor;
    var editor_id = spt.ace_editor.editor_id;

    spt.ace_editor.drag_start_x = mouse_411.curr_x;
    spt.ace_editor.drag_start_y = mouse_411.curr_y;

    var editor_el = $(editor_id);
    spt.ace_editor.drag_editor_el = editor_el;
    spt.ace_editor.drag_size = editor_el.getSize();

    var top = bvr.src_el.getParent(".spt_ace_editor_top");
    spt.ace_editor.drag_size_el = top.getElement(".spt_size");
}


spt.ace_editor.drag_resize_motion = function(evt, bvr, mouse_411)
{
    var diff_x = parseFloat(mouse_411.curr_x - spt.ace_editor.drag_start_x);
    var diff_y = parseFloat(mouse_411.curr_y - spt.ace_editor.drag_start_y);

    var size = spt.ace_editor.drag_size;


    var editor_el = spt.ace_editor.drag_editor_el;

    var width = size.x + diff_x
    if (width < 300) {
        width = 300;
    }
    var height = size.y + diff_y
    if (height < 200) {
        height = 200;
    }

    editor_el.setStyle("width", width);
    editor_el.setStyle("height", height);

    spt.ace_editor.drag_size_el.value = width + "," + height;

    var editor = spt.ace_editor.editor;
    editor.resize();

}
    var js_files = [
        "ace/ace-0.2.0/src/ace.js",
        //"ace/ace-0.2.0/src/ace-uncompressed.js",
    ];


   

    var ace_setup =  function() {
        var editor = ace.edit(bvr.unique_id);
        spt.ace_editor.editor = editor;

        // put the editor into the dom
        spt.ace_editor.editor_id = bvr.unique_id;
        $(bvr.unique_id).editor = editor;

        editor.setTheme("ace/theme/" + spt.ace_editor.theme);
        var JavaScriptMode = require("ace/mode/javascript").Mode;
        editor.getSession().setMode(new JavaScriptMode())
    }

    


    spt.dom.load_js(js_files, function() { 
    
        ace; require; define; 

        var core_js_files = [
        "ace/ace-0.2.0/src/mode-javascript.js",
         "ace/ace-0.2.0/src/mode-xml.js",
            "ace/ace-0.2.0/src/mode-python.js",
             "ace/ace-0.2.0/src/theme-twilight.js",
               
            "ace/ace-0.2.0/src/theme-textmate.js",
            "ace/ace-0.2.0/src/theme-vibrant_ink.js",
            "ace/ace-0.2.0/src/theme-merbivore.js",
            "ace/ace-0.2.0/src/theme-clouds.js",
            "ace/ace-0.2.0/src/theme-eclipse.js"
        ];
        //var supp_js_files = [];
           
         
        

        spt.dom.load_js(core_js_files, ace_setup);
        //spt.dom.load_js(supp_js_files);      
        });
   

    





}
else {
    var editor = ace.edit(bvr.unique_id);
    editor.setTheme("ace/theme/" +  bvr.theme);
    var JavaScriptMode = require("ace/mode/javascript").Mode;
   
    editor.getSession().setMode(new JavaScriptMode())

    spt.ace_editor.editor_id = bvr.unique_id;
    spt.ace_editor.editor = editor;
    $(bvr.unique_id).editor = editor;

}
            '''
        } )


        return top
Example #42
0
    def get_display(self):

        self.search_type = self.kwargs.get('search_type')
        self.element_name = self.kwargs.get('element_name')
        assert self.search_type
        assert self.element_name

        class_name = 'tactic.ui.app.aggregate_wdg.AggregateCmd'
        interval = 120
        priority = None

        if self.kwargs.get('is_refresh'):
            user = Environment.get_user_name()

            # these interval jobs need to have a specific code
            code = "aggregate|%s|%s" % (self.search_type, self.element_name)

            # check to see if the job exists
            #job = Search.get_by_code("sthpw/queue", code)
            job = None
            if not job:
                job = SearchType.create("sthpw/queue")
                #job.set_value("code", code)

                job.set_value("project_code", Project.get_project_code())
                job.set_value("class_name", class_name)
                job.set_value("command", class_name)
                job.set_value("serialized", str(self.kwargs))
                job.set_value("interval", 120)
                job.set_value("state", 'pending')
                job.set_value("queue", 'interval')
                job.set_value("priority", 9999)
                job.set_value("login", user)
                job.commit()

        self.view = self.kwargs.get('view')
        if not self.view:
            self.view = 'definition'

        top = DivWdg()
        self.set_as_panel(top)

        action_div = DivWdg()
        top.add(action_div)

        refresh = IconButtonWdg("Refresh", IconWdg.REFRESH)
        refresh.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_panel");
        spt.panel.refresh(top);
        '''
        })
        action_div.add(refresh)

        register_div = DivWdg()
        register_div.add_class("spt_queue_register")
        top.add(register_div)
        register_div.add_style("border: solid 1px black")
        register_div.add_style("padding: 20px")
        register_div.add("Register new interval aggregate")

        table = Table()
        table.add_style("margin: 15px")
        register_div.add(table)
        table.add_row()
        table.add_cell("command: ")
        table.add_cell(class_name)

        #table.add_row()
        #table.add_cell("priority: ")
        #table.add_cell(priority)

        table.add_row()
        table.add_cell("interval: ")
        td = table.add_cell("every ")
        td.set_attr("title", "Recalculation interval")
        text = TextWdg("interval")
        text.add_style("width: 30px")
        text.set_value(interval)
        td.add(text)

        unit_select = SelectWdg("unit")
        unit_select.set_value(interval)
        unit_select.set_option("values", "seconds|minutes|hours|days")
        td.add(" ")
        td.add(unit_select)

        table.add_row()
        table.add_cell("queue: ")
        table.add_cell("interval")

        from pyasm.widget import ProdIconButtonWdg
        button = ProdIconButtonWdg("Register")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_queue_register")
        var values = spt.api.get_input_values(top);
        var top = bvr.src_el.getParent(".spt_panel");
        spt.panel.refresh(top);
        '''
        })
        register_div.add(button)

        from pyasm.widget import ProdIconButtonWdg
        button = ProdIconButtonWdg("Cancel")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        alert('cancel');
        '''
        })
        register_div.add(button)
        '''
        cmd = AggregateCmd(**self.kwargs)

        print "registering scheduled task"
        scheduler = Scheduler.get()
        scheduler.start_thread()
        task = AggregateRefreshTask(name="cow", command=cmd)
        scheduler.add_interval_task(task, 10, mode='forked')
        scheduler.cancel_task("cow", delay=35)
        '''

        top.add("<br/>")
        top.add("<b>Current Job Queue</b>")
        top.add("<br/><br/>")
        from tactic.ui.panel import TableLayoutWdg
        table = TableLayoutWdg(search_type='sthpw/queue', view='test')
        top.add(table)

        return top
Example #43
0
    def get_display(self):
        web = WebContainer.get_web()
        key = web.get_form_value('name')

        top = DivWdg()
        top.add_class('ad_search_wdg_top')
        self.set_as_panel(top)

        text = TextWdg("name")
        text.set_value(key)

        close_wdg = SpanWdg()
        close_wdg.add(IconWdg("Close", IconWdg.POPUP_WIN_CLOSE))
        close_wdg.add_style("float: right")
        close_wdg.add_class("hand")

        # NOTE: the div we are looking for to hide on 'close' is outside of the this widget and
        #       is part of the parent widget
        close_wdg.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
                var ad_input_content = bvr.src_el.getParent(".ad_input_content");
                spt.toggle_show_hide(ad_input_content);
            '''
        })

        top.add(close_wdg)
        top.add("Active Directory Search:<br clear='all'/> ")

        table = Table()
        table.add_row()
        table.add_cell(text)
        td = table.add_cell(self.get_search_wdg())
        td.add_style("display", "")
        top.add(table)

        results_div = DivWdg()
        top.add(results_div)
        results_div.add_style("border: solid 1px #444")
        results_div.add_style("margin: 10px")
        results_div.add_style("padding: 5px")
        #results_div.add_style("max-height: 400px")
        results_div.add_style("overflow: auto")

        if not key:
            results_div.add("Please enter search criteria")
            return top

        results_div.add("Results Found ...")
        users = self.find_users(key)

        max_num_users = 20
        if len(users) > max_num_users:
            display_users = users[:max_num_users]
        else:
            display_users = users

        for user in display_users:
            user_div = DivWdg()
            user_div.add_style("margin: 5px")
            user_div.add_class("hand")
            user_div.add_event("onmouseover",
                               "$(this).setStyle('background','#444')")
            user_div.add_event("onmouseout",
                               "$(this).setStyle('background','#222')")

            checkbox = CheckboxWdg()
            user_div.add(checkbox)

            display_name = user.get('display_name')
            if not display_name:
                display_name = "%s %s" % (user.get('first_name'),
                                          user.get('last_name'))
            email = user.get('email')
            login = user.get('login')
            phone_number = user.get('phone_number')

            user_div.add(display_name)
            if email:
                user_div.add(" (%s) " % email)

            self.cbjs_action = self.kwargs.get('cbjs_action')
            if self.cbjs_action:
                user_behavior = {
                    'type': 'click_up',
                    'cbjs_action': self.cbjs_action
                }
                user_div.add_behavior(user_behavior)
            else:
                user_behavior = {
                    'type': 'click_up',
                    'cbjs_action': 'alert("Not implemented")'
                }
                user_div.add_behavior(user_behavior)

            user_div.add_attr("spt_input_value", login)
            user_div.add_attr("spt_display_value", display_name)
            user_div.add_attr("spt_phone_number", phone_number)
            user_div.add_attr("spt_email", email)

            results_div.add(user_div)

        num_users = len(users)
        if num_users > max_num_users:

            results_div.add("... and %s more results matched" %
                            (num_users - max_num_users))

            results_div.add("<br/>Please narrow your search")
            #nav_div = DivWdg()
            #num_categories = num_users / max_num_users + 1
            #if num_categories > 10:
            #    nav_div.add("<br/>Please narrow your search")
            #else:
            #    for i in range(0, num_categories):
            #        span = SpanWdg()
            #        span.add(i)
            #        span.add("&nbsp;&nbsp;")
            #        nav_div.add(span)
            #results_div.add(nav_div)

        if not users:
            user_div = DivWdg()
            user_div.add_style("margin: 5px")
            user_div.add("No Results")
            results_div.add(user_div)
        return top
Example #44
0
    def get_display(self):
        web = WebContainer.get_web()
        key = web.get_form_value('name')

        top = DivWdg()
        top.add_class('ad_search_wdg_top')
        self.set_as_panel(top)

        text = TextWdg("name")
        text.set_value(key)

        close_wdg = SpanWdg()
        close_wdg.add( IconWdg("Close", IconWdg.POPUP_WIN_CLOSE) )
        close_wdg.add_style("float: right")
        close_wdg.add_class("hand")

        # NOTE: the div we are looking for to hide on 'close' is outside of the this widget and
        #       is part of the parent widget
        close_wdg.add_behavior({
            'type': 'click_up',
            'cbjs_action': '''
                var ad_input_content = bvr.src_el.getParent(".ad_input_content");
                spt.toggle_show_hide(ad_input_content);
            '''
        })

        top.add( close_wdg )
        top.add("Active Directory Search:<br clear='all'/> ")

        table = Table()
        table.add_row()
        table.add_cell(text)
        td = table.add_cell(self.get_search_wdg())
        td.add_style("display", "")
        top.add(table)



        results_div = DivWdg()
        top.add(results_div)
        results_div.add_style("border: solid 1px #444")
        results_div.add_style("margin: 10px")
        results_div.add_style("padding: 5px")
        #results_div.add_style("max-height: 400px")
        results_div.add_style("overflow: auto")

        if not key:
            results_div.add("Please enter search criteria")
            return top


        results_div.add("Results Found ...")
        users = self.find_users(key)

        max_num_users = 20
        if len(users) > max_num_users:
            display_users = users[:max_num_users]
        else:
            display_users = users

        for user in display_users:
            user_div = DivWdg()
            user_div.add_style("margin: 5px")
            user_div.add_class("hand")
            user_div.add_event("onmouseover", "$(this).setStyle('background','#444')")
            user_div.add_event("onmouseout", "$(this).setStyle('background','#222')")

            checkbox = CheckboxWdg()
            user_div.add(checkbox)

            display_name = user.get('display_name')
            if not display_name:
                display_name = "%s %s" % (user.get('first_name'), user.get('last_name'))
            email = user.get('email')
            login = user.get('login')
            phone_number = user.get('phone_number')

            user_div.add(display_name)
            if email:
                user_div.add(" (%s) " % email)


            self.cbjs_action = self.kwargs.get('cbjs_action')
            if self.cbjs_action:
                user_behavior = {
                    'type': 'click_up',
                    'cbjs_action': self.cbjs_action
                }
                user_div.add_behavior( user_behavior )
            else:
                user_behavior = {
                    'type': 'click_up',
                    'cbjs_action': 'alert("Not implemented")'
                }
                user_div.add_behavior( user_behavior )

            user_div.add_attr("spt_input_value", login)
            user_div.add_attr("spt_display_value", display_name)
            user_div.add_attr("spt_phone_number", phone_number)
            user_div.add_attr("spt_email", email)

            results_div.add(user_div)


        num_users = len(users)
        if num_users > max_num_users:

            results_div.add("... and %s more results matched" % (num_users-max_num_users))

            results_div.add("<br/>Please narrow your search")
            #nav_div = DivWdg()
            #num_categories = num_users / max_num_users + 1
            #if num_categories > 10:
            #    nav_div.add("<br/>Please narrow your search")
            #else:
            #    for i in range(0, num_categories):
            #        span = SpanWdg()
            #        span.add(i)
            #        span.add("&nbsp;&nbsp;")
            #        nav_div.add(span)
            #results_div.add(nav_div)


        if not users:
            user_div = DivWdg()
            user_div.add_style("margin: 5px")
            user_div.add("No Results")
            results_div.add(user_div)
        return top
Example #45
0
    def get_display(my):

        my.doc_mode = my.kwargs.get("doc_mode")
        path = my.kwargs.get("path")
        my.search_type = my.kwargs.get("search_type")

        my.last_path = None

        doc_key = my.kwargs.get("doc_key")
        if doc_key:
            my.doc = Search.get_by_search_key(doc_key)
            snapshot = Snapshot.get_latest_by_sobject(my.doc)
            if snapshot:
                my.last_path = snapshot.get_lib_path_by_type('main')

            path = my.doc.get_value("link")

        # TEST TEST TEST
        if not path:
            #path = "/home/apache/pdf/mongodb.txt"
            #path = "/home/apache/assets/google_docs.html"
            #path = "/home/apache/pdf/star_wars.txt"
            path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true"

            path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub"

            #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html"
            path = "/home/apache/tactic/doc/alias.json"

        if not my.search_type:
            my.search_type = "test3/shot"

        my.column = "description"

        top = my.top
        top.add_class("spt_document_top")
        my.set_as_panel(top)

        #table = Table()
        table = ResizableTableWdg()

        top.add(table)
        table.add_row()
        table.set_max_width()

        left_td = table.add_cell()
        left_td.add_style("vertical-align: top")

        title = DivWdg()
        left_td.add(title)
        title.add_style("padding: 10px")
        title.add_color("background", "background3")

        button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH)
        title.add(button)
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.app_busy.show("Reloading Document");
            var top = bvr.src_el.getParent(".spt_document_top");
            spt.panel.refresh(top);
            spt.app_busy.hide();
            '''
        })
        button.add_style("float: left")

        button = IconButtonWdg(title="Save", icon=IconWdg.SAVE)
        title.add(button)
        button.add_behavior({
            'type': 'click_up',
            'cbjs_action': '''
            '''
        })
        button.add_style("float: left")

        if not my.doc_mode:
            my.doc_mode = "text"
        select = SelectWdg("doc_mode")
        select.set_option("values", "text|formatted")
        title.add(select)
        select.set_value(my.doc_mode)
        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
            spt.app_busy.show("Reloading Document");
            var top = bvr.src_el.getParent(".spt_document_top");
            var value = bvr.src_el.value;
            top.setAttribute("spt_doc_mode", value);
            spt.panel.refresh(top);
            spt.app_busy.hide();
            '''
        })

        title.add("<br clear='all'/>")

        #title.add(path)

        text_wdg = DivWdg()
        text_wdg.add_class("spt_document_content")
        left_td.add(text_wdg)

        #if path.startswith("https://docs.google.com/spreadsheet"):
        #    #path = "http://www.southpawtech.com.com"
        #    text_wdg.add('''
        #    <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe>
        #    ''' % path)
        #    text_wdg.add_style("overflow-x: hidden")
        if True:

            if not my.last_path and my.doc:
                tmp_dir = Environment.get_tmp_dir()
                tmp_path = '%s/last_path.txt' % tmp_dir
                f = open(tmp_path, 'w')

                text = my.get_text(path, highlight=False)

                f.write(text)
                f.close()

                cmd = FileCheckin(my.doc, tmp_path)
                Command.execute_cmd(cmd)

            else:
                save = False
                if save:
                    # open up the last path
                    f = open(my.last_path, 'r')
                    last_text = f.read()
                    text = my.get_text(path, None, highlight=False)

                    if last_text != text:

                        tmp_dir = Environment.get_tmp_dir()
                        tmp_path = '%s/last_path.txt' % tmp_dir
                        f = open(tmp_path, 'w')
                        f.write(text)
                        f.write(text)
                        f.close()

                        cmd = FileCheckin(my.doc, tmp_path)
                        Command.execute_cmd(cmd)

                text = my.get_text(path, my.last_path)

            lines = text.split("\n")

            if my.doc_mode == "text":

                num_lines = len(lines)
                """
                line_div = HtmlElement.pre()
                text_wdg.add(line_div)
                line_div.add_style("width: 20px")
                line_div.add_style("float: left")
                line_div.add_style("text-align: right")
                line_div.add_style("opacity: 0.3")
                line_div.add_style("padding-right: 10px")
                for i in range(0, num_lines*2):
                    line_div.add(i+1)
                    line_div.add("<br/>")
                """

            if my.doc_mode == "text":
                pre = HtmlElement.pre()
                pre.add_style("white-space: pre-wrap")
            else:
                pre = DivWdg()
            pre = DivWdg()
            text_wdg.add(pre)

            text_wdg.add_style("padding: 10px 5px")
            text_wdg.add_style("max-height: 600px")
            text_wdg.add_style("overflow-y: auto")
            text_wdg.add_style("width: 600px")
            text_wdg.add_class("spt_resizable")

            pre.add_style("font-family: courier")

            if my.doc_mode == "formatted":
                pre.add(text)

            else:
                line_table = Table()
                pre.add(line_table)
                line_table.add_style("width: 100%")
                count = 1
                for line in lines:
                    #line = line.replace(" ", "&nbsp;")
                    tr = line_table.add_row()
                    if count % 2 == 0:
                        tr.add_color("background", "background", -2)

                    td = line_table.add_cell()

                    # FIXME: hacky
                    if line.startswith('''<span style='background: #CFC'>'''):
                        is_new = True
                    else:
                        td.add_style("vertical-align: top")
                        text = TextWdg()
                        text.add_style("border", "none")
                        text.add_style("text-align", "right")
                        text.add_style("width", "25px")
                        text.add_style("margin", "0 10 0 0")
                        text.add_style("opacity", "0.5")
                        text.set_value(count)
                        td.add(text)
                        count += 1
                        is_new = False

                    td = line_table.add_cell()
                    if not is_new:
                        SmartMenu.assign_as_local_activator(td, 'TEXT_CTX')
                        tr.add_class("spt_line")
                    else:
                        SmartMenu.assign_as_local_activator(td, 'TEXT_NEW_CTX')
                        tr.add_class("spt_new_line")

                    td.add_class("spt_line_content")
                    td.add(line)

            #from tactic.ui.app import AceEditorWdg
            #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px")
            #text_wdg.add(editor)

        # add a click on spt_item
        text_wdg.add_relay_behavior({
            'type':
            'mouseup',
            'bvr_match_class':
            'spt_document_item',
            'search_type':
            my.search_type,
            'cbjs_action':
            '''

            var top = bvr.src_el.getParent(".spt_document_top");
            var data_el = top.getElement(".spt_document_data");

            var search_key = bvr.src_el.getAttribute("spt_search_key");

            var class_name = 'tactic.ui.panel.ViewPanelWdg';
            var kwargs = {
                'search_type': bvr.search_type,
                'search_key': search_key,
            }
            spt.panel.load(data_el, class_name, kwargs);
            '''
        })

        # add a double click on spt_item
        bgcolor = text_wdg.get_color("background", -10)
        text_wdg.add_relay_behavior({
            'type':
            'mouseover',
            'bvr_match_class':
            'spt_document_item',
            'search_type':
            my.search_type,
            'bgcolor':
            bgcolor,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("opacity", "1.0");
            //bvr.src_el.setStyle("font-weight", "normal");
            bvr.src_el.setStyle("background", bvr.bgcolor);
            '''
        })

        # add a double click on spt_item
        text_wdg.add_relay_behavior({
            'type':
            'mouseout',
            'bvr_match_class':
            'spt_document_item',
            'search_type':
            my.search_type,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("opacity", "1.0");
            //bvr.src_el.setStyle("font-weight", "bold");
            bvr.src_el.setStyle("background", "");
            '''
        })

        # add a context menu
        ctx_menu = my.get_text_context_menu()
        ctx_new_menu = my.get_text_new_context_menu()
        menus_in = {
            'TEXT_CTX': ctx_menu,
            'TEXT_NEW_CTX': ctx_new_menu,
        }
        SmartMenu.attach_smart_context_menu(text_wdg, menus_in, False)

        panel = ViewPanelWdg(search_type=my.search_type, layout="blah")

        right_td = table.add_cell()
        right_td.add_style("vertical-align: top")

        panel_div = DivWdg()
        panel_div.add_class("spt_document_data")
        right_td.add(panel_div)
        panel_div.add(panel)

        text_wdg.add_behavior({
            'type':
            'load',
            'cbjs_action':
            r'''

spt.document = {};

spt.document.selected_text = null;

spt.document.get_selected_text = function(frame)
{

    var t = '';

    if (frame) {
        var rng = frame.contentWindow.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }

    else if (window.getSelection) // FF4 with one tab open?
    {
        var rng = window.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }
    else if (document.getSelection) // FF4 with multiple tabs open?
    {
        var rng = document.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }
    else if (document.selection) // IE8
    {
        var rng = document.selection.createRange();
        // expand range to enclose any word partially enclosed in it
        rng.expand("word");
        t = rng.text;
    }

    // convert newline chars to spaces, collapse whitespace, and trim non-word chars
    return t.replace(/^\W+|\W+$/g, '');
    //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, '');
}

// expand FF range to enclose any word partially enclosed in it
spt.document.expandtoword = function(range)
{
    if (range.collapsed) {
        return;
    }

    while (range.startOffset > 0 && range.toString()[0].match(/\w/)) {
        range.setStart(range.startContainer, range.startOffset - 1);
    }

    while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/))
    {
        range.setEnd(range.endContainer, range.endOffset + 1);
    }
}
            '''
        })

        top.add_relay_behavior({
            'type':
            'mouseup',
            'bvr_match_class':
            'spt_document_content',
            'cbjs_action':
            r'''
            //spt.ace_editor.set_editor_top(bvr.src_el);
            //var text = spt.ace_editor.get_selection();
            var text = spt.document.get_selected_text();
            text = text.replace(/\n\n/mg, "\n");
            text = text.replace(/\n\n/mg, "\n");
            spt.document.selected_text = text + "";
            '''
        })

        return top
Example #46
0
    def get_display(my):
        web = WebContainer.get_web()

        top = my.top
        top.add_class("spt_ace_editor_top")

        script = my.kwargs.get("custom_script")
        if script:
            language = script.get_value("language")
        else:
            language = my.kwargs.get("language")
            if not language:
                language = 'javascript'

        code = my.kwargs.get("code")
        if not code:
            code = ""


        show_options = my.kwargs.get("show_options")
        if show_options in ['false', False]:
            show_options = False
        else:
            show_options = True

        options_div = DivWdg()
        top.add(options_div)
        if not show_options:
            options_div.add_style("display: none")
        options_div.add_color("background", "background3")
        options_div.add_border()
        options_div.add_style("text-align: center")
        options_div.add_style("padding: 2px")



        select = SelectWdg("language")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.add_class("spt_language")
        select.set_option("values", "javascript|python|expression|xml")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var value = bvr.src_el.value;
            spt.ace_editor.set_language(value);

            //register_change(bvr);

            '''
        } )
 
        select = SelectWdg("font_size")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "8 pt|9 pt|10 pt|11 pt|12 pt|14 pt|16 pt")
        select.set_option("values", "8 pt|9pt|10pt|11pt|12pt|14pt|16pt")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'click_up',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var value = bvr.src_el.value;
            $(editor_id).setStyle("font-size", value)
            //editor.resize();
            '''
        } )



        select = SelectWdg("keybinding")
        select.add_style("width: 100px")
        #options_div.add(select)
        select.set_option("labels", "Ace|Vim|Emacs")
        select.set_option("values", "ace|vim|emacs")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var vim = require("ace/keyboard/keybinding/vim").Vim;
            editor.setKeyboardHandler(vim)
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)


        if code:
            load_div = DivWdg()
            top.add(load_div)
            readonly = my.kwargs.get("readonly")
            if readonly in ['true', True]:
                readonly = True
            else:
                readonly = False

            load_div.add_behavior( {
                'type': 'load',
                'code': code,
                'language': language,
                'editor_id': my.get_editor_id(),
                'readonly': readonly,
                'cbjs_action': '''
                spt.ace_editor.set_editor(bvr.editor_id);
                var func = function() {
                    var editor = spt.ace_editor.editor;
                    var document = editor.getSession().getDocument();
                    if (bvr.code) {
                        spt.ace_editor.set_value(bvr.code);
                    }
                    spt.ace_editor.set_language(bvr.language);
                    editor.setReadOnly(bvr.readonly);


                    var session = editor.getSession();
                    //session.setUseWrapMode(true);
                    //session.setWrapLimitRange(120, 120);
                };

                var editor = spt.ace_editor.editor;
                if (!editor) {
                    setTimeout( func, 1000);
                }
                else {
                    func();
                }

                '''
            } )




        # theme
        select = SelectWdg("theme")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "Eclipse|Twilight|TextMate|Vibrant Ink|Merbivore|Clouds")
        select.set_option("values", "eclipse|twilight|textmate|vibrant_ink|merbivore|clouds")
        select.set_value("twilight")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;
            value = bvr.src_el.value;

            editor.setTheme("ace/theme/" + value);
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)




        my.text_area.add_style("margin-top: -1px")
        my.text_area.add_style("margin-bottom: 0px")
        my.text_area.add_color("background", "background")
        my.text_area.add_style("font-family: courier new")
        my.text_area.add_border()
        editor_div.add(my.text_area)
        my.text_area.add_style("position: relative")
        #text_area.add_style("margin: 20px")


        size = web.get_form_value("size")
        if size:
            width, height = size.split(",")
        else:
            width = my.kwargs.get("width")
            if not width:
                width = "650px"
            height = my.kwargs.get("height")
            if not height:
                height = "450px"
        my.text_area.add_style("width: %s" % width)
        my.text_area.add_style("height: %s" % height)



        bottom_div = DivWdg()
        top.add(bottom_div)
        bottom_div.add_color("background", "background3")
        bottom_div.add_border()
        bottom_div.add_style("text-align: center")
        bottom_div.add_style("padding: 2px")
        bottom_div.add_style("height: 20px")

        bottom_title = "Script Editor"
        bottom_div.add(bottom_title)

        icon = IconWdg("Resize Editor", IconWdg.RESIZE_CORNER)
        bottom_div.add(icon)
        icon.add_style("float: right")
        icon.add_style("margin-right: -4px")
        icon.add_style("cursor: se-resize")
        icon.add_behavior( {
            'type': 'drag',
            "cb_set_prefix": 'spt.ace_editor.drag_resize',
        } )


        #hidden = HiddenWdg("size")
        hidden = TextWdg("size")
        bottom_div.add(hidden)
        hidden.add_style("width: 85px")
        hidden.add_style("text-align: center")
        hidden.add_style("float: right")
        hidden.add_class("spt_size")
        hidden.set_value("%s,%s" % (width, height))

        theme = top.get_theme()
        if theme == 'dark':
            theme = 'twilight'
        else:
            theme = 'eclipse'

        print "theme: ", theme

        top.add_behavior( {
            'type': 'load',
            'unique_id': my.unique_id,
            'theme': theme,
            'cbjs_action': '''

if (typeof(ace) == 'undefined') {

// fist time loading
spt.ace_editor = {}
spt.ace_editor.editor = null;
spt.ace_editor.editor_id = bvr.unique_id;
spt.ace_editor.theme = bvr.theme;


spt.ace_editor.set_editor = function(editor_id) {
    spt.ace_editor.editor_id = editor_id;
    spt.ace_editor.editor = $(editor_id).editor;
}

spt.ace_editor.set_editor_top = function(top_el) {
    if (!top_el.hasClass("spt_ace_editor")) {
        top_el = top_el.getElement(".spt_ace_editor");
    }

    var editor_id = top_el.getAttribute("id");
    spt.ace_editor.set_editor(editor_id);
}




spt.ace_editor.get_editor = function() {
    return spt.ace_editor.editor;

}



spt.ace_editor.clear_selection = function() {
    var editor = spt.ace_editor.editor;
    editor.clearSelection();

}



spt.ace_editor.get_selection = function() {
    var editor = spt.ace_editor.editor;
    //return editor.getSelection();
    return editor.getCopyText();
}





spt.ace_editor.get_value = function() {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    var value = document.getValue();
    return value;
}



spt.ace_editor.set_value = function(value) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    document.setValue(value);
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
}

spt.ace_editor.goto_line = function(number) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
 

}


spt.ace_editor.insert = function(value) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertInLine(position, value);
}

 
spt.ace_editor.insert_lines = function(values) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertLines(position.row, values);
}



spt.ace_editor.get_document = function() {
    var document = spt.ace_editor.editor.getSession().getDocument()
    return document;

}




spt.ace_editor.set_language = function(value) {
    if (!value) {
        value = 'javascript';
    }

    var editor = spt.ace_editor.editor;
    var top = $(spt.ace_editor.editor_id).getParent(".spt_ace_editor_top");
    var lang_el = top.getElement(".spt_language");

    for ( var i = 0; i < lang_el.options.length; i++ ) {
        if ( lang_el.options[i].value == value ) {
            lang_el.options[i].selected = true;
            break;
        }
    }



    var session = editor.getSession();
    var mode;
    if (value == 'python') {
        mode = require("ace/mode/python").Mode;
    }
    else if (value == 'xml') {
        mode = require("ace/mode/xml").Mode;
    }
    else if (value == 'expression') {
        mode = require("ace/mode/xml").Mode;
    }
    else {
        mode = require("ace/mode/javascript").Mode;
    }
    session.setMode( new mode() );
}

spt.ace_editor.drag_start_x;
spt.ace_editor.drag_start_y;
spt.ace_editor.drag_size;
spt.ace_editor.drag_editor_el;
spt.ace_editor.drag_size_el;
spt.ace_editor.drag_resize_setup = function(evt, bvr, mouse_411)
{
    var editor = spt.ace_editor.editor;
    var editor_id = spt.ace_editor.editor_id;

    spt.ace_editor.drag_start_x = mouse_411.curr_x;
    spt.ace_editor.drag_start_y = mouse_411.curr_y;

    var editor_el = $(editor_id);
    spt.ace_editor.drag_editor_el = editor_el;
    spt.ace_editor.drag_size = editor_el.getSize();

    var top = bvr.src_el.getParent(".spt_ace_editor_top");
    spt.ace_editor.drag_size_el = top.getElement(".spt_size");
}


spt.ace_editor.drag_resize_motion = function(evt, bvr, mouse_411)
{
    var diff_x = parseFloat(mouse_411.curr_x - spt.ace_editor.drag_start_x);
    var diff_y = parseFloat(mouse_411.curr_y - spt.ace_editor.drag_start_y);

    var size = spt.ace_editor.drag_size;


    var editor_el = spt.ace_editor.drag_editor_el;

    var width = size.x + diff_x
    if (width < 300) {
        width = 300;
    }
    var height = size.y + diff_y
    if (height < 200) {
        height = 200;
    }

    editor_el.setStyle("width", width);
    editor_el.setStyle("height", height);

    spt.ace_editor.drag_size_el.value = width + "," + height;

    var editor = spt.ace_editor.editor;
    editor.resize();

}
    var js_files = [
        "ace/ace-0.2.0/src/ace.js",
        //"ace/ace-0.2.0/src/ace-uncompressed.js",
    ];


   

    var ace_setup =  function() {
        var editor = ace.edit(bvr.unique_id);
        spt.ace_editor.editor = editor;

        // put the editor into the dom
        spt.ace_editor.editor_id = bvr.unique_id;
        $(bvr.unique_id).editor = editor;

        editor.setTheme("ace/theme/" + spt.ace_editor.theme);
        var JavaScriptMode = require("ace/mode/javascript").Mode;
        editor.getSession().setMode(new JavaScriptMode())
    }

    


    spt.dom.load_js(js_files, function() { 
    
        ace; require; define; 

        var core_js_files = [
        "ace/ace-0.2.0/src/mode-javascript.js",
         "ace/ace-0.2.0/src/mode-xml.js",
            "ace/ace-0.2.0/src/mode-python.js",
             "ace/ace-0.2.0/src/theme-twilight.js",
               
            "ace/ace-0.2.0/src/theme-textmate.js",
            "ace/ace-0.2.0/src/theme-vibrant_ink.js",
            "ace/ace-0.2.0/src/theme-merbivore.js",
            "ace/ace-0.2.0/src/theme-clouds.js",
            "ace/ace-0.2.0/src/theme-eclipse.js"
        ];
        //var supp_js_files = [];
           
         
        

        spt.dom.load_js(core_js_files, ace_setup);
        //spt.dom.load_js(supp_js_files);      
        });
   

    





}
else {
    var editor = ace.edit(bvr.unique_id);
    editor.setTheme("ace/theme/" +  bvr.theme);
    var JavaScriptMode = require("ace/mode/javascript").Mode;
   
    editor.getSession().setMode(new JavaScriptMode())

    spt.ace_editor.editor_id = bvr.unique_id;
    spt.ace_editor.editor = editor;
    $(bvr.unique_id).editor = editor;

}
            '''
        } )


        return top
Example #47
0
    def get_display(my):

        my.search_type = my.kwargs.get('search_type')
        my.element_name = my.kwargs.get('element_name')
        assert my.search_type
        assert my.element_name

        class_name = 'tactic.ui.app.aggregate_wdg.AggregateCmd'
        interval = 120
        priority = None

        if my.kwargs.get('is_refresh'):
            user = Environment.get_user_name()

            # these interval jobs need to have a specific code
            code = "aggregate|%s|%s" % (my.search_type, my.element_name)

            # check to see if the job exists
            #job = Search.get_by_code("sthpw/queue", code)
            job = None
            if not job:
                job = SearchType.create("sthpw/queue")
                #job.set_value("code", code)

                job.set_value("project_code", Project.get_project_code() )
                job.set_value("class_name", class_name)
                job.set_value("command", class_name)
                job.set_value("serialized", str(my.kwargs) )
                job.set_value("interval", 120)
                job.set_value("state", 'pending')
                job.set_value("queue", 'interval')
                job.set_value("priority", 9999)
                job.set_value("login", user) 
                job.commit()




        my.view = my.kwargs.get('view')
        if not my.view:
            my.view = 'definition'

        
        top = DivWdg()
        my.set_as_panel(top)

        action_div = DivWdg()
        top.add(action_div)

        refresh = IconButtonWdg("Refresh", IconWdg.REFRESH)
        refresh.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_panel");
        spt.panel.refresh(top);
        '''
        } )
        action_div.add(refresh)



        register_div = DivWdg()
        register_div.add_class("spt_queue_register")
        top.add(register_div)
        register_div.add_style("border: solid 1px black")
        register_div.add_style("padding: 20px")
        register_div.add("Register new interval aggregate")

        table = Table()
        table.add_style("margin: 15px")
        register_div.add(table)
        table.add_row()
        table.add_cell("command: ")
        table.add_cell(class_name)

        #table.add_row()
        #table.add_cell("priority: ")
        #table.add_cell(priority)

        table.add_row()
        table.add_cell("interval: ")
        td = table.add_cell("every ")
        td.set_attr("title", "Recalculation interval")
        text = TextWdg("interval")
        text.add_style("width: 30px")
        text.set_value(interval)
        td.add(text)

        unit_select = SelectWdg("unit")
        unit_select.set_value(interval)
        unit_select.set_option("values", "seconds|minutes|hours|days")
        td.add(" ")
        td.add(unit_select)

        table.add_row()
        table.add_cell("queue: ")
        table.add_cell("interval")


        from pyasm.widget import ProdIconButtonWdg
        button = ProdIconButtonWdg("Register")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_queue_register")
        var values = spt.api.get_input_values(top);
        var top = bvr.src_el.getParent(".spt_panel");
        spt.panel.refresh(top);
        '''
        } )
        register_div.add(button)


        from pyasm.widget import ProdIconButtonWdg
        button = ProdIconButtonWdg("Cancel")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        alert('cancel');
        '''
        } )
        register_div.add(button)


        '''
        cmd = AggregateCmd(**my.kwargs)

        print "registering scheduled task"
        scheduler = Scheduler.get()
        scheduler.start_thread()
        task = AggregateRefreshTask(name="cow", command=cmd)
        scheduler.add_interval_task(task, 10, mode='forked')
        scheduler.cancel_task("cow", delay=35)
        '''


        top.add("<br/>")
        top.add("<b>Current Job Queue</b>")
        top.add("<br/><br/>")
        from tactic.ui.panel import TableLayoutWdg
        table = TableLayoutWdg(search_type='sthpw/queue',view='test')
        top.add(table)

        return top
Example #48
0
    def get_display(my):
        sobject = my.get_current_sobject()

        # handle the start and end
        frame_start = sobject.get_value("tc_frame_start")
        frame_end = sobject.get_value("tc_frame_end")

        frame_start_text = TextWdg("tc_frame_start")
        frame_start_text.set_value(frame_start)
        frame_start_text.set_option("size", "2")

        frame_end_text = TextWdg("tc_frame_end")
        frame_end_text.set_value(frame_end)
        frame_end_text.set_option("size", "2")

        # handle the notes
        frame_notes = sobject.get_value("frame_note")
        frame_notes_text = TextAreaWdg("frame_note")
        frame_notes_text.set_value(frame_notes)
        frame_notes_text.set_option("rows", "1")

        # handle the in and out handles
        frame_in = sobject.get_value("frame_in")
        frame_out = sobject.get_value("frame_out")

        frame_in_text = TextWdg("frame_in")
        frame_in_text.set_value(frame_in)
        frame_in_text.set_option("size", "2")

        frame_out_text = TextWdg("frame_out")
        frame_out_text.set_value(frame_out)
        frame_out_text.set_option("size", "2")

        div = DivWdg()

        table = Table()
        div.add(table)
        table.add_row()
        td = table.add_cell("Range:")
        td.add_style("width: 100px")
        td = table.add_cell()
        td.add("start: ")
        td.add(frame_start_text)
        td.add(" - end: ")
        td.add(frame_end_text)

        table.add_row()
        table.add_cell("Handles:")
        td = table.add_cell()
        td.add("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in: ")
        td.add(frame_in_text)
        td.add(" - out: ")
        td.add(frame_out_text)
        td.add("<br/>")

        table.add_row()
        table.add_cell("Notes:")
        td = table.add_cell(frame_notes_text)
        """
        div.add("Range - start: ")
        div.add(frame_start_text)
        div.add(" - end: ")
        div.add(frame_end_text)
        div.add("<br/>")
        div.add("Handles - in: ")
        div.add(frame_in_text)
        div.add(" - out: ")
        div.add(frame_out_text)
        div.add("<br/>")
        div.add("Notes:")
        div.add(frame_notes_text)
        """

        return div
    def get_new_definition_wdg(my):
        detail_wdg = DivWdg()
        detail_wdg.add_style("color: black")
        detail_wdg.add_style("width: 350px")
        detail_wdg.add_style("margin-top: 10px")
        detail_wdg.add_style("padding: 10px")
        detail_wdg.add_border()
        title = DivWdg()
        title.add_style("color: black")
        title.add("Column Definition")
        title.add_style("margin-top: -22px")
        detail_wdg.add(title)

        # add a name entry
        title = SpanWdg()
        detail_wdg.add("Name: ")
        detail_wdg.add(title)
        input = SpanWdg()
        input.add_style('padding-top: 6px')
        input.set_id("config_element_name")
        text = TextWdg('column_name')
        text.set_value(my.name_string)
        input.add(text)
        detail_wdg.add(input)
        hidden = HiddenWdg('target_search_type', my.search_type)
        detail_wdg.add(hidden)

        detail_wdg.add(HtmlElement.br(2))

        # add data_type entry
        data_type = SpanWdg()
        default_data_types = [
            'varchar(256)', 'varchar', 'character', 'text', 'integer', 'float',
            'boolean', 'timestamp', 'Other...'
        ]
        select = SelectWdg('config_data_type', label='Data Type: ')
        #detail_wdg.add(": ")
        select.set_option('values', default_data_types)
        select.set_value(my.data_type_string)

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            "if (bvr.src_el.value=='Other...') {spt.show('config_data_type_custom');}\
                    else {spt.hide('config_data_type_custom');}"
        })
        data_type.add(select)

        text = TextWdg('config_data_type_custom')
        span = SpanWdg("Other: ", css='med')
        span.add(text)
        span.set_id('config_data_type_custom')
        span.add_style('display', 'none')
        text.set_value(my.data_type_string)

        data_type.add("<br/>")
        data_type.add(span)
        detail_wdg.add(data_type)

        detail_wdg.add("<br/>")
        # add a nullable entry
        nullable = DivWdg()
        checkbox = CheckboxWdg('config_nullable',
                               label='Allow null(empty) value: ')
        nullable.add(checkbox)

        if my.nullable_string in ['True', 'true']:
            checkbox.set_checked()

        detail_wdg.add(nullable)

        return detail_wdg
Example #50
0
    def get_tables_wdg(self):

        div = DivWdg()
        div.set_name("Tables")

        div.add(
            "In order to fully register a database, you must bind it to a TACTIC project"
        )
        div.add("<br/>")

        project_code = "mongodb"
        database = "test_database"

        db_resource = DbResource(server='localhost',
                                 vendor='MongoDb',
                                 database=database)

        try:
            connect = DbContainer.get(db_resource)
        except Exception as e:
            div.add("Could not connect")
            div.add_style("padding: 30px")
            div.add("<br/>" * 2)
            div.add(str(e))
            return div

        # Bind project to this resource
        database_text = TextWdg("database")
        div.add("Database: ")
        div.add(database_text)

        div.add("<br/>" * 2)

        project_text = TextWdg("project")
        div.add("Project Code: ")
        div.add(project_text)

        div.add("<br/>")
        div.add("<hr/>")

        # connect and introspect the tables in this database
        tables = connect.get_tables()

        table = Table()
        div.add(table)
        table.set_max_width()

        for table_name in tables:
            table.add_row()
            search_type = "table/%s?project=%s" % (table_name, project_code)

            td = table.add_cell()
            icon = IconWdg("View Table", IconWdg.FOLDER_GO)
            td.add(icon)
            icon.add_behavior({
                'type':
                'click_up',
                'search_type':
                search_type,
                'cbjs_action':
                '''
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type
                }
                spt.panel.load_popup("table", class_name, kwargs);
                '''
            })

            td = table.add_cell()
            td.add(table_name)

            td = table.add_cell()
            search = Search(search_type)
            count = search.get_count()
            td.add(" %s item/s" % count)

            columns = search.get_columns()
            td = table.add_cell()
            td.add(columns)

            # search_type
            td = table.add_cell()
            text = TextWdg("search_type")
            td.add(text)
            new_search_type = "%s/%s" % (project_code, table_name)
            text.set_value(new_search_type)

        register_div = DivWdg()
        div.add(register_div)
        register_div.add_style("padding: 20px")

        button = ActionButtonWdg(title="Register")
        register_div.add(button)

        return div
    def get_display(my):

        top_wdg = DivWdg()
        top_wdg.add_style("color: black")
        top_wdg.add_style("width: 350px")
        top_wdg.add_style("margin-top: 10px")
        top_wdg.add_style("padding: 10px")
        top_wdg.add_border()
        title = DivWdg()
        title.add_style("color: black")
        title.add_style("margin-top: -22px")

        top_wdg.add(title)
        #if not my.name_string:
        #    title.add('No database column')
        #    return top_wdg

        title.add("Widget Definition")

        widget_types = {
            'foreign_key': 'tactic.ui.table.ForeignKeyElementWdg',
            'button': 'tactic.ui.table.ButtonElementWdg',
            'expression': 'tactic.ui.table.ExpressionElementWdg'
        }

        web = WebContainer.get_web()
        config_string = web.get_form_value("config_xml")
        if not config_string:
            config_string = '<config/>'
        xml = Xml()
        xml.read_string(config_string)

        #print "config_string: ", config_string

        # get values from the config file
        element_name = xml.get_value('element/@name')

        config = WidgetConfig.get(
            view='element',
            xml='<config><element>%s</element></config>' % config_string)
        display_options = config.get_display_options(element_name)

        title = xml.get_value('element/@title')
        display_handler = xml.get_value('element/display/@class')
        if not display_handler:
            display_handler = 'tactic.ui.panel.TypeTableElementWdg'

        widget_name = xml.get_value('element/display/@widget')
        if not widget_name:
            widget_name = 'custom'

        custom_table = Table()
        custom_table.add_style("color: black")
        top_wdg.add(custom_table)

        name_text = DivWdg()
        name_text.add_style("color: black")
        name_text.add(element_name)
        custom_table.add_row()
        custom_table.add_cell("Name: ")
        custom_table.add_cell(name_text)

        # add title
        custom_table.add_row()
        title_wdg = TextWdg("custom_title")
        title_wdg.set_value(title)
        title_wdg.add_attr("size", "50")
        custom_table.add_cell("Title: ")
        custom_table.add_cell(title_wdg)

        # add description
        #custom_table.add_row()
        #description_wdg = TextAreaWdg("custom_description")
        #td = custom_table.add_cell( "Description: " )
        #td.add_style("vertical-align: top")
        #custom_table.add_cell( description_wdg )

        type_select = SelectWdg("custom_type")
        #type_select.add_empty_option("-- Select --")

        type_select.set_option(
            "values",
            "string|integer|float|boolean|currency|date|foreign_key|link|list|button|custom"
        )
        type_select.set_option(
            "labels",
            "String(db)|Integer(db)|Float(db)|Boolean(db)|Currency(db)|Date(db)|Foreign Key|Link|List|Button|Custom"
        )
        type_select.set_value(widget_name)

        #type_select.set_option("values", "string|integer|float|boolean|currency|date|link|list|foreign_key|button|empty")
        #type_select.set_option("labels", "String|Integer|Float|Boolean|Currency|Date|Link|List|Foreign Key|Button|Empty")
        custom_table.add_row()
        td = custom_table.add_cell("Widget Type: ")
        td.add_style("vertical-align: top")
        td = custom_table.add_cell(type_select)
        type_select.add_event(
            "onchange", "spt.CustomProject.property_type_select_cbk(this)")

        td.add(HtmlElement.br())
        display_handler_text = TextWdg("display_handler")
        display_handler_text.add_attr("size", "50")
        display_handler_text.set_value(display_handler)
        td.add(display_handler_text)

        # extra info for foreign key
        custom_table.add_row()
        div = DivWdg()
        div.add_class("foreign_key_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())

        # extra info for foreign key
        custom_table.add_row()
        div = DivWdg()
        div.add_class("foreign_key_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Relate to: ")
        search_type_select = SearchTypeSelectWdg(
            "foreign_key_search_select",
            mode=SearchTypeSelectWdg.CURRENT_PROJECT)
        div.add(search_type_select)
        td.add(div)

        # extra info for list
        custom_table.add_row()
        div = DivWdg()
        div.add_class("list_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")
        div.add("Options")
        div.add(HtmlElement.br())
        # TODO: this class should not be in prod!!
        from pyasm.prod.web import SearchTypeSelectWdg
        div.add("Values: ")
        search_type_text = TextWdg("list_values")
        div.add(search_type_text)
        td.add(div)

        # extra info for button
        custom_table.add_row()
        div = DivWdg()
        div.add_style("color: black")
        div.add_class("button_options")
        div.add_style("display: none")
        div.add_style("margin-top: 10px")

        #class_path = "tactic.ui.table.ButtonElementWdg"
        class_path = display_handler
        button = Common.create_from_class_path(class_path)
        args_keys = button.get_args_keys()

        div.add("Options")
        div.add(HtmlElement.br())

        for key in args_keys.keys():
            option_name_text = HiddenWdg("option_name")
            option_name_text.set_value(key)
            div.add(option_name_text)

            div.add("%s: " % key)
            div.add(" &nbsp; &nbsp;")

            input = button.get_input_by_arg_key(key)

            value = display_options.get(key)
            if value:
                input.set_value(value)

            div.add(input)
            div.add(HtmlElement.br())
        td.add(div)

        # is searchable checkbox
        #custom_table.add_row()
        #current_searchable_wdg = CheckboxWdg("is_searchable")
        #current_view_wdg.set_checked()
        #custom_table.add_cell("Searchable? ")
        #td = custom_table.add_cell(current_searchable_wdg)

        custom_table.close_tbody()

        return top_wdg
Example #52
0
    def get_bottom_wdg(my, search_keys=[]):
        # check if the user has enabled it
        info = my.check_bottom_wdg()

        if info.get('check') == False:
            return None

        if info.get('mode') != 'total':
            top = DivWdg()
            top.add("Only [total] is supported. Please change it in Edit Column Definition")
            return top

        my.today = datetime.date.today()

        if my.is_refresh:
            top = Widget()
        else:
            top = DivWdg()
           
        days = []
        for date in my.dates:
            days.append( date.strftime("%Y_%m_%d") )

        today = my.today.strftime("%Y_%m_%d")

        table = Table()
        top.add(table)

        row_list = [my.ST_ROW]
        if my.show_overtime:
            row_list.append( my.OT_ROW)
            
        for row_to_draw in row_list:

            table.add_row()
            table.add_color("color", "color")
            table.add_styles("width: %spx; float: left"%my.table_width)

            td = table.add_blank_cell()
            td.add_style("min-width: %spx" % (my.MONTH_WIDTH + my.LEFT_WIDTH+8))
            time_prefix = ''
            if row_to_draw == my.OT_ROW:
                time_prefix = 'ot'
                div = DivWdg()
                div.add("OT")
               
                div.add_styles('text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)
            elif row_to_draw == my.STT_ROW:
                time_prefix = 'stt'
                div = DivWdg()
                div.add("ST")
               
                div.add_styles('text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)
            elif row_to_draw == my.ENT_ROW:
                time_prefix = 'ent'
                div = DivWdg()
                div.add("ET")
               
                div.add_styles('text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)


            for idx, day in enumerate(days):
                day_wdg = DivWdg()
                day_wdg.add(day)
                
                td = table.add_cell()
                td.add_style("width: %spx" % my.day_width)
                # keep it as text input for consistent alignment
                text = TextWdg("%sday_%s" % (time_prefix, day) )

                if row_to_draw == my.OT_ROW:
                    sobj_daily_dict = my.summary_ot[idx]
                else:
                    sobj_daily_dict = my.summary_st[idx]

                if search_keys:
                    sobj_daily_sub_dict = Common.subset_dict(sobj_daily_dict, search_keys)
                else:
                    sobj_daily_sub_dict = sobj_daily_dict

                daily_total = 0
                for value in sobj_daily_sub_dict.values():
                    if value:
                        daily_total += value

                text.set_value(daily_total)
                td.add(text)

                text.add_class("spt_day%s" % (time_prefix))
                text.add_style("width: %spx"%(my.day_width-2))
                #text.add_style("width: 100%")
                text.add_style("text-align: right")
                text.add_style("padding-left: 2px")
                text.add_style('font-weight: 500')
                text.set_attr("readonly", "readonly")
                # grey out the text color
                text.add_color('color', 'color', +40)

                if day == today:
                    text.add_style("border: solid 1px black")
                elif idx in [0,6]:
                    if row_to_draw == my.OT_ROW:
                        # FOOTER: Overtime, weekends
                        text.add_color("background", "background2", modifier=[-15,0,5])
                    else:
                        # FOOTER: Straight time, weekends
                        text.add_color("background", "background2", modifier=[0,15,20])


            text = TextWdg("total")
            daily_total = 0
            if row_to_draw == my.OT_ROW:
                sobj_daily_dict = my.summary_ot[7]
            else:
                sobj_daily_dict = my.summary_st[7]

            if search_keys:
                sobj_daily_sub_dict = Common.subset_dict(sobj_daily_dict, search_keys)
            else:
                sobj_daily_sub_dict = sobj_daily_dict
            for value in sobj_daily_sub_dict.values():
                if value:
                    daily_total += value
            text.set_value(daily_total)

            td = table.add_cell(text)
            text.add_class("spt_total%s" % (time_prefix))
            # does not look good in FF
            #td.add_style("border-width: 0 0 0 1")
            #td.add_style("border-style: solid")
            td.add_style("width: %spx"%my.day_width)
            text.add_styles("font-weight: 500;width: %spx; text-align: right; padding-left: 2px"%(my.day_width))
            
            text.set_attr("readonly", "readonly")
            text.add_color('color', 'color', +40)

            if row_to_draw == my.OT_ROW:
                # FOOTER: Overtime, total.
                text.add_color("background", "background2", modifier=[5,-15,0])
            else:
                # FOOTER: Straight time, total
                text.add_color("background", "background2", modifier=[20,0,15])

            td = table.add_blank_cell()
            td.add_style('width','100%')

        return top
Example #53
0
    def get_display(self):
        top = DivWdg()
        top.add_class("ad_input_top")

        name = self.get_name()
        text = TextWdg(self.get_input_name())


        # get the login
        sobject = self.get_current_sobject()
        client = sobject.get_value("contact_name")
        print "client: ", client
        if client:
            login_sobj = Login.get_by_code(client)
        else:
            login_sobj = Environment.get_login()

        # build the display_name
        login = login_sobj.get_value("login")
        display_name = login_sobj.get_value("display_name")
        if not display_name:
            display_name = "%s %s" % (user.get('first_name'), user.get('last_name'))
        display_name = display_name.replace('"', "'")


        
        print "login: "******"spt_ad_input")
        if login:
            hidden.set_value(login)
        top.add(hidden)


        # copy over some options
        #text.set_options( self.options.copy() )
        if login:
            text.set_value(display_name)
        text.set_option("read_only", "true")
        text.add_class("spt_ad_display")
        top.add(text)



        top.add("&nbsp;&nbsp;")



        groups_str = self.get_option("groups_allowed_to_search")
        if groups_str:
            stmt = 'groups_list = %s' % groups_str
            exec stmt
        else:
            groups_list = None

        allow_search = True

        if groups_list:
            allow_search = False
            login_in_group_list = Search.eval("@SOBJECT(sthpw/login_in_group['login','=','%s'])" % login)
            for login_in_group in login_in_group_list:
                group = login_in_group.get_value("login_group")
                if group in groups_list:
                    allow_search = True
                    break

        if login == 'admin':
            allow_search = True


        if allow_search:
            button = IconButtonWdg('Search for User', IconWdg.USER)
            #button = ButtonWdg()
            button.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                var top = bvr.src_el.getParent('.ad_input_top');
                var content = top.getElement('.ad_input_content');
                spt.toggle_show_hide(content);
                '''
            } )
            top.add(button)

        ad_top = DivWdg()
        ad_top.add_class("ad_input_content")
        ad_top.add_style("display: none")
        ad_top.add_style("position: absolute")
        ad_top.add_style("background: #222")
        ad_top.add_style("min-width: 300px")
        ad_top.add_style("border: solid 1px #000")
        ad_top.add_style("padding: 20px")

        cbjs_action = '''
        var value = bvr.src_el.getAttribute('spt_input_value');
        var display_value = bvr.src_el.getAttribute('spt_display_value');
        var phone_number = bvr.src_el.getAttribute('spt_phone_number');
        var email = bvr.src_el.getAttribute('spt_mail');

        var top = bvr.src_el.getParent('.ad_input_top');
        var content = top.getElement('.ad_input_content');
        var input = top.getElement('.spt_ad_input');
        var display = top.getElement('.spt_ad_display');
        input.value = value;
        display.value = display_value;

        server = TacticServerStub.get()
        server.execute_cmd("tactic.active_directory.ADCacheUserCbk", {login: value})

        spt.toggle_show_hide(content);

        '''
        ad_search_wdg = ADSearchWdg(cbjs_action=cbjs_action)
        ad_top.add(ad_search_wdg)

        top.add(ad_top)

        return top
Example #54
0
    def get_display(self):
        sobject = self.get_current_sobject()

        # handle the start and end
        frame_start = sobject.get_value("tc_frame_start")
        frame_end = sobject.get_value("tc_frame_end")

        frame_start_text = TextWdg("tc_frame_start")
        frame_start_text.set_value(frame_start)
        frame_start_text.set_option("size", "2")

        frame_end_text = TextWdg("tc_frame_end")
        frame_end_text.set_value(frame_end)
        frame_end_text.set_option("size", "2")

        # handle the notes
        frame_notes = sobject.get_value("frame_note")
        frame_notes_text = TextAreaWdg("frame_note")
        frame_notes_text.set_value(frame_notes)
        frame_notes_text.set_option("rows", "2")

        # handle the in and out handles
        frame_in = sobject.get_value("frame_in")
        frame_out = sobject.get_value("frame_out")

        frame_in_text = TextWdg("frame_in")
        frame_in_text.set_value(frame_in)
        frame_in_text.set_option("size", "2")

        frame_out_text = TextWdg("frame_out")
        frame_out_text.set_value(frame_out)
        frame_out_text.set_option("size", "2")

        div = DivWdg()

        table = Table()
        div.add(table)
        table.add_row()
        td = table.add_cell("Range:")
        td.add_style("width: 100px")
        td = table.add_cell()
        td.add_style("text-align: right")
        td.add_style("padding: 5px")
        td.add("start: ")
        td.add(frame_start_text)
        td = table.add_cell()
        td.add_style("text-align: right")
        td.add_style("padding: 5px")
        td.add("end: ")
        td.add(frame_end_text)

        table.add_row()
        table.add_cell("Handles:")
        td = table.add_cell()
        td.add_style("text-align: right")
        td.add_style("padding: 5px")
        td.add("in: ")
        td.add(frame_in_text)
        td = table.add_cell()
        td.add_style("text-align: right")
        td.add_style("padding: 5px")
        td.add("out: ")
        td.add(frame_out_text)
        td.add("<br/>")

        table.add_row()
        table.add_cell("Notes:")
        td = table.add_cell(frame_notes_text)
        td.add_style("padding: 5px")
        td.add_attr("colspan", "2")

        return div
Example #55
0
    def get_display(my):
        widget = DivWdg()
        table = Table()
        table.add_attr('class', 'scraper')
        table.add_style('background-color: #FFFFFF;')
        table.add_style('height: 1000px;')
        table.add_row()
        tb = TextWdg('title_box')
        tb.add_attr('id', 'title_box')
        tb.add_attr('size', '45')
        multiple_titles = None
        searched_imdb = False
        orders = []

        # TODO: Remove hard-coded URL
        no_img = 'http://tactic.2gdigital.com/imdb_images/no_image.png'
        if 'code' in my.kwargs.keys() and my.title_of_show in [None, '']:
            server = TacticServerStub.get()
            this_order = server.eval("@SOBJECT(twog/order['code','%s'])" % my.kwargs.get('code'))[0]
            my.title_of_show = this_order.get('name')

        if my.title_of_show not in [None, '']:
            tb.set_value(my.title_of_show)
            if my.search_when_loaded:
                # poster_url_text = my.get_poster_url(my.title_of_show)
                # poster_url = poster_url_text.split('=')[1]
                server = TacticServerStub.get()
                orders = server.eval("@SOBJECT(twog/order['name','~','%s']['classification','not in','Master|Cancelled'])" % my.title_of_show)
                # order_s = Search("twog/order")
                # order_s.add_where("\"name\" like '%s%s%s'" %  ('%', my.title_of_show.lower(), '%'))
                # statement = order_s.get_statement()
                # print "STATEMENT = %s" % statement
                # orders = order_s.get_sobjects()
                # print "ORDER LEN = %s" % len(orders)
                if len(orders) > 0:
                    multiple_titles = get_multiple_title_info(my.title_of_show)
                    # print "MULTIPLE TITLES = %s" % multiple_titles
                    searched_imdb = True
        tb.add_behavior(my.get_search())
        top_tbl = Table()
        top_tbl.add_attr('width', '400px')
        top_tbl.add_attr('height', '50px')
        top_tbl.add_attr('cellpadding', '20')
        top_tbl.add_attr('cellspacing', '20')
        top_tbl.add_style('background-color: #417e97;')
        top_tbl.add_row()

        if len(orders) > 0:
            butt = top_tbl.add_cell('<input type="button" value="Associate All Selected"/>')
            butt.add_behavior(my.get_associate_em())

        sn = top_tbl.add_cell('<font color="#d9af1f"><b>Search Name:</b></font>&nbsp;&nbsp;&nbsp;&nbsp;')
        sn.add_attr('align', 'right')
        sn.add_attr('nowrap', 'nowrap')
        tb_cell1 = top_tbl.add_cell(tb)
        tb_cell = table.add_cell(top_tbl)
        tb_cell.add_attr('colspan', '2')
        tb_cell.add_attr('align', 'center')
        order_table = Table()
        order_table.add_attr('border', '1')
        order_table.add_attr('cellpadding', '10')
        order_table.add_row()

        if len(orders) > 0:
            toggler = CustomCheckboxWdg(name='chk_toggler', additional_js=my.get_toggler(), value_field='toggler',
                                        id='selection_toggler', checked='false', text='<b><- Select/Deselect ALL</b>',
                                        text_spot='right', text_align='left', nowrap='nowrap')
            order_table.add_cell(toggler)
            order_table.add_row()
            order_table.add_cell('Selector')
            order_table.add_cell('Poster')
            order_table.add_cell('Order Builder')
            order_table.add_cell('Code')
            order_table.add_cell('Name')
            order_table.add_cell('Client')
            order_table.add_cell('PO Number')
            order_table.add_cell('Classification')
            order_table.add_cell('Platform')
            order_table.add_cell('Due Date')
            order_table.add_cell('Completion Ratio')
            order_table.add_cell('Scheduler')
        elif my.title_of_show not in [None, ''] and my.search_when_loaded:
            description_box = order_table.add_cell('<b>No Tactic Orders Were Found With "%s" In The Name</b>' % my.title_of_show)
            description_box.add_style('font-size: 14px;')
        else:
            description_box = order_table.add_cell('<b>Please type the name of the show in the box above</b>')
            description_box.add_style('font-size: 14px;')
        for order in orders:
            checkbox = CustomCheckboxWdg(name='associate_order_%s' % order.get('code'),
                                         additional_js=my.highlight_order_row(order.get('code')),
                                         alert_name=order.get('name'),
                                         value_field=order.get('code'),
                                         checked='false',
                                         dom_class='associated_orders')
            imarow = order_table.add_row()
            imarow.add_attr('id', 'row_%s' % order.get('code'))
            chk = order_table.add_cell(checkbox)
            chk.add_attr('align', 'center')
            poster_cell = order_table.add_cell(OrderImageWdg(code=order.get('code')))
            poster_cell.add_attr('id', 'img_%s' % order.get('code'))
            ob = OrderBuilderLauncherWdg(code=order.get('code'))
            obc = order_table.add_cell(ob)
            obc.add_attr('align', 'center')
            order_table.add_cell(order.get('code'))
            order_table.add_cell(order.get('name'))
            order_table.add_cell(order.get('client_name'))
            order_table.add_cell(order.get('po_number'))
            order_table.add_cell(order.get('classification'))
            order_table.add_cell(order.get('platform'))
            order_table.add_cell(order.get('due_date'))
            order_table.add_cell('%s/%s' % (order.get('titles_completed'), order.get('titles_total')))
            order_table.add_cell(order.get('login'))
        imdb_table = Table()
        imdb_table.add_attr('border', '1')
        imdb_table.add_attr('cellpadding', '10')
        if multiple_titles not in [None, ''] and len(multiple_titles) > 0:
            mcount = 0
            seen_titles = []
            for m in multiple_titles:
                title_id = m['TopLevel']['title_id']
                if title_id not in seen_titles:
                    seen_titles.append(title_id)
                    imarow = imdb_table.add_row()
                    imarow.add_attr('id', 'row_%s' % m['TopLevel']['title_id'])
                    this_img = no_img

                    # TODO: Download the image and save in a temp folder
                    if m['TopLevel']['poster'] not in [None, '']:
                        this_img = m['TopLevel']['poster']
                        imdb_image_url = m['TopLevel']['poster']
                    checkbox = CustomCheckboxWdg(name='associate_imdb_%s' % m['TopLevel']['title_id'],
                                                 additional_js=my.act_like_radio(m['TopLevel']['title_id']),
                                                 alert_name=m['TopLevel']['title'],
                                                 value_field=m['TopLevel']['title_id'],
                                                 checked='false',
                                                 dom_class='associated_imdb',
                                                 extra1=m['TopLevel']['title_id'],
                                                 extra2=m['TopLevel']['title'],
                                                 extra3=m['TopLevel']['runtime'],
                                                 extra4=m['TopLevel']['release_date'],
                                                 extra5=m['TopLevel']['imdb_url'],
                                                 extra6=this_img)
                    chk = imdb_table.add_cell(checkbox)
                    chk.add_attr('align', 'center')
                    imdb_table.add_cell('<img src="%s"/>' % this_img)
                    info_tbl = Table()
                    info_tbl.add_row()
                    title_cell = info_tbl.add_cell('<b>Title: %s</b>' % m['TopLevel']['title'])
                    title_cell.add_style('cursor: pointer;')
                    title_cell.add_behavior(my.get_more_info(mcount))
                    info_tbl.add_row()
                    info_tbl.add_cell('<i>Original Title: %s</i>' % m['TopLevel']['original_title'])
                    info_tbl.add_row()
                    info_tbl.add_cell('<i>Run Time: %s</i>' % m['TopLevel']['runtime'])
                    info_tbl.add_row()
                    info_tbl.add_cell('<i>Release Date: %s</i>' % m['TopLevel']['release_date'])
                    info_tbl.add_row()
                    info_tbl.add_cell('<i>Rating: %s</i>' % m['TopLevel']['rating'])
                    info_tbl.add_row()
                    info_tbl.add_cell('<i>IMDb URL: %s</i>' % m['TopLevel']['imdb_url'])
                    info_tbl.add_row()
                    info_tbl.add_cell('<i>Plot: %s</i>' % m['TopLevel']['plot'])
                    info2 = Table()
                    mkeys = m.keys()
                    for k in mkeys: 
                        if k not in ['media_images', 'recommended_titles', 'videos', 'cinematographers', 'editors',
                                     'producers', 'cast', 'directors', 'writers', 'stars', 'plot_keywords', 'musicians',
                                     'TopLevel']:
                            info2.add_row()
                            info2.add_cell('<b><u>%s</u></b>' % k)
                            dudes = m[k]
                            dkeys = dudes.keys()
                            for d in dkeys:
                                info2.add_row()
                                info2.add_cell('%s: %s' % (d, dudes[d]))
                    intable = imdb_table.add_cell(info_tbl)
                    intable.add_attr('valign', 'top')
                    intable.add_attr('align', 'left')
                    # intable.add_behavior(my.get_hover_behavior(mcount))
                    hidrow = imdb_table.add_row()
                    hidrow.add_attr('hidden_id', mcount)
                    hidrow.add_attr('class', 'hidden_info')
                    hidrow.add_style('display: none;')
                    intable2 = imdb_table.add_cell(info2)
                    intable2.add_attr('valign', 'top')
                    intable2.add_attr('align', 'left')
                    mcount += 1
        elif my.title_of_show not in [None, ''] and searched_imdb:
            imdb_table.add_row()
            description_box = imdb_table.add_cell('<b>No IMDb Titles Were Found With "%s" In The Name</b>' % my.title_of_show)
            description_box.add_style('font-size: 14px;')
            imarow = imdb_table.add_row()
            imarow.add_attr('id', 'row_%s' % 'none')
            checkbox = CustomCheckboxWdg(name='associate_imdb_%s' % 'none', additional_js=my.act_like_radio('none'),
                                         alert_name='No IMDb Link', value_field='none', checked='false',
                                         dom_class='associated_imdb', extra1='none', extra2='No IMDb Link', extra3='',
                                         extra4='', extra5='none', extra6=no_img)
            chk = imdb_table.add_cell(checkbox)
            chk.add_attr('align', 'center')
            imdb_table.add_cell('<img src="%s"/>' % no_img)
            info_tbl = Table()
            info_tbl.add_row()
            title_cell = info_tbl.add_cell('<b>Title: %s</b>' % 'No IMDb Link')
            title_cell.add_style('cursor: pointer;')
            intable = imdb_table.add_cell(info_tbl)
            intable.add_attr('valign', 'top')
            intable.add_attr('align', 'left')
            hidrow = imdb_table.add_row()
            hidrow.add_attr('class', 'hidden_info')
            hidrow.add_style('display: none;')
        elif my.title_of_show not in [None, '']:
            imdb_table.add_row()
            description_box = imdb_table.add_cell("<b>No Tactic Orders Found, Didn't Query IMDb</b>")
            description_box.add_style('font-size: 14px;')
        table.add_row()
        order_div = DivWdg()
        order_div.add_style('overflow-y: scroll;')
        order_div.add_style('height: 1000px;')
        order_div.add_style('width: 750px;')
        order_div.add('<font size=7><b>Tactic Orders</b></font>')
        order_div.add(order_table)
        ot = table.add_cell(order_div)
        ot.add_attr('valign', 'top')
        imdb_div = DivWdg()
        imdb_div.add_style('overflow-y: scroll;')
        imdb_div.add_style('height: 1000px;')
        imdb_div.add_style('width: 750px;')
        imdb_div.add('<font size=7><b>IMDb</b></font>')
        imdb_div.add(imdb_table)
        it = table.add_cell(imdb_div)
        it.add_attr('valign', 'top')
        widget.add(table)
        return widget
Example #56
0
    def get_display(self):

        web = WebContainer.get_web()
        naming_util = NamingUtil()

        if not self.widget_name:
            self.widget_name = self.get_name()

        # get the sobject required by this input
        sobject = self.get_current_sobject()
        if not sobject:
            sobject = Search.get_by_id(self.search_type, self.search_id)

        if self.new_sample_name:
            self.new_sample_name.replace("//", "/")
        else:
            self.new_sample_name = sobject.get_value(self.widget_name)

        widget = DivWdg()
        widget.set_id("naming")
        widget.add_style("display: block")

        # set the sample text
        div = DivWdg()
        div.add("Sample name: <i>%s</i>" % self.new_sample_name)
        div.add(HtmlElement.br(2))

        new_sample_wdg = ProdIconButtonWdg("Set New Sample")
        new_sample_wdg.add_event("onclick", "toggle_display('generate')")
        div.add(new_sample_wdg)

        generate = DivWdg()
        generate.add(HtmlElement.br())
        generate.set_id("generate")
        generate.add_style("display: none")
        sample_text = TextWdg("new_sample_name")
        sample_text.set_option("size", "30")
        #sample_text.set_persist_on_submit()
        #if self.new_sample_name:
        #    sample_text.set_value(self.new_sample_name)
        generate.add(sample_text)

        button = IconButtonWdg("Generate", IconWdg.REFRESH, long=True)
        on_script = self.setup_ajax("naming")
        button.add_event("onclick", on_script)
        generate.add(button)
        generate.add(HtmlElement.br(2))

        div.add(generate)
        widget.add(div)

        hidden = TextWdg(self.widget_name)
        value = self.naming
        hidden.set_value(self.new_sample_name)
        widget.add(self.widget_name)
        widget.add(hidden)

        # get all of the parts

        # TODO: not sure if this should be dictated by the sample name
        # break up the name into parts
        import re
        if self.new_sample_name:
            tmp = self.new_sample_name.strip("/")
            parts = re.split('[\\/._]', tmp)
            print "parts: ", parts
        else:
            return widget

        # if there is a naming, then populate that
        if self.edit_search_type:
            options = naming_util.get_options(self.edit_search_type)
        else:
            options = naming_util.get_options(sobject.get_value("search_type"))

        table = Table()
        type_values = []
        padding_values = []
        for idx, part in enumerate(parts):
            table.add_row()
            table.add_cell(part)

            type_select = SelectWdg("type_%s" % idx)
            type_select.add_empty_option("-- Explicit --")
            type_select.set_persist_on_submit()
            type_select.set_option("values", "|".join(options))
            type_values.append(type_select.get_value())
            td = table.add_cell(type_select)

        widget.add(table)

        return widget
    def get_bottom_wdg(my, search_keys=[]):
        # check if the user has enabled it
        info = my.check_bottom_wdg()

        if info.get('check') == False:
            return None

        if info.get('mode') != 'total':
            top = DivWdg()
            top.add(
                "Only [total] is supported. Please change it in Edit Column Definition"
            )
            return top

        my.today = datetime.date.today()

        if my.is_refresh:
            top = Widget()
        else:
            top = DivWdg()

        days = []
        for date in my.dates:
            days.append(date.strftime("%Y_%m_%d"))

        today = my.today.strftime("%Y_%m_%d")

        table = Table()
        top.add(table)

        row_list = [my.ST_ROW]
        if my.show_overtime:
            row_list.append(my.OT_ROW)

        for row_to_draw in row_list:

            table.add_row()
            table.add_color("color", "color")
            table.add_styles("width: %spx; float: left" % my.table_width)

            td = table.add_blank_cell()
            td.add_style("min-width: %spx" %
                         (my.MONTH_WIDTH + my.LEFT_WIDTH + 8))
            time_prefix = ''
            if row_to_draw == my.OT_ROW:
                time_prefix = 'ot'
                div = DivWdg()
                div.add("OT")

                div.add_styles(
                    'text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)
            elif row_to_draw == my.STT_ROW:
                time_prefix = 'stt'
                div = DivWdg()
                div.add("ST")

                div.add_styles(
                    'text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)
            elif row_to_draw == my.ENT_ROW:
                time_prefix = 'ent'
                div = DivWdg()
                div.add("ET")

                div.add_styles(
                    'text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)

            for idx, day in enumerate(days):
                day_wdg = DivWdg()
                day_wdg.add(day)

                td = table.add_cell()
                td.add_style("width: %spx" % my.day_width)
                # keep it as text input for consistent alignment
                text = TextWdg("%sday_%s" % (time_prefix, day))

                if row_to_draw == my.OT_ROW:
                    sobj_daily_dict = my.summary_ot[idx]
                else:
                    sobj_daily_dict = my.summary_st[idx]

                if search_keys:
                    sobj_daily_sub_dict = Common.subset_dict(
                        sobj_daily_dict, search_keys)
                else:
                    sobj_daily_sub_dict = sobj_daily_dict

                daily_total = 0
                for value in sobj_daily_sub_dict.values():
                    if value:
                        daily_total += value

                text.set_value(daily_total)
                td.add(text)

                text.add_class("spt_day%s" % (time_prefix))
                text.add_style("width: %spx" % (my.day_width - 2))
                #text.add_style("width: 100%")
                text.add_style("text-align: right")
                text.add_style("padding-left: 2px")
                text.add_style('font-weight: 500')
                text.set_attr("readonly", "readonly")
                # grey out the text color
                text.add_color('color', 'color', +40)

                if day == today:
                    text.add_style("border: solid 1px black")
                elif idx in [0, 6]:
                    if row_to_draw == my.OT_ROW:
                        # FOOTER: Overtime, weekends
                        text.add_color("background",
                                       "background2",
                                       modifier=[-15, 0, 5])
                    else:
                        # FOOTER: Straight time, weekends
                        text.add_color("background",
                                       "background2",
                                       modifier=[0, 15, 20])

            text = TextWdg("total")
            daily_total = 0
            if row_to_draw == my.OT_ROW:
                sobj_daily_dict = my.summary_ot[7]
            else:
                sobj_daily_dict = my.summary_st[7]

            if search_keys:
                sobj_daily_sub_dict = Common.subset_dict(
                    sobj_daily_dict, search_keys)
            else:
                sobj_daily_sub_dict = sobj_daily_dict
            for value in sobj_daily_sub_dict.values():
                if value:
                    daily_total += value
            text.set_value(daily_total)

            td = table.add_cell(text)
            text.add_class("spt_total%s" % (time_prefix))
            # does not look good in FF
            #td.add_style("border-width: 0 0 0 1")
            #td.add_style("border-style: solid")
            td.add_style("width: %spx" % my.day_width)
            text.add_styles(
                "font-weight: 500;width: %spx; text-align: right; padding-left: 2px"
                % (my.day_width))

            text.set_attr("readonly", "readonly")
            text.add_color('color', 'color', +40)

            if row_to_draw == my.OT_ROW:
                # FOOTER: Overtime, total.
                text.add_color("background",
                               "background2",
                               modifier=[5, -15, 0])
            else:
                # FOOTER: Straight time, total
                text.add_color("background",
                               "background2",
                               modifier=[20, 0, 15])

            td = table.add_blank_cell()
            td.add_style('width', '100%')

        return top
Example #58
0
    def get_display(my):

        data = my.kwargs.get('kwargs')
        if data:
            data = jsonloads(data)
            my.kwargs.update(data)

        my.search_type = my.kwargs.get("search_type")

        my.x_axis = my.kwargs.get("x_axis")
        if not my.x_axis:
            my.x_axis = 'code'

        my.y_axis = my.kwargs.get("y_axis")
        if type(my.y_axis) == types.ListType:
            my.y_axis = "|".join(my.y_axis)

        my.chart_type = my.kwargs.get("chart_type")
        if not my.chart_type:
            my.chart_type = 'bar'

        # get any search keys if any are passed in
        my.search_keys = my.kwargs.get("search_keys")

        top = DivWdg()
        top.add_class("spt_chart_builder")
        top.add_color("background", "background")
        top.add_border()

        from tactic.ui.app import HelpButtonWdg
        help_button = HelpButtonWdg(alias='charting')
        top.add(help_button)
        help_button.add_style("float: right")

        project = Project.get()
        search_types = project.get_search_types(include_sthpw=True)
        search_types = [x.get_value("search_type") for x in search_types]

        build_div = DivWdg()

        from pyasm.widget import SwapDisplayWdg
        swap_wdg = SwapDisplayWdg.get_triangle_wdg()
        swap_script = swap_wdg.get_swap_script()
        build_div.add(swap_wdg)

        build_div.add("<b>Chart Specifications</b>")
        build_div.add_style("margin-bottom: 5px")
        build_div.add_style("height: 25px")
        build_div.add_style("padding-top: 5px")
        build_div.add_gradient("background", "background", -10)
        build_div.add_color("color", "color")

        build_div.add_class("hand")
        build_div.add_class("SPT_DTS")
        top.add(build_div)
        build_div.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_chart_builder");
            var spec = top.getElement(".spt_chart_spec");
            //spt.api.toggle_show_hide(spec);
            spt.toggle_show_hide(spec);
            %s;
            ''' % swap_script
        })

        spec_div = DivWdg()
        spec_div.add_color("color", "color3")
        spec_div.add_color("background", "background3")
        spec_div.add_class("spt_chart_spec")
        spec_div.add_border()
        spec_div.add_style("padding: 10px")
        spec_div.add_style("margin: 5px")
        spec_div.add_style("display: none")
        top.add(spec_div)

        table = Table()
        table.add_color("color", "color3")
        spec_div.add(table)

        # add the search type selector
        table.add_row()
        table.add_cell("Search Type: ")

        search_type_div = DivWdg()
        search_type_select = TextWdg("search_type")
        search_type_select.set_value(my.search_type)
        #search_type_select.set_option("values", search_types)
        search_type_div.add(search_type_select)
        table.add_cell(search_type_div)

        # add the chart type selector
        table.add_row()
        table.add_cell("Chart Type: ")

        type_div = DivWdg()
        #type_div.add_style("padding: 3px")
        type_select = SelectWdg("chart_type")
        type_select.set_option("values", "line|bar|area")
        if my.chart_type:
            type_select.set_value(my.chart_type)
        type_div.add(type_select)
        table.add_cell(type_div)

        # add the chart type selector
        table.add_row()
        table.add_cell("X-Axis: ")

        # need to find all expression widgets or use get_text_value()?
        x_axis_div = DivWdg()
        x_axis_text = TextWdg("x_axis")
        x_axis_text.set_value("code")
        x_axis_div.add(x_axis_text)
        table.add_cell(x_axis_div)

        # add the chart type selector
        table.add_row()
        td = table.add_cell("Y-Axis: ")
        td.add_style("vertical-align: top")

        y_axis_div = DivWdg()
        #y_axis_text = TextWdg("y_axis")
        #if my.y_axis:
        #    y_axis_text.set_value(my.y_axis)
        #y_axis_div.add(y_axis_text)
        td = table.add_cell(y_axis_div)

        # add in a list of entries
        from tactic.ui.container import DynamicListWdg
        list_wdg = DynamicListWdg()
        for value in my.y_axis.split("|"):
            item = TextWdg("y_axis")
            item.set_value(value, set_form_value=False)
            list_wdg.add_item(item)
        y_axis_div.add(list_wdg)

        spec_div.add("<br/>")
        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title="Refresh")
        spec_div.add(button)
        spec_div.add(HtmlElement.br(2))
        button.add_style("float: left")

        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_chart_builder");
        var chart = top.getElement(".spt_chart");
        var values = spt.api.get_input_values(top);
        //var values = spt.api.Utility.get_input_values(top);
        spt.panel.refresh(chart, values);
        '''
        })

        #TODO: provide a field for user to type in the chart name
        """

        button = ActionButtonWdg(title="Save")
        spec_div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_chart_builder");
        var chart = top.getElement(".spt_chart");
        var values = spt.api.get_input_values(top);

        var login = '******';
        var search_type = 'SideBarWdg';
        var side_bar_view = 'project_view';
        var unique_el_name = 'chart_test'

        var kwargs = {};
        kwargs['login'] = null;
        //if (save_as_personal) 
        //    kwargs['login'] = login;
        kwargs['class_name'] = 'tactic.ui.chart.ChartBuilderWdg';

        var display_options = {};
        display_options['search_type'] = 'prod/asset'
        kwargs['display_options'] = display_options;
 
        kwargs['unique'] = true;
        //if (new_title)
        //    kwargs['element_attrs'] = {'title': new_title}; 

        var server = TacticServerStub.get()
        server.add_config_element(search_type, side_bar_view, unique_el_name, kwargs);
        spt.panel.refresh("side_bar");
        '''
        } )
        """

        width = '600px'
        kwargs = {
            'y_axis': my.y_axis,
            'chart_type': my.chart_type,
            'search_type': my.search_type,
            'width': width,
            'search_keys': my.search_keys
        }

        chart_div = DivWdg()
        chart = BarChartWdg(**kwargs)

        chart_div.add(chart)
        top.add(chart_div)

        #from chart2_wdg import SampleSObjectChartWdg
        #chart = SampleSObjectChartWdg(**kwargs)
        #chart_div.add(chart)

        return top
Example #59
0
    def get_display(self):

        self.doc_mode = self.kwargs.get("doc_mode")
        path = self.kwargs.get("path")
        self.search_type = self.kwargs.get("search_type")

        self.last_path = None

        doc_key = self.kwargs.get("doc_key")
        if doc_key:
            self.doc = Search.get_by_search_key(doc_key)
            snapshot = Snapshot.get_latest_by_sobject(self.doc)
            if snapshot:
                self.last_path = snapshot.get_lib_path_by_type('main')

            path = self.doc.get_value("link")


        # TEST TEST TEST
        if not path:
            #path = "/home/apache/pdf/mongodb.txt"
            #path = "/home/apache/assets/google_docs.html"
            #path = "/home/apache/pdf/star_wars.txt"
            path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true"

            path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub"

            #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html"
            path = "/home/apache/tactic/doc/alias.json"

        if not self.search_type:
            self.search_type = "test3/shot"


        self.column = "description"

        top = self.top
        top.add_class("spt_document_top")
        self.set_as_panel(top)

        #table = Table()
        table = ResizableTableWdg()

        top.add(table)
        table.add_row()
        table.set_max_width()

        left_td = table.add_cell()
        left_td.add_style("vertical-align: top")


        title = DivWdg()
        left_td.add(title)
        title.add_style("padding: 10px")
        title.add_color("background", "background3")

        button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH)
        title.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.app_busy.show("Reloading Document");
            var top = bvr.src_el.getParent(".spt_document_top");
            spt.panel.refresh(top);
            spt.app_busy.hide();
            '''
        } )
        button.add_style("float: left")


        button = IconButtonWdg(title="Save", icon=IconWdg.SAVE)
        title.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            '''
        } )
        button.add_style("float: left")


        if not self.doc_mode:
            self.doc_mode = "text"
        select = SelectWdg("doc_mode")
        select.set_option("values", "text|formatted")
        title.add(select)
        select.set_value(self.doc_mode)
        select.add_behavior( {
            'type': 'change',
            'cbjs_action': '''
            spt.app_busy.show("Reloading Document");
            var top = bvr.src_el.getParent(".spt_document_top");
            var value = bvr.src_el.value;
            top.setAttribute("spt_doc_mode", value);
            spt.panel.refresh(top);
            spt.app_busy.hide();
            '''
        } )


        title.add("<br clear='all'/>")

        #title.add(path)


        text_wdg = DivWdg()
        text_wdg.add_class("spt_document_content")
        left_td.add(text_wdg)

        #if path.startswith("https://docs.google.com/spreadsheet"):
        #    #path = "http://www.southpawtech.com.com"
        #    text_wdg.add('''
        #    <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe>
        #    ''' % path)
        #    text_wdg.add_style("overflow-x: hidden")
        if True:

            if not self.last_path and self.doc:
                tmp_dir = Environment.get_tmp_dir()
                tmp_path = '%s/last_path.txt' % tmp_dir
                f = open(tmp_path, 'w')

                text = self.get_text(path, highlight=False)

                f.write(text)
                f.close()

                cmd = FileCheckin(self.doc, tmp_path)
                Command.execute_cmd(cmd)

            else:
                save = False
                if save:
                    # open up the last path
                    f = open(self.last_path, 'r')
                    last_text = f.read()
                    text = self.get_text(path, None, highlight=False)

                    if last_text != text:

                        tmp_dir = Environment.get_tmp_dir()
                        tmp_path = '%s/last_path.txt' % tmp_dir
                        f = open(tmp_path, 'w')
                        f.write(text)
                        f.write(text)
                        f.close()

                        cmd = FileCheckin(self.doc, tmp_path)
                        Command.execute_cmd(cmd)

                text = self.get_text(path, self.last_path)


            lines = text.split("\n") 

            if self.doc_mode == "text":

                num_lines = len(lines)

                """
                line_div = HtmlElement.pre()
                text_wdg.add(line_div)
                line_div.add_style("width: 20px")
                line_div.add_style("float: left")
                line_div.add_style("text-align: right")
                line_div.add_style("opacity: 0.3")
                line_div.add_style("padding-right: 10px")
                for i in range(0, num_lines*2):
                    line_div.add(i+1)
                    line_div.add("<br/>")
                """



            if self.doc_mode == "text":
                pre = HtmlElement.pre()
                pre.add_style("white-space: pre-wrap")
            else:
                pre = DivWdg()
            pre = DivWdg()
            text_wdg.add(pre)

            text_wdg.add_style("padding: 10px 5px")
            text_wdg.add_style("max-height: 600px")
            text_wdg.add_style("overflow-y: auto")
            text_wdg.add_style("width: 600px")
            text_wdg.add_class("spt_resizable")


            pre.add_style("font-family: courier")


            if self.doc_mode == "formatted":
                pre.add(text)

            else:
                line_table = Table()
                pre.add(line_table)
                line_table.add_style("width: 100%")
                count = 1
                for line in lines:
                    #line = line.replace(" ", "&nbsp;")
                    tr = line_table.add_row()
                    if count % 2 == 0:
                        tr.add_color("background", "background", -2)

                    td = line_table.add_cell()

                    # FIXME: hacky
                    if line.startswith('''<span style='background: #CFC'>'''):
                        is_new = True
                    else:
                        td.add_style("vertical-align: top")
                        text = TextWdg()
                        text.add_style("border", "none")
                        text.add_style("text-align", "right")
                        text.add_style("width", "25px")
                        text.add_style("margin", "0 10 0 0")
                        text.add_style("opacity", "0.5")
                        text.set_value(count)
                        td.add(text)
                        count += 1
                        is_new = False

                    td = line_table.add_cell()
                    if not is_new:
                        SmartMenu.assign_as_local_activator( td,'TEXT_CTX' )
                        tr.add_class("spt_line");
                    else:
                        SmartMenu.assign_as_local_activator( td,'TEXT_NEW_CTX' )
                        tr.add_class("spt_new_line");

                    td.add_class("spt_line_content");
                    td.add(line)




            #from tactic.ui.app import AceEditorWdg
            #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px")
             #text_wdg.add(editor)



        # add a click on spt_item
        text_wdg.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': 'spt_document_item',
            'search_type': self.search_type,
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_document_top");
            var data_el = top.getElement(".spt_document_data");

            var search_key = bvr.src_el.getAttribute("spt_search_key");

            var class_name = 'tactic.ui.panel.ViewPanelWdg';
            var kwargs = {
                'search_type': bvr.search_type,
                'search_key': search_key,
            }
            spt.panel.load(data_el, class_name, kwargs);
            '''
        } )


        # add a double click on spt_item
        bgcolor = text_wdg.get_color("background", -10)
        text_wdg.add_relay_behavior( {
            'type': 'mouseover',
            'bvr_match_class': 'spt_document_item',
            'search_type': self.search_type,
            'bgcolor': bgcolor,
            'cbjs_action': '''
            bvr.src_el.setStyle("opacity", "1.0");
            //bvr.src_el.setStyle("font-weight", "normal");
            bvr.src_el.setStyle("background", bvr.bgcolor);
            '''
        } )

        # add a double click on spt_item
        text_wdg.add_relay_behavior( {
            'type': 'mouseout',
            'bvr_match_class': 'spt_document_item',
            'search_type': self.search_type,
            'cbjs_action': '''
            bvr.src_el.setStyle("opacity", "1.0");
            //bvr.src_el.setStyle("font-weight", "bold");
            bvr.src_el.setStyle("background", "");
            '''
        } )






        # add a context menu
        ctx_menu = self.get_text_context_menu()
        ctx_new_menu = self.get_text_new_context_menu()
        menus_in = {
            'TEXT_CTX': ctx_menu,
            'TEXT_NEW_CTX': ctx_new_menu,
        }
        SmartMenu.attach_smart_context_menu( text_wdg, menus_in, False )



        panel = ViewPanelWdg(
                search_type=self.search_type,
                layout="blah"
        )


        right_td = table.add_cell()
        right_td.add_style("vertical-align: top")

        panel_div = DivWdg()
        panel_div.add_class("spt_document_data")
        right_td.add(panel_div)
        panel_div.add(panel)


        text_wdg.add_behavior( {
            'type': 'load',
            'cbjs_action': r'''

spt.document = {};

spt.document.selected_text = null;

spt.document.get_selected_text = function(frame)
{

    var t = '';

    if (frame) {
        var rng = frame.contentWindow.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }

    else if (window.getSelection) // FF4 with one tab open?
    {
        var rng = window.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }
    else if (document.getSelection) // FF4 with multiple tabs open?
    {
        var rng = document.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }
    else if (document.selection) // IE8
    {
        var rng = document.selection.createRange();
        // expand range to enclose any word partially enclosed in it
        rng.expand("word");
        t = rng.text;
    }

    // convert newline chars to spaces, collapse whitespace, and trim non-word chars
    return t.replace(/^\W+|\W+$/g, '');
    //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, '');
}

// expand FF range to enclose any word partially enclosed in it
spt.document.expandtoword = function(range)
{
    if (range.collapsed) {
        return;
    }

    while (range.startOffset > 0 && range.toString()[0].match(/\w/)) {
        range.setStart(range.startContainer, range.startOffset - 1);
    }

    while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/))
    {
        range.setEnd(range.endContainer, range.endOffset + 1);
    }
}
            '''
        } )

        top.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': 'spt_document_content',
            'cbjs_action': r'''
            //spt.ace_editor.set_editor_top(bvr.src_el);
            //var text = spt.ace_editor.get_selection();
            var text = spt.document.get_selected_text();
            text = text.replace(/\n\n/mg, "\n");
            text = text.replace(/\n\n/mg, "\n");
            spt.document.selected_text = text + "";
            '''
        } )




        return top
Example #60
0
    def get_display(self):

        top = DivWdg()
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("min-width: 600px")

        os_name = os.name

        top.set_unique_id()
        top.add_smart_style("spt_info_title", "background",
                            self.top.get_color("background3"))
        top.add_smart_style("spt_info_title", "padding", "3px")
        top.add_smart_style("spt_info_title", "font-weight", "bold")

        # server
        title_div = DivWdg()
        top.add(title_div)
        title_div.add("Server")
        title_div.add_class("spt_info_title")

        os_div = DivWdg()
        top.add(os_div)

        os_info = platform.uname()
        try:
            os_login = os.getlogin()
        except Exception:
            os_login = os.environ.get("LOGNAME")

        table = Table()
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        os_div.add(table)

        for i, title in enumerate(
            ['OS', 'Node Name', 'Release', 'Version', 'Machine']):
            table.add_row()
            td = table.add_cell("%s: " % title)
            td.add_style("width: 150px")
            table.add_cell(os_info[i])

        table.add_row()
        table.add_cell("CPU Count: ")
        try:
            import multiprocessing
            table.add_cell(multiprocessing.cpu_count())
        except (ImportError, NotImplementedError):
            table.add_cell("n/a")

        table.add_row()
        table.add_cell("Login: "******"Python")
        title_div.add_class("spt_info_title")

        table = Table()
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        top.add(table)
        table.add_row()
        td = table.add_cell("Version: ")
        td.add_style("width: 150px")
        table.add_cell(sys.version)

        # client
        title_div = DivWdg()
        top.add(title_div)
        title_div.add("Client")
        title_div.add_class("spt_info_title")

        web = WebContainer.get_web()
        user_agent = web.get_env("HTTP_USER_AGENT")

        table = Table()
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        top.add(table)
        table.add_row()
        td = table.add_cell("User Agent: ")
        td.add_style("width: 150px")
        table.add_cell(user_agent)

        table.add_row()
        td = table.add_cell("TACTIC User: "******"Performance Test")
        title_div.add_class("spt_info_title")

        performance_wdg = PerformanceWdg()
        top.add(performance_wdg)

        top.add('<br/>')

        # mail server
        title_div = DivWdg()
        top.add(title_div)
        title_div.add("Mail Server")
        title_div.add_class("spt_info_title")

        table = Table(css='email_server')
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        top.add(table)
        table.add_row()
        td = table.add_cell("Server: ")
        td.add_style("width: 150px")
        mailserver = Config.get_value("services", "mailserver")
        has_mailserver = True
        if mailserver:
            table.add_cell(mailserver)
        else:
            table.add_cell("None configured")
            has_mailserver = False

        login = Login.get_by_login('admin')
        login_email = login.get_value('email')
        table.add_row()
        td = table.add_cell("From: ")
        td.add_style("width: 150px")
        text = TextWdg('email_from')
        text.set_attr('size', '40')
        text.set_value(login_email)
        text.add_class('email_from')
        table.add_cell(text)

        table.add_row()
        td = table.add_cell("To: ")
        td.add_style("width: 150px")
        text = TextWdg('email_to')
        text.set_attr('size', '40')
        text.add_class('email_to')
        text.set_value(login_email)
        table.add_cell(text)

        button = ActionButtonWdg(title='Email Send Test')
        table.add_row_cell('<br/>')
        table.add_row()

        table.add_cell(button)
        button.add_style("float: right")
        button.add_behavior({
            'type':
            'click_up',
            'has_mailserver':
            has_mailserver,
            'cbjs_action':
            '''
             if (!bvr.has_mailserver) {
                spt.alert('You have to fill in mailserver and possibly other mail related options in the TACTIC config file to send email.');
                return;
            }
             var s = TacticServerStub.get();
             try {

                spt.app_busy.show('Sending email'); 
                var from_txt = bvr.src_el.getParent('.email_server').getElement('.email_from');
                var to_txt = bvr.src_el.getParent('.email_server').getElement('.email_to');
                
                var rtn = s.execute_cmd('pyasm.command.EmailTriggerTestCmd', 
                {'sender_email': from_txt.value,
                 'recipient_emails': to_txt.value.split(','),
                 'msg': 'Simple Email Test by TACTIC'}
                 );
                 if (rtn.status == 'OK') {
                    spt.info("Email sent successfully to " + to_txt.value)
                 }
             } catch(e) {
                spt.alert(spt.exception.handler(e));
             }
             spt.app_busy.hide();


        '''
        })

        top.add('<br/>')
        self.handle_directories(top)

        #table.add_row()
        #td = table.add_cell("TACTIC User: ")
        #table.add_cell( web.get_user_name() )

        top.add('<br/>')
        top.add(DivWdg('Link Test', css='spt_info_title'))
        top.add('<br/>')
        top.add(LinkLoadTestWdg())

        top.add('<br/>')
        self.handle_python_script_test(top)
        top.add('<br/>')
        self.handle_sidebar_clear(top)

        return top