Пример #1
0
    def get_display(my):
       
        name = my.kwargs.get('name')
        select = SelectWdg(name)
        select.add_class('twog_move_select')
        select.set_option('empty','true')
        # limit to last 10
        select.set_options(my.kwargs)

        # if it's not set from kwargs, we have this default values/labels
        if not my.kwargs.get('values_expr'):
            select.set_option('values_expr', "@GET(twog/movement['@LIMIT','10']['@ORDER_BY','timestamp desc'].code)")
            select.set_option('labels_expr', "@GET(twog/movement['@LIMIT','10']['@ORDER_BY','timestamp desc'].code) + ':' + @GET(twog/movement['@LIMIT','10']['@ORDER_BY','timestamp desc'].name)")
        return select
Пример #2
0
    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
Пример #3
0
    def get_data_wdg(my):
        div = DivWdg()

        from pyasm.biz import Pipeline
        from pyasm.widget import SelectWdg
        search_type_obj = SearchType.get(my.search_type)
        base_type = search_type_obj.get_base_key()
        search = Search("sthpw/pipeline")
        search.add_filter("search_type", base_type)
        pipelines = search.get_sobjects()
        if pipelines:
            pipeline = pipelines[0]

            process_names = pipeline.get_process_names()
            if process_names:
                table = Table()
                div.add(table)
                table.add_row()
                table.add_cell("Process: ")
                select = SelectWdg("process")
                table.add_cell(select)
                process_names.append("---")
                process_names.append("publish")
                process_names.append("icon")
                select.set_option("values", process_names)

        ####
        buttons = Table()
        div.add(buttons)
        buttons.add_row()

        #button = IconButtonWdg(title="Fill in Data", icon=IconWdg.EDIT)
        button = ActionButtonWdg(title="Metadata")
        button.add_style("float: left")
        button.add_style("margin-top: -3px")
        buttons.add_cell(button)

        select_label = DivWdg("Update mode")
        select_label.add_style("float: left")
        select_label.add_style("margin-top: -3px")
        select_label.add_style("margin-left: 20px")
        buttons.add_cell(select_label)

        update_mode_option = my.kwargs.get("update_mode")
        if not update_mode_option:
            update_mode_option = "true"
        update_mode = SelectWdg(name="update mode")
        update_mode.add_class("spt_update_mode_select")
        update_mode.set_option("values", ["false", "true", "sequence"])
        update_mode.set_option("labels", ["Off", "On", "Sequence"])
        update_mode.set_option("default", update_mode_option)
        update_mode.add_style("float: left")
        update_mode.add_style("margin-top: -3px")
        update_mode.add_style("margin-left: 5px")
        update_mode.add_style("margin-right: 5px")
        buttons.add_cell(update_mode)

        update_info = DivWdg()
        update_info.add_class("glyphicon")
        update_info.add_class("glyphicon-info-sign")
        update_info.add_style("float: left")
        update_info.add_style("margin-top: -3px")
        update_info.add_style("margin-left: 10px")
        update_info.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.info("When update mode is on, if a file shares the name of one other file in the asset library, the file will update on ingest. If more than one file shares the name of an ingested asset, a new asset is created.<br> If sequence mode is selected, the system will update the sobject on ingest if a file sequence sharing the same name already exists.", {type: 'html'});
            '''
        })
        buttons.add_cell(update_info)

        dialog = DialogWdg(display="false", show_title=False)
        div.add(dialog)
        dialog.set_as_activator(button, offset={'x': -10, 'y': 10})

        dialog_data_div = DivWdg()
        dialog_data_div.add_color("background", "background")
        dialog_data_div.add_style("padding", "20px")
        dialog.add(dialog_data_div)

        # Order folders by date
        name_div = DivWdg()
        dialog_data_div.add(name_div)
        name_div.add_style("margin: 15px 0px")

        if SearchType.column_exists(my.search_type, "relative_dir"):

            category_div = DivWdg()
            name_div.add(category_div)
            checkbox = RadioWdg("category")
            checkbox.set_option("value", "none")
            category_div.add(checkbox)
            category_div.add(" No categories")
            category_div.add_style("margin-bottom: 5px")
            checkbox.set_option("checked", "true")

            category_div = DivWdg()
            name_div.add(category_div)
            checkbox = RadioWdg("category")
            checkbox.set_option("value", "by_day")
            category_div.add(checkbox)
            category_div.add(" Categorize files by Day")
            category_div.add_style("margin-bottom: 5px")

            category_div = DivWdg()
            name_div.add(category_div)
            checkbox = RadioWdg("category")
            checkbox.set_option("value", "by_week")
            category_div.add(checkbox)
            category_div.add(" Categorize files by Week")
            category_div.add_style("margin-bottom: 5px")

            category_div = DivWdg()
            name_div.add(category_div)
            checkbox = RadioWdg("category")
            checkbox.set_option("value", "by_year")
            category_div.add(checkbox)
            category_div.add(" Categorize files by Year")
            category_div.add_style("margin-bottom: 5px")
            """
            checkbox = RadioWdg("category")
            checkbox.set_option("value", "custom")
            name_div.add(checkbox)
            name_div.add(" Custom")
            """

            name_div.add("<br/>")

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

        from tactic.ui.panel import EditWdg

        sobject = SearchType.create(my.search_type)
        edit = EditWdg(search_key=sobject.get_search_key(),
                       mode='view',
                       view=ingest_data_view)

        dialog_data_div.add(edit)
        hidden = HiddenWdg(name="parent_key")
        dialog_data_div.add(hidden)
        hidden.add_class("spt_parent_key")
        parent_key = my.kwargs.get("parent_key") or ""
        if parent_key:
            hidden.set_value(parent_key)

        extra_data = my.kwargs.get("extra_data")
        if not isinstance(extra_data, basestring):
            extra_data = jsondumps(extra_data)

        if extra_data and extra_data != "null":
            # it needs a TextArea instead of Hidden because of JSON data
            text = TextAreaWdg(name="extra_data")
            text.add_style('display: none')
            text.set_value(extra_data)
            dialog_data_div.add(text)
        """
 
        dialog_data_div.add("Keywords:<br/>")
        dialog.add(dialog_data_div)
        text = TextAreaWdg(name="keywords")
        dialog_data_div.add(text)
        text.add_class("spt_keywords")
        text.add_style("padding: 1px")


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

       
        text.add_class("spt_extra_data")
        text.add_style("padding: 1px")

        """

        #### TEST Image options
        """
        button = IconButtonWdg(title="Resize", icon=IconWdg.FILM)
        buttons.add_cell(button)

        dialog = DialogWdg(display="false", show_title=False)
        div.add(dialog)
        dialog.set_as_activator(button, offset={'x':-10,'y':10})

        try:
            from spt.tools.convert import ConvertOptionsWdg
            convert_div = DivWdg()
            dialog.add(convert_div)
            convert_div.add_style("padding: 20px")
            convert_div.add_color("background", "background")
            convert_div.add_class("spt_image_convert")

            convert = ConvertOptionsWdg()
            convert_div.add(convert)
        except:
            pass
        """

        # use base name for name
        """
        name_div = DivWdg()
        dialog_data_div.add(name_div)
        name_div.add_style("margin: 15px 0px")


        checkbox = CheckboxWdg("use_file_name")
        name_div.add(checkbox)
        name_div.add(" Use name of file for name")

        name_div.add("<br/>")

        checkbox = CheckboxWdg("use_base_name")
        name_div.add(checkbox)
        name_div.add(" Remove extension")


        name_div.add("<br/>")

        checkbox = CheckboxWdg("file_keywords")
        name_div.add(checkbox)
        name_div.add(" Use file name for keywords")
        """

        return div
Пример #4
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
Пример #5
0
    def get_data_wdg(my):
        div = DivWdg()

        from pyasm.biz import Pipeline
        from pyasm.widget import SelectWdg
        search_type_obj = SearchType.get(my.search_type)
        base_type = search_type_obj.get_base_key()
        search = Search("sthpw/pipeline")
        search.add_filter("search_type", base_type)
        pipelines = search.get_sobjects()
        if pipelines:
            pipeline = pipelines[0]

            process_names = pipeline.get_process_names()
            if process_names:
                table = Table()
                div.add(table)
                table.add_row()
                table.add_cell("Process: ")
                select = SelectWdg("process")
                table.add_cell(select)
                process_names.append("---")
                process_names.append("publish")
                process_names.append("icon")
                select.set_option("values", process_names)
        


        ####
        buttons = Table()
        div.add(buttons)
        buttons.add_row()


        #button = IconButtonWdg(title="Fill in Data", icon=IconWdg.EDIT)
        button = ActionButtonWdg(title="Metadata")
        button.add_style("float: left")
        button.add_style("margin-top: -3px")
        buttons.add_cell(button)
        
        select_label = DivWdg("Update mode");
        select_label.add_style("float: left")
        select_label.add_style("margin-top: -3px")
        select_label.add_style("margin-left: 20px")
        buttons.add_cell(select_label)
        
        update_mode_option = my.kwargs.get("update_mode")
        if not update_mode_option:
            update_mode_option = "true"
        update_mode = SelectWdg(name="update mode")
        update_mode.add_class("spt_update_mode_select")
        update_mode.set_option("values", ["false", "true", "sequence"])
        update_mode.set_option("labels", ["Off", "On", "Sequence"])
        update_mode.set_option("default", update_mode_option)
        update_mode.add_style("float: left")
        update_mode.add_style("margin-top: -3px")
        update_mode.add_style("margin-left: 5px")
        update_mode.add_style("margin-right: 5px")
        buttons.add_cell(update_mode)

        update_info = DivWdg()
        update_info.add_class("glyphicon")
        update_info.add_class("glyphicon-info-sign")
        update_info.add_style("float: left")
        update_info.add_style("margin-top: -3px")
        update_info.add_style("margin-left: 10px")
        update_info.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.info("When update mode is on, if a file shares the name of one other file in the asset library, the file will update on ingest. If more than one file shares the name of an ingested asset, a new asset is created.<br> If sequence mode is selected, the system will update the sobject on ingest if a file sequence sharing the same name already exists.", {type: 'html'});
            '''
        } )
        buttons.add_cell(update_info);
 
        dialog = DialogWdg(display="false", show_title=False)
        div.add(dialog)
        dialog.set_as_activator(button, offset={'x':-10,'y':10})

        dialog_data_div = DivWdg()
        dialog_data_div.add_color("background", "background")
        dialog_data_div.add_style("padding", "20px")
        dialog.add(dialog_data_div)


        # Order folders by date
        name_div = DivWdg()
        dialog_data_div.add(name_div)
        name_div.add_style("margin: 15px 0px")

        if SearchType.column_exists(my.search_type, "relative_dir"):

            category_div = DivWdg()
            name_div.add(category_div)
            checkbox = RadioWdg("category")
            checkbox.set_option("value", "none")
            category_div.add(checkbox)
            category_div.add(" No categories")
            category_div.add_style("margin-bottom: 5px")
            checkbox.set_option("checked", "true")


            category_div = DivWdg()
            name_div.add(category_div)
            checkbox = RadioWdg("category")
            checkbox.set_option("value", "by_day")
            category_div.add(checkbox)
            category_div.add(" Categorize files by Day")
            category_div.add_style("margin-bottom: 5px")


            category_div = DivWdg()
            name_div.add(category_div)
            checkbox = RadioWdg("category")
            checkbox.set_option("value", "by_week")
            category_div.add(checkbox)
            category_div.add(" Categorize files by Week")
            category_div.add_style("margin-bottom: 5px")


            category_div = DivWdg()
            name_div.add(category_div)
            checkbox = RadioWdg("category")
            checkbox.set_option("value", "by_year")
            category_div.add(checkbox)
            category_div.add(" Categorize files by Year")
            category_div.add_style("margin-bottom: 5px")


            """
            checkbox = RadioWdg("category")
            checkbox.set_option("value", "custom")
            name_div.add(checkbox)
            name_div.add(" Custom")
            """

            name_div.add("<br/>")

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

        from tactic.ui.panel import EditWdg

        sobject = SearchType.create(my.search_type)
        edit = EditWdg(search_key =sobject.get_search_key(), mode='view', view=ingest_data_view )
        
        dialog_data_div.add(edit)
        hidden = HiddenWdg(name="parent_key")
        dialog_data_div.add(hidden)
        hidden.add_class("spt_parent_key")
        parent_key = my.kwargs.get("parent_key") or ""
        if parent_key:
            hidden.set_value(parent_key)


        extra_data = my.kwargs.get("extra_data")
        if not isinstance(extra_data, basestring):
            extra_data = jsondumps(extra_data)

        if extra_data and extra_data != "null":
            # it needs a TextArea instead of Hidden because of JSON data
            text = TextAreaWdg(name="extra_data")
            text.add_style('display: none')
            text.set_value(extra_data)
            dialog_data_div.add(text)

        """
 
        dialog_data_div.add("Keywords:<br/>")
        dialog.add(dialog_data_div)
        text = TextAreaWdg(name="keywords")
        dialog_data_div.add(text)
        text.add_class("spt_keywords")
        text.add_style("padding: 1px")


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

       
        text.add_class("spt_extra_data")
        text.add_style("padding: 1px")

        """

        #### TEST Image options
        """
        button = IconButtonWdg(title="Resize", icon=IconWdg.FILM)
        buttons.add_cell(button)

        dialog = DialogWdg(display="false", show_title=False)
        div.add(dialog)
        dialog.set_as_activator(button, offset={'x':-10,'y':10})

        try:
            from spt.tools.convert import ConvertOptionsWdg
            convert_div = DivWdg()
            dialog.add(convert_div)
            convert_div.add_style("padding: 20px")
            convert_div.add_color("background", "background")
            convert_div.add_class("spt_image_convert")

            convert = ConvertOptionsWdg()
            convert_div.add(convert)
        except:
            pass
        """


        # use base name for name
        """
        name_div = DivWdg()
        dialog_data_div.add(name_div)
        name_div.add_style("margin: 15px 0px")


        checkbox = CheckboxWdg("use_file_name")
        name_div.add(checkbox)
        name_div.add(" Use name of file for name")

        name_div.add("<br/>")

        checkbox = CheckboxWdg("use_base_name")
        name_div.add(checkbox)
        name_div.add(" Remove extension")


        name_div.add("<br/>")

        checkbox = CheckboxWdg("file_keywords")
        name_div.add(checkbox)
        name_div.add(" Use file name for keywords")
        """


        return div
