def get_section_wdg(my, title, description, image, behavior): section_wdg = DivWdg() section_wdg.set_round_corners() section_wdg.add_border() section_wdg.add_class("spt_report_top") section_wdg.add_style("width: 200px") section_wdg.add_style("height: 100px") section_wdg.add_style("overflow: hidden") section_wdg.add_style("margin: 10px") section_wdg.set_box_shadow("0px 0px 10px") title_wdg = DivWdg() section_wdg.add(title_wdg) title_wdg.add(title) title_wdg.add_style("height: 20px") title_wdg.add_style("padding: 3px") title_wdg.add_style("margin-top: 3px") title_wdg.add_style("font-weight: bold") title_wdg.add_gradient("background", "background") button = IconButtonWdg(title="Options", icon=IconWdg.ARROWHEAD_DARK_DOWN) title_wdg.add(button) button.add_style("float: right") # set up menus menu = my.get_menu() SmartMenu.add_smart_menu_set( button, { 'MENU_ITEM': menu } ) SmartMenu.assign_as_local_activator( button, "MENU_ITEM", True ) section_wdg.add_color("background", "background") #section_wdg.add_gradient("background", "background", 0, -3) section_wdg.add_behavior( { 'type': 'hover', 'add_color_modifier': -5, 'cb_set_prefix': 'spt.mouse.table_layout_hover', } ) desc_div = DivWdg() desc_div.add(description) desc_div.add_style("padding: 5px 10px 10px 5px") div = DivWdg() section_wdg.add(div) div.add_style("padding: 3px") div.add_style("margin: 5px") div.add_style("width: 65px") div.add_style("height: 50px") div.add_style("float: left") div.add(image) section_wdg.add(desc_div) div.add_style("overflow: hidden") section_wdg.add_behavior( behavior ) section_wdg.add_class("hand") return section_wdg
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_display(my): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_gradient("background", "background", 0, -5) #top.add_style("height: 550px") top.add_behavior( { 'type': 'load', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|hide", {} ); ''' } ) project = Project.get() title = TitleWdg(title='Client Home') top.add(title) shelf = DivWdg() top.add(shelf) shelf.add_style("margin-left: -8px") shelf.add_style("width: 130px") security = Environment.get_security() view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow') if view_side_bar: button_div = DivWdg() shelf.add(button_div) button_div.add_style("float: left") button_div.add_style("margin-top: -3px") button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT) button_div.add(button) shelf.add("Toggle Side Bar") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' } ) shelf.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' } ) shelf.add_class("hand") else: shelf.add(" ") 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("padding: 3px") td.add_style("vertical-align: top") title = "My Approvals" description = '''View all pending items for approval<br/><br/> ''' #image = "<img src='/context/images/getting_started_pipeline.png'/>" image = "<img src='/context/icons/64x64/dashboard_64.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { search_type: 'sthpw/sobject_list', view: 'client_approval', show_shelf: false, show_select: false, element_names: ['preview', 'name', 'description', 'task_pipeline_vertical','notes'], is_editable: false, //expression: "@SOBJECT(sthpw/task['project_code','fickle3'].fickle3/cars.sthpw/sobject_list)" }; spt.tab.add_new("approvals", "Approvals", class_name, kwargs); ''' } config_wdg = my.get_section_wdg(title, description, image, behavior) td.add(config_wdg) td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "My Dashboard" image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''Dashboards display key project data in single views. Drill down further to work on tasks, make status changes or add notes.''' # read the config file from pyasm.widget import WidgetConfig tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path="%s/../config/dashboard-conf.xml" % (dir_name) config = WidgetConfig.get(file_path=file_path, view="definition") #element_name = "my_dashboard" element_name = "my_dashboard" attrs = config.get_element_attributes(element_name) dashboard_data = {} kwargs = config.get_display_options(element_name) class_name = kwargs.get('class_name') dashboard_data['class_name'] = class_name dashboard_data['kwargs'] = kwargs dashboard_data['title'] = attrs.get("title") dashboard_data['description'] = attrs.get("description") dashboard_data['image'] = attrs.get("image") behavior = { 'type': 'click_up', 'dashboard': dashboard_data, 'cbjs_action': ''' var class_name = 'tactic.ui.startup.dashboards_wdg.DashboardsWdg'; var kwargs = {}; spt.tab.set_main_body_tab(); spt.tab.add_new("my_dashboard", "My Dashboard", bvr.dashboard.class_name, bvr.dashboard.kwargs); ''' } pipeline_wdg = my.get_section_wdg(title, description, image, behavior) td.add(pipeline_wdg) td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "My Reports" image = "<img src='/context/icons/64x64/report_64.png'/>" description = '''TACTIC provides a number of predefined reports that project managers can access instantly to get real-time analytics.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.reports_wdg.ReportsWdg'; var kwargs = {}; spt.tab.set_main_body_tab(); spt.tab.add_new("reports", "Reports", class_name, kwargs); //spt.panel.load_popup("Reports", class_name, kwargs); ''' } side_bar_wdg = my.get_section_wdg(title, description, image, behavior) td.add(side_bar_wdg) """ td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Documentation" description = '''TACTIC Documentation. <br/><br/> * Project Setup Documentation<br/> <br/> * End User Documentation<br/> <br/> * Developer Documentation<br/> <br/> * System Administrator Documentation<br/> <br/> ''' image = "<img src='/context/images/getting_started_pipeline.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.help.load_alias("main") ''' } doc_wdg = my.get_section_wdg(title, description, image, behavior) td.add(doc_wdg) """ tr, td = table.add_row_cell() td.add_style("font-size: 14px") td.add("<br/>"*2) quick_links_wdg = QuickLinksWdg() td.add(quick_links_wdg) return top
def get_display(my): web = WebContainer.get_web() show_multi_project = web.get_form_value('show_multi_project') project = Project.get() search_type_objs = project.get_search_types(include_multi_project=show_multi_project) top = my.top top.add_class("spt_panel_stype_list_top") #top.add_style("min-width: 400px") #top.add_style("max-width: 1000px") #top.add_style("width: 100%") top.center() button = SingleButtonWdg(title="Advanced Setup", icon=IconWdg.ADVANCED) top.add(button) button.add_style("float: right") button.add_style("margin-top: -8px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.app.ProjectStartWdg'; spt.tab.set_main_body_tab() spt.tab.add_new("project_setup", "Project Setup", class_name) ''' } ) button = SingleButtonWdg(title="Add", tip="Add New Searchable Type (sType)", icon=IconWdg.ADD) top.add(button) button.add_style("float: left") button.add_style("margin-top: -8px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.app.SearchTypeCreatorWdg'; var kwargs = { }; var popup = spt.panel.load_popup("Create New Searchable Type", class_name, kwargs); var top = bvr.src_el.getParent(".spt_panel_stype_list_top"); popup.on_register_cbk = function() { spt.panel.refresh(top); } ''' } ) cb = CheckboxWdg('show_multi_project', label=' show multi-project') if show_multi_project: cb.set_checked() cb.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var panel = bvr.src_el.getParent('.spt_panel_stype_list_top') spt.panel.refresh(panel, {show_multi_project: bvr.src_el.checked}); ''' }) span = SpanWdg(css='small') top.add(span) top.add(cb) top.add("<br clear='all'/>") #search_type_objs = [] if not search_type_objs: arrow_div = DivWdg() top.add(arrow_div) icon = IconWdg("Click to Add", IconWdg.ARROW_UP_LEFT_32) icon.add_style("margin-top: -20") icon.add_style("margin-left: -15") icon.add_style("position: absolute") arrow_div.add(icon) arrow_div.add(" "*5) arrow_div.add("<b>Click to Add</b>") arrow_div.add_style("position: relative") arrow_div.add_style("margin-top: 5px") arrow_div.add_style("margin-left: 20px") arrow_div.add_style("float: left") arrow_div.add_style("padding: 25px") arrow_div.set_box_shadow("0px 5px 20px") arrow_div.set_round_corners(30) arrow_div.add_color("background", "background") div = DivWdg() top.add(div) div.add_border() div.add_style("min-height: 180px") div.add_style("width: 600px") div.add_style("margin: 30px auto") div.add_style("padding: 20px") div.add_color("background", "background3") icon = IconWdg( "WARNING", IconWdg.WARNING ) div.add(icon) div.add("<b>No Searchable Types have been created</b>") div.add("<br/><br/>") div.add("Searchables Types contain lists of items that are managed in this project. Each item will automatically have the ability to have files checked into it, track tasks and status and record work hours.") div.add("<br/>"*2) div.add("For more information, read the help docs: ") from tactic.ui.app import HelpButtonWdg help = HelpButtonWdg(alias="main") div.add(help) div.add("<br/>") div.add("Click on the 'Add' button above to start adding new types.") return top div = DivWdg() top.add(div) #div.add_style("max-height: 300px") #div.add_style("overflow-y: auto") table = Table() div.add(table) table.add_style("margin-top: 10px") table.set_max_width() # group mouse over table.add_relay_behavior( { 'type': "mouseover", 'bvr_match_class': 'spt_row', 'cbjs_action': "spt.mouse.table_layout_hover_over({}, {src_el: bvr.src_el, add_color_modifier: -2})" } ) table.add_relay_behavior( { 'type': "mouseout", 'bvr_match_class': 'spt_row', 'cbjs_action': "spt.mouse.table_layout_hover_out({}, {src_el: bvr.src_el})" } ) tr = table.add_row() tr.add_color("color", "color") tr.add_gradient("background", "background", -10) th = table.add_header("") th.add_style("text-align: left") th = table.add_header("Title") th.add_style("text-align: left") th = table.add_header("# Items") th.add_style("text-align: left") th = table.add_header("View") th.add_style("text-align: left") th = table.add_header("Add") th.add_style("text-align: left") th = table.add_header("Import") th.add_style("text-align: left") th = table.add_header("Custom Columns") th.add_style("text-align: left") th = table.add_header("Workflow") th.add_style("text-align: left") th = table.add_header("Notifications") th.add_style("text-align: left") th = table.add_header("Triggers") th.add_style("text-align: left") th = table.add_header("Edit") th.add_style("text-align: left") #th = table.add_header("Security") #th.add_style("text-align: left") for i, search_type_obj in enumerate(search_type_objs): tr = table.add_row() tr.add_class("spt_row") if not i or not i%2: tr.add_color("background", "background3") else: tr.add_color("background", "background", -2 ) thumb = ThumbWdg() thumb.set_sobject(search_type_obj) thumb.set_icon_size(30) td = table.add_cell(thumb) search_type = search_type_obj.get_value("search_type") title = search_type_obj.get_title() table.add_cell(title) try: search = Search(search_type) count = search.get_count() if count: table.add_cell("%s item/s" % count) else: table.add_cell(" ") except: td = table.add_cell("< No table >") td.add_style("font-style: italic") td.add_style("color: #F00") continue #search = Search(search_type) #search.add_interval_filter("timestamp", "today") #created_today = search.get_count() #table.add_cell(created_today) td = table.add_cell() button = IconButtonWdg(title="View", icon=IconWdg.ZOOM) td.add(button) button.add_behavior( { 'type': 'click_up', 'search_type': search_type, 'title': title, 'cbjs_action': ''' var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { search_type: bvr.search_type, view: 'table', 'simple_search_view': 'simple_search' }; // use tab var top = bvr.src_el.getParent(".spt_dashboard_top"); spt.tab.set_tab_top(top); spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs); //spt.panel.load_popup(bvr.title, class_name, kwargs); ''' } ) button.add_style("float: left") arrow_button = IconButtonWdg(tip="More Views", icon=IconWdg.ARROWHEAD_DARK_DOWN) arrow_button.add_style("margin-left: 20px") td.add(arrow_button) cbk = ''' var activator = spt.smenu.get_activator(bvr); var class_name = bvr.class_name; var layout = bvr.layout; var kwargs = { search_type: bvr.search_type, layout: layout, view: bvr.view, simple_search_view: 'simple_search', element_names: bvr.element_names, }; // use tab var top = activator.getParent(".spt_dashboard_top"); spt.tab.set_tab_top(top); spt.tab.add_new('%s', '%s', class_name, kwargs); ''' % (title, title) from tactic.ui.panel import SwitchLayoutMenu SwitchLayoutMenu(search_type=search_type, activator=arrow_button, cbk=cbk, is_refresh=False) td = table.add_cell() button = IconButtonWdg(title="Add", icon=IconWdg.ADD) td.add(button) button.add_behavior( { 'type': 'listen', 'search_type': search_type, 'event_name': 'startup_save:' + search_type_obj.get_title(), 'title': search_type_obj.get_title(), 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_dashboard_top"); spt.tab.set_tab_top(top); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { search_type: bvr.search_type, view: 'table', 'simple_search_view': 'simple_search' }; spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs); ''' } ) button.add_behavior( { 'type': 'click_up', 'search_type': search_type, 'title': search_type_obj.get_title(), 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_dashboard_top"); spt.tab.set_tab_top(top); var class_name = 'tactic.ui.panel.EditWdg'; var kwargs = { search_type: bvr.search_type, view: "insert", save_event: "startup_save:" + bvr.title } spt.panel.load_popup("Add New Items ("+bvr.title+")", class_name, kwargs); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { search_type: bvr.search_type, view: 'table', 'simple_search_view': 'simple_search' }; spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs); ''' } ) """ td = table.add_cell() button = IconButtonWdg(title="Check-in", icon=IconWdg.PUBLISH) td.add(button) button.add_behavior( { 'type': 'click_up', 'search_type': search_type, 'title': title, 'cbjs_action': ''' var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { search_type: bvr.search_type, view: 'checkin', element_names: ['preview','code','name','description','history','general_checkin','notes'] }; // use tab var top = bvr.src_el.getParent(".spt_dashboard_top"); spt.tab.set_tab_top(top); spt.tab.add_new(bvr.title, bvr.title, class_name, kwargs); //spt.panel.load_popup(bvr.title, class_name, kwargs); ''' } ) """ td = table.add_cell() button = IconButtonWdg(title="Import", icon=IconWdg.IMPORT) td.add(button) button.add_behavior( { 'type': 'click_up', 'search_type': search_type, 'title': "Import Data", 'cbjs_action': ''' var class_name = 'tactic.ui.widget.CsvImportWdg'; var kwargs = { search_type: bvr.search_type, }; spt.panel.load_popup(bvr.title, class_name, kwargs); ''' } ) td = table.add_cell() button = IconButtonWdg(title="Custom Columns", icon=IconWdg.COLUMNS) td.add(button) button.add_behavior( { 'type': 'click_up', 'search_type': search_type, 'title': "Add Custom Columns", 'cbjs_action': ''' var class_name = 'tactic.ui.startup.ColumnEditWdg'; var kwargs = { search_type: bvr.search_type, }; spt.panel.load_popup(bvr.title, class_name, kwargs); ''' } ) td = table.add_cell() button = IconButtonWdg(title="Workflow", icon=IconWdg.PIPELINE) button.add_style("float: left") td.add(button) search = Search("sthpw/pipeline") search.add_filter("search_type", search_type) count = search.get_count() if count: check = IconWdg( "Has Items", IconWdg.CHECK, width=8 ) td.add(check) #check.add_style("margin-left: 0px") check.add_style("margin-top: 4px") button.add_behavior( { 'type': 'click_up', 'title': 'Workflow', 'search_type': search_type, 'cbjs_action': ''' var class_name = 'tactic.ui.startup.PipelineEditWdg'; var kwargs = { search_type: bvr.search_type }; spt.panel.load_popup(bvr.title, class_name, kwargs); ''' } ) td = table.add_cell() button = IconButtonWdg(title="Notifications", icon=IconWdg.MAIL) button.add_style("float: left") td.add(button) search = Search("sthpw/notification") search.add_filter("search_type", search_type) count = search.get_count() if count: check = IconWdg( "Has Items", IconWdg.CHECK, width=8 ) td.add(check) #check.add_style("margin-left: 0px") check.add_style("margin-top: 4px") button.add_behavior( { 'type': 'click_up', 'title': 'Trigger', 'search_type': search_type, 'cbjs_action': ''' var class_name = 'tactic.ui.tools.TriggerToolWdg'; var kwargs = { mode: "search_type", search_type: bvr.search_type }; spt.panel.load_popup(bvr.title, class_name, kwargs); ''' } ) td = table.add_cell() button = IconButtonWdg(title="Triggers", icon=IconWdg.ARROW_OUT) td.add(button) button.add_style("float: left") search = Search("config/trigger") search.add_filter("search_type", search_type) count = search.get_count() if count: check = IconWdg( "Has Items", IconWdg.CHECK, width=8 ) td.add(check) #check.add_style("margin-left: 0px") check.add_style("margin-top: 4px") button.add_behavior( { 'type': 'click_up', 'title': 'Trigger', 'search_type': search_type, 'cbjs_action': ''' var class_name = 'tactic.ui.tools.TriggerToolWdg'; var kwargs = { mode: "search_type", search_type: bvr.search_type }; spt.panel.load_popup(bvr.title, class_name, kwargs); ''' } ) td = table.add_cell() button = IconButtonWdg(title="Edit Searchable Type", icon=IconWdg.EDIT) td.add(button) button.add_behavior( { 'type': 'click_up', 'search_key': search_type_obj.get_search_key(), 'cbjs_action': ''' var class_name = 'tactic.ui.panel.EditWdg'; var kwargs = { search_type: "sthpw/sobject", view: "edit_startup", search_key: bvr.search_key } spt.panel.load_popup("Edit Searchable Type", class_name, kwargs); ''' } ) """ td = table.add_cell() button = IconButtonWdg(title="Security", icon=IconWdg.LOCK) td.add(button) button.add_behavior( { 'type': 'click_up', 'title': 'Trigger', 'search_type': search_type, 'cbjs_action': ''' alert("security"); ''' } ) """ columns_wdg = DivWdg() top.add(columns_wdg) return top
def get_display(self): self.doc_mode = self.kwargs.get("doc_mode") path = self.kwargs.get("path") self.search_type = self.kwargs.get("search_type") self.last_path = None doc_key = self.kwargs.get("doc_key") if doc_key: self.doc = Search.get_by_search_key(doc_key) snapshot = Snapshot.get_latest_by_sobject(self.doc) if snapshot: self.last_path = snapshot.get_lib_path_by_type('main') path = self.doc.get_value("link") # TEST TEST TEST if not path: #path = "/home/apache/pdf/mongodb.txt" #path = "/home/apache/assets/google_docs.html" #path = "/home/apache/pdf/star_wars.txt" path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true" path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub" #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html" path = "/home/apache/tactic/doc/alias.json" if not self.search_type: self.search_type = "test3/shot" self.column = "description" top = self.top top.add_class("spt_document_top") self.set_as_panel(top) #table = Table() table = ResizableTableWdg() top.add(table) table.add_row() table.set_max_width() left_td = table.add_cell() left_td.add_style("vertical-align: top") title = DivWdg() left_td.add(title) title.add_style("padding: 10px") title.add_color("background", "background3") button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH) title.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); spt.panel.refresh(top); spt.app_busy.hide(); ''' } ) button.add_style("float: left") button = IconButtonWdg(title="Save", icon=IconWdg.SAVE) title.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' ''' } ) button.add_style("float: left") if not self.doc_mode: self.doc_mode = "text" select = SelectWdg("doc_mode") select.set_option("values", "text|formatted") title.add(select) select.set_value(self.doc_mode) select.add_behavior( { 'type': 'change', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); var value = bvr.src_el.value; top.setAttribute("spt_doc_mode", value); spt.panel.refresh(top); spt.app_busy.hide(); ''' } ) title.add("<br clear='all'/>") #title.add(path) text_wdg = DivWdg() text_wdg.add_class("spt_document_content") left_td.add(text_wdg) #if path.startswith("https://docs.google.com/spreadsheet"): # #path = "http://www.southpawtech.com.com" # text_wdg.add(''' # <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe> # ''' % path) # text_wdg.add_style("overflow-x: hidden") if True: if not self.last_path and self.doc: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') text = self.get_text(path, highlight=False) f.write(text) f.close() cmd = FileCheckin(self.doc, tmp_path) Command.execute_cmd(cmd) else: save = False if save: # open up the last path f = open(self.last_path, 'r') last_text = f.read() text = self.get_text(path, None, highlight=False) if last_text != text: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') f.write(text) f.write(text) f.close() cmd = FileCheckin(self.doc, tmp_path) Command.execute_cmd(cmd) text = self.get_text(path, self.last_path) lines = text.split("\n") if self.doc_mode == "text": num_lines = len(lines) """ line_div = HtmlElement.pre() text_wdg.add(line_div) line_div.add_style("width: 20px") line_div.add_style("float: left") line_div.add_style("text-align: right") line_div.add_style("opacity: 0.3") line_div.add_style("padding-right: 10px") for i in range(0, num_lines*2): line_div.add(i+1) line_div.add("<br/>") """ if self.doc_mode == "text": pre = HtmlElement.pre() pre.add_style("white-space: pre-wrap") else: pre = DivWdg() pre = DivWdg() text_wdg.add(pre) text_wdg.add_style("padding: 10px 5px") text_wdg.add_style("max-height: 600px") text_wdg.add_style("overflow-y: auto") text_wdg.add_style("width: 600px") text_wdg.add_class("spt_resizable") pre.add_style("font-family: courier") if self.doc_mode == "formatted": pre.add(text) else: line_table = Table() pre.add(line_table) line_table.add_style("width: 100%") count = 1 for line in lines: #line = line.replace(" ", " ") tr = line_table.add_row() if count % 2 == 0: tr.add_color("background", "background", -2) td = line_table.add_cell() # FIXME: hacky if line.startswith('''<span style='background: #CFC'>'''): is_new = True else: td.add_style("vertical-align: top") text = TextWdg() text.add_style("border", "none") text.add_style("text-align", "right") text.add_style("width", "25px") text.add_style("margin", "0 10 0 0") text.add_style("opacity", "0.5") text.set_value(count) td.add(text) count += 1 is_new = False td = line_table.add_cell() if not is_new: SmartMenu.assign_as_local_activator( td,'TEXT_CTX' ) tr.add_class("spt_line"); else: SmartMenu.assign_as_local_activator( td,'TEXT_NEW_CTX' ) tr.add_class("spt_new_line"); td.add_class("spt_line_content"); td.add(line) #from tactic.ui.app import AceEditorWdg #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px") #text_wdg.add(editor) # add a click on spt_item text_wdg.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_document_item', 'search_type': self.search_type, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_document_top"); var data_el = top.getElement(".spt_document_data"); var search_key = bvr.src_el.getAttribute("spt_search_key"); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': bvr.search_type, 'search_key': search_key, } spt.panel.load(data_el, class_name, kwargs); ''' } ) # add a double click on spt_item bgcolor = text_wdg.get_color("background", -10) text_wdg.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_document_item', 'search_type': self.search_type, 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "normal"); bvr.src_el.setStyle("background", bvr.bgcolor); ''' } ) # add a double click on spt_item text_wdg.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_document_item', 'search_type': self.search_type, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "bold"); bvr.src_el.setStyle("background", ""); ''' } ) # add a context menu ctx_menu = self.get_text_context_menu() ctx_new_menu = self.get_text_new_context_menu() menus_in = { 'TEXT_CTX': ctx_menu, 'TEXT_NEW_CTX': ctx_new_menu, } SmartMenu.attach_smart_context_menu( text_wdg, menus_in, False ) panel = ViewPanelWdg( search_type=self.search_type, layout="blah" ) right_td = table.add_cell() right_td.add_style("vertical-align: top") panel_div = DivWdg() panel_div.add_class("spt_document_data") right_td.add(panel_div) panel_div.add(panel) text_wdg.add_behavior( { 'type': 'load', 'cbjs_action': r''' spt.document = {}; spt.document.selected_text = null; spt.document.get_selected_text = function(frame) { var t = ''; if (frame) { var rng = frame.contentWindow.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (window.getSelection) // FF4 with one tab open? { var rng = window.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.getSelection) // FF4 with multiple tabs open? { var rng = document.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.selection) // IE8 { var rng = document.selection.createRange(); // expand range to enclose any word partially enclosed in it rng.expand("word"); t = rng.text; } // convert newline chars to spaces, collapse whitespace, and trim non-word chars return t.replace(/^\W+|\W+$/g, ''); //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, ''); } // expand FF range to enclose any word partially enclosed in it spt.document.expandtoword = function(range) { if (range.collapsed) { return; } while (range.startOffset > 0 && range.toString()[0].match(/\w/)) { range.setStart(range.startContainer, range.startOffset - 1); } while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/)) { range.setEnd(range.endContainer, range.endOffset + 1); } } ''' } ) top.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_document_content', 'cbjs_action': r''' //spt.ace_editor.set_editor_top(bvr.src_el); //var text = spt.ace_editor.get_selection(); var text = spt.document.get_selected_text(); text = text.replace(/\n\n/mg, "\n"); text = text.replace(/\n\n/mg, "\n"); spt.document.selected_text = text + ""; ''' } ) return top
def get_display(self): top = self.top self.set_as_panel(top) top.add_class("spt_ingestion_top") top.add_color("background", "background", -5) self.data = {} rules_div = DivWdg() top.add(rules_div) rules_div.add_style("padding: 10px") rules_div.add("Rules: ") rules_select = SelectWdg("rule_code") rule_code = self.get_value('rule_code') if rule_code: rules_select.set_value(rule_code) rules_select.set_option("query", "config/ingest_rule|code|title") rules_select.add_empty_option("-- New --") rules_div.add(rules_select) rules_select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var class_name = 'tactic.ui.tools.IngestionToolWdg'; spt.panel.load(top, class_name, {rule_code: value} ); ''' } ) rules_div.add("<hr/>") # read from the database if rule_code: search = Search("config/ingest_rule") search.add_filter("code", rule_code) sobject = search.get_sobject() else: sobject = None if sobject: self.data = sobject.get_value("data") if self.data: self.data = jsonloads(self.data) session_code = self.kwargs.get("session_code") if session_code: session = Search.get_by_code("config/ingest_session", session_code) else: if sobject: session = sobject.get_related_sobject("config/ingest_session") print("sobject: ", sobject.get_code(), sobject.get_value("spt_ingest_session_code")) print("parent: ", session) else: session = None if not session: #session = SearchType.create("config/ingest_session") #session.set_value("code", "session101") #session.set_value("location", "local") ##session.set_value("base_dir", "C:") top.add("No session defined!!!") return top rule = "" filter = "" ignore = "" # get the base path if sobject: base_dir = sobject.get_value("base_dir") else: base_dir = '' #else: # base_dir = self.get_value("base_dir") #if not base_dir: # base_dir = '' if sobject: title = sobject.get_value("title") else: title = '' if sobject: code = sobject.get_value("code") else: code = '' file_list = self.get_value("file_list") scan_type = self.get_value("scan_type") action_type = self.get_value("action_type") rule = self.get_value("rule") if not rule: rule = base_dir # get the rule for this path checkin_mode = "dir" depth = 0 table = Table() rules_div.add(table) table.add_color("color", "color") from tactic.ui.input.text_input_wdg import TextInputWdg # add the title table.add_row() td = table.add_cell() td.add("Title: ") td = table.add_cell() text = TextInputWdg(name="title") td.add(text) if title: text.set_value(title) text.add_class("spt_title") text.add_style("width: 400px") #text.add_color("background", "background", -10) # add the optional code table.add_row() td = table.add_cell() td.add("Code (optional): ") td = table.add_cell() text = TextInputWdg(name="code") td.add(text) if code: text.set_value(code) text.set_readonly() text.add_color("background", "background", -10) text.add_class("spt_code") text.add_style("width: 400px") table.add_row() td = table.add_cell() td.add_style("height: 10px") td.add("<hr/>") table.add_row() td = table.add_cell() td.add("<b>Scan:</b><br/>") td.add("The following information will be used to find the paths that will be operated on by the ingestion process<br/><br/>") # add a scan type table.add_row() td = table.add_cell() td.add("Type: ") select = SelectWdg("scan_type") select.add_class("spt_scan_type") td = table.add_cell() td.add(select) select.set_value( self.get_value("action") ) labels = ['Simple List', 'Rule', 'Script'] values = ['list', 'rule', 'script'] select.set_option("values", values) select.set_option("labels", labels) if scan_type: select.set_value(scan_type) table.add_row() table.add_cell(" ") select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var elements = top.getElements(".spt_scan_list"); for (var i = 0; i < elements.length; i++) { if (value == 'list') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_scan_rule"); for (var i = 0; i < elements.length; i++) { if (value == 'rule') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_scan_script"); for (var i = 0; i < elements.length; i++) { if (value == 'script') spt.show(elements[i]); else spt.hide(elements[i]); } ''' } ) # add in a list of stuff tbody = table.add_tbody() tbody.add_class("spt_scan_list") if scan_type != 'list': tbody.add_style("display: none") tr = table.add_row() td = table.add_cell() td.add("List of files: ") td = table.add_cell() text = TextAreaWdg(name="file_list") td.add(text) text.add_style("width: 400px") #text.set_readonly() #text.add_color("background", "background", -10) text.set_value(file_list) table.close_tbody() # add rule scan mode tbody = table.add_tbody() tbody.add_class("spt_scan_rule") if scan_type != 'rule': tbody.add_style("display: none") # add the path tr = table.add_row() td = table.add_cell() td.add("Starting Path: ") td = table.add_cell() hidden = HiddenWdg("session_code", session.get_code() ) td.add(hidden) text = TextInputWdg(name="base_dir") td.add(text) text.set_value(base_dir) text.add_style("width: 400px") #text.set_readonly() #text.add_color("background", "background", -10) text.set_value(base_dir) # add rule tr = table.add_row() td = table.add_cell() td.add("Tag Rule: ") td = table.add_cell() text = TextInputWdg(name="rule") td.add(text) text.add_style("width: 400px") text.set_value(rule) tr = table.add_row() td = table.add_cell() td.add("Filter: ") td = table.add_cell() text = TextWdg("filter") td.add(text) text.set_value( self.get_value("filter") ) text.add_style("width: 400px") text.add_style("padding: 2px") text.add_style("-moz-border-radius: 5px") tr = table.add_row() td = table.add_cell() td.add("Ignore: ") td = table.add_cell() text = TextWdg("ignore") td.add(text) text.set_value( self.get_value("ignore") ) text.set_value(ignore) text.add_style("width: 400px") text.add_style("padding: 2px") text.add_style("-moz-border-radius: 5px") table.add_row() td = table.add_cell() td.add("Validation script: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextInputWdg(name="validation_script") text.set_value( self.get_value("validation_script") ) text.add_style("width: 400px") td.add(text) icon = IconButtonWdg(title='Edit Validation Script', icon=IconWdg.EDIT) icon.add_style("float: right") td.add(icon) icon.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("show_script_editor"); var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); var kwargs = { script_path: values.validation_script } setTimeout( function() { spt.js_edit.display_script_cbk(evt, kwargs) }, 500 ); ''' } ) table.close_tbody() # add the script path tbody = table.add_tbody() tbody.add_class("spt_scan_script") if scan_type != 'script': tbody.add_style("display: none") tr = table.add_row() td = table.add_cell() td.add("Script Path: ") td = table.add_cell() text = TextInputWdg(name="script_path") td.add(text) text.add_style("width: 400px") table.close_tbody() table.add_row() td = table.add_cell("<hr/>") table.add_row() td = table.add_cell() td.add("<b>Action</b><br/>") td.add("The following information define the actions that will be used on each matched path<br/><br/>") # pick the type of action table.add_row() td = table.add_cell() td.add("Type: ") select = SelectWdg("action_type") td = table.add_cell() td.add(select) labels = ['Checkin', 'Ignore'] values = ['checkin', 'ignore'] select.set_option("values", values) select.set_option("labels", labels) select.add_empty_option("-- Select --") if action_type: select.set_value(action_type) select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var elements = top.getElements(".spt_action_ignore"); for (var i = 0; i < elements.length; i++) { if (value == 'ignore') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_action_checkin"); for (var i = 0; i < elements.length; i++) { if (value == 'checkin') spt.show(elements[i]); else spt.hide(elements[i]); } ''' } ) table.add_row() td = table.add_cell("<br/>") # add the script path tbody = table.add_tbody() tbody.add_class("spt_action_checkin") if action_type != 'checkin': tbody.add_style("display: none") # add the checkin type table.add_row() td = table.add_cell() td.add("Action: ") select = SelectWdg("action") td = table.add_cell() td.add(select) select.set_value( self.get_value("action") ) labels = ['File Checkin', 'Directory Checkin', 'Sequence Checkin'] values = ['file', 'directory', 'sequence', 'ignore'] select.set_option("values", values) select.set_option("labels", labels) table.add_row() td = table.add_cell() td.add("Mode: ") select = SelectWdg("mode") td = table.add_cell() td.add(select) labels = ['Copy', 'Move', 'In Place'] values = ['copy', 'move', 'inplace'] select.set_option("values", values) select.set_option("labels", labels) # add the search_type table.add_row() td = table.add_cell() td.add("sType: ") td = table.add_cell() select = SelectWdg("search_type") td.add(select) search_types = Project.get().get_search_types() values = [x.get_value("search_type") for x in search_types] select.set_option("values", values) search_type = self.kwargs.get("search_type") if search_type: select.set_value(search_type) # add the search_type table.add_row() td = table.add_cell() td.add("Context: ") td = table.add_cell() select = SelectWdg("context") td.add(select) select.set_option("values", ['publish', 'by rule', 'custom']) # add extra values extra_div = DivWdg() text = TextWdg("extra_name") text.add_attr("spt_is_multiple", "true") extra_div.add(text) extra_div.add(" = ") text = TextWdg("extra_value") extra_div.add(text) text.add_attr("spt_is_multiple", "true") template_div = DivWdg() text = TextWdg("extra_name") text.add_attr("spt_is_multiple", "true") template_div.add(text) template_div.add(" = ") text = TextWdg("extra_value") template_div.add(text) text.add_attr("spt_is_multiple", "true") table.close_tbody() table.add_row() td = table.add_cell("<br/>") table.add_row() td = table.add_cell() td.add("Extra Keywords: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("keywords") text.add_style("width: 300px") td.add(text) table.add_row() td = table.add_cell() td.add("Extra Values: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() extra_list = DynamicListWdg() td.add(extra_list) extra_list.add_item(extra_div) extra_list.add_template(template_div) table.add_row() table.add_cell(" ") table.add_row() td = table.add_cell() td.add("Process script: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("process_script") text.add_style("width: 300px") td.add(text) text.set_value( self.get_value("process_script") ) icon = IconButtonWdg(title='Edit Process Script', icon=IconWdg.EDIT) icon.add_style("float: right") td.add(icon) icon.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("show_script_editor"); var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); var kwargs = { script_path: values.process_script } // need to wait for this setTimeout( function() { spt.js_edit.display_script_cbk(evt, kwargs) }, 500 ); ''' } ) table.add_row() td = table.add_cell() td.add("Custom Naming: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("naming") text.add_style("width: 300px") td.add(text) table.add_row() td = table.add_cell() #td.add("<br clear='all'/>") td.add("<hr/>") behavior = { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); spt.app_busy.show("Scanning ...", values.base_dir); var class_name = 'tactic.ui.tools.IngestionProcessWdg'; var server = TacticServerStub.get(); values.mode = bvr.mode; values.is_local = 'true'; // scan client side if (values.is_local == 'true') { var base_dir = values.base_dir; var applet = spt.Applet.get(); var files = applet.list_recursive_dir(base_dir); // turn into a string var files_in_js = []; for (var i = 0; i < files.length; i++) { var file = files[i].replace(/\\\\/g, "/"); files_in_js.push( file ); } values.files = files_in_js; values.base_dir = base_dir; /* var server = TacticServerStub.get(); var handoff_dir = server.get_handoff_dir(); var applet = spt.Applet.get(); for (var i = 0; i < files_in_js.length; i++) { try { var parts = files_in_js[i].split("/"); var filename = parts[parts.length-1]; spt.app_busy.show("Copying files to handoff", filename); applet.copy_file(files_in_js[i], handoff_dir+"/"+filename); } catch(e) { log.error(e); } } */ } var info_el = top.getElement(".spt_info"); spt.panel.load(info_el, class_name, values); spt.app_busy.hide(); ''' } # Save button button = ActionButtonWdg(title="Save", tip="Save Rule") td.add(button) button.add_style("float: right") behavior['mode'] = 'save' button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); spt.app_busy.show("Saving ..."); var class_name = 'tactic.command.CheckinRuleSaveCmd'; var server = TacticServerStub.get(); server.execute_cmd(class_name, values); spt.panel.refresh(top, {}); spt.app_busy.hide(); ''' } ) # Scan button button = ActionButtonWdg(title="Scan", tip="Click to Scan") td.add(button) button.add_style("float: left") # set a limit #limit = TextWdg("limit") #td.add(limit) #text.add_style("float: left") behavior = behavior.copy() behavior['mode'] = 'scan' button.add_behavior(behavior) # Test button button = ActionButtonWdg(title="Test", tip="Do a test of this rule") td.add(button) behavior = behavior.copy() behavior['mode'] = 'test' button.add_behavior(behavior) button.add_style("float: left") # Ingest button button = ActionButtonWdg(title="Ingest", tip="Click to start ingesting") td.add(button) behavior = behavior.copy() behavior['mode'] = 'checkin' button.add_behavior(behavior) table.add_behavior( { 'type': 'listen', 'event_name': 'file_browser|select', 'cbjs_action': ''' var dirname = bvr.firing_data.dirname; var top = bvr.src_el.getParent(".spt_ingestion_top"); var kwargs = { base_dir: dirname }; spt.panel.load(top, top.getAttribute("spt_class_name"), kwargs); ''' }) top.add( self.get_info_wdg() ) return top
def get_category_wdg(self, category, mode="new"): subscriptions = self.get_subscriptions(category, mode) if not subscriptions: return div = DivWdg() div.add_style("width: 100%") title_div = DivWdg() div.add(title_div) title_div.add_style("padding: 10px") title_div.add_border() title_div.add_color("background", "background3") title = category or "Subscriptions" title_div.add("%s " % title) summary_div = SpanWdg() title_div.add(summary_div) summary_div.add_style("font-size: 0.8em") summary_div.add_style("opacity: 0.5") search_keys = [x.get_search_key() for x in subscriptions] button = ActionButtonWdg(title="Clear All") button.add_styles('float: right; padding: 2px') button_div = DivWdg(button) button_div.add_style('min-height: 26px') div.add(button_div) button.add_behavior( { 'type': 'click_up', 'search_keys': search_keys, 'cbjs_action': ''' var server = TacticServerStub.get(); for (var i = 0; i < bvr.search_keys.length; i++) { var search_key = bvr.search_keys[i]; server.update(search_key, {'last_cleared':'NOW'}); spt.panel.refresh(bvr.src_el); } ''' } ) # types of subscriptions table_div = DivWdg() table_div.add_styles('overflow-y: auto; max-height: 500px; width: 100%') div.add(table_div) table = Table() table.add_style('width: 100%') table.add_border() table.add_color("background", "background3") table_div.add(table) ss = [] for subscription in subscriptions: table.add_row() td = table.add_cell() message_code = subscription.get_value("message_code") search = Search("sthpw/message") search.add_filter("code", message_code) message = search.get_sobject() # show the thumb if not message: if mode == "all": td = table.add_cell(FormatMessageWdg.get_preview_wdg(subscription)) td = table.add_cell() td.add("No Messages") continue size = 60 show_preview = self.kwargs.get('show_preview') if show_preview in ['',None]: show_preview = True msg_element = FormatMessageWdg(subscription=subscription, short_format='true',show_preview=show_preview) # this is optional msg_element.set_sobject(message) description = msg_element.get_buffer_display() #td = table.add_cell() history_icon = IconButtonWdg(title="Subscription History", icon=IconWdg.HISTORY) #td.add(icon) message_code = subscription.get_value("message_code") history_icon.add_behavior( { 'type': 'click_up', 'message_code': message_code, 'cbjs_action': ''' var class_name = 'tactic.ui.panel.FastTableLayoutWdg'; var message_code = bvr.message_code; var kwargs = { search_type: 'sthpw/message_log', show_shelf: false, expression: "@SOBJECT(sthpw/message_log['message_code','"+message_code+"'])", view: 'history' }; spt.tab.set_main_body_tab(); spt.tab.add_new("Message History", "Message History", class_name, kwargs); ''' } ) # description can take up 70% td = table.add_cell() td.add_style("width: %spx"%(SubscriptionBarWdg.WIDTH*0.7)) desc_div = DivWdg() td.add(desc_div) desc_div.add(description) desc_div.add_style("padding: 0px 20px") td = table.add_cell() #td.add(message.get_value("status")) #td = table.add_cell() timestamp = message.get_datetime_value("timestamp") if timestamp: timestamp_str = timestamp.strftime("%b %d, %Y - %H:%M") else: timestamp_str = "" show_timestamp = self.kwargs.get('show_timestamp') if show_timestamp in ['',None]: show_timestamp = True if show_timestamp in ["True","true",True]: td.add(timestamp_str) #td = table.add_cell() #td.add(subscription.get_value("last_cleared")) td = table.add_cell() show_message_history = self.kwargs.get('show_message_history') if show_message_history in ['',None]: show_message_history = True if show_message_history in ["True","true",True]: td.add(history_icon) td.add(HtmlElement.br(2)) td.add_style('width: 30px') icon = IconButtonWdg(title="Unsubscribe", icon=IconWdg.DELETE) icon.add_style('bottom: 14px') subscription_key = subscription.get_search_key() icon.add_behavior( { 'type': 'click_up', 'search_key': subscription_key, 'message_code': message_code, 'cbjs_action': ''' if (!confirm("Unsubscribe from [" + bvr.message_code + "]?")) { return; } var top = bvr.src_el.getParent(".spt_subscription_top"); var server = TacticServerStub.get(); server.delete_sobject(bvr.search_key); spt.panel.refresh(top); ''' } ) show_unsubscribe = self.kwargs.get('show_unsubscribe') if show_unsubscribe in ['',None]: show_unsubscribe = False if show_unsubscribe in ["True","true",True]: td.add(icon) ss.append(subscription) num_sobjects = len(ss) if not num_sobjects: return None summary_div.add("(%s changes)" % num_sobjects) #from tactic.ui.panel import FastTableLayoutWdg #table = FastTableLayoutWdg(search_type="sthpw/subscription",show_shelf=False) #div.add(table) #table.set_sobjects(ss) return div
def get_display(my): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_gradient("background", "background", 0, -5) #top.add_style("height: 550px") top.add_behavior( { 'type': 'load', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|hide_now", {} ); ''' } ) project = Project.get() title = DivWdg() title.add("Project Startup and Configuration") title.add_style("font-size: 18px") title.add_style("font-weight: bold") title.add_style("text-align: center") title.add_style("padding: 10px") title.add_style("margin: -10px -10px 10px -10px") top.add(title) title.add_gradient("background", "background3", 5, -10) shelf = DivWdg() top.add(shelf) shelf.add_style("margin-left: -8px") shelf.add_style("width: 130px") button_div = DivWdg() shelf.add(button_div) button_div.add_style("float: left") button_div.add_style("margin-top: -3px") security = Environment.get_security() view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow') if view_side_bar: button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT) button_div.add(button) shelf.add("Toggle Side Bar") shelf.add_attr("title", "Toggle Side Bar (or press '1')") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' } ) shelf.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' } ) shelf.add_class("hand") else: shelf.add(" ") 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': 'result_list', 'keywords': keywords, 'simple_search_view': 'simple_filter', //'show_shelf': false, } spt.tab.set_main_body_tab(); spt.tab.add_new("Search Results", "Search Results", class_name, kwargs); } ''' from tactic.ui.input import TextInputWdg, LookAheadTextInputWdg #text = TextInputWdg(name="search") text = LookAheadTextInputWdg(name="search", custom_cbk=custom_cbk, width='280') #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': 'result_list', 'keywords': keywords, 'simple_search_view': 'simple_filter', //'show_shelf': false, } spt.tab.set_main_body_tab(); spt.tab.add_new("Search Results", "Search Results", class_name, kwargs); ''' } ) #desc = DivWdg() #top.add(desc) #desc.add("Dashboard") #desc.add_style("width: 600px") # create a bunch of panels table = Table() table.add_color("color", "color") table.add_style("margin-bottom: 20px") table.center() top.add(table) table.add_row() #security = Environment.get_security() #if not security.check_access("builtin", "view_site_admin", "allow"): td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "Configuration" #description = '''All TACTIC projects can be uniquely designed and managed using our configuration tools.''' description = '''Configure a Project from start to finish.''' image = "<img src='/context/icons/64x64/configuration_64.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.startup.ProjectConfigWdg'; var kwargs = { help_alias: 'project-startup-configuration' }; spt.tab.add_new("configuration", "Configuration", class_name, kwargs); ''' } config_wdg = my.get_main_section_wdg(title, description, image, behavior) td.add(config_wdg) # Manage Users td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Manage Users and Security" image = "<img src='/context/icons/64x64/dashboard_64.png'/>" image = DivWdg() image_link = "<div style='margin-bottom: -64px'><img src='/context/icons/64x64/lock_64.png'/></div>" image.add(image_link) image1 = IconWdg("Manage Users", IconWdg.USER_32) image2 = IconWdg("Manage Users", IconWdg.USER_32) image3 = IconWdg("Manage Users", IconWdg.USER_32) image4 = IconWdg("Manage Users", IconWdg.USER_32) image.add(image1) image.add(image2) image.add("<br/>") image.add(image3) image.add(image4) description = '''Manage users that can access the system''' behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.startup.UserConfigWdg'; var kwargs = { help_alias: 'project-startup-manage-users' }; spt.tab.add_new("user", "Users", class_name, kwargs); ''' } manage_users_wdg = my.get_main_section_wdg(title, description, image, behavior) td.add(manage_users_wdg) # custom layout editor td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "Custom Layouts" description = '''Create interfaces using the Custom Layout Editor.''' image = "<img src='/context/icons/64x64/layout_64.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.tools.CustomLayoutEditWdg'; var kwargs = { help_alias: 'project-startup-configuration' }; spt.tab.add_new("custom_layout_editor", "Custom Layout Editor", class_name, kwargs); ''' } config_wdg = my.get_main_section_wdg(title, description, image, behavior) td.add(config_wdg) """ # Manage Security td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Manage Security" image = "<img src='/context/icons/64x64/lock_64.png'/>" description = '''Configure User Group security for Projects, Links and more''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.SecurityWdg'; var kwargs = { help_alias: 'manage-security' }; spt.tab.set_main_body_tab(); spt.tab.add_new("security", "Security", class_name, kwargs); ''' } security_wdg = my.get_main_section_wdg(title, description, image, behavior) td.add(security_wdg) """ """ table.add_row() # Lists td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "Lists of Items" image = IconWdg("Lists", IconWdg.SEARCH_TYPE_32) description = '''View all of the lists items for this project''' behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.startup.HomeWdg'; var kwargs = { help_alias: 'main' }; spt.tab.add_new("lists", "Lists", class_name, kwargs); ''' } lists_wdg = my.get_small_section_wdg(title, description, image, behavior) td.add(lists_wdg) """ """ # Dashboards td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Dashboards" image = IconWdg("Dashboards", IconWdg.DASHBOARD_02) #image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''Dashboards display key project data in single views.''' 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_small_section_wdg(title, description, image, behavior) td.add(dashboard_wdg) """ """ # Reports td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "Reports" image = IconWdg("Reports", IconWdg.GRAPH_LINE_03) #image = "<img src='/context/icons/64x64/report_64.png'/>" #description = '''TACTIC provides a number of predefined reports for real-time analytics.''' description = '''A number of predefined reports for real-time project analytics.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.reports_wdg.ReportsWdg'; var kwargs = { help_alias: 'main' }; spt.tab.set_main_body_tab(); spt.tab.add_new("reports", "Reports", class_name, kwargs); ''' } report_wdg = my.get_small_section_wdg(title, description, image, behavior) td.add(report_wdg) """ tr = table.add_row() # Plugins td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Plugin Manager" image = IconWdg("Plugins Manager", IconWdg.PLUGIN_32) #image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''Upload, install, remove and create TACTIC plugins.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.app.PluginWdg'; spt.tab.set_main_body_tab(); spt.tab.add_new("plugin_manager", "Plugin Manager", class_name, kwargs); ''' } plugin_wdg = my.get_small_section_wdg(title, description, image, behavior) td.add(plugin_wdg) # Examples td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Tools" image = IconWdg("Tools", IconWdg.SHARE_32) #image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''A collection of example views.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.ToolsWdg'; spt.tab.set_main_body_tab(); spt.tab.add_new("tools", "Tools", class_name, kwargs); ''' } share_wdg = my.get_small_section_wdg(title, description, image, behavior) td.add(share_wdg) # Share """ td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Shares" image = IconWdg("Shares", IconWdg.SHARE_32) #image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''Share project with other TACTIC installs.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.ShareWdg'; spt.tab.set_main_body_tab(); spt.tab.add_new("shares", "Shares", class_name, kwargs); ''' } share_wdg = my.get_small_section_wdg(title, description, image, behavior) td.add(share_wdg) """ # Advanced td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Advanced Setup" image = IconWdg("Advanced", IconWdg.ADVANCED_32) #image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''A set of advanced configuration tools.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.app.ProjectStartWdg'; spt.tab.set_main_body_tab() spt.tab.add_new("project_setup", "Project Setup", class_name) ''' } share_wdg = my.get_small_section_wdg(title, description, image, behavior) td.add(share_wdg) """ td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Documentation" description = '''TACTIC Documentation. * Project Setup Documentation<br/> <br/> * End User Documentation<br/> <br/> * Developer Documentation<br/> <br/> * System Administrator Documentation<br/> <br/> ''' image = "<img src='/context/images/getting_started_pipeline.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.help.load_alias("main") ''' } doc_wdg = my.get_section_wdg(title, description, image, behavior) td.add(doc_wdg) """ tr, td = table.add_row_cell() td.add_style("font-size: 14px") td.add("<br/>") from misc_wdg import QuickLinksWdg quick_links_wdg = QuickLinksWdg() td.add(quick_links_wdg) #td = table.add_cell() #totals_wdg = my.get_totals_wdg() #td.add(totals_wdg) return top
def get_shelf_wdg(self): process = self.get_value("process") versions = self.get_value("versions") div = DivWdg() filter_table = Table() div.add(filter_table) filter_table.add_row() button = SingleButtonWdg(title="Refresh", icon=IconWdg.REFRESH) filter_table.add_cell(button) filter_table.add_cell(" " * 5) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.panel.refresh(bvr.src_el); ''' }) # get all of the pipelnes for this search type pipeline_code = self.sobject.get_value("pipeline_code", no_exception=True) processes = [] if pipeline_code: pipeline = Pipeline.get_by_code(pipeline_code) if pipeline: process_names = pipeline.get_process_names() processes.extend(process_names) processes.insert(0, "all") filter_table.add_cell("Process: ") select = SelectWdg("process") select.add_style("width: 200px") if process != 'all': select.set_value(process) select.set_option("values", processes) filter_table.add_cell(select) filter_table.add_cell(" " * 10) filter_table.add_cell("Versions: ") select = SelectWdg("versions") select.add_style("width: 200px") select.set_option("values", "latest|current|today|last 10|all") if versions: select.set_value(versions) filter_table.add_cell(select) asset_dir = Environment.get_asset_dir() select = IconButtonWdg(tip="Toggle Selection", icon=IconWdg.SELECT, show_arrow=False) div.add(select) select.add_style("float: right") select.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top_class = 'spt_sobject_dir_list_top' var toggle_state = bvr.src_el.getAttribute('toggle'); if (toggle_state && toggle_state=='true') bvr.src_el.setAttribute('toggle','false'); else bvr.src_el.setAttribute('toggle','true'); var top = bvr.src_el.getParent("."+top_class); spt.selection.set_top(top); toggle_state = bvr.src_el.getAttribute('toggle'); if (toggle_state == 'true') spt.selection.select_all_items(); else spt.selection.unselect_all_items(); ''' }) show = IconButtonWdg(tip="Switch View", icon=IconWdg.VIEW, show_arrow=False) div.add(show) show.add_style("float: right") show.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top_class = 'spt_sobject_dir_list_top' var top = bvr.src_el.getParent("."+top_class); spt.selection.set_top(top); var els = top.getElements(".spt_file_dir_item"); for (var i = 0; i < els.length; i++) { var el = els[i]; if (el.getStyle("display") == "none") { els[i].setStyle("display", ""); } else { els[i].setStyle("display", "none"); } } var els = top.getElements(".spt_file_item"); for (var i = 0; i < els.length; i++) { var el = els[i]; if (el.getStyle("padding-left") == "6px") { var padding = el.getAttribute("spt_padding_left"); el.setStyle("padding-left", padding); } else { el.setStyle("padding-left", "6px"); } } ''' }) gear = IconButtonWdg(tip="Download", icon=IconWdg.DOWNLOAD, show_arrow=False) div.add(gear) gear.add_style("float: right") gear.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.app_busy.show('Select a folder to download to...',''); var top_class = 'spt_sobject_dir_list_top'; var top = bvr.src_el.getParent("."+top_class); spt.selection.set_top(top); var items = spt.selection.get_selected(); setTimeout( function() { var applet = spt.Applet.get(); var select_dir =true; var dir = applet.open_file_browser('', select_dir); if (dir.length == 0) dir = applet.get_current_dir(); else dir = dir[0]; if (!dir) { spt.alert("No folder selected to copy to."); spt.app_busy.hide(); return; } if (items.length == 0){ spt.alert("Please select at least one file to download."); spt.app_busy.hide(); return; } var asset_dir = '%s'; for (var i = 0; i < items.length; i++) { var path = items[i].getAttribute("spt_path"); var env = spt.Environment.get(); var server_url = env.get_server_url(); var url = server_url + "/assets/" + path.replace(asset_dir, ""); var parts = path.split("/"); var filename = parts[parts.length-1]; spt.app_busy.show("Downloading file", filename); applet.download_file(url, dir + "/" + filename); } spt.app_busy.hide(); if (dir) spt.notify.show_message("Download to '" + dir + "' completed.") }, 100); ''' % asset_dir }) return div
def get_collection_wdg(my): div = DivWdg() div.add_style("margin: 15px 0px") title_div = DivWdg("Collection Manager") div.add(title_div) div.add_class("spt_collection_left") title_div.add_style("font-size: 1.2em") title_div.add_style("font-weight: bold") div.add("<hr/>") # Shelf shelf_div = DivWdg() div.add(shelf_div) shelf_div.add_style("float: right") shelf_div.add_style("margin-bottom: 15px") #button = IconButtonWdg(title='Delete Selected Collection', icon="BS_TRASH") #shelf_div.add(button) #button.add_style("display: inline-block") #button.add_style("width: auto") button = IconButtonWdg(title='Add New Collection', icon="BS_PLUS") shelf_div.add(button) button.add_style("display: inline-block") button.add_style("vertical-align: top") insert_view = "edit_collection" button.add_behavior( { 'type': 'click_up', 'insert_view': insert_view, 'search_type': my.search_type, 'cbjs_action': ''' kwargs = { search_type: bvr.search_type, mode: 'insert', view: bvr.insert_view, save_event: bvr.event_name, show_header: false, num_columns: 2, default: { _is_collection: true } }; var popup = spt.panel.load_popup('Add New Collection', 'tactic.ui.panel.EditWdg', kwargs); ''' } ) text_div = DivWdg() shelf_div.add(text_div) custom_cbk = {} custom_cbk['enter'] = ''' var top = bvr.src_el.getParent(".spt_collection_left"); var input = top.getElement(".spt_main_search"); var search_value = input.value.toLowerCase(); var collections = top.getElements(".spt_collection_div"); var num_result = 0; for (i = 0; i < collections.length; i++) { // Access the Collection title (without number count) var collection_title = collections[i].attributes[0].value.toLowerCase(); if (collection_title.indexOf(search_value) != '-1') { collections[i].style.display = "block"; num_result += 1; } else { collections[i].style.display = "none"; } } // if no search results, display all if (num_result == 0) { for (i = 0; i < collections.length; i++) { collections[i].style.display = "block"; } } ''' filters = [] filters.append(("_is_collection",True)) filters.append(("status","Verified")) text = LookAheadTextInputWdg( search_type = "workflow/asset", column="name", width="100%", height="30px", hint_text="Enter terms to filter collections...", value_column="name", filters=filters, custom_cbk=custom_cbk, is_collection=True ) text.add_class("spt_main_search") text_div.add(text) text_div.add_style("width: 270px") text_div.add_style("display: inline-block") # Asset Library folder access div.add("<br clear='all'/>") asset_lib_div = DivWdg() div.add(asset_lib_div) folder_icon = IconWdg(icon="FOLDER_2", width='30px') asset_lib_div.add(folder_icon) asset_lib_div.add_style("margin: 5px 0px 5px -5px") asset_lib_div.add_style("height: 20px") asset_lib_div.add_style("padding-top: 5px") asset_lib_div.add_style("padding-bottom: 5px") asset_lib_div.add_style("font-weight: bold") asset_lib_div.add("Asset Library") asset_lib_div.add_class("tactic_hover") asset_lib_div.add_class("hand") asset_lib_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_collection_top"); var view_panel = top.getParent('.spt_view_panel'); spt.panel.refresh(view_panel); ''' } ) # Collections folder structure in the left panel search_type = my.kwargs.get('search_type') collections_div = CollectionFolderWdg(search_type=search_type) div.add(collections_div) return div
def get_collection_wdg(my): div = DivWdg() div.add_style("margin: 15px 0px") title_div = DivWdg("Collection Manager") div.add(title_div) div.add_class("spt_collection_left") title_div.add_style("font-size: 1.2em") title_div.add_style("font-weight: bold") div.add("<hr/>") # Shelf shelf_div = DivWdg() div.add(shelf_div) shelf_div.add_style("float: right") shelf_div.add_style("margin-bottom: 15px") #button = IconButtonWdg(title='Delete Selected Collection', icon="BS_TRASH") #shelf_div.add(button) #button.add_style("display: inline-block") #button.add_style("width: auto") button = IconButtonWdg(title='Add New Collection', icon="BS_PLUS") shelf_div.add(button) button.add_style("display: inline-block") button.add_style("vertical-align: top") insert_view = "edit_collection" button.add_behavior({ 'type': 'click_up', 'insert_view': insert_view, 'search_type': my.search_type, 'cbjs_action': ''' kwargs = { search_type: bvr.search_type, mode: 'insert', view: bvr.insert_view, save_event: bvr.event_name, show_header: false, num_columns: 2, default: { _is_collection: true } }; var popup = spt.panel.load_popup('Add New Collection', 'tactic.ui.panel.EditWdg', kwargs); ''' }) text_div = DivWdg() shelf_div.add(text_div) custom_cbk = {} custom_cbk['enter'] = ''' var top = bvr.src_el.getParent(".spt_collection_left"); var input = top.getElement(".spt_main_search"); var search_value = input.value.toLowerCase(); var collections = top.getElements(".spt_collection_div"); var num_result = 0; for (i = 0; i < collections.length; i++) { // Access the Collection title (without number count) var collection_title = collections[i].attributes[0].value.toLowerCase(); if (collection_title.indexOf(search_value) != '-1') { collections[i].style.display = "block"; num_result += 1; } else { collections[i].style.display = "none"; } } // if no search results, display all if (num_result == 0) { for (i = 0; i < collections.length; i++) { collections[i].style.display = "block"; } } ''' filters = [] filters.append(("_is_collection", True)) filters.append(("status", "Verified")) text = LookAheadTextInputWdg( search_type="workflow/asset", column="name", width="100%", height="30px", hint_text="Enter terms to filter collections...", value_column="name", filters=filters, custom_cbk=custom_cbk, is_collection=True) text.add_class("spt_main_search") text_div.add(text) text_div.add_style("width: 270px") text_div.add_style("display: inline-block") # Asset Library folder access div.add("<br clear='all'/>") asset_lib_div = DivWdg() div.add(asset_lib_div) folder_icon = IconWdg(icon="FOLDER_2", width='30px') asset_lib_div.add(folder_icon) asset_lib_div.add_style("margin: 5px 0px 5px -5px") asset_lib_div.add_style("height: 20px") asset_lib_div.add_style("padding-top: 5px") asset_lib_div.add_style("padding-bottom: 5px") asset_lib_div.add_style("font-weight: bold") asset_lib_div.add("Asset Library") asset_lib_div.add_class("tactic_hover") asset_lib_div.add_class("hand") asset_lib_div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_collection_top"); var view_panel = top.getParent('.spt_view_panel'); spt.panel.refresh(view_panel); ''' }) # Collections folder structure in the left panel search_type = my.kwargs.get('search_type') collections_div = CollectionFolderWdg(search_type=search_type) div.add(collections_div) return div
def get_header_wdg(my): div = DivWdg() if my.collection_key: button = IconButtonWdg( title='Remove Selected Items from Collection', icon="BS_MINUS") div.add(button) button.add_style("display: inline-block") button.add_style("vertical-align: top") button.add_behavior({ 'type': 'click_up', 'collection_key': my.collection_key, 'cbjs_action': ''' var search_keys = spt.table.get_selected_search_keys(false); var server = TacticServerStub.get(); if (search_keys.length == 0) { spt.notify.show_message("Nothing selected to remove"); return; } // default to false, if there is at least one collection selected, change to true var collection_selected = false; for (i=0; i<search_keys.length; i++){ var sobject = server.get_by_search_key(search_keys[i]); if (sobject._is_collection){ collection_selected = true; break; } } var ok = null; var cancel = function() { return }; var msg = "Are you sure you wish to remove the selected Assets from the Collection?"; var ok = function() { var cls = 'tactic.ui.panel.CollectionRemoveCmd'; var kwargs = { collection_key: bvr.collection_key, search_keys: search_keys, } try { server.execute_cmd(cls, kwargs); spt.table.remove_selected(); } catch(e) { spt.alert(spt.exception.handler(e)); } // Refresh left panel only if a collection is removed if (collection_selected) { var top = bvr.src_el.getParent(".spt_collection_top"); var collection_left = top.getElement(".spt_collection_left_side"); spt.panel.refresh(collection_left); } } spt.confirm(msg, ok, cancel); ''' }) button = IconButtonWdg(title='Delete Collection', icon="BS_TRASH") #button = ActionButtonWdg(title='Delete Collection', icon="BS_TRASH") div.add(button) button.add_style("display: inline-block") button.add_style("vertical-align: top") button.add_behavior({ 'type': 'click_up', 'collection_key': my.collection_key, 'cbjs_action': ''' var ok = null; var cancel = function() { return }; var msg = "Are you sure you wish to delete the Collection?"; var ok = function() { var cls = 'tactic.ui.panel.CollectionDeleteCmd'; var kwargs = { collection_key: bvr.collection_key, } var server = TacticServerStub.get(); try { server.execute_cmd(cls, kwargs); } catch(e) { spt.alert(e); return; } var top = bvr.src_el.getParent(".spt_collection_top"); if (top) { var layout = top.getParent(".spt_layout"); spt.table.set_layout(layout); } spt.table.run_search(); } spt.confirm(msg, ok, cancel); ''' }) """ button = IconButtonWdg(title='Download Selected Items', icon="BS_DOWNLOAD") div.add(button) button.add_style("display: inline-block") button.add_style("vertical-align: top") text_div = DivWdg() div.add(text_div) text_div.add_style("width: 200px") text = LookAheadTextInputWdg( name="name", icon="BS_SEARCH", icon_pos="right", width="100%" ) text_div.add(text) text_div.add_style("display: inline-block") """ div.add_style("width: auto") div.add_style("float: right") div.add("<br clear='all'/>") return div
def get_display(my): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_gradient("background", "background", 0, -5) #top.add_style("height: 550px") top.add_behavior({ 'type': 'load', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|hide_now", {} ); ''' }) project = Project.get() title = DivWdg() title.add("Project Startup and Configuration") title.add_style("font-size: 18px") title.add_style("font-weight: bold") title.add_style("text-align: center") title.add_style("padding: 10px") title.add_style("margin: -10px -10px 10px -10px") top.add(title) title.add_gradient("background", "background3", 5, -10) shelf = DivWdg() top.add(shelf) shelf.add_style("margin-left: -8px") shelf.add_style("width: 130px") button_div = DivWdg() shelf.add(button_div) button_div.add_style("float: left") button_div.add_style("margin-top: -3px") security = Environment.get_security() view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow') if view_side_bar: button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT) button_div.add(button) shelf.add("Toggle Side Bar") shelf.add_attr("title", "Toggle Side Bar (or press '1')") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' }) shelf.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' }) shelf.add_class("hand") else: shelf.add(" ") 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': 'result_list', 'keywords': keywords, 'simple_search_view': 'simple_filter', //'show_shelf': false, } spt.tab.set_main_body_tab(); spt.tab.add_new("Search Results", "Search Results", class_name, kwargs); } ''' from tactic.ui.input import TextInputWdg, LookAheadTextInputWdg #text = TextInputWdg(name="search") text = LookAheadTextInputWdg(name="search", custom_cbk=custom_cbk, width='280') #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': 'result_list', 'keywords': keywords, 'simple_search_view': 'simple_filter', //'show_shelf': false, } spt.tab.set_main_body_tab(); spt.tab.add_new("Search Results", "Search Results", class_name, kwargs); ''' }) #desc = DivWdg() #top.add(desc) #desc.add("Dashboard") #desc.add_style("width: 600px") # create a bunch of panels table = Table() table.add_color("color", "color") table.add_style("margin-bottom: 20px") table.center() top.add(table) table.add_row() #security = Environment.get_security() #if not security.check_access("builtin", "view_site_admin", "allow"): td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "Configuration" #description = '''All TACTIC projects can be uniquely designed and managed using our configuration tools.''' description = '''Configure a Project from start to finish.''' image = "<img src='/context/icons/64x64/configuration_64.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.startup.ProjectConfigWdg'; var kwargs = { help_alias: 'project-startup-configuration' }; spt.tab.add_new("project_configuration", "Configuration", class_name, kwargs); ''' } config_wdg = my.get_main_section_wdg(title, description, image, behavior) td.add(config_wdg) # Manage Users td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Manage Users and Security" image = "<img src='/context/icons/64x64/dashboard_64.png'/>" image = DivWdg() image_link = "<div style='margin-bottom: -64px'><img src='/context/icons/64x64/lock_64.png'/></div>" image.add(image_link) image1 = IconWdg("Manage Users", IconWdg.USER_32) image2 = IconWdg("Manage Users", IconWdg.USER_32) image3 = IconWdg("Manage Users", IconWdg.USER_32) image4 = IconWdg("Manage Users", IconWdg.USER_32) image.add(image1) image.add(image2) image.add("<br/>") image.add(image3) image.add(image4) description = '''Manage users that can access the system''' behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.startup.UserConfigWdg'; var kwargs = { help_alias: 'project-startup-manage-users' }; spt.tab.add_new("manage_user", "Manage Users", class_name, kwargs); ''' } manage_users_wdg = my.get_main_section_wdg(title, description, image, behavior) td.add(manage_users_wdg) # custom layout editor td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "Custom Layouts" description = '''Create interfaces using the Custom Layout Editor.''' image = "<img src='/context/icons/64x64/layout_64.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.tools.CustomLayoutEditWdg'; var kwargs = { help_alias: 'project-startup-configuration' }; spt.tab.add_new("custom_layout_editor", "Custom Layout Editor", class_name, kwargs); ''' } config_wdg = my.get_main_section_wdg(title, description, image, behavior) td.add(config_wdg) tr = table.add_row() # Plugins td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Plugin Manager" image = IconWdg("Plugins Manager", IconWdg.PLUGIN_32) #image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''Upload, install, remove and create TACTIC plugins.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.app.PluginWdg'; spt.tab.set_main_body_tab(); spt.tab.add_new("plugins", "Plugin Manager", class_name, kwargs); ''' } plugin_wdg = my.get_small_section_wdg(title, description, image, behavior) td.add(plugin_wdg) # Examples td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Tools" image = IconWdg("Tools", IconWdg.SHARE_32) #image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''A collection of example views.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.ToolsWdg'; spt.tab.set_main_body_tab(); spt.tab.add_new("tools", "Tools", class_name, kwargs); ''' } share_wdg = my.get_small_section_wdg(title, description, image, behavior) td.add(share_wdg) # Share """ td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Shares" image = IconWdg("Shares", IconWdg.SHARE_32) #image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''Share project with other TACTIC installs.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.ShareWdg'; spt.tab.set_main_body_tab(); spt.tab.add_new("shares", "Shares", class_name, kwargs); ''' } share_wdg = my.get_small_section_wdg(title, description, image, behavior) td.add(share_wdg) """ # Advanced td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Advanced Setup" image = IconWdg("Advanced", IconWdg.ADVANCED_32) #image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''A set of advanced configuration tools.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.app.ProjectStartWdg'; spt.tab.set_main_body_tab() spt.tab.add_new("project_setup", "Project Setup", class_name) ''' } share_wdg = my.get_small_section_wdg(title, description, image, behavior) td.add(share_wdg) """ td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Documentation" description = '''TACTIC Documentation. * Project Setup Documentation<br/> <br/> * End User Documentation<br/> <br/> * Developer Documentation<br/> <br/> * System Administrator Documentation<br/> <br/> ''' image = "<img src='/context/images/getting_started_pipeline.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.help.load_alias("main") ''' } doc_wdg = my.get_section_wdg(title, description, image, behavior) td.add(doc_wdg) """ tr, td = table.add_row_cell() td.add_style("font-size: 14px") td.add("<br/>") from misc_wdg import QuickLinksWdg quick_links_wdg = QuickLinksWdg() td.add(quick_links_wdg) #td = table.add_cell() #totals_wdg = my.get_totals_wdg() #td.add(totals_wdg) return top
def get_collection_wdg(my): div = DivWdg() div.add_style("margin: 15px 0px") title_div = DivWdg("Collection Manager") div.add(title_div) div.add_class("spt_collection_left") title_div.add_style("font-size: 1.2em") title_div.add_style("font-weight: bold") div.add("<hr/>") # Shelf shelf_div = DivWdg() div.add(shelf_div) shelf_div.add_style("float: right") shelf_div.add_style("margin-bottom: 15px") #button = IconButtonWdg(title='Delete Selected Collection', icon="BS_TRASH") #shelf_div.add(button) #button.add_style("display: inline-block") #button.add_style("width: auto") button = IconButtonWdg(title='Add New Collection', icon="BS_PLUS") shelf_div.add(button) button.add_style("display: inline-block") button.add_style("vertical-align: top") insert_view = "edit_collection" button.add_behavior({ 'type': 'click_up', 'insert_view': insert_view, 'search_type': my.search_type, 'cbjs_action': ''' kwargs = { search_type: bvr.search_type, mode: 'insert', view: bvr.insert_view, save_event: bvr.event_name, show_header: false, num_columns: 2, default: { _is_collection: true } }; var popup = spt.panel.load_popup('Add New Collection', 'tactic.ui.panel.EditWdg', kwargs); ''' }) text_div = DivWdg() shelf_div.add(text_div) custom_cbk = {} custom_cbk['enter'] = ''' var top = bvr.src_el.getParent(".spt_collection_left"); var input = top.getElement(".spt_main_search"); var search_value = input.value.toLowerCase(); var collections = top.getElements(".spt_collection_div"); var num_result = 0; for (i = 0; i < collections.length; i++) { // Access the Collection title (without number count) var collection_title = collections[i].attributes[0].value.toLowerCase(); if (collection_title.indexOf(search_value) != '-1') { collections[i].style.display = "block"; num_result += 1; } else { collections[i].style.display = "none"; } } // if no search results, display all if (num_result == 0) { for (i = 0; i < collections.length; i++) { collections[i].style.display = "block"; } } ''' filters = [] filters.append(("_is_collection", True)) filters.append(("status", "Verified")) text = LookAheadTextInputWdg( search_type="workflow/asset", column="name", width="100%", hint_text="Enter terms to filter collections...", value_column="name", filters=filters, custom_cbk=custom_cbk, is_collection=True) text.add_class("spt_main_search") text_div.add(text) text_div.add_style("width: 270px") text_div.add_style("display: inline-block") # Asset Library folder access div.add("<br clear='all'/>") asset_lib_div = DivWdg() div.add(asset_lib_div) folder_icon = IconWdg(icon="FOLDER_2", width='30px') asset_lib_div.add(folder_icon) asset_lib_div.add_style("margin: 5px 0px 5px -5px") asset_lib_div.add_style("height: 20px") asset_lib_div.add_style("padding-top: 5px") asset_lib_div.add_style("padding-bottom: 5px") asset_lib_div.add_style("font-weight: bold") asset_lib_div.add("Asset Library") asset_lib_div.add_class("tactic_hover") asset_lib_div.add_class("hand") asset_lib_div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_collection_top"); var content = top.getElements(".spt_collection_content"); spt.panel.refresh(top); ''' }) # collection search = Search(my.search_type) search.add_filter("_is_collection", True) collections = search.get_sobjects() collections_div = DivWdg() collections_div.add_class("spt_collection_list") div.add(collections_div) collections_div.add_style("margin: 5px 0px 5px -5px") from tactic.ui.panel import ThumbWdg2 parts = my.search_type.split("/") collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1]) collections_div.add_relay_behavior({ 'type': 'mouseup', 'search_type': my.search_type, 'collection_type': collection_type, 'bvr_match_class': 'spt_collection_item', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_collection_top"); var content = top.getElement(".spt_collection_content"); var list = bvr.src_el.getParent(".spt_collection_list"); var items = list.getElements(".spt_collection_item"); for (var i = 0; i < items.length; i++) { items[i].setStyle("background", ""); items[i].setStyle("box-shadow", ""); } bvr.src_el.setStyle("background", "#EEE"); var collection_key = bvr.src_el.getAttribute("spt_collection_key"); var collection_code = bvr.src_el.getAttribute("spt_collection_code"); var collection_path = bvr.src_el.getAttribute("spt_collection_path"); var expr = "@SEARCH("+bvr.collection_type+"['parent_code','"+collection_code+"']."+bvr.search_type+")"; var parent_dict = {}; var parent_collection = bvr.src_el.getParent(".spt_subcollection_wdg"); var path = collection_path.substring(0, collection_path.lastIndexOf("/")); if (parent_collection) { for (var i = 0; i < collection_path.split("/").length - 1; i++) { var n = path.lastIndexOf("/"); var collection_name = path.substring(n+1); path = path.substring(0, n); var parent_key = parent_collection.getAttribute("spt_parent_key"); parent_dict[collection_name] = parent_key; parent_collection = parent_collection.getParent(".spt_subcollection_wdg"); } } var cls = "tactic.ui.panel.CollectionContentWdg"; var kwargs = { collection_key: collection_key, path: collection_path, search_type: bvr.search_type, show_shelf: false, show_search_limit: true, expression: expr, parent_dict: parent_dict } spt.panel.load(content, cls, kwargs); bvr.src_el.setStyle("box-shadow", "0px 0px 3px rgba(0,0,0,0.5)"); // hide the bottom show_search_limit when clicking into a collection var panel = bvr.src_el.getParent(".spt_panel"); var search_limit_div = panel.getElements(".spt_search_limit_top"); if (search_limit_div.length == 2){ search_limit_div[1].setStyle("visibility", "hidden"); } ''' }) collections_div.add_relay_behavior({ 'type': 'mouseup', 'search_type': my.search_type, 'bvr_match_class': 'spt_collection_open', 'cbjs_action': ''' var item = bvr.src_el.getParent(".spt_collection_div_top"); var next = item.getNext(); if (bvr.src_el.hasClass("spt_open")) { next.innerHTML = ""; bvr.src_el.setStyle("opacity", 1.0); bvr.src_el.removeClass("spt_open"); } else { var collection_key = bvr.src_el.getAttribute("spt_collection_key"); var collection_path = bvr.src_el.getAttribute("spt_collection_path"); var cls = "tactic.ui.panel.CollectionListWdg"; var kwargs = { parent_key: collection_key, path: collection_path, } spt.panel.load(next, cls, kwargs, null, {show_loading: false}); bvr.src_el.setStyle("opacity", 0.3); bvr.src_el.addClass("spt_open"); evt.stopPropagation(); } ''' }) for collection in collections: collection_wdg = CollectionItemWdg( collection=collection, path=collection.get_value("name")) collections_div.add(collection_wdg) collection_wdg.add_class("spt_collection_div") subcollection_wdg = DivWdg() collections_div.add(subcollection_wdg) subcollection_wdg.add_class("spt_subcollection_wdg") subcollection_wdg.add_style("padding-left: 15px") return div
def get_display(my): top = my.top #help_div = DivWdg() help_div = top #top.add(help_div) help_div.add_class("spt_help_top") help_div.set_id("spt_help_top") show_title = my.kwargs.get("show_title") if show_title in [True, 'true']: show_title = True else: show_title = False if show_title: title_wdg = DivWdg() help_div.add(title_wdg) title_wdg.add_style("font-size: 12px") title_wdg.add_style("font-weight: bold") title_wdg.add_color("background", "background", -10) title_wdg.add_style("padding: 3px") #title_wdg.add_style("margin-top: 8px") title_wdg.add_style("margin-bottom: 5px") title_wdg.add_style("height: 26px") title_wdg.add_style("padding: 6 0 0 6") title_wdg.set_round_corners(corners=['TL','TR']) icon = IconWdg("Close", IconWdg.KILL) title_wdg.add(icon) icon.add_style("float: right") title_wdg.add("Help") help_div.set_round_corners() help_div.add_color("color", "color2") help_div.add_color("background", "background") help_div.add_style("overflow: hidden") help_div.add_border() shelf_div = DivWdg() help_div.add(shelf_div) shelf_div.add_style("padding: 10px") shelf_div.add_color("background", "background", -10) shelf_div.add_style("height: 25px") #button = SingleButtonWdg(title="Documentation Main Page", icon=IconWdg.HOME) button = IconButtonWdg(title="Documentation Main Page", icon="BS_HOME") shelf_div.add(button) button.add_style("float: left") button.add_style("margin: 0px 10px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_alias("main") ''' } ) #button = SingleButtonWdg(title="Edit Help", icon=IconWdg.EDIT) if my.show_add_new: button = IconButtonWdg(title="Add New Help", icon="BS_EDIT") shelf_div.add(button) button.add_style("float: left") button.add_style("margin: 0px 10px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.app.HelpEditWdg'; var element_name = spt.help.get_view(); if (!element_name) { element_name = "default"; } var kwargs = { view: element_name } spt.tab.add_new("help_edit", "Help Edit", class_name, kwargs); ''' } ) #button = SingleButtonWdg(title="Go Back One Page", icon=IconWdg.ARROW_LEFT) button = IconButtonWdg(title="Go Back One Page", icon="BS_CIRCLE_ARROW_LEFT") shelf_div.add(button) button.add_style("float: left") button.add_style("margin: 0px 10px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_prev(); ''' } ) #button = SingleButtonWdg(title="Go Forward One Page", icon=IconWdg.ARROW_RIGHT) button = IconButtonWdg(title="Go Forward One Page", icon="BS_CIRCLE_ARROW_RIGHT") shelf_div.add(button) button.add_style("float: left") button.add_style("margin: 0px 10px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_next(); ''' } ) #button = SingleButtonWdg(title="Documentation Downloads", icon=IconWdg.DOWNLOAD) button = IconButtonWdg(title="Documentation Downloads", icon="BS_DOWNLOAD") shelf_div.add(button) button.add_style("float: right") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.help.set_top(); spt.help.load_alias("pdf") ''' } ) shelf_div.add("<br clear='all'/>") help_div.add_behavior( { 'type': 'load', 'cbjs_action': my.get_onload_js() }) help_div.add_behavior( { 'type': 'listen', 'event_name': 'tab|select', 'cbjs_action': ''' var content = bvr.src_el.getElement(".spt_help_content"); var options = bvr.firing_data; var element_name = options.element_name; var alias = options.alias; if (!alias) { alias = options.element_name; } spt.help.set_top(); if (spt.help.is_visible()) { spt.help.load_alias(alias); } else { spt.help.set_view(alias); } ''' } ) help_div.add_behavior( { 'type': 'listen', 'event_name': 'show_help', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_help"); var content = top.getElement(".spt_help_content"); var firing_data = bvr.firing_data; var class_name = firing_data.class_name; if (!class_name) { class_name = 'tactic.ui.app.HelpContentWdg'; } if (top.getStyle("display") != 'none') { spt.hide(top); return; } spt.help.set_top() // get the help view var help_view = spt.help.get_view(); var html = firing_data.html; if (html) { spt.help.load_html(html); } else { if (!help_view) { help_view = 'default' } spt.help.load_alias(help_view); } var size = $(window).getSize(); var dialog = bvr.src_el.getParent(".spt_dialog_content"); dialog.setStyle("height", size.y - 100); dialog.setStyle("width", 650); var top = bvr.src_el.getParent(".spt_dialog_top"); top.setStyle("left", size.x - 660); top.setStyle("top", 40); spt.show(top); ''' } ) content = DivWdg() help_div.add(content) content.add_class("spt_help_content"); content.add_style("position: relative") content.add_style("overflow_x: auto") content.add_style("overflow_y: auto") content.add_style("margin-bottom: 10px") #content.add_style("border: solid 1px blue") content.add_style("height: 98%") #key = "schema_editor" #search = Search("config/doc") #search.add_filter("code", key) #doc = search.get_sobject() #doc_html = doc.get_value("doc") #help_div.add(doc_html) return top
def get_display(self): top = self.top self.set_as_panel(top) top.add_class("spt_ingestion_top") top.add_color("background", "background", -5) self.data = {} rules_div = DivWdg() top.add(rules_div) rules_div.add_style("padding: 10px") rules_div.add("Rules: ") rules_select = SelectWdg("rule_code") rule_code = self.get_value('rule_code') if rule_code: rules_select.set_value(rule_code) rules_select.set_option("query", "config/ingest_rule|code|title") rules_select.add_empty_option("-- New --") rules_div.add(rules_select) rules_select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var class_name = 'tactic.ui.tools.IngestionToolWdg'; spt.panel.load(top, class_name, {rule_code: value} ); ''' }) rules_div.add("<hr/>") # read from the database if rule_code: search = Search("config/ingest_rule") search.add_filter("code", rule_code) sobject = search.get_sobject() else: sobject = None if sobject: self.data = sobject.get_value("data") if self.data: self.data = jsonloads(self.data) session_code = self.kwargs.get("session_code") if session_code: session = Search.get_by_code("config/ingest_session", session_code) else: if sobject: session = sobject.get_related_sobject("config/ingest_session") print("sobject: ", sobject.get_code(), sobject.get_value("spt_ingest_session_code")) print("parent: ", session) else: session = None if not session: #session = SearchType.create("config/ingest_session") #session.set_value("code", "session101") #session.set_value("location", "local") ##session.set_value("base_dir", "C:") top.add("No session defined!!!") return top rule = "" filter = "" ignore = "" # get the base path if sobject: base_dir = sobject.get_value("base_dir") else: base_dir = '' #else: # base_dir = self.get_value("base_dir") #if not base_dir: # base_dir = '' if sobject: title = sobject.get_value("title") else: title = '' if sobject: code = sobject.get_value("code") else: code = '' file_list = self.get_value("file_list") scan_type = self.get_value("scan_type") action_type = self.get_value("action_type") rule = self.get_value("rule") if not rule: rule = base_dir # get the rule for this path checkin_mode = "dir" depth = 0 table = Table() rules_div.add(table) table.add_color("color", "color") from tactic.ui.input.text_input_wdg import TextInputWdg # add the title table.add_row() td = table.add_cell() td.add("Title: ") td = table.add_cell() text = TextInputWdg(name="title") td.add(text) if title: text.set_value(title) text.add_class("spt_title") text.add_style("width: 400px") #text.add_color("background", "background", -10) # add the optional code table.add_row() td = table.add_cell() td.add("Code (optional): ") td = table.add_cell() text = TextInputWdg(name="code") td.add(text) if code: text.set_value(code) text.set_readonly() text.add_color("background", "background", -10) text.add_class("spt_code") text.add_style("width: 400px") table.add_row() td = table.add_cell() td.add_style("height: 10px") td.add("<hr/>") table.add_row() td = table.add_cell() td.add("<b>Scan:</b><br/>") td.add( "The following information will be used to find the paths that will be operated on by the ingestion process<br/><br/>" ) # add a scan type table.add_row() td = table.add_cell() td.add("Type: ") select = SelectWdg("scan_type") select.add_class("spt_scan_type") td = table.add_cell() td.add(select) select.set_value(self.get_value("action")) labels = ['Simple List', 'Rule', 'Script'] values = ['list', 'rule', 'script'] select.set_option("values", values) select.set_option("labels", labels) if scan_type: select.set_value(scan_type) table.add_row() table.add_cell(" ") select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var elements = top.getElements(".spt_scan_list"); for (var i = 0; i < elements.length; i++) { if (value == 'list') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_scan_rule"); for (var i = 0; i < elements.length; i++) { if (value == 'rule') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_scan_script"); for (var i = 0; i < elements.length; i++) { if (value == 'script') spt.show(elements[i]); else spt.hide(elements[i]); } ''' }) # add in a list of stuff tbody = table.add_tbody() tbody.add_class("spt_scan_list") if scan_type != 'list': tbody.add_style("display: none") tr = table.add_row() td = table.add_cell() td.add("List of files: ") td = table.add_cell() text = TextAreaWdg(name="file_list") td.add(text) text.add_style("width: 400px") #text.set_readonly() #text.add_color("background", "background", -10) text.set_value(file_list) table.close_tbody() # add rule scan mode tbody = table.add_tbody() tbody.add_class("spt_scan_rule") if scan_type != 'rule': tbody.add_style("display: none") # add the path tr = table.add_row() td = table.add_cell() td.add("Starting Path: ") td = table.add_cell() hidden = HiddenWdg("session_code", session.get_code()) td.add(hidden) text = TextInputWdg(name="base_dir") td.add(text) text.set_value(base_dir) text.add_style("width: 400px") #text.set_readonly() #text.add_color("background", "background", -10) text.set_value(base_dir) # add rule tr = table.add_row() td = table.add_cell() td.add("Tag Rule: ") td = table.add_cell() text = TextInputWdg(name="rule") td.add(text) text.add_style("width: 400px") text.set_value(rule) tr = table.add_row() td = table.add_cell() td.add("Filter: ") td = table.add_cell() text = TextWdg("filter") td.add(text) text.set_value(self.get_value("filter")) text.add_style("width: 400px") text.add_style("padding: 2px") text.add_style("-moz-border-radius: 5px") tr = table.add_row() td = table.add_cell() td.add("Ignore: ") td = table.add_cell() text = TextWdg("ignore") td.add(text) text.set_value(self.get_value("ignore")) text.set_value(ignore) text.add_style("width: 400px") text.add_style("padding: 2px") text.add_style("-moz-border-radius: 5px") table.add_row() td = table.add_cell() td.add("Validation script: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextInputWdg(name="validation_script") text.set_value(self.get_value("validation_script")) text.add_style("width: 400px") td.add(text) icon = IconButtonWdg(title='Edit Validation Script', icon=IconWdg.EDIT) icon.add_style("float: right") td.add(icon) icon.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("show_script_editor"); var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); var kwargs = { script_path: values.validation_script } setTimeout( function() { spt.js_edit.display_script_cbk(evt, kwargs) }, 500 ); ''' }) table.close_tbody() # add the script path tbody = table.add_tbody() tbody.add_class("spt_scan_script") if scan_type != 'script': tbody.add_style("display: none") tr = table.add_row() td = table.add_cell() td.add("Script Path: ") td = table.add_cell() text = TextInputWdg(name="script_path") td.add(text) text.add_style("width: 400px") table.close_tbody() table.add_row() td = table.add_cell("<hr/>") table.add_row() td = table.add_cell() td.add("<b>Action</b><br/>") td.add( "The following information define the actions that will be used on each matched path<br/><br/>" ) # pick the type of action table.add_row() td = table.add_cell() td.add("Type: ") select = SelectWdg("action_type") td = table.add_cell() td.add(select) labels = ['Checkin', 'Ignore'] values = ['checkin', 'ignore'] select.set_option("values", values) select.set_option("labels", labels) select.add_empty_option("-- Select --") if action_type: select.set_value(action_type) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); value = bvr.src_el.value; var elements = top.getElements(".spt_action_ignore"); for (var i = 0; i < elements.length; i++) { if (value == 'ignore') spt.show(elements[i]); else spt.hide(elements[i]); } var elements = top.getElements(".spt_action_checkin"); for (var i = 0; i < elements.length; i++) { if (value == 'checkin') spt.show(elements[i]); else spt.hide(elements[i]); } ''' }) table.add_row() td = table.add_cell("<br/>") # add the script path tbody = table.add_tbody() tbody.add_class("spt_action_checkin") if action_type != 'checkin': tbody.add_style("display: none") # add the checkin type table.add_row() td = table.add_cell() td.add("Action: ") select = SelectWdg("action") td = table.add_cell() td.add(select) select.set_value(self.get_value("action")) labels = ['File Checkin', 'Directory Checkin', 'Sequence Checkin'] values = ['file', 'directory', 'sequence', 'ignore'] select.set_option("values", values) select.set_option("labels", labels) table.add_row() td = table.add_cell() td.add("Mode: ") select = SelectWdg("mode") td = table.add_cell() td.add(select) labels = ['Copy', 'Move', 'In Place'] values = ['copy', 'move', 'inplace'] select.set_option("values", values) select.set_option("labels", labels) # add the search_type table.add_row() td = table.add_cell() td.add("sType: ") td = table.add_cell() select = SelectWdg("search_type") td.add(select) search_types = Project.get().get_search_types() values = [x.get_value("search_type") for x in search_types] select.set_option("values", values) search_type = self.kwargs.get("search_type") if search_type: select.set_value(search_type) # add the search_type table.add_row() td = table.add_cell() td.add("Context: ") td = table.add_cell() select = SelectWdg("context") td.add(select) select.set_option("values", ['publish', 'by rule', 'custom']) # add extra values extra_div = DivWdg() text = TextWdg("extra_name") text.add_attr("spt_is_multiple", "true") extra_div.add(text) extra_div.add(" = ") text = TextWdg("extra_value") extra_div.add(text) text.add_attr("spt_is_multiple", "true") template_div = DivWdg() text = TextWdg("extra_name") text.add_attr("spt_is_multiple", "true") template_div.add(text) template_div.add(" = ") text = TextWdg("extra_value") template_div.add(text) text.add_attr("spt_is_multiple", "true") table.close_tbody() table.add_row() td = table.add_cell("<br/>") table.add_row() td = table.add_cell() td.add("Extra Keywords: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("keywords") text.add_style("width: 300px") td.add(text) table.add_row() td = table.add_cell() td.add("Extra Values: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() extra_list = DynamicListWdg() td.add(extra_list) extra_list.add_item(extra_div) extra_list.add_template(template_div) table.add_row() table.add_cell(" ") table.add_row() td = table.add_cell() td.add("Process script: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("process_script") text.add_style("width: 300px") td.add(text) text.set_value(self.get_value("process_script")) icon = IconButtonWdg(title='Edit Process Script', icon=IconWdg.EDIT) icon.add_style("float: right") td.add(icon) icon.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("show_script_editor"); var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); var kwargs = { script_path: values.process_script } // need to wait for this setTimeout( function() { spt.js_edit.display_script_cbk(evt, kwargs) }, 500 ); ''' }) table.add_row() td = table.add_cell() td.add("Custom Naming: ") td.add_style("vertical-align: top") td.add_style("padding-top: 5px") td = table.add_cell() text = TextWdg("naming") text.add_style("width: 300px") td.add(text) table.add_row() td = table.add_cell() #td.add("<br clear='all'/>") td.add("<hr/>") behavior = { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); spt.app_busy.show("Scanning ...", values.base_dir); var class_name = 'tactic.ui.tools.IngestionProcessWdg'; var server = TacticServerStub.get(); values.mode = bvr.mode; values.is_local = 'true'; // scan client side if (values.is_local == 'true') { var base_dir = values.base_dir; var applet = spt.Applet.get(); var files = applet.list_recursive_dir(base_dir); // turn into a string var files_in_js = []; for (var i = 0; i < files.length; i++) { var file = files[i].replace(/\\\\/g, "/"); files_in_js.push( file ); } values.files = files_in_js; values.base_dir = base_dir; /* var server = TacticServerStub.get(); var handoff_dir = server.get_handoff_dir(); var applet = spt.Applet.get(); for (var i = 0; i < files_in_js.length; i++) { try { var parts = files_in_js[i].split("/"); var filename = parts[parts.length-1]; spt.app_busy.show("Copying files to handoff", filename); applet.copy_file(files_in_js[i], handoff_dir+"/"+filename); } catch(e) { log.error(e); } } */ } var info_el = top.getElement(".spt_info"); spt.panel.load(info_el, class_name, values); spt.app_busy.hide(); ''' } # Save button button = ActionButtonWdg(title="Save", tip="Save Rule") td.add(button) button.add_style("float: right") behavior['mode'] = 'save' button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var values = spt.api.Utility.get_input_values(top, null, false); spt.app_busy.show("Saving ..."); var class_name = 'tactic.command.CheckinRuleSaveCmd'; var server = TacticServerStub.get(); server.execute_cmd(class_name, values); spt.panel.refresh(top, {}); spt.app_busy.hide(); ''' }) # Scan button button = ActionButtonWdg(title="Scan", tip="Click to Scan") td.add(button) button.add_style("float: left") # set a limit #limit = TextWdg("limit") #td.add(limit) #text.add_style("float: left") behavior = behavior.copy() behavior['mode'] = 'scan' button.add_behavior(behavior) # Test button button = ActionButtonWdg(title="Test", tip="Do a test of this rule") td.add(button) behavior = behavior.copy() behavior['mode'] = 'test' button.add_behavior(behavior) button.add_style("float: left") # Ingest button button = ActionButtonWdg(title="Ingest", tip="Click to start ingesting") td.add(button) behavior = behavior.copy() behavior['mode'] = 'checkin' button.add_behavior(behavior) table.add_behavior({ 'type': 'listen', 'event_name': 'file_browser|select', 'cbjs_action': ''' var dirname = bvr.firing_data.dirname; var top = bvr.src_el.getParent(".spt_ingestion_top"); var kwargs = { base_dir: dirname }; spt.panel.load(top, top.getAttribute("spt_class_name"), kwargs); ''' }) top.add(self.get_info_wdg()) return top
def get_display(my): my.doc_mode = my.kwargs.get("doc_mode") path = my.kwargs.get("path") my.search_type = my.kwargs.get("search_type") my.last_path = None doc_key = my.kwargs.get("doc_key") if doc_key: my.doc = Search.get_by_search_key(doc_key) snapshot = Snapshot.get_latest_by_sobject(my.doc) if snapshot: my.last_path = snapshot.get_lib_path_by_type('main') path = my.doc.get_value("link") # TEST TEST TEST if not path: #path = "/home/apache/pdf/mongodb.txt" #path = "/home/apache/assets/google_docs.html" #path = "/home/apache/pdf/star_wars.txt" path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true" path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub" #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html" path = "/home/apache/tactic/doc/alias.json" if not my.search_type: my.search_type = "test3/shot" my.column = "description" top = my.top top.add_class("spt_document_top") my.set_as_panel(top) #table = Table() table = ResizableTableWdg() top.add(table) table.add_row() table.set_max_width() left_td = table.add_cell() left_td.add_style("vertical-align: top") title = DivWdg() left_td.add(title) title.add_style("padding: 10px") title.add_color("background", "background3") button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH) title.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); spt.panel.refresh(top); spt.app_busy.hide(); ''' }) button.add_style("float: left") button = IconButtonWdg(title="Save", icon=IconWdg.SAVE) title.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' ''' }) button.add_style("float: left") if not my.doc_mode: my.doc_mode = "text" select = SelectWdg("doc_mode") select.set_option("values", "text|formatted") title.add(select) select.set_value(my.doc_mode) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' spt.app_busy.show("Reloading Document"); var top = bvr.src_el.getParent(".spt_document_top"); var value = bvr.src_el.value; top.setAttribute("spt_doc_mode", value); spt.panel.refresh(top); spt.app_busy.hide(); ''' }) title.add("<br clear='all'/>") #title.add(path) text_wdg = DivWdg() text_wdg.add_class("spt_document_content") left_td.add(text_wdg) #if path.startswith("https://docs.google.com/spreadsheet"): # #path = "http://www.southpawtech.com.com" # text_wdg.add(''' # <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe> # ''' % path) # text_wdg.add_style("overflow-x: hidden") if True: if not my.last_path and my.doc: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') text = my.get_text(path, highlight=False) f.write(text) f.close() cmd = FileCheckin(my.doc, tmp_path) Command.execute_cmd(cmd) else: save = False if save: # open up the last path f = open(my.last_path, 'r') last_text = f.read() text = my.get_text(path, None, highlight=False) if last_text != text: tmp_dir = Environment.get_tmp_dir() tmp_path = '%s/last_path.txt' % tmp_dir f = open(tmp_path, 'w') f.write(text) f.write(text) f.close() cmd = FileCheckin(my.doc, tmp_path) Command.execute_cmd(cmd) text = my.get_text(path, my.last_path) lines = text.split("\n") if my.doc_mode == "text": num_lines = len(lines) """ line_div = HtmlElement.pre() text_wdg.add(line_div) line_div.add_style("width: 20px") line_div.add_style("float: left") line_div.add_style("text-align: right") line_div.add_style("opacity: 0.3") line_div.add_style("padding-right: 10px") for i in range(0, num_lines*2): line_div.add(i+1) line_div.add("<br/>") """ if my.doc_mode == "text": pre = HtmlElement.pre() pre.add_style("white-space: pre-wrap") else: pre = DivWdg() pre = DivWdg() text_wdg.add(pre) text_wdg.add_style("padding: 10px 5px") text_wdg.add_style("max-height: 600px") text_wdg.add_style("overflow-y: auto") text_wdg.add_style("width: 600px") text_wdg.add_class("spt_resizable") pre.add_style("font-family: courier") if my.doc_mode == "formatted": pre.add(text) else: line_table = Table() pre.add(line_table) line_table.add_style("width: 100%") count = 1 for line in lines: #line = line.replace(" ", " ") tr = line_table.add_row() if count % 2 == 0: tr.add_color("background", "background", -2) td = line_table.add_cell() # FIXME: hacky if line.startswith('''<span style='background: #CFC'>'''): is_new = True else: td.add_style("vertical-align: top") text = TextWdg() text.add_style("border", "none") text.add_style("text-align", "right") text.add_style("width", "25px") text.add_style("margin", "0 10 0 0") text.add_style("opacity", "0.5") text.set_value(count) td.add(text) count += 1 is_new = False td = line_table.add_cell() if not is_new: SmartMenu.assign_as_local_activator(td, 'TEXT_CTX') tr.add_class("spt_line") else: SmartMenu.assign_as_local_activator(td, 'TEXT_NEW_CTX') tr.add_class("spt_new_line") td.add_class("spt_line_content") td.add(line) #from tactic.ui.app import AceEditorWdg #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px") #text_wdg.add(editor) # add a click on spt_item text_wdg.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_document_item', 'search_type': my.search_type, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_document_top"); var data_el = top.getElement(".spt_document_data"); var search_key = bvr.src_el.getAttribute("spt_search_key"); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': bvr.search_type, 'search_key': search_key, } spt.panel.load(data_el, class_name, kwargs); ''' }) # add a double click on spt_item bgcolor = text_wdg.get_color("background", -10) text_wdg.add_relay_behavior({ 'type': 'mouseover', 'bvr_match_class': 'spt_document_item', 'search_type': my.search_type, 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "normal"); bvr.src_el.setStyle("background", bvr.bgcolor); ''' }) # add a double click on spt_item text_wdg.add_relay_behavior({ 'type': 'mouseout', 'bvr_match_class': 'spt_document_item', 'search_type': my.search_type, 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); //bvr.src_el.setStyle("font-weight", "bold"); bvr.src_el.setStyle("background", ""); ''' }) # add a context menu ctx_menu = my.get_text_context_menu() ctx_new_menu = my.get_text_new_context_menu() menus_in = { 'TEXT_CTX': ctx_menu, 'TEXT_NEW_CTX': ctx_new_menu, } SmartMenu.attach_smart_context_menu(text_wdg, menus_in, False) panel = ViewPanelWdg(search_type=my.search_type, layout="blah") right_td = table.add_cell() right_td.add_style("vertical-align: top") panel_div = DivWdg() panel_div.add_class("spt_document_data") right_td.add(panel_div) panel_div.add(panel) text_wdg.add_behavior({ 'type': 'load', 'cbjs_action': r''' spt.document = {}; spt.document.selected_text = null; spt.document.get_selected_text = function(frame) { var t = ''; if (frame) { var rng = frame.contentWindow.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (window.getSelection) // FF4 with one tab open? { var rng = window.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.getSelection) // FF4 with multiple tabs open? { var rng = document.getSelection().getRangeAt(0); spt.document.expandtoword(rng); t = rng.toString(); } else if (document.selection) // IE8 { var rng = document.selection.createRange(); // expand range to enclose any word partially enclosed in it rng.expand("word"); t = rng.text; } // convert newline chars to spaces, collapse whitespace, and trim non-word chars return t.replace(/^\W+|\W+$/g, ''); //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, ''); } // expand FF range to enclose any word partially enclosed in it spt.document.expandtoword = function(range) { if (range.collapsed) { return; } while (range.startOffset > 0 && range.toString()[0].match(/\w/)) { range.setStart(range.startContainer, range.startOffset - 1); } while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/)) { range.setEnd(range.endContainer, range.endOffset + 1); } } ''' }) top.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_document_content', 'cbjs_action': r''' //spt.ace_editor.set_editor_top(bvr.src_el); //var text = spt.ace_editor.get_selection(); var text = spt.document.get_selected_text(); text = text.replace(/\n\n/mg, "\n"); text = text.replace(/\n\n/mg, "\n"); spt.document.selected_text = text + ""; ''' }) return top
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") button.add_styles('float: right; padding: 2px') button_div = DivWdg(button) button_div.add_style('min-height: 26px') div.add(button_div) button.add_behavior( { 'type': 'click_up', 'search_keys': search_keys, 'cbjs_action': ''' var server = TacticServerStub.get(); for (var i = 0; i < bvr.search_keys.length; i++) { var search_key = bvr.search_keys[i]; server.update(search_key, {'last_cleared':'NOW'}); spt.panel.refresh(bvr.src_el); } ''' } ) # types of subscriptions table_div = DivWdg() table_div.add_styles('overflow-y: auto; max-height: 500px; width: 100%') div.add(table_div) table = Table() table.add_style('width: 100%') table.add_border() table.add_color("background", "background3") table_div.add(table) ss = [] for subscription in subscriptions: table.add_row() td = table.add_cell() message_code = subscription.get_value("message_code") search = Search("sthpw/message") search.add_filter("code", message_code) message = search.get_sobject() # show the thumb if not message: if mode == "all": td = table.add_cell(FormatMessageWdg.get_preview_wdg(subscription)) td = table.add_cell() td.add("No Messages") continue size = 60 show_preview = my.kwargs.get('show_preview') if show_preview in ['',None]: show_preview = True msg_element = FormatMessageWdg(subscription=subscription, short_format='true',show_preview=show_preview) # this is optional msg_element.set_sobject(message) description = msg_element.get_buffer_display() #td = table.add_cell() history_icon = IconButtonWdg(title="Subscription History", icon=IconWdg.HISTORY) #td.add(icon) message_code = subscription.get_value("message_code") history_icon.add_behavior( { 'type': 'click_up', 'message_code': message_code, 'cbjs_action': ''' var class_name = 'tactic.ui.panel.FastTableLayoutWdg'; var message_code = bvr.message_code; var kwargs = { search_type: 'sthpw/message_log', show_shelf: false, expression: "@SOBJECT(sthpw/message_log['message_code','"+message_code+"'])", view: 'history' }; spt.tab.set_main_body_tab(); spt.tab.add_new("Message History", "Message History", class_name, kwargs); ''' } ) # description can take up 70% td = table.add_cell() td.add_style("width: %spx"%(SubscriptionBarWdg.WIDTH*0.7)) desc_div = DivWdg() td.add(desc_div) desc_div.add(description) desc_div.add_style("padding: 0px 20px") td = table.add_cell() #td.add(message.get_value("status")) #td = table.add_cell() timestamp = message.get_datetime_value("timestamp") if timestamp: timestamp_str = timestamp.strftime("%b %d, %Y - %H:%M") else: timestamp_str = "" show_timestamp = my.kwargs.get('show_timestamp') if show_timestamp in ['',None]: show_timestamp = True if show_timestamp in ["True","true",True]: td.add(timestamp_str) #td = table.add_cell() #td.add(subscription.get_value("last_cleared")) td = table.add_cell() show_message_history = my.kwargs.get('show_message_history') if show_message_history in ['',None]: show_message_history = True if show_message_history in ["True","true",True]: td.add(history_icon) td.add(HtmlElement.br(2)) td.add_style('width: 30px') icon = IconButtonWdg(title="Unsubscribe", icon=IconWdg.DELETE) icon.add_style('bottom: 14px') subscription_key = subscription.get_search_key() icon.add_behavior( { 'type': 'click_up', 'search_key': subscription_key, 'message_code': message_code, 'cbjs_action': ''' if (!confirm("Unsubscribe from [" + bvr.message_code + "]?")) { return; } var top = bvr.src_el.getParent(".spt_subscription_top"); var server = TacticServerStub.get(); server.delete_sobject(bvr.search_key); spt.panel.refresh(top); ''' } ) show_unsubscribe = my.kwargs.get('show_unsubscribe') if show_unsubscribe in ['',None]: show_unsubscribe = False if show_unsubscribe in ["True","true",True]: td.add(icon) ss.append(subscription) num_sobjects = len(ss) if not num_sobjects: return None summary_div.add("(%s changes)" % num_sobjects) #from tactic.ui.panel import FastTableLayoutWdg #table = FastTableLayoutWdg(search_type="sthpw/subscription",show_shelf=False) #div.add(table) #table.set_sobjects(ss) return div
def get_chat_wdg(self, key, interval=False): div = DivWdg() div.add_class("spt_chat_session_top") div.add_color("background", "background") title_wdg = DivWdg() div.add(title_wdg) title_wdg.add_color("background", "background3") title_wdg.add_style("padding: 5px") title_wdg.add_style("font-weight: bold") title_wdg.add_border() icon = IconButtonWdg(title="Remove Chat", icon=IconWdg.DELETE) icon.add_style("float: right") icon.add_style("margin-top: -5px") title_wdg.add(icon) icon.add_behavior( { 'type': 'click_up', 'key': key, 'cbjs_action': ''' var server = TacticServerStub.get(); var top = bvr.src_el.getParent(".spt_chat_session_top"); spt.behavior.destroy_element(top); ''' } ) current_user = Environment.get_user_name() logins = Search.eval("@SOBJECT(sthpw/subscription['message_code','%s'].sthpw/login)" % key) for login in logins: if login.get_value("login") == current_user: continue thumb = ThumbWdg() thumb.set_icon_size(45) thumb.set_sobject(login) thumb.add_style("float: left") thumb.add_style("margin: -5px 10px 0px -5px") title_wdg.add(thumb) title_wdg.add(login.get_value("display_name")) title_wdg.add("<br clear='all'/>") history_div = DivWdg() div.add(history_div) history_div.add_class("spt_chat_history") history_div.add_style("width: auto") history_div.add_style("height: auto") history_div.add_style("max-height: 400px") history_div.add_style("padding: 5px") history_div.add_class("spt_resizable") history_div.add_border() history_div.add_style("overflow-y: auto") #history_div.add_style("font-size: 0.9em") search = Search("sthpw/message_log") search.add_filter("message_code", key) search.add_order_by("timestamp") message_logs = search.get_sobjects() last_login = None; last_date = None; for message_log in message_logs: login = message_log.get("login") message = message_log.get("message") timestamp = message_log.get_datetime_value("timestamp") #timestamp = timestamp.strftime("%b %d, %Y - %H:%M") timestamp_str = timestamp.strftime("%H:%M") date_str = timestamp.strftime("%b %d, %Y") if login != last_login: table = Table() history_div.add(table) table.add_row() table.add_style("width: 100%") table.add_style("margin-top: 15px") login_sobj = Search.get_by_code("sthpw/login", login) thumb_div = DivWdg() td = table.add_cell() td.add_style("vertical-align: top") td.add_style("width: 75px") thumb_div = DivWdg() td.add(thumb_div) thumb_div.add_style("overflow: hidden") thumb = ThumbWdg() thumb_div.add(thumb) thumb.set_sobject(login_sobj) thumb.set_icon_size(60) display_name = login_sobj.get("display_name") td = table.add_cell() td.add_style("padding-top: 3px") name_div = DivWdg() td.add(name_div) name_div.add_style("color", "#214e75") name_div.add_style("font-size", "1.3em") name_div.add(display_name) msg = ""; msg += "<table style='margin-top: 5px; font-size: 1.0em; width: 100%'>"; if date_str != last_date: msg += "<tr><td colspan='2' style='text-align: right'><br/><b style='font-size: 1.0em'>"+date_str+"</b></td></tr>"; last_login = None msg += "<tr><td>" msg += message.replace("\n",'<br/>') msg += "</td><td style='vertical-align: top; text-align: right; margin-bottom: 5px; width: 75px; vertical-align: top; opacity: 0.7;'>"; msg += timestamp_str; msg += "</td></tr></table>"; td.add(msg) last_login = login last_date = date_str history_div.add_behavior( { 'type': 'load', 'cbjs_action': ''' bvr.src_el.scrollTop = bvr.src_el.scrollHeight; ''' } ) if message_logs: last_message = message_logs[-1].get("message") last_login = message_logs[-1].get("login") else: last_message = "" last_login = "" div.add_attr("spt_last_message", last_message) div.add_attr("spt_last_login", last_login) if interval: div.add_behavior( { 'type': 'load', 'key': key, 'cbjs_action': r''' var text_el = bvr.src_el.getElement(".spt_chat_text"); var history_el = bvr.src_el.getElement(".spt_chat_history"); var callback = function(message) { //history_el.setStyle("background", "red"); var login = message.login; var timestamp = message.timestamp; if (timestamp) { var parts = timestamp.split(" "); parts = parts[1].split("."); timestamp = parts[0]; } else { timestamp = ""; } var tmp = message.message || ""; var last_message = bvr.src_el.getAttribute("spt_last_message"); var last_login = bvr.src_el.getAttribute("spt_last_login"); if (tmp == last_message && login == last_login) { return; } bvr.src_el.setAttribute("spt_last_message", tmp); bvr.src_el.setAttribute("spt_last_login", login); var msg = ""; msg += "<table style='margin-top: 5px; font-size: 1.0em; width: 100%'><tr><td>"; if (login != last_login) { msg += "<b>"+login+"</b><br/>"; } msg += tmp.replace(/\n/g,'<br/>'); msg += "</td><td style='text-align: right; margin-bottom: 5px; width: 75px; vertical-align: top'>"; msg += timestamp; msg += "</td></tr></table>"; if (msg == history_el.last_msg) { return; } history_el.innerHTML = history_el.innerHTML + msg; // remember last message history_el.last_msg = msg; history_el.scrollTop = history_el.scrollHeight; } spt.message.set_interval(bvr.key, callback, 3000, bvr.src_el); ''' } ) text = TextAreaWdg("chat") div.add(text) text.add_class("spt_chat_text") text.add_style("width: 100%") text.add_style("padding: 5px") #text.add_style("margin-top: -1px") text.add_style("margin-top: 5px") text.add_behavior( { 'type': 'load', 'cbjs_action': ''' bvr.src_el.addEvent("keydown", function(e) { var keys = ['tab','keys(control+enter)', 'enter']; var key = e.key; var input = bvr.src_el if (keys.indexOf(key) > -1) e.stop(); if (key == 'tab') { } else if (key == 'enter') { if (e.control == false) { pass; } else { // TODO: check if it's multi-line first //... use ctrl-ENTER for new-line, regular ENTER (RETURN) accepts value //var tvals = parse_selected_text(input); //input.value = tvals[0] + "\\n" + tvals[1]; //spt.set_cursor_position( input, tvals[0].length + 1 ); } } } ) ''' } ) button = ActionButtonWdg(title="Send") div.add(button) button.add_style("float: right") button.add_style("margin: 5px") button.add_behavior( { 'type': 'click_up', 'key': key, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_chat_session_top"); var text_el = top.getElement(".spt_chat_text"); var message = text_el.value; if (!message) { return; } var history_el = top.getElement(".spt_chat_history"); var category = "chat"; var server = TacticServerStub.get(); var key = bvr.key; var last_message = server.log_message(key, message, {category:category, status:"in_progress"}); text_el.value = ""; ''' } ) div.add("<br clear='all'/>") return div
def get_collection_wdg(my): div = DivWdg() div.add_style("margin: 15px 0px") title_div = DivWdg("Collection Manager") div.add(title_div) div.add_class("spt_collection_left") title_div.add_style("font-size: 1.2em") title_div.add_style("font-weight: bold") div.add("<hr/>") # Shelf shelf_div = DivWdg() div.add(shelf_div) shelf_div.add_style("float: right") shelf_div.add_style("margin-bottom: 15px") #button = IconButtonWdg(title='Delete Selected Collection', icon="BS_TRASH") #shelf_div.add(button) #button.add_style("display: inline-block") #button.add_style("width: auto") button = IconButtonWdg(title='Add New Collection', icon="BS_PLUS") shelf_div.add(button) button.add_style("display: inline-block") button.add_style("vertical-align: top") insert_view = "edit_collection" button.add_behavior( { 'type': 'click_up', 'insert_view': insert_view, 'search_type': my.search_type, 'cbjs_action': ''' kwargs = { search_type: bvr.search_type, mode: 'insert', view: bvr.insert_view, save_event: bvr.event_name, show_header: false, num_columns: 2, default: { _is_collection: true } }; var popup = spt.panel.load_popup('Add New Collection', 'tactic.ui.panel.EditWdg', kwargs); ''' } ) text_div = DivWdg() shelf_div.add(text_div) custom_cbk = {} custom_cbk['enter'] = ''' var top = bvr.src_el.getParent(".spt_collection_left"); var input = top.getElement(".spt_main_search"); var search_value = input.value.toLowerCase(); var collections = top.getElements(".spt_collection_div"); var num_result = 0; for (i = 0; i < collections.length; i++) { // Access the Collection title (without number count) var collection_title = collections[i].attributes[0].value.toLowerCase(); if (collection_title.indexOf(search_value) != '-1') { collections[i].style.display = "block"; num_result += 1; } else { collections[i].style.display = "none"; } } // if no search results, display all if (num_result == 0) { for (i = 0; i < collections.length; i++) { collections[i].style.display = "block"; } } ''' filters = [] filters.append(("_is_collection",True)) filters.append(("status","Verified")) text = LookAheadTextInputWdg( search_type = "workflow/asset", column="name", width="100%", hint_text="Enter terms to filter collections...", value_column="name", filters=filters, custom_cbk=custom_cbk, is_collection=True ) text.add_class("spt_main_search") text_div.add(text) text_div.add_style("width: 270px") text_div.add_style("display: inline-block") # Asset Library folder access div.add("<br clear='all'/>") asset_lib_div = DivWdg() div.add(asset_lib_div) folder_icon = IconWdg(icon="FOLDER_2", width='30px') asset_lib_div.add(folder_icon) asset_lib_div.add_style("margin: 5px 0px 5px -5px") asset_lib_div.add_style("height: 20px") asset_lib_div.add_style("padding-top: 5px") asset_lib_div.add_style("padding-bottom: 5px") asset_lib_div.add_style("font-weight: bold") asset_lib_div.add("Asset Library") asset_lib_div.add_class("tactic_hover") asset_lib_div.add_class("hand") asset_lib_div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_collection_top"); var content = top.getElements(".spt_collection_content"); spt.panel.refresh(top); ''' } ) # collection search = Search(my.search_type) search.add_filter("_is_collection", True) collections = search.get_sobjects() collections_div = DivWdg() collections_div.add_class("spt_collection_list") div.add(collections_div) collections_div.add_style("margin: 5px 0px 5px -5px") from tactic.ui.panel import ThumbWdg2 parts = my.search_type.split("/") collection_type = "%s/%s_in_%s" % (parts[0], parts[1], parts[1]) collections_div.add_relay_behavior( { 'type': 'mouseup', 'search_type': my.search_type, 'collection_type': collection_type, 'bvr_match_class': 'spt_collection_item', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_collection_top"); var content = top.getElement(".spt_collection_content"); var list = bvr.src_el.getParent(".spt_collection_list"); var items = list.getElements(".spt_collection_item"); for (var i = 0; i < items.length; i++) { items[i].setStyle("background", ""); items[i].setStyle("box-shadow", ""); } bvr.src_el.setStyle("background", "#EEE"); var collection_key = bvr.src_el.getAttribute("spt_collection_key"); var collection_code = bvr.src_el.getAttribute("spt_collection_code"); var collection_path = bvr.src_el.getAttribute("spt_collection_path"); var expr = "@SEARCH("+bvr.collection_type+"['parent_code','"+collection_code+"']."+bvr.search_type+")"; var parent_dict = {}; var parent_collection = bvr.src_el.getParent(".spt_subcollection_wdg"); var path = collection_path.substring(0, collection_path.lastIndexOf("/")); if (parent_collection) { for (var i = 0; i < collection_path.split("/").length - 1; i++) { var n = path.lastIndexOf("/"); var collection_name = path.substring(n+1); path = path.substring(0, n); var parent_key = parent_collection.getAttribute("spt_parent_key"); parent_dict[collection_name] = parent_key; parent_collection = parent_collection.getParent(".spt_subcollection_wdg"); } } var cls = "tactic.ui.panel.CollectionContentWdg"; var kwargs = { collection_key: collection_key, path: collection_path, search_type: bvr.search_type, show_shelf: false, show_search_limit: true, expression: expr, parent_dict: parent_dict } spt.panel.load(content, cls, kwargs); bvr.src_el.setStyle("box-shadow", "0px 0px 3px rgba(0,0,0,0.5)"); // hide the bottom show_search_limit when clicking into a collection var panel = bvr.src_el.getParent(".spt_panel"); var search_limit_div = panel.getElements(".spt_search_limit_top"); if (search_limit_div.length == 2){ search_limit_div[1].setStyle("visibility", "hidden"); } ''' } ) collections_div.add_relay_behavior( { 'type': 'mouseup', 'search_type': my.search_type, 'bvr_match_class': 'spt_collection_open', 'cbjs_action': ''' var item = bvr.src_el.getParent(".spt_collection_div_top"); var next = item.getNext(); if (bvr.src_el.hasClass("spt_open")) { next.innerHTML = ""; bvr.src_el.setStyle("opacity", 1.0); bvr.src_el.removeClass("spt_open"); } else { var collection_key = bvr.src_el.getAttribute("spt_collection_key"); var collection_path = bvr.src_el.getAttribute("spt_collection_path"); var cls = "tactic.ui.panel.CollectionListWdg"; var kwargs = { parent_key: collection_key, path: collection_path, } spt.panel.load(next, cls, kwargs, null, {show_loading: false}); bvr.src_el.setStyle("opacity", 0.3); bvr.src_el.addClass("spt_open"); evt.stopPropagation(); } ''' } ) for collection in collections: collection_wdg = CollectionItemWdg(collection=collection, path=collection.get_value("name")) collections_div.add(collection_wdg) collection_wdg.add_class("spt_collection_div") subcollection_wdg = DivWdg() collections_div.add(subcollection_wdg) subcollection_wdg.add_class("spt_subcollection_wdg") subcollection_wdg.add_style("padding-left: 15px") return div
def get_header_wdg(my): div = DivWdg() if my.collection_key: button = IconButtonWdg(title='Remove Selected Items from Collection', icon="BS_MINUS") div.add(button) button.add_style("display: inline-block") button.add_style("vertical-align: top") button.add_behavior( { 'type': 'click_up', 'collection_key': my.collection_key, 'cbjs_action': ''' var search_keys = spt.table.get_selected_search_keys(false); if (search_keys.length == 0) { spt.notify.show_message("Nothing selected to remove"); return; } var ok = null; var cancel = function() { return }; var msg = "Are you sure you wish to remove the selected Assets from the Collection?"; var ok = function() { var cls = 'tactic.ui.panel.CollectionRemoveCmd'; var kwargs = { collection_key: bvr.collection_key, search_keys: search_keys, } var server = TacticServerStub.get(); try { server.execute_cmd(cls, kwargs); spt.table.remove_selected(); } catch(e) { spt.alert(spt.exception.handler(e)); } } spt.confirm(msg, ok, cancel); ''' } ) button = IconButtonWdg(title='Delete Collection', icon="BS_TRASH") #button = ActionButtonWdg(title='Delete Collection', icon="BS_TRASH") div.add(button) button.add_style("display: inline-block") button.add_style("vertical-align: top") button.add_behavior( { 'type': 'click_up', 'collection_key': my.collection_key, 'cbjs_action': ''' var ok = null; var cancel = function() { return }; var msg = "Are you sure you wish to delete the Collection?"; var ok = function() { var cls = 'tactic.ui.panel.CollectionDeleteCmd'; var kwargs = { collection_key: bvr.collection_key, } var server = TacticServerStub.get(); try { server.execute_cmd(cls, kwargs); } catch(e) { spt.alert(e); return; } var top = bvr.src_el.getParent(".spt_collection_top"); if (top) { var layout = top.getParent(".spt_layout"); spt.table.set_layout(layout); } spt.table.run_search(); } spt.confirm(msg, ok, cancel); ''' } ) """ button = IconButtonWdg(title='Download Selected Items', icon="BS_DOWNLOAD") div.add(button) button.add_style("display: inline-block") button.add_style("vertical-align: top") text_div = DivWdg() div.add(text_div) text_div.add_style("width: 200px") text = LookAheadTextInputWdg( name="name", icon="BS_SEARCH", icon_pos="right", width="100%" ) text_div.add(text) text_div.add_style("display: inline-block") """ div.add_style("width: auto") div.add_style("float: right") div.add("<br clear='all'/>") return div
def get_display(my): relative_dir = my.kwargs.get("relative_dir") my.relative_dir = relative_dir div = DivWdg() div.add_class("spt_ingest_top") div.add_style("width: 100%px") div.add_style("min-width: 500px") div.add_style("padding: 20px") div.add_color("background", "background") my.search_type = my.kwargs.get("search_type") if not my.search_type: div.add("No search type specfied") return div if relative_dir: folder_div = DivWdg() div.add(folder_div) folder_div.add("Folder: %s" % relative_dir) folder_div.add_style("opacity: 0.5") folder_div.add_style("font-style: italic") folder_div.add_style("margin-bottom: 10px") data_div = my.get_data_wdg() data_div.add_style("float: left") data_div.add_style("float: left") div.add(data_div) # create the help button help_button_wdg = DivWdg() div.add(help_button_wdg) help_button_wdg.add_style("float: right") help_button = ActionButtonWdg(title="?", tip="Ingestion Widget Help", size='s') help_button_wdg.add(help_button) help_button.add_behavior({ 'type': 'click_up', 'cbjs_action': '''spt.help.load_alias("ingestion_widget")''' }) from tactic.ui.input import Html5UploadWdg upload = Html5UploadWdg(multiple=True) div.add(upload) button = ActionButtonWdg(title="Add") button.add_style("float: right") button.add_style("margin-top: -3px") div.add(button) button.add_behavior({ 'type': 'click_up', 'normal_ext': File.NORMAL_EXT, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var files_el = top.getElement(".spt_to_ingest_files"); var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i'); //clear upload progress var upload_bar = top.getElement('.spt_upload_progress'); if (upload_bar) { upload_bar.setStyle('width','0%'); upload_bar.innerHTML = ''; } var onchange = function (evt) { var files = spt.html5upload.get_files(); var delay = 0; for (var i = 0; i < files.length; i++) { var size = files[i].size; var file_name = files[i].name; var is_normal = regex.test(file_name); if (size >= 10*1024*1024 || is_normal) { spt.drag.show_file(files[i], files_el, 0, false); } else { spt.drag.show_file(files[i], files_el, delay, true); if (size < 100*1024) delay += 50; else if (size < 1024*1024) delay += 500; else if (size < 10*1024*1024) delay += 1000; } } } spt.html5upload.clear(); spt.html5upload.set_form( top ); spt.html5upload.select_file( onchange ); ''' }) button = ActionButtonWdg(title="Clear") button.add_style("float: right") button.add_style("margin-top: -3px") div.add(button) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); }; ''' }) div.add("<br clear='all'/>") div.add("<br clear='all'/>") border_color_light = div.get_color("background2", 8) border_color_dark = div.get_color("background2", -15) background_mouseout = div.get_color("background3", 10) background_mouseenter = div.get_color("background3", 8) files_div = DivWdg() files_div.add_style("position: relative") files_div.add_class("spt_to_ingest_files") div.add(files_div) files_div.add_style("max-height: 300px") files_div.add_style("height: 300px") files_div.add_style("overflow-y: auto") files_div.add_style("padding: 3px") files_div.add_color("background", background_mouseout) files_div.add_style("border: 3px dashed %s" % border_color_light) files_div.add_style("border-radius: 20px 20px 20px 20px") files_div.add_style("z-index: 1") #files_div.add_style("display: none") bgcolor = div.get_color("background3") bgcolor2 = div.get_color("background3", -3) #style_text = "text-align: center; margin-top: 100px; color: #A0A0A0; font-size: 3.0em; z-index: 10;" background = DivWdg() background.add_class("spt_files_background") files_div.add(background) background.add_style("text-align: center") background.add_style("margin-top: 100px") background.add_style("opacity: 0.65") background.add_style("font-size: 3.0em") background.add_style("z-index: 10") background_text = DivWdg("<p>Drag Files Here</p>") background.add(background_text) files_div.add_behavior({ 'type': 'mouseover', 'cbjs_action': ''' bvr.src_el.setStyle("border","3px dashed %s") bvr.src_el.setStyle("background","%s") ''' % (border_color_dark, background_mouseenter) }) files_div.add_behavior({ 'type': 'mouseout', 'cbjs_action': ''' bvr.src_el.setStyle("border", "3px dashed %s") bvr.src_el.setStyle("background","%s") ''' % (border_color_light, background_mouseout) }) # Test drag and drop files files_div.add_attr("ondragenter", "return false") files_div.add_attr("ondragover", "return false") files_div.add_attr("ondrop", "spt.drag.noop(event, this)") files_div.add_behavior({ 'type': 'load', 'normal_ext': File.NORMAL_EXT, 'cbjs_action': ''' spt.drag = {} var background; spt.drag.show_file = function(file, top, delay, icon) { if (!background) { background = top.getElement(".spt_files_background"); if (background) background.setStyle("display", "none"); } var template = top.getElement(".spt_upload_file_template"); var clone = spt.behavior.clone(template); clone.removeClass("spt_upload_file_template"); clone.addClass("spt_upload_file"); clone.setStyle("display", ""); if (typeof(delay) == 'undefined') { delay = 0; } // remember the file handle clone.file = file; var name = file.name; var size = parseInt(file.size / 1024 * 10) / 10; var thumb_el = clone.getElement(".spt_thumb"); var date_label_el = clone.getElement(".spt_date_label"); var date_el = clone.getElement(".spt_date"); //var loadingImage = loadImage( setTimeout( function() { var draw_empty_icon = function() { var img = $(document.createElement("div")); img.setStyle("width", "58"); img.setStyle("height", "34"); //img.innerHTML = "MP4"; img.setStyle("border", "1px dotted #222") thumb_el.appendChild(img); }; if (icon) { var loadingImage = loadImage( file, function (img) { if (img.width) thumb_el.appendChild(img); else draw_empty_icon(); }, {maxWidth: 80, maxHeight: 60, canvas: true, contain: true} ); } else { draw_empty_icon(); } loadImage.parseMetaData( file, function(data) { if (data.exif) { var date = data.exif.get('DateTimeOriginal'); if (date) { date_label_el.innerHTML = date; if (date_el) { date_el.value = date; } } } } ); }, delay ); /* var reader = new FileReader(); reader.thumb_el = thumb_el; reader.onload = function(e) { this.thumb_el.innerHTML = [ '<img class="thumb" src="', e.target.result, '" title="', escape(name), '" width="60px"', '" padding="5px"', '"/>' ].join(''); } reader.readAsDataURL(file); */ clone.getElement(".spt_name").innerHTML = file.name; clone.getElement(".spt_size").innerHTML = size + " KB"; clone.inject(top); } spt.drag.noop = function(evt, el) { var top = $(el).getParent(".spt_ingest_top"); var files_el = top.getElement(".spt_to_ingest_files"); evt.stopPropagation(); evt.preventDefault(); evt.dataTransfer.dropEffect = 'copy'; var files = evt.dataTransfer.files; var delay = 0; var skip = false; var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i'); for (var i = 0; i < files.length; i++) { var size = files[i].size; var file_name = files[i].name; var is_normal = regex.test(file_name); if (size >= 10*1024*1024 || is_normal) { spt.drag.show_file(files[i], files_el, 0, false); } else { spt.drag.show_file(files[i], files_el, delay, true); if (size < 100*1024) delay += 50; else if (size < 1024*1024) delay += 500; else if (size < 10*1024*1024) delay += 1000; } } } ''' }) # create a template that will be filled in for each file files_div.add_relay_behavior({ 'type': 'mouseenter', 'color': files_div.get_color("background3", -5), 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.color); ''' }) files_div.add_relay_behavior({ 'type': 'mouseleave', 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' bvr.src_el.setStyle("background", ""); ''' }) files_div.add_relay_behavior({ 'type': 'mouseup', 'bvr_match_class': 'spt_remove', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_upload_file"); spt.behavior.destroy_element(top); ''' }) """ metadata_view = "test/wizard/metadata" files_div.add_relay_behavior( { 'type': 'mouseup', 'view': metadata_view, 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' var class_name = 'tactic.ui.panel.CustomLayoutWdg'; var kwargs = { view: bvr.view } spt.app_busy.show("Loading Metadata"); spt.panel.load_popup("Metadata", class_name, kwargs); spt.app_busy.hide(); ''' } ) """ # template for each file item file_template = DivWdg() file_template.add_class("spt_upload_file_template") files_div.add(file_template) file_template.add_style("margin-bottom: 3px") file_template.add_style("padding: 3px") file_template.add_style("height: 40px") file_template.add_style("display: none") thumb_div = DivWdg() file_template.add(thumb_div) thumb_div.add_style("float: left") thumb_div.add_style("width: 60") thumb_div.add_style("height: 40") thumb_div.add_style("overflow: hidden") thumb_div.add_style("margin: 3 10 3 0") thumb_div.add_class("spt_thumb") info_div = DivWdg() file_template.add(info_div) info_div.add_style("float: left") name_div = DivWdg() name_div.add_class("spt_name") info_div.add(name_div) name_div.add("image001.jpg") name_div.add_style("width: 150px") """ dialog = DialogWdg(display="false", show_title=False) info_div.add(dialog) dialog.set_as_activator(info_div, offset={'x':0,'y':10}) dialog_data_div = DivWdg() dialog_data_div.add_color("background", "background") dialog_data_div.add_style("padding", "10px") dialog.add(dialog_data_div) dialog_data_div.add("Category: ") text = TextInputWdg(name="category") dialog_data_div.add(text) text.add_class("spt_category") text.add_style("padding: 1px") """ date_div = DivWdg() date_div.add_class("spt_date_label") info_div.add(date_div) date_div.add("") date_div.add_style("opacity: 0.5") date_div.add_style("font-size: 0.8em") date_div.add_style("font-style: italic") date_div.add_style("margin-top: 3px") hidden_date_div = HiddenWdg("date") hidden_date_div.add_class("spt_date") info_div.add(date_div) size_div = DivWdg() size_div.add_class("spt_size") file_template.add(size_div) size_div.add("433Mb") size_div.add_style("float: left") size_div.add_style("width: 150px") size_div.add_style("text-align: right") remove_div = DivWdg() remove_div.add_class("spt_remove") file_template.add(remove_div) icon = IconButtonWdg(title="Remove", icon=IconWdg.DELETE) icon.add_style("float: right") remove_div.add(icon) #remove_div.add_style("text-align: right") div.add("<br/>") info = DivWdg() div.add(info) info.add_class("spt_upload_info") progress_div = DivWdg() progress_div.add_class("spt_upload_progress_top") div.add(progress_div) progress_div.add_style("width: 100%") progress_div.add_style("height: 15px") progress_div.add_style("margin-bottom: 10px") progress_div.add_border() #progress_div.add_style("display: none") progress = DivWdg() progress_div.add(progress) progress.add_class("spt_upload_progress") progress.add_style("width: 0px") progress.add_style("height: 100%") progress.add_gradient("background", "background3", -10) progress.add_style("text-align: right") progress.add_style("overflow: hidden") progress.add_style("padding-right: 3px") from tactic.ui.app import MessageWdg progress.add_behavior({ 'type': 'load', 'cbjs_action': MessageWdg.get_onload_js() }) # NOTE: files variable is passed in automatically upload_init = ''' server.start( {description: "Upload and check-in of ["+files.length+"] files"} ); var info_el = top.getElement(".spt_upload_info"); info_el.innerHTML = "Uploading ..."; ''' upload_progress = ''' var top = bvr.src_el.getParent(".spt_ingest_top"); progress_el = top.getElement(".spt_upload_progress"); var percent = Math.round(evt.loaded * 100 / evt.total); progress_el.setStyle("width", percent + "%"); progress_el.innerHTML = String(percent) + "%"; ''' oncomplete_script_path = my.kwargs.get("oncomplete_script_path") oncomplete_script = '' if oncomplete_script_path: script_folder, script_title = oncomplete_script_path.split("/") oncomplete_script_expr = "@GET(config/custom_script['folder','%s']['title','%s'].script)" % ( script_folder, script_title) server = TacticServerStub.get() oncomplete_script_ret = server.eval(oncomplete_script_expr, single=True) if oncomplete_script_ret: oncomplete_script = '''var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); };''' + oncomplete_script_ret script_found = True else: script_found = False oncomplete_script = "alert('Error: oncomplete script not found');" if not oncomplete_script: oncomplete_script = ''' var click_action = function() { var fade = true; var pop = spt.popup.get_popup(top) spt.popup.close(pop, fade); } spt.info("Ingest Completed", {click: click_action}); server.finish(); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); }; var background = top.getElement(".spt_files_background"); background.setStyle("display", ""); spt.message.stop_interval(key); var info_el = top.getElement(".spt_upload_info"); info_el.innerHTML = ''; if (spt.table) { spt.table.run_search(); } spt.panel.refresh(top); ''' script_found = True on_complete = ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var update_data_top = top.getElement(".spt_edit_top"); var progress_el = top.getElement(".spt_upload_progress"); progress_el.innerHTML = "100%"; progress_el.setStyle("width", "100%"); var info_el = top.getElement(".spt_upload_info"); var search_type = bvr.kwargs.search_type; var relative_dir = bvr.kwargs.relative_dir; var update_mode_select = top.getElement(".spt_update_mode_select"); var update_mode = update_mode_select.value; var filenames = []; for (var i = 0; i != files.length;i++) { var name = files[i].name; filenames.push(name); } var key = spt.message.generate_key(); var values = spt.api.get_input_values(top); //var category = values.category[0]; //var keywords = values.keywords[0]; var extra_data = values.extra_data ? values.extra_data[0]: {}; var parent_key = values.parent_key[0]; var convert_el = top.getElement(".spt_image_convert") var convert = spt.api.get_input_values(convert_el); var processes = values.process; if (processes) { process = processes[0]; if (!process) { process = null; } } else { process = null; } var return_array = false; var update_data = spt.api.get_input_values(update_data_top, null, return_array); var kwargs = { search_type: search_type, relative_dir: relative_dir, filenames: filenames, key: key, parent_key: parent_key, //category: category, //keywords: keywords, extra_data: extra_data, update_data: update_data, process: process, convert: convert, update_mode: update_mode, } on_complete = function(rtn_data) { ''' + oncomplete_script + ''' }; var class_name = bvr.action_handler; // TODO: make the async_callback return throw an e so we can run // server.abort server.execute_cmd(class_name, kwargs, null, {on_complete:on_complete}); on_progress = function(message) { msg = JSON.parse(message.message); var percent = msg.progress; var description = msg.description; info_el.innerHTML = description; progress_el.setStyle("width", percent+"%"); progress_el.innerHTML = percent + "%"; } spt.message.set_interval(key, on_progress, 2000); ''' upload_div = DivWdg() div.add(upload_div) #button = UploadButtonWdg(**kwargs) button = ActionButtonWdg(title="Ingest") upload_div.add(button) button.add_style("float: right") upload_div.add_style("margin-bottom: 15px") upload_div.add("<br clear='all'/>") action_handler = my.kwargs.get("action_handler") if not action_handler: action_handler = 'tactic.ui.tools.IngestUploadCmd' button.add_behavior({ 'type': 'click_up', 'action_handler': action_handler, 'kwargs': { 'search_type': my.search_type, 'relative_dir': relative_dir, 'script_found': script_found, }, 'cbjs_action': ''' if (bvr.kwargs.script_found != true) { spt.alert("Error: provided on_complete script not found"); return; } var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); // get the server that will be used in the callbacks var server = TacticServerStub.get(); // retrieved the stored file handles var files = []; for (var i = 0; i < file_els.length; i++) { files.push( file_els[i].file ); } if (files.length == 0) { alert("Either click 'Add' or drag some files over to ingest."); return; } // defined the callbacks var upload_start = function(evt) { } var upload_progress = function(evt) { %s; } var upload_complete = function(evt) { %s; spt.app_busy.hide(); } var upload_file_kwargs = { files: files, upload_start: upload_start, upload_complete: upload_complete, upload_progress: upload_progress }; if (bvr.ticket) upload_file_kwargs['ticket'] = bvr.ticket; %s; spt.html5upload.set_form( top ); spt.html5upload.upload_file(upload_file_kwargs); ''' % (upload_progress, on_complete, upload_init) }) return div
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_display(my): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_gradient("background", "background", 0, -5) #top.add_style("height: 550px") top.add_behavior({ 'type': 'load', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|hide", {} ); ''' }) project = Project.get() title = TitleWdg(title='Client Home') top.add(title) shelf = DivWdg() top.add(shelf) shelf.add_style("margin-left: -8px") shelf.add_style("width: 130px") security = Environment.get_security() view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow') if view_side_bar: button_div = DivWdg() shelf.add(button_div) button_div.add_style("float: left") button_div.add_style("margin-top: -3px") button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT) button_div.add(button) shelf.add("Toggle Side Bar") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' }) shelf.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' }) shelf.add_class("hand") else: shelf.add(" ") 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("padding: 3px") td.add_style("vertical-align: top") title = "My Approvals" description = '''View all pending items for approval<br/><br/> ''' #image = "<img src='/context/images/getting_started_pipeline.png'/>" image = "<img src='/context/icons/64x64/dashboard_64.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { search_type: 'sthpw/sobject_list', view: 'client_approval', show_shelf: false, show_select: false, element_names: ['preview', 'name', 'description', 'task_pipeline_vertical','notes'], is_editable: false, //expression: "@SOBJECT(sthpw/task['project_code','fickle3'].fickle3/cars.sthpw/sobject_list)" }; spt.tab.add_new("approvals", "Approvals", class_name, kwargs); ''' } config_wdg = my.get_section_wdg(title, description, image, behavior) td.add(config_wdg) td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "My Dashboard" image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''Dashboards display key project data in single views. Drill down further to work on tasks, make status changes or add notes.''' # read the config file from pyasm.widget import WidgetConfig tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path = "%s/../config/dashboard-conf.xml" % (dir_name) config = WidgetConfig.get(file_path=file_path, view="definition") #element_name = "my_dashboard" element_name = "my_dashboard" attrs = config.get_element_attributes(element_name) dashboard_data = {} kwargs = config.get_display_options(element_name) class_name = kwargs.get('class_name') dashboard_data['class_name'] = class_name dashboard_data['kwargs'] = kwargs dashboard_data['title'] = attrs.get("title") dashboard_data['description'] = attrs.get("description") dashboard_data['image'] = attrs.get("image") behavior = { 'type': 'click_up', 'dashboard': dashboard_data, 'cbjs_action': ''' var class_name = 'tactic.ui.startup.dashboards_wdg.DashboardsWdg'; var kwargs = {}; spt.tab.set_main_body_tab(); spt.tab.add_new("my_dashboard", "My Dashboard", bvr.dashboard.class_name, bvr.dashboard.kwargs); ''' } pipeline_wdg = my.get_section_wdg(title, description, image, behavior) td.add(pipeline_wdg) td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "My Reports" image = "<img src='/context/icons/64x64/report_64.png'/>" description = '''TACTIC provides a number of predefined reports that project managers can access instantly to get real-time analytics.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.reports_wdg.ReportsWdg'; var kwargs = {}; spt.tab.set_main_body_tab(); spt.tab.add_new("reports", "Reports", class_name, kwargs); //spt.panel.load_popup("Reports", class_name, kwargs); ''' } side_bar_wdg = my.get_section_wdg(title, description, image, behavior) td.add(side_bar_wdg) """ td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Documentation" description = '''TACTIC Documentation. <br/><br/> * Project Setup Documentation<br/> <br/> * End User Documentation<br/> <br/> * Developer Documentation<br/> <br/> * System Administrator Documentation<br/> <br/> ''' image = "<img src='/context/images/getting_started_pipeline.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.help.load_alias("main") ''' } doc_wdg = my.get_section_wdg(title, description, image, behavior) td.add(doc_wdg) """ tr, td = table.add_row_cell() td.add_style("font-size: 14px") td.add("<br/>" * 2) quick_links_wdg = QuickLinksWdg() td.add(quick_links_wdg) return top
def get_shelf_wdg(my): process = my.get_value("process") versions = my.get_value("versions") div = DivWdg() filter_table = Table() div.add(filter_table) filter_table.add_row() button = SingleButtonWdg(title="Refresh", icon=IconWdg.REFRESH) filter_table.add_cell(button) filter_table.add_cell(" "*5) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.panel.refresh(bvr.src_el); ''' } ) # get all of the pipelnes for this search type pipeline_code = my.sobject.get_value("pipeline_code", no_exception=True) processes = [] if pipeline_code: pipeline = Pipeline.get_by_code(pipeline_code) if pipeline: process_names = pipeline.get_process_names() processes.extend(process_names) processes.insert(0, "all") filter_table.add_cell("Process: ") select = SelectWdg("process") select.add_style("width: 200px") if process != 'all': select.set_value(process) select.set_option("values", processes) filter_table.add_cell(select) filter_table.add_cell(" "*10) filter_table.add_cell("Versions: ") select = SelectWdg("versions") select.add_style("width: 200px") select.set_option("values", "latest|current|today|last 10|all") if versions: select.set_value(versions) filter_table.add_cell(select) asset_dir = Environment.get_asset_dir() select = IconButtonWdg( tip="Toggle Selection", icon=IconWdg.SELECT, show_arrow=False ) div.add(select) select.add_style("float: right") select.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top_class = 'spt_sobject_dir_list_top' var toggle_state = bvr.src_el.getAttribute('toggle'); if (toggle_state && toggle_state=='true') bvr.src_el.setAttribute('toggle','false'); else bvr.src_el.setAttribute('toggle','true'); var top = bvr.src_el.getParent("."+top_class); spt.selection.set_top(top); toggle_state = bvr.src_el.getAttribute('toggle'); if (toggle_state == 'true') spt.selection.select_all_items(); else spt.selection.unselect_all_items(); ''' } ) show = IconButtonWdg( tip="Switch View", icon=IconWdg.VIEW, show_arrow=False ) div.add(show) show.add_style("float: right") show.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top_class = 'spt_sobject_dir_list_top' var top = bvr.src_el.getParent("."+top_class); spt.selection.set_top(top); var els = top.getElements(".spt_file_dir_item"); for (var i = 0; i < els.length; i++) { var el = els[i]; if (el.getStyle("display") == "none") { els[i].setStyle("display", ""); } else { els[i].setStyle("display", "none"); } } var els = top.getElements(".spt_file_item"); for (var i = 0; i < els.length; i++) { var el = els[i]; if (el.getStyle("padding-left") == "6px") { var padding = el.getAttribute("spt_padding_left"); el.setStyle("padding-left", padding); } else { el.setStyle("padding-left", "6px"); } } ''' } ) gear = IconButtonWdg( tip="Download", icon=IconWdg.DOWNLOAD, show_arrow=False ) div.add(gear) gear.add_style("float: right") gear.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.app_busy.show('Select a folder to download to...',''); var top_class = 'spt_sobject_dir_list_top'; var top = bvr.src_el.getParent("."+top_class); spt.selection.set_top(top); var items = spt.selection.get_selected(); setTimeout( function() { var applet = spt.Applet.get(); var select_dir =true; var dir = applet.open_file_browser('', select_dir); if (dir.length == 0) dir = applet.get_current_dir(); else dir = dir[0]; if (!dir) { spt.alert("No folder selected to copy to."); spt.app_busy.hide(); return; } if (items.length == 0){ spt.alert("Please select at least one file to download."); spt.app_busy.hide(); return; } var asset_dir = '%s'; for (var i = 0; i < items.length; i++) { var path = items[i].getAttribute("spt_path"); var env = spt.Environment.get(); var server_url = env.get_server_url(); var url = server_url + "/assets/" + path.replace(asset_dir, ""); var parts = path.split("/"); var filename = parts[parts.length-1]; spt.app_busy.show("Downloading file", filename); applet.download_file(url, dir + "/" + filename); } spt.app_busy.hide(); if (dir) spt.notify.show_message("Download to '" + dir + "' completed.") }, 100); ''' % asset_dir } ) return div
def get_display(my): relative_dir = my.kwargs.get("relative_dir") my.relative_dir = relative_dir div = DivWdg() div.add_class("spt_ingest_top") div.add_style("width: 100%px") div.add_style("min-width: 500px") div.add_style("padding: 20px") div.add_color("background", "background") my.search_type = my.kwargs.get("search_type") if not my.search_type: div.add("No search type specfied") return div if relative_dir: folder_div = DivWdg() div.add(folder_div) folder_div.add("Folder: %s" % relative_dir) folder_div.add_style("opacity: 0.5") folder_div.add_style("font-style: italic") folder_div.add_style("margin-bottom: 10px") data_div = my.get_data_wdg() data_div.add_style("float: left") data_div.add_style("float: left") div.add(data_div) # create the help button help_button_wdg = DivWdg() div.add(help_button_wdg) help_button_wdg.add_style("float: right") help_button = ActionButtonWdg(title="?", tip="Ingestion Widget Help", size='s') help_button_wdg.add(help_button) help_button.add_behavior( { 'type': 'click_up', 'cbjs_action': '''spt.help.load_alias("ingestion_widget")''' } ) from tactic.ui.input import Html5UploadWdg upload = Html5UploadWdg(multiple=True) div.add(upload) button = ActionButtonWdg(title="Add") button.add_style("float: right") button.add_style("margin-top: -3px") div.add(button) button.add_behavior( { 'type': 'click_up', 'normal_ext': File.NORMAL_EXT, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var files_el = top.getElement(".spt_to_ingest_files"); var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i'); //clear upload progress var upload_bar = top.getElement('.spt_upload_progress'); if (upload_bar) { upload_bar.setStyle('width','0%'); upload_bar.innerHTML = ''; } var onchange = function (evt) { var files = spt.html5upload.get_files(); var delay = 0; for (var i = 0; i < files.length; i++) { var size = files[i].size; var file_name = files[i].name; var is_normal = regex.test(file_name); if (size >= 10*1024*1024 || is_normal) { spt.drag.show_file(files[i], files_el, 0, false); } else { spt.drag.show_file(files[i], files_el, delay, true); if (size < 100*1024) delay += 50; else if (size < 1024*1024) delay += 500; else if (size < 10*1024*1024) delay += 1000; } } } spt.html5upload.clear(); spt.html5upload.set_form( top ); spt.html5upload.select_file( onchange ); ''' } ) button = ActionButtonWdg(title="Clear") button.add_style("float: right") button.add_style("margin-top: -3px") div.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); }; ''' } ) div.add("<br clear='all'/>") div.add("<br clear='all'/>") border_color_light = div.get_color("background2", 8) border_color_dark = div.get_color("background2", -15) background_mouseout = div.get_color("background3", 10) background_mouseenter = div.get_color("background3", 8) files_div = DivWdg() files_div.add_style("position: relative") files_div.add_class("spt_to_ingest_files") div.add(files_div) files_div.add_style("max-height: 300px") files_div.add_style("height: 300px") files_div.add_style("overflow-y: auto") files_div.add_style("padding: 3px") files_div.add_color("background", background_mouseout) files_div.add_style("border: 3px dashed %s" % border_color_light) files_div.add_style("border-radius: 20px 20px 20px 20px") files_div.add_style("z-index: 1") #files_div.add_style("display: none") bgcolor = div.get_color("background3") bgcolor2 = div.get_color("background3", -3) #style_text = "text-align: center; margin-top: 100px; color: #A0A0A0; font-size: 3.0em; z-index: 10;" background = DivWdg() background.add_class("spt_files_background") files_div.add(background) background.add_style("text-align: center") background.add_style("margin-top: 100px") background.add_style("opacity: 0.65") background.add_style("font-size: 3.0em") background.add_style("z-index: 10") background_text = DivWdg("<p>Drag Files Here</p>") background.add(background_text) files_div.add_behavior( { 'type': 'mouseover', 'cbjs_action': ''' bvr.src_el.setStyle("border","3px dashed %s") bvr.src_el.setStyle("background","%s") ''' % (border_color_dark, background_mouseenter) } ) files_div.add_behavior( { 'type': 'mouseout', 'cbjs_action': ''' bvr.src_el.setStyle("border", "3px dashed %s") bvr.src_el.setStyle("background","%s") ''' % (border_color_light, background_mouseout) } ) # Test drag and drop files files_div.add_attr("ondragenter", "return false") files_div.add_attr("ondragover", "return false") files_div.add_attr("ondrop", "spt.drag.noop(event, this)") files_div.add_behavior( { 'type': 'load', 'normal_ext': File.NORMAL_EXT, 'cbjs_action': ''' spt.drag = {} var background; spt.drag.show_file = function(file, top, delay, icon) { if (!background) { background = top.getElement(".spt_files_background"); if (background) background.setStyle("display", "none"); } var template = top.getElement(".spt_upload_file_template"); var clone = spt.behavior.clone(template); clone.removeClass("spt_upload_file_template"); clone.addClass("spt_upload_file"); clone.setStyle("display", ""); if (typeof(delay) == 'undefined') { delay = 0; } // remember the file handle clone.file = file; var name = file.name; var size = parseInt(file.size / 1024 * 10) / 10; var thumb_el = clone.getElement(".spt_thumb"); var date_label_el = clone.getElement(".spt_date_label"); var date_el = clone.getElement(".spt_date"); //var loadingImage = loadImage( setTimeout( function() { var draw_empty_icon = function() { var img = $(document.createElement("div")); img.setStyle("width", "58"); img.setStyle("height", "34"); //img.innerHTML = "MP4"; img.setStyle("border", "1px dotted #222") thumb_el.appendChild(img); }; if (icon) { var loadingImage = loadImage( file, function (img) { if (img.width) thumb_el.appendChild(img); else draw_empty_icon(); }, {maxWidth: 80, maxHeight: 60, canvas: true, contain: true} ); } else { draw_empty_icon(); } loadImage.parseMetaData( file, function(data) { if (data.exif) { var date = data.exif.get('DateTimeOriginal'); if (date) { date_label_el.innerHTML = date; if (date_el) { date_el.value = date; } } } } ); }, delay ); /* var reader = new FileReader(); reader.thumb_el = thumb_el; reader.onload = function(e) { this.thumb_el.innerHTML = [ '<img class="thumb" src="', e.target.result, '" title="', escape(name), '" width="60px"', '" padding="5px"', '"/>' ].join(''); } reader.readAsDataURL(file); */ clone.getElement(".spt_name").innerHTML = file.name; clone.getElement(".spt_size").innerHTML = size + " KB"; clone.inject(top); } spt.drag.noop = function(evt, el) { var top = $(el).getParent(".spt_ingest_top"); var files_el = top.getElement(".spt_to_ingest_files"); evt.stopPropagation(); evt.preventDefault(); evt.dataTransfer.dropEffect = 'copy'; var files = evt.dataTransfer.files; var delay = 0; var skip = false; var regex = new RegExp('(' + bvr.normal_ext.join('|') + ')$', 'i'); for (var i = 0; i < files.length; i++) { var size = files[i].size; var file_name = files[i].name; var is_normal = regex.test(file_name); if (size >= 10*1024*1024 || is_normal) { spt.drag.show_file(files[i], files_el, 0, false); } else { spt.drag.show_file(files[i], files_el, delay, true); if (size < 100*1024) delay += 50; else if (size < 1024*1024) delay += 500; else if (size < 10*1024*1024) delay += 1000; } } } ''' } ) # create a template that will be filled in for each file files_div.add_relay_behavior( { 'type': 'mouseenter', 'color': files_div.get_color("background3", -5), 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.color); ''' } ) files_div.add_relay_behavior( { 'type': 'mouseleave', 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' bvr.src_el.setStyle("background", ""); ''' } ) files_div.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_remove', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_upload_file"); spt.behavior.destroy_element(top); ''' } ) """ metadata_view = "test/wizard/metadata" files_div.add_relay_behavior( { 'type': 'mouseup', 'view': metadata_view, 'bvr_match_class': 'spt_upload_file', 'cbjs_action': ''' var class_name = 'tactic.ui.panel.CustomLayoutWdg'; var kwargs = { view: bvr.view } spt.app_busy.show("Loading Metadata"); spt.panel.load_popup("Metadata", class_name, kwargs); spt.app_busy.hide(); ''' } ) """ # template for each file item file_template = DivWdg() file_template.add_class("spt_upload_file_template") files_div.add(file_template) file_template.add_style("margin-bottom: 3px") file_template.add_style("padding: 3px") file_template.add_style("height: 40px") file_template.add_style("display: none") thumb_div = DivWdg() file_template.add(thumb_div) thumb_div.add_style("float: left") thumb_div.add_style("width: 60"); thumb_div.add_style("height: 40"); thumb_div.add_style("overflow: hidden"); thumb_div.add_style("margin: 3 10 3 0"); thumb_div.add_class("spt_thumb") info_div = DivWdg() file_template.add(info_div) info_div.add_style("float: left") name_div = DivWdg() name_div.add_class("spt_name") info_div.add(name_div) name_div.add("image001.jpg") name_div.add_style("width: 150px") """ dialog = DialogWdg(display="false", show_title=False) info_div.add(dialog) dialog.set_as_activator(info_div, offset={'x':0,'y':10}) dialog_data_div = DivWdg() dialog_data_div.add_color("background", "background") dialog_data_div.add_style("padding", "10px") dialog.add(dialog_data_div) dialog_data_div.add("Category: ") text = TextInputWdg(name="category") dialog_data_div.add(text) text.add_class("spt_category") text.add_style("padding: 1px") """ date_div = DivWdg() date_div.add_class("spt_date_label") info_div.add(date_div) date_div.add("") date_div.add_style("opacity: 0.5") date_div.add_style("font-size: 0.8em") date_div.add_style("font-style: italic") date_div.add_style("margin-top: 3px") hidden_date_div = HiddenWdg("date") hidden_date_div.add_class("spt_date") info_div.add(date_div) size_div = DivWdg() size_div.add_class("spt_size") file_template.add(size_div) size_div.add("433Mb") size_div.add_style("float: left") size_div.add_style("width: 150px") size_div.add_style("text-align: right") remove_div = DivWdg() remove_div.add_class("spt_remove") file_template.add(remove_div) icon = IconButtonWdg(title="Remove", icon=IconWdg.DELETE) icon.add_style("float: right") remove_div.add(icon) #remove_div.add_style("text-align: right") div.add("<br/>") info = DivWdg() div.add(info) info.add_class("spt_upload_info") progress_div = DivWdg() progress_div.add_class("spt_upload_progress_top") div.add(progress_div) progress_div.add_style("width: 100%") progress_div.add_style("height: 15px") progress_div.add_style("margin-bottom: 10px") progress_div.add_border() #progress_div.add_style("display: none") progress = DivWdg() progress_div.add(progress) progress.add_class("spt_upload_progress") progress.add_style("width: 0px") progress.add_style("height: 100%") progress.add_gradient("background", "background3", -10) progress.add_style("text-align: right") progress.add_style("overflow: hidden") progress.add_style("padding-right: 3px") from tactic.ui.app import MessageWdg progress.add_behavior( { 'type': 'load', 'cbjs_action': MessageWdg.get_onload_js() } ) # NOTE: files variable is passed in automatically upload_init = ''' server.start( {description: "Upload and check-in of ["+files.length+"] files"} ); var info_el = top.getElement(".spt_upload_info"); info_el.innerHTML = "Uploading ..."; ''' upload_progress = ''' var top = bvr.src_el.getParent(".spt_ingest_top"); progress_el = top.getElement(".spt_upload_progress"); var percent = Math.round(evt.loaded * 100 / evt.total); progress_el.setStyle("width", percent + "%"); progress_el.innerHTML = String(percent) + "%"; ''' oncomplete_script_path = my.kwargs.get("oncomplete_script_path") oncomplete_script = '' if oncomplete_script_path: script_folder, script_title = oncomplete_script_path.split("/") oncomplete_script_expr = "@GET(config/custom_script['folder','%s']['title','%s'].script)" %(script_folder,script_title) server = TacticServerStub.get() oncomplete_script_ret = server.eval(oncomplete_script_expr, single=True) if oncomplete_script_ret: oncomplete_script = '''var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); };''' + oncomplete_script_ret script_found = True else: script_found = False oncomplete_script = "alert('Error: oncomplete script not found');" if not oncomplete_script: oncomplete_script = ''' var click_action = function() { var fade = true; var pop = spt.popup.get_popup(top) spt.popup.close(pop, fade); } spt.info("Ingest Completed", {click: click_action}); server.finish(); var file_els = top.getElements(".spt_upload_file"); for ( var i = 0; i < file_els.length; i++) { spt.behavior.destroy( file_els[i] ); }; var background = top.getElement(".spt_files_background"); background.setStyle("display", ""); spt.message.stop_interval(key); var info_el = top.getElement(".spt_upload_info"); info_el.innerHTML = ''; if (spt.table) { spt.table.run_search(); } spt.panel.refresh(top); ''' script_found = True on_complete = ''' var top = bvr.src_el.getParent(".spt_ingest_top"); var update_data_top = top.getElement(".spt_edit_top"); var progress_el = top.getElement(".spt_upload_progress"); progress_el.innerHTML = "100%"; progress_el.setStyle("width", "100%"); var info_el = top.getElement(".spt_upload_info"); var search_type = bvr.kwargs.search_type; var relative_dir = bvr.kwargs.relative_dir; var update_mode_select = top.getElement(".spt_update_mode_select"); var update_mode = update_mode_select.value; var filenames = []; for (var i = 0; i != files.length;i++) { var name = files[i].name; filenames.push(name); } var key = spt.message.generate_key(); var values = spt.api.get_input_values(top); //var category = values.category[0]; //var keywords = values.keywords[0]; var extra_data = values.extra_data ? values.extra_data[0]: {}; var parent_key = values.parent_key[0]; var convert_el = top.getElement(".spt_image_convert") var convert = spt.api.get_input_values(convert_el); var processes = values.process; if (processes) { process = processes[0]; if (!process) { process = null; } } else { process = null; } var return_array = false; var update_data = spt.api.get_input_values(update_data_top, null, return_array); var kwargs = { search_type: search_type, relative_dir: relative_dir, filenames: filenames, key: key, parent_key: parent_key, //category: category, //keywords: keywords, extra_data: extra_data, update_data: update_data, process: process, convert: convert, update_mode: update_mode, } on_complete = function(rtn_data) { ''' + oncomplete_script + ''' }; var class_name = bvr.action_handler; // TODO: make the async_callback return throw an e so we can run // server.abort server.execute_cmd(class_name, kwargs, null, {on_complete:on_complete}); on_progress = function(message) { msg = JSON.parse(message.message); var percent = msg.progress; var description = msg.description; info_el.innerHTML = description; progress_el.setStyle("width", percent+"%"); progress_el.innerHTML = percent + "%"; } spt.message.set_interval(key, on_progress, 2000); ''' upload_div = DivWdg() div.add(upload_div) #button = UploadButtonWdg(**kwargs) button = ActionButtonWdg(title="Ingest") upload_div.add(button) button.add_style("float: right") upload_div.add_style("margin-bottom: 15px") upload_div.add("<br clear='all'/>") action_handler = my.kwargs.get("action_handler") if not action_handler: action_handler = 'tactic.ui.tools.IngestUploadCmd'; button.add_behavior( { 'type': 'click_up', 'action_handler': action_handler, 'kwargs': { 'search_type': my.search_type, 'relative_dir': relative_dir, 'script_found': script_found, }, 'cbjs_action': ''' if (bvr.kwargs.script_found != true) { spt.alert("Error: provided on_complete script not found"); return; } var top = bvr.src_el.getParent(".spt_ingest_top"); var file_els = top.getElements(".spt_upload_file"); // get the server that will be used in the callbacks var server = TacticServerStub.get(); // retrieved the stored file handles var files = []; for (var i = 0; i < file_els.length; i++) { files.push( file_els[i].file ); } if (files.length == 0) { alert("Either click 'Add' or drag some files over to ingest."); return; } // defined the callbacks var upload_start = function(evt) { } var upload_progress = function(evt) { %s; } var upload_complete = function(evt) { %s; spt.app_busy.hide(); } var upload_file_kwargs = { files: files, upload_start: upload_start, upload_complete: upload_complete, upload_progress: upload_progress }; if (bvr.ticket) upload_file_kwargs['ticket'] = bvr.ticket; %s; spt.html5upload.set_form( top ); spt.html5upload.upload_file(upload_file_kwargs); ''' % (upload_progress, on_complete, upload_init) } ) return div