示例#1
0
    def get_advanced_definition_wdg(self):
        # add the advanced entry
        advanced = DivWdg()
        advanced.add_style("margin-top: 10px")
        advanced.add_style("padding: 10px")
        advanced.add_border()
        title = DivWdg()
        title.add_style("color: black")
        title.add("Advanced - XML Column Definition")
        title.add_style("margin-top: -23")
        advanced.add(title)
        advanced.add("<br/>")

        input = TextAreaWdg("config_xml")
        input.set_id("config_xml")
        input.set_option("rows", "10")
        input.set_option("cols", "70")
        input.set_value(self.config_string)
        advanced.add(input)
        advanced.add(HtmlElement.br(2))

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

        button = ActionButtonWdg(title="Save Definition") 
        #button = ProdIconButtonWdg("Save Definition")
        button.add_event("onclick", "spt.custom_project.save_definition_cbk()")
        button_div.add(button)
        button_div.add_style("margin-left: 130px")
        advanced.add(button_div)

        return advanced
示例#2
0
    def get_checkin(my):
        '''the button which initiates the checkin'''
        # create the button with the javascript function
        widget = Widget()
        #button = TextBtnWdg(label=my.PUBLISH_BUTTON, size='large', width='100', side_padding='20', vert_offset='-5')
        #button.get_top_el().add_class('smaller')
        button = ActionButtonWdg(title=my.PUBLISH_BUTTON, tip='Publish the selected assets')
        button.add_style('margin-bottom: 10px')
        #button.add_color("background", "background")

        hidden = HiddenWdg(my.PUBLISH_BUTTON, '')
        button.add( hidden )
       
        '''
        status_sel = SelectWdg('checkin_status', label='Status: ')
        status_sel.set_option('setting', 'checkin_status')
        status_sel.set_persist_on_submit()
        status_sel.add_empty_option('-- Checkin Status --')
        widget.add(status_sel)
        '''
        widget.add(button)

        # custom defined 
        server_cbk = "pyasm.prod.web.AssetCheckinCbk"
        #TODO: make other Publish Buttons call their own handle_input function
        exec( Common.get_import_from_class_path(server_cbk) )
        exec( "%s.handle_input(button, my.search_type, my.texture_search_type)" % server_cbk)

        return widget
示例#3
0
    def get_save_button(my,checkin_keys):
        save_button = ActionButtonWdg(title="Save >>", tip="Save configuration and start using TACTIC")
   
        save_button.add_style("float: right")
        save_button.add_behavior( {
            'type': 'click_up',
            'os' : os.name, 
            'checkin_options':checkin_keys,
            'cbjs_action': '''
            
            var top = bvr.src_el.getParent(".spt_db_config_top");
            var failed_els = top.getElements('.spt_input_validation_failed')
            if (failed_els.length > 0){
                spt.alert('One of the fields fail validation. Please correct it before saving')
                return;
            }
            spt.app_busy.show("Saving configuration. Please wait...")
            var values = spt.api.Utility.get_input_values(top, null, false);
            var class_name = 'tactic.ui.startup.DbConfigSaveCbk';
            var server = TacticServerStub.get();
            var kwargs = {checkin_options:bvr.checkin_options};
            try {
                var ret_val = server.execute_cmd(class_name, kwargs, values);
                var info = ret_val.info;
            }
            catch(e) {
                log.critical(spt.exception.handler(e));
                //FIXME: recognize it's a 502 which is normal and pass , otherwise throw the error
                //spt.error(spt.exception.handler(e));
                //spt.app_busy.hide();
                //return;
            }

           
            
            // This means TACTIC was restarted
            
            if (typeof(info) == 'undefined' || bvr.os == 'nt' ) {
                spt.app_busy.show("Restarting TACTIC ...");
                var id = setInterval( function() {
                    var ping_rtn =  server.ping();
                    if (ping_rtn) {
                        window.location = '/tactic';
                        clearInterval(id);
                    }
                  
                }, 5000 );

            }
            else if (info.error) {
                spt.alert(info.error);
                spt.app_busy.hide();
            }
            else {
                window.location = '/tactic';
            }

            '''
            } )
        return save_button
    def get_advanced_definition_wdg(my):
        # add the advanced entry
        advanced = DivWdg()
        advanced.add_style("margin-top: 10px")
        advanced.add_style("padding: 10px")
        advanced.add_border()
        title = DivWdg()
        title.add_style("color: black")
        title.add("Advanced - XML Column Definition")
        title.add_style("margin-top: -23")
        advanced.add(title)
        advanced.add("<br/>")

        input = TextAreaWdg("config_xml")
        input.set_id("config_xml")
        input.set_option("rows", "10")
        input.set_option("cols", "70")
        input.set_value(my.config_string)
        advanced.add(input)
        advanced.add(HtmlElement.br(2))

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

        button = ActionButtonWdg(title="Save Definition")
        #button = ProdIconButtonWdg("Save Definition")
        button.add_event("onclick", "spt.custom_project.save_definition_cbk()")
        button_div.add(button)
        button_div.add_style("margin-left: 130px")
        advanced.add(button_div)

        return advanced
示例#5
0
    def handle_python_script_test(self, top):
        top.add(DivWdg('Python Script Test', css='spt_info_title'))
        table = Table(css='script')
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        table.add_style("width: 100%")
        top.add(table)
        table.add_row()
        td = table.add_cell("Script Path: ")
        td.add_style("width: 150px")
        text = TextWdg('script_path')
        td = table.add_cell(text)
        button = ActionButtonWdg(title='Run')
        table.add_cell(button)
        button.add_style("float: right")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
             var s = TacticServerStub.get();
             try {
                var path =  bvr.src_el.getParent('.script').getElement('.spt_input').value;
                if (! path)
                    throw('Please enter a valid script path');
                s.execute_cmd('tactic.command.PythonCmd', {script_path: path});
             } catch(e) {
                spt.alert(spt.exception.handler(e));
             }

        '''
        })
示例#6
0
    def get_search_wdg(self):
        search_div = DivWdg()

        if self.kwargs.get('run_search_bvr'):
            run_search_bvr = self.kwargs.get('run_search_bvr')
        else:
            run_search_bvr = {
                'type': 'click_up',
                'cbjs_action': '''
                spt.simple_search.hide();
                spt.dg_table.search_cbk(evt, bvr);
                ''',
                'new_search': True,
                'panel_id': self.prefix
            }

        title = "Apply"

        button = ActionButtonWdg(title=title,
                                 tip='Run search with this criteria')
        search_div.add(button)
        #button.add_style("margin-top: -7px")
        button.add_behavior(run_search_bvr)

        return search_div
示例#7
0
    def get_tools_wdg(self):

        div = DivWdg()
        div.set_name("Tools")
        div.add_style("padding: 10px")

        div.add("This tool will export out a version of the project")

        button = ActionButtonWdg(title="Export")
        div.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'server': self.server_code,
            'cbjs_action': '''
            var class_name = 'tactic.ui.sync.SyncCreateTemplateCmd';
            var kwargs = {
                server: bvr.server
            }
            spt.app_busy.show("Exporting project ...");
            var server = TacticServerStub.get();
            server.execute_cmd(class_name, kwargs);
            spt.app_busy.hide();

            spt.panel.refresh(bvr.src_el);

            '''
        } )



        return div
示例#8
0
    def get_tools_wdg(my):

        div = DivWdg()
        div.set_name("Tools")
        div.add_style("padding: 10px")

        div.add("This tool will export out a version of the project")

        button = ActionButtonWdg(title="Export")
        div.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'server': my.server_code,
            'cbjs_action': '''
            var class_name = 'tactic.ui.sync.SyncCreateTemplateCmd';
            var kwargs = {
                server: bvr.server
            }
            spt.app_busy.show("Exporting project ...");
            var server = TacticServerStub.get();
            server.execute_cmd(class_name, kwargs);
            spt.app_busy.hide();

            spt.panel.refresh(bvr.src_el);

            '''
        } )



        return div
示例#9
0
    def get_search_wdg(self):
        search_div = DivWdg()

        if self.kwargs.get('run_search_bvr'):
            run_search_bvr = self.kwargs.get('run_search_bvr')
        else:
            run_search_bvr = {
                'type':         'click_up',
                'cbjs_action':  '''
                spt.simple_search.hide();
                spt.dg_table.search_cbk(evt, bvr);
                ''',
                'new_search':   True,
                'panel_id':     self.prefix
            }


        title = "Apply"

        button = ActionButtonWdg(title=title, tip='Run search with this criteria' )
        search_div.add(button)
        #button.add_style("margin-top: -7px")
        button.add_behavior( run_search_bvr )

        return search_div
示例#10
0
 def handle_sidebar_clear(self, top):
     top.add(DivWdg('Clear Side Bar Cache ', css='spt_info_title'))
     table = Table()
     table.add_color("color", "color")
     table.add_style("margin: 10px")
     top.add(table)
     table.add_row()
     td = table.add_cell("Clear the Side Bar Cache for all users")
     td.add_style("width: 250px")
     button = ActionButtonWdg(title='Run')
     table.add_cell(button)
     button.add_behavior({
         'type':
         'click_up',
         'cbjs_action':
         '''
         try {
         var s = TacticServerStub.get();
         s.execute_cmd('tactic.ui.app.ClearSideBarCache');
         
         } catch(e) {
             spt.alert(spt.exception.handler(e));
         }
         spt.info('Side Bar cache cleared.')
     '''
     })
示例#11
0
    def handle_load_balancing(self, top):
        # deal with asset directories
        top.add(DivWdg('Load Balancing', css='spt_info_title'))
        table = Table()
        table.add_class("spt_loadbalance")
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        top.add(table)
        table.add_row()
        td = table.add_cell("Load Balancing: ")
        td.add_style("width: 150px")

        button = ActionButtonWdg(title='Test')
        td = table.add_cell(button)
        message_div = DivWdg()
        message_div.add_class("spt_loadbalance_message")
        table.add_cell(message_div)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var server = TacticServerStub.get()
        var ports = {};
        var count = 0;
        for (var i = 0; i < 50; i++) {
          var info = server.get_connection_info();
          var port = info.port;
          var num = ports[port];
          if (!num) {
            ports[port] = 1;
            count += 1;
          }
          else {
            ports[port] += 1;
          }
          // if there are 10 requests and still only one, then break
          if (i == 10 && count == 1)
            break;
        }


        // build the ports string
        x = [];
        for (i in ports) {
            x.push(i);
        }
        x.sort();
        x = x.join(", ");

        var loadbalance_el = bvr.src_el.getParent(".spt_loadbalance");
        var message_el = loadbalance_el.getElement(".spt_loadbalance_message");
        if (count > 1) {
            var message = "Yes (found " + count + " ports: "+x+")";
        }
        else {
            var message = "<blink style='background: red; padding: 3px'>Not enabled (found only port " + x + ")</blink>";
        }
        message_el.innerHTML = message
        '''
        } )
示例#12
0
    def get_display(self):

        top = self.top

        upload = Html5UploadWdg(name="formxyz")
        top.add(upload)
        upload_id = upload.get_upload_id()

        color = self.kwargs.get("color")
        width = self.kwargs.get("width")

        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title="Upload", color=color, width=width)
        top.add(button)
        button.add_behavior({
            'type':
            'click_up',
            'upload_id':
            upload_id,
            'cbjs_action':
            '''

            // set the form
            spt.html5upload.form = $(bvr.upload_id);

            // set an action for completion
            var upload_complete = function(evt) {
                var search_key = "sthpw/login?code=admin";
                var server = TacticServerStub.get();
                var file = spt.html5upload.get_file();
                if (file) {
                   file_name = file.name;
                     
                   server.simple_checkin(search_key, "icon", file_name, {mode:'uploaded'});
                }
                else 
                  alert('Error: file object cannot be found.')

            }

            var upload_progress = function(evt) {
                var percent = Math.round(evt.loaded * 100 / evt.total);
            }

            var onchange = function () {
                spt.html5upload.upload_file( {
                  upload_complete: upload_complete,
                  upload_progress: upload_progress 
                } );
            }


  
            spt.html5upload.select_file( onchange);

            '''
        })

        return top
示例#13
0
    def get_display(self):

        top = self.top

        upload = Html5UploadWdg(name="formxyz")
        top.add(upload)
        upload_id = upload.get_upload_id()

        color = self.kwargs.get("color")
        width = self.kwargs.get("width")

        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title="Upload", color=color, width=width)
        top.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'upload_id': upload_id,
            'cbjs_action': '''

            // set the form
            spt.html5upload.form = $(bvr.upload_id);

            // set an action for completion
            var upload_complete = function(evt) {
                var search_key = "sthpw/login?code=admin";
                var server = TacticServerStub.get();
                var file = spt.html5upload.get_file();
                if (file) {
                   file_name = file.name;
                     
                   server.simple_checkin(search_key, "icon", file_name, {mode:'uploaded'});
                }
                else 
                  alert('Error: file object cannot be found.')

            }

            var upload_progress = function(evt) {
                var percent = Math.round(evt.loaded * 100 / evt.total);
            }

            var onchange = function () {
                spt.html5upload.upload_file( {
                  upload_complete: upload_complete,
                  upload_progress: upload_progress 
                } );
            }


  
            spt.html5upload.select_file( onchange);

            '''
        } )

        return top
示例#14
0
文件: error_wdg.py 项目: 0-T-0/TACTIC
    def get_error_wdg(my):
        div = DivWdg()
        error_div = DivWdg()
        error_div.add("Error %s" % my.status)
        div.add(error_div)
        error_div.add_style("font-size: 18px")
        error_div.add_style("font-weight: bold")
        error_div.add_style("padding: 10px")
        error_div.add_style("width: auto")
        error_div.add_gradient("background", "background")
        error_div.add_border()
        error_div.add_style("margin-left: 5px")
        error_div.add_style("margin-right: 5px")
        error_div.add_style("margin-top: -10px")

        div.add("<br/>")


        span = DivWdg()
        #span.add_color("color", "color")
        span.add_style("color", "#FFF")
        if my.status == 404:
            span.add(HtmlElement.b("You have tried to access a url that is not recognized."))
        else:
            span.add(HtmlElement.b(my.message))
        span.add(HtmlElement.br(2))

        web = WebContainer.get_web()
        root = web.get_site_root()
        if my.message.startswith('No project ['):
            label = 'You may need to correct the default_project setting in the TACTIC config.'
        else:
            label = "Go to the Main page for a list of valid projects"
        span.add(label)
        div.add(span)
        div.add(HtmlElement.br())

        from tactic.ui.widget import ActionButtonWdg
        button_div = DivWdg()
        button_div.add_style("width: 90px")
        button_div.add_style("margin: 0px auto")

        div.add(button_div)
        button = ActionButtonWdg(title="Go to Main", tip='Click to go to main page')
        button_div.add(button)
        
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        document.location = '/';
        '''
        } )
        button.add_event("onmouseup", "document.location='/'")

        return div
示例#15
0
    def get_error_wdg(my):
        div = DivWdg()
        error_div = DivWdg()
        error_div.add("Error %s" % my.status)
        div.add(error_div)
        error_div.add_style("font-size: 16px")
        error_div.add_style("font-weight: bold")
        error_div.add_style("width: 97%")
        error_div.add_gradient("background", "background")
        error_div.add_border()
        error_div.add_style("margin-left: 5px")
        error_div.add_style("margin-top: -10px")

        div.add("<br/>")

        span = DivWdg()
        #span.add_color("color", "color")
        span.add_style("color", "#FFF")
        if my.status == 404:
            span.add(
                HtmlElement.b(
                    "You have tried to access a url that is not recognized."))
        else:
            span.add(HtmlElement.b(my.message))
        span.add(HtmlElement.br(2))

        web = WebContainer.get_web()
        root = web.get_site_root()
        if my.message.startswith('No project ['):
            label = 'You may need to correct the default_project setting in the TACTIC config.'
        else:
            label = "Go to the Main page for a list of valid projects"
        span.add(label)
        div.add(span)
        div.add(HtmlElement.br())

        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title="Go to Main",
                                 tip='Click to go to main page')
        div.add(button)

        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        document.location = '/tactic';
        '''
        })
        button.add_event("onmouseup", "document.location='/tactic'")
        button.add_style("margin-left: auto")
        button.add_style("margin-right: auto")

        return div
