Beispiel #1
0
    def get_sync_mode_wdg(self):

        div = DivWdg()
        div.add_class("spt_sync_mode")

        div.add("Share Mode: ")
        select = SelectWdg("sync_mode")
        div.add(select)
        select.set_option("values", "file|xmlrpc")

        select.add_behavior( {
            'type': 'change',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_sync_mode");
            var value = bvr.src_el.value;
            var xmlrpc_el = top.getElement(".spt_xmlrpc_mode");
            var file_el = top.getElement(".spt_file_mode");

            if (value == 'xmlrpc') {
                spt.show(xmlrpc_el);
                spt.hide(file_el);
            }
            else {
                spt.hide(xmlrpc_el);
                spt.show(file_el);
            }
            '''
        } )

        div.add( self.get_xmlrpc_mode_wdg() )
        div.add( self.get_file_mode_wdg() )

        return div
Beispiel #2
0
    def get_sync_mode_wdg(my):

        div = DivWdg()
        div.add_class("spt_sync_mode")

        div.add("Share Mode: ")
        select = SelectWdg("sync_mode")
        div.add(select)
        select.set_option("values", "file|xmlrpc")

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_sync_mode");
            var value = bvr.src_el.value;
            var xmlrpc_el = top.getElement(".spt_xmlrpc_mode");
            var file_el = top.getElement(".spt_file_mode");

            if (value == 'xmlrpc') {
                spt.show(xmlrpc_el);
                spt.hide(file_el);
            }
            else {
                spt.hide(xmlrpc_el);
                spt.show(file_el);
            }
            '''
        })

        div.add(my.get_xmlrpc_mode_wdg())
        div.add(my.get_file_mode_wdg())

        return div
Beispiel #3
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
Beispiel #4
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
Beispiel #5
0
    def get_display(my):

        state = my.get_state()
        search_type = state.get("search_type")
        sobj = my.get_current_sobject()

        if search_type:
            st = search_type
        else:

            st = sobj.get_base_search_type()
        # for inline insert, this should proceed
        #if not sobj:
        #    return ''

        st_suffix = st.split('/', 1)

        if len(st_suffix) == 2:
            st_suffix = st_suffix[1]

        search = Search('sthpw/pipeline')
        search.add_op_filters([('search_type', 'EQ', '/%s' % st_suffix)])

        # takes into account site-wide pipeline
        search.add_project_filter(show_unset=True)
        sobjects = search.get_sobjects()

        codes = [x.get_code() for x in sobjects]
        select = SelectWdg(my.get_input_name())
        select.add_empty_option("-- Default --")
        select.set_option("values", codes)
        if sobj:
            value = sobj.get_value(my.get_name())
            if value:
                select.set_value(value)

        else:
            # only for inline
            behavior = {
                'type':
                'click',
                'cbjs_action':
                'spt.dg_table.select_wdg_clicked( evt, bvr.src_el );'
            }
            select.add_behavior(behavior)

        return select
Beispiel #6
0
    def get_example_display(my):

        div = DivWdg()
        div.add_styles("background: grey; padding: 10px; width: 450px;")
        div.add("<br/><br/>")

        from tactic.ui.container import RoundedCornerDivWdg
        rc_wdg = RoundedCornerDivWdg(corner_size=10)
        # rc_wdg.set_dimensions(width_str="100%", content_height_str='100%', height_str="100%")
        rs0_wdg = ResizeScrollWdg(
            width=300,
            height=200,
            scroll_bar_size_str='thin',
            scroll_expansion='inside',
            # max_content_w=500, max_content_h=400,
            set_max_to_content_size=True,
            min_content_w=100,
            min_content_h=50)
        rs0_wdg.add(my.get_popwin_oversize_content())

        rc_wdg.add(rs0_wdg)
        div.add(rc_wdg)

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

        div.add(
            "<p style='color: black;'>Resize/Scroll Widget example ...</p>")
        rs_wdg = ResizeScrollWdg(width=300,
                                 height=200,
                                 scroll_bar_size_str='thin',
                                 scroll_expansion='inside')
        rs_wdg.add(my.get_popwin_oversize_content())
        div.add(rs_wdg)

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

        div.add( "<p style='color: black;'>Resize/Scroll Widget example WITH NO RESIZE CAPABILITY" \
                 " (just scroll bars) ...</p>" )
        rs2_wdg = ResizeScrollWdg(width=300,
                                  height=200,
                                  scroll_bar_size_str='thin',
                                  scroll_expansion='inside',
                                  no_resize=True)
        rs2_wdg.add(my.get_popwin_oversize_content())
        div.add(rs2_wdg)

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

        popwin_id = "NewPopupWindowTest"
        popwin_title = "New Popup Window Widget Test"
        popwin = PopWindowWdg(top_id=popwin_id,
                              title=popwin_title,
                              width=150,
                              height=150)
        popwin.add(my.get_popwin_oversize_content())
        div.add(popwin)
        pwin_launch = DivWdg()

        pwin_launch.add_styles(
            "cursor: pointer; background-color: red; color: black; border: 1px solid black; width: 100px; height: 50px;"
        )
        pwin_launch.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            'spt.popup.open("' + popwin_id + '");'
        })
        pwin_launch.add("Click to launch New Popup Window")
        div.add(pwin_launch)

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

        test_div = DivWdg()
        test_div.add_styles(
            "background: black; padding: 10px; width: 350px; text-align: center;"
        )

        test_div.add(
            SpanWdg("This black DIV has<br/>text-align set to center"))

        my_table = Table()
        my_table.add_row()
        my_table.add_cell("This").add_styles(
            "border: 1px solid white; padding: 4px;")
        my_table.add_cell("that").add_styles(
            "border: 1px solid white; padding: 4px;")
        my_table.add_cell("and").add_styles(
            "border: 1px solid white; padding: 4px;")
        my_table.add_cell("The").add_styles(
            "border: 1px solid white; padding: 4px;")
        my_table.add_cell("other").add_styles(
            "border: 1px solid white; padding: 4px;")

        test_div.add("<br/><br/>")
        test_div.add(my_table)

        test_div.add("<br/><br/>")
        tmp_div = DivWdg()
        tmp_div.add_styles(
            "width: 200px; background-color: green; color: black; padding: 10px;"
        )
        tmp_div.add("I am a DIV without my margins set")
        test_div.add(tmp_div)

        test_div.add("<br/><br/>")
        tmp_div = DivWdg()
        tmp_div.add_styles(
            "width: 200px; background-color: green; color: black; padding: 10px;"
        )
        tmp_div.center()
        tmp_div.add(
            "I am a DIV with my margins<br/>set using HtmlElement.center()")
        test_div.add(tmp_div)

        test_div.add("<br/><br/>")
        buttons_list = [{
            'label': "Insert",
            'tip': "This is an insert",
            'bvr': {
                'cbjs_action': 'alert("Insert!");'
            }
        }, {
            'label': 'Cancel',
            'tip': 'Cancel',
            'bvr': {
                'cbjs_action': 'alert("Cancel!");'
            }
        }]
        buttons = TextBtnSetWdg(float="",
                                align="center",
                                buttons=buttons_list,
                                spacing=6,
                                size='medium',
                                side_padding=4)
        test_div.add(buttons)

        div.add(test_div)

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

        buttons_list = [
            {
                'label': 'One',
                'tip': 'Button One',
                'bvr': {
                    'cbjs_action': 'alert("First button!");'
                }
            },
            {
                'label': 'Two',
                'tip': 'Button Two',
                'bvr': {
                    'cbjs_action': 'alert("Second button!");'
                }
            },
            {
                'label': 'Three',
                'tip': 'Button Three',
                'bvr': {
                    'cbjs_action': 'alert("Third button!");'
                }
            },
            {
                'label': 'Four',
                'tip': 'Button Four',
                'bvr': {
                    'cbjs_action': 'alert("Fourth button!");'
                }
            },
        ]

        txt_btn_set = TextBtnSetWdg(float='right',
                                    buttons=buttons_list,
                                    spacing=6,
                                    size='large',
                                    side_padding=4)
        txt_btn_set.get_btn_by_label('Three').add_behavior({
            'type':
            'click_up',
            'modkeys':
            'SHIFT',
            'cbjs_action':
            'alert("SHIFT happened!");'
        })
        div.add(txt_btn_set)

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

        d1 = my.get_simple_div(
            "Drop Zone (runs cbjs_action of drag-drop element on drop)", None)
        d1.set_attr("SPT_ACCEPT_DROP", "Qweejibo")
        d1.add_behavior({
            'type': 'hover',
            'mod_styles': 'background-color: green;'
        })

        table1 = Table()
        tr = table1.add_row()
        tr.add_behavior({
            'type': 'hover',
            'mod_styles': 'background-color: #f11; color: green'
        })

        td = table1.add_cell('what')
        #td.add_behavior( { 'type': 'hover', 'mod_styles': 'background-color: orange;' } )
        td = table1.add_cell('is')
        #td.add_behavior( { 'type': 'hover', 'mod_styles': 'background-color: green;' } )
        div.add(table1)

        # d2 = my.get_simple_div( "Pick Up!", "white" )
        d2 = my.get_simple_div("Override with 'accept_drop' behavior!", None)
        d2.add_looks("menu")

        # NOTE: with 'accept_drop' behavior you do not need to set the "SPT_ACCEPT_DROP" attribute on the
        #       given drop-on element, just need to add the same value to a 'drop_code' attribute in the
        #       'accept_drop' bvr spec (doing this will automatically add it to the SPT_ACCEPT_DROP at
        #       behavior construction time
        # so we do not need this here --> d2.set_attr("SPT_ACCEPT_DROP","Qweejibo")
        d2.add_behavior({
            'type': 'accept_drop',
            'cbjs_action': 'log.debug("Override #1 on Qweejibo");',
            'drop_code': 'Qweejibo'
        })
        d2.add_behavior({
            'type': 'accept_drop',
            'cbjs_action': '''
                log.debug("Override #2 on Qweejibo");
                var el = bvr._drop_source_bvr.src_el;
                el.setStyle("background-color", "white");
            ''',
            'drop_code': 'Qweejibo'
        })

        d2.add_behavior({'type': 'hover', 'add_looks': 'menu_hover'})
        d2.add_behavior({
            'type': 'hover',
            'mod_styles': 'border: 1px solid red;',
            'drag_drop_codes': 'Qweejibo',
        })

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

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

        btn = DivWdg()
        btn.add("TEST JS LOG TIME")
        btn.add_styles(
            "padding: 4px; width: 150px; cursor: pointer; background: red; color: white; "
            + "border: 1px solid white;")
        btn.add_behavior({
            'type': 'click',
            'cbjs_action': 'spt.js_log.test_perf();'
        })

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

        dragme = DivWdg()
        dragme.add_styles( "background: blue; padding: 10px; width: 200px; border: 1px solid black; " \
                           "position: absolute; top: 200px; left: 400px; cursor: default;" )
        dragme.add("Click me OR Drag me!")

        # dragme.add_behavior( { 'type': 'drag', 'drag_el': '@', 'use_default_cbs': 'true',
        #                        'cbjs_action_onnomotion': 'alert("I\'ve been clicked!");' } )

        dragme.add_behavior({
            'type':
            'smart_drag',
            'drag_el':
            '@',
            'use_copy':
            'true',
            'use_delta':
            'true',
            'dx':
            1,
            'dy':
            1,
            'drop_code':
            'Qweejibo',
            'copy_styles':
            'background: red; opacity: .3;',
            'cbjs_action':
            'alert("Got Qweejibo");',
            'cbjs_action_onnomotion':
            'alert("I\'ve been clicked!");'
        })

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

        select = SelectWdg("OnChangeTestSelectWidget")
        select.add_behavior({
            'type':
            'change',
            'cbjs_preaction':
            '''
                alert("Click OK then see Web Client Output Log for 'change' behavior activity");
                log.debug("[preaction] My value is now: "+bvr.src_el.value);
                ''',
            'cbjs_action':
            'log.debug("[action] My value is now: "+bvr.src_el.value);',
            'cbjs_postaction':
            'log.debug("[postaction] My value is now: "+bvr.src_el.value);'
        })
        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            'log.debug("ORIG - stacked change behavior #2!");'
        })
        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            'log.debug("ORIG - stacked change behavior #3!");'
        })
        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            'log.debug("ORIG - stacked change behavior #4!");'
        })
        select.set_option("values", "One|Day|In|Your|Life")
        select.set_value("Life")

        # Test for set_behavior override with stacked onchange behaviors ...
        '''
        select.set_behavior( {'type': 'change', 'cbjs_action': 'alert("This is what me gots: "+bvr.src_el.value);'} );
        select.add_behavior( {'type': 'change', 'cbjs_action': 'log.debug("OVERRIDE - stacked change behavior #5!");'} );
        select.add_behavior( {'type': 'change', 'cbjs_action': 'log.debug("OVERRIDE - stacked change behavior #6!");'} );
        '''

        div.add(select)

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

        click_core_div = DivWdg()
        click_core_div.add_styles(
            "background-color: blue; color: white; border: 1px solid black; padding: 10px"
        )
        click_core_div.add_styles("cursor: pointer;")
        click_core_div.add("Click me for preaction, action, postaction test")
        click_core_div.add_behavior({
            'type':
            'click',
            'cbjs_preaction':
            '''
                alert("Click OK then see Web output log for 'click' behavior activity");
                log.debug("Click pre-action");
            ''',
            'cbjs_action':
            'log.debug("Click action");',
            'cbjs_postaction':
            'log.debug("Click post-action");'
        })

        div.add(click_core_div)

        div.add("<br/><br/>")
        override = DivWdg()
        override.add_styles(
            "padding: 4px; background: white; color: black; border: 1px solid black; cursor: pointer;"
        )
        override.add("Set Behavior Override Test")

        bvr = {
            'type': 'click',
            'modkeys': 'SHIFT',
            'cbjs_action': 'alert("Load ONE");'
        }
        override.add_behavior(bvr)

        bvr = {
            'type': 'click',
            'modkeys': 'SHIFT',
            'cbjs_action': 'alert("Load ONE OVERRIDDEN!");'
        }
        override.set_behavior(bvr)

        div.add(override)

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

        div1 = DivWdg()
        div1.add_styles(
            "background: #444477; border: solid 1px black; padding: 10px;")
        div1.add("Div1")
        div1.set_id("Div_1")

        div2 = DivWdg()
        div2.add_styles(
            "background: #4444BB; border: solid 1px black; padding: 10px; cursor: pointer;"
        )
        div2.add("Div2")
        div2.set_id("Div_2")

        # div2.add_behavior( { 'type': 'click_up', 'cbjs_action': '$("Div_3").inject("Div_2","after");' } )
        div2.add_behavior({
            'type': 'click_up',
            'cbjs_action': '$("Div_3").inject("Div_1","bottom");'
        })

        div1.add(div2)

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

        div3 = DivWdg()
        div3.add_styles(
            "background: #4444FF; border: solid 1px black; padding: 10px;")
        div3.add("Div3")
        div3.set_id("Div_3")

        div.add(div3)

        return div
    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
Beispiel #8
0
    def get_example_display(self):

        div = DivWdg()
        div.add_styles("background: grey; padding: 10px; width: 450px;")
        div.add( "<br/><br/>" )

        from tactic.ui.container import RoundedCornerDivWdg
        rc_wdg = RoundedCornerDivWdg(corner_size=10)
        # rc_wdg.set_dimensions(width_str="100%", content_height_str='100%', height_str="100%")
        rs0_wdg = ResizeScrollWdg( width=300, height=200, scroll_bar_size_str='thin', scroll_expansion='inside',
                                   # max_content_w=500, max_content_h=400,
                                   set_max_to_content_size=True,
                                   min_content_w=100, min_content_h=50 )
        rs0_wdg.add( self.get_popwin_oversize_content() )

        rc_wdg.add( rs0_wdg )
        div.add( rc_wdg )

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

        div.add( "<p style='color: black;'>Resize/Scroll Widget example ...</p>" )
        rs_wdg = ResizeScrollWdg( width=300, height=200, scroll_bar_size_str='thin', scroll_expansion='inside' )
        rs_wdg.add( self.get_popwin_oversize_content() )
        div.add( rs_wdg )

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

        div.add( "<p style='color: black;'>Resize/Scroll Widget example WITH NO RESIZE CAPABILITY" \
                 " (just scroll bars) ...</p>" )
        rs2_wdg = ResizeScrollWdg( width=300, height=200, scroll_bar_size_str='thin', scroll_expansion='inside',
                                  no_resize=True )
        rs2_wdg.add( self.get_popwin_oversize_content() )
        div.add( rs2_wdg )

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

        popwin_id = "NewPopupWindowTest"
        popwin_title = "New Popup Window Widget Test"
        popwin = PopWindowWdg(top_id=popwin_id, title=popwin_title, width=150, height=150)
        popwin.add( self.get_popwin_oversize_content() )
        div.add( popwin )
        pwin_launch = DivWdg()

        pwin_launch.add_styles("cursor: pointer; background-color: red; color: black; border: 1px solid black; width: 100px; height: 50px;")
        pwin_launch.add_behavior( {'type': 'click_up', 'cbjs_action': 'spt.popup.open("' + popwin_id + '");'} )
        pwin_launch.add("Click to launch New Popup Window")
        div.add( pwin_launch )



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

        test_div = DivWdg()
        test_div.add_styles("background: black; padding: 10px; width: 350px; text-align: center;")

        test_div.add( SpanWdg("This black DIV has<br/>text-align set to center") )

        my_table = Table()
        my_table.add_row()
        my_table.add_cell("This").add_styles("border: 1px solid white; padding: 4px;")
        my_table.add_cell("that").add_styles("border: 1px solid white; padding: 4px;")
        my_table.add_cell("and").add_styles("border: 1px solid white; padding: 4px;")
        my_table.add_cell("The").add_styles("border: 1px solid white; padding: 4px;")
        my_table.add_cell("other").add_styles("border: 1px solid white; padding: 4px;")

        test_div.add( "<br/><br/>" )
        test_div.add( my_table )

        test_div.add( "<br/><br/>" )
        tmp_div = DivWdg()
        tmp_div.add_styles("width: 200px; background-color: green; color: black; padding: 10px;")
        tmp_div.add("I am a DIV without self margins set")
        test_div.add(tmp_div)

        test_div.add( "<br/><br/>" )
        tmp_div = DivWdg()
        tmp_div.add_styles("width: 200px; background-color: green; color: black; padding: 10px;")
        tmp_div.center()
        tmp_div.add("I am a DIV with self margins<br/>set using HtmlElement.center()")
        test_div.add(tmp_div)

        test_div.add( "<br/><br/>" )
        buttons_list = [
            {
                'label': "Insert",
                'tip': "This is an insert",
                'bvr': {'cbjs_action': 'alert("Insert!");'}
            },
            {
                'label': 'Cancel',
                'tip': 'Cancel',
                'bvr': {'cbjs_action': 'alert("Cancel!");'}
            }
        ]
        buttons = TextBtnSetWdg( float="", align="center", buttons=buttons_list, spacing=6,
                                 size='medium', side_padding=4 )
        test_div.add( buttons )

        div.add(test_div)



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

        buttons_list = [
                {'label': 'One', 'tip': 'Button One', 'bvr': {'cbjs_action': 'alert("First button!");'} },
                {'label': 'Two', 'tip': 'Button Two', 'bvr': {'cbjs_action': 'alert("Second button!");'} },
                {'label': 'Three', 'tip': 'Button Three', 'bvr': {'cbjs_action': 'alert("Third button!");'} },
                {'label': 'Four', 'tip': 'Button Four', 'bvr': {'cbjs_action': 'alert("Fourth button!");'} },
        ]

        txt_btn_set = TextBtnSetWdg( float='right', buttons=buttons_list, spacing=6, size='large', side_padding=4 )
        txt_btn_set.get_btn_by_label('Three').add_behavior( {'type': 'click_up', 'modkeys': 'SHIFT',
                                                             'cbjs_action': 'alert("SHIFT happened!");'} )
        div.add( txt_btn_set )


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

        d1 = self.get_simple_div( "Drop Zone (runs cbjs_action of drag-drop element on drop)", None )
        d1.set_attr("SPT_ACCEPT_DROP","Qweejibo")
        d1.add_behavior( { 'type': 'hover', 'mod_styles': 'background-color: green;' } )


        table1 = Table()
        tr = table1.add_row()
        tr.add_behavior( { 'type': 'hover', 'mod_styles': 'background-color: #f11; color: green' } )

        td = table1.add_cell('what')
        #td.add_behavior( { 'type': 'hover', 'mod_styles': 'background-color: orange;' } )
        td = table1.add_cell('is')
        #td.add_behavior( { 'type': 'hover', 'mod_styles': 'background-color: green;' } )
        div.add(table1)

        # d2 = self.get_simple_div( "Pick Up!", "white" )
        d2 = self.get_simple_div( "Override with 'accept_drop' behavior!", None )
        d2.add_looks("menu");

        # NOTE: with 'accept_drop' behavior you do not need to set the "SPT_ACCEPT_DROP" attribute on the
        #       given drop-on element, just need to add the same value to a 'drop_code' attribute in the
        #       'accept_drop' bvr spec (doing this will automatically add it to the SPT_ACCEPT_DROP at
        #       behavior construction time
        # so we do not need this here --> d2.set_attr("SPT_ACCEPT_DROP","Qweejibo")
        d2.add_behavior( { 'type': 'accept_drop', 'cbjs_action': 'log.debug("Override #1 on Qweejibo");',
                            'drop_code': 'Qweejibo' } )
        d2.add_behavior( { 'type': 'accept_drop',
            'cbjs_action': '''
                log.debug("Override #2 on Qweejibo");
                var el = bvr._drop_source_bvr.src_el;
                el.setStyle("background-color", "white");
            ''',
            'drop_code': 'Qweejibo' } )

        d2.add_behavior( { 'type': 'hover', 'add_looks': 'menu_hover' } )
        d2.add_behavior( { 'type': 'hover', 'mod_styles': 'border: 1px solid red;',
                            'drag_drop_codes': 'Qweejibo',
                            } )

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


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

        btn = DivWdg()
        btn.add("TEST JS LOG TIME")
        btn.add_styles("padding: 4px; width: 150px; cursor: pointer; background: red; color: white; " + 
                        "border: 1px solid white;")
        btn.add_behavior( { 'type': 'click', 'cbjs_action': 'spt.js_log.test_perf();' } )

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

        dragme = DivWdg()
        dragme.add_styles( "background: blue; padding: 10px; width: 200px; border: 1px solid black; " \
                           "position: absolute; top: 200px; left: 400px; cursor: default;" )
        dragme.add( "Click me OR Drag me!" )


        # dragme.add_behavior( { 'type': 'drag', 'drag_el': '@', 'use_default_cbs': 'true',
        #                        'cbjs_action_onnomotion': 'alert("I\'ve been clicked!");' } )

        dragme.add_behavior( { 'type': 'smart_drag', 'drag_el': '@',
                               'use_copy': 'true',
                               'use_delta': 'true', 'dx': 1, 'dy': 1,
                               'drop_code': 'Qweejibo',
                               'copy_styles': 'background: red; opacity: .3;',
                               'cbjs_action': 'alert("Got Qweejibo");',
                               'cbjs_action_onnomotion': 'alert("I\'ve been clicked!");' } )


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

        select = SelectWdg("OnChangeTestSelectWidget")
        select.add_behavior( {'type': 'change',
            'cbjs_preaction': '''
                alert("Click OK then see Web Client Output Log for 'change' behavior activity");
                log.debug("[preaction] My value is now: "+bvr.src_el.value);
                ''',
            'cbjs_action': 'log.debug("[action] My value is now: "+bvr.src_el.value);',
            'cbjs_postaction': 'log.debug("[postaction] My value is now: "+bvr.src_el.value);'
        } );
        select.add_behavior( {'type': 'change', 'cbjs_action': 'log.debug("ORIG - stacked change behavior #2!");'} );
        select.add_behavior( {'type': 'change', 'cbjs_action': 'log.debug("ORIG - stacked change behavior #3!");'} );
        select.add_behavior( {'type': 'change', 'cbjs_action': 'log.debug("ORIG - stacked change behavior #4!");'} );
        select.set_option("values", "One|Day|In|Your|Life")
        select.set_value("Life")

        # Test for set_behavior override with stacked onchange behaviors ...
        '''
        select.set_behavior( {'type': 'change', 'cbjs_action': 'alert("This is what me gots: "+bvr.src_el.value);'} );
        select.add_behavior( {'type': 'change', 'cbjs_action': 'log.debug("OVERRIDE - stacked change behavior #5!");'} );
        select.add_behavior( {'type': 'change', 'cbjs_action': 'log.debug("OVERRIDE - stacked change behavior #6!");'} );
        '''

        div.add(select)

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

        click_core_div = DivWdg()
        click_core_div.add_styles( "background-color: blue; color: white; border: 1px solid black; padding: 10px" )
        click_core_div.add_styles( "cursor: pointer;" )
        click_core_div.add( "Click me for preaction, action, postaction test" )
        click_core_div.add_behavior( {'type': 'click',
            'cbjs_preaction': '''
                alert("Click OK then see Web output log for 'click' behavior activity");
                log.debug("Click pre-action");
            ''',
            'cbjs_action': 'log.debug("Click action");',
            'cbjs_postaction': 'log.debug("Click post-action");'
        } )

        div.add( click_core_div )


        div.add( "<br/><br/>" )
        override = DivWdg()
        override.add_styles( "padding: 4px; background: white; color: black; border: 1px solid black; cursor: pointer;" )
        override.add( "Set Behavior Override Test" )

        bvr = { 'type': 'click', 'modkeys': 'SHIFT', 'cbjs_action': 'alert("Load ONE");' }
        override.add_behavior( bvr )

        bvr = { 'type': 'click', 'modkeys': 'SHIFT', 'cbjs_action': 'alert("Load ONE OVERRIDDEN!");' }
        override.set_behavior( bvr )

        div.add(override)

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

        div1 = DivWdg()
        div1.add_styles("background: #444477; border: solid 1px black; padding: 10px;")
        div1.add("Div1")
        div1.set_id("Div_1")

        div2 = DivWdg()
        div2.add_styles("background: #4444BB; border: solid 1px black; padding: 10px; cursor: pointer;")
        div2.add("Div2")
        div2.set_id("Div_2")

        # div2.add_behavior( { 'type': 'click_up', 'cbjs_action': '$("Div_3").inject("Div_2","after");' } )
        div2.add_behavior( { 'type': 'click_up', 'cbjs_action': '$("Div_3").inject("Div_1","bottom");' } )

        div1.add( div2 )

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

        div3 = DivWdg()
        div3.add_styles("background: #4444FF; border: solid 1px black; padding: 10px;")
        div3.add("Div3")
        div3.set_id("Div_3")

        div.add(div3)

        return div
Beispiel #9
0
    def get_display(my):

        top = my.top
        top.add_class("spt_db_config_top")
        top.add_style("width: 430px")
        top.add_style("min-height: 500")
        top.add_style("padding: 15px")
        top.add_style("margin-left: auto")
        top.add_style("margin-right: auto")
        top.add_color("background", "background", -10)
        top.add_border()

        title_wdg = DivWdg()
        top.add(title_wdg)
        title_wdg.add("System Configuration Setup")
        title_wdg.add_style("font-size: 20px")


        top.add("<hr/>")

        top.add("<i style='opacity: 0.5'>%s</i><br/>" % Config.get_config_path())
        top.add("<br/>")


        checkin_keys=Config.get_section_values('checkin')
        checkin_keys=checkin_keys.keys()
        save_button = my.get_save_button(checkin_keys)
        top.add(save_button)
        vendor = Config.get_value("database", "vendor")

        title_wdg = DivWdg()
        top.add(title_wdg)
        title_wdg.add("<b>Database Setup</b>")
        title_wdg.add_style("margin-bottom: 10px")


        db_select = SelectWdg("database/vendor")
        db_select.set_option("labels", "SQLite|PostgreSQL|MySQL|Oracle|SQLServer")
        db_select.set_option("values", "Sqlite|PostgreSQL|MySQL|Oracle|SQLServer")

        db_select.set_value(vendor)



        db_select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''

        var key;
        if (bvr.src_el.value == 'Sqlite') {
            key = 'Sqlite';
        }
        else {
            key = 'Other';
        }

        var top = bvr.src_el.getParent(".spt_db_config_top");
        var options_els = top.getElements(".spt_db_options");
        for (var i = 0; i < options_els.length; i++) {
            var vendor = options_els[i].getAttribute("spt_vendor");
            if (vendor == key) {
                spt.show(options_els[i]);
            }
            else {
                spt.hide(options_els[i]);
            }

        }
        '''
        } )
 
        option_div = DivWdg()
        top.add(option_div)
        option_div.add("Vendor: ")
        option_div.add(db_select)
        option_div.add_style("margin: 20px")

        sqlite_wdg = my.get_sqlite_wdg()
        option_div.add(sqlite_wdg)
        otherdb_wdg = my.get_otherdb_wdg()
        option_div.add(otherdb_wdg)

        if vendor == 'Sqlite':
            otherdb_wdg.add_style("display: none")
            sqlite_wdg.add_style("display", "")
        else:
            otherdb_wdg.add_style("display", "")
            sqlite_wdg.add_style("display: none")


        test_button = ActionButtonWdg(title="<< Test >>", tip="Test connecting to database")
        option_div.add(test_button)
        test_button.add_style("margin-left: auto")
        test_button.add_style("margin-right: auto")
        test_button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_db_config_top");
        var values = spt.api.Utility.get_input_values(top, null, false);
        var class_name = 'tactic.ui.startup.DbConfigCbk';
        var server = TacticServerStub.get();
        var kwargs = {};
        var ret_val = server.execute_cmd(class_name, kwargs, values);
        var info = ret_val.info;
        if (info.error) {
            spt.error(info.error);
        }
        else {
            spt.info("Connection to database successful");
        }
        '''
        } )


        #
        # Install
        #
        top.add("<hr/>")

        top.add("<br/>")

        title = "Installation"

        category = "install"

        options = ['default_project']

        if 'tmp_dir' not in options:
            options.append('tmp_dir')

        top.add( my.configure_category(title, category, options) )

        top.add("<hr/>")

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

        title = "Asset Management Setup"
        category = "checkin"


        options=checkin_keys[:]

        my._remove_item_from_list(options,'win32_server_handoff_dir')
        my._remove_item_from_list(options,'linux_server_handoff_dir')

        if os.name == "nt":
            options.append('win32_server_handoff_dir')
        else:
            options.append('linux_server_handoff_dir')


        top.add( my.configure_category(title, category, options) )

        top.add("<hr/>")
        top.add("<br/>")

        title = "Mail Server "
        category = "services"
        options = ['mailserver', 'mail_user', 'mail_password', 'mail_port', 'mail_tls_enabled', 'mail_sender_disabled']
        top.add( my.configure_category(title, category, options) )

        top.add("<hr/>")

        title = "Services"
        category = "services"
        options = ['process_count', 'process_time_alive', 'thread_count', 'python_path']
        top.add( my.configure_category(title, category, options) )

        top.add("<hr/>")

        title = "Look and Feel"
        category = "look"
        options = ['palette']
        top.add( my.configure_category(title, category, options) )

        #wizard_wdg = WizardWdg()
        #top.add(wizard_wdg)
        #wizard_wdg.add(DivWdg("cow"), "cow")
        #wizard_wdg.add(DivWdg("pig"), "pig")
        #wizard_wdg.add(DivWdg("dog"), "dog")
        return top
