Example #1
0
    def get_display(my):

        top = my.top

        if not HelpWdg.exists():
            return top

        alias = my.kwargs.get("alias")
        description = my.kwargs.get("description")
        if not description:
            description = "Show Help"

        if my.kwargs.get("use_icon"):
            #help_button = SingleButtonWdg(title='Help', icon=IconWdg.HELP_BUTTON, show_arrow=False)
            help_button = IconButtonWdg(title='Help', icon=IconWdg.HELP_BUTTON, show_arrow=False)
        else:
            help_button = ActionButtonWdg(title="?", tip=description, size='small')
        top.add(help_button)

        if not my.cbjs_action:
            my.cbjs_action = '''
            spt.help.set_top();
            spt.help.load_alias(bvr.alias);
            '''

            help_button.add_behavior( {
                'type': 'click_up',
                'alias': alias,
                'cbjs_action': my.cbjs_action
            } )


        return top
Example #2
0
    def get_section_wdg(my, title, description, image, behavior):

        section_wdg = DivWdg()
        section_wdg.set_round_corners()
        section_wdg.add_border()
        section_wdg.add_class("spt_report_top")
        section_wdg.add_style("width: 200px")
        section_wdg.add_style("height: 100px")
        section_wdg.add_style("overflow: hidden")
        section_wdg.add_style("margin: 10px")
        section_wdg.set_box_shadow("0px 0px 10px")

        title_wdg = DivWdg()
        section_wdg.add(title_wdg)
        title_wdg.add(title)
        title_wdg.add_style("height: 20px")
        title_wdg.add_style("padding: 3px")
        title_wdg.add_style("margin-top: 3px")
        title_wdg.add_style("font-weight: bold")
        title_wdg.add_gradient("background", "background")


        button = IconButtonWdg(title="Options", icon=IconWdg.ARROWHEAD_DARK_DOWN)
        title_wdg.add(button)
        button.add_style("float: right")

        # set up menus
        menu = my.get_menu()
        SmartMenu.add_smart_menu_set( button, { 'MENU_ITEM': menu } )
        SmartMenu.assign_as_local_activator( button, "MENU_ITEM", True )


        section_wdg.add_color("background", "background")
        #section_wdg.add_gradient("background", "background", 0, -3)
        section_wdg.add_behavior( {
        'type': 'hover',
        'add_color_modifier': -5,
        'cb_set_prefix': 'spt.mouse.table_layout_hover',
        } )

        desc_div = DivWdg()
        desc_div.add(description)
        desc_div.add_style("padding: 5px 10px 10px 5px")


        div = DivWdg()
        section_wdg.add(div)
        div.add_style("padding: 3px")
        div.add_style("margin: 5px")
        div.add_style("width: 65px")
        div.add_style("height: 50px")
        div.add_style("float: left")
        div.add(image)
        section_wdg.add(desc_div)
        div.add_style("overflow: hidden")

        section_wdg.add_behavior( behavior )
        section_wdg.add_class("hand")

        return section_wdg
Example #3
0
    def get_display(my):

        sobject = my.get_current_sobject()

        my.search_key = SearchKey.get_by_sobject(sobject)
    
        div = DivWdg()
        div.add_class("hand")

        title = "Show Item Details"
        if my.widget:
            widget = my.widget
        else:
            widget = IconButtonWdg(title=title, icon=IconWdg.ZOOM)


        code = sobject.get_code()
        name = sobject.get_value("name", no_exception=True)
        if not name:
            name = code


        widget.add_behavior( {
        'type': 'click_up',
        'search_key': my.search_key,
        'code': code,
        'name': name,
        'cbjs_action': '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.tools.TaskDetailPanelWdg';
        var kwargs = {
            search_key: bvr.search_key,
        };

        var mode = '';
        var layout = bvr.src_el.getParent(".spt_tool_top");
        if (layout != null) {
            mode = 'tool'
        }

        if (mode == 'tool') {
            spt.app_busy.show("Loading ...");
            var layout = bvr.src_el.getParent(".spt_tool_top");
            var element = layout.getElement(".spt_tool_content");
            spt.panel.load(element, class_name, kwargs);
            spt.app_busy.hide();
        }
        else {
            var element_name = "detail_"+bvr.code;
            var title = "Detail ["+bvr.name+"]";
            spt.tab.add_new(element_name, title, class_name, kwargs);
        }
        '''
        } )


        div.add(widget)

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

        # create the gear menu
        btn_dd = self.btn_dd
        """
        btn_dd.add_styles("width: 36px; height: 18px; padding: none; padding-top: 1px;")

        btn_dd.add( "<img src='/context/icons/common/transparent_pixel.gif' alt='' " \
                    "title='TACTIC Actions Menu' class='tactic_tip' " \
                    "style='text-decoration: none; padding: none; margin: none; width: 4px;' />" )
        btn_dd.add( "<img src='/context/icons/silk/cog.png' alt='' " \
                    "title='TACTIC Actions Menu' class='tactic_tip' " \
                    "style='text-decoration: none; padding: none; margin: none;' />" )
        btn_dd.add( "<img src='/context/icons/silk/bullet_arrow_down.png' alt='' " \
                    "title='TACTIC Actions Menu' class='tactic_tip' " \
                    "style='text-decoration: none; padding: none; margin: none;' />" )

        btn_dd.add_behavior( { 'type': 'hover',
                    'mod_styles': 'background-image: url(/context/icons/common/gear_menu_btn_bkg_hilite.png); ' \
                                    'background-repeat: no-repeat;' } )



        """

        from pyasm.widget import IconWdg
        from tactic.ui.widget import IconButtonWdg
        icon = IconButtonWdg(name="Settings", icon="BS_COG", show_arrow="true")
        btn_dd.add(icon)

        smenu_set = SmartMenu.add_smart_menu_set(
            btn_dd, {'DG_TABLE_GEAR_MENU': self.menus})
        SmartMenu.assign_as_local_activator(btn_dd, "DG_TABLE_GEAR_MENU", True)
        return btn_dd
Example #5
0
    def get_filter_wdg(self, filter_name):

        if not filter_name:
            filter_name = self.get_name()

        from pyasm.web import DivWdg
        from tactic.ui.widget import IconButtonWdg
        filter_wdg = DivWdg()
        button = IconButtonWdg(title="Show Filter", icon="BS_SEARCH")
        filter_wdg.add_class("spt_filter_button")

        filter_wdg.add(button)
        filter_wdg.add_style("display: inline-block")
        filter_wdg.add_style("vertical-align: middle")
        filter_wdg.add_style("opacity: 0.5")

        filter_wdg.add_attr("spt_filter_name", filter_name)
        filter_wdg.add_behavior({
            'type':
            'click',
            'cbjs_action':
            '''
            var panel = bvr.src_el.getParent(".spt_view_panel_top");
            var th = bvr.src_el.getParent("th");
            var pos = th.getPosition(panel);

            var name = bvr.src_el.getAttribute("spt_filter_name");

            if (! spt.simple_search.has_element(name) ) {
                return;
            }

            pos.y += 35;


            spt.simple_search.show_elements([name]);
            spt.simple_search.set_position(pos);
            spt.simple_search.hide_title();
            spt.simple_search.show();

            var top = spt.simple_search.get_top();
            var size = top.getSize();
            var cur_pos = top.getPosition( $(document.body) );
            var window_size = $(document.body).getSize();
            if (cur_pos.x + size.x > window_size.x) {
                var panel_size = panel.getSize();
                pos.x = panel_size.x - size.x;
                spt.simple_search.set_position(pos);
            }

            '''
        })

        return filter_wdg
Example #6
0
    def get_display(my):

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

        top = my.top
        top.add_class("spt_dialog")
        button = IconButtonWdg(title='Add to Collection',
                               icon="BS_TH_LARGE",
                               show_arrow=True)
        top.add(button)

        detail_wdg = DivWdg()
        top.add(detail_wdg)

        dialog = DialogWdg()
        top.add(dialog)

        dialog.set_as_activator(button, offset={'x': -25, 'y': 0})
        dialog.add_title("Collections")

        dialog_content = CollectionAddDialogWdg(search_type=search_type)
        dialog.add(dialog_content)

        return top
Example #7
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
Example #8
0
    def get_display(my):

        sobject = my.get_current_sobject()

        use_parent = my.get_option("use_parent")
        use_parent = use_parent in ['true', True]
        #if use_parent in ['true', True]:
        #    sobject = sobject.get_parent()
        #    if not sobject:
        #        return DivWdg()

        my.search_key = SearchKey.get_by_sobject(sobject)
    
        div = DivWdg()
        div.add_class("hand")
        #div.add_style("width: 100%")
        #div.add_style("height: 100%")

        target_id = "main_body"

        title = "Show Item Details"
        if my.widget:
            widget = my.widget
        else:
            widget = IconButtonWdg(title=title, icon=IconWdg.ZOOM)


        code = sobject.get_code()
        name = sobject.get_value("name", no_exception=True)
        if not name:
            name = code


        tab_element_names = my.kwargs.get("tab_element_names") or ""
        detail_view = my.kwargs.get("detail_view") or ""

        widget.add_behavior( {
        'type': 'click_up',
        'search_key': my.search_key,
        'use_parent': use_parent,
        'tab_element_names': tab_element_names,
        'detail_view': detail_view,
        'show_task_process': my.show_task_process,
        'code': code,
        'name': name,
        'cbjs_action': '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.tools.SObjectDetailWdg';
        var kwargs = {
            search_key: bvr.search_key,
            use_parent: bvr.use_parent,
            tab_element_names: bvr.tab_element_names,
            show_task_process: bvr.show_task_process,
            detail_view: bvr.detail_view
        };

        var mode = 'xxx';
        var layout = bvr.src_el.getParent(".spt_tool_top");
        if (layout != null) {
            mode = 'tool'
        }

        if (mode == 'tool') {
            spt.app_busy.show("Loading ...");
            var layout = bvr.src_el.getParent(".spt_tool_top");
            var element = layout.getElement(".spt_tool_content");
            spt.panel.load(element, class_name, kwargs);
            spt.app_busy.hide();
        }
        else {
            var element_name = "detail_"+bvr.code;
            var title = "Detail ["+bvr.name+"]";
            spt.tab.add_new(element_name, title, class_name, kwargs);
        }
        '''
        } )


        #link_wdg = my.get_link_wdg(target_id, title, widget)
        #div.add( link_wdg )
        div.add(widget)

        return div
Example #9
0
    def get_category_wdg(my, category, mode="new"):

        subscriptions = my.get_subscriptions(category, mode)
        if not subscriptions:
            return

        div = DivWdg()
        div.add_style("width: 100%")

        title_div = DivWdg()
        div.add(title_div)
        title_div.add_style("padding: 10px")
        title_div.add_border()
        title_div.add_color("background", "background3")
        title = category or "Subscriptions"
        title_div.add("%s " % title)
        

        summary_div = SpanWdg()
        title_div.add(summary_div)
        summary_div.add_style("font-size: 0.8em")
        summary_div.add_style("opacity: 0.5")


        search_keys = [x.get_search_key() for x in subscriptions]
        button = ActionButtonWdg(title="Clear All")
        div.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'search_keys': search_keys,
            'cbjs_action': '''
            var server = TacticServerStub.get();
            for (var i = 0; i < bvr.search_keys.length; i++) {
                var search_key = bvr.search_keys[i];
                server.update(search_key, {'last_cleared':'NOW'});
            spt.panel.refresh(bvr.src_el);
            }
            '''
        } )



        # types of subscriptions

        table = Table()
        table.add_style('width: 100%')
        table.add_border()
        table.add_color("background", "background3")


        div.add(table)
        ss = []
        for subscription in subscriptions:
            table.add_row()
            td = table.add_cell()

            message_code = subscription.get_value("message_code")

            search = Search("sthpw/message")
            search.add_filter("code", message_code)
            message = search.get_sobject()

            # show the thumb
            if not message:
                if mode == "all":
                    td = table.add_cell(FormatMessageWdg.get_preview_wdg(subscription))

                    td = table.add_cell()
                    td.add("No Messages")
                continue

            size = 60

            msg_element = FormatMessageWdg(subscription=subscription, short_format='true')
            # this is optional
            msg_element.set_sobject(message)
            description = msg_element.get_buffer_display() 
          
            #td = table.add_cell()
            history_icon = IconButtonWdg(title="Subscription History", icon=IconWdg.HISTORY)
            #td.add(icon)
            message_code = subscription.get_value("message_code")
            history_icon.add_behavior( {
                'type': 'click_up',
                'message_code': message_code,
                'cbjs_action': '''
                var class_name = 'tactic.ui.panel.FastTableLayoutWdg';
                var message_code = bvr.message_code;
                var kwargs = {
                    search_type: 'sthpw/message_log',
                    show_shelf: false,
                    expression: "@SOBJECT(sthpw/message_log['message_code','"+message_code+"'])",
                    view: 'history'
                };
                spt.tab.set_main_body_tab();
                spt.tab.add_new("Message History", "Message History", class_name, kwargs);
                '''
            } )
 

            # description can take up 70%
            td = table.add_cell()
            td.add_style("width: %spx"%(SubscriptionBarWdg.WIDTH*0.7))

            desc_div = DivWdg()
            td.add(desc_div)
            desc_div.add(description)
            desc_div.add_style("padding: 0px 20px")

            td = table.add_cell()
            #td.add(message.get_value("status"))
            #td = table.add_cell()
            timestamp = message.get_datetime_value("timestamp")
            if timestamp:
                timestamp_str = timestamp.strftime("%b %d, %Y - %H:%M")
            else:
                timestamp_str = ""
            td.add(timestamp_str)

            #td = table.add_cell()
            #td.add(subscription.get_value("last_cleared"))

            td = table.add_cell()
            td.add(history_icon)
            td.add(HtmlElement.br(2))
            td.add_style('width: 30px')
            icon = IconButtonWdg(title="Unsubscribe", icon=IconWdg.DELETE)
            td.add(icon)
            subscription_key = subscription.get_search_key()
            icon.add_behavior( {
                'type': 'click_up',
                'search_key': subscription_key,
                'message_code': message_code,
                'cbjs_action': '''
                    if (!confirm("Unsubscribe from [" + bvr.message_code + "]?")) {
                        return;
                    }
                    var top = bvr.src_el.getParent(".spt_subscription_top");
                    var server = TacticServerStub.get();
                    server.delete_sobject(bvr.search_key);
                    spt.panel.refresh(top);
                '''
            } )






            ss.append(subscription)

        num_sobjects = len(ss)
        if not num_sobjects:
            return None
        summary_div.add("(%s changes)" % num_sobjects)

        #from tactic.ui.panel import FastTableLayoutWdg
        #table = FastTableLayoutWdg(search_type="sthpw/subscription",show_shelf=False)
        #div.add(table)
        #table.set_sobjects(ss)


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

        top = DivWdg()
        top.add_border()
        top.add_style("padding: 10px")
        top.add_color("color", "color")
        top.add_gradient("background", "background", 0, -5)
        #top.add_style("height: 550px")

        top.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
            spt.named_events.fire_event("side_bar|hide_now", {} );
            '''
        })

        project = Project.get()
        title = DivWdg()
        title.add("Project Startup and Configuration")
        title.add_style("font-size: 18px")
        title.add_style("font-weight: bold")
        title.add_style("text-align: center")
        title.add_style("padding: 10px")
        title.add_style("margin: -10px -10px 10px -10px")

        top.add(title)
        title.add_gradient("background", "background3", 5, -10)

        shelf = DivWdg()
        top.add(shelf)
        shelf.add_style("margin-left: -8px")
        shelf.add_style("width: 130px")

        button_div = DivWdg()
        shelf.add(button_div)
        button_div.add_style("float: left")
        button_div.add_style("margin-top: -3px")

        security = Environment.get_security()
        view_side_bar = security.check_access("builtin",
                                              "view_side_bar",
                                              "allow",
                                              default='allow')
        if view_side_bar:
            button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT)
            button_div.add(button)
            shelf.add("Toggle Side Bar")
            shelf.add_attr("title", "Toggle Side Bar (or press '1')")
            button.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                spt.named_events.fire_event("side_bar|toggle");
                '''
            })
            shelf.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                spt.named_events.fire_event("side_bar|toggle");
                '''
            })
            shelf.add_class("hand")
        else:
            shelf.add("&nbsp;")

        search_wdg = Table()
        top.add(search_wdg)
        search_wdg.add_row()

        search_wdg.add_class("spt_main_top")
        search_wdg.add_style("padding: 10px")
        search_wdg.add_style("margin: 20px auto")
        search_wdg.add_style("width: 430px")

        td = search_wdg.add_cell("Search: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 8px")

        custom_cbk = {}
        custom_cbk['enter'] = '''
            var top = bvr.src_el.getParent(".spt_main_top");
            var search_el = top.getElement(".spt_main_search");
            var keywords = search_el.value;

            if (keywords != '') {
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    'search_type': 'sthpw/sobject_list',
                    'view': 'result_list',
                    'keywords': keywords,
                    'simple_search_view': 'simple_filter',
                    //'show_shelf': false,
                }
                spt.tab.set_main_body_tab();
                spt.tab.add_new("Search Results", "Search Results", class_name, kwargs);
            }
        '''

        from tactic.ui.input import TextInputWdg, LookAheadTextInputWdg
        #text = TextInputWdg(name="search")
        text = LookAheadTextInputWdg(name="search",
                                     custom_cbk=custom_cbk,
                                     width='280',
                                     height='42px')
        #text = TextWdg("search")
        text.add_class("spt_main_search")
        text.add_style("width: 290px")

        search_wdg.add_cell(text)
        search_wdg.add_style("font-weight: bold")
        search_wdg.add_style("font-size: 16px")

        icon_div = DivWdg()
        td = search_wdg.add_cell(icon_div)
        td.add_style("vertical-align: top")
        icon_div.add_style("width: 38px")
        icon_div.add_style("height: 27px")
        icon_div.add_style("padding-top: 7px")
        icon_div.add_style("padding-left: 4px")
        icon_div.add_style("text-align: center")
        #icon_div.add_gradient("background", "background3", 15, -10)
        icon_div.add_color("background", "background3", 10)
        over_color = icon_div.get_color("background3", 0)
        out_color = icon_div.get_color("background3", 10)
        icon_div.set_round_corners(5)
        icon_div.set_box_shadow("1px 1px 1px 1px")
        icon = IconWdg("Search", IconWdg.SEARCH_32, width=24)
        icon_div.add(icon)
        button = icon_div
        icon_div.add_class("hand")
        icon_div.add_behavior({
            'type':
            'mouseover',
            'color':
            over_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("background", bvr.color);
            '''
        })
        icon_div.add_behavior({
            'type':
            'mouseout',
            'color':
            out_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("background", bvr.color);
            bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-5");
            bvr.src_el.setStyle("margin-right", "0");
            '''
        })
        icon_div.add_behavior({
            'type':
            'click',
            'color':
            out_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("box-shadow", "0px 0px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-3");
            bvr.src_el.setStyle("margin-right", "-2");
            '''
        })
        icon_div.add_behavior({
            'type':
            'click_up',
            'color':
            out_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-5");
            bvr.src_el.setStyle("margin-right", "0");
            '''
        })

        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_main_top");
            var search_el = top.getElement(".spt_main_search");
            var keywords = search_el.value;

            if (keywords == '') {
                return;
            }

            var class_name = 'tactic.ui.panel.ViewPanelWdg';
            var kwargs = {
                'search_type': 'sthpw/sobject_list',
                'view': 'result_list',
                'keywords': keywords,
                'simple_search_view': 'simple_filter',
                //'show_shelf': false,
            }
            spt.tab.set_main_body_tab();
            spt.tab.add_new("Search Results", "Search Results", class_name, kwargs);
            '''
        })

        #desc = DivWdg()
        #top.add(desc)
        #desc.add("Dashboard")
        #desc.add_style("width: 600px")

        # create a bunch of panels
        table = Table()
        table.add_color("color", "color")
        table.add_style("margin-bottom: 20px")
        table.center()
        top.add(table)
        table.add_row()

        #security = Environment.get_security()
        #if not security.check_access("builtin", "view_site_admin", "allow"):

        td = table.add_cell()
        td.add_style("padding: 3px")
        td.add_style("vertical-align: top")
        title = "Configuration"
        #description = '''All TACTIC projects can be uniquely designed and managed using our configuration tools.'''
        description = '''Configure a Project from start to finish.'''
        image = "<img src='/context/icons/64x64/configuration_64.png'/>"
        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.tab.set_main_body_tab();
            var class_name = 'tactic.ui.startup.ProjectConfigWdg';
            var kwargs = {
                help_alias: 'project-startup-configuration'
                };
            spt.tab.add_new("project_configuration", "Configuration", class_name, kwargs);
            '''
        }
        config_wdg = self.get_main_section_wdg(title, description, image,
                                               behavior)
        td.add(config_wdg)

        # Manage Users
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "Manage Users and Security"
        image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        image = DivWdg()
        image_link = "<div style='margin-bottom: -64px'><img src='/context/icons/64x64/lock_64.png'/></div>"
        image.add(image_link)

        image1 = IconWdg("Manage Users", IconWdg.USER_32)
        image2 = IconWdg("Manage Users", IconWdg.USER_32)
        image3 = IconWdg("Manage Users", IconWdg.USER_32)
        image4 = IconWdg("Manage Users", IconWdg.USER_32)
        image.add(image1)
        image.add(image2)
        image.add("<br/>")
        image.add(image3)
        image.add(image4)
        description = '''Manage users that can access the system'''

        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.startup.UserConfigWdg';
        var kwargs = {
            help_alias: 'project-startup-manage-users'
            };
        spt.tab.add_new("manage_user", "Manage Users", class_name, kwargs);
        '''
        }
        manage_users_wdg = self.get_main_section_wdg(title, description, image,
                                                     behavior)
        td.add(manage_users_wdg)

        # custom layout editor
        td = table.add_cell()
        td.add_style("padding: 3px")
        td.add_style("vertical-align: top")
        title = "Custom Layouts"
        description = '''Create interfaces using the Custom Layout Editor.'''
        image = "<img src='/context/icons/64x64/layout_64.png'/>"
        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.tab.set_main_body_tab();
            var class_name = 'tactic.ui.tools.CustomLayoutEditWdg';
            var kwargs = {
                help_alias: 'project-startup-configuration'
                };
            spt.tab.add_new("custom_layout_editor", "Custom Layout Editor", class_name, kwargs);
            '''
        }
        config_wdg = self.get_main_section_wdg(title, description, image,
                                               behavior)
        td.add(config_wdg)

        tr = table.add_row()

        # Plugins
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "Manage Plugins"
        image = IconWdg("Manage Plugins", IconWdg.PLUGIN_32)
        #image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''Upload, install, remove and create TACTIC plugins.'''

        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''
        var class_name = 'tactic.ui.app.PluginWdg';
        spt.tab.set_main_body_tab();
        spt.tab.add_new("plugins", "Manage Plugin", class_name, kwargs);
        '''
        }
        plugin_wdg = self.get_small_section_wdg(title, description, image,
                                                behavior)
        td.add(plugin_wdg)

        # Examples
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "Tools"
        image = IconWdg("Tools", IconWdg.SHARE_32)
        #image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''A collection of example views.'''

        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''
        var class_name = 'tactic.ui.startup.ToolsWdg';
        spt.tab.set_main_body_tab();
        spt.tab.add_new("tools", "Tools", class_name, kwargs);
        '''
        }
        share_wdg = self.get_small_section_wdg(title, description, image,
                                               behavior)
        td.add(share_wdg)

        # Share
        """
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "Shares"
        image = IconWdg("Shares", IconWdg.SHARE_32)
        #image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''Share project with other TACTIC installs.'''

        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        var class_name = 'tactic.ui.startup.ShareWdg';
        spt.tab.set_main_body_tab();
        spt.tab.add_new("shares", "Shares", class_name, kwargs);
        '''
        }
        share_wdg = self.get_small_section_wdg(title, description, image, behavior)
        td.add(share_wdg)
        """

        # Advanced
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "Advanced Setup"
        image = IconWdg("Advanced", IconWdg.ADVANCED_32)
        #image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''A set of advanced configuration tools.'''

        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''
        var class_name = 'tactic.ui.app.ProjectStartWdg';
        spt.tab.set_main_body_tab()
        spt.tab.add_new("project_setup", "Project Setup", class_name)
        '''
        }
        share_wdg = self.get_small_section_wdg(title, description, image,
                                               behavior)
        td.add(share_wdg)
        """
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
	title = "Documentation"

        description = '''TACTIC Documentation.
        * Project Setup Documentation<br/>
        <br/>
        * End User Documentation<br/>
        <br/>
        * Developer Documentation<br/>
        <br/>
        * System Administrator Documentation<br/>
        <br/>
        '''
        image = "<img src='/context/images/getting_started_pipeline.png'/>"
        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        spt.help.load_alias("main")
        '''
        }
        doc_wdg = self.get_section_wdg(title, description, image, behavior)
        td.add(doc_wdg)
        """

        tr, td = table.add_row_cell()
        td.add_style("font-size: 14px")
        td.add("<br/>")

        from misc_wdg import QuickLinksWdg
        quick_links_wdg = QuickLinksWdg()
        td.add(quick_links_wdg)

        #td = table.add_cell()
        #totals_wdg = self.get_totals_wdg()
        #td.add(totals_wdg)

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

        web = WebContainer.get_web()
        show_multi_project = web.get_form_value('show_multi_project')
        project = Project.get()
        search_type_objs = project.get_search_types(include_multi_project=show_multi_project)


        top = my.top
        top.add_class("spt_panel_stype_list_top")
        #top.add_style("min-width: 400px")
        #top.add_style("max-width: 1000px")
        #top.add_style("width: 100%")
        top.center()



        button = SingleButtonWdg(title="Advanced Setup", icon=IconWdg.ADVANCED)
        top.add(button)
        button.add_style("float: right")
        button.add_style("margin-top: -8px")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var class_name = 'tactic.ui.app.ProjectStartWdg';
            spt.tab.set_main_body_tab()
            spt.tab.add_new("project_setup", "Project Setup", class_name)
            '''
        } )


        button = SingleButtonWdg(title="Add", tip="Add New Searchable Type (sType)", icon=IconWdg.ADD)
        top.add(button)
        button.add_style("float: left")
        button.add_style("margin-top: -8px")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var class_name = 'tactic.ui.app.SearchTypeCreatorWdg';

            var kwargs = {
            };
            var popup = spt.panel.load_popup("Create New Searchable Type", class_name, kwargs);

            var top = bvr.src_el.getParent(".spt_panel_stype_list_top");
            popup.on_register_cbk = function() {
                spt.panel.refresh(top);
            }

            '''
        } )

        cb = CheckboxWdg('show_multi_project', label=' show multi-project')
        if show_multi_project:
            cb.set_checked()
        cb.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
                var panel = bvr.src_el.getParent('.spt_panel_stype_list_top')
                spt.panel.refresh(panel, {show_multi_project: bvr.src_el.checked});
            '''
            })
        span = SpanWdg(css='small')
        top.add(span)
        top.add(cb)
        top.add("<br clear='all'/>")
        #search_type_objs = []
        if not search_type_objs:
            arrow_div = DivWdg()
            top.add(arrow_div)
            icon = IconWdg("Click to Add", IconWdg.ARROW_UP_LEFT_32)
            icon.add_style("margin-top: -20")
            icon.add_style("margin-left: -15")
            icon.add_style("position: absolute")
            arrow_div.add(icon)
            arrow_div.add("&nbsp;"*5)
            arrow_div.add("<b>Click to Add</b>")
            arrow_div.add_style("position: relative")
            arrow_div.add_style("margin-top: 5px")
            arrow_div.add_style("margin-left: 20px")
            arrow_div.add_style("float: left")
            arrow_div.add_style("padding: 25px")
            arrow_div.set_box_shadow("0px 5px 20px")
            arrow_div.set_round_corners(30)
            arrow_div.add_color("background", "background")

            div = DivWdg()
            top.add(div)
            div.add_border()
            div.add_style("min-height: 180px")
            div.add_style("width: 600px")
            div.add_style("margin: 30px auto")
            div.add_style("padding: 20px")
            div.add_color("background", "background3")
            icon = IconWdg( "WARNING", IconWdg.WARNING )
            div.add(icon)
            div.add("<b>No Searchable Types have been created</b>")
            div.add("<br/><br/>")
            div.add("Searchables Types contain lists of items that are managed in this project.  Each item will automatically have the ability to have files checked into it, track tasks and status and record work hours.")
            div.add("<br/>"*2)
            div.add("For more information, read the help docs: ")
            from tactic.ui.app import HelpButtonWdg
            help = HelpButtonWdg(alias="main")
            div.add(help)
            div.add("<br/>")
            div.add("Click on the 'Add' button above to start adding new types.")
            return top


        div = DivWdg()
        top.add(div)
        #div.add_style("max-height: 300px")
        #div.add_style("overflow-y: auto")



        table = Table()
        div.add(table)
        table.add_style("margin-top: 10px")
        table.set_max_width()



        # group mouse over
        table.add_relay_behavior( {
            'type': "mouseover",
            'bvr_match_class': 'spt_row',
            'cbjs_action': "spt.mouse.table_layout_hover_over({}, {src_el: bvr.src_el, add_color_modifier: -2})"
        } )
        table.add_relay_behavior( {
            'type': "mouseout",
            'bvr_match_class': 'spt_row',
            'cbjs_action': "spt.mouse.table_layout_hover_out({}, {src_el: bvr.src_el})"
        } )



        tr = table.add_row()
        tr.add_color("color", "color")
        tr.add_gradient("background", "background", -10)
        th = table.add_header("")
        th.add_style("text-align: left")
        th = table.add_header("Title")
        th.add_style("text-align: left")
        th = table.add_header("# Items")
        th.add_style("text-align: left")
        th = table.add_header("View")
        th.add_style("text-align: left")
        th = table.add_header("Add")
        th.add_style("text-align: left")
        th = table.add_header("Import")
        th.add_style("text-align: left")
        th = table.add_header("Custom Columns")
        th.add_style("text-align: left")
        th = table.add_header("Workflow")
        th.add_style("text-align: left")
        th = table.add_header("Notifications")
        th.add_style("text-align: left")
        th = table.add_header("Triggers")
        th.add_style("text-align: left")
        th = table.add_header("Edit")
        th.add_style("text-align: left")
        #th = table.add_header("Security")
        #th.add_style("text-align: left")



        for i, search_type_obj in enumerate(search_type_objs):
            tr = table.add_row()
            tr.add_class("spt_row")

            if not i or not i%2:
                tr.add_color("background", "background3")
            else:
                tr.add_color("background", "background", -2 )


            thumb = ThumbWdg()
            thumb.set_sobject(search_type_obj)
            thumb.set_icon_size(30)
            td = table.add_cell(thumb)



            search_type = search_type_obj.get_value("search_type")
            title = search_type_obj.get_title()

            table.add_cell(title)

            try:
                search = Search(search_type)
                count = search.get_count()
                if count:
                    table.add_cell("%s item/s" % count)
                else:
                    table.add_cell("&nbsp;")
            except:
                td = table.add_cell("&lt; No table &gt;")
                td.add_style("font-style: italic")
                td.add_style("color: #F00")
                continue



            #search = Search(search_type)
            #search.add_interval_filter("timestamp", "today")
            #created_today = search.get_count()
            #table.add_cell(created_today)



            td = table.add_cell()
            button = IconButtonWdg(title="View", icon=IconWdg.ZOOM)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'title': title,
                'cbjs_action': '''

                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                    view: 'table',
                    'simple_search_view': 'simple_search'
                };

                // use tab
                var top = bvr.src_el.getParent(".spt_dashboard_top");
                spt.tab.set_tab_top(top);
                spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs);
                //spt.panel.load_popup(bvr.title, class_name, kwargs);

                '''
            } )
            button.add_style("float: left")


            arrow_button = IconButtonWdg(tip="More Views", icon=IconWdg.ARROWHEAD_DARK_DOWN)
            arrow_button.add_style("margin-left: 20px")
            td.add(arrow_button)

            cbk = '''
            var activator = spt.smenu.get_activator(bvr);

            var class_name = bvr.class_name;
            var layout = bvr.layout;

            var kwargs = {
                search_type: bvr.search_type,
                layout: layout,
                view: bvr.view,
                simple_search_view: 'simple_search',
                element_names: bvr.element_names,
            };

            // use tab
            var top = activator.getParent(".spt_dashboard_top");
            spt.tab.set_tab_top(top);
            spt.tab.add_new('%s', '%s', class_name, kwargs);
            ''' % (title, title)


            from tactic.ui.panel import SwitchLayoutMenu
            SwitchLayoutMenu(search_type=search_type, activator=arrow_button, cbk=cbk, is_refresh=False)

            td = table.add_cell()
            button = IconButtonWdg(title="Add", icon=IconWdg.ADD)
            td.add(button)
            button.add_behavior( {
                'type': 'listen',
                'search_type': search_type,
                'event_name': 'startup_save:' + search_type_obj.get_title(),
                'title': search_type_obj.get_title(),
                'cbjs_action': '''
                var top = bvr.src_el.getParent(".spt_dashboard_top");
                spt.tab.set_tab_top(top);
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                    view: 'table',
                    'simple_search_view': 'simple_search'
                };

                spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs);
 

                '''
            } )
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'title': search_type_obj.get_title(),
                'cbjs_action': '''

                var top = bvr.src_el.getParent(".spt_dashboard_top");
                spt.tab.set_tab_top(top);

                var class_name = 'tactic.ui.panel.EditWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                    view: "insert",
                    save_event: "startup_save:" + bvr.title
                }
                spt.panel.load_popup("Add New Items ("+bvr.title+")", class_name, kwargs);

                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                    view: 'table',
                    'simple_search_view': 'simple_search'
                };

                spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs);
                '''
            } )


            """
            td = table.add_cell()
            button = IconButtonWdg(title="Check-in", icon=IconWdg.PUBLISH)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'title': title,
                'cbjs_action': '''

                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                    view: 'checkin',
                    element_names: ['preview','code','name','description','history','general_checkin','notes']
                };

                // use tab
                var top = bvr.src_el.getParent(".spt_dashboard_top");
                spt.tab.set_tab_top(top);
                spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs);
                //spt.panel.load_popup(bvr.title, class_name, kwargs);

                '''
            } )
            """





            td = table.add_cell()
            button = IconButtonWdg(title="Import", icon=IconWdg.IMPORT)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'title': "Import Data",
                'cbjs_action': '''

                var class_name = 'tactic.ui.widget.CsvImportWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                };

                spt.panel.load_popup(bvr.title, class_name, kwargs);

                '''
            } )



            td = table.add_cell()
            button = IconButtonWdg(title="Custom Columns", icon=IconWdg.COLUMNS)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'title': "Add Custom Columns",
                'cbjs_action': '''
                var class_name = 'tactic.ui.startup.ColumnEditWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                };
                spt.panel.load_popup(bvr.title, class_name, kwargs);

                '''
            } )





            td = table.add_cell()
            button = IconButtonWdg(title="Workflow", icon=IconWdg.PIPELINE)
            button.add_style("float: left")
            td.add(button)

            search = Search("sthpw/pipeline")
            search.add_filter("search_type", search_type)
            count = search.get_count()
            if count:
                check = IconWdg( "Has Items", IconWdg.CHECK, width=8 )
                td.add(check)
                #check.add_style("margin-left: 0px")
                check.add_style("margin-top: 4px")




            button.add_behavior( {
                'type': 'click_up',
                'title': 'Workflow',
                'search_type': search_type,
                'cbjs_action': '''
                var class_name = 'tactic.ui.startup.PipelineEditWdg';
                var kwargs = {
                    search_type: bvr.search_type
                };
                spt.panel.load_popup(bvr.title, class_name, kwargs);
                '''
            } )
 


            td = table.add_cell()
            button = IconButtonWdg(title="Notifications", icon=IconWdg.MAIL)
            button.add_style("float: left")
            td.add(button)

            search = Search("sthpw/notification")
            search.add_filter("search_type", search_type)
            count = search.get_count()
            if count:
                check = IconWdg( "Has Items", IconWdg.CHECK, width=8 )
                td.add(check)
                #check.add_style("margin-left: 0px")
                check.add_style("margin-top: 4px")






            button.add_behavior( {
                'type': 'click_up',
                'title': 'Trigger',
                'search_type': search_type,
                'cbjs_action': '''

                var class_name = 'tactic.ui.tools.TriggerToolWdg';
                var kwargs = {
                    mode: "search_type",
                    search_type: bvr.search_type
                };
                spt.panel.load_popup(bvr.title, class_name, kwargs);
                '''
            } )


            td = table.add_cell()
            button = IconButtonWdg(title="Triggers", icon=IconWdg.ARROW_OUT)
            td.add(button)
            button.add_style("float: left")

            search = Search("config/trigger")
            search.add_filter("search_type", search_type)
            count = search.get_count()
            if count:
                check = IconWdg( "Has Items", IconWdg.CHECK, width=8 )
                td.add(check)
                #check.add_style("margin-left: 0px")
                check.add_style("margin-top: 4px")


            button.add_behavior( {
                'type': 'click_up',
                'title': 'Trigger',
                'search_type': search_type,
                'cbjs_action': '''

                var class_name = 'tactic.ui.tools.TriggerToolWdg';
                var kwargs = {
                    mode: "search_type",
                    search_type: bvr.search_type
                };
                spt.panel.load_popup(bvr.title, class_name, kwargs);
                '''
            } )





            td = table.add_cell()
            button = IconButtonWdg(title="Edit Searchable Type", icon=IconWdg.EDIT)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'search_key': search_type_obj.get_search_key(),
                'cbjs_action': '''

                var class_name = 'tactic.ui.panel.EditWdg';
                var kwargs = {
                    search_type: "sthpw/sobject",
                    view: "edit_startup",
                    search_key: bvr.search_key
                }
                spt.panel.load_popup("Edit Searchable Type", class_name, kwargs);


                '''
            } )


 
            """
            td = table.add_cell()
            button = IconButtonWdg(title="Security", icon=IconWdg.LOCK)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'title': 'Trigger',
                'search_type': search_type,
                'cbjs_action': '''
                alert("security");
                '''
            } )
            """


        columns_wdg = DivWdg()
        top.add(columns_wdg)


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


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

        div = DivWdg()
        div.add_class("spt_ingest_top")
        div.add_style("width: 100%px")
        div.add_style("min-width: 500px")
        div.add_style("padding: 20px")
        div.add_color("background", "background")


        title_div = DivWdg()
        div.add(title_div)
        title_div.add("Ingest Files")
        title_div.add_style("font-size: 14px")
        title_div.add_style("font-weight: bold")
        title_div.add_style("padding: 10px")
        title_div.add_color("background", "background3")
        title_div.add_border()

        my.search_type = my.kwargs.get("search_type")
        if not my.search_type:
            div.add("No search type specfied")
            return div

        if relative_dir:
            folder_div = DivWdg()
            div.add(folder_div)
            folder_div.add("Folder: %s" % relative_dir)
            folder_div.add_style("opacity: 0.5")
            folder_div.add_style("font-style: italic")
            folder_div.add_style("margin-bottom: 10px")

            title_div.add_style("margin: -20px -21px 5px -21px")
        else:
            title_div.add_style("margin: -20px -21px 15px -21px")


        div.add("Add files or drag/drop files to be uploaded and ingested:")
        div.add("<br/>"*2)


        data_div = my.get_data_wdg()
        data_div.add_style("float: left")
        data_div.add_style("float: left")
        div.add(data_div)

        # create the help button
        help_button_wdg = DivWdg()
        div.add(help_button_wdg)
        help_button_wdg.add_style("margin-top: -3px")
        help_button_wdg.add_style("float: right")
        help_button = ActionButtonWdg(title="?", tip="Ingestion Widget Help", size='s')
        help_button_wdg.add(help_button)

        help_button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''spt.help.load_alias("ingestion_widget")'''
        } )

        from tactic.ui.input import Html5UploadWdg
        upload = Html5UploadWdg(multiple=True)
        div.add(upload)


        button = ActionButtonWdg(title="Add")
        button.add_style("float: right")
        button.add_style("margin-top: -3px")
        div.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_ingest_top");
            var files_el = top.getElement(".spt_upload_files");

	    var onchange = function (evt) {
                var files = spt.html5upload.get_files();
                for (var i = 0; i < files.length; i++) {
                    spt.drag.show_file(files[i], files_el, 0, true);
                }
	    }

            spt.html5upload.set_form( top );
            spt.html5upload.select_file( onchange );

         '''
         } )



        button = ActionButtonWdg(title="Clear")
        button.add_style("float: right")
        button.add_style("margin-top: -3px")
        div.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_ingest_top");
            var file_els = top.getElements(".spt_upload_file");
            for ( var i = 0; i < file_els.length; i++) {
                spt.behavior.destroy( file_els[i] );
            };

         '''
         } )




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


        files_div = DivWdg()
        files_div.add_style("position: relative")
        files_div.add_class("spt_upload_files")
        div.add(files_div)
        files_div.add_style("max-height: 300px")
        files_div.add_style("height: 300px")
        files_div.add_style("overflow-y: auto")
        files_div.add_border()
        files_div.add_style("padding: 3px")
        files_div.add_color("background", "background3")
        #files_div.add_style("display: none")

        bgcolor = div.get_color("background3")
        bgcolor2 = div.get_color("background3", -3)

        files_div.add_behavior( {
            'type': 'mouseenter',
            'bgcolor': bgcolor2,
            'cbjs_action': '''
            bvr.src_el.setStyle("background", bvr.bgcolor)
            '''
        } )

        files_div.add_behavior( {
            'type': 'mouseout',
            'bgcolor': bgcolor,
            'cbjs_action': '''
            bvr.src_el.setStyle("background", bvr.bgcolor)
            '''
        } )


        background = DivWdg()
        background.add_class("spt_files_background")
        files_div.add(background)
        background.add_style("font-size: 4.0em")
        background.add_style("font-weight: bold")
        background.add_style("opacity: 0.1")
        background.add_style("position: absolute")
        background.add_style("left: 50%")
        background.add_style("top: 100px")
        background.add_border()
        inner_background = DivWdg("Drag Files Here")
        background.add(inner_background)
        inner_background.set_style("position: absolute")
        inner_background.set_style("margin-left: -50%")



        # Test drag and drop files
        files_div.add_attr("ondragenter", "return false")
        files_div.add_attr("ondragover", "return false")
        files_div.add_attr("ondrop", "spt.drag.noop(event, this)")
        files_div.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        spt.drag = {}
        var background;

        spt.drag.show_file = function(file, top, delay, icon) {

            if (!background) {
                background = top.getElement(".spt_files_background");
                background.setStyle("display", "none");
            }

            var template = top.getElement(".spt_upload_file_template");
            var clone = spt.behavior.clone(template);
            clone.removeClass("spt_upload_file_template");
            clone.addClass("spt_upload_file");
            clone.setStyle("display", "");

            if (typeof(delay) == 'undefined') {
                delay = 0;
            }

            // remember the file handle
            clone.file = file;

            var name = file.name;
            var size = parseInt(file.size / 1024 * 10) / 10;

            var thumb_el = clone.getElement(".spt_thumb");
            var date_label_el = clone.getElement(".spt_date_label");
            var date_el = clone.getElement(".spt_date");

            //var loadingImage = loadImage(
            setTimeout( function() {
                if (icon) {
                    var loadingImage = loadImage(
                        file,
                        function (img) {
                            thumb_el.appendChild(img);
                        },
                        {maxWidth: 80, maxHeight: 60, canvas: true, contain: true}
                    );
                }
                else {
                    var img = $(document.createElement("div"));
                    img.setStyle("width", "60");
                    img.setStyle("height", "40");
                    //img.innerHTML = "MP4";
                    img.setStyle("border", "solid 1px black")
                    thumb_el.appendChild(img);
                }


                loadImage.parseMetaData(
                    file,
                    function(data) {
                        if (data.exif) {
                            var date = data.exif.get('DateTimeOriginal');
                            if (date) {
                                date_label_el.innerHTML = date;
                                if (date_el) {
                                    date_el.value = date;
                                }
                            }
                        }

                    }
                );

            }, delay );

            /*
            var reader = new FileReader();
            reader.thumb_el = thumb_el;
            reader.onload = function(e) {
                this.thumb_el.innerHTML = [
                    '<img class="thumb" src="',
                    e.target.result,
                    '" title="', escape(name),
                    '" width="60px"',
                    '" padding="5px"',
                    '"/>'
                ].join('');
            }
            reader.readAsDataURL(file);
            */
         
            clone.getElement(".spt_name").innerHTML = file.name;
            clone.getElement(".spt_size").innerHTML = size + " KB";
            clone.inject(top);
        }

        spt.drag.noop = function(evt, el) {
            var top = $(el).getParent(".spt_ingest_top");
            var files_el = top.getElement(".spt_upload_files");
            evt.stopPropagation();
            evt.preventDefault();
            evt.dataTransfer.dropEffect = 'copy';
            var files = evt.dataTransfer.files;

            var delay = 0;
            var skip = false;
            for (var i = 0; i < files.length; i++) {
                var size = files[i].size;

                if (size >= 10*1024*1024) {
                    spt.drag.show_file(files[i], files_el, 0, false);
                }
                else {
                    spt.drag.show_file(files[i], files_el, delay, true);

                    if (size < 100*1024)       delay += 50;
                    else if (size < 1024*1024) delay += 500;
                    else if (size < 10*1024*1024) delay += 1000;
                }

            }
        }
        '''
        } )

        # create a template that will be filled in for each file
        files_div.add_relay_behavior( {
            'type': 'mouseenter',
            'color': files_div.get_color("background3", -5),
            'bvr_match_class': 'spt_upload_file',
            'cbjs_action': '''
            bvr.src_el.setStyle("background", bvr.color);
            '''
        } )
        files_div.add_relay_behavior( {
            'type': 'mouseleave',
            'bvr_match_class': 'spt_upload_file',
            'cbjs_action': '''
            bvr.src_el.setStyle("background", "");
            '''
        } )
        files_div.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': 'spt_remove',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_upload_file");
            spt.behavior.destroy_element(top);
            '''
        } )


        """
        metadata_view = "test/wizard/metadata"
        files_div.add_relay_behavior( {
            'type': 'mouseup',
            'view': metadata_view,
            'bvr_match_class': 'spt_upload_file',
            'cbjs_action': '''
            var class_name = 'tactic.ui.panel.CustomLayoutWdg';
            var kwargs = {
                view: bvr.view
            }
            spt.app_busy.show("Loading Metadata");
            spt.panel.load_popup("Metadata", class_name, kwargs);
            spt.app_busy.hide();
            '''
        } )
        """



        # template for each file item
        file_template = DivWdg()
        file_template.add_class("spt_upload_file_template")
        files_div.add(file_template)
        file_template.add_style("margin-bottom: 3px")
        file_template.add_style("padding: 3px")
        file_template.add_style("height: 40px")
        file_template.add_style("display: none")

        thumb_div = DivWdg()
        file_template.add(thumb_div)
        thumb_div.add_style("float: left")
        thumb_div.add_style("width: 60");
        thumb_div.add_style("height: 40");
        thumb_div.add_style("overflow: hidden");
        thumb_div.add_style("margin: 3 10 3 0");
        thumb_div.add_class("spt_thumb")


        info_div = DivWdg()
        file_template.add(info_div)
        info_div.add_style("float: left")

        name_div = DivWdg()
        name_div.add_class("spt_name")
        info_div.add(name_div)
        name_div.add("image001.jpg")
        name_div.add_style("width: 150px")



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

        dialog_data_div = DivWdg()
        dialog_data_div.add_color("background", "background")
        dialog_data_div.add_style("padding", "10px")

        dialog.add(dialog_data_div)
        dialog_data_div.add("Category: ")
        text = TextInputWdg(name="category")
        dialog_data_div.add(text)
        text.add_class("spt_category")
        text.add_style("padding: 1px")
        """

        date_div = DivWdg()
        date_div.add_class("spt_date_label")
        info_div.add(date_div)
        date_div.add("")
        date_div.add_style("opacity: 0.5")
        date_div.add_style("font-size: 0.8em")
        date_div.add_style("font-style: italic")
        date_div.add_style("margin-top: 3px")

        hidden_date_div = HiddenWdg("date")
        hidden_date_div.add_class("spt_date")
        info_div.add(date_div)




        size_div = DivWdg()
        size_div.add_class("spt_size")
        file_template.add(size_div)
        size_div.add("433Mb")
        size_div.add_style("float: left")
        size_div.add_style("width: 150px")
        size_div.add_style("text-align: right")

        remove_div = DivWdg()
        remove_div.add_class("spt_remove")
        file_template.add(remove_div)
        icon = IconButtonWdg(title="Remove", icon=IconWdg.DELETE)
        icon.add_style("float: right")
        remove_div.add(icon)
        #remove_div.add_style("text-align: right")


        div.add("<br/>")



        info = DivWdg()
        div.add(info)
        info.add_class("spt_upload_info")


        progress_div = DivWdg()
        progress_div.add_class("spt_upload_progress_top")
        div.add(progress_div)
        progress_div.add_style("width: 100%")
        progress_div.add_style("height: 15px")
        progress_div.add_style("margin-bottom: 10px")
        progress_div.add_border()
        #progress_div.add_style("display: none")

        progress = DivWdg()
        progress_div.add(progress)
        progress.add_class("spt_upload_progress")
        progress.add_style("width: 0px")
        progress.add_style("height: 100%")
        progress.add_gradient("background", "background3", -10)
        progress.add_style("text-align: right")
        progress.add_style("overflow: hidden")
        progress.add_style("padding-right: 3px")

        from tactic.ui.app import MessageWdg
        progress.add_behavior( {
            'type': 'load',
            'cbjs_action': MessageWdg.get_onload_js()
        } )



        # NOTE: files variable is passed in automatically

        upload_init = '''
        var server = TacticServerStub.get();
        server.start( {description: "Upload and check-in of ["+files.length+"] files"} );
        var info_el = top.getElement(".spt_upload_info");
        info_el.innerHTML = "Uploading ...";
        '''

        upload_progress = '''
        var top = bvr.src_el.getParent(".spt_ingest_top");
        progress_el = top.getElement(".spt_upload_progress");
        var percent = Math.round(evt.loaded * 100 / evt.total);
        progress_el.setStyle("width", percent + "%");
        progress_el.innerHTML = String(percent) + "%";


        '''


        on_complete = '''
        var top = bvr.src_el.getParent(".spt_ingest_top");
        var progress_el = top.getElement(".spt_upload_progress");
        progress_el.innerHTML = "100%";
        progress_el.setStyle("width", "100%");

        var info_el = top.getElement(".spt_upload_info");
        
        var search_type = bvr.kwargs.search_type;
        var relative_dir = bvr.kwargs.relative_dir;

        var filenames = [];
        for (var i = 0; i != files.length;i++) {
            var name = files[i].name;
            filenames.push(name);
        }

        var key = spt.message.generate_key();
        var values = spt.api.get_input_values(top);
        //var category = values.category[0];
        var keywords = values.keywords[0];

        var extra_data = values.extra_data[0];
        var parent_key = values.parent_key[0];

        var convert_el = top.getElement(".spt_image_convert")
        var convert = spt.api.get_input_values(convert_el);

        var processes = values.process;
        if (processes) {
            process = processes[0];
            if (!process) {
                process = null;
            }
        }
        else {
            process = null;
        }

        var kwargs = {
            search_type: search_type,
            relative_dir: relative_dir,
            filenames: filenames,
            key: key,
            parent_key: parent_key,
            //category: category,
            keywords: keywords,
            extra_data: extra_data,
            process: process,
            convert: convert,
        }
        on_complete = function() {
            spt.info("Ingest complete");
            server.finish();

            var file_els = top.getElements(".spt_upload_file");
            for ( var i = 0; i < file_els.length; i++) {
                spt.behavior.destroy( file_els[i] );
            };
            var background = top.getElement(".spt_files_background");
            background.setStyle("display", "");

            spt.message.stop_interval(key);
        };

        var class_name = bvr.action_handler;


        server.execute_cmd(class_name, kwargs, null, {on_complete:on_complete});

        on_progress = function(message) {
            msg = JSON.parse(message.message);
            var percent = msg.progress;
            var description = msg.description;
            info_el.innerHTML = description;

            progress_el.setStyle("width", percent+"%");
            progress_el.innerHTML = percent + "%";
        }
        spt.message.set_interval(key, on_progress, 2000);

        '''


        upload_div = DivWdg()
        div.add(upload_div)
        #button = UploadButtonWdg(**kwargs)
        button = ActionButtonWdg(title="Ingest")
        upload_div.add(button)
        button.add_style("float: right")
        upload_div.add_style("margin-bottom: 15px")
        upload_div.add("<br clear='all'/>")


        action_handler = my.kwargs.get("action_handler")
        if not action_handler:
            action_handler = 'tactic.ui.tools.IngestUploadCmd';

        button.add_behavior( {
            'type': 'click_up',
            'action_handler': action_handler,
            'kwargs': {
                'search_type': my.search_type,
                'relative_dir': relative_dir
            },
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_ingest_top");
            var file_els = top.getElements(".spt_upload_file");

            // get the server that will be used in the callbacks
            var server = TacticServerStub.get();

            // retrieved the stored file handles
            var files = [];
            for (var i = 0; i < file_els.length; i++) {
                files.push( file_els[i].file );
            }
            if (files.length == 0) {
                alert("No files selected");
                return;
            }


            // defined the callbacks
            var upload_start = function(evt) {
            }

            var upload_progress = function(evt) {
            %s;
            }

            var upload_complete = function(evt) {
            %s;
            spt.app_busy.hide();
            }


            var upload_file_kwargs =  {
                files: files,
                upload_start: upload_start,
                upload_complete: upload_complete,
                upload_progress: upload_progress 
            };
            if (bvr.ticket)
               upload_file_kwargs['ticket'] = bvr.ticket; 

            %s;

            spt.html5upload.set_form( top );
            spt.html5upload.upload_file(upload_file_kwargs);

            ''' % (upload_progress, on_complete, upload_init)
        } )


        return div
Example #13
0
    def get_collection_wdg(my):

        div = DivWdg()
        div.add_style("margin: 15px 0px")

        title_div = DivWdg("Collection Manager") 
        div.add(title_div)
        div.add_class("spt_collection_left")
        title_div.add_style("font-size: 1.2em")
        title_div.add_style("font-weight: bold")

        div.add("<hr/>")

        # Shelf
        shelf_div = DivWdg()
        div.add(shelf_div)
        shelf_div.add_style("float: right")
        shelf_div.add_style("margin-bottom: 15px")


        #button = IconButtonWdg(title='Delete Selected Collection', icon="BS_TRASH")
        #shelf_div.add(button)
        #button.add_style("display: inline-block")
        #button.add_style("width: auto")

        button = IconButtonWdg(title='Add New Collection', icon="BS_PLUS")
        shelf_div.add(button)
        button.add_style("display: inline-block")
        button.add_style("vertical-align: top")

        insert_view = "edit_collection"

        button.add_behavior( {
            'type': 'click_up',
            'insert_view': insert_view,
            'search_type': my.search_type,
            'cbjs_action': '''
                kwargs = {
                  search_type: bvr.search_type,
                  mode: 'insert',
                  view: bvr.insert_view,
                  save_event: bvr.event_name,
                  show_header: false,
                  num_columns: 2,
                  default: {
                    _is_collection: true
                  }
                };
                var popup = spt.panel.load_popup('Add New Collection', 'tactic.ui.panel.EditWdg', kwargs);
            '''
        } )
        text_div = DivWdg()
        shelf_div.add(text_div)

        custom_cbk = {}
        custom_cbk['enter'] = '''

            var top = bvr.src_el.getParent(".spt_collection_left");
            var input = top.getElement(".spt_main_search");
            var search_value = input.value.toLowerCase();
            var collections = top.getElements(".spt_collection_div");

            var num_result = 0;
            for (i = 0; i < collections.length; i++) {
                // Access the Collection title (without number count) 
                var collection_title = collections[i].attributes[0].value.toLowerCase();

                if (collection_title.indexOf(search_value) != '-1') {
                    collections[i].style.display = "block";
                    num_result += 1;
                }
                else {
                    collections[i].style.display = "none";
                }
            }
            // if no search results, display all
            if (num_result == 0) {
                for (i = 0; i < collections.length; i++) {
                    collections[i].style.display = "block";
                }
            }

        '''

        filters = []
        filters.append(("_is_collection",True))
        filters.append(("status","Verified"))
        text = LookAheadTextInputWdg(
            search_type = "workflow/asset",
            column="name",
            width="100%",
            height="30px",
            hint_text="Enter terms to filter collections...",
            value_column="name",
            filters=filters,
            custom_cbk=custom_cbk,
            is_collection=True
        )
        text.add_class("spt_main_search")

        text_div.add(text)
        text_div.add_style("width: 270px")
        text_div.add_style("display: inline-block")

        # Asset Library folder access
        div.add("<br clear='all'/>")
        asset_lib_div = DivWdg()
        div.add(asset_lib_div)
        folder_icon = IconWdg(icon="FOLDER_2", width='30px')

        asset_lib_div.add(folder_icon)
        asset_lib_div.add_style("margin: 5px 0px 5px -5px")
        asset_lib_div.add_style("height: 20px")
        asset_lib_div.add_style("padding-top: 5px")
        asset_lib_div.add_style("padding-bottom: 5px")
        asset_lib_div.add_style("font-weight: bold")

        asset_lib_div.add("Asset Library")
        asset_lib_div.add_class("tactic_hover")
        asset_lib_div.add_class("hand")
        asset_lib_div.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                var top = bvr.src_el.getParent(".spt_collection_top");             
                var view_panel = top.getParent('.spt_view_panel');
               
                spt.panel.refresh(view_panel);
                '''
            } )

        # Collections folder structure in the left panel
        search_type = my.kwargs.get('search_type')
        collections_div = CollectionFolderWdg(search_type=search_type)
        div.add(collections_div)

        return div