示例#16
0
    def get_display(my):
        top = DivWdg()
     
        top.add_style("width: 100%")
        top.add_color("background", "background", -10)
        top.add_style("padding-top: 30px")
        top.add_style("padding-bottom: 50px")
        top.add_class("twog_wizard_top")

        inner = DivWdg()
        top.add(inner)

        # set the width and height here
        inner.add_style("width: 800px")
        inner.add_style("min-height: 600px")
        inner.add_style("float: center")
        inner.add_border()
        inner.center()
        inner.add_style("padding: 20px")
        inner.add_color("background", "background")


        from tactic.ui.container import WizardWdg


        title = DivWdg()
        title.add("Step 1")

        wizard = WizardWdg(title=title)
        my.wizard = wizard
        inner.add(wizard)


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

        page_one = my.get_page_one()
        wizard.add(page_one, 'Step 1')
        page_two = my.get_page_two()
        wizard.add(page_two, 'Step 2')
        page_three = my.get_page_three()
        wizard.add(page_three, 'Step 3')
        page_four = my.get_page_four()
        wizard.add(page_four, 'Step 4')


        return top
示例#17
0
    def get_display(my):

        search_key = ''
        sobj = my.get_current_sobject()

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

        span = ActionButtonWdg(title="Email Test")
        #span = ProdIconButtonWdg('Email Test')
        top.add(span)
        span.add_behavior(my.get_behavior(sobj))

        return top
示例#18
0
    def get_display(my):
         
        search_key = ''
        sobj = my.get_current_sobject()

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

        span = ActionButtonWdg(title="Email Test")
        #span = ProdIconButtonWdg('Email Test')
        top.add(span)
        span.add_behavior(my.get_behavior(sobj))


        return top
示例#19
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)
        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
示例#20
0
    def get_add_chat_wdg(my):

        div = DivWdg()
        div.add_border()
        div.add_style("padding: 20px")
        div.add_class("spt_add_chat_top")

        table = Table()
        table.add_style("width: auto")
        div.add(table)
        table.add_row()

        text = TextInputWdg(title="user", icon="USER_ADD")
        table.add_cell(text)
        text.add_class("spt_add_chat_user")

        add_button = ActionButtonWdg(title="Start Chat")
        table.add_cell(add_button)
        add_button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_add_chat_top");
            var el = top.getElement(".spt_add_chat_user");
            var user = el.value;
            if (!user) {
                alert("Specify a valid user to chat with");
                return;
            }

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

            var class_name = 'tactic.ui.app.ChatCmd';
            var kwargs = {
                users: [user]
            }
            server.execute_cmd(class_name, kwargs);

            spt.panel.refresh(bvr.src_el);
            '''
        })

        return div
示例#21
0
    def get_add_chat_wdg(my):

        div = DivWdg()
        div.add_border()
        div.add_style("padding: 20px")
        div.add_class("spt_add_chat_top")

        table = Table()
        table.add_style("width: auto")
        div.add(table)
        table.add_row()

        text = TextInputWdg(title="user", icon="USER_ADD")
        table.add_cell(text)
        text.add_class("spt_add_chat_user")


        add_button = ActionButtonWdg(title="Start Chat")
        table.add_cell(add_button)
        add_button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_add_chat_top");
            var el = top.getElement(".spt_add_chat_user");
            var user = el.value;
            if (!user) {
                alert("Specify a valid user to chat with");
                return;
            }

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

            var class_name = 'tactic.ui.app.ChatCmd';
            var kwargs = {
                users: [user]
            }
            server.execute_cmd(class_name, kwargs);

            spt.panel.refresh(bvr.src_el);
            '''
        } )

        return div
示例#22
0
    def get_search_wdg(my):
        search_div = DivWdg()

        if my.kwargs.get('run_search_bvr'):
            run_search_bvr = my.kwargs.get('run_search_bvr')
        else:
            run_search_bvr = {
                'type':         'click_up',
                'cbjs_action':  'spt.dg_table.search_cbk(evt, bvr)',
                'new_search':   True,
                'panel_id':     my.prefix
            }

        button = ActionButtonWdg(title='Search', tip='Run search with this criteria' )
        search_div.add(button)
        #button.add_style("margin-top: -7px")
        button.add_behavior( run_search_bvr )

        return search_div
示例#23
0
    def get_search_wdg(my):
        search_div = DivWdg()

        if my.kwargs.get('run_search_bvr'):
            run_search_bvr = my.kwargs.get('run_search_bvr')
        else:
            run_search_bvr = {
                'type':         'click_up',
                'cbjs_action':  'spt.dg_table.search_cbk(evt, bvr)',
                'new_search':   True,
                'panel_id':     my.prefix
            }

        button = ActionButtonWdg(title='Search', tip='Run search with this criteria' )
        search_div.add(button)
        #button.add_style("margin-top: -7px")
        button.add_behavior( run_search_bvr )

        return search_div
示例#24
0
    def get_activator_wdg(self, title):

        color = self.kwargs.get("color")
        width = self.kwargs.get("width")

        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title=title,
                                 color=color,
                                 width=width,
                                 size='b')
        return button
示例#25
0
    def get_save_button(my,checkin_keys):
        save_button = ActionButtonWdg(title="Save >>", tip="Save configuration and start using TACTIC")
   
        save_button.add_style("float: right")
        save_button.add_behavior( {
            'type': 'click_up',
            'os' : os.name, 
            'checkin_options':checkin_keys,
            'cbjs_action': '''
            spt.app_busy.show("Saving configuration. Please wait...")
            var top = bvr.src_el.getParent(".spt_db_config_top");
            var values = spt.api.Utility.get_input_values(top, null, false);
            var class_name = 'tactic.ui.startup.DbConfigSaveCbk';
            var server = TacticServerStub.get();
            var kwargs = {checkin_options:bvr.checkin_options};

            var ret_val = server.execute_cmd(class_name, kwargs, values);
            var info = ret_val.info;
            
            // This means TACTIC was restarted
            if (typeof(info) == 'undefined' || bvr.os == 'nt' ) {
                spt.app_busy.show("Restarting TACTIC ...");
                var id = setInterval( function() {
                    var ping_rtn =  server.ping();
                    if (ping_rtn) {
                        window.location = '/tactic';
                        clearInterval(id);
                    }
                  
                }, 5000 );

            }
            else if (info.error) {
                spt.alert(info.error);
            }
            else {
                window.location = '/tactic';
            }
            '''
            } )
        return save_button
    def get_checkin(my):
        '''the button which initiates the checkin'''
        # create the button with the javascript function
        widget = Widget()
        #button = TextBtnWdg(label=my.PUBLISH_BUTTON, size='large', width='100', side_padding='20', vert_offset='-5')
        #button.get_top_el().add_class('smaller')
        button = ActionButtonWdg(title=my.PUBLISH_BUTTON,
                                 tip='Publish the selected assets')
        button.add_style('margin-bottom: 10px')
        #button.add_color("background", "background")

        hidden = HiddenWdg(my.PUBLISH_BUTTON, '')
        button.add(hidden)
        '''
        status_sel = SelectWdg('checkin_status', label='Status: ')
        status_sel.set_option('setting', 'checkin_status')
        status_sel.set_persist_on_submit()
        status_sel.add_empty_option('-- Checkin Status --')
        widget.add(status_sel)
        '''
        widget.add(button)

        # custom defined
        server_cbk = "pyasm.prod.web.AssetCheckinCbk"
        #TODO: make other Publish Buttons call their own handle_input function
        exec(Common.get_import_from_class_path(server_cbk))
        exec(
            "%s.handle_input(button, my.search_type, my.texture_search_type)" %
            server_cbk)

        return widget