Beispiel #10
0
    def get_action_wdg(my, name):
        '''get the action widget for ui option of note entry'''

        note_wdg = DivWdg()
        note_wdg.add_style("padding-top: 3px")

        # note options

        option = DivWdg(css='spt_uber_note_option')
        cb = CheckboxWdg('is_private')
        #cb.set_default_checked()

        checkbox_name = 'note_master_private_cb'
        master_cb = CheckboxWdg(checkbox_name)
        if master_cb.is_checked():
            cb.set_default_checked()

        option.add_style('margin-right', '5px')
        option.add_style('float', 'right')

        option.add(cb)
        option.add('private')

        #commit = TextBtnWdg(label='save', size='small')
        commit = ActionButtonWdg(title='save', tip="Save Changes")
        commit.add_style('margin-top: -5px')
        commit.add_style('margin-bottom: 5px')
        commit.add_style('float: right')
        commit.add_behavior({
            'type': 'click_up',
            'cbjs_action': '''
            var td = bvr.src_el.getParent(".spt_table_td");
            var text = td.getElement(".spt_note_text");
            text.blur();
            spt.dg_table.update_row(evt, bvr);
            td.setStyle('background-color','');
            ''',
            'cell_only': True
        })
        #commit.set_scale("0.75")

        # do some gynastics to handle a refresh.
        if my.parent_wdg:
            info = my.parent_wdg.get_aux_info()
            sobject_dict = info.get('sobjects')
            sobject = sobject_dict.get(my.get_name())
            parent = info.get('parent')
        else:
            sobject = None
            parent = None

        if not sobject:

            if my.parent_key:
                parent = SearchKey.get_by_search_key(my.parent_key)
            # get the latest note
            #search_key = my.kwargs.get("search_key")
            #if search_key:
            #    sobject = SearchKey.get_by_search_key(search_key)

            search = Search('sthpw/note')
            search.add_parent_filter(parent)
            search.add_filter('context', name)
            # Make the assumption that the last one entered is by timestamp
            search.add_order_by('timestamp desc')
            sobject = search.get_sobject()

        # Show a history of notes
        if sobject:
            history = ActionButtonWdg(title='history', tip="Show note history")
            #history = TextBtnWdg(label='history', size='small')
            #history.get_top_el().add_style("margin-left: 4px")
            #history.get_top_el().add_style('float: left')
            history.add_style("float: left")
            history.add_style("margin-top: -5px")
            history.add_style("margin-bottom: 5px")
            note_wdg.add(history)

            my.parent_key = SearchKey.get_by_sobject(parent)

            context = name
            filter = '[{"prefix":"main_body","main_body_enabled":"on","main_body_column":"context","main_body_relation":"is","main_body_value":"%s"}]' % context
            history.add_behavior({
                'type': 'click_up',
                'cbjs_action': "spt.popup.get_widget(evt, bvr)",
                'options': {
                    'class_name': 'tactic.ui.panel.ViewPanelWdg',
                    'title': 'Notes History',
                    'popup_id': 'Notes_History_%s' % context
                },
                'args': {
                    'search_type': 'sthpw/note',
                    'view': 'summary',
                    'parent_key': my.parent_key,
                    'filter': filter,
                }
            })

        note_wdg.add(commit)
        note_wdg.add(option)

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

        from pyasm.biz import PrefSetting
        quick_text = PrefSetting.get_value_by_key('quick_text')
        if quick_text:
            quick_sel = SelectWdg('quick_text', label='quick: ')
            quick_sel.set_option('values', quick_text)
            quick_sel.add_empty_option('-- text --', '')
            quick_sel.add_behavior({
                'type':
                'change',
                'cbjs_action':
                '''var val = bvr.src_el.value; 
            var text=bvr.src_el.getParent('.spt_note_top').getElement('.spt_note_text')
            text.value = text.value + val;
            '''
            })

            note_wdg.add(SpanWdg(quick_sel, css='small'))
            note_wdg.add(HtmlElement.br(2))
        # Show the last note
        note_wdg.add("<i>Last note</i> ")

        if sobject:
            timestamp = sobject.get_value("timestamp")
            timestamp = parser.parse(timestamp)
            timestamp = timestamp.strftime("%m/%d %H:%M")
            timestamp_div = SpanWdg()
            timestamp_div.add("(%s)" % timestamp)
            note_wdg.add(timestamp_div)
            timestamp_div.add_style("font-size: 11px")
            timestamp_div.add_style("font-style: italic")

            # add a private tag
            access = sobject.get_value("access")
            if access == 'private':
                private = SpanWdg()
                #private.add_style('float: right')
                private.add(" &nbsp; <i>-- private --</i>")
                note_wdg.add(private)

        hr = DivWdg("<hr/>")
        hr.add_style("height: 1px")
        hr.add_style("margin-top: -5px")
        note_wdg.add(hr)

        div = DivWdg()
        note_wdg.add(div)
        div.add_style("max-height", "50px")
        div.add_style("overflow", "auto")
        div.add_style("padding: 3px")
        if sobject:
            value = sobject.get_value('note')
            from pyasm.web import WikiUtil
            value = WikiUtil().convert(value)
            div.add(value)

        else:
            no_notes = DivWdg()
            div.add(no_notes)
            no_notes.add('<i> -- No Notes --</i>')
            no_notes.add_style("font-size: 11px")
            no_notes.add_style("opacity: 0.7")

        return note_wdg
    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
Beispiel #12
0
    def get_display(my):
        # if no filters are defined, then display nothing
        if not my.filters:
            return Widget()

        #filter_top = DivWdg(css="maq_search_bar")
        filter_top = DivWdg()
        filter_top.add_color("color", "color")
        filter_top.add_color("background", "background", -5)
        filter_top.add_style("padding: 5px")
        filter_top.add_style("min-width: 800px")
        filter_top.add_border()
        my.set_as_panel(filter_top)

        # TEST link to help for search widget
        help_button = ActionButtonWdg(title="?",
                                      tip="Search Documentation",
                                      size='small')
        filter_top.add(help_button)
        help_button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.help.set_top();
            spt.help.load_alias("search-quickstart|what-is-searching|search-interface|search-compound|search-expressions");
            '''
        })
        help_button.add_style("float: right")

        # this id should be removed
        filter_top.set_id("%s_search" % my.prefix)
        filter_top.add_class("spt_search")

        for name, value in my.kwargs.items():
            filter_top.set_attr("spt_%s" % name, value)

        #filter_top.add(my.statement)
        popup = my.get_retrieve_wdg()
        filter_top.add(popup)
        popup = my.get_save_wdg()
        filter_top.add(popup)

        display = my.kwargs.get('display')

        # Add a number of filters indicator
        div = DivWdg()
        div.add_class("spt_search_num_filters")
        div.add_style("float: right")
        div.add_style("font-size: 0.9em")
        div.add_style("margin: 0 10 0 10")
        #search_summary.add(div)
        filter_top.add(div)

        if my.num_filters_enabled:
            msg = "[%s] filter/s" % my.num_filters_enabled
            icon = IconWdg(msg, IconWdg.DOT_GREEN)
            div.add(icon)
            div.add("%s" % msg)

        filter_div = DivWdg()
        filter_div.set_id("search_filters")
        filter_div.add_class("spt_search_filters")

        # TODO: disabling for now
        # add the action buttons
        #action_wdg =  my.get_action_wdg()
        #action_wdg.add_style("text-align: right")
        #filter_div.add( action_wdg )
        # add the top
        display_str = 'block'
        if not display:
            display_str = 'none'
        filter_div.add_style("display: %s" % display_str)

        search_wdg = my.get_search_wdg()

        prefix = "filter_mode"
        if my.prefix_namespace:
            prefix = '%s_%s' % (my.prefix_namespace, prefix)
        hidden = HiddenWdg("prefix", prefix)

        match_div = DivWdg()
        match_div.add(hidden)
        match_div.add_class('spt_search_filter')

        palette = match_div.get_palette()
        bg_color = palette.color('background')
        light_bg_color = palette.color('background', modifier=+10)

        select = SelectWdg("filter_mode")
        select.add_style("width: 110px")

        select.add_class("spt_search_filter_mode")
        select.set_persist_on_submit(prefix)
        select.remove_empty_option()
        # for Local search, leave out compound search for now
        if my.kwargs.get('prefix_namespace'):
            select.set_option("labels", "Match all|Match any")
            select.set_option("values", "and|or")
        else:
            select.set_option("labels", "Match all|Match any|Compound")
            select.set_option("values", "and|or|custom")
        #select.set_option("labels", "all|any")
        #select.set_option("values", "and|or")

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
        var display = bvr.src_el.value == 'custom';;

        var top = bvr.src_el.getParent(".spt_search");
        var ops = top.getElements(".spt_op");
        for (var i = 0; i < ops.length; i++) {
            var op = ops[i];
            var element = op.getElement(".spt_op_display");
            var value = op.getAttribute("spt_op");
            if (display) {
                element.innerHTML = value;
                var level = op.getAttribute("spt_level");
                if (level == 1) {
                    element.setStyle("background", "%s")
                    element.setStyle("padding", "4px")
                }
            } else {
                element.innerHTML = '&nbsp;';
                element.setStyle("background", "%s")
                element.setStyle("padding", "1px")
            }
        }
        ''' % (light_bg_color, bg_color)
        })

        match_div.add(select)
        match_div.add_color("color", "color2")
        #match_div.add(" on the following")
        #hint = HintWdg( "An 'AND' operation is always applied to each category below. " \
        #                "This controls only the filters within each category." )
        #match_div.add(hint)
        #match_div.add('<br/>')
        #match_div.add_style("padding-top: 5px")

        filter_div.add(search_wdg)
        search_wdg.add_style("float: left")
        filter_div.add(match_div)

        filter_div.add(HtmlElement.br())

        filters_div = DivWdg()
        filters_div.add_style("margin: 0 -6 0 -6")

        security = Environment.get_security()

        # add all the filters
        for filter in my.filters:
            element_name = filter.get_name()

            if not security.check_access("search", element_name, "view"):
                continue

            # no need to create it again
            #filter = my.config.get_display_widget(element_name)
            div = DivWdg()
            filters_div.add(div)

            div.add_class("hand")
            class_suffix = element_name.replace(' ', '_')
            cbjs_action = 'var el=spt.get_cousin(bvr.src_el,".spt_search",".spt_filter_%s");spt.simple_display_toggle(el);' % class_suffix
            div.add_behavior({'type': 'click_up', 'cbjs_action': cbjs_action})
            div.add_color("color", "color", +5)
            #div.add_gradient("background", "background", -5, -5)
            div.add_style("margin-top: -1px")
            div.add_style("height: 18px")

            div.add_border()
            div.add_style("padding: 8px 5px")
            div.add_style("whitespace: nowrap")

            if element_name in ["Parent", 'Children']:
                swap = SwapDisplayWdg.get_triangle_wdg()
            else:
                swap = SwapDisplayWdg.get_triangle_wdg()
                swap.set_off()
            swap.add_action_script(cbjs_action)

            div.add_event("onclick", swap.get_swap_script())
            div.add(swap)
            div.add_class("SPT_DTS")
            div.add(element_name)

            div = DivWdg()
            div.add_class("spt_filter_%s" % class_suffix)

            if element_name in ["Parent", 'Children']:
                div.add_style("display: none")
            else:
                div.add_style("display: block")

            #div.add_style("background-color: #333")
            div.add_color("background", "background")
            div.add_border()
            div.add_style("padding: 10px 8px")
            div.add_style("margin-top: -1px")
            #div.add_style("margin-left: 20px")
            #div.add_style("width: 660")
            div.add(filter)
            filters_div.add(div)

        filter_div.add(filters_div)

        buttons_div = DivWdg()
        buttons_div.add_style("margin-top: 7px")
        buttons_div.add_style("margin-bottom: 7px")
        search_wdg = my.get_search_wdg()
        search_wdg.add_style("margin: 15px auto")
        buttons_div.add(search_wdg)
        filter_div.add(buttons_div)

        filter_top.add(filter_div)

        return filter_top
Beispiel #13
0
    def get_first_row_wdg(my):

        # read the csv file
        #my.file_path = ""

        div = DivWdg(id='csv_import_main')
        div.add_class('spt_panel')
        
        div.add( my.get_upload_wdg() )
        if not my.search_type:
            return div

        if not my.file_path:
            return div


        if not my.file_path.endswith(".csv"):
            div.add('<br/>')
            div.add( "Uploaded file [%s] is not a csv file. Refreshing in 3 seconds. . ."% os.path.basename(my.file_path))
            div.add_behavior( {'type': 'load', \
                                  'cbjs_action': "setTimeout(function() {spt.panel.load('csv_import_main','%s', {}, {\
                                    'search_type_filter': '%s'});}, 3000);" %(Common.get_full_class_name(my), my.search_type) } )
            return div

        if not os.path.exists(my.file_path):
            raise TacticException("Path '%s' does not exist" % my.file_path)

        
        div.add(HtmlElement.br(2))



        # NOT NEEDED:  clear the widget settings before drawing
        #expr = "@SOBJECT(sthpw/wdg_settings['key','EQ','pyasm.widget.input_wdg.CheckboxWdg|column_enabled_']['login','$LOGIN']['project_code','$PROJECT'])"
        #sobjs = Search.eval(expr)
        #for sobj in sobjs:
        #    sobj.delete(log=False)


        div.add( HtmlElement.b("The following is taken from the first line in the uploaded csv file.  Select the appropriate column to match.") )
        div.add(HtmlElement.br())
        """
        text =  HtmlElement.b("Make sure you have all the required columns** in the csv.")
        text.add_style('text-align: left')
        div.add(text)
        """
        div.add(HtmlElement.br(2))
        option_div_top = DivWdg()
        option_div_top.add_color('color','color')
        option_div_top.add_color('background','background', -5)
        option_div_top.add_style("padding: 10px")
        option_div_top.add_border()
        option_div_top.add_style("width: 300px")

        swap = SwapDisplayWdg(title="Parsing Options")
        option_div_top.add(swap)

        option_div_top.add_style("margin-right: 30px")

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

        option_div = DivWdg()
        swap.set_content_id(option_div.set_unique_id() )
        option_div.add_style("display: none")
        option_div.add_style('margin-left: 14px')
        option_div.add_style('margin-top: 10px')
        option_div.add_style("font-weight: bold")
        option_div_top.add(option_div)

        # first row and second row
        #option_div.add( HtmlElement.br() )
        option_div.add(SpanWdg("Use Title Row: ", css='small'))
        title_row_checkbox = CheckboxWdg("has_title")
        title_row_checkbox.set_default_checked()

        title_row_checkbox.add_behavior({'type' : 'click_up',
                    'propagate_evt': 'true',
                    'cbjs_action': "spt.panel.refresh('preview_data',\
                    spt.api.Utility.get_input_values('csv_import_main'))"})
        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(SpanWdg("Use Lowercase Title: ", css='small'))
        lower_title_checkbox = CheckboxWdg("lowercase_title")

        lower_title_checkbox.add_behavior({'type' : 'click_up',
                    'propagate_evt': 'true',
                    'cbjs_action': "spt.panel.refresh('preview_data',\
                    spt.api.Utility.get_input_values('csv_import_main'))"})
        option_div.add(lower_title_checkbox)
        option_div.add( HtmlElement.br(2) )

        option_div.add(SpanWdg("Sample Data Row: ", css='small'))
        data_row_text = SelectWdg("data_row")
        data_row_text.set_option('values', '1|2|3|4|5')
        data_row_text.set_value('1')
        data_row_text.add_behavior({'type' : 'change',
                    'cbjs_action': "spt.panel.refresh('preview_data',\
                    spt.api.Utility.get_input_values('csv_import_main'))"})
        option_div.add(data_row_text)
        option_div.add( HintWdg("Set this as a sample data row for display here") )

        option_div.add( HtmlElement.br(2) )
      
        # encoder
        option_div.add(SpanWdg("Encoder: ", css='small'))
        select_wdg = SelectWdg('encoder')
        select_wdg.set_option('values', ['','utf-8', 'iso_8859-1']) 
        select_wdg.set_option('labels', ['ASCII (default)','UTF-8','Excel ISO 8859-1']) 
        select_wdg.add_behavior({'type' : 'change',
                    'cbjs_action': "spt.panel.refresh('preview_data',\
                    spt.api.Utility.get_input_values('csv_import_main'))"})
        option_div.add(select_wdg)
        option_div.add( HtmlElement.br(2) )


        option_div.add(SpanWdg("Identifying Column: ", css='small'))
        select_wdg = SelectWdg('id_col')
        select_wdg.set_option('empty','true')
        #columns = my.search_type_obj.get_columns()
        columns = SearchType.get_columns(my.search_type)
        
        # make sure it starts off with id, code where applicable
        if 'code' in columns:
            columns.remove('code')
            columns.insert(0, 'code')
        if 'id' in columns:
            columns.remove('id')
            columns.insert(0, 'id')

        select_wdg.set_option('values', columns) 
        option_div.add(select_wdg)
        option_div.add( HintWdg("Set which column to use for identifying an item to update during CSV Import") )
        option_div.add( HtmlElement.br(2) )

        
        # triggers mode
        option_div.add(SpanWdg("Triggers: ", css='small'))
        select_wdg = SelectWdg('triggers_mode')
        select_wdg.set_option('values', ['','False', 'True', 'none']) 
        select_wdg.set_option('labels', ['- Select -','Internal Triggers Only','All Triggers','No Triggers']) 
        select_wdg.add_behavior({'type' : 'change',
                    'cbjs_action': "spt.panel.refresh('preview_data',\
                    spt.api.Utility.get_input_values('csv_import_main'))"})
        option_div.add(select_wdg)
        option_div.add( HtmlElement.br(2) )

        div.add(option_div_top)

        my.has_title = title_row_checkbox.is_checked()
        
        
        # need to somehow specify defaults for columns
        div.add(my.get_preview_wdg())


        return div          