Example #14
0
    def get_display(my):

        sobject = my.get_current_sobject()

        use_parent = my.get_option("use_parent")
        use_parent = use_parent in ['true', True]
        #if use_parent in ['true', True]:
        #    sobject = sobject.get_parent()
        #    if not sobject:
        #        return DivWdg()

        my.search_key = SearchKey.get_by_sobject(sobject)
    
        div = DivWdg()
        div.add_class("hand")
        #div.add_style("width: 100%")
        #div.add_style("height: 100%")

        target_id = "main_body"

        title = "Show Item Details"
        if my.widget:
            widget = my.widget
        else:
            widget = IconButtonWdg(title=title, icon=IconWdg.ZOOM)


        code = sobject.get_code()


        widget.add_behavior( {
        'type': 'click_up',
        'search_key': my.search_key,
        'use_parent': use_parent,
        'code': code,
        'cbjs_action': '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.tools.SObjectDetailWdg';
        var kwargs = {
            search_key: bvr.search_key,
            use_parent: bvr.use_parent
        };


        var mode = 'xxx';
        var layout = bvr.src_el.getParent(".spt_tool_top");
        if (layout != null) {
            mode = 'tool'
        }

        if (mode == 'tool') {
            spt.app_busy.show("Loading ...");
            var layout = bvr.src_el.getParent(".spt_tool_top");
            var element = layout.getElement(".spt_tool_content");
            spt.panel.load(element, class_name, kwargs);
            spt.app_busy.hide();
        }
        else {
            var element_name = "detail_"+bvr.code;
            var title = "Detail ["+bvr.code+"]";
            spt.tab.add_new(element_name, title, class_name, kwargs);
        }
        '''
        } )


        #link_wdg = my.get_link_wdg(target_id, title, widget)
        #div.add( link_wdg )
        div.add(widget)

        return div
Example #15
0
    def get_collection_wdg(my):

        div = DivWdg()
        div.add_style("margin: 15px 0px")

        title_div = DivWdg("Collection Manager")
        div.add(title_div)
        div.add_class("spt_collection_left")
        title_div.add_style("font-size: 1.2em")
        title_div.add_style("font-weight: bold")

        div.add("<hr/>")

        # Shelf
        shelf_div = DivWdg()
        div.add(shelf_div)
        shelf_div.add_style("float: right")
        shelf_div.add_style("margin-bottom: 15px")

        #button = IconButtonWdg(title='Delete Selected Collection', icon="BS_TRASH")
        #shelf_div.add(button)
        #button.add_style("display: inline-block")
        #button.add_style("width: auto")

        button = IconButtonWdg(title='Add New Collection', icon="BS_PLUS")
        shelf_div.add(button)
        button.add_style("display: inline-block")
        button.add_style("vertical-align: top")

        insert_view = "edit_collection"

        button.add_behavior({
            'type':
            'click_up',
            'insert_view':
            insert_view,
            'search_type':
            my.search_type,
            'cbjs_action':
            '''
                kwargs = {
                  search_type: bvr.search_type,
                  mode: 'insert',
                  view: bvr.insert_view,
                  save_event: bvr.event_name,
                  show_header: false,
                  num_columns: 2,
                  default: {
                    _is_collection: true
                  }
                };
                var popup = spt.panel.load_popup('Add New Collection', 'tactic.ui.panel.EditWdg', kwargs);
            '''
        })
        text_div = DivWdg()
        shelf_div.add(text_div)

        custom_cbk = {}
        custom_cbk['enter'] = '''

            var top = bvr.src_el.getParent(".spt_collection_left");
            var input = top.getElement(".spt_main_search");
            var search_value = input.value.toLowerCase();
            var collections = top.getElements(".spt_collection_div");

            var num_result = 0;
            for (i = 0; i < collections.length; i++) {
                // Access the Collection title (without number count) 
                var collection_title = collections[i].attributes[0].value.toLowerCase();

                if (collection_title.indexOf(search_value) != '-1') {
                    collections[i].style.display = "block";
                    num_result += 1;
                }
                else {
                    collections[i].style.display = "none";
                }
            }
            // if no search results, display all
            if (num_result == 0) {
                for (i = 0; i < collections.length; i++) {
                    collections[i].style.display = "block";
                }
            }

        '''

        filters = []
        filters.append(("_is_collection", True))
        filters.append(("status", "Verified"))
        text = LookAheadTextInputWdg(
            search_type="workflow/asset",
            column="name",
            width="100%",
            height="30px",
            hint_text="Enter terms to filter collections...",
            value_column="name",
            filters=filters,
            custom_cbk=custom_cbk,
            is_collection=True)
        text.add_class("spt_main_search")

        text_div.add(text)
        text_div.add_style("width: 270px")
        text_div.add_style("display: inline-block")

        # Asset Library folder access
        div.add("<br clear='all'/>")
        asset_lib_div = DivWdg()
        div.add(asset_lib_div)
        folder_icon = IconWdg(icon="FOLDER_2", width='30px')

        asset_lib_div.add(folder_icon)
        asset_lib_div.add_style("margin: 5px 0px 5px -5px")
        asset_lib_div.add_style("height: 20px")
        asset_lib_div.add_style("padding-top: 5px")
        asset_lib_div.add_style("padding-bottom: 5px")
        asset_lib_div.add_style("font-weight: bold")

        asset_lib_div.add("Asset Library")
        asset_lib_div.add_class("tactic_hover")
        asset_lib_div.add_class("hand")
        asset_lib_div.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
                var top = bvr.src_el.getParent(".spt_collection_top");             
                var view_panel = top.getParent('.spt_view_panel');
               
                spt.panel.refresh(view_panel);
                '''
        })

        # Collections folder structure in the left panel
        search_type = my.kwargs.get('search_type')
        collections_div = CollectionFolderWdg(search_type=search_type)
        div.add(collections_div)

        return div
Example #16
0
    def get_header_wdg(my):

        div = DivWdg()

        if my.collection_key:

            button = IconButtonWdg(
                title='Remove Selected Items from Collection', icon="BS_MINUS")
            div.add(button)
            button.add_style("display: inline-block")
            button.add_style("vertical-align: top")

            button.add_behavior({
                'type':
                'click_up',
                'collection_key':
                my.collection_key,
                'cbjs_action':
                '''
                var search_keys = spt.table.get_selected_search_keys(false);
                var server = TacticServerStub.get();

                if (search_keys.length == 0) {
                    spt.notify.show_message("Nothing selected to remove");
                    return;
                }
                
                // default to false, if there is at least one collection selected, change to true
                var collection_selected = false;
                
                for (i=0; i<search_keys.length; i++){
                    var sobject = server.get_by_search_key(search_keys[i]);

                    if (sobject._is_collection){
                        collection_selected = true;
                        break;
                    }
                }

                var ok = null;
                var cancel = function() { return };
                var msg = "Are you sure you wish to remove the selected Assets from the Collection?";

                var ok = function() {
                    var cls = 'tactic.ui.panel.CollectionRemoveCmd';
                    var kwargs = {
                        collection_key: bvr.collection_key,
                        search_keys: search_keys,
                    }

                    try {
                        server.execute_cmd(cls, kwargs);
                        spt.table.remove_selected();
                    } catch(e) {
                        spt.alert(spt.exception.handler(e));
                    }

                    // Refresh left panel only if a collection is removed
                    if (collection_selected) {
                        var top = bvr.src_el.getParent(".spt_collection_top");
                        var collection_left = top.getElement(".spt_collection_left_side");
                        spt.panel.refresh(collection_left);
                    }
                }
                
                spt.confirm(msg, ok, cancel);

                '''
            })

            button = IconButtonWdg(title='Delete Collection', icon="BS_TRASH")
            #button = ActionButtonWdg(title='Delete Collection', icon="BS_TRASH")
            div.add(button)
            button.add_style("display: inline-block")
            button.add_style("vertical-align: top")

            button.add_behavior({
                'type':
                'click_up',
                'collection_key':
                my.collection_key,
                'cbjs_action':
                '''
                var ok = null;
                var cancel = function() { return };
                var msg = "Are you sure you wish to delete the Collection?";

                var ok = function() {
                    var cls = 'tactic.ui.panel.CollectionDeleteCmd';
                    var kwargs = {
                        collection_key: bvr.collection_key,
                    }
                    var server = TacticServerStub.get();
                    try {
                        server.execute_cmd(cls, kwargs);
                    } catch(e) {
                        spt.alert(e);
                        return;
                    }

                    var top = bvr.src_el.getParent(".spt_collection_top");
                    if (top) {
                        var layout = top.getParent(".spt_layout");
                        spt.table.set_layout(layout);
                    }

                    spt.table.run_search();
                }

                spt.confirm(msg, ok, cancel);
                '''
            })
        """
        button = IconButtonWdg(title='Download Selected Items', icon="BS_DOWNLOAD")
        div.add(button)
        button.add_style("display: inline-block")
        button.add_style("vertical-align: top")

        text_div = DivWdg()
        div.add(text_div)
        text_div.add_style("width: 200px")
        text = LookAheadTextInputWdg(
            name="name",
            icon="BS_SEARCH",
            icon_pos="right",
            width="100%"
        ) 
        text_div.add(text)
        text_div.add_style("display: inline-block")
        """

        div.add_style("width: auto")
        div.add_style("float: right")

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

        return div