示例#27
0
    def handle_python_script_test(self, top):
        top.add(DivWdg('Python Script Test', css='spt_info_title'))
        table = Table(css='script')
        table.add_color("color", "color")
        table.add_style("margin: 10px")
        table.add_style("width: 100%")
        top.add(table)
        table.add_row()
        td = table.add_cell("Script Path: ")
        td.add_style("width: 150px")
        text = TextWdg('script_path')
        td = table.add_cell(text)
        button = ActionButtonWdg(title='Run')
        table.add_cell(button)
        button.add_style("float: right")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
             var s = TacticServerStub.get();
             try {
                var path =  bvr.src_el.getParent('.script').getElement('.spt_input').value;
                if (! path)
                    throw('Please enter a valid script path');
                s.execute_cmd('tactic.command.PythonCmd', {script_path: path});
             } catch(e) {
                spt.alert(spt.exception.handler(e));
             }

        '''
        })
示例#28
0
    def get_save_button(my, checkin_keys):
        save_button = ActionButtonWdg(
            title="Save >>", tip="Save configuration and start using TACTIC")

        save_button.add_style("float: right")
        save_button.add_behavior({
            'type':
            'click_up',
            'os':
            os.name,
            'checkin_options':
            checkin_keys,
            'cbjs_action':
            '''
            spt.app_busy.show("Saving configuration. Please wait...")
            var top = bvr.src_el.getParent(".spt_db_config_top");
            var values = spt.api.Utility.get_input_values(top, null, false);
            var class_name = 'tactic.ui.startup.DbConfigSaveCbk';
            var server = TacticServerStub.get();
            var kwargs = {checkin_options:bvr.checkin_options};
            try {
                var ret_val = server.execute_cmd(class_name, kwargs, values);
                var info = ret_val.info;
            }
            catch(e) {
                log.critical(spt.exception.handler(e));
                //FIXME: recognize it's a 502 which is normal and pass , otherwise throw the error
                //spt.error(spt.exception.handler(e));
                //spt.app_busy.hide();
                //return;
            }

           
            
            // This means TACTIC was restarted
            
            if (typeof(info) == 'undefined' || bvr.os == 'nt' ) {
                spt.app_busy.show("Restarting TACTIC ...");
                var id = setInterval( function() {
                    var ping_rtn =  server.ping();
                    if (ping_rtn) {
                        window.location = '/tactic';
                        clearInterval(id);
                    }
                  
                }, 5000 );

            }
            else if (info.error) {
                spt.alert(info.error);
                spt.app_busy.hide();
            }
            else {
                window.location = '/tactic';
            }

            '''
        })
        return save_button
示例#29
0
 def handle_sidebar_clear(self, top):
     top.add(DivWdg('Clear Side Bar Cache ', css='spt_info_title'))
     table = Table()
     table.add_color("color", "color")
     table.add_style("margin: 10px")
     top.add(table)
     table.add_row()
     td = table.add_cell("Clear the Side Bar Cache for all users")
     td.add_style("width: 250px")
     button = ActionButtonWdg(title='Run')
     table.add_cell(button)
     button.add_behavior( {
     'type': 'click_up',
     'cbjs_action': '''
         try {
         var s = TacticServerStub.get();
         s.execute_cmd('tactic.ui.app.ClearSideBarCache');
         
         } catch(e) {
             spt.alert(spt.exception.handler(e));
         }
         spt.info('Side Bar cache cleared.')
     '''
     })
示例#30
0
    def get_display(self):
        top = self.top
        top.add_color("background", "background")
        top.add_class("spt_ingestion_shelf_top")

        #base_dir = self.kwargs.get("base_dir")
        #location = self.kwargs.get("location")
        base_dir = "/home/apache/Structures"
        location = "server"

        scan = ActionButtonWdg(title="Scan Files", tip="Scan Files")
        top.add(scan)
        scan.add_behavior({
            'type':
            'click_up',
            'base_dir':
            base_dir,
            'location':
            location,
            'cbjs_action':
            '''
        var class_name = 'tactic.ui.tools.IngestionToolDirListWdg';
        var kwargs = {
            base_dir: bvr.base_dir,
            location: bvr.location
        };
        var top = bvr.src_el.getParent(".spt_ingestion_shelf_top");
        var content = top.getElement(".spt_content");
        spt.panel.load(content, class_name, kwargs);

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

        scan = ActionButtonWdg(title="Handled", tip="Show Handled Files")
        top.add(scan)
        scan.add_behavior({
            'type':
            'click_up',
            'base_dir':
            base_dir,
            'location':
            location,
            'cbjs_action':
            '''
        var class_name = 'tactic.ui.tools.IngestionToolScanWdg';
        var kwargs = {
        };
        var top = bvr.src_el.getParent(".spt_ingestion_shelf_top");
        var content = top.getElement(".spt_content");
        spt.panel.load(content, class_name, kwargs);

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

        scan = ActionButtonWdg(title="Not Handled",
                               tip="Show Files Not Handled")
        top.add(scan)
        scan.add_behavior({
            'type':
            'click_up',
            'base_dir':
            base_dir,
            'location':
            location,
            'cbjs_action':
            '''
        var class_name = 'tactic.ui.tools.IngestionToolScanWdg';
        var kwargs = {
        };
        var top = bvr.src_el.getParent(".spt_ingestion_shelf_top");
        var content = top.getElement(".spt_content");
        spt.panel.load(content, class_name, kwargs);

        '''
        })

        top.add("<hr/>")

        content = DivWdg()
        top.add(content)
        content.add_style("height: 100%")
        content.add_style("padding: 10px")
        content.add_class("spt_content")
        content.add("&nbsp;")

        return top
示例#31
0
    def get_display(my):

        expr_filter = "sthpw/login['login','not in','admin|guest']['begin']['license_type','user']['license_type','is','NULL']['or']"
        current_users = Search.eval("@COUNT(%s)" %expr_filter)

        top = my.top
        top.add_class("spt_panel_user_top")
        top.add_style("min-width: 400px")
        
        tool_div = DivWdg()
        # tool_div.add_style('margin-bottom','8px')
        tool_div.add_style('display','inline-flex')
        tool_div.add_style('width','50%')
        tool_div.add_style('margin-bottom','-4px')
       
        button = ActionButtonWdg(title="Add", tip="Add New User")
        button.add_style('align-self: flex-end')
        tool_div.add(button)
        
        button.add_style("float: left")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var class_name = 'tactic.ui.panel.EditWdg';
            var kwargs = {
                search_type: "sthpw/login",
                view: "edit",
                show_header: false,
            }
            var popup = spt.panel.load_popup("Create New User", class_name, kwargs);
            var top = bvr.src_el.getParent(".spt_panel_user_top");
            popup.on_save_cbk = function() {
                spt.panel.refresh(top);
            }

            '''
        } )


        security = Environment.get_security()
        license = security.get_license()
        num_left = license.get_num_licenses_left()
        current_users = license.get_current_users()
        #max_users = license.get_max_users()


        div = DivWdg('Users')
        div.add_style('align-self: flex-end')
        div.add_styles("margin: 0 0 6px 20px")
        badge_span = SpanWdg(css='badge')
        badge_span.add_style('margin-left','6px')
        badge_span.add(current_users)
        div.add(badge_span)
        tool_div.add(div)

        tool_div2 = DivWdg()
        # tool_div.add_style('margin-bottom','8px')
        tool_div2.add_style('display','inline-flex')
        tool_div2.add_style('justify-content','flex-end')
        tool_div2.add_style('width','50%')

        top.add(tool_div)
        top.add(tool_div2)


        if num_left < 1000:
            div = DivWdg('Users Left')
            div.add_style('align-self: flex-end')
            div.add_styles("margin: 0 0 6px 20px")
            badge_span = SpanWdg(css='badge')
            badge_span.add_style('margin-left','6px')
            badge_span.add(num_left)
            div.add(badge_span)
            tool_div.add(div)

            top.add(tool_div)


        show_security = my.kwargs.get("show_security")
        if show_security not in ['false', False]:
            button = ActionButtonWdg(title="Security")
            button.add_style('align-self: flex-end')
            #button.add_styles("position: absolute; right: 10px;")
            tool_div2.add(button)
            #button.add_style("margin-top: -8px")
            button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var class_name = 'tactic.ui.startup.SecurityWdg';
            spt.tab.set_main_body_tab()
            spt.tab.add_new("Security", "Security", class_name)
            '''
            } )




        br = HtmlElement.br(clear=True)
        top.add(br)



        if not current_users:
            div = DivWdg()
            top.add(div)
            div.add_style("text-align: center")
            div.add_border()
            div.add_style("min-height: 150px")
            div.add_style("margin: 15px 30px 30px 30px")
            div.add_style("padding: 30px 20px 0px 20px")
            div.add_color("background", "background3")
            icon = IconWdg( "WARNING", IconWdg.WARNING )
            div.add(icon)
            div.add("<b>No users have been added</b>")
            div.add("<br/><br/>")
            div.add("For more information, read the help docs: ")
            from tactic.ui.app import HelpButtonWdg
            help = HelpButtonWdg(alias=my.get_help_alias())
            div.add(help)
            div.add("<br/>")
            div.add("Click on the 'Add' button above to start adding new users.")

            return top




        div = DivWdg()
        top.add(div)
        #div.add_style("max-height: 300px")
        #div.add_style("overflow-y: auto")
        expr = "@SEARCH(%s)" %expr_filter
        panel = ViewPanelWdg(search_type='sthpw/login',view='manage_user',show_insert='false',\
            show_gear='false', show_select='false', height='700', expression=expr,\
            simple_search_view='simple_manage_filter', show_column_manager='false',\
            show_layout_switcher='false', show_expand='false')
        div.add(panel)
        div.add_style('margin-top', '4px')
        
        return top

        """
示例#32
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
示例#33
0
    def get_display(self):
        top = self.top
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("width", "400px")
        top.add_class('spt_delete_stype_top')
        top.add_border()

        project_code = Project.get_project_code()
        # Note search types should only really be deleted if they were just
        # created

        search_type = self.kwargs.get("search_type")
        if not search_type:
            node_name = self.kwargs.get("node_name")
            if node_name:
                #project_code = Project.get_project_code()
                search_type = "%s/%s" % (project_code, node_name)

        assert search_type
        built_in_stypes = ['task','note','work_hour','login','login_group','schema','project','login_in_group','snapshot','file','trigger','spt_trigger','widget_config','custom_script','notification','notification_log','file_access','cache','exception_log','milestone','pipeline','pref_list','pref_setting','project_type','repo','remote_repo','search_sobject','sobject_list','ticket','db_resource','wdg_settings','status_log','debug_log','transaction_log', 'sobject_log']

        for tbl in built_in_stypes:
            if search_type == 'sthpw/%s'%tbl:
                top.add("sType [%s] is internal and cannot be deleted!" % search_type)
                top.add_style("font-size: 14px")
                top.add_style('padding: 20px')
                return top

        search_type_obj = SearchType.get(search_type)
        if not search_type:
            top.add("sType [%s] does not exist!" % search_type)
            top.add_style("font-size: 14px")
            top.add_style('padding: 20px')
            return top
        table = search_type_obj.get_table()

        db_val = search_type_obj.get_value('database')
        if db_val == '{project}':
            label = ''
        elif db_val == 'sthpw':
            label = 'built-in'
        else:
            label = 'project-specific'

        
        # warn if more than 1 sType point to the same table in the same project
        expr = "@GET(sthpw/search_type['table_name', '%s']['database', 'in',  '{project}|%s']['namespace','%s'].search_type)" %(table, project_code, project_code)
        rtn = Search.eval(expr)
        
        warning_msg = ''
        if len(rtn) > 1:
            warning_msg = 'Warning: There is more than 1 sType [%s] pointing to the same table [%s]. Deleting will affect both sTypes.' %(', '.join(rtn), table)
           
        title_wdg = DivWdg()

        top.add(title_wdg)
        title_wdg.add(IconWdg(icon=IconWdg.WARNING))
        title_wdg.add("Delete %s sType: %s" % (label,search_type))
        title_wdg.add_color("background", "background", -10)
        title_wdg.add_style("font-weight: bold")
        title_wdg.add_style("font-size: 14px")


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

        if warning_msg:
            content.add(DivWdg(warning_msg, css='warning'))
            content.add("<br/>")
        content.add("This sType uses the table \"%s\" to store items.<br/>" % table)


        content.add("<br/>")

        search = Search(search_type)
        count = search.get_count()
        content.add("Number of items in the table: %s<br/>" % count)

        content.add("<br/>")

        search.add_column("id")
        sobjects = search.get_sobjects()

        if sobjects:
            items_search_type = sobjects[0].get_search_type()

            search_ids = [x.get_id() for x in sobjects]

            notes_search = Search("sthpw/note")
            notes_search.add_filters("search_id", search_ids)
            notes_search.add_filter("search_type", items_search_type)
            note_count = notes_search.get_count()
            cb = CheckboxWdg('related_types')
            cb.set_attr('value', 'sthpw/note')
            content.add(cb)
            content.add(SpanWdg("Number of related notes: %s"% note_count, css='small') )
            content.add(HtmlElement.br())

            tasks_search = Search("sthpw/task")
            tasks_search.add_filters("search_id", search_ids)
            tasks_search.add_filter("search_type", items_search_type)
            task_count = tasks_search.get_count()
            cb = CheckboxWdg('related_types')
            cb.set_attr('value', 'sthpw/task')
            content.add(cb)
            content.add(SpanWdg("Number of related tasks: %s"% task_count, css='small') )
            content.add(HtmlElement.br())


            snapshots_search = Search("sthpw/snapshot")
            snapshots_search.add_filters("search_id", search_ids)
            snapshots_search.add_filter("search_type", items_search_type)
            snapshot_count = snapshots_search.get_count()
            cb = CheckboxWdg('related_types')
            cb.set_attr('value', 'sthpw/snapshot')
            content.add(cb)
            content.add(SpanWdg("Number of related snapshots: %s"% snapshot_count, css='small') )
            content.add(HtmlElement.br())

        pipelines_search = Search("sthpw/pipeline")
        pipelines_search.add_filter("search_type", search_type)
        pipeline_count = pipelines_search.get_count()
        cb = CheckboxWdg('related_types')
        cb.set_attr('value','sthpw/pipeline')
        content.add(cb)
        content.add(SpanWdg("Number of related pipelines: %s"% pipeline_count, css='small') )
        content.add(HtmlElement.br(2))




        content.add("<b>WARNING: Deleting the sType will delete all of these items.</b> ")
        content.add("<br/>"*2)
        content.add("Do you wish to continue deleting?")
        content.add("<br/>"*2)

        button_div = DivWdg()
        button_div.add_styles('width: 300px; height: 50px')
        button = ActionButtonWdg(title="Delete")
        button_div.add(button)
        content.add(button_div)
        button.add_style("float: left")

        button.add_behavior( {
        'type': 'click_up',
        'search_type': search_type,
        'cbjs_action': '''
        spt.app_busy.show("Deleting sType");
        var class_name = "tactic.ui.tools.DeleteSearchTypeCmd";
        var ui_top = bvr.src_el.getParent(".spt_delete_stype_top");
        var values = spt.api.Utility.get_input_values(ui_top);
        var kwargs = {
            'search_type': bvr.search_type,
             'values': values
        };
        var server = TacticServerStub.get();
        try {
            server.start({'title': 'Delete sType', 'description': 'Delete sType [' + bvr.search_type + ']'});
            server.execute_cmd(class_name, kwargs);
            var top = bvr.src_el.getParent(".spt_popup");
            spt.pipeline.remove_node(top.stype_node);

            // force a schema save
            spt.named_events.fire_event('schema|save', bvr)
            top.destroy();
            
            server.finish();
        
        }
        catch(e) {
            spt.alert(spt.exception.handler(e));
        }

        spt.app_busy.hide();

        spt.notify.show_message("Successfully deleted sType ["+bvr.search_type+"]");
       
        '''
        } )



        button = ActionButtonWdg(title="Cancel")
        button.add_style("float: left")
        button_div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_popup");
        top.destroy();
        '''
        } )


        return top
示例#34
0
    def get_display(my):
        top = my.top
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("width", "400px")
        top.add_class('spt_delete_stype_top')
        top.add_border()

        project_code = Project.get_project_code()
        # Note search types should only really be deleted if they were just
        # created

        search_type = my.kwargs.get("search_type")
        if not search_type:
            node_name = my.kwargs.get("node_name")
            if node_name:
                #project_code = Project.get_project_code()
                search_type = "%s/%s" % (project_code, node_name)

        assert search_type
        built_in_stypes = [
            'task', 'note', 'work_hour', 'login', 'login_group', 'schema',
            'project', 'login_in_group', 'snapshot', 'file', 'trigger',
            'spt_trigger', 'widget_config', 'custom_script', 'notification',
            'notification_log', 'file_access', 'cache', 'exception_log',
            'milestone', 'pipeline', 'pref_list', 'pref_setting',
            'project_type', 'repo', 'remote_repo', 'search_sobject',
            'sobject_list', 'ticket', 'db_resource', 'wdg_settings',
            'status_log', 'debug_log', 'transaction_log', 'sobject_log'
        ]

        for tbl in built_in_stypes:
            if search_type == 'sthpw/%s' % tbl:
                top.add("sType [%s] is internal and cannot be deleted!" %
                        search_type)
                top.add_style("font-size: 14px")
                top.add_style('padding: 20px')
                return top

        search_type_obj = SearchType.get(search_type)
        if not search_type:
            top.add("sType [%s] does not exist!" % search_type)
            top.add_style("font-size: 14px")
            top.add_style('padding: 20px')
            return top
        table = search_type_obj.get_table()

        db_val = search_type_obj.get_value('database')
        if db_val == '{project}':
            label = ''
        elif db_val == 'sthpw':
            label = 'built-in'
        else:
            label = 'project-specific'

        # warn if more than 1 sType point to the same table in the same project
        expr = "@GET(sthpw/search_type['table_name', '%s']['database', 'in',  '{project}|%s']['namespace','%s'].search_type)" % (
            table, project_code, project_code)
        rtn = Search.eval(expr)

        warning_msg = ''
        if len(rtn) > 1:
            warning_msg = 'Warning: There is more than 1 sType [%s] pointing to the same table [%s]. Deleting will affect both sTypes.' % (
                ', '.join(rtn), table)

        title_wdg = DivWdg()

        top.add(title_wdg)
        title_wdg.add(IconWdg(icon=IconWdg.WARNING))
        title_wdg.add("Delete %s sType: %s" % (label, search_type))
        title_wdg.add_gradient("background", "background", -10, -10)
        title_wdg.add_style("padding: 5px")
        title_wdg.add_style("font-weight: bold")
        title_wdg.add_style("font-size: 14px")

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

        if warning_msg:
            content.add(DivWdg(warning_msg, css='warning'))
            content.add("<br/>")
        content.add("This sType uses the table \"%s\" to store items.<br/>" %
                    table)

        content.add("<br/>")

        search = Search(search_type)
        count = search.get_count()
        content.add("Number of items in the table: %s<br/>" % count)

        content.add("<br/>")

        search.add_column("id")
        sobjects = search.get_sobjects()

        if sobjects:
            items_search_type = sobjects[0].get_search_type()

            search_ids = [x.get_id() for x in sobjects]

            notes_search = Search("sthpw/note")
            notes_search.add_filters("search_id", search_ids)
            notes_search.add_filter("search_type", items_search_type)
            note_count = notes_search.get_count()
            cb = CheckboxWdg('related_types')
            cb.set_attr('value', 'sthpw/note')
            content.add(cb)
            content.add(
                SpanWdg("Number of related notes: %s" % note_count,
                        css='small'))
            content.add(HtmlElement.br())

            tasks_search = Search("sthpw/task")
            tasks_search.add_filters("search_id", search_ids)
            tasks_search.add_filter("search_type", items_search_type)
            task_count = tasks_search.get_count()
            cb = CheckboxWdg('related_types')
            cb.set_attr('value', 'sthpw/task')
            content.add(cb)
            content.add(
                SpanWdg("Number of related tasks: %s" % task_count,
                        css='small'))
            content.add(HtmlElement.br())

            snapshots_search = Search("sthpw/snapshot")
            snapshots_search.add_filters("search_id", search_ids)
            snapshots_search.add_filter("search_type", items_search_type)
            snapshot_count = snapshots_search.get_count()
            cb = CheckboxWdg('related_types')
            cb.set_attr('value', 'sthpw/snapshot')
            content.add(cb)
            content.add(
                SpanWdg("Number of related snapshots: %s" % snapshot_count,
                        css='small'))
            content.add(HtmlElement.br())

        pipelines_search = Search("sthpw/pipeline")
        pipelines_search.add_filter("search_type", search_type)
        pipeline_count = pipelines_search.get_count()
        cb = CheckboxWdg('related_types')
        cb.set_attr('value', 'sthpw/pipeline')
        content.add(cb)
        content.add(
            SpanWdg("Number of related pipelines: %s" % pipeline_count,
                    css='small'))
        content.add(HtmlElement.br(2))

        content.add(
            "<b>WARNING: Deleting the sType will delete all of these items.</b> "
        )
        content.add("<br/>" * 2)
        content.add("Do you wish to continue deleting?")
        content.add("<br/>" * 2)

        button_div = DivWdg()
        button_div.add_styles('width: 300px; height: 50px')
        button = ActionButtonWdg(title="Delete")
        button_div.add(button)
        content.add(button_div)
        button.add_style("float: left")

        button.add_behavior({
            'type':
            'click_up',
            'search_type':
            search_type,
            'cbjs_action':
            '''
        spt.app_busy.show("Deleting sType");
        var class_name = "tactic.ui.tools.DeleteSearchTypeCmd";
        var ui_top = bvr.src_el.getParent(".spt_delete_stype_top");
        var values = spt.api.Utility.get_input_values(ui_top);
        var kwargs = {
            'search_type': bvr.search_type,
             'values': values
        };
        var server = TacticServerStub.get();
        try {
            server.start({'title': 'Delete sType', 'description': 'Delete sType [' + bvr.search_type + ']'});
            server.execute_cmd(class_name, kwargs);
            var top = bvr.src_el.getParent(".spt_popup");
            spt.pipeline.remove_node(top.stype_node);

            // force a schema save
            spt.named_events.fire_event('schema|save', bvr)
            top.destroy();
            
            server.finish();
        
        }
        catch(e) {
            spt.alert(spt.exception.handler(e));
        }

        spt.app_busy.hide();

        spt.notify.show_message("Successfully deleted sType ["+bvr.search_type+"]");
       
        '''
        })

        button = ActionButtonWdg(title="Cancel")
        button.add_style("float: left")
        button_div.add(button)
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_popup");
        top.destroy();
        '''
        })

        return top
示例#35
0
    def get_display(my):

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

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


        top.add("<hr/>")

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


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

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


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

        db_select.set_value(vendor)



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

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

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

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

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

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


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


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

        top.add("<br/>")

        title = "Installation"

        category = "install"

        options = ['default_project']

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

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

        top.add("<hr/>")

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

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


        options=checkin_keys[:]

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

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


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

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

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

        top.add("<hr/>")

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

        top.add("<hr/>")

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

        #wizard_wdg = WizardWdg()
        #top.add(wizard_wdg)
        #wizard_wdg.add(DivWdg("cow"), "cow")
        #wizard_wdg.add(DivWdg("pig"), "pig")
        #wizard_wdg.add(DivWdg("dog"), "dog")
        return top
示例#36
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
示例#37
0
    def get_display(my):
        top = my.top

        view = my.kwargs.get("view")
        top.add_class("spt_help_edit_content")


        search = Search("config/widget_config")
        search.add_filter("category", "HelpWdg")
        search.add_filter("view", view)
        sobject = search.get_sobject()

        if not sobject:
            value = ""
            search_key = ""

        else:
            xml_value = sobject.get_xml_value("config")
            value = xml_value.get_value("config/%s/html/div" % (view) )
            search_key = sobject.get_search_key()


        title_wdg = DivWdg()
        top.add(title_wdg)
        title_wdg.add("<b>View: %s</b>" % view)
        title_wdg.add_style("font-style: bold")
        title_wdg.add_style("padding: 5px")
        title_wdg.add_gradient("background", "background", 0, -10)


        hidden = HiddenWdg("view")
        top.add(hidden)
        hidden.set_value(view)


        text = TextAreaWdg("content")
        text_id = text.set_unique_id()
        text.set_value(value)

        from tactic.ui.widget import ActionButtonWdg
        if sobject:
            delete_button = ActionButtonWdg(title="Delete")
            top.add(delete_button)
            delete_button.add_style("float: right")
            delete_button.add_style("margin-top: -3px")
            delete_button.add_behavior( {
            'type': 'click_up',
            'search_key': search_key,
            'cbjs_action': '''
            if (!confirm("Are you sure you wish to delete this help page?")) {
                return;
            }
            var server = TacticServerStub.get();
            server.delete_sobject(bvr.search_key);
            var top = bvr.src_el.getParent(".spt_help_edit_top");
            spt.panel.refresh(top);
            '''
            })



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

        var js_file = "ckeditor/ckeditor.js";

        var url = "/context/spt_js/" + js_file;
        var js_el = document.createElement("script");
        js_el.setAttribute("type", "text/javascript");
        js_el.setAttribute("src", url);

        var head = document.getElementsByTagName("head")[0];
        head.appendChild(js_el);



        var cmd = "CKEDITOR.instances." + bvr.text_id + ".getData()";
        var text_value = eval( cmd );

        bvr.options = {};
        bvr.options.html = text_value;
        spt.named_events.fire_event("show_help", bvr)
        '''
        })



        save_button = ActionButtonWdg(title="Save")
        top.add(save_button)
        save_button.add_style("float: right")
        save_button.add_style("margin-top: -3px")

        top.add("<br/>")


        save_button.add_behavior( {
        'type': 'click_up',
        'text_id': text_id,
        'cbjs_action': '''

        spt.app_busy.show("Saving Help", " ")

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

        var cmd = "CKEDITOR.instances." + bvr.text_id + ".getData()";
        var text_value = eval( cmd );
        values.content = text_value;

        var command = "tactic.ui.app.HelpEditCbk";
        var kwargs = values;
        var server = TacticServerStub.get();
        server.execute_cmd(command, kwargs);

        setTimeout("spt.app_busy.hide()", 200)
        '''
        } )

        #top.add("Style: ")
        #select = SelectWdg("style")
        #top.add(select)
        #select.set_option("values", "text|html")


        top.add("<br/>")

        top.add(text)
        text.set_value(value)
        text.add_style("width: 100%")
        text.add_style("height: 100%")
        text.add_style("min-height: 500px")
        text.add_style("display: none")
        text.add_behavior( {
        'type': 'load',
        'color': text.get_color("background", -10),
        'text_id': text_id,
        'cbjs_action': '''

        var js_file = "ckeditor/ckeditor.js";
        var url = "/context/spt_js/" + js_file;
        var js_el = document.createElement("script");
        js_el.setAttribute("type", "text/javascript");
        js_el.setAttribute("src", url);
        var head = document.getElementsByTagName("head")[0];
        head.appendChild(js_el);


        setTimeout( function() {


        CKEDITOR.on( 'instanceReady', function( ev )
        {
            ev.editor.dataProcessor.writer.indentationChars = ' ';
        });



        var config = {
          toolbar: 'Full',
          uiColor: bvr.color,
          height: '500px'
        };
config.toolbar_Full =
[
    ['Source'],
    ['Cut','Copy','Paste'],
    ['Undo','Redo','-','Find','Replace'],
    ['Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    '/',
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    ['HorizontalRule','SpecialChar'],
    ['Styles','Format','Font','FontSize'],
    ['TextColor','BGColor'],
    ['Maximize', 'ShowBlocks']
];

        CKEDITOR.replace(bvr.text_id, config );
        bvr.src_el.setStyle("display", "");

        }, 500);
        '''
        } )

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

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

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

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

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

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

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

        option_div.add(sel)

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

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

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

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

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

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

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

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

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

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

        show_subpipeline = True
        min_height = '150px'

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

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

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

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

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

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

                    for x in labels:
                        process_labels.append(process_label)

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

                    process_labels.append(process_label)

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

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

        skipped = []

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

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

        return div