Beispiel #14
0
    def get_display(self):

        top = self.top
        self.set_as_panel(top)

        is_refresh = self.kwargs.get("is_refresh")

        inner = DivWdg()
        top.add(inner)

        title = DivWdg()
        inner.add(title)

        inner.add_class("spt_sync_settings_top")

        inner.add_style("padding: 20px")
        inner.add_color("background", "background")


        server_code = self.get_value("server")

        # get all of the defined servers
        search = Search("sthpw/sync_server")
        servers = search.get_sobjects()
        server_codes = [x.get_code() for x in servers]
        if not server_codes and not server_code:
            msg_div = DivWdg()
            msg_div.add("No servers defined.  Please add a server")
            inner.add(msg_div)
            return top


        if len(server_codes) == 1 or not server_code:
            server_code = server_codes[0]


        select = SelectWdg("server")
        inner.add("Server: ")
        inner.add(select)
        select.set_option("values", server_codes)
        if server_code:
            select.set_value(server_code)
        else:
            return top

        select.add_behavior( { 
            'type': 'change',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_sync_settings_top");
            spt.panel.refresh(top);
            '''
        } )



        project = Project.get()
        project_code = project.get_code()
        if project_code == "admin":
            project_code = ""


        inner.add( self.get_install_wdg(server_code, project_code) )
        inner.add( self.get_dump_wdg(server_code, project_code) )

        if is_refresh:
            return inner
        else:
            return top
Beispiel #15
0
    def get_filter_wdg(self):

        div = DivWdg()
        div.add_style("margin: 10px")
        div.add_class("spt_view_manager_filter")
        div.add('Search Type: ')

        security = Environment.get_security()
        if security.check_access("builtin", "view_site_admin", "allow"):
            select_mode = SearchTypeSelectWdg.ALL
        else:
            select_mode = SearchTypeSelectWdg.ALL_BUT_STHPW
        select = SearchTypeSelectWdg(name='search_type', \
            mode=select_mode)

        behavior = {
            'type':
            'change',
            'cbjs_action':
            '''
            var filter_top = bvr.src_el.getParent(".spt_view_manager_filter");
            var table_top = bvr.src_el.getParent(".spt_table_view_manager_top");
            var manager_top = table_top.getElement(".spt_view_manager_top");

            var input = spt.api.Utility.get_input(filter_top, 'search_type');
            var view_input = spt.api.Utility.get_input(filter_top, 'view');
            var view_input_value = '';
            if (view_input != null) {
                view_input_value = view_input.value;
            }
            var values = {'search_type': input.value, 'view': view_input_value, 'is_refresh': 'true'}; 
            spt.panel.refresh(table_top, values);'''

            #//spt.panel.refresh(manager_top, values);'''
        }
        select.add_behavior(behavior)
        select.set_value(self.search_type)
        div.add(select)

        if not self.search_type:
            return div

        div.add('View: ')
        view_wdg = SelectWdg("view")
        view_wdg.set_value(self.view)
        view_wdg.add_empty_option("-- Select --")
        view_wdg.add_behavior(behavior)
        div.add(view_wdg)

        search = Search("config/widget_config")
        search.add_filter("search_type", self.search_type)
        db_configs = search.get_sobjects()

        views = set()
        for db_config in db_configs:
            view = db_config.get_value("view")
            views.update([view])

        if self.search_type and self.view:
            config_view = WidgetConfigView.get_by_search_type(
                self.search_type, self.view)

            configs = config_view.get_configs()
            for x in configs:
                view = x.get_view()
                file_path = x.get_file_path()
                if view != self.view:
                    continue
                if file_path and file_path.endswith("DEFAULT-conf.xml"):
                    continue
                config_views = x.get_all_views()
                views.update(config_views)

        views_list = list(views)
        views_list.sort()
        view_wdg.set_option("values", views_list)

        return div
Beispiel #16
0
    def get_display(my):
        person_code = ''
        person = None
        person_exists = False
        has_login = '******'
        is_disabled = 'false'
        is_employee = 'false'
        login_obj = None
        password = ''
        existing_login_name = ''
        if 'person_code' in my.kwargs.keys():
            person_code = my.kwargs.get('person_code')
            person_s = Search("twog/person")
            person_s.add_filter('code',person_code)
            person = person_s.get_sobject()
            if person:
                person_exists = True
                login_name = person.get_value('login_name')
                if login_name not in [None,'']:
                    login_s = Search("sthpw/login")
                    login_s.add_filter('login',login_name)
                    login_obj = login_s.get_sobject()
                    if login_obj:
                        has_login = '******'
                        license_type = login_obj.get_value('license_type')
                        password = login_obj.get_value('password')
                        existing_login_name = login_obj.get_value('login')
                        if license_type == 'disabled':
                            is_disabled = 'true'
                        if login_obj.get_value('location') == 'internal':
                            is_employee = 'true'
        first_name = ''
        last_name = ''
        company_code = ''
        title = ''
        email = ''
        alternate_email = ''
        main_phone = ''
        work_phone = ''
        cell_phone = ''
        home_phone = ''
        fax = ''
        country = ''
        state = ''
        city = ''
        zip = ''
        street_address = ''
        suite = ''
        if person_exists:
            first_name = person.get_value('first_name')
            last_name = person.get_value('last_name')
            company_code = person.get_value('company_code')
            title = person.get_value('title')
            email = person.get_value('email')
            alternate_email = person.get_value('alternate_email')
            main_phone = person.get_value('main_phone')
            work_phone = person.get_value('work_phone')
            cell_phone = person.get_value('cell_phone')
            home_phone = person.get_value('home_phone')
            fax = person.get_value('fax')
            country = person.get_value('country')
            state = person.get_value('state')
            city = person.get_value('city')
            zip = person.get_value('zip')
            street_address = person.get_value('street_address')
            suite = person.get_value('suite')

        people_s = Search("twog/person")
        people_s.add_order_by('last_name')
        people_s.add_order_by('first_name')
        people = people_s.get_sobjects()
        peep_sel = SelectWdg("person_selector")
        peep_sel.add_attr('id','person_selector')
        peep_sel.append_option('--Create New Login--','NEW')
        for peep in people:
            peep_sel.append_option('%s, %s' % (peep.get_value('last_name'), peep.get_value('first_name')), peep.get_code())
        if person_exists:
            peep_sel.set_value(person_code)
        peep_sel.add_behavior(my.switch_person())

        company_s = Search("twog/company")
        company_s.add_order_by('name')
        companies = company_s.get_sobjects()
        comp_sel = SelectWdg('company_code')
        comp_sel.add_attr('id','company_code')
        comp_sel.append_option('--Select--','')
        for company in companies:
            comp_sel.append_option(company.get_value('name'), company.get_code())
        if person_exists:
            comp_sel.set_value(company_code)
        
        country_sel = SelectWdg('country')
        country_sel.add_attr('id','country')
        country_sel.append_option('--Select--','')
        for country in my.countries:
            country_sel.append_option(country,country)
        if person_exists:
            my_country = person.get_value('country')
            if my_country in [None,'']:
                my_country = ''
            country_sel.set_value(my_country)

        state_sel = SelectWdg('state')
        state_sel.add_attr('id','state')
        state_sel.append_option('--Select--','')
        for state in my.states:
            state_sel.append_option(state,state)
        if person_exists:
            my_state = person.get_value('state')
            if my_state in [None,'']:
                my_state = ''
            state_sel.set_value(my_state)

        group_tbl = Table()
        group_tbl.add_row()
        group_tbl.add_cell("<b><u>GROUPS:</u></b>")
        login_gs = Search('sthpw/login_group')
        login_gs.add_order_by('login_group')
        login_groups = login_gs.get_sobjects()
        lgs = []
        if has_login == 'true':
            my_lg_s = Search('sthpw/login_in_group')
            my_lg_s.add_filter('login',login_obj.get_value('login'))
            my_lgs = my_lg_s.get_sobjects()
            for ml in my_lgs:
                lgs.append(ml.get_value('login_group'))
        group_tbl.add_row()
        lcount = 0
        for lg in login_groups:
            if lg.get_value('login_group') not in ['client','user','default']:
                if lcount % 7 == 0:
                    group_tbl.add_row()
                this_group = 'false'
                if lg.get_value('login_group') in lgs:
                    this_group = 'true'
                chk = CustomCheckboxWdg(name='group_check_%s' % lcount,value_field=lg.get_value('login_group'),id='group_check_%s' % lcount,checked=this_group,dom_class='group_check',text='%s:' % lg.get_value('login_group').upper(),text_spot='right',text_align='left',nowrap='nowrap',extra1=this_group) 
                group_tbl.add_cell(chk)
                lcount = lcount + 1
        group_tbl.add_row()
        group_tbl.add_cell('&nbsp;')
                

        widget = DivWdg()
        table = Table()
        table.add_attr('class','login_manager_wdg')
        lt = Table()
        ltop = Table()
        red_row = ltop.add_row()
        red_row.add_attr('id','red_row')
        red_row.add_style('background-color: #FF0000;')
        if 'login_name' in my.kwargs.keys():
            ltop.add_cell("<b>Login Name: %s, Password: %s</b>" % (my.kwargs.get('login_name'), my.kwargs.get('login_pass'))) 
        else:
            red_row.add_style('display: none;')
        ltop.add_row()
        emp_checker = CustomCheckboxWdg(name='is_employee',value_field='is_employee',id='is_employee',checked=is_employee,dom_class='is_employee',additional_js=my.switch_has_login(),extra1=is_employee) 
        ltop.add_cell(emp_checker)
        ltop.add_cell('Is Employee?')
        ltop.add_cell('&nbsp;&nbsp;&nbsp;')
        login_checker = CustomCheckboxWdg(name='has_login',value_field='has_login',id='has_login',checked=has_login,dom_class='has_login',extra1=has_login,extra2=existing_login_name) 
        ltop.add_cell(login_checker)
        ltop.add_cell('Enable Login?')
        ltop.add_cell('&nbsp;&nbsp;&nbsp;')
        disabled_checker = CustomCheckboxWdg(name='account_disabled',value_field='account_disabled',id='account_disabled',checked=is_disabled,dom_class='account_disabled',extra1=is_disabled) 
        ltop.add_cell(disabled_checker)
        ltop.add_cell('Account Disabled?')
        group_row = ltop.add_row()
        group_row.add_attr('id','group_row')
        if is_employee != 'true':
            group_row.add_style('display: none;')
        gcell = ltop.add_cell(group_tbl)
        gcell.add_attr('colspan','7')
        
        lt.add_row()
        ltt = lt.add_cell(ltop)
        ltt.add_attr('colspan','2')
  
        lt.add_row() 
        lt.add_cell('First Name: ')
        lt.add_cell(my.txtbox('first_name',first_name))
        lt.add_row() 
        lt.add_cell('Last Name: ')
        lt.add_cell(my.txtbox('last_name',last_name))
        lt.add_row()
        lt.add_cell('Company: ')
        side_tbl = Table()
        side_tbl.add_row()
        side_tbl.add_cell(comp_sel)
        side_tbl.add_cell("&nbsp;&nbsp;&nbsp;&nbsp;")
        add_comp = side_tbl.add_cell('<input type="button" value="Add New Company"/>')
        add_comp.add_behavior(my.add_company())
        lt.add_cell(side_tbl)
        lt.add_row() 
        lt.add_cell('Title: ')
        lt.add_cell(my.txtbox('title',title))
        lt.add_row() 
        lt.add_cell('Email: ')
        lt.add_cell(my.txtbox('email',email))
        lt.add_row() 
        lt.add_cell('Alt Email: ')
        lt.add_cell(my.txtbox('alternate_email',alternate_email))
        lt.add_row() 
        lt.add_cell('Main Phone: ')
        lt.add_cell(my.txtbox('main_phone',main_phone))
        lt.add_row() 
        lt.add_cell('Work Phone: ')
        lt.add_cell(my.txtbox('work_phone',work_phone))
        lt.add_row() 
        lt.add_cell('Cell Phone: ')
        lt.add_cell(my.txtbox('cell_phone',cell_phone))
        lt.add_row() 
        lt.add_cell('Home Phone: ')
        lt.add_cell(my.txtbox('home_phone',home_phone))
        lt.add_row() 
        lt.add_cell('Fax: ')
        lt.add_cell(my.txtbox('fax',fax))
        lt.add_row() 
        lt.add_cell('Country: ')
        lt.add_cell(country_sel)
        lt.add_row() 
        lt.add_cell('State: ')
        lt.add_cell(state_sel)
        lt.add_row() 
        lt.add_cell('City: ')
        lt.add_cell(my.txtbox('city',city))
        lt.add_row() 
        lt.add_cell('Zip: ')
        lt.add_cell(my.txtbox('zip',zip))
        lt.add_row() 
        lt.add_cell('Street Address: ')
        lt.add_cell(my.txtbox('street_address',street_address))
        lt.add_row() 
        lt.add_cell('Suite: ')
        lt.add_cell(my.txtbox('suite',suite))

        img = my.get_snapshot(person, login_obj) 

        rt = Table()
        rt.add_attr('width','300px')
        rt.add_style('background-color: #ba4e33;')
        rt.add_style('height: 400px;')
        rt.add_row()
        img_cell = rt.add_cell(img)
        img_cell.add_attr('valign','top')
        img_cell.add_attr('align','center')

        selector_row = table.add_row()
        selector_row.add_attr('id','selector_row')
        select_tbl = Table()
        select_tbl.add_row()
        select_tbl.add_cell('Person: ')
        select_tbl.add_cell(peep_sel)

        select_cell = table.add_cell(select_tbl)
        select_cell.add_attr('colspan','3')
        select_cell.add_attr('align','center') 
        table.add_row()
        top1 = table.add_cell(lt)
        top1.add_attr('valign','top')
        table.add_cell('&nbsp;&nbsp;&nbsp;&nbsp;') 
        top2 = table.add_cell(rt)
        top2.add_attr('valign','top')
        table.add_row()
        save_butt = table.add_cell('<input type="button" value="Save/Create" />')
        save_butt.add_attr('colspan','3')
        save_butt.add_attr('align','center')
        save_butt.add_behavior(my.get_save())
        widget.add(table)
        return widget
Beispiel #17
0
    def get_action_wdg(self, name):
        '''get the action widget for ui option of note entry'''

        note_wdg = DivWdg()
        note_wdg.add_style("padding-top: 3px")

        # note options
        
        option = DivWdg(css='spt_uber_note_option')
        cb = CheckboxWdg('is_private')
        #cb.set_default_checked()

        checkbox_name = 'note_master_private_cb'
        master_cb = CheckboxWdg(checkbox_name)
        if master_cb.is_checked():
            cb.set_default_checked()

        option.add_style('margin-right','5px') 
        option.add_style('float','right') 
       
        option.add(cb)
        option.add('private')
        

        #commit = TextBtnWdg(label='save', size='small')
        commit = ActionButtonWdg(title='save', tip="Save Changes")
        commit.add_style('margin-top: -5px')
        commit.add_style('margin-bottom: 5px')
        commit.add_style('float: right')
        commit.add_behavior({
        'type': 'click_up', 
        'cbjs_action': '''
            var td = bvr.src_el.getParent(".spt_table_td");
            var text = td.getElement(".spt_note_text");
            text.blur();
            spt.dg_table.update_row(evt, bvr);
            td.setStyle('background-color','');
            ''',
        'cell_only': True
        }) 
        #commit.set_scale("0.75")
        
        
        

        # do some gynastics to handle a refresh.
        if self.parent_wdg:
            info = self.parent_wdg.get_aux_info()
            sobject_dict = info.get('sobjects')
            sobject = sobject_dict.get(self.get_name())
            parent = info.get('parent')
        else:
            sobject = None
            parent = None

        if not sobject:
            
            if self.parent_key:
                parent = SearchKey.get_by_search_key(self.parent_key)
            # get the latest note
            #search_key = self.kwargs.get("search_key")
            #if search_key:
            #    sobject = SearchKey.get_by_search_key(search_key)

            search = Search('sthpw/note')
            search.add_parent_filter(parent)
            search.add_filter('context', name)
            # Make the assumption that the last one entered is by timestamp
            search.add_order_by('timestamp desc')
            sobject = search.get_sobject()


        # Show a history of notes
        if sobject:
            history = ActionButtonWdg(title='history', tip="Show note history")
            #history = TextBtnWdg(label='history', size='small')
            #history.get_top_el().add_style("margin-left: 4px")
            #history.get_top_el().add_style('float: left')
            history.add_style("float: left")
            history.add_style("margin-top: -5px")
            history.add_style("margin-bottom: 5px")
            note_wdg.add(history)

            self.parent_key = SearchKey.get_by_sobject(parent)
            
            context = name
            filter = '[{"prefix":"main_body","main_body_enabled":"on","main_body_column":"context","main_body_relation":"is","main_body_value":"%s"}]' % context
            history.add_behavior( {
                'type': 'click_up',
                'cbjs_action': "spt.popup.get_widget(evt, bvr)",
                'options': {
                    'class_name': 'tactic.ui.panel.ViewPanelWdg',
                    'title': 'Notes History',
                    'popup_id': 'Notes_History_%s'%context 
                },
                'args': {
                    'search_type': 'sthpw/note',
                    'view': 'summary',
                    'parent_key': self.parent_key,
                    'filter': filter,

                }
            } )

        
        note_wdg.add(commit)
        note_wdg.add(option)
   
        note_wdg.add("<br clear='all'/>")
        
        from pyasm.biz import PrefSetting
        quick_text = PrefSetting.get_value_by_key('quick_text')
        if quick_text: 
            quick_sel = SelectWdg('quick_text', label='quick: ')  
            quick_sel.set_option('values',quick_text)
            quick_sel.add_empty_option('-- text --', '')
            quick_sel.add_behavior({'type': 'change', 
            'cbjs_action': '''var val = bvr.src_el.value; 
            var text=bvr.src_el.getParent('.spt_note_top').getElement('.spt_note_text')
            text.value = text.value + val;
            '''})

        
            note_wdg.add(SpanWdg(quick_sel, css='small'))
            note_wdg.add(HtmlElement.br(2))
        # Show the last note
        note_wdg.add("<i>Last note</i> ")

        if sobject:
            timestamp = sobject.get_value("timestamp")
            timestamp = parser.parse(timestamp)
            timestamp = timestamp.strftime("%m/%d %H:%M")
            timestamp_div = SpanWdg()
            timestamp_div.add( "(%s)" % timestamp)
            note_wdg.add( timestamp_div)
            timestamp_div.add_style("font-size: 11px")
            timestamp_div.add_style("font-style: italic")

            # add a private tag
            access = sobject.get_value("access")
            if access == 'private':
                private = SpanWdg()
                #private.add_style('float: right')
                private.add(" &nbsp; <i>-- private --</i>")
                note_wdg.add(private)


        hr = DivWdg("<hr/>")
        hr.add_style("height: 1px")
        hr.add_style("margin-top: -5px")
        note_wdg.add(hr)

        div = DivWdg()
        note_wdg.add(div)
        div.add_style("max-height", "50px")
        div.add_style("overflow", "auto")
        div.add_style("padding: 3px")
        if sobject:
            value = sobject.get_value('note')
            from pyasm.web import WikiUtil
            value = WikiUtil().convert(value)
            div.add(value)

        else:
            no_notes = DivWdg()
            div.add(no_notes)
            no_notes.add('<i> -- No Notes --</i>')
            no_notes.add_style("font-size: 11px")
            no_notes.add_style("opacity: 0.7")


        return note_wdg
    def get_display(my):
        top = DivWdg()
        top.add_class("spt_element_top")

        prefix = my.kwargs.get('prefix')
        # this should be name to be consistent with the BaseInputWdg interface
        widget_name = my.kwargs.get('name')
        if not widget_name:
            widget_name = 'data_type'

        display_options = my.kwargs.get('display_options')
        if not display_options:
            display_options = {}

        option = my.kwargs.get('option')
        if not option:
            option = {}



        # get the current value
        option_name = option.get('name')
        widget_type = display_options.get(option_name)

        select = SelectWdg(widget_name)
        top.add(select)
        default = option.get('default')
        if default:
            select.set_value(default)
        else:
            select.add_empty_option('-- Select --')

        values = option.get('values')
        if not values:
            values = 'integer|float|percent|currency|date|time|scientific|boolean|text|timecode',
        select.set_option('values', values)


        if widget_type:
            select.set_value(widget_type)

        select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        var top = bvr.src_el.getParent(".spt_element_top");
        var selects = top.getElements(".spt_format");
        for (var i = 0; i < selects.length; i++) {
            var type = selects[i].getAttribute("spt_type");
            if (value == type) {
                selects[i].setStyle("display", "");
                selects[i].removeAttribute("disabled");
            }
            else {
                selects[i].setStyle("display", "none");
                selects[i].setAttribute("disabled", "disabled");
                selects[i].value = '';

            }
        }
        '''
        } )


        selects_values = {
            '':             [],
            'integer':      ['-1234',
                             '-1,234'],

            'float':        ['-1234.12',
                             '-1,234.12'],

            'percent':      ['-13%', 
                             '-12.95%'],

            'currency':     ['-$1,234',
                             '-$1,234.00',
                             '-$1,234.--',
                             '-1,234.00 CAD',
                             '($1,234.00)',
                             ],

            'date':         ['31/12/99',
                             'December 31, 1999',
                             '31/12/1999',
                             'Dec 31, 99', 
                             'Dec 31, 1999',
                             '31 Dec, 1999',
                             '31 December 1999',
                             'Fri, Dec 31, 99',
                             'Fri 31/Dec 99',
                             'Fri, December 31, 1999',
                             'Friday, December 31, 1999',
                             '12-31',
                             '99-12-31',
                             '1999-12-31',
                             '12-31-1999',
                             '12/99',
                             '31/Dec',
                             'December',
                             '52',
                             'DATE'],

            'time':         ['13:37',
                             '13:37:46',
                             '01:37 PM',
                             '01:37:46 PM',
                             '31/12/99 13:37',
                             '31/12/99 13:37:46',
                             'DATETIME'],

            'scientific':   ['-1.23E+03',
                             '-1.234E+03'],

            'boolean':      ['true|false', 'True|False', 'Checkbox'],

            'timecode':      ['MM:SS.FF',
                              'MM:SS:FF',
                              'MM:SS',
                              'HH:MM:SS.FF',
                              'HH:MM:SS:FF',
                              'HH:MM:SS'],
        }

        for key, select_values in selects_values.items():
            # skip the empty key
            if not key:
                continue

            # options for each
            if prefix:
                select = SelectWdg("%s|format" % prefix, for_display=False)
            else:
                select = SelectWdg("format", for_display=False)

            select.add_class("spt_format")
           
            select.add_attr("spt_type", key)

            value = display_options.get('format')
            if key == '':
                select.add_style("display", "none")
            elif widget_type == key:
                select.set_value(value)
            else:
                select.add_style("display", "none")
                select.add_attr("disabled", "disabled")

            select.set_option("values", select_values)
            select.add_empty_option("-- Format --")
            top.add(select)
  
            if key == 'timecode':
                if prefix:
                    select = SelectWdg("%s|fps" % prefix, for_display=False)
                else:
                    select = SelectWdg("fps", for_display=False)
                select.add_class("spt_format")
                select.add_attr("spt_type", key)

                value = display_options.get('fps')
                if widget_type == key:
                    select.set_value(value)
                else:
                    select.add_style("display", "none")
                select.set_option("values", "12|24|25|30|60")
                select.set_option("labels", "12 fps|24 fps|25 fps|30 fps|60 fps")
                select.add_empty_option("-- fps --")
                top.add(select)
               

        return top
Beispiel #19
0
    def get_display(self):
        self.check()
        if self.is_refresh:
            div = Widget()
        else:
            div = DivWdg()
            self.set_as_panel(div)
            div.add_style('padding', '6px')
            min_width = '400px'
            div.add_style('min-width', min_width)
            div.add_color('background', 'background')
            div.add_class('spt_add_task_panel')
            div.add_style("padding: 20px")

        from tactic.ui.app import HelpButtonWdg
        help_button = HelpButtonWdg(alias="creating-tasks")
        div.add(help_button)
        help_button.add_style("float: right")
        help_button.add_style("margin-top: -5px")

        if not self.search_key_list:
            msg_div = DivWdg()
            msg_table = Table()
            msg_div.add(msg_table)
            msg_table.add_row()
            msg_table.add_cell(IconWdg("No items selected", IconWdg.WARNING))
            msg_table.add_cell(
                'Please select at least 1 item to add tasks to.')

            msg_div.add_style('margin: 10px')
            msg_table.add_style("font-weight: bold")
            div.add(msg_div)
            return div

        msg_div = DivWdg()
        msg_div.add_style('margin-left: 4px')
        div.add(msg_div, 'info')
        msg_div.add('Total: %s item/s to add tasks to' %
                    len(self.search_key_list))
        div.add(HtmlElement.br())
        hint = HintWdg('Tasks are added according to the assigned pipeline.')
        msg_div.add(" &nbsp; ")
        msg_div.add(hint)
        msg_div.add(HtmlElement.br())

        option_div = DivWdg(css='spt_ui_options')
        #option_div.add_style('margin-left: 12px')

        sel = SelectWdg('pipeline_mode', label='Create tasks by: ')
        sel.set_option('values', ['simple process', 'context', 'standard'])
        sel.set_option('labels',
                       ['process', 'context', 'all contexts in process'])
        sel.set_persistence()
        sel.add_behavior({
            'type': 'change',
            'cbjs_action': 'spt.panel.refresh(bvr.src_el)'
        })

        option_div.add(sel)

        value = sel.get_value()
        # default to simple process
        if not value:
            value = 'simple process'
        msg = ''
        if value not in ['simple process', 'context', 'standard']:
            value = 'simple process'

        if value == 'context':
            msg = 'In context mode, a single task will be created for each selected context.'
        elif value == 'simple process':
            msg = 'In process mode, a single task will be created for each selected process.'

        elif value == 'standard':
            msg = 'In this mode, a task will be created for all contexts of each selected process.'

        option_div.add(HintWdg(msg))
        div.add(option_div)
        div.add(HtmlElement.br())

        title = DivWdg('Assigned Pipelines')
        title.add_style('padding: 6px')
        title.add_color('background', 'background2')
        title.add_color('color', 'color', +120)
        div.add(title)

        content_div = DivWdg()
        content_div.add_style('min-height', '150px')
        div.add(content_div)
        content_div.add_border()

        filtered_search_key_list = []
        for sk in self.search_key_list:
            id = SearchKey.extract_id(sk)
            if id == '-1':
                continue
            filtered_search_key_list.append(sk)

        sobjects = SearchKey.get_by_search_keys(filtered_search_key_list)
        skipped = []
        pipeline_codes = []
        for sobject in sobjects:
            if isinstance(sobject, Task):
                msg_div = DivWdg(
                    'WARNING: Creation of task for [Task] is not allowed.')
                msg_div.add_style('margin-left: 10px')
                div.add(msg_div, 'info')
                return div
            pipeline_code = sobject.get_value('pipeline_code',
                                              no_exception=True)
            if not pipeline_code:
                skipped.append(sobject)
            if pipeline_code not in pipeline_codes:
                pipeline_codes.append(pipeline_code)

        pipelines = Search.get_by_code('sthpw/pipeline', pipeline_codes)
        if pipelines == None:
            pipelines = []
        #if not pipelines:
        #    msg_div = DivWdg('WARNING: No Pipelines found for selected.')
        #    msg_div.add_style('margin-left: 10px')
        #    div.add(msg_div, 'info')
        #    return div

        # expand the width according to num of pipelines
        content_div.add_style('min-width', len(pipelines) * 250)
        mode_cb = SelectWdg('pipeline_mode')
        mode_cb.set_persistence()
        mode = mode_cb.get_value()
        if 'context' == mode:
            mode = 'context'
        else:
            mode = 'process'

        show_subpipeline = True
        min_height = '150px'

        # create a temp default pipeline
        if not pipelines:
            pipeline = SearchType.create("sthpw/pipeline")
            pipeline.set_value("code", "__default__")
            pipeline.set_value(
                "pipeline", '''
<pipeline>
    <process name='publish'/>
</pipeline>
            ''')
            # FIXME: HACK to initialize virtual pipeline
            pipeline.set_pipeline(pipeline.get_value("pipeline"))
            pipelines = [pipeline]

        for pipeline in pipelines:
            name = pipeline.get_value("name")
            if not name:
                name = pipeline.get_code()
            span = SpanWdg("Pipeline: %s" % name)
            span.add_style('font-weight: bold')
            v_div = FloatDivWdg(span)
            v_div.add_style('margin: 20px')
            v_div.add_style('min-height', min_height)
            v_div.add(HtmlElement.br(2))
            content_div.add(v_div)
            processes = pipeline.get_processes(recurse=show_subpipeline,
                                               type=['manual', 'approval'])

            cb_name = '%s|task_process' % pipeline.get_code()
            master_cb = CheckboxWdg('master_control')
            master_cb.set_checked()
            master_cb.add_behavior({
                'type':
                'click_up',
                'propagate_evt':
                True,
                'cbjs_action':
                '''
                    var inputs = spt.api.Utility.get_inputs(bvr.src_el.getParent('.spt_add_task_panel'),'%s');
                    for (var i = 0; i < inputs.length; i++)
                        inputs[i].checked = bvr.src_el.checked;
                        ''' % cb_name
            })
            toggle_div = DivWdg()
            toggle_div.add(SpanWdg(master_cb, css='small'))
            label = HtmlElement.i('toggle all')
            label.add_style('color: #888')
            toggle_div.add_styles(
                'border-bottom: 1px solid #888; width: 170px')
            toggle_div.add(label)
            v_div.add(toggle_div)
            process_names = []

            for process in processes:
                process_labels = []
                if process.is_from_sub_pipeline():
                    process_name = process.get_full_name()
                else:
                    process_name = process.get_name()

                process_label = process.get_label()
                if not process_label:
                    process_label = ''
                if mode == 'context':
                    contexts = pipeline.get_output_contexts(process.get_name())

                    labels = contexts
                    if process.is_from_sub_pipeline():
                        labels = [
                            '%s/%s' % (process.parent_pipeline_code, x)
                            for x in contexts
                        ]

                    for x in labels:
                        process_labels.append(process_label)

                    # prepend process to contexts in this mode to ensure uniqueness
                    contexts = ['%s:%s' % (process_name, x) for x in contexts]
                else:
                    contexts = [process_name]
                    labels = contexts

                    process_labels.append(process_label)

                for idx, context in enumerate(contexts):
                    cb = CheckboxWdg(cb_name)
                    cb.set_checked()
                    cb.set_option('value', context)
                    v_div.add(SpanWdg(cb, css='small'))
                    if mode == 'context':
                        span = SpanWdg(process_name, css='med')
                        #span.add_color('color','color')
                        v_div.add(span)
                    v_div.add(SpanWdg(labels[idx]))
                    process_label = process_labels[idx]
                    if process_label:
                        v_div.add(SpanWdg("(%s)" % process_label, css='small'))
                    v_div.add(HtmlElement.br())

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

        skipped = []

        if True:
            div.add("<br/>")
            btn = ActionButtonWdg(title='Add Tasks')
            btn.add_behavior({
                'type': 'click_up',
                'post_event': 'search_table_%s' % self.table_id,
                'cbjs_action': '''
            spt.dg_table.add_task_selected(bvr);
            ''',
                'search_key_list': self.search_key_list
            })
            cb = CheckboxWdg('skip_duplicated', label='Skip Duplicates')
            cb.set_checked()
            option_div = DivWdg(cb)
            option_div.add_style('width', '130px')
            option_div.add_style('align: left')
            div.add(option_div)
            div.add(HtmlElement.br())
            btn.add_style("float: right")
            div.add(btn)
            div.add(HtmlElement.br(clear="all"))

        if skipped:
            content_div.add(HtmlElement.br())
            skip_div = DivWdg('Missing pipeline code (Skipped)')
            skip_div.add_style('text-decoration: underline')
            content_div.add(skip_div)
            content_div.add(HtmlElement.br())
            item_div = DivWdg()
            item_div.add_style('margin-left: 10px')
            content_div.add(item_div)
        for skip in skipped:
            item_div.add(skip.get_code())
            item_div.add(HtmlElement.br())

        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
Beispiel #21
0
    def get_display(my):

        top = my.top
        top.add_class("spt_db_config_top")
        top.add_style("width: 430px")
        top.add_style("min-height: 500")
        top.add_style("padding: 15px")
        top.add_style("margin-left: auto")
        top.add_style("margin-right: auto")
        top.add_color("background", "background", -10)
        top.add_border()

        title_wdg = DivWdg()
        top.add(title_wdg)
        title_wdg.add("System Configuration Setup")
        title_wdg.add_style("font-size: 20px")

        top.add("<hr/>")

        top.add("<i style='opacity: 0.5'>%s</i><br/>" %
                Config.get_config_path())
        top.add("<br/>")

        checkin_keys = Config.get_section_values('checkin')
        checkin_keys = checkin_keys.keys()
        save_button = my.get_save_button(checkin_keys)
        top.add(save_button)
        vendor = Config.get_value("database", "vendor")

        title_wdg = DivWdg()
        top.add(title_wdg)
        title_wdg.add("<b>Database Setup</b>")
        title_wdg.add_style("margin-bottom: 10px")

        db_select = SelectWdg("database/vendor")
        db_select.set_option("labels",
                             "SQLite|PostgreSQL|MySQL|Oracle|SQLServer")
        db_select.set_option("values",
                             "Sqlite|PostgreSQL|MySQL|Oracle|SQLServer")

        db_select.set_value(vendor)

        db_select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''

        var key;
        if (bvr.src_el.value == 'Sqlite') {
            key = 'Sqlite';
        }
        else if (bvr.src_el.value == 'MySQL') {
            key = 'MySQL';
        }
        else {
            key = 'Other';
        }
        var top = bvr.src_el.getParent(".spt_db_config_top");
        var options_els = top.getElements(".spt_db_options");
        for (var i = 0; i < options_els.length; i++) {
            var vendor = options_els[i].getAttribute("spt_vendor");
            if (vendor == key) {
                spt.show(options_els[i]);
            }
            else {
                spt.hide(options_els[i]);
            }

        }
        '''
        })

        option_div = DivWdg()
        top.add(option_div)
        option_div.add("Vendor: ")
        option_div.add(db_select)
        option_div.add_style("margin: 20px")

        sqlite_wdg = my.get_sqlite_wdg()
        option_div.add(sqlite_wdg)
        mysql_wdg = my.get_mysql_wdg()
        option_div.add(mysql_wdg)
        otherdb_wdg = my.get_otherdb_wdg()
        option_div.add(otherdb_wdg)

        if vendor == 'Sqlite':
            sqlite_wdg.add_style("display", "")
            otherdb_wdg.add_style("display: none")
            mysql_wdg.add_style("display: none")

        if vendor == 'MySQL':
            mysql_wdg.add_style("display", "")
            otherdb_wdg.add_style("display: none")
            sqlite_wdg.add_style("display: none")

        else:
            otherdb_wdg.add_style("display", "")
            mysql_wdg.add_style("display: none")
            sqlite_wdg.add_style("display: none")

        test_button = ActionButtonWdg(title=" Test ",
                                      tip="Test connecting to database")
        option_div.add(test_button)
        test_button.add_style("margin-left: auto")
        test_button.add_style("margin-right: auto")
        test_button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_db_config_top");
        var values = spt.api.Utility.get_input_values(top, null, false);
        var class_name = 'tactic.ui.startup.DbConfigCbk';
        var server = TacticServerStub.get();
        var kwargs = {};
        var ret_val = server.execute_cmd(class_name, kwargs, values);
        var info = ret_val.info;
        if (info.error) {
            spt.error(info.error);
        }
        else {
            spt.info("Connection to database successful");
        }
        '''
        })

        #
        # Install
        #
        top.add("<hr/>")

        top.add("<br/>")

        title = "Installation"

        category = "install"

        options = ['default_project']

        if 'tmp_dir' not in options:
            options.append('tmp_dir')

        top.add(my.configure_category(title, category, options))

        top.add("<hr/>")

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

        title = "Asset Management Setup"
        category = "checkin"

        options = checkin_keys[:]

        my._remove_item_from_list(options, 'win32_server_handoff_dir')
        my._remove_item_from_list(options, 'linux_server_handoff_dir')

        if os.name == "nt":
            options.append('win32_server_handoff_dir')
        else:
            options.append('linux_server_handoff_dir')

        top.add(my.configure_category(title, category, options))

        top.add("<hr/>")
        top.add("<br/>")

        title = "Mail Server"
        category = "services"
        options = [
            'mailserver', 'mail_user', 'mail_password', 'mail_port',
            'mail_tls_enabled', 'mail_sender_disabled'
        ]
        top.add(my.configure_category(title, category, options))

        top.add("<hr/>")

        title = "Services"
        category = "services"
        options = [
            'process_count', 'process_time_alive', 'thread_count',
            'python_path'
        ]
        top.add(my.configure_category(title, category, options))

        top.add("<hr/>")

        title = "Look and Feel"
        category = "look"
        options = ['palette']
        top.add(my.configure_category(title, category, options))

        #wizard_wdg = WizardWdg()
        #top.add(wizard_wdg)
        #wizard_wdg.add(DivWdg("cow"), "cow")
        #wizard_wdg.add(DivWdg("pig"), "pig")
        #wizard_wdg.add(DivWdg("dog"), "dog")
        return top
Beispiel #22
0
    def get_display(my):   
        my.code = str(my.kwargs.get('code'))
        is_external_rejection = False
        sob = None
        my.sk = None
        operator_description = 'operator_description'
        scheduler_description = 'scheduler_description'
        pre_type = 'Operator Description'
        rejection_cause_str = 'Rejection Cause'
        rejection_cause_field = 'rejection_cause'
        description_str = 'Description'
        description_field = 'description'
        action_taken_str = 'Action Taken'
        action_taken_field = 'action_taken'
        client_name = ''
        if 'EXTERNAL_REJECTION' in my.code:
            is_external_rejection = True
            sob = my.server.eval("@SOBJECT(twog/external_rejection['code','%s'])" % my.code)[0]
            operator_description = 'reported_issue'
            scheduler_description = 'reported_issue'
            pre_type = 'Reported Issue'
            rejection_cause_str = 'Root Cause Type'
            rejection_cause_field = 'root_cause_type'
            description_str = 'Root Cause'
            description_field = 'root_cause'
            action_taken_str = 'Corrective Action'
            action_taken_field = 'corrective_action'
            the_order = my.server.eval("@SOBJECT(twog/order['code','%s'])" % sob.get('order_code'))[0]
            client_name = the_order.get('client_name')
        else:
            sob = my.server.eval("@SOBJECT(twog/production_error['code','%s'])" % my.code)[0]
        my.sk = sob.get('__search_key__') 
        table = Table()
        table.add_attr('id','error_tbl_%s' % my.code)
        #table.add_style('background-color: #86a6da;')
        video_tbl = my.make_check_table(my.video_reasons, my.video_reasons_arr, sob, 'Video', '#ffef91', is_external_rejection)
        audio_tbl =  my.make_check_table(my.audio_reasons, my.audio_reasons_arr, sob, 'Audio', '#ffefa1', is_external_rejection)
        metadata_tbl =  my.make_check_table(my.metadata_reasons, my.metadata_reasons_arr, sob, 'MetaData', '#ffefb1', is_external_rejection)
        subtitle_tbl =  my.make_check_table(my.subtitle_reasons, my.subtitle_reasons_arr, sob, 'Subtitle', '#ffefc1', is_external_rejection)
        cc_tbl =  my.make_check_table(my.cc_reasons, my.cc_reasons_arr, sob, 'CC', '#ffefd1', is_external_rejection)
        if not is_external_rejection:
            login_tbl = my.make_login_table(sob)
        cause_sel = None
        assigned_sel = None
        corrective_action_sel = None
        status_sel = None
        if not is_external_rejection:
            cause_sel = SelectWdg('rejection_cause')
            cause_sel.append_option('--Select--','--Select--')
            for cause in my.rejection_causes:
                cause_sel.append_option(cause, cause)
                if cause == sob.get('rejection_cause'):
                    cause_sel.set_value(cause)
            cause_sel.add_behavior(my.get_sel_change_behavior(my.code, 'twog/production_error', 'rejection_cause')) 
        else:
            cause_sel = SelectWdg('root_cause_type')
            cause_sel.append_option('--Select--','--Select--')
            for cause in my.root_cause_types:
                cause_sel.append_option(cause, cause)
                if cause == sob.get('root_cause_type'):
                    cause_sel.set_value(cause)
            #cause_sel.add_behavior(my.get_sel_change_behavior(my.code, 'twog/external_rejection', 'root_cause_type')) 

            status_sel = SelectWdg('status')
            status_sel.append_option('--Select--','--Select--')
            for status in my.statuses:
                status_sel.append_option(status, status)
                if status == sob.get('status'):
                    status_sel.set_value(status)
            #status_sel.add_behavior(my.get_sel_change_behavior(my.code, 'twog/external_rejection','status')) 

            logins = my.server.eval("@GET(sthpw/login['location','internal']['license_type','!=','disabled']['@ORDER_BY','login asc'].login)")
            groups = my.server.eval("@GET(sthpw/login_group['login_group','not in','client|user|admin']['@ORDER_BY','login_group asc'].login_group)")
            assigned_sel = SelectWdg('assigned')
            assigned_sel.append_option('--Select--','--Select--')
            for login_str in logins:
                assigned_sel.append_option(login_str, login_str)
                if login_str == sob.get('assigned'):
                    assigned_sel.set_value(login_str)
            for group in groups:
                group = group.upper()
                assigned_sel.append_option(group, group)
                if group == sob.get('assigned'):
                    assigned_sel.set_value(group)
            #assigned_sel.add_behavior(my.get_sel_change_behavior(my.code, 'twog/external_rejection', 'assigned')) 

            corrective_action_sel = SelectWdg('corrective_action_assigned')
            corrective_action_sel.append_option('--Select--','--Select--')
            for login_str in logins:
                corrective_action_sel.append_option(login_str, login_str)
                if login_str == sob.get('corrective_action_assigned'):
                    corrective_action_sel.set_value(login_str)
            for group in groups:
                group = group.upper()
                corrective_action_sel.append_option(group, group)
                if group == sob.get('assigned'):
                    corrective_action_sel.set_value(group)
            #corrective_action_sel.add_behavior(my.get_sel_change_behavior(my.code, 'twog/external_rejection', 'corrective_action_assigned')) 

        cause_sel.add_style('width: 175px;')
        info_table = Table()
        info_table.add_row()
        info_table.add_cell('<b><u>Order:</u> %s [%s]</b>' % (sob.get('order_name'), sob.get('order_code')))
        my_title = sob.get('title')
        if sob.get('episode') not in [None,'']:
            my_title = '%s, %s' % (my_title, sob.get('episode'))
        info_table.add_cell('<b><u>Title:</u> %s [%s]</b>' % (my_title, sob.get('title_code')))
        
        if sob.get('work_order_code') not in [None,''] and not is_external_rejection:
            info_table.add_cell('<b><u>Work Order:</u> %s [%s]</b>' % (sob.get('process'), sob.get('work_order_code')))
        if is_external_rejection:
            from history import SObjectHistoryLauncherWdg
            histy = SObjectHistoryLauncherWdg(search_key=my.sk)
            hi = info_table.add_cell(histy)
            hi.add_attr('align','right')
        info_table.add_row()
        info1 = info_table.add_cell('<b><u>Client:</u> %s</b>' % client_name)
        info1.add_attr('nowrap','nowrap')
        if not is_external_rejection:
            info_table.add_cell('<b><u>Scheduler:</u> %s</b>' % sob.get('scheduler_login'))
            info_table.add_cell('<b><u>Operator:</u> %s</b>' % sob.get('operator_login'))
            info_table.add_row()
            info_table.add_cell('<b><u>Type:</u><font color="#ff0000"> %s</font></b>' % sob.get('error_type'))
        else:
            tb1 = Table()
            tb1.add_row()
            tb1.add_cell('Assigned:')
            tb1.add_cell(assigned_sel)
            info_table.add_cell(tb1)
            tb2 = Table()
            tb2.add_row()
            tt2 = tb2.add_cell('Corrective Action Assigned:')
            tt2.add_attr('nowrap','nowrap')
            tb2.add_cell(corrective_action_sel)
            info_table.add_cell(tb2)
            info_table.add_row()
            tb23 = Table()
            tb23.add_attr('width','100%s' % '%')
            tb23.add_row()
            tb231 = tb23.add_cell('&nbsp;')
            tb231.add_attr('width','20%s' % '%')
            tb23.add_cell('Replacement Order:')
            tb23.add_cell('<input type="text" value="%s" class="%s_replacement_order_code"/>' % (sob.get('replacement_order_code'), sob.get('code')))
            tb23.add_cell('&nbsp;')
            tb23.add_cell('Replacement Title:')
            tb23.add_cell('<input type="text" value="%s" class="%s_replacement_title_code"/>' % (sob.get('replacement_title_code'), sob.get('code')))
            info_table.add_cell(tb23)
        initial_descript = sob.get(operator_description)
        if initial_descript in [None,''] and not is_external_rejection:
            initial_descript = sob.get(scheduler_description)
            pre_type = 'Scheduler Description'
            if initial_descript in [None,'']:
                initial_descript = sob.get('client_description')
                pre_type = 'Client Description'
        info_table.add_row()
        #info_table.add_cell('<textarea cols="120" rows="4" style="background-color: #86a6da;" readonly>[%s]: %s</textarea>' % (pre_type, initial_descript)) 
        info_table.add_cell('<textarea cols="120" rows="4" style="background-color: #959595;" readonly>[%s]: %s</textarea>' % (pre_type, initial_descript)) 
        if is_external_rejection:
            info_table.add_row()
            files_tbl = FaultFilesWdg(external_rejection_code=sob.get('code'))
            info_table.add_cell(files_tbl)
        cause_tbl = Table()
        cause_tbl.add_attr('width','100%s' % '%')
        cause_tbl.add_style('background-color: #fefefe;')
        cause_tbl.add_row()
        rc = cause_tbl.add_cell('<b><u>%s:</u></b>' % rejection_cause_str)
        rc.add_attr('nowrap','nowrap')
        cause_tbl.add_cell(cause_sel)
        cause_tbl.add_cell('&nbsp;')
        ts = cause_tbl.add_cell('Time Spent: ')
        ts.add_attr('nowrap','nowrap')
        cause_tbl.add_cell('<input type="text" value="%s" class="%s_time_spent"/>' % (sob.get('time_spent'), sob.get('code')))
        if not is_external_rejection:
            longguy = cause_tbl.add_cell(' ')
            longguy.add_attr('width','100%s' % '%')
        else:
            tb3 = Table()
            tb3.add_row()
            tb3.add_cell('Status:')
            tb3.add_cell(status_sel)
            cause_tbl.add_cell(tb3)
        table.add_row()
        table.add_cell(info_table)
        table.add_row()
        table.add_cell(cause_tbl)
        table.add_row()
        table.add_cell(video_tbl)
        table.add_row()
        table.add_cell(audio_tbl)
        table.add_row()
        table.add_cell(metadata_tbl)
        table.add_row()
        table.add_cell(subtitle_tbl)
        table.add_row()
        table.add_cell(cc_tbl)
        if not is_external_rejection:
            table.add_row()
            table.add_cell(login_tbl)
        table.add_row()
        if not is_external_rejection:
            cme = table.add_cell('<b><u>%s</u></b>' % description_str)
            cme.add_attr('align','center')
            table.add_row()
            table.add_cell('<textarea cols="120" rows="10" class="%s_description">%s</textarea>' % (my.code, sob.get(description_field)))
            table.add_row()
            ame = table.add_cell('<b><u>%s</u></b>' % action_taken_str)
            ame.add_attr('align','center')
            table.add_row()
            table.add_cell('<textarea cols="120" rows="10" class="%s_action_taken">%s</textarea>' % (my.code, sob.get(action_taken_field)))
            table.add_row()
        else:
            from tactic.ui.widget import DiscussionWdg
            table.add_cell("<u><b>Root Cause</b></u>")
            table.add_row()
            root_cause_wdg = DiscussionWdg(search_key=my.sk,process='Root Cause',chronological=True)
            table.add_cell(root_cause_wdg)
            table.add_row()
            table.add_cell("<u><b>Corrective Action</b></u>")
            table.add_row()
            action_taken_wdg = DiscussionWdg(search_key=my.sk,process='Corrective Action',chronological=True)
            table.add_cell(action_taken_wdg)
            table.add_row()
            

        button = table.add_cell('<input type="button" value="Save"/>')
        button.add_attr('align','right')
        if not is_external_rejection:
            button.add_behavior(my.get_save_description_behavior(my.code))
        else:
            button.add_behavior(my.get_save_external_rejection(my.code))
        return table
Beispiel #23
0
    def get_display(my):
        widget = DivWdg(id='new_item_panel')
        widget.add_class("new_item_panel")
        widget.add_class("spt_new_item_top")

        div = DivWdg()
        div.add_color("background", "background")
        div.add_color("color", "color")
        div.add_style("padding", "5px")
        div.add_border()

        if my.is_personal:
            is_personal = 'true'
        else:
            is_personal = 'false'

        if my.type == 'new_folder':
            #div.set_attr('spt_view', 'new_folder')
            div.add(HtmlElement.b('Create New Folder'))
            div.add(HtmlElement.br(2))
            item_div = DivWdg(css='spt_new_item')
            item_div.add_style('display: none')
            div.add(HtmlElement.br())
            div.add(item_div)
            """
            # add exisiting views in the div for checking with client's input
             # add exiting views:
            from panel_wdg import ViewPanelSaveWdg
            views = ViewPanelSaveWdg.get_existing_views(my.is_personal)
            hidden = HiddenWdg('existing_views', '|'.join(views))
            div.add(hidden)
            """
            text2 = TextWdg("new_title")
            text2.add_class("spt_new_item_title")
            span = SpanWdg("Title: ")
            span.set_id('create_new_title')
            #span.add_style('display: none')
            span.add_style('padding-left: 8px')
            span.add(text2)
            div.add(span)
            div.add(HtmlElement.br(2))

            div.add_style("width: 350px")

            action = '''
            var top = bvr.src_el.getParent(".spt_new_item_top");
            var name_el = top.getElement(".spt_new_item_name");
            var title = bvr.src_el.value;
            var name = title.replace(/[\?.!@#$%^&*()'"]/g, "");
            name = name.replace(/ /g, "_");
            name = name.toLowerCase();
            name_el.value = name;
            '''

            # change the name based on the title
            text2.add_behavior({'type': 'change', 'cbjs_action': action})

            div.add(
                "The name of the folder is a hidden name that is used by other elements to refer to uniquely to this item.<br/><br/>"
            )
            text = TextWdg('new_name')
            text.add_class("spt_new_item_name")
            span = SpanWdg('Name: ')
            span.add(text)
            div.add(span)

            div.add(HtmlElement.br(2))

            #script = "spt.side_bar.manage_section_action_cbk({'value':'predefined'},'project_view');"
            #link = HtmlElement.js_href(script, data='[ Predefined View ]')
            #div3 = DivWdg('Optional: drag existing elements from Project Views or %s into this new folder' %link.get_buffer_display())
            #div.add(div3)
            #item_div = DivWdg(css='spt_new_item spt_side_bar_content')
            #div.add(item_div)

            div.add("<hr/>")

            #save_div = SpanWdg(css='med hand')
            #div.add(save_div)
            #save_div.add(IconWdg('Save Folder', IconWdg.SAVE))

            save_button = ActionButtonWdg(title='Create',
                                          tip='Create a new folder')
            div.add(save_button)

            bvr = {
                "type":
                "click_up",
                "view":
                my.view,
                "is_personal":
                is_personal == 'true',
                'cbjs_action':
                '''
            var top = bvr.src_el.getParent(".spt_new_item_top");
            var name_el = top.getElement(".spt_new_item_name");
            var name_value = name_el.value;
            if (name_value == "") {
                var title_el = top.getElement(".spt_new_item_title");
                var title = title_el.value;
                var name = spt.convert_to_alpha_numeric(title);
                name_el.value = name;
            }
            if (name_value == "") {
                spt.alert("Please fill in a value for name.");
                return;
            }
            spt.side_bar.manage_section_action_cbk(
                    { 'value':'save_folder'}, bvr.view, bvr.is_personal);
            '''
            }
            save_button.add_behavior(bvr)
            div.add(HtmlElement.br())

        elif my.type == 'new_link':

            div.set_attr('spt_view', 'new_link')
            div.add(HtmlElement.b('Create New Link'))
            div.add(HtmlElement.br())

            item_div = DivWdg(css='spt_new_item')
            item_div.add_style('display: none')
            div.add(HtmlElement.br())
            div.add(item_div)

            text = TextWdg('new_link_title')
            span = SpanWdg('Title: ')
            span.add(text)
            div.add(span)

            div.add(HtmlElement.br(2))
            cb = CheckboxWdg('include_search_view',
                             label='Include Saved Search')
            cb.set_default_checked()
            div.add(cb)

            div.add(HtmlElement.br(2))
            div.add("Select a search type and view of this link")
            div.add(HtmlElement.br())

            select = SelectWdg("new_search_type")
            select.add_empty_option("-- Select Search type --")

            security = Environment.get_security()
            if security.check_access("builtin", "view_site_admin", "allow"):
                search_types = Project.get().get_search_types(
                    include_sthpw=True, include_config=True)
            else:
                search_types = Project.get().get_search_types()

            values = [x.get_value("search_type") for x in search_types]
            labels = [
                "%s (%s)" % (x.get_value("search_type"), x.get_title())
                for x in search_types
            ]
            values.append("CustomLayoutWdg")
            labels.append("CustomLayoutWdg")
            select.set_option("values", values)
            select.set_option("labels", labels)

            #security = Environment.get_security()
            #if security.check_access("builtin", "view_site_admin", "allow"):
            #    select_mode =  SearchTypeSelectWdg.ALL
            #else:
            #    select_mode =  SearchTypeSelectWdg.ALL_BUT_STHPW
            #select = SearchTypeSelectWdg(name='new_search_type', \
            #    mode=select_mode)

            select.add_behavior({
                'type':
                'change',
                'cbjs_action':
                '''
                var top = bvr.src_el.getParent(".new_item_panel");
                var link_view_select = top.getElement(".link_view_select");
                var input = spt.api.Utility.get_input(top, 'new_search_type'); var values = {'search_type': input.value, 
                'is_refresh': 'true'}; 
                spt.panel.refresh(link_view_select, values);'''
            })
            div.add(HtmlElement.br())
            div.add(select)

            div.add(HtmlElement.br())

            link_view_sel = NewLinkViewSelectWdg()
            div.add(HtmlElement.br())
            div.add(link_view_sel)

            div.add(HtmlElement.br())
            #select.add_behavior('change')
            div.add(HtmlElement.hr())
            div.add(HtmlElement.br())

            #save_div = DivWdg(css='med hand')
            #div.add(save_div)
            #save_button = ProdIconButtonWdg('Save Link', IconWdg.SAVE)
            #save_div.add(save_button)

            save_button = ActionButtonWdg(title='Create',
                                          tip='Create a new link')
            div.add(save_button)
            bvr = { "type": "click_up",
                'cbjs_action': "spt.side_bar.manage_section_action_cbk({"\
                "'value':'save_link'},'%s', %s);" %(my.view, is_personal)}
            save_button.add_behavior(bvr)
            div.add(HtmlElement.br(1))

        elif my.type == 'new_separator':
            div.set_attr('spt_view', 'new_separator')
            div.add(HtmlElement.b('Creating New Separator. . .'))
            div.add(HtmlElement.br())

            item_div = DivWdg(css='spt_new_item')
            item_div.add_style('display: none')
            div.add(HtmlElement.br())
            div.add(item_div)
            # since it's automated, this button is not needed
            """ 
            save_div = SpanWdg(css='med hand')
            save_div.add(IconWdg('Save', IconWdg.SAVE))
        
            bvr = { "type": "click_up",\
                'cbjs_action': "spt.side_bar.manage_section_action_cbk({"\
                "'value':'save_separator'},'%s');" %my.view}
            save_div.add_behavior(bvr)
            div.add(save_div)
            """
        widget.add(div)
        return widget
Beispiel #24
0
    def get_new_custom_widget(self, search_type, view):

        div = DivWdg()
        div.add_style('width: 500px')

        mode_select = SelectWdg("custom_mode")
        mode_select.add_class("spt_custom_mode")
        mode_select.set_option("values", "simple|xml")
        mode_select.set_option("labels", "Simple|XML")
        mode_select.add_class("spt_input")
        behavior = {
            'type': 'change',
            'cbfn_action': 'spt.custom_property_adder.switch_property_mode'
        }
        mode_select.add_behavior(behavior)

        div.add("Mode: ")
        div.add(mode_select)
        div.add("<br/><br/>")

        custom_table = Table()
        custom_table.add_color("color", "color")

        custom_table.set_max_width()
        mode = "simple"
        self.handle_simple_mode(custom_table, mode)
        #self.handle_widget_mode(custom_table, mode)
        self.handle_xml_mode(custom_table, mode)
        div.add(custom_table)

        div.add("<br/>")

        custom_table = Table()
        custom_table.center()
        custom_table.add_row()

        from tactic.ui.widget import ActionButtonWdg
        submit = ActionButtonWdg(title="Add/Next")
        behavior = {
            'type': 'click',
            'mouse_btn': 'LMB',
            'cbfn_action': 'spt.custom_property_adder.add_property_cbk',
            'search_type': self.search_type,
            'view': view
        }
        submit.add_behavior(behavior)
        td = custom_table.add_cell(submit)

        behavior['exit'] = 'true'
        submit_exit = ActionButtonWdg(title="Add/Exit")
        submit_exit.add_behavior(behavior)
        custom_table.add_cell(submit_exit)

        cancel = ActionButtonWdg(title="Cancel")
        behavior = {
            'type': 'click_up',
            'cbjs_action': "spt.popup.close('New Table Column')"
        }
        cancel.add_behavior(behavior)
        custom_table.add_cell(cancel)

        div.add(custom_table)

        return div
Beispiel #25
0
    def get_filter_wdg(my):

        div = DivWdg()
        div.add_style("padding: 10px")
        div.add_style("margin: -10 -10 10 -10")
        div.add_style("min-width: 600px")
        div.add_class("spt_view_manager_filter")

        from tactic.ui.app import HelpButtonWdg

        help_wdg = HelpButtonWdg(alias="view-manager|what-are-views")
        div.add(help_wdg)
        help_wdg.add_style("float: right")

        div.add("<b>Search Type:</b> ")

        div.add_gradient("background", "background", -10)

        security = Environment.get_security()
        project = Project.get()
        if security.check_access("builtin", "view_site_admin", "allow"):
            search_type_objs = project.get_search_types(include_sthpw=True, include_config=True)
        else:
            search_type_objs = project.get_search_types()

        search_types = [x.get_value("search_type") for x in search_type_objs]
        titles = ["%s (%s)" % (x.get_value("search_type"), x.get_value("title")) for x in search_type_objs]

        select = SelectWdg(name="search_type")
        select.set_option("values", search_types)
        select.set_option("labels", titles)
        select.add_empty_option("-- Select --")
        select.set_persistence()
        # select.set_persist_on_submit()

        # security = Environment.get_security()
        # if security.check_access("builtin", "view_site_admin", "allow"):
        #    select_mode =  SearchTypeSelectWdg.ALL
        # else:
        #    select_mode =  SearchTypeSelectWdg.ALL_BUT_STHPW
        # select = SearchTypeSelectWdg(name='search_type', \
        #    mode=select_mode)

        behavior = {
            "type": "change",
            "cbjs_action": """
            var manager_top = bvr.src_el.getParent(".spt_view_manager_top");

            var input = spt.api.Utility.get_input(manager_top, 'search_type');
            var view_input = spt.api.Utility.get_input(manager_top, 'view');
            var view_input_value = '';
            if (view_input != null) {
                view_input_value = view_input.value;
            }
            var values = {'search_type': input.value, 'view': view_input_value, 'is_refresh': 'true'}; 
            spt.panel.refresh(manager_top, values);"""
            # //spt.panel.refresh(manager_top, values);'''
        }
        select.add_behavior(behavior)
        select.set_value(my.search_type)
        div.add(select)

        if not my.search_type:
            content = DivWdg()
            content.add_style("width: 400px")
            content.add_style("height: 400px")
            div.add(content)
            content.add_style("padding: 20px")
            content.add(IconWdg("WARNING", IconWdg.WARNING))
            content.add("No Search Type Selected")
            content.add_border()
            content.add_style("margin-top: 20px")
            content.add_color("background", "background")
            content.add_style("font-weight: bold")

            return div

        div.add("&nbsp;&nbsp;&nbsp;")
        div.add("<b>View: </b>")
        view_wdg = SelectWdg("view")
        view_wdg.set_value(my.view)
        view_wdg.add_empty_option("-- Select --")
        view_wdg.add_behavior(behavior)
        div.add(view_wdg)

        search = Search("config/widget_config")
        search.add_filter("search_type", my.search_type)
        db_configs = search.get_sobjects()

        views = set()
        for db_config in db_configs:
            view = db_config.get_value("view")
            if view.startswith("link_search:"):
                continue
            views.update([view])

        # print "search_type: ", my.search_type
        # print "view: ", views, my.view

        if my.search_type and my.view:
            config_view = WidgetConfigView.get_by_search_type(my.search_type, my.view)

            configs = config_view.get_configs()
            for x in configs:
                view = x.get_view()
                file_path = x.get_file_path()
                if view != my.view:
                    continue
                if file_path and file_path.endswith("DEFAULT-conf.xml"):
                    continue
                config_views = x.get_all_views()
                views.update(config_views)

        views_list = list(views)
        views_list.sort()
        view_wdg.set_option("values", views_list)

        return div
    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
Beispiel #27
0
    def get_shelf_wdg(my):

        process = my.get_value("process")
        versions = my.get_value("versions")

        div = DivWdg()

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


        button = SingleButtonWdg(title="Refresh", icon=IconWdg.REFRESH)
        filter_table.add_cell(button)
        filter_table.add_cell("&nbsp;"*5)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.panel.refresh(bvr.src_el);
            '''
        } )

        # get all of the pipelnes for this search type
        pipeline_code = my.sobject.get_value("pipeline_code", no_exception=True)
        processes = []
        if pipeline_code:
            pipeline = Pipeline.get_by_code(pipeline_code)
            if pipeline:
                process_names = pipeline.get_process_names()
                processes.extend(process_names)

        processes.insert(0, "all")



        filter_table.add_cell("Process: ")
        select = SelectWdg("process")
        select.add_style("width: 200px")
        if process != 'all':
            select.set_value(process)

        select.set_option("values", processes)

        filter_table.add_cell(select)



        filter_table.add_cell("&nbsp;"*10)

        filter_table.add_cell("Versions: ")
        select = SelectWdg("versions")
        select.add_style("width: 200px")
        select.set_option("values", "latest|current|today|last 10|all")
        if versions:
            select.set_value(versions)
        filter_table.add_cell(select)


        asset_dir = Environment.get_asset_dir()

        select = IconButtonWdg( tip="Toggle Selection", icon=IconWdg.SELECT, show_arrow=False )
        div.add(select)
        select.add_style("float: right")
        select.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top_class = 'spt_sobject_dir_list_top'
            var toggle_state = bvr.src_el.getAttribute('toggle');
            if (toggle_state && toggle_state=='true')
                bvr.src_el.setAttribute('toggle','false');
            else
                bvr.src_el.setAttribute('toggle','true');

            var top = bvr.src_el.getParent("."+top_class);
            spt.selection.set_top(top);
            
            toggle_state = bvr.src_el.getAttribute('toggle');
            if (toggle_state == 'true')
                spt.selection.select_all_items();
            else
                spt.selection.unselect_all_items();

            '''
            } )



        show = IconButtonWdg( tip="Switch View", icon=IconWdg.VIEW, show_arrow=False )
        div.add(show)
        show.add_style("float: right")
        show.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top_class = 'spt_sobject_dir_list_top'
            var top = bvr.src_el.getParent("."+top_class);
            spt.selection.set_top(top);
            var els = top.getElements(".spt_file_dir_item");
            for (var i = 0; i < els.length; i++) {
                var el = els[i];
                if (el.getStyle("display") == "none") {
                    els[i].setStyle("display", "");
                }
                else {
                    els[i].setStyle("display", "none");
                }
            }
            var els = top.getElements(".spt_file_item");
            for (var i = 0; i < els.length; i++) {
                var el = els[i];
                if (el.getStyle("padding-left") == "6px") {
                    var padding = el.getAttribute("spt_padding_left");
                    el.setStyle("padding-left", padding);
                }
                else {
                    el.setStyle("padding-left", "6px");
                }

            }


            '''
        } )






        gear = IconButtonWdg( tip="Download", icon=IconWdg.DOWNLOAD, show_arrow=False )
        div.add(gear)
        gear.add_style("float: right")
        gear.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.app_busy.show('Select a folder to download to...','');
            var top_class = 'spt_sobject_dir_list_top';
            var top = bvr.src_el.getParent("."+top_class);
            spt.selection.set_top(top);
            var items = spt.selection.get_selected();
            
       
            setTimeout( function() {
                var applet = spt.Applet.get();
                var select_dir =true;
                var dir = applet.open_file_browser('', select_dir);
                if (dir.length == 0)
                    dir = applet.get_current_dir();
                else 
                    dir = dir[0];

                if (!dir) {
                    spt.alert("No folder selected to copy to.");
                    spt.app_busy.hide();
                    return;
                }
                if (items.length == 0){
                    spt.alert("Please select at least one file to download.");
                    spt.app_busy.hide();
                    return;
                }
                

                var asset_dir = '%s';
                for (var i = 0; i < items.length; i++) {
                    var path = items[i].getAttribute("spt_path");
                    var env = spt.Environment.get();
                    var server_url = env.get_server_url();
                    var url = server_url + "/assets/" + path.replace(asset_dir, "");
                    var parts = path.split("/");
                    var filename = parts[parts.length-1];
                    spt.app_busy.show("Downloading file", filename);
                    applet.download_file(url, dir + "/" + filename);
                }
                spt.app_busy.hide();
                if (dir)
                    spt.notify.show_message("Download to '" + dir + "' completed.")
            }, 100);

            ''' % asset_dir
 
        } )

        return div
