def _get_inner_div(my): '''get the inner div for the process dialog''' inner_div = FloatDivWdg() inner_div.add_style("padding: 5px") inner_div.add_style('height: 260px') inner_div.add_color("background", "background") inner_div.add_color("color", "color") return inner_div
def _get_inner_div(self): '''get the inner div for the process dialog''' inner_div = FloatDivWdg() inner_div.add_style("padding: 5px") inner_div.add_style('height: 260px') inner_div.add_color("background", "background") inner_div.add_color("color", "color") return inner_div
def _handle_ref_node(self, node, widget, upstream=False, recursive=True): # get the reference snapshot (should maybe use the loader or # at least share the code instance = Xml.get_attribute(node,"instance") search_type = Xml.get_attribute(node,"search_type") search_id = Xml.get_attribute(node,"search_id") context = Xml.get_attribute(node,"context") version = Xml.get_attribute(node,"version") # this is often the Maya file node name or XSI long clip name node_name = Xml.get_attribute(node, "node") my_name = Xml.get_node_name(node) # get the snapshot ref_snapshot = Snapshot.get_by_version(search_type, search_id,\ context, version) #ref_snapshot = Snapshot.get_latest(search_type,search_id, context) if ref_snapshot == None: widget.add("|---> <font color='red'>Error: No reference found for [%s, %s, %s]</font>" % \ (search_type, search_id, context) ) return toggle_id = self.generate_unique_id('toggle') widget.add(FloatDivWdg(), toggle_id) version = ref_snapshot.get_value("version") try: sobject = ref_snapshot.get_sobject() except SObjectNotFoundException, e: widget.add('[%s|%s] may have been deleted or is not viewable.' % (ref_snapshot.get_value('search_type'),\ ref_snapshot.get_value('search_id'))) return
def get_context_wdg(self, search_type): '''drop down which selects which context to checkin''' # add a filter # use a regular SelectWdg with submit instead of FilterSelectWdg filter_div = FloatDivWdg("Context / subcontext:") select = SelectWdg("publish_context") labels, values = self.get_context_data(search_type, self.process) select.set_option("values", "|".join(values)) select.set_option("labels", "|".join(labels)) select.append_option('publish','publish') select.add_style("font-size: 0.8em") select.add_style("margin: 0px 3px") # explicitly set the value current = select.get_value() if current in values: context = current elif values: context = values[0] else: context = "" web = WebContainer.get_web() web.set_form_value("publish_context", context) select.set_value( context ) # set it to a instance variable self.context_select = select filter_div.add(select) # if specified, add a sub_context base_search_type = SearchType(search_type).get_base_key() settings = ProdSetting.get_value_by_key("%s/sub_context" % context,\ base_search_type) filter_div.add( "/ ") sub_context = None if settings: sub_context = SelectWdg("publish_sub_context") sub_context.set_option("values", settings) sub_context.set_submit_onchange() sub_context.add_empty_option("<- Select ->") else: # provide a text field sub_context = TextWdg("publish_sub_context") sub_context.set_attr('size','10') sub_context.set_persistence() filter_div.add( sub_context ) self.sub_context_select = sub_context #filter_div.add_style('padding-right','10px') return filter_div
def get_context_wdg(my, search_type): '''drop down which selects which context to checkin''' # add a filter # use a regular SelectWdg with submit instead of FilterSelectWdg filter_div = FloatDivWdg("Context / subcontext:") select = SelectWdg("publish_context") labels, values = my.get_context_data(search_type, my.process) select.set_option("values", "|".join(values)) select.set_option("labels", "|".join(labels)) select.append_option('publish','publish') select.add_style("font-size: 0.8em") select.add_style("margin: 0px 3px") # explicitly set the value current = select.get_value() if current in values: context = current elif values: context = values[0] else: context = "" web = WebContainer.get_web() web.set_form_value("publish_context", context) select.set_value( context ) # set it to a instance variable my.context_select = select filter_div.add(select) # if specified, add a sub_context base_search_type = SearchType(search_type).get_base_key() settings = ProdSetting.get_value_by_key("%s/sub_context" % context,\ base_search_type) filter_div.add( "/ ") sub_context = None if settings: sub_context = SelectWdg("publish_sub_context") sub_context.set_option("values", settings) sub_context.set_submit_onchange() sub_context.add_empty_option("<- Select ->") else: # provide a text field sub_context = TextWdg("publish_sub_context") sub_context.set_attr('size','10') sub_context.set_persistence() filter_div.add( sub_context ) my.sub_context_select = sub_context #filter_div.add_style('padding-right','10px') return filter_div
def get_file_type_wdg(my): '''drop down which selects which file type to export to''' # add a filter div = DivWdg() filter_div = FloatDivWdg(HtmlElement.b("File Type:"), width="15em") div.add(filter_div) select = SelectWdg() select.set_name("file_type") select.set_id("file_type") app = WebContainer.get_web().get_selected_app() if app == 'Maya': select.set_option("values", "mayaAscii|mayaBinary|obj|collada") select.set_option( "labels", "Maya Ascii (.ma)|Maya Binary (.mb)|Wavefront .obj|Collada (.dae)" ) elif app == 'Houdini': select.set_option("values", "otl") select.set_option("labels", "Houdini Digital Asset(.otl)") elif app == 'XSI': select.set_option("values", "emdl|dotXSI|obj") select.set_option( "labels", "3D Model (.emdl)|SoftImage dotXSI (.xsi)|Wavefront .obj") else: select.set_option("values", "mayaAscii|mayaBinary|obj|collada") select.set_option( "labels", "Maya Ascii (.ma)|Maya Binary (.mb)|Wavefront .obj|Collada (.dae)" ) select.add_style("font-size: 0.8em") select.add_style("margin-top: 5px") select.add_style("margin-right: 10px") select.set_persistence() div.add(select) return div
def get_display(my): assert my.load_script widget = DivWdg() widget.add_style('float', 'right') load_button = TextOptionBtnWdg(label=' Load ', size='medium') load_button.get_top_el().add_style('float', 'left') load_button.get_top_el().set_id(my.LOAD_BUTTON_ID) load_button.add_behavior( {'type': "click_up", "cbjs_action": "setTimeout(function() {%s}, 200) "% my.load_script }) widget.add(load_button) arrow_button = load_button.get_option_widget() #widget.add(arrow_button) suffix = "ASSET_LOADER_FUNCTIONS" menus_in = [ my.smart_menu_data ] SmartMenu.add_smart_menu_set( arrow_button, menus_in) SmartMenu.assign_as_local_activator(arrow_button, None, True) #SmartMenu.attach_smart_context_menu( load_button, menus_in, False ) x_div = FloatDivWdg("x") x_div.add_color('color','color') x_div.add_style('margin-right: 6px') widget.add(x_div) multiplier = TextWdg() multiplier.set_id("load_multiplier") multiplier.set_option("size", "1.5") multiplier.add_style("font-size: 0.8em") multiplier.add_style("float: left") multiplier.add_class("load_multiplier") widget.add( multiplier ) return widget
def get_display(my): sobject = my.get_current_sobject() if isinstance(sobject, Shot): frame_range = sobject.get_frame_range() frame_in, frame_out = sobject.get_frame_handles() frame_notes = sobject.get_frame_notes() else: from pyasm.prod.biz import FrameRange frame_start = my._get_frame_num(sobject, "tc_frame_start") frame_end = my._get_frame_num(sobject, "tc_frame_end") frame_range = FrameRange(frame_start, frame_end, 1 ) frame_in, frame_out = my._get_frame_handles(sobject) frame_notes = sobject.get_value("frame_note", no_exception=True) frame_notes = WikiUtil().convert(frame_notes) if frame_range.frame_end == frame_range.frame_start == 0: return 'n/a' widget = SpanWdg() widget.set_attr("nowrap", "1") offset = 2 label_width = 16 if frame_range.frame_start > 99: label_width = 20 # start / end frame duration_color = '#969353' div = DivWdg() div.add_tip('START -- END (TOTAL)') wdg_width = 150 div.add_style('width', wdg_width) total = frame_range.frame_end - frame_range.frame_start + 1 start_frame = SpanWdg(str(frame_range.frame_start)) end_frame = SpanWdg(str(frame_range.frame_end)) end_div = FloatDivWdg(end_frame) duration_width = wdg_width * 0.2 - offset #spacer_width = float('%.2f' %((duration_width + offset) * (frame_range.frame_start -1 ) /\ # frame_range.frame_end)) spacer_width = 0 start_div = FloatDivWdg(start_frame, width=label_width+spacer_width ) start_div.add_class('right_content') duration = FloatDivWdg( width=duration_width ) duration.add_style("border: 1px dotted %s" % duration_color) duration.add_style("margin-top: 3px") duration.add_style("margin-left: 5px") duration.add_style("margin-right: 5px") duration.add_style("height: 3px") duration.add_style("line-height: 3px") div.add(start_div) div.add(duration) div.add(end_div) dur_text = FloatDivWdg('<i>(%s)</i>' %total) dur_text.add_style("opacity", "0.3") div.add(dur_text) widget.add(div) widget.add(HtmlElement.br()) if frame_in: # in / out frame duration_color = '#b8b365' div = DivWdg() div.add_tip('IN -- OUT') div.add_style('width', wdg_width) handle_total = frame_out - frame_in + 1 in_frame = SpanWdg(str(frame_in)) out_frame = SpanWdg(str(frame_out)) if frame_range.frame_start == 0: frame_range.frame_start = 0.001 spacer_width = float('%.2f' % ((spacer_width) * \ float(frame_in) /frame_range.frame_start )) in_div = FloatDivWdg(in_frame, width=label_width + spacer_width) in_div.add_class('right_content') out_div = FloatDivWdg(out_frame) factor = float(handle_total) / total if factor > 1: factor = 1 duration_width = (duration_width + offset) * factor - offset duration = FloatDivWdg( width=duration_width ) duration.add_style("border: 1px solid %s" % duration_color) duration.add_style("background", duration_color) duration.add_style("margin-top: 5px") duration.add_style("margin-left: 5px") duration.add_style("margin-right: 5px") duration.add_style("line-height: 1px") duration.add(' ') # IE needs that to draw a 1px wide div bar = FloatDivWdg('<!-- -->', width=1) bar.add_style("margin-top: 1px") bar.add_style("line-height: 10px") bar.add_style("background", duration_color) div.add(in_div) div.add(bar) div.add(duration) div.add(bar) div.add(out_div) dur_text = SpanWdg('<i>(%s)</i>' %handle_total) dur_text.add_style("opacity", "0.3") div.add(dur_text) widget.add(div) if frame_notes: widget.add(HtmlElement.br()) widget.add(frame_notes) return widget
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_display(my): #content.add_event("oncontextmenu", "spt.side_bar.manage_context_menu_action_cbk(); return false") context_menu = DivWdg() context_menu.add_class('spt_menu_top') context_menu.add_behavior({ 'type': 'load', 'cbjs_action': ''' spt.finger_menu = {}; spt.finger_menu.timeout_id = -1; ''' }) context_menu.add_behavior({ 'type': 'mouseover', 'cbjs_action': ''' if (spt.finger_menu.timeout_id != -1) { clearTimeout(spt.finger_menu.timeout_id); spt.finger_menu.timeout_id = -1; } ''' }) #context_menu.set_box_shadow(color='#fff') # this may not be needed as it is set in JS context_menu.add_style("z-index: 200") # set up what happens when the mouse leaves the actual menu my._set_menu_out(context_menu) width = my.kwargs.get('width') height = my.kwargs.get('height') if not height: height = 20 if not width: width = 35 font_size = my.kwargs.get('font_size') if not font_size: font_size = 'smaller' force = my.kwargs.get("force") if my.mode == 'horizontal': div = DivWdg(css='spt_finger_menu') if force: div.add_attr("spt_finger_force", force) div.add_style("border-color: #aaa") div.add_style("border-style: solid") if force == "left": div.add_style("border-width: 1px 0px 1px 1px") div.add_style("border-radius: 12px 0px 0px 12px") else: div.add_style("border-width: 1px 1px 1px 0px") div.add_style("border-radius: 0px 12px 12px 0px") div.set_box_shadow(value="0px 0px 2px 1px") #div.add_style("z-index: 1000") total_width = width * len(my.items) + 15 div.add_style('width', total_width) div.add_styles('height: %spx; padding: 2px;' % height) context_menu.add(div) div.add_color('background', 'background', -10) palette = div.get_palette() sb_title_bg = palette.color('side_bar_title') bg_color = div.get_color('background', -10) color = div.get_color('color') for item in my.items: mouse_enter_bvr = { 'type': 'mouseenter', 'cbjs_action': ''' bvr.src_el.setStyles({'background': '%s', 'color': 'white'})''' % sb_title_bg } mouse_leave_bvr = { 'type': 'mouseleave', 'cbjs_action': ''' bvr.src_el.setStyles({'background': '%s', 'color': '%s'})''' % (bg_color, color) } menu_item = FloatDivWdg(css='unselectable hand') menu_item.add_color('background', 'background', -10) menu_item.add(item.get_option('label')) menu_item.add_behavior(mouse_enter_bvr) menu_item.add_behavior(mouse_leave_bvr) # add the passed-in bvr bvr = item.get_option('bvr_cb') menu_item.add_behavior(bvr) menu_item.add_styles( 'margin: 0px 0 0 0; padding: 2px 0 2px 0; text-align: center; font-size: %s; width: %s; height: %spx' % (font_size, width, height - 4)) menu_item.add_behavior({ 'type': 'click_up', 'cbjs_action': '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);''' }) div.add(menu_item) else: # this width only matters in vertical mode context_menu.add_style("width: %s" % width) menu_table = Table() menu_table.add_styles( "text-align: left; text-indent: 4px; border-collapse: collapse; cell-padding: 8px; border-radius: 32px;" ) context_menu.add(menu_table) my._add_spacer_row(menu_table, 3, width) for widget in my.widgets: tbody = menu_table.add_tbody() tbody.add_style("display", "table-row-group") tr = menu_table.add_row() tr.add_looks("smenu") #tr.add_class( "SPT_SMENU_ENTRY" ) hover_bvr = {'type': 'hover', 'add_looks': 'smenu_hilite'} #'cbjs_action_over': 'spt.smenu.entry_over( evt, bvr );', #'cbjs_action_out': 'spt.smenu.entry_out( evt, bvr );' } tr.add_behavior(hover_bvr) menu_item = menu_table.add_cell() font_size = '4px' menu_item.add_styles( 'padding: 0px 0 0 6px; font-size: %s; width: %s; height: 16px' % (font_size, width)) menu_item.add_behavior({ 'type': 'click_up', 'cbjs_action': '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);''' }) menu_item.add(widget) my._add_spacer_row(menu_table, 3, width) return context_menu
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_title(my): div = DivWdg() div.add_behavior({'type': 'load', 'cbjs_action': my.get_onload_js()}) # for csv export hid = HiddenWdg('start_date', my.start_date) div.add(hid) mday = my.today.strftime("%d") mmonth = my.today.strftime("%m") my.weekday_dict = {} days = [] for idx, date in enumerate(my.dates): day_div = DivWdg() days.append( day_div ) week_day = date.strftime("%a") day_div.add( "%s<br/>%s" % (week_day, date.strftime("%d") )) my.weekday_dict[idx] = week_day table = Table() div.add(table) table.add_row() table.add_color("color", "color") table.add_style("width: %spx"%my.table_width) table.add_style("float: left") month_div = FloatDivWdg(my.start_date.strftime("%b")) month_div.add_style('font-weight: 600') td = table.add_cell(month_div) td.add_style('width', '%spx'%my.MONTH_WIDTH) icon = IconButtonWdg(tip="Previous Week", icon=IconWdg.LEFT) td = table.add_cell(icon) offset = 0 if not my.use_straight_time: offset = 12 td.add_style("width: %spx" % (my.LEFT_WIDTH + offset) ) display_days = my.days_per_page next_start_date = my.start_date + datetime.timedelta(days=display_days) prev_start_date = my.start_date + datetime.timedelta(days=-display_days) icon.add_behavior( { 'type': 'click_up', 'start_date': prev_start_date.__str__(), 'cbjs_action': ''' spt.app_busy.show('Loading previous week...'); var header = bvr.src_el.getParent('.spt_table_header'); if (!header) { spt.alert('Work hour widget requires the new Fast Table Layout to scroll to previous week. You can do so in [Manage Side Bar].'); spt.app_busy.hide(); return; } var cur_name = spt.table.get_element_name_by_header(header); var values = {'start_date': bvr.start_date}; spt.table.refresh_column(cur_name, values); spt.app_busy.hide(); ''' } ) for day in days: day_wdg = DivWdg() day_wdg.add(day) td = table.add_cell() td.add(day_wdg) td.add_styles("text-align: center; padding-left: 2px;min-width: %spx"%my.day_width) icon = IconButtonWdg(tip="Next Week", icon=IconWdg.RIGHT) icon.add_behavior( { 'type': 'click_up', 'start_date': next_start_date.__str__(), 'cbjs_action': ''' spt.app_busy.show('Loading next week...'); var header = bvr.src_el.getParent('.spt_table_header'); if (!header) { spt.alert('Work hour widget requires the new Fast Table Layout to scroll to next week. You can do so in [Manage Side Bar].'); spt.app_busy.hide(); return; } var cur_name = spt.table.get_element_name_by_header(header); var values = {'start_date': bvr.start_date}; spt.table.refresh_column(cur_name, values); spt.app_busy.hide(); ''' } ) td = table.add_cell(icon) td.add_style('width: %spx'%my.day_width) # empty total cell td = table.add_blank_cell() td.add_style('width: 100%') return div
def get_display(my): sobject = my.get_current_sobject() if isinstance(sobject, Shot): frame_range = sobject.get_frame_range() frame_in, frame_out = sobject.get_frame_handles() frame_notes = sobject.get_frame_notes() else: from pyasm.prod.biz import FrameRange frame_start = my._get_frame_num(sobject, "tc_frame_start") frame_end = my._get_frame_num(sobject, "tc_frame_end") frame_range = FrameRange(frame_start, frame_end, 1) frame_in, frame_out = my._get_frame_handles(sobject) frame_notes = sobject.get_value("frame_note", no_exception=True) frame_notes = WikiUtil().convert(frame_notes) if frame_range.frame_end == frame_range.frame_start == 0: return 'n/a' widget = SpanWdg() widget.set_attr("nowrap", "1") offset = 2 label_width = 16 if frame_range.frame_start > 99: label_width = 20 # start / end frame duration_color = '#969353' div = DivWdg() div.add_tip('START -- END (TOTAL)') wdg_width = 100 div.add_style('width', wdg_width) total = frame_range.frame_end - frame_range.frame_start + 1 start_frame = SpanWdg(str(frame_range.frame_start)) end_frame = SpanWdg(str(frame_range.frame_end)) end_div = FloatDivWdg(end_frame) duration_width = wdg_width * 0.2 - offset spacer_width = float('%.2f' %((duration_width + offset) * (frame_range.frame_start -1 ) /\ frame_range.frame_end)) start_div = FloatDivWdg(start_frame, width=label_width + spacer_width) start_div.add_class('right_content') duration = FloatDivWdg(width=duration_width) duration.add_style("border: 1px dotted %s" % duration_color) duration.add_style("margin-top: 3px") duration.add_style("margin-left: 5px") duration.add_style("margin-right: 5px") duration.add_style("height: 3px") duration.add_style("line-height: 3px") div.add(start_div) div.add(duration) div.add(end_div) dur_text = FloatDivWdg('(%s)' % total) dur_text.add_style("opacity", "0.5") div.add(dur_text) widget.add(div) widget.add(HtmlElement.br()) if frame_in: # in / out frame duration_color = '#b8b365' div = DivWdg() div.add_tip('IN -- OUT') div.add_style('width', wdg_width) handle_total = frame_out - frame_in + 1 in_frame = SpanWdg(str(frame_in)) out_frame = SpanWdg(str(frame_out)) if frame_range.frame_start == 0: frame_range.frame_start = 0.001 spacer_width = float('%.2f' % ((spacer_width) * \ float(frame_in) /frame_range.frame_start )) in_div = FloatDivWdg(in_frame, width=label_width + spacer_width) in_div.add_class('right_content') out_div = FloatDivWdg(out_frame) factor = float(handle_total) / total if factor > 1: factor = 1 duration_width = (duration_width + offset) * factor - offset duration = FloatDivWdg(width=duration_width) duration.add_style("border: 1px solid %s" % duration_color) duration.add_style("background", duration_color) duration.add_style("margin-top: 5px") duration.add_style("margin-left: 5px") duration.add_style("margin-right: 5px") duration.add_style("line-height: 1px") duration.add(' ') # IE needs that to draw a 1px wide div bar = FloatDivWdg('<!-- -->', width=1) bar.add_style("margin-top: 1px") bar.add_style("height: 10px") bar.add_style("line-height: 10px") bar.add_style("background", duration_color) div.add(in_div) div.add(bar) div.add(duration) div.add(bar) div.add(out_div) dur_text = SpanWdg('(%s)' % handle_total) div.add(dur_text) widget.add(div) if frame_notes: widget.add(HtmlElement.br()) widget.add(frame_notes) return widget
def get_viewer(my): top = DivWdg(css='spt_note_viewer_top') # draw checkbox options swap = SwapDisplayWdg() title = SpanWdg('main context') split_div = FloatDivWdg(css='spt_split_cb') div = DivWdg(css='spt_main_context_cb') content_div = DivWdg() content_div.add_color('color', 'color') content_div.add_style('padding: 10px') SwapDisplayWdg.create_swap_title(title, swap, content_div, is_open=False) div.add(swap) div.add(title) checkbox_name = 'split_screen' split_cb = CheckboxWdg(checkbox_name, label='Split View') split_cb.persistence = True split_cb.persistence_obj = split_cb key = split_cb.get_key() #cb.add_style('float: left') split_cb.add_behavior({ 'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_note_viewer_top"); var table_top = top.getElement(".spt_note_viewer_table"); var cbs = top.getElement('.spt_main_context_cb'); var values = spt.api.Utility.get_input_values(cbs); var processes = values.note_context_cb; var kwargs = { process_names: processes}; if (bvr.src_el.checked) { kwargs.split_view = 'true'; kwargs.show_context = 'true'; kwargs.left_process_names = processes; kwargs.right_process_names = processes; } spt.input.save_selected(bvr, '%s','%s'); spt.app_busy.show("Note Viewer", 'Loading') ; setTimeout(function(){ spt.panel.refresh(table_top, kwargs, false); if (bvr.src_el.checked) spt.hide(cbs); else spt.show(cbs); spt.app_busy.hide(); }, 50 ); ''' % (checkbox_name, key) }) split_div.add(split_cb) top.add(split_div) top.add(div) div.add(content_div) top.add(HtmlElement.br()) checkbox_name = 'note_main_context_cb' cb = CheckboxWdg(checkbox_name) cb.persistence = True cb.persistence_obj = cb my.checked_process_names = cb.get_values() for value in my.process_names: #my.checked_process_names = web.get_form_values('process_names') cb = CheckboxWdg(checkbox_name, label=value) if value in my.checked_process_names: my.checked_processes.append(value) # FIXME: this is very tenous. Accessing private members to # override behavior cb.persistence = True cb.persistence_obj = cb key = cb.get_key() cb.set_option('value', value) cb.add_behavior({ 'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_note_viewer_top") var table_top = top.getElement('.spt_note_viewer_table'); var cbs = top.getElement('.spt_main_context_cb'); var values = spt.api.Utility.get_input_values(cbs); var processes = values.note_main_context_cb; var kwargs = { process_names: processes}; spt.input.save_selected(bvr, '%s','%s'); spt.panel.refresh(table_top, kwargs, false); ''' % (checkbox_name, key) }) content_div.add(cb) table_top = DivWdg(css='spt_note_viewer_table') expression = "@SOBJECT(sthpw/note['context','in','%s'])" % '|'.join( my.checked_processes) if split_cb.is_checked(): table = my.get_split_viewer() else: table_id = 'main_table1' table = TableLayoutWdg(table_id=table_id, search_type='sthpw/note', view=my.view,\ show_row_select=True, show_insert=False, state={'parent_key': my.parent_key}, inline_search=False, show_refresh=True, expression=expression ) my.set_as_panel(table_top) table_top.add_style('float: left') top.add(table_top) table_top.add(table) return top
class DependencyWdg(BaseRefreshWdg): '''widget that follows a snapshot's dependencies and prints them out''' MAX_NODE_LENGTH = 100 def init(self): self.show_title = True self.mode = self.kwargs.get('mode') def set_show_title(self, flag): self.show_title = flag def get_display(self): if self.mode == 'detail': upstream = True div = DivWdg() self.snapshot_code = self.kwargs.get('snapshot_code') ref_snapshot = Snapshot.get_by_code(self.snapshot_code) self._handle_snapshot(ref_snapshot, div, upstream, recursive=False) return div self.web = WebContainer.get_web() if self.sobjects: snapshot = self.sobjects[0] else: search_type = self.kwargs.get("search_type") search_id = self.kwargs.get("search_id") snapshot = None if search_type == Snapshot.SEARCH_TYPE: snapshot = Search.get_by_id(search_type, search_id) else: snapshot = Snapshot.get_latest(search_type, search_id) if not snapshot: self.add(HtmlElement.h3("No snapshot found")) return super(DependencyWdg,self).get_display() widget = DivWdg() widget.add_style('min-width: 700px') if self.show_title: self.add(HtmlElement.h3("Asset Dependency")) from tactic.ui.panel import TableLayoutWdg table = TableLayoutWdg(search_type="sthpw/snapshot", mode='simple', view='table', width='700px') table.add_style('min-width: 700px') table.set_sobject(snapshot) widget.add(table) sobject = snapshot.get_sobject() search_type_obj = sobject.get_search_type_obj() #file_div = DivWdg(css='left_content discussion_child') file_div = DivWdg() file_div.add_color("background", "background", -20) file_div.add_color("color", "color") file_div.add_style("padding: 5px") file_div.add_border() #file_div.add_style('margin','0 10px 0 10px') file_div.add_style('padding','10px 0 0 10px') #file_div.add_style('-moz-border-radius: 6px') title = DivWdg() title.add_style("font-weight: bold") title.add_style("font-size: 1.2em") #title.add_style('margin-left', '10px') if self.show_title: title.add(search_type_obj.get_title() ) title.add(" - ") title.add(sobject.get_code() ) if sobject.has_value("description"): title.add(" : ") title.add(sobject.get_value("description") ) file_div.add(title) file_div.add(HtmlElement.br()) # find out how many 1st level ref nodes we are dealing with xml = snapshot.get_xml_value("snapshot") #self.total_ref_count = len(xml.get_nodes("snapshot/file/ref | snapshot/ref |snapshot/input_ref| snapshot/fref")) self._handle_snapshot(snapshot, file_div, upstream=True, recursive=True ) self._handle_snapshot(snapshot, file_div, upstream=False, recursive=True ) #widget.add(widget) widget.add(file_div) widget.add(HtmlElement.br(2)) #return super(DependencyWdg,self).get_display() return widget def _handle_snapshot(self, snapshot, widget, upstream, recursive=True): ''' handle the files and refs in this snapshot ''' if upstream: self._handle_files(snapshot, widget, upstream, recursive) # handle the refs in this snapshot self._handle_refs(snapshot, widget, upstream, recursive) return len(widget.widgets) def _handle_files(self, snapshot, widget, upstream, recursive=True): web_dir = snapshot.get_web_dir() xml = snapshot.get_xml_value("snapshot") # handle files files = xml.get_nodes("snapshot/file") for file in files: file_code = Xml.get_attribute(file, "file_code") file_type = Xml.get_attribute(file, "type") file_range = Xml.get_attribute(file, "file_range") #file_range = "1-4/1" dir = snapshot.get_client_lib_dir(file_type=file_type) lib_dir = snapshot.get_lib_dir(file_type=file_type) open_button = IconButtonWdg( "Explore: %s" % dir, IconWdg.LOAD, False) if dir == lib_dir: open_button.add_behavior({'type':'click_up', 'cbjs_action': '''var applet = spt.Applet.get(); spt.alert('You are not allowed to browse directories on a web server.'); '''}) else: open_button.add_behavior({'type':'click_up', 'dir' : dir, 'cbjs_action': ''' var applet = spt.Applet.get(); var dir = bvr.dir; applet.open_explorer(dir);'''}) open_button.add_class('small') open_button.add_style('float: left') widget.add(open_button) if file_range: file_name = Xml.get_attribute(file, "name") widget.add("%s [code = %s, type = %s]" % (file_name, file_code, file_type)) widget.add(HtmlElement.br(2)) # display all of the paths file_names = FileGroup.expand_paths( file_name, FileRange.get(file_range) ) for file_name in file_names: #link = HtmlElement.href(file_name, "%s/%s" % (web_dir, file_name), target="_blank" ) link = SpanWdg(file_name) link.add_color("color", "color") widget.add(link) widget.add(HtmlElement.br()) else: thumb = DependencyThumbWdg() thumb.set_show_filename(True) thumb.set_sobject(snapshot) thumb.set_icon_size(15) thumb.set_image_link_order([file_type]) thumb.set_option('detail', 'false') widget.add(SpanWdg(thumb, css='small')) widget.add("[code = %s, type = %s]" % ( file_code, file_type)) widget.add(HtmlElement.br()) block = DivWdg() block.add_style("margin-left: 30px") block.add_style("margin-top: 10px") nodes = xml.get_nodes("snapshot/file[@file_code='%s']/ref" % file_code) widget.add(HtmlElement.br(clear="all")) # handle sub refs for node in nodes: self._handle_ref_node(node, block, upstream, recursive) block.add(HtmlElement.br()) if nodes: widget.add(block) widget.add(HtmlElement.br()) files = xml.get_nodes("snapshot/unknown_ref") if files: widget.add(HtmlElement.b("Unknown ref.")) for file in files: block = DivWdg() block.add_style("margin-left: 30px") block.add_style("margin-top: 10px") block.add( IconWdg( "Unknown", IconWdg.UNKNOWN) ) path = Xml.get_attribute(file, "path") block.add(path) widget.add(block) def _handle_refs(self, snapshot, widget, upstream, recursive=True): xml = snapshot.get_xml_value("snapshot") # go through the references if upstream: nodes = xml.get_nodes("snapshot/ref") if nodes: widget.add(HtmlElement.b('Upstream ref.')) block = DivWdg() block.add_style("margin-left: 30px") block.add_style("margin-top: 10px") for node in nodes: self._handle_ref_node(node, block, upstream, recursive) block.add(HtmlElement.br()) widget.add(block) # go through the input references nodes = xml.get_nodes("snapshot/input_ref") if nodes: widget.add(HtmlElement.br()) widget.add(HtmlElement.b("Input ref.")) block = DivWdg() block.add_style("margin-left: 30px") block.add_style("margin-top: 10px") for node in nodes: self._handle_ref_node(node, block, upstream, recursive) widget.add(block) else: # go through the forward references nodes = xml.get_nodes("snapshot/fref") if nodes: widget.add(HtmlElement.b("Downstream ref.")) block = DivWdg() block.add_style("margin-left: 30px") block.add_style("margin-top: 10px") for node in nodes: self._handle_ref_node(node, block, upstream, recursive) widget.add(block) def _handle_ref_node(self, node, widget, upstream=False, recursive=True): # get the reference snapshot (should maybe use the loader or # at least share the code instance = Xml.get_attribute(node,"instance") search_type = Xml.get_attribute(node,"search_type") search_id = Xml.get_attribute(node,"search_id") context = Xml.get_attribute(node,"context") version = Xml.get_attribute(node,"version") # this is often the Maya file node name or XSI long clip name node_name = Xml.get_attribute(node, "node") my_name = Xml.get_node_name(node) # get the snapshot ref_snapshot = Snapshot.get_by_version(search_type, search_id,\ context, version) #ref_snapshot = Snapshot.get_latest(search_type,search_id, context) if ref_snapshot == None: widget.add("|---> <font color='red'>Error: No reference found for [%s, %s, %s]</font>" % \ (search_type, search_id, context) ) return toggle_id = self.generate_unique_id('toggle') widget.add(FloatDivWdg(), toggle_id) version = ref_snapshot.get_value("version") try: sobject = ref_snapshot.get_sobject() except SObjectNotFoundException, e: widget.add('[%s|%s] may have been deleted or is not viewable.' % (ref_snapshot.get_value('search_type'),\ ref_snapshot.get_value('search_id'))) return search_type_obj = sobject.get_search_type_obj() # this is the top level icon usually thumb_span = SpanWdg() thumb_span.add_style("float: left") thumb = ThumbWdg() thumb.set_sobject(ref_snapshot) thumb.set_icon_size(15) # for input_ref, just get the latest icon if my_name == 'ref': thumb.set_version(version) # this has to be a FloatDivWdg widget.add(FloatDivWdg(thumb)) info_div = DivWdg() info_span = SpanWdg(css='med') info_span.add_color("color", "color") info_div.add(info_span) widget.add(info_div) info_span.add(HtmlElement.b(search_type_obj.get_title()) ) widget.add(" ") if instance != "": info_span.add(" : ") info_span.add( instance ) info_span.add(" : ") info_span.add(sobject.get_code() ) if sobject.has_value("description"): info_span.add(" : ") info_span.add(sobject.get_value("description") ) info_span.add( " : %s" % (context) ) info_span.add( " : v%0.2d " % (int(version)) ) if ref_snapshot.is_current(): info_span.add( IconWdg("Currency", IconWdg.DOT_GREEN) ) else: info_span.add( IconWdg("Currency", IconWdg.DOT_RED) ) #if not recursive: # return # input ref may not have node_name if node_name: node_name_len = len(node_name) suffix = '' if node_name_len > self.MAX_NODE_LENGTH: node_name_len = self.MAX_NODE_LENGTH suffix = '...' node_data = "<b>node</b> : %s %s" % (node_name[:node_name_len], suffix) node_span = SpanWdg(node_data) node_span.add_style('padding-left: 22px') widget.add(node_span) widget.add(HtmlElement.br()) # more info of this ref node is put into this div div_id = 'toggle_content_%s' % toggle_id div = DivWdg(id=div_id) div.add_style('display: none') swap = SwapDisplayWdg.get_triangle_wdg() swap.add_style('float: left') div.add_style('margin: 0 20px 0 20px') div.add(HtmlElement.br()) # stop the recursion after this around if recursive: recursive = False else: return # set up the toggle scripts title = None SwapDisplayWdg.create_swap_title(title, swap, div) swap.get_on_widget().add_behavior({'type': 'click_up', 'cbjs_action': "spt.panel.load('%s', 'pyasm.widget.DependencyWdg', {'mode':'detail', \ 'snapshot_code': '%s'}, {}, false)" %(div_id, ref_snapshot.get_code())}) widget.add(HtmlElement.br()) widget.set_widget(swap, toggle_id) widget.add(div) """
def get_viewer(self): top = DivWdg(css='spt_note_viewer_top') # draw checkbox options swap = SwapDisplayWdg() title = SpanWdg('main context') split_div = FloatDivWdg(css='spt_split_cb') div = DivWdg(css='spt_main_context_cb') content_div = DivWdg() content_div.add_color('color','color') content_div.add_style('padding: 10px') SwapDisplayWdg.create_swap_title(title, swap, content_div, is_open=False) div.add(swap) div.add(title) checkbox_name = 'split_screen' split_cb = CheckboxWdg(checkbox_name, label='Split View') split_cb.persistence = True split_cb.persistence_obj = split_cb key = split_cb.get_key() #cb.add_style('float: left') split_cb.add_behavior({'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_note_viewer_top"); var table_top = top.getElement(".spt_note_viewer_table"); var cbs = top.getElement('.spt_main_context_cb'); var values = spt.api.Utility.get_input_values(cbs); var processes = values.note_context_cb; var kwargs = { process_names: processes}; if (bvr.src_el.checked) { kwargs.split_view = 'true'; kwargs.show_context = 'true'; kwargs.left_process_names = processes; kwargs.right_process_names = processes; } spt.input.save_selected(bvr, '%s','%s'); spt.app_busy.show("Note Viewer", 'Loading') ; setTimeout(function(){ spt.panel.refresh(table_top, kwargs, false); if (bvr.src_el.checked) spt.hide(cbs); else spt.show(cbs); spt.app_busy.hide(); }, 50 ); ''' % ( checkbox_name, key) }) split_div.add(split_cb) top.add(split_div) top.add(div) div.add(content_div) top.add(HtmlElement.br()) checkbox_name = 'note_main_context_cb' cb = CheckboxWdg(checkbox_name) cb.persistence = True cb.persistence_obj = cb self.checked_process_names = cb.get_values() for value in self.process_names: #self.checked_process_names = web.get_form_values('process_names') cb = CheckboxWdg(checkbox_name, label=value) if value in self.checked_process_names: self.checked_processes.append(value) # FIXME: this is very tenous. Accessing private members to # override behavior cb.persistence = True cb.persistence_obj = cb key = cb.get_key() cb.set_option('value', value) cb.add_behavior({ 'type': 'click_up', 'propagate_evt': True, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_note_viewer_top") var table_top = top.getElement('.spt_note_viewer_table'); var cbs = top.getElement('.spt_main_context_cb'); var values = spt.api.Utility.get_input_values(cbs); var processes = values.note_main_context_cb; var kwargs = { process_names: processes}; spt.input.save_selected(bvr, '%s','%s'); spt.panel.refresh(table_top, kwargs, false); ''' % (checkbox_name, key) }) content_div.add(cb) table_top = DivWdg(css='spt_note_viewer_table') expression = "@SOBJECT(sthpw/note['context','in','%s'])" %'|'.join(self.checked_processes) if split_cb.is_checked(): table = self.get_split_viewer() else: table_id = 'main_table1' table = TableLayoutWdg(table_id=table_id, search_type='sthpw/note', view=self.view,\ show_row_select=True, show_insert=False, state={'parent_key': self.parent_key}, inline_search=False, show_refresh=True, expression=expression ) self.set_as_panel(table_top) table_top.add_style('float: left') top.add(table_top) table_top.add(table) return top
def get_display(my): search_key = my.kwargs.get("search_key") msg = None base_search_type = SearchKey.extract_search_type(search_key) sobject = SearchKey.get_by_search_key(search_key) process_div = DivWdg() process_div.add_style('padding-top: 10px') if base_search_type in ['sthpw/task', 'sthpw/note']: my.process = sobject.get_value('process') my.context = sobject.get_value('context') if not my.process: my.process = '' parent = sobject.get_parent() if parent: search_key = SearchKey.get_by_sobject(parent) else: msg = "Parent for [%s] not found"%search_key else: my.process = my.kwargs.get('process') top = my.top top.add_class('spt_simple_checkin') top.add_color("background", "background") top.add_styles("position: relative") content = DivWdg(msg) top.add(content) #content.add_border() #content.add_color("background", "background3") #content.add_color("color", "background3") content.add_style("width: 600px") content.add_styles("margin-left: auto; margin-right: auto;") content.add_style("height: 200px") from tactic.ui.widget import CheckinWdg content.add_behavior( { 'type': 'load', 'cbjs_action': CheckinWdg.get_onload_js() } ) button_div = DivWdg() content.add(process_div) content.add(button_div) button = IconWdg(title="Check-In", icon=IconWdg.CHECK_IN_3D_LG) title = Common.get_display_title(my.checkin_action) button.add_attr('title', title) button_div.add(button) button_div.set_box_shadow("1px 1px 1px 1px") button_div.add_style("width: 60px") button_div.add_style("height: 60px") button_div.add_style("float: left") button_div.add_style("background: white") button_div.add_class("hand") button_div.add_style("padding: 2px 3px 0 0") button_div.add_style("margin: 20px 60px 20px 200px") button_div.add_style("text-align: center") button_div.add("Check-in") # to be consistent with Check-in New File if my.process: checkin_process = my.process else: # Dont' specify, the user can choose later in check-in widget checkin_process = '' button.add_behavior( { 'type': 'click_up', 'search_key': search_key, 'process': checkin_process, 'context': my.context, 'cbjs_action': ''' var class_name = 'tactic.ui.widget.CheckinWdg'; var applet = spt.Applet.get(); spt.app_busy.show("Choose file(s) to check in") var current_dir = null; var is_sandbox = false; var refresh = false var values = spt.checkin.browse_folder(current_dir, is_sandbox, refresh); if (!values) { spt.app_busy.hide(); return; } var file_paths = values.file_paths; if (file_paths.length == 0) { spt.alert("You need to select files(s) to check in."); spt.app_busy.hide(); return; } spt.app_busy.hide(); var args = { 'search_key': bvr.search_key, 'show_links': false, 'show_history': false, 'close_on_publish': true } if (bvr.process) args.process = bvr.process; if (bvr.context) args.context = bvr.context; var kwargs = {}; kwargs.values = values; spt.panel.load_popup("Check-in", class_name, args, kwargs); /* var options= { title: "Check-in Widget", class_name: 'tactic.ui.widget.CheckinWdg', popup_id: 'checkin_widget' }; var bvr2 = {}; bvr2.options = options; bvr2.values = values; bvr2.args = args; spt.popup.get_widget({}, bvr2) */ ''' } ) button_div = DivWdg() content.add(button_div) button = IconWdg(title="Check-Out", icon=IconWdg.CHECK_OUT_3D_LG) button_div.add(button) button_div.set_box_shadow("1px 1px 1px 1px") button_div.add_style("width: 60px") button_div.add_style("height: 60px") button_div.add_style("float: left") button_div.add_style("margin: 20px") button_div.add_style("padding: 2px 3px 0 0") button_div.add_style("background: white") button_div.add_class("hand") button_div.add_style("text-align: center") button_div.add("Check-out") sobject = SearchKey.get_by_search_key(search_key) # snapshot is retrieved for getting the process informatoin, they are not being used # for loading as real_time snapshot query option is used. search = Search("sthpw/snapshot") search.add_sobject_filter(sobject) if my.process: search.add_filter("process", my.process) search.add_filter("is_latest", True) snapshot = search.get_sobject() if not my.process and snapshot: my.process = snapshot.get_value('process') # for old process-less snapshots if not my.process: my.process = snapshot.get_value('context') process_wdg = DivWdg(HtmlElement.b(checkin_process)) if checkin_process: width = len(checkin_process)*10 else: width = 10 process_wdg.add_styles('margin-left: auto; margin-right: auto; text-align: center; width: %s'%width) process_div.add(process_wdg) # DO NOT pass in snapshot_code, get it in real time snapshot_codes = [] show_status = True if my.checkout_action == 'latest': cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status) bvr = {'snapshot_codes': snapshot_codes, 'real_time': True, 'file_types': ['main'], 'filename_mode': 'repo', 'cbjs_action': cbjs_action} elif my.checkout_action == 'latest (version_omitted)': cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status) bvr = {'snapshot_codes':snapshot_codes, 'real_time': True, 'file_types': ['main'], 'filename_mode': 'versionless', 'cbjs_action': cbjs_action} elif my.checkout_action == 'latest versionless': cbjs_action = CheckinSandboxListWdg.get_checkout_cbjs_action(my.process, show_status) bvr = {'snapshot_codes':snapshot_codes, 'real_time': True, 'versionless': True, 'file_types': ['main'], 'filename_mode': 'versionless', 'cbjs_action': cbjs_action} elif my.checkout_action == 'open file browser': bvr = { 'cbjs_action': ''' var class_name = 'tactic.ui.checkin.SObjectDirListWdg'; var kwargs = { search_keys: [bvr.search_key], process: '%s' }; spt.panel.load_popup("Check-out", class_name, kwargs); '''%my.process } bvr.update({ 'type': 'click_up', 'search_key': search_key}) button.add_behavior(bvr) title = Common.get_display_title(my.checkout_action) button.add_attr('title', title) #TODO: remove these margin-top which is used to compensate all the ButtonNewWdg top extra white space content.add("<br clear='all'/>") status_div = DivWdg() status_div.add_style('margin: 20px 0 0 10px') status_div.add_style('width: 100%') text_info = FloatDivWdg() text_info.add_styles('padding: 4px; width: 500px') text_info.add_style('margin-top: 8px') text_info.add_attr('title','Displays the last checked out file path') text_info.add_border() text_info.set_round_corners() text_content = DivWdg() text_content.add(' ') text_content.add_class('spt_status_area') text_info.add(text_content) label = FloatDivWdg('path:') label.add_style('margin: 12px 6px 0 6px') # button button = ButtonNewWdg(title="Explore", icon=IconWdg.FOLDER_GO) button.add_style('padding-bottom: 15px') button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var applet = spt.Applet.get(); var status_div = bvr.src_el.getParent('.spt_simple_checkin').getElement('.spt_status_area'); var value = status_div.get('text'); var dir_name = spt.path.get_dirname(value); if (dir_name) applet.open_explorer(dir_name); ''' } ) status_div.add(label) status_div.add(text_info) content.add(status_div) content.add(button) content.add_behavior({'type':'load', 'cbjs_action': ''' if (!spt.Applet.applet) { spt.api.app_busy_show('Initializing Java', 'Please wait...'); var exec = function() {var applet = spt.Applet.get()}; spt.api.app_busy_hide(exec); }'''}) return top
def get_display(my): #content.add_event("oncontextmenu", "spt.side_bar.manage_context_menu_action_cbk(); return false") context_menu = DivWdg() context_menu.add_class('spt_menu_top') context_menu.add_behavior( { 'type': 'load', 'cbjs_action': ''' spt.finger_menu = {}; spt.finger_menu.timeout_id = -1; ''' } ) context_menu.add_behavior( { 'type': 'mouseover', 'cbjs_action': ''' if (spt.finger_menu.timeout_id != -1) { clearTimeout(spt.finger_menu.timeout_id); spt.finger_menu.timeout_id = -1; } ''' } ) #context_menu.set_box_shadow(color='#fff') # this may not be needed as it is set in JS context_menu.add_style("z-index: 200") # set up what happens when the mouse leaves the actual menu my._set_menu_out(context_menu) width = my.kwargs.get('width') height = my.kwargs.get('height') if not height: height = 20 if not width: width = 35 font_size = my.kwargs.get('font_size') if not font_size: font_size = 'smaller' force = my.kwargs.get("force") if my.mode == 'horizontal': div = DivWdg(css='spt_finger_menu') if force: div.add_attr("spt_finger_force", force) div.add_style("border-color: #aaa") div.add_style("border-style: solid") if force == "left": div.add_style("border-width: 1px 0px 1px 1px") div.add_style("border-radius: 12px 0px 0px 12px") else: div.add_style("border-width: 1px 1px 1px 0px") div.add_style("border-radius: 0px 12px 12px 0px") div.set_box_shadow(value="0px 0px 2px 1px") #div.add_style("z-index: 1000") total_width = width * len(my.items) + 15 div.add_style('width', total_width) div.add_styles('height: %spx; padding: 2px;' %height) context_menu.add(div) div.add_color('background','background', -10) palette = div.get_palette() sb_title_bg = palette.color('side_bar_title') bg_color = div.get_color('background', -10) color = div.get_color('color') for item in my.items: mouse_enter_bvr = {'type':'mouseenter', 'cbjs_action': ''' bvr.src_el.setStyles({'background': '%s', 'color': 'white'})''' %sb_title_bg} mouse_leave_bvr = {'type':'mouseleave', 'cbjs_action': ''' bvr.src_el.setStyles({'background': '%s', 'color': '%s'})''' %(bg_color, color)} menu_item = FloatDivWdg(css='unselectable hand') menu_item.add_color('background','background', -10) menu_item.add(item.get_option('label')) menu_item.add_behavior( mouse_enter_bvr ) menu_item.add_behavior( mouse_leave_bvr ) # add the passed-in bvr bvr = item.get_option('bvr_cb') menu_item.add_behavior(bvr ) menu_item.add_styles('margin: 0px 0 0 0; padding: 2px 0 2px 0; text-align: center; font-size: %s; width: %s; height: %spx'%(font_size, width, height-4)) menu_item.add_behavior({'type': 'click_up', 'cbjs_action': '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);'''}) div.add(menu_item) else: # this width only matters in vertical mode context_menu.add_style("width: %s" %width) menu_table = Table() menu_table.add_styles( "text-align: left; text-indent: 4px; border-collapse: collapse; cell-padding: 8px; border-radius: 32px;" ) context_menu.add(menu_table) my._add_spacer_row(menu_table, 3, width) for widget in my.widgets: tbody = menu_table.add_tbody() tbody.add_style("display","table-row-group") tr = menu_table.add_row() tr.add_looks( "smenu" ) #tr.add_class( "SPT_SMENU_ENTRY" ) hover_bvr = {'type':'hover', 'add_looks': 'smenu_hilite'} #'cbjs_action_over': 'spt.smenu.entry_over( evt, bvr );', #'cbjs_action_out': 'spt.smenu.entry_out( evt, bvr );' } tr.add_behavior( hover_bvr ) menu_item = menu_table.add_cell() font_size = '4px' menu_item.add_styles('padding: 0px 0 0 6px; font-size: %s; width: %s; height: 16px'%(font_size, width)) menu_item.add_behavior({'type': 'click_up', 'cbjs_action': '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);'''}) menu_item.add(widget) my._add_spacer_row(menu_table, 3, width) return context_menu
def get_upload_wdg(my): '''get search type select and upload wdg''' widget = DivWdg(css='spt_import_csv') widget.add_color('color','color') widget.add_color('background','background') widget.add_style('width: 600px') # get the search type title = DivWdg("<b>Select sType to import data into:</b> ") widget.add( title ) title.add_style("float: left") # handle new search_types new_search_type = CheckboxWdg("new_search_type_checkbox") new_search_type.add_event("onclick", "toggle_display('new_search_type_div')") #span = SpanWdg(css="med") #span.add(new_search_type) #span.add("Create new type") #span.add(" ... or ... ") #widget.add(span) new_search_type_div = DivWdg() new_search_type_div.set_id("new_search_type_div") name_input = TextWdg("asset_name") title = TextWdg("asset_title") description = TextAreaWdg("asset_description") key='csv_import' table = Table() table.set_id('csv_main_body') table.add_style("margin: 10px 10px") table.add_col().set_attr('width','140') table.add_col().set_attr('width','400') table.add_row() table.add_header("Search Type: ").set_attr('align','left') table.add_cell(name_input) table.add_row() table.add_header("Title: ").set_attr('align','left') table.add_cell(title) table.add_row() table.add_header("Description: ").set_attr('align','left') table.add_cell(description) new_search_type_div.add(table) new_search_type_div.add_style("display: none") #widget.add(new_search_type_div) div = DivWdg() search_type_select = SearchTypeSelectWdg("search_type_filter", mode=SearchTypeSelectWdg.ALL) search_type_select.add_empty_option("-- Select --") if not search_type_select.get_value(): search_type_select.set_value(my.search_type) search_type_select.set_persist_on_submit() div.add(search_type_select) widget.add(div) search_type_select.add_behavior( {'type': 'change', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': bvr.src_el.value});" %(Common.get_full_class_name(my)) } ) if my.search_type: sobj = None try: sobj = SObjectFactory.create(my.search_type) except ImportError: widget.add(HtmlElement.br()) widget.add(SpanWdg('WARNING: Import Error encountered. Please choose another search type.', css='warning')) return widget required_columns = sobj.get_required_columns() if required_columns: widget.add(HtmlElement.br()) req_span = SpanWdg("Required Columns: ", css='med') req_span.add_color('color','color') widget.add(req_span) #required_columns = ['n/a'] req_span.add(', '.join(required_columns)) widget.add( HtmlElement.br() ) if my.file_path: hidden = HiddenWdg("file_path", my.file_path) widget.add(hidden) if my.web_url: file_span = FloatDivWdg('URL: <i>%s</i> ' %my.web_url, css='med') else: file_span = FloatDivWdg('File uploaded: <i>%s</i> ' %os.path.basename(my.file_path), css='med') file_span.add_color('color','color') file_span.add_style('margin: 8px 0 0 10px') file_span.add_style('font-size: 14px') widget.add(file_span) button = ActionButtonWdg(title='Change') button.add_style('float','left') button.add_behavior( {'type': 'click_up', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': '%s'});" %(Common.get_full_class_name(my), my.search_type) } ) widget.add(button) widget.add("<br clear='all'/>") widget.add(HtmlElement.br()) return widget widget.add("<br/>") widget.add_style("overflow-y: auto") msg = DivWdg() widget.add(msg) msg.add( "<div style='float: left; padding-left: 100px; padding-top: 6px'><b>Upload a csv file: </b></div>") msg.add_border() msg.add_style("width: 400px") msg.add_color("background", "background3") msg.add_style("padding: 20px") msg.add_style("margin: 30 auto") msg.add_style("text-align: center") ticket = Environment.get_security().get_ticket_key() on_complete = '''var server = TacticServerStub.get(); var file = spt.html5upload.get_file(); if (file) { var file_name = file.name; // clean up the file name the way it is done in the server file_name = spt.path.get_filesystem_name(file_name); var server = TacticServerStub.get(); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; values['html5_ticket'] = '%s'; try { var info = spt.panel.load('csv_import_main', class_name, {}, values); spt.app_busy.hide(); } catch(e) { spt.alert(spt.exception.handler(e)); } } else { alert('Error: file object cannot be found.') } spt.app_busy.hide();'''%ticket from tactic.ui.input import UploadButtonWdg browse = UploadButtonWdg(name='new_csv_upload', title="Browse", tip="Click to choose a csv file",\ on_complete=on_complete, ticket=ticket) browse.add_style('float: left') msg.add(browse) # this is now only used in the copy and paste Upload button for backward-compatibility upload_wdg = SimpleUploadWdg(key=key, show_upload=False) upload_wdg.add_style('display: none') msg.add(upload_wdg) #widget.add(span) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Published URL: </b>") text = TextWdg("web_url") msg.add(text) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Copy and Paste from a Spreadsheet: </b>") text = TextAreaWdg("data") text.add_style('width: 33em') text.add_class("spt_import_cut_paste") msg.add(text) button = ActionButtonWdg(title="Parse") button.add_style("margin: 5px auto") msg.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_import_top"); var el = top.getElement(".spt_import_cut_paste"); var applet = spt.Applet.get(); var value = el.value; var csv = []; // convert to a csv file! lines = value.split("\\n"); for (var i = 0; i < lines.length; i++) { if (lines[i] == '') { continue; } var parts = lines[i].split("\\t"); var new_line = []; for (var j = 0; j < parts.length; j++) { if (parts[j] == '') { new_line.push(''); } else { new_line.push('"'+parts[j]+'"'); } } new_line = new_line.join(","); csv.push(new_line); } csv = csv.join("\\n") // FIXME: need to get a local temp directory var path = spt.browser.os_is_Windows() ? "C:/sthpw/copy_n_paste.csv" : "/tmp/sthpw/copy_n_paste.csv"; applet.create_file(path, csv); // upload the file applet.upload_file(path) applet.rmtree(path); var top = bvr.src_el.getParent(".spt_import_csv"); var hidden = top.getElement(".spt_upload_hidden"); hidden.value = path; var file_name = spt.path.get_basename(hidden.value); file_name = spt.path.get_filesystem_name(file_name); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; var info = spt.panel.load('csv_import_main', class_name, {}, values); ''' } ) return widget
def get_title(my): div = DivWdg() div.add_behavior({'type': 'load', 'cbjs_action': my.get_onload_js()}) # for csv export hid = HiddenWdg('start_date', my.start_date) div.add(hid) mday = my.today.strftime("%d") mmonth = my.today.strftime("%m") my.weekday_dict = {} days = [] for idx, date in enumerate(my.dates): day_div = DivWdg() days.append(day_div) week_day = date.strftime("%a") day_div.add("%s<br/>%s" % (week_day, date.strftime("%d"))) my.weekday_dict[idx] = week_day table = Table() div.add(table) table.add_row() table.add_color("color", "color") table.add_style("width: %spx" % my.table_width) table.add_style("float: left") month_div = FloatDivWdg(my.start_date.strftime("%b")) month_div.add_style('font-weight: 600') td = table.add_cell(month_div) td.add_style('width', '%spx' % my.MONTH_WIDTH) icon = IconButtonWdg(tip="Previous Week", icon=IconWdg.LEFT) td = table.add_cell(icon) offset = 0 if not my.use_straight_time: offset = 12 td.add_style("width: %spx" % (my.LEFT_WIDTH + offset)) display_days = my.days_per_page next_start_date = my.start_date + datetime.timedelta(days=display_days) prev_start_date = my.start_date + datetime.timedelta( days=-display_days) icon.add_behavior({ 'type': 'click_up', 'start_date': prev_start_date.__str__(), 'cbjs_action': ''' spt.app_busy.show('Loading previous week...'); var header = bvr.src_el.getParent('.spt_table_header'); if (!header) { spt.alert('Work hour widget requires the new Fast Table Layout to scroll to previous week. You can do so in [Manage Side Bar].'); spt.app_busy.hide(); return; } var cur_name = spt.table.get_element_name_by_header(header); var values = {'start_date': bvr.start_date}; spt.table.refresh_column(cur_name, values); spt.app_busy.hide(); ''' }) for day in days: day_wdg = DivWdg() day_wdg.add(day) td = table.add_cell() td.add(day_wdg) td.add_styles( "text-align: center; padding-left: 2px;min-width: %spx" % my.day_width) icon = IconButtonWdg(tip="Next Week", icon=IconWdg.RIGHT) icon.add_behavior({ 'type': 'click_up', 'start_date': next_start_date.__str__(), 'cbjs_action': ''' spt.app_busy.show('Loading next week...'); var header = bvr.src_el.getParent('.spt_table_header'); if (!header) { spt.alert('Work hour widget requires the new Fast Table Layout to scroll to next week. You can do so in [Manage Side Bar].'); spt.app_busy.hide(); return; } var cur_name = spt.table.get_element_name_by_header(header); var values = {'start_date': bvr.start_date}; spt.table.refresh_column(cur_name, values); spt.app_busy.hide(); ''' }) td = table.add_cell(icon) td.add_style('width: %spx' % my.day_width) # empty total cell td = table.add_blank_cell() td.add_style('width: 100%') return div
def get_upload_wdg(my): '''get search type select and upload wdg''' widget = DivWdg(css='spt_import_csv') widget.add_color('color','color') widget.add_color('background','background') widget.add_style('width: 600px') # get the search type title = DivWdg("<b>Select sType to import data into:</b> ") widget.add( title ) title.add_style("float: left") # handle new search_types new_search_type = CheckboxWdg("new_search_type_checkbox") new_search_type.add_event("onclick", "toggle_display('new_search_type_div')") #span = SpanWdg(css="med") #span.add(new_search_type) #span.add("Create new type") #span.add(" ... or ... ") #widget.add(span) new_search_type_div = DivWdg() new_search_type_div.set_id("new_search_type_div") name_input = TextWdg("asset_name") title = TextWdg("asset_title") description = TextAreaWdg("asset_description") key='csv_import' table = Table() table.set_id('csv_main_body') table.add_style("margin: 10px 10px") table.add_col().set_attr('width','140') table.add_col().set_attr('width','400') table.add_row() table.add_header("Search Type: ").set_attr('align','left') table.add_cell(name_input) table.add_row() table.add_header("Title: ").set_attr('align','left') table.add_cell(title) table.add_row() table.add_header("Description: ").set_attr('align','left') table.add_cell(description) new_search_type_div.add(table) new_search_type_div.add_style("display: none") #widget.add(new_search_type_div) div = DivWdg() search_type_select = SearchTypeSelectWdg("search_type_filter", mode=SearchTypeSelectWdg.ALL) search_type_select.add_empty_option("-- Select --") if not search_type_select.get_value(): search_type_select.set_value(my.search_type) search_type_select.set_persist_on_submit() div.add(search_type_select) widget.add(div) search_type_select.add_behavior( {'type': 'change', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': bvr.src_el.value});" %(Common.get_full_class_name(my)) } ) if my.search_type: sobj = None try: sobj = SObjectFactory.create(my.search_type) except ImportError: widget.add(HtmlElement.br()) widget.add(SpanWdg('WARNING: Import Error encountered. Please choose another search type.', css='warning')) return widget required_columns = sobj.get_required_columns() if required_columns: widget.add(HtmlElement.br()) req_span = SpanWdg("Required Columns: ", css='med') req_span.add_color('color','color') widget.add(req_span) #required_columns = ['n/a'] req_span.add(', '.join(required_columns)) widget.add( HtmlElement.br() ) if my.file_path: hidden = HiddenWdg("file_path", my.file_path) widget.add(hidden) if my.web_url: file_span = FloatDivWdg('URL: <i>%s</i> ' %my.web_url, css='med') else: file_span = FloatDivWdg('File uploaded: <i>%s</i> ' %os.path.basename(my.file_path), css='med') file_span.add_color('color','color') file_span.add_style('margin: 8px 0 0 10px') file_span.add_style('font-size: 14px') widget.add(file_span) button = ActionButtonWdg(title='Change') button.add_style('float','left') button.add_behavior( {'type': 'click_up', \ 'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\ 'search_type_filter': '%s'});" %(Common.get_full_class_name(my), my.search_type) } ) widget.add(button) widget.add("<br clear='all'/>") widget.add(HtmlElement.br()) return widget widget.add("<br/>") widget.add_style("overflow-y: auto") msg = DivWdg() widget.add(msg) msg.add( "<div style='float: left; padding-left: 100px; padding-top: 6px'><b>Upload a csv file: </b></div>") msg.add_border() msg.add_style("width: 400px") msg.add_color("background", "background3") msg.add_style("padding: 20px") msg.add_style("margin: 30 auto") msg.add_style("text-align: center") ticket = Environment.get_security().get_ticket_key() on_complete = '''var server = TacticServerStub.get(); var file = spt.html5upload.get_file(); if (file) { var file_name = file.name; // clean up the file name the way it is done in the server //file_name = spt.path.get_filesystem_name(file_name); var server = TacticServerStub.get(); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; values['html5_ticket'] = '%s'; try { var info = spt.panel.load('csv_import_main', class_name, {}, values); spt.app_busy.hide(); } catch(e) { spt.alert(spt.exception.handler(e)); } } else { alert('Error: file object cannot be found.') } spt.app_busy.hide();'''%ticket from tactic.ui.input import UploadButtonWdg browse = UploadButtonWdg(name='new_csv_upload', title="Browse", tip="Click to choose a csv file",\ on_complete=on_complete, ticket=ticket) browse.add_style('float: left') msg.add(browse) # this is now only used in the copy and paste Upload button for backward-compatibility upload_wdg = SimpleUploadWdg(key=key, show_upload=False) upload_wdg.add_style('display: none') msg.add(upload_wdg) #widget.add(span) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Published URL: </b>") text = TextWdg("web_url") msg.add(text) msg.add("<br/><br/>-- OR --</br/><br/>") msg.add("<b>Copy and Paste from a Spreadsheet: </b>") text = TextAreaWdg("data") text.add_style('width: 33em') text.add_class("spt_import_cut_paste") msg.add(text) button = ActionButtonWdg(title="Parse") button.add_style("margin: 5px auto") msg.add(button) button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_import_top"); var el = top.getElement(".spt_import_cut_paste"); var applet = spt.Applet.get(); var value = el.value; var csv = []; // convert to a csv file! lines = value.split("\\n"); for (var i = 0; i < lines.length; i++) { if (lines[i] == '') { continue; } var parts = lines[i].split("\\t"); var new_line = []; for (var j = 0; j < parts.length; j++) { if (parts[j] == '') { new_line.push(''); } else { new_line.push('"'+parts[j]+'"'); } } new_line = new_line.join(","); csv.push(new_line); } csv = csv.join("\\n") // FIXME: need to get a local temp directory var path = spt.browser.os_is_Windows() ? "C:/sthpw/copy_n_paste.csv" : "/tmp/sthpw/copy_n_paste.csv"; applet.create_file(path, csv); // upload the file applet.upload_file(path) applet.rmtree(path); var top = bvr.src_el.getParent(".spt_import_csv"); var hidden = top.getElement(".spt_upload_hidden"); hidden.value = path; var file_name = spt.path.get_basename(hidden.value); file_name = spt.path.get_filesystem_name(file_name); var class_name = 'tactic.ui.widget.CsvImportWdg'; var values = spt.api.Utility.get_input_values('csv_import_main'); values['is_refresh'] = true; values['file_name'] = file_name; var info = spt.panel.load('csv_import_main', class_name, {}, values); ''' } ) return widget