示例#39
0
    def get_display(my):
        widget = DivWdg(id='new_item_panel')
        widget.add_class("new_item_panel")
        widget.add_class("spt_new_item_top")

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

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

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

            div.add_style("width: 350px")

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

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

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

            div.add(HtmlElement.br(2))

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

            div.add("<hr/>")

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

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

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

        elif my.type == 'new_link':

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

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

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

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

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

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

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

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

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

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

            div.add(HtmlElement.br())

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

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

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

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

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

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

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

        top.add_color("background", "background")
        top.add_style("padding: 30px")
        top.add_style("width: 300px")

        icon = IconWdg("Not signed in", IconWdg.WARNING)
        top.add(icon)

        top.add("You are not signed into Perforce.")
        top.add("<br/>" * 2)

        table = Table()
        top.add(table)

        from tactic.ui.input import TextInputWdg, PasswordInputWdg

        table.add_row()
        td = table.add_cell("Port: ")
        td.add_style("width: 75px")

        text = TextInputWdg(name="port")
        td = table.add_cell(text)
        td.add_style("vertical-align: top")
        text.set_value("1666")

        table.add_row()
        td = table.add_cell("Login: "******"vertical-align: top")
        td.add_style("width: 75px")

        text = TextInputWdg(name="user")
        td = table.add_cell(text)
        td.add_style("vertical-align: top")
        user = Environment.get_user_name()
        text.set_value(user)

        table.add_row()

        td = table.add_cell("Password: "******"vertical-align: top")

        text = PasswordInputWdg(name="password")
        table.add_cell(text)

        tr = table.add_row()
        table.add_row_cell("&nbsp;")

        tr = table.add_row()
        tr.add_class("spt_workspaces")
        #tr.add_style("display: none")
        td = table.add_cell("Workspace: ")
        td.add_style("vertical-align: top")

        workspaces = my.kwargs.get("workspaces")
        td = table.add_cell()
        button = ActionButtonWdg(width='55', title="Lookup")
        td.add(button)
        button.add_style("float: right")

        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            try {
                var workspaces = spt.scm.get_workspaces();

                var clients = [];
                for (var i = 0; i < workspaces.length; i++) {
                    clients.push(workspaces[i].client);
                }
                clients = clients.join("|");
                var kwargs = {
                    workspaces: clients
                }
                spt.scm.show_login(kwargs);
            }
            catch(e) {
                spt.scm.signout_user();
                spt.scm.show_login();
            }
            '''
        })

        if not workspaces:
            text = TextInputWdg(name="workspace")
            text.add_style("width: 165px")
            td.add(text)

        else:
            select = SelectWdg("workspace")
            td.add(select)
            select.set_option("values", workspaces)

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

        button = ActionButtonWdg(title="Sign In >>", size='medium')
        top.add(button)
        button.add_style("float: right")

        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_sign_in_top");
            var values = spt.api.get_input_values(top);

            var port = values.port[0];
            var user = values.user[0];
            var password = values.password[0];
            var client = values.workspace[0];


            if (!port) {
                alert("No port specified");
                return;
            }
            if (!user) {
                alert("No user specified");
                return;
            }
            if (!client) {
                alert("No workspace specified");
                return;
            }



            // login in user
            spt.scm.port = port;
            spt.scm.user = user;
            spt.scm.password = password;

            // test the connection
            var ping = spt.scm.ping();
            if (ping != "OK") {
                alert("Cannot connect to Perforce")
                spt.scm.signout_user();
                spt.scm.show_login();
            }
            else {
                spt.scm.client = client;

                // close the popup
                var popup = bvr.src_el.getParent(".spt_popup");
                if (popup) {
                    spt.popup.destroy(popup);
                }

                // NOTE: this is global: find a check-in widget and refresh
                var checkin_el = $(document.body).getElement(".spt_checkin_top");
                spt.panel.refresh(checkin_el);
            }

            '''
        })

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

        return top
示例#41
0
    def get_action_wdg(my, name):
        '''get the action widget for ui option of note entry'''

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

        # note options

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

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

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

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

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

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

        if not sobject:

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

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

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

            my.parent_key = SearchKey.get_by_sobject(parent)

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

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

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

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

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

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

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

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

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

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

        return note_wdg
示例#42
0
    def get_display(my):
        if my.is_refresh:
            top = Widget()
            my.add(top)
        else:
            container = DivWdg()
            my.add(container)
            #parent = SearchKey.get_by_search_key(my.search_key)
            top = DivWdg()
            container.add(top)
            my.set_as_panel(top)
            top.add_style("margin-top: -2px")

            top.add_class("spt_uber_notes_top")

        from tactic.ui.app import HelpButtonWdg
        help_button = HelpButtonWdg(alias="note-sheet-widget")
        top.add(help_button)
        help_button.add_style("float: right")

        table_id = 'sub_table'
        view = 'table'
        span = DivWdg(css='spt_input_group')
        top.add(span)

        span.add_border()
        span.add_style("height: 27px")
        span.add_style("padding: 5px")

        button_div = DivWdg()
        span.add(button_div)
        button_div.add_style("float: left")
        button_div.add_style("margin-right: 10px")

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

        from tactic.ui.widget import SingleButtonWdg
        refresh = SingleButtonWdg(title="Refresh", icon=IconWdg.REFRESH)
        table.add_cell(refresh)
        refresh.add_style("float: left")
        refresh.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_uber_notes_top");
            var tbody = top.getElements('.spt_table_tbody')[2];
            var values = spt.api.Utility.get_input_values(tbody);
            spt.panel.refresh(top, values, false);
        '''
        })

        save = SingleButtonWdg(title="Save", icon=IconWdg.SAVE)
        table.add_cell(save)
        save.add_style("float: left")
        save.add_behavior({
            'type':
            'click_up',
            'update_current_only':
            True,
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_uber_notes_top");
            var table = top.getElement(".spt_table");
            bvr.src_el = table;
            spt.dg_table.update_row(evt, bvr)
            '''
        })

        process = SingleButtonWdg(title="Show Processes",
                                  icon=IconWdg.PROCESS,
                                  show_arrow=True)
        table.add_cell(process)

        from tactic.ui.container import DialogWdg
        process_dialog = DialogWdg(display=False)
        span.add(process_dialog)
        process_dialog.set_as_activator(process)
        process_dialog.add_title("Processes")

        process_div = DivWdg()
        process_dialog.add(process_div)
        #process_div.add_style("padding: 5px")
        process_div.add_color("background", "background")
        process_div.add_color("color", "color")
        process_div.add_border()

        refresh = ActionButtonWdg(title="Refresh")
        refresh.add_style('margin: 0 auto 10px auto')
        process_div.add(refresh)
        refresh.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_uber_notes_top");
            var tbody = top.getElements('.spt_table_tbody')[2];
            var values = spt.api.Utility.get_input_values(tbody);
            spt.panel.refresh(top, values, false);
        '''
        })
        process_div.add("<hr/>")

        selected_process_names = []
        step = 0

        for idx, value in enumerate(my.process_names):
            checkbox_name = 'note_process_cb'
            if my.child_mode:
                selected_process_names.append(value)
                #break
            cb = CheckboxWdg(checkbox_name, label=value)

            cb.persistence = True
            cb.persistence_obj = cb
            key = cb.get_key()
            cb.set_option('value', value)
            #cb.set_persistence()

            cb.add_behavior({
                'type':
                'click_up',
                'cbjs_action':
                '''
                    spt.input.save_selected(bvr, '%s','%s');
                ''' % (checkbox_name, key)
            })

            # only 1 is selected in child_mode
            if cb.is_checked():
                selected_process_names.append(value)

            if idx == 0 or idx == 10 * step:
                # add a new inner div
                inner_div = my._get_inner_div()
                process_div.add(inner_div, 'inner%s' % step)
                step += 1

            inner_div.add(cb)

            inner_div.add("<br/>")

        # if less than 10, make it wider
        if len(my.process_names) < 10:
            inner_div.add_style('width: 100px')

        # add a master private checkbox
        if not my.child_mode:
            checkbox_name = 'note_master_private_cb'
            cb = CheckboxWdg(checkbox_name, label='make notes private')
            cb.persistence = True
            cb.persistence_obj = cb
            key = cb.get_key()
            cb.add_behavior({
                'type':
                'click_up',
                'propagate_evt':
                True,
                'cbjs_action':
                '''
                    var top = bvr.src_el.getParent(".spt_uber_notes_top");
                    var tbody = top.getElements('.spt_table_tbody')[2];
                    var inputs = spt.api.Utility.get_inputs(tbody,'is_private');
                    for (var i = 0; i < inputs.length; i++)
                        inputs[i].checked = bvr.src_el.checked;
                    spt.input.save_selected(bvr, '%s','%s');
                    ''' % (checkbox_name, key)
            })

            cb_span = DivWdg(cb, css='small')
            cb_span.add_styles(
                'border-left: 1px dotted #bbb; margin-left: 10px')
            span.add(cb_span)

        main_config_view = my._get_main_config(view, selected_process_names)

        sobject_dict = {}

        # TODO: do a union all search or by order number = 1
        for value in selected_process_names:
            search = Search('sthpw/note')
            search.add_filter('project_code', Project.get_project_code())
            search.add_filter('context', value)
            search.add_filter('search_type', my.parent_search_type)
            search.add_filter('search_id', my.parent_search_id)
            search.add_order_by('timestamp desc')
            search.add_limit(1)
            sobject = search.get_sobject()
            if sobject:
                sobject_dict[value] = sobject
        #sobjects = search.get_sobjects()
        # virtual sobject for placeholder, we can put more than 1 maybe?
        sobject = SearchType.create('sthpw/note')

        edit_config = my._get_edit_config('edit', selected_process_names)
        edit_configs = {'sthpw/note': edit_config}
        Container.put("CellEditWdg:configs", edit_configs)

        table = TableLayoutWdg(table_id=table_id,
                               search_type='sthpw/note',
                               view='table',
                               config=main_config_view,
                               aux_info={
                                   'sobjects': sobject_dict,
                                   'parent': my.parent
                               },
                               mode="simple",
                               show_row_select=False,
                               show_insert=False,
                               show_commit_all=True,
                               show_refresh='false',
                               state={'parent_key': my.search_key})
        table.set_sobject(sobject)

        top.add(table)

        return super(NoteSheetWdg, my).get_display()
示例#43
0
    def get_display(my):

        my.sobject = my.kwargs.get("sobject")
        search_key = my.sobject.get_search_key()

        top = DivWdg()
        top.add_class("spt_checkin_publish")
        top.add_style("padding: 10px")

        margin_top = '60px'
        top.add_style("margin-top", margin_top)
        top.add_style("position: relative")

        current_changelist = WidgetSettings.get_value_by_key(
            "current_changelist")
        current_branch = WidgetSettings.get_value_by_key("current_branch")
        current_workspace = WidgetSettings.get_value_by_key(
            "current_workspace")

        top.add("Branch: %s<br/>" % current_branch)
        top.add("Changelist: %s<br/>" % current_changelist)
        top.add("Workspace: %s<br/>" % current_workspace)
        top.add("<br/>")

        checked_out_div = DivWdg()
        checkbox = CheckboxWdg("editable")
        top.add(checked_out_div)
        checkbox.add_class("spt_checkin_editable")
        checked_out_div.add(checkbox)
        checked_out_div.add("Leave files editable")

        top.add("<br/>")

        top.add("Publish Description<br/>")
        text = TextAreaWdg("description")
        # this needs to be set or it will stick out to the right
        text.add_style("width: 220px")
        text.add_class("spt_checkin_description")
        top.add(text)

        # add as a note
        note_div = DivWdg()
        top.add(note_div)
        note_div.add_class("spt_add_note")
        checkbox = CheckboxWdg("add_note")

        web = WebContainer.get_web()
        browser = web.get_browser()
        if browser in ['Qt']:
            checkbox.add_style("margin-top: -4px")
            checkbox.add_style("margin-right: 3px")
            note_div.add_style("margin-top: 3px")

        checkbox.add_class("spt_checkin_add_note")
        note_div.add(checkbox)
        note_div.add("Also add as note")

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

        button = ActionButtonWdg(title="Check-in",
                                 icon=IconWdg.PUBLISH,
                                 size='medium')
        top.add(button)

        my.repo_type = 'perforce'
        if my.repo_type == 'perforce':

            # the depot is set per project (unless overridden)
            project = my.sobject.get_project()
            depot = project.get_value("location", no_exception=True)
            if not depot:
                depot = project.get_code()

            asset_dir = Environment.get_asset_dir()
            sandbox_dir = Environment.get_sandbox_dir()

            changelist = WidgetSettings.get_value_by_key("current_changelist")
            button.add_behavior({
                'type':
                'click_up',
                'depot':
                depot,
                'changelist':
                changelist,
                'sandbox_dir':
                sandbox_dir,
                'search_key':
                search_key,
                'cbjs_action':
                '''

            var paths = spt.checkin.get_selected_paths();
            spt.app_busy.show("Checking in "+paths.length+" file/s into Perforce");
            var top = bvr.src_el.getParent(".spt_checkin_top");
            var description = top.getElement(".spt_checkin_description").value;
            var add_note = top.getElement(".spt_checkin_add_note").value;
            var editable = top.getElement(".spt_checkin_editable").value;

            if (editable == 'on') {
                editable = true;
            }
            else {
                editable = false;
            }

            var process = top.getElement(".spt_checkin_process").value;

            // check into TACTIC
            var server = TacticServerStub.get();

            var revisions = [];
            server.start({description: "File Check-in"});

            try {

            var top = bvr.src_el.getParent(".spt_checkin_top");
            var el = top.getElement(".spt_mode");
            var mode = el.value;

            // check-in the changelist
            var changelist = 'default';
            if (mode == 'changelist') {
                var scm_info = spt.scm.run("commit_changelist", [changelist, description]);

                for ( var i = 1; i < scm_info.length-1; i++) {
                    // the first item is the changelist number
                    //console.log(scm_info[i]);

                    var action = scm_info[i];
                    revision = action.rev;
                    revisions.push(revision);

                    // Do an inplace check-in into TACTIC
                    var path = action.depotFile;

                    var parts = path.split("/");
                    var filename = parts[parts.length-1];
                    var context = process + "/" + filename;

                    var snapshot = server.simple_checkin(bvr.search_key, context, path, {description: description, mode: "perforce", version: revision} );
                }

            }
            else {

                // check in all of the files
                for ( var i = 0; i < paths.length; i++) {
                    var path = paths[i];
                    var scm_info = spt.scm.run("commit_file", [path, description, editable]);
                    // the first item is the changelist number
                    var action = scm_info[1];
                    revision = action.rev;
                    revisions.push(revision);

                    var parts = path.split("/");
                    var filename = parts[parts.length-1];
                    var context = process + "/" + filename;

                    //path = path.replace(bvr.sandbox_dir, "//"+bvr.depot);
                    // NOTE: this assumes project == depot
                    path = path.replace(bvr.sandbox_dir, "//");

                    // Do an inplace check-in into TACTIC
                    var snapshot = server.simple_checkin(bvr.search_key, context, path, {description: description, mode: "perforce", version: revision} );
                }
            }


            if (add_note == 'on') {
                var note = [];
                note.push('CHECK-IN');
                for (var i = 0; i < paths.length; i++) { 
                    var parts = paths[i].split("/");
                    var filename = parts[parts.length-1];
                    note.push(filename+' (v'+revisions[i]+')');
                }
                note.push(': ');
                note.push(description);

                note = note.join(" ");
                server.create_note(bvr.search_key, note, {process: process});
            }
            server.finish({description: "File Check-in ["+paths.length+" file/s]"});
            spt.panel.refresh(top);

            }
            catch(e) {
              spt.error("Error detected: " + e.msg)
              //console.log(e);
              server.abort();
            }

            spt.app_busy.hide();
            '''
            })
        else:
            button.add_behavior(behavior)

        button.add_style("margin-right: auto")
        button.add_style("margin-left: auto")
        button.add_style("margin-top: 20px")
        button.add_style("margin-bottom: 20px")

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

        hidden = HiddenWdg("checkin_type")
        top.add(hidden)
        hidden.add_class("spt_checkin_type")

        grey_out_div = DivWdg()
        top.add(grey_out_div)
        grey_out_div.add_class("spt_publish_disable")
        grey_out_div.add_style("position: absolute")
        grey_out_div.add_style("left: 0px")
        grey_out_div.add_style("top: 10px")
        grey_out_div.add_style("opacity: 0.6")
        grey_out_div.add_color("background", "background")
        grey_out_div.add_style("height: 100%")
        grey_out_div.add_style("width: 100%")
        #grey_out_div.add_border()

        return top
示例#44
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
示例#45
0
    def get_display(my):

        top = my.top
        top.add_class("spt_help_edit_top")
        top.add_color("background", "background")

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

        from tactic.ui.container import ResizableTableWdg
        table = ResizableTableWdg()
        top.add(table)
        table.add_color("color", "color")
        table.add_style("width: 100%")
        table.add_style("height: 500px")


        table.add_row()
        left = table.add_cell()
        left.add_color("background", "background3")

        title_wdg = Table()
        
        title_wdg.add_row()
        left.add(title_wdg)
        title_wdg.add_gradient("background", "background", 0, -10)
        title_wdg.add_style("padding: 5px")
        title_wdg.add_style("margin-bottom: 5px")
        title_wdg.add_style("width: 100%")        

        title_div = DivWdg("<b>Help Pages</b>")
        title_cell = title_wdg.add_cell(title_div)
        title_cell.add_style("width: 100%")

        from tactic.ui.widget import ActionButtonWdg
        insert_button = ActionButtonWdg(title="+", size="small")
        insert_button.add_style("margin-top: -3px")
        insert_button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''

        var class_name = "tactic.ui.panel.EditWdg"
        var view = "edit"
        var title = "Add new help doc"
        var cbjs_insert = "spt.tab.reload_selected();"
        var kwargs = {
          'view': view,
          'search_type': 'config/widget_config',
          'default': '{"category":"HelpWdg"}',
          'ignore': 'search_type|login|config',
          'mode': 'insert',
          //'cbjs_insert': cbjs_insert
        }

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

        '''
        })

        title_wdg.add_cell(insert_button)

        docs_wdg = my.get_doc_wdg()
        left.add(docs_wdg)
        left.add_style("width: 150px")
        left.add_style("min-width: 150px")
        left.add_style("min-height: 500px")
        left.add_style("vertical-align: top")
        left.add_border()


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

        content = HelpEditContentWdg(view=view)
        right.add(content)


        return top