Beispiel #28
0
    def get_display(my):

        top = my.top
        my.set_as_panel(top)

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

        inner = DivWdg()
        top.add(inner)

        title = DivWdg()
        inner.add(title)

        inner.add_class("spt_sync_settings_top")

        inner.add_style("padding: 20px")
        inner.add_color("background", "background")

        server_code = my.get_value("server")

        # get all of the defined servers
        search = Search("sthpw/sync_server")
        servers = search.get_sobjects()
        server_codes = [x.get_code() for x in servers]
        if not server_codes and not server_code:
            msg_div = DivWdg()
            msg_div.add("No servers defined.  Please add a server")
            inner.add(msg_div)
            return top

        if len(server_codes) == 1 or not server_code:
            server_code = server_codes[0]

        select = SelectWdg("server")
        inner.add("Server: ")
        inner.add(select)
        select.set_option("values", server_codes)
        if server_code:
            select.set_value(server_code)
        else:
            return top

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_sync_settings_top");
            spt.panel.refresh(top);
            '''
        })

        project = Project.get()
        project_code = project.get_code()
        if project_code == "admin":
            project_code = ""

        inner.add(my.get_install_wdg(server_code, project_code))
        inner.add(my.get_dump_wdg(server_code, project_code))

        if is_refresh:
            return inner
        else:
            return top
    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
Beispiel #30
0
    def get_display(self):

        top = self.top
        self.set_as_panel(top)
        top.add_class("spt_ingestion_top")
        top.add_color("background", "background", -5)

        self.data = {}

        rules_div = DivWdg()
        top.add(rules_div)
        rules_div.add_style("padding: 10px")

        rules_div.add("Rules: ")

        rules_select = SelectWdg("rule_code")
        rule_code = self.get_value('rule_code')
        if rule_code:
            rules_select.set_value(rule_code)
        rules_select.set_option("query", "config/ingest_rule|code|title")
        rules_select.add_empty_option("-- New --")
        rules_div.add(rules_select)
        rules_select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;
        var class_name = 'tactic.ui.tools.IngestionToolWdg';
        spt.panel.load(top, class_name, {rule_code: value} );
        '''
        })

        rules_div.add("<hr/>")

        # read from the database
        if rule_code:
            search = Search("config/ingest_rule")
            search.add_filter("code", rule_code)
            sobject = search.get_sobject()
        else:
            sobject = None
        if sobject:
            self.data = sobject.get_value("data")
            if self.data:
                self.data = jsonloads(self.data)

        session_code = self.kwargs.get("session_code")
        if session_code:
            session = Search.get_by_code("config/ingest_session", session_code)
        else:
            if sobject:
                session = sobject.get_related_sobject("config/ingest_session")
                print("sobject: ", sobject.get_code(),
                      sobject.get_value("spt_ingest_session_code"))
                print("parent: ", session)
            else:
                session = None

        if not session:
            #session = SearchType.create("config/ingest_session")
            #session.set_value("code", "session101")
            #session.set_value("location", "local")
            ##session.set_value("base_dir", "C:")
            top.add("No session defined!!!")
            return top

        rule = ""
        filter = ""
        ignore = ""

        # get the base path
        if sobject:
            base_dir = sobject.get_value("base_dir")
        else:
            base_dir = ''

        #else:
        #    base_dir = self.get_value("base_dir")
        #if not base_dir:
        #    base_dir = ''

        if sobject:
            title = sobject.get_value("title")
        else:
            title = ''

        if sobject:
            code = sobject.get_value("code")
        else:
            code = ''

        file_list = self.get_value("file_list")
        scan_type = self.get_value("scan_type")
        action_type = self.get_value("action_type")
        rule = self.get_value("rule")
        if not rule:
            rule = base_dir

        # get the rule for this path
        checkin_mode = "dir"
        depth = 0

        table = Table()
        rules_div.add(table)
        table.add_color("color", "color")

        from tactic.ui.input.text_input_wdg import TextInputWdg

        # add the title
        table.add_row()
        td = table.add_cell()
        td.add("Title: ")
        td = table.add_cell()

        text = TextInputWdg(name="title")
        td.add(text)
        if title:
            text.set_value(title)
        text.add_class("spt_title")
        text.add_style("width: 400px")
        #text.add_color("background", "background", -10)

        # add the optional code
        table.add_row()
        td = table.add_cell()
        td.add("Code (optional): ")
        td = table.add_cell()

        text = TextInputWdg(name="code")
        td.add(text)
        if code:
            text.set_value(code)
            text.set_readonly()
            text.add_color("background", "background", -10)
        text.add_class("spt_code")
        text.add_style("width: 400px")

        table.add_row()
        td = table.add_cell()
        td.add_style("height: 10px")
        td.add("<hr/>")

        table.add_row()
        td = table.add_cell()
        td.add("<b>Scan:</b><br/>")
        td.add(
            "The following information will be used to find the paths that will be operated on by the ingestion process<br/><br/>"
        )

        # add a scan type
        table.add_row()
        td = table.add_cell()
        td.add("Type: ")
        select = SelectWdg("scan_type")
        select.add_class("spt_scan_type")
        td = table.add_cell()
        td.add(select)
        select.set_value(self.get_value("action"))
        labels = ['Simple List', 'Rule', 'Script']
        values = ['list', 'rule', 'script']
        select.set_option("values", values)
        select.set_option("labels", labels)
        if scan_type:
            select.set_value(scan_type)

        table.add_row()
        table.add_cell("&nbsp;")

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;

        var elements = top.getElements(".spt_scan_list");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'list')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        var elements = top.getElements(".spt_scan_rule");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'rule')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }
        var elements = top.getElements(".spt_scan_script");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'script')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        '''
        })

        # add in a list of stuff
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_list")
        if scan_type != 'list':
            tbody.add_style("display: none")

        tr = table.add_row()
        td = table.add_cell()
        td.add("List of files: ")
        td = table.add_cell()

        text = TextAreaWdg(name="file_list")
        td.add(text)
        text.add_style("width: 400px")
        #text.set_readonly()
        #text.add_color("background", "background", -10)
        text.set_value(file_list)

        table.close_tbody()

        # add rule scan mode
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_rule")
        if scan_type != 'rule':
            tbody.add_style("display: none")

        # add the path
        tr = table.add_row()
        td = table.add_cell()
        td.add("Starting Path: ")
        td = table.add_cell()

        hidden = HiddenWdg("session_code", session.get_code())
        td.add(hidden)

        text = TextInputWdg(name="base_dir")
        td.add(text)
        text.set_value(base_dir)
        text.add_style("width: 400px")
        #text.set_readonly()
        #text.add_color("background", "background", -10)
        text.set_value(base_dir)

        # add rule
        tr = table.add_row()
        td = table.add_cell()
        td.add("Tag Rule: ")
        td = table.add_cell()

        text = TextInputWdg(name="rule")
        td.add(text)
        text.add_style("width: 400px")
        text.set_value(rule)

        tr = table.add_row()
        td = table.add_cell()
        td.add("Filter: ")
        td = table.add_cell()
        text = TextWdg("filter")
        td.add(text)
        text.set_value(self.get_value("filter"))
        text.add_style("width: 400px")
        text.add_style("padding: 2px")
        text.add_style("-moz-border-radius: 5px")

        tr = table.add_row()
        td = table.add_cell()
        td.add("Ignore: ")
        td = table.add_cell()
        text = TextWdg("ignore")
        td.add(text)
        text.set_value(self.get_value("ignore"))
        text.set_value(ignore)
        text.add_style("width: 400px")
        text.add_style("padding: 2px")
        text.add_style("-moz-border-radius: 5px")

        table.add_row()
        td = table.add_cell()
        td.add("Validation script: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextInputWdg(name="validation_script")
        text.set_value(self.get_value("validation_script"))
        text.add_style("width: 400px")
        td.add(text)

        icon = IconButtonWdg(title='Edit Validation Script', icon=IconWdg.EDIT)
        icon.add_style("float: right")
        td.add(icon)
        icon.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        spt.named_events.fire_event("show_script_editor");

        var top = bvr.src_el.getParent(".spt_ingestion_top");
        var values = spt.api.Utility.get_input_values(top, null, false);

        var kwargs = {
            script_path: values.validation_script
        }
        setTimeout( function() {
        spt.js_edit.display_script_cbk(evt, kwargs)
        }, 500 );
        '''
        })

        table.close_tbody()

        # add the script path
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_script")
        if scan_type != 'script':
            tbody.add_style("display: none")

        tr = table.add_row()
        td = table.add_cell()
        td.add("Script Path: ")
        td = table.add_cell()

        text = TextInputWdg(name="script_path")
        td.add(text)
        text.add_style("width: 400px")

        table.close_tbody()

        table.add_row()
        td = table.add_cell("<hr/>")

        table.add_row()
        td = table.add_cell()
        td.add("<b>Action</b><br/>")
        td.add(
            "The following information define the actions that will be used on each matched path<br/><br/>"
        )

        # pick the type of action
        table.add_row()
        td = table.add_cell()
        td.add("Type: ")
        select = SelectWdg("action_type")
        td = table.add_cell()
        td.add(select)
        labels = ['Checkin', 'Ignore']
        values = ['checkin', 'ignore']
        select.set_option("values", values)
        select.set_option("labels", labels)
        select.add_empty_option("-- Select --")
        if action_type:
            select.set_value(action_type)

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;

        var elements = top.getElements(".spt_action_ignore");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'ignore')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        var elements = top.getElements(".spt_action_checkin");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'checkin')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        '''
        })

        table.add_row()
        td = table.add_cell("<br/>")

        # add the script path
        tbody = table.add_tbody()
        tbody.add_class("spt_action_checkin")
        if action_type != 'checkin':
            tbody.add_style("display: none")

        # add the checkin type
        table.add_row()
        td = table.add_cell()
        td.add("Action: ")
        select = SelectWdg("action")
        td = table.add_cell()
        td.add(select)
        select.set_value(self.get_value("action"))
        labels = ['File Checkin', 'Directory Checkin', 'Sequence Checkin']
        values = ['file', 'directory', 'sequence', 'ignore']
        select.set_option("values", values)
        select.set_option("labels", labels)

        table.add_row()
        td = table.add_cell()
        td.add("Mode: ")
        select = SelectWdg("mode")
        td = table.add_cell()
        td.add(select)
        labels = ['Copy', 'Move', 'In Place']
        values = ['copy', 'move', 'inplace']
        select.set_option("values", values)
        select.set_option("labels", labels)

        # add the search_type
        table.add_row()
        td = table.add_cell()
        td.add("sType: ")
        td = table.add_cell()
        select = SelectWdg("search_type")
        td.add(select)
        search_types = Project.get().get_search_types()
        values = [x.get_value("search_type") for x in search_types]
        select.set_option("values", values)

        search_type = self.kwargs.get("search_type")
        if search_type:
            select.set_value(search_type)

        # add the search_type
        table.add_row()
        td = table.add_cell()
        td.add("Context: ")
        td = table.add_cell()
        select = SelectWdg("context")
        td.add(select)
        select.set_option("values", ['publish', 'by rule', 'custom'])

        # add extra values
        extra_div = DivWdg()
        text = TextWdg("extra_name")
        text.add_attr("spt_is_multiple", "true")
        extra_div.add(text)
        extra_div.add(" = ")
        text = TextWdg("extra_value")
        extra_div.add(text)
        text.add_attr("spt_is_multiple", "true")

        template_div = DivWdg()
        text = TextWdg("extra_name")
        text.add_attr("spt_is_multiple", "true")
        template_div.add(text)
        template_div.add(" = ")
        text = TextWdg("extra_value")
        template_div.add(text)
        text.add_attr("spt_is_multiple", "true")

        table.close_tbody()

        table.add_row()
        td = table.add_cell("<br/>")

        table.add_row()
        td = table.add_cell()
        td.add("Extra Keywords: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("keywords")
        text.add_style("width: 300px")
        td.add(text)

        table.add_row()
        td = table.add_cell()
        td.add("Extra Values: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        extra_list = DynamicListWdg()
        td.add(extra_list)
        extra_list.add_item(extra_div)
        extra_list.add_template(template_div)

        table.add_row()
        table.add_cell("&nbsp;")

        table.add_row()
        td = table.add_cell()
        td.add("Process script: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("process_script")
        text.add_style("width: 300px")
        td.add(text)
        text.set_value(self.get_value("process_script"))

        icon = IconButtonWdg(title='Edit Process Script', icon=IconWdg.EDIT)
        icon.add_style("float: right")
        td.add(icon)
        icon.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        spt.named_events.fire_event("show_script_editor");

        var top = bvr.src_el.getParent(".spt_ingestion_top");
        var values = spt.api.Utility.get_input_values(top, null, false);

        var kwargs = {
            script_path: values.process_script
        }

        // need to wait for this
        setTimeout( function() {
        spt.js_edit.display_script_cbk(evt, kwargs)
        }, 500 );
        '''
        })

        table.add_row()
        td = table.add_cell()
        td.add("Custom Naming: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("naming")
        text.add_style("width: 300px")
        td.add(text)

        table.add_row()
        td = table.add_cell()

        #td.add("<br clear='all'/>")
        td.add("<hr/>")

        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''

            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var values = spt.api.Utility.get_input_values(top, null, false);

            spt.app_busy.show("Scanning ...", values.base_dir);

            var class_name = 'tactic.ui.tools.IngestionProcessWdg';

            var server = TacticServerStub.get();
            values.mode = bvr.mode;

            values.is_local = 'true';

            // scan client side
            if (values.is_local == 'true') {
                var base_dir = values.base_dir;
                var applet = spt.Applet.get();
                var files = applet.list_recursive_dir(base_dir);
                // turn into a string
                var files_in_js = [];
                for (var i = 0; i < files.length; i++) {
                    var file = files[i].replace(/\\\\/g, "/");
                    files_in_js.push( file );
                }
                values.files = files_in_js;
                values.base_dir = base_dir;

                /*
                var server = TacticServerStub.get();
                var handoff_dir = server.get_handoff_dir();
                var applet = spt.Applet.get();
                for (var i = 0; i < files_in_js.length; i++) {
                    try {
                        var parts = files_in_js[i].split("/");
                        var filename = parts[parts.length-1];
                        spt.app_busy.show("Copying files to handoff", filename);
                        applet.copy_file(files_in_js[i], handoff_dir+"/"+filename);
                    } catch(e) {
                        log.error(e);
                    }

                }
                */
            }

            var info_el = top.getElement(".spt_info");
            spt.panel.load(info_el, class_name, values);
            spt.app_busy.hide();
            '''
        }

        # Save button
        button = ActionButtonWdg(title="Save", tip="Save Rule")
        td.add(button)
        button.add_style("float: right")
        behavior['mode'] = 'save'
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''

            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var values = spt.api.Utility.get_input_values(top, null, false);
            spt.app_busy.show("Saving ...");

            var class_name = 'tactic.command.CheckinRuleSaveCmd';
            var server = TacticServerStub.get();
            server.execute_cmd(class_name, values);

            spt.panel.refresh(top, {});

            spt.app_busy.hide();

            '''
        })

        # Scan button
        button = ActionButtonWdg(title="Scan", tip="Click to Scan")
        td.add(button)
        button.add_style("float: left")

        # set a limit
        #limit = TextWdg("limit")
        #td.add(limit)
        #text.add_style("float: left")

        behavior = behavior.copy()
        behavior['mode'] = 'scan'
        button.add_behavior(behavior)

        # Test button
        button = ActionButtonWdg(title="Test", tip="Do a test of this rule")
        td.add(button)
        behavior = behavior.copy()
        behavior['mode'] = 'test'
        button.add_behavior(behavior)
        button.add_style("float: left")

        # Ingest button
        button = ActionButtonWdg(title="Ingest",
                                 tip="Click to start ingesting")
        td.add(button)
        behavior = behavior.copy()
        behavior['mode'] = 'checkin'
        button.add_behavior(behavior)

        table.add_behavior({
            'type':
            'listen',
            'event_name':
            'file_browser|select',
            'cbjs_action':
            '''
            var dirname = bvr.firing_data.dirname;
            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var kwargs = {
              base_dir: dirname
            };

            spt.panel.load(top, top.getAttribute("spt_class_name"), kwargs);
            '''
        })

        top.add(self.get_info_wdg())

        return top