Пример #6
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
Пример #7
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
Пример #8
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
Пример #9
0
    def handle_simple_mode(self, custom_table, mode):

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

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

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

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

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

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

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

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

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

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

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

            div.add(" &nbsp; ")

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

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

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

        custom_table.close_tbody()
Пример #10
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
Пример #11
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',
                             '($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
Пример #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
Пример #13
0
    def get_install_wdg(self, server_code, project_code):

        div = DivWdg()
        div.add_style("padding: 30px")
        div.add_style("margin: 10px")
        div.add_border()
        div.add_style("width: 300px")
        div.add_class("spt_sync_install_top")
        div.add_color("background", "background3")


        server = Search.get_by_code("sthpw/sync_server", server_code)
        if not server:
            div.add("No server [%s] exists in this installation" % server_code)
            return div

        if server.get_value("sync_mode") == "file":
            base_dir = server.get_value("base_dir")
        else:
            div.add("No base directory defined")
            return div


        if not os.path.exists(base_dir):
            div.add("Base Directory [%s] does not exist" % base_dir)
            return div



        dirnames = os.listdir(base_dir)
        templates_set = set()
        for dirname in dirnames:
            if dirname.endswith(".zip"):
                if dirname.find("_template-") != -1:
                    parts = dirname.split("_template-")
                    templates_set.add(parts[0])
                

        project_codes = list(templates_set)
        project_codes.sort()

        if not project_codes:
            div.add("There are no templates available.<br/><br/>")


        else:

            div.add("This will import a project template that has been dumped out.  The project cannot currently exist in the database.<br/><br/>")


            div.add("Available Templates: ")
            text_wdg = SelectWdg("server")
            text_wdg.set_option("values", project_codes)
            if project_code:
                text_wdg.set_value(project_code)
            text_wdg.add_class("spt_project")
            div.add(text_wdg)

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

            # This will create a project template dynamically and provide it for
            # download?
            button = ActionButtonWdg(title="Install")
            div.add(button)
            button.add_style("margin-left: auto")
            button.add_style("margin-right: auto")
            button.add_behavior( {
                'type': 'click_up',
                'server': server_code,
                'project_code': project_code,
                'cbjs_action': '''
                var top = bvr.src_el.getParent(".spt_sync_install_top");
                var text = top.getElement(".spt_project");
                var project_code = text.value ;

                spt.app_busy.show("Importing Project", "from remote server ["+bvr.server+"].");

                try {
                    var cmd = 'tactic.ui.sync.SyncRemoteProjectCmd';
                    var kwargs = {
                        'server': bvr.server,
                        'project_code': project_code
                    }
                    var server = TacticServerStub.get();
                    server.execute_cmd(cmd, kwargs);
                }
                catch(e) {
                    alert("Error importing project: " + e);
                }
                spt.app_busy.hide();
                '''
            } )

        return div
