def get_security_wdg(my): div = DivWdg() div.add_class("spt_security") div.add( "A server can sync either be scoped for a single project or all projects. Transactions that occur in the admin project never get synced." ) div.add("<br/>" * 2) div.add("Project: ") search = Search("sthpw/project") search.add_filters("code", ['admin', 'unittest'], op='not in') search.add_order_by("title") projects = search.get_sobjects() select = SelectWdg("projects") div.add(select) labels = [x.get_value("title") for x in projects] values = [x.get_value("code") for x in projects] project_code = Project.get_project_code() if project_code != 'admin': select.set_value(project_code) select.set_option("labels", labels) select.set_option("values", values) select.add_empty_option("-- All --") div.add("<br/>" * 2) return div
def get_sync_mode_wdg(my): div = DivWdg() div.add_class("spt_sync_mode") div.add("Share Mode: ") select = SelectWdg("sync_mode") div.add(select) select.set_option("values", "file|xmlrpc") select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_sync_mode"); var value = bvr.src_el.value; var xmlrpc_el = top.getElement(".spt_xmlrpc_mode"); var file_el = top.getElement(".spt_file_mode"); if (value == 'xmlrpc') { spt.show(xmlrpc_el); spt.hide(file_el); } else { spt.hide(xmlrpc_el); spt.show(file_el); } ''' }) div.add(my.get_xmlrpc_mode_wdg()) div.add(my.get_file_mode_wdg()) return div
def get_security_wdg(self): div = DivWdg() div.add_class("spt_security") div.add("A server can sync either be scoped for a single project or all projects. Transactions that occur in the admin project never get synced.") div.add("<br/>"*2) div.add("Project: ") search = Search("sthpw/project") search.add_filters("code", ['admin','unittest'], op='not in') search.add_order_by("title") projects = search.get_sobjects() select = SelectWdg("projects") div.add(select) labels = [x.get_value("title") for x in projects] values = [x.get_value("code") for x in projects] project_code = Project.get_project_code() if project_code != 'admin': select.set_value(project_code) select.set_option("labels", labels) select.set_option("values", values) select.add_empty_option("-- All --") div.add("<br/>"*2) return div
def get_sync_mode_wdg(self): div = DivWdg() div.add_class("spt_sync_mode") div.add("Share Mode: ") select = SelectWdg("sync_mode") div.add(select) select.set_option("values", "file|xmlrpc") select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_sync_mode"); var value = bvr.src_el.value; var xmlrpc_el = top.getElement(".spt_xmlrpc_mode"); var file_el = top.getElement(".spt_file_mode"); if (value == 'xmlrpc') { spt.show(xmlrpc_el); spt.hide(file_el); } else { spt.hide(xmlrpc_el); spt.show(file_el); } ''' } ) div.add( self.get_xmlrpc_mode_wdg() ) div.add( self.get_file_mode_wdg() ) return div
def get_display(my): widget = DivWdg(id='link_view_select') widget.add_class("link_view_select") if my.refresh: widget = Widget() else: my.set_as_panel(widget) views = [] if my.search_type: from pyasm.search import WidgetDbConfig search = Search( WidgetDbConfig.SEARCH_TYPE ) search.add_filter("search_type", my.search_type) search.add_regex_filter("view", "link_search:|saved_search:", op="NEQI") search.add_order_by('view') widget_dbs = search.get_sobjects() views = SObject.get_values(widget_dbs, 'view') labels = [view for view in views] views.insert(0, 'table') labels.insert(0, 'table (Default)') st_select = SelectWdg('new_link_view', label='View: ') st_select.set_option('values', views) st_select.set_option('labels', labels) widget.add(st_select) return widget
def get_display(my): widget = DivWdg(id='link_view_select') widget.add_class("link_view_select") if my.refresh: widget = Widget() else: my.set_as_panel(widget) views = [] if my.search_type: from pyasm.search import WidgetDbConfig search = Search(WidgetDbConfig.SEARCH_TYPE) search.add_filter("search_type", my.search_type) search.add_regex_filter("view", "link_search:|saved_search:", op="NEQI") search.add_order_by('view') widget_dbs = search.get_sobjects() views = SObject.get_values(widget_dbs, 'view') labels = [view for view in views] views.insert(0, 'table') labels.insert(0, 'table (Default)') st_select = SelectWdg('new_link_view', label='View: ') st_select.set_option('values', views) st_select.set_option('labels', labels) widget.add(st_select) return widget
def get_display(my): sobject = my.get_current_sobject() key = sobject.get_value("key") options = sobject.get_value("options") type = sobject.get_value("type") # get the value of the users preferences search = Search("sthpw/pref_setting") search.add_user_filter() search.add_filter("key", key) pref_setting = search.get_sobject() if pref_setting: value = pref_setting.get_value("value") else: value = "" div = DivWdg() element_name = "%s_%s" % (my.get_name(), sobject.get_id() ) script = '''var server = TacticServerStub.get(); var value = bvr.src_el.value; if (!value) return; spt.app_busy.show("Saving", "Saving Preference for [%s]"); setTimeout( function() { try{ server.execute_cmd('tactic.ui.table.SetPreferenceCmd', {key: '%s', value: value}); }catch(e){ spt.alert(spt.exception.handler(e)); } spt.app_busy.hide() }, 200);'''%(key, key) if key in ['skin', 'palette', 'js_logging_level']: script = '''%s; spt.app_busy.show('Reloading Page ...'); setTimeout('spt.refresh_page()', 200);'''%script if type == "sequence": from pyasm.prod.web import SelectWdg select = SelectWdg(element_name) select.add_behavior({'type': "change", 'cbjs_action': script}) select.set_option("values",options) if value: select.set_value(value) div.add(select) else: text = TextWdg(element_name) text.add_behavior({'type': "blur", 'cbjs_action': script}) if value: text.set_value(value) div.add(text) return div
def get_display(my): sobject = my.get_current_sobject() key = sobject.get_value("key") options = sobject.get_value("options") type = sobject.get_value("type") # get the value of the users preferences search = Search("sthpw/pref_setting") search.add_user_filter() search.add_filter("key", key) pref_setting = search.get_sobject() if pref_setting: value = pref_setting.get_value("value") else: value = "" div = DivWdg() element_name = "%s_%s" % (my.get_name(), sobject.get_id()) script = '''var server = TacticServerStub.get(); var value = bvr.src_el.value; if (!value) return; spt.app_busy.show("Saving", "Saving Preference for [%s]"); setTimeout( function() { try{ server.execute_cmd('tactic.ui.table.SetPreferenceCmd', {key: '%s', value: value}); }catch(e){ spt.alert(spt.exception.handler(e)); } spt.app_busy.hide() }, 200);''' % (key, key) if key in ['skin', 'palette', 'js_logging_level']: script = '''%s; spt.app_busy.show('Reloading Page ...'); setTimeout('spt.refresh_page()', 200);''' % script if type == "sequence": from pyasm.prod.web import SelectWdg select = SelectWdg(element_name) select.add_behavior({'type': "change", 'cbjs_action': script}) select.set_option("values", options) if value: select.set_value(value) div.add(select) else: text = TextWdg(element_name) text.add_behavior({'type': "blur", 'cbjs_action': script}) if value: text.set_value(value) div.add(text) return div
def configure_category(my, title, category, options, options_type = {}): div = DivWdg() title_wdg = DivWdg() div.add(title_wdg) #from tactic.ui.widget.swap_display_wdg import SwapDisplayWdg #swap = SwapDisplayWdg() #div.add(swap) title_wdg.add("<b>%s</b>" % title) table = Table() div.add(table) #table.add_color("color", "color") table.add_style("color: #000") table.add_style("margin: 20px") for option in options: table.add_row() display_title = Common.get_display_title(option) td = table.add_cell("%s: " % display_title) td.add_style("width: 150px") option_type = options_type.get(option) validation_scheme = "" #add selectWdg for those options whose type is bool if option_type == 'bool': text = SelectWdg(name="%s/%s" % (category, option)) text.set_option('values','true|false') text.set_option('empty','true') text.add_style("margin-left: 0px") elif option.endswith('password'): text = PasswordInputWdg(name="%s/%s" % (category, option)) # dealing with options whose type is number else: if option_type == 'number': validation_scheme = 'INTEGER' else: validation_scheme = "" text = TextInputWdg(name="%s/%s" % (category, option), validation_scheme=validation_scheme, read_only="false") value = Config.get_value(category, option) if value: text.set_value(value) table.add_cell(text) return div
def get_display(my): state = my.get_state() search_type = state.get("search_type") sobj = my.get_current_sobject() if search_type: st = search_type else: st = sobj.get_base_search_type() # for inline insert, this should proceed #if not sobj: # return '' st_suffix = st.split('/', 1) if len(st_suffix) == 2: st_suffix = st_suffix[1] search = Search('sthpw/pipeline') search.add_op_filters([('search_type', 'EQ', '/%s' % st_suffix)]) # takes into account site-wide pipeline search.add_project_filter(show_unset=True) sobjects = search.get_sobjects() codes = [x.get_code() for x in sobjects] if my.get_option("use_code") in [True, 'true']: names = codes else: names = [] for x in sobjects: name = x.get_value("name") if not name: name = x.get_value("code") names.append(name) select = SelectWdg(my.get_input_name()) select.add_empty_option("-- Default --") select.set_option("values", codes) select.set_option("labels", names) if sobj: value = sobj.get_value(my.get_name()) if value: select.set_value(value) else: # only for inline #behavior = { 'type': 'click', # 'cbjs_action': 'spt.dg_table.select_wdg_clicked( evt, bvr.src_el );'} #select.add_behavior(behavior) pass return select
def configure_category(my, title, category, options, options_type={}): div = DivWdg() title_wdg = DivWdg() div.add(title_wdg) #from tactic.ui.widget.swap_display_wdg import SwapDisplayWdg #swap = SwapDisplayWdg() #div.add(swap) title_wdg.add("<b>%s</b>" % title) table = Table() div.add(table) #table.add_color("color", "color") table.add_style("color: #000") table.add_style("margin: 20px") for option in options: table.add_row() display_title = Common.get_display_title(option) td = table.add_cell("%s: " % display_title) td.add_style("width: 150px") option_type = options_type.get(option) validation_scheme = "" #add selectWdg for those options whose type is bool if option_type == 'bool': text = SelectWdg(name="%s/%s" % (category, option)) text.set_option('values', 'true|false') text.set_option('empty', 'true') text.add_style("margin-left: 0px") elif option.endswith('password'): text = PasswordInputWdg(name="%s/%s" % (category, option)) # dealing with options whose type is number else: if option_type == 'number': validation_scheme = 'INTEGER' else: validation_scheme = "" text = TextInputWdg(name="%s/%s" % (category, option), validation_scheme=validation_scheme, read_only="false") value = Config.get_value(category, option) if value: text.set_value(value) table.add_cell(text) return div
def get_input_by_arg_key(self, key): if key == 'icon': input = SelectWdg("option_icon_select") input.set_option("values", IconWdg.get_icons_keys()) input.add_empty_option("-- Select --") elif key == 'script': input = SelectWdg("option_script_select") input.set_option("query", "config/custom_script|code|code" ) input.add_empty_option("-- Select --") else: input = TextWdg("value") return input
def get_input_by_arg_key(my, key): if key == 'icon': input = SelectWdg("option_icon_select") input.set_option("values", IconWdg.get_icons_keys()) input.add_empty_option("-- Select --") elif key == 'script': input = SelectWdg("option_script_select") input.set_option("query", "config/custom_script|code|code") input.add_empty_option("-- Select --") else: input = TextWdg("value") return input
def get_action_wdg(my): filter_div = DivWdg() select = SelectWdg("filter_action") select.add_empty_option("-- search action --") select.add_style("text-align: right") select.set_option("labels", "Retrieve Search|Save Search") select.set_option("values", "retrieve|save") select.add_event("onchange", "spt.dg_table.search_action_cbk(this)") filter_div.add(select) return filter_div
def get_display(self): widget = DivWdg() pipeline_code = self.get_option('pipeline') pipeline = Pipeline.get_by_code(pipeline_code) if not pipeline: widget.add("No pipeline defined") return widget processes = pipeline.get_process_names() widget.add_style("border: solid 1px blue") widget.add_style("position: absolute") widget.add_style("top: 300") widget.add_style("left: -500") for process in processes: #inputs = pipeline.get_input_processes(process) outputs = pipeline.get_output_processes(process) div = DivWdg() widget.add(div) div.add_class("spt_input_option") div.add_attr("spt_input_key", process) #if not outputs: # # then we can't go anywhere, so just add a message # text = "" # div.add(text) # continue values = [] #values.extend( [str(x) for x in inputs] ) values.append(process) values.extend( [str(x) for x in outputs] ) select = SelectWdg(self.get_input_name()) select.set_value(process) select.add_empty_option('-- Select --') select.set_option("values", values) div.add(select) from tactic.ui.panel import CellEditWdg CellEditWdg.add_edit_behavior(select) return widget
def get_display(my): widget = DivWdg() pipeline_code = my.get_option('pipeline') pipeline = Pipeline.get_by_code(pipeline_code) if not pipeline: widget.add("No pipeline defined") return widget processes = pipeline.get_process_names() widget.add_style("border: solid 1px blue") widget.add_style("position: absolute") widget.add_style("top: 300") widget.add_style("left: -500") for process in processes: #inputs = pipeline.get_input_processes(process) outputs = pipeline.get_output_processes(process) div = DivWdg() widget.add(div) div.add_class("spt_input_option") div.add_attr("spt_input_key", process) #if not outputs: # # then we can't go anywhere, so just add a message # text = "" # div.add(text) # continue values = [] #values.extend( [str(x) for x in inputs] ) values.append(process) values.extend( [str(x) for x in outputs] ) select = SelectWdg(my.get_input_name()) select.set_value(process) select.add_empty_option('-- Select --') select.set_option("values", values) div.add(select) from tactic.ui.panel import CellEditWdg CellEditWdg.add_edit_behavior(select) return widget
def get_display(self): # add a view action view_div = DivWdg() view_select = SelectWdg("action|view_action") view_select.add_style("text-align: right") view_select.add_empty_option("-- view --") view_select.set_option("values", "copy_url|add_my_view|edit|save|rename|delete|custom_property|custom_script") view_select.set_option("labels", "X Copy URL to this View|Add to My Views|Edit as Draft|Save Project View As|X Rename View|X Delete View|Add Custom Property|Add Custom Script") view_div.add_style("float: right") view_div.add(view_select) view_select.add_event("onchange", "spt.dg_table.view_action_cbk(this,'%s')" % self.table_id) return view_div
def get_display(self): # add a view action view_div = DivWdg() view_select = SelectWdg("action|table") view_select.add_style("text-align: right") view_select.add_empty_option("-- items --") view_select.set_option("values", "add|edit|retire|delete|export_all|export_selected") view_select.set_option("labels", "Add New Item|X Edit Selected|Retire Selected|Delete Selected|X CSV Export (all)|X CSV Export (selected)") view_div.add_style("float: right") view_div.add(view_select) #view_select.add_event("onchange", "spt.dg_table.retire_selected_cbk('%s')" % self.target_id) view_select.add_event("onchange", "spt.dg_table.table_action_cbk(this,'%s')" % self.table_id ) return view_div
def get_display(my): search_type = "prod/asset" web = WebContainer.get_web() related_asset = web.get_form_value("edit|related") search = Search(search_type) search.add_filter("code", related_asset) sobjects = search.get_sobjects() labels = "|".join( ["%s - %s" % (x.get_code(), x.get_value("name") ) for x in sobjects ] ) values = "|".join( [x.get_code() for x in sobjects ] ) select = SelectWdg( my.get_input_name() ) select.set_persist_on_submit() select.set_option("values", values) select.set_option("labels", labels) select.set_option("web_state","true") return select
def get_display(self): from calendar_wdg import CalendarInputWdg top = DivWdg() top.add_class("spt_input_top") if not self.calendar_key: self.calendar_key = 'read' top.add_attr("spt_cbjs_get_input_key", \ "var value=spt.dg_table.get_element_value(cell_to_edit, '%s'); return value" %self.get_name()) #top.add_style("background: black") # put in a default default_sel = SelectWdg(self.get_name()) for key, value in self.kwargs.items(): default_sel.set_option(key, value) sel_div = DivWdg(css='spt_input_option') sel_div.add_attr("spt_input_key", "default") #default_div.add("No options for selected [%s]" % depend_element) sel_div.add(default_sel) top.add(sel_div) cal = CalendarInputWdg(self.get_name()) cal_div = DivWdg(css='spt_input_option') cal_div.add_attr("spt_input_key", self.calendar_key) cal_div.add(cal) from tactic.ui.panel import CellEditWdg CellEditWdg.add_edit_behavior(default_sel) top.add(cal_div) return top
def get_display(my): search_type = "prod/asset" web = WebContainer.get_web() related_asset = web.get_form_value("edit|related") search = Search(search_type) search.add_filter("code", related_asset) sobjects = search.get_sobjects() labels = "|".join([ "%s - %s" % (x.get_code(), x.get_value("name")) for x in sobjects ]) values = "|".join([x.get_code() for x in sobjects]) select = SelectWdg(my.get_input_name()) select.set_persist_on_submit() select.set_option("values", values) select.set_option("labels", labels) select.set_option("web_state", "true") return select
def get_display(my): from calendar_wdg import CalendarInputWdg top = DivWdg() top.add_class("spt_input_top") if not my.calendar_key: my.calendar_key = 'read' top.add_attr("spt_cbjs_get_input_key", \ "var value=spt.dg_table.get_element_value(cell_to_edit, '%s'); return value" %my.get_name()) #top.add_style("background: black") # put in a default default_sel = SelectWdg(my.get_name()) for key, value in my.kwargs.items(): default_sel.set_option(key, value) sel_div = DivWdg(css='spt_input_option') sel_div.add_attr("spt_input_key", "default") #default_div.add("No options for selected [%s]" % depend_element) sel_div.add(default_sel) top.add(sel_div) cal = CalendarInputWdg(my.get_name()) cal_div = DivWdg(css='spt_input_option') cal_div.add_attr("spt_input_key", my.calendar_key) cal_div.add(cal) from tactic.ui.panel import CellEditWdg CellEditWdg.add_edit_behavior(default_sel) top.add(cal_div) return top
def get_display(my): div = DivWdg() table = Table() table.set_class("minimal") table.add_style("font-size: 0.8em") table.add_row() table.add_cell("File") table.add_cell('<input type="file" name="%s"/>' % (my.get_input_name()) ) table.add_row() table.add_cell("Context") select = SelectWdg("%s|context" % my.get_input_name() ) select.set_option("values", "publish|roughDesign|colorFinal|colorKey") table.add_cell(select) table.add_row() table.add_cell("Description") table.add_cell('<textarea name="%s|description"></textarea>' % my.get_input_name()) div.add(table) return div
def get_display(self): top = DivWdg() top.add_style("width: 200px") top.add_style("height: 200px") top.add_color("background", "background") top.add_color("padding", "10px") top.add_border() template = self.get_option("template") template = "prod/sequence" select = SelectWdg("foo") top.add(select) select.set_option("values", "XG|FF|WOW") text = TextWdg("foo") top.add(text) top.add("!!!!!") return top
def get_display(my): name = my.kwargs.get('name') select = SelectWdg(name) select.add_class('twog_move_select') select.set_option('empty','true') # limit to last 10 select.set_options(my.kwargs) # if it's not set from kwargs, we have this default values/labels if not my.kwargs.get('values_expr'): select.set_option('values_expr', "@GET(twog/movement['@LIMIT','10']['@ORDER_BY','timestamp desc'].code)") select.set_option('labels_expr', "@GET(twog/movement['@LIMIT','10']['@ORDER_BY','timestamp desc'].code) + ':' + @GET(twog/movement['@LIMIT','10']['@ORDER_BY','timestamp desc'].name)") return select
def get_display(my): top = DivWdg() top.add_class("spt_input_top") div = DivWdg() div.add_class("spt_input_option") key = 'main' div.add_attr("spt_input_key", key) query = my.kwargs.get("query"); query_filter = my.kwargs.get("query_filter"); input_name = my.kwargs.get("name"); select = SelectWdg(input_name) select.add_empty_option('-- Select --') values = my.kwargs.get("values") if values: select.set_option("values", values) labels = my.kwargs.get("labels") if labels: select.set_option("labels", labels) else: select.set_option("query", query) select.set_option("query_filter", query_filter) div.add(select) from tactic.ui.panel import CellEditWdg CellEditWdg.add_edit_behavior(select) top.add(div) return top
def get_display(self): top = DivWdg() top.add_class("spt_input_top") div = DivWdg() div.add_class("spt_input_option") key = 'main' div.add_attr("spt_input_key", key) query = self.kwargs.get("query"); query_filter = self.kwargs.get("query_filter"); input_name = self.kwargs.get("name"); select = SelectWdg(input_name) select.add_empty_option('-- Select --') values = self.kwargs.get("values") if values: select.set_option("values", values) labels = self.kwargs.get("labels") if labels: select.set_option("labels", labels) else: select.set_option("query", query) select.set_option("query_filter", query_filter) div.add(select) from tactic.ui.panel import CellEditWdg CellEditWdg.add_edit_behavior(select) top.add(div) return top
def get_display(self): return '' search_types = 'MMS/discipline.MMS/product_type'.split(".") top = DivWdg() parents = None for search_type in search_types: if not parents: search = Search(search_type) sobjects = search.get_sobjects() columns = search.get_columns() column = columns[1] select = SelectWdg(search_type) select.set_option("values", [x.get_id() for x in sobjects] ) select.set_option("labels", [x.get_value(column) for x in sobjects] ) top.add(select) else: for parent in parents: search = Search(search_type) search.add_relationship_filter(parent) sobjects = search.get_sobjects() if not sobjects: continue columns = search.get_columns() column = columns[1] values = [x.get_id() for x in sobjects] labels = [x.get_value(column) for x in sobjects] select = SelectWdg(search_type) select.add_attr("spt_input_key", parent.get_id() ) select.set_option("values", values ) select.set_option("labels", labels ) top.add(select) parents = sobjects return top
def get_display(my): return '' search_types = 'MMS/discipline.MMS/product_type'.split(".") top = DivWdg() parents = None for search_type in search_types: if not parents: search = Search(search_type) sobjects = search.get_sobjects() columns = search.get_columns() column = columns[1] select = SelectWdg(search_type) select.set_option("values", [x.get_id() for x in sobjects] ) select.set_option("labels", [x.get_value(column) for x in sobjects] ) top.add(select) else: for parent in parents: search = Search(search_type) search.add_relationship_filter(parent) sobjects = search.get_sobjects() if not sobjects: continue columns = search.get_columns() column = columns[1] values = [x.get_id() for x in sobjects] labels = [x.get_value(column) for x in sobjects] select = SelectWdg(search_type) select.add_attr("spt_input_key", parent.get_id() ) select.set_option("values", values ) select.set_option("labels", labels ) top.add(select) parents = sobjects return top
def get_display(my): widget = DivWdg(id='new_item_panel') widget.add_class("new_item_panel") widget.add_class("spt_new_item_top") div = DivWdg() div.add_color("background", "background") div.add_color("color", "color") div.add_style("padding", "5px") div.add_border() if my.is_personal: is_personal = 'true' else: is_personal = 'false' if my.type == 'new_folder': #div.set_attr('spt_view', 'new_folder') div.add(HtmlElement.b('Create New Folder')) div.add(HtmlElement.br(2)) item_div = DivWdg(css='spt_new_item') item_div.add_style('display: none') div.add(HtmlElement.br()) div.add(item_div) """ # add exisiting views in the div for checking with client's input # add exiting views: from panel_wdg import ViewPanelSaveWdg views = ViewPanelSaveWdg.get_existing_views(my.is_personal) hidden = HiddenWdg('existing_views', '|'.join(views)) div.add(hidden) """ text2 = TextWdg("new_title") text2.add_class("spt_new_item_title") span = SpanWdg("Title: ") span.set_id('create_new_title') #span.add_style('display: none') span.add_style('padding-left: 8px') span.add(text2) div.add(span) div.add(HtmlElement.br(2)) div.add_style("width: 350px") action = ''' var top = bvr.src_el.getParent(".spt_new_item_top"); var name_el = top.getElement(".spt_new_item_name"); var title = bvr.src_el.value; var name = title.replace(/[\?.!@#$%^&*()'"]/g, ""); name = name.replace(/ /g, "_"); name = name.toLowerCase(); name_el.value = name; ''' # change the name based on the title text2.add_behavior({'type': 'change', 'cbjs_action': action}) div.add( "The name of the folder is a hidden name that is used by other elements to refer to uniquely to this item.<br/><br/>" ) text = TextWdg('new_name') text.add_class("spt_new_item_name") span = SpanWdg('Name: ') span.add(text) div.add(span) div.add(HtmlElement.br(2)) #script = "spt.side_bar.manage_section_action_cbk({'value':'predefined'},'project_view');" #link = HtmlElement.js_href(script, data='[ Predefined View ]') #div3 = DivWdg('Optional: drag existing elements from Project Views or %s into this new folder' %link.get_buffer_display()) #div.add(div3) #item_div = DivWdg(css='spt_new_item spt_side_bar_content') #div.add(item_div) div.add("<hr/>") #save_div = SpanWdg(css='med hand') #div.add(save_div) #save_div.add(IconWdg('Save Folder', IconWdg.SAVE)) save_button = ActionButtonWdg(title='Create', tip='Create a new folder') div.add(save_button) bvr = { "type": "click_up", "view": my.view, "is_personal": is_personal == 'true', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_new_item_top"); var name_el = top.getElement(".spt_new_item_name"); var name_value = name_el.value; if (name_value == "") { var title_el = top.getElement(".spt_new_item_title"); var title = title_el.value; var name = spt.convert_to_alpha_numeric(title); name_el.value = name; } if (name_value == "") { spt.alert("Please fill in a value for name."); return; } spt.side_bar.manage_section_action_cbk( { 'value':'save_folder'}, bvr.view, bvr.is_personal); ''' } save_button.add_behavior(bvr) div.add(HtmlElement.br()) elif my.type == 'new_link': div.set_attr('spt_view', 'new_link') div.add(HtmlElement.b('Create New Link')) div.add(HtmlElement.br()) item_div = DivWdg(css='spt_new_item') item_div.add_style('display: none') div.add(HtmlElement.br()) div.add(item_div) text = TextWdg('new_link_title') span = SpanWdg('Title: ') span.add(text) div.add(span) div.add(HtmlElement.br(2)) cb = CheckboxWdg('include_search_view', label='Include Saved Search') cb.set_default_checked() div.add(cb) div.add(HtmlElement.br(2)) div.add("Select a search type and view of this link") div.add(HtmlElement.br()) select = SelectWdg("new_search_type") select.add_empty_option("-- Select Search type --") security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): search_types = Project.get().get_search_types( include_sthpw=True, include_config=True) else: search_types = Project.get().get_search_types() values = [x.get_value("search_type") for x in search_types] labels = [ "%s (%s)" % (x.get_value("search_type"), x.get_title()) for x in search_types ] values.append("CustomLayoutWdg") labels.append("CustomLayoutWdg") select.set_option("values", values) select.set_option("labels", labels) #security = Environment.get_security() #if security.check_access("builtin", "view_site_admin", "allow"): # select_mode = SearchTypeSelectWdg.ALL #else: # select_mode = SearchTypeSelectWdg.ALL_BUT_STHPW #select = SearchTypeSelectWdg(name='new_search_type', \ # mode=select_mode) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var top = bvr.src_el.getParent(".new_item_panel"); var link_view_select = top.getElement(".link_view_select"); var input = spt.api.Utility.get_input(top, 'new_search_type'); var values = {'search_type': input.value, 'is_refresh': 'true'}; spt.panel.refresh(link_view_select, values);''' }) div.add(HtmlElement.br()) div.add(select) div.add(HtmlElement.br()) link_view_sel = NewLinkViewSelectWdg() div.add(HtmlElement.br()) div.add(link_view_sel) div.add(HtmlElement.br()) #select.add_behavior('change') div.add(HtmlElement.hr()) div.add(HtmlElement.br()) #save_div = DivWdg(css='med hand') #div.add(save_div) #save_button = ProdIconButtonWdg('Save Link', IconWdg.SAVE) #save_div.add(save_button) save_button = ActionButtonWdg(title='Create', tip='Create a new link') div.add(save_button) bvr = { "type": "click_up", 'cbjs_action': "spt.side_bar.manage_section_action_cbk({"\ "'value':'save_link'},'%s', %s);" %(my.view, is_personal)} save_button.add_behavior(bvr) div.add(HtmlElement.br(1)) elif my.type == 'new_separator': div.set_attr('spt_view', 'new_separator') div.add(HtmlElement.b('Creating New Separator. . .')) div.add(HtmlElement.br()) item_div = DivWdg(css='spt_new_item') item_div.add_style('display: none') div.add(HtmlElement.br()) div.add(item_div) # since it's automated, this button is not needed """ save_div = SpanWdg(css='med hand') save_div.add(IconWdg('Save', IconWdg.SAVE)) bvr = { "type": "click_up",\ 'cbjs_action': "spt.side_bar.manage_section_action_cbk({"\ "'value':'save_separator'},'%s');" %my.view} save_div.add_behavior(bvr) div.add(save_div) """ widget.add(div) return widget
def get_display(my): my.labels_attr = my.get_option('label_attr') if my.labels_attr: my.labels_attr = my.labels_attr.split('|') from tactic.ui.panel import EditWdg if hasattr(my, 'parent_wdg') and isinstance(my.get_parent_wdg(), EditWdg): sobject = my.get_current_sobject() parent = sobject.get_parent() group = None pipeline_code = None if parent: pipeline_code = parent.get_value('pipeline_code') pipeline = Pipeline.get_by_code(pipeline_code) labels_expr = None if pipeline: attrs = pipeline.get_process_attrs(sobject.get_value('process')) group = attrs.get('%s_login_group'%my.get_name()) if group: values_expr = "@GET(sthpw/login_group['login_group', '%s'].sthpw/login_in_group.sthpw/login.login)"%group if my.labels_attr: labels_expr = ["@GET(sthpw/login_group['login_group', '%s'].sthpw/login_in_group.sthpw/login.%s)"%(group, x.strip()) for x in my.labels_attr] labels_expr = ' +   + '.join(labels_expr) else: values_expr = "@GET(sthpw/login.login)" if my.labels_attr: labels_expr = ["@GET(sthpw/login.%s)"%(x.strip()) for x in my.labels_attr] labels_expr = ' +   + '.join(labels_expr) select = SelectWdg(my.get_input_name()) select.add_empty_option("-- Select a User --") """ values = [] labels = [] for user in group_users: values.append(user) labels.append(' %s'%user) """ select.set_option('values_expr', values_expr) if labels_expr: select.set_option('labels_expr', labels_expr) current_value = sobject.get_value(my.get_name()) if current_value: select.set_value(current_value) return select #all_users = Search.eval("@GET(sthpw/login.login)") all_users = Search.eval("@SOBJECT(sthpw/login)") all_users_label = [] # don't use expression here since it's not as db-efficient as retrieving the sobjects """ if my.labels_attr: labels_expr = ["@GET(sthpw/login.login.%s)"%x.strip() for x in my.labels_attr] """ ''' groups = Search.eval("@SOBJECT(sthpw/login_group)") group_dict = {} for group in groups: group_users = Search.eval("@GET(sthpw/login_group['login_group', '%s'].sthpw/login_in_group.sthpw/login.login)"%group.get_value('login_group')) group_dict[group.get_value('login_group')] = group_users ''' logins_dict = {} for user in all_users: user_name = user.get_value('login') logins_dict[user_name] = {} group_dict = {} items = Search.eval("@SOBJECT(sthpw/login_in_group)") for item in items: item_login = item.get_value("login") if logins_dict.get(item_login) == None: continue item_group = item.get_value("login_group") group_list = group_dict.get(item_group) if group_list == None: group_list = [] group_dict[item_group] = group_list group_list.append(item_login) top = DivWdg() top.add_class("spt_input_top") # HACK! This isn't very well constructed ### Tore: Not my code! Copied from ProcessContextInputWdg. Seems to work though. top.add_attr("spt_cbjs_get_input_key", "return cell_to_edit.getAttribute('spt_pipeline_code');") # Adding an "all users" select option in case it can't find a useful select widget. div = DivWdg() div.add_class("spt_input_option") #div.add_attr("spt_input_key", '__all__') #Not needed, since it defaults to the first one anyway. select = SelectWdg(my.get_name()) select.add_empty_option("-- Select a User --") values = [] labels = [] labels_dict = {} for user in all_users: user_name = user.get_value('login') values.append(user_name) label = user_name if my.labels_attr: user_labels = [user.get_value(x) for x in my.labels_attr] label = ' '.join(user_labels) labels_dict[user_name] = label labels.append('%s'%label) #print "select ", user_name # -- NOTE: leaving this commented out code here for reference. Not sure why this is the case but when # -- this click behavior is used instead of a 'change' behavior that forces a blur on select, # -- click selection only works for this widget in Firefox and does NOT work in IE # # select.add_behavior( { 'type': 'click', # 'cbjs_action': 'spt.dg_table.select_wdg_clicked( evt, bvr.src_el );' } ) # -- Replace previous 'click' behavior with a 'change' behavior to force blur() of select element ... # -- this works for both Firefox and IE # select.add_behavior( { 'type': 'change', 'cbjs_action': 'bvr.src_el.blur();' } ) #behavior = { # 'type': 'keyboard', # 'kbd_handler_name': 'DgTableSelectWidgetKeyInput', #} #select.add_behavior( behavior ) select.set_option("values", values) select.set_option("labels", labels) div.add(select) top.add(div) #Building each of the select widgets per group here. for group in group_dict.keys(): div = DivWdg() div.add_class("spt_input_option") div.add_attr("spt_input_key", group) select = SelectWdg(my.get_name()) select.add_empty_option("-- Select a User --") values = [''] labels = ['<< %s >>'%group] for user in group_dict[group]: values.append(user) label = labels_dict.get(user) labels.append(' %s'%label) select.add_behavior( { 'type': 'click', 'cbjs_action': 'spt.dg_table.select_wdg_clicked( evt, bvr.src_el );' } ) #behavior = { # 'type': 'keyboard', # 'kbd_handler_name': 'DgTableSelectWidgetKeyInput', #} #select.add_behavior( behavior ) select.set_option("values", values) select.set_option("labels", labels) div.add(select) top.add(div) return top
def get_display(my): top = DivWdg() top.add_class("spt_top") dialog = DialogWdg() dialog_id = dialog.get_id() # create the button button = DivWdg() button.add_style("padding: 5px") button.add_style("width: 30px") button.add_style("text-align: center") button.add_style("float: left") button.add_gradient("background", "background") button.add_border() top.add(button) icon = IconWdg("Press Me", IconWdg.ZOOM) icon.add_style("float: left") button.add(icon) icon = IconWdg("Press Me", IconWdg.INFO_OPEN_SMALL) icon.add_style("margin-left: -9px") button.add(icon) button.add_behavior({ 'type': 'click_up', 'dialog_id': dialog_id, 'cbjs_action': ''' var pos = bvr.src_el.getPosition(); var el = $(bvr.dialog_id); el.setStyle("left", pos.x+1); el.setStyle("top", pos.y+32); el.setStyle("display", ""); ''' }) # defined the dialog top.add(dialog) dialog.add_title("Search Limit") table = Table() table.add_color("color", "color2") dialog.add(table) table.add_row() td = table.add_cell() td.add("Search Limit: ") td = table.add_cell() select = SelectWdg("search_limit") select.set_option("values", "5|10|20|50|100|200|Custom") td.add(select) save_button = ProdIconButtonWdg("Save") td.add(save_button) cancel_script = dialog.get_cancel_script() save_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var dialog_top = bvr.src_el.getParent(".spt_dialog_top"); var values = spt.api.get_input_values(dialog_top); var top = spt.get_parent(bvr.src_el, ".spt_top"); var input = top.getElement(".spt_search_limit"); input.value = values.search_limit; %s ''' % cancel_script }) text = TextWdg("search_limit") text.add_class("spt_search_limit") top.add(text) return top
def get_filter_wdg(my): div = DivWdg() div.add_style("padding: 10px") div.add_style("margin: -10 -10 10 -10") div.add_style("min-width: 600px") div.add_class("spt_view_manager_filter") from tactic.ui.app import HelpButtonWdg help_wdg = HelpButtonWdg(alias="view-manager|what-are-views") div.add(help_wdg) help_wdg.add_style("float: right") div.add("<b>Search Type:</b> ") div.add_gradient("background", "background", -10) security = Environment.get_security() project = Project.get() if security.check_access("builtin", "view_site_admin", "allow"): search_type_objs = project.get_search_types(include_sthpw=True, include_config=True) else: search_type_objs = project.get_search_types() search_types = [x.get_value("search_type") for x in search_type_objs] titles = ["%s (%s)" % (x.get_value("search_type"), x.get_value("title")) for x in search_type_objs] select = SelectWdg(name="search_type") select.set_option("values", search_types) select.set_option("labels", titles) select.add_empty_option("-- Select --") select.set_persistence() # select.set_persist_on_submit() # security = Environment.get_security() # if security.check_access("builtin", "view_site_admin", "allow"): # select_mode = SearchTypeSelectWdg.ALL # else: # select_mode = SearchTypeSelectWdg.ALL_BUT_STHPW # select = SearchTypeSelectWdg(name='search_type', \ # mode=select_mode) behavior = { "type": "change", "cbjs_action": """ var manager_top = bvr.src_el.getParent(".spt_view_manager_top"); var input = spt.api.Utility.get_input(manager_top, 'search_type'); var view_input = spt.api.Utility.get_input(manager_top, 'view'); var view_input_value = ''; if (view_input != null) { view_input_value = view_input.value; } var values = {'search_type': input.value, 'view': view_input_value, 'is_refresh': 'true'}; spt.panel.refresh(manager_top, values);""" # //spt.panel.refresh(manager_top, values);''' } select.add_behavior(behavior) select.set_value(my.search_type) div.add(select) if not my.search_type: content = DivWdg() content.add_style("width: 400px") content.add_style("height: 400px") div.add(content) content.add_style("padding: 20px") content.add(IconWdg("WARNING", IconWdg.WARNING)) content.add("No Search Type Selected") content.add_border() content.add_style("margin-top: 20px") content.add_color("background", "background") content.add_style("font-weight: bold") return div div.add(" ") div.add("<b>View: </b>") view_wdg = SelectWdg("view") view_wdg.set_value(my.view) view_wdg.add_empty_option("-- Select --") view_wdg.add_behavior(behavior) div.add(view_wdg) search = Search("config/widget_config") search.add_filter("search_type", my.search_type) db_configs = search.get_sobjects() views = set() for db_config in db_configs: view = db_config.get_value("view") if view.startswith("link_search:"): continue views.update([view]) # print "search_type: ", my.search_type # print "view: ", views, my.view if my.search_type and my.view: config_view = WidgetConfigView.get_by_search_type(my.search_type, my.view) configs = config_view.get_configs() for x in configs: view = x.get_view() file_path = x.get_file_path() if view != my.view: continue if file_path and file_path.endswith("DEFAULT-conf.xml"): continue config_views = x.get_all_views() views.update(config_views) views_list = list(views) views_list.sort() view_wdg.set_option("values", views_list) return div
def get_nav_wdg(self): #base_dir = self.kwargs.get("base_dir") #location = self.kwargs.get("location") base_dir = self.session.get_value("base_dir") location = self.session.get_value("location") nav_wdg = DivWdg() nav_wdg.add("<b>Session 101 - Clean up self Crap</b><hr/>") nav_wdg.add_style("margin-bottom: 10px") nav_wdg.add_class("spt_file_nav") nav_wdg.add_style("width: 575px") nav_wdg.add_border() nav_wdg.set_round_corners() nav_wdg.add_style("padding: 5px") button = ActionButtonWdg(title="Scan", tip="Scan for files in specified folder") button.add_style("float: right") button.add_style("margin-top: -5px") nav_wdg.add(button) from tactic.ui.input import TextInputWdg title_wdg = "Session Title: " nav_wdg.add(title_wdg) text = TextInputWdg(name="title") text.add_class("spt_title") text.add_style("width: 300px") nav_wdg.add(text) nav_wdg.add("<br/><br/>") folder_wdg = "Base folder of this session: " nav_wdg.add(folder_wdg) text = TextInputWdg(name="base_dir") text.add_class("spt_base_dir") text.add_style("width: 300px") if base_dir: text.set_value(base_dir) nav_wdg.add(text) # add a hidden paths variable text = HiddenWdg("paths") text.add_class("spt_paths") nav_wdg.add(text) nav_wdg.add("<br/>") # add a hidden paths variable select = SelectWdg("location") if location: select.set_value(location) nav_wdg.add("<br/>") nav_wdg.add("Folder is on ") nav_wdg.add(select) select.set_option("values", "local|server") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_ingestion_top"); var nav = top.getElement(".spt_file_nav"); var nav_values = spt.api.Utility.get_input_values(nav,null,false); var base_dir = nav_values.base_dir; var location = nav_values.location; spt.app_busy.show("Scanning", base_dir); if (location == 'local') { var applet = spt.Applet.get(); var paths = applet.list_dir(base_dir, 2); var paths_el = nav.getElement(".spt_paths"); var js_paths = []; for (var i = 0; i < paths.length; i++) { var js_path = paths[i].replace(/\\\\/g,"/"); if (applet.is_dir(js_path) ) { js_path = js_path + '/'; js_paths.push(js_path); } //if (i > 100) break; else { js_paths.push(js_path); } } paths_el.value = js_paths.join("|"); } //var nav_values = spt.api.Utility.get_input_values(nav,null,false); //spt.panel.refresh(top, nav_values); spt.tab.set_tab_top(top); spt.tab.select("files") var class_name = "tactic.ui.tools.IngestionToolDirListWdg"; var kwargs = { base_dir: base_dir, location: location, paths: js_paths } spt.tab.load_selected("files", "Files", class_name, kwargs); spt.app_busy.hide(); ''' } ) return nav_wdg
def get_display(my): top_wdg = DivWdg() top_wdg.add_style("color: black") top_wdg.add_style("width: 350px") top_wdg.add_style("margin-top: 10px") top_wdg.add_style("padding: 10px") top_wdg.add_border() title = DivWdg() title.add_style("color: black") title.add_style("margin-top: -22px") top_wdg.add(title) #if not my.name_string: # title.add('No database column') # return top_wdg title.add("Widget Definition") widget_types = { 'foreign_key': 'tactic.ui.table.ForeignKeyElementWdg', 'button': 'tactic.ui.table.ButtonElementWdg', 'expression': 'tactic.ui.table.ExpressionElementWdg' } web = WebContainer.get_web() config_string = web.get_form_value("config_xml") if not config_string: config_string = '<config/>' xml = Xml() xml.read_string(config_string) #print "config_string: ", config_string # get values from the config file element_name = xml.get_value('element/@name') config = WidgetConfig.get( view='element', xml='<config><element>%s</element></config>' % config_string) display_options = config.get_display_options(element_name) title = xml.get_value('element/@title') display_handler = xml.get_value('element/display/@class') if not display_handler: display_handler = 'tactic.ui.panel.TypeTableElementWdg' widget_name = xml.get_value('element/display/@widget') if not widget_name: widget_name = 'custom' custom_table = Table() custom_table.add_style("color: black") top_wdg.add(custom_table) name_text = DivWdg() name_text.add_style("color: black") name_text.add(element_name) custom_table.add_row() custom_table.add_cell("Name: ") custom_table.add_cell(name_text) # add title custom_table.add_row() title_wdg = TextWdg("custom_title") title_wdg.set_value(title) title_wdg.add_attr("size", "50") custom_table.add_cell("Title: ") custom_table.add_cell(title_wdg) # add description #custom_table.add_row() #description_wdg = TextAreaWdg("custom_description") #td = custom_table.add_cell( "Description: " ) #td.add_style("vertical-align: top") #custom_table.add_cell( description_wdg ) type_select = SelectWdg("custom_type") #type_select.add_empty_option("-- Select --") type_select.set_option( "values", "string|integer|float|boolean|currency|date|foreign_key|link|list|button|custom" ) type_select.set_option( "labels", "String(db)|Integer(db)|Float(db)|Boolean(db)|Currency(db)|Date(db)|Foreign Key|Link|List|Button|Custom" ) type_select.set_value(widget_name) #type_select.set_option("values", "string|integer|float|boolean|currency|date|link|list|foreign_key|button|empty") #type_select.set_option("labels", "String|Integer|Float|Boolean|Currency|Date|Link|List|Foreign Key|Button|Empty") custom_table.add_row() td = custom_table.add_cell("Widget Type: ") td.add_style("vertical-align: top") td = custom_table.add_cell(type_select) type_select.add_event( "onchange", "spt.CustomProject.property_type_select_cbk(this)") td.add(HtmlElement.br()) display_handler_text = TextWdg("display_handler") display_handler_text.add_attr("size", "50") display_handler_text.set_value(display_handler) td.add(display_handler_text) # extra info for foreign key custom_table.add_row() div = DivWdg() div.add_class("foreign_key_options") div.add_style("display: none") div.add_style("margin-top: 10px") div.add("Options") div.add(HtmlElement.br()) # extra info for foreign key custom_table.add_row() div = DivWdg() div.add_class("foreign_key_options") div.add_style("display: none") div.add_style("margin-top: 10px") div.add("Options") div.add(HtmlElement.br()) # TODO: this class should not be in prod!! from pyasm.prod.web import SearchTypeSelectWdg div.add("Relate to: ") search_type_select = SearchTypeSelectWdg( "foreign_key_search_select", mode=SearchTypeSelectWdg.CURRENT_PROJECT) div.add(search_type_select) td.add(div) # extra info for list custom_table.add_row() div = DivWdg() div.add_class("list_options") div.add_style("display: none") div.add_style("margin-top: 10px") div.add("Options") div.add(HtmlElement.br()) # TODO: this class should not be in prod!! from pyasm.prod.web import SearchTypeSelectWdg div.add("Values: ") search_type_text = TextWdg("list_values") div.add(search_type_text) td.add(div) # extra info for button custom_table.add_row() div = DivWdg() div.add_style("color: black") div.add_class("button_options") div.add_style("display: none") div.add_style("margin-top: 10px") #class_path = "tactic.ui.table.ButtonElementWdg" class_path = display_handler button = Common.create_from_class_path(class_path) args_keys = button.get_args_keys() div.add("Options") div.add(HtmlElement.br()) for key in args_keys.keys(): option_name_text = HiddenWdg("option_name") option_name_text.set_value(key) div.add(option_name_text) div.add("%s: " % key) div.add(" ") input = button.get_input_by_arg_key(key) value = display_options.get(key) if value: input.set_value(value) div.add(input) div.add(HtmlElement.br()) td.add(div) # is searchable checkbox #custom_table.add_row() #current_searchable_wdg = CheckboxWdg("is_searchable") #current_view_wdg.set_checked() #custom_table.add_cell("Searchable? ") #td = custom_table.add_cell(current_searchable_wdg) custom_table.close_tbody() return top_wdg
def get_simple_definition_wdg(my): detail_wdg = DivWdg() detail_wdg.add_color("color", "color") detail_wdg.add_style("width: 350px") detail_wdg.add_style("margin-top: 10px") detail_wdg.add_style("padding: 10px") detail_wdg.add_border() title = DivWdg() title.add_style("margin-top: -23px") detail_wdg.add(title) if not my.name_string: title.add('No database column') return detail_wdg title.add("Column Definition") # add a name entry detail_wdg.add("<br/>") title = SpanWdg() detail_wdg.add("Name: ") detail_wdg.add(title) input = SpanWdg() input.add_style('padding-top: 6px') input.set_id("config_element_name") input.add(HtmlElement.b(my.name_string)) detail_wdg.add(input) hidden = HiddenWdg('column_name', my.name_string) detail_wdg.add(hidden) hidden = HiddenWdg('target_search_type', my.search_type) detail_wdg.add(hidden) detail_wdg.add(HtmlElement.br(2)) # add data_type entry data_type = SpanWdg() default_data_types = [ 'varchar(256)', 'varchar', 'character', 'text', 'integer', 'float', 'boolean', 'timestamp', 'Other...' ] select = SelectWdg('config_data_type', label='Data Type: ') #detail_wdg.add(": ") select.set_option('values', default_data_types) select.set_value(my.data_type_string) select.add_behavior({ 'type': 'change', 'cbjs_action': "if (bvr.src_el.value=='Other...') {spt.show('config_data_type_custom');}\ else {spt.hide('config_data_type_custom');}" }) data_type.add(select) text = TextWdg('config_data_type_custom') span = SpanWdg("Other: ", css='med') span.add(text) span.set_id('config_data_type_custom') span.add_style('display', 'none') text.set_value(my.data_type_string) data_type.add("<br/>") data_type.add(span) detail_wdg.add(data_type) detail_wdg.add("<br/>") # add a nullable entry nullable = SpanWdg() checkbox = CheckboxWdg('config_nullable', label='Allow null(empty) value: ') #detail_wdg.add(": ") nullable.add(checkbox) if my.nullable_string in ['True', 'true']: checkbox.set_checked() detail_wdg.add(nullable) #constraint = DivWdg() #detail_wdg.add(constraint) #constraint.add_style("margin-top: 10px") #constraint.add("Constraint: ") #select = SelectWdg("config_constraint") #constraint.add(select) #select.set_option("values", "unique|indexed") #select.add_empty_option("-- None --") button_div = DivWdg() button_div.add_style("text-align: center") button_div.add_behavior({ 'type': 'load', 'cbjs_action': ''' spt.manage_search_type = {}; spt.manage_search_type.change_column_cbk = function(bvr) { var class_name = 'tactic.ui.panel.AlterSearchTypeCbk'; var options ={ 'alter_mode': bvr.alter_mode, 'title': bvr.title }; try { var server = TacticServerStub.get(); var panel = $('search_type_detail'); if (! panel.getAttribute("spt_class_name") ) { panel = panel.getParent(".spt_panel"); } var values = spt.api.Utility.get_input_values(panel); rtn = server.execute_cmd(class_name, options, values); if (bvr.alter_mode == 'Remove Column') spt.info("Column [" + bvr.column + "] has been deleted."); else if (bvr.alter_mode == 'Modify Column') spt.notify.show_message("Column [" + bvr.column + "] has been modified."); } catch (e) { spt.alert(spt.exception.handler(e)); } var view = 'db_column'; spt.panel.refresh("ManageSearchTypeMenuWdg_" + view); var view = 'definition'; spt.panel.refresh("ManageSearchTypeMenuWdg_" + view); } ''' }) detail_wdg.add(button_div) button_div.add("<hr/><br/>") if my.is_new_column: button = ActionButtonWdg(title="Commit") #button = ProdIconButtonWdg("Commit New Column") button.add_behavior({"type": "click_up", "cbjs_action": "spt.manage_search_type.change_column_cbk(bvr)", \ "alter_mode": my.ADD_COLUMN}) button_div.add(button) else: table = Table() button_div.add(table) table.add_row() table.center() button = ActionButtonWdg(title="Modify") #button = ProdIconButtonWdg("Modify Column") button.add_behavior({ "type": "click_up", "cbjs_action": '''spt.manage_search_type.change_column_cbk(bvr); ''', "alter_mode": my.MODIFY_COLUMN, "column": my.name_string, "title": my.title_string }) table.add_cell(button) button = ActionButtonWdg(title="Delete") #button = ProdIconButtonWdg("Delete Column") #button.add_style('background-color: #BF462E') button.add_behavior({ "type": "click_up", "cbjs_action": ''' var yes = function() { spt.manage_search_type.change_column_cbk(bvr); } spt.confirm("Are you sure you wish to delete this column?", yes) ''', "alter_mode": my.REMOVE_COLUMN, "column": my.name_string }) table.add_cell(button) button_div.add(HiddenWdg('delete_column')) button_div.add(HiddenWdg('modify_column')) return detail_wdg
def get_new_definition_wdg(my): detail_wdg = DivWdg() detail_wdg.add_style("color: black") detail_wdg.add_style("width: 350px") detail_wdg.add_style("margin-top: 10px") detail_wdg.add_style("padding: 10px") detail_wdg.add_border() title = DivWdg() title.add_style("color: black") title.add("Column Definition") title.add_style("margin-top: -22px") detail_wdg.add(title) # add a name entry title = SpanWdg() detail_wdg.add("Name: ") detail_wdg.add(title) input = SpanWdg() input.add_style('padding-top: 6px') input.set_id("config_element_name") text = TextWdg('column_name') text.set_value(my.name_string) input.add(text) detail_wdg.add(input) hidden = HiddenWdg('target_search_type', my.search_type) detail_wdg.add(hidden) detail_wdg.add(HtmlElement.br(2)) # add data_type entry data_type = SpanWdg() default_data_types = [ 'varchar(256)', 'varchar', 'character', 'text', 'integer', 'float', 'boolean', 'timestamp', 'Other...' ] select = SelectWdg('config_data_type', label='Data Type: ') #detail_wdg.add(": ") select.set_option('values', default_data_types) select.set_value(my.data_type_string) select.add_behavior({ 'type': 'change', 'cbjs_action': "if (bvr.src_el.value=='Other...') {spt.show('config_data_type_custom');}\ else {spt.hide('config_data_type_custom');}" }) data_type.add(select) text = TextWdg('config_data_type_custom') span = SpanWdg("Other: ", css='med') span.add(text) span.set_id('config_data_type_custom') span.add_style('display', 'none') text.set_value(my.data_type_string) data_type.add("<br/>") data_type.add(span) detail_wdg.add(data_type) detail_wdg.add("<br/>") # add a nullable entry nullable = DivWdg() checkbox = CheckboxWdg('config_nullable', label='Allow null(empty) value: ') nullable.add(checkbox) if my.nullable_string in ['True', 'true']: checkbox.set_checked() detail_wdg.add(nullable) return detail_wdg
def get_display(self): parser = self.kwargs.get("parser") self.search_key = self.kwargs.get("search_key") sobject = Search.get_by_search_key(self.search_key) if sobject.get_base_search_type() == "sthpw/snapshot": snapshot = sobject elif sobject.get_base_search_type() == "sthpw/file": # if it is a file object snapshot = sobject.get_parent() else: snapshots = Snapshot.get_by_sobject(sobject, is_latest=True) snapshot = snapshots[0] # Extension determine UI class for preview thumb_path = snapshot.get_web_path_by_type("icon") web_src = snapshot.get_web_path_by_type("web") from pyasm.biz import File file_type = "main" lib_path = snapshot.get_lib_path_by_type(file_type) src = snapshot.get_web_path_by_type(file_type) if not web_src: web_src = src parts = os.path.splitext(src) ext = parts[1] ext = ext.lstrip(".") ext = ext.lower() #parent = snapshot.get_parent() top = self.top self.set_as_panel(top) if ext == "pdf": iframe = HtmlElement.iframe() iframe.set_attr('src', src) iframe.add_style("width: 100%") iframe.add_style("height: 800px") top.add(iframe) return top from tactic.ui.container import ResizableTableWdg table = ResizableTableWdg() top.add(table) tr = table.add_row() # These bvrs allow for smooth switching if switching between files # like in the RepoBrowserWdg tr.add_style("height: 200px") load_height_bvr = { 'type': 'load', 'cbjs_action': ''' var last_height = spt.container.get_value("last_img_height"); if (last_height) { bvr.src_el.setStyle("height", last_height); } ''' } tr.add_behavior(load_height_bvr) unload_height_bvr = { 'type': 'unload', 'cbjs_action': ''' var last_height = bvr.src_el.getStyle("height"); spt.container.set_value("last_img_height", last_height); ''' } tr.add_behavior(unload_height_bvr) table.add_style("width: 100%") table.add_style("text-align", "center") from tactic.ui.widget import EmbedWdg td = table.add_cell() td.add_color( "background", "background", ) td.add_style("vertical-align: middle") td.add_style("height: inherit") td.add_style("overflow-x: auto") if ext in ['txt', 'html', 'ini']: content_div = DivWdg() f = open(lib_path, 'r') content = f.read(10000) f.close() if not content: text = "No Content" else: size = os.path.getsize(lib_path) from pyasm.common import FormatValue value = FormatValue().get_format_value(size, "KB") content_div.add("Showing first 10K of %s<hr/>" % value) text = TextAreaWdg() text.add(content) text.add_style("width: 100%") text.add_style("height: 100%") text.add_style("padding: 10px") text.add_style("border: none") text.add_attr("readonly", "true") content_div.add(text) td.add(content_div) content_div.add_style("color", "#000") content_div.add_style("width", "auto") content_div.add_style("margin", "20px") content_div.add_style("height", "100%") elif ext in File.IMAGE_EXT or ext == "gif": if lib_path.find("#") != -1: img = DivWdg() file_range = snapshot.get_file_range() file_range_div = DivWdg() file_range_div.add("File Range: %s" % file_range.get_display()) img.add(file_range_div) file_range_div.add_style("font-size: 1.4em") file_range_div.add_style("margin: 15px 0px") """ left_chevron = IconWdg("Previous", "BS_CHEVRON_LEFT") file_range_div.add(left_chevron) right_chevron = IconWdg("Next", "BS_CHEVRON_RIGHT") file_range_div.add(right_chevron) """ expanded_paths = snapshot.get_expanded_web_paths() lib_paths = snapshot.get_expanded_lib_paths() lib_path = lib_paths[0] items_div = DivWdg() img.add(items_div) items_div.add_style("width: auto") for path in expanded_paths: item = HtmlElement.img(src=path) items_div.add(item) item.add_style("max-height: 300px") item.add_style("height: auto") item.add_style("width: 32%") item.add_style("margin: 2px") item.add_style("display: inline-block") #item.add_class("spt_resizable") img.add_style("margin: 20px") img.add_style("max-height: 400px") img.add_style("overflow-y: auto") img.add_style("overflow-hidden: auto") img.add_style("text-align: left") else: if ext == "gif": img = HtmlElement.img(src=src) else: img = HtmlElement.img(src=web_src) img.add_style("height: inherit") img.add_style("width: auto") td.add(img) elif ext in File.VIDEO_EXT: embed_wdg = EmbedWdg(src=src, thumb_path=thumb_path, preload="auto", controls=True) td.add(embed_wdg) embed_wdg.add_style("margin: auto auto") embed_wdg.add_class("spt_resizable") embed_wdg.add_behavior(load_height_bvr) embed_wdg.add_behavior(unload_height_bvr) else: thumb_table = DivWdg() td.add(thumb_table) thumb_table.add_behavior({ 'type': 'click_up', 'src': src, 'cbjs_action': ''' window.open(bvr.src); ''' }) thumb_table.add_class("hand") thumb_table.add_style("width: 200px") thumb_table.add_style("height: 125px") thumb_table.add_style("padding: 5px") thumb_table.add_style("margin-left: 20px") thumb_table.add_style("display: inline-block") thumb_table.add_style("vertical-align: top") thumb_table.add_style("overflow-y: hidden") from tactic.ui.panel import ThumbWdg2 thumb = ThumbWdg2() thumb_table.add(thumb) thumb.set_sobject(snapshot) table.add_row() td = table.add_cell() from tactic.ui.checkin import PathMetadataWdg from tactic.ui.checkin import SnapshotMetadataWdg from pyasm.widget import SelectWdg select = SelectWdg(name="parser") select.add_style("width: 125px") select.add_style("margin-top: 0px") select.add_style("margin-right: 10px") select.add_empty_option("-- Metadata --") td.add(select) select.add_style("float: right") select.set_option("values", ["IPTC", "EXIF", "XMP", "ImageMagick", "PIL"]) select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var parser = bvr.src_el.value; spt.panel.refresh_element(bvr.src_el, {parser: parser}) ''' }) if parser: select.set_value(parser) title_div = DivWdg() td.add(title_div) title_div.add("<div style='font-size: 16px'>File Metadata</div>") title_div.add("<div>Metadata extracted directly from the file</div>") title_div.add("<hr/>") title_div.add_style("text-align: left") title_div.add_style("margin: 0px 10px") metadata_div = DivWdg() td.add(metadata_div) metadata_div.add_style("max-height: 400px") metadata_div.add_style("overflow-y: auto") metadata_div.add_style("overflow-x: hidden") metadata_div.add_style("margin: 20px 0px 20px 10px") metadata_div.add_style("text-align: left") use_tactic_tags = self.kwargs.get("use_tactic_tags") server_src = lib_path # get it dynamically by path metadata_wdg = PathMetadataWdg(path=server_src, parser=parser, use_tactic_tags=use_tactic_tags, search_key=self.search_key) metadata_div.add(metadata_wdg) top.add("<br/>") return top
def get_display(self): type = self.kwargs.get("type") if type not in ['string', 'varchar', 'float', 'integer', 'timestamp', 'login']: print("WARNING: FilterWdg: type [%s] not supported, using 'string'" % type) type = 'string' filter_span = SpanWdg() web = WebContainer.get_web() if type in ["string", "varchar"]: relations = ["is", "is not", "contains", "does not contain", "is empty", "starts with", "ends with"] relation_select = SelectWdg("%s_relation" % self.prefix) relation_select.set_option("values", relations) relation_select.set_persist_on_submit() self.set_filter_value(relation_select) filter_span.add(relation_select) value_text = TextWdg("%s_value" % self.prefix) value_text.set_persist_on_submit() self.set_filter_value(value_text) filter_span.add(value_text) elif type in ['integer', 'float', 'currency']: relations = ["is equal to", "is greater than", "is less than"] relation_select = SelectWdg("%s_relation" % self.prefix) relation_select.set_option("values", relations) relation_select.set_persist_on_submit() self.set_filter_value(relation_select) filter_span.add(relation_select) value_text = TextWdg("%s_value" % self.prefix) value_text.set_persist_on_submit() self.set_filter_value(value_text) filter_span.add(value_text) elif type == 'timestamp': relations = ["is newer than", "is older than"] relation_select = SelectWdg("%s_relation" % self.prefix) relation_select.set_option("values", relations) relation_select.set_persist_on_submit() self.set_filter_value(relation_select) filter_span.add(relation_select) options = ["1 day", '2 days', '1 week', '1 month'] another_select = SelectWdg("%s_select" % self.prefix) another_select.add_empty_option("-- Select --") another_select.set_option("values", options) another_select.set_persist_on_submit() self.set_filter_value(another_select) filter_span.add(another_select) filter_span.add(" or ") value_text = TextWdg("%s_value" % self.prefix) value_text.set_persist_on_submit() self.set_filter_value(value_text) filter_span.add(value_text) elif type in ['login']: relations = ["is", "is not", "contains", "does not contain", "is empty", "starts with", "ends with"] relation_select = SelectWdg("%s_relation" % self.prefix) relation_select.set_option("values", relations) relation_select.set_persist_on_submit() self.set_filter_value(relation_select) filter_span.add(relation_select) value_text = CheckboxWdg("%s_user" % self.prefix) value_text.set_persist_on_submit() self.set_filter_value(value_text) filter_span.add(value_text) filter_span.add("{user}") filter_span.add(" or ") value_text = TextWdg("%s_value" % self.prefix) value_text.set_persist_on_submit() self.set_filter_value(value_text) filter_span.add(value_text) return filter_span
def get_display(my): web = WebContainer.get_web() top = my.top top.add_class("spt_ace_editor_top") script = my.kwargs.get("custom_script") if script: language = script.get_value("language") else: language = my.kwargs.get("language") if not language: language = 'javascript' code = my.kwargs.get("code") if not code: code = "" show_options = my.kwargs.get("show_options") if show_options in ['false', False]: show_options = False else: show_options = True options_div = DivWdg() top.add(options_div) if not show_options: options_div.add_style("display: none") options_div.add_color("background", "background3") options_div.add_border() options_div.add_style("text-align: center") options_div.add_style("padding: 2px") select = SelectWdg("language") select.add_style("width: 100px") select.add_style("display: inline") options_div.add(select) select.add_class("spt_language") select.set_option("values", "javascript|python|expression|xml") select.add_behavior( { 'type': 'change', 'editor_id': my.get_editor_id(), 'cbjs_action': ''' spt.ace_editor.set_editor(bvr.editor_id); var value = bvr.src_el.value; spt.ace_editor.set_language(value); //register_change(bvr); ''' } ) select = SelectWdg("font_size") select.add_style("width: 100px") select.add_style("display: inline") options_div.add(select) select.set_option("labels", "8 pt|9 pt|10 pt|11 pt|12 pt|14 pt|16 pt") select.set_option("values", "8 pt|9pt|10pt|11pt|12pt|14pt|16pt") select.set_value("10pt") select.add_behavior( { 'type': 'click_up', 'editor_id': my.get_editor_id(), 'cbjs_action': ''' spt.ace_editor.set_editor(bvr.editor_id); var editor = spt.ace_editor.editor; var editor_id = spt.ace_editor.editor_id; var value = bvr.src_el.value; $(editor_id).setStyle("font-size", value) //editor.resize(); ''' } ) select = SelectWdg("keybinding") select.add_style("width: 100px") #options_div.add(select) select.set_option("labels", "Ace|Vim|Emacs") select.set_option("values", "ace|vim|emacs") select.set_value("10pt") select.add_behavior( { 'type': 'change', 'editor_id': my.get_editor_id(), 'cbjs_action': ''' spt.ace_editor.set_editor(bvr.editor_id); var editor = spt.ace_editor.editor; var editor_id = spt.ace_editor.editor_id; var vim = require("ace/keyboard/keybinding/vim").Vim; editor.setKeyboardHandler(vim) ''' } ) editor_div = DivWdg() top.add(editor_div) if code: load_div = DivWdg() top.add(load_div) readonly = my.kwargs.get("readonly") if readonly in ['true', True]: readonly = True else: readonly = False load_div.add_behavior( { 'type': 'load', 'code': code, 'language': language, 'editor_id': my.get_editor_id(), 'readonly': readonly, 'cbjs_action': ''' spt.ace_editor.set_editor(bvr.editor_id); var func = function() { var editor = spt.ace_editor.editor; var document = editor.getSession().getDocument(); if (bvr.code) { spt.ace_editor.set_value(bvr.code); } spt.ace_editor.set_language(bvr.language); editor.setReadOnly(bvr.readonly); var session = editor.getSession(); //session.setUseWrapMode(true); //session.setWrapLimitRange(120, 120); }; var editor = spt.ace_editor.editor; if (!editor) { setTimeout( func, 1000); } else { func(); } ''' } ) # theme select = SelectWdg("theme") select.add_style("width: 100px") select.add_style("display: inline") options_div.add(select) select.set_option("labels", "Eclipse|Twilight|TextMate|Vibrant Ink|Merbivore|Clouds") select.set_option("values", "eclipse|twilight|textmate|vibrant_ink|merbivore|clouds") select.set_value("twilight") select.add_behavior( { 'type': 'change', 'editor_id': my.get_editor_id(), 'cbjs_action': ''' spt.ace_editor.set_editor(bvr.editor_id); var editor = spt.ace_editor.editor; var editor_id = spt.ace_editor.editor_id; value = bvr.src_el.value; editor.setTheme("ace/theme/" + value); ''' } ) editor_div = DivWdg() top.add(editor_div) my.text_area.add_style("margin-top: -1px") my.text_area.add_style("margin-bottom: 0px") my.text_area.add_color("background", "background") my.text_area.add_style("font-family: courier new") my.text_area.add_border() editor_div.add(my.text_area) my.text_area.add_style("position: relative") #text_area.add_style("margin: 20px") size = web.get_form_value("size") if size: width, height = size.split(",") else: width = my.kwargs.get("width") if not width: width = "650px" height = my.kwargs.get("height") if not height: height = "450px" my.text_area.add_style("width: %s" % width) my.text_area.add_style("height: %s" % height) bottom_div = DivWdg() top.add(bottom_div) bottom_div.add_color("background", "background3") bottom_div.add_border() bottom_div.add_style("text-align: center") bottom_div.add_style("padding: 2px") bottom_div.add_style("height: 20px") bottom_title = "Script Editor" bottom_div.add(bottom_title) icon = IconWdg("Resize Editor", IconWdg.RESIZE_CORNER) bottom_div.add(icon) icon.add_style("float: right") icon.add_style("margin-right: -4px") icon.add_style("cursor: se-resize") icon.add_behavior( { 'type': 'drag', "cb_set_prefix": 'spt.ace_editor.drag_resize', } ) #hidden = HiddenWdg("size") hidden = TextWdg("size") bottom_div.add(hidden) hidden.add_style("width: 85px") hidden.add_style("text-align: center") hidden.add_style("float: right") hidden.add_class("spt_size") hidden.set_value("%s,%s" % (width, height)) theme = top.get_theme() if theme == 'dark': theme = 'twilight' else: theme = 'eclipse' print "theme: ", theme top.add_behavior( { 'type': 'load', 'unique_id': my.unique_id, 'theme': theme, 'cbjs_action': ''' if (typeof(ace) == 'undefined') { // fist time loading spt.ace_editor = {} spt.ace_editor.editor = null; spt.ace_editor.editor_id = bvr.unique_id; spt.ace_editor.theme = bvr.theme; spt.ace_editor.set_editor = function(editor_id) { spt.ace_editor.editor_id = editor_id; spt.ace_editor.editor = $(editor_id).editor; } spt.ace_editor.set_editor_top = function(top_el) { if (!top_el.hasClass("spt_ace_editor")) { top_el = top_el.getElement(".spt_ace_editor"); } var editor_id = top_el.getAttribute("id"); spt.ace_editor.set_editor(editor_id); } spt.ace_editor.get_editor = function() { return spt.ace_editor.editor; } spt.ace_editor.clear_selection = function() { var editor = spt.ace_editor.editor; editor.clearSelection(); } spt.ace_editor.get_selection = function() { var editor = spt.ace_editor.editor; //return editor.getSelection(); return editor.getCopyText(); } spt.ace_editor.get_value = function() { var editor = spt.ace_editor.editor; var document = editor.getSession().getDocument() var value = document.getValue(); return value; } spt.ace_editor.set_value = function(value) { var editor = spt.ace_editor.editor; var document = editor.getSession().getDocument() document.setValue(value); editor.gotoLine(2); editor.resize(); editor.focus(); } spt.ace_editor.goto_line = function(number) { var editor = spt.ace_editor.editor; var document = editor.getSession().getDocument() editor.gotoLine(2); editor.resize(); editor.focus(); } spt.ace_editor.insert = function(value) { var editor = spt.ace_editor.editor; var position = editor.getCursorPosition(); var doc = editor.getSession().getDocument() doc.insertInLine(position, value); } spt.ace_editor.insert_lines = function(values) { var editor = spt.ace_editor.editor; var position = editor.getCursorPosition(); var doc = editor.getSession().getDocument() doc.insertLines(position.row, values); } spt.ace_editor.get_document = function() { var document = spt.ace_editor.editor.getSession().getDocument() return document; } spt.ace_editor.set_language = function(value) { if (!value) { value = 'javascript'; } var editor = spt.ace_editor.editor; var top = $(spt.ace_editor.editor_id).getParent(".spt_ace_editor_top"); var lang_el = top.getElement(".spt_language"); for ( var i = 0; i < lang_el.options.length; i++ ) { if ( lang_el.options[i].value == value ) { lang_el.options[i].selected = true; break; } } var session = editor.getSession(); var mode; if (value == 'python') { mode = require("ace/mode/python").Mode; } else if (value == 'xml') { mode = require("ace/mode/xml").Mode; } else if (value == 'expression') { mode = require("ace/mode/xml").Mode; } else { mode = require("ace/mode/javascript").Mode; } session.setMode( new mode() ); } spt.ace_editor.drag_start_x; spt.ace_editor.drag_start_y; spt.ace_editor.drag_size; spt.ace_editor.drag_editor_el; spt.ace_editor.drag_size_el; spt.ace_editor.drag_resize_setup = function(evt, bvr, mouse_411) { var editor = spt.ace_editor.editor; var editor_id = spt.ace_editor.editor_id; spt.ace_editor.drag_start_x = mouse_411.curr_x; spt.ace_editor.drag_start_y = mouse_411.curr_y; var editor_el = $(editor_id); spt.ace_editor.drag_editor_el = editor_el; spt.ace_editor.drag_size = editor_el.getSize(); var top = bvr.src_el.getParent(".spt_ace_editor_top"); spt.ace_editor.drag_size_el = top.getElement(".spt_size"); } spt.ace_editor.drag_resize_motion = function(evt, bvr, mouse_411) { var diff_x = parseFloat(mouse_411.curr_x - spt.ace_editor.drag_start_x); var diff_y = parseFloat(mouse_411.curr_y - spt.ace_editor.drag_start_y); var size = spt.ace_editor.drag_size; var editor_el = spt.ace_editor.drag_editor_el; var width = size.x + diff_x if (width < 300) { width = 300; } var height = size.y + diff_y if (height < 200) { height = 200; } editor_el.setStyle("width", width); editor_el.setStyle("height", height); spt.ace_editor.drag_size_el.value = width + "," + height; var editor = spt.ace_editor.editor; editor.resize(); } var js_files = [ "ace/ace-0.2.0/src/ace.js", //"ace/ace-0.2.0/src/ace-uncompressed.js", ]; var ace_setup = function() { var editor = ace.edit(bvr.unique_id); spt.ace_editor.editor = editor; // put the editor into the dom spt.ace_editor.editor_id = bvr.unique_id; $(bvr.unique_id).editor = editor; editor.setTheme("ace/theme/" + spt.ace_editor.theme); var JavaScriptMode = require("ace/mode/javascript").Mode; editor.getSession().setMode(new JavaScriptMode()) } spt.dom.load_js(js_files, function() { ace; require; define; var core_js_files = [ "ace/ace-0.2.0/src/mode-javascript.js", "ace/ace-0.2.0/src/mode-xml.js", "ace/ace-0.2.0/src/mode-python.js", "ace/ace-0.2.0/src/theme-twilight.js", "ace/ace-0.2.0/src/theme-textmate.js", "ace/ace-0.2.0/src/theme-vibrant_ink.js", "ace/ace-0.2.0/src/theme-merbivore.js", "ace/ace-0.2.0/src/theme-clouds.js", "ace/ace-0.2.0/src/theme-eclipse.js" ]; //var supp_js_files = []; spt.dom.load_js(core_js_files, ace_setup); //spt.dom.load_js(supp_js_files); }); } else { var editor = ace.edit(bvr.unique_id); editor.setTheme("ace/theme/" + bvr.theme); var JavaScriptMode = require("ace/mode/javascript").Mode; editor.getSession().setMode(new JavaScriptMode()) spt.ace_editor.editor_id = bvr.unique_id; spt.ace_editor.editor = editor; $(bvr.unique_id).editor = editor; } ''' } ) return top
def get_display(my): top = my.top top.add_class("spt_db_config_top") top.add_style("width: 430px") top.add_style("min-height: 500") top.add_style("padding: 15px") top.add_style("margin-left: auto") top.add_style("margin-right: auto") top.add_color("background", "background", -10) top.add_border() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("System Configuration Setup") title_wdg.add_style("font-size: 20px") top.add("<hr/>") top.add("<i style='opacity: 0.5'>%s</i><br/>" % Config.get_config_path()) top.add("<br/>") checkin_keys = Config.get_section_values('checkin') checkin_keys = checkin_keys.keys() save_button = my.get_save_button(checkin_keys) top.add(save_button) vendor = Config.get_value("database", "vendor") title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>Database Setup</b>") title_wdg.add_style("margin-bottom: 10px") db_select = SelectWdg("database/vendor") db_select.set_option("labels", "SQLite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_option("values", "Sqlite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_value(vendor) db_select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var key; if (bvr.src_el.value == 'Sqlite') { key = 'Sqlite'; } else if (bvr.src_el.value == 'MySQL') { key = 'MySQL'; } else { key = 'Other'; } var top = bvr.src_el.getParent(".spt_db_config_top"); var options_els = top.getElements(".spt_db_options"); for (var i = 0; i < options_els.length; i++) { var vendor = options_els[i].getAttribute("spt_vendor"); if (vendor == key) { spt.show(options_els[i]); } else { spt.hide(options_els[i]); } } ''' }) option_div = DivWdg() top.add(option_div) option_div.add("Vendor: ") option_div.add(db_select) option_div.add_style("margin: 20px") sqlite_wdg = my.get_sqlite_wdg() option_div.add(sqlite_wdg) mysql_wdg = my.get_mysql_wdg() option_div.add(mysql_wdg) otherdb_wdg = my.get_otherdb_wdg() option_div.add(otherdb_wdg) if vendor == 'Sqlite': sqlite_wdg.add_style("display", "") otherdb_wdg.add_style("display: none") mysql_wdg.add_style("display: none") if vendor == 'MySQL': mysql_wdg.add_style("display", "") otherdb_wdg.add_style("display: none") sqlite_wdg.add_style("display: none") else: otherdb_wdg.add_style("display", "") mysql_wdg.add_style("display: none") sqlite_wdg.add_style("display: none") test_button = ActionButtonWdg(title=" Test ", tip="Test connecting to database") option_div.add(test_button) test_button.add_style("margin-left: auto") test_button.add_style("margin-right: auto") test_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_db_config_top"); var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigCbk'; var server = TacticServerStub.get(); var kwargs = {}; var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; if (info.error) { spt.error(info.error); } else { spt.info("Connection to database successful"); } ''' }) # # Install # top.add("<hr/>") top.add("<br/>") title = "Installation" category = "install" options = ['default_project'] if 'tmp_dir' not in options: options.append('tmp_dir') top.add(my.configure_category(title, category, options)) top.add("<hr/>") top.add("<br/>") top.add("<br/>") title = "Asset Management Setup" category = "checkin" options = checkin_keys[:] my._remove_item_from_list(options, 'win32_server_handoff_dir') my._remove_item_from_list(options, 'linux_server_handoff_dir') if os.name == "nt": options.append('win32_server_handoff_dir') else: options.append('linux_server_handoff_dir') top.add(my.configure_category(title, category, options)) top.add("<hr/>") top.add("<br/>") title = "Mail Server" category = "services" options = [ 'mailserver', 'mail_user', 'mail_password', 'mail_port', 'mail_tls_enabled', 'mail_sender_disabled' ] top.add(my.configure_category(title, category, options)) top.add("<hr/>") title = "Services" category = "services" options = [ 'process_count', 'process_time_alive', 'thread_count', 'python_path' ] top.add(my.configure_category(title, category, options)) top.add("<hr/>") title = "Look and Feel" category = "look" options = ['palette'] top.add(my.configure_category(title, category, options)) #wizard_wdg = WizardWdg() #top.add(wizard_wdg) #wizard_wdg.add(DivWdg("cow"), "cow") #wizard_wdg.add(DivWdg("pig"), "pig") #wizard_wdg.add(DivWdg("dog"), "dog") return top
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_action_wdg(my, name): '''get the action widget for ui option of note entry''' note_wdg = DivWdg() note_wdg.add_style("padding-top: 3px") # note options option = DivWdg(css='spt_uber_note_option') cb = CheckboxWdg('is_private') #cb.set_default_checked() checkbox_name = 'note_master_private_cb' master_cb = CheckboxWdg(checkbox_name) if master_cb.is_checked(): cb.set_default_checked() option.add_style('margin-right', '5px') option.add_style('float', 'right') option.add(cb) option.add('private') #commit = TextBtnWdg(label='save', size='small') commit = ActionButtonWdg(title='save', tip="Save Changes") commit.add_style('margin-top: -5px') commit.add_style('margin-bottom: 5px') commit.add_style('float: right') commit.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var td = bvr.src_el.getParent(".spt_table_td"); var text = td.getElement(".spt_note_text"); text.blur(); spt.dg_table.update_row(evt, bvr); td.setStyle('background-color',''); ''', 'cell_only': True }) #commit.set_scale("0.75") # do some gynastics to handle a refresh. if my.parent_wdg: info = my.parent_wdg.get_aux_info() sobject_dict = info.get('sobjects') sobject = sobject_dict.get(my.get_name()) parent = info.get('parent') else: sobject = None parent = None if not sobject: if my.parent_key: parent = SearchKey.get_by_search_key(my.parent_key) # get the latest note #search_key = my.kwargs.get("search_key") #if search_key: # sobject = SearchKey.get_by_search_key(search_key) search = Search('sthpw/note') search.add_parent_filter(parent) search.add_filter('context', name) # Make the assumption that the last one entered is by timestamp search.add_order_by('timestamp desc') sobject = search.get_sobject() # Show a history of notes if sobject: history = ActionButtonWdg(title='history', tip="Show note history") #history = TextBtnWdg(label='history', size='small') #history.get_top_el().add_style("margin-left: 4px") #history.get_top_el().add_style('float: left') history.add_style("float: left") history.add_style("margin-top: -5px") history.add_style("margin-bottom: 5px") note_wdg.add(history) my.parent_key = SearchKey.get_by_sobject(parent) context = name filter = '[{"prefix":"main_body","main_body_enabled":"on","main_body_column":"context","main_body_relation":"is","main_body_value":"%s"}]' % context history.add_behavior({ 'type': 'click_up', 'cbjs_action': "spt.popup.get_widget(evt, bvr)", 'options': { 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'title': 'Notes History', 'popup_id': 'Notes_History_%s' % context }, 'args': { 'search_type': 'sthpw/note', 'view': 'summary', 'parent_key': my.parent_key, 'filter': filter, } }) note_wdg.add(commit) note_wdg.add(option) note_wdg.add("<br clear='all'/>") from pyasm.biz import PrefSetting quick_text = PrefSetting.get_value_by_key('quick_text') if quick_text: quick_sel = SelectWdg('quick_text', label='quick: ') quick_sel.set_option('values', quick_text) quick_sel.add_empty_option('-- text --', '') quick_sel.add_behavior({ 'type': 'change', 'cbjs_action': '''var val = bvr.src_el.value; var text=bvr.src_el.getParent('.spt_note_top').getElement('.spt_note_text') text.value = text.value + val; ''' }) note_wdg.add(SpanWdg(quick_sel, css='small')) note_wdg.add(HtmlElement.br(2)) # Show the last note note_wdg.add("<i>Last note</i> ") if sobject: timestamp = sobject.get_value("timestamp") timestamp = parser.parse(timestamp) timestamp = timestamp.strftime("%m/%d %H:%M") timestamp_div = SpanWdg() timestamp_div.add("(%s)" % timestamp) note_wdg.add(timestamp_div) timestamp_div.add_style("font-size: 11px") timestamp_div.add_style("font-style: italic") # add a private tag access = sobject.get_value("access") if access == 'private': private = SpanWdg() #private.add_style('float: right') private.add(" <i>-- private --</i>") note_wdg.add(private) hr = DivWdg("<hr/>") hr.add_style("height: 1px") hr.add_style("margin-top: -5px") note_wdg.add(hr) div = DivWdg() note_wdg.add(div) div.add_style("max-height", "50px") div.add_style("overflow", "auto") div.add_style("padding: 3px") if sobject: value = sobject.get_value('note') from pyasm.web import WikiUtil value = WikiUtil().convert(value) div.add(value) else: no_notes = DivWdg() div.add(no_notes) no_notes.add('<i> -- No Notes --</i>') no_notes.add_style("font-size: 11px") no_notes.add_style("opacity: 0.7") return note_wdg
def get_display(my): my.search_type = my.kwargs.get('search_type') my.element_name = my.kwargs.get('element_name') assert my.search_type assert my.element_name class_name = 'tactic.ui.app.aggregate_wdg.AggregateCmd' interval = 120 priority = None if my.kwargs.get('is_refresh'): user = Environment.get_user_name() # these interval jobs need to have a specific code code = "aggregate|%s|%s" % (my.search_type, my.element_name) # check to see if the job exists #job = Search.get_by_code("sthpw/queue", code) job = None if not job: job = SearchType.create("sthpw/queue") #job.set_value("code", code) job.set_value("project_code", Project.get_project_code() ) job.set_value("class_name", class_name) job.set_value("command", class_name) job.set_value("serialized", str(my.kwargs) ) job.set_value("interval", 120) job.set_value("state", 'pending') job.set_value("queue", 'interval') job.set_value("priority", 9999) job.set_value("login", user) job.commit() my.view = my.kwargs.get('view') if not my.view: my.view = 'definition' top = DivWdg() my.set_as_panel(top) action_div = DivWdg() top.add(action_div) refresh = IconButtonWdg("Refresh", IconWdg.REFRESH) refresh.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); ''' } ) action_div.add(refresh) register_div = DivWdg() register_div.add_class("spt_queue_register") top.add(register_div) register_div.add_style("border: solid 1px black") register_div.add_style("padding: 20px") register_div.add("Register new interval aggregate") table = Table() table.add_style("margin: 15px") register_div.add(table) table.add_row() table.add_cell("command: ") table.add_cell(class_name) #table.add_row() #table.add_cell("priority: ") #table.add_cell(priority) table.add_row() table.add_cell("interval: ") td = table.add_cell("every ") td.set_attr("title", "Recalculation interval") text = TextWdg("interval") text.add_style("width: 30px") text.set_value(interval) td.add(text) unit_select = SelectWdg("unit") unit_select.set_value(interval) unit_select.set_option("values", "seconds|minutes|hours|days") td.add(" ") td.add(unit_select) table.add_row() table.add_cell("queue: ") table.add_cell("interval") from pyasm.widget import ProdIconButtonWdg button = ProdIconButtonWdg("Register") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_queue_register") var values = spt.api.get_input_values(top); var top = bvr.src_el.getParent(".spt_panel"); spt.panel.refresh(top); ''' } ) register_div.add(button) from pyasm.widget import ProdIconButtonWdg button = ProdIconButtonWdg("Cancel") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' alert('cancel'); ''' } ) register_div.add(button) ''' cmd = AggregateCmd(**my.kwargs) print "registering scheduled task" scheduler = Scheduler.get() scheduler.start_thread() task = AggregateRefreshTask(name="cow", command=cmd) scheduler.add_interval_task(task, 10, mode='forked') scheduler.cancel_task("cow", delay=35) ''' top.add("<br/>") top.add("<b>Current Job Queue</b>") top.add("<br/><br/>") from tactic.ui.panel import TableLayoutWdg table = TableLayoutWdg(search_type='sthpw/queue',view='test') top.add(table) return top
def handle_simple_mode(my, custom_table, mode): tbody = custom_table.add_tbody() tbody.add_class("spt_custom_simple") if mode != 'simple': tbody.add_style('display: none') name_text = TextWdg("custom_name") name_text.add_class("spt_input") tr = custom_table.add_row() tr.add_color("background", "background", -7) td = custom_table.add_cell("Name: ") td.add_style("min-width: 150px") custom_table.add_cell(name_text) # add title custom_table.add_row() title_wdg = TextWdg("custom_title") title_wdg.add_attr("size", "50") custom_table.add_cell( "Title: " ) custom_table.add_cell( title_wdg ) # add description tr = custom_table.add_row() tr.add_color("background", "background", -7) description_wdg = TextAreaWdg("custom_description") custom_table.add_cell( "Description: " ) custom_table.add_cell( description_wdg ) type_select = SelectWdg("custom_type") type_select.add_class("spt_input") #type_select.add_empty_option("-- Select --") type_select.set_option("values", "string|text|integer|float|boolean|currency|date|foreign_key|list|button|empty") type_select.set_option("labels", "String(db)|Text(db)|Integer(db)|Float(db)|Boolean(db)|Currency(db)|Date(db)|Foreign Key(db)|List(db)|Button|Empty") #type_select.set_option("labels", "String|Integer|Boolean|Currency|Timestamp|Link|Foreign Key|List|Checkbox|Text|Number|Date|Date Range") tr = custom_table.add_row() custom_table.add_cell("Property Type: ") td = custom_table.add_cell(type_select) type_select.add_event("onchange", "spt.custom_property_adder.property_type_select_cbk(this)") # extra info for foreign key custom_table.add_row() div = DivWdg() div.add_class("foreign_key_options") div.add_style("display: none") div.add_style("margin-top: 10px") div.add("Options") div.add(HtmlElement.br()) # TODO: this class should not be in prod!! from pyasm.prod.web import SearchTypeSelectWdg div.add("Relate to: ") search_type_select = SearchTypeSelectWdg("foreign_key_search_select", mode=SearchTypeSelectWdg.CURRENT_PROJECT) div.add(search_type_select) td.add(div) # extra info for list custom_table.add_row() div = DivWdg() div.add_class("list_options") div.add_style("display: none") div.add_style("margin-top: 10px") div.add("Options") div.add(HtmlElement.br()) # TODO: this class should not be in prod!! from pyasm.prod.web import SearchTypeSelectWdg div.add("Values: ") search_type_text = TextWdg("list_values") div.add(search_type_text) td.add(div) # extra info for button custom_table.add_row() div = DivWdg() div.add_class("button_options") div.add_style("display: none") div.add_style("margin-top: 10px") class_path = "tactic.ui.table.ButtonElementWdg" button = Common.create_from_class_path(class_path) args_keys = button.get_args_keys() div.add("Options") div.add(HtmlElement.br()) for key in args_keys.keys(): div.add("Name: ") option_name_text = TextWdg("option_name") option_name_text.add_attr("readonly", "true") option_name_text.set_value(key) div.add(option_name_text) div.add(" ") div.add("Value: ") input = button.get_input_by_arg_key(key) div.add(input) #option_value_text = TextWdg("option_value") #div.add(option_value_text) div.add(HtmlElement.br()) td.add(div) # is searchable checkbox tr = custom_table.add_row() tr.add_color("background", "background", -7) current_searchable_wdg = CheckboxWdg("is_searchable") #current_view_wdg.set_checked() custom_table.add_cell("Is Searchable? ") td = custom_table.add_cell(current_searchable_wdg) custom_table.close_tbody()
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(my): top = my.top top.add_class("spt_db_config_top") top.add_style("width: 430px") top.add_style("min-height: 500") top.add_style("padding: 15px") top.add_style("margin-left: auto") top.add_style("margin-right: auto") top.add_color("background", "background", -10) top.add_border() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("System Configuration Setup") title_wdg.add_style("font-size: 20px") top.add("<hr/>") top.add("<i style='opacity: 0.5'>%s</i><br/>" % Config.get_config_path()) top.add("<br/>") checkin_keys=Config.get_section_values('checkin') checkin_keys=checkin_keys.keys() save_button = my.get_save_button(checkin_keys) top.add(save_button) vendor = Config.get_value("database", "vendor") title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>Database Setup</b>") title_wdg.add_style("margin-bottom: 10px") db_select = SelectWdg("database/vendor") db_select.set_option("labels", "SQLite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_option("values", "Sqlite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_value(vendor) db_select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var key; if (bvr.src_el.value == 'Sqlite') { key = 'Sqlite'; } else { key = 'Other'; } var top = bvr.src_el.getParent(".spt_db_config_top"); var options_els = top.getElements(".spt_db_options"); for (var i = 0; i < options_els.length; i++) { var vendor = options_els[i].getAttribute("spt_vendor"); if (vendor == key) { spt.show(options_els[i]); } else { spt.hide(options_els[i]); } } ''' } ) option_div = DivWdg() top.add(option_div) option_div.add("Vendor: ") option_div.add(db_select) option_div.add_style("margin: 20px") sqlite_wdg = my.get_sqlite_wdg() option_div.add(sqlite_wdg) otherdb_wdg = my.get_otherdb_wdg() option_div.add(otherdb_wdg) if vendor == 'Sqlite': otherdb_wdg.add_style("display: none") sqlite_wdg.add_style("display", "") else: otherdb_wdg.add_style("display", "") sqlite_wdg.add_style("display: none") test_button = ActionButtonWdg(title="<< Test >>", tip="Test connecting to database") option_div.add(test_button) test_button.add_style("margin-left: auto") test_button.add_style("margin-right: auto") test_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_db_config_top"); var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigCbk'; var server = TacticServerStub.get(); var kwargs = {}; var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; if (info.error) { spt.error(info.error); } else { spt.info("Connection to database successful"); } ''' } ) # # Install # top.add("<hr/>") top.add("<br/>") title = "Installation" category = "install" options = ['default_project'] if 'tmp_dir' not in options: options.append('tmp_dir') top.add( my.configure_category(title, category, options) ) top.add("<hr/>") top.add("<br/>") top.add("<br/>") title = "Asset Management Setup" category = "checkin" options=checkin_keys[:] my._remove_item_from_list(options,'win32_server_handoff_dir') my._remove_item_from_list(options,'linux_server_handoff_dir') if os.name == "nt": options.append('win32_server_handoff_dir') else: options.append('linux_server_handoff_dir') top.add( my.configure_category(title, category, options) ) top.add("<hr/>") top.add("<br/>") title = "Mail Server " category = "services" options = ['mailserver', 'mail_user', 'mail_password', 'mail_port', 'mail_tls_enabled', 'mail_sender_disabled'] top.add( my.configure_category(title, category, options) ) top.add("<hr/>") title = "Services" category = "services" options = ['process_count', 'process_time_alive', 'thread_count', 'python_path'] top.add( my.configure_category(title, category, options) ) top.add("<hr/>") title = "Look and Feel" category = "look" options = ['palette'] top.add( my.configure_category(title, category, options) ) #wizard_wdg = WizardWdg() #top.add(wizard_wdg) #wizard_wdg.add(DivWdg("cow"), "cow") #wizard_wdg.add(DivWdg("pig"), "pig") #wizard_wdg.add(DivWdg("dog"), "dog") return top
def get_data_wdg(my): div = DivWdg() from pyasm.biz import Pipeline from pyasm.widget import SelectWdg search_type_obj = SearchType.get(my.search_type) base_type = search_type_obj.get_base_key() search = Search("sthpw/pipeline") search.add_filter("search_type", base_type) pipelines = search.get_sobjects() if pipelines: pipeline = pipelines[0] process_names = pipeline.get_process_names() if process_names: table = Table() div.add(table) table.add_row() table.add_cell("Process: ") select = SelectWdg("process") table.add_cell(select) process_names.append("---") process_names.append("publish") process_names.append("icon") select.set_option("values", process_names) #### buttons = Table() div.add(buttons) buttons.add_row() button = IconButtonWdg(title="Add Data", icon=IconWdg.FOLDER) buttons.add_cell(button) dialog = DialogWdg(display="false", show_title=False) div.add(dialog) dialog.set_as_activator(button, offset={'x':-10,'y':10}) dialog_data_div = DivWdg() dialog_data_div.add_color("background", "background") dialog_data_div.add_style("padding", "20px") dialog.add(dialog_data_div) # Order folders by date name_div = DivWdg() dialog_data_div.add(name_div) name_div.add_style("margin: 15px 0px") if SearchType.column_exists(my.search_type, "relative_dir"): category_div = DivWdg() name_div.add(category_div) checkbox = RadioWdg("category") checkbox.set_option("value", "none") category_div.add(checkbox) category_div.add(" No categories") category_div.add_style("margin-bottom: 5px") checkbox.set_option("checked", "true") category_div = DivWdg() name_div.add(category_div) checkbox = RadioWdg("category") checkbox.set_option("value", "by_day") category_div.add(checkbox) category_div.add(" Categorize files by Day") category_div.add_style("margin-bottom: 5px") category_div = DivWdg() name_div.add(category_div) checkbox = RadioWdg("category") checkbox.set_option("value", "by_week") category_div.add(checkbox) category_div.add(" Categorize files by Week") category_div.add_style("margin-bottom: 5px") category_div = DivWdg() name_div.add(category_div) checkbox = RadioWdg("category") checkbox.set_option("value", "by_year") category_div.add(checkbox) category_div.add(" Categorize files by Year") category_div.add_style("margin-bottom: 5px") """ checkbox = RadioWdg("category") checkbox.set_option("value", "custom") name_div.add(checkbox) name_div.add(" Custom") """ name_div.add("<br/>") hidden = HiddenWdg(name="parent_key") dialog_data_div.add(hidden) hidden.add_class("spt_parent_key") parent_key = my.kwargs.get("parent_key") or "" if parent_key: hidden.set_value(parent_key) dialog_data_div.add("Keywords:<br/>") dialog.add(dialog_data_div) text = TextAreaWdg(name="keywords") dialog_data_div.add(text) text.add_class("spt_keywords") text.add_style("padding: 1px") dialog_data_div.add("<br/>"*2) extra_data = my.kwargs.get("extra_data") if not isinstance(extra_data, basestring): extra_data = jsondumps(extra_data) dialog_data_div.add("Extra Data (JSON):<br/>") text = TextAreaWdg(name="extra_data") dialog_data_div.add(text) if extra_data != "null": text.set_value(extra_data) text.add_class("spt_extra_data") text.add_style("padding: 1px") #### TEST Image options """ button = IconButtonWdg(title="Resize", icon=IconWdg.FILM) buttons.add_cell(button) dialog = DialogWdg(display="false", show_title=False) div.add(dialog) dialog.set_as_activator(button, offset={'x':-10,'y':10}) try: from spt.tools.convert import ConvertOptionsWdg convert_div = DivWdg() dialog.add(convert_div) convert_div.add_style("padding: 20px") convert_div.add_color("background", "background") convert_div.add_class("spt_image_convert") convert = ConvertOptionsWdg() convert_div.add(convert) except: pass """ # use base name for name """ name_div = DivWdg() dialog_data_div.add(name_div) name_div.add_style("margin: 15px 0px") checkbox = CheckboxWdg("use_file_name") name_div.add(checkbox) name_div.add(" Use name of file for name") name_div.add("<br/>") checkbox = CheckboxWdg("use_base_name") name_div.add(checkbox) name_div.add(" Remove extension") name_div.add("<br/>") checkbox = CheckboxWdg("file_keywords") name_div.add(checkbox) name_div.add(" Use file name for keywords") """ return div
def get_display(self): self.check() if self.is_refresh: div = Widget() else: div = DivWdg() self.set_as_panel(div) div.add_style('padding', '6px') min_width = '400px' div.add_style('min-width', min_width) div.add_color('background', 'background') div.add_class('spt_add_task_panel') div.add_style("padding: 20px") from tactic.ui.app import HelpButtonWdg help_button = HelpButtonWdg(alias="creating-tasks") div.add(help_button) help_button.add_style("float: right") help_button.add_style("margin-top: -5px") if not self.search_key_list: msg_div = DivWdg() msg_table = Table() msg_div.add(msg_table) msg_table.add_row() msg_table.add_cell(IconWdg("No items selected", IconWdg.WARNING)) msg_table.add_cell( 'Please select at least 1 item to add tasks to.') msg_div.add_style('margin: 10px') msg_table.add_style("font-weight: bold") div.add(msg_div) return div msg_div = DivWdg() msg_div.add_style('margin-left: 4px') div.add(msg_div, 'info') msg_div.add('Total: %s item/s to add tasks to' % len(self.search_key_list)) div.add(HtmlElement.br()) hint = HintWdg('Tasks are added according to the assigned pipeline.') msg_div.add(" ") msg_div.add(hint) msg_div.add(HtmlElement.br()) option_div = DivWdg(css='spt_ui_options') #option_div.add_style('margin-left: 12px') sel = SelectWdg('pipeline_mode', label='Create tasks by: ') sel.set_option('values', ['simple process', 'context', 'standard']) sel.set_option('labels', ['process', 'context', 'all contexts in process']) sel.set_persistence() sel.add_behavior({ 'type': 'change', 'cbjs_action': 'spt.panel.refresh(bvr.src_el)' }) option_div.add(sel) value = sel.get_value() # default to simple process if not value: value = 'simple process' msg = '' if value not in ['simple process', 'context', 'standard']: value = 'simple process' if value == 'context': msg = 'In context mode, a single task will be created for each selected context.' elif value == 'simple process': msg = 'In process mode, a single task will be created for each selected process.' elif value == 'standard': msg = 'In this mode, a task will be created for all contexts of each selected process.' option_div.add(HintWdg(msg)) div.add(option_div) div.add(HtmlElement.br()) title = DivWdg('Assigned Pipelines') title.add_style('padding: 6px') title.add_color('background', 'background2') title.add_color('color', 'color', +120) div.add(title) content_div = DivWdg() content_div.add_style('min-height', '150px') div.add(content_div) content_div.add_border() filtered_search_key_list = [] for sk in self.search_key_list: id = SearchKey.extract_id(sk) if id == '-1': continue filtered_search_key_list.append(sk) sobjects = SearchKey.get_by_search_keys(filtered_search_key_list) skipped = [] pipeline_codes = [] for sobject in sobjects: if isinstance(sobject, Task): msg_div = DivWdg( 'WARNING: Creation of task for [Task] is not allowed.') msg_div.add_style('margin-left: 10px') div.add(msg_div, 'info') return div pipeline_code = sobject.get_value('pipeline_code', no_exception=True) if not pipeline_code: skipped.append(sobject) if pipeline_code not in pipeline_codes: pipeline_codes.append(pipeline_code) pipelines = Search.get_by_code('sthpw/pipeline', pipeline_codes) if pipelines == None: pipelines = [] #if not pipelines: # msg_div = DivWdg('WARNING: No Pipelines found for selected.') # msg_div.add_style('margin-left: 10px') # div.add(msg_div, 'info') # return div # expand the width according to num of pipelines content_div.add_style('min-width', len(pipelines) * 250) mode_cb = SelectWdg('pipeline_mode') mode_cb.set_persistence() mode = mode_cb.get_value() if 'context' == mode: mode = 'context' else: mode = 'process' show_subpipeline = True min_height = '150px' # create a temp default pipeline if not pipelines: pipeline = SearchType.create("sthpw/pipeline") pipeline.set_value("code", "__default__") pipeline.set_value( "pipeline", ''' <pipeline> <process name='publish'/> </pipeline> ''') # FIXME: HACK to initialize virtual pipeline pipeline.set_pipeline(pipeline.get_value("pipeline")) pipelines = [pipeline] for pipeline in pipelines: name = pipeline.get_value("name") if not name: name = pipeline.get_code() span = SpanWdg("Pipeline: %s" % name) span.add_style('font-weight: bold') v_div = FloatDivWdg(span) v_div.add_style('margin: 20px') v_div.add_style('min-height', min_height) v_div.add(HtmlElement.br(2)) content_div.add(v_div) processes = pipeline.get_processes(recurse=show_subpipeline, type=['manual', 'approval']) cb_name = '%s|task_process' % pipeline.get_code() master_cb = CheckboxWdg('master_control') master_cb.set_checked() master_cb.add_behavior({ 'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var inputs = spt.api.Utility.get_inputs(bvr.src_el.getParent('.spt_add_task_panel'),'%s'); for (var i = 0; i < inputs.length; i++) inputs[i].checked = bvr.src_el.checked; ''' % cb_name }) toggle_div = DivWdg() toggle_div.add(SpanWdg(master_cb, css='small')) label = HtmlElement.i('toggle all') label.add_style('color: #888') toggle_div.add_styles( 'border-bottom: 1px solid #888; width: 170px') toggle_div.add(label) v_div.add(toggle_div) process_names = [] for process in processes: process_labels = [] if process.is_from_sub_pipeline(): process_name = process.get_full_name() else: process_name = process.get_name() process_label = process.get_label() if not process_label: process_label = '' if mode == 'context': contexts = pipeline.get_output_contexts(process.get_name()) labels = contexts if process.is_from_sub_pipeline(): labels = [ '%s/%s' % (process.parent_pipeline_code, x) for x in contexts ] for x in labels: process_labels.append(process_label) # prepend process to contexts in this mode to ensure uniqueness contexts = ['%s:%s' % (process_name, x) for x in contexts] else: contexts = [process_name] labels = contexts process_labels.append(process_label) for idx, context in enumerate(contexts): cb = CheckboxWdg(cb_name) cb.set_checked() cb.set_option('value', context) v_div.add(SpanWdg(cb, css='small')) if mode == 'context': span = SpanWdg(process_name, css='med') #span.add_color('color','color') v_div.add(span) v_div.add(SpanWdg(labels[idx])) process_label = process_labels[idx] if process_label: v_div.add(SpanWdg("(%s)" % process_label, css='small')) v_div.add(HtmlElement.br()) content_div.add("<br clear='all'/>") skipped = [] if True: div.add("<br/>") btn = ActionButtonWdg(title='Add Tasks') btn.add_behavior({ 'type': 'click_up', 'post_event': 'search_table_%s' % self.table_id, 'cbjs_action': ''' spt.dg_table.add_task_selected(bvr); ''', 'search_key_list': self.search_key_list }) cb = CheckboxWdg('skip_duplicated', label='Skip Duplicates') cb.set_checked() option_div = DivWdg(cb) option_div.add_style('width', '130px') option_div.add_style('align: left') div.add(option_div) div.add(HtmlElement.br()) btn.add_style("float: right") div.add(btn) div.add(HtmlElement.br(clear="all")) if skipped: content_div.add(HtmlElement.br()) skip_div = DivWdg('Missing pipeline code (Skipped)') skip_div.add_style('text-decoration: underline') content_div.add(skip_div) content_div.add(HtmlElement.br()) item_div = DivWdg() item_div.add_style('margin-left: 10px') content_div.add(item_div) for skip in skipped: item_div.add(skip.get_code()) item_div.add(HtmlElement.br()) return div
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): top = my.top top.add_class("spt_sign_in_top") top.add_color("background", "background") top.add_style("padding: 30px") top.add_style("width: 300px") icon = IconWdg("Not signed in", IconWdg.WARNING) top.add(icon) top.add("You are not signed into Perforce.") top.add("<br/>" * 2) table = Table() top.add(table) from tactic.ui.input import TextInputWdg, PasswordInputWdg table.add_row() td = table.add_cell("Port: ") td.add_style("width: 75px") text = TextInputWdg(name="port") td = table.add_cell(text) td.add_style("vertical-align: top") text.set_value("1666") table.add_row() td = table.add_cell("Login: "******"vertical-align: top") td.add_style("width: 75px") text = TextInputWdg(name="user") td = table.add_cell(text) td.add_style("vertical-align: top") user = Environment.get_user_name() text.set_value(user) table.add_row() td = table.add_cell("Password: "******"vertical-align: top") text = PasswordInputWdg(name="password") table.add_cell(text) tr = table.add_row() table.add_row_cell(" ") tr = table.add_row() tr.add_class("spt_workspaces") #tr.add_style("display: none") td = table.add_cell("Workspace: ") td.add_style("vertical-align: top") workspaces = my.kwargs.get("workspaces") td = table.add_cell() button = ActionButtonWdg(width='55', title="Lookup") td.add(button) button.add_style("float: right") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' try { var workspaces = spt.scm.get_workspaces(); var clients = []; for (var i = 0; i < workspaces.length; i++) { clients.push(workspaces[i].client); } clients = clients.join("|"); var kwargs = { workspaces: clients } spt.scm.show_login(kwargs); } catch(e) { spt.scm.signout_user(); spt.scm.show_login(); } ''' }) if not workspaces: text = TextInputWdg(name="workspace") text.add_style("width: 165px") td.add(text) else: select = SelectWdg("workspace") td.add(select) select.set_option("values", workspaces) top.add("<br/>" * 2) button = ActionButtonWdg(title="Sign In >>", size='medium') top.add(button) button.add_style("float: right") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_sign_in_top"); var values = spt.api.get_input_values(top); var port = values.port[0]; var user = values.user[0]; var password = values.password[0]; var client = values.workspace[0]; if (!port) { alert("No port specified"); return; } if (!user) { alert("No user specified"); return; } if (!client) { alert("No workspace specified"); return; } // login in user spt.scm.port = port; spt.scm.user = user; spt.scm.password = password; // test the connection var ping = spt.scm.ping(); if (ping != "OK") { alert("Cannot connect to Perforce") spt.scm.signout_user(); spt.scm.show_login(); } else { spt.scm.client = client; // close the popup var popup = bvr.src_el.getParent(".spt_popup"); if (popup) { spt.popup.destroy(popup); } // NOTE: this is global: find a check-in widget and refresh var checkin_el = $(document.body).getElement(".spt_checkin_top"); spt.panel.refresh(checkin_el); } ''' }) top.add("<br/>" * 2) return top
def get_display(my): state = my.get_state() search_type = state.get("search_type") sobj = my.get_current_sobject() if search_type: st = search_type else: st = sobj.get_base_search_type() # for inline insert, this should proceed #if not sobj: # return '' st_suffix = st.split('/', 1) if len(st_suffix) == 2: st_suffix = st_suffix[1] search = Search('sthpw/pipeline') search.add_op_filters([('search_type','EQ', '/%s' %st_suffix)]) # takes into account site-wide pipeline search.add_project_filter(show_unset=True) sobjects = search.get_sobjects() codes = [x.get_code() for x in sobjects] if my.get_option("use_code") in [True, 'true']: names = codes else: names = [] for x in sobjects: name = x.get_value("name") if not name: name = x.get_value("code") names.append(name) select = SelectWdg(my.get_input_name()) select.add_empty_option("-- Default --") select.set_option("values", codes) select.set_option("labels", names) if sobj: value = sobj.get_value(my.get_name()) if value: select.set_value(value) else: # only for inline #behavior = { 'type': 'click', # 'cbjs_action': 'spt.dg_table.select_wdg_clicked( evt, bvr.src_el );'} #select.add_behavior(behavior) pass return select
def get_display(my): # add the detail widget detail_wdg = DivWdg(css='spt_detail_panel') if not my.name_string and not my.config_string: detail_wdg.add("<br/>" * 3) detail_wdg.add('<- Click on an item on the left for modification.') detail_wdg.add_style("padding: 10px") detail_wdg.add_color("background", "background", -5) detail_wdg.add_style("width: 350px") detail_wdg.add_style("height: 400px") detail_wdg.add_border() return detail_wdg if my.kwargs.get("mode") == "empty": overlay = DivWdg() detail_wdg.add(overlay) detail_wdg.add_border() detail_wdg.add_color("color", "black") detail_wdg.add_style("padding: 10px") detail_wdg.add_color("background", "background", -5) detail_wdg.set_id('search_type_detail') # put in the selection for simple or advanced select = SelectWdg("config_mode", label='Mode: ') select.set_persistence() values = ['simple', 'advanced'] select.set_option("values", values) config_mode = select.get_value() #select.add_behavior({"type": "change", "cbjs_action": "spt.simple_display_toggle( spt.get_cousin(bvr.src_el, '.spt_detail_panel','.config_simple') )"}) select.add_behavior({"type": "change", "cbjs_action": \ "spt.simple_display_toggle( spt.get_cousin(bvr.src_el, '.spt_detail_panel','.config_advanced')); %s" %select.get_save_script()}) select.add_class('spt_config_mode') title_div = DivWdg("Column Detail") title_div.add_class("maq_search_bar") detail_wdg.add(title_div) detail_wdg.add("<br/>") detail_wdg.add(select) detail_wdg.add(HtmlElement.br(2)) #simple_mode_wdg = WidgetDetailSimpleModeWdg() #detail_wdg.add(simple_mode_wdg) #detail_wdg.add(HtmlElement.br(2)) if my.is_new_column: detail_wdg.add(my.get_new_definition_wdg()) else: simple_wdg = my.get_simple_definition_wdg() simple_wdg.add_class("config_simple") detail_wdg.add(simple_wdg) adv_wdg = my.get_advanced_definition_wdg() adv_wdg.add_class("config_advanced") if config_mode == 'simple': adv_wdg.add_style('display: none') detail_wdg.add(HtmlElement.br(2)) detail_wdg.add(adv_wdg) detail_wdg.add(HtmlElement.br(2)) security_wdg = my.get_security_wdg() detail_wdg.add(security_wdg) # add hidden input for view for panel refreshing # we are only interested in whether it is project_view or definition # sub-views of project_view is not of our interest #if my.view != 'project_view': # my.view = 'custom_definition' detail_wdg.add(HiddenWdg('view', my.view)) return detail_wdg