Beispiel #31
0
    def get_display(self):
        self.check()
        if self.is_refresh:
            div = Widget()
        else:
            div = DivWdg()
            self.set_as_panel(div)
            div.add_style('padding','6px')
            min_width = '400px'
            div.add_style('min-width', min_width)
            div.add_color('background','background')
            div.add_class('spt_add_task_panel')
            div.add_style("padding: 20px")


        from tactic.ui.app import HelpButtonWdg
        help_button = HelpButtonWdg(alias="creating-tasks")
        div.add(help_button)
        help_button.add_style("float: right")
        help_button.add_style("margin-top: -5px")

        if not self.search_key_list:
            msg_div = DivWdg()
            msg_table = Table()
            msg_div.add(msg_table)
            msg_table.add_row()
            msg_table.add_cell( IconWdg("No items selected", IconWdg.WARNING) )
            msg_table.add_cell('Please select at least 1 item to add tasks to.')

            msg_div.add_style('margin: 10px')
            msg_table.add_style("font-weight: bold")
            div.add(msg_div)
            return div

        msg_div = DivWdg()
        msg_div.add_style('margin-left: 4px')
        div.add(msg_div, 'info')
        msg_div.add('Total: %s item/s to add tasks to' %len(self.search_key_list))
        div.add(HtmlElement.br())
        hint = HintWdg('Tasks are added according to the assigned pipeline.')
        msg_div.add(" &nbsp; ")
        msg_div.add(hint)
        msg_div.add(HtmlElement.br())
        
        
        option_div = DivWdg(css='spt_ui_options')
        #option_div.add_style('margin-left: 12px')
        
        sel = SelectWdg('pipeline_mode', label='Create tasks by: ')
        sel.set_option('values', ['simple process','context', 'standard'])
        sel.set_option('labels', ['process','context', 'all contexts in process'])
        sel.set_persistence()
        sel.add_behavior({'type':'change',
                 'cbjs_action': 'spt.panel.refresh(bvr.src_el)'}) 
        
        option_div.add(sel)

        value = sel.get_value()
        # default to simple process
        if not value:
            value = 'simple process'
        msg = ''
        if value not in ['simple process','context','standard']:
            value = 'simple process'
        
        if value == 'context':
            msg = 'In context mode, a single task will be created for each selected context.'
        elif value == 'simple process':
            msg = 'In process mode, a single task will be created for each selected process.'

        elif value == 'standard':
            msg = 'In this mode, a task will be created for all contexts of each selected process.'

        option_div.add(HintWdg(msg))
        div.add(option_div)
        div.add(HtmlElement.br())

        title = DivWdg('Assigned Pipelines')
        title.add_style('padding: 6px')
        title.add_color('background','background2')
        title.add_color('color','color', +120)
        div.add(title)
    
        content_div = DivWdg()
        content_div.add_style('min-height', '150px')
        div.add(content_div)
        content_div.add_border()
        
        filtered_search_key_list = []
        for sk in self.search_key_list:
            id = SearchKey.extract_id(sk)
            if id=='-1':
                continue
            filtered_search_key_list.append(sk)

        sobjects = SearchKey.get_by_search_keys(filtered_search_key_list)
        skipped = []
        pipeline_codes = []
        for sobject in sobjects:
            if isinstance(sobject, Task):
                msg_div = DivWdg('WARNING: Creation of task for [Task] is not allowed.')
                msg_div.add_style('margin-left: 10px')
                div.add(msg_div, 'info')
                return div
            pipeline_code = sobject.get_value('pipeline_code', no_exception=True)
            if not pipeline_code:
                skipped.append(sobject)
            if pipeline_code not in pipeline_codes:
                pipeline_codes.append(pipeline_code)
       

        pipelines = Search.get_by_code('sthpw/pipeline', pipeline_codes)
        if pipelines == None:
            pipelines = []
        #if not pipelines:
        #    msg_div = DivWdg('WARNING: No Pipelines found for selected.')
        #    msg_div.add_style('margin-left: 10px')
        #    div.add(msg_div, 'info')
        #    return div

        # expand the width according to num of pipelines
        content_div.add_style('min-width', len(pipelines)*250)
        mode_cb = SelectWdg('pipeline_mode') 
        mode_cb.set_persistence()
        mode = mode_cb.get_value()
        if 'context' == mode:
            mode = 'context'
        else:   
            mode = 'process'

        show_subpipeline = True
        min_height = '150px'



        # create a temp default pipeline
        if not pipelines:
            pipeline = SearchType.create("sthpw/pipeline")
            pipeline.set_value("code", "__default__")
            pipeline.set_value("pipeline", '''
<pipeline>
    <process name='publish'/>
</pipeline>
            ''')
            # FIXME: HACK to initialize virtual pipeline
            pipeline.set_pipeline(pipeline.get_value("pipeline"))
            pipelines = [pipeline]

        for pipeline in pipelines:
            name = pipeline.get_value("name")
            if not name:
                name = pipeline.get_code()
            span = SpanWdg("Pipeline: %s" % name)
            span.add_style('font-weight: bold')
            v_div = FloatDivWdg(span)
            v_div.add_style('margin: 20px')
            v_div.add_style('min-height', min_height)
            v_div.add(HtmlElement.br(2))
            content_div.add(v_div)    
            processes = pipeline.get_processes(recurse=show_subpipeline, type=['manual','approval'])

            cb_name = '%s|task_process'  %pipeline.get_code()
            master_cb = CheckboxWdg('master_control')
            master_cb.set_checked()
            master_cb.add_behavior({'type': 'click_up',
                'propagate_evt': True,
                'cbjs_action': '''
                    var inputs = spt.api.Utility.get_inputs(bvr.src_el.getParent('.spt_add_task_panel'),'%s');
                    for (var i = 0; i < inputs.length; i++)
                        inputs[i].checked = bvr.src_el.checked;
                        ''' %cb_name})
            toggle_div = DivWdg()
            toggle_div.add(SpanWdg(master_cb, css='small'))
            label = HtmlElement.i('toggle all')
            label.add_style('color: #888')
            toggle_div.add_styles('border-bottom: 1px solid #888; width: 170px')
            toggle_div.add(label)
            v_div.add(toggle_div)
            process_names = []

            for process in processes:
                process_labels = []
                if process.is_from_sub_pipeline():
                    process_name  = process.get_full_name()
                else:
                    process_name  = process.get_name()

                process_label = process.get_label()
                if not process_label:
                    process_label = ''
                if mode =='context':
                    contexts =  pipeline.get_output_contexts(process.get_name())
                    
                    labels = contexts
                    if process.is_from_sub_pipeline():
                        labels = ['%s/%s'%(process.parent_pipeline_code, x) for x in contexts]
                    
                    for x in labels: 
                        process_labels.append(process_label)
                    
                    # prepend process to contexts in this mode to ensure uniqueness
                    contexts = ['%s:%s' %(process_name, x) for x in contexts]
                else:
                    contexts = [process_name]
                    labels = contexts
                
                    process_labels.append(process_label)

                for idx, context in enumerate(contexts):
                    cb = CheckboxWdg(cb_name)
                    cb.set_checked()
                    cb.set_option('value', context)
                    v_div.add(SpanWdg(cb, css='small'))
                    if mode == 'context':
                        span = SpanWdg(process_name, css='med')
                        #span.add_color('color','color')
                        v_div.add(span)
                    v_div.add(SpanWdg(labels[idx]))
                    process_label = process_labels[idx]
                    if process_label:
                        v_div.add(SpanWdg("(%s)" %process_label, css='small'))
                    v_div.add(HtmlElement.br())
        
       
        content_div.add("<br clear='all'/>")

        skipped = [] 

        if True:
            div.add("<br/>")
            btn = ActionButtonWdg(title='Add Tasks')
            btn.add_behavior({'type' : 'click_up',
            'post_event': 'search_table_%s'% self.table_id,
            'cbjs_action': '''
            spt.dg_table.add_task_selected(bvr);
            ''',
            'search_key_list': self.search_key_list
            })
            cb = CheckboxWdg('skip_duplicated', label='Skip Duplicates')
            cb.set_checked()
            option_div =DivWdg(cb)
            option_div.add_style('width', '130px')
            option_div.add_style('align: left')
            div.add(option_div)
            div.add(HtmlElement.br())
            btn.add_style("float: right")
            div.add(btn)
            div.add(HtmlElement.br(clear="all"))


        if skipped:
            content_div.add(HtmlElement.br())
            skip_div = DivWdg('Missing pipeline code (Skipped)')
            skip_div.add_style('text-decoration: underline')
            content_div.add(skip_div)
            content_div.add(HtmlElement.br())
            item_div = DivWdg()
            item_div.add_style('margin-left: 10px')
            content_div.add(item_div)
        for skip in skipped:
            item_div.add(skip.get_code())
            item_div.add(HtmlElement.br())



        return div
Beispiel #32
0
    def get_display(my):
        top = my.top
        my.set_as_panel(top)
        top.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            spt.named_events.fire_event("side_bar|hide")
            '''
        } )
        top.add_style("width: 100%")
        top.add_color("background", "background", -10)
        top.add_style("padding-top: 10px")
        top.add_style("padding-bottom: 50px")
        top.add_class("spt_project_top")

        inner = DivWdg()
        top.add(inner)
        inner.add_style("width: 700px")
        inner.add_style("float: center")
        inner.add_border()
        inner.center()
        inner.add_style("padding: 30px")
        inner.add_color("background", "background")


        from tactic.ui.container import WizardWdg


        title = DivWdg()
        title.add("Create A New Project")

        wizard = WizardWdg(title=title, width="100%")
        inner.add(wizard)


        help_button = ActionButtonWdg(title="?", tip="Create Project Help", size='s')
        title.add(help_button)
        help_button.add_style("float: right")
        help_button.add_style("margin-top: -20px")
        help_button.add_style("margin-right: -10px")
        help_button.add_behavior({
            'type': 'click_up',
            'cbjs_action': '''
            spt.help.set_top();
            spt.help.load_alias("create-new-project");
            '''
        })




        info_page = DivWdg()
        wizard.add(info_page, 'Info')
        info_page.add_class("spt_project_top")
        info_page.add_style("font-size: 12px")
        info_page.add_color("background", "background")
        info_page.add_color("color", "color")
        info_page.add_style("padding: 20px")



        from tactic.ui.input import TextInputWdg

        info_page.add("<b>Project Title:</b> &nbsp;&nbsp;")
    
        text = TextWdg("project_title")
        text.add_behavior( {
            'type': 'blur',
            'cbjs_action': '''
            if (bvr.src_el.value == '') {
                spt.alert("You must enter a project title");
                return;
            }
        '''})

        #text = TextInputWdg(title="project_title")
        info_page.add(text)
        text.add_style("width: 250px")
        info_page.add(HtmlElement.br(3))
        span = DivWdg()
        info_page.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add_color("background", "background3")
        span.add("The project title can be descriptive and contain spaces and special characters.")
        info_page.add("<br/><br/><hr/><br/><br/>")
        text.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var title = bvr.src_el.value;
        if (title.length > 100) {
            spt.alert("Title cannot exceed 100 characters.");
            return;
        }
        var code = spt.convert_to_alpha_numeric(title);
        code = code.substring(0,30);
        var top = bvr.src_el.getParent(".spt_project_top");
        var code_el = top.getElement(".spt_project_code");
        code_el.value = code;
        '''
        } )


        info_page.add("<b>Project Code: &nbsp;&nbsp;</b>")
        text = TextWdg("project_code")
        #text = TextInputWdg(title="project_code")
        text.add_behavior( {
            'type': 'blur',
            'cbjs_action': '''
            var value = bvr.src_el.value;
            var code = spt.convert_to_alpha_numeric(value);
            bvr.src_el.value = code;
            
            if (code == '') {
                spt.alert("You must enter a project code.");
                return;
            }
            if (spt.input.has_special_chars(code)) {
                spt.alert("Project code cannot contain special characters.");
                return;
            }
        
            if (code.test(/^\d/)) {
                spt.alert("Project code cannot start with a number.");
                return;
            }
            if (code.length > 30) {
                 spt.alert("Project code cannot exceed 30 characters.");
                return;
            }
       
            '''
        } )


        info_page.add(text)
        text.add_style("width: 250px")
        text.add_class("spt_project_code")
        info_page.add(HtmlElement.br(4))

        span = DivWdg()
        info_page.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add_color("background", "background3")
        span.add("The project code is a very important key that will tie many components of the project together.")
        span.add("<br/><br/>")
        span.add("* Note: the project code must contain only alphanumeric characters [A-Z]/[0-9] and only an '_' as a separator")
        info_page.add(span)

        info_page.add("<br/>"*2)


        projects = Project.get_all_projects()

        info_page.add("<b>Is Main Project? </b>")

        checkbox = CheckboxWdg("is_main_project")
        default_project_code = Config.get_value("install", "default_project")
        info_page.add(checkbox)
        if default_project_code:
            default_project = Project.get_by_code(default_project_code)
        else:
            default_project = None

        if default_project:
            default_title = default_project.get_value("title")
            info_span = SpanWdg()
            info_page.add(info_span)
            info_span.add("%sCurrent: %s (%s)" % ("&nbsp;"*3, default_title, default_project_code))
            info_span.add_style("font-size: 0.9em")
            info_span.add_style("font-style: italic")
        else:
            if len(projects) == 0:
                checkbox.set_checked()

        info_page.add("<br/>"*2)

        span = DivWdg()
        info_page.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add_color("background", "background3")
        span.add("A TACTIC installation can have multiple projects, but one can be designated as the main project.  This project will appear at the root of the url. This is meant for building custom project launcher which is based on a main project.")
        span.add("<br/>"*2)
        span.add("* Note: TACTIC may need to be restarted in order for this to take effect")
        info_page.add(span)

        info_page.add("<br/>")









        # add an icon for this project
        image_div = DivWdg()
        wizard.add(image_div, 'Preview Image')
        image_div.add_class("spt_image_top")
        image_div.add_color("background", "background")
        image_div.add_color("color", "color")
        image_div.add_style("padding: 20px")


        image_div.add("<b>Project Image: </b>")
        image_div.add("<br/>"*3)
        on_complete = '''var server = TacticServerStub.get();
        var file = spt.html5upload.get_file(); 
        if (file) { 

            var top = bvr.src_el.getParent(".spt_image_top");
            var text = top.getElement(".spt_image_path");
            var display = top.getElement(".spt_path_display");
            var check_icon = top.getElement(".spt_check_icon");

            var server = TacticServerStub.get();
            var ticket = spt.Environment.get().get_ticket();


            display.innerHTML = "Uploaded: " + file.name;
            display.setStyle("padding", "10px");
            check_icon.setStyle("display", "");
          
          
            var filename = file.name;
            filename = spt.path.get_filesystem_name(filename);
            var kwargs = {
                ticket: ticket,
                filename: filename
            }
            try {
                var ret_val = server.execute_cmd("tactic.command.CopyFileToAssetTempCmd", kwargs);
                var info = ret_val.info;
                var path = info.web_path;
                text.value = info.lib_path;
                display.innerHTML = display.innerHTML + "<br/><br/><div style='text-align: center'><img style='width: 80px;' src='"+path+"'/></div>";
            }
            catch(e) {
                spt.alert(spt.exception.handler(e));
            }
            spt.app_busy.hide();
            }
        else {
            spt.alert('Error: file object cannot be found.') 
        }
            spt.app_busy.hide();
        '''
        button = UploadButtonWdg(title="Browse", on_complete=on_complete) 
        button.add_style("margin-left: auto")
        button.add_style("margin-right: auto")
        image_div.add(button)


        text = HiddenWdg("project_image_path")
        text.add_class("spt_image_path")
        image_div.add(text)

        check_div = DivWdg()
        image_div.add(check_div)
        check_div.add_class("spt_check_icon")
        check_icon = IconWdg("Image uploaded", IconWdg.CHECK)
        check_div.add(check_icon)
        check_div.add_style("display: none")
        check_div.add_style("float: left")
        check_div.add_style("padding-top: 8px")

        path_div = DivWdg()
        image_div.add(path_div)
        path_div.add_class("spt_path_display")

        image_div.add(HtmlElement.br(3))
        span = DivWdg()
        image_div.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add_color("background", "background3")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add("The project image is a small image that will be used in various places as a visual representation of this project.")

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





        # get all of the template projects that are installed
        copy_div = DivWdg()
        wizard.add(copy_div, "Template")
        copy_div.add_style("padding-top: 20px")





        template = ActionButtonWdg(title="Manage", tip="Manage Templates")
        copy_div.add(template)
        template.add_style("float: right")
        template.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
                var class_name = 'tactic.ui.app.ProjectTemplateWdg'
                spt.panel.load_popup("Templates", class_name)
            '''
        } )
        template.add_style("margin-top: -5px")




        copy_div.add("<b>Copy From Template: &nbsp;&nbsp;</b>")



        search = Search("sthpw/project")
        search.add_filter("is_template", True)
        template_projects = search.get_sobjects()
        values = [x.get_value("code") for x in template_projects]
        labels = [x.get_value("title") for x in template_projects]


        # find all of the template projects installed
        template_dir = Environment.get_template_dir()
        import os
        if not os.path.exists(template_dir):
            paths = []
        else:
            paths = os.listdir(template_dir);


            file_values = []
            file_labels = []
            for path in paths:
                if path.endswith("zip"):
                    orig_path = '%s/%s'%(template_dir, path)
                    path = path.replace(".zip", "")
                    parts = path.split("-")
                    plugin_code = parts[0]

                    # skip if there is a matching project in the database
                    #match_project = plugin_code.replace("_template", "")
                    
                    match_project = plugin_code
                    old_style_plugin_code = re.sub( '_template$', '', plugin_code)

                    if match_project in values:
                        continue
                    elif old_style_plugin_code in values:
                        continue

                    label = "%s (from file)" % Common.get_display_title(match_project)

                    # for zip file, we want the path as well
                    value = '%s|%s'%(plugin_code, orig_path)
                    file_values.append(value)
                    file_labels.append(label)

            if file_values:
                values.extend(file_values)
                labels.extend(file_labels)


        values.insert(0, "_empty")
        labels.insert(0, "- Empty Project -")

        select = SelectWdg("project_source")
        copy_div.add(select)
        select.set_option("values", values)
        select.set_option("labels", labels)
        #select.add_empty_option("-- Select --")

        select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        var top = bvr.src_el.getParent(".spt_project_top");
        var type = top.getElement(".spt_custom_project_top");
        var namespace_option = top.getElement(".spt_custom_namespace_top");

        var theme_el = top.getElement(".spt_theme_top");

        if (bvr.src_el.value == "_empty") {
            spt.show(type);
            spt.show(namespace_option);

            spt.show(theme_el);

        }
        else {
            spt.hide(type);
            spt.hide(namespace_option);

            spt.hide(theme_el);
        }
        '''
        } )



        copy_div.add(HtmlElement.br(3))
        span = DivWdg()
        copy_div.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add_color("background", "background3")
        span.add("This will use the selected project template as a basis and copy all of the configuration elements.  Only template projects should be copied.")

        #copy_div.add(HtmlElement.br(2))
        #span = DivWdg("This will create an empty project with no predefined configuration.")
        #copy_div.add(span)

        #
        # Theme
        #
        theme_div = DivWdg()
        theme_div.add_class("spt_theme_top")
        theme_div.add_style("padding: 10px")
        theme_div.add_style("margin-top: 20px")
        copy_div.add(theme_div)
        theme_div.add("<b>Theme: </b>&nbsp; ")
        theme_div.add_style('padding-right: 6px')

        theme_select = SelectWdg('project_theme')
        theme_div.add(theme_select)



        # look in the plugins for all of the themes?
        from pyasm.biz import PluginUtil
        plugin_util = PluginUtil()
        data = plugin_util.get_plugins_data("theme")

        builtin_dir = Environment.get_builtin_plugin_dir()
        plugin_util = PluginUtil(base_dir=builtin_dir)

        data2 = plugin_util.get_plugins_data("theme")


        data = dict(data.items() + data2.items())

        themes = data.keys()
        themes.sort()




        theme_select.set_option("values", themes)
        theme_select.add_empty_option('- No Theme -')
        default_theme = "TACTIC/default_theme"
        theme_select.set_value(default_theme)

        theme_select.add_behavior( {
            'type': 'change',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_project_top");
            var img_div = top.getElement(".spt_project_theme_div");
            var theme = bvr.src_el.value;

            var img_els = img_div.getElements(".spt_project_theme_image");
            for (var i = 0; i < img_els.length; i++) {
                if (theme == img_els[i].getAttribute("spt_theme") ) {
                    img_els[i].setStyle("display", "");
                }
                else {
                    img_els[i].setStyle("display", "none");
                }
            }
            '''
        } )

        theme_img_div = DivWdg()
        theme_div.add(theme_img_div)
        theme_img_div.add_class("spt_project_theme_div")

        for theme in themes:
            theme_item = DivWdg()
            theme_item.add_style("margin: 15px")
            theme_img_div.add(theme_item)
            theme_item.add_attr("spt_theme", theme)
            theme_item.add_class("spt_project_theme_image")
            if theme != default_theme:
                theme_item.add_style("display: none")

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

            if Environment.is_builtin_plugin(theme):
                theme_img = HtmlElement.img(src="/tactic/builtin_plugins/%s/media/screenshot.jpg" % theme)
            else:
                theme_img = HtmlElement.img(src="/tactic/plugins/%s/media/screenshot.jpg" % theme)
            theme_img.add_border()
            theme_img.set_box_shadow("1px 1px 1px 1px")
            theme_img.add_style("margin: 20px 10px")
            theme_img.add_style("width: 240px")

            plugin_data = data.get(theme)

            description = plugin_data.get("description")
            if not description:
                description = "No Description"

            table.add_cell(theme_img)
            table.add_cell( description )



        theme_img_div.add_style("text-align: center")
        theme_img_div.add_style("margin: 10px")

 

        #
        # namespace
        #
        ns_div = DivWdg()
        ns_div.add_class("spt_custom_namespace_top")
        ns_div.add_style("padding: 10px")
        copy_div.add(ns_div)
        ns_div.add("<br/>")
        ns = HtmlElement.b("Namespace:")
        ns.add_style('padding-right: 6px')
        ns_div.add(ns)

        text = TextWdg('custom_namespace')
        text.add_class("spt_custom_namespace")
        text.add_behavior( {
            'type': 'blur',
            'cbjs_action': '''
                 var project_namespace = bvr.src_el.value;
                 if (['sthpw','prod'].contains(project_namespace)) 
                    spt.alert('Namespace [' + project_namespace + '] is reserved.');

                 if (project_namespace.strip()=='') 
                    spt.alert('A "default" namespace will be used if you leave it empty.');
            
            '''})

        ns_div.add(text)

        hint = HintWdg('This will be used as the prefix for your sTypes. You can use your company name for instance')
        ns_div.add(hint)

        # is_template
        is_template_div = DivWdg()
        #is_template_div.add_style('display: none')

        is_template_div.add_class("spt_custom_project_top")
        is_template_div.add_style("padding: 10px")
        copy_div.add(is_template_div)
        is_template_div.add("<br/>")
        is_template_div.add("<b>Is this project a template: </b>")

        text = CheckboxWdg("custom_is_template")
        text.add_class("spt_custom_is_template")
        is_template_div.add(text)

        is_template_div.add(HtmlElement.br(2))
        span = DivWdg("Template projects are used as a blueprint for generating new projects.")
        is_template_div.add(span)



        # Disabling for now ... advanced feature and may not be necessary
        #stypes_div = my.get_stypes_div()
        #is_template_div.add(stypes_div)








        last_page = DivWdg()
        wizard.add(last_page, "Complete")

        last_page.add_style("padding-top: 80px")
        last_page.add_style("padding-left: 30px")

        cb = RadioWdg('jump_project', label='Jump to New Project')
        cb.set_option("value", "project")
        #cb.set_option('disabled','disabled')
        cb.set_checked()
        last_page.add(cb)

        last_page.add(HtmlElement.br(2))

        cb = RadioWdg('jump_project', label='Jump to Project Admin')
        cb.set_option("value", "admin")
        last_page.add(cb)


        last_page.add(HtmlElement.br(2))

        cb = RadioWdg('jump_project', label='Create Another Project')
        cb.set_option("value", "new")
        last_page.add(cb)




        last_page.add(HtmlElement.br(5))


        button_div = DivWdg()

        create_button = ActionButtonWdg(title="Create >>", tip="Create new project")
        wizard.add_submit_button(create_button)
        #button_div.add(create_button)
        create_button.add_style("float: right")

        create_button.add_behavior({
        'type': "click_up",
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_project_top");
        var values = spt.api.Utility.get_input_values(top, null, null, null, {cb_boolean: true});

        var project_code = values['project_code'][0];
        if (project_code == '') {
            spt.alert("You must enter a project code.");
            return;
        }
        if (spt.input.has_special_chars(project_code)) {
            spt.alert("Project code cannot contain special characters.");
            return;
        }
        
        if (project_code.test(/^\d/)) {
            spt.alert("Project code cannot start with a number.");
            return;
        }
        if (values['project_title'] == '') {
            spt.alert("You must enter a project title");
            return;
        }

        var project_source = values.project_source[0];

        var project_image_path = values['project_image_path'][0];

        var project_theme = values['project_theme'][0];

        var options = {
            'project_code': project_code,
            'project_title': values['project_title'][0],
            'project_image_path': project_image_path,
            'project_theme': project_theme,
        }

        //'copy_pipelines': values['copy_pipelines'][0]

        var class_name;
        var busy_title;
        var busy_msg;
        var use_transaction;
        if (project_source == '') {
            spt.alert("Please select a template to copy or select create an empty project");
            return;
        }
        else if (project_source != '_empty') {
            busy_title = "Copying Project"; 
            busy_msg = "Copying project ["+project_source+"] ...";
            use_transaction = false;

            class_name = 'tactic.command.ProjectTemplateInstallerCmd';
            if (project_source.test(/\|/)) {
                var tmps = project_source.split('|');
                project_source = tmps[0];
                var path = tmps[1];
                options['path'] = path;
            }
            options['template_code'] = project_source;
            options['force_database'] = true;

        }
        else {
            class_name = "tactic.command.CreateProjectCmd";
            busy_title = "Creating New Project"; 
            busy_msg = "Creating new project based on project info ...";
            use_transaction = true;

            // use project code as the project type if namespace is not specified
            var project_namespace = values['custom_namespace'][0];
            if (['sthpw','prod'].contains(project_namespace)) {
                spt.alert('Namespace [' + project_namespace + '] is reserved.');
                return;
            }
            options['project_type'] =  project_namespace ? project_namespace : project_code
            var is_template = values['custom_is_template'];
            if (is_template) {
                options['is_template'] = is_template[0];
            }
            // This has been commented out in the UI
            //options['project_stype'] = values['project_stype'].slice(1);


            var is_main_project = values['is_main_project'];
            if (is_main_project) {
                options['is_main_project'] = is_main_project[0];
            }

        }

        // Display app busy pop-up until create project command
        // has completed executing.
        spt.app_busy.show( busy_title, busy_msg ); 

        setTimeout( function() {

            var ret_val = '';
            var server = TacticServerStub.get();
            try {
                ret_val = server.execute_cmd(class_name, options, {}, {use_transaction: true});
            }
            catch(e) {
                spt.app_busy.hide();
                spt.alert("Error: " + spt.exception.handler(e));
                return;
                throw(e);
            }
            spt.api.Utility.clear_inputs(top);

            // show feedback at the end
            var jump = values['jump_project'][0];
            if (jump == 'project' || jump == 'admin') {
                var location;
                if (jump == 'admin') {
                    location = "/tactic/" + project_code + "/admin";
                }
                else if (project_theme) {
                    location = "/tactic/" + project_code + "/";
                }
                else {
                    location = "/tactic/" + project_code + "/admin/link/_startup";
                }
                setTimeout( function() {
                    document.location = location;
                    }, 1000);
            }
            else { 
                // Refresh header
                spt.panel.refresh(top);
                setTimeout( function() {
                    spt.panel.refresh('ProjectSelectWdg');
                }, 2800);


                spt.app_busy.hide();
            }

            // don't hide because it gives the false impression that nothing
            // happened as it waits for the timeout
            //spt.app_busy.hide();
        }, 0 );

        '''


        })


        cancel_script = my.kwargs.get("cancel_script")
        if cancel_script:
            cancel_button = ActionButtonWdg(title="Cancel")
            cancel_button.add_style("float: left")

            cancel_button.add_behavior({
                'type': "click_up",
                'cbjs_action': cancel_script
            })

            button_div.add(cancel_button)

            create_button.add_style("margin-right: 15px")
            create_button.add_style("margin-left: 75px")


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

        last_page.add(button_div)


        inner.add(HtmlElement.br())
   
        return top