Example #17
0
    def get_display(my):

        web = WebContainer.get_web()

        widget = DivWdg()
        widget.add_class("spt_search_limit_top")
        #widget.add_style("border", "solid 1px blue")
        widget.add_color("background", "background")
        widget.add_color("color", "color")
        widget.add_style("padding: 10px")

        hidden = HiddenWdg("prefix", my.prefix)
        widget.add(hidden)

        if not my.search and not my.sobjects:
            widget.add("No search or sobjects found")
            return widget

        # my.count should have been set in alter_search()
        # which can be called explicitly thru this instance, my.
        if not my.count:
            my.count = my.search.get_count(no_exception=True)

        # if my.sobjects exist thru inheriting from parent widgets
        # or explicitly set, (this is not mandatory though)
        if my.sobjects and len(my.sobjects) < my.search_limit:
            limit = len(my.sobjects)
        elif my.search and my.count < my.search_limit:
            # this is only true if the total result of the search is
            # less than the limit and so this wdg will not display
            limit = my.count
        else:
            limit = my.search_limit

        if not limit:
            limit = 50
            my.search_limit = limit

        if my.refresh:
            prev = SpanWdg(IconButtonWdg(title="Prev", icon="BS_CHEVRON_LEFT"))
            prev.add_style("margin-left: 8px")
            prev.add_style("margin-right: 6px")
            prev.add_style("margin-top: 5px")

            next = SpanWdg(IconButtonWdg(title="Next",
                                         icon="BS_CHEVRON_RIGHT"))
            next.add_style("margin-left: 6px")
            next.add_style("margin-top: 5px")

            prev.add_behavior({
                'type': 'click_up',
                'cbjs_action': my.refresh_script
            })
            next.add_behavior({
                'type': 'click_up',
                'cbjs_action': my.refresh_script
            })

            prev.add_style("float: left")
            next.add_style("float: left")

        else:  # the old code pre 2.5
            prev = IconButtonWdg(title="Prev", icon="BS_CHEVRON_LEFT")
            hidden_name = my.prev_hidden_name
            hidden = HiddenWdg(hidden_name, "")
            prev.add(hidden)
            prev.add_event('onclick'," spt.api.Utility.get_input(document,'%s').value ='Prev';%s"\
                    %(hidden_name, my.refresh_script))
            next = IconButtonWdg(title="Next", icon="BS_CHEVRON_RIGHT")
            hidden_name = my.next_hidden_name
            hidden = HiddenWdg(hidden_name, "")
            next.add(hidden)
            next.add_event('onclick',"spt.api.Utility.get_input(document,'%s').value ='Next';%s" \
                    %(hidden_name, my.refresh_script))

        showing_wdg = DivWdg()
        widget.add(showing_wdg)
        showing_wdg.add_style("padding: 20px")
        showing_wdg.add_style("margin: 10px")
        showing_wdg.add_color("background", "background", -5)
        #showing_wdg.add_color("text-align", "center")
        showing_wdg.add_border()

        label_span = SpanWdg("Showing: ")
        showing_wdg.add(label_span)
        showing_wdg.add("<br clear='all'/>")
        showing_wdg.add("<br/>")
        showing_wdg.add(prev)

        # this min calculation is used so that if my.sobjects is not set
        # above for the calculation of the limit, which will make the last
        # set of range numbers too big

        left_bound = my.current_offset + 1
        if not limit:
            # prevent error in ItemsNavigatorWdg if a search encounters query error
            limit = 50
            my.search_limit = limit

        right_bound = min(my.current_offset + limit, my.count)
        if left_bound > right_bound:
            left_bound = 1
        current_value = "%d - %d" % (left_bound, right_bound)

        if my.style == my.SIMPLE:
            showing_wdg.add(current_value)
        else:
            # add a range selector using ItemsNavigatorWdg
            from pyasm.widget import ItemsNavigatorWdg
            selector = ItemsNavigatorWdg(my.label, my.count, my.search_limit)
            selector.select.add_behavior({
                'type': 'change',
                'cbjs_action': my.refresh_script
            })

            selector.set_style(my.style)
            selector.select.add_style("width: 100px")
            #selector.add_style("display: inline")
            selector.add_style("float: left")

            selector.set_value(current_value)
            selector.set_display_label(False)

            showing_wdg.add(selector)

        showing_wdg.add(next)

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

        #showing_wdg.add( " x ")
        showing_wdg.add(my.text)
        my.text.add_style("margin-top: -3px")
        my.text.set_attr("size", "1")
        my.text.add_attr("title", "Set number of items per page")

        # set the limit
        set_limit_wdg = my.get_set_limit_wdg()
        widget.add(set_limit_wdg)

        from tactic.ui.widget.button_new_wdg import ActionButtonWdg
        button = ActionButtonWdg(title='Search')
        widget.add(button)
        button.add_style("float: right")
        button.add_style("margin-top: 8px")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_search_limit_top");
            var select = top.getElement(".spt_search_limit_select");
            var value = select.value;
            if (value == 'Custom') {
                custom = top.getElement(".spt_search_limit_custom_text");
                value = custom.value;
            }
            if (value == '') {
                value = 20;
            }
            var text = top.getElement(".spt_search_limit_text");
            text.value = value;

            spt.dg_table.search_cbk({}, bvr) 
            '''
        })

        offset_wdg = HiddenWdg("%s_last_search_offset" % my.label)
        offset_wdg.set_value(my.current_offset)
        widget.add(offset_wdg)

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

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

        top = my.top
        top.add_class("spt_switcher_top")
        
        '''
        This supports supports two menu definitions:
        menu - specifies a view for SideBarWdg which will be ingected as menu 
        config_xml - specifies menu entries. For example:

        <display class="tactic.ui.widget.LayoutSwitcherWdg">
          <!-- config_xml -->
          <config>
            <!-- Menu item 1 -->
            <element name="my_tasks_default" title="My Tasks">
              <display class="tactic.ui.panel.ViewPanelWdg">
                <search_type>sthpw/task</search_type>
                <show_shelf>false</show_shelf>
                <view>my_tasks_default</view>
                <target>spt_my_tasks_table_top</target>
              </display>
            </element>
            <!-- Menu item 2 -->
            <element ... >
              <display ... >
                <target ... />
              </display>
            </element>
          </config>
        </display>

        target - specifies target div to load views when using "menu" kwarg
        use_href - updates address bar hash (this is TODO)
        '''
        
        menu = my.kwargs.get("menu")
        config_xml = my.kwargs.get("config_xml")
        target = my.kwargs.get("target")
        # TODO: use_href to go to specific layout switcher view
        # use_href = my.kwrags.get("use_href")
        
        # Layout switcher button displays menu and assumes right hand position of screen
        activator = IconButtonWdg( name="Layout Switcher", icon="BS_TH_LIST")
        top.add(activator)
        activator.add_class("spt_switcher_activator")
        activator.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var activator = bvr.src_el;
            var top = activator.getParent(".spt_switcher_top");
            var menu = top.getElement(".spt_switcher_menu");
            
            if (top.hasClass("spt_selected")) {
                top.removeClass("spt_selected");
                menu.setStyle("display", "none");    
            } else {
                top.addClass("spt_selected");
                menu.setStyle("display", "");
                var pos = activator.getPosition();
                var button_size = activator.getSize();
                var menu_size = menu.getSize();
                var offset = {
                    x: button_size.x - menu_size.x,
                    y: button_size.y
                }
                menu.position({position: 'upperleft', relativeTo: activator, offset: offset});

                var pointer = menu.getElement(".spt_popup_pointer");
                pointer.setStyle("margin-left", menu_size.x - button_size.x);
            } 
            '''
        } )
            
        # menu_wdg 
        menu_wdg = DivWdg()
        top.add(menu_wdg)
        menu_wdg.add_class("spt_switcher_menu")
        menu_wdg.add_style("display: none")
        menu_wdg.add_style("margin-top", "15px")
        menu_wdg.add_style("position", "absolute")
        menu_wdg.add_style("z-index", "10")
        menu_wdg.add_behavior( {
            'type': 'mouseleave',
            'cbjs_action': '''
            var menu = bvr.src_el;
            var top = menu.getParent(".spt_switcher_top");
            top.removeClass("spt_selected");
            menu.setStyle("display", "none")
            '''
        } )
        
        # Pointer under activator
        pointer_wdg = DivWdg()
        menu_wdg.add(pointer_wdg)
        pointer_wdg.add('''
            <div class="spt_first_arrow_div"> </div>
            <div class="spt_second_arrow_div"> </div>
        ''')
        pointer_wdg.add_class("spt_popup_pointer")

        style = HtmlElement.style('''
            .spt_switcher_menu .spt_popup_pointer {
                z-index: 10;
                margin-top: -15px;
                margin-left: 100px;
            }

            .spt_switcher_menu .spt_first_arrow_div {
                border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #ccc;
                top: -15px;
                z-index: 1;
                border-width: 0 15px 15px;
                height: 0;
                width: 0;
                border-style: dashed dashed solid;
                left: 15px;
            }

            .spt_switcher_menu .spt_second_arrow_div{
                border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #fff;
                z-index: 1;
                border-width: 0 15px 15px;
                height: 0;
                width: 0;
                border-style: dashed dashed solid;
                margin-top: -14px;
                position: absolute;
            }
        ''')
        pointer_wdg.add(style)
 
        if menu:
            from tactic.ui.panel import SimpleSideBarWdg
            simple_sidebar = SimpleSideBarWdg(view=menu, search_type="SidebarWdg", target=target) 
            menu_wdg.add(simple_sidebar)
        else:
            style = my.get_style()
            top.add(style)
            
            my.view = 'tab'
            config = WidgetConfig.get(view=my.view, xml=config_xml)
            element_names = config.get_element_names()

            for element_name in element_names:

                item_div = DivWdg()
                menu_wdg.add(item_div)
                item_div.add_class("spt_switcher_item")
                item_div.add_class("tactic_hover")

                attrs = config.get_element_attributes(element_name)
                title = attrs.get("title")
                if not title:
                    title = Common.get_display_title(element_name)

                item_div.add(title)

                target = attrs.get("target")
                if not target:
                    target = "spt_content"

                display_class = config.get_display_handler(element_name)
                display_options = config.get_display_options(element_name)

                item_div.add_behavior( {
                    'type': 'click_up',
                    'display_class': display_class,
                    'display_options': display_options,
                    'target': target,
                    'cbjs_action': '''
                    var menu_item = bvr.src_el;
                    var top = menu_item.getParent(".spt_switcher_top");
                    var menu = menu_item.getParent(".spt_switcher_menu");
                    
                    // Get target class
                    var target_class = bvr.target;
                    if (target_class.indexOf(".") != "-1") {
                        var parts = target_class.split(".");
                        target_class = parts[1]; 
                    }
                    
                    var target = $(document.body).getElement("."+target_class);
                    if (target) {
                        spt.panel.load(target, bvr.display_class, bvr.display_options);
                    }

                    menu.setStyle("display", "none");
                    top.removeClass("spt_selected");
                    '''
                } )
        
        return top
Example #19
0
    def get_category_wdg(self, category, mode="new"):

        subscriptions = self.get_subscriptions(category, mode)
        if not subscriptions:
            return

        div = DivWdg()
        div.add_style("width: 100%")

        title_div = DivWdg()
        div.add(title_div)
        title_div.add_style("padding: 10px")
        title_div.add_border()
        title_div.add_color("background", "background3")
        title = category or "Subscriptions"
        title_div.add("%s " % title)
        

        summary_div = SpanWdg()
        title_div.add(summary_div)
        summary_div.add_style("font-size: 0.8em")
        summary_div.add_style("opacity: 0.5")


        search_keys = [x.get_search_key() for x in subscriptions]
        button = ActionButtonWdg(title="Clear All")
        button.add_styles('float: right; padding: 2px')
        button_div = DivWdg(button)
        button_div.add_style('min-height: 26px')
        div.add(button_div)

        button.add_behavior( {
            'type': 'click_up',
            'search_keys': search_keys,
            'cbjs_action': '''
            var server = TacticServerStub.get();
            for (var i = 0; i < bvr.search_keys.length; i++) {
                var search_key = bvr.search_keys[i];
                server.update(search_key, {'last_cleared':'NOW'});
            spt.panel.refresh(bvr.src_el);
            }
            '''
        } )



        # types of subscriptions
        table_div = DivWdg()
        table_div.add_styles('overflow-y: auto; max-height: 500px; width: 100%')
        div.add(table_div)
        table = Table()
        table.add_style('width: 100%')
        table.add_border()
        table.add_color("background", "background3")

        
        table_div.add(table)
        ss = []
        for subscription in subscriptions:
            table.add_row()
            td = table.add_cell()

            message_code = subscription.get_value("message_code")
            search = Search("sthpw/message")
            search.add_filter("code", message_code)
            message = search.get_sobject()

            # show the thumb
            if not message:
                if mode == "all":
                    td = table.add_cell(FormatMessageWdg.get_preview_wdg(subscription))
                    td = table.add_cell()
                    td.add("No Messages")
                continue

            size = 60

            
            show_preview = self.kwargs.get('show_preview')
            if show_preview in ['',None]:
                show_preview = True

            msg_element = FormatMessageWdg(subscription=subscription, short_format='true',show_preview=show_preview)
            # this is optional
            msg_element.set_sobject(message)
            description = msg_element.get_buffer_display() 
          
            #td = table.add_cell()

            history_icon = IconButtonWdg(title="Subscription History", icon=IconWdg.HISTORY)
            #td.add(icon)
            message_code = subscription.get_value("message_code")
            history_icon.add_behavior( {
                'type': 'click_up',
                'message_code': message_code,
                'cbjs_action': '''
                var class_name = 'tactic.ui.panel.FastTableLayoutWdg';
                var message_code = bvr.message_code;
                var kwargs = {
                    search_type: 'sthpw/message_log',
                    show_shelf: false,
                    expression: "@SOBJECT(sthpw/message_log['message_code','"+message_code+"'])",
                    view: 'history'
                };
                spt.tab.set_main_body_tab();
                spt.tab.add_new("Message History", "Message History", class_name, kwargs);
                '''
            } )
 

            # description can take up 70%
            td = table.add_cell()
            td.add_style("width: %spx"%(SubscriptionBarWdg.WIDTH*0.7))

            desc_div = DivWdg()
            td.add(desc_div)
            desc_div.add(description)
            desc_div.add_style("padding: 0px 20px")

            td = table.add_cell()
            #td.add(message.get_value("status"))
            #td = table.add_cell()
            timestamp = message.get_datetime_value("timestamp")
            if timestamp:
                timestamp_str = timestamp.strftime("%b %d, %Y - %H:%M")
            else:
                timestamp_str = ""

            
            show_timestamp = self.kwargs.get('show_timestamp')
            if show_timestamp in ['',None]:
                show_timestamp = True

            if show_timestamp in ["True","true",True]:
                td.add(timestamp_str)

            #td = table.add_cell()
            #td.add(subscription.get_value("last_cleared"))

            td = table.add_cell()
            
            show_message_history = self.kwargs.get('show_message_history')
            if show_message_history in ['',None]:
                show_message_history = True
            if show_message_history in ["True","true",True]:
                td.add(history_icon)

            td.add(HtmlElement.br(2))
            td.add_style('width: 30px')
            icon = IconButtonWdg(title="Unsubscribe", icon=IconWdg.DELETE)
            icon.add_style('bottom: 14px')

            subscription_key = subscription.get_search_key()
            icon.add_behavior( {
                'type': 'click_up',
                'search_key': subscription_key,
                'message_code': message_code,
                'cbjs_action': '''
                    if (!confirm("Unsubscribe from [" + bvr.message_code + "]?")) {
                        return;
                    }
                    var top = bvr.src_el.getParent(".spt_subscription_top");
                    var server = TacticServerStub.get();
                    server.delete_sobject(bvr.search_key);
                    spt.panel.refresh(top);
                '''
            } )
            
            show_unsubscribe = self.kwargs.get('show_unsubscribe')
            if show_unsubscribe in ['',None]: 
                show_unsubscribe = False
            if show_unsubscribe in ["True","true",True]:
                td.add(icon)

            
            






            ss.append(subscription)

        num_sobjects = len(ss)
        if not num_sobjects:
            return None
        summary_div.add("(%s changes)" % num_sobjects)

        #from tactic.ui.panel import FastTableLayoutWdg
        #table = FastTableLayoutWdg(search_type="sthpw/subscription",show_shelf=False)
        #div.add(table)
        #table.set_sobjects(ss)


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

        sobject = my.get_current_sobject()

        use_parent = my.get_option("use_parent")
        use_parent = use_parent in ['true', True]
        #if use_parent in ['true', True]:
        #    sobject = sobject.get_parent()
        #    if not sobject:
        #        return DivWdg()

        my.search_key = SearchKey.get_by_sobject(sobject)
    
        div = DivWdg()
        div.add_class("hand")
        target_id = "main_body"

        mode = my.get_option("mode")
        #mode = "link"

        title = "Show Item Details"
        if my.widget:
            widget = my.widget
        elif mode == "link":
            widget = HtmlElement.href()
            column = my.get_option("link_column")
            if not column:
                column = "code"
            widget.add( sobject.get_value(column) )
            widget.add_style('text-decoration: underline')
        else:
            #widget = IconButtonWdg(title=title, icon=IconWdg.ZOOM)
            widget = IconButtonWdg(title=title, icon="BS_SEARCH")
            div.add_style("width: 26px")
            div.add_style("margin-left: auto")
            div.add_style("margin-right: auto")



        code = sobject.get_code()
        name = sobject.get_value("name", no_exception=True)
        if not name:
            name = code


        search_type_obj = sobject.get_search_type_obj()
        title = search_type_obj.get_title()
        if not title:
            title = "Detail"
        title = _(title)


        tab_element_names = my.kwargs.get("tab_element_names") or ""
        detail_view = my.kwargs.get("detail_view") or ""

        widget.add_behavior( {
        'type': 'click_up',
        'search_key': my.search_key,
        'use_parent': use_parent,
        'tab_element_names': tab_element_names,
        'detail_view': detail_view,
        'show_task_process': my.show_task_process,
        'code': code,
        'name': name,
        'label': title,
        'cbjs_action': '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.tools.SObjectDetailWdg';
        var kwargs = {
            search_key: bvr.search_key,
            use_parent: bvr.use_parent,
            tab_element_names: bvr.tab_element_names,
            show_task_process: bvr.show_task_process,
            detail_view: bvr.detail_view
        };

        var mode = '';
        var layout = bvr.src_el.getParent(".spt_tool_top");
        if (layout != null) {
            mode = 'tool'
        }

        if (mode == 'tool') {
            spt.app_busy.show("Loading ...");
            var layout = bvr.src_el.getParent(".spt_tool_top");
            var element = layout.getElement(".spt_tool_content");
            spt.panel.load(element, class_name, kwargs);
            spt.app_busy.hide();
        }
        else {
            var element_name = "detail_"+bvr.code;
            var title = bvr.label + " ["+bvr.name+"]";
            spt.tab.add_new(element_name, title, class_name, kwargs);
        }
        '''
        } )


        #link_wdg = my.get_link_wdg(target_id, title, widget)
        #div.add( link_wdg )
        div.add(widget)

        return div
Example #21
0
 if sobject.is_insert():
     button = IconWdg("No Path Found", IconWdg.CROSS, long=False)
 else:
     try:
         if mode == "sandbox":
             sobject_dir = my.get_base_dir(sobject)
         elif mode in ["client_repo", "repository"]:
             sobject_dir = my.get_client_repo_dir(sobject)
             sobject_lib_dir = my.get_lib_dir(sobject)
         sobject_dir = sobject_dir.strip()
         sobject_dir = Common.process_unicode_string(sobject_dir)
     except TacticException, e:
         print "WARNING: ", str(e)
         button = IconWdg("No Path Found", IconWdg.CROSS, long=False)
     else:
         button = IconButtonWdg(title="Explore: %s" % sobject_dir, icon=IconWdg.LOAD)
         if sobject_dir == sobject_lib_dir:
             button.add_behavior(
                 {
                     "type": "click_up",
                     "cbjs_action": "spt.alert('You are not allowed to browse directories on a web server.');",
                 }
             )
         else:
             button.add_behavior(
                 {
                     "type": "click_up",
                     "cbjs_action": """var applet = spt.Applet.get(); applet.makedirs('%s'); applet.open_explorer('%s');"""
                     % (sobject_dir, sobject_dir),
                 }
             )
Example #22
0
 if sobject.is_insert():
     button = IconWdg("No Path Found", IconWdg.CROSS, long=False)
 else:
     try:
         if mode == 'sandbox':
             sobject_dir = my.get_base_dir(sobject)
         elif mode in ['client_repo', 'repository']:
             sobject_dir = my.get_client_repo_dir(sobject)
             sobject_lib_dir = my.get_lib_dir(sobject)
         sobject_dir = sobject_dir.strip()
         sobject_dir = Common.process_unicode_string(sobject_dir)
     except TacticException, e:
         print "WARNING: ", str(e)
         button = IconWdg("No Path Found", IconWdg.CROSS, long=False)
     else:
         button = IconButtonWdg(title="Explore: %s" % sobject_dir,
                                icon=IconWdg.LOAD)
         if sobject_dir == sobject_lib_dir:
             button.add_behavior({
                 'type':
                 'click_up',
                 'cbjs_action':
                 "spt.alert('You are not allowed to browse directories on a web server.');"
             })
         else:
             button.add_behavior({
                 'type':
                 'click_up',
                 'cbjs_action':
                 '''var applet = spt.Applet.get(); applet.makedirs('%s'); applet.open_explorer('%s');'''
                 % (sobject_dir, sobject_dir)
             })
Example #23
0
    def get_display(my):

        top = my.top
        top.add_class("spt_changelist_content")
        my.set_as_panel(top)
        top.add_color("color", "color")
        top.add_color("background", "background")
        #top.add_border()
        #top.add_style("padding", "10px")
        top.add_style("min-width: 600px")
        top.add_style("min-height: 400px")

        top.add_behavior( {
            'type': 'load',
            'cbjs_action': scm_get_onload_js()
        } )



        sync_dir = Environment.get_sandbox_dir()
        # HARD CODED
        project = Project.get()
        depot = project.get_value("location", no_exception=True)
        if not depot:
            depot = project.get_code()
        location = '//%s' % depot


        changelist = my.kwargs.get("changelist")
        if not changelist:
            changelist = WidgetSettings.get_value_by_key("current_changelist")
        else:
            WidgetSettings.set_value_by_key("current_changelist", changelist)

        if not changelist:
            changelist = 'default'


        changelists = my.kwargs.get("changelists")
        if not changelists:
            changelists = []
        elif isinstance(changelists, basestring):
            changelists = changelists.replace("'", '"')
            changelists = jsonloads(changelists)

        top.add_behavior( {
            'type': 'load',
            'sync_dir': sync_dir,
            'depot': depot,
            'cbjs_action': '''
            spt.scm.sync_dir = bvr.sync_dir;
            spt.scm.depot = bvr.depot;
            '''
        } )



        inner = DivWdg()
        top.add(inner)

        table = Table()
        inner.add(table)
        table.add_style("width: 100%")
        table.add_color("background", "background", -3)

        table.add_row()
        th = table.add_header("")

        th = table.add_header("Changelist")
        th.add_style("text-align: left")
        th = table.add_header("Description")
        th.add_style("text-align: left")
        th = table.add_header("# Items")
        th.add_style("text-align: left")
        th = table.add_header("Status")
        th.add_style("text-align: left")
        th = table.add_header("View")
        th.add_style("text-align: left")
        th = table.add_header("Delete")
        th.add_style("text-align: left")
        #table.set_unique_id()
        #table.add_smart_styles("spt_changelist_item", {
        #    'text-align: right'
        #    } ))

        bgcolor = table.get_color("background", -8)
        table.add_relay_behavior( {
            'type': 'mouseover',
            'bvr_match_class': 'spt_changelist_item',
            'bgcolor': bgcolor,
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", bvr.bgcolor);
            '''
        } )
        table.add_relay_behavior( {
            'type': 'mouseout',
            'bvr_match_class': 'spt_changelist_item',
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", '');
            '''
        } )


        table.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': "spt_changelist_radio",
            'cbjs_action': '''

            var changelist = bvr.src_el.value;
            var top = bvr.src_el.getParent(".spt_changelist_content");
            top.setAttribute("spt_changelist", changelist);
            spt.app_busy.show("Loading Changelists Information");
            spt.changelist.load(bvr.src_el, changelist);
            spt.app_busy.hide();

            '''
        } )




        for c in changelists:
            num_items = len(c.get("info"))
            name = c.get("change")

            tr = table.add_row()
            tr.add_class("spt_changelist_item")

            radio = RadioWdg("changelist")
            radio.add_class("spt_changelist_radio")
            table.add_cell(radio)
            radio.set_option("value", name)
            if name == changelist:
                radio.set_checked()


            table.add_cell(name)
            table.add_cell(c.get("desc"))
            table.add_cell(num_items)
            table.add_cell(c.get("status"))

            if num_items:
                icon = IconButtonWdg(title="View", icon=IconWdg.ZOOM)

                icon.add_behavior( {
                    'type': 'click_up',
                    'changelist': c.get("change"),
                    'cbjs_action': '''
                    var top = bvr.src_el.getParent(".spt_changelist_content");
                    top.setAttribute("spt_changelist", bvr.changelist);

                    spt.app_busy.show("Loading Changelist");
                    spt.changelist.load(bvr.src_el, bvr.changelist);
                    spt.app_busy.hide();

                    '''
                } )
            else:
                icon = ''
            table.add_cell(icon)

            if not num_items and name != 'default':
                icon = IconButtonWdg(title="Delete Changelist", icon=IconWdg.DELETE)
            else:
                icon = ""

            table.add_cell(icon)




        inner.add("<hr/>")


        files = my.kwargs.get("files")
        if isinstance(files, basestring):
            files = files.replace("'", '"')
            files = jsonloads(files)



        if files == None:
            inner.add_behavior( {
                'type': 'load',
                'location': location,
                'changelist': changelist,
                'sync_dir': sync_dir,
                'cbjs_action': '''

spt.changelist = {}
spt.changelist.load = function(el, changelist) {
    var applet = spt.Applet.get();
    var changelists = spt.scm.run("get_changelists_by_user",[]);
    var dflt = {
        'change': 'default',
        'status': 'pending'
    }
    changelists.push(dflt);
    changelists = changelists.reverse();
    for (var i = 0; i < changelists.length; i++) {
        var info = spt.scm.run("get_changelist_files",[changelists[i].change]);
        changelists[i]['info'] = info;
    }

    // get the current chnage list
    var files = spt.scm.run("get_changelist_files",[changelist]);
    var path_info = {};
    var sizes = [];
    for ( var i = 0; i < files.length; i++) {

        // FIXME: perforce specific
        var path = files[i].depotFile;
        path = path.replace(bvr.location, bvr.sync_dir);
        files[i].path = path;

        var size;
        if (applet.exists(path)) {
            var info = applet.get_path_info(path);
            size = info.size;
        }
        else {
            size = 0;
        }
        sizes.push(size);
        path_info[path] = 'editable';
    }
    //var ret_val = spt.scm.status(bvr.sync_dir);
    //console.log(ret_val);

    var class_name = 'tactic.ui.checkin.changelist_wdg.ChangelistWdg';
    var kwargs = {
        files: files,
        sizes: sizes,
        changelist: changelist,
        changelists: changelists,
        path_info: path_info,
    }
    var top = el.getParent(".spt_changelist_content");
    spt.panel.load(top, class_name, kwargs);

}
spt.changelist.load(bvr.src_el, bvr.changelist);
            '''
        } )

        content = DivWdg()
        inner.add(content)
        content.add_class("spt_changelist_content")


        if files == None:

            loading_wdg = DivWdg()
            content.add(loading_wdg)
            loading_wdg.add("<b>Loading ...</b>")
            loading_wdg.add_style("padding: 30px")



        elif files:
            title_wdg = DivWdg()
            title_wdg.add_style("height: 15px")
            title_wdg.add("Changelist: [%s]" % changelist)
            content.add(title_wdg)
            title_wdg.add_gradient("background", "background", -5)
            title_wdg.add_style("padding: 5px")
            title_wdg.add_border()

            #button = SingleButtonWdg(tip='Add New Changelist', icon=IconWdg.ADD)
            #content.add(button)

            content.add("<br/>")

            paths = [x.get("path") for x in files]
            sizes = my.kwargs.get("sizes")
            path_info = my.kwargs.get("path_info")
            from scm_dir_list_wdg import ScmDirListWdg
            # dummy search_key
            search_key = "sthpw/virtual?code=xx001"
            dir_list_wdg = ScmDirListWdg(
                    base_dir=sync_dir,
                    paths=paths,
                    sizes=sizes,
                    path_info=path_info,
                    all_open=True,
                    #search_key=search_key
            )
            content.add(dir_list_wdg)

        else:

            content.add("Changelist: [%s]" % changelist)
            content.add("<br/>"*2)

            no_files_wdg = DivWdg()
            content.add(no_files_wdg)
            no_files_wdg.add_style("padding: 20px")
            no_files_wdg.add_border()
            no_files_wdg.add("No files in changelist")

            no_files_wdg.add_color("color", "color3")
            no_files_wdg.add_color("background", "background3")
            no_files_wdg.add_style("font-weight: bold")
            no_files_wdg.add_style("text-align: center")



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

        top = my.top
        top.add_class("spt_branch_content")
        my.set_as_panel(top)
        top.add_color("color", "color")
        top.add_color("background", "background")
        #top.add_border()
        #top.add_style("padding", "10px")
        top.add_style("min-width: 600px")
        top.add_style("min-height: 400px")

        top.add_behavior( {
            'type': 'load',
            'cbjs_action': scm_get_onload_js()
        } )



        sync_dir = Environment.get_sandbox_dir()
        project = Project.get()
        depot = project.get_value("location", no_exception=True)
        if not depot:
            depot = project.get_code()
        location = '//%s' % depot


        branch = my.kwargs.get("branch")
        if not branch:
            branch = WidgetSettings.get_value_by_key("current_branch")
        else:
            WidgetSettings.set_value_by_key("current_branch", branch)

        if not branch:
            branch = 'main'


        branches = my.kwargs.get("branches")
        if not branches:
            branches = []
        elif isinstance(branches, basestring):
            branches = branches.replace("'", '"')
            branches = jsonloads(branches)

        top.add_behavior( {
            'type': 'load',
            'depot': depot,
            'sync_dir': sync_dir,
            'cbjs_action': '''
            spt.scm.sync_dir = bvr.sync_dir;
            spt.scm.depot = bvr.depot;
            '''
        } )



        inner = DivWdg()
        top.add(inner)

        table = Table()
        inner.add(table)
        table.add_style("width: 100%")

        table.add_row()
        th = table.add_header("")

        th = table.add_header("Branches")
        th.add_style("text-align: left")
        th = table.add_header("Options")
        th.add_style("text-align: left")
        th = table.add_header("Owner")
        th.add_style("text-align: left")
        th = table.add_header("Check-out")
        th.add_style("text-align: left")

        bgcolor = table.get_color("background", -8)
        table.add_relay_behavior( {
            'type': 'mouseover',
            'bvr_match_class': 'spt_branch_item',
            'bgcolor': bgcolor,
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", bvr.bgcolor);
            '''
        } )
        table.add_relay_behavior( {
            'type': 'mouseout',
            'bvr_match_class': 'spt_branch_item',
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", '');
            '''
        } )


        table.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': "spt_branch_radio",
            'cbjs_action': '''
            var value = bvr.src_el.value;


            spt.app_busy.show("Setting current branch to " + value);
            var server = TacticServerStub.get();

            server.set_widget_setting("current_branch", value);

            var top = bvr.src_el.getParent(".spt_checkin_top");
            top.removeAttribute("spt_sandbox_dir");
            spt.panel.refresh(top);
            spt.app_busy.hide();

            '''
        } )


        for c in branches:
            name = c.get("branch")

            tr = table.add_row()
            tr.add_class("spt_branch_item")

            radio = RadioWdg("branch")
            radio.add_class("spt_branch_radio")
            table.add_cell(radio)
            radio.set_option("value", name)
            if name == branch:
                radio.set_checked()


            table.add_cell(name)
            table.add_cell(c.get("Options"))
            table.add_cell(c.get("Owner"))

            icon = IconButtonWdg(title="Check-out", icon=IconWdg.CHECK_OUT_SM)
            table.add_cell(icon)

            icon.add_behavior( {
                'type': 'click_up',
                'branch': c.get("branch"),
                'cbjs_action': '''
                var top = bvr.src_el.getParent(".spt_branch_content");
                top.setAttribute("spt_brange", bvr.branch);

                spt.app_busy.show("Checking out branch ["+bvr.branch+"]");
                spt.scm.checkout("new_project/"+bvr.branch);
                spt.app_busy.hide();

                '''
            } )



        inner.add("<hr/>")

        if my.kwargs.get("branches") == None:
            inner.add_behavior( {
            'type': 'load',
            'location': location,
            'sync_dir': sync_dir,
            'cbjs_action': '''

spt.branch = {}
spt.branch.load = function(el) {
    var branches = spt.scm.run("get_branches",[]);

    var class_name = 'tactic.ui.checkin.branch_wdg.BranchWdg';
    var kwargs = {
        branches: branches,
    }
    var top = el.getParent(".spt_branch_content");
    spt.panel.load(top, class_name, kwargs);
}

spt.branch.load(bvr.src_el);

        ''' } )


        return top
Example #25
0
    def get_shelf_wdg(my):

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

        div = DivWdg()

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


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

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

        processes.insert(0, "all")



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

        select.set_option("values", processes)

        filter_table.add_cell(select)



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

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


        asset_dir = Environment.get_asset_dir()

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

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

            '''
            } )



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

            }


            '''
        } )






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

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

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

            ''' % asset_dir
 
        } )

        return div