示例#46
0
    def get_bottom_wdg(self):
        from tactic.ui.widget import ActionButtonWdg
        div = DivWdg()
        div.add_style("margin-top: 10px")

        back = ActionButtonWdg(title="< Back", tip="Go back to last page")
        div.add(back)
        back.add_class("spt_wizard_back")
        back.add_style("float: left")

        # FIXME: need to do this because set_style is not the same element as
        # add class
        back.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_wizard_top");
        var back = top.getElement(".spt_wizard_back");
        back.setStyle("display", "none");
        '''
        })

        back.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_wizard_top");
        var pages = top.getElements(".spt_wizard_page");
        var on_dots = top.getElements(".spt_wizard_on_dot");
        var off_dots = top.getElements(".spt_wizard_off_dot");

        // check boundary
        if (pages[0].hasClass("spt_wizard_selected")) {
            return;
        }

        var selected_index = 0;
        for (var i = 0; i < pages.length; i++) {
            var page = pages[i];
            var on_dot = on_dots[i];
            var off_dot = off_dots[i];
            if (page.hasClass("spt_wizard_selected")) {
                page.removeClass("spt_wizard_selected");
                selected_index = i;
            }
            page.setStyle("display", "none");
            on_dot.setStyle("display", "none");
            off_dot.setStyle("display", "");
        }

        if (selected_index == 1) {
            var back = top.getElement(".spt_wizard_back");
            back.setStyle("display", "none");
        }
        if (selected_index == pages.length-1) {
            var next = top.getElement(".spt_wizard_next");
            next.setStyle("display", "");
        }

        var page = pages[selected_index-1];
        page.setStyle("display", "");
        page.addClass("spt_wizard_selected");
        var on_dot = on_dots[selected_index-1];
        var off_dot = off_dots[selected_index-1];
        on_dot.setStyle("display", "");
        off_dot.setStyle("display", "none");

        '''
        })

        if self.submit_button:
            submit = self.submit_button
        else:
            submit_title = self.kwargs.get("submit_title")
            command = self.kwargs.get("command")
            script = self.kwargs.get("script")
            jsscript = self.kwargs.get("jsscript")

            if not submit_title:
                submit_title = "Submit"
            submit = ActionButtonWdg(title="%s >>" % submit_title,
                                     tip=submit_title)
            submit.add_class("spt_wizard_submit")
            submit.add_behavior({
                'type':
                'click_up',
                'command':
                command,
                'script':
                script,
                'jsscript':
                jsscript,
                'cbjs_action':
                '''
            var top = bvr.src_el.getParent(".spt_wizard_top");

            var values = spt.api.Utility.get_input_values(top);

            var server = TacticServerStub.get();
            try {
                if (bvr.command) {
                    spt.app_busy.show("Executing ...", "");
                    server.execute_cmd(bvr.command, values);
                }
                else if (bvr.jsscript) {
                    var values = spt.api.get_input_values(top, null, false);
                    spt.CustomProject.run_script_by_path(bvr.jsscript, values);
                }
                else if (bvr.script) {
                    var values = spt.api.get_input_values(top, null, false);
                    server.execute_python_script(bvr.script, {values:values});
                }
                else {
                    alert("No script or command defined");
                }
            }
            catch(e) {
                console.log(e);
                var xml = spt.parse_xml(e);
                var node = xml.getElementsByTagName("string")[0];
                if (node) {
                    var error = node.textContent;
                    spt.error("Error: " + error);
                    spt.app_busy.hide();
                }
                else {
                    alert(e);
                }
                throw(e);
            }
            spt.app_busy.hide();

            '''
            })

        div.add(submit)
        submit.add_style("float: right")

        next = ActionButtonWdg(title="Next >", tip="Go to next page")
        div.add(next)
        next.add_class("spt_wizard_next")
        next.add_style("float: right")

        next.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_wizard_top");
        var pages = top.getElements(".spt_wizard_page");
        var on_dots = top.getElements(".spt_wizard_on_dot");
        var off_dots = top.getElements(".spt_wizard_off_dot");


        // check boundary
        if (pages[pages.length-1].hasClass("spt_wizard_selected")) {
            return;
        }

        var selected_index = 0;
        for (var i = 0; i < pages.length; i++) {
            var page = pages[i];
            var on_dot = on_dots[i];
            var off_dot = off_dots[i];
            if (page.hasClass("spt_wizard_selected")) {
                page.removeClass("spt_wizard_selected");
                selected_index = i;
            }

            page.setStyle("display", "none");
            on_dot.setStyle("display", "none");
            off_dot.setStyle("display", "");
        }

        if (selected_index == pages.length-2) {
            var next = top.getElement(".spt_wizard_next");
            next.setStyle("display", "none");
        }
        if (selected_index == 0) {
            var back = top.getElement(".spt_wizard_back");
            back.setStyle("display", "");
        }

        var page = pages[selected_index+1];
        page.setStyle("display", "");
        page.addClass("spt_wizard_selected");
        var on_dot = on_dots[selected_index+1];
        var off_dot = off_dots[selected_index+1];
        on_dot.setStyle("display", "");
        off_dot.setStyle("display", "none");

        '''
        })

        div.add("<br clear='all'/>")
        return div
示例#47
0
    def get_display(my):
        top = my.top
        my.set_as_panel(top)
        top.add_class("spt_delete_top")
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_border()
        top.add_style("width: 300px")
        top.add_border()

        search_key = my.kwargs.get("search_key")
        search_keys = my.kwargs.get("search_keys")
        if search_key:
            sobject = Search.get_by_search_key(search_key)
            sobjects = [sobject]
            search_keys = [search_key]
        elif search_keys:
            sobjects = Search.get_by_search_keys(search_keys)
            sobject = sobjects[0]

        if not sobjects:
            msg = "%s not found" % search_key
            return msg
        search_type = sobject.get_base_search_type()

        if search_type in ['sthpw/project', 'sthpw/search_object']:
            msg = 'You cannot delete these items with this tool'
            return msg

        my.search_keys = search_keys

        title = DivWdg()
        top.add(title)
        title.add_color("background", "background", -10)
        if my.search_keys:
            title.add("Delete %s Items" % len(my.search_keys))
        else:
            title.add("Delete Item [%s]" % (sobject.get_code()))
        title.add_style("font-size: 14px")
        title.add_style("font-weight: bold")
        title.add_style("padding: 10px")

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

        content.add(
            "The item to be deleted has a number of dependencies as described below:<br/>",
            'heading')

        # find all the relationships
        related_types = SearchType.get_related_types(search_type,
                                                     direction='children')

        items_div = DivWdg()
        content.add(items_div)
        items_div.add_style("padding: 10px")
        valid_related_ctr = 0
        for related_type in related_types:
            if related_type == "*":
                print "WARNING: related_type is *"
                continue
            if related_type == search_type:
                continue
            if related_type in ['sthpw/search_object', 'sthpw/search_type']:
                continue

            item_div = my.get_item_div(sobjects, related_type)
            if item_div:
                items_div.add(item_div)
                valid_related_ctr += 1

        if valid_related_ctr > 0:
            icon = IconWdg("WARNING", IconWdg.WARNING)
            icon.add_style("float: left")
            content.add(icon)
            content.add(
                "<div><b>WARNING: By selecting the related items above, you can delete them as well when deleting this sObject.</b></div>"
            )
            content.add("<br/>" * 2)
        else:
            # changed the heading to say no dependencies
            content.add("The item to be deleted has no dependencies.<br/>",
                        'heading')

        content.add("There are %s items to be deleted" % len(my.search_keys))
        content.add("<br/>" * 2)

        content.add("Do you wish to continue deleting?")
        content.add("<br/>" * 2)

        button_div = DivWdg()
        button_div.add_styles('width: 300px; height: 75px')
        button = ActionButtonWdg(title="Delete")
        button_div.add(button)
        content.add(button_div)
        button.add_style("float: left")

        button.add_behavior({
            'type':
            'click_up',
            'search_keys':
            my.search_keys,
            'cbjs_action':
            '''
        spt.app_busy.show("Deleting");

        var top = bvr.src_el.getParent(".spt_delete_top");
        var values = spt.api.Utility.get_input_values(top);

        var class_name = "tactic.ui.tools.DeleteCmd";
        var kwargs = {
            'search_keys': bvr.search_keys,
            'values': values
        };

        var del_trigger = function() {
            
            // for fast table
            var tmps = spt.split_search_key(bvr.search_keys[0])
            var tmps2 = tmps[0].split('?');
            var del_st_event = "delete|" + tmps2[0];
            var bvr_fire = {};
            var input = {'search_keys': bvr.search_keys};
            bvr_fire.options = input;
            spt.named_events.fire_event(del_st_event, bvr_fire);
        }

        var server = TacticServerStub.get();
        try {
            server.start({'title': 'Delete sObject', 'description': 'Delete sObject [' + bvr.search_keys + ']'});
            server.execute_cmd(class_name, kwargs);
            server.finish();

            // run the post delete and destroy the popup
            var popup = bvr.src_el.getParent(".spt_popup");
            if (popup.spt_on_post_delete) {
                popup.spt_on_post_delete();
            }

            del_trigger();

            spt.popup.destroy(popup);


        }
        catch(e) {
            spt.alert(spt.exception.handler(e));
        }

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

        button = ActionButtonWdg(title="Cancel")
        button.add_style("float: left")
        button_div.add(button)
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_popup");
        top.destroy();
        '''
        })

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

        return top
示例#48
0
    def get_gear_menu(my):

        top = DivWdg()

        # FIXME: the gear menu widget should be here
        from tactic.ui.container import GearMenuWdg, Menu, MenuItem

        menu = Menu(width=180)

        menu_item = MenuItem(type="title", label="Actions")
        menu.add(menu_item)

        # create a new element
        menu_item = MenuItem(type="action", label="New Element")
        behavior = {
            "options": {"is_insert": "true", "search_type": my.search_type, "view": my.view},
            "cbjs_action": """

        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_view_manager_top");
        var detail_panel = top.getElement(".spt_view_manager_detail");

        var class_name = 'tactic.ui.manager.ElementDefinitionWdg';
        var options = bvr.options
        var values = {};
        spt.panel.load(detail_panel, class_name, options, values, false);
        """,
        }
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        menu_item = MenuItem(type="separator")
        menu.add(menu_item)

        # Show preview of the view
        menu_item = MenuItem(type="action", label="Show Preview")
        behavior = {
            "search_type": my.search_type,
            "view": my.view,
            "cbjs_action": """
        var kwargs = {
          search_type: bvr.search_type,
          view: bvr.view
        };
        var title = "Search Type: [" + bvr.search_type + "], View [" + bvr.view + "]";
        spt.panel.load_popup(title, 'tactic.ui.panel.ViewPanelWdg', kwargs);
        """,
        }
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        # Show preview of the view
        menu_item = MenuItem(type="action", label="Show Full XML Config")
        behavior = {
            "search_type": my.search_type,
            "view": my.view,
            "cbjs_action": """
        var kwargs = {
          search_type: 'config/widget_config',
          view: 'table',
          expression: "@SOBJECT(config/widget_config['search_type','"+bvr.search_type+"']['view','"+bvr.view+"'])",
          filter: [{}]
        };
        var title = "Widget Config - ["+bvr.search_type+"] ["+bvr.view+"]";
        spt.panel.load_popup(title, 'tactic.ui.panel.ViewPanelWdg', kwargs);
        """,
        }
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        menu_item = MenuItem(type="separator")
        menu.add(menu_item)

        # New view popup
        new_view_wdg = DivWdg()
        new_view_wdg.add_class("spt_new_view")
        new_view_wdg.add_style("display: none")
        new_view_wdg.add_style("position: absolute")
        new_view_wdg.add_color("background", "background")
        new_view_wdg.add_style("z-index: 100")
        new_view_wdg.add_border()
        new_view_wdg.set_round_corners()
        new_view_wdg.set_box_shadow()
        new_view_wdg.add_style("padding: 30px")
        new_view_wdg.add("New View Name: ")
        new_view_text = TextWdg("new_view")
        new_view_text.add_class("spt_new_view_text")
        new_view_wdg.add(new_view_text)
        new_view_wdg.add(HtmlElement.br(2))

        # new_view_button = ProdIconButtonWdg('Save New View')
        new_view_button = ActionButtonWdg(title="Save", tip="Save New View")
        new_view_button.add_style("float: left")
        new_view_wdg.add(new_view_button)
        new_view_button.add_behavior(
            {
                "type": "click_up",
                "search_type": my.search_type,
                "cbjs_action": """
            var top = bvr.src_el.getParent(".spt_view_manager_top");
            var new_view_wdg = bvr.src_el.getParent(".spt_new_view");
            var new_view_text = new_view_wdg.getElement(".spt_new_view_text");
            var view = new_view_text.value;
            if (view != '') {
                var server = TacticServerStub.get()
                server.update_config(bvr.search_type, view, []);
                var values = {
                    search_type: bvr.search_type,
                    view: view
                };
                spt.panel.refresh(top, values);
                spt.hide(new_view_wdg);
            }
            else {
                alert("Must supply view name");
            }

            """,
            }
        )
        # new_view_cancel_button = ProdIconButtonWdg('Cancel')
        new_view_cancel_button = ActionButtonWdg(title="Cancel", tip="Cancel Save")
        new_view_cancel_button.add_behavior(
            {
                "type": "click_up",
                "cbjs_action": """
            var new_view_wdg = bvr.src_el.getParent(".spt_new_view");
            spt.hide(new_view_wdg);
            """,
            }
        )
        new_view_wdg.add(new_view_cancel_button)
        top.add(new_view_wdg)

        # TODO: to be implemented.. no more xx please!
        """
        # Save to Project View
        menu_item = MenuItem(type='action', label='xx Save to Project View')
        behavior = {
        'options': {
            'search_type': 'SideBarWdg',
            'view':        'project_view'
        },
        'cbjs_action': '''
        spt.panel.load_popup('SideBar Section', 'tactic.ui.manager.SideBarSectionWdg', bvr.options);
        '''}
        menu_item.add_behavior(behavior)
        menu.add(menu_item)
        """

        # Create a new view
        menu_item = MenuItem(type="action", label="Create New View")
        behavior = {
            "search_type": my.search_type,
            "view": my.view,
            "cbjs_action": """
        var activator = spt.smenu.get_activator(bvr);
        var top = activator.getParent(".spt_view_manager_top");
        var new_view_wdg = top.getElement(".spt_new_view");
        spt.show(new_view_wdg);

        """,
        }
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        # Clear the current view
        menu_item = MenuItem(type="action", label="Clear View")
        behavior = {
            "options": {"is_insert": "true", "search_type": my.search_type, "view": my.view},
            "cbjs_action": """
        if (confirm("Are you sure you wih to clear this view?")) {
            var activator = spt.smenu.get_activator(bvr);
            var top = activator.getParent(".spt_view_manager_top");
            var list_top = top.getElement(".spt_menu_item_list");
            var elements = spt.side_bar.get_elements(bvr.view,list_top);
            for (var i=0; i<elements.length; i++) {
                var element = elements[i];
                if (element.hasClass("spt_side_bar_dummy")) {
                    continue;
                }
                element.destroy();

            }
        }
        """,
        }
        menu_item.add_behavior(behavior)
        menu.add(menu_item)

        gear_menu = GearMenuWdg()
        gear_menu.add(menu)

        top.add(gear_menu)
        return top
示例#49
0
    def get_display(my):
        top = my.top
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("width", "400px")
        top.add_border()
        top.add_class("spt_delete_project_tool_top")

        project_code = my.kwargs.get("project_code")
        if project_code:
            project = Project.get_by_code(project_code)
        else:
            search_key = my.kwargs.get("search_key")
            project = Search.get_by_search_key(search_key)
            if project:
                project_code = project.get_code()

        title_wdg = DivWdg()

        if project:
            top.add(title_wdg)
            title_wdg.add(IconWdg(icon=IconWdg.WARNING))
            title_wdg.add("Deleting Project: %s" % project.get_value("title"))
            title_wdg.add_gradient("background", "background", -10, -10)
            title_wdg.add_style("padding: 5px")
            title_wdg.add_style("font-weight: bold")
            title_wdg.add_style("font-size: 14px")

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

        if not search_key:
            warning_msg = "Projects must be deleted individually"
            content.add(DivWdg(warning_msg, css='warning'))
            content.add("<br/>")
            return top

        warning_msg = "Deleting a project will delete the database associated with this project.  All data will be lost.  Please consider carefully before proceeding."
        if warning_msg:
            content.add(DivWdg(warning_msg, css='warning'))
            content.add("<br/>")

        if not project_code:
            content.add("This project [%s] has been deleted." % search_key)
            return top
        elif not project:
            content.add("This project [%s] has been deleted." % project_code)
            return top

        assert project_code
        assert project

        content.add("<br/>")

        content.add(
            "<b>WARNING: These items will be deleted, but the sTypes entries in search_objects table will be retained.</b> "
        )

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

        total_items_wdg = DivWdg()
        total_items = 0
        content.add(total_items_wdg)

        # find all of the sTypes
        details_wdg = DivWdg()
        content.add(details_wdg)
        details_wdg.add_style("max-height: 300px")
        details_wdg.add_style("overflow-y: auto")
        details_wdg.add_style("padding-left: 15px")
        details_wdg.add_border()

        search_types = project.get_search_types()

        related_types = []

        for search_type_obj in search_types:
            search_type_wdg = DivWdg()
            title = search_type_obj.get_title()
            search_type = search_type_obj.get_value("search_type")

            search_type_wdg.add_style("margin-top: 5px")
            search_type_wdg.add_style("margin-bottom: 5px")

            details_wdg.add(search_type_wdg)
            search_type_wdg.add(title)
            search_type_wdg.add(" (%s)" % search_type)

            search = Search(search_type, project_code=project_code)
            count = search.get_count()
            total_items += count
            search_type_wdg.add("&nbsp; - &nbsp; %s item(s)" % count)

            # TODO: this is similar to SearchType.get_related_types(). streamline at some point.
            related_types = my.get_related_types(search_type)
            for related_type in related_types:

                search = Search(related_type)
                full_search_type = "%s?project=%s" % (search_type,
                                                      project_code)
                if related_type.startswith("sthpw/"):
                    search.add_filter("search_type", full_search_type)
                count = search.get_count()
                if count == 0:
                    continue
                total_items += count

                related_wdg = DivWdg()
                related_wdg.add_style('padding-left: 25px')
                search_type_wdg.add(related_wdg)
                related_wdg.add(related_type)
                related_wdg.add("&nbsp; - &nbsp; %s item(s)" % count)

        if total_items:
            total_items_wdg.add("Total # of items to be deleted: ")
            total_items_wdg.add(total_items)
            total_items_wdg.add_style("font-size: 14px")
            total_items_wdg.add_style("font-weight: bold")
            total_items_wdg.add("<br/>")

        content.add("<br/>" * 2)
        content.add("<b>Do you wish to continue deleting? </b>")
        radio = RadioWdg("mode")
        radio.add_class("spt_mode_radio")
        radio.set_value("delete")
        content.add(radio)
        content.add("<br/>" * 2)

        #content.add("<b>Or do you just wish to retire the project? </b>")
        #radio = RadioWdg("mode")
        #radio.add_class("spt_mode_radio")
        #radio.set_value("retire")
        #content.add(radio)
        #content.add(radio)

        #content.add("<br/>"*2)

        #button = ActionButtonWdg(title="Retire")
        #content.add(button)
        #button.add_style("float: left")

        buttons = Table()
        content.add(buttons)
        buttons.add_row()
        buttons.add_style("margin-left: auto")
        buttons.add_style("margin-right: auto")
        buttons.add_style("width: 250px")

        button = ActionButtonWdg(title="Delete")
        buttons.add_cell(button)

        button.add_behavior({
            'type':
            'click_up',
            #'search_type': search_type,
            'project_code':
            project_code,
            'related_types':
            related_types,
            'cbjs_action':
            '''
            spt.app_busy.show("Deleting");
            var class_name = "tactic.ui.tools.DeleteProjectCmd";
            var kwargs = {
                'project_code': bvr.project_code,
                'related_types': bvr.related_types
            };

            var top = bvr.src_el.getParent(".spt_delete_project_tool_top");
            var radios = top.getElements(".spt_mode_radio");

            //if (!radios[0].checked && !radios[1].checked) {
            if (!radios[0].checked) {
                spt.alert("Please confirm the delete by checking the radio button.");
                spt.app_busy.hide();
                return;
            }

            var mode = 'retire';
            if (radios[0].checked == true) {
                mode = 'delete';
            }


            if (mode == 'retire') {
                return;
            }



            var success = false;
            var server = TacticServerStub.get();
            setTimeout(function() {
                spt.app_busy.show("Deleting Project ["+bvr.project_code+"]")
                var error_message = "Error deleting project ["+bvr.project_code+"]";
                try {
                    server.start({'title': 'Deleted Project ', 'description': 'Deleted Project [' + bvr.project_code + ']'});
                    server.execute_cmd(class_name, kwargs);
                    success = true;

                    var top = bvr.src_el.getParent(".spt_popup");
                    spt.popup.destroy(top);
                    server.finish();
                }
                catch(e) {
                    error_message = spt.exception.handler(e);
                }

                
                spt.app_busy.hide();

                if (success) {
                    spt.notify.show_message("Successfully deleted project ["+bvr.project_code+"]");

                    spt.tab.set_main_body_tab();
                    spt.tab.reload_selected();
                }
                else {
                    if (error_message.test(/does not exist/))
                        error_message += '. You are advised to sign out and log in again.';
                    spt.error(error_message);
                }
            }, 100);
       
        '''
        })

        button = ActionButtonWdg(title="Cancel")
        buttons.add_cell(button)
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_popup");
        spt.popup.destroy(top);
        '''
        })

        return top
    def get_display(my):

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

        title = my.kwargs.get("title")
        name = my.kwargs.get("name")

        if not name:
            name = "upload"

        if not title:
            title = Common.get_display_title(name)

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


        hidden = HiddenWdg(name)
        top.add(hidden)


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

       
        if my.upload_id:
            upload_id = my.upload_id
        else:
            upload = Html5UploadWdg(name=name, multiple=multiple)
            top.add(upload)
            upload_id = upload.get_upload_id()



        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title=title)


        button_id = my.kwargs.get("id")
        if button_id:
            button.set_id(button_id)
        top.add(button)

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



        upload_start = my.kwargs.get("upload_start")
        if not upload_start:
            upload_start = '''
            var top = bvr.src_el.getParent(".spt_upload_top");
            var hidden = top.getElement(".spt_input");
            var file = spt.html5upload.get_file();
            if (!file) {
               return;
            }
            hidden.value = file.name;
            '''
 
        on_complete = my.get_on_complete()
        if not on_complete:
            on_complete = '''
            var files = spt.html5upload.get_files();
            if (files.length == 0) {
               alert('Error: files cannot be found.')
               spt.app_busy.hide();
               return;
            }

            spt.notify.show_message("Uploaded "+files.length+" files");
            spt.app_busy.hide();
            '''

        upload_progress = my.kwargs.get("upload_progress")
        if not upload_progress:
            upload_progress = '''
            var percent = Math.round(evt.loaded * 100 / evt.total);
            spt.app_busy.show("Uploading ["+percent+"%% complete]");
            '''

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


        button.add_behavior( {
            'type': 'click_up',
            'upload_id': upload_id,
            'search_key': search_key,
            'ticket': my.ticket,
            'multiple': multiple,
            'kwargs': my.on_complete_kwargs,
            'cbjs_action': '''
            var search_key = bvr.search_key;

            // set the form
            if (!spt.html5upload.form) {
                spt.html5upload.set_form( $(bvr.upload_id) );
            }
            spt.html5upload.clear();
            spt.html5upload.kwargs = bvr.kwargs;

            var file_obj = spt.html5upload.form.getElement(".spt_file");
           
            var is_multiple = bvr.multiple == true;
        


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

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

            // set an action for completion
            var upload_complete = function(evt) {
            %s;
            spt.app_busy.hide();
            }

            var reader_load = function(file) {
            %s;
            }

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

            var onchange = function () {
                %s;
                spt.html5upload.upload_file(upload_file_kwargs);
	    }

	    if (is_multiple) {
                file_obj.setAttribute('multiple','multiple');
                spt.html5upload.select_files(onchange);
            }
            else
                spt.html5upload.select_file(onchange);

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

        return top
示例#51
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
示例#52
0
    def get_display(my):
        top = my.top
        my.set_as_panel(top)
        top.add_class("spt_delete_top")
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_border()
        top.add_style("width: 300px")
        top.add_border()


        search_key = my.kwargs.get("search_key")
        search_keys = my.kwargs.get("search_keys")
        if search_key:
            sobject = Search.get_by_search_key(search_key)
            sobjects = [sobject]
            search_keys = [search_key]
        elif search_keys:
            sobjects = Search.get_by_search_keys(search_keys)
            sobject = sobjects[0]

        if not sobjects:
            msg =  "%s not found" %search_key
            return msg
        search_type = sobject.get_base_search_type()

        if search_type in ['sthpw/project', 'sthpw/search_object']:
            msg = 'You cannot delete these items with this tool'
            return msg


        my.search_keys = search_keys


        title = DivWdg()
        top.add(title)
        title.add_color("background", "background", -10)
        if my.search_keys:
            title.add("Delete %s Items" % len(my.search_keys))
        else:
            title.add("Delete Item [%s]" % (sobject.get_code()))
        title.add_style("font-size: 14px")
        title.add_style("font-weight: bold")
        title.add_style("padding: 10px")

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


        content.add("The item to be deleted has a number of dependencies as described below:<br/>", 'heading')

        # find all the relationships
        schema = Schema.get()
        related_types = schema.get_related_search_types(search_type, direction="children")
        parent_type = schema.get_parent_type(search_type)
        child_types = schema.get_child_types(search_type)


        # some special considerations
        # FIXME: this needs to be more automatic.  Should only be
        # deletable children (however, that will be defined)
        if search_type in ['sthpw/task','sthpw/note', 'sthpw/snapshot']:
            if "sthpw/project" in related_types:
                related_types.remove("sthpw/project")

            if "sthpw/login" in related_types:
                related_types.remove("sthpw/login")

            if "config/process" in related_types:
                related_types.remove("config/process")



        if parent_type in related_types:
            related_types.remove(parent_type)

        related_types.append('sthpw/note')
        related_types.append('sthpw/task')
        related_types.append('sthpw/snapshot')
        if 'sthpw/work_hour' not in related_types:
            related_types.append('sthpw/work_hour')
       
        items_div = DivWdg()
        content.add( items_div )
        items_div.add_style("padding: 10px")
        valid_related_ctr = 0
        for related_type in related_types:
            if related_type == "*":
                print "WARNING: related_type is *"
                continue
            if related_type == search_type:
                continue
            if related_type in ['sthpw/search_object','sthpw/search_type']:
                continue

            item_div = my.get_item_div(sobjects, related_type)
            if item_div:
                items_div.add(item_div)
                valid_related_ctr += 1


        

        if valid_related_ctr > 0:
            icon = IconWdg("WARNING", IconWdg.WARNING)
            icon.add_style("float: left")
            content.add( icon )
            content.add("<div><b>WARNING: By selecting the related items above, you can delete them as well when deleting this sObject.</b></div>")
            content.add("<br/>"*2)
        else:
            # changed the heading to say no dependencies
            content.add("The item to be deleted has no dependencies.<br/>", 'heading')


        content.add("There are %s items to be deleted" % len(my.search_keys))
        content.add("<br/>"*2)

        content.add("Do you wish to continue deleting?")
        content.add("<br/>"*2)

        button_div = DivWdg()
        button_div.add_styles('width: 300px; height: 50px')
        button = ActionButtonWdg(title="Delete")
        button_div.add(button)
        content.add(button_div)
        button.add_style("float: left")

        button.add_behavior( {
        'type': 'click_up',
        'search_keys': my.search_keys,
        'cbjs_action': '''
        spt.app_busy.show("Deleting");

        var top = bvr.src_el.getParent(".spt_delete_top");
        var values = spt.api.Utility.get_input_values(top);

        var class_name = "tactic.ui.tools.DeleteCmd";
        var kwargs = {
            'search_keys': bvr.search_keys,
            'values': values
        };
        var server = TacticServerStub.get();
        try {
            server.start({'title': 'Delete sObject', 'description': 'Delete sObject [' + bvr.search_keys + ']'});
            server.execute_cmd(class_name, kwargs);
            server.finish();

            // run the post delete and destroy the popup
            var popup = bvr.src_el.getParent(".spt_popup");
            if (popup.spt_on_post_delete) {
                popup.spt_on_post_delete();
            }

            spt.popup.destroy(popup);


        }
        catch(e) {
            spt.alert(spt.exception.handler(e));
        }

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



        button = ActionButtonWdg(title="Cancel")
        button.add_style("float: left")
        button_div.add(button)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_popup");
        top.destroy();
        '''
        } )


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


        return top
示例#53
0
    def get_display(self):
        top = self.top
        self.set_as_panel(top)
        top.add_class("spt_delete_top")
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_border()
        top.add_style("width: 400px")
        top.add_border()


        search_key = self.kwargs.get("search_key")
        search_keys = self.kwargs.get("search_keys")
        if search_key:
            sobject = Search.get_by_search_key(search_key)
            sobjects = [sobject]
            search_keys = [search_key]
        elif search_keys:
            sobjects = Search.get_by_search_keys(search_keys)
            sobject = sobjects[0]

        if not sobjects or not sobject:
            msg =  "%s not found" %search_key
            return msg
        search_type = sobject.get_base_search_type()

        if search_type in ['sthpw/project', 'sthpw/search_object']:
            msg = 'You cannot delete these items with this tool'
            return msg


        self.search_keys = search_keys


        title = DivWdg()
        top.add(title)

        icon = IconWdg("WARNING", IconWdg.WARNING)
        icon.add_style("float: left")
        title.add(icon)

        if len(self.search_keys) > 1:
            title.add("Delete %s Items" % len(self.search_keys))
        else:
            title.add("Delete Item [%s]" % (sobject.get_code()))
        title.add_style("font-size: 20px")
        title.add_style("font-weight: bold")
        title.add_style("padding: 10px")

        title.add("<hr/>")

        content = DivWdg()
        top.add(content)
        content.add_style("margin: 5px 10px 20px 10px")


        content.add("The item to be deleted has a number of dependencies as described below:<br/>", 'heading')

        # find all the relationships
        related_types = SearchType.get_related_types(search_type, direction='children') 
       
        items_div = DivWdg()
        content.add( items_div )
        items_div.add_style("padding: 10px")
        valid_related_ctr = 0
        for related_type in related_types:
            if related_type == "*":
                print("WARNING: related_type is *")
                continue
            if related_type == search_type:
                continue
            if related_type in ['sthpw/search_object','sthpw/search_type']:
                continue

            item_div = self.get_item_div(sobjects, related_type)
            if item_div:
                items_div.add(item_div)
                valid_related_ctr += 1


        

        if valid_related_ctr > 0:
            #icon = IconWdg("Note", "BS_NOTE")
            #icon.add_style("float: left")
            #content.add( icon )
            content.add("<div><b>By selecting the above, the corresponding related items will be deleted as well.</b></div>")
            content.add("<br/>"*2)
        else:
            # changed the heading to say no dependencies
            content.add("The item to be deleted has no dependencies.<br/>", 'heading')


        num_items = len(self.search_keys)
        if num_items == 1:
            verb = "is 1 item"
        else:
            verb = "are %s items" % num_items
        content.add("There %s to be deleted" % verb)
        content.add("<br/>"*2)

        content.add("Do you wish to continue deleting?")
        content.add("<br/>"*3)

        button_div = DivWdg()
        button_div.add_class("spt_buttons")
        content.add(button_div)
        button_div.add_style('text-align: center')

        button = ActionButtonWdg(title="Delete", width=100, color="danger")
        button_div.add(button)
        button.add_style("display: inline-block")

        deleting_div = DivWdg()
        content.add(deleting_div)
        deleting_div.add("<img src='/context/icons/common/indicator_snake.gif'/>")
        deleting_div.add_class("spt_delete_msg")
        deleting_div.add(" Deleting ...")
        deleting_div.add_style("text-align: center")
        deleting_div.add_style("font-size: 16px")
        deleting_div.add_style("margin: 20px")
        deleting_div.add_style("display: none")

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

        button.add_behavior( {
        'type': 'click_up',
        'search_keys': self.search_keys,
        'on_complete': on_complete,
        'cbjs_action': '''
        spt.app_busy.show("Deleting");
        //spt.notify.show_message("Deleting ...");

        //var button_el = bvr.src_el.getParent(".spt_buttons");
        //button_el.setStyle("display", "none");

        var top = bvr.src_el.getParent(".spt_delete_top");
        var values = spt.api.Utility.get_input_values(top);

        var class_name = "tactic.ui.tools.DeleteCmd";
        var kwargs = {
            'search_keys': bvr.search_keys,
            'values': values
        };

        var del_trigger = function() {
            
            // for fast table
            var tmps = spt.split_search_key(bvr.search_keys[0])
            var tmps2 = tmps[0].split('?');
            var del_st_event = "delete|" + tmps2[0];
            var bvr_fire = {};
            var input = {'search_keys': bvr.search_keys};
            bvr_fire.options = input;
            spt.named_events.fire_event(del_st_event, bvr_fire);
        }

        var server = TacticServerStub.get();

        server.execute_cmd(class_name, kwargs, null, {
            on_complete: function() {
                //spt.notify.show_message("Finshed deleting ...");

                // run the post delete and destroy the popup
                var popup = bvr.src_el.getParent(".spt_popup");
                if (popup.spt_on_post_delete) {
                    popup.spt_on_post_delete();
                }

                del_trigger();

                spt.popup.destroy(popup);


                if (bvr.on_complete) {
                   on_complete = function() {
                       eval(bvr.on_complete);
                   }
                   on_complete();
                }

                spt.app_busy.hide();
            },
            on_error: function(e) {
                spt.notify.show_message("Error on delete");
                spt.alert(spt.exception.handler(e));
                spt.app_busy.hide();
            }
        } );

        '''
        } )



        button = ActionButtonWdg(title="Cancel", width=100)
        button_div.add(button)
        button.add_style("display: inline-block")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_popup");
        top.destroy();
        '''
        } )


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


        return top