Beispiel #33
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
Beispiel #34
0
    def get_filter_wdg(my):

        div = DivWdg()
        div.add_style("margin: 10px")
        div.add_class("spt_view_manager_filter")
        div.add('Search Type: ')

        security = Environment.get_security()
        if security.check_access("builtin", "view_site_admin", "allow"):
            select_mode =  SearchTypeSelectWdg.ALL
        else:
            select_mode =  SearchTypeSelectWdg.ALL_BUT_STHPW
        select = SearchTypeSelectWdg(name='search_type', \
            mode=select_mode)

        behavior = {'type': 'change', 'cbjs_action': '''
            var filter_top = bvr.src_el.getParent(".spt_view_manager_filter");
            var table_top = bvr.src_el.getParent(".spt_table_view_manager_top");
            var manager_top = table_top.getElement(".spt_view_manager_top");

            var input = spt.api.Utility.get_input(filter_top, 'search_type');
            var view_input = spt.api.Utility.get_input(filter_top, 'view');
            var view_input_value = '';
            if (view_input != null) {
                view_input_value = view_input.value;
            }
            var values = {'search_type': input.value, 'view': view_input_value, 'is_refresh': 'true'}; 
            spt.panel.refresh(table_top, values);'''
            #//spt.panel.refresh(manager_top, values);'''
        }
        select.add_behavior(behavior)
        select.set_value(my.search_type)
        div.add(select)

        if not my.search_type:
            return div

        div.add('View: ')
        view_wdg = SelectWdg("view")
        view_wdg.set_value(my.view)
        view_wdg.add_empty_option("-- Select --")
        view_wdg.add_behavior(behavior)
        div.add(view_wdg)


        search = Search("config/widget_config")
        search.add_filter("search_type", my.search_type)
        db_configs = search.get_sobjects()


        views = set()
        for db_config in db_configs:
            view = db_config.get_value("view")
            views.update([view])

        if my.search_type and my.view:
            config_view = WidgetConfigView.get_by_search_type(my.search_type, my.view)

            configs = config_view.get_configs()
            for x in configs:
                view = x.get_view()
                file_path = x.get_file_path()
                if view != my.view:
                    continue
                if file_path and file_path.endswith("DEFAULT-conf.xml"):
                    continue
                config_views = x.get_all_views()
                views.update(config_views)

        views_list = list(views)
        views_list.sort()
        view_wdg.set_option("values", views_list)


        return div
Beispiel #35
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
Beispiel #36
0
    def get_filter_wdg(my):

        div = DivWdg()
        div.add_style("padding: 10px")
        div.add_style("margin: -10 -10 10 -10")
        div.add_style("min-width: 600px")
        div.add_class("spt_view_manager_filter")



        from tactic.ui.app import HelpButtonWdg
        help_wdg = HelpButtonWdg(alias="view-manager|what-are-views")
        div.add(help_wdg)
        help_wdg.add_style("float: right")





        div.add('<b>Search Type:</b> ')

        div.add_gradient("background", "background", -10)


        security = Environment.get_security()
        project = Project.get()
        if security.check_access("builtin", "view_site_admin", "allow"):
            search_type_objs = project.get_search_types(include_sthpw=True, include_config=True)
        else:
            search_type_objs = project.get_search_types()

        search_types = [x.get_value("search_type") for x in search_type_objs]
        titles = ["%s (%s)" % (x.get_value("search_type"), x.get_value("title")) for x in search_type_objs]


        select = SelectWdg(name='search_type')
        select.set_option('values', search_types)
        select.set_option('labels', titles)
        select.add_empty_option('-- Select --')
        select.set_persistence()
        #select.set_persist_on_submit()


        #security = Environment.get_security()
        #if security.check_access("builtin", "view_site_admin", "allow"):
        #    select_mode =  SearchTypeSelectWdg.ALL
        #else:
        #    select_mode =  SearchTypeSelectWdg.ALL_BUT_STHPW
        #select = SearchTypeSelectWdg(name='search_type', \
        #    mode=select_mode)

        behavior = {'type': 'change', 'cbjs_action': '''
            var manager_top = bvr.src_el.getParent(".spt_view_manager_top");

            var input = spt.api.Utility.get_input(manager_top, 'search_type');
            var view_input = spt.api.Utility.get_input(manager_top, 'view');
            var view_input_value = '';
            if (view_input != null) {
                view_input_value = view_input.value;
            }
            var values = {'search_type': input.value, 'view': view_input_value, 'is_refresh': 'true'}; 
            spt.panel.refresh(manager_top, values);'''
            #//spt.panel.refresh(manager_top, values);'''
        }
        select.add_behavior(behavior)
        select.set_value(my.search_type)
        div.add(select)

        if not my.search_type:
            content = DivWdg()
            content.add_style("width: 400px")
            content.add_style("height: 400px")
            div.add(content)
            content.add_style("padding: 20px")
            content.add( IconWdg("WARNING", IconWdg.WARNING) )
            content.add("No Search Type Selected")
            content.add_border()
            content.add_style("margin-top: 20px")
            content.add_color("background", "background")
            content.add_style("font-weight: bold")

            return div

        div.add('&nbsp;&nbsp;&nbsp;')
        div.add('<b>View: </b>')
        view_wdg = SelectWdg("view")
        view_wdg.set_value(my.view)
        view_wdg.add_empty_option("-- Select --")
        view_wdg.add_behavior(behavior)
        div.add(view_wdg)


        search = Search("config/widget_config")
        search.add_filter("search_type", my.search_type)
        db_configs = search.get_sobjects()


        views = set()
        for db_config in db_configs:
            view = db_config.get_value("view")
            if view.startswith('link_search:'):
                continue
            views.update([view])

        #print "search_type: ", my.search_type
        #print "view: ", views, my.view

        if my.search_type and my.view:
            config_view = WidgetConfigView.get_by_search_type(my.search_type, my.view)

            configs = config_view.get_configs()
            for x in configs:
                view = x.get_view()
                file_path = x.get_file_path()
                if view != my.view:
                    continue
                if file_path and file_path.endswith("DEFAULT-conf.xml"):
                    continue
                config_views = x.get_all_views()
                views.update(config_views)

        views_list = list(views)
        views_list.sort()
        view_wdg.set_option("values", views_list)


        return div
Beispiel #37
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
Beispiel #38
0
    def get_shelf_wdg(self):

        process = self.get_value("process")
        versions = self.get_value("versions")

        div = DivWdg()

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

        button = SingleButtonWdg(title="Refresh", icon=IconWdg.REFRESH)
        filter_table.add_cell(button)
        filter_table.add_cell("&nbsp;" * 5)
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.panel.refresh(bvr.src_el);
            '''
        })

        # get all of the pipelnes for this search type
        pipeline_code = self.sobject.get_value("pipeline_code",
                                               no_exception=True)
        processes = []
        if pipeline_code:
            pipeline = Pipeline.get_by_code(pipeline_code)
            if pipeline:
                process_names = pipeline.get_process_names()
                processes.extend(process_names)

        processes.insert(0, "all")

        filter_table.add_cell("Process: ")
        select = SelectWdg("process")
        select.add_style("width: 200px")
        if process != 'all':
            select.set_value(process)

        select.set_option("values", processes)

        filter_table.add_cell(select)

        filter_table.add_cell("&nbsp;" * 10)

        filter_table.add_cell("Versions: ")
        select = SelectWdg("versions")
        select.add_style("width: 200px")
        select.set_option("values", "latest|current|today|last 10|all")
        if versions:
            select.set_value(versions)
        filter_table.add_cell(select)

        asset_dir = Environment.get_asset_dir()

        select = IconButtonWdg(tip="Toggle Selection",
                               icon=IconWdg.SELECT,
                               show_arrow=False)
        div.add(select)
        select.add_style("float: right")
        select.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top_class = 'spt_sobject_dir_list_top'
            var toggle_state = bvr.src_el.getAttribute('toggle');
            if (toggle_state && toggle_state=='true')
                bvr.src_el.setAttribute('toggle','false');
            else
                bvr.src_el.setAttribute('toggle','true');

            var top = bvr.src_el.getParent("."+top_class);
            spt.selection.set_top(top);
            
            toggle_state = bvr.src_el.getAttribute('toggle');
            if (toggle_state == 'true')
                spt.selection.select_all_items();
            else
                spt.selection.unselect_all_items();

            '''
        })

        show = IconButtonWdg(tip="Switch View",
                             icon=IconWdg.VIEW,
                             show_arrow=False)
        div.add(show)
        show.add_style("float: right")
        show.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top_class = 'spt_sobject_dir_list_top'
            var top = bvr.src_el.getParent("."+top_class);
            spt.selection.set_top(top);
            var els = top.getElements(".spt_file_dir_item");
            for (var i = 0; i < els.length; i++) {
                var el = els[i];
                if (el.getStyle("display") == "none") {
                    els[i].setStyle("display", "");
                }
                else {
                    els[i].setStyle("display", "none");
                }
            }
            var els = top.getElements(".spt_file_item");
            for (var i = 0; i < els.length; i++) {
                var el = els[i];
                if (el.getStyle("padding-left") == "6px") {
                    var padding = el.getAttribute("spt_padding_left");
                    el.setStyle("padding-left", padding);
                }
                else {
                    el.setStyle("padding-left", "6px");
                }

            }


            '''
        })

        gear = IconButtonWdg(tip="Download",
                             icon=IconWdg.DOWNLOAD,
                             show_arrow=False)
        div.add(gear)
        gear.add_style("float: right")
        gear.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.app_busy.show('Select a folder to download to...','');
            var top_class = 'spt_sobject_dir_list_top';
            var top = bvr.src_el.getParent("."+top_class);
            spt.selection.set_top(top);
            var items = spt.selection.get_selected();
            
       
            setTimeout( function() {
                var applet = spt.Applet.get();
                var select_dir =true;
                var dir = applet.open_file_browser('', select_dir);
                if (dir.length == 0)
                    dir = applet.get_current_dir();
                else 
                    dir = dir[0];

                if (!dir) {
                    spt.alert("No folder selected to copy to.");
                    spt.app_busy.hide();
                    return;
                }
                if (items.length == 0){
                    spt.alert("Please select at least one file to download.");
                    spt.app_busy.hide();
                    return;
                }
                

                var asset_dir = '%s';
                for (var i = 0; i < items.length; i++) {
                    var path = items[i].getAttribute("spt_path");
                    var env = spt.Environment.get();
                    var server_url = env.get_server_url();
                    var url = server_url + "/assets/" + path.replace(asset_dir, "");
                    var parts = path.split("/");
                    var filename = parts[parts.length-1];
                    spt.app_busy.show("Downloading file", filename);
                    applet.download_file(url, dir + "/" + filename);
                }
                spt.app_busy.hide();
                if (dir)
                    spt.notify.show_message("Download to '" + dir + "' completed.")
            }, 100);

            ''' % asset_dir
        })

        return div
    def get_display(my):

        # add the detail widget
        detail_wdg = DivWdg(css='spt_detail_panel')
        if not my.name_string and not my.config_string:
            detail_wdg.add("<br/>" * 3)
            detail_wdg.add('<- Click on an item on the left for modification.')
            detail_wdg.add_style("padding: 10px")
            detail_wdg.add_color("background", "background", -5)
            detail_wdg.add_style("width: 350px")
            detail_wdg.add_style("height: 400px")
            detail_wdg.add_border()

            return detail_wdg

        if my.kwargs.get("mode") == "empty":
            overlay = DivWdg()
            detail_wdg.add(overlay)

        detail_wdg.add_border()
        detail_wdg.add_color("color", "black")
        detail_wdg.add_style("padding: 10px")
        detail_wdg.add_color("background", "background", -5)

        detail_wdg.set_id('search_type_detail')

        # put in the selection for simple or advanced
        select = SelectWdg("config_mode", label='Mode: ')
        select.set_persistence()
        values = ['simple', 'advanced']
        select.set_option("values", values)
        config_mode = select.get_value()
        #select.add_behavior({"type": "change", "cbjs_action": "spt.simple_display_toggle( spt.get_cousin(bvr.src_el, '.spt_detail_panel','.config_simple') )"})
        select.add_behavior({"type": "change", "cbjs_action": \
            "spt.simple_display_toggle( spt.get_cousin(bvr.src_el, '.spt_detail_panel','.config_advanced')); %s" %select.get_save_script()})

        select.add_class('spt_config_mode')

        title_div = DivWdg("Column Detail")
        title_div.add_class("maq_search_bar")
        detail_wdg.add(title_div)
        detail_wdg.add("<br/>")
        detail_wdg.add(select)
        detail_wdg.add(HtmlElement.br(2))

        #simple_mode_wdg = WidgetDetailSimpleModeWdg()
        #detail_wdg.add(simple_mode_wdg)
        #detail_wdg.add(HtmlElement.br(2))

        if my.is_new_column:
            detail_wdg.add(my.get_new_definition_wdg())
        else:

            simple_wdg = my.get_simple_definition_wdg()

            simple_wdg.add_class("config_simple")
            detail_wdg.add(simple_wdg)
            adv_wdg = my.get_advanced_definition_wdg()
            adv_wdg.add_class("config_advanced")
            if config_mode == 'simple':
                adv_wdg.add_style('display: none')
            detail_wdg.add(HtmlElement.br(2))
            detail_wdg.add(adv_wdg)

        detail_wdg.add(HtmlElement.br(2))

        security_wdg = my.get_security_wdg()
        detail_wdg.add(security_wdg)

        # add hidden input for view for panel refreshing
        # we are only interested in whether it is project_view or definition
        # sub-views of project_view is not of our interest

        #if my.view != 'project_view':
        #    my.view = 'custom_definition'
        detail_wdg.add(HiddenWdg('view', my.view))

        return detail_wdg
Beispiel #40
0
    def get_display(self):

        parser = self.kwargs.get("parser")

        self.search_key = self.kwargs.get("search_key")
        sobject = Search.get_by_search_key(self.search_key)

        if sobject.get_base_search_type() == "sthpw/snapshot":
            snapshot = sobject
        elif sobject.get_base_search_type() == "sthpw/file":
            # if it is a file object
            snapshot = sobject.get_parent()
        else:
            snapshots = Snapshot.get_by_sobject(sobject, is_latest=True)
            snapshot = snapshots[0]

        # Extension determine UI class for preview
        thumb_path = snapshot.get_web_path_by_type("icon")
        web_src = snapshot.get_web_path_by_type("web")

        from pyasm.biz import File
        file_type = "main"
        lib_path = snapshot.get_lib_path_by_type(file_type)
        src = snapshot.get_web_path_by_type(file_type)
        if not web_src:
            web_src = src
        
        parts = os.path.splitext(src)
        ext = parts[1]
        ext = ext.lstrip(".")
        ext = ext.lower()
        
        #parent = snapshot.get_parent()

        top = self.top
        self.set_as_panel(top)

        if ext == "pdf":
            iframe = HtmlElement.iframe()
            iframe.set_attr('src', src)
            iframe.add_style("width: 100%")
            iframe.add_style("height: 800px")
            top.add(iframe)
            return top

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

        # These bvrs allow for smooth switching if switching between files 
        # like in the RepoBrowserWdg
        tr.add_style("height: 200px")
        load_height_bvr = {
            'type': 'load',
            'cbjs_action': '''
            var last_height = spt.container.get_value("last_img_height");
            if (last_height) {
                bvr.src_el.setStyle("height", last_height);
            } 
            '''
        } 
        tr.add_behavior(load_height_bvr)

        unload_height_bvr = {
            'type': 'unload',
            'cbjs_action': '''
            var last_height = bvr.src_el.getStyle("height");
            spt.container.set_value("last_img_height", last_height);
            '''
        }
        tr.add_behavior(unload_height_bvr)

        table.add_style("width: 100%")
        table.add_style("text-align", "center")

        from tactic.ui.widget import EmbedWdg
        td = table.add_cell()
        td.add_color("background", "background",)
        td.add_style("vertical-align: middle")
        td.add_style("height: inherit")
        td.add_style("overflow-x: auto")


        if ext in ['txt','html', 'ini']:
            content_div = DivWdg()
            f = open(lib_path, 'r')
            content = f.read(10000)
            f.close()
            if not content:
                text = "No Content"
            else:

                size = os.path.getsize(lib_path)

                from pyasm.common import FormatValue
                value = FormatValue().get_format_value(size, "KB")

                content_div.add("Showing first 10K of %s<hr/>" % value)

                text = TextAreaWdg()
                text.add(content)
                text.add_style("width: 100%")
                text.add_style("height: 100%")
                text.add_style("padding: 10px")
                text.add_style("border: none")
                text.add_attr("readonly", "true")

            content_div.add(text)
            td.add(content_div)
            content_div.add_style("color", "#000")
            content_div.add_style("width", "auto")
            content_div.add_style("margin", "20px")
            content_div.add_style("height", "100%")
 
        elif ext in File.IMAGE_EXT or ext == "gif":
            if lib_path.find("#") != -1:
                img = DivWdg()

                file_range = snapshot.get_file_range()
                file_range_div = DivWdg()
                file_range_div.add("File Range: %s" % file_range.get_display())
                img.add(file_range_div)
                file_range_div.add_style("font-size: 1.4em")
                file_range_div.add_style("margin: 15px 0px")

                """
                left_chevron = IconWdg("Previous", "BS_CHEVRON_LEFT")
                file_range_div.add(left_chevron)
                right_chevron = IconWdg("Next", "BS_CHEVRON_RIGHT")
                file_range_div.add(right_chevron)
                """


                expanded_paths = snapshot.get_expanded_web_paths()
                lib_paths = snapshot.get_expanded_lib_paths()
                lib_path = lib_paths[0]

                items_div = DivWdg()
                img.add(items_div)
                items_div.add_style("width: auto")

                for path in expanded_paths:
                    item = HtmlElement.img(src=path)
                    items_div.add(item)
                    item.add_style("max-height: 300px")
                    item.add_style("height: auto")
                    item.add_style("width: 32%")
                    item.add_style("margin: 2px")
                    item.add_style("display: inline-block")
                    #item.add_class("spt_resizable")

                img.add_style("margin: 20px")
                img.add_style("max-height: 400px")
                img.add_style("overflow-y: auto")
                img.add_style("overflow-hidden: auto")
                img.add_style("text-align: left")

                    
            else:
                if ext == "gif":
                    img = HtmlElement.img(src=src)
                else:
                    img = HtmlElement.img(src=web_src)
                img.add_style("height: inherit")
                img.add_style("width: auto")
            td.add(img)
        elif ext in File.VIDEO_EXT:
            embed_wdg = EmbedWdg(src=src, thumb_path=thumb_path, preload="auto", controls=True)
            td.add(embed_wdg)
            
            embed_wdg.add_style("margin: auto auto")
            embed_wdg.add_class("spt_resizable")

            embed_wdg.add_behavior(load_height_bvr)
            embed_wdg.add_behavior(unload_height_bvr)

        else:
            thumb_table = DivWdg()
            td.add(thumb_table)
            
            thumb_table.add_behavior( {
                'type': 'click_up',
                'src': src,
                'cbjs_action': '''
                window.open(bvr.src);
                '''
            } )
            thumb_table.add_class("hand")
            thumb_table.add_style("width: 200px")
            thumb_table.add_style("height: 125px")
            thumb_table.add_style("padding: 5px")
            thumb_table.add_style("margin-left: 20px")
            thumb_table.add_style("display: inline-block")
            thumb_table.add_style("vertical-align: top")
            thumb_table.add_style("overflow-y: hidden")    
            from tactic.ui.panel import ThumbWdg2
            thumb = ThumbWdg2()
            thumb_table.add(thumb)
            thumb.set_sobject(snapshot)


        table.add_row()
        td = table.add_cell()


        from tactic.ui.checkin import PathMetadataWdg
        from tactic.ui.checkin import SnapshotMetadataWdg

        from pyasm.widget import SelectWdg
        select = SelectWdg(name="parser")
        select.add_style("width: 125px")
        select.add_style("margin-top: 0px")
        select.add_style("margin-right: 10px")
        select.add_empty_option("-- Metadata --")
        td.add(select)
        select.add_style("float: right")
        select.set_option("values", ["IPTC","EXIF","XMP","ImageMagick","PIL"])
        select.add_behavior( {
            'type': 'change',
            'cbjs_action': '''
            var parser = bvr.src_el.value;
            spt.panel.refresh_element(bvr.src_el, {parser: parser})
            '''
        } )
        if parser:
            select.set_value(parser)



        title_div = DivWdg()
        td.add(title_div)
        title_div.add("<div style='font-size: 16px'>File Metadata</div>")
        title_div.add("<div>Metadata extracted directly from the file</div>")
        title_div.add("<hr/>")
        title_div.add_style("text-align: left")
        title_div.add_style("margin: 0px 10px")


        metadata_div = DivWdg()
        td.add(metadata_div)
        metadata_div.add_style("max-height: 400px")
        metadata_div.add_style("overflow-y: auto")
        metadata_div.add_style("overflow-x: hidden")
        metadata_div.add_style("margin: 20px 0px 20px 10px")
        metadata_div.add_style("text-align: left")

        use_tactic_tags = self.kwargs.get("use_tactic_tags")

        server_src = lib_path

        # get it dynamically by path
        metadata_wdg = PathMetadataWdg(path=server_src, parser=parser, use_tactic_tags=use_tactic_tags, search_key=self.search_key)
        metadata_div.add(metadata_wdg)

        top.add("<br/>")

        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