Example #26
0
    def get_shelf_wdg(self):

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

        div = DivWdg()

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

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

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

        processes.insert(0, "all")

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

        select.set_option("values", processes)

        filter_table.add_cell(select)

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

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

        asset_dir = Environment.get_asset_dir()

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

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

            '''
        })

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

            }


            '''
        })

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

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

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

            ''' % asset_dir
        })

        return div
Example #27
0
    def get_display(my):

        top = DivWdg()
        top.add_border()
        top.add_style("padding: 10px")
        top.add_color("color", "color")
        top.add_gradient("background", "background", 0, -5)
        #top.add_style("height: 550px")

        top.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            spt.named_events.fire_event("side_bar|hide", {} );
            '''
        } )


        project = Project.get()

        title = TitleWdg(title='Client Home')
        top.add(title)


        shelf = DivWdg()
        top.add(shelf)
        shelf.add_style("margin-left: -8px")
        shelf.add_style("width: 130px")

        security = Environment.get_security()
        view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow')
        if view_side_bar:
            button_div = DivWdg()
            shelf.add(button_div)
            button_div.add_style("float: left")
            button_div.add_style("margin-top: -3px")

            button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT)
            button_div.add(button)
            shelf.add("Toggle Side Bar")
            button.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                spt.named_events.fire_event("side_bar|toggle");
                '''
            } )

            shelf.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                spt.named_events.fire_event("side_bar|toggle");
                '''
            } )
            shelf.add_class("hand")
        else:
            shelf.add("&nbsp;")


        search_wdg = DivWdg()
        search_wdg.add_class("spt_main_top")
        top.add(search_wdg)
        search_wdg.add_style("padding: 10px")
        search_wdg.add_style("margin: 10px auto")
        search_wdg.add_style("width: 430px")
        search_wdg.add("Search: ")
        search_wdg.add("&nbsp;"*3)





        custom_cbk = {}
        custom_cbk['enter'] = '''
            var top = bvr.src_el.getParent(".spt_main_top");
            var search_el = top.getElement(".spt_main_search");
            var keywords = search_el.value;

            if (keywords != '') {
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    'search_type': 'sthpw/sobject_list',
                    'view': 'table',
                    'keywords': keywords,
                    'simple_search_view': 'simple_search',
                    //'show_shelf': false,
                }
                spt.tab.set_main_body_tab();
                spt.tab.add_new("Search Results", "Search Results", class_name, kwargs);
            }
        '''


        from tactic.ui.input import TextInputWdg, LookAheadTextInputWdg
        #text = TextInputWdg(name="search")
        text = LookAheadTextInputWdg(name="search", custom_cbk=custom_cbk)
        #text = TextWdg("search")
        text.add_class("spt_main_search")
        text.add_style("width: 290px")
        search_wdg.add(text)
        search_wdg.add_style("font-weight: bold")
        search_wdg.add_style("font-size: 16px")


        button = ActionButtonWdg(title="Search")
        #search_wdg.add(button)
        button.add_style("float: right")
        #button.add_style("margin-top: -28px")

        icon_div = DivWdg()
        search_wdg.add(icon_div)
        icon_div.add_style("width: 38px")
        icon_div.add_style("height: 27px")
        icon_div.add_style("padding-top: 3px")
        icon_div.add_style("padding-left: 4px")
        icon_div.add_style("text-align: center")
        #icon_div.add_gradient("background", "background3", 15, -10)
        icon_div.add_color("background", "background3", 10)
        over_color = icon_div.get_color("background3", 0)
        out_color = icon_div.get_color("background3", 10)
        icon_div.set_round_corners(5)
        icon_div.set_box_shadow("1px 1px 1px 1px")
        icon = IconWdg("Search", IconWdg.SEARCH_32, width=24)
        icon_div.add(icon)
        icon_div.add_style("float: right")
        icon_div.add_style("margin-top: -5px")
        button = icon_div
        icon_div.add_class("hand")
        icon_div.add_behavior( {
            'type': 'mouseover',
            'color': over_color,
            'cbjs_action': '''
            bvr.src_el.setStyle("background", bvr.color);
            '''
        } )
        icon_div.add_behavior( {
            'type': 'mouseout',
            'color': out_color,
            'cbjs_action': '''
            bvr.src_el.setStyle("background", bvr.color);
            bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-5");
            bvr.src_el.setStyle("margin-right", "0");
            '''
        } )
        icon_div.add_behavior( {
            'type': 'click',
            'color': out_color,
            'cbjs_action': '''
            bvr.src_el.setStyle("box-shadow", "0px 0px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-3");
            bvr.src_el.setStyle("margin-right", "-2");
            '''
        } )
        icon_div.add_behavior( {
            'type': 'click_up',
            'color': out_color,
            'cbjs_action': '''
            bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-5");
            bvr.src_el.setStyle("margin-right", "0");
            '''
        } )





        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_main_top");
            var search_el = top.getElement(".spt_main_search");
            var keywords = search_el.value;

            if (keywords == '') {
                return;
            }

            var class_name = 'tactic.ui.panel.ViewPanelWdg';
            var kwargs = {
                'search_type': 'sthpw/sobject_list',
                'view': 'table',
                'keywords': keywords,
                'simple_search_view': 'simple_search',
                //'show_shelf': false,
            }
            spt.tab.set_main_body_tab();
            spt.tab.add_new("Search Results", "Search Results", class_name, kwargs);
            '''
        } )

        #desc = DivWdg()
        #top.add(desc)
        #desc.add("Dashboard")
        #desc.add_style("width: 600px")


        # create a bunch of panels
        table = Table()
        table.add_color("color", "color")
        table.add_style("margin-bottom: 20px")
        table.center()
        top.add(table)
        table.add_row()


        td = table.add_cell()
        td.add_style("padding: 3px")
        td.add_style("vertical-align: top")
        title = "My Approvals"
        description = '''View all pending items for approval<br/><br/>
        '''
        #image = "<img src='/context/images/getting_started_pipeline.png'/>"
        image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.panel.ViewPanelWdg';
        var kwargs = {
            search_type: 'sthpw/sobject_list',
            view: 'client_approval',
            show_shelf: false,
            show_select: false,
            element_names: ['preview', 'name', 'description', 'task_pipeline_vertical','notes'],
            is_editable: false,
            //expression: "@SOBJECT(sthpw/task['project_code','fickle3'].fickle3/cars.sthpw/sobject_list)"
        };
        spt.tab.add_new("approvals", "Approvals", class_name, kwargs);
        '''
        }
        config_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(config_wdg)



        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "My Dashboard"
        image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''Dashboards display key project data in single views. Drill down further to work on tasks, make status changes or add notes.'''




        # read the config file
        from pyasm.widget import WidgetConfig
        tmp_path = __file__
        dir_name = os.path.dirname(tmp_path)
        file_path="%s/../config/dashboard-conf.xml" % (dir_name)
        config = WidgetConfig.get(file_path=file_path, view="definition")

        #element_name = "my_dashboard"
        element_name = "my_dashboard"
        attrs = config.get_element_attributes(element_name)
        dashboard_data = {}
        kwargs = config.get_display_options(element_name)
        class_name = kwargs.get('class_name')

        dashboard_data['class_name'] = class_name
        dashboard_data['kwargs'] = kwargs
        dashboard_data['title'] = attrs.get("title")
        dashboard_data['description'] = attrs.get("description")
        dashboard_data['image'] = attrs.get("image")

        behavior = {
        'type': 'click_up',
        'dashboard': dashboard_data,
        'cbjs_action': '''
        var class_name = 'tactic.ui.startup.dashboards_wdg.DashboardsWdg';
        var kwargs = {};
        spt.tab.set_main_body_tab();
        spt.tab.add_new("my_dashboard", "My Dashboard", bvr.dashboard.class_name, bvr.dashboard.kwargs);
        '''
        }
        pipeline_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(pipeline_wdg)




        td = table.add_cell()
        td.add_style("padding: 3px")
        td.add_style("vertical-align: top")
        title = "My Reports"
        image = "<img src='/context/icons/64x64/report_64.png'/>"
        description = '''TACTIC provides a number of predefined reports that project managers can access instantly to get real-time analytics.'''


        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        var class_name = 'tactic.ui.startup.reports_wdg.ReportsWdg';
        var kwargs = {};
        spt.tab.set_main_body_tab();
        spt.tab.add_new("reports", "Reports", class_name, kwargs);
        //spt.panel.load_popup("Reports", class_name, kwargs);
        '''
        }

        side_bar_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(side_bar_wdg)


        """
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
	title = "Documentation"

        description = '''TACTIC Documentation.
        <br/><br/>
        * Project Setup Documentation<br/>
        <br/>
        * End User Documentation<br/>
        <br/>
        * Developer Documentation<br/>
        <br/>
        * System Administrator Documentation<br/>
        <br/>
        '''
        image = "<img src='/context/images/getting_started_pipeline.png'/>"
        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        spt.help.load_alias("main")
        '''
        }
        doc_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(doc_wdg)
        """





        tr, td = table.add_row_cell()
        td.add_style("font-size: 14px")
        td.add("<br/>"*2)


        quick_links_wdg = QuickLinksWdg()
        td.add(quick_links_wdg)


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

        web = WebContainer.get_web()
        show_multi_project = web.get_form_value('show_multi_project')
        project = Project.get()
        search_type_objs = project.get_search_types(include_multi_project=show_multi_project)


        top = my.top
        top.add_class("spt_panel_stype_list_top")
        #top.add_style("min-width: 400px")
        #top.add_style("max-width: 1000px")
        #top.add_style("width: 100%")
        top.center()



        button = SingleButtonWdg(title="Advanced Setup", icon=IconWdg.ADVANCED)
        top.add(button)
        button.add_style("float: right")
        button.add_style("margin-top: -8px")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var class_name = 'tactic.ui.app.ProjectStartWdg';
            spt.tab.set_main_body_tab()
            spt.tab.add_new("project_setup", "Project Setup", class_name)
            '''
        } )


        button = SingleButtonWdg(title="Add", tip="Add New Searchable Type (sType)", icon=IconWdg.ADD)
        top.add(button)
        button.add_style("float: left")
        button.add_style("margin-top: -8px")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var class_name = 'tactic.ui.app.SearchTypeCreatorWdg';

            var kwargs = {
            };
            var popup = spt.panel.load_popup("Create New Searchable Type", class_name, kwargs);

            var top = bvr.src_el.getParent(".spt_panel_stype_list_top");
            popup.on_register_cbk = function() {
                spt.panel.refresh(top);
            }

            '''
        } )

        cb = CheckboxWdg('show_multi_project', label=' show multi-project')
        if show_multi_project:
            cb.set_checked()
        cb.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
                var panel = bvr.src_el.getParent('.spt_panel_stype_list_top')
                spt.panel.refresh(panel, {show_multi_project: bvr.src_el.checked});
            '''
            })
        span = SpanWdg(css='small')
        top.add(span)
        top.add(cb)
        top.add("<br clear='all'/>")
        #search_type_objs = []
        if not search_type_objs:
            arrow_div = DivWdg()
            top.add(arrow_div)
            icon = IconWdg("Click to Add", IconWdg.ARROW_UP_LEFT_32)
            icon.add_style("margin-top: -20")
            icon.add_style("margin-left: -15")
            icon.add_style("position: absolute")
            arrow_div.add(icon)
            arrow_div.add("&nbsp;"*5)
            arrow_div.add("<b>Click to Add</b>")
            arrow_div.add_style("position: relative")
            arrow_div.add_style("margin-top: 5px")
            arrow_div.add_style("margin-left: 20px")
            arrow_div.add_style("float: left")
            arrow_div.add_style("padding: 25px")
            arrow_div.set_box_shadow("0px 5px 20px")
            arrow_div.set_round_corners(30)
            arrow_div.add_color("background", "background")

            div = DivWdg()
            top.add(div)
            div.add_border()
            div.add_style("min-height: 180px")
            div.add_style("width: 600px")
            div.add_style("margin: 30px auto")
            div.add_style("padding: 20px")
            div.add_color("background", "background3")
            icon = IconWdg( "WARNING", IconWdg.WARNING )
            div.add(icon)
            div.add("<b>No Searchable Types have been created</b>")
            div.add("<br/><br/>")
            div.add("Searchables Types contain lists of items that are managed in this project.  Each item will automatically have the ability to have files checked into it, track tasks and status and record work hours.")
            div.add("<br/>"*2)
            div.add("For more information, read the help docs: ")
            from tactic.ui.app import HelpButtonWdg
            help = HelpButtonWdg(alias="main")
            div.add(help)
            div.add("<br/>")
            div.add("Click on the 'Add' button above to start adding new types.")
            return top


        div = DivWdg()
        top.add(div)
        #div.add_style("max-height: 300px")
        #div.add_style("overflow-y: auto")



        table = Table()
        div.add(table)
        table.add_style("margin-top: 10px")
        table.set_max_width()



        # group mouse over
        table.add_relay_behavior( {
            'type': "mouseover",
            'bvr_match_class': 'spt_row',
            'cbjs_action': "spt.mouse.table_layout_hover_over({}, {src_el: bvr.src_el, add_color_modifier: -2})"
        } )
        table.add_relay_behavior( {
            'type': "mouseout",
            'bvr_match_class': 'spt_row',
            'cbjs_action': "spt.mouse.table_layout_hover_out({}, {src_el: bvr.src_el})"
        } )



        tr = table.add_row()
        tr.add_color("color", "color")
        tr.add_gradient("background", "background", -10)
        th = table.add_header("")
        th.add_style("text-align: left")
        th = table.add_header("Title")
        th.add_style("text-align: left")
        th = table.add_header("# Items")
        th.add_style("text-align: left")
        th = table.add_header("View")
        th.add_style("text-align: left")
        th = table.add_header("Add")
        th.add_style("text-align: left")
        th = table.add_header("Import")
        th.add_style("text-align: left")
        th = table.add_header("Custom Columns")
        th.add_style("text-align: left")
        th = table.add_header("Workflow")
        th.add_style("text-align: left")
        th = table.add_header("Notifications")
        th.add_style("text-align: left")
        th = table.add_header("Triggers")
        th.add_style("text-align: left")
        th = table.add_header("Edit")
        th.add_style("text-align: left")
        #th = table.add_header("Security")
        #th.add_style("text-align: left")



        for i, search_type_obj in enumerate(search_type_objs):
            tr = table.add_row()
            tr.add_class("spt_row")

            if not i or not i%2:
                tr.add_color("background", "background3")
            else:
                tr.add_color("background", "background", -2 )


            thumb = ThumbWdg()
            thumb.set_sobject(search_type_obj)
            thumb.set_icon_size(30)
            td = table.add_cell(thumb)



            search_type = search_type_obj.get_value("search_type")
            title = search_type_obj.get_title()

            table.add_cell(title)

            try:
                search = Search(search_type)
                count = search.get_count()
                if count:
                    table.add_cell("%s item/s" % count)
                else:
                    table.add_cell("&nbsp;")
            except:
                td = table.add_cell("&lt; No table &gt;")
                td.add_style("font-style: italic")
                td.add_style("color: #F00")
                continue



            #search = Search(search_type)
            #search.add_interval_filter("timestamp", "today")
            #created_today = search.get_count()
            #table.add_cell(created_today)



            td = table.add_cell()
            button = IconButtonWdg(title="View", icon=IconWdg.ZOOM)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'title': title,
                'cbjs_action': '''

                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                    view: 'table',
                    'simple_search_view': 'simple_search'
                };

                // use tab
                var top = bvr.src_el.getParent(".spt_dashboard_top");
                spt.tab.set_tab_top(top);
                spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs);
                //spt.panel.load_popup(bvr.title, class_name, kwargs);

                '''
            } )
            button.add_style("float: left")


            arrow_button = IconButtonWdg(tip="More Views", icon=IconWdg.ARROWHEAD_DARK_DOWN)
            arrow_button.add_style("margin-left: 20px")
            td.add(arrow_button)

            cbk = '''
            var activator = spt.smenu.get_activator(bvr);

            var class_name = bvr.class_name;
            var layout = bvr.layout;

            var kwargs = {
                search_type: bvr.search_type,
                layout: layout,
                view: bvr.view,
                simple_search_view: 'simple_search',
                element_names: bvr.element_names,
            };

            // use tab
            var top = activator.getParent(".spt_dashboard_top");
            spt.tab.set_tab_top(top);
            spt.tab.add_new('%s', '%s', class_name, kwargs);
            ''' % (title, title)


            from tactic.ui.panel import SwitchLayoutMenu
            SwitchLayoutMenu(search_type=search_type, activator=arrow_button, cbk=cbk, is_refresh=False)

            td = table.add_cell()
            button = IconButtonWdg(title="Add", icon=IconWdg.ADD)
            td.add(button)
            button.add_behavior( {
                'type': 'listen',
                'search_type': search_type,
                'event_name': 'startup_save:' + search_type_obj.get_title(),
                'title': search_type_obj.get_title(),
                'cbjs_action': '''
                var top = bvr.src_el.getParent(".spt_dashboard_top");
                spt.tab.set_tab_top(top);
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                    view: 'table',
                    'simple_search_view': 'simple_search'
                };

                spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs);
 

                '''
            } )
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'title': search_type_obj.get_title(),
                'cbjs_action': '''

                var top = bvr.src_el.getParent(".spt_dashboard_top");
                spt.tab.set_tab_top(top);

                var class_name = 'tactic.ui.panel.EditWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                    view: "insert",
                    save_event: "startup_save:" + bvr.title
                }
                spt.panel.load_popup("Add New Items ("+bvr.title+")", class_name, kwargs);

                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                    view: 'table',
                    'simple_search_view': 'simple_search'
                };

                spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs);
                '''
            } )


            """
            td = table.add_cell()
            button = IconButtonWdg(title="Check-in", icon=IconWdg.PUBLISH)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'title': title,
                'cbjs_action': '''

                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                    view: 'checkin',
                    element_names: ['preview','code','name','description','history','general_checkin','notes']
                };

                // use tab
                var top = bvr.src_el.getParent(".spt_dashboard_top");
                spt.tab.set_tab_top(top);
                spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs);
                //spt.panel.load_popup(bvr.title, class_name, kwargs);

                '''
            } )
            """





            td = table.add_cell()
            button = IconButtonWdg(title="Import", icon=IconWdg.IMPORT)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'title': "Import Data",
                'cbjs_action': '''

                var class_name = 'tactic.ui.widget.CsvImportWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                };

                spt.panel.load_popup(bvr.title, class_name, kwargs);

                '''
            } )



            td = table.add_cell()
            button = IconButtonWdg(title="Custom Columns", icon=IconWdg.COLUMNS)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'title': "Add Custom Columns",
                'cbjs_action': '''
                var class_name = 'tactic.ui.startup.ColumnEditWdg';
                var kwargs = {
                    search_type: bvr.search_type,
                };
                spt.panel.load_popup(bvr.title, class_name, kwargs);

                '''
            } )





            td = table.add_cell()
            button = IconButtonWdg(title="Workflow", icon=IconWdg.PIPELINE)
            button.add_style("float: left")
            td.add(button)

            search = Search("sthpw/pipeline")
            search.add_filter("search_type", search_type)
            count = search.get_count()
            if count:
                check = IconWdg( "Has Items", IconWdg.CHECK, width=8 )
                td.add(check)
                #check.add_style("margin-left: 0px")
                check.add_style("margin-top: 4px")




            button.add_behavior( {
                'type': 'click_up',
                'title': 'Workflow',
                'search_type': search_type,
                'cbjs_action': '''
                var class_name = 'tactic.ui.startup.PipelineEditWdg';
                var kwargs = {
                    search_type: bvr.search_type
                };
                spt.panel.load_popup(bvr.title, class_name, kwargs);
                '''
            } )
 


            td = table.add_cell()
            button = IconButtonWdg(title="Notifications", icon=IconWdg.MAIL)
            button.add_style("float: left")
            td.add(button)

            search = Search("sthpw/notification")
            search.add_filter("search_type", search_type)
            count = search.get_count()
            if count:
                check = IconWdg( "Has Items", IconWdg.CHECK, width=8 )
                td.add(check)
                #check.add_style("margin-left: 0px")
                check.add_style("margin-top: 4px")






            button.add_behavior( {
                'type': 'click_up',
                'title': 'Trigger',
                'search_type': search_type,
                'cbjs_action': '''

                var class_name = 'tactic.ui.tools.TriggerToolWdg';
                var kwargs = {
                    mode: "search_type",
                    search_type: bvr.search_type
                };
                spt.panel.load_popup(bvr.title, class_name, kwargs);
                '''
            } )


            td = table.add_cell()
            button = IconButtonWdg(title="Triggers", icon=IconWdg.ARROW_OUT)
            td.add(button)
            button.add_style("float: left")

            search = Search("config/trigger")
            search.add_filter("search_type", search_type)
            count = search.get_count()
            if count:
                check = IconWdg( "Has Items", IconWdg.CHECK, width=8 )
                td.add(check)
                #check.add_style("margin-left: 0px")
                check.add_style("margin-top: 4px")


            button.add_behavior( {
                'type': 'click_up',
                'title': 'Trigger',
                'search_type': search_type,
                'cbjs_action': '''

                var class_name = 'tactic.ui.tools.TriggerToolWdg';
                var kwargs = {
                    mode: "search_type",
                    search_type: bvr.search_type
                };
                spt.panel.load_popup(bvr.title, class_name, kwargs);
                '''
            } )





            td = table.add_cell()
            button = IconButtonWdg(title="Edit Searchable Type", icon=IconWdg.EDIT)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'search_key': search_type_obj.get_search_key(),
                'cbjs_action': '''

                var class_name = 'tactic.ui.panel.EditWdg';
                var kwargs = {
                    search_type: "sthpw/sobject",
                    view: "edit_startup",
                    search_key: bvr.search_key
                }
                spt.panel.load_popup("Edit Searchable Type", class_name, kwargs);


                '''
            } )


 
            """
            td = table.add_cell()
            button = IconButtonWdg(title="Security", icon=IconWdg.LOCK)
            td.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'title': 'Trigger',
                'search_type': search_type,
                'cbjs_action': '''
                alert("security");
                '''
            } )
            """


        columns_wdg = DivWdg()
        top.add(columns_wdg)


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

        top = self.top
        top.add_class("spt_switcher_top")
        '''
        This supports supports two menu definitions:
        menu - specifies a view for SideBarWdg which will be ingected as menu 
        config_xml - specifies menu entries. For example:

        <display class="tactic.ui.widget.LayoutSwitcherWdg">
          <!-- config_xml -->
          <config>
            <!-- Menu item 1 -->
            <element name="self_tasks_default" title="My Tasks" target=spt_my_tasks_table_top">
              <display class="tactic.ui.panel.ViewPanelWdg">
                <search_type>sthpw/task</search_type>
                <show_shelf>false</show_shelf>
                <view>my_tasks_default</view>
              </display>
            </element>
            <!-- Menu item 2 -->
            <element ... >
              <display ... >
              </display>
            </element>
          </config>
        </display>

        target - specifies target div to load views when using "menu" kwarg
        use_href - updates address bar hash (this is TODO)
        '''

        menu = self.kwargs.get("menu")
        config_xml = self.kwargs.get("config_xml")
        target = self.kwargs.get("target")

        #default
        default_layout = self.kwargs.get("default_layout")

        # find the save state value, if state is to be saved
        save_state = self.kwargs.get("save_state")

        if save_state in [False, 'false']:
            save_state = None
            show_first = False
        else:
            show_first = True

        state_value = None
        if save_state:
            state_value = WidgetSettings.get_value_by_key(save_state)
        elif default_layout:
            state_value = default_layout

        title = self.kwargs.get("title")
        if not title and state_value:
            title = state_value
        if not title:
            title = "Switch Layout"

        mode = self.kwargs.get("mode")
        if mode == "button":
            color = self.kwargs.get("color") or "default"
            activator = DivWdg(
                "<button class='btn btn-%s dropdown-toggle' style='width: 160px'><span class='spt_title'>%s</span> <span class='caret'></span></button>"
                % (color, title))
        elif mode == "div":
            color = self.kwargs.get("color") or ""
            background = self.kwargs.get("background") or "transparent"
            activator = DivWdg(
                "<button class='btn dropdown-toggle' style='width: 160px; background: %s; color: %s; font-weight: bold'><span class='spt_title'>%s</span> <span class='caret'></span></button>"
                % (background, color, title))

        else:
            activator = IconButtonWdg(name="Layout Switcher",
                                      icon="BS_TH_LIST")

        top.add(activator)
        activator.add_class("spt_switcher_activator")
        activator.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var activator = bvr.src_el;
            var top = activator.getParent(".spt_switcher_top");
            var menu = top.getElement(".spt_switcher_menu");
            
            if (top.hasClass("spt_selected")) {
                top.removeClass("spt_selected");
                menu.setStyle("display", "none");    
            } else {
                top.addClass("spt_selected");
                menu.setStyle("display", "");
                var pos = activator.getPosition();
                var button_size = activator.getSize();
                var menu_size = menu.getSize();
                var offset = {
                    x: button_size.x - menu_size.x,
                    y: button_size.y
                }
                menu.position({position: 'upperleft', relativeTo: activator, offset: offset});

                spt.body.add_focus_element(menu);

                var pointer = menu.getElement(".spt_switcher_popup_pointer");
                pointer.setStyle("margin-left", menu_size.x - button_size.x);

            } 
            '''
        })

        outer_wdg = DivWdg()
        top.add(outer_wdg)

        # menu_wdg

        menu_wdg = DivWdg()
        outer_wdg.add(menu_wdg)
        menu_wdg.add_color("color", "color")
        menu_wdg.add_color("background", "background")
        menu_wdg.add_border()
        menu_wdg.add_class("spt_switcher_menu")
        menu_wdg.add_style("display: none")
        menu_wdg.add_style("margin-top", "20px")
        menu_wdg.add_style("position", "absolute")
        menu_wdg.add_style("z-index", "101")
        menu_wdg.add_behavior({
            'type':
            'mouseleave',
            'cbjs_action':
            '''
            var menu = bvr.src_el;
            var top = menu.getParent(".spt_switcher_top");
            top.removeClass("spt_selected");
            menu.setStyle("display", "none")
            '''
        })

        border_color = menu_wdg.get_color("border")

        # Pointer under activator
        pointer_wdg = DivWdg()
        menu_wdg.add(pointer_wdg)
        pointer_wdg.add('''
            <div class="spt_switcher_first_arrow_div"> </div>
            <div class="spt_switcher_second_arrow_div"> </div>
        ''')
        pointer_wdg.add_class("spt_switcher_popup_pointer")

        style = HtmlElement.style('''
            .spt_switcher_menu .spt_switcher_popup_pointer {
                z-index: 10;
                position: absolute;
                top: -15px;
                right: 15px;
            }

            .spt_switcher_menu .spt_switcher_first_arrow_div {
                border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) %s;
                top: -15px;
                z-index: 1;
                border-width: 0 15px 15px;
                height: 0;
                width: 0;
                border-style: dashed dashed solid;
                left: 15px;
            }

            .spt_switcher_menu .spt_switcher_second_arrow_div{
                border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #fff;
                z-index: 1;
                border-width: 0 15px 15px;
                height: 0;
                width: 0;
                border-style: dashed dashed solid;
                margin-top: -14px;
                position: absolute;
                left: 0px;
                top: 15px;
            }
        ''' % border_color)
        pointer_wdg.add(style)

        if menu:
            from tactic.ui.panel import SimpleSideBarWdg
            simple_sidebar = SimpleSideBarWdg(view=menu,
                                              search_type="SidebarWdg",
                                              target=target)
            menu_wdg.add(simple_sidebar)
        else:
            style = self.get_style()
            top.add(style)

            self.view = 'tab'
            config = WidgetConfig.get(view=self.view, xml=config_xml)
            element_names = config.get_element_names()

            if not element_names:
                outer_wdg.add_style("display: none")

            if not state_value:
                if not element_names:
                    state_value = ""
                else:
                    state_value = element_names[0]

            for element_name in element_names:

                item_div = DivWdg()
                menu_wdg.add(item_div)
                item_div.add_class("spt_switcher_item")
                item_div.add_class("tactic_hover")

                item_div.add_style("width: 100%")

                attrs = config.get_element_attributes(element_name)
                title = attrs.get("title")
                if not title:
                    title = Common.get_display_title(element_name)

                for name, value in attrs.items():
                    if name in ['title', 'class']:
                        continue
                    item_div.add_attr(name, value)

                css_class = attrs.get("class")
                if css_class:
                    item_div.add_class(css_class)

                item_div.add(title)
                item_div.add_attr("spt_title", title)

                target = attrs.get("target")
                if not target:
                    target = "spt_content"

                display_class = config.get_display_handler(element_name)
                display_options = config.get_display_options(element_name)

                if show_first != False:
                    if element_name == state_value:
                        item_div.add_behavior({
                            'type':
                            'load',
                            'cbjs_action':
                            '''
                            bvr.src_el.click();
                            '''
                        })

                if display_class:
                    item_div.add_behavior({
                        'type':
                        'click_up',
                        'display_class':
                        display_class,
                        'display_options':
                        display_options,
                        'element_name':
                        element_name,
                        'target':
                        target,
                        'save_state':
                        save_state,
                        'cbjs_action':
                        '''
                        var menu_item = bvr.src_el;
                        var top = menu_item.getParent(".spt_switcher_top");
                        var menu = menu_item.getParent(".spt_switcher_menu");
                        
                        // Get target class
                        var target_class = bvr.target;
                        if (target_class.indexOf(".") != -1) {
                            var parts = target_class.split(".");
                            target_class = parts[1]; 
                            target_top_class = parts[0];
                        }
                        else {
                            target_top_class = null;
                        }
                    
                        if (target_top_class) {
                            var target_top = bvr.src_el.getParent("."+target_top_class);
                        }
                        else {
                            var target_top = $(document.body);
                        }
                        var target = target_top.getElement("."+target_class);
                        if (target) {
                            spt.panel.load(target, bvr.display_class, bvr.display_options);
                        }

                        menu.setStyle("display", "none");
                        top.removeClass("spt_selected");

                        var title = bvr.src_el.getAttribute("spt_title");

                        var title_el = top.getElement(".spt_title");
                        if (title_el)
                            title_el.innerHTML = title

                        if (bvr.save_state) {
                            var server = TacticServerStub.get()
                            server.set_widget_setting(bvr.save_state, bvr.element_name);
                        }

                        '''
                    })

        return top
Example #30
0
    def get_collection_wdg(my):

        div = DivWdg()
        div.add_style("margin: 15px 0px")

        title_div = DivWdg("Collection Manager") 
        div.add(title_div)
        div.add_class("spt_collection_left")
        title_div.add_style("font-size: 1.2em")
        title_div.add_style("font-weight: bold")

        div.add("<hr/>")

        # Shelf
        shelf_div = DivWdg()
        div.add(shelf_div)
        shelf_div.add_style("float: right")
        shelf_div.add_style("margin-bottom: 15px")


        #button = IconButtonWdg(title='Delete Selected Collection', icon="BS_TRASH")
        #shelf_div.add(button)
        #button.add_style("display: inline-block")
        #button.add_style("width: auto")

        button = IconButtonWdg(title='Add New Collection', icon="BS_PLUS")
        shelf_div.add(button)
        button.add_style("display: inline-block")
        button.add_style("vertical-align: top")

        insert_view = "edit_collection"

        button.add_behavior( {
            'type': 'click_up',
            'insert_view': insert_view,
            'search_type': my.search_type,
            'cbjs_action': '''
                kwargs = {
                  search_type: bvr.search_type,
                  mode: 'insert',
                  view: bvr.insert_view,
                  save_event: bvr.event_name,
                  show_header: false,
                  num_columns: 2,
                  default: {
                    _is_collection: true
                  }
                };
                var popup = spt.panel.load_popup('Add New Collection', 'tactic.ui.panel.EditWdg', kwargs);
            '''
        } )
        text_div = DivWdg()
        shelf_div.add(text_div)

        custom_cbk = {}
        custom_cbk['enter'] = '''

            var top = bvr.src_el.getParent(".spt_collection_left");
            var input = top.getElement(".spt_main_search");
            var search_value = input.value.toLowerCase();
            var collections = top.getElements(".spt_collection_div");

            var num_result = 0;
            for (i = 0; i < collections.length; i++) {
                // Access the Collection title (without number count) 
                var collection_title = collections[i].attributes[0].value.toLowerCase();

                if (collection_title.indexOf(search_value) != '-1') {
                    collections[i].style.display = "block";
                    num_result += 1;
                }
                else {
                    collections[i].style.display = "none";
                }
            }
            // if no search results, display all
            if (num_result == 0) {
                for (i = 0; i < collections.length; i++) {
                    collections[i].style.display = "block";
                }
            }

        '''

        filters = []
        filters.append(("_is_collection",True))
        filters.append(("status","Verified"))
        text = LookAheadTextInputWdg(
            search_type = "workflow/asset",
            column="name",
            width="100%",
            hint_text="Enter terms to filter collections...",
            value_column="name",
            filters=filters,
            custom_cbk=custom_cbk,
            is_collection=True
        )
        text.add_class("spt_main_search")

        text_div.add(text)
        text_div.add_style("width: 270px")
        text_div.add_style("display: inline-block")

        # Asset Library folder access
        div.add("<br clear='all'/>")
        asset_lib_div = DivWdg()
        div.add(asset_lib_div)
        folder_icon = IconWdg(icon="FOLDER_2", width='30px')

        asset_lib_div.add(folder_icon)
        asset_lib_div.add_style("margin: 5px 0px 5px -5px")
        asset_lib_div.add_style("height: 20px")
        asset_lib_div.add_style("padding-top: 5px")
        asset_lib_div.add_style("padding-bottom: 5px")
        asset_lib_div.add_style("font-weight: bold")

        asset_lib_div.add("Asset Library")
        asset_lib_div.add_class("tactic_hover")
        asset_lib_div.add_class("hand")
        asset_lib_div.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                var top = bvr.src_el.getParent(".spt_collection_top");
                var content = top.getElements(".spt_collection_content");

                spt.panel.refresh(top);
                '''
            } )


        # collection
        search = Search(my.search_type)
        search.add_filter("_is_collection", True)
        collections = search.get_sobjects()

        collections_div = DivWdg()
        collections_div.add_class("spt_collection_list")
        div.add(collections_div)
        collections_div.add_style("margin: 5px 0px 5px -5px")

        from tactic.ui.panel import ThumbWdg2


        parts = my.search_type.split("/")
        collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1])


        collections_div.add_relay_behavior( {
            'type': 'mouseup',
            'search_type': my.search_type,
            'collection_type': collection_type,
            'bvr_match_class': 'spt_collection_item',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_collection_top");
            var content = top.getElement(".spt_collection_content");

            
            var list = bvr.src_el.getParent(".spt_collection_list");
            var items = list.getElements(".spt_collection_item");
            for (var i = 0; i < items.length; i++) {
                items[i].setStyle("background", "");
                items[i].setStyle("box-shadow", "");
            }
            bvr.src_el.setStyle("background", "#EEE");
            var collection_key = bvr.src_el.getAttribute("spt_collection_key");
            var collection_code = bvr.src_el.getAttribute("spt_collection_code");
            var collection_path = bvr.src_el.getAttribute("spt_collection_path");

            var expr = "@SEARCH("+bvr.collection_type+"['parent_code','"+collection_code+"']."+bvr.search_type+")";

            var parent_dict = {};
            var parent_collection = bvr.src_el.getParent(".spt_subcollection_wdg");
            var path = collection_path.substring(0, collection_path.lastIndexOf("/"));
            if (parent_collection) {
                for (var i = 0; i < collection_path.split("/").length - 1; i++) {
                    var n = path.lastIndexOf("/");
                    var collection_name = path.substring(n+1);                
                    path = path.substring(0, n);

                    var parent_key = parent_collection.getAttribute("spt_parent_key");
                    parent_dict[collection_name] = parent_key;
                    parent_collection = parent_collection.getParent(".spt_subcollection_wdg");
                    
                }
            }            

            var cls = "tactic.ui.panel.CollectionContentWdg";
            var kwargs = {
                collection_key: collection_key,
                path: collection_path,
                search_type: bvr.search_type,
                show_shelf: false,
                show_search_limit: true,
                expression: expr,
                parent_dict: parent_dict
            }
            spt.panel.load(content, cls, kwargs);

            bvr.src_el.setStyle("box-shadow", "0px 0px 3px rgba(0,0,0,0.5)");

            // hide the bottom show_search_limit when clicking into a collection
            var panel = bvr.src_el.getParent(".spt_panel");
            var search_limit_div = panel.getElements(".spt_search_limit_top");
            if (search_limit_div.length == 2){
                search_limit_div[1].setStyle("visibility", "hidden");
            }
            '''
        } )


        collections_div.add_relay_behavior( {
            'type': 'mouseup',
            'search_type': my.search_type,
            'bvr_match_class': 'spt_collection_open',
            'cbjs_action': '''
            var item = bvr.src_el.getParent(".spt_collection_div_top");
            var next = item.getNext();

            if (bvr.src_el.hasClass("spt_open")) {
                next.innerHTML = "";
                bvr.src_el.setStyle("opacity", 1.0);
                bvr.src_el.removeClass("spt_open");
            }
            else {
                var collection_key = bvr.src_el.getAttribute("spt_collection_key");
                var collection_path = bvr.src_el.getAttribute("spt_collection_path");

                var cls = "tactic.ui.panel.CollectionListWdg";
                var kwargs = {
                    parent_key: collection_key,
                    path: collection_path,
                }
                spt.panel.load(next, cls, kwargs, null, {show_loading: false});

                bvr.src_el.setStyle("opacity", 0.3);
                bvr.src_el.addClass("spt_open");

                evt.stopPropagation();
            }



            '''
        } )



        for collection in collections:

            collection_wdg = CollectionItemWdg(collection=collection, path=collection.get_value("name"))
            collections_div.add(collection_wdg)
            collection_wdg.add_class("spt_collection_div")

            subcollection_wdg = DivWdg()
            collections_div.add(subcollection_wdg)
            subcollection_wdg.add_class("spt_subcollection_wdg")
            subcollection_wdg.add_style("padding-left: 15px")


        return div
Example #31
0
    def get_display(my):

        sobject = my.get_current_sobject()

        use_parent = my.get_option("use_parent")
        use_parent = use_parent in ["true", True]
        # if use_parent in ['true', True]:
        #    sobject = sobject.get_parent()
        #    if not sobject:
        #        return DivWdg()

        my.search_key = SearchKey.get_by_sobject(sobject)

        div = DivWdg()
        div.add_class("hand")
        div.add_style("width: 26px")
        div.add_style("margin-left: auto")
        div.add_style("margin-right: auto")

        target_id = "main_body"

        title = "Show Item Details"
        if my.widget:
            widget = my.widget
        else:
            widget = IconButtonWdg(title=title, icon="BS_SEARCH")

        code = sobject.get_code()
        name = sobject.get_value("name", no_exception=True)
        if not name:
            name = code

        tab_element_names = my.kwargs.get("tab_element_names") or ""
        detail_view = my.kwargs.get("detail_view") or ""

        widget.add_behavior(
            {
                "type": "click_up",
                "search_key": my.search_key,
                "use_parent": use_parent,
                "tab_element_names": tab_element_names,
                "detail_view": detail_view,
                "show_task_process": my.show_task_process,
                "code": code,
                "name": name,
                "cbjs_action": """
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.tools.SObjectDetailWdg';
        var kwargs = {
            search_key: bvr.search_key,
            use_parent: bvr.use_parent,
            tab_element_names: bvr.tab_element_names,
            show_task_process: bvr.show_task_process,
            detail_view: bvr.detail_view
        };

        var mode = '';
        var layout = bvr.src_el.getParent(".spt_tool_top");
        if (layout != null) {
            mode = 'tool'
        }

        if (mode == 'tool') {
            spt.app_busy.show("Loading ...");
            var layout = bvr.src_el.getParent(".spt_tool_top");
            var element = layout.getElement(".spt_tool_content");
            spt.panel.load(element, class_name, kwargs);
            spt.app_busy.hide();
        }
        else {
            var element_name = "detail_"+bvr.code;
            var title = "Detail ["+bvr.name+"]";
            spt.tab.add_new(element_name, title, class_name, kwargs);
        }
        """,
            }
        )

        # link_wdg = my.get_link_wdg(target_id, title, widget)
        # div.add( link_wdg )
        div.add(widget)

        return div
