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)); } ''' })
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
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_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
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 ''' } )
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
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
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
def get_page_four(my): last_page = DivWdg() last_page.add_style("padding-top: 80px") last_page.add_style("padding-left: 30px") cb = CheckboxWdg('jump_to_tab', label='Jump to Tab') cb.set_checked() last_page.add(cb) last_page.add(HtmlElement.br(5)) button_div = DivWdg() create_button = ActionButtonWdg(title="Create >>", tip="Create new project") my.wizard.add_submit_button(create_button) create_button.add_style("float: right") create_button.add_behavior({ 'type': "click_up", 'cbjs_action': ''' spt.alert('perform action here'); ''' }) # you can even pass in a custom cacel_script like # spt.info("You have cancelled") cancel_script = my.kwargs.get("cancel_script") if cancel_script: cancel_button = ActionButtonWdg(title="Cancel") cancel_button.add_style("float: left") cancel_button.add_behavior({ 'type': "click_up", 'cbjs_action': cancel_script }) button_div.add(cancel_button) create_button.add_style("margin-right: 15px") create_button.add_style("margin-left: 75px") button_div.add("<br clear='all'/>") last_page.add(button_div) return last_page
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
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
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
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
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 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.') ''' })
def get_search_wdg(my): filter_div = DivWdg() filter_div.add_style("width: 200px") search_button = ActionButtonWdg(title='Search', tip='Run search with this criteria') if my.run_search_bvr: run_search_bvr = my.run_search_bvr else: # cbjs works better than cbfn here run_search_bvr = { 'type': 'click_up', 'new_search': True, 'cbjs_action': 'spt.dg_table.search_cbk(evt, bvr)', 'panel_id': my.prefix, } search_button.add_behavior( run_search_bvr ) # add a listener for other widgets to call Run Search listen_bvr = run_search_bvr.copy() listen_bvr['type'] = 'listen' listen_bvr['event_name'] = 'search_%s' %my.search_type # needed for CgApp loader search_button.add_behavior( listen_bvr ) clear_button = ActionButtonWdg(title='Clear', tip='Clear all search criteria') clear_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs(bvr.src_el.getParent(".spt_search"), '.spt_input:not(select.spt_search_filter_mode)'); ''' } ) # {'label': 'Clear', 'tip': 'Clear all search criteria', 'width': 45, # 'bvr': {'cbjs_action': 'spt.api.Utility.clear_inputs(bvr.src_el.getParent(".spt_search"))'} } #] #txt_btn_set = TextBtnSetWdg(buttons=buttons_list, spacing=6, size='small', side_padding=4 ) filter_div.add(search_button) search_button.add_style("float: left") filter_div.add(clear_button) clear_button.add_style("float: left") filter_div.add("<br clear='all'/>") return filter_div
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_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
def get_display(my): my.check() if my.is_refresh: div = Widget() else: div = DivWdg() my.set_as_panel(div) div.add_style('padding','6px') min_width = '300px' div.add_style('min-width', min_width) div.add_color('background','background') div.add_class('spt_add_task_panel') 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 my.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 items to add tasks to' %len(my.search_key_list)) div.add(HtmlElement.br()) hint = HintWdg('Tasks are added according to the assigned pipeline.') 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 my.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: span = SpanWdg("Pipeline: %s" % pipeline.get_code()) 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) 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 len(skipped) == len(sobjects): #if skipped: # msg_div = DivWdg('WARNING: No valid item to add task for.') # msg_div.add_style('margin-left: 10px') # div.add(msg_div, 'info') #else: if True: #btn = TextBtnWdg(size='medium', label='Add Tasks', horiz_aligh='center') btn = ActionButtonWdg(title='Add Tasks') btn.add_behavior({'type' : 'click_up', 'post_event': 'search_table_%s'% my.table_id, 'cbjs_action': ''' spt.dg_table.add_task_selected(bvr); ''', 'search_key_list': my.search_key_list }) cb = CheckboxWdg('skip_duplicated', label='skip duplicated') cb.set_checked() option_div =DivWdg(cb) option_div.add_style('width', '130px') hint = HintWdg("If checked, it won't add the task if a task for the checked process has already been created.") option_div.add(hint) option_div.add_style('align: left') div.add(option_div) div.add(HtmlElement.br()) btn.add_style("float: right") div.add(btn) div.add(HtmlElement.br(clear="all")) if skipped: content_div.add(HtmlElement.br()) skip_div = DivWdg('Missing pipeline code (Skipped)') skip_div.add_style('text-decoration: underline') content_div.add(skip_div) content_div.add(HtmlElement.br()) item_div = DivWdg() item_div.add_style('margin-left: 10px') content_div.add(item_div) for skip in skipped: item_div.add(skip.get_code()) item_div.add(HtmlElement.br()) return div
def get_buttons_wdg(my): button_div = DivWdg() button = ActionButtonWdg(title='Run') button_div.add(button) button.add_style("float: left") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_script_editor_top"); var code = top.getElement(".spt_code").value; var folder = top.getElement(".spt_folder").value; var title = top.getElement(".spt_title").value; var language = top.getElement(".spt_language").value; spt.ace_editor.set_editor_top(top); var editor = spt.ace_editor.editor; var value = editor.getSession().toString(); try { if (language == 'javascript') { eval(value); } else if (language == 'expression') { var server = TacticServerStub.get(); var ret_val; ret_val = server.eval(value); if (ret_val && ret_val.length) { for (var i = 0; i < ret_val.length; i++) { log.critical(ret_val[i]); } } else { log.critical(ret_val); } } else if (language == 'python') { var path = folder + "/" + title; var server = TacticServerStub.get(); var info = server.execute_python_script(path); log.critical(info); } else { var ok = function() { eval(value);} spt.confirm("Please set the language of this script. It's assumed to be javascript if left blank. Continue to run?", ok, null); } } catch(e) { spt.error(spt.exception.handler(e)); } ''' }) button = ActionButtonWdg(title='Save') button_div.add(button) button.add_style("float: left") button.add_behavior({ 'type': 'click_up', 'editor_id': my.unique_id, 'cbjs_action': ''' /* if (!has_changes(bvr)) { spt.alert("No changes have been made"); return; } */ var top = bvr.src_el.getParent(".spt_script_editor_top"); spt.app_busy.show("Saving Script ..."); setTimeout(function() { spt.ace_editor.set_editor_top(top); spt.script_editor.save_script_cbk(evt, bvr); spt.app_busy.hide(); }, 10); ''' }) button = ActionButtonWdg(title='Clear') button_div.add(button) button.add_style("float: left") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') ); var top = bvr.src_el.getParent(".spt_script_editor_top"); spt.ace_editor.set_editor_top(top); var editor = spt.ace_editor.editor; var document = editor.getSession().getDocument() document.setValue(""); ''' }) button = ActionButtonWdg(title='Resize') #button_div.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var editor = spt.ace_editor.editor; var editor_id = spt.ace_editor.editor_id; $(editor_id).setStyle("width", "1000px"); $(editor_id).setStyle("height", "800px"); editor.resize(); ''' }) return button_div
def get_files_wdg(self): div = DivWdg() div.set_name("Files") div.add_style("padding: 10px") shelf_wdg = DivWdg() div.add(shelf_wdg) shelf_wdg.add_style("height: 25px") shelf_wdg.add_style("padding: 5px") shelf_wdg.add_border() shelf_wdg.add_color("background", "background3") shelf_wdg.add_style("margin: 0px -11px 10px -11px") project_code = Project.get_project_code() share_code = self.server.get_code() # NOT supported yet base_dir = self.server.get_value("base_dir") imports_dir = "%s/imports" % base_dir #import datetime #now = datetime.datetime.now() #version = now.strftime("%Y%m%d_%H%M%S") button = ActionButtonWdg(title="Export") shelf_wdg.add(button) button.add_behavior( { 'type': 'click_up', 'project_code': project_code, 'share_code': share_code, 'imports_dir': imports_dir, 'cbjs_action': ''' var class_name = 'tactic.ui.sync.SyncCreateTemplateCmd' var kwargs = { server: bvr.share_code, project_code: bvr.project_code, base_dir: bvr.imports_dir, } spt.app_busy.show("Exporting project ..."); var server = TacticServerStub.get(); server.execute_cmd(class_name, kwargs); var top = bvr.src_el.getParent(".spt_share_item"); spt.panel.refresh(top); spt.app_busy.hide(); ''' }) from tactic.ui.app import PluginDirListWdg dir_list = PluginDirListWdg(base_dir=self.base_dir, location="server") #from tactic.ui.widget import DirListWdg #dir_list = DirListWdg(base_dir=self.base_dir, location="server") div.add(dir_list) return div
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
def get_gear_menu(self): 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': self.search_type, 'view': self.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': self.search_type, 'view': self.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': self.search_type, 'view': self.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': self.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': self.search_type, 'view': self.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': self.search_type, 'view': self.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
def get_display(my): top = my.top top.add_color("background", "background") top.add_class("spt_pipelines_top") my.set_as_panel(top) inner = DivWdg() top.add(inner) search_type = my.kwargs.get("search_type") pipeline_code = my.kwargs.get("pipeline_code") if search_type: search = Search("sthpw/pipeline") search.add_filter("search_type", search_type) pipelines = search.get_sobjects() else: pipeline = Pipeline.get_by_code(pipeline_code) if pipeline: pipelines = [pipeline] else: pipelines = [] if not pipelines: div = DivWdg() inner.add(div) inner.add_style("padding: 50px") div.add_border() div.add_color("color", "color3") div.add_color("background", "background3") div.add_style("width: 400px") div.add_style("height: 100px") div.add_style("padding: 30px") icon = IconWdg("WARNING", IconWdg.WARNING) div.add(icon) div.add( "<b>This Searchable Type does not have pipelines defined.</b>") div.add("<br/>" * 2) div.add( "<b style='padding-left: 35px'>Click Create to add one...</b>") div.add("<br/>" * 2) button_div = DivWdg() div.add(button_div) button = ActionButtonWdg(title="Create", tip="Create pipeline") button_div.add(button) button.add_style("margin: auto") button.add_behavior({ 'type': 'click_up', 'search_type': search_type, 'cbjs_action': ''' var server = TacticServerStub.get(); var cmd = 'tactic.ui.startup.PipelineCreateCbk'; var kwargs = { search_type: bvr.search_type } server.execute_cmd(cmd, kwargs) var top = bvr.src_el.getParent(".spt_pipelines_top"); spt.panel.refresh(top); ''' }) return top # get the defalt task statuses task_pipeline = Pipeline.get_by_code("task") if task_pipeline: statuses = task_pipeline.get_process_names() else: statuses = ['Pending', 'In Progress', 'Complete'] statuses_str = ",".join(statuses) pipelines_div = DivWdg() inner.add(pipelines_div) pipelines_div.add_style("font-size: 12px") pipelines_div.add_style("padding: 10px") buttons_div = DivWdg() pipelines_div.add(buttons_div) button = SingleButtonWdg(title="Save Pipelines", icon=IconWdg.SAVE) buttons_div.add(button) button.add_behavior({ 'type': 'click_up', 'default_statuses': statuses_str, 'cbjs_action': ''' spt.app_busy.show("Saving Pipeline...") setTimeout(function() { try { var top = bvr.src_el.getParent(".spt_pipelines_top"); // get all the pipeline divs var pipeline_els = top.getElements(".spt_pipeline_top"); var data = {}; for ( var i = 0; i < pipeline_els.length; i++) { var pipeline_code = pipeline_els[i].getAttribute("spt_pipeline_code"); var values = spt.api.Utility.get_input_values(pipeline_els[i]); data[pipeline_code] = values; } var class_name = 'tactic.ui.startup.PipelineEditCbk'; var kwargs = { data: data } var server = TacticServerStub.get(); server.execute_cmd(class_name, kwargs); } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); } , 100); ''' }) buttons_div.add("<br clear='all'/>") buttons_div.add_style("margin-bottom: 5px") for pipeline in pipelines: pipeline_div = DivWdg() pipelines_div.add(pipeline_div) pipeline_div.add_class("spt_pipeline_top") code = pipeline.get_code() pipeline_div.add_attr("spt_pipeline_code", code) title = DivWdg() pipeline_div.add(title) title.add("Pipeline: ") title.add(code) title.add_style("padding: 5px") title.add_gradient("background", "background", -10) title.add_style("font-weight: bold") title.add_style("margin: -10 -10 5 -10") header_wdg = DivWdg() pipeline_div.add(header_wdg) header_wdg.add_color("background", "background", -5) headers = ['Process', 'Description', 'Task Status'] widths = ['90px', '170px', '200px'] for header, width in zip(headers, widths): th = DivWdg() header_wdg.add(th) th.add("<b>%s</b>" % header) th.add_style("float: left") th.add_style("width: %s" % width) th.add_style("padding: 3px") header_wdg.add("<br clear='all'/>") # get all of the process sobjects from this pipeline pipeline_code = pipeline.get_code() search = Search("config/process") search.add_filter("pipeline_code", pipeline.get_code()) process_sobjs = search.get_sobjects() process_sobj_dict = {} for process_sobj in process_sobjs: process = process_sobj.get_value("process") process_sobj_dict[process] = process_sobj from tactic.ui.container import DynamicListWdg dyn_list = DynamicListWdg() pipeline_div.add(dyn_list) pipeline_div.add_style("width: 725px") processes = pipeline.get_process_names() if not processes: processes.append("") processes.append("") processes.append("") processes.insert(0, "") for i, process in enumerate(processes): if process == '': process_name = '' description = '' else: process_sobj = process_sobj_dict.get(process) if process_sobj: process_name = process_sobj.get_value("process") description = process_sobj.get_value("description") else: if isinstance(process, basestring): process_name = process else: process_name = process.get_name() deccription = '' # get the task pipeline for this process if process_name: process = pipeline.get_process(process_name) task_pipeline_code = process.get_task_pipeline() if task_pipeline_code != "task": task_pipeline = Search.get_by_code( "sthpw/pipeline", task_pipeline_code) else: task_pipeline = None else: task_pipeline_code = "task" task_pipeline = None process_div = DivWdg() process_div.add_style("float: left") process_div.add_class("spt_process_top") if i == 0: dyn_list.add_template(process_div) else: dyn_list.add_item(process_div) #process_div.add_style("padding-left: 10px") #process_div.add_style("margin: 5px") table = Table() process_div.add(table) table.add_row() text = NewTextWdg("process") table.add_cell(text) text.add_style("width: 95px") text.set_value(process_name) text.add_class("spt_process") # the template has a border if i == 0: text.add_style("border: solid 1px #AAA") text = NewTextWdg("description") table.add_cell(text) text.add_style("width: 175px") text.set_value(description) # the template has a border if i == 0: text.add_style("border: solid 1px #AAA") text = NewTextWdg("task_status") table.add_cell(text) text.add_style("width: 325px") #text.set_value(statuses_str) if task_pipeline: statuses = task_pipeline.get_process_names() text.set_value(",".join(statuses)) else: text.set_value("(default)") #text.add_style("opacity: 0.5") text.add_style("border-style: none") text.add_behavior({ 'type': 'click_up', 'statuses': statuses_str, 'cbjs_action': ''' if (bvr.src_el.value == '(default)') { bvr.src_el.value = bvr.statuses; } ''' }) table.add_cell(" " * 2) button = IconButtonWdg(tip="Trigger", icon=IconWdg.ARROW_OUT) table.add_cell(button) button.add_behavior({ 'type': 'click_up', 'search_type': search_type, 'pipeline_code': pipeline_code, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_process_top"); var process_el = top.getElement(".spt_process"); var process = process_el.value; if (process == "") { alert("Process value is empty"); return; } var class_name = 'tactic.ui.tools.TriggerToolWdg'; var kwargs = { mode: "pipeline", process: process, pipeline_code: bvr.pipeline_code }; spt.panel.load_popup("Trigger", class_name, kwargs); ''' }) """ button = IconButtonWdg(tip="Edit", icon=IconWdg.EDIT) table.add_cell(button) button.add_behavior( { 'type': 'click_up', 'search_type': search_type, 'pipeline_code': pipeline_code, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_process_top"); var process_el = top.getElement(".spt_process"); var process = process_el.value; if (process == "") { alert("Process value is empty"); return; } var class_name = 'tactic.ui.panel.EditWdg'; var kwargs = { expression: "@SOBJECT(config/process['process','"+process+"'])" } spt.panel.load_popup("Trigger", class_name, kwargs); ''' } ) """ table.add_cell(" " * 3) pipeline_div.add("<br clear='all'/>") pipeline_div.add("<br clear='all'/>") if my.kwargs.get("is_refresh"): return inner else: return top
def get_display(my): relative_dir = my.kwargs.get("relative_dir") my.relative_dir = relative_dir div = DivWdg() div.add_class("spt_ingest_top") div.add_style("width: 100%px") div.add_style("min-width: 500px") div.add_style("padding: 20px") div.add_color("background", "background") my.search_type = my.kwargs.get("search_type") if not my.search_type: div.add("No search type specfied") return div if relative_dir: folder_div = DivWdg() div.add(folder_div) folder_div.add("Folder: %s" % relative_dir) folder_div.add_style("opacity: 0.5") folder_div.add_style("font-style: italic") folder_div.add_style("margin-bottom: 10px") data_div = my.get_data_wdg() data_div.add_style("float: left") data_div.add_style("float: left") div.add(data_div) # create the help button help_button_wdg = DivWdg() div.add(help_button_wdg) help_button_wdg.add_style("float: right") help_button = ActionButtonWdg(title="?", tip="Ingestion Widget Help", size='s') help_button_wdg.add(help_button) help_button.add_behavior({ 'type': 'click_up', 'cbjs_action': '''spt.help.load_alias("ingestion_widget")''' }) from tactic.ui.input import Html5UploadWdg upload = Html5UploadWdg(multiple=True) div.add(upload) button = ActionButtonWdg(title="Add") button.add_style("float: right") button.add_style("margin-top: -3px") div.add(button) button.add_behavior({ 'type': 'click_up', 'normal_ext': File.NORMAL_EXT, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var files_el = top.getElement(".spt_to_ingest_files"); var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i'); //clear upload progress var upload_bar = top.getElement('.spt_upload_progress'); if (upload_bar) { upload_bar.setStyle('width','0%'); upload_bar.innerHTML = ''; } var onchange = function (evt) { var files = spt.html5upload.get_files(); var delay = 0; for (var i = 0; i < files.length; i++) { var size = files[i].size; var file_name = files[i].name; var is_normal = regex.test(file_name); if (size >= 10*1024*1024 || is_normal) { spt.drag.show_file(files[i], files_el, 0, false); } else { spt.drag.show_file(files[i], files_el, delay, true); if (size < 100*1024) delay += 50; else if (size < 1024*1024) delay += 500; else if (size < 10*1024*1024) delay += 1000; } } } spt.html5upload.clear(); spt.html5upload.set_form( top ); spt.html5upload.select_file( onchange ); ''' }) button = ActionButtonWdg(title="Clear") button.add_style("float: right") button.add_style("margin-top: -3px") div.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); }; ''' }) div.add("<br clear='all'/>") div.add("<br clear='all'/>") border_color_light = div.get_color("background2", 8) border_color_dark = div.get_color("background2", -15) background_mouseout = div.get_color("background3", 10) background_mouseenter = div.get_color("background3", 8) files_div = DivWdg() files_div.add_style("position: relative") files_div.add_class("spt_to_ingest_files") div.add(files_div) files_div.add_style("max-height: 300px") files_div.add_style("height: 300px") files_div.add_style("overflow-y: auto") files_div.add_style("padding: 3px") files_div.add_color("background", background_mouseout) files_div.add_style("border: 3px dashed %s" % border_color_light) files_div.add_style("border-radius: 20px 20px 20px 20px") files_div.add_style("z-index: 1") #files_div.add_style("display: none") bgcolor = div.get_color("background3") bgcolor2 = div.get_color("background3", -3) #style_text = "text-align: center; margin-top: 100px; color: #A0A0A0; font-size: 3.0em; z-index: 10;" background = DivWdg() background.add_class("spt_files_background") files_div.add(background) background.add_style("text-align: center") background.add_style("margin-top: 100px") background.add_style("opacity: 0.65") background.add_style("font-size: 3.0em") background.add_style("z-index: 10") background_text = DivWdg("<p>Drag Files Here</p>") background.add(background_text) files_div.add_behavior({ 'type': 'mouseover', 'cbjs_action': ''' bvr.src_el.setStyle("border","3px dashed %s") bvr.src_el.setStyle("background","%s") ''' % (border_color_dark, background_mouseenter) }) files_div.add_behavior({ 'type': 'mouseout', 'cbjs_action': ''' bvr.src_el.setStyle("border", "3px dashed %s") bvr.src_el.setStyle("background","%s") ''' % (border_color_light, background_mouseout) }) # Test drag and drop files files_div.add_attr("ondragenter", "return false") files_div.add_attr("ondragover", "return false") files_div.add_attr("ondrop", "spt.drag.noop(event, this)") files_div.add_behavior({ 'type': 'load', 'normal_ext': File.NORMAL_EXT, 'cbjs_action': ''' spt.drag = {} var background; spt.drag.show_file = function(file, top, delay, icon) { if (!background) { background = top.getElement(".spt_files_background"); if (background) background.setStyle("display", "none"); } var template = top.getElement(".spt_upload_file_template"); var clone = spt.behavior.clone(template); clone.removeClass("spt_upload_file_template"); clone.addClass("spt_upload_file"); clone.setStyle("display", ""); if (typeof(delay) == 'undefined') { delay = 0; } // remember the file handle clone.file = file; var name = file.name; var size = parseInt(file.size / 1024 * 10) / 10; var thumb_el = clone.getElement(".spt_thumb"); var date_label_el = clone.getElement(".spt_date_label"); var date_el = clone.getElement(".spt_date"); //var loadingImage = loadImage( setTimeout( function() { var draw_empty_icon = function() { var img = $(document.createElement("div")); img.setStyle("width", "58"); img.setStyle("height", "34"); //img.innerHTML = "MP4"; img.setStyle("border", "1px dotted #222") thumb_el.appendChild(img); }; if (icon) { var loadingImage = loadImage( file, function (img) { if (img.width) thumb_el.appendChild(img); else draw_empty_icon(); }, {maxWidth: 80, maxHeight: 60, canvas: true, contain: true} ); } else { draw_empty_icon(); } loadImage.parseMetaData( file, function(data) { if (data.exif) { var date = data.exif.get('DateTimeOriginal'); if (date) { date_label_el.innerHTML = date; if (date_el) { date_el.value = date; } } } } ); }, delay ); /* var reader = new FileReader(); reader.thumb_el = thumb_el; reader.onload = function(e) { this.thumb_el.innerHTML = [ '<img class="thumb" src="', e.target.result, '" title="', escape(name), '" width="60px"', '" padding="5px"', '"/>' ].join(''); } reader.readAsDataURL(file); */ clone.getElement(".spt_name").innerHTML = file.name; clone.getElement(".spt_size").innerHTML = size + " KB"; clone.inject(top); } spt.drag.noop = function(evt, el) { var top = $(el).getParent(".spt_ingest_top"); var files_el = top.getElement(".spt_to_ingest_files"); evt.stopPropagation(); evt.preventDefault(); evt.dataTransfer.dropEffect = 'copy'; var files = evt.dataTransfer.files; var delay = 0; var skip = false; var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i'); for (var i = 0; i < files.length; i++) { var size = files[i].size; var file_name = files[i].name; var is_normal = regex.test(file_name); if (size >= 10*1024*1024 || is_normal) { spt.drag.show_file(files[i], files_el, 0, false); } else { spt.drag.show_file(files[i], files_el, delay, true); if (size < 100*1024) delay += 50; else if (size < 1024*1024) delay += 500; else if (size < 10*1024*1024) delay += 1000; } } } ''' }) # create a template that will be filled in for each file files_div.add_relay_behavior({ 'type': 'mouseenter', 'color': files_div.get_color("background3", -5), 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.color); ''' }) files_div.add_relay_behavior({ 'type': 'mouseleave', 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' bvr.src_el.setStyle("background", ""); ''' }) files_div.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_remove', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_upload_file"); spt.behavior.destroy_element(top); ''' }) """ metadata_view = "test/wizard/metadata" files_div.add_relay_behavior( { 'type': 'mouseup', 'view': metadata_view, 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' var class_name = 'tactic.ui.panel.CustomLayoutWdg'; var kwargs = { view: bvr.view } spt.app_busy.show("Loading Metadata"); spt.panel.load_popup("Metadata", class_name, kwargs); spt.app_busy.hide(); ''' } ) """ # template for each file item file_template = DivWdg() file_template.add_class("spt_upload_file_template") files_div.add(file_template) file_template.add_style("margin-bottom: 3px") file_template.add_style("padding: 3px") file_template.add_style("height: 40px") file_template.add_style("display: none") thumb_div = DivWdg() file_template.add(thumb_div) thumb_div.add_style("float: left") thumb_div.add_style("width: 60") thumb_div.add_style("height: 40") thumb_div.add_style("overflow: hidden") thumb_div.add_style("margin: 3 10 3 0") thumb_div.add_class("spt_thumb") info_div = DivWdg() file_template.add(info_div) info_div.add_style("float: left") name_div = DivWdg() name_div.add_class("spt_name") info_div.add(name_div) name_div.add("image001.jpg") name_div.add_style("width: 150px") """ dialog = DialogWdg(display="false", show_title=False) info_div.add(dialog) dialog.set_as_activator(info_div, offset={'x':0,'y':10}) dialog_data_div = DivWdg() dialog_data_div.add_color("background", "background") dialog_data_div.add_style("padding", "10px") dialog.add(dialog_data_div) dialog_data_div.add("Category: ") text = TextInputWdg(name="category") dialog_data_div.add(text) text.add_class("spt_category") text.add_style("padding: 1px") """ date_div = DivWdg() date_div.add_class("spt_date_label") info_div.add(date_div) date_div.add("") date_div.add_style("opacity: 0.5") date_div.add_style("font-size: 0.8em") date_div.add_style("font-style: italic") date_div.add_style("margin-top: 3px") hidden_date_div = HiddenWdg("date") hidden_date_div.add_class("spt_date") info_div.add(date_div) size_div = DivWdg() size_div.add_class("spt_size") file_template.add(size_div) size_div.add("433Mb") size_div.add_style("float: left") size_div.add_style("width: 150px") size_div.add_style("text-align: right") remove_div = DivWdg() remove_div.add_class("spt_remove") file_template.add(remove_div) icon = IconButtonWdg(title="Remove", icon=IconWdg.DELETE) icon.add_style("float: right") remove_div.add(icon) #remove_div.add_style("text-align: right") div.add("<br/>") info = DivWdg() div.add(info) info.add_class("spt_upload_info") progress_div = DivWdg() progress_div.add_class("spt_upload_progress_top") div.add(progress_div) progress_div.add_style("width: 100%") progress_div.add_style("height: 15px") progress_div.add_style("margin-bottom: 10px") progress_div.add_border() #progress_div.add_style("display: none") progress = DivWdg() progress_div.add(progress) progress.add_class("spt_upload_progress") progress.add_style("width: 0px") progress.add_style("height: 100%") progress.add_gradient("background", "background3", -10) progress.add_style("text-align: right") progress.add_style("overflow: hidden") progress.add_style("padding-right: 3px") from tactic.ui.app import MessageWdg progress.add_behavior({ 'type': 'load', 'cbjs_action': MessageWdg.get_onload_js() }) # NOTE: files variable is passed in automatically upload_init = ''' server.start( {description: "Upload and check-in of ["+files.length+"] files"} ); var info_el = top.getElement(".spt_upload_info"); info_el.innerHTML = "Uploading ..."; ''' upload_progress = ''' var top = bvr.src_el.getParent(".spt_ingest_top"); progress_el = top.getElement(".spt_upload_progress"); var percent = Math.round(evt.loaded * 100 / evt.total); progress_el.setStyle("width", percent + "%"); progress_el.innerHTML = String(percent) + "%"; ''' oncomplete_script_path = my.kwargs.get("oncomplete_script_path") oncomplete_script = '' if oncomplete_script_path: script_folder, script_title = oncomplete_script_path.split("/") oncomplete_script_expr = "@GET(config/custom_script['folder','%s']['title','%s'].script)" % ( script_folder, script_title) server = TacticServerStub.get() oncomplete_script_ret = server.eval(oncomplete_script_expr, single=True) if oncomplete_script_ret: oncomplete_script = '''var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); };''' + oncomplete_script_ret script_found = True else: script_found = False oncomplete_script = "alert('Error: oncomplete script not found');" if not oncomplete_script: oncomplete_script = ''' var click_action = function() { var fade = true; var pop = spt.popup.get_popup(top) spt.popup.close(pop, fade); } spt.info("Ingest Completed", {click: click_action}); server.finish(); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); }; var background = top.getElement(".spt_files_background"); background.setStyle("display", ""); spt.message.stop_interval(key); var info_el = top.getElement(".spt_upload_info"); info_el.innerHTML = ''; if (spt.table) { spt.table.run_search(); } ''' script_found = True on_complete = ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var update_data_top = top.getElement(".spt_edit_top"); var progress_el = top.getElement(".spt_upload_progress"); progress_el.innerHTML = "100%"; progress_el.setStyle("width", "100%"); var info_el = top.getElement(".spt_upload_info"); var search_type = bvr.kwargs.search_type; var relative_dir = bvr.kwargs.relative_dir; var filenames = []; for (var i = 0; i != files.length;i++) { var name = files[i].name; filenames.push(name); } var key = spt.message.generate_key(); var values = spt.api.get_input_values(top); //var category = values.category[0]; //var keywords = values.keywords[0]; var extra_data = values.extra_data ? values.extra_data[0]: {}; var parent_key = values.parent_key[0]; var convert_el = top.getElement(".spt_image_convert") var convert = spt.api.get_input_values(convert_el); var processes = values.process; if (processes) { process = processes[0]; if (!process) { process = null; } } else { process = null; } var return_array = false; var update_data = spt.api.get_input_values(update_data_top, null, return_array); var kwargs = { search_type: search_type, relative_dir: relative_dir, filenames: filenames, key: key, parent_key: parent_key, //category: category, //keywords: keywords, extra_data: extra_data, update_data: update_data, process: process, convert: convert, } on_complete = function() { ''' + oncomplete_script + ''' }; var class_name = bvr.action_handler; // TODO: make the async_callback return throw an e so we can run // server.abort server.execute_cmd(class_name, kwargs, null, {on_complete:on_complete}); on_progress = function(message) { msg = JSON.parse(message.message); var percent = msg.progress; var description = msg.description; info_el.innerHTML = description; progress_el.setStyle("width", percent+"%"); progress_el.innerHTML = percent + "%"; } spt.message.set_interval(key, on_progress, 2000); ''' upload_div = DivWdg() div.add(upload_div) #button = UploadButtonWdg(**kwargs) button = ActionButtonWdg(title="Ingest") upload_div.add(button) button.add_style("float: right") upload_div.add_style("margin-bottom: 15px") upload_div.add("<br clear='all'/>") action_handler = my.kwargs.get("action_handler") if not action_handler: action_handler = 'tactic.ui.tools.IngestUploadCmd' button.add_behavior({ 'type': 'click_up', 'action_handler': action_handler, 'kwargs': { 'search_type': my.search_type, 'relative_dir': relative_dir, 'script_found': script_found }, 'cbjs_action': ''' if (bvr.kwargs.script_found != true) { spt.alert("Error: provided on_complete script not found"); return; } var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); // get the server that will be used in the callbacks var server = TacticServerStub.get(); // retrieved the stored file handles var files = []; for (var i = 0; i < file_els.length; i++) { files.push( file_els[i].file ); } if (files.length == 0) { alert("Either click 'Add' or drag some files over to ingest."); return; } // defined the callbacks var upload_start = function(evt) { } var upload_progress = function(evt) { %s; } var upload_complete = function(evt) { %s; spt.app_busy.hide(); } var upload_file_kwargs = { files: files, upload_start: upload_start, upload_complete: upload_complete, upload_progress: upload_progress }; if (bvr.ticket) upload_file_kwargs['ticket'] = bvr.ticket; %s; spt.html5upload.set_form( top ); spt.html5upload.upload_file(upload_file_kwargs); ''' % (upload_progress, on_complete, upload_init) }) return div
def get_category_wdg(my, category, mode="new"): subscriptions = my.get_subscriptions(category, mode) if not subscriptions: return div = DivWdg() div.add_style("width: 100%") title_div = DivWdg() div.add(title_div) title_div.add_style("padding: 10px") title_div.add_border() title_div.add_color("background", "background3") title = category or "Subscriptions" title_div.add("%s " % title) summary_div = SpanWdg() title_div.add(summary_div) summary_div.add_style("font-size: 0.8em") summary_div.add_style("opacity: 0.5") search_keys = [x.get_search_key() for x in subscriptions] button = ActionButtonWdg(title="Clear All") div.add(button) button.add_behavior({ 'type': 'click_up', 'search_keys': search_keys, 'cbjs_action': ''' var server = TacticServerStub.get(); for (var i = 0; i < bvr.search_keys.length; i++) { var search_key = bvr.search_keys[i]; server.update(search_key, {'last_cleared':'NOW'}); spt.panel.refresh(bvr.src_el); } ''' }) # types of subscriptions table = Table() table.add_style('width: 100%') table.add_border() table.add_color("background", "background3") div.add(table) ss = [] for subscription in subscriptions: table.add_row() td = table.add_cell() message_code = subscription.get_value("message_code") search = Search("sthpw/message") search.add_filter("code", message_code) message = search.get_sobject() # show the thumb if not message: if mode == "all": td = table.add_cell( FormatMessageWdg.get_preview_wdg(subscription)) td = table.add_cell() td.add("No Messages") continue size = 60 msg_element = FormatMessageWdg(subscription=subscription, short_format='true') # this is optional msg_element.set_sobject(message) description = msg_element.get_buffer_display() #td = table.add_cell() history_icon = IconButtonWdg(title="Subscription History", icon=IconWdg.HISTORY) #td.add(icon) message_code = subscription.get_value("message_code") history_icon.add_behavior({ 'type': 'click_up', 'message_code': message_code, 'cbjs_action': ''' var class_name = 'tactic.ui.panel.FastTableLayoutWdg'; var message_code = bvr.message_code; var kwargs = { search_type: 'sthpw/message_log', show_shelf: false, expression: "@SOBJECT(sthpw/message_log['message_code','"+message_code+"'])", view: 'history' }; spt.tab.set_main_body_tab(); spt.tab.add_new("Message History", "Message History", class_name, kwargs); ''' }) # description can take up 70% td = table.add_cell() td.add_style("width: %spx" % (SubscriptionBarWdg.WIDTH * 0.7)) desc_div = DivWdg() td.add(desc_div) desc_div.add(description) desc_div.add_style("padding: 0px 20px") td = table.add_cell() #td.add(message.get_value("status")) #td = table.add_cell() timestamp = message.get_datetime_value("timestamp") if timestamp: timestamp_str = timestamp.strftime("%b %d, %Y - %H:%M") else: timestamp_str = "" td.add(timestamp_str) #td = table.add_cell() #td.add(subscription.get_value("last_cleared")) td = table.add_cell() td.add(history_icon) td.add(HtmlElement.br(2)) td.add_style('width: 30px') icon = IconButtonWdg(title="Unsubscribe", icon=IconWdg.DELETE) td.add(icon) subscription_key = subscription.get_search_key() icon.add_behavior({ 'type': 'click_up', 'search_key': subscription_key, 'message_code': message_code, 'cbjs_action': ''' if (!confirm("Unsubscribe from [" + bvr.message_code + "]?")) { return; } var top = bvr.src_el.getParent(".spt_subscription_top"); var server = TacticServerStub.get(); server.delete_sobject(bvr.search_key); spt.panel.refresh(top); ''' }) ss.append(subscription) num_sobjects = len(ss) if not num_sobjects: return None summary_div.add("(%s changes)" % num_sobjects) #from tactic.ui.panel import FastTableLayoutWdg #table = FastTableLayoutWdg(search_type="sthpw/subscription",show_shelf=False) #div.add(table) #table.set_sobjects(ss) return div
def get_chat_wdg(my, key, interval=False): div = DivWdg() div.add_class("spt_chat_session_top") div.add_color("background", "background") title_wdg = DivWdg() div.add(title_wdg) title_wdg.add_color("background", "background3") title_wdg.add_style("padding: 5px") title_wdg.add_style("font-weight: bold") title_wdg.add_border() icon = IconButtonWdg(title="Remove Chat", icon=IconWdg.DELETE) icon.add_style("float: right") icon.add_style("margin-top: -5px") title_wdg.add(icon) icon.add_behavior({ 'type': 'click_up', 'key': key, 'cbjs_action': ''' var server = TacticServerStub.get(); var top = bvr.src_el.getParent(".spt_chat_session_top"); spt.behavior.destroy_element(top); ''' }) current_user = Environment.get_user_name() logins = Search.eval( "@SOBJECT(sthpw/subscription['message_code','%s'].sthpw/login)" % key) for login in logins: if login.get_value("login") == current_user: continue thumb = ThumbWdg() thumb.set_icon_size(45) thumb.set_sobject(login) thumb.add_style("float: left") thumb.add_style("margin: -5px 10px 0px -5px") title_wdg.add(thumb) title_wdg.add(login.get_value("display_name")) title_wdg.add("<br clear='all'/>") history_div = DivWdg() div.add(history_div) history_div.add_class("spt_chat_history") history_div.add_style("width: auto") history_div.add_style("height: auto") history_div.add_style("max-height: 400px") history_div.add_style("padding: 5px") history_div.add_class("spt_resizable") history_div.add_border() history_div.add_style("overflow-y: auto") #history_div.add_style("font-size: 0.9em") search = Search("sthpw/message_log") search.add_filter("message_code", key) search.add_order_by("timestamp") message_logs = search.get_sobjects() last_login = None last_date = None for message_log in message_logs: login = message_log.get("login") message = message_log.get("message") timestamp = message_log.get_datetime_value("timestamp") #timestamp = timestamp.strftime("%b %d, %Y - %H:%M") timestamp_str = timestamp.strftime("%H:%M") date_str = timestamp.strftime("%b %d, %Y") msg = "" msg += "<table style='margin-top: 5px; font-size: 0.9em; width: 100%'><tr><td colspan='2'>" if date_str != last_date: msg += "<br/><b style='font-size: 1.0em'>" + date_str + "</b><hr/></td></tr>" msg += "<tr><td>" last_login = None if login != last_login: msg += "<b>" + login + "</b><br/>" msg += message.replace("\n", '<br/>') msg += "</td><td style='text-align: right; margin-bottom: 5px; width: 75px; vertical-align: top'>" msg += timestamp_str msg += "</td></tr></table>" history_div.add(msg) last_login = login last_date = date_str history_div.add_behavior({ 'type': 'load', 'cbjs_action': ''' bvr.src_el.scrollTop = bvr.src_el.scrollHeight; ''' }) if message_logs: last_message = message_logs[-1].get("message") last_login = message_logs[-1].get("login") else: last_message = "" last_login = "" div.add_attr("spt_last_message", last_message) div.add_attr("spt_last_login", last_login) if interval: div.add_behavior({ 'type': 'load', 'key': key, 'cbjs_action': r''' var text_el = bvr.src_el.getElement(".spt_chat_text"); var history_el = bvr.src_el.getElement(".spt_chat_history"); var callback = function(message) { //history_el.setStyle("background", "red"); var login = message.login; var timestamp = message.timestamp; if (timestamp) { var parts = timestamp.split(" "); parts = parts[1].split("."); timestamp = parts[0]; } else { timestamp = ""; } var tmp = message.message || ""; var last_message = bvr.src_el.getAttribute("spt_last_message"); var last_login = bvr.src_el.getAttribute("spt_last_login"); if (tmp == last_message && login == last_login) { return; } bvr.src_el.setAttribute("spt_last_message", tmp); bvr.src_el.setAttribute("spt_last_login", login); var msg = ""; msg += "<table style='margin-top: 5px; font-size: 0.9em; width: 100%'><tr><td>"; if (login != last_login) { msg += "<b>"+login+"</b><br/>"; } msg += tmp.replace(/\n/g,'<br/>'); msg += "</td><td style='text-align: right; margin-bottom: 5px; width: 75px; vertical-align: top'>"; msg += timestamp; msg += "</td></tr></table>"; if (msg == history_el.last_msg) { return; } history_el.innerHTML = history_el.innerHTML + msg; // remember last message history_el.last_msg = msg; history_el.scrollTop = history_el.scrollHeight; } spt.message.set_interval(bvr.key, callback, 3000, bvr.src_el); ''' }) text = TextAreaWdg("chat") div.add(text) text.add_class("spt_chat_text") text.add_style("width: 100%") text.add_style("padding: 5px") text.add_style("margin-top: -1px") text.add_behavior({ 'type': 'load', 'cbjs_action': ''' bvr.src_el.addEvent("keydown", function(e) { var keys = ['tab','keys(control+enter)', 'enter']; var key = e.key; var input = bvr.src_el if (keys.indexOf(key) > -1) e.stop(); if (key == 'tab') { } else if (key == 'enter') { if (e.control == false) { pass; } else { // TODO: check if it's multi-line first //... use ctrl-ENTER for new-line, regular ENTER (RETURN) accepts value //var tvals = parse_selected_text(input); //input.value = tvals[0] + "\\n" + tvals[1]; //spt.set_cursor_position( input, tvals[0].length + 1 ); } } } ) ''' }) button = ActionButtonWdg(title="Send") div.add(button) button.add_behavior({ 'type': 'click_up', 'key': key, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_chat_session_top"); var text_el = top.getElement(".spt_chat_text"); var message = text_el.value; if (!message) { return; } var history_el = top.getElement(".spt_chat_history"); var category = "chat"; var server = TacticServerStub.get(); var key = bvr.key; var last_message = server.log_message(key, message, {category:category, status:"in_progress"}); text_el.value = ""; ''' }) return div
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
def get_share_wdg(self): div = DivWdg() div.add_style("padding: 20px") msg = '''<p>Before starting to work on a project that you are sharing, you should import the starting point.</p>''' div.add(msg) button = ActionButtonWdg(title="Import") div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.sync.SyncImportWdg'; var top = bvr.src_el.getParent(".spt_share_top"); var content = top.getElement(".spt_share_content"); spt.panel.load(content, class_name); //spt.panel.load_popup("Sync Import", class_name); ''' } ) msg = '''<p>This allows you to create a share for this project. This will allow you to share this project with others.</p>''' div.add(msg) button = ActionButtonWdg(title="Share") div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.sync.SyncServerAddWdg'; spt.panel.load_popup("Sync Share", class_name); ''' } ) title_wdg = DivWdg() div.add( title_wdg ) title_wdg.add( "Local" ) title_wdg.add_style("padding: 5px") title_wdg.add_color("background", "background", -10) title_wdg.add_border() title_wdg.add_style("margin: 5px -22px 10px -22px") local_code = Config.get_value("install", "server") or "" local_div = DivWdg() div.add(local_div) local_div.add_class("spt_share_item") local_div.add_attr("spt_server_code", local_code) local_div.add_class("hand") local_div.add(local_code) local_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.LocalItemWdg'; var top = bvr.src_el.getParent(".spt_share_top"); var content = top.getElement(".spt_share_content"); spt.panel.load(content, class_name); //spt.panel.load_popup("Sync Import", class_name); ''' } ) div.add("<br/>") search = Search("sthpw/sync_server") shares = search.get_sobjects() title_wdg = DivWdg() div.add( title_wdg ) title_wdg.add( "Share List" ) title_wdg.add_style("padding: 5px") title_wdg.add_color("background", "background", -10) title_wdg.add_border() title_wdg.add_style("margin: 5px -22px 10px -22px") shares_div = DivWdg() div.add(shares_div) shares_div.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_share_item', 'cbjs_action': ''' var server_code = bvr.src_el.getAttribute("spt_server_code"); var class_name = 'tactic.ui.startup.ShareItemWdg'; var kwargs = { server_code: server_code } var top = bvr.src_el.getParent(".spt_share_top"); var content = top.getElement(".spt_share_content"); spt.panel.load(content, class_name, kwargs); ''' } ) bgcolor = shares_div.get_color("background", -5) shares_div.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_share_item', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.bgcolor); ''' } ) shares_div.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_share_item', 'cbjs_action': ''' bvr.src_el.setStyle("background", ""); ''' } ) from pyasm.security import AccessManager access_manager = AccessManager() project = Project.get() project_code = project.get_code() # add in a context menu menu = self.get_context_menu() menus = [menu.get_data()] menus_in = { 'SHARE_ITEM_CTX': menus, } SmartMenu.attach_smart_context_menu( shares_div, menus_in, False ) count = 0 for share in shares: # hide the shares that are not in this project rules = share.get_value("access_rules"); access_manager.add_xml_rules(rules) key1 = { 'code': project_code } key2 = { 'code': '*' } keys = [key1, key2] if not access_manager.check_access("project", keys, "allow", default="deny"): continue share_div = DivWdg() shares_div.add(share_div) share_div.add_class("spt_share_item") share_div.add_attr("spt_server_code", share.get_code()) share_div.add_class("hand") share_div.add(share.get_code()) share_div.add_attr("title", share.get_value("description") ) share_div.add_style("padding: 5px") base_dir = share.get_value("base_dir") if base_dir: base_div = SpanWdg() share_div.add(base_div) base_div.add_style("font-size: 0.9em") base_div.add_style("font-style: italic") base_div.add_style("opacity: 0.5") base_div.add(" (%s)" % base_dir) share_div.add_attr("spt_share_code", share.get_code() ) SmartMenu.assign_as_local_activator( share_div, 'SHARE_ITEM_CTX' ) count += 1 if not count: share_div = DivWdg() shares_div.add(share_div) share_div.add("<i>No shares</i>") share_div.add_style("padding: 5px") return div
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
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
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
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
def get_display(my): top = my.top top.add_class("spt_script_editor_top") """ top.add_class("SPT_CHANGE") top.add_behavior( { 'type': 'load', 'cbjs_action': ''' register_change = function(bvr) { var change_top = bvr.src_el.getParent(".SPT_CHANGE"); change_top.addClass("SPT_HAS_CHANGES"); change_top.update_change(change_top, bvr); } has_changes = function(bvr) { var change_top = bvr.src_el.getParent(".SPT_CHANGE"); return change_top.hasClass("SPT_HAS_CHANGES"); } bvr.src_el.update_change = function(top, bvr) { change_el = top.getElement(".spt_change_element"); change_el.setStyle("display", ""); } ''' } ) """ change_div = DivWdg() top.add(change_div) #change_div.add("CHANGES!!!") change_div.add_style("display: none") change_div.add_class("spt_change_element") top.add_class("spt_panel") top.add_class("spt_js_editor") top.add_attr("spt_class_name", Common.get_full_class_name(my)) top.add_color("background", "background") top.add_style("padding", "10px") div = DivWdg() top.add(div) # if script_path script_path = my.kwargs.get("script_path") search_key = my.kwargs.get("search_key") if script_path: search = Search("config/custom_script") dirname = os.path.dirname(script_path) basename = os.path.basename(script_path) search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() elif search_key: script_sobj = Search.get_by_search_key(search_key) else: script_sobj = None if script_sobj: script_code = script_sobj.get_value("code") script_folder = script_sobj.get_value("folder") script_name = script_sobj.get_value("title") script_value = script_sobj.get_value("script") script_language = script_sobj.get_value("language") else: script_code = '' script_folder = '' script_name = '' script_value = '' editor = AceEditorWdg(custom_script=script_sobj) my.editor_id = editor.get_editor_id() if not Container.get_dict("JSLibraries", "spt_script_editor"): div.add_behavior({ 'type': 'load', 'cbjs_action': my.get_onload_js() }) # create the insert button help_button_wdg = DivWdg() div.add(help_button_wdg) help_button_wdg.add_style("float: right") help_button = ActionButtonWdg(title="?", tip="Script Editor Help", size='s') help_button_wdg.add(help_button) help_button.add_behavior({ 'type': 'click_up', 'cbjs_action': '''spt.help.load_alias("tactic-script-editor")''' }) # create the insert button add_button_wdg = DivWdg() add_button_wdg.add_style("float: right") add_button = ActionButtonWdg(title="Manage") add_button.add_behavior({ 'type': 'click_up', 'cbfn_action': 'spt.popup.get_widget', 'options': { 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'title': 'Manage: [%s]' % my.search_type }, 'args': { 'search_type': my.search_type, 'view': 'table', 'show_shelf': False, 'element_names': ['folder', 'title', 'description', 'language'], }, }) add_button_wdg.add(add_button) div.add(add_button_wdg) button_div = editor.get_buttons_wdg() div.add(button_div) """ button_div = DivWdg() #div.add(button_div) button_div.add_style("text-align: left") button = ActionButtonWdg(title="Run") button.add_style("float: left") button.add_style("margin: 0 10 3") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' //var editor = $('shelf_script'); var value = editAreaLoader.getValue('shelf_script') eval( value ) ''' } ) button_div.add(button) button = ActionButtonWdg(title="Save") button.add_style("float: left") button.add_style("margin: 0 10 3") #button = ProdIconButtonWdg("Save") #button.add_style("margin: 5 10") behavior = { 'type': 'click_up', 'cbfn_action': 'spt.script_editor.save_script_cbk' } button.add_behavior(behavior) button_div.add(button) button = ActionButtonWdg(title="Clear") button.add_style("float: left") button.add_style("margin: 0 10 3") #button = ProdIconButtonWdg("Clear") #button.add_style("margin: 5 10") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') ); editAreaLoader.setValue('shelf_script', ''); ''' } ) button_div.add(button) """ div.add("<br clear='all'/><br/>") save_wdg = DivWdg() div.add(save_wdg) save_wdg.add_style("padding: 2px 5px 6px 5px") #save_wdg.add_color("background", "background", -5) # script code save_span = Table() save_wdg.add(save_span) save_span.add_row() code_span = SpanWdg() code_span.add("<b>Code: </b>") td = save_span.add_cell(code_span) td.add_style("display: none") code_text = TextInputWdg(name="shelf_code") code_text.add_style("display: inline") code_text.add_style("width: 100px") code_text.set_value(script_code) code_text.add_attr("readonly", "true") code_text.set_id("shelf_code") code_text.add_class("spt_code") td = save_span.add_cell(code_text) td.add_style("padding-top: 10px") td.add_style("display: none") save_span.add_cell(" ") # script name (path??) td = save_span.add_cell("<b>Script Path: </b>") td.add_style("padding-top: 10px") save_text = TextInputWdg(name="shelf_folder") save_text.add_style("width: 250px") save_text.set_id("shelf_folder") save_text.add_class("spt_folder") save_text.set_value(script_folder) td = save_span.add_cell(save_text) td.add_style("padding-top: 10px") td = save_span.add_cell(" / ") td.add_style("padding-top: 10px") td.add_style("font-size: 1.5em") save_text = TextInputWdg(name="shelf_title") save_text.add_style("width: 350px") save_text.add_attr("size", "40") save_text.set_id("shelf_title") save_text.add_class("spt_title") save_text.set_value(script_name) td = save_span.add_cell(save_text) td.add_style("padding-top: 10px") from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() table.add_row() td = table.add_cell(resize=False) td.add_style("vertical-align: top") td.add(editor) text = TextAreaWdg("shelf_script") td = table.add_cell() td.add_style('vertical-align: top') td.add(my.get_script_wdg()) table.add_row(resize=False) div.add(table) if my.kwargs.get("is_refresh"): return div else: return top
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: submit_title = my.kwargs.get("submit_title") command = my.kwargs.get("command") script = my.kwargs.get("script") jsscript = my.kwargs.get("jsscript") if not submit_title: submit_title = "Submit" submit = ActionButtonWdg(title="%s >>" % submit_title, tip=submit_title) 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
def get_display(self): # if no filters are defined, then display nothing if not self.filters: return Widget() top = self.top top.add_class("spt_search_top") filter_top = DivWdg() top.add(filter_top) filter_top.add_color("color", "color") filter_top.add_color("background", "background", -5) filter_top.add_style("padding: 5px") filter_top.add_style("min-width: 800px") filter_top.add_border() self.set_as_panel(filter_top) # TEST link to help for search widget help_button = ActionButtonWdg(title="?", tip="Search Documentation", size='small') filter_top.add(help_button) help_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_alias("search-quickstart|what-is-searching|search-interface|search-compound|search-expressions"); ''' } ) help_button.add_style("float: right") # this id should be removed filter_top.set_id("%s_search" % self.prefix) filter_top.add_class("spt_search") for name, value in self.kwargs.items(): filter_top.set_attr("spt_%s" % name, value) display = self.kwargs.get('display') # Add a number of filters indicator div = DivWdg() div.add_class("spt_search_num_filters") div.add_style("float: right") div.add_style("font-size: 0.9em") div.add_style("margin: 0 10 0 10") #search_summary.add(div) filter_top.add(div) if self.num_filters_enabled: msg = "[%s] filter/s" % self.num_filters_enabled icon = IconWdg(msg, IconWdg.DOT_GREEN) div.add(icon) div.add("%s" % msg) filter_div = DivWdg() filter_div.set_id("search_filters") filter_div.add_class("spt_search_filters") # TODO: disabling for now # add the action buttons #action_wdg = self.get_action_wdg() #action_wdg.add_style("text-align: right") #filter_div.add( action_wdg ) # add the top display_str = 'block' if not display: display_str = 'none' filter_div.add_style("display: %s" % display_str) search_wdg = self.get_search_wdg() prefix = "filter_mode" if self.prefix_namespace: prefix = '%s_%s' %(self.prefix_namespace, prefix) hidden = HiddenWdg("prefix", prefix) match_div = DivWdg() match_div.add(hidden) match_div.add_class('spt_search_filter') palette = match_div.get_palette() bg_color = palette.color('background') light_bg_color = palette.color('background', modifier=+10) select = SelectWdg("filter_mode") select.add_style("width: 110px") select.add_class("spt_search_filter_mode") select.set_persist_on_submit(prefix) select.remove_empty_option() # for Local search, leave out compound search for now if self.kwargs.get('prefix_namespace'): select.set_option("labels", "Match all|Match any") select.set_option("values", "and|or") else: select.set_option("labels", "Match all|Match any|Compound") select.set_option("values", "and|or|custom") #select.set_option("labels", "all|any") #select.set_option("values", "and|or") select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var display = bvr.src_el.value == 'custom';; var top = bvr.src_el.getParent(".spt_search"); var ops = top.getElements(".spt_op"); for (var i = 0; i < ops.length; i++) { var op = ops[i]; var element = op.getElement(".spt_op_display"); var value = op.getAttribute("spt_op"); if (display) { element.innerHTML = value; var level = op.getAttribute("spt_level"); if (level == 1) { element.setStyle("background", "%s") element.setStyle("padding", "4px") } } else { element.innerHTML = ' '; element.setStyle("background", "%s") element.setStyle("padding", "1px") } } ''' %(light_bg_color, bg_color) } ) match_div.add(select) match_div.add_color("color", "color2") #match_div.add(" on the following") #hint = HintWdg( "An 'AND' operation is always applied to each category below. " \ # "This controls only the filters within each category." ) #match_div.add(hint) #match_div.add('<br/>') #match_div.add_style("padding-top: 5px") filter_div.add( search_wdg) search_wdg.add_style("float: left") filter_div.add( match_div) filter_div.add(HtmlElement.br()) filters_div = DivWdg() filters_div.add_style("margin: 0 -6 0 -6") security = Environment.get_security() # add all the filters for filter in self.filters: element_name = filter.get_name() if not security.check_access("search", element_name, "view"): continue # no need to create it again #filter = self.config.get_display_widget(element_name) div = DivWdg() filters_div.add(div) div.add_class("hand") class_suffix = element_name.replace(' ', '_') cbjs_action = 'var el=spt.get_cousin(bvr.src_el,".spt_search",".spt_filter_%s");spt.simple_display_toggle(el);' % class_suffix div.add_behavior( { 'type': 'click_up', 'cbjs_action': cbjs_action } ) div.add_color("color", "color", +5) #div.add_gradient("background", "background", -5, -5) div.add_style("margin-top: -1px") div.add_style("height: 18px") div.add_border() div.add_style("padding: 8px 5px") div.add_style("white-space: nowrap") if element_name in ["Parent", 'Children']: swap = SwapDisplayWdg.get_triangle_wdg() else: swap = SwapDisplayWdg.get_triangle_wdg() swap.set_off() swap.add_action_script(cbjs_action) div.add_event("onclick", swap.get_swap_script() ) div.add(swap) div.add_class("SPT_DTS") div.add(element_name) div = DivWdg() div.add_class("spt_filter_%s" % class_suffix) if element_name in ["Parent", 'Children']: div.add_style("display: none") else: div.add_style("display: block") #div.add_style("background-color: #333") div.add_color("background", "background") div.add_border() div.add_style("padding: 10px 8px") div.add_style("margin-top: -1px") #div.add_style("margin-left: 20px") #div.add_style("width: 660") div.add(filter) filters_div.add(div) filter_div.add(filters_div) buttons_div = DivWdg() buttons_div.add_style("margin-top: 7px") buttons_div.add_style("margin-bottom: 7px") search_wdg = self.get_search_wdg() search_wdg.add_style("margin: 15px auto") buttons_div.add(search_wdg) filter_div.add(buttons_div) filter_top.add(filter_div) if self.kwargs.get("is_refresh"): return filter_top else: return top
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
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(" - %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(" - %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_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
def get_display(my): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_gradient("background", "background", 0, -5) #top.add_style("height: 550px") #top.add_behavior( { # 'type': 'load', # 'cbjs_action': ''' # spt.named_events.fire_event("side_bar|hide_now", {} ); # ''' #} ) project = Project.get() title = TitleWdg(title='Tools') top.add(title) shelf = DivWdg() top.add(shelf) shelf.add_style("margin-left: -8px") shelf.add_style("width: 130px") button_div = DivWdg() shelf.add(button_div) button_div.add_style("float: left") button_div.add_style("margin-top: -3px") """ security = Environment.get_security() view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow') if view_side_bar: button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT) button_div.add(button) shelf.add("Toggle Side Bar") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' } ) shelf.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' } ) shelf.add_class("hand") else: shelf.add(" ") """ search_wdg = DivWdg() search_wdg.add_class("spt_main_top") top.add(search_wdg) search_wdg.add_style("padding: 10px") search_wdg.add_style("margin: 10px auto") search_wdg.add_style("width: 430px") search_wdg.add("Search: ") search_wdg.add(" " * 3) custom_cbk = {} custom_cbk['enter'] = ''' var top = bvr.src_el.getParent(".spt_main_top"); var search_el = top.getElement(".spt_main_search"); var keywords = search_el.value; if (keywords != '') { var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': 'sthpw/sobject_list', 'view': 'table', 'keywords': keywords, 'simple_search_view': 'simple_search', //'show_shelf': false, } spt.tab.set_main_body_tab(); spt.tab.add_new("Search Results", "Search Results", class_name, kwargs); } ''' from tactic.ui.input import TextInputWdg, LookAheadTextInputWdg #text = TextInputWdg(name="search") text = LookAheadTextInputWdg(name="search", custom_cbk=custom_cbk) #text = TextWdg("search") text.add_class("spt_main_search") text.add_style("width: 290px") search_wdg.add(text) search_wdg.add_style("font-weight: bold") search_wdg.add_style("font-size: 16px") button = ActionButtonWdg(title="Search") #search_wdg.add(button) button.add_style("float: right") #button.add_style("margin-top: -28px") icon_div = DivWdg() search_wdg.add(icon_div) icon_div.add_style("width: 38px") icon_div.add_style("height: 27px") icon_div.add_style("padding-top: 3px") icon_div.add_style("padding-left: 4px") icon_div.add_style("text-align: center") #icon_div.add_gradient("background", "background3", 15, -10) icon_div.add_color("background", "background3", 10) over_color = icon_div.get_color("background3", 0) out_color = icon_div.get_color("background3", 10) icon_div.set_round_corners(5) icon_div.set_box_shadow("1px 1px 1px 1px") icon = IconWdg("Search", IconWdg.SEARCH_32, width=24) icon_div.add(icon) icon_div.add_style("float: right") icon_div.add_style("margin-top: -5px") button = icon_div icon_div.add_class("hand") icon_div.add_behavior({ 'type': 'mouseover', 'color': over_color, 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.color); ''' }) icon_div.add_behavior({ 'type': 'mouseout', 'color': out_color, 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.color); bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999"); bvr.src_el.setStyle("margin-top", "-5"); bvr.src_el.setStyle("margin-right", "0"); ''' }) icon_div.add_behavior({ 'type': 'click', 'color': out_color, 'cbjs_action': ''' bvr.src_el.setStyle("box-shadow", "0px 0px 1px 1px #999"); bvr.src_el.setStyle("margin-top", "-3"); bvr.src_el.setStyle("margin-right", "-2"); ''' }) icon_div.add_behavior({ 'type': 'click_up', 'color': out_color, 'cbjs_action': ''' bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999"); bvr.src_el.setStyle("margin-top", "-5"); bvr.src_el.setStyle("margin-right", "0"); ''' }) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_main_top"); var search_el = top.getElement(".spt_main_search"); var keywords = search_el.value; if (keywords == '') { return; } var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': 'sthpw/sobject_list', 'view': 'table', 'keywords': keywords, 'simple_search_view': 'simple_search', //'show_shelf': false, } spt.tab.set_main_body_tab(); spt.tab.add_new("Search Results", "Search Results", class_name, kwargs); ''' }) #desc = DivWdg() #top.add(desc) #desc.add("Dashboard") #desc.add_style("width: 600px") # create a bunch of panels table = Table() table.add_color("color", "color") table.add_style("margin-bottom: 20px") table.center() top.add(table) table.add_row() td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Themes" image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''Themes define the look and feel of a project.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.themes_wdg.ThemesWdg'; var kwargs = { help_alias: 'project-startup-dashboards' }; spt.tab.set_main_body_tab(); spt.tab.add_new("themes", "Themes", class_name, kwargs); ''' } dashboard_wdg = my.get_section_wdg(title, description, image, behavior) td.add(dashboard_wdg) td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Dashboards" image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''Dashboards display key project data in single views. Drill down further to work on tasks, make status changes or add notes.''' # read the config file #from pyasm.widget import WidgetConfig #tmp_path = __file__ #dir_name = os.path.dirname(tmp_path) #file_path="%s/../config/dashboard-conf.xml" % (dir_name) #config = WidgetConfig.get(file_path=file_path, view="definition") # FIXME: this bypasses the link security #element_name = "dashboards" #attrs = config.get_element_attributes(element_name) #dashboard_data = {} #kwargs = config.get_display_options(element_name) #class_name = kwargs.get('class_name') behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.dashboards_wdg.DashboardsWdg'; var kwargs = { help_alias: 'project-startup-dashboards' }; spt.tab.set_main_body_tab(); spt.tab.add_new("dashboards", "Dashboards", class_name, kwargs); ''' } dashboard_wdg = my.get_section_wdg(title, description, image, behavior) td.add(dashboard_wdg) td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "Reports" image = "<img src='/context/icons/64x64/report_64.png'/>" description = '''TACTIC provides a number of predefined reports that project managers can access instantly to get real-time analytics.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.reports_wdg.ReportsWdg'; var kwargs = {}; spt.tab.set_main_body_tab(); spt.tab.add_new("reports", "Reports", class_name, kwargs); //spt.panel.load_popup("Reports", class_name, kwargs); ''' } side_bar_wdg = my.get_section_wdg(title, description, image, behavior) td.add(side_bar_wdg) td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "Lists of Items" description = '''View all of the lists items for this project<br/><br/> ''' image = "<img src='/context/icons/48x48/search_type_48.png'/>" #image = "<img src='/context/images/getting_started_pipeline.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.startup.HomeWdg'; var kwargs = {}; spt.tab.add_new("lists", "Lists", class_name, kwargs); ''' } config_wdg = my.get_section_wdg(title, description, image, behavior) td.add(config_wdg) tr, td = table.add_row_cell() td.add_style("font-size: 14px") td.add("<br/>" * 2) quick_links_wdg = QuickLinksWdg() td.add(quick_links_wdg) return top
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
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
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
def get_import_wdg(self): div = DivWdg() if self.data: div.add("<br/>" * 2) div.add("The following TACTIC share was found: ") div.add("<br/>" * 2) data_input = TextAreaWdg("data") data_input.add_style("display: none") div.add(data_input) #print "xxxx: ", self.data data_str = jsondumps(self.data) #data_str = data_str.replace('"', "'") print "data: ", data_str data_input.set_value(data_str) table = Table() div.add(table) table.set_max_width() table.add_style("margin-left: 20px") table.add_style("margin-right: 20px") for name, value in self.data.items(): name = Common.get_display_title(name) table.add_row() table.add_cell(name) table.add_cell(value) div.add("<br/>" * 2) div.add(self.get_versions_wdg()) div.add("<br/>" * 2) # check to see if the project exists project_code = self.data.get("project_code") project_code = self.data.get("projects") project = Project.get_by_code(project_code) #if project: if False: msg_div = DivWdg() div.add(msg_div) msg_div.add_style("padding: 20px") msg_div.add_color("background", "background3") msg_div.add_color("color", "color") msg_div.add_border() icon = IconWdg("WARNING", IconWdg.WARNING) msg_div.add(icon) icon.add_style("float: left") msg_div.add( "The project with code [%s] already exists. You must remove the installed project before trying to import this one." % project_code) return div if self.data.get("is_encrypted") == "true": div.add( "The transactions in this share is encrypted. Please provide an encryption key to decrypt the transactions<br/><br/>" ) div.add("Encryption Key: ") text = TextWdg("encryption_key") div.add(text) div.add("<br/>" * 2) button = ActionButtonWdg(title="Import >>") button.add_style("float: right") div.add(button) div.add("<br/>" * 2) button.add_behavior({ 'type': 'click_up', 'project_code': project_code, 'cbjs_action': ''' spt.app_busy.show("Importing Project "+bvr.project_code+"..."); var top = bvr.src_el.getParent(".spt_sync_import_top"); var values = spt.api.Utility.get_input_values(top, null, false); var cmd = "tactic.ui.sync.SyncImportCmd"; var server = TacticServerStub.get(); server.execute_cmd(cmd, values, {}, {use_transaction: false}); spt.notify.show_message("Finished importing project"); spt.app_busy.hide(); document.location = '/tactic/'+bvr.project_code; ''' }) return div
def get_action_html(my): search_key = SearchKey.get_by_sobject(my.sobjects[0], use_id=True) search_type = my.sobjects[0].get_base_search_type() div = DivWdg(css='centered') # construct the bvr element_names = my.element_names[:] for element_name in my.skipped_element_names: element_names.remove(element_name) bvr = { 'type': 'click_up', 'mode': my.mode, 'element_names': element_names, 'search_key': search_key, 'input_prefix': my.input_prefix, 'view': my.view } if my.mode == 'insert': bvr['refresh'] = 'true' # for adding parent relationship in EditCmd if my.parent_key: bvr['parent_key'] = my.parent_key hidden_div = DivWdg() hidden_div.add_style("display: none") div.add(hidden_div) hidden = TextAreaWdg("__data__") hidden_div.add(hidden) hidden.set_value( jsondumps(bvr) ) show_action = my.kwargs.get("show_action") if show_action in [False, 'false']: return div div.add_styles('height: 35px; margin-top: 5px;') div.add_named_listener('close_EditWdg', ''' var popup = spt.popup.get_popup( $('edit_popup') ); if (popup != null) { spt.popup.destroy(popup); } ''') # custom callbacks cbjs_cancel = my.kwargs.get('cbjs_cancel') if not cbjs_cancel: cbjs_cancel = ''' spt.named_events.fire_event('preclose_edit_popup', {}); spt.named_events.fire_event('close_EditWdg', {}) ''' # custom callbacks cbjs_insert_path = my.kwargs.get('cbjs_%s_path' % my.mode) cbjs_insert = None if cbjs_insert_path: script_obj = CustomScript.get_by_path(cbjs_insert_path) if script_obj: cbjs_insert = script_obj.get_value("script") # get it inline if not cbjs_insert: cbjs_insert = my.kwargs.get('cbjs_%s' % my.mode) # use a default if not cbjs_insert: mode_label = my.mode.capitalize() cbjs_insert = ''' spt.app_busy.show("%sing items", ""); spt.edit.edit_form_cbk(evt, bvr); spt.app_busy.hide(); '''%mode_label save_event = my.kwargs.get('save_event') if not save_event: save_event = div.get_unique_event("save") bvr['save_event'] = save_event bvr['named_event'] = 'edit_pressed' bvr['cbjs_action'] = cbjs_insert ok_btn_label = my.mode.capitalize() if ok_btn_label == 'Edit': ok_btn_label = 'Save' if ok_btn_label == 'Insert': ok_btn_label = 'Add' if my.kwargs.get('ok_btn_label'): ok_btn_label = my.kwargs.get('ok_btn_label') ok_btn_tip = ok_btn_label if my.kwargs.get('ok_btn_tip'): ok_btn_tip = my.kwargs.get('ok_btn_tip') cancel_btn_label = 'Cancel' if my.kwargs.get('cancel_btn_label'): cancel_btn_label = my.kwargs.get('cancel_btn_label') cancel_btn_tip = cancel_btn_label if my.kwargs.get('cancel_btn_tip'): cancel_btn_tip = my.kwargs.get('cancel_btn_tip') # create the buttons insert_button = ActionButtonWdg(title=ok_btn_label, tip=ok_btn_tip) insert_button.add_behavior(bvr) cancel_button = ActionButtonWdg(title=cancel_btn_label, tip=cancel_btn_tip) cancel_button.add_behavior({ 'type': 'click_up', 'cbjs_action': cbjs_cancel }) table = Table() table.add_style("margin-left: auto") table.add_style("margin-right: auto") table.add_style("margin-top: 15px") table.add_style("margin-bottom: 15px") table.add_row() table.add_cell(insert_button) table.add_cell(cancel_button) div.add(table) #div.add(SpanWdg(edit, css='med')) #div.add(SpanWdg(edit_close, css='med')) #div.add(SpanWdg(cancel, css='med')) return div
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
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
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
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(" - %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(" - %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_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
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
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
def get_base_dir_wdg(self): div = DivWdg() title = DivWdg() div.add(title) title.add("Sync Project Import: ") title.add_style("font-size: 14px") title.add_style("font-weight: bold") div.add("<br/>") base_dir = self.kwargs.get("base_dir") is_local = False if is_local: button = ActionButtonWdg(title="Browse") div.add(button) button.add_style("float: right") button.add_style("margin-top: -5px") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var applet = spt.Applet.get(); var files = applet.open_file_browser(); if (!files.length) { return; } var file = files[0]; var top = bvr.src_el.getParent(".spt_sync_import_top"); var el = top.getElement(".spt_sync_base_dir"); el.value = file; ''' }) div.add("Share Location: ") text = TextInputWdg(name="base_dir") div.add(text) text.add_class("spt_sync_base_dir") text.add_style("width: 300px") if base_dir: text.set_value(base_dir) text.add_behavior({ 'type': 'blur', 'is_local': is_local, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_sync_import_top"); var applet = spt.Applet.get(); var value = bvr.src_el.value; var manifest_path = value + "/tactic.txt"; if (!value) { return; } if (bvr.is_local) { if (!applet.exists(value)) { alert('Share folder does not exist.'); return; } if (!applet.exists(manifest_path)) { alert('Cannot find manifest file.'); return; } var data = applet.read_file(manifest_path); var json = JSON.parse(data); data = JSON.stringify(json); top.setAttribute("spt_data", data) } top.setAttribute("spt_base_dir", value) spt.panel.refresh(top); ''' }) return div
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
def get_new_custom_widget(my, search_type, view): div = DivWdg() div.add_style('width: 500px') mode_select = SelectWdg("custom_mode") mode_select.add_class("spt_custom_mode") mode_select.set_option("values", "simple|xml") mode_select.set_option("labels", "Simple|XML") mode_select.add_class("spt_input") behavior = { 'type': 'change', 'cbfn_action': 'spt.custom_property_adder.switch_property_mode' } mode_select.add_behavior(behavior) div.add("Mode: ") div.add(mode_select) div.add("<br/><br/>") custom_table = Table() custom_table.add_color("color", "color") custom_table.set_max_width() mode = "simple" my.handle_simple_mode(custom_table, mode) #my.handle_widget_mode(custom_table, mode) my.handle_xml_mode(custom_table, mode) div.add(custom_table) div.add("<br/>") custom_table = Table() custom_table.center() custom_table.add_row() from tactic.ui.widget import ActionButtonWdg submit = ActionButtonWdg(title="Add/Next") behavior = { 'type': 'click', 'mouse_btn': 'LMB', 'cbfn_action': 'spt.custom_property_adder.add_property_cbk', 'search_type': my.search_type, 'view': view } submit.add_behavior(behavior) td = custom_table.add_cell(submit) behavior['exit'] = 'true' submit_exit = ActionButtonWdg(title="Add/Exit") submit_exit.add_behavior(behavior) custom_table.add_cell(submit_exit) cancel = ActionButtonWdg(title="Cancel") behavior = { 'type': 'click_up', 'cbjs_action': "spt.popup.close('New Table Column')" } cancel.add_behavior(behavior) custom_table.add_cell(cancel) div.add(custom_table) return div
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
def get_display(self): div = DivWdg() div.add_class("spt_security") div.add_attr("id", "SecurityManagerWdg") div.add_attr("spt_class_name", Common.get_full_class_name(self) ) div.add_attr("spt_search_key", self.search_key) div.add_attr("spt_update", "true") project_div = DivWdg() project_div.add_color("background", "background") project_div.add_color("color", "color") project_div.add_style("padding: 10px") project_div.add_border() project_div.add_style("width: 300px") group = SearchKey.get_by_search_key(self.search_key) title = DivWdg() title.add_class("maq_search_bar") name = group.get_value("login_group") title.add("Global security settings for %s" % name) project_div.add(title) access_rules = group.get_xml_value("access_rules") access_manager = AccessManager() access_manager.add_xml_rules(access_rules) access_level = group.get_access_level() project_code = group.get_value('project_code') if project_code: project_codes = set(project_code) else: project_codes = set() xml = LoginGroup.get_default_access_rule(access_level, project_codes) access_manager.add_xml_rules(xml) group = "builtin" global_default_access = "deny" list_div = DivWdg() list_div.add_style("color: #222") for item in permission_list: if item.get('group'): group_div = DivWdg() list_div.add(group_div) group_div.add_style("margin-top: 10px") group_div.add_style("font-weight: bold") group_div.add(item.get('group')) group_div.add("<hr/>") continue item_div = DivWdg() list_div.add(item_div) item_div.add_style("margin-top: 5px") key = item.get('key') item_default = item.get('default') if item_default: default_access = item_default else: default_access = global_default_access allowed = access_manager.check_access(group, key, "allow", default=default_access) checkbox = CheckboxWdg("rule") if allowed: checkbox.set_checked() checkbox.set_option("value", key) item_div.add(checkbox) item_div.add_style("color: #222") item_div.add(item.get('title') ) project_div.add(list_div) project_div.add("<hr>") #close_script = "spt.popup.close(bvr.src_el.getParent('.spt_popup'))" save_button = ActionButtonWdg(title="Save", tip="Save Security Settings") save_button.add_behavior( { "type": "click_up", "cbjs_action": "el=bvr.src_el.getParent('.spt_security');spt.panel.refresh(el);" } ) save_button.add_style("margin-left: auto") save_button.add_style("margin-right: auto") project_div.add(save_button) div.add(project_div) if self.update == "true": div.add(HtmlElement.br()) div.add(HtmlElement.b(self.description)) return div
def get_display(my): top = my.top my.set_as_panel(top) top.add_class("spt_checkin_dependency_top") top.add_color("background", "background") top.add_color("color", "color") top.add_style("width: 800px") title = DivWdg() top.add(title) title.add("Current Dependencies") title.add_color("color", "color3") title.add_color("background", "background3") title.add_style("font-size: 1.2em") title.add_style("font-weight: bold") title.add_style("padding: 10px 10px") # Not sure what to do with this yet search_key = my.kwargs.get("search_key") search_key = None snapshot_key = my.kwargs.get("snapshot_key") process = my.kwargs.get("process") if not process: process = "publish" if snapshot_key: snapshot = Search.get_by_search_key(snapshot_key) elif search_key: sobject = Search.get_by_search_key(search_key) snapshot = Snapshot.get_latest_by_sobject(sobject, process=process) else: snapshot = None #context = my.kwargs.get("context") #context = "publish/X6.tex" from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Browse") button.add_style("float: left") top.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var applet = spt.Applet.get(); var files = applet.open_file_browser(); alert(files); ''' }) from tactic.ui.widget import ActionButtonWdg button = ActionButtonWdg(title="Clipboard") button.add_style("float: left") top.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': r''' var server = TacticServerStub.get(); var items = server.eval("@SOBJECT(sthpw/clipboard['category','select']['login',$LOGIN])") var search_keys = spt.table.get_all_search_keys(); for (var i = 0; i < items.length; i++) { var item = items[i]; var search_key = item.search_type + "&code=" + item.search_code; search_keys.push(search_key); } var top = bvr.src_el.getParent(".spt_checkin_dependency_top"); top.setAttribute("spt_snapshot_keys", search_keys.join("|")) spt.panel.refresh(top); spt.tab.set_tab_top_from_child(bvr.src_el); var content = spt.tab.get_content("Dependency"); var activator = content.activator; activator.setAttribute("spt_depend_keys", search_keys.join("|")); ''' }) button = ActionButtonWdg(title="Remove") button.add_style("float: left") top.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_checkin_dependency_top"); var layout = top.getElement(".spt_layout"); spt.table.set_layout(layout); spt.table.remove_selected(); var search_keys = spt.table.get_all_search_keys(); alert(search_keys); spt.tab.set_tab_top_from_child(bvr.src_el); var content = spt.tab.get_content("Dependency"); var activator = content.activator; activator.setAttribute("spt_depend_keys", search_keys.join("|")); activator.setStyle("border", "solid 1px green"); ''' }) """ button = ActionButtonWdg(title="Attach") button.add_style("float: left") top.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_checkin_dependency_top"); var layout = top.getElement(".spt_layout"); spt.table.set_layout(layout); var search_keys = spt.table.get_selected_search_keys(); ''' } ) """ top.add("<br clear='all'/>") sobject_wdg = DivWdg() top.add(sobject_wdg) #text = TextInputWdg("search_type") #sobject_wdg.add(text) depend_keys = my.kwargs.get("depend_keys") print "depend_keys: ", depend_keys if isinstance(depend_keys, basestring): depend_keys = depend_keys.split("|") if depend_keys: ref_snapshots = Search.get_by_search_keys(depend_keys) elif snapshot: # get the already existing snapshots ref_snapshots = snapshot.get_all_ref_snapshots(snapshot) else: ref_snapshots = [] snapshot_keys = my.kwargs.get("snapshot_keys") if snapshot_keys: snapshot_keys = snapshot_keys.split("|") extra_snapshots = Search.get_by_search_keys(snapshot_keys) for extra_snapshot in extra_snapshots: extra_snapshot = Snapshot.get_latest_by_sobject( extra_snapshot, process=process) if extra_snapshot: ref_snapshots.append(extra_snapshot) if not ref_snapshots: return top print "ref: ", ref_snapshots search_type = "jobs/media" search_type = "sthpw/snapshot" from tactic.ui.panel import ViewPanelWdg panel = ViewPanelWdg( search_type=search_type, show_shelf=False, ) #layout='tile', panel.set_sobjects(ref_snapshots) top.add(panel) return top
def get_display(my): top = my.top top.add_class("spt_script_editor_top") """ top.add_class("SPT_CHANGE") top.add_behavior( { 'type': 'load', 'cbjs_action': ''' register_change = function(bvr) { var change_top = bvr.src_el.getParent(".SPT_CHANGE"); change_top.addClass("SPT_HAS_CHANGES"); change_top.update_change(change_top, bvr); } has_changes = function(bvr) { var change_top = bvr.src_el.getParent(".SPT_CHANGE"); return change_top.hasClass("SPT_HAS_CHANGES"); } bvr.src_el.update_change = function(top, bvr) { change_el = top.getElement(".spt_change_element"); change_el.setStyle("display", ""); } ''' } ) """ change_div = DivWdg() top.add(change_div) #change_div.add("CHANGES!!!") change_div.add_style("display: none") change_div.add_class("spt_change_element") top.add_class("spt_panel") top.add_class("spt_js_editor") top.add_attr("spt_class_name", Common.get_full_class_name(my)) top.add_color("background", "background") top.add_style("padding", "10px") div = DivWdg() top.add(div) # if script_path script_path = my.kwargs.get("script_path") search_key = my.kwargs.get("search_key") if script_path: search = Search("config/custom_script") dirname = os.path.dirname(script_path) basename = os.path.basename(script_path) search.add_filter("folder", dirname) search.add_filter("title", basename) script_sobj = search.get_sobject() elif search_key: script_sobj = Search.get_by_search_key(search_key) else: script_sobj = None if script_sobj: script_code = script_sobj.get_value("code") script_folder = script_sobj.get_value("folder") script_name = script_sobj.get_value("title") script_value = script_sobj.get_value("script") script_language = script_sobj.get_value("langauge") else: script_code = '' script_folder = '' script_name = '' script_value = '' editor = AceEditorWdg(custom_script=script_sobj) my.editor_id = editor.get_editor_id() if not Container.get_dict("JSLibraries", "spt_script_editor"): div.add_behavior({ 'type': 'load', 'cbjs_action': my.get_onload_js() }) # create the insert button help_button_wdg = DivWdg() div.add(help_button_wdg) help_button_wdg.add_style("float: right") help_button = ActionButtonWdg(title="?", tip="Script Editor Help", size='s') help_button_wdg.add(help_button) help_button.add_behavior({ 'type': 'click_up', 'cbjs_action': '''spt.help.load_alias("tactic-script-editor")''' }) # create the insert button add_button_wdg = DivWdg() add_button_wdg.add_style("float: right") add_button = ActionButtonWdg(title="Manage") add_button.add_behavior({ 'type': 'click_up', 'cbfn_action': 'spt.popup.get_widget', 'options': { 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'title': 'Manage: [%s]' % my.search_type }, 'args': { 'search_type': my.search_type, 'view': 'table' }, }) add_button_wdg.add(add_button) div.add(add_button_wdg) button_div = editor.get_buttons_wdg() div.add(button_div) """ button_div = DivWdg() #div.add(button_div) button_div.add_style("text-align: left") button = ActionButtonWdg(title="Run") button.add_style("float: left") button.add_style("margin: 0 10 3") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' //var editor = $('shelf_script'); var value = editAreaLoader.getValue('shelf_script') eval( value ) ''' } ) button_div.add(button) button = ActionButtonWdg(title="Save") button.add_style("float: left") button.add_style("margin: 0 10 3") #button = ProdIconButtonWdg("Save") #button.add_style("margin: 5 10") behavior = { 'type': 'click_up', 'cbfn_action': 'spt.script_editor.save_script_cbk' } button.add_behavior(behavior) button_div.add(button) button = ActionButtonWdg(title="Clear") button.add_style("float: left") button.add_style("margin: 0 10 3") #button = ProdIconButtonWdg("Clear") #button.add_style("margin: 5 10") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.api.Utility.clear_inputs( bvr.src_el.getParent('.spt_js_editor') ); editAreaLoader.setValue('shelf_script', ''); ''' } ) button_div.add(button) """ div.add("<br clear='all'/><br/>") save_wdg = DivWdg() div.add(save_wdg) save_wdg.add_style("padding: 2px 5px 6px 5px") #save_wdg.add_color("background", "background", -5) # script code save_span = Table() save_wdg.add(save_span) save_span.add_row() code_span = SpanWdg() code_span.add("<b>Code: </b>") save_span.add_cell(code_span) code_text = TextInputWdg(name="shelf_code") code_text.add_style("display: inline") code_text.add_style("width: 100px") code_text.set_value(script_code) code_text.add_attr("readonly", "true") code_text.set_id("shelf_code") code_text.add_class("spt_code") td = save_span.add_cell(code_text) td.add_style("padding-top: 10px") save_span.add_cell(" ") # script name (path??) save_span.add_cell("<b>Script Path: </b>") save_text = TextInputWdg(name="shelf_folder") save_text.add_style("width: 120px") save_text.add_attr("size", "40") save_text.set_id("shelf_folder") save_text.add_class("spt_folder") save_text.set_value(script_folder) td = save_span.add_cell(save_text) td.add_style("padding-top: 10px") save_span.add_cell(" / ") save_text = TextInputWdg(name="shelf_title") save_text.add_style("width: 350px") save_text.add_attr("size", "40") save_text.set_id("shelf_title") save_text.add_class("spt_title") save_text.set_value(script_name) td = save_span.add_cell(save_text) td.add_style("padding-top: 10px") from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() table.add_row() td = table.add_cell(resize=False) td.add_style("vertical-align: top") td.add(editor) text = TextAreaWdg("shelf_script") #text.add_behavior( { # 'type': 'double_click', # 'cbjs_action': ''' # var text = $('shelf_script'); # editor(text) # ''' # } ) """ text.set_id("shelf_script") text.add_style("width: 550px") text.add_style("height: 300px") text.add_class("codepress") text.add_class("html") text.add_behavior( { 'type': 'load', 'cbjs_action': ''' editAreaLoader.init({ id: "shelf_script", // id of the textarea to transform start_highlight: true, // if start with highlight allow_resize: "both", allow_toggle: true, word_wrap: true, language: "en", syntax: "js", // need to make this setable replace_tab_by_spaces: "4", font_size: "8", toolbar: "search, go_to_line, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, highlight", syntax_selection_allow: "js,python" }); ''' } ) text.add_style("margin-top: 5px") text.add_style("font-family: courier new") text.add_style("font-size: 11px") text.set_id("shelf_script") #text.add_attr("cols", "80") #text.add_attr("rows", "20") text.add_style("min-height", "400px") text.add_style("height", "400px") text.add_style("width", "600px") text.set_value(script_value) td.add(text) """ td = table.add_cell() td.add_style('vertical-align: top') td.add(my.get_script_wdg()) table.add_row(resize=False) div.add(table) if my.kwargs.get("is_refresh"): return div else: return top
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 """
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 """