示例#54
0
    def get_bottom_wdg(my):
        from tactic.ui.widget import ActionButtonWdg
        div = DivWdg()


        back = ActionButtonWdg(title="< Back", tip="Go back to last page")
        div.add(back)
        back.add_class("spt_wizard_back")
        back.add_style("float: left")

        # FIXME: need to do this because set_style is not the same element as
        # add class
        back.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_wizard_top");
        var back = top.getElement(".spt_wizard_back");
        back.setStyle("display", "none");
        '''
        } )

        back.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_wizard_top");
        var pages = top.getElements(".spt_wizard_page");
        var on_dots = top.getElements(".spt_wizard_on_dot");
        var off_dots = top.getElements(".spt_wizard_off_dot");

        // check boundary
        if (pages[0].hasClass("spt_wizard_selected")) {
            return;
        }

        var selected_index = 0;
        for (var i = 0; i < pages.length; i++) {
            var page = pages[i];
            var on_dot = on_dots[i];
            var off_dot = off_dots[i];
            if (page.hasClass("spt_wizard_selected")) {
                page.removeClass("spt_wizard_selected");
                selected_index = i;
            }
            page.setStyle("display", "none");
            on_dot.setStyle("display", "none");
            off_dot.setStyle("display", "");
        }

        if (selected_index == 1) {
            var back = top.getElement(".spt_wizard_back");
            back.setStyle("display", "none");
        }
        if (selected_index == pages.length-1) {
            var next = top.getElement(".spt_wizard_next");
            next.setStyle("display", "");
        }

        var page = pages[selected_index-1];
        page.setStyle("display", "");
        page.addClass("spt_wizard_selected");
        var on_dot = on_dots[selected_index-1];
        var off_dot = off_dots[selected_index-1];
        on_dot.setStyle("display", "");
        off_dot.setStyle("display", "none");

        '''
        } )




        if my.submit_button:
            submit = my.submit_button
        else:
            command = my.kwargs.get("command")
            submit_title = my.kwargs.get("submit_title")
            if not submit_title:
                submit_title = "Submit"
            submit = ActionButtonWdg(title="%s >>" % submit_title, tip=submit_title)
            submit.add_behavior( {
            'type': 'click_up',
            'command': command,
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_wizard_top");

            var values = spt.api.Utility.get_input_values(top);

            spt.app_busy.show("Executing ...", "");
            var server = TacticServerStub.get();
            try {
                server.execute_cmd(bvr.command, values);
            }
            catch(e) {
                var xml = spt.parse_xml(e);
                var node = xml.getElementsByTagName("string")[0];
                var error = node.textContent;
                spt.error("Error: " + error);
                spt.app_busy.hide();
                throw(e);
            }

            '''
            } )



        div.add(submit)
        submit.add_style("float: right")


        next = ActionButtonWdg(title="Next >", tip="Go to next page")
        div.add(next)
        next.add_class("spt_wizard_next")
        next.add_style("float: right")

        next.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_wizard_top");
        var pages = top.getElements(".spt_wizard_page");
        var on_dots = top.getElements(".spt_wizard_on_dot");
        var off_dots = top.getElements(".spt_wizard_off_dot");


        // check boundary
        if (pages[pages.length-1].hasClass("spt_wizard_selected")) {
            return;
        }

        var selected_index = 0;
        for (var i = 0; i < pages.length; i++) {
            var page = pages[i];
            var on_dot = on_dots[i];
            var off_dot = off_dots[i];
            if (page.hasClass("spt_wizard_selected")) {
                page.removeClass("spt_wizard_selected");
                selected_index = i;
            }

            page.setStyle("display", "none");
            on_dot.setStyle("display", "none");
            off_dot.setStyle("display", "");
        }

        if (selected_index == pages.length-2) {
            var next = top.getElement(".spt_wizard_next");
            next.setStyle("display", "none");
        }
        if (selected_index == 0) {
            var back = top.getElement(".spt_wizard_back");
            back.setStyle("display", "");
        }

        var page = pages[selected_index+1];
        page.setStyle("display", "");
        page.addClass("spt_wizard_selected");
        var on_dot = on_dots[selected_index+1];
        var off_dot = off_dots[selected_index+1];
        on_dot.setStyle("display", "");
        off_dot.setStyle("display", "none");

        '''
        } )


        div.add("<br clear='all'/>")
        return div