Example #32
0
    def get_display(my):

        sobject = my.get_current_sobject()

        my.search_key = SearchKey.get_by_sobject(sobject)

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

        title = "Show Item Details"
        if my.widget:
            widget = my.widget
        else:
            widget = IconButtonWdg(title=title, icon=IconWdg.ZOOM)

        code = sobject.get_code()
        name = sobject.get_value("name", no_exception=True)
        if not name:
            name = code

        widget.add_behavior({
            'type':
            'click_up',
            'search_key':
            my.search_key,
            'code':
            code,
            'name':
            name,
            'cbjs_action':
            '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.tools.TaskDetailPanelWdg';
        var kwargs = {
            search_key: bvr.search_key,
        };

        var mode = '';
        var layout = bvr.src_el.getParent(".spt_tool_top");
        if (layout != null) {
            mode = 'tool'
        }

        if (mode == 'tool') {
            spt.app_busy.show("Loading ...");
            var layout = bvr.src_el.getParent(".spt_tool_top");
            var element = layout.getElement(".spt_tool_content");
            spt.panel.load(element, class_name, kwargs);
            spt.app_busy.hide();
        }
        else {
            var element_name = "detail_"+bvr.code;
            var title = "Detail ["+bvr.name+"]";
            spt.tab.add_new(element_name, title, class_name, kwargs);
        }
        '''
        })

        div.add(widget)

        return div
Example #33
0
    def get_display(my):

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

        my.last_path = None

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

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

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

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

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

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

        my.column = "description"

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

        #table = Table()
        table = ResizableTableWdg()

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

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

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

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

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

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

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

        #title.add(path)

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

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

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

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

                f.write(text)
                f.close()

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

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

                    if last_text != text:

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

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

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

            lines = text.split("\n")

            if my.doc_mode == "text":

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

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

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

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

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

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

                    td = line_table.add_cell()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

spt.document = {};

spt.document.selected_text = null;

spt.document.get_selected_text = function(frame)
{

    var t = '';

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

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

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

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

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

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

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

        return top
Example #34
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
Example #35
0
    def get_chat_wdg(self, key, interval=False):

        div = DivWdg()
        div.add_class("spt_chat_session_top")
        div.add_color("background", "background")

        title_wdg = DivWdg()
        div.add(title_wdg)
        title_wdg.add_color("background", "background3")
        title_wdg.add_style("padding: 5px")
        title_wdg.add_style("font-weight: bold")
        title_wdg.add_border()

        icon = IconButtonWdg(title="Remove Chat", icon=IconWdg.DELETE)
        icon.add_style("float: right")
        icon.add_style("margin-top: -5px")
        title_wdg.add(icon)
        icon.add_behavior( {
            'type': 'click_up',
            'key': key,
            'cbjs_action': '''
            var server = TacticServerStub.get();

            var top = bvr.src_el.getParent(".spt_chat_session_top");
            spt.behavior.destroy_element(top);
            '''
        } )


        current_user = Environment.get_user_name()
        logins = Search.eval("@SOBJECT(sthpw/subscription['message_code','%s'].sthpw/login)" % key)
        for login in logins:
            if login.get_value("login") == current_user:
                continue

            thumb = ThumbWdg()
            thumb.set_icon_size(45)
            thumb.set_sobject(login)
            thumb.add_style("float: left")
            thumb.add_style("margin: -5px 10px 0px -5px")
            title_wdg.add(thumb)
            title_wdg.add(login.get_value("display_name"))

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


        history_div = DivWdg()
        div.add(history_div)
        history_div.add_class("spt_chat_history")
        history_div.add_style("width: auto")
        history_div.add_style("height: auto")
        history_div.add_style("max-height: 400px")
        history_div.add_style("padding: 5px")
        history_div.add_class("spt_resizable")

        history_div.add_border()
        history_div.add_style("overflow-y: auto")
        #history_div.add_style("font-size: 0.9em")


        search = Search("sthpw/message_log")
        search.add_filter("message_code", key)
        search.add_order_by("timestamp")
        message_logs = search.get_sobjects()
        last_login = None;
        last_date = None;
        for message_log in message_logs:

            login = message_log.get("login")
            message = message_log.get("message")
            timestamp = message_log.get_datetime_value("timestamp")
            #timestamp = timestamp.strftime("%b %d, %Y - %H:%M")
            timestamp_str = timestamp.strftime("%H:%M")
            date_str = timestamp.strftime("%b %d, %Y")

        

            if login != last_login:

                table = Table()
                history_div.add(table)
                table.add_row()
                table.add_style("width: 100%")
                table.add_style("margin-top: 15px")

                login_sobj = Search.get_by_code("sthpw/login", login)
                thumb_div = DivWdg()
                td = table.add_cell()
                td.add_style("vertical-align: top")
                td.add_style("width: 75px")

                thumb_div = DivWdg()
                td.add(thumb_div)
                thumb_div.add_style("overflow: hidden")

                thumb = ThumbWdg()
                thumb_div.add(thumb)
                thumb.set_sobject(login_sobj)
                thumb.set_icon_size(60)


                display_name = login_sobj.get("display_name")

                td = table.add_cell()
                td.add_style("padding-top: 3px")
                
                name_div = DivWdg()
                td.add(name_div)
                name_div.add_style("color", "#214e75")
                name_div.add_style("font-size", "1.3em")
                name_div.add(display_name)


            msg = "";
            msg += "<table style='margin-top: 5px; font-size: 1.0em; width: 100%'>";


            if date_str != last_date:
                msg += "<tr><td colspan='2' style='text-align: right'><br/><b style='font-size: 1.0em'>"+date_str+"</b></td></tr>";
                last_login = None

            msg += "<tr><td>"
            msg += message.replace("\n",'<br/>')
            msg += "</td><td style='vertical-align: top; text-align: right; margin-bottom: 5px; width: 75px; vertical-align: top; opacity: 0.7;'>";
            msg += timestamp_str;
            msg += "</td></tr></table>";

            td.add(msg)

            

            last_login = login
            last_date = date_str

        history_div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            bvr.src_el.scrollTop = bvr.src_el.scrollHeight;
            '''
        } )


        if message_logs:
            last_message = message_logs[-1].get("message")
            last_login = message_logs[-1].get("login")
        else:
            last_message = ""
            last_login = ""
        div.add_attr("spt_last_message", last_message)
        div.add_attr("spt_last_login", last_login)




        if interval:

            div.add_behavior( {
            'type': 'load',
            'key': key,
            'cbjs_action': r'''
            var text_el = bvr.src_el.getElement(".spt_chat_text");
            var history_el = bvr.src_el.getElement(".spt_chat_history");
            var callback = function(message) {
                //history_el.setStyle("background", "red");
                var login = message.login;
                var timestamp = message.timestamp;
                if (timestamp) {
                    var parts = timestamp.split(" ");
                    parts = parts[1].split(".");
                    timestamp = parts[0];
                }
                else {
                    timestamp = "";
                }

                var tmp = message.message || "";

                var last_message = bvr.src_el.getAttribute("spt_last_message");
                var last_login = bvr.src_el.getAttribute("spt_last_login");
                if (tmp == last_message && login == last_login) {
                    return;
                }
                bvr.src_el.setAttribute("spt_last_message", tmp);
                bvr.src_el.setAttribute("spt_last_login", login);

                var msg = "";
                msg += "<table style='margin-top: 5px; font-size: 1.0em; width: 100%'><tr><td>";
                if (login != last_login) {
                    msg += "<b>"+login+"</b><br/>";
                }
                msg += tmp.replace(/\n/g,'<br/>');
                msg += "</td><td style='text-align: right; margin-bottom: 5px; width: 75px; vertical-align: top'>";
                msg += timestamp;
                msg += "</td></tr></table>";

                if (msg == history_el.last_msg) {
                    return;
                }
                history_el.innerHTML =  history_el.innerHTML + msg;

                // remember last message
                history_el.last_msg = msg;


                history_el.scrollTop = history_el.scrollHeight;
            }
            spt.message.set_interval(bvr.key, callback, 3000, bvr.src_el);
            '''
            } )

        text = TextAreaWdg("chat")
        div.add(text)
        text.add_class("spt_chat_text")
        text.add_style("width: 100%")
        text.add_style("padding: 5px")
        #text.add_style("margin-top: -1px")
        text.add_style("margin-top: 5px")
        
        text.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        bvr.src_el.addEvent("keydown", function(e) {

        var keys = ['tab','keys(control+enter)', 'enter'];
        var key = e.key;
        var input = bvr.src_el
        if (keys.indexOf(key) > -1) e.stop();

        if (key == 'tab') {
        }
        else if (key == 'enter') {
            if (e.control == false) {
                pass;
            }
            else {
                 // TODO: check if it's multi-line first 
                 //... use ctrl-ENTER for new-line, regular ENTER (RETURN) accepts value
                //var tvals = parse_selected_text(input);
                //input.value = tvals[0] + "\\n" + tvals[1];
                //spt.set_cursor_position( input, tvals[0].length + 1 );
            }
        }
        } )
        '''
        } )



        button = ActionButtonWdg(title="Send")
        div.add(button)
        button.add_style("float: right")
        button.add_style("margin: 5px")
        button.add_behavior( {
        'type': 'click_up',
        'key': key,
        'cbjs_action': '''

        var top = bvr.src_el.getParent(".spt_chat_session_top");
        var text_el = top.getElement(".spt_chat_text");
        var message = text_el.value;
        if (!message) {
            return;
        }

        var history_el = top.getElement(".spt_chat_history");

        var category = "chat";
        var server = TacticServerStub.get();

        var key = bvr.key;
        var last_message = server.log_message(key, message, {category:category, status:"in_progress"});

        text_el.value = "";

            '''
        } )

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


        return div
Example #36
0
    def get_display(my):

        top = my.top

        #help_div = DivWdg()
        help_div = top
        #top.add(help_div)
        help_div.add_class("spt_help_top")
        help_div.set_id("spt_help_top")

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

        if show_title:
            title_wdg = DivWdg()
            help_div.add(title_wdg)
            title_wdg.add_style("font-size: 12px")
            title_wdg.add_style("font-weight: bold")
            title_wdg.add_color("background", "background", -10)
            title_wdg.add_style("padding: 3px")
            #title_wdg.add_style("margin-top: 8px")
            title_wdg.add_style("margin-bottom: 5px")
            title_wdg.add_style("height: 26px")
            title_wdg.add_style("padding: 6 0 0 6")
            title_wdg.set_round_corners(corners=['TL','TR'])

            icon = IconWdg("Close", IconWdg.KILL)
            title_wdg.add(icon)
            icon.add_style("float: right")
            title_wdg.add("Help")



        help_div.set_round_corners()
        help_div.add_color("color", "color2")
        help_div.add_color("background", "background")
        help_div.add_style("overflow: hidden")
        help_div.add_border()



        shelf_div = DivWdg()
        help_div.add(shelf_div)
        shelf_div.add_style("padding: 10px")
        shelf_div.add_color("background", "background", -10)
        shelf_div.add_style("height: 25px")


        #button = SingleButtonWdg(title="Documentation Main Page", icon=IconWdg.HOME)
        button = IconButtonWdg(title="Documentation Main Page", icon="BS_HOME")
        shelf_div.add(button)
        button.add_style("float: left")
        button.add_style("margin: 0px 10px")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        spt.help.set_top();
        spt.help.load_alias("main")
        '''
        } )




        #button = SingleButtonWdg(title="Edit Help", icon=IconWdg.EDIT)
        if my.show_add_new:
            button = IconButtonWdg(title="Add New Help", icon="BS_EDIT")
            shelf_div.add(button)
            button.add_style("float: left")
            button.add_style("margin: 0px 10px")
            button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tab.set_main_body_tab();
            var class_name = 'tactic.ui.app.HelpEditWdg';

            var element_name = spt.help.get_view();
            if (!element_name) {
              element_name = "default";
            }
            var kwargs = {
              view: element_name
            }

            spt.tab.add_new("help_edit", "Help Edit", class_name, kwargs);
                
            '''
            } )



        #button = SingleButtonWdg(title="Go Back One Page", icon=IconWdg.ARROW_LEFT)
        button = IconButtonWdg(title="Go Back One Page", icon="BS_CIRCLE_ARROW_LEFT")
        shelf_div.add(button)
        button.add_style("float: left")
        button.add_style("margin: 0px 10px")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        spt.help.set_top();
        spt.help.load_prev();
        '''
        } )

        #button = SingleButtonWdg(title="Go Forward One Page", icon=IconWdg.ARROW_RIGHT)
        button = IconButtonWdg(title="Go Forward One Page", icon="BS_CIRCLE_ARROW_RIGHT")
        shelf_div.add(button)
        button.add_style("float: left")
        button.add_style("margin: 0px 10px")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        spt.help.set_top();
        spt.help.load_next();
        '''
        } )



        #button = SingleButtonWdg(title="Documentation Downloads", icon=IconWdg.DOWNLOAD)
        button = IconButtonWdg(title="Documentation Downloads", icon="BS_DOWNLOAD")
        shelf_div.add(button)
        button.add_style("float: right")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        spt.help.set_top();
        spt.help.load_alias("pdf")
        '''
        } )


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



        help_div.add_behavior( {
        'type': 'load',
        'cbjs_action': my.get_onload_js()
        })


        help_div.add_behavior( {
        'type': 'listen',
        'event_name': 'tab|select',
        'cbjs_action': '''

        var content = bvr.src_el.getElement(".spt_help_content");
        var options = bvr.firing_data;
        var element_name = options.element_name;
        var alias = options.alias;

        if (!alias) {
            alias = options.element_name;
        }

        spt.help.set_top();
        if (spt.help.is_visible()) {
            spt.help.load_alias(alias);
        }
        else {
            spt.help.set_view(alias);
        }
        '''

        } )


        help_div.add_behavior( {
        'type': 'listen',
        'event_name': 'show_help',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_help");
        var content = top.getElement(".spt_help_content");
        var firing_data = bvr.firing_data;
        var class_name = firing_data.class_name;
        if (!class_name) {
            class_name = 'tactic.ui.app.HelpContentWdg';
        }

        if (top.getStyle("display") != 'none') {
            spt.hide(top);
            return;
        }

        spt.help.set_top()

        // get the help view
        var help_view = spt.help.get_view();
        var html = firing_data.html;
        if (html) {
            spt.help.load_html(html);    
        }
        else {
            if (!help_view) {
                help_view = 'default'    
            }
            spt.help.load_alias(help_view);
        }

        var size = $(window).getSize();

        var dialog = bvr.src_el.getParent(".spt_dialog_content");

        dialog.setStyle("height", size.y - 100);
        dialog.setStyle("width", 650);

        var top = bvr.src_el.getParent(".spt_dialog_top");
        top.setStyle("left", size.x - 660);
        top.setStyle("top", 40);

        spt.show(top);
        '''
        } )






        content = DivWdg()
        help_div.add(content)
        content.add_class("spt_help_content");
        content.add_style("position: relative")
        content.add_style("overflow_x: auto")
        content.add_style("overflow_y: auto")
        content.add_style("margin-bottom: 10px")
        #content.add_style("border: solid 1px blue")
        content.add_style("height: 98%")


        #key = "schema_editor"
        #search = Search("config/doc")
        #search.add_filter("code", key)
        #doc = search.get_sobject()
        #doc_html = doc.get_value("doc")
        #help_div.add(doc_html)


        return top
Example #37
0
    def get_header_wdg(my):

        div = DivWdg()

        if my.collection_key:

            button = IconButtonWdg(title='Remove Selected Items from Collection', icon="BS_MINUS")
            div.add(button)
            button.add_style("display: inline-block")
            button.add_style("vertical-align: top")

            button.add_behavior( {
                'type': 'click_up',
                'collection_key': my.collection_key,
                'cbjs_action': '''
                var search_keys = spt.table.get_selected_search_keys(false);

                if (search_keys.length == 0) {
                    spt.notify.show_message("Nothing selected to remove");
                    return;
                }
                var ok = null;
                var cancel = function() { return };
                var msg = "Are you sure you wish to remove the selected Assets from the Collection?";

                var ok = function() {
                    var cls = 'tactic.ui.panel.CollectionRemoveCmd';
                    var kwargs = {
                        collection_key: bvr.collection_key,
                        search_keys: search_keys,
                    }
                    var server = TacticServerStub.get();
                    try {
                        server.execute_cmd(cls, kwargs);
                        spt.table.remove_selected();
                    } catch(e) {
                        spt.alert(spt.exception.handler(e));
                    }
                }
                
                spt.confirm(msg, ok, cancel);

                '''
            } )



            button = IconButtonWdg(title='Delete Collection', icon="BS_TRASH")
            #button = ActionButtonWdg(title='Delete Collection', icon="BS_TRASH")
            div.add(button)
            button.add_style("display: inline-block")
            button.add_style("vertical-align: top")

            button.add_behavior( {
                'type': 'click_up',
                'collection_key': my.collection_key,
                'cbjs_action': '''
                var ok = null;
                var cancel = function() { return };
                var msg = "Are you sure you wish to delete the Collection?";

                var ok = function() {
                    var cls = 'tactic.ui.panel.CollectionDeleteCmd';
                    var kwargs = {
                        collection_key: bvr.collection_key,
                    }
                    var server = TacticServerStub.get();
                    try {
                        server.execute_cmd(cls, kwargs);
                    } catch(e) {
                        spt.alert(e);
                        return;
                    }

                    var top = bvr.src_el.getParent(".spt_collection_top");
                    if (top) {
                        var layout = top.getParent(".spt_layout");
                        spt.table.set_layout(layout);
                    }

                    spt.table.run_search();
                }

                spt.confirm(msg, ok, cancel);
                '''
            } )



        """
        button = IconButtonWdg(title='Download Selected Items', icon="BS_DOWNLOAD")
        div.add(button)
        button.add_style("display: inline-block")
        button.add_style("vertical-align: top")

        text_div = DivWdg()
        div.add(text_div)
        text_div.add_style("width: 200px")
        text = LookAheadTextInputWdg(
            name="name",
            icon="BS_SEARCH",
            icon_pos="right",
            width="100%"
        ) 
        text_div.add(text)
        text_div.add_style("display: inline-block")
        """

        div.add_style("width: auto")
        div.add_style("float: right")

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


        return div
Example #38
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)
        buttons.add_cell(button)

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

        sobject = my.get_current_sobject()

        use_parent = my.get_option("use_parent")
        use_parent = use_parent in ['true', True]
        #if use_parent in ['true', True]:
        #    sobject = sobject.get_parent()
        #    if not sobject:
        #        return DivWdg()

        my.search_key = SearchKey.get_by_sobject(sobject)

        div = DivWdg()
        div.add_class("hand")
        div.add_style("width: 26px")
        div.add_style("margin-left: auto")
        div.add_style("margin-right: auto")

        target_id = "main_body"

        title = "Show Item Details"
        if my.widget:
            widget = my.widget
        else:
            widget = IconButtonWdg(title=title, icon="BS_SEARCH")

        code = sobject.get_code()
        name = sobject.get_value("name", no_exception=True)
        if not name:
            name = code

        tab_element_names = my.kwargs.get("tab_element_names") or ""
        detail_view = my.kwargs.get("detail_view") or ""

        widget.add_behavior({
            'type':
            'click_up',
            'search_key':
            my.search_key,
            'use_parent':
            use_parent,
            'tab_element_names':
            tab_element_names,
            'detail_view':
            detail_view,
            'show_task_process':
            my.show_task_process,
            'code':
            code,
            'name':
            name,
            'cbjs_action':
            '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.tools.SObjectDetailWdg';
        var kwargs = {
            search_key: bvr.search_key,
            use_parent: bvr.use_parent,
            tab_element_names: bvr.tab_element_names,
            show_task_process: bvr.show_task_process,
            detail_view: bvr.detail_view
        };

        var mode = '';
        var layout = bvr.src_el.getParent(".spt_tool_top");
        if (layout != null) {
            mode = 'tool'
        }

        if (mode == 'tool') {
            spt.app_busy.show("Loading ...");
            var layout = bvr.src_el.getParent(".spt_tool_top");
            var element = layout.getElement(".spt_tool_content");
            spt.panel.load(element, class_name, kwargs);
            spt.app_busy.hide();
        }
        else {
            var element_name = "detail_"+bvr.code;
            var title = "Detail ["+bvr.name+"]";
            spt.tab.add_new(element_name, title, class_name, kwargs);
        }
        '''
        })

        #link_wdg = my.get_link_wdg(target_id, title, widget)
        #div.add( link_wdg )
        div.add(widget)

        return div