Beispiel #42
0
    def get_display(my):

        top = my.top
        top.add_style("padding: 20px")
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("width", "500px")

        top.add_class("spt_db_register_top")
        my.set_as_panel(top)

        inner = DivWdg()
        top.add(inner)

        # db resource
        db_resource = my.get_value("db_resource")

        db_resource_wdg = DivWdg()
        inner.add(db_resource_wdg)
        db_resource_wdg.add("Database Resource: ")

        search = Search("sthpw/db_resource")
        db_resources = search.get_sobjects()
        codes = [x.get_code() for x in db_resources]

        select = SelectWdg("db_resource")
        db_resource_wdg.add(select)
        select.set_option("values", codes)
        if db_resource:
            select.set_value(db_resource)
        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_db_register_top");
            spt.panel.refresh(top);
            '''
        })

        if db_resource:
            info_wdg = DivWdg()
            db_resource_wdg.add(info_wdg)
            info_wdg.add_border()
            info_wdg.add_style("padding: 20px")
            info_wdg.add_style("margin: 20px")

        inner.add("<br/>")

        # list of databases
        database_wdg = DivWdg()
        inner.add(database_wdg)
        database_wdg.add("Available Databases: ")

        databases = ['test', 'test1', 'test2']

        select = SelectWdg("databases")
        database_wdg.add(select)
        select.set_option("values", databases)

        # list of projects

        if my.kwargs.get('is_refresh') == 'true':
            return inner
        else:
            return top
Beispiel #43
0
    def get_display(my):
        widget = DivWdg(id='new_item_panel')
        widget.add_class("new_item_panel")
        widget.add_class("spt_new_item_top")

        div = DivWdg()
        div.add_color("background", "background")
        div.add_color("color", "color")
        div.add_style("padding", "5px")
        div.add_border()

        if my.is_personal:
            is_personal = 'true'
        else:
            is_personal = 'false'

        if my.type == 'new_folder':
            #div.set_attr('spt_view', 'new_folder')
            div.add(HtmlElement.b('Create New Folder'))
            div.add(HtmlElement.br(2))
            """
            # add exisiting views in the div for checking with client's input
             # add exiting views:
            from panel_wdg import ViewPanelSaveWdg
            views = ViewPanelSaveWdg.get_existing_views(my.is_personal)
            hidden = HiddenWdg('existing_views', '|'.join(views))
            div.add(hidden)
            """
            text2 = TextWdg("new_title")
            text2.add_class("spt_new_item_title")
            span = SpanWdg("Title: ")
            span.set_id('create_new_title')
            #span.add_style('display: none')
            span.add_style('padding-left: 8px')
            span.add(text2)
            div.add(span)
            div.add(HtmlElement.br(2))

            div.add_style("width: 350px")


            action = '''
            var top = bvr.src_el.getParent(".spt_new_item_top");
            var name_el = top.getElement(".spt_new_item_name");
            var title = bvr.src_el.value;
            var name = title.replace(/[\?.!@#$%^&*()'"]/g, "");
            name = name.replace(/ /g, "_");
            name = name.toLowerCase();
            name_el.value = name;
            '''


            # change the name based on the title
            text2.add_behavior( {
            'type': 'change',
            'cbjs_action': action
            } )

            div.add("The name of the folder is a hidden name that is used by other elements to refer to uniquely to this item.<br/><br/>")
            text = TextWdg('new_name')
            text.add_class("spt_new_item_name")
            span = SpanWdg('Name: ')
            span.add(text)
            div.add(span)

            div.add(HtmlElement.br(2))
            
            #script = "spt.side_bar.manage_section_action_cbk({'value':'predefined'},'project_view');"
            #link = HtmlElement.js_href(script, data='[ Predefined View ]')
            #div3 = DivWdg('Optional: drag existing elements from Project Views or %s into this new folder' %link.get_buffer_display())
            #div.add(div3)
            #item_div = DivWdg(css='spt_new_item spt_side_bar_content')
            #div.add(item_div)

            div.add("<hr/>")

           
            #save_div = SpanWdg(css='med hand')
            #div.add(save_div)
            #save_div.add(IconWdg('Save Folder', IconWdg.SAVE))

            save_button = ActionButtonWdg(title='Create', tip='Create a new folder')
            div.add(save_button)
       
            bvr = {
            "type": "click_up",
            "view": my.view,
            "is_personal": is_personal == 'true',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_new_item_top");
            var name_el = top.getElement(".spt_new_item_name");
            var name_value = name_el.value;
            if (name_value == "") {
                var title_el = top.getElement(".spt_new_item_title");
                var title = title_el.value;
                var name = spt.convert_to_alpha_numeric(title);
                name_el.value = name;
            }
            if (name_value == "") {
                spt.alert("Please fill in a value for name.");
                return;
            }
            spt.side_bar.manage_section_action_cbk(
                    { 'value':'save_folder'}, bvr.view, bvr.is_personal);
            ''' }
            save_button.add_behavior(bvr)
            div.add(HtmlElement.br())


        elif my.type == 'new_link':

            div.set_attr('spt_view', 'new_link')
            div.add(HtmlElement.b('Create New Link'))
            div.add(HtmlElement.br())
         
            item_div = DivWdg(css='spt_new_item')
            item_div.add_style('display: none')
            div.add(HtmlElement.br())
            div.add(item_div)
            
            text = TextWdg('new_link_title')
            span = SpanWdg('Title: ')
            span.add(text)
            div.add(span)
            
            div.add(HtmlElement.br(2))
            cb = CheckboxWdg('include_search_view', label='Include Saved Search')
            cb.set_default_checked()
            div.add(cb)

            div.add(HtmlElement.br(2))
            div.add("Select a search type and view of this link")
            div.add(HtmlElement.br())

           
            select = SelectWdg("new_search_type")
            select.add_empty_option("-- Select Search type --")
    
            security = Environment.get_security()
            if security.check_access("builtin", "view_site_admin", "allow"):
                search_types = Project.get().get_search_types(include_sthpw=True, include_config=True)
            else:
                search_types = Project.get().get_search_types()

            values = [x.get_value("search_type") for x in search_types]
            labels = ["%s (%s)" % (x.get_value("search_type"), x.get_title()) for x in search_types]
            values.append("CustomLayoutWdg")
            labels.append("CustomLayoutWdg")
            select.set_option("values", values)
            select.set_option("labels", labels)

    
            #security = Environment.get_security()
            #if security.check_access("builtin", "view_site_admin", "allow"):
            #    select_mode =  SearchTypeSelectWdg.ALL
            #else:
            #    select_mode =  SearchTypeSelectWdg.ALL_BUT_STHPW
            #select = SearchTypeSelectWdg(name='new_search_type', \
            #    mode=select_mode)

            select.add_behavior({'type': 'change',
            'cbjs_action': '''
                var top = bvr.src_el.getParent(".new_item_panel");
                var link_view_select = top.getElement(".link_view_select");
                var input = spt.api.Utility.get_input(top, 'new_search_type'); var values = {'search_type': input.value, 
                'is_refresh': 'true'}; 
                spt.panel.refresh(link_view_select, values);'''
            })
            div.add(HtmlElement.br())
            div.add(select)
      

            div.add(HtmlElement.br())
                  
            
            
            link_view_sel = NewLinkViewSelectWdg()
            div.add(HtmlElement.br())
            div.add(link_view_sel)

            div.add(HtmlElement.br())
            #select.add_behavior('change')
            div.add(HtmlElement.hr())
            div.add(HtmlElement.br())
            
            #save_div = DivWdg(css='med hand')
            #div.add(save_div)
            #save_button = ProdIconButtonWdg('Save Link', IconWdg.SAVE)
            #save_div.add(save_button)

            save_button = ActionButtonWdg(title='Create', tip='Create a new link')
            div.add(save_button)
            bvr = { "type": "click_up",
                'cbjs_action': "spt.side_bar.manage_section_action_cbk({"\
                "'value':'save_link'},'%s', %s);" %(my.view, is_personal)}
            save_button.add_behavior(bvr)
            div.add(HtmlElement.br(1))

        elif my.type == 'new_separator':
            div.set_attr('spt_view', 'new_separator')
            div.add(HtmlElement.b('Creating New Separator. . .'))
            div.add(HtmlElement.br())
           
            item_div = DivWdg(css='spt_new_item')
            item_div.add_style('display: none')
            div.add(HtmlElement.br())
            div.add(item_div)
            # since it's automated, this button is not needed
            """ 
            save_div = SpanWdg(css='med hand')
            save_div.add(IconWdg('Save', IconWdg.SAVE))
        
            bvr = { "type": "click_up",\
                'cbjs_action': "spt.side_bar.manage_section_action_cbk({"\
                "'value':'save_separator'},'%s');" %my.view}
            save_div.add_behavior(bvr)
            div.add(save_div)
            """
        widget.add(div)
        return widget
Beispiel #44
0
    def get_first_row_wdg(my):

        # read the csv file
        #my.file_path = ""

        div = DivWdg(id='csv_import_main')
        div.add_class('spt_panel')
        
        div.add( my.get_upload_wdg() )
        if not my.search_type:
            return div

        if not my.file_path:
            return div


        if not my.file_path.endswith(".csv"):
            div.add('<br>')
            div.add( "Uploaded file [%s] is not a csv file. Refreshing in 3 seconds. . ."% os.path.basename(my.file_path))
            div.add_behavior( {'type': 'load', \
                                  'cbjs_action': "setTimeout(function() {spt.panel.load('csv_import_main','%s', {}, {\
                                    'search_type_filter': '%s'});}, 3000);" %(Common.get_full_class_name(my), my.search_type) } )
            return div

        if not os.path.exists(my.file_path):
            raise TacticException("Path '%s' does not exist" % my.file_path)

        
        div.add(HtmlElement.br(2))



        # NOT NEEDED:  clear the widget settings before drawing
        #expr = "@SOBJECT(sthpw/wdg_settings['key','EQ','pyasm.widget.input_wdg.CheckboxWdg|column_enabled_']['login','$LOGIN']['project_code','$PROJECT'])"
        #sobjs = Search.eval(expr)
        #for sobj in sobjs:
        #    sobj.delete(log=False)


        div.add( HtmlElement.b("The following is taken from the first line in the uploaded csv file.  Select the appropriate column to match.") )
        div.add(HtmlElement.br())
        """
        text =  HtmlElement.b("Make sure you have all the required columns** in the csv.")
        text.add_style('text-align: left')
        div.add(text)
        """
        div.add(HtmlElement.br(2))
        option_div_top = DivWdg()
        option_div_top.add_color('color','color')
        option_div_top.add_color('background','background', -5)
        option_div_top.add_style("padding: 10px")
        option_div_top.add_border()
        option_div_top.add_style("width: 300px")

        swap = SwapDisplayWdg(title="Parsing Options")
        option_div_top.add(swap)

        option_div_top.add_style("margin-right: 30px")

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

        option_div = DivWdg()
        swap.set_content_id(option_div.set_unique_id() )
        option_div.add_style("display: none")
        option_div.add_style('margin-left: 14px')
        option_div.add_style('margin-top: 10px')
        option_div.add_style("font-weight: bold")
        option_div_top.add(option_div)

        # first row and second row
        #option_div.add( HtmlElement.br() )
        option_div.add(SpanWdg("Use Title Row: ", css='small'))
        title_row_checkbox = CheckboxWdg("has_title")
        title_row_checkbox.set_default_checked()

        title_row_checkbox.add_behavior({'type' : 'click_up',
                    'propagate_evt': 'true',
                    'cbjs_action': "spt.panel.refresh('preview_data',\
                    spt.api.Utility.get_input_values('csv_import_main'))"})
        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(SpanWdg("Use Lowercase Title: ", css='small'))
        lower_title_checkbox = CheckboxWdg("lowercase_title")

        lower_title_checkbox.add_behavior({'type' : 'click_up',
                    'propagate_evt': 'true',
                    'cbjs_action': "spt.panel.refresh('preview_data',\
                    spt.api.Utility.get_input_values('csv_import_main'))"})
        option_div.add(lower_title_checkbox)
        option_div.add( HtmlElement.br(2) )

        option_div.add(SpanWdg("Sample Data Row: ", css='small'))
        data_row_text = SelectWdg("data_row")
        data_row_text.set_option('values', '1|2|3|4|5')
        data_row_text.set_value('1')
        data_row_text.add_behavior({'type' : 'change',
                    'cbjs_action': "spt.panel.refresh('preview_data',\
                    spt.api.Utility.get_input_values('csv_import_main'))"})
        option_div.add(data_row_text)
        option_div.add( HintWdg("Set this as a sample data row for display here") )

        option_div.add( HtmlElement.br(2) )
      
        # encoder
        option_div.add(SpanWdg("Encoder: ", css='small'))
        select_wdg = SelectWdg('encoder')
        select_wdg.set_option('values', ['','utf-8', 'iso_8859-1']) 
        select_wdg.set_option('labels', ['ASCII (default)','UTF-8','Excel ISO 8859-1']) 
        select_wdg.add_behavior({'type' : 'change',
                    'cbjs_action': "spt.panel.refresh('preview_data',\
                    spt.api.Utility.get_input_values('csv_import_main'))"})
        option_div.add(select_wdg)
        option_div.add( HtmlElement.br(2) )


        option_div.add(SpanWdg("Identifying Column: ", css='small'))
        select_wdg = SelectWdg('id_col')
        select_wdg.set_option('empty','true')
        #columns = my.search_type_obj.get_columns()
        columns = SearchType.get_columns(my.search_type)
        
        # make sure it starts off with id, code where applicable
        if 'code' in columns:
            columns.remove('code')
            columns.insert(0, 'code')
        if 'id' in columns:
            columns.remove('id')
            columns.insert(0, 'id')

        select_wdg.set_option('values', columns) 
        option_div.add(select_wdg)
        option_div.add( HintWdg("Set which column to use for identifying an item to update during CSV Import") )
        option_div.add( HtmlElement.br(2) )

        

        div.add(option_div_top)

        my.has_title = title_row_checkbox.is_checked()
        
        
        # need to somehow specify defaults for columns
        div.add(my.get_preview_wdg())


        return div          
Beispiel #45
0
    def get_new_custom_widget(my, search_type, view):

        div = DivWdg()
        div.add_style('width: 500px')
        
        mode_select = SelectWdg("custom_mode")
        mode_select.add_class("spt_custom_mode")
        mode_select.set_option("values", "simple|xml")
        mode_select.set_option("labels", "Simple|XML")
        mode_select.add_class("spt_input")
        behavior = {
            'type': 'change',
            'cbfn_action': 'spt.custom_property_adder.switch_property_mode'
        }
        mode_select.add_behavior(behavior)

        div.add("Mode: ")
        div.add(mode_select)
        div.add("<br/><br/>")


        custom_table = Table()
        custom_table.add_color("color", "color")

        custom_table.set_max_width()
        mode = "simple"
        my.handle_simple_mode(custom_table, mode)
        #my.handle_widget_mode(custom_table, mode)
        my.handle_xml_mode(custom_table, mode)
        div.add(custom_table)

        div.add("<br/>")

        custom_table = Table()
        custom_table.center()
        custom_table.add_row()


        from tactic.ui.widget import ActionButtonWdg
        submit = ActionButtonWdg(title="Add/Next")
        behavior = {
            'type': 'click',
            'mouse_btn': 'LMB',
            'cbfn_action': 'spt.custom_property_adder.add_property_cbk',
            'search_type': my.search_type,
            'view': view

        }
        submit.add_behavior(behavior)
        td = custom_table.add_cell(submit)

        behavior['exit'] = 'true'
        submit_exit = ActionButtonWdg(title="Add/Exit")
        submit_exit.add_behavior(behavior)
        custom_table.add_cell(submit_exit)

        cancel = ActionButtonWdg(title="Cancel")
        behavior = {
            'type': 'click_up',
            'cbjs_action': "spt.popup.close('New Table Column')"
        }
        cancel.add_behavior(behavior)
        custom_table.add_cell(cancel)

        div.add(custom_table)

        return div
Beispiel #46
0
    def get_display(my):
        # if no filters are defined, then display nothing
        if not my.filters:
            return Widget()

        #filter_top = DivWdg(css="maq_search_bar")
        filter_top = DivWdg()
        filter_top.add_color("color", "color")
        filter_top.add_color("background", "background", -5)
        filter_top.add_style("padding: 5px")
        filter_top.add_style("min-width: 700px")
        filter_top.add_border()
        my.set_as_panel(filter_top)


        # TEST link to help for search widget
        help_button = ActionButtonWdg(title="?", tip="Search Documentation", size='small')
        filter_top.add(help_button)
        help_button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.help.set_top();
            spt.help.load_alias("search-quickstart|what-is-searching|search-interface|search-compound|search-expressions");
            '''
        } )
        help_button.add_style("float: right")


        # this id should be removed
        filter_top.set_id("%s_search" % my.prefix)
        filter_top.add_class("spt_search")


        for name, value in my.kwargs.items():
            filter_top.set_attr("spt_%s" % name, value)

        #filter_top.add(my.statement)
        popup = my.get_retrieve_wdg()
        filter_top.add(popup)
        popup = my.get_save_wdg()
        filter_top.add(popup)

        display = my.kwargs.get('display')
       

        # Add a number of filters indicator
        div = DivWdg()
        div.add_class("spt_search_num_filters")
        div.add_style("float: right")
        div.add_style("font-size: 0.9em")
        div.add_style("margin: 0 10 0 10")
        #search_summary.add(div)
        filter_top.add(div)

        if my.num_filters_enabled:
            msg = "[%s] filter/s" % my.num_filters_enabled
            icon = IconWdg(msg, IconWdg.DOT_GREEN)
            div.add(icon)
            div.add("%s" % msg)


        filter_div = DivWdg()
        filter_div.set_id("search_filters")
        filter_div.add_class("spt_search_filters")


        # TODO: disabling for now
        # add the action buttons
        #action_wdg =  my.get_action_wdg()
        #action_wdg.add_style("text-align: right")
        #filter_div.add( action_wdg )
        # add the top
        display_str = 'block'
        if not display:
            display_str = 'none'
        filter_div.add_style("display: %s" % display_str)

        search_wdg = my.get_search_wdg()

        prefix = "filter_mode"
        if my.prefix_namespace:
            prefix = '%s_%s' %(my.prefix_namespace, prefix)
        hidden = HiddenWdg("prefix", prefix)

        match_div = DivWdg()
        match_div.add(hidden)
        match_div.add_class('spt_search_filter') 

        palette =  match_div.get_palette()
        bg_color = palette.color('background')
        light_bg_color =  palette.color('background', modifier=+10)
        

        select = SelectWdg("filter_mode")
        select.add_class("spt_search_filter_mode")
        select.set_persist_on_submit(prefix)
        select.remove_empty_option() 
        # for Local search, leave out compound search for now
        if my.kwargs.get('prefix_namespace'):
            select.set_option("labels", "Match all|Match any")
            select.set_option("values", "and|or")
        else:
            select.set_option("labels", "Match all|Match any|Compound search")
            select.set_option("values", "and|or|custom")
        #select.set_option("labels", "all|any")
        #select.set_option("values", "and|or")

        select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var display = bvr.src_el.value == 'custom';;

        var top = bvr.src_el.getParent(".spt_search");
        var ops = top.getElements(".spt_op");
        for (var i = 0; i < ops.length; i++) {
            var op = ops[i];
            var element = op.getElement(".spt_op_display");
            var value = op.getAttribute("spt_op");
            if (display) {
                element.innerHTML = value;
                var level = op.getAttribute("spt_level");
                if (level == 1) {
                    element.setStyle("background", "%s")
                    element.setStyle("padding", "4px")
                }
            } else {
                element.innerHTML = '&nbsp;';
                element.setStyle("background", "%s")
                element.setStyle("padding", "1px")
            }
        }
        ''' %(light_bg_color, bg_color)
        } )

        match_div.add(select)
        match_div.add_color("color", "color2")
        match_div.add(" on the following")
        hint = HintWdg( "An 'AND' operation is always applied to each category below. " \
                        "This controls only the filters within each category." )
        match_div.add(hint)
        match_div.add('<br/>')

        match_div.add_style("padding-top: 5px")

        filter_div.add( search_wdg)
        search_wdg.add_style("float: left")
        filter_div.add( match_div)


        filter_div.add(HtmlElement.br())

        filters_div = DivWdg()
        filters_div.add_style("margin: 0 -6 0 -6")

        security = Environment.get_security()

        # add all the filters
        for filter in my.filters:
            element_name = filter.get_name()

            if not security.check_access("search", element_name, "view"):
                continue

            # no need to create it again    
            #filter = my.config.get_display_widget(element_name)
            div = DivWdg()
            filters_div.add(div)

            div.add_class("hand")
            class_suffix = element_name.replace(' ', '_')
            cbjs_action = 'var el=spt.get_cousin(bvr.src_el,".spt_search",".spt_filter_%s");spt.simple_display_toggle(el);' % class_suffix
            div.add_behavior( {
                'type': 'click_up',
                'cbjs_action': cbjs_action
            } )
            div.add_color("color", "color", +5)
            div.add_gradient("background", "background", -5, -5)
            div.add_style("margin-top: -1px")

            div.add_border()
            div.add_style("padding: 3px")
            div.add_style("whitespace: nowrap")

            
            if element_name in ["Parent", 'Children']:
                swap = SwapDisplayWdg.get_triangle_wdg()
            else:
                swap = SwapDisplayWdg.get_triangle_wdg()
                swap.set_off()
            swap.add_action_script(cbjs_action)


            div.add_event("onclick", swap.get_swap_script() )
            div.add(swap)
            div.add_class("SPT_DTS")
            div.add(element_name)

            div = DivWdg()
            div.add_class("spt_filter_%s" % class_suffix)

            if element_name in ["Parent", 'Children']:
                div.add_style("display: none")
            else:
                div.add_style("display: block")

            #div.add_style("background-color: #333")
            div.add_color("background", "background")
            div.add_border()
            div.add_style("padding: 5px 3px 5px 3px")
            div.add_style("margin-top: -1px")
            #div.add_style("margin-left: 20px")
            #div.add_style("width: 660")
            div.add(filter)
            filters_div.add(div)

        filter_div.add(filters_div)

        buttons_div = DivWdg()
        buttons_div.add_style("margin-top: 7px")
        buttons_div.add_style("margin-bottom: 7px")
        buttons_div.add(my.get_search_wdg() )
        filter_div.add(buttons_div)


        filter_top.add(filter_div)

        return filter_top