示例#55
0
    def get_display(self):
       
        top = self.top
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("width", "400px")
        top.add_border()
        top.add_class("spt_delete_project_tool_top")
        site = self.kwargs.get("site")
        set_site = self.kwargs.get("set_site")

        if set_site != False and site:
            Site.set_site(site)

        login = Environment.get_user_name()
        
        security = Environment.get_security()

        if not security.is_admin() and not security.is_in_group(self.delete_group):

            top.add(IconWdg(icon=IconWdg.WARNING))
            top.add("Only Admin can delete projects")
            top.add_style("padding: 50px")
            top.add_style("text-align: center")
            if set_site and site:
                Site.pop_site()
            return top






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

        # check if delete permissions exist for this site and project
        security = Environment.get_security()
        if False and not security.check_access("project", project_code, "delete"):
            top.add(IconWdg(icon=IconWdg.WARNING))
            top.add("Not permitted to delete this project")
            top.add_style("padding: 30px")
            top.add_style("text-align: center")
            top.add_style("margin: 50px 30px")
            top.add_border()
            top.add_color("background", "background3")
            return top


        


        if project_code:
            project = Project.get_by_code(project_code)
            if not project:
                top.add(IconWdg(icon=IconWdg.WARNING))
                top.add("No project [%s] exists in this database" % project_code)
                top.add_style("padding: 30px")
                top.add_style("text-align: center")
                top.add_style("margin: 50px 30px")
                top.add_border()
                top.add_color("background", "background3")
                return top
            search_key = project.get_search_key()
        else:
            search_key = self.kwargs.get("search_key")
            project = Search.get_by_search_key(search_key)
            if project:
                project_code = project.get_code()

       
           
        title_wdg = DivWdg()

        if project:
            top.add(title_wdg)
            title_wdg.add(IconWdg(icon=IconWdg.WARNING))
            title_wdg.add("Deleting Project: %s" % project.get_value("title") ) 
            title_wdg.add_color("background", "background", -5)
            title_wdg.add_style("padding: 5px")
            title_wdg.add_style("font-weight: bold")
            title_wdg.add_style("font-size: 14px")


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

        if not search_key:
            warning_msg = "Projects must be deleted individually"
            content.add(DivWdg(warning_msg, css='warning'))
            content.add("<br/>")
            return top

        warning_msg = "Deleting a project will delete the database associated with this project.  All data and files will be lost.  Please consider carefully before proceeding."
        if warning_msg:
            warning_wdg = DivWdg(warning_msg, css='warning')
            content.add(warning_wdg)
            warning_wdg.add_style("margin: 20 10px")
            content.add("<br/>")

        
        if not project_code:
            content.add("This project [%s] has been deleted."%search_key)
            return top
        elif not project:
            content.add("This project [%s] has been deleted."%project_code)
            return top


        assert project_code
        assert project

        content.add("<br/>")

        content.add("<b>NOTE: These items will be deleted, but the sTypes entries in search_objects table will be retained.</b> ")


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

        total_items_wdg = DivWdg()
        total_items = 0
        content.add(total_items_wdg)


        # find all of the sTypes
        details_wdg = DivWdg()
        content.add(details_wdg)
        details_wdg.add_style("max-height: 300px")
        details_wdg.add_style("overflow-y: auto")
        details_wdg.add_style("padding-left: 15px")
        details_wdg.add_border()

        search_types = project.get_search_types()

        related_types = []

        for search_type_obj in search_types:
            search_type_wdg = DivWdg()
            title = search_type_obj.get_title()
            search_type = search_type_obj.get_value("search_type")

            search_type_wdg.add_style("margin-top: 5px")
            search_type_wdg.add_style("margin-bottom: 5px")


            details_wdg.add(search_type_wdg)
            search_type_wdg.add(title)
            search_type_wdg.add(" (%s)" % search_type )

            search = Search( search_type, project_code=project_code )
            count = search.get_count()
            total_items += count
            search_type_wdg.add("&nbsp; - &nbsp; %s item(s)" % count)

            # TODO: this is similar to SearchType.get_related_types(). streamline at some point. 
            related_types = self.get_related_types(search_type)
            for related_type in related_types:

                try:
                    search = Search(related_type)
                except Exception as e:
                    print("WARNING: ", e)
                    continue
                full_search_type = "%s?project=%s" % (search_type, project_code)
                if related_type.startswith("sthpw/"):
                    search.add_filter("search_type", full_search_type)
                count = search.get_count()
                if count == 0:
                    continue
                total_items += count


                related_wdg = DivWdg()
                related_wdg.add_style('padding-left: 25px')
                search_type_wdg.add(related_wdg)
                related_wdg.add(related_type)
                related_wdg.add("&nbsp; - &nbsp; %s item(s)" % count)


        if total_items:
            total_items_wdg.add("Total # of items to be deleted: ")
            total_items_wdg.add(total_items)
            total_items_wdg.add_style("font-size: 14px")
            total_items_wdg.add_style("font-weight: bold")
            total_items_wdg.add("<br/>")



        content.add("<br/>"*2)
        content.add("<b>Do you wish to continue deleting? </b>")
        radio = RadioWdg("mode")
        radio.add_class("spt_mode_radio")
        radio.set_value("delete")
        radio.add_style("margin-left: 15")
        radio.add_style("margin-top: 5")
        content.add(radio)
        content.add("<br/>"*3)

        #content.add("<b>Or do you just wish to retire the project? </b>")
        #radio = RadioWdg("mode")
        #radio.add_class("spt_mode_radio")
        #radio.set_value("retire")
        #content.add(radio)
        #content.add(radio)

        #content.add("<br/>"*2)


        #button = ActionButtonWdg(title="Retire")
        #content.add(button)
        #button.add_style("float: left")

        buttons = Table()
        content.add(buttons)
        buttons.add_row()
        buttons.add_style("margin-left: auto")
        buttons.add_style("margin-right: auto")
        buttons.add_style("width: 250px")


        button = ActionButtonWdg(title="Delete", color="danger")
        buttons.add_cell(button)

        command_class = self.kwargs.get("command_class")
        if not command_class:
            command_class = 'tactic.ui.tools.DeleteProjectCmd'

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

        button.add_behavior( {
        'type': 'click_up',
        #'search_type': search_type,
        'project_code': project_code,
        'site': site,
        'related_types': related_types,
        'command_class': command_class,
        'on_complete': on_complete,
        'cbjs_action': '''
            spt.app_busy.show("Deleting");
            var class_name = bvr.command_class;
            var kwargs = {
                'site': bvr.site,
                'project_code': bvr.project_code,
                'related_types': bvr.related_types
            };

            var top = bvr.src_el.getParent(".spt_delete_project_tool_top");
            var radios = top.getElements(".spt_mode_radio");

            //if (!radios[0].checked && !radios[1].checked) {
            if (!radios[0].checked) {
                spt.alert("Please confirm the delete by checking the radio button.");
                spt.app_busy.hide();
                return;
            }

            var mode = 'retire';
            if (radios[0].checked == true) {
                mode = 'delete';
            }


            if (mode == 'retire') {
                return;
            }



            var success = false;
            var server = TacticServerStub.get();
            setTimeout(function() {
                spt.app_busy.show("Deleting Project ["+bvr.project_code+"]")
                var error_message = "Error deleting project ["+bvr.project_code+"]";
                try {
                    server.start({'title': 'Deleted Project ', 'description': 'Deleted Project [' + bvr.project_code + ']'});
                    server.execute_cmd(class_name, kwargs);
                    success = true;
                }
                catch(e) {
                    error_message = spt.exception.handler(e);
                }

                
                spt.app_busy.hide();

                if (success) {


                    if (bvr.on_complete) {
                       on_complete = function() {
                           eval(bvr.on_complete);
                       }
                       on_complete();
                    }

                    spt.notify.show_message("Successfully deleted project ["+bvr.project_code+"]");

                    spt.tab.set_main_body_tab();
                    spt.tab.reload_selected();
                }
                else {
                    if (error_message.test(/does not exist/))
                        error_message += '. You are advised to sign out and log in again.';
                    spt.error(error_message);
                }
                
                
                var top = bvr.src_el.getParent(".spt_popup");
                spt.popup.destroy(top);
                server.finish();
                    
                    
            }, 100);
       
        '''
        } )



        button = ActionButtonWdg(title="Cancel")
        buttons.add_cell(button)
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_popup");
        spt.popup.destroy(top);
        '''
        } )


        if site:
            Site.pop_site()


        return top
    def get_simple_definition_wdg(my):

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

        title.add("Column Definition")

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

        detail_wdg.add(HtmlElement.br(2))

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

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

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

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

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

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

        detail_wdg.add(nullable)

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

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

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

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

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


            '''
        })

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

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

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

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

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

        return detail_wdg