Example #40
0
    def get_category_wdg(my, category, mode="new"):

        subscriptions = my.get_subscriptions(category, mode)
        if not subscriptions:
            return

        div = DivWdg()
        div.add_style("width: 100%")

        title_div = DivWdg()
        div.add(title_div)
        title_div.add_style("padding: 10px")
        title_div.add_border()
        title_div.add_color("background", "background3")
        title = category or "Subscriptions"
        title_div.add("%s " % title)
        

        summary_div = SpanWdg()
        title_div.add(summary_div)
        summary_div.add_style("font-size: 0.8em")
        summary_div.add_style("opacity: 0.5")


        search_keys = [x.get_search_key() for x in subscriptions]
        button = ActionButtonWdg(title="Clear All")
        div.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'search_keys': search_keys,
            'cbjs_action': '''
            var server = TacticServerStub.get();
            for (var i = 0; i < bvr.search_keys.length; i++) {
                var search_key = bvr.search_keys[i];
                server.update(search_key, {'last_cleared':'NOW'});
            spt.panel.refresh(bvr.src_el);
            }
            '''
        } )



        # types of subscriptions

        table = Table()
        table.add_style("width: 100%")
        table.add_border()
        table.add_color("background", "background3")


        div.add(table)
        ss = []
        for subscription in subscriptions:
            table.add_row()
            td = table.add_cell()

            message_code = subscription.get_value("message_code")

            search = Search("sthpw/message")
            search.add_filter("code", message_code)
            message = search.get_sobject()

            # show the thumb
            if not message:
                if mode == "all":
                    td = table.add_cell(my.get_preview_wdg(subscription))

                    td = table.add_cell()
                    td.add("No Messages")
                continue

            size = 60

            category = message.get_value("category")
            td = table.add_cell()
            td.add( my.get_preview_wdg(subscription) )


            #td = table.add_cell(message_code)

            message_value = message.get_value("message")
            if message_value.startswith("{") and message_value.endswith("}"):

                # FIXME: this is needed because the json has some bad
                # \\ issues. 
                message_value = message_value.replace(r"\\", "\\");
                message_value = jsonloads(message_value)
                update_data = message_value.get("update_data")

                if category == "sobject":
                    search_type = message_value.get("search_type")
                    if search_type == "sthpw/note":
                        description = "<b>Note Added:</b><br/>%s" % update_data.get("note")
                    elif search_type == "sthpw/task":
                        description = "<b>Task modified:</b><br/>%s" % update_data.get("process")
                    elif search_type == "sthpw/snapshot":
                        sobject = message_value.get("sobject")
                        description = "<b>Files Checked In:</b><br/>%s" % sobject.get("process")
                    else:
                        description = "<b>Data modified:</b><br/>%s" % update_data


                else:
                    description = message_value.get("description")


            else:

                if category == "chat":
                    login = message.get("login")
                    timestamp = message.get("timestamp")

                    message_value = message.get("message")
                    message_value = message_value.replace("\n", "<br/>")

                    description = '''
                    <b>%s</b><br/>
                    %s
                    ''' % (login, message_value)
                else:
                    description = message_value


            td = table.add_cell()
            icon = IconButtonWdg(title="Subscription History", icon=IconWdg.HISTORY)
            td.add(icon)
            subscription_key = subscription.get_search_key()
            message_code = subscription.get_value("message_code")
            icon.add_behavior( {
                'type': 'click_up',
                'message_code': message_code,
                'cbjs_action': '''
                var class_name = 'tactic.ui.panel.FastTableLayoutWdg';
                var message_code = bvr.message_code;
                alert(message_code);
                var kwargs = {
                    search_type: 'sthpw/message_log',
                    show_shelf: false,
                    expression: "@SOBJECT(sthpw/message_log['message_code','"+message_code+"'])",
                };
                spt.tab.set_main_body_tab();
                spt.tab.add_new("Message History", "Message History", class_name, kwargs);
                '''
            } )
 

            td = table.add_cell()

            desc_div = DivWdg()
            td.add(desc_div)
            desc_div.add(description)
            desc_div.add_style("padding: 0px 20px")
            desc_div.add_style("max-width: 600px")

            td = table.add_cell()
            #td.add(message.get_value("status"))
            #td = table.add_cell()
            timestamp = message.get_datetime_value("timestamp")
            if timestamp:
                timestamp_str = timestamp.strftime("%b %d, %Y - %H:%M")
            else:
                timestamp_str = ""
            td.add(timestamp_str)

            #td = table.add_cell()
            #td.add(subscription.get_value("last_cleared"))

            td = table.add_cell()
            icon = IconButtonWdg(title="Unsubscribe", icon=IconWdg.DELETE)
            td.add(icon)
            subscription_key = subscription.get_search_key()
            icon.add_behavior( {
                'type': 'click_up',
                'search_key': subscription_key,
                'cbjs_action': '''
                    if (!confirm("Confirm subscription delete?")) {
                        return;
                    }
                    var top = bvr.src_el.getParent(".spt_subscription_top");
                    var server = TacticServerStub.get();
                    server.delete_sobject(bvr.search_key);
                    spt.panel.refresh(top);
                '''
            } )






            ss.append(subscription)

        num_sobjects = len(ss)
        if not num_sobjects:
            return None
        summary_div.add("(%s changes)" % num_sobjects)

        #from tactic.ui.panel import FastTableLayoutWdg
        #table = FastTableLayoutWdg(search_type="sthpw/subscription",show_shelf=False)
        #div.add(table)
        #table.set_sobjects(ss)


        return div
    def get_title(my):

        div = DivWdg()
        div.add_behavior({'type': 'load', 'cbjs_action': my.get_onload_js()})
        # for csv export
        hid = HiddenWdg('start_date', my.start_date)
        div.add(hid)

        mday = my.today.strftime("%d")
        mmonth = my.today.strftime("%m")

        my.weekday_dict = {}
        days = []
        for idx, date in enumerate(my.dates):
            day_div = DivWdg()
            days.append(day_div)
            week_day = date.strftime("%a")
            day_div.add("%s<br/>%s" % (week_day, date.strftime("%d")))
            my.weekday_dict[idx] = week_day

        table = Table()
        div.add(table)
        table.add_row()
        table.add_color("color", "color")
        table.add_style("width: %spx" % my.table_width)
        table.add_style("float: left")

        month_div = FloatDivWdg(my.start_date.strftime("%b"))
        month_div.add_style('font-weight: 600')
        td = table.add_cell(month_div)
        td.add_style('width', '%spx' % my.MONTH_WIDTH)

        icon = IconButtonWdg(tip="Previous Week", icon=IconWdg.LEFT)
        td = table.add_cell(icon)
        offset = 0
        if not my.use_straight_time:
            offset = 12
        td.add_style("width: %spx" % (my.LEFT_WIDTH + offset))

        display_days = my.days_per_page
        next_start_date = my.start_date + datetime.timedelta(days=display_days)
        prev_start_date = my.start_date + datetime.timedelta(
            days=-display_days)

        icon.add_behavior({
            'type':
            'click_up',
            'start_date':
            prev_start_date.__str__(),
            'cbjs_action':
            '''
           spt.app_busy.show('Loading previous week...');
           var header = bvr.src_el.getParent('.spt_table_header');
           if (!header) {
                spt.alert('Work hour widget requires the new Fast Table Layout to scroll to previous week. You can do so in [Manage Side Bar].');
                spt.app_busy.hide();
                return;
           } 
           var cur_name = spt.table.get_element_name_by_header(header);
           var values = {'start_date': bvr.start_date};
           spt.table.refresh_column(cur_name, values);

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

        for day in days:
            day_wdg = DivWdg()
            day_wdg.add(day)

            td = table.add_cell()
            td.add(day_wdg)
            td.add_styles(
                "text-align: center; padding-left: 2px;min-width: %spx" %
                my.day_width)

        icon = IconButtonWdg(tip="Next Week", icon=IconWdg.RIGHT)
        icon.add_behavior({
            'type':
            'click_up',
            'start_date':
            next_start_date.__str__(),
            'cbjs_action':
            '''
           spt.app_busy.show('Loading next week...');
           var header = bvr.src_el.getParent('.spt_table_header');
           if (!header) {
                spt.alert('Work hour widget requires the new Fast Table Layout to scroll to next week. You can do so in [Manage Side Bar].');
                spt.app_busy.hide();
                return;
           } 
           var cur_name = spt.table.get_element_name_by_header(header);
           var values = {'start_date': bvr.start_date};
           spt.table.refresh_column(cur_name, values);
           spt.app_busy.hide();

        
        '''
        })
        td = table.add_cell(icon)
        td.add_style('width: %spx' % my.day_width)
        # empty total cell
        td = table.add_blank_cell()
        td.add_style('width: 100%')

        return div
Example #42
0
    def get_title(my):

        div = DivWdg()
        div.add_behavior({'type': 'load',
            'cbjs_action': my.get_onload_js()})
        # for csv export
        hid = HiddenWdg('start_date', my.start_date)
        div.add(hid)

        mday = my.today.strftime("%d")
        mmonth = my.today.strftime("%m")
        
        my.weekday_dict = {}
        days = []
        for idx, date in enumerate(my.dates):
            day_div = DivWdg()
            days.append( day_div )
            week_day = date.strftime("%a")
            day_div.add( "%s<br/>%s" % (week_day, date.strftime("%d") ))
            my.weekday_dict[idx] = week_day

        table = Table()
        div.add(table)
        table.add_row()
        table.add_color("color", "color")
        table.add_style("width: %spx"%my.table_width)
        table.add_style("float: left")
        
        month_div = FloatDivWdg(my.start_date.strftime("%b"))
        month_div.add_style('font-weight: 600')
        td = table.add_cell(month_div)
        td.add_style('width', '%spx'%my.MONTH_WIDTH)

        icon = IconButtonWdg(tip="Previous Week", icon=IconWdg.LEFT)
        td = table.add_cell(icon)
        offset = 0
        if not my.use_straight_time:
            offset = 12
        td.add_style("width: %spx" % (my.LEFT_WIDTH + offset) )
        
        display_days = my.days_per_page
        next_start_date = my.start_date + datetime.timedelta(days=display_days)
        prev_start_date = my.start_date + datetime.timedelta(days=-display_days)


        icon.add_behavior( {
        'type': 'click_up',
        'start_date': prev_start_date.__str__(),
        'cbjs_action': '''
           spt.app_busy.show('Loading previous week...');
           var header = bvr.src_el.getParent('.spt_table_header');
           if (!header) {
                spt.alert('Work hour widget requires the new Fast Table Layout to scroll to previous week. You can do so in [Manage Side Bar].');
                spt.app_busy.hide();
                return;
           } 
           var cur_name = spt.table.get_element_name_by_header(header);
           var values = {'start_date': bvr.start_date};
           spt.table.refresh_column(cur_name, values);

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

        for day in days:
            day_wdg = DivWdg()
            day_wdg.add(day)

            td = table.add_cell()
            td.add(day_wdg)
            td.add_styles("text-align: center; padding-left: 2px;min-width: %spx"%my.day_width)

        icon = IconButtonWdg(tip="Next Week", icon=IconWdg.RIGHT)
        icon.add_behavior( {
        'type': 'click_up',
        'start_date': next_start_date.__str__(),
        'cbjs_action': '''
           spt.app_busy.show('Loading next week...');
           var header = bvr.src_el.getParent('.spt_table_header');
           if (!header) {
                spt.alert('Work hour widget requires the new Fast Table Layout to scroll to next week. You can do so in [Manage Side Bar].');
                spt.app_busy.hide();
                return;
           } 
           var cur_name = spt.table.get_element_name_by_header(header);
           var values = {'start_date': bvr.start_date};
           spt.table.refresh_column(cur_name, values);
           spt.app_busy.hide();

        
        '''
        } )
        td = table.add_cell(icon)
        td.add_style('width: %spx'%my.day_width)
        # empty total cell
        td = table.add_blank_cell()
        td.add_style('width: 100%')

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

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

        self.last_path = None

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

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


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

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

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

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


        self.column = "description"

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

        #table = Table()
        table = ResizableTableWdg()

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

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


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

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


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


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


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

        #title.add(path)


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

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

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

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

                f.write(text)
                f.close()

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

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

                    if last_text != text:

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

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

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


            lines = text.split("\n") 

            if self.doc_mode == "text":

                num_lines = len(lines)

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



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

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


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


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

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

                    td = line_table.add_cell()

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

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

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




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



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

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

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

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


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

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






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



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


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

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


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

spt.document = {};

spt.document.selected_text = null;

spt.document.get_selected_text = function(frame)
{

    var t = '';

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

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

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

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

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

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

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




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

        web = WebContainer.get_web()

        widget = Widget()
        html = HtmlElement("html")


        is_xhtml = False
        if is_xhtml:
            web.set_content_type("application/xhtml+xml")
            widget.add('''<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            ''')
            html.add_attr("xmlns", "http://www.w3.org/1999/xhtml")
            #html.add_attr("xmlns:svg", "http://www.w3.org/2000/svg")


        # add the copyright
        widget.add( my.get_copyright_wdg() )
        widget.add(html)


        # create the header
        head = HtmlElement("head")
        html.add(head)

        head.add('<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n')
        head.add('<meta http-equiv="X-UA-Compatible" content="IE=edge"/>\n')

        # Add the tactic favicon
        head.add('<link rel="shortcut icon" href="/context/favicon.ico" type="image/x-icon"/>')

        # add the css styling
        head.add(my.get_css_wdg())

        # add the title in the header
        project = Project.get()
        project_code = project.get_code()
        project_title = project.get_value("title")

        if web.is_admin_page():
            is_admin = " - Admin"
        else:
            is_admin = ""

        if project_code == 'admin':
            head.add("<title>TACTIC Site Admin</title>\n" )
        else:
            head.add("<title>%s%s</title>\n" % (project_title, is_admin) )


        # add the javascript libraries
        head.add( JavascriptImportWdg() )



        # add the body
        body = my.body
        html.add( body )


        # Add a NOSCRIPT tag block here to provide a warning message on browsers where 'Enable JavaScript'
        # is not checked ... TODO: clean up and re-style to make look nicer
        body.add( """
        <NOSCRIPT>
        <div style="border: 2px solid black; background-color: #FFFF99; color: black; width: 600px; height: 70px; padding: 20px;">
        <img src="%s" style="border: none;" /> <b>Javascript is not enabled on your browser!</b>
        <p>This TACTIC powered, web-based application requires JavaScript to be enabled in order to function. In your browser's options/preferences, please make sure that the 'Enable JavaScript' option is checked on, click OK to accept the settings change, and then refresh this web page.</p>
        </div>
        </NOSCRIPT>
        """ % ( IconWdg.get_icon_path("ERROR") ) )




        # add the content
        if my.widgets:
            content_wdg = my.get_widget('content')
        else:
            content_wdg = Widget()
            my.add(content_wdg)
        body.add( content_wdg )

        body.add_event('onload', 'spt.onload_startup(this)')


        if web.is_admin_page():
            from tactic_branding_wdg import TacticCopyrightNoticeWdg
            branding = TacticCopyrightNoticeWdg(show_license_info=True)
            body.add(branding)


        # add the admin bar
        security = Environment.get_security()
        if not web.is_admin_page() and security.check_access("builtin", "view_site_admin", "allow"):

            div = DivWdg()
            body.add(div)
            body.add_style("padding-top: 21px")

            div.add_class("spt_admin_bar")

            div.add_style("height: 15px")
            div.add_style("padding: 3px 0px 3px 15px")
            #div.add_style("margin-bottom: -5px")
            div.add_style("position: fixed")
            div.add_style("top: 0px")
            div.add_style("left: 0px")
            div.add_style("opacity: 0.7")
            div.add_style("width: 100%")
            #div.add_gradient("background", "background2", 20, 10)
            div.add_style("background-color", "#000")
            div.add_style("color", "#FFF")
            div.add_style("z-index", "1000")
            div.add_class("hand")
            div.set_box_shadow("0px 5px 5px")

            # remove
            icon_div = DivWdg()
            div.add(icon_div)
            icon_div.add_style("float: right")
            icon_div.add_style("margin-right: 10px")
            icon_div.add_style("margin-top: -3px")
            icon_button = IconButtonWdg(title="Remove Admin Bar", icon=IconWdg.POPUP_WIN_CLOSE)
            icon_div.add(icon_button)
            icon_button.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                var parent = bvr.src_el.getParent(".spt_admin_bar");
                spt.behavior.destroy_element(parent);
                $(document.body).setStyle("padding-top", "0px");
                '''
            } )



            div.add("<b>ADMIN >></b>")


            div.add_behavior( {
                'type': 'listen',
                'event_name': 'close_admin_bar',
                'cbjs_action': '''
                spt.behavior.destroy_element(bvr.src_el);
                $(document.body).setStyle("padding-top", "0px");
                '''
            } )

            div.add_behavior( {
                'type': 'mouseover',
                'cbjs_action': '''
                bvr.src_el.setStyle("opacity", 0.85)
                //new Fx.Tween(bvr.src_el).start('height', "30px");
                '''
            } )
            div.add_behavior( {
                'type': 'mouseout',
                'cbjs_action': '''
                bvr.src_el.setStyle("opacity", 0.7)
                //new Fx.Tween(bvr.src_el).start('height', "15px");
                '''
            } )
            project_code = Project.get_project_code()
            div.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                var url = "/tactic/%s/link/_startup";
                window.open(url);

                ''' % project_code
            } )





        # Add the script editor listener
        load_div = DivWdg()
        body.add(load_div)
        load_div.add_behavior( {
        'type': 'listen',
        'event_name': 'show_script_editor',
        'cbjs_action': '''
        var js_popup_id = "TACTIC Script Editor";
        var js_popup = $(js_popup_id);
        if( js_popup ) {
            spt.popup.toggle_display( js_popup_id, false );
        }
        else {
            spt.panel.load_popup(js_popup_id, "tactic.ui.app.ShelfEditWdg", {}, {"load_once": true} );
        }
        '''} )



        # deal with the palette defined in /index which can override the palette
        if my.kwargs.get("hash") == ():
            key = "index"
            search = Search("config/url")
            search.add_filter("url", "/%s/%%"%key, "like")
            search.add_filter("url", "/%s"%key)
            search.add_where("or")
            url = search.get_sobject()
            if url:
                xml = url.get_xml_value("widget")
                palette_key = xml.get_value("element/@palette")

                # look up palette the expression for index
                from pyasm.web import Palette
                palette = Palette.get()

                palette.set_palette(palette_key)
                colors = palette.get_colors()
                colors = jsondumps(colors)

                script = HtmlElement.script('''
                    var env = spt.Environment.get();
                    env.set_colors(%s);
                    env.set_palette('%s');
                    ''' % (colors, palette_key)
                )
                body.add(script)


        env = Environment.get()
        client_handoff_dir = env.get_client_handoff_dir(include_ticket=False, no_exception=True)
        client_asset_dir = env.get_client_repo_dir()

        login = Environment.get_login()
        user_name = login.get_value("login")
        user_id = login.get_id()
        login_groups = Environment.get_group_names()


        # add environment information
        script = HtmlElement.script('''
        var env = spt.Environment.get();
        env.set_project('%s');
        env.set_user('%s');
        env.set_user_id('%s');
        var login_groups = '%s'.split('|');
        env.set_login_groups(login_groups);
        env.set_client_handoff_dir('%s');
        env.set_client_repo_dir('%s');

        ''' % (Project.get_project_code(), user_name, user_id, '|'.join(login_groups), client_handoff_dir,client_asset_dir))
        body.add(script)


        # add a global container for commonly used widgets
        div = DivWdg()
        body.add(div)
        div.set_id("global_container")

        # add in the app busy widget
        # find out if there is an override for this
        search = Search("config/url")
        search.add_filter("url", "/app_busy")
        url = search.get_sobject()
        if url:
            busy_div = DivWdg()
            div.add(busy_div)

            busy_div.add_class( "SPT_PUW" )
            busy_div.add_styles( "display: none; position: absolute; z-index: 1000" )

            busy_div.add_class("app_busy_msg_block")
            busy_div.add_style("width: 300px")
            busy_div.add_style("height: 100px")
            busy_div.add_style("padding: 20px")
            busy_div.add_color("background", "background3")
            busy_div.add_border()
            busy_div.set_box_shadow()
            busy_div.set_round_corners(20)
            busy_div.set_attr("id","app_busy_msg_block")



            # put the custom url here

            title_wdg = DivWdg()
            busy_div.add(title_wdg)
            title_wdg.add_style("font-size: 20px")
            title_wdg.add_class("spt_app_busy_title")
            busy_div.add("<hr/>")
            msg_div = DivWdg()
            busy_div.add(msg_div)
            msg_div.add_class("spt_app_busy_msg")
 

        else:
            from page_header_wdg import AppBusyWdg
            div.add( AppBusyWdg() )


        # popup parent
        popup = DivWdg()
        popup.set_id("popup")
        div.add(popup)

        # create another general popup
        popup_div = DivWdg()
        popup_div.set_id("popup_container")
        popup_div.add_class("spt_panel")
        popup = PopupWdg(id="popup_template",destroy_on_close=True)
        popup_div.add(popup)
        div.add(popup_div)


        # popup parent
        inner_html_div = DivWdg()
        inner_html_div.set_id("inner_html")
        div.add(inner_html_div)


        # add in a global color
        from tactic.ui.input import ColorWdg
        color = ColorWdg()
        div.add(color)

        # add in a global notify wdg
        from notify_wdg import NotifyWdg
        widget.add(NotifyWdg())


        return widget
Example #45
0
    def get_display(my):

        top = my.top
        top.add_class("spt_changelist_content")
        my.set_as_panel(top)
        top.add_color("color", "color")
        top.add_color("background", "background")
        #top.add_border()
        #top.add_style("padding", "10px")
        top.add_style("min-width: 600px")
        top.add_style("min-height: 400px")

        top.add_behavior({'type': 'load', 'cbjs_action': scm_get_onload_js()})

        sync_dir = Environment.get_sandbox_dir()
        # HARD CODED
        project = Project.get()
        depot = project.get_value("location", no_exception=True)
        if not depot:
            depot = project.get_code()
        location = '//%s' % depot

        changelist = my.kwargs.get("changelist")
        if not changelist:
            changelist = WidgetSettings.get_value_by_key("current_changelist")
        else:
            WidgetSettings.set_value_by_key("current_changelist", changelist)

        if not changelist:
            changelist = 'default'

        changelists = my.kwargs.get("changelists")
        if not changelists:
            changelists = []
        elif isinstance(changelists, basestring):
            changelists = changelists.replace("'", '"')
            changelists = jsonloads(changelists)

        top.add_behavior({
            'type':
            'load',
            'sync_dir':
            sync_dir,
            'depot':
            depot,
            'cbjs_action':
            '''
            spt.scm.sync_dir = bvr.sync_dir;
            spt.scm.depot = bvr.depot;
            '''
        })

        inner = DivWdg()
        top.add(inner)

        table = Table()
        inner.add(table)
        table.add_style("width: 100%")
        table.add_color("background", "background", -3)

        table.add_row()
        th = table.add_header("")

        th = table.add_header("Changelist")
        th.add_style("text-align: left")
        th = table.add_header("Description")
        th.add_style("text-align: left")
        th = table.add_header("# Items")
        th.add_style("text-align: left")
        th = table.add_header("Status")
        th.add_style("text-align: left")
        th = table.add_header("View")
        th.add_style("text-align: left")
        th = table.add_header("Delete")
        th.add_style("text-align: left")
        #table.set_unique_id()
        #table.add_smart_styles("spt_changelist_item", {
        #    'text-align: right'
        #    } ))

        bgcolor = table.get_color("background", -8)
        table.add_relay_behavior({
            'type':
            'mouseover',
            'bvr_match_class':
            'spt_changelist_item',
            'bgcolor':
            bgcolor,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("background-color", bvr.bgcolor);
            '''
        })
        table.add_relay_behavior({
            'type':
            'mouseout',
            'bvr_match_class':
            'spt_changelist_item',
            'cbjs_action':
            '''
            bvr.src_el.setStyle("background-color", '');
            '''
        })

        table.add_relay_behavior({
            'type':
            'mouseup',
            'bvr_match_class':
            "spt_changelist_radio",
            'cbjs_action':
            '''

            var changelist = bvr.src_el.value;
            var top = bvr.src_el.getParent(".spt_changelist_content");
            top.setAttribute("spt_changelist", changelist);
            spt.app_busy.show("Loading Changelists Information");
            spt.changelist.load(bvr.src_el, changelist);
            spt.app_busy.hide();

            '''
        })

        for c in changelists:
            num_items = len(c.get("info"))
            name = c.get("change")

            tr = table.add_row()
            tr.add_class("spt_changelist_item")

            radio = RadioWdg("changelist")
            radio.add_class("spt_changelist_radio")
            table.add_cell(radio)
            radio.set_option("value", name)
            if name == changelist:
                radio.set_checked()

            table.add_cell(name)
            table.add_cell(c.get("desc"))
            table.add_cell(num_items)
            table.add_cell(c.get("status"))

            if num_items:
                icon = IconButtonWdg(title="View", icon=IconWdg.ZOOM)

                icon.add_behavior({
                    'type':
                    'click_up',
                    'changelist':
                    c.get("change"),
                    'cbjs_action':
                    '''
                    var top = bvr.src_el.getParent(".spt_changelist_content");
                    top.setAttribute("spt_changelist", bvr.changelist);

                    spt.app_busy.show("Loading Changelist");
                    spt.changelist.load(bvr.src_el, bvr.changelist);
                    spt.app_busy.hide();

                    '''
                })
            else:
                icon = ''
            table.add_cell(icon)

            if not num_items and name != 'default':
                icon = IconButtonWdg(title="Delete Changelist",
                                     icon=IconWdg.DELETE)
            else:
                icon = ""

            table.add_cell(icon)

        inner.add("<hr/>")

        files = my.kwargs.get("files")
        if isinstance(files, basestring):
            files = files.replace("'", '"')
            files = jsonloads(files)

        if files == None:
            inner.add_behavior({
                'type':
                'load',
                'location':
                location,
                'changelist':
                changelist,
                'sync_dir':
                sync_dir,
                'cbjs_action':
                '''

spt.changelist = {}
spt.changelist.load = function(el, changelist) {
    var applet = spt.Applet.get();
    var changelists = spt.scm.run("get_changelists_by_user",[]);
    var dflt = {
        'change': 'default',
        'status': 'pending'
    }
    changelists.push(dflt);
    changelists = changelists.reverse();
    for (var i = 0; i < changelists.length; i++) {
        var info = spt.scm.run("get_changelist_files",[changelists[i].change]);
        changelists[i]['info'] = info;
    }

    // get the current chnage list
    var files = spt.scm.run("get_changelist_files",[changelist]);
    var path_info = {};
    var sizes = [];
    for ( var i = 0; i < files.length; i++) {

        // FIXME: perforce specific
        var path = files[i].depotFile;
        path = path.replace(bvr.location, bvr.sync_dir);
        files[i].path = path;

        var size;
        if (applet.exists(path)) {
            var info = applet.get_path_info(path);
            size = info.size;
        }
        else {
            size = 0;
        }
        sizes.push(size);
        path_info[path] = 'editable';
    }
    //var ret_val = spt.scm.status(bvr.sync_dir);
    //console.log(ret_val);

    var class_name = 'tactic.ui.checkin.changelist_wdg.ChangelistWdg';
    var kwargs = {
        files: files,
        sizes: sizes,
        changelist: changelist,
        changelists: changelists,
        path_info: path_info,
    }
    var top = el.getParent(".spt_changelist_content");
    spt.panel.load(top, class_name, kwargs);

}
spt.changelist.load(bvr.src_el, bvr.changelist);
            '''
            })

        content = DivWdg()
        inner.add(content)
        content.add_class("spt_changelist_content")

        if files == None:

            loading_wdg = DivWdg()
            content.add(loading_wdg)
            loading_wdg.add("<b>Loading ...</b>")
            loading_wdg.add_style("padding: 30px")

        elif files:
            title_wdg = DivWdg()
            title_wdg.add_style("height: 15px")
            title_wdg.add("Changelist: [%s]" % changelist)
            content.add(title_wdg)
            title_wdg.add_gradient("background", "background", -5)
            title_wdg.add_style("padding: 5px")
            title_wdg.add_border()

            #button = SingleButtonWdg(tip='Add New Changelist', icon=IconWdg.ADD)
            #content.add(button)

            content.add("<br/>")

            paths = [x.get("path") for x in files]
            sizes = my.kwargs.get("sizes")
            path_info = my.kwargs.get("path_info")
            from scm_dir_list_wdg import ScmDirListWdg
            # dummy search_key
            search_key = "sthpw/virtual?code=xx001"
            dir_list_wdg = ScmDirListWdg(
                base_dir=sync_dir,
                paths=paths,
                sizes=sizes,
                path_info=path_info,
                all_open=True,
                #search_key=search_key
            )
            content.add(dir_list_wdg)

        else:

            content.add("Changelist: [%s]" % changelist)
            content.add("<br/>" * 2)

            no_files_wdg = DivWdg()
            content.add(no_files_wdg)
            no_files_wdg.add_style("padding: 20px")
            no_files_wdg.add_border()
            no_files_wdg.add("No files in changelist")

            no_files_wdg.add_color("color", "color3")
            no_files_wdg.add_color("background", "background3")
            no_files_wdg.add_style("font-weight: bold")
            no_files_wdg.add_style("text-align: center")

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

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

        div = DivWdg()
        div.add_class("spt_ingest_top")
        div.add_style("width: 100%px")
        div.add_style("min-width: 500px")
        div.add_style("padding: 20px")
        div.add_color("background", "background")

        my.search_type = my.kwargs.get("search_type")
        if not my.search_type:
            div.add("No search type specfied")
            return div

        if relative_dir:
            folder_div = DivWdg()
            div.add(folder_div)
            folder_div.add("Folder: %s" % relative_dir)
            folder_div.add_style("opacity: 0.5")
            folder_div.add_style("font-style: italic")
            folder_div.add_style("margin-bottom: 10px")

        data_div = my.get_data_wdg()
        data_div.add_style("float: left")
        data_div.add_style("float: left")
        div.add(data_div)

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

        help_button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''spt.help.load_alias("ingestion_widget")'''
        })

        from tactic.ui.input import Html5UploadWdg
        upload = Html5UploadWdg(multiple=True)
        div.add(upload)

        button = ActionButtonWdg(title="Add")
        button.add_style("float: right")
        button.add_style("margin-top: -3px")
        div.add(button)
        button.add_behavior({
            'type':
            'click_up',
            'normal_ext':
            File.NORMAL_EXT,
            'cbjs_action':
            '''

            var top = bvr.src_el.getParent(".spt_ingest_top");
            var files_el = top.getElement(".spt_to_ingest_files");
            var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i');
        
            //clear upload progress
            var upload_bar = top.getElement('.spt_upload_progress');
            if (upload_bar) {
                upload_bar.setStyle('width','0%');
                upload_bar.innerHTML = '';
            }
        var onchange = function (evt) {
                var files = spt.html5upload.get_files();
                var delay = 0; 
                for (var i = 0; i < files.length; i++) {
                    var size = files[i].size;
                    var file_name = files[i].name;
                    var is_normal = regex.test(file_name);
                    if (size >= 10*1024*1024 || is_normal) {
                        spt.drag.show_file(files[i], files_el, 0, false);
                    }
                    else {
                        spt.drag.show_file(files[i], files_el, delay, true);

                        if (size < 100*1024)       delay += 50;
                        else if (size < 1024*1024) delay += 500;
                        else if (size < 10*1024*1024) delay += 1000;
                    }
                }
        }

            spt.html5upload.clear();
            spt.html5upload.set_form( top );
            spt.html5upload.select_file( onchange );

         '''
        })

        button = ActionButtonWdg(title="Clear")
        button.add_style("float: right")
        button.add_style("margin-top: -3px")
        div.add(button)
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_ingest_top");
            var file_els = top.getElements(".spt_upload_file");
            for ( var i = 0; i < file_els.length; i++) {
                spt.behavior.destroy( file_els[i] );
            };

         '''
        })

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

        border_color_light = div.get_color("background2", 8)
        border_color_dark = div.get_color("background2", -15)
        background_mouseout = div.get_color("background3", 10)
        background_mouseenter = div.get_color("background3", 8)

        files_div = DivWdg()
        files_div.add_style("position: relative")
        files_div.add_class("spt_to_ingest_files")
        div.add(files_div)
        files_div.add_style("max-height: 300px")
        files_div.add_style("height: 300px")
        files_div.add_style("overflow-y: auto")
        files_div.add_style("padding: 3px")
        files_div.add_color("background", background_mouseout)
        files_div.add_style("border: 3px dashed %s" % border_color_light)
        files_div.add_style("border-radius: 20px 20px 20px 20px")
        files_div.add_style("z-index: 1")
        #files_div.add_style("display: none")

        bgcolor = div.get_color("background3")
        bgcolor2 = div.get_color("background3", -3)

        #style_text = "text-align: center; margin-top: 100px; color: #A0A0A0; font-size: 3.0em; z-index: 10;"

        background = DivWdg()
        background.add_class("spt_files_background")
        files_div.add(background)

        background.add_style("text-align: center")
        background.add_style("margin-top: 100px")
        background.add_style("opacity: 0.65")
        background.add_style("font-size: 3.0em")
        background.add_style("z-index: 10")

        background_text = DivWdg("<p>Drag Files Here</p>")

        background.add(background_text)

        files_div.add_behavior({
            'type':
            'mouseover',
            'cbjs_action':
            '''
            bvr.src_el.setStyle("border","3px dashed %s")
            bvr.src_el.setStyle("background","%s")
            ''' % (border_color_dark, background_mouseenter)
        })

        files_div.add_behavior({
            'type':
            'mouseout',
            'cbjs_action':
            '''
            bvr.src_el.setStyle("border", "3px dashed %s")
            bvr.src_el.setStyle("background","%s")
            ''' % (border_color_light, background_mouseout)
        })

        # Test drag and drop files
        files_div.add_attr("ondragenter", "return false")
        files_div.add_attr("ondragover", "return false")
        files_div.add_attr("ondrop", "spt.drag.noop(event, this)")
        files_div.add_behavior({
            'type':
            'load',
            'normal_ext':
            File.NORMAL_EXT,
            'cbjs_action':
            '''
        spt.drag = {}
        var background;

        spt.drag.show_file = function(file, top, delay, icon) {

            if (!background) {
                background = top.getElement(".spt_files_background");
                if (background)
                    background.setStyle("display", "none");
            }
            var template = top.getElement(".spt_upload_file_template");
            var clone = spt.behavior.clone(template);

            clone.removeClass("spt_upload_file_template");
            clone.addClass("spt_upload_file");
            clone.setStyle("display", "");

            if (typeof(delay) == 'undefined') {
                delay = 0;
            }

            // remember the file handle
            clone.file = file;

            var name = file.name;
            var size = parseInt(file.size / 1024 * 10) / 10;

            var thumb_el = clone.getElement(".spt_thumb");
            var date_label_el = clone.getElement(".spt_date_label");
            var date_el = clone.getElement(".spt_date");

            //var loadingImage = loadImage(
            setTimeout( function() {
                var draw_empty_icon = function() {
                        var img = $(document.createElement("div"));
                        img.setStyle("width", "58");
                        img.setStyle("height", "34");
                        //img.innerHTML = "MP4";
                        img.setStyle("border", "1px dotted #222")
                        thumb_el.appendChild(img);
                    };
                if (icon) {
                        var loadingImage = loadImage(
                            file,
                            function (img) {
                            if (img.width)
                                thumb_el.appendChild(img);
                            else
                                draw_empty_icon();
                                
                            },
                            {maxWidth: 80, maxHeight: 60, canvas: true, contain: true}
                        );
                        
                }
                else {
                    draw_empty_icon();
                }


                loadImage.parseMetaData(
                    file,
                    function(data) {
                        if (data.exif) {
                            var date = data.exif.get('DateTimeOriginal');
                            if (date) {
                                date_label_el.innerHTML = date;
                                if (date_el) {
                                    date_el.value = date;
                                }
                            }
                        }

                    }
                );

            }, delay );

            /*
            var reader = new FileReader();
            reader.thumb_el = thumb_el;
            reader.onload = function(e) {
                this.thumb_el.innerHTML = [
                    '<img class="thumb" src="',
                    e.target.result,
                    '" title="', escape(name),
                    '" width="60px"',
                    '" padding="5px"',
                    '"/>'
                ].join('');
            }
            reader.readAsDataURL(file);
            */
         
            clone.getElement(".spt_name").innerHTML = file.name;
            clone.getElement(".spt_size").innerHTML = size + " KB";
            clone.inject(top);
        }

        spt.drag.noop = function(evt, el) {
            var top = $(el).getParent(".spt_ingest_top");
            var files_el = top.getElement(".spt_to_ingest_files");
            evt.stopPropagation();
            evt.preventDefault();
            evt.dataTransfer.dropEffect = 'copy';
            var files = evt.dataTransfer.files;

            var delay = 0;
            var skip = false;
            var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i');
            for (var i = 0; i < files.length; i++) {
                var size = files[i].size;
                var file_name = files[i].name;
                var is_normal = regex.test(file_name);
                if (size >= 10*1024*1024 || is_normal) {
                    spt.drag.show_file(files[i], files_el, 0, false);
                }
                else {
                    spt.drag.show_file(files[i], files_el, delay, true);

                    if (size < 100*1024)       delay += 50;
                    else if (size < 1024*1024) delay += 500;
                    else if (size < 10*1024*1024) delay += 1000;
                }

            }
        }
        '''
        })

        # create a template that will be filled in for each file
        files_div.add_relay_behavior({
            'type':
            'mouseenter',
            'color':
            files_div.get_color("background3", -5),
            'bvr_match_class':
            'spt_upload_file',
            'cbjs_action':
            '''
            bvr.src_el.setStyle("background", bvr.color);
            '''
        })
        files_div.add_relay_behavior({
            'type':
            'mouseleave',
            'bvr_match_class':
            'spt_upload_file',
            'cbjs_action':
            '''
            bvr.src_el.setStyle("background", "");
            '''
        })
        files_div.add_relay_behavior({
            'type':
            'mouseup',
            'bvr_match_class':
            'spt_remove',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_upload_file");
            spt.behavior.destroy_element(top);
            '''
        })
        """
        metadata_view = "test/wizard/metadata"
        files_div.add_relay_behavior( {
            'type': 'mouseup',
            'view': metadata_view,
            'bvr_match_class': 'spt_upload_file',
            'cbjs_action': '''
            var class_name = 'tactic.ui.panel.CustomLayoutWdg';
            var kwargs = {
                view: bvr.view
            }
            spt.app_busy.show("Loading Metadata");
            spt.panel.load_popup("Metadata", class_name, kwargs);
            spt.app_busy.hide();
            '''
        } )
        """

        # template for each file item
        file_template = DivWdg()
        file_template.add_class("spt_upload_file_template")
        files_div.add(file_template)
        file_template.add_style("margin-bottom: 3px")
        file_template.add_style("padding: 3px")
        file_template.add_style("height: 40px")
        file_template.add_style("display: none")

        thumb_div = DivWdg()
        file_template.add(thumb_div)
        thumb_div.add_style("float: left")
        thumb_div.add_style("width: 60")
        thumb_div.add_style("height: 40")
        thumb_div.add_style("overflow: hidden")
        thumb_div.add_style("margin: 3 10 3 0")
        thumb_div.add_class("spt_thumb")

        info_div = DivWdg()
        file_template.add(info_div)
        info_div.add_style("float: left")

        name_div = DivWdg()
        name_div.add_class("spt_name")
        info_div.add(name_div)
        name_div.add("image001.jpg")
        name_div.add_style("width: 150px")
        """
        dialog = DialogWdg(display="false", show_title=False)
        info_div.add(dialog)
        dialog.set_as_activator(info_div, offset={'x':0,'y':10})

        dialog_data_div = DivWdg()
        dialog_data_div.add_color("background", "background")
        dialog_data_div.add_style("padding", "10px")

        dialog.add(dialog_data_div)
        dialog_data_div.add("Category: ")
        text = TextInputWdg(name="category")
        dialog_data_div.add(text)
        text.add_class("spt_category")
        text.add_style("padding: 1px")
        """

        date_div = DivWdg()
        date_div.add_class("spt_date_label")
        info_div.add(date_div)
        date_div.add("")
        date_div.add_style("opacity: 0.5")
        date_div.add_style("font-size: 0.8em")
        date_div.add_style("font-style: italic")
        date_div.add_style("margin-top: 3px")

        hidden_date_div = HiddenWdg("date")
        hidden_date_div.add_class("spt_date")
        info_div.add(date_div)

        size_div = DivWdg()
        size_div.add_class("spt_size")
        file_template.add(size_div)
        size_div.add("433Mb")
        size_div.add_style("float: left")
        size_div.add_style("width: 150px")
        size_div.add_style("text-align: right")

        remove_div = DivWdg()
        remove_div.add_class("spt_remove")
        file_template.add(remove_div)
        icon = IconButtonWdg(title="Remove", icon=IconWdg.DELETE)
        icon.add_style("float: right")
        remove_div.add(icon)
        #remove_div.add_style("text-align: right")

        div.add("<br/>")

        info = DivWdg()
        div.add(info)
        info.add_class("spt_upload_info")

        progress_div = DivWdg()
        progress_div.add_class("spt_upload_progress_top")
        div.add(progress_div)
        progress_div.add_style("width: 100%")
        progress_div.add_style("height: 15px")
        progress_div.add_style("margin-bottom: 10px")
        progress_div.add_border()
        #progress_div.add_style("display: none")

        progress = DivWdg()
        progress_div.add(progress)
        progress.add_class("spt_upload_progress")
        progress.add_style("width: 0px")
        progress.add_style("height: 100%")
        progress.add_gradient("background", "background3", -10)
        progress.add_style("text-align: right")
        progress.add_style("overflow: hidden")
        progress.add_style("padding-right: 3px")

        from tactic.ui.app import MessageWdg
        progress.add_behavior({
            'type': 'load',
            'cbjs_action': MessageWdg.get_onload_js()
        })

        # NOTE: files variable is passed in automatically

        upload_init = '''
        server.start( {description: "Upload and check-in of ["+files.length+"] files"} );
        var info_el = top.getElement(".spt_upload_info");
        info_el.innerHTML = "Uploading ...";
        '''

        upload_progress = '''
        var top = bvr.src_el.getParent(".spt_ingest_top");
        progress_el = top.getElement(".spt_upload_progress");
        var percent = Math.round(evt.loaded * 100 / evt.total);
        progress_el.setStyle("width", percent + "%");
        progress_el.innerHTML = String(percent) + "%";


        '''

        oncomplete_script_path = my.kwargs.get("oncomplete_script_path")
        oncomplete_script = ''
        if oncomplete_script_path:
            script_folder, script_title = oncomplete_script_path.split("/")
            oncomplete_script_expr = "@GET(config/custom_script['folder','%s']['title','%s'].script)" % (
                script_folder, script_title)
            server = TacticServerStub.get()
            oncomplete_script_ret = server.eval(oncomplete_script_expr,
                                                single=True)

            if oncomplete_script_ret:
                oncomplete_script = '''var top = bvr.src_el.getParent(".spt_ingest_top");
                var file_els = top.getElements(".spt_upload_file");
                for ( var i = 0; i < file_els.length; i++) {
                spt.behavior.destroy( file_els[i] );
                };''' + oncomplete_script_ret
                script_found = True
            else:
                script_found = False
                oncomplete_script = "alert('Error: oncomplete script not found');"

        if not oncomplete_script:
            oncomplete_script = '''
            var click_action = function() {
                var fade = true;
                var pop = spt.popup.get_popup(top)
                spt.popup.close(pop, fade); 
            }
            spt.info("Ingest Completed", {click: click_action});
            server.finish();

            var file_els = top.getElements(".spt_upload_file");
            for ( var i = 0; i < file_els.length; i++) {
                spt.behavior.destroy( file_els[i] );
            };
            var background = top.getElement(".spt_files_background");
            background.setStyle("display", "");

            spt.message.stop_interval(key);

            var info_el = top.getElement(".spt_upload_info");
            info_el.innerHTML = ''; 

            if (spt.table)
            {
                spt.table.run_search();
            }
            
            spt.panel.refresh(top);
            '''
            script_found = True

        on_complete = '''
        var top = bvr.src_el.getParent(".spt_ingest_top");
        var update_data_top = top.getElement(".spt_edit_top");
        var progress_el = top.getElement(".spt_upload_progress");
        progress_el.innerHTML = "100%";
        progress_el.setStyle("width", "100%");

        var info_el = top.getElement(".spt_upload_info");
        
        var search_type = bvr.kwargs.search_type;
        var relative_dir = bvr.kwargs.relative_dir;
        
        var update_mode_select = top.getElement(".spt_update_mode_select");
        var update_mode = update_mode_select.value;

        var filenames = [];
        for (var i = 0; i != files.length;i++) {
            var name = files[i].name;
            filenames.push(name);
        }

        var key = spt.message.generate_key();
        var values = spt.api.get_input_values(top);
        //var category = values.category[0];
        //var keywords = values.keywords[0];

        var extra_data = values.extra_data ? values.extra_data[0]: {};
        var parent_key = values.parent_key[0];

        var convert_el = top.getElement(".spt_image_convert")
        var convert = spt.api.get_input_values(convert_el);

        var processes = values.process;
        if (processes) {
            process = processes[0];
            if (!process) {
                process = null;
            }
        }
        else {
            process = null;
        }

        var return_array = false;
        var update_data = spt.api.get_input_values(update_data_top, null, return_array);

        var kwargs = {
            search_type: search_type,
            relative_dir: relative_dir,
            filenames: filenames,
            key: key,
            parent_key: parent_key,
            //category: category,
            //keywords: keywords,
            extra_data: extra_data,
            update_data: update_data,
            process: process,
            convert: convert,
            update_mode: update_mode,
        }
        on_complete = function(rtn_data) {

        ''' + oncomplete_script + '''

        };

        var class_name = bvr.action_handler;
        // TODO: make the async_callback return throw an e so we can run 
        // server.abort
        server.execute_cmd(class_name, kwargs, null, {on_complete:on_complete});
        
        
        on_progress = function(message) {
            msg = JSON.parse(message.message);
            var percent = msg.progress;
            var description = msg.description;
            info_el.innerHTML = description;

            progress_el.setStyle("width", percent+"%");
            progress_el.innerHTML = percent + "%";
        }
        spt.message.set_interval(key, on_progress, 2000);

        '''

        upload_div = DivWdg()
        div.add(upload_div)
        #button = UploadButtonWdg(**kwargs)
        button = ActionButtonWdg(title="Ingest")
        upload_div.add(button)
        button.add_style("float: right")
        upload_div.add_style("margin-bottom: 15px")
        upload_div.add("<br clear='all'/>")

        action_handler = my.kwargs.get("action_handler")
        if not action_handler:
            action_handler = 'tactic.ui.tools.IngestUploadCmd'

        button.add_behavior({
            'type':
            'click_up',
            'action_handler':
            action_handler,
            'kwargs': {
                'search_type': my.search_type,
                'relative_dir': relative_dir,
                'script_found': script_found,
            },
            'cbjs_action':
            '''

            if (bvr.kwargs.script_found != true)
            {
                spt.alert("Error: provided on_complete script not found");
                return;
            }

            var top = bvr.src_el.getParent(".spt_ingest_top");
           
            var file_els = top.getElements(".spt_upload_file");

            // get the server that will be used in the callbacks
            var server = TacticServerStub.get();

            // retrieved the stored file handles
            var files = [];
            for (var i = 0; i < file_els.length; i++) {
                files.push( file_els[i].file );
            }
            if (files.length == 0) {
                alert("Either click 'Add' or drag some files over to ingest.");
                return;
            }


            // defined the callbacks
            var upload_start = function(evt) {
            }

            var upload_progress = function(evt) {
            %s;
            }

            var upload_complete = function(evt) {
            %s;
            spt.app_busy.hide();
            }


            var upload_file_kwargs =  {
                files: files,
                upload_start: upload_start,
                upload_complete: upload_complete,
                upload_progress: upload_progress
            };
            if (bvr.ticket)
               upload_file_kwargs['ticket'] = bvr.ticket; 

            %s;

            spt.html5upload.set_form( top );
            spt.html5upload.upload_file(upload_file_kwargs);

            ''' % (upload_progress, on_complete, upload_init)
        })

        return div