Beispiel #47
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
Beispiel #48
0
    def get_display(my):
        top = DivWdg()
        top.add_class("spt_element_top")

        prefix = my.kwargs.get('prefix')
        # this should be name to be consistent with the BaseInputWdg interface
        widget_name = my.kwargs.get('name')
        if not widget_name:
            widget_name = 'data_type'

        display_options = my.kwargs.get('display_options')
        if not display_options:
            display_options = {}

        option = my.kwargs.get('option')
        if not option:
            option = {}

        # get the current value
        option_name = option.get('name')
        widget_type = display_options.get(option_name)

        select = SelectWdg(widget_name)
        top.add(select)
        default = option.get('default')
        if default:
            select.set_value(default)
        else:
            select.add_empty_option('-- Select --')

        values = option.get('values')
        if not values:
            values = 'integer|float|percent|currency|date|time|scientific|boolean|text|timecode',
        select.set_option('values', values)

        if widget_type:
            select.set_value(widget_type)

        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
        var value = bvr.src_el.value;
        var top = bvr.src_el.getParent(".spt_element_top");
        var selects = top.getElements(".spt_format");
        for (var i = 0; i < selects.length; i++) {
            var type = selects[i].getAttribute("spt_type");
            if (value == type) {
                selects[i].setStyle("display", "");
                selects[i].removeAttribute("disabled");
            }
            else {
                selects[i].setStyle("display", "none");
                selects[i].setAttribute("disabled", "disabled");
                selects[i].value = '';

            }
        }
        '''
        })

        selects_values = {
            '': [],
            'integer': ['-1234', '-1,234'],
            'float': ['-1234.12', '-1,234.12'],
            'percent': ['-13%', '-12.95%'],
            'currency':
            ['-$1,234', '-$1,234.00', '-$1,234.--', '-1,234.00 CAD'],
            'date': [
                '31/12/99', 'December 31, 1999', '31/12/1999', 'Dec 31, 99',
                'Dec 31, 1999', '31 Dec, 1999', '31 December 1999',
                'Fri, Dec 31, 99', 'Fri 31/Dec 99', 'Fri, December 31, 1999',
                'Friday, December 31, 1999', '12-31', '99-12-31', '1999-12-31',
                '12-31-1999', '12/99', '31/Dec', 'December', '52', 'DATE'
            ],
            'time': [
                '13:37', '13:37:46', '01:37 PM', '01:37:46 PM',
                '31/12/99 13:37', '31/12/99 13:37:46', 'DATETIME'
            ],
            'scientific': ['-1.23E+03', '-1.234E+03'],
            'boolean': ['true|false', 'True|False', 'Checkbox'],
            'timecode': [
                'MM:SS.FF', 'MM:SS:FF', 'MM:SS', 'HH:MM:SS.FF', 'HH:MM:SS:FF',
                'HH:MM:SS'
            ],
        }

        for key, select_values in selects_values.items():
            # skip the empty key
            if not key:
                continue

            # options for each
            if prefix:
                select = SelectWdg("%s|format" % prefix, for_display=False)
            else:
                select = SelectWdg("format", for_display=False)

            select.add_class("spt_format")

            select.add_attr("spt_type", key)

            value = display_options.get('format')
            if key == '':
                select.add_style("display", "none")
            elif widget_type == key:
                select.set_value(value)
            else:
                select.add_style("display", "none")
                select.add_attr("disabled", "disabled")

            select.set_option("values", select_values)
            select.add_empty_option("-- Format --")
            top.add(select)

            if key == 'timecode':
                if prefix:
                    select = SelectWdg("%s|fps" % prefix, for_display=False)
                else:
                    select = SelectWdg("fps", for_display=False)
                select.add_class("spt_format")
                select.add_attr("spt_type", key)

                value = display_options.get('fps')
                if widget_type == key:
                    select.set_value(value)
                else:
                    select.add_style("display", "none")
                select.set_option("values", "12|24|25|30|60")
                select.set_option("labels",
                                  "12 fps|24 fps|25 fps|30 fps|60 fps")
                select.add_empty_option("-- fps --")
                top.add(select)

        return top
Beispiel #49
0
    def get_display(self):

        top = self.top
        self.set_as_panel(top)
        top.add_class("spt_ingestion_top")
        top.add_color("background", "background", -5)

        self.data = {}

        rules_div = DivWdg()
        top.add(rules_div)
        rules_div.add_style("padding: 10px")

        rules_div.add("Rules: ")

        rules_select = SelectWdg("rule_code")
        rule_code = self.get_value('rule_code')
        if rule_code:
            rules_select.set_value(rule_code)
        rules_select.set_option("query", "config/ingest_rule|code|title")
        rules_select.add_empty_option("-- New --")
        rules_div.add(rules_select)
        rules_select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;
        var class_name = 'tactic.ui.tools.IngestionToolWdg';
        spt.panel.load(top, class_name, {rule_code: value} );
        '''
        } )

        rules_div.add("<hr/>")

        # read from the database
        if rule_code:
            search = Search("config/ingest_rule")
            search.add_filter("code", rule_code)
            sobject = search.get_sobject()
        else:
            sobject = None
        if sobject:
            self.data = sobject.get_value("data")
            if self.data:
                self.data = jsonloads(self.data)

        session_code = self.kwargs.get("session_code")
        if session_code:
            session = Search.get_by_code("config/ingest_session", session_code)
        else:
            if sobject:
                session = sobject.get_related_sobject("config/ingest_session")
                print("sobject: ", sobject.get_code(), sobject.get_value("spt_ingest_session_code"))
                print("parent: ", session)
            else:
                session = None


        if not session:
            #session = SearchType.create("config/ingest_session")
            #session.set_value("code", "session101")
            #session.set_value("location", "local")
            ##session.set_value("base_dir", "C:")
            top.add("No session defined!!!")
            return top



        rule = ""
        filter = ""
        ignore = ""


        # get the base path
        if sobject:
            base_dir = sobject.get_value("base_dir")
        else:
            base_dir = ''

        #else:
        #    base_dir = self.get_value("base_dir")
        #if not base_dir:
        #    base_dir = ''

        if sobject:
            title = sobject.get_value("title")
        else:
            title = ''

        if sobject:
            code = sobject.get_value("code")
        else:
            code = ''


        file_list = self.get_value("file_list")
        scan_type = self.get_value("scan_type")
        action_type = self.get_value("action_type")
        rule = self.get_value("rule")
        if not rule:
            rule = base_dir

        # get the rule for this path
        checkin_mode = "dir"
        depth = 0

        table = Table()
        rules_div.add(table)
        table.add_color("color", "color")


        from tactic.ui.input.text_input_wdg import TextInputWdg


        # add the title
        table.add_row()
        td = table.add_cell()
        td.add("Title: ")
        td = table.add_cell()

        text = TextInputWdg(name="title")
        td.add(text)
        if title:
            text.set_value(title)
        text.add_class("spt_title")
        text.add_style("width: 400px")
        #text.add_color("background", "background", -10)

        # add the optional code
        table.add_row()
        td = table.add_cell()
        td.add("Code (optional): ")
        td = table.add_cell()

        text = TextInputWdg(name="code")
        td.add(text)
        if code:
            text.set_value(code)
            text.set_readonly()
            text.add_color("background", "background", -10)
        text.add_class("spt_code")
        text.add_style("width: 400px")





        table.add_row()
        td = table.add_cell()
        td.add_style("height: 10px")
        td.add("<hr/>")


        table.add_row()
        td = table.add_cell()
        td.add("<b>Scan:</b><br/>")
        td.add("The following information will be used to find the paths that will be operated on by the ingestion process<br/><br/>")


        # add a scan type
        table.add_row()
        td = table.add_cell()
        td.add("Type: ")
        select = SelectWdg("scan_type")
        select.add_class("spt_scan_type")
        td = table.add_cell()
        td.add(select)
        select.set_value( self.get_value("action") )
        labels = ['Simple List', 'Rule', 'Script']
        values = ['list', 'rule', 'script']
        select.set_option("values", values)
        select.set_option("labels", labels)
        if scan_type:
            select.set_value(scan_type)

        table.add_row() 
        table.add_cell("&nbsp;")

        select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;

        var elements = top.getElements(".spt_scan_list");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'list')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        var elements = top.getElements(".spt_scan_rule");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'rule')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }
        var elements = top.getElements(".spt_scan_script");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'script')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        '''
        } )

        # add in a list of stuff
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_list")
        if scan_type != 'list':
            tbody.add_style("display: none")

        tr = table.add_row()
        td = table.add_cell()
        td.add("List of files: ")
        td = table.add_cell()

        text = TextAreaWdg(name="file_list")
        td.add(text)
        text.add_style("width: 400px")
        #text.set_readonly()
        #text.add_color("background", "background", -10)
        text.set_value(file_list)

        table.close_tbody()



        # add rule scan mode
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_rule")
        if scan_type != 'rule':
            tbody.add_style("display: none")



        # add the path
        tr = table.add_row()
        td = table.add_cell()
        td.add("Starting Path: ")
        td = table.add_cell()

        hidden = HiddenWdg("session_code", session.get_code() )
        td.add(hidden)

        text = TextInputWdg(name="base_dir")
        td.add(text)
        text.set_value(base_dir)
        text.add_style("width: 400px")
        #text.set_readonly()
        #text.add_color("background", "background", -10)
        text.set_value(base_dir)



        # add rule
        tr = table.add_row()
        td = table.add_cell()
        td.add("Tag Rule: ")
        td = table.add_cell()

        text = TextInputWdg(name="rule")
        td.add(text)
        text.add_style("width: 400px")
        text.set_value(rule)


        tr = table.add_row()
        td = table.add_cell()
        td.add("Filter: ")
        td = table.add_cell()
        text = TextWdg("filter")
        td.add(text)
        text.set_value( self.get_value("filter") )
        text.add_style("width: 400px")
        text.add_style("padding: 2px")
        text.add_style("-moz-border-radius: 5px")




        tr = table.add_row()
        td = table.add_cell()
        td.add("Ignore: ")
        td = table.add_cell()
        text = TextWdg("ignore")
        td.add(text)
        text.set_value( self.get_value("ignore") )
        text.set_value(ignore)
        text.add_style("width: 400px")
        text.add_style("padding: 2px")
        text.add_style("-moz-border-radius: 5px")


        table.add_row()
        td = table.add_cell()
        td.add("Validation script: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextInputWdg(name="validation_script")
        text.set_value( self.get_value("validation_script") )
        text.add_style("width: 400px")
        td.add(text)

        icon = IconButtonWdg(title='Edit Validation Script', icon=IconWdg.EDIT)
        icon.add_style("float: right")
        td.add(icon)
        icon.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        spt.named_events.fire_event("show_script_editor");

        var top = bvr.src_el.getParent(".spt_ingestion_top");
        var values = spt.api.Utility.get_input_values(top, null, false);

        var kwargs = {
            script_path: values.validation_script
        }
        setTimeout( function() {
        spt.js_edit.display_script_cbk(evt, kwargs)
        }, 500 );
        '''
        } )



        table.close_tbody()



        # add the script path
        tbody = table.add_tbody()
        tbody.add_class("spt_scan_script")
        if scan_type != 'script':
            tbody.add_style("display: none")


        tr = table.add_row()
        td = table.add_cell()
        td.add("Script Path: ")
        td = table.add_cell()

        text = TextInputWdg(name="script_path")
        td.add(text)
        text.add_style("width: 400px")


        table.close_tbody()



        table.add_row()
        td = table.add_cell("<hr/>")



        table.add_row()
        td = table.add_cell()
        td.add("<b>Action</b><br/>")
        td.add("The following information define the actions that will be used on each matched path<br/><br/>")


        # pick the type of action
        table.add_row()
        td = table.add_cell()
        td.add("Type: ")
        select = SelectWdg("action_type")
        td = table.add_cell()
        td.add(select)
        labels = ['Checkin', 'Ignore']
        values = ['checkin', 'ignore']
        select.set_option("values", values)
        select.set_option("labels", labels)
        select.add_empty_option("-- Select --")
        if action_type:
            select.set_value(action_type)

        select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_ingestion_top");
        value = bvr.src_el.value;

        var elements = top.getElements(".spt_action_ignore");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'ignore')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        var elements = top.getElements(".spt_action_checkin");
        for (var i = 0; i < elements.length; i++) {
          if (value == 'checkin')
            spt.show(elements[i]);
          else
            spt.hide(elements[i]);
        }

        '''
        } )



        table.add_row()
        td = table.add_cell("<br/>")



        # add the script path
        tbody = table.add_tbody()
        tbody.add_class("spt_action_checkin")
        if action_type != 'checkin':
            tbody.add_style("display: none")



        # add the checkin type
        table.add_row()
        td = table.add_cell()
        td.add("Action: ")
        select = SelectWdg("action")
        td = table.add_cell()
        td.add(select)
        select.set_value( self.get_value("action") )
        labels = ['File Checkin', 'Directory Checkin', 'Sequence Checkin']
        values = ['file', 'directory', 'sequence', 'ignore']
        select.set_option("values", values)
        select.set_option("labels", labels)





        table.add_row()
        td = table.add_cell()
        td.add("Mode: ")
        select = SelectWdg("mode")
        td = table.add_cell()
        td.add(select)
        labels = ['Copy', 'Move', 'In Place']
        values = ['copy', 'move', 'inplace']
        select.set_option("values", values)
        select.set_option("labels", labels)






        # add the search_type
        table.add_row()
        td = table.add_cell()
        td.add("sType: ")
        td = table.add_cell()
        select = SelectWdg("search_type")
        td.add(select)
        search_types = Project.get().get_search_types()
        values = [x.get_value("search_type") for x in search_types]
        select.set_option("values", values)

        search_type = self.kwargs.get("search_type")
        if search_type:
            select.set_value(search_type)



        # add the search_type
        table.add_row()
        td = table.add_cell()
        td.add("Context: ")
        td = table.add_cell()
        select = SelectWdg("context")
        td.add(select)
        select.set_option("values", ['publish', 'by rule', 'custom'])




        # add extra values
        extra_div = DivWdg()
        text = TextWdg("extra_name")
        text.add_attr("spt_is_multiple", "true")
        extra_div.add(text)
        extra_div.add(" = ")
        text = TextWdg("extra_value")
        extra_div.add(text)
        text.add_attr("spt_is_multiple", "true")

        template_div = DivWdg()
        text = TextWdg("extra_name")
        text.add_attr("spt_is_multiple", "true")
        template_div.add(text)
        template_div.add(" = ")
        text = TextWdg("extra_value")
        template_div.add(text)
        text.add_attr("spt_is_multiple", "true")


        table.close_tbody()



        table.add_row()
        td = table.add_cell("<br/>")

        table.add_row()
        td = table.add_cell()
        td.add("Extra Keywords: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("keywords")
        text.add_style("width: 300px")
        td.add(text)





        table.add_row()
        td = table.add_cell()
        td.add("Extra Values: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        extra_list = DynamicListWdg()
        td.add(extra_list)
        extra_list.add_item(extra_div)
        extra_list.add_template(template_div)


        table.add_row()
        table.add_cell("&nbsp;")



        table.add_row()
        td = table.add_cell()
        td.add("Process script: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("process_script")
        text.add_style("width: 300px")
        td.add(text)
        text.set_value( self.get_value("process_script") )


        icon = IconButtonWdg(title='Edit Process Script', icon=IconWdg.EDIT)
        icon.add_style("float: right")
        td.add(icon)
        icon.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        spt.named_events.fire_event("show_script_editor");

        var top = bvr.src_el.getParent(".spt_ingestion_top");
        var values = spt.api.Utility.get_input_values(top, null, false);

        var kwargs = {
            script_path: values.process_script
        }

        // need to wait for this
        setTimeout( function() {
        spt.js_edit.display_script_cbk(evt, kwargs)
        }, 500 );
        '''
        } )



        table.add_row()
        td = table.add_cell()
        td.add("Custom Naming: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 5px")
        td = table.add_cell()
        text = TextWdg("naming")
        text.add_style("width: 300px")
        td.add(text)




        table.add_row()
        td = table.add_cell()

        #td.add("<br clear='all'/>")
        td.add("<hr/>")


        behavior = {
            'type': 'click_up',
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var values = spt.api.Utility.get_input_values(top, null, false);

            spt.app_busy.show("Scanning ...", values.base_dir);

            var class_name = 'tactic.ui.tools.IngestionProcessWdg';

            var server = TacticServerStub.get();
            values.mode = bvr.mode;

            values.is_local = 'true';

            // scan client side
            if (values.is_local == 'true') {
                var base_dir = values.base_dir;
                var applet = spt.Applet.get();
                var files = applet.list_recursive_dir(base_dir);
                // turn into a string
                var files_in_js = [];
                for (var i = 0; i < files.length; i++) {
                    var file = files[i].replace(/\\\\/g, "/");
                    files_in_js.push( file );
                }
                values.files = files_in_js;
                values.base_dir = base_dir;

                /*
                var server = TacticServerStub.get();
                var handoff_dir = server.get_handoff_dir();
                var applet = spt.Applet.get();
                for (var i = 0; i < files_in_js.length; i++) {
                    try {
                        var parts = files_in_js[i].split("/");
                        var filename = parts[parts.length-1];
                        spt.app_busy.show("Copying files to handoff", filename);
                        applet.copy_file(files_in_js[i], handoff_dir+"/"+filename);
                    } catch(e) {
                        log.error(e);
                    }

                }
                */
            }

            var info_el = top.getElement(".spt_info");
            spt.panel.load(info_el, class_name, values);
            spt.app_busy.hide();
            '''
        }


        # Save button
        button = ActionButtonWdg(title="Save", tip="Save Rule")
        td.add(button)
        button.add_style("float: right")
        behavior['mode'] = 'save'
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var values = spt.api.Utility.get_input_values(top, null, false);
            spt.app_busy.show("Saving ...");

            var class_name = 'tactic.command.CheckinRuleSaveCmd';
            var server = TacticServerStub.get();
            server.execute_cmd(class_name, values);

            spt.panel.refresh(top, {});

            spt.app_busy.hide();

            '''
        } )



 
        # Scan button
        button = ActionButtonWdg(title="Scan", tip="Click to Scan")
        td.add(button)
        button.add_style("float: left")


        # set a limit
        #limit = TextWdg("limit")
        #td.add(limit)
        #text.add_style("float: left")


        behavior = behavior.copy()
        behavior['mode'] = 'scan'
        button.add_behavior(behavior)

        # Test button
        button = ActionButtonWdg(title="Test", tip="Do a test of this rule")
        td.add(button)
        behavior = behavior.copy()
        behavior['mode'] = 'test'
        button.add_behavior(behavior)
        button.add_style("float: left")




        # Ingest button
        button = ActionButtonWdg(title="Ingest", tip="Click to start ingesting")
        td.add(button)
        behavior = behavior.copy()
        behavior['mode'] = 'checkin'
        button.add_behavior(behavior)



        table.add_behavior( {
            'type': 'listen',
            'event_name': 'file_browser|select',
            'cbjs_action': '''
            var dirname = bvr.firing_data.dirname;
            var top = bvr.src_el.getParent(".spt_ingestion_top");
            var kwargs = {
              base_dir: dirname
            };

            spt.panel.load(top, top.getAttribute("spt_class_name"), kwargs);
            '''
        })


        top.add( self.get_info_wdg() )

        return top
Beispiel #50
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
Beispiel #51
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
Beispiel #52
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
    def get_display(my):
        my.labels_attr =  my.get_option('label_attr')
        if my.labels_attr:
            my.labels_attr = my.labels_attr.split('|')

        from tactic.ui.panel import EditWdg
        if hasattr(my, 'parent_wdg') and isinstance(my.get_parent_wdg(), EditWdg):
            sobject = my.get_current_sobject()
            parent = sobject.get_parent()
            group = None
            pipeline_code = None

            if parent:
                pipeline_code = parent.get_value('pipeline_code')
            pipeline = Pipeline.get_by_code(pipeline_code)
            
            labels_expr = None

            if pipeline:
                attrs = pipeline.get_process_attrs(sobject.get_value('process'))
                group = attrs.get('%s_login_group'%my.get_name())
            if group:
            
                values_expr = "@GET(sthpw/login_group['login_group', '%s'].sthpw/login_in_group.sthpw/login.login)"%group
                if my.labels_attr:
                    labels_expr = ["@GET(sthpw/login_group['login_group', '%s'].sthpw/login_in_group.sthpw/login.%s)"%(group, x.strip()) for x in my.labels_attr]
                    labels_expr =  ' + &nbsp + '.join(labels_expr)
            else:
                values_expr = "@GET(sthpw/login.login)"
                if my.labels_attr:
                    labels_expr = ["@GET(sthpw/login.%s)"%(x.strip()) for x in my.labels_attr]
                    labels_expr =  ' + &nbsp + '.join(labels_expr)
            select = SelectWdg(my.get_input_name())
            select.add_empty_option("-- Select a User --")
            """
            values = []
            labels = []
            for user in group_users:
                values.append(user)
                labels.append('  %s'%user)
            """
            select.set_option('values_expr', values_expr)
            if labels_expr:
                select.set_option('labels_expr', labels_expr)
            current_value = sobject.get_value(my.get_name())
            if current_value:
                select.set_value(current_value)
            return select


        #all_users = Search.eval("@GET(sthpw/login.login)")
        all_users = Search.eval("@SOBJECT(sthpw/login)")
        all_users_label =  []
        
        # don't use expression here since it's not as db-efficient as retrieving the sobjects
        """
        if my.labels_attr:
            labels_expr = ["@GET(sthpw/login.login.%s)"%x.strip() for x in my.labels_attr]
        """
        '''
        groups = Search.eval("@SOBJECT(sthpw/login_group)")
        group_dict = {}
        for group in groups:
            group_users =
Search.eval("@GET(sthpw/login_group['login_group',
'%s'].sthpw/login_in_group.sthpw/login.login)"%group.get_value('login_group'))
            group_dict[group.get_value('login_group')] = group_users
        '''

        logins_dict = {}
        for user in all_users:
            user_name = user.get_value('login')
            logins_dict[user_name] = {}
        group_dict = {}
        items = Search.eval("@SOBJECT(sthpw/login_in_group)")
        for item in items:
             item_login = item.get_value("login")
             if logins_dict.get(item_login) == None:
                 continue
             item_group = item.get_value("login_group")

             group_list = group_dict.get(item_group)
             if group_list == None:
                 group_list = []
                 group_dict[item_group] = group_list
             group_list.append(item_login)


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

        # HACK! This isn't very well constructed
        ### Tore: Not my code! Copied from ProcessContextInputWdg. Seems to work though.
        top.add_attr("spt_cbjs_get_input_key", "return cell_to_edit.getAttribute('spt_pipeline_code');")
        
        # Adding an "all users" select option in case it can't find a useful select widget.
        div = DivWdg()
        div.add_class("spt_input_option")
        #div.add_attr("spt_input_key", '__all__') #Not needed, since it defaults to the first one anyway.
        select = SelectWdg(my.get_name())
        select.add_empty_option("-- Select a User --")
        values = []
        labels = []
        labels_dict = {}
        for user in all_users:
            user_name = user.get_value('login')
            values.append(user_name)
            label = user_name
            if my.labels_attr:
                user_labels = [user.get_value(x) for x in my.labels_attr]
                label = ' '.join(user_labels)

            labels_dict[user_name] = label
            
            labels.append('%s'%label)
            #print "select ", user_name

        # -- NOTE: leaving this commented out code here for reference. Not sure why this is the case but when
        # --       this click behavior is used instead of a 'change' behavior that forces a blur on select,
        # --       click selection only works for this widget in Firefox and does NOT work in IE
        #
        # select.add_behavior( { 'type': 'click',
        #    'cbjs_action': 'spt.dg_table.select_wdg_clicked( evt, bvr.src_el );' } )


        # -- Replace previous 'click' behavior with a 'change' behavior to force blur() of select element ...
        # -- this works for both Firefox and IE
        #
        select.add_behavior( { 'type': 'change',
           'cbjs_action': 'bvr.src_el.blur();' } )


        #behavior = {
        #    'type': 'keyboard',
        #    'kbd_handler_name': 'DgTableSelectWidgetKeyInput',
        #}
        #select.add_behavior( behavior )


        select.set_option("values", values)
        select.set_option("labels", labels)
           
        div.add(select)
        top.add(div)
        
        #Building each of the select widgets per group here.
        for group in group_dict.keys():
            div = DivWdg()
            div.add_class("spt_input_option")
            div.add_attr("spt_input_key", group)
            
            select = SelectWdg(my.get_name())
            select.add_empty_option("-- Select a User --")
            values = ['']
            labels = ['<< %s >>'%group]
            for user in group_dict[group]:
                values.append(user)
                label = labels_dict.get(user)
                labels.append('  %s'%label)
            select.add_behavior( { 'type': 'click',
               'cbjs_action': 'spt.dg_table.select_wdg_clicked( evt, bvr.src_el );' } )
            #behavior = {
            #    'type': 'keyboard',
            #    'kbd_handler_name': 'DgTableSelectWidgetKeyInput',
            #}
            #select.add_behavior( behavior )
            select.set_option("values", values)
            select.set_option("labels", labels)
            
            div.add(select)
            top.add(div)
        
        return top
    def get_display(self):

        # add the detail widget
        detail_wdg = DivWdg(css='spt_detail_panel')
        if not self.name_string and not self.config_string:
            detail_wdg.add("<br/>"*3)
            detail_wdg.add('<- Click on an item on the left for modification.')
            detail_wdg.add_style("padding: 10px")
            detail_wdg.add_color("background", "background", -5)
            detail_wdg.add_style("width: 350px")
            detail_wdg.add_style("height: 400px")
            detail_wdg.add_border()

            return detail_wdg

        if self.kwargs.get("mode") == "empty":
            overlay = DivWdg()
            detail_wdg.add(overlay)

        detail_wdg.add_border()
        detail_wdg.add_color("color", "black")
        detail_wdg.add_style("padding: 10px")
        detail_wdg.add_color("background", "background", -5)

        detail_wdg.set_id('search_type_detail')

        # put in the selection for simple or advanced
        select = SelectWdg("config_mode", label='Mode: ')
        select.set_persistence()
        values = ['simple', 'advanced']
        select.set_option("values", values)
        config_mode = select.get_value()
        #select.add_behavior({"type": "change", "cbjs_action": "spt.simple_display_toggle( spt.get_cousin(bvr.src_el, '.spt_detail_panel','.config_simple') )"})
        select.add_behavior({"type": "change", "cbjs_action": \
            "spt.simple_display_toggle( spt.get_cousin(bvr.src_el, '.spt_detail_panel','.config_advanced')); %s" %select.get_save_script()})

        select.add_class('spt_config_mode')

        title_div = DivWdg("Column Detail")
        title_div.add_class("maq_search_bar")
        detail_wdg.add(title_div)
        detail_wdg.add("<br/>")
        detail_wdg.add(select)
        detail_wdg.add(HtmlElement.br(2))

        #simple_mode_wdg = WidgetDetailSimpleModeWdg()
        #detail_wdg.add(simple_mode_wdg)
        #detail_wdg.add(HtmlElement.br(2))

        if self.is_new_column:
            detail_wdg.add( self.get_new_definition_wdg() )
        else:
            
            simple_wdg = self.get_simple_definition_wdg()
           
            simple_wdg.add_class("config_simple")
            detail_wdg.add( simple_wdg )
            adv_wdg = self.get_advanced_definition_wdg()
            adv_wdg.add_class("config_advanced")
            if config_mode == 'simple':
                adv_wdg.add_style('display: none')
            detail_wdg.add(HtmlElement.br(2))
            detail_wdg.add( adv_wdg )

        detail_wdg.add(HtmlElement.br(2))


        security_wdg = self.get_security_wdg()
        detail_wdg.add(security_wdg)


        # add hidden input for view for panel refreshing
        # we are only interested in whether it is project_view or definition
        # sub-views of project_view is not of our interest

        #if self.view != 'project_view':
        #    self.view = 'custom_definition'
        detail_wdg.add(HiddenWdg('view', self.view))


        return detail_wdg
Beispiel #55
0
    def get_display(self):

        parser = self.kwargs.get("parser")

        self.search_key = self.kwargs.get("search_key")
        sobject = Search.get_by_search_key(self.search_key)

        if sobject.get_base_search_type() == "sthpw/snapshot":
            snapshot = sobject
        elif sobject.get_base_search_type() == "sthpw/file":
            # if it is a file object
            snapshot = sobject.get_parent()
        else:
            snapshots = Snapshot.get_by_sobject(sobject, is_latest=True)
            snapshot = snapshots[0]

        # Extension determine UI class for preview
        thumb_path = snapshot.get_web_path_by_type("icon")
        web_src = snapshot.get_web_path_by_type("web")

        from pyasm.biz import File
        file_type = "main"
        lib_path = snapshot.get_lib_path_by_type(file_type)
        src = snapshot.get_web_path_by_type(file_type)
        if not web_src:
            web_src = src

        parts = os.path.splitext(src)
        ext = parts[1]
        ext = ext.lstrip(".")
        ext = ext.lower()

        #parent = snapshot.get_parent()

        top = self.top
        self.set_as_panel(top)

        if ext == "pdf":
            iframe = HtmlElement.iframe()
            iframe.set_attr('src', src)
            iframe.add_style("width: 100%")
            iframe.add_style("height: 800px")
            top.add(iframe)
            return top

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

        # These bvrs allow for smooth switching if switching between files
        # like in the RepoBrowserWdg
        tr.add_style("height: 200px")
        load_height_bvr = {
            'type':
            'load',
            'cbjs_action':
            '''
            var last_height = spt.container.get_value("last_img_height");
            if (last_height) {
                bvr.src_el.setStyle("height", last_height);
            } 
            '''
        }
        tr.add_behavior(load_height_bvr)

        unload_height_bvr = {
            'type':
            'unload',
            'cbjs_action':
            '''
            var last_height = bvr.src_el.getStyle("height");
            spt.container.set_value("last_img_height", last_height);
            '''
        }
        tr.add_behavior(unload_height_bvr)

        table.add_style("width: 100%")
        table.add_style("text-align", "center")

        from tactic.ui.widget import EmbedWdg
        td = table.add_cell()
        td.add_color(
            "background",
            "background",
        )
        td.add_style("vertical-align: middle")
        td.add_style("height: inherit")
        td.add_style("overflow-x: auto")

        if ext in ['txt', 'html', 'ini']:
            content_div = DivWdg()
            f = open(lib_path, 'r')
            content = f.read(10000)
            f.close()
            if not content:
                text = "No Content"
            else:

                size = os.path.getsize(lib_path)

                from pyasm.common import FormatValue
                value = FormatValue().get_format_value(size, "KB")

                content_div.add("Showing first 10K of %s<hr/>" % value)

                text = TextAreaWdg()
                text.add(content)
                text.add_style("width: 100%")
                text.add_style("height: 100%")
                text.add_style("padding: 10px")
                text.add_style("border: none")
                text.add_attr("readonly", "true")

            content_div.add(text)
            td.add(content_div)
            content_div.add_style("color", "#000")
            content_div.add_style("width", "auto")
            content_div.add_style("margin", "20px")
            content_div.add_style("height", "100%")

        elif ext in File.IMAGE_EXT or ext == "gif":
            if lib_path.find("#") != -1:
                img = DivWdg()

                file_range = snapshot.get_file_range()
                file_range_div = DivWdg()
                file_range_div.add("File Range: %s" % file_range.get_display())
                img.add(file_range_div)
                file_range_div.add_style("font-size: 1.4em")
                file_range_div.add_style("margin: 15px 0px")
                """
                left_chevron = IconWdg("Previous", "BS_CHEVRON_LEFT")
                file_range_div.add(left_chevron)
                right_chevron = IconWdg("Next", "BS_CHEVRON_RIGHT")
                file_range_div.add(right_chevron)
                """

                expanded_paths = snapshot.get_expanded_web_paths()
                lib_paths = snapshot.get_expanded_lib_paths()
                lib_path = lib_paths[0]

                items_div = DivWdg()
                img.add(items_div)
                items_div.add_style("width: auto")

                for path in expanded_paths:
                    item = HtmlElement.img(src=path)
                    items_div.add(item)
                    item.add_style("max-height: 300px")
                    item.add_style("height: auto")
                    item.add_style("width: 32%")
                    item.add_style("margin: 2px")
                    item.add_style("display: inline-block")
                    #item.add_class("spt_resizable")

                img.add_style("margin: 20px")
                img.add_style("max-height: 400px")
                img.add_style("overflow-y: auto")
                img.add_style("overflow-hidden: auto")
                img.add_style("text-align: left")

            else:
                if ext == "gif":
                    img = HtmlElement.img(src=src)
                else:
                    img = HtmlElement.img(src=web_src)
                img.add_style("height: inherit")
                img.add_style("width: auto")
            td.add(img)
        elif ext in File.VIDEO_EXT:
            embed_wdg = EmbedWdg(src=src,
                                 thumb_path=thumb_path,
                                 preload="auto",
                                 controls=True)
            td.add(embed_wdg)

            embed_wdg.add_style("margin: auto auto")
            embed_wdg.add_class("spt_resizable")

            embed_wdg.add_behavior(load_height_bvr)
            embed_wdg.add_behavior(unload_height_bvr)

        else:
            thumb_table = DivWdg()
            td.add(thumb_table)

            thumb_table.add_behavior({
                'type':
                'click_up',
                'src':
                src,
                'cbjs_action':
                '''
                window.open(bvr.src);
                '''
            })
            thumb_table.add_class("hand")
            thumb_table.add_style("width: 200px")
            thumb_table.add_style("height: 125px")
            thumb_table.add_style("padding: 5px")
            thumb_table.add_style("margin-left: 20px")
            thumb_table.add_style("display: inline-block")
            thumb_table.add_style("vertical-align: top")
            thumb_table.add_style("overflow-y: hidden")
            from tactic.ui.panel import ThumbWdg2
            thumb = ThumbWdg2()
            thumb_table.add(thumb)
            thumb.set_sobject(snapshot)

        table.add_row()
        td = table.add_cell()

        from tactic.ui.checkin import PathMetadataWdg
        from tactic.ui.checkin import SnapshotMetadataWdg

        from pyasm.widget import SelectWdg
        select = SelectWdg(name="parser")
        select.add_style("width: 125px")
        select.add_style("margin-top: 0px")
        select.add_style("margin-right: 10px")
        select.add_empty_option("-- Metadata --")
        td.add(select)
        select.add_style("float: right")
        select.set_option("values",
                          ["IPTC", "EXIF", "XMP", "ImageMagick", "PIL"])
        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
            var parser = bvr.src_el.value;
            spt.panel.refresh_element(bvr.src_el, {parser: parser})
            '''
        })
        if parser:
            select.set_value(parser)

        title_div = DivWdg()
        td.add(title_div)
        title_div.add("<div style='font-size: 16px'>File Metadata</div>")
        title_div.add("<div>Metadata extracted directly from the file</div>")
        title_div.add("<hr/>")
        title_div.add_style("text-align: left")
        title_div.add_style("margin: 0px 10px")

        metadata_div = DivWdg()
        td.add(metadata_div)
        metadata_div.add_style("max-height: 400px")
        metadata_div.add_style("overflow-y: auto")
        metadata_div.add_style("overflow-x: hidden")
        metadata_div.add_style("margin: 20px 0px 20px 10px")
        metadata_div.add_style("text-align: left")

        use_tactic_tags = self.kwargs.get("use_tactic_tags")

        server_src = lib_path

        # get it dynamically by path
        metadata_wdg = PathMetadataWdg(path=server_src,
                                       parser=parser,
                                       use_tactic_tags=use_tactic_tags,
                                       search_key=self.search_key)
        metadata_div.add(metadata_wdg)

        top.add("<br/>")

        return top
Beispiel #56
0
    def get_display(my):

        top = my.top
        top.add_style("padding: 20px")
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("width", "500px")

        top.add_class("spt_db_register_top")
        my.set_as_panel(top)


        inner = DivWdg()
        top.add(inner)


        # db resource
        db_resource = my.get_value("db_resource")

        db_resource_wdg = DivWdg()
        inner.add(db_resource_wdg)
        db_resource_wdg.add("Database Resource: ")

        search = Search("sthpw/db_resource")
        db_resources = search.get_sobjects()
        codes = [x.get_code() for x in db_resources]

        select = SelectWdg("db_resource")
        db_resource_wdg.add(select)
        select.set_option("values", codes)
        if db_resource:
            select.set_value(db_resource)
        select.add_behavior( {
            'type': 'change',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_db_register_top");
            spt.panel.refresh(top);
            '''
        } )

        if db_resource:
            info_wdg = DivWdg()
            db_resource_wdg.add(info_wdg)
            info_wdg.add_border()
            info_wdg.add_style("padding: 20px")
            info_wdg.add_style("margin: 20px")



        inner.add("<br/>")


        # list of databases
        database_wdg = DivWdg()
        inner.add(database_wdg)
        database_wdg.add("Available Databases: ")


        databases = ['test', 'test1', 'test2']

        select = SelectWdg("databases")
        database_wdg.add(select)
        select.set_option("values", databases)



        # list of projects





        if my.kwargs.get('is_refresh') == 'true':
            return inner
        else:
            return top