示例#57
0
    def get_group_wdg(self, prev_sobj):
        if not self.is_preprocessed:
            self.preprocess()

        sobject = self.get_current_sobject()
        ref_sobj = self.get_ref_obj(sobject)
        self.current_ref_sobj = ref_sobj
        
        if not ref_sobj:
            return "Undetermined parent: [%s]" % SearchKey.get_by_sobject(sobject)

        widget = DivWdg()

        # add add button
        #from tactic.ui.widget import TextBtnWdg, TextBtnSetWdg
        #buttons_list = []
        #buttons_list.append( {
        #    'label': '+', 'tip': 'Add Another Item',
        #    'bvr': { 'cbjs_action': "spt.dg_table.add_item_cbk(evt, bvr)" }
        #} )
        #add_btn = TextBtnSetWdg( float="right", buttons=buttons_list,
        #                     spacing=6, size='small', side_padding=0 )
        #widget.add(add_btn)

        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title='+', tip='Add Another Item', size='small')
        widget.add(button)
        button.add_style("float: right")
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': "spt.dg_table.add_item_cbk(evt, bvr)"
        } )

 
        label = "Attach"
        label_option = self.get_option("label")
        if label_option:
            label = label_option 
       
        table = Table()
        table.add_color("color", "color")
        table.add_row()

        search_key = sobject.get_search_key()
        # add a thumbe widget
        thumb = ThumbWdg()
        thumb.set_icon_size(40)
        thumb.set_sobject(ref_sobj)
        thumb.set_option('latest_icon', 'true') 
        table.add_cell(thumb)


        # add the text description
        name_span = DivWdg(ref_sobj.get_code())
        name_span.add_style('margin-left: 20px')
        table.add_cell(name_span)


        if ref_sobj.has_value("name"):
            name_span.add( " - " )
            name_span.add( ref_sobj.get_value("name") )

        #status = ref_sobj.get_value("status", no_exception=True)
        #if status:
        #    span = SpanWdg("(status:%s)" % ref_sobj.get_value("status"))
        #    table.add_cell(span)

        
        if ref_sobj.has_value("description"):
            description_wdg = ExpandableTextWdg("description")
            description_wdg.set_max_length(200)
            description_wdg.set_sobject(ref_sobj)
            td = table.add_cell( description_wdg )
            td.add_style("padding-left: 15px")



        # FIXME: not sure about the layout here
        #if ref_sobj.has_value("pipeline_code"):
        #    pipeline_code = ref_sobj.get_value("pipeline_code")
        #    span = SpanWdg("(pipeline:%s)" % pipeline_code )
        #    td = table.add_cell(span)
        #    td.add_style("padding-left: 15px")
        
        widget.add(table)
            

        return widget
示例#58
0
    def get_display(my):
        top = my.top
        top.add_style("height: 100%")
        top.add_style("overflow-x: hidden")
        top.set_unique_id()

        width = my.kwargs.get("width")
        if width:
            top.add_style("width: %s" % width)



        from tactic.ui.panel import CustomLayoutWdg
        html = my.kwargs.get("html")
        view = my.kwargs.get("view")

        alias = my.kwargs.get("alias")
        if alias:
            aliases = alias.split("|")
            alias = aliases[0]
            aliases = aliases[1:]
        else:
            aliases = []

        top.add_relay_behavior( {
            'type': 'mouseover',
            'bvr_match_class': 'spt_link',
            'cbjs_action': '''
            spt.mouse.table_layout_hover_over({}, {src_el: bvr.src_el, add_color_modifier: -5});
            '''
        } )

        top.add_relay_behavior( {
            'type': 'mouseout',
            'bvr_match_class': 'spt_link',
            'cbjs_action': '''
            spt.mouse.table_layout_hover_out({}, {src_el: bvr.src_el})
            '''
        } )

        top.add_smart_style("spt_link", "margin-left", "5px")
        if alias == 'main':
            top.add_smart_style("spt_link", "text-decoration", "none")
        else:
            top.add_smart_style("spt_link", "text-decoration", "underline")
        top.add_smart_style("spt_link", "padding", "1px")



        if aliases:
            related_wdg = my.get_related_wdg(aliases)
            top.add( related_wdg )


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

        # attempt to get if from the widget config
        search = Search("config/widget_config")
        search.add_filter("category", "HelpWdg")
        search.add_filter("view", alias)
        config = search.get_sobject()


        if html:
            layout = CustomLayoutWdg(html=html, view=view)
            top.add(layout)

        # config can override alias
        elif config:
            layout = CustomLayoutWdg(config=config, view=alias)
            author = config.get_value("login")
            timestamp = config.get_value("timestamp")
            top.add(layout)

        elif alias:
            widget = HelpDocFilterWdg(alias=alias)
            top.add(widget)

        elif rel_path:
            widget = HelpDocFilterWdg(rel_path=rel_path)
            top.add(widget)


        elif not view:
            layout = DivWdg()
            top.add(layout)
            allow_create = my.kwargs.get("allow_create")
            if allow_create not in ['false', False]:
                layout.add(HelpCreateWdg())
            else:
                layout.add("No documentation found")
                layout.add_style("padding: 30px 20px")
                layout.add_style("margin-left: auto")
                layout.add_style("margin-right: auto")
                layout.add_style("margin-top: 50px")
                layout.add_style("text-align: center")
                layout.add_style("width: 250px;")
                layout.add_color("background", "background3")
                layout.add_color("color", "color3")
                layout.add_border()


        elif view == 'default':
            top.add(my.get_default_wdg())

        else:
            author = "TACTIC"
            timestamp = None

            search = Search("config/widget_config")
            search.add_filter("category", "HelpWdg")
            search.add_filter("view", view)
            config = search.get_sobject()
            if config:
                layout = CustomLayoutWdg(config=config, view=view)
                author = config.get_value("login")
                timestamp = config.get_value("timestamp")

            else:
                # get it from the file system
                layout = DivWdg()
                install_dir = Environment.get_install_dir()
                path = "%s/src/context/help/%s.html" % (install_dir,view)
                if os.path.exists(path):
                    f = open(path)
                    html = f.read()
                    f.close()
                    layout.add(html)

                else:
                    div = DivWdg()
                    layout.add(div)
                    div.add_style("padding: 15px")
                    div.add_style("margin: 10px")
                    div.add_border()
                    div.add_color("background", "background", -5)
                    div.add_style("text-align: center")
                    div.add_style("font-weight: bold")

                    icon = IconWdg("WARNING", IconWdg.WARNING)
                    div.add(icon)
                    div.add("There are no help pages available for this key [%s]<br/><br/>" % view)
                    div.add("<br/>")

                    div.add("Click to create a new custom doc:")
                    from tactic.ui.widget import ActionButtonWdg
                    button = ActionButtonWdg(title="Create", tip="Create docs for this view")
                    div.add(button)
                    button.add_style("margin-right: auto")
                    button.add_style("margin-left: auto")
                    button.add_style("margin-top: 15px")
                    button.add_style("margin-bottom: 15px")
                    # FIXME: copied code from above
                    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);
                        
                    '''
                    } )



                layout.add_style("margin-top: 10px")



            info_div = DivWdg()
            info_div.add("<i>Author: %s</i>" % author)
            info_div.add_style("opacity: 0.5")
            info_div.add_style("font-size: 10px")
            info_div.add_style("position: absolute")
            info_div.add_style("bottom: 20px")

            content_div = DivWdg()
            top.add(content_div)
            content_div.add_style("padding: 5px")
            content_div.add(layout)

            top.add(info_div)

        #top.add(HelpContentWdg.get_default_wdg(aliases))

        return top
示例#59
0
    def get_display(my):
        alias = my.kwargs.get("alias")

        div = DivWdg()
        div.add_style("padding: 15px")
        div.add_style("margin: 10px")
        div.add_border()
        div.add_color("background", "background", -5)
        div.add_style("text-align: center")
        div.add_style("font-weight: bold")

        icon = IconWdg("WARNING", IconWdg.HELP_MISSING)
        div.add(icon)
        div.add("Add custom documentation page by clicking the Create button")

        from tactic.ui.widget import ActionButtonWdg
        button = ActionButtonWdg(title="Create", tip="Create docs for this view")
        div.add(button)
        button.add_style("margin-right: auto")
        button.add_style("margin-left: auto")
        button.add_style("margin-top: 15px")
        button.add_style("margin-bottom: 15px")
        # FIXME: copied code from above
        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);
            
        '''
        } )
        return div
示例#60
0
    def get_display(my):

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

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

        top.add("<hr/>")

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

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

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

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

        db_select.set_value(vendor)

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

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

        }
        '''
        })

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

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

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

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

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

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

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

        top.add("<br/>")

        title = "Installation"

        category = "install"

        options = ['default_project']

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

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

        top.add("<hr/>")

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

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

        options = checkin_keys[:]

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

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

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

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

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

        top.add("<hr/>")

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

        top.add("<hr/>")

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

        #wizard_wdg = WizardWdg()
        #top.add(wizard_wdg)
        #wizard_wdg.add(DivWdg("cow"), "cow")
        #wizard_wdg.add(DivWdg("pig"), "pig")
        #wizard_wdg.add(DivWdg("dog"), "dog")
        return top