Пример #14
0
    def get_dump_wdg(self, server_code, project_code):

        div = DivWdg()
        div.add_style("padding: 30px")
        div.add_style("margin: 10px")
        div.add_border()
        div.add_style("width: 300px")
        div.add_class("spt_sync_dump_top")
        div.add_color("background", "background3")



        # Dump Project

        search = Search("sthpw/project")
        search.add_filters("code", ["admin","unittest"], op='not in')
        projects = search.get_sobjects()
        project_codes = [x.get_code() for x in projects]


        div.add("This will dump out the current state of the project and can be reimported back in on a remote server<br/><br/>")

        div.add("Project: ")
        text_wdg = SelectWdg("project_to_dump")
        text_wdg.add_empty_option("-- Select --")
        text_wdg.set_option("values", project_codes)
        if project_code:
            text_wdg.set_value(project_code)
        text_wdg.add_class("spt_project")
        div.add(text_wdg)

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


        button = ActionButtonWdg(title="Dump")
        div.add(button)
        button.add_style("margin-left: auto")
        button.add_style("margin-right: auto")
        button.add_behavior( {
            'type': 'click_up',
            'server': server_code,
            'project_code': project_code,
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_sync_dump_top");
            var text = top.getElement(".spt_project");
            var project_code = text.value;


            if (!project_code) {
                spt.alert("No project specified");
                return
            }

            spt.app_busy.show("Dumping "+project_code+" Project ...") ;

            var cmd = 'tactic.ui.sync.SyncCreateTemplateCmd';
            var server = TacticServerStub.get();

            var kwargs = {
                'server': bvr.server,
                'project_code': project_code
            }
            server.execute_cmd(cmd, kwargs);

            var top = bvr.src_el.getParent(".spt_sync_settings_top");
            spt.panel.refresh(top);

            spt.app_busy.hide();

            '''
        } )


        return div
Пример #15
0
    def get_display(self):

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

        div = self.top

        div.add("List of Saved Searches: ")
        div.add(HtmlElement.br(2))
        div.add_style("margin: 20px")
        div.add_style("width: 400px")
        div.add_class("spt_saved_search_top")
        
        try:
            search = Search("config/widget_config")
            search.add_op("begin")
            search.add_filter("view", 'saved_search:%', op="like")
            search.add_filter("category", 'search_filter')
            search.add_op("or")
            search.add_op("begin")
            search.add_user_filter()
            search.add_filter("login", "NULL", op="is", quoted=False)
            search.add_op("or")
            search.add_filter("search_type", search_type)
            configs = search.get_sobjects()
        except SearchException as e:
            print("WARNING: ", e)
            configs = []
        except:
            SearchWdg.clear_search_data(search_type)
            raise

        """
        from tactic.ui.panel import TableLayoutWdg
        element_names = ['view','name','description','delete']
        table = TableLayoutWdg(
                search_type=search_type,
                element_names=element_names,
                search=search,
                show_shelf=False,
                show_border=False,
                show_search_limit=False,
                height="auto",

        )
        div.add(table)
        """

        values = [x.get("view") for x in configs]
        labels = [x.get("title") or x.get("view") for x in configs]

        select = SelectWdg("saved_search")
        div.add(select)
        select.set_id("saved_search")
        select.add_class("spt_saved_search_input")
        select.add_empty_option("-- Select --")
        select.set_option("values", values)
        select.set_option("labels", labels)

        retrieve_button = ActionButtonWdg(title="Load")
        behavior = {
            'type':         'click',
            #'cbjs_action':  'spt.dg_table.retrieve_search_cbk(evt, bvr);'
            'cbjs_action':  '''
            var top = bvr.src_el.getParent(".spt_saved_search_top")
            var input = top.getElement(".spt_saved_search_input");
            var value = input.value;
            if (!value) {
                spt.alert("Please select a saved search to load.");
                return;
            }

            var popup = bvr.src_el.getParent(".spt_popup");
            var activator = popup.activator;
            var layout = activator.getElement(".spt_layout");
            spt.table.set_layout(layout);

            spt.table.load_search(value);
            '''
        }
        retrieve_button.add_behavior( behavior )
        retrieve_button.add_style("display: inline-block")


        remove_button = ActionButtonWdg(title="Remove")
        remove_button.add_behavior( {
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_saved_search_top")
            var input = top.getElement(".spt_saved_search_input");
            var value = input.value;
            if (!value) {
                spt.alert("Please select a saved search to remove.");
                return;
            }

            spt.alert("Remove: " + value);



            '''
        } )
        remove_button.add_style("display: inline-block")



        cancel_button = ActionButtonWdg(title="Cancel")
        cancel_button.add_behavior( {
            'cbjs_action': '''
            var popup = bvr.src_el.getParent(".spt_popup");
            spt.popup.close(popup);
            '''
        } )
        cancel_button.add_style("display: inline-block")

        div.add("<br/>")
        button_div = DivWdg()
        button_div.add_style("text-align: center")
        button_div.add(retrieve_button)
        button_div.add("&nbsp;&nbsp;")
        button_div.add(remove_button)
        button_div.add("&nbsp;&nbsp;")
        button_div.add(cancel_button)
        div.add(button_div)



        div.add("<hr/>")

        save_div = DivWdg()
        div.add(save_div)
        save_div.add("Save Current Search")
        save_div.add("<br/>")
        save_div.add("<br/>")

        text = TextInputWdg(name="new_search_name")
        save_div.add(text)
        text.add_class("spt_new_search_name")

        save_div.add("<br/>")


        save_button = ActionButtonWdg(title="Save Search", width="200")
        save_div.add(save_button)
        save_button.add_behavior( {
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_saved_search_top");
            var input = top.getElement(".spt_new_search_name");
            var value = input.value;
            if (!value) {
                spt.alert("No view name specified");
                return;
            }
            spt.table.save_search(value, {personal: true});

            spt.notify.show_message("Search saved");

            var popup = bvr.src_el.getParent(".spt_popup");
            spt.popup.close(popup);
            '''
        } )
        save_button.add_style("display: inline-block")

        return div
Пример #16
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
Пример #17
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
Пример #18
0
    def get_dump_wdg(my, server_code, project_code):

        div = DivWdg()
        div.add_style("padding: 30px")
        div.add_style("margin: 10px")
        div.add_border()
        div.add_style("width: 300px")
        div.add_class("spt_sync_dump_top")
        div.add_color("background", "background3")

        # Dump Project

        search = Search("sthpw/project")
        search.add_filters("code", ["admin", "unittest"], op='not in')
        projects = search.get_sobjects()
        project_codes = [x.get_code() for x in projects]

        div.add(
            "This will dump out the current state of the project and can be reimported back in on a remote server<br/><br/>"
        )

        div.add("Project: ")
        text_wdg = SelectWdg("project_to_dump")
        text_wdg.add_empty_option("-- Select --")
        text_wdg.set_option("values", project_codes)
        if project_code:
            text_wdg.set_value(project_code)
        text_wdg.add_class("spt_project")
        div.add(text_wdg)

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

        button = ActionButtonWdg(title="Dump")
        div.add(button)
        button.add_style("margin-left: auto")
        button.add_style("margin-right: auto")
        button.add_behavior({
            'type':
            'click_up',
            'server':
            server_code,
            'project_code':
            project_code,
            'cbjs_action':
            '''

            var top = bvr.src_el.getParent(".spt_sync_dump_top");
            var text = top.getElement(".spt_project");
            var project_code = text.value;


            if (!project_code) {
                spt.alert("No project specified");
                return
            }

            spt.app_busy.show("Dumping "+project_code+" Project ...") ;

            var cmd = 'tactic.ui.sync.SyncCreateTemplateCmd';
            var server = TacticServerStub.get();

            var kwargs = {
                'server': bvr.server,
                'project_code': project_code
            }
            server.execute_cmd(cmd, kwargs);

            var top = bvr.src_el.getParent(".spt_sync_settings_top");
            spt.panel.refresh(top);

            spt.app_busy.hide();

            '''
        })

        return div
Пример #19
0
    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
Пример #20
0
    def get_install_wdg(my, server_code, project_code):

        div = DivWdg()
        div.add_style("padding: 30px")
        div.add_style("margin: 10px")
        div.add_border()
        div.add_style("width: 300px")
        div.add_class("spt_sync_install_top")
        div.add_color("background", "background3")

        server = Search.get_by_code("sthpw/sync_server", server_code)
        if not server:
            div.add("No server [%s] exists in this installation" % server_code)
            return div

        if server.get_value("sync_mode") == "file":
            base_dir = server.get_value("base_dir")
        else:
            div.add("No base directory defined")
            return div

        if not os.path.exists(base_dir):
            div.add("Base Directory [%s] does not exist" % base_dir)
            return div

        dirnames = os.listdir(base_dir)
        templates_set = set()
        for dirname in dirnames:
            if dirname.endswith(".zip"):
                if dirname.find("_template-") != -1:
                    parts = dirname.split("_template-")
                    templates_set.add(parts[0])

        project_codes = list(templates_set)
        project_codes.sort()

        if not project_codes:
            div.add("There are no templates available.<br/><br/>")

        else:

            div.add(
                "This will import a project template that has been dumped out.  The project cannot currently exist in the database.<br/><br/>"
            )

            div.add("Available Templates: ")
            text_wdg = SelectWdg("server")
            text_wdg.set_option("values", project_codes)
            if project_code:
                text_wdg.set_value(project_code)
            text_wdg.add_class("spt_project")
            div.add(text_wdg)

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

            # This will create a project template dynamically and provide it for
            # download?
            button = ActionButtonWdg(title="Install")
            div.add(button)
            button.add_style("margin-left: auto")
            button.add_style("margin-right: auto")
            button.add_behavior({
                'type':
                'click_up',
                'server':
                server_code,
                'project_code':
                project_code,
                'cbjs_action':
                '''
                var top = bvr.src_el.getParent(".spt_sync_install_top");
                var text = top.getElement(".spt_project");
                var project_code = text.value ;

                spt.app_busy.show("Importing Project", "from remote server ["+bvr.server+"].");

                try {
                    var cmd = 'tactic.ui.sync.SyncRemoteProjectCmd';
                    var kwargs = {
                        'server': bvr.server,
                        'project_code': project_code
                    }
                    var server = TacticServerStub.get();
                    server.execute_cmd(cmd, kwargs);
                }
                catch(e) {
                    alert("Error importing project: " + e);
                }
                spt.app_busy.hide();
                '''
            })

        return div
Пример #21
0
    def handle_simple_mode(my, custom_table, mode):

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


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


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

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


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



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



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




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

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


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

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

            div.add(" &nbsp; ")

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

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






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

        custom_table.close_tbody()
Пример #22
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
Пример #23
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
Пример #24
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