Example #47
0
    def get_display(my):

        top = my.top
        top.add_class("spt_switcher_top")
        '''
        This supports supports two menu definitions:
        menu - specifies a view for SideBarWdg which will be ingected as menu 
        config_xml - specifies menu entries. For example:

        <display class="tactic.ui.widget.LayoutSwitcherWdg">
          <!-- config_xml -->
          <config>
            <!-- Menu item 1 -->
            <element name="my_tasks_default" title="My Tasks">
              <display class="tactic.ui.panel.ViewPanelWdg">
                <search_type>sthpw/task</search_type>
                <show_shelf>false</show_shelf>
                <view>my_tasks_default</view>
                <target>spt_my_tasks_table_top</target>
              </display>
            </element>
            <!-- Menu item 2 -->
            <element ... >
              <display ... >
                <target ... />
              </display>
            </element>
          </config>
        </display>

        target - specifies target div to load views when using "menu" kwarg
        use_href - updates address bar hash (this is TODO)
        '''

        menu = my.kwargs.get("menu")
        config_xml = my.kwargs.get("config_xml")
        target = my.kwargs.get("target")
        # TODO: use_href to go to specific layout switcher view
        # use_href = my.kwrags.get("use_href")

        # Layout switcher button displays menu and assumes right hand position of screen
        activator = IconButtonWdg(name="Layout Switcher", icon="BS_TH_LIST")
        top.add(activator)
        activator.add_class("spt_switcher_activator")
        activator.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var activator = bvr.src_el;
            var top = activator.getParent(".spt_switcher_top");
            var menu = top.getElement(".spt_switcher_menu");
            
            if (top.hasClass("spt_selected")) {
                top.removeClass("spt_selected");
                menu.setStyle("display", "none");    
            } else {
                top.addClass("spt_selected");
                menu.setStyle("display", "");
                var pos = activator.getPosition();
                var button_size = activator.getSize();
                var menu_size = menu.getSize();
                var offset = {
                    x: button_size.x - menu_size.x,
                    y: button_size.y
                }
                menu.position({position: 'upperleft', relativeTo: activator, offset: offset});

                var pointer = menu.getElement(".spt_popup_pointer");
                pointer.setStyle("margin-left", menu_size.x - button_size.x);
            } 
            '''
        })

        # menu_wdg
        menu_wdg = DivWdg()
        top.add(menu_wdg)
        menu_wdg.add_class("spt_switcher_menu")
        menu_wdg.add_style("display: none")
        menu_wdg.add_style("margin-top", "15px")
        menu_wdg.add_style("position", "absolute")
        menu_wdg.add_style("z-index", "10")
        menu_wdg.add_behavior({
            'type':
            'mouseleave',
            'cbjs_action':
            '''
            var menu = bvr.src_el;
            var top = menu.getParent(".spt_switcher_top");
            top.removeClass("spt_selected");
            menu.setStyle("display", "none")
            '''
        })

        # Pointer under activator
        pointer_wdg = DivWdg()
        menu_wdg.add(pointer_wdg)
        pointer_wdg.add('''
            <div class="spt_first_arrow_div"> </div>
            <div class="spt_second_arrow_div"> </div>
        ''')
        pointer_wdg.add_class("spt_popup_pointer")

        style = HtmlElement.style('''
            .spt_switcher_menu .spt_popup_pointer {
                z-index: 10;
                margin-top: -15px;
                margin-left: 100px;
            }

            .spt_switcher_menu .spt_first_arrow_div {
                border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #ccc;
                top: -15px;
                z-index: 1;
                border-width: 0 15px 15px;
                height: 0;
                width: 0;
                border-style: dashed dashed solid;
                left: 15px;
            }

            .spt_switcher_menu .spt_second_arrow_div{
                border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #fff;
                z-index: 1;
                border-width: 0 15px 15px;
                height: 0;
                width: 0;
                border-style: dashed dashed solid;
                margin-top: -14px;
                position: absolute;
            }
        ''')
        pointer_wdg.add(style)

        if menu:
            from tactic.ui.panel import SimpleSideBarWdg
            simple_sidebar = SimpleSideBarWdg(view=menu,
                                              search_type="SidebarWdg",
                                              target=target)
            menu_wdg.add(simple_sidebar)
        else:
            style = my.get_style()
            top.add(style)

            my.view = 'tab'
            config = WidgetConfig.get(view=my.view, xml=config_xml)
            element_names = config.get_element_names()

            for element_name in element_names:

                item_div = DivWdg()
                menu_wdg.add(item_div)
                item_div.add_class("spt_switcher_item")
                item_div.add_class("tactic_hover")

                attrs = config.get_element_attributes(element_name)
                title = attrs.get("title")
                if not title:
                    title = Common.get_display_title(element_name)

                item_div.add(title)

                target = attrs.get("target")
                if not target:
                    target = "spt_content"

                display_class = config.get_display_handler(element_name)
                display_options = config.get_display_options(element_name)

                item_div.add_behavior({
                    'type':
                    'click_up',
                    'display_class':
                    display_class,
                    'display_options':
                    display_options,
                    'target':
                    target,
                    'cbjs_action':
                    '''
                    var menu_item = bvr.src_el;
                    var top = menu_item.getParent(".spt_switcher_top");
                    var menu = menu_item.getParent(".spt_switcher_menu");
                    
                    // Get target class
                    var target_class = bvr.target;
                    if (target_class.indexOf(".") != "-1") {
                        var parts = target_class.split(".");
                        target_class = parts[1]; 
                    }
                    
                    var target = $(document.body).getElement("."+target_class);
                    if (target) {
                        spt.panel.load(target, bvr.display_class, bvr.display_options);
                    }

                    menu.setStyle("display", "none");
                    top.removeClass("spt_selected");
                    '''
                })

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

        top = self.top
        top.add_color("background", "background")
        top.add_class("spt_pipelines_top")
        self.set_as_panel(top)

        inner = DivWdg()
        top.add(inner)


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

        if search_type:
            search = Search("sthpw/pipeline")
            search.add_filter("search_type", search_type)
            pipelines = search.get_sobjects()
        else:
            pipeline = Pipeline.get_by_code(pipeline_code)
            if pipeline:
                pipelines = [pipeline]
            else:
                pipelines = []


        if not pipelines:
            div = DivWdg()
            inner.add(div)
            inner.add_style("padding: 50px")
            div.add_border()
            div.add_color("color", "color3")
            div.add_color("background", "background3")
            div.add_style("width: 400px")
            div.add_style("height: 100px")
            div.add_style("padding: 30px")
           
            icon = IconWdg("WARNING", IconWdg.WARNING)
            div.add(icon)
            div.add("<b>This Searchable Type does not have pipelines defined.</b>")
            div.add("<br/>"*2)

            div.add("<b style='padding-left: 35px'>Click Create to add one...</b>")
            div.add("<br/>"*2)
 
            button_div = DivWdg()
            div.add(button_div)

            button = ActionButtonWdg(title="Create", tip="Create pipeline")
            button_div.add(button)
            button.add_style("margin: auto")
            button.add_behavior( {
                'type': 'click_up',
                'search_type': search_type,
                'cbjs_action': '''
                var server = TacticServerStub.get();

                var cmd = 'tactic.ui.startup.PipelineCreateCbk';
                var kwargs = {
                    search_type: bvr.search_type
                }
                server.execute_cmd(cmd, kwargs)

                var top = bvr.src_el.getParent(".spt_pipelines_top");
                spt.panel.refresh(top);
                '''
            } )

            return top



        # get the defalt task statuses
        task_pipeline = Pipeline.get_by_code("task")
        if task_pipeline:
            statuses = task_pipeline.get_process_names()
        else:
            statuses = ['Pending', 'In Progress', 'Complete']
        statuses_str = ",".join(statuses)



        pipelines_div = DivWdg()
        inner.add( pipelines_div )
        pipelines_div.add_style("font-size: 12px")
        pipelines_div.add_style("padding: 10px")

        buttons_div = DivWdg()
        pipelines_div.add(buttons_div)

        #button = SingleButtonWdg( title="Save Pipelines", icon=IconWdg.SAVE )
        button = ActionButtonWdg( title="Save" )
        buttons_div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'default_statuses': statuses_str,
        'cbjs_action': '''
        spt.app_busy.show("Saving Pipeline...")

        setTimeout(function() {
            try {
                var top = bvr.src_el.getParent(".spt_pipelines_top");
                // get all the pipeline divs
                var pipeline_els = top.getElements(".spt_pipeline_top");
                var data = {};
                for ( var i = 0; i < pipeline_els.length; i++) {
                    var pipeline_code = pipeline_els[i].getAttribute("spt_pipeline_code");
                    var values = spt.api.Utility.get_input_values(pipeline_els[i]);
                    data[pipeline_code] = values;
                }


                var class_name = 'tactic.ui.startup.PipelineEditCbk';
                var kwargs = {
                    data: data
                }
                var server = TacticServerStub.get();
                server.execute_cmd(class_name, kwargs);
            } catch(e) {
                spt.alert(spt.exception.handler(e));
            }
            spt.app_busy.hide();
        }
        , 100);

        '''
        } )


        buttons_div.add("<br clear='all'/>")
        buttons_div.add_style("margin-bottom: 5px")




        for pipeline in pipelines:
            pipeline_div = DivWdg()
            pipelines_div.add(pipeline_div)
            pipeline_div.add_class("spt_pipeline_top")


            code = pipeline.get_code()
            label = '%s  (%s)' %(pipeline.get('name'), code)
            pipeline_div.add_attr("spt_pipeline_code", code)

            title = DivWdg()
            pipeline_div.add(title)
            title.add("Pipeline: ")
            
            title.add(label)
            title.add_style("padding: 8px 10px")
            title.add_color("background", "background3")
            title.add_style("font-weight: bold")
            title.add_style("margin: -10 -10 5 -10")


            header_wdg = DivWdg()
            pipeline_div.add(header_wdg)
            header_wdg.add_color("background", "background", -5)

            headers = ['Process', 'Description', 'Task Status']
            widths = ['100px', '180px', '210px']
            for header, width in zip(headers,widths):
                th = DivWdg()
                header_wdg.add(th)
                th.add("<b>%s</b>" % header)
                th.add_style("float: left")
                th.add_style("width: %s" % width)
                th.add_style("padding: 8px 3px")
            header_wdg.add("<br clear='all'/>")



            # get all of the process sobjects from this pipeline
            pipeline_code = pipeline.get_code()
            search = Search("config/process")
            search.add_filter("pipeline_code", pipeline.get_code() )
            process_sobjs = search.get_sobjects()

            process_sobj_dict = {}
            for process_sobj in process_sobjs:
                process = process_sobj.get_value("process")
                process_sobj_dict[process] = process_sobj


            from tactic.ui.container import DynamicListWdg
            dyn_list = DynamicListWdg()
            pipeline_div.add(dyn_list)
            pipeline_div.add_style("width: 725px")

            processes = pipeline.get_process_names()
            if not processes:
                processes.append("")
                processes.append("")
                processes.append("")

            processes.insert(0, "")

            for i, process in enumerate(processes):

                if process == '':
                    process_name = ''
                    description = ''
                else:
                    process_sobj = process_sobj_dict.get(process)
                    if process_sobj:
                        process_name = process_sobj.get_value("process")
                        description = process_sobj.get_value("description")
                    else:
                        if isinstance(process,basestring):
                            process_name = process
                        else:
                            process_name = process.get_name()
                        deccription = ''

                process_type = 'manual'
                process_xpos = ''
                process_ypos = ''
                # get the task pipeline for this process
                if process_name:
                    process = pipeline.get_process(process_name)
                    process_type = process.get_type()
                    process_xpos = process.get_attribute('xpos')
                    process_ypos = process.get_attribute('ypos')

                    task_pipeline_code = process.get_task_pipeline()
                    if task_pipeline_code != "task":
                        task_pipeline = Search.get_by_code("sthpw/pipeline", task_pipeline_code)
                    else:
                        task_pipeline = None
                else:
                    task_pipeline_code = "task"
                    task_pipeline = None

                
                process_div = DivWdg()
                process_div.add_style("float: left")
                process_div.add_class("spt_process_top")


                if i == 0:
                    dyn_list.add_template(process_div)
                else:
                    dyn_list.add_item(process_div)

                #process_div.add_style("padding-left: 10px")
                #process_div.add_style("margin: 5px")

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

                text = TextInputWdg(name="process")
                process_cell = table.add_cell(text)
                text.add_style("width: 95px")
                text.add_style("margin: 5px")
                text.set_value(process_name)
                text.add_class("spt_process")

                # the template has a border
                if i == 0:
                    text.add_style("border: solid 1px #AAA")

                hidden = HiddenWdg(name='process_type')
                hidden.set_value(process_type)
                process_cell.add(hidden)

                hidden = HiddenWdg(name='process_xpos')
                hidden.set_value(process_xpos)
                process_cell.add(hidden)

                hidden = HiddenWdg(name='process_ypos')
                hidden.set_value(process_ypos)
                process_cell.add(hidden)


                text = TextInputWdg(name="description")
                table.add_cell(text)
                text.add_style("width: 175px")
                text.add_style("margin: 5px")
                text.set_value(description)
                # the template has a border
                if i == 0:
                    text.add_style("border: solid 1px #AAA")

                
                if process_type in ['manual','approval']:
                    read_only = False
                else:
                    read_only = True
                text = TextInputWdg(name="task_status", read_only=read_only)

                table.add_cell(text)
                text.add_style("width: 325px")
                text.add_style("margin: 5px")

                #text.set_value(statuses_str)
                    #text.add_style("opacity: 0.5")
                

                text.add_style("border-style: none")
                if process_type in ['manual','approval']:
                    if task_pipeline:
                        statuses = task_pipeline.get_process_names()
                        text.set_value(",".join(statuses))
                    else:
                        text.set_value("(default)")
                    text.add_behavior( {
                    'type': 'click_up',
                    'statuses': statuses_str,
                    'cbjs_action': '''
                    if (bvr.src_el.value == '(default)') {
                        bvr.src_el.value = bvr.statuses;
                    }
                    '''
                    } )

                table.add_cell("&nbsp;"*2)

                button = IconButtonWdg(tip="Trigger", icon=IconWdg.ARROW_OUT)
                table.add_cell(button)
                button.add_behavior( {
                    'type': 'click_up',
                    'search_type': search_type,
                    'pipeline_code': pipeline_code,
                    'cbjs_action': '''
                    var top = bvr.src_el.getParent(".spt_process_top");
                    var process_el = top.getElement(".spt_process");

                    var process = process_el.value;
                    if (process == "") {
                        alert("Process value is empty");
                        return;
                    }

                    var class_name = 'tactic.ui.tools.TriggerToolWdg';
                    var kwargs = {
                        mode: "pipeline",
                        process: process,
                        pipeline_code: bvr.pipeline_code
                    };
                    spt.panel.load_popup("Trigger", class_name, kwargs);
     
                    '''
                } )

                """
                button = IconButtonWdg(tip="Edit", icon=IconWdg.EDIT)
                table.add_cell(button)
                button.add_behavior( {
                    'type': 'click_up',
                    'search_type': search_type,
                    'pipeline_code': pipeline_code,
                    'cbjs_action': '''
                    var top = bvr.src_el.getParent(".spt_process_top");
                    var process_el = top.getElement(".spt_process");

                    var process = process_el.value;
                    if (process == "") {
                        alert("Process value is empty");
                        return;
                    }

                    var class_name = 'tactic.ui.panel.EditWdg';
                    var kwargs = {
                        expression: "@SOBJECT(config/process['process','"+process+"'])"
                    }
                    spt.panel.load_popup("Trigger", class_name, kwargs);
     
                    '''
                } )
                """

                table.add_cell("&nbsp;"*3)
               


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



        if self.kwargs.get("is_refresh"):
            return inner
        else:
            return top
Example #49
0
    def get_display(my):

        top = DivWdg()
        top.add_border()
        top.add_style("padding: 10px")
        top.add_color("color", "color")
        top.add_gradient("background", "background", 0, -5)
        #top.add_style("height: 550px")

        top.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            spt.named_events.fire_event("side_bar|hide_now", {} );
            '''
        } )


        project = Project.get()
        title = DivWdg()
        title.add("Project Startup and Configuration")
        title.add_style("font-size: 18px")
        title.add_style("font-weight: bold")
        title.add_style("text-align: center")
        title.add_style("padding: 10px")
        title.add_style("margin: -10px -10px 10px -10px")

        top.add(title)
        title.add_gradient("background", "background3", 5, -10)


        shelf = DivWdg()
        top.add(shelf)
        shelf.add_style("margin-left: -8px")
        shelf.add_style("width: 130px")

        button_div = DivWdg()
        shelf.add(button_div)
        button_div.add_style("float: left")
        button_div.add_style("margin-top: -3px")

        security = Environment.get_security()
        view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow')
        if view_side_bar:
            button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT)
            button_div.add(button)
            shelf.add("Toggle Side Bar")
            shelf.add_attr("title", "Toggle Side Bar (or press '1')")
            button.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                spt.named_events.fire_event("side_bar|toggle");
                '''
            } )
            shelf.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                spt.named_events.fire_event("side_bar|toggle");
                '''
            } )
            shelf.add_class("hand")
        else:
            shelf.add("&nbsp;")


        search_wdg = Table()
        top.add(search_wdg)
        search_wdg.add_row()

        search_wdg.add_class("spt_main_top")
        search_wdg.add_style("padding: 10px")
        search_wdg.add_style("margin: 20px auto")
        search_wdg.add_style("width: 430px")

        td = search_wdg.add_cell("Search: ")
        td.add_style("vertical-align: top")
        td.add_style("padding-top: 8px")


        custom_cbk = {}
        custom_cbk['enter'] = '''
            var top = bvr.src_el.getParent(".spt_main_top");
            var search_el = top.getElement(".spt_main_search");
            var keywords = search_el.value;

            if (keywords != '') {
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    'search_type': 'sthpw/sobject_list',
                    'view': 'result_list',
                    'keywords': keywords,
                    'simple_search_view': 'simple_filter',
                    //'show_shelf': false,
                }
                spt.tab.set_main_body_tab();
                spt.tab.add_new("Search Results", "Search Results", class_name, kwargs);
            }
        '''


        from tactic.ui.input import TextInputWdg, LookAheadTextInputWdg
        #text = TextInputWdg(name="search")
        text = LookAheadTextInputWdg(name="search", custom_cbk=custom_cbk, width='280', height='42px')
        #text = TextWdg("search")
        text.add_class("spt_main_search")
        text.add_style("width: 290px")

        search_wdg.add_cell(text)
        search_wdg.add_style("font-weight: bold")
        search_wdg.add_style("font-size: 16px")


        icon_div = DivWdg()
        td = search_wdg.add_cell(icon_div)
        td.add_style("vertical-align: top")
        icon_div.add_style("width: 38px")
        icon_div.add_style("height: 27px")
        icon_div.add_style("padding-top: 7px")
        icon_div.add_style("padding-left: 4px")
        icon_div.add_style("text-align: center")
        #icon_div.add_gradient("background", "background3", 15, -10)
        icon_div.add_color("background", "background3", 10)
        over_color = icon_div.get_color("background3", 0)
        out_color = icon_div.get_color("background3", 10)
        icon_div.set_round_corners(5)
        icon_div.set_box_shadow("1px 1px 1px 1px")
        icon = IconWdg("Search", IconWdg.SEARCH_32, width=24)
        icon_div.add(icon)
        button = icon_div
        icon_div.add_class("hand")
        icon_div.add_behavior( {
            'type': 'mouseover',
            'color': over_color,
            'cbjs_action': '''
            bvr.src_el.setStyle("background", bvr.color);
            '''
        } )
        icon_div.add_behavior( {
            'type': 'mouseout',
            'color': out_color,
            'cbjs_action': '''
            bvr.src_el.setStyle("background", bvr.color);
            bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-5");
            bvr.src_el.setStyle("margin-right", "0");
            '''
        } )
        icon_div.add_behavior( {
            'type': 'click',
            'color': out_color,
            'cbjs_action': '''
            bvr.src_el.setStyle("box-shadow", "0px 0px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-3");
            bvr.src_el.setStyle("margin-right", "-2");
            '''
        } )
        icon_div.add_behavior( {
            'type': 'click_up',
            'color': out_color,
            'cbjs_action': '''
            bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-5");
            bvr.src_el.setStyle("margin-right", "0");
            '''
        } )





        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_main_top");
            var search_el = top.getElement(".spt_main_search");
            var keywords = search_el.value;

            if (keywords == '') {
                return;
            }

            var class_name = 'tactic.ui.panel.ViewPanelWdg';
            var kwargs = {
                'search_type': 'sthpw/sobject_list',
                'view': 'result_list',
                'keywords': keywords,
                'simple_search_view': 'simple_filter',
                //'show_shelf': false,
            }
            spt.tab.set_main_body_tab();
            spt.tab.add_new("Search Results", "Search Results", class_name, kwargs);
            '''
        } )

        #desc = DivWdg()
        #top.add(desc)
        #desc.add("Dashboard")
        #desc.add_style("width: 600px")


        # create a bunch of panels
        table = Table()
        table.add_color("color", "color")
        table.add_style("margin-bottom: 20px")
        table.center()
        top.add(table)
        table.add_row()

        #security = Environment.get_security()
        #if not security.check_access("builtin", "view_site_admin", "allow"):

         

        td = table.add_cell()
        td.add_style("padding: 3px")
        td.add_style("vertical-align: top")
        title = "Configuration"
        #description = '''All TACTIC projects can be uniquely designed and managed using our configuration tools.'''
        description = '''Configure a Project from start to finish.'''
	image = "<img src='/context/icons/64x64/configuration_64.png'/>"
        behavior = {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tab.set_main_body_tab();
            var class_name = 'tactic.ui.startup.ProjectConfigWdg';
            var kwargs = {
                help_alias: 'project-startup-configuration'
                };
            spt.tab.add_new("project_configuration", "Configuration", class_name, kwargs);
            '''
        }
        config_wdg = my.get_main_section_wdg(title, description, image, behavior)
        td.add(config_wdg)



        # Manage Users
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "Manage Users and Security"
        image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        image = DivWdg()
        image_link = "<div style='margin-bottom: -64px'><img src='/context/icons/64x64/lock_64.png'/></div>"
        image.add(image_link)

        image1 = IconWdg("Manage Users", IconWdg.USER_32)
        image2 = IconWdg("Manage Users", IconWdg.USER_32)
        image3 = IconWdg("Manage Users", IconWdg.USER_32)
        image4 = IconWdg("Manage Users", IconWdg.USER_32)
        image.add(image1)
        image.add(image2)
        image.add("<br/>")
        image.add(image3)
        image.add(image4)
        description = '''Manage users that can access the system'''

        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.startup.UserConfigWdg';
        var kwargs = {
            help_alias: 'project-startup-manage-users'
            };
        spt.tab.add_new("manage_user", "Manage Users", class_name, kwargs);
        '''
        }
        manage_users_wdg = my.get_main_section_wdg(title, description, image, behavior)
        td.add(manage_users_wdg)



        # custom layout editor 
        td = table.add_cell()
        td.add_style("padding: 3px")
        td.add_style("vertical-align: top")
        title = "Custom Layouts"
        description = '''Create interfaces using the Custom Layout Editor.'''
	image = "<img src='/context/icons/64x64/layout_64.png'/>"
        behavior = {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tab.set_main_body_tab();
            var class_name = 'tactic.ui.tools.CustomLayoutEditWdg';
            var kwargs = {
                help_alias: 'project-startup-configuration'
                };
            spt.tab.add_new("custom_layout_editor", "Custom Layout Editor", class_name, kwargs);
            '''
        }
        config_wdg = my.get_main_section_wdg(title, description, image, behavior)
        td.add(config_wdg)




        tr = table.add_row()

        # Plugins
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "Manage Plugin"
        image = IconWdg("Manage Plugin", IconWdg.PLUGIN_32)
        #image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''Upload, install, remove and create TACTIC plugins.'''

        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        var class_name = 'tactic.ui.app.PluginWdg';
        spt.tab.set_main_body_tab();
        spt.tab.add_new("plugins", "Manage Plugin", class_name, kwargs);
        '''
        }
        plugin_wdg = my.get_small_section_wdg(title, description, image, behavior)
        td.add(plugin_wdg)



        # Examples
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "Tools"
        image = IconWdg("Tools", IconWdg.SHARE_32)
        #image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''A collection of example views.'''

        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        var class_name = 'tactic.ui.startup.ToolsWdg';
        spt.tab.set_main_body_tab();
        spt.tab.add_new("tools", "Tools", class_name, kwargs);
        '''
        }
        share_wdg = my.get_small_section_wdg(title, description, image, behavior)
        td.add(share_wdg)





        # Share
        """
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "Shares"
        image = IconWdg("Shares", IconWdg.SHARE_32)
        #image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''Share project with other TACTIC installs.'''

        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        var class_name = 'tactic.ui.startup.ShareWdg';
        spt.tab.set_main_body_tab();
        spt.tab.add_new("shares", "Shares", class_name, kwargs);
        '''
        }
        share_wdg = my.get_small_section_wdg(title, description, image, behavior)
        td.add(share_wdg)
        """


        # Advanced
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "Advanced Setup"
        image = IconWdg("Advanced", IconWdg.ADVANCED_32)
        #image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''A set of advanced configuration tools.'''

        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        var class_name = 'tactic.ui.app.ProjectStartWdg';
        spt.tab.set_main_body_tab()
        spt.tab.add_new("project_setup", "Project Setup", class_name)
        '''
        }
        share_wdg = my.get_small_section_wdg(title, description, image, behavior)
        td.add(share_wdg)




        """
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
	title = "Documentation"

        description = '''TACTIC Documentation.
        * Project Setup Documentation<br/>
        <br/>
        * End User Documentation<br/>
        <br/>
        * Developer Documentation<br/>
        <br/>
        * System Administrator Documentation<br/>
        <br/>
        '''
        image = "<img src='/context/images/getting_started_pipeline.png'/>"
        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        spt.help.load_alias("main")
        '''
        }
        doc_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(doc_wdg)
        """





        tr, td = table.add_row_cell()
        td.add_style("font-size: 14px")
        td.add("<br/>")

        from misc_wdg import QuickLinksWdg
        quick_links_wdg = QuickLinksWdg()
        td.add(quick_links_wdg)
        
        #td = table.add_cell()
        #totals_wdg = my.get_totals_wdg()
	#td.add(totals_wdg)

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

        top = DivWdg()
        top.add_border()
        top.add_style("padding: 10px")
        top.add_color("color", "color")
        top.add_gradient("background", "background", 0, -5)
        #top.add_style("height: 550px")

        top.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
            spt.named_events.fire_event("side_bar|hide", {} );
            '''
        })

        project = Project.get()

        title = TitleWdg(title='Client Home')
        top.add(title)

        shelf = DivWdg()
        top.add(shelf)
        shelf.add_style("margin-left: -8px")
        shelf.add_style("width: 130px")

        security = Environment.get_security()
        view_side_bar = security.check_access("builtin",
                                              "view_side_bar",
                                              "allow",
                                              default='allow')
        if view_side_bar:
            button_div = DivWdg()
            shelf.add(button_div)
            button_div.add_style("float: left")
            button_div.add_style("margin-top: -3px")

            button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT)
            button_div.add(button)
            shelf.add("Toggle Side Bar")
            button.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                spt.named_events.fire_event("side_bar|toggle");
                '''
            })

            shelf.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                spt.named_events.fire_event("side_bar|toggle");
                '''
            })
            shelf.add_class("hand")
        else:
            shelf.add("&nbsp;")

        search_wdg = DivWdg()
        search_wdg.add_class("spt_main_top")
        top.add(search_wdg)
        search_wdg.add_style("padding: 10px")
        search_wdg.add_style("margin: 10px auto")
        search_wdg.add_style("width: 430px")
        search_wdg.add("Search: ")
        search_wdg.add("&nbsp;" * 3)

        custom_cbk = {}
        custom_cbk['enter'] = '''
            var top = bvr.src_el.getParent(".spt_main_top");
            var search_el = top.getElement(".spt_main_search");
            var keywords = search_el.value;

            if (keywords != '') {
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    'search_type': 'sthpw/sobject_list',
                    'view': 'table',
                    'keywords': keywords,
                    'simple_search_view': 'simple_search',
                    //'show_shelf': false,
                }
                spt.tab.set_main_body_tab();
                spt.tab.add_new("Search Results", "Search Results", class_name, kwargs);
            }
        '''

        from tactic.ui.input import TextInputWdg, LookAheadTextInputWdg
        #text = TextInputWdg(name="search")
        text = LookAheadTextInputWdg(name="search", custom_cbk=custom_cbk)
        #text = TextWdg("search")
        text.add_class("spt_main_search")
        text.add_style("width: 290px")
        search_wdg.add(text)
        search_wdg.add_style("font-weight: bold")
        search_wdg.add_style("font-size: 16px")

        button = ActionButtonWdg(title="Search")
        #search_wdg.add(button)
        button.add_style("float: right")
        #button.add_style("margin-top: -28px")

        icon_div = DivWdg()
        search_wdg.add(icon_div)
        icon_div.add_style("width: 38px")
        icon_div.add_style("height: 27px")
        icon_div.add_style("padding-top: 3px")
        icon_div.add_style("padding-left: 4px")
        icon_div.add_style("text-align: center")
        #icon_div.add_gradient("background", "background3", 15, -10)
        icon_div.add_color("background", "background3", 10)
        over_color = icon_div.get_color("background3", 0)
        out_color = icon_div.get_color("background3", 10)
        icon_div.set_round_corners(5)
        icon_div.set_box_shadow("1px 1px 1px 1px")
        icon = IconWdg("Search", IconWdg.SEARCH_32, width=24)
        icon_div.add(icon)
        icon_div.add_style("float: right")
        icon_div.add_style("margin-top: -5px")
        button = icon_div
        icon_div.add_class("hand")
        icon_div.add_behavior({
            'type':
            'mouseover',
            'color':
            over_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("background", bvr.color);
            '''
        })
        icon_div.add_behavior({
            'type':
            'mouseout',
            'color':
            out_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("background", bvr.color);
            bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-5");
            bvr.src_el.setStyle("margin-right", "0");
            '''
        })
        icon_div.add_behavior({
            'type':
            'click',
            'color':
            out_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("box-shadow", "0px 0px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-3");
            bvr.src_el.setStyle("margin-right", "-2");
            '''
        })
        icon_div.add_behavior({
            'type':
            'click_up',
            'color':
            out_color,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999");
            bvr.src_el.setStyle("margin-top", "-5");
            bvr.src_el.setStyle("margin-right", "0");
            '''
        })

        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_main_top");
            var search_el = top.getElement(".spt_main_search");
            var keywords = search_el.value;

            if (keywords == '') {
                return;
            }

            var class_name = 'tactic.ui.panel.ViewPanelWdg';
            var kwargs = {
                'search_type': 'sthpw/sobject_list',
                'view': 'table',
                'keywords': keywords,
                'simple_search_view': 'simple_search',
                //'show_shelf': false,
            }
            spt.tab.set_main_body_tab();
            spt.tab.add_new("Search Results", "Search Results", class_name, kwargs);
            '''
        })

        #desc = DivWdg()
        #top.add(desc)
        #desc.add("Dashboard")
        #desc.add_style("width: 600px")

        # create a bunch of panels
        table = Table()
        table.add_color("color", "color")
        table.add_style("margin-bottom: 20px")
        table.center()
        top.add(table)
        table.add_row()

        td = table.add_cell()
        td.add_style("padding: 3px")
        td.add_style("vertical-align: top")
        title = "My Approvals"
        description = '''View all pending items for approval<br/><br/>
        '''
        #image = "<img src='/context/images/getting_started_pipeline.png'/>"
        image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''
        spt.tab.set_main_body_tab();
        var class_name = 'tactic.ui.panel.ViewPanelWdg';
        var kwargs = {
            search_type: 'sthpw/sobject_list',
            view: 'client_approval',
            show_shelf: false,
            show_select: false,
            element_names: ['preview', 'name', 'description', 'task_pipeline_vertical','notes'],
            is_editable: false,
            //expression: "@SOBJECT(sthpw/task['project_code','fickle3'].fickle3/cars.sthpw/sobject_list)"
        };
        spt.tab.add_new("approvals", "Approvals", class_name, kwargs);
        '''
        }
        config_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(config_wdg)

        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
        title = "My Dashboard"
        image = "<img src='/context/icons/64x64/dashboard_64.png'/>"
        description = '''Dashboards display key project data in single views. Drill down further to work on tasks, make status changes or add notes.'''

        # read the config file
        from pyasm.widget import WidgetConfig
        tmp_path = __file__
        dir_name = os.path.dirname(tmp_path)
        file_path = "%s/../config/dashboard-conf.xml" % (dir_name)
        config = WidgetConfig.get(file_path=file_path, view="definition")

        #element_name = "my_dashboard"
        element_name = "my_dashboard"
        attrs = config.get_element_attributes(element_name)
        dashboard_data = {}
        kwargs = config.get_display_options(element_name)
        class_name = kwargs.get('class_name')

        dashboard_data['class_name'] = class_name
        dashboard_data['kwargs'] = kwargs
        dashboard_data['title'] = attrs.get("title")
        dashboard_data['description'] = attrs.get("description")
        dashboard_data['image'] = attrs.get("image")

        behavior = {
            'type':
            'click_up',
            'dashboard':
            dashboard_data,
            'cbjs_action':
            '''
        var class_name = 'tactic.ui.startup.dashboards_wdg.DashboardsWdg';
        var kwargs = {};
        spt.tab.set_main_body_tab();
        spt.tab.add_new("my_dashboard", "My Dashboard", bvr.dashboard.class_name, bvr.dashboard.kwargs);
        '''
        }
        pipeline_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(pipeline_wdg)

        td = table.add_cell()
        td.add_style("padding: 3px")
        td.add_style("vertical-align: top")
        title = "My Reports"
        image = "<img src='/context/icons/64x64/report_64.png'/>"
        description = '''TACTIC provides a number of predefined reports that project managers can access instantly to get real-time analytics.'''

        behavior = {
            'type':
            'click_up',
            'cbjs_action':
            '''
        var class_name = 'tactic.ui.startup.reports_wdg.ReportsWdg';
        var kwargs = {};
        spt.tab.set_main_body_tab();
        spt.tab.add_new("reports", "Reports", class_name, kwargs);
        //spt.panel.load_popup("Reports", class_name, kwargs);
        '''
        }

        side_bar_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(side_bar_wdg)
        """
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding: 3px")
	title = "Documentation"

        description = '''TACTIC Documentation.
        <br/><br/>
        * Project Setup Documentation<br/>
        <br/>
        * End User Documentation<br/>
        <br/>
        * Developer Documentation<br/>
        <br/>
        * System Administrator Documentation<br/>
        <br/>
        '''
        image = "<img src='/context/images/getting_started_pipeline.png'/>"
        behavior = {
        'type': 'click_up',
        'cbjs_action': '''
        spt.help.load_alias("main")
        '''
        }
        doc_wdg = my.get_section_wdg(title, description, image, behavior)
        td.add(doc_wdg)
        """

        tr, td = table.add_row_cell()
        td.add_style("font-size: 14px")
        td.add("<br/>" * 2)

        quick_links_wdg = QuickLinksWdg()
        td.add(quick_links_wdg)

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

        web = WebContainer.get_web()

        widget = Widget()
        html = HtmlElement("html")

        is_xhtml = False
        if is_xhtml:
            web.set_content_type("application/xhtml+xml")
            widget.add('''<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            ''')
            html.add_attr("xmlns", "http://www.w3.org/1999/xhtml")
            #html.add_attr("xmlns:svg", "http://www.w3.org/2000/svg")

        # add the copyright
        widget.add(my.get_copyright_wdg())
        widget.add(html)

        # create the header
        head = HtmlElement("head")
        html.add(head)

        head.add(
            '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n'
        )
        head.add('<meta http-equiv="X-UA-Compatible" content="IE=edge"/>\n')

        # Add the tactic favicon
        head.add(
            '<link rel="shortcut icon" href="/context/favicon.ico" type="image/x-icon"/>'
        )

        # add the css styling
        head.add(my.get_css_wdg())

        # add the title in the header
        project = Project.get()
        project_code = project.get_code()
        project_title = project.get_value("title")

        if web.is_admin_page():
            is_admin = " - Admin"
        else:
            is_admin = ""

        if project_code == 'admin':
            head.add("<title>TACTIC Site Admin</title>\n")
        else:
            head.add("<title>%s%s</title>\n" % (project_title, is_admin))

        # add the javascript libraries
        head.add(JavascriptImportWdg())

        # add the body
        body = my.body
        html.add(body)
        body.add_event('onload', 'spt.onload_startup(this)')

        top = my.top

        # Add a NOSCRIPT tag block here to provide a warning message on browsers where 'Enable JavaScript'
        # is not checked ... TODO: clean up and re-style to make look nicer
        top.add("""
        <NOSCRIPT>
        <div style="border: 2px solid black; background-color: #FFFF99; color: black; width: 600px; height: 70px; padding: 20px;">
        <img src="%s" style="border: none;" /> <b>Javascript is not enabled on your browser!</b>
        <p>This TACTIC powered, web-based application requires JavaScript to be enabled in order to function. In your browser's options/preferences, please make sure that the 'Enable JavaScript' option is checked on, click OK to accept the settings change, and then refresh this web page.</p>
        </div>
        </NOSCRIPT>
        """ % (IconWdg.get_icon_path("ERROR")))

        # add the content
        content_div = DivWdg()
        top.add(content_div)
        Container.put("TopWdg::content", content_div)

        # add a dummy button for global behaviors
        from tactic.ui.widget import ButtonNewWdg, IconButtonWdg
        ButtonNewWdg(title="DUMMY", icon=IconWdg.FILM)
        IconButtonWdg(title="DUMMY", icon=IconWdg.FILM)
        # NOTE: it does not need to be in the DOM.  Just needs to be
        # instantiated
        #content_div.add(button)

        if my.widgets:
            content_wdg = my.get_widget('content')
        else:
            content_wdg = Widget()
            my.add(content_wdg)

        content_div.add(content_wdg)

        # add a calendar wdg

        from tactic.ui.widget import CalendarWdg
        cal_wdg = CalendarWdg(css_class='spt_calendar_template_top')
        cal_wdg.top.add_style('display: none')
        content_div.add(cal_wdg)

        if web.is_admin_page():
            from tactic_branding_wdg import TacticCopyrightNoticeWdg
            branding = TacticCopyrightNoticeWdg(show_license_info=True)
            top.add(branding)

        # add the admin bar
        security = Environment.get_security()
        if not web.is_admin_page() and security.check_access(
                "builtin", "view_site_admin", "allow"):

            div = DivWdg()
            top.add(div)
            top.add_style("padding-top: 21px")

            div.add_class("spt_admin_bar")

            div.add_style("height: 15px")
            div.add_style("padding: 3px 0px 3px 15px")
            #div.add_style("margin-bottom: -5px")
            div.add_style("position: fixed")
            div.add_style("top: 0px")
            div.add_style("left: 0px")
            div.add_style("opacity: 0.7")
            div.add_style("width: 100%")
            #div.add_gradient("background", "background2", 20, 10)
            div.add_style("background-color", "#000")
            div.add_style("color", "#FFF")
            div.add_style("z-index", "1000")
            div.add_class("hand")
            div.set_box_shadow("0px 5px 5px")

            # remove
            icon_div = DivWdg()
            div.add(icon_div)
            icon_div.add_style("float: right")
            icon_div.add_style("margin-right: 10px")
            icon_div.add_style("margin-top: -3px")
            icon_button = IconButtonWdg(title="Remove Admin Bar",
                                        icon=IconWdg.G_CLOSE)
            icon_div.add(icon_button)
            icon_button.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                var parent = bvr.src_el.getParent(".spt_admin_bar");
                bvr.src_el.getParent(".spt_top").setStyle("padding-top", "0px");
                spt.behavior.destroy_element(parent);
                '''
            })

            div.add("<b>ADMIN >></b>")

            div.add_behavior({
                'type':
                'listen',
                'event_name':
                'close_admin_bar',
                'cbjs_action':
                '''
                bvr.src_el.getParent(".spt_top").setStyle("padding-top", "0px");
                spt.behavior.destroy_element(bvr.src_el);
                '''
            })

            div.add_behavior({
                'type':
                'mouseover',
                'cbjs_action':
                '''
                bvr.src_el.setStyle("opacity", 0.85)
                //new Fx.Tween(bvr.src_el).start('height', "30px");
                '''
            })
            div.add_behavior({
                'type':
                'mouseout',
                'cbjs_action':
                '''
                bvr.src_el.setStyle("opacity", 0.7)
                //new Fx.Tween(bvr.src_el).start('height', "15px");
                '''
            })
            project_code = Project.get_project_code()
            div.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                var url = "/tactic/%s/admin/link/_startup";
                window.open(url);

                ''' % project_code
            })

        # Add the script editor listener
        load_div = DivWdg()
        top.add(load_div)
        load_div.add_behavior({
            'type':
            'listen',
            'event_name':
            'show_script_editor',
            'cbjs_action':
            '''
        var js_popup_id = "TACTIC Script Editor";
        var js_popup = $(js_popup_id);
        if( js_popup ) {
            spt.popup.toggle_display( js_popup_id, false );
        }
        else {
            spt.panel.load_popup(js_popup_id, "tactic.ui.app.ShelfEditWdg", {}, {"load_once": true} );
        }
        '''
        })

        # deal with the palette defined in /index which can override the palette
        if my.kwargs.get("hash") == ():
            key = "index"
            search = Search("config/url")
            search.add_filter("url", "/%s/%%" % key, "like")
            search.add_filter("url", "/%s" % key)
            search.add_where("or")
            url = search.get_sobject()
            if url:
                xml = url.get_xml_value("widget")
                palette_key = xml.get_value("element/@palette")

                # look up palette the expression for index
                from pyasm.web import Palette
                palette = Palette.get()

                palette.set_palette(palette_key)
                colors = palette.get_colors()
                colors = jsondumps(colors)

                script = HtmlElement.script('''
                    var env = spt.Environment.get();
                    env.set_colors(%s);
                    env.set_palette('%s');
                    ''' % (colors, palette_key))
                top.add(script)

        env = Environment.get()
        client_handoff_dir = env.get_client_handoff_dir(include_ticket=False,
                                                        no_exception=True)
        client_asset_dir = env.get_client_repo_dir()

        login = Environment.get_login()
        user_name = login.get_value("login")
        user_id = login.get_id()
        login_groups = Environment.get_group_names()

        # add environment information
        script = HtmlElement.script('''
        var env = spt.Environment.get();
        env.set_project('%s');
        env.set_user('%s');
        env.set_user_id('%s');
        var login_groups = '%s'.split('|');
        env.set_login_groups(login_groups);
        env.set_client_handoff_dir('%s');
        env.set_client_repo_dir('%s');

        ''' % (Project.get_project_code(), user_name, user_id,
               '|'.join(login_groups), client_handoff_dir, client_asset_dir))
        top.add(script)

        # add a global container for commonly used widgets
        div = DivWdg()
        top.add(div)
        div.set_id("global_container")

        # add in the app busy widget
        # find out if there is an override for this
        search = Search("config/url")
        search.add_filter("url", "/app_busy")
        url = search.get_sobject()
        if url:
            busy_div = DivWdg()
            div.add(busy_div)

            busy_div.add_class("SPT_PUW")
            busy_div.add_styles(
                "display: none; position: absolute; z-index: 1000")

            busy_div.add_class("app_busy_msg_block")
            busy_div.add_style("width: 300px")
            busy_div.add_style("height: 100px")
            busy_div.add_style("padding: 20px")
            busy_div.add_color("background", "background3")
            busy_div.add_border()
            busy_div.set_box_shadow()
            busy_div.set_round_corners(20)
            busy_div.set_attr("id", "app_busy_msg_block")

            # put the custom url here

            title_wdg = DivWdg()
            busy_div.add(title_wdg)
            title_wdg.add_style("font-size: 20px")
            title_wdg.add_class("spt_app_busy_title")
            busy_div.add("<hr/>")
            msg_div = DivWdg()
            busy_div.add(msg_div)
            msg_div.add_class("spt_app_busy_msg")

        else:
            from page_header_wdg import AppBusyWdg
            div.add(AppBusyWdg())

        # popup parent
        popup = DivWdg()
        popup.set_id("popup")
        div.add(popup)

        # create another general popup
        popup_div = DivWdg()
        popup_div.set_id("popup_container")
        popup_div.add_class("spt_panel")
        popup = PopupWdg(id="popup_template", destroy_on_close=True)
        popup_div.add(popup)
        div.add(popup_div)

        inner_html_div = DivWdg()
        inner_html_div.set_id("inner_html")
        div.add(inner_html_div)

        # add in a global color
        from tactic.ui.input import ColorWdg
        color = ColorWdg()
        div.add(color)

        # add in a global notify wdg
        from notify_wdg import NotifyWdg
        widget.add(NotifyWdg())

        return widget
Example #52
0
    def get_chat_wdg(my, key, interval=False):

        div = DivWdg()
        div.add_class("spt_chat_session_top")
        div.add_color("background", "background")

        title_wdg = DivWdg()
        div.add(title_wdg)
        title_wdg.add_color("background", "background3")
        title_wdg.add_style("padding: 5px")
        title_wdg.add_style("font-weight: bold")
        title_wdg.add_border()

        icon = IconButtonWdg(title="Remove Chat", icon=IconWdg.DELETE)
        icon.add_style("float: right")
        icon.add_style("margin-top: -5px")
        title_wdg.add(icon)
        icon.add_behavior( {
            'type': 'click_up',
            'key': key,
            'cbjs_action': '''
            var server = TacticServerStub.get();

            var top = bvr.src_el.getParent(".spt_chat_session_top");
            spt.behavior.destroy_element(top);
            '''
        } )


        current_user = Environment.get_user_name()
        logins = Search.eval("@SOBJECT(sthpw/subscription['message_code','%s'].sthpw/login)" % key)
        for login in logins:
            if login.get_value("login") == current_user:
                continue

            thumb = ThumbWdg()
            thumb.set_icon_size(45)
            thumb.set_sobject(login)
            thumb.add_style("float: left")
            thumb.add_style("margin: -5px 10px 0px -5px")
            title_wdg.add(thumb)
            title_wdg.add(login.get_value("display_name"))

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


        history_div = DivWdg()
        div.add(history_div)
        history_div.add_class("spt_chat_history")
        history_div.add_style("width: auto")
        history_div.add_style("height: auto")
        history_div.add_style("max-height: 400px")
        history_div.add_style("padding: 5px")
        history_div.add_class("spt_resizable")

        history_div.add_border()
        history_div.add_style("overflow-y: auto")
        #history_div.add_style("font-size: 0.9em")


        search = Search("sthpw/message_log")
        search.add_filter("message_code", key)
        search.add_order_by("timestamp")
        message_logs = search.get_sobjects()
        last_login = None;
        last_date = None;
        for message_log in message_logs:

            login = message_log.get("login")
            message = message_log.get("message")
            timestamp = message_log.get_datetime_value("timestamp")
            #timestamp = timestamp.strftime("%b %d, %Y - %H:%M")
            timestamp_str = timestamp.strftime("%H:%M")
            date_str = timestamp.strftime("%b %d, %Y")
        
            msg = "";
            msg += "<table style='margin-top: 5px; font-size: 0.9em; width: 100%'><tr><td colspan='2'>";

            if date_str != last_date:
                msg += "<br/><b style='font-size: 1.0em'>"+date_str+"</b><hr/></td></tr>";
                msg += "<tr><td>";
                last_login = None

            if login != last_login:
                msg += "<b>"+login+"</b><br/>";
            msg += message.replace("\n",'<br/>');
            msg += "</td><td style='text-align: right; margin-bottom: 5px; width: 75px; vertical-align: top'>";
            msg += timestamp_str;
            msg += "</td></tr></table>";

            history_div.add(msg)

            last_login = login
            last_date = date_str

        history_div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            bvr.src_el.scrollTop = bvr.src_el.scrollHeight;
            '''
        } )


        if message_logs:
            last_message = message_logs[-1].get("message")
            last_login = message_logs[-1].get("login")
        else:
            last_message = ""
            last_login = ""
        div.add_attr("spt_last_message", last_message)
        div.add_attr("spt_last_login", last_login)




        if interval:

            div.add_behavior( {
            'type': 'load',
            'key': key,
            'cbjs_action': r'''
            var text_el = bvr.src_el.getElement(".spt_chat_text");
            var history_el = bvr.src_el.getElement(".spt_chat_history");
            var callback = function(message) {
                //history_el.setStyle("background", "red");
                var login = message.login;
                var timestamp = message.timestamp;
                if (timestamp) {
                    var parts = timestamp.split(" ");
                    parts = parts[1].split(".");
                    timestamp = parts[0];
                }
                else {
                    timestamp = "";
                }

                var tmp = message.message || "";

                var last_message = bvr.src_el.getAttribute("spt_last_message");
                var last_login = bvr.src_el.getAttribute("spt_last_login");
                if (tmp == last_message && login == last_login) {
                    return;
                }
                bvr.src_el.setAttribute("spt_last_message", tmp);
                bvr.src_el.setAttribute("spt_last_login", login);

                var msg = "";
                msg += "<table style='margin-top: 5px; font-size: 0.9em; width: 100%'><tr><td>";
                if (login != last_login) {
                    msg += "<b>"+login+"</b><br/>";
                }
                msg += tmp.replace(/\n/g,'<br/>');
                msg += "</td><td style='text-align: right; margin-bottom: 5px; width: 75px; vertical-align: top'>";
                msg += timestamp;
                msg += "</td></tr></table>";

                if (msg == history_el.last_msg) {
                    return;
                }
                history_el.innerHTML =  history_el.innerHTML + msg;

                // remember last message
                history_el.last_msg = msg;


                history_el.scrollTop = history_el.scrollHeight;
            }
            spt.message.set_interval(bvr.key, callback, 3000, bvr.src_el);
            '''
            } )

        text = TextAreaWdg("chat")
        div.add(text)
        text.add_class("spt_chat_text")
        text.add_style("width: 100%")
        text.add_style("padding: 5px")
        text.add_style("margin-top: -1px")
        
        text.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        bvr.src_el.addEvent("keydown", function(e) {

        var keys = ['tab','keys(control+enter)', 'enter'];
        var key = e.key;
        var input = bvr.src_el
        if (keys.indexOf(key) > -1) e.stop();

        if (key == 'tab') {
        }
        else if (key == 'enter') {
            if (e.control == false) {
                pass;
            }
            else {
                 // TODO: check if it's multi-line first 
                 //... use ctrl-ENTER for new-line, regular ENTER (RETURN) accepts value
                //var tvals = parse_selected_text(input);
                //input.value = tvals[0] + "\\n" + tvals[1];
                //spt.set_cursor_position( input, tvals[0].length + 1 );
            }
        }
        } )
        '''
        } )



        button = ActionButtonWdg(title="Send")
        div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'key': key,
        'cbjs_action': '''

        var top = bvr.src_el.getParent(".spt_chat_session_top");
        var text_el = top.getElement(".spt_chat_text");
        var message = text_el.value;
        if (!message) {
            return;
        }

        var history_el = top.getElement(".spt_chat_history");

        var category = "chat";
        var server = TacticServerStub.get();

        var key = bvr.key;
        var last_message = server.log_message(key, message, {category:category, status:"in_progress"});

        text_el.value = "";

            '''
        } )


        return div
Example #53
0
    def get_title_wdg(my):

        title = my.kwargs.get("title")
        if not title:
            widget = my.get_widget("title")
            if not widget and my.widgets:
                widget = my.widgets[0]
                title = widget.get_name().title()
        if not title:
            title = "No Title"

        icon = my.kwargs.get("icon")
        if not icon:
            icon = "G_FOLDER"

        title_div = DivWdg()
        title_div.add_class("spt_content_box_title")

        # icon on the left
        icon_div = DivWdg()
        title_div.add(icon_div)
        icon = IconWdg(icon=icon, width=16)
        icon_div.add(icon)
        icon_div.add_styles(
            '''float: left; height: 25px; margin-top: 0px; padding: 0px 8px 0px 5px;'''
        )

        # icon on the right
        show_gear = my.kwargs.get("show_gear")
        if show_gear in [True, 'true']:
            icon_div = DivWdg()
            title_div.add(icon_div)
            icon = IconWdg(icon="G_SETTINGS", width=16)
            icon_div.add(icon)
            icon_div.add_styles(
                '''float: right; height: 25px; margin-top: 0px; padding: 0px 8px 0px 5px;'''
            )

        icon_div = DivWdg()
        title_div.add(icon_div)
        icon = IconButtonWdg(icon="G_UP", width=16)
        icon_div.add(icon)
        icon_div.add_styles(
            '''float: right; height: 25px; margin-top: 0px; padding: 0px 8px;'''
        )
        icon_div.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_content_box");
            var content = top.getElement(".spt_content_box_content");
            var inner = top.getElement(".spt_content_box_inner");
            var state = inner.getAttribute("spt_state");
            if ( state != "closed" ) {
                var size = inner.getSize();
                dst = -size.y-5;
                inner.setAttribute("spt_state", "open");
            }
            else {
                dst = 0;
                inner.setAttribute("spt_state", "closed");
            }
            new Fx.Tween(content, {duration: 500}).start("margin-top", dst);


            '''
        })

        icon_div = DivWdg()
        title_div.add(icon_div)
        icon = IconButtonWdg(icon="G_MAXIMIZE", width=16)
        icon_div.add(icon)
        icon_div.add_styles(
            '''float: right; height: 25px; margin-top: 0px; padding: 0px 0px;'''
        )

        icon_div.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_content_box");
            if (top.hasClass("spt_content_box_max")) {
                top.removeClass("spt_content_box_max");
                top.addClass("spt_content_box_inline");
                top.size = top.getSize();
                var window_size = window.getSize();
                top.setStyle("height", window_size.y)


            }
            else {
                top.addClass("spt_content_box_max");
                top.removeClass("spt_content_box_inline");
                var size = top.size;
                top.setStyle("height", size.y)
            }
            '''
        })

        #title_div.add('''<div style="float: right; width: 20px; height: 20px; margin-top: -9px; margin-right: -8px; padding: 8px; border: solid 0px #000;">X</div>''')

        title_div.add(title)

        return title_div
Example #54
0
    def get_display(my):

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

        div = DivWdg()
        div.add_class("spt_ingest_top")
        div.add_style("width: 100%px")
        div.add_style("min-width: 500px")
        div.add_style("padding: 20px")
        div.add_color("background", "background")
        
        my.search_type = my.kwargs.get("search_type")
        if not my.search_type:
            div.add("No search type specfied")
            return div

        if relative_dir:
            folder_div = DivWdg()
            div.add(folder_div)
            folder_div.add("Folder: %s" % relative_dir)
            folder_div.add_style("opacity: 0.5")
            folder_div.add_style("font-style: italic")
            folder_div.add_style("margin-bottom: 10px")



        data_div = my.get_data_wdg()
        data_div.add_style("float: left")
        data_div.add_style("float: left")
        div.add(data_div)

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

        help_button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''spt.help.load_alias("ingestion_widget")'''
        } )

        from tactic.ui.input import Html5UploadWdg
        upload = Html5UploadWdg(multiple=True)
        div.add(upload)


        button = ActionButtonWdg(title="Add")
        button.add_style("float: right")
        button.add_style("margin-top: -3px")
        div.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'normal_ext': File.NORMAL_EXT,
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_ingest_top");
            var files_el = top.getElement(".spt_to_ingest_files");
            var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i');
        
            //clear upload progress
            var upload_bar = top.getElement('.spt_upload_progress');
            if (upload_bar) {
                upload_bar.setStyle('width','0%');
                upload_bar.innerHTML = '';
            }
        var onchange = function (evt) {
                var files = spt.html5upload.get_files();
                var delay = 0; 
                for (var i = 0; i < files.length; i++) {
                    var size = files[i].size;
                    var file_name = files[i].name;
                    var is_normal = regex.test(file_name);
                    if (size >= 10*1024*1024 || is_normal) {
                        spt.drag.show_file(files[i], files_el, 0, false);
                    }
                    else {
                        spt.drag.show_file(files[i], files_el, delay, true);

                        if (size < 100*1024)       delay += 50;
                        else if (size < 1024*1024) delay += 500;
                        else if (size < 10*1024*1024) delay += 1000;
                    }
                }
        }

            spt.html5upload.clear();
            spt.html5upload.set_form( top );
            spt.html5upload.select_file( onchange );

         '''
         } )



        button = ActionButtonWdg(title="Clear")
        button.add_style("float: right")
        button.add_style("margin-top: -3px")
        div.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_ingest_top");
            var file_els = top.getElements(".spt_upload_file");
            for ( var i = 0; i < file_els.length; i++) {
                spt.behavior.destroy( file_els[i] );
            };

         '''
         } )




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

        border_color_light = div.get_color("background2", 8)
        border_color_dark = div.get_color("background2", -15)
        background_mouseout = div.get_color("background3", 10)
        background_mouseenter = div.get_color("background3", 8)


        files_div = DivWdg()
        files_div.add_style("position: relative")
        files_div.add_class("spt_to_ingest_files")
        div.add(files_div)
        files_div.add_style("max-height: 300px")
        files_div.add_style("height: 300px")
        files_div.add_style("overflow-y: auto")
        files_div.add_style("padding: 3px")
        files_div.add_color("background", background_mouseout)
        files_div.add_style("border: 3px dashed %s" % border_color_light)
        files_div.add_style("border-radius: 20px 20px 20px 20px")
        files_div.add_style("z-index: 1")
        #files_div.add_style("display: none")

        bgcolor = div.get_color("background3")
        bgcolor2 = div.get_color("background3", -3)

        #style_text = "text-align: center; margin-top: 100px; color: #A0A0A0; font-size: 3.0em; z-index: 10;"

        background = DivWdg()
        background.add_class("spt_files_background")
        files_div.add(background)

        background.add_style("text-align: center")
        background.add_style("margin-top: 100px")
        background.add_style("opacity: 0.65")
        background.add_style("font-size: 3.0em")
        background.add_style("z-index: 10")

        background_text = DivWdg("<p>Drag Files Here</p>")

        background.add(background_text)

        files_div.add_behavior( {
            'type': 'mouseover',
            'cbjs_action': '''
            bvr.src_el.setStyle("border","3px dashed %s")
            bvr.src_el.setStyle("background","%s")
            ''' % (border_color_dark, background_mouseenter)
        } )

        files_div.add_behavior( {
            'type': 'mouseout',
            'cbjs_action': '''
            bvr.src_el.setStyle("border", "3px dashed %s")
            bvr.src_el.setStyle("background","%s")
            ''' % (border_color_light, background_mouseout)
        } ) 






        # Test drag and drop files
        files_div.add_attr("ondragenter", "return false")
        files_div.add_attr("ondragover", "return false")
        files_div.add_attr("ondrop", "spt.drag.noop(event, this)")
        files_div.add_behavior( {
        'type': 'load',
        'normal_ext': File.NORMAL_EXT,
        'cbjs_action': '''
        spt.drag = {}
        var background;

        spt.drag.show_file = function(file, top, delay, icon) {

            if (!background) {
                background = top.getElement(".spt_files_background");
                if (background)
                    background.setStyle("display", "none");
            }
            var template = top.getElement(".spt_upload_file_template");
            var clone = spt.behavior.clone(template);

            clone.removeClass("spt_upload_file_template");
            clone.addClass("spt_upload_file");
            clone.setStyle("display", "");

            if (typeof(delay) == 'undefined') {
                delay = 0;
            }

            // remember the file handle
            clone.file = file;

            var name = file.name;
            var size = parseInt(file.size / 1024 * 10) / 10;

            var thumb_el = clone.getElement(".spt_thumb");
            var date_label_el = clone.getElement(".spt_date_label");
            var date_el = clone.getElement(".spt_date");

            //var loadingImage = loadImage(
            setTimeout( function() {
                var draw_empty_icon = function() {
                        var img = $(document.createElement("div"));
                        img.setStyle("width", "58");
                        img.setStyle("height", "34");
                        //img.innerHTML = "MP4";
                        img.setStyle("border", "1px dotted #222")
                        thumb_el.appendChild(img);
                    };
                if (icon) {
                        var loadingImage = loadImage(
                            file,
                            function (img) {
                            if (img.width)
                                thumb_el.appendChild(img);
                            else
                                draw_empty_icon();
                                
                            },
                            {maxWidth: 80, maxHeight: 60, canvas: true, contain: true}
                        );
                        
                }
                else {
                    draw_empty_icon();
                }


                loadImage.parseMetaData(
                    file,
                    function(data) {
                        if (data.exif) {
                            var date = data.exif.get('DateTimeOriginal');
                            if (date) {
                                date_label_el.innerHTML = date;
                                if (date_el) {
                                    date_el.value = date;
                                }
                            }
                        }

                    }
                );

            }, delay );

            /*
            var reader = new FileReader();
            reader.thumb_el = thumb_el;
            reader.onload = function(e) {
                this.thumb_el.innerHTML = [
                    '<img class="thumb" src="',
                    e.target.result,
                    '" title="', escape(name),
                    '" width="60px"',
                    '" padding="5px"',
                    '"/>'
                ].join('');
            }
            reader.readAsDataURL(file);
            */
         
            clone.getElement(".spt_name").innerHTML = file.name;
            clone.getElement(".spt_size").innerHTML = size + " KB";
            clone.inject(top);
        }

        spt.drag.noop = function(evt, el) {
            var top = $(el).getParent(".spt_ingest_top");
            var files_el = top.getElement(".spt_to_ingest_files");
            evt.stopPropagation();
            evt.preventDefault();
            evt.dataTransfer.dropEffect = 'copy';
            var files = evt.dataTransfer.files;

            var delay = 0;
            var skip = false;
            var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i');
            for (var i = 0; i < files.length; i++) {
                var size = files[i].size;
                var file_name = files[i].name;
                var is_normal = regex.test(file_name);
                if (size >= 10*1024*1024 || is_normal) {
                    spt.drag.show_file(files[i], files_el, 0, false);
                }
                else {
                    spt.drag.show_file(files[i], files_el, delay, true);

                    if (size < 100*1024)       delay += 50;
                    else if (size < 1024*1024) delay += 500;
                    else if (size < 10*1024*1024) delay += 1000;
                }

            }
        }
        '''
        } )

        # create a template that will be filled in for each file
        files_div.add_relay_behavior( {
            'type': 'mouseenter',
            'color': files_div.get_color("background3", -5),
            'bvr_match_class': 'spt_upload_file',
            'cbjs_action': '''
            bvr.src_el.setStyle("background", bvr.color);
            '''
        } )
        files_div.add_relay_behavior( {
            'type': 'mouseleave',
            'bvr_match_class': 'spt_upload_file',
            'cbjs_action': '''
            bvr.src_el.setStyle("background", "");
            '''
        } )
        files_div.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': 'spt_remove',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_upload_file");
            spt.behavior.destroy_element(top);
            '''
        } )


        """
        metadata_view = "test/wizard/metadata"
        files_div.add_relay_behavior( {
            'type': 'mouseup',
            'view': metadata_view,
            'bvr_match_class': 'spt_upload_file',
            'cbjs_action': '''
            var class_name = 'tactic.ui.panel.CustomLayoutWdg';
            var kwargs = {
                view: bvr.view
            }
            spt.app_busy.show("Loading Metadata");
            spt.panel.load_popup("Metadata", class_name, kwargs);
            spt.app_busy.hide();
            '''
        } )
        """



        # template for each file item
        file_template = DivWdg()
        file_template.add_class("spt_upload_file_template")
        files_div.add(file_template)
        file_template.add_style("margin-bottom: 3px")
        file_template.add_style("padding: 3px")
        file_template.add_style("height: 40px")
        file_template.add_style("display: none")

        thumb_div = DivWdg()
        file_template.add(thumb_div)
        thumb_div.add_style("float: left")
        thumb_div.add_style("width: 60");
        thumb_div.add_style("height: 40");
        thumb_div.add_style("overflow: hidden");
        thumb_div.add_style("margin: 3 10 3 0");
        thumb_div.add_class("spt_thumb")


        info_div = DivWdg()
        file_template.add(info_div)
        info_div.add_style("float: left")

        name_div = DivWdg()
        name_div.add_class("spt_name")
        info_div.add(name_div)
        name_div.add("image001.jpg")
        name_div.add_style("width: 150px")



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

        dialog_data_div = DivWdg()
        dialog_data_div.add_color("background", "background")
        dialog_data_div.add_style("padding", "10px")

        dialog.add(dialog_data_div)
        dialog_data_div.add("Category: ")
        text = TextInputWdg(name="category")
        dialog_data_div.add(text)
        text.add_class("spt_category")
        text.add_style("padding: 1px")
        """

        date_div = DivWdg()
        date_div.add_class("spt_date_label")
        info_div.add(date_div)
        date_div.add("")
        date_div.add_style("opacity: 0.5")
        date_div.add_style("font-size: 0.8em")
        date_div.add_style("font-style: italic")
        date_div.add_style("margin-top: 3px")

        hidden_date_div = HiddenWdg("date")
        hidden_date_div.add_class("spt_date")
        info_div.add(date_div)




        size_div = DivWdg()
        size_div.add_class("spt_size")
        file_template.add(size_div)
        size_div.add("433Mb")
        size_div.add_style("float: left")
        size_div.add_style("width: 150px")
        size_div.add_style("text-align: right")

        remove_div = DivWdg()
        remove_div.add_class("spt_remove")
        file_template.add(remove_div)
        icon = IconButtonWdg(title="Remove", icon=IconWdg.DELETE)
        icon.add_style("float: right")
        remove_div.add(icon)
        #remove_div.add_style("text-align: right")


        div.add("<br/>")



        info = DivWdg()
        div.add(info)
        info.add_class("spt_upload_info")


        progress_div = DivWdg()
        progress_div.add_class("spt_upload_progress_top")
        div.add(progress_div)
        progress_div.add_style("width: 100%")
        progress_div.add_style("height: 15px")
        progress_div.add_style("margin-bottom: 10px")
        progress_div.add_border()
        #progress_div.add_style("display: none")

        progress = DivWdg()
        progress_div.add(progress)
        progress.add_class("spt_upload_progress")
        progress.add_style("width: 0px")
        progress.add_style("height: 100%")
        progress.add_gradient("background", "background3", -10)
        progress.add_style("text-align: right")
        progress.add_style("overflow: hidden")
        progress.add_style("padding-right: 3px")

        from tactic.ui.app import MessageWdg
        progress.add_behavior( {
            'type': 'load',
            'cbjs_action': MessageWdg.get_onload_js()
        } )



        # NOTE: files variable is passed in automatically

        upload_init = '''
        server.start( {description: "Upload and check-in of ["+files.length+"] files"} );
        var info_el = top.getElement(".spt_upload_info");
        info_el.innerHTML = "Uploading ...";
        '''

        upload_progress = '''
        var top = bvr.src_el.getParent(".spt_ingest_top");
        progress_el = top.getElement(".spt_upload_progress");
        var percent = Math.round(evt.loaded * 100 / evt.total);
        progress_el.setStyle("width", percent + "%");
        progress_el.innerHTML = String(percent) + "%";


        '''
        
        oncomplete_script_path = my.kwargs.get("oncomplete_script_path")
        oncomplete_script = ''
        if oncomplete_script_path:
            script_folder, script_title = oncomplete_script_path.split("/")
            oncomplete_script_expr = "@GET(config/custom_script['folder','%s']['title','%s'].script)" %(script_folder,script_title)    
            server = TacticServerStub.get()
            oncomplete_script_ret = server.eval(oncomplete_script_expr, single=True)
            
            if oncomplete_script_ret:
                oncomplete_script = '''var top = bvr.src_el.getParent(".spt_ingest_top");
                var file_els = top.getElements(".spt_upload_file");
                for ( var i = 0; i < file_els.length; i++) {
                spt.behavior.destroy( file_els[i] );
                };''' + oncomplete_script_ret
                script_found = True
            else:
                script_found = False
                oncomplete_script = "alert('Error: oncomplete script not found');"

        if not oncomplete_script:
            oncomplete_script = '''
            var click_action = function() {
                var fade = true;
                var pop = spt.popup.get_popup(top)
                spt.popup.close(pop, fade); 
            }
            spt.info("Ingest Completed", {click: click_action});
            server.finish();

            var file_els = top.getElements(".spt_upload_file");
            for ( var i = 0; i < file_els.length; i++) {
                spt.behavior.destroy( file_els[i] );
            };
            var background = top.getElement(".spt_files_background");
            background.setStyle("display", "");

            spt.message.stop_interval(key);

            var info_el = top.getElement(".spt_upload_info");
            info_el.innerHTML = ''; 

            if (spt.table)
            {
                spt.table.run_search();
            }
            
            spt.panel.refresh(top);
            '''
            script_found = True
        
        on_complete = '''
        var top = bvr.src_el.getParent(".spt_ingest_top");
        var update_data_top = top.getElement(".spt_edit_top");
        var progress_el = top.getElement(".spt_upload_progress");
        progress_el.innerHTML = "100%";
        progress_el.setStyle("width", "100%");

        var info_el = top.getElement(".spt_upload_info");
        
        var search_type = bvr.kwargs.search_type;
        var relative_dir = bvr.kwargs.relative_dir;
        
        var update_mode_select = top.getElement(".spt_update_mode_select");
        var update_mode = update_mode_select.value;

        var filenames = [];
        for (var i = 0; i != files.length;i++) {
            var name = files[i].name;
            filenames.push(name);
        }

        var key = spt.message.generate_key();
        var values = spt.api.get_input_values(top);
        //var category = values.category[0];
        //var keywords = values.keywords[0];

        var extra_data = values.extra_data ? values.extra_data[0]: {};
        var parent_key = values.parent_key[0];

        var convert_el = top.getElement(".spt_image_convert")
        var convert = spt.api.get_input_values(convert_el);

        var processes = values.process;
        if (processes) {
            process = processes[0];
            if (!process) {
                process = null;
            }
        }
        else {
            process = null;
        }

        var return_array = false;
        var update_data = spt.api.get_input_values(update_data_top, null, return_array);

        var kwargs = {
            search_type: search_type,
            relative_dir: relative_dir,
            filenames: filenames,
            key: key,
            parent_key: parent_key,
            //category: category,
            //keywords: keywords,
            extra_data: extra_data,
            update_data: update_data,
            process: process,
            convert: convert,
            update_mode: update_mode,
        }
        on_complete = function(rtn_data) {

        ''' + oncomplete_script + '''

        };

        var class_name = bvr.action_handler;
        // TODO: make the async_callback return throw an e so we can run 
        // server.abort
        server.execute_cmd(class_name, kwargs, null, {on_complete:on_complete});
        
        
        on_progress = function(message) {
            msg = JSON.parse(message.message);
            var percent = msg.progress;
            var description = msg.description;
            info_el.innerHTML = description;

            progress_el.setStyle("width", percent+"%");
            progress_el.innerHTML = percent + "%";
        }
        spt.message.set_interval(key, on_progress, 2000);

        '''


        upload_div = DivWdg()
        div.add(upload_div)
        #button = UploadButtonWdg(**kwargs)
        button = ActionButtonWdg(title="Ingest")
        upload_div.add(button)
        button.add_style("float: right")
        upload_div.add_style("margin-bottom: 15px")
        upload_div.add("<br clear='all'/>")


        action_handler = my.kwargs.get("action_handler")
        if not action_handler:
            action_handler = 'tactic.ui.tools.IngestUploadCmd';
 
        button.add_behavior( {
            'type': 'click_up',
            'action_handler': action_handler,
            'kwargs': {
                'search_type': my.search_type,
                'relative_dir': relative_dir,
                'script_found': script_found,
            },
            'cbjs_action': '''

            if (bvr.kwargs.script_found != true)
            {
                spt.alert("Error: provided on_complete script not found");
                return;
            }

            var top = bvr.src_el.getParent(".spt_ingest_top");
           
            var file_els = top.getElements(".spt_upload_file");

            // get the server that will be used in the callbacks
            var server = TacticServerStub.get();

            // retrieved the stored file handles
            var files = [];
            for (var i = 0; i < file_els.length; i++) {
                files.push( file_els[i].file );
            }
            if (files.length == 0) {
                alert("Either click 'Add' or drag some files over to ingest.");
                return;
            }


            // defined the callbacks
            var upload_start = function(evt) {
            }

            var upload_progress = function(evt) {
            %s;
            }

            var upload_complete = function(evt) {
            %s;
            spt.app_busy.hide();
            }


            var upload_file_kwargs =  {
                files: files,
                upload_start: upload_start,
                upload_complete: upload_complete,
                upload_progress: upload_progress
            };
            if (bvr.ticket)
               upload_file_kwargs['ticket'] = bvr.ticket; 

            %s;

            spt.html5upload.set_form( top );
            spt.html5upload.upload_file(upload_file_kwargs);

            ''' % (upload_progress, on_complete, upload_init)
        } )


        return div