def add_internal_config(cls, configs, views): '''add an internal config based on project base type''' project = Project.get() project_type = project.get_base_type() # catch potential invalid xpath error try: if project_type: tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path="%s/../config/%s-conf.xml" % (dir_name, project_type) if os.path.exists(file_path): for view in views: config = WidgetConfig.get(file_path=file_path, view=view) if config.get_view_node(): configs.append(config) # finally, just look at the DEFAULT config tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path="%s/../config/%s-conf.xml" % (dir_name, "DEFAULT") if os.path.exists(file_path): for view in views: config = WidgetConfig.get(file_path=file_path, view=view) if config.get_view_node(): configs.append(config) except XmlException, e: msg = "Error with view [%s]"% ' '.join(views) error_list = Container.get_seq(cls.ERR_MSG) if msg not in error_list: Container.append_seq(cls.ERR_MSG, msg) print e.__str__()
def get_config(my): config = None config_xml = my.kwargs.get("config_xml") if config_xml: config = WidgetConfig.get(xml=config_xml, view=my.view) return config # this is the new preferred way of defining CustomLayoutWdg search = Search("config/widget_config") if my.category: search.add_filter("category", my.category) else: search.add_filter("category", "CustomLayoutWdg") if my.search_type: search.add_filter("search_type", my.search_type) search.add_filter("view", my.view) config = search.get_sobject() if config: return config # if it is not defined in the database, look at a config file includes = my.kwargs.get("include") if includes: includes = includes.split("|") for include in includes: tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path = "%s/../config/%s" % (dir_name, include) config = WidgetConfig.get(file_path=file_path, view=my.view) if config and config.has_view(my.view): return config # deprecated approach, assuming a "CustomLayoutWdg" as search_type, # is deprecated if not config: search = Search("config/widget_config") if my.category: search.add_filter("category", my.category) if my.search_type: search.add_filter("search_type", "CustomLayoutWdg") search.add_filter("view", my.view) config = search.get_sobject() # if not config and my.search_type and my.view: # config = WidgetConfigView.get_by_search_type(my.search_type, my.view) # this is the new preferred way of defining CustomLayoutWdg # NOTE: this finds a definition where search type is not explicitly # given> if not config: search = Search("config/widget_config") search.add_filter("view", my.view) search.add_filter("search_type", None) config = search.get_sobject() return config
def get_def_config(my, def_xml=None): def_confg = None my.def_view = my.kwargs.get('definition') if my.def_view: #raise TacticException("No definition view defined in custom layout with view [%s]" % my.view) my.search_type = "CustomLayoutWdg" search = Search("config/widget_config") search.add_filter("search_type", my.search_type) search.add_filter("view", my.def_view) def_db_config = search.get_sobject() if not def_db_config: raise TacticException("Definition config [%s] not defined" % my.def_view) def_xml = def_db_config.get_xml() def_config = WidgetConfig.get("definition", xml=def_xml) # also look inline to see if there are any definitions if def_xml: # just use the passed in xml for a definition def_config = WidgetConfig.get(my.view, xml=def_xml) return def_config
def init(my): """initialize the widget_config, and from there retrieve the schema_config""" web = WebContainer.get_web() my.search_type = my.kwargs.get("search_type") element_name = my.kwargs.get("element_name") my.view = my.kwargs.get("view") # FIXME: comment out the assert for now to avoid error screen if not my.view: my.view = "table" # assert my.view my.config_xml = my.kwargs.get("config_xml") if not my.config_xml: my.config_xml = web.get_form_value("config_xml") my.default = my.kwargs.get("default") == "True" cbk = ManageSearchTypeDetailCbk(search_type=my.search_type, view=my.view, element_name=element_name) Command.execute_cmd(cbk) my.config_string = "" my.data_type_string = "" my.name_string = "" my.title_string = "" my.nullable_string = "" my.has_column = True if element_name: if my.config_xml: my.config_string = my.config_xml whole_config_string = "<config><%s>%s</%s></config>" % (my.view, my.config_xml, my.view) config = WidgetConfig.get(xml=whole_config_string, view=my.view) my.config = WidgetConfigView(my.search_type, my.view, [config]) else: # don't pass in default here my.config = my.get_config(my.search_type, my.view) node = my.config.get_element_node(element_name) if node is not None: config_xml = my.config.get_xml() my.config_string = config_xml.to_string(node) my.title_string = config_xml.get_attribute(node, "title") schema_config = SearchType.get_schema_config(my.search_type) attributes = schema_config.get_element_attributes(element_name) my.data_type_string = attributes.get("data_type") # double_precision is float if my.data_type_string == "double precision": my.data_type_string = "float" my.name_string = attributes.get("name") my.nullable_string = attributes.get("nullable") my.is_new_column = attributes.get("new") == "True" # a database columnless widget if not my.name_string: my.has_column = False
def get_async_element_wdg(my, xml, element_name, load): tmp_config = WidgetConfig.get("tmp", xml=xml) display_handler = tmp_config.get_display_handler(element_name) display_options = tmp_config.get_display_options(element_name) div = DivWdg() unique_id = div.set_unique_id() if load == "sequence": my.sequence_data.append({"class_name": display_handler, "kwargs": display_options, "unique_id": unique_id}) else: div.add_behavior( { "type": "load", "class_name": display_handler, "kwargs": display_options, "cbjs_action": """ spt.panel.async_load(bvr.src_el, bvr.class_name, bvr.kwargs); """, } ) loading_div = DivWdg() loading_div.add_style("margin: auto auto") loading_div.add_style("width: 150px") loading_div.add_style("text-align: center") loading_div.add_style("padding: 20px") div.add(loading_div) loading_div.add("""<img src="/context/icons/common/indicator_snake.gif" border="0"/> <b>Loading ...</b>""") return div
def _get_template_config(self): base_dir = Environment.get_install_dir() file_path="%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir if os.path.exists(file_path): widget_config = WidgetConfig.get(file_path=file_path, view='template') return widget_config
def _get_main_config(self, view, process_names): '''get the main config for this table layout''' xml = Xml() xml.create_doc("config") root = xml.get_root_node() view_node = xml.create_element(view) #root.appendChild(view_node) xml.append_child(root, view_node) for idx, process_name in enumerate(process_names): element = xml.create_element('element') Xml.set_attribute(element, 'name', process_name) #view_node.appendChild(element) xml.append_child(view_node, element) display = xml.create_element('display') if self.element_class: Xml.set_attribute(display, 'class',self.element_class) else: Xml.set_attribute(display, 'class', "tactic.ui.app.NoteTableElementWdg") #element.appendChild(display) xml.append_child(element, display) op_element = xml.create_data_element('parent_key', self.search_key) xml.append_child(display, op_element) config_xml = xml.to_string() widget_config = WidgetConfig.get(view=view, xml = config_xml) widget_config_view = WidgetConfigView('sthpw/note', view, [widget_config]) return widget_config_view
def get_folder_wdg(my, element_name, config, options, base_path, current_path, info, personal, use_same_config): li = HtmlElement.li() li.add_class("spt_side_bar_link") li.add_class("main_li") title = my._get_title(config, element_name) title_wdg = DivWdg() title_wdg.add_class("menu_header") li.add(title_wdg) title_wdg.add(title) ul = HtmlElement.ul() li.add(ul) ul.add_class("spt_side_bar_section") ul.add_class("sub_ul") # then get view name from options in order to read a new # config and recurse ... options_view_name = options.get('view') if options_view_name: if use_same_config: xml = config.get_xml() sub_config = WidgetConfig.get(xml=xml) sub_config.set_view(options_view_name) else: sub_config = my.get_config( my.config_search_type, options_view_name, default=my.default, personal=personal) info['level'] += 1 my.generate_section( sub_config, ul, info, base_path=current_path, personal=personal, use_same_config=use_same_config ) info['level'] -= 1 return li
def get_async_element_wdg(my, xml, element_name, load): tmp_config = WidgetConfig.get('tmp', xml=xml) display_handler = tmp_config.get_display_handler(element_name) display_options = tmp_config.get_display_options(element_name) div = DivWdg() unique_id = div.set_unique_id() if load == "sequence": my.sequence_data.append( { 'class_name': display_handler, 'kwargs': display_options, 'unique_id': unique_id } ) else: div.add_behavior( { 'type': 'load', 'class_name': display_handler, 'kwargs': display_options, 'cbjs_action': ''' spt.panel.async_load(bvr.src_el, bvr.class_name, bvr.kwargs); ''' } ) loading_div = DivWdg() loading_div.add_style("margin: auto auto") loading_div.add_style("width: 150px") loading_div.add_style("text-align: center") loading_div.add_style("padding: 20px") div.add(loading_div) loading_div.add('''<img src="/context/icons/common/indicator_snake.gif" border="0"/> <b>Loading ...</b>''') return div
def get_config(my): # TEST config_xml = ''' <config> <custom_filter> <element name='asset_library'> <display class='SelectWdg'> <query>prod/asset_library|code|code</query> <empty>true</empty> </display> </element> <element name='pipeline_code'> <display class='SelectWdg'> <query>sthpw/pipeline|code|code</query> <empty>true</empty> </display> </element> </custom_filter> </config> ''' my.view = my.kwargs.get("search_view") if not my.view: my.view = 'custom_filter' #view = "custom_filter" project_code = Project.extract_project_code(my.search_type) search = Search("config/widget_config", project_code=project_code ) search.add_filter("view", my.view) search.add_filter("search_type", my.base_search_type) config_sobj = search.get_sobject() if config_sobj: config_xml = config_sobj.get_value("config") else: config_xml = ''' <config> <custom_filter> </custom_filter> </config> ''' # use the one defined in the default config file file_configs = WidgetConfigView.get_configs_from_file(my.base_search_type, my.view) if file_configs: config = file_configs[0] xml_node = config.get_view_node() if xml_node is not None: xml = Xml(config.get_xml().to_string()) config_xml = '<config>%s</config>' %xml.to_string(node=xml_node) from pyasm.widget import WidgetConfig config = WidgetConfig.get(view=my.view, xml=config_xml) return config
def get_config(self): self.view = self.kwargs.get("search_view") config = self.kwargs.get("search_config") if not self.view: self.view = 'custom_filter' #view = "custom_filter" project_code = Project.extract_project_code(self.search_type) search = Search("config/widget_config", project_code=project_code ) search.add_filter("view", self.view) search.add_filter("search_type", self.base_search_type) config_sobjs = search.get_sobjects() from pyasm.search import WidgetDbConfig config_sobj = WidgetDbConfig.merge_configs(config_sobjs) if config_sobj: #config_xml = config_sobj.get("config") config_xml = config_sobj.get_xml().to_string() config_xml = config_xml.replace("<", "<") config_xml = config_xml.replace(">", ">") config_xml = Common.run_mako(config_xml) elif config: config_xml = ''' <config> <custom_filter>%s </custom_filter> </config> ''' % config else: config_xml = ''' <config> <custom_filter> </custom_filter> </config> ''' # use the one defined in the default config file file_configs = WidgetConfigView.get_configs_from_file(self.base_search_type, self.view) if file_configs: config = file_configs[0] xml_node = config.get_view_node() if xml_node is not None: xml = Xml(config.get_xml().to_string()) config_xml = '<config>%s</config>' %xml.to_string(node=xml_node) from pyasm.widget import WidgetConfig config = WidgetConfig.get(view=self.view, xml=config_xml) return config
def get_config(my): my.view = my.kwargs.get("view") search = Search("config/widget_config") search.add_filter("category", "TabWdg") config_sobj = search.get_sobject() config_xml = config_sobj.get_value("config") config = WidgetConfig.get(view=my.view, xml=config_xml) return config
def get_last_filter_config(search_type): # get the last search view = "saved_search:%s" % search_type search = Search('config/widget_config') search.add_filter("view", view) search.add_filter("search_type", search_type) search.add_user_filter() config_sobj = search.get_sobject() config = None if config_sobj: config_xml = config_sobj.get_xml_value("config") config = WidgetConfig.get(xml=config_xml, view='filter') return config
def get_default_filter_config(my): custom_filter_view = my.kwargs.get('custom_filter_view') config = ''' <config> <filter> <element name='Filter'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>%(prefix_namespace)s_main_body</prefix> <search_type>%(search_type)s</search_type> <mode>sobject</mode> </display> </element> </filter> </config> ''' % {'search_type': my.searchable_search_type, 'prefix_namespace': my.prefix_namespace } config_xml = Xml() config_xml.read_string(config) config = WidgetConfig.get(xml=config_xml, view='filter') return config
def get_config(my): my.view = my.kwargs.get("view") my.view = 'tab_config_whatever' search = Search("config/widget_config") search.add_filter("category", "TabWdg") config_sobj = search.get_sobject() if config_sobj: config_xml = config_sobj.get_value("config") else: config_xml = ''' <config> <tab> </tab> </config>''' config = WidgetConfig.get(view=my.view, xml=config_xml) return config
def get_folder_wdg(self, element_name, config, options, base_path, current_path, info, personal, use_same_config): attributes = config.get_element_attributes(element_name) if attributes.get("is_visible") == "false": return li = HtmlElement.li() li.add_class("spt_side_bar_link") li.add_class("main_li unselectable") title = self._get_title(config, element_name) title_wdg = DivWdg() title_wdg.add_class("menu_header") li.add(title_wdg) title_wdg.add(title) ul = HtmlElement.ul() li.add(ul) ul.add_class("spt_side_bar_section") ul.add_class("sub_ul unselectable") ul.add_style('cursor','pointer') # then get view name from options in order to read a new # config and recurse ... options_view_name = options.get('view') if options_view_name: if use_same_config: xml = config.get_xml() sub_config = WidgetConfig.get(xml=xml) sub_config.set_view(options_view_name) else: sub_config = self.get_config( self.config_search_type, options_view_name, default=self.default, personal=personal) info['level'] += 1 self.generate_section( sub_config, ul, info, base_path=current_path, personal=personal, use_same_config=use_same_config ) info['level'] -= 1 return li
def check(my): my.web = WebContainer.get_web() search_type = my.sobject.get_search_type_obj() config = WidgetConfig.get_by_search_type(search_type, "insert", local_search=True) columns = config.get_element_names() if len(columns) != 3: raise TacticException('The command is expecting 3 fields only.') my.date = my.web.get_form_value('edit|%s' % columns[0]) my.desc = my.web.get_form_value('edit|%s'% columns[1]) date = Date(db_date=my.date) my.year = date.get_year() my.week = date.get_week() my.project_code = my.web.get_form_value('edit|%s'% columns[2]) if not my.desc or not my.date or not my.project_code: raise UserException('One or more fields are empty.') Project.set_project(my.project_code) return True
def _get_edit_config(self, view, process_names): xml = Xml() xml.create_doc("config") root = xml.get_root_node() view_node = xml.create_element(view) #root.appendChild(view_node) xml.append_child(root, view_node) for idx, process_name in enumerate(process_names): element = xml.create_element('element') Xml.set_attribute(element, 'name', process_name) #view_node.appendChild(element) xml.append_child(view_node, element) display = xml.create_element('display') Xml.set_attribute(display, 'class', "pyasm.widget.TextAreaWdg") #element.appendChild(display) xml.append_child(element, display) config_xml = xml.to_string() widget_config = WidgetConfig.get(view=view, xml = config_xml) widget_config_view = WidgetConfigView('sthpw/note', view, [widget_config]) return widget_config_view
def get_display(my): my.search_type = None my.view = 'tab' config_xml = my.get_config_xml() config = WidgetConfig.get(view=my.view, xml=config_xml) top = DivWdg() #tab = TabWdg(width=1000, save_state="admin_tab_state") tab = TabWdg(config=config, view=my.view, width=1000) top.add(tab) for widget in my.widgets: tab.add(widget) # set the current one active div = DivWdg() div.add_style("display: hidden") div.add_behavior( { 'type': 'load', 'cbjs_action': ''' spt.tab.set_main_body_top(); var headers = spt.tab.get_headers(); // if there are no headers, then there was an error if (headers.length == 0) { return; } var name = headers[headers.length-1].getAttribute("spt_element_name"); spt.tab.select(name); ''' } ) top.add(div) return top
def execute(my): sobject = my.sobject search_type = sobject.get_search_type_obj() config = WidgetConfigView.get_by_search_type(search_type, "custom") if not config: return my.element_names = config.get_element_names() # create all of the handlers action_handlers = [] for element_name in (my.element_names): action_handler_class = \ config.get_action_handler(element_name) if action_handler_class == "": action_handler_class = "DatabaseAction" action_handler = WidgetConfig.create_widget( action_handler_class ) action_handler.set_name(element_name) action_handler.set_input_prefix("edit") action_options = config.get_action_options(element_name) for key, value in action_options.items(): action_handler.set_option(key, value) action_handlers.append(action_handler) # set the sobject for each action handler for action_handler in action_handlers: action_handler.set_sobject(sobject) if action_handler.check(): action_handler.execute()
def get_display(self): category = 'SerializeWdg' view = '123COW' sobjects = Search.eval("@SOBJECT(prod/asset)") element_names = ['preview', 'code', 'task_status'] serializer = SObjectSerializer() serialized = serializer.create_config_xml("prod/asset", sobjects, element_names) search = Search("config/widget_config") search.add_filter("category", category) search.add_filter("view", view) config_sobj = search.get_sobject() serialized = config_sobj.get_xml_value("config") sobject_str = serialized.get_value("config/custom/element/display/sobjects") sobjects = serializer.loads("prod/asset", sobject_str) print sobjects top = DivWdg() self.set_as_panel(top) print top.attrs from pyasm.widget import WidgetConfig config = WidgetConfig.get(view='custom', xml=serialized) widget = config.get_display_widget("custom") widget.set_sobjects(sobjects[1:3]) top.add(widget) return top
def get_config(my): config = None config_xml = my.kwargs.get('config_xml') if config_xml: config = WidgetConfig.get(xml=config_xml, view=my.view) return config # this is the new preferred way of defining CustomLayoutWdg search = Search("config/widget_config") if my.category: search.add_filter("category", my.category) else: search.add_filter("category", 'CustomLayoutWdg') if my.search_type: search.add_filter("search_type", my.search_type) search.add_filter("view", my.view) config = search.get_sobject() if config: return config # if it is not defined in the database, look at a config file includes = my.kwargs.get("include") if includes: includes = includes.split("|") for include in includes: tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path="%s/../config/%s" % (dir_name, include) config = WidgetConfig.get(file_path=file_path, view=my.view) if config and config.has_view(my.view): return config # deprecated approach, assuming a "CustomLayoutWdg" as search_type, # is deprecated if not config: search = Search("config/widget_config") if my.category: search.add_filter("category", my.category) if my.search_type: search.add_filter("search_type", "CustomLayoutWdg") search.add_filter("view", my.view) config = search.get_sobject() #if not config and my.search_type and my.view: # config = WidgetConfigView.get_by_search_type(my.search_type, my.view) # this is the new preferred way of defining CustomLayoutWdg # NOTE: this finds a definition where search type is not explicitly # given> if not config: search = Search("config/widget_config") search.add_filter("view", my.view) search.add_filter("search_type", None) config = search.get_sobject() return config
def get_display(self): is_admin_project = Project.get().is_admin() security = Environment.get_security() if is_admin_project and not security.check_access( "builtin", "view_site_admin", "allow"): return Error403Wdg() # create the elements config = WidgetConfig.get(xml=self.config_xml, view="application") left_nav_handler = config.get_display_handler("left_nav") left_nav_options = config.get_display_options("left_nav") view_side_bar = None if left_nav_handler: left_nav_wdg = Common.create_from_class_path( left_nav_handler, [], left_nav_options) # caching side_bar_cache = self.get_side_bar_cache(left_nav_wdg) else: view_side_bar = False # create the main table core_table = Table() core_table.add_tbody() core_table.set_style( "border: 0px; border-collapse: collapse; width: 100%;") # add a spacer row #spacer_tr = core_table.add_row() #spacer_tr.add_style("width: 100%") #td = core_table.add_cell() #td.set_style("min-height: 1px; height: 1px;") #core_table.add_cell() #core_table.add_cell() # determine if the side bar is visible if view_side_bar == None: view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow') # add the main cells tr, td = core_table.add_row_cell() td.add_style("padding: 0px") td.add_style("margin: 0px") # add the main resizable table from tactic.ui.container import ResizableTableWdg main_table = ResizableTableWdg() main_table.set_keep_table_size() main_table.add_style("width: 100%") td.add(main_table) left_nav_td = main_table.add_cell() if view_side_bar: left_nav_td.add_class("spt_panel") left_nav_td.add_style("padding: 0px") main_body_td = main_table.add_cell(resize=False) main_body_td.add_style("padding: 10px") main_body_td.set_style( "width: 100%; vertical-align: top; text-align: center; padding-top: 3px" ) if view_side_bar: left_nav_td.set_style("vertical-align: top") # create the left navigation panel left_nav_div = DivWdg() left_nav_td.add(left_nav_div) left_nav_div.set_id("side_bar") # add the detail to the panel left_nav_div.add_attr("spt_class_name", left_nav_handler) for name, value in left_nav_options.items(): left_nav_div.add_attr("spt_%s" % name, value) left_nav_div.add_style("max_width: 185px") left_nav_div.add_style("width: 185px") left_nav_div.add_style("text-align: right") left_nav_div.add_style("vertical-align: top") left_nav_div.add_style("overflow: hidden") left_nav_div.add_class("spt_resizable") side_bar_inner = DivWdg() left_nav_div.add(side_bar_inner) #side_bar_inner.add_style("padding-left: 1px") side_bar_inner.add_style("width: 100%") # add side bar to nav side_bar_inner.add(side_bar_cache) left_nav_div.add_style("border-style: solid") left_nav_div.add_style("border-width: 0px 1px 0px 0px") #left_nav_div.add_color("border-color", "border") left_nav_div.add_color("border-color", "border", -10) web = WebContainer.get_web() browser = web.get_browser() if browser in ['Qt', 'Webkit']: min_width = "1px" else: min_width = "0px" left_nav_div.add_behavior({ 'type': 'listen', 'event_name': 'side_bar|hide_now', 'min_width': min_width, 'cbjs_action': ''' var size = bvr.src_el.getSize(); bvr.src_el.setAttribute("spt_size", size.x); bvr.src_el.setStyle("width", bvr.min_width); ''' }) left_nav_div.add_behavior({ 'type': 'listen', 'event_name': 'side_bar|hide', 'min_width': min_width, 'cbjs_action': ''' var size = bvr.src_el.getSize(); bvr.src_el.setAttribute("spt_size", size.x); new Fx.Tween(bvr.src_el, {duration:'short'}).start('width', bvr.min_width); ''' }) left_nav_div.add_behavior({ 'type': 'listen', 'event_name': 'side_bar|show', 'min_width': min_width, 'cbjs_action': ''' var width = bvr.src_el.getAttribute("spt_size"); if (!width) { width = 185; } if (parseInt(width) < 5) { width = 185; } //bvr.src_el.setStyle("width", width + "px"); new Fx.Tween(bvr.src_el, {duration:'short'}).start('width', bvr.min_width, width+"px"); ''' }) left_nav_div.add_behavior({ 'type': 'listen', 'event_name': 'side_bar|toggle', 'cbjs_action': ''' var size = bvr.src_el.getSize(); if (size.x < 5) { spt.named_events.fire_event("side_bar|show", {} ); } else { spt.named_events.fire_event("side_bar|hide", {} ); } ''' }) # create the main body panel palette = WebContainer.get_palette() color = palette.color("background2") main_body_rounded = DivWdg() main_body_inner = main_body_rounded main_body_inner.add_style("min-height: 500px") # DEBREACATED """ # add a breadcrumb breadcrumb_wdg = DivWdg() # hide the breadcrumb breadcrumb_wdg.add_style("display", "none") Container.put("breadcrumb", breadcrumb_wdg) breadcrumb_wdg.set_id("breadcrumb") breadcrumb_wdg.add_style("text-align: left") breadcrumb_wdg.add_looks( "fnt_title_3" ) main_body_inner.add(breadcrumb_wdg) """ main_body_panel = DivWdg() main_body_panel.set_id("main_body") main_body_panel.add_class("spt_main_panel") main_body_inner.add(main_body_panel) tab = MainBodyTabWdg() main_body_panel.add(tab) # TEST: NEW LAYOUT if Config.get_value("install", "layout") == "fixed": main_body_panel.add_style("margin-top: 31px") main_body_rounded.add_color("background", "background") main_body_rounded.add_style("padding: 3px 0px 0px 0px") # add the content to the main body panel try: if self.widget: tab.add(self.widget) element_name = self.widget.get_name() else: main_body_handler = config.get_display_handler("main_body") main_body_options = config.get_display_options("main_body") element_name = main_body_options.get("element_name") title = main_body_options.get("title") main_body_content = Common.create_from_class_path( main_body_handler, [], main_body_options) # get the web values from top_layout main_body_values = config.get_web_options("main_body") web = WebContainer.get_web() if isinstance(main_body_values, dict): for name, value in main_body_values.items(): web.set_form_value(name, value) main_body_content.set_name(element_name) tab.add(main_body_content, element_name, title) self.set_as_panel(main_body_panel, class_name=main_body_handler, kwargs=main_body_options) main_body_panel.add_behavior({ 'type': 'load', 'element_name': element_name, 'cbjs_action': ''' if (spt.help) spt.help.set_view(bvr.element_name); ''' }) except Exception as e: # handle an error in the drawing buffer = self.get_buffer_on_exception() error_wdg = self.handle_exception(e) main_body_content = DivWdg() main_body_content.add(error_wdg) main_body_content = main_body_content.get_buffer_display() tab.add(main_body_content, element_name, title) # add the main container container_div = DivWdg() container_div.set_style("width: 100%;") # NOTE: the td should not be the sliding element! So we create a div inside the TD to be the sliding element main_body_div = DivWdg() main_body_div.set_id("horizontal_main_body_slider") main_body_div.add(main_body_inner) """ # get the global drag_ghost_div drag_ghost_div = self.get_drag_ghost_div() drag_ghost_div.set_id( "drag_ghost_copy" ) drag_ghost_div.add_class( "SPT_PUW" ) # make it a Page Utility Widget (now processed client side) drag_ghost_div.set_z_start( 400 ) """ from page_header_wdg import PageHeaderWdg header_panel = DivWdg() header_panel.set_id("main_header") header_panel.add_attr("spt_class_name", "tactic.ui.app.PageHeaderWdg") header_wdg = PageHeaderWdg() header_panel.add(header_wdg) container_div.add(header_panel.get_buffer_display()) main_body_dis = main_body_div.get_buffer_display() main_body_td.add(main_body_dis) container_div.add(core_table) #container_div.add( drag_ghost_div ) is_admin = False security = Environment.get_security() if security.check_access("builtin", "view_site_admin", "allow"): is_admin = True if is_admin: from quick_box_wdg import QuickBoxWdg quick_box = QuickBoxWdg() container_div.add(quick_box) container_div.add_behavior({ 'type': 'load', 'cbjs_action': ''' spt.named_events.fire_event("close_admin_bar"); ''' }) return container_div
def get_config(cls, config_search_type, view, default=False): config = None configs = [] login = None defined_view = view # this is really for the predefined view that shouldn't go to the db # otherwise, it is a never ending cycle. if default: views = [defined_view, 'definition'] cls.add_internal_config(configs, views) # special condition for children elif view in ['children']: tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path = "%s/../config/children-conf.xml" % (dir_name) config = WidgetConfig.get(file_path=file_path, view=defined_view) configs.append(config) elif view == "definition": # look for a definition in the database search = Search("config/widget_config") search.add_filter("search_type", config_search_type) search.add_filter("view", "definition") # lower the chance of getting some other definition files search.add_filter("login", None) config = search.get_sobject() if config: configs.append(config) # We should not allow redefinition of a predefined item # so it is fine to add internal config for definition # then look for a definition in the definition file cls.add_internal_config(configs, ['definition']) else: # first look in the database search = Search("config/widget_config") search.add_filter("search_type", config_search_type) search.add_filter("view", view) #search.add_filter("login", login) config = search.get_sobject() if config: configs.append(config) # then look for a file cls.add_internal_config(configs, [defined_view]) # look for a definition in the database search = Search("config/widget_config") search.add_filter("search_type", config_search_type) search.add_filter("view", "definition") # lower the chance of getting some other definition files search.add_filter("login", None) config = search.get_sobject() if config: configs.append(config) # then look for a definition in the definition file cls.add_internal_config(configs, ['definition']) widget_config_view = WidgetConfigView(config_search_type, view, configs) return widget_config_view
def get_display(my): category = "FreeformWdg" view = my.get_input_value("view") sobject = my.get_input_value("sobject") if not sobject and my.sobjects: sobject = my.sobjects[0] if not view: view = 'freeform' if sobject: search_key = sobject.get_search_key() search_type = sobject.get_base_search_type() else: search_key = my.get_input_value("search_key") search_type = my.get_input_value("search_type") if sobject: pass elif search_key: sobject = Search.get_by_search_key(search_key) elif search_type: search = Search(search_type) search.add_limit(1) sobject = search.get_sobject() else: sobject = None top = DivWdg() top.add_class("spt_freeform_top") search = Search("config/widget_config") search.add_filter("search_type", search_type) search.add_filter("view", view) config_sobj = search.get_sobject() if config_sobj: config_xml = config_sobj.get_value("config") else: config_xml = "" if not config_xml: top.add("No definition found") return top config = WidgetConfig.get(view=view, xml=config_xml) view_attrs = config.get_view_attributes() bgcolor = view_attrs.get("bgcolor") if not bgcolor: bgcolor = my.get_default_background() if bgcolor: top.add_style("background", bgcolor) # draw the layout freeform_layout = my.get_canvas_display(search_type, view, config, sobject) top.add(freeform_layout) return top
def get_display(my): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_color("background", "background") top.add_class("spt_reports_top") title = DivWdg() title.add("Dashboards") title.add_style("font-size: 18px") title.add_style("font-weight: bold") title.add_style("text-align: center") title.add_style("padding: 10px") title.add_style("margin: -10px -10px 10px -10px") title.add_gradient("background", "background3", 5, -10) top.add(title) from tactic.ui.widget import TitleWdg subtitle = TitleWdg(name_of_title='List of Dashboards', help_alias='project-startup-dashboards') top.add(subtitle) top.add("<br/>") dashboards = [] # read the config file from pyasm.widget import WidgetConfig tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path = "%s/../config/dashboard-conf.xml" % (dir_name) config = WidgetConfig.get(file_path=file_path, view="definition") element_names = config.get_element_names() for element_name in element_names: attrs = config.get_element_attributes(element_name) dashboard_data = {} kwargs = config.get_display_options(element_name) class_name = kwargs.get('class_name') dashboard_data['class_name'] = class_name dashboard_data['kwargs'] = kwargs dashboard_data['title'] = attrs.get("title") dashboard_data['description'] = attrs.get("description") dashboard_data['image'] = attrs.get("image") dashboard_data['image'] = attrs.get("image") dashboards.append(dashboard_data) # get all of the configs from the database search = Search("config/widget_config") search.add_filter("widget_type", "dashboard") db_configs = search.get_sobjects() for db_config in db_configs: dashboard_data = {} view = db_config.get_value("view") kwargs = {'view': view} parts = view.split(".") title = Common.get_display_title(parts[-1]) xml = db_config.get_value("config") dashboard_data['class_name'] = "tactic.ui.panel.CustomLayoutWdg" dashboard_data['kwargs'] = kwargs dashboard_data['title'] = title dashboard_data['description'] = title dashboard_data['image'] = None dashboard_data['xml'] = xml dashboard_data['widget_type'] = db_config.get_value("widget_type") dashboards.append(dashboard_data) # create a bunch of panels table = Table() top.add(table) table.add_color("color", "color") table.add_style("margin-bottom: 20px") table.center() for i, dashboard in enumerate(dashboards): if i == 0 or i % 4 == 0: tr = table.add_row() td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = dashboard description = dashboard.get("title") # Each node will contain a list of "items" and will be stored as a table in the database.''' class_name = dashboard.get("class_name") kwargs = dashboard.get("kwargs") title = dashboard.get("title") description = dashboard.get("description") xml = dashboard.get("xml") or "" image = dashboard.get("image") icon = dashboard.get("icon") if image: div = DivWdg() if isinstance(image, basestring): image = image.upper() image = eval("IconWdg('', IconWdg.%s)" % image) div.add_style("margin-left: 15px") div.add_style("margin-top: 5px") else: image = image div.add(image) image = div elif icon: icon = icon.upper() image = eval("IconWdg('', IconWdg.%s)" % icon) else: div = DivWdg() #image = IconWdg("Bar Chart", IconWdg.WARNING) image = IconWdg("Bar Chart", IconWdg.DASHBOARD_02) div.add_style("margin-left: 15px") div.add_style("margin-top: 5px") div.add(image) image = div behavior = { 'type': 'click_up', 'title': title, 'class_name': class_name, 'kwargs': kwargs, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_reports_top"); spt.tab.set_main_body_tab(); //spt.tab.set_tab_top(top); var kwargs = {}; spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs); ''' } schema_wdg = my.get_section_wdg(title, description, image, behavior) schema_wdg.add_behavior({ 'type': 'load', 'title': title, 'class_name': class_name, 'xml': xml, 'kwargs': kwargs, 'cbjs_action': ''' var report_top = bvr.src_el; report_top.kwargs = bvr.kwargs; report_top.class_name = bvr.class_name; report_top.element_name = bvr.title; report_top.xml = bvr.xml; ''' }) td.add(schema_wdg) #from tactic.ui.container import TabWdg #tab = TabWdg(show_add=False) #top.add(tab) return top
def get_display(my): if not my.search_type: return "No search type found" web = WebContainer.get_web() my.view = web.get_form_value("view") if not my.view: my.view = web.get_form_value("filter|view") if not my.view: my.view = get_template_view() widget = Widget() widget.add( HiddenWdg("search_type", my.search_type) ) element_names = [] # see if there is an override search_type_obj = SearchType.get(my.search_type) config = WidgetConfig.get_by_search_type(my.search_type,"browser_list") if config: element_names = config.get_element_names() search = Search("sthpw/widget_config") search.add_filter("search_type", my.search_type) search.add_filter("view", my.view) widget_config = search.get_sobject() if widget_config: edit_link_wdg = EditLinkWdg("sthpw/widget_config", widget_config.get_id(), text="Edit XML", long=True) edit_link_wdg.set_iframe_width(95) widget.add(edit_link_wdg) custom_config = WidgetConfigView.get_by_search_type(my.search_type,my.view) custom_element_names = custom_config.get_element_names() # get the custom properties search = Search("prod/custom_property") search.add_filter("search_type", my.search_type) custom_properties = search.get_sobjects() # action popup action_popup = PopupMenuWdg("table_action", multi=True, width='12em') action_popup.set_auto_hide(False) action_popup.set_submit(False) action_popup.add( HtmlElement.href("Add ...", "javascript:document.form.submit()") ) for custom_property in custom_properties: element_name = custom_property.get_name() if element_name not in custom_element_names: action_popup.add( " %s" % element_name, "add|%s" % element_name ) # if there is an override if element_names: for element_name in element_names: if element_name not in custom_element_names: action_popup.add( " %s" % element_name, "add|%s" % element_name ) # get all of the columns else: search_type_obj = SearchType.get(my.search_type) element_names = search_type_obj.get_columns() for element_name in element_names: if element_name not in custom_element_names: action_popup.add( " %s" % element_name, "add|%s" % element_name ) # add some standard properties if my.view in ["edit", "insert"]: for element_name in PREDEFINED_EDIT_ELEMENTS: if element_name not in custom_element_names: action_popup.add( " %s" % element_name, "add|%s" % element_name ) else: for element_name in PREDEFINED_ELEMENTS: if element_name not in custom_element_names: action_popup.add( " %s" % element_name, "add|%s" % element_name ) action_popup.add_separator() action_popup.add( HtmlElement.href("Remove ...", "javascript:document.form.submit()") ) for element_name in custom_element_names: action_popup.add( " %s" % element_name, "remove|%s" % element_name ) action_popup.add_separator() span = SpanWdg("New Custom ...", css="hand") iframe = WebContainer.get_iframe() url = WebContainer.get_web().get_widget_url() url.set_option("widget", "pyasm.widget.CustomAddPropertyWdg") url.set_option("search_type", my.search_type) url.set_option("view", my.view) action = iframe.get_on_script(url.to_string() ) span.add_event("onclick", action) action_popup.add( span ) # add the edit button edit = IconButtonWdg("Edit View", IconWdg.EDIT, True) edit.add_event("oncontextmenu", "%s;return false" % action_popup.get_on_script() ) edit.add_event("onclick", "%s" % action_popup.get_on_script() ) # lay it all out widget.add(SpanWdg(action_popup)) widget.add(edit) # add the edit button #save = IconButtonWdg("Save", IconWdg.SAVE, True) #widget.add(save) # add the add property button if my.mode == "admin": add = CustomAddPropertyLinkWdg(my.search_type, my.view) widget.add(add) #add_element = CustomAddElementLinkWdg(my.search_type, my.view) #widget.add(add_element) # add the clear button if my.mode == "admin" or my.view.startswith("custom_"): clear = IconSubmitWdg("Clear", IconWdg.DELETE, True) widget.add(clear) widget.add(SpanWdg(css="small")) WebContainer.register_cmd("pyasm.widget.CustomViewAction") return widget
def init(my): '''initialize the widget_config, and from there retrieve the schema_config''' web = WebContainer.get_web() my.search_type = my.kwargs.get('search_type') element_name = my.kwargs.get('element_name') my.view = my.kwargs.get('view') # FIXME: comment out the assert for now to avoid error screen if not my.view: my.view = 'table' #assert my.view my.config_xml = my.kwargs.get('config_xml') if not my.config_xml: my.config_xml = web.get_form_value('config_xml') my.default = my.kwargs.get('default') == 'True' cbk = ManageSearchTypeDetailCbk(search_type=my.search_type, view=my.view, \ element_name=element_name) Command.execute_cmd(cbk) my.config_string = "" my.data_type_string = "" my.name_string = "" my.title_string = "" my.nullable_string = "" my.has_column = True if element_name: if my.config_xml: my.config_string = my.config_xml whole_config_string = "<config><%s>%s</%s></config>" % ( my.view, my.config_xml, my.view) config = WidgetConfig.get(xml=whole_config_string, view=my.view) my.config = WidgetConfigView(my.search_type, my.view, [config]) else: # don't pass in default here my.config = my.get_config(my.search_type, my.view) node = my.config.get_element_node(element_name) if node is not None: config_xml = my.config.get_xml() my.config_string = config_xml.to_string(node) my.title_string = config_xml.get_attribute(node, 'title') schema_config = SearchType.get_schema_config(my.search_type) attributes = schema_config.get_element_attributes(element_name) my.data_type_string = attributes.get("data_type") # double_precision is float if my.data_type_string == 'double precision': my.data_type_string = 'float' my.name_string = attributes.get("name") my.nullable_string = attributes.get("nullable") my.is_new_column = attributes.get("new") == 'True' # a database columnless widget if not my.name_string: my.has_column = False
def get_display(self): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_gradient("background", "background", 0, -5) #top.add_style("height: 550px") top.add_class("spt_reports_top") self.set_as_panel(top) inner = DivWdg() top.add(inner) title = DivWdg() title.add("Reports") title.add_style("font-size: 18px") title.add_style("font-weight: bold") title.add_style("text-align: center") title.add_style("padding: 10px") title.add_style("margin: -10px -10px 0px -10px") inner.add(title) title.add_gradient("background", "background3", 5, -10) from tactic.ui.widget import TitleWdg subtitle = TitleWdg(name_of_title='List of Built in Reports', help_alias='main') inner.add(subtitle) inner.add("<br/>") button_div = DivWdg() inner.add(button_div) button_div.add_class("spt_buttons_top") button_div.add_style("margin-top: -5px") button_div.add_style("margin-bottom: 30px") button_div.add_border() button_div.add_style("margin-top: -15px") button_div.add_style("margin-bottom: 0px") button_div.add_style("width: 100%") button_div.add_style("height: 33px") button_div.add_color("background", "background2") button_div.add_style("margin-left: auto") button_div.add_style("margin-right: auto") button = SingleButtonWdg(title="Collapse", icon=IconWdg.HOME) button_div.add(button) button.add_style("float: left") button.add_style("left: 5px") button.add_style("top: 5px") # FIXME: get home for the user #home = 'tactic.ui.startup.ContentCreatorWdg' home = 'tactic.ui.startup.MainWdg' button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.startup.MainWdg'; var kwargs = { help_alias: 'main' }; spt.tab.add_new("_startup", "Startup", class_name, kwargs); ''' }) """ button = SingleButtonWdg(title="Collapse", icon=IconWdg.ARROW_UP) button_div.add(button) button.add_class("spt_collapse") inner.add(button_div) button.add_style("float: left") button.add_style("left: 5px") button.add_style("top: 5px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_reports_top"); var element = top.getElement(".spt_reports_list"); var buttons = bvr.src_el.getParent(".spt_buttons_top"); expand = buttons.getElement(".spt_expand"); new Fx.Tween(element).start('margin-top', "-400px"); expand.setStyle("display", ""); bvr.src_el.setStyle("display", "none"); ''' } ) button = SingleButtonWdg(title="Expand", icon=IconWdg.ARROW_DOWN) button.add_style("display: none") button.add_class("spt_expand") button_div.add(button) button.add_style("left: 5px") button.add_style("top: 5px") inner.add(button_div) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_reports_top"); var element = top.getElement(".spt_reports_list"); var buttons = bvr.src_el.getParent(".spt_buttons_top"); collapse = buttons.getElement(".spt_collapse"); new Fx.Tween(element).start('margin-top', "0px"); collapse.setStyle("display", ""); bvr.src_el.setStyle("display", "none"); ''' } ) """ reports = [] # read the config file from pyasm.widget import WidgetConfig tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path = "%s/../config/reports-conf.xml" % (dir_name) config = WidgetConfig.get(file_path=file_path, view="definition") category = self.kwargs.get('category') # get all of the configs from the database if not category or category in ["custom_reports", "custom_charts"]: search = Search("config/widget_config") search.add_op("begin") if category == "custom_reports": search.add_filter("widget_type", "report") elif category == "custom_charts": search.add_filter("widget_type", "chart") elif not category: search.add_filters("widget_type", ["chart", "report"]) search.add_op("or") db_configs = search.get_sobjects() else: db_configs = [] element_names = self.kwargs.get("element_names") if element_names is None: element_names = config.get_element_names() project = Project.get() for element_name in element_names: key = {'project': project.get_code(), 'element': element_name} key2 = {'project': project.get_code(), 'element': '*'} key3 = {'element': element_name} key4 = {'element': '*'} keys = [key, key2, key3, key4] if not top.check_access("link", keys, "view", default="deny"): continue attrs = config.get_element_attributes(element_name) report_data = {} kwargs = config.get_display_options(element_name) class_name = kwargs.get('class_name') # the straight xml definition contains the sidebar class_name # with LinkWdg ... we shouldn't use this, so build the # element from scratch #xml = config.get_element_xml(element_name) from pyasm.search import WidgetDbConfig xml = WidgetDbConfig.build_xml_definition(class_name, kwargs) report_data['class_name'] = class_name report_data['kwargs'] = kwargs report_data['title'] = attrs.get("title") report_data['description'] = attrs.get("description") report_data['image'] = attrs.get("image") report_data['xml'] = xml reports.append(report_data) for db_config in db_configs: element_name = db_config.get_value("view") key = {'project': project.get_code(), 'element': element_name} key2 = {'project': project.get_code(), 'element': '*'} key3 = {'element': element_name} key4 = {'element': '*'} keys = [key, key2, key3, key4] if not top.check_access("link", keys, "view", default="deny"): continue report_data = {} view = db_config.get_value("view") kwargs = {'view': view} parts = view.split(".") title = Common.get_display_title(parts[-1]) xml = db_config.get_value("config") report_data['class_name'] = "tactic.ui.panel.CustomLayoutWdg" report_data['kwargs'] = kwargs report_data['title'] = title report_data['description'] = title report_data['image'] = None report_data['xml'] = xml report_data['widget_type'] = db_config.get_value("widget_type") if report_data['widget_type'] == 'report': report_data['category'] = "custom_reports" elif report_data['widget_type'] == 'chart': report_data['category'] = "custom_charts" reports.append(report_data) """ report_data = { 'title': 'Tasks Completed This Week', 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'kwargs': { 'search_type': 'sthpw/task', 'view': 'table' }, } reports.append(report_data) """ if category == 'list_item_reports' or not category: search_types = Project.get().get_search_types() for search_type in search_types: base_key = search_type.get_base_key() key = {'project': project.get_code(), 'code': base_key} key2 = {'project': project.get_code(), 'code': '*'} key3 = {'code': base_key} key4 = {'code': '*'} keys = [key, key2, key3, key4] if not top.check_access( "search_type", keys, "view", default="deny"): continue if not SearchType.column_exists(base_key, "pipeline_code"): continue thumb_div = DivWdg() image = thumb_div thumb_div.add_border() thumb_div.set_box_shadow("1px 1px 1px 1px") thumb_div.add_style("width: 60px") thumb = ThumbWdg() thumb_div.add(thumb) thumb.set_sobject(search_type) thumb.set_icon_size(60) report_data = { 'title': '%s Workflow Status' % search_type.get_title(), 'description': 'Number of items in each process', 'class_name': 'tactic.ui.report.stype_report_wdg.STypeReportWdg', 'kwargs': { 'search_type': base_key }, 'image': thumb_div } reports.append(report_data) report_data = { 'title': '%s Labor Cost Report' % search_type.get_title(), 'description': 'Labor Cost Breakdown for each Item', 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'kwargs': { 'search_type': search_type.get_code(), 'view': "table", 'show_header': False, 'mode': 'simple', 'element_names': "preview,code,title,cost_breakdown,bid_hours,bid_cost,actual_hours,actual_cost,overbudget,variance" }, 'image': IconWdg("", IconWdg.REPORT_03) } reports.append(report_data) table2 = Table() inner.add(table2) table2.add_style("width: 100%") categories_div = DivWdg() td = table2.add_cell(categories_div) td.add_style("vertical-align: top") td.add_style("width: 200px") td.add_color("background", "background3") td.add_border() #categories_div.add_style("margin: -1px 0px 0px -1px") categories_div.add_style("padding-top: 10px") #categories_div.add_style("float: left") categories_div.add_color("color", "color3") categories = config.get_all_views() categories.insert(-1, "list_item_reports") categories.insert(-1, "custom_charts") categories.insert(-1, "custom_reports") table_div = DivWdg() td = table2.add_cell(table_div) td.add_style("vertical-align: top") table_div.add_class("spt_reports_list") table_div.add_border() table_div.add_color("background", "background", -5) table_div.add_style("min-height: 500px") for i, category in enumerate(categories): if i == len(categories) - 1: categories_div.add("<hr/>") config.set_view(category) element_names = config.get_element_names() if category == "definition": title = "All Reports" else: title = Common.get_display_title(category) category_div = DivWdg() categories_div.add(category_div) category_div.add(title) category_div.add_style("padding: 5px") category_div.add_class("hand") category_div.add_behavior({ 'type': 'click_up', 'category': category, 'element_names': element_names, 'class_name': Common.get_full_class_name(self), 'cbjs_action': ''' var kwargs = { is_refresh: true, category: bvr.category, element_names: bvr.element_names } //spt.panel.refresh(top, kwargs); var top = bvr.src_el.getParent(".spt_reports_top"); spt.panel.load(top, bvr.class_name, kwargs); ''' }) bgcolor = category_div.get_color("background3", -10) category_div.add_behavior({ 'type': 'mouseover', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.bgcolor); ''' }) category_div.add_behavior({ 'type': 'mouseout', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background", ""); ''' }) # create a bunch of panels table = Table() table_div.add(table) table.add_color("color", "color") table.add_style("margin-top: 20px") table.center() table_div.add_style("margin: -3px -3px -1px -2px") if not reports: tr = table.add_row() td = table.add_cell() td.add("There are no reports defined.") td.add_style("padding: 50px") if self.kwargs.get("is_refresh") in ['true', True]: return inner else: return top for i, report in enumerate(reports): #if i == 0 or i%4 == 0: if i % 3 == 0: tr = table.add_row() td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = report #description = '''The schema is used to layout the basic components of your project. Each component represents a list of items that you use in your business everyday.''' description = report.get("title") # Each node will contain a list of "items" and will be stored as a table in the database.''' class_name = report.get("class_name") kwargs = report.get("kwargs") title = report.get("title") description = report.get("description") widget_type = report.get("widget_type") image = report.get("image") icon = report.get("icon") xml = report.get("xml") if image: div = DivWdg() if isinstance(image, basestring): image = image.upper() image = eval("IconWdg('', IconWdg.%s)" % image) div.add_style("margin-left: 15px") div.add_style("margin-top: 5px") else: image = image div.add(image) image = div elif icon: icon = icon.upper() image = eval("IconWdg('', IconWdg.%s)" % icon) else: div = DivWdg() """ import random num = random.randint(0,3) if num == 1: image = IconWdg("Bar Chart", IconWdg.GRAPH_BAR_01) elif num == 2: image = IconWdg("Bar Chart", IconWdg.GRAPH_LINE_01) else: image = IconWdg("Bar Chart", IconWdg.GRAPH_BAR_02) """ if widget_type == "chart": image = IconWdg("Chart", IconWdg.GRAPH_BAR_02) else: image = IconWdg("No Image", IconWdg.WARNING) div.add_style("margin-left: 15px") div.add_style("margin-top: 5px") div.add(image) image = div behavior = { 'type': 'click_up', 'title': title, 'class_name': class_name, 'kwargs': kwargs, 'cbjs_action': ''' spt.tab.set_main_body_tab(); //var top = bvr.src_el.getParent(".spt_reports_top"); //spt.tab.set_tab_top(top); spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs); ''' } schema_wdg = self.get_section_wdg(title, description, image, behavior) schema_wdg.add_behavior({ 'type': 'load', 'title': title, 'class_name': class_name, 'xml': xml, 'kwargs': kwargs, 'cbjs_action': ''' var report_top = bvr.src_el; report_top.kwargs = bvr.kwargs; report_top.class_name = bvr.class_name; report_top.element_name = bvr.title; report_top.xml = bvr.xml; ''' }) td.add(schema_wdg) inner.add("<br/>") #from tactic.ui.container import TabWdg #tab = TabWdg(show_add=False) #inner.add(tab) if self.kwargs.get("is_refresh") in ['true', True]: return inner else: return top
class SearchWdg(BaseRefreshWdg): def get_args_keys(my): '''External settings which populate the widget. There are 3 ways to define which searches exist. 1) specify the filters, 2) specify the view, 3) specify whether to use the last saved search ''' return { 'search_type': 'The search_type that this search is operating on', 'display': 'Boolean. The initial display mode of the search. it is none by default', 'view': 'The stored view for the data. Saved Search', 'parent_key': 'Provides ability to search by a single parent key', #'popup_embedded': 'Boolean, if True then this widget is generated for a Popup window (so now open close)', 'filter': 'manaual data structure for filter', 'use_last_search': 'Boolean to determine if the last search is read or not', 'state': 'the surrounding state of the search', 'user_override': 'if True, current search data overrides what is in the search_view', 'limit': 'an overriding search limit. < 0 means no limit', 'run_search_bvr': 'Run Search behavior', 'custom_filter_view': 'Provide a custom filter area', 'custom_search_view': 'Provide a custom search view' } def get_default_filter_config(my): custom_filter_view = my.kwargs.get('custom_filter_view') if not custom_filter_view: custom_filter_view = '' config = [] config.append("<config>\n") config.append("<filter>\n") config.append(''' <element name='Combination'> <display class='tactic.ui.filter.SObjectSearchFilterWdg'> <search_type>%s</search_type> <prefix>quick</prefix> </display> </element> ''' % my.search_type) config.append(''' <element name='Custom'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>custom</prefix> <search_type>%s</search_type> <mode>custom</mode> <custom_filter_view>%s</custom_filter_view> </display> </element> ''' % (my.search_type, custom_filter_view)) config.append(''' <element name='Filter'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>main_body</prefix> <search_type>%s</search_type> <mode>sobject</mode> </display> </element> ''' % my.search_type) """ config.append(''' <element name='Filter2'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>filter2</prefix> <search_type>%s</search_type> <mode>sobject</mode> </display> </element> ''' % my.search_type) """ config.append(''' <element name='Parent'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>parent</prefix> <search_type>%s</search_type> <mode>parent</mode> </display> </element> ''' % my.search_type) config.append(''' <element name='Children'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>children</prefix> <search_type>%s</search_type> <mode>child</mode> </display> </element> ''' % my.search_type) """ config.append(''' <element name='Related'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>related</prefix> <search_type>%s</search_type> <mode>child</mode> </display> </element> ''' % my.search_type) """ config.append("</filter>\n") config.append("</config>\n") config = ''.join(config) config_xml = Xml() config_xml.read_string(config) config = WidgetConfig.get(xml=config_xml, view='filter') return config def get_num_filters_enabled(my): return my.num_filters_enabled def init(my): my.user_override = my.kwargs.get('user_override') in ['true', True] custom_search_view = my.kwargs.get('custom_search_view') if not custom_search_view or not custom_search_view.strip(): custom_search_view = 'search' # create a search for this search widget my.search_type = my.kwargs.get('search_type') my.search = Search(my.search_type) my.config = None # determine whether or not to use the last search. If any kind of # state has been set, then ignore the last_search my.use_last_search = True parent_key = my.kwargs.get('parent_key') state = my.kwargs.get('state') if parent_key or state or my.kwargs.get('use_last_search') == False: my.use_last_search = False my.prefix_namespace = my.kwargs.get('prefix_namespace') # NOTE: this is still hard coded my.prefix = 'main_body' # if we are asking for a specific saved search save = my.kwargs.get('save') my.view = my.kwargs.get('view') # get the config from a specific location # if the view is specified, use this view with the values # specified explicitly in this view my.config = None # see if a filter is explicitly passed in filter = my.kwargs.get('filter') my.limit = my.kwargs.get('limit') my.run_search_bvr = my.kwargs.get('run_search_bvr') # get from search view # filter can be either dict(data) or a list or # xml(filter wdg definition) if filter: if type(filter) == types.DictType: my.config = my.get_default_filter_config() filter_data = FilterData([filter]) filter_data.set_to_cgi() elif type(filter) == types.ListType: my.config = my.get_default_filter_config() filter_data = FilterData(filter) filter_data.set_to_cgi() else: try: filter_data = None # TODO: remove this. This is for backward compatibilty my.config = WidgetConfig.get(xml=filter, view='filter') filter_data = FilterData.get() if not filter_data.get_data(): # use widget settings key = SearchWdg._get_key(my.search_type, my.view) data = WidgetSettings.get_value_by_key(key) if data: filter_data = FilterData(data) filter_data.set_to_cgi() except XmlException, e: print "WARNING: non-xml filter detected!! %s" % filter # NOTE: this is only used to maintain backwards compatibility # plus it is needed for link_search: which contains the filter_config (old way of doing it) if not my.config: # and my.view: """ if ':' in my.view: # avoid view of a SearchWdg like link_search:<search_type>:<view> search_view = custom_search_view else: search_view = my.view """ search_view = custom_search_view config_view = WidgetConfigView.get_by_search_type(my.search_type, view=search_view) # get the my.config first for the display of SearchWdg # then get the filter data below if there is any if config_view.get_config().has_view(search_view): my.config = config_view.get_config() try: search = Search('config/widget_config') search.add_filter("view", my.view) search.add_filter("search_type", my.search_type) config_sobj = search.get_sobject() except SearchException, e: print "WARNING: ", e config_sobj = None if config_sobj: config_xml = config_sobj.get_xml_value("config") if not config_view.get_config().has_view(my.view): # make sure it does have the old way of storing filter # elements instead of just filter data if config_xml.get_nodes("config/filter/element"): my.config = WidgetConfig.get(xml=config_xml, view='filter') #my.config = my.get_default_filter_config() # set the form variables for the filters data = config_xml.get_value("config/filter/values") # link_search with specific search params takes precesdence # TODO: make a distinction between search definition and alter # search data provided by user if data and not my.user_override: filter_data = FilterData(data) filter_data.set_to_cgi() else: my.set_filter_data(my.search_type, my.view) else: if my.use_last_search: my.set_filter_data(my.search_type, my.view)
def init(my): my.user_override = my.kwargs.get('user_override') in ['true', True] custom_search_view = my.kwargs.get('custom_search_view') if not custom_search_view or not custom_search_view.strip(): custom_search_view = 'search' # create a search for this search widget my.search_type = my.kwargs.get('search_type') my.search = Search(my.search_type) my.config = None # determine whether or not to use the last search. If any kind of # state has been set, then ignore the last_search my.use_last_search = True parent_key = my.kwargs.get('parent_key') state = my.kwargs.get('state') if parent_key or state or my.kwargs.get('use_last_search') == False: my.use_last_search = False my.prefix_namespace = my.kwargs.get('prefix_namespace') # NOTE: this is still hard coded my.prefix = 'main_body' # if we are asking for a specific saved search save = my.kwargs.get('save') my.view = my.kwargs.get('view') # get the config from a specific location # if the view is specified, use this view with the values # specified explicitly in this view my.config = None # see if a filter is explicitly passed in filter = my.kwargs.get('filter') my.limit = my.kwargs.get('limit') my.run_search_bvr = my.kwargs.get('run_search_bvr') # get from search view # filter can be either dict(data) or a list or # xml(filter wdg definition) if filter: if type(filter) == types.DictType: my.config = my.get_default_filter_config() filter_data = FilterData([filter]) filter_data.set_to_cgi() elif type(filter) == types.ListType: my.config = my.get_default_filter_config() filter_data = FilterData(filter) filter_data.set_to_cgi() else: try: filter_data = None # TODO: remove this. This is for backward compatibilty my.config = WidgetConfig.get(xml=filter, view='filter') filter_data = FilterData.get() if not filter_data.get_data(): # use widget settings key = SearchWdg._get_key(my.search_type, my.view) data = WidgetSettings.get_value_by_key(key) if data: filter_data = FilterData(data) filter_data.set_to_cgi() except XmlException, e: print "WARNING: non-xml filter detected!! %s" % filter
def get_default_filter_config(my): custom_filter_view = my.kwargs.get('custom_filter_view') if not custom_filter_view: custom_filter_view = '' config = [] config.append("<config>\n") config.append("<filter>\n") config.append(''' <element name='Combination'> <display class='tactic.ui.filter.SObjectSearchFilterWdg'> <search_type>%s</search_type> <prefix>quick</prefix> </display> </element> ''' % my.search_type) config.append(''' <element name='Custom'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>custom</prefix> <search_type>%s</search_type> <mode>custom</mode> <custom_filter_view>%s</custom_filter_view> </display> </element> ''' % (my.search_type, custom_filter_view)) config.append(''' <element name='Filter'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>main_body</prefix> <search_type>%s</search_type> <mode>sobject</mode> </display> </element> ''' % my.search_type) """ config.append(''' <element name='Filter2'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>filter2</prefix> <search_type>%s</search_type> <mode>sobject</mode> </display> </element> ''' % my.search_type) """ config.append(''' <element name='Parent'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>parent</prefix> <search_type>%s</search_type> <mode>parent</mode> </display> </element> ''' % my.search_type) config.append(''' <element name='Children'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>children</prefix> <search_type>%s</search_type> <mode>child</mode> </display> </element> ''' % my.search_type) """ config.append(''' <element name='Related'> <display class='tactic.ui.filter.GeneralFilterWdg'> <prefix>related</prefix> <search_type>%s</search_type> <mode>child</mode> </display> </element> ''' % my.search_type) """ config.append("</filter>\n") config.append("</config>\n") config = ''.join(config) config_xml = Xml() config_xml.read_string(config) config = WidgetConfig.get(xml=config_xml, view='filter') return config
def init(self): self.user_override = self.kwargs.get('user_override') in ['true', True] custom_search_view = self.kwargs.get('custom_search_view') if not custom_search_view or not custom_search_view.strip(): custom_search_view = 'search' # create a search for this search widget self.search_type = self.kwargs.get('search_type') self.search = self.kwargs.get("search") if not self.search: self.search = Search(self.search_type) self.config = None # determine whether or not to use the last search. If any kind of # state has been set, then ignore the last_search self.use_last_search = True parent_key = self.kwargs.get('parent_key') state = self.kwargs.get('state') if parent_key or state or self.kwargs.get('use_last_search') in [False, 'false']: self.use_last_search = False self.prefix_namespace = self.kwargs.get('prefix_namespace') # NOTE: this is still hard coded self.prefix = 'main_body' # if we are asking for a specific saved search save = self.kwargs.get('save') self.view = self.kwargs.get('view') # get the config from a specific location # if the view is specified, use this view with the values # specified explicitly in this view self.config = None # see if a filter is explicitly passed in filter = self.kwargs.get('filter') self.limit = self.kwargs.get('limit') self.run_search_bvr = self.kwargs.get('run_search_bvr') # get from search view # filter can be either dict(data) or a list or # xml(filter wdg definition) if filter: if type(filter) == types.DictType: self.config = self.get_default_filter_config() filter_data = FilterData([filter]) filter_data.set_to_cgi() elif type(filter) == types.ListType: self.config = self.get_default_filter_config() filter_data = FilterData(filter) filter_data.set_to_cgi() else: try: filter_data = None # TODO: remove this. This is for backward compatibilty self.config = WidgetConfig.get(xml=filter, view='filter') filter_data = FilterData.get() if not filter_data.get_data(): # use widget settings key = SearchWdg._get_key(self.search_type, self.view) data = WidgetSettings.get_value_by_key(key) if data: filter_data = FilterData(data) filter_data.set_to_cgi() except XmlException as e: print("WARNING: non-xml filter detected!!") # NOTE: this is only used to maintain backwards compatibility # plus it is needed for link_search: which contains the filter_config (old way of doing it) if not self.config:# and self.view: """ if ':' in self.view: # avoid view of a SearchWdg like link_search:<search_type>:<view> search_view = custom_search_view else: search_view = self.view """ search_view = custom_search_view config_view = WidgetConfigView.get_by_search_type(self.search_type, view=search_view) # get the self.config first for the display of SearchWdg # then get the filter data below if there is any if config_view.get_config().has_view(search_view): self.config = config_view.get_config() try: search = Search('config/widget_config') search.add_filter("view", self.view) search.add_filter("search_type", self.search_type) config_sobjs = search.get_sobjects() from pyasm.search import WidgetDbConfig config_sobj = WidgetDbConfig.merge_configs(config_sobjs) #config_sobj = config_sobjs[0] except SearchException as e: print("WARNING: ", e) config_sobj = None if config_sobj: config_xml = config_sobj.get_xml_value("config") if not config_view.get_config().has_view(self.view): # make sure it does have the old way of storing filter # elements instead of just filter data if config_xml.get_nodes("config/filter/element"): self.config = WidgetConfig.get(xml=config_xml, view='filter') #self.config = self.get_default_filter_config() # set the form variables for the filters data = config_xml.get_value("config/filter/values") # link_search with specific search params takes precesdence # TODO: make a distinction between search definition and alter # search data provided by user if data and not self.user_override: filter_data = FilterData(data) filter_data.set_to_cgi() else: self.set_filter_data(self.search_type, self.view) else: if self.use_last_search: self.set_filter_data(self.search_type, self.view) if not self.config: # get the approprate filter definition self.config = self.get_default_filter_config() if self.use_last_search: self.set_filter_data(self.search_type, self.view) if not self.config: return self.num_filters_enabled = 0 # create the filters self.filters = [] security = Environment.get_security() element_names = self.config.get_element_names() #element_names = ["Keywords", "Related"] for element_name in element_names: filter = self.config.get_display_widget(element_name) if filter and filter.is_visible(): self.filters.append(filter) # make sure there is at least one filter defined #assert self.filters # just for drawing purpose if self.kwargs.get('skip_search') == True: return try: self.alter_search() self.set_persistent_value() except SearchInputException as e: self.clear_search_data(self.search_type) raise SearchInputException("%s If this problem persists, this view may contain invalid data in < values >. Clean up the data in Widget Config for the view [%s]."%( e.__str__(), self.view)) except: self.clear_search_data(self.search_type) raise
def get_display(my): my.sobject = my.get_sobject() top = DivWdg() top.add_class("spt_detail_top") top.add_color("background", "background") top.add_color("color", "color") if not my.sobject: top.add("No SObject defined for this widget") return top if my.parent: my.search_type = my.parent.get_base_search_type() my.search_key = SearchKey.get_by_sobject(my.parent) top.add_attr("spt_parent_key", my.search_key) my.pipeline_code = my.parent.get_value("pipeline_code", no_exception=True) my.full_search_type = my.parent.get_search_type() else: my.pipeline_code = my.sobject.get_value("pipeline_code", no_exception=True) my.search_type = my.sobject.get_base_search_type() my.search_key = SearchKey.get_by_sobject(my.sobject) my.full_search_type = my.sobject.get_search_type() if not my.pipeline_code: my.pipeline_code = 'default' top.add_style("text-align: left") my.set_as_panel(top) table = Table() #from tactic.ui.container import ResizableTableWdg #table = ResizableTableWdg() table.add_color("background", "background") table.add_color("color", "color") top.add(table) table.set_max_width() table.add_row() if my.parent: code = my.parent.get_value("code", no_exception=True) name = my.parent.get_value("name", no_exception=True) search_type_obj = my.parent.get_search_type_obj() else: code = my.sobject.get_value("code", no_exception=True) name = my.sobject.get_value("name", no_exception=True) search_type_obj = my.sobject.get_search_type_obj() # add the title td = table.add_cell() td.add_attr("colspan", "3") title = DivWdg() search = Search("sthpw/snapshot") search.add_filter("search_type", "sthpw/search_type") search.add_filter("search_code", search_type_obj.get_value("code")) if search.get_sobject(): thumb = ThumbWdg() title.add(thumb) thumb.set_icon_size(30) thumb.set_sobject(search_type_obj) thumb.add_style("float: left") td.add(title) title.add_color("background", "background3") title.add_style("height: 20px") title.add_style("padding: 6px") title.add_style("font-weight: bold") title.add_style("font-size: 1.4em") stype_title = search_type_obj.get_value("title") if stype_title: title.add("%s: " % stype_title) if name: title.add("%s" % name) if code: title.add(" <i style='font-size: 0.8; opacity: 0.7'>(%s)</i>" % code) elif code: title.add("%s" % code) else: title.add("(No name)") title.add_border() table.add_row() # left td = table.add_cell() td.add_style("width: 300px") td.add_style("min-width: 300px") td.add_style("vertical-align: top") div = DivWdg() td.add(div) div.add_class("spt_sobject_detail_top") thumb_table = Table() div.add(thumb_table) thumb_table.add_row() from tactic.ui.panel import ThumbWdg2 thumb = ThumbWdg2() # use a larger version for clearer display #thumb.set_icon_type('web') if my.parent: thumb.set_sobject(my.parent) search_key = my.parent.get_search_key() else: thumb.set_sobject(my.sobject) search_key = my.sobject.get_search_key() gallery_div = DivWdg() div.add(gallery_div) gallery_div.add_class("spt_tile_gallery") thumb_table.add_behavior({ 'type': 'click_up', 'search_key': search_key, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_sobject_detail_top"); var gallery_el = top.getElement(".spt_tile_gallery"); var class_name = 'tactic.ui.widget.gallery_wdg.GalleryWdg'; var kwargs = { search_key: bvr.search_key, search_keys: [bvr.search_key], }; spt.panel.load(gallery_el, class_name, kwargs); ''' }) # prefer to see the original image, then web #thumb.set_option('image_link_order', 'main|web|icon') #thumb.set_option("detail", "false") #thumb.set_option("icon_size", "100%") td = thumb_table.add_cell(thumb) td.add_style("vertical-align: top") td.add_style("width: auto") td.add_style("padding: 15px") sobject_info_wdg = my.get_sobject_info_wdg() sobject_info_wdg.add_style("width: auto") td.add(sobject_info_wdg) if my.search_type == 'sthpw/task' and not my.parent: pass else: sobject_info_wdg = my.get_sobject_detail_wdg() td = table.add_cell() td.add(sobject_info_wdg) td.add_style("vertical-align: top") td.add_style("overflow: hidden") # right td = table.add_cell() td.add_style("text-align: left") td.add_style("vertical-align: top") td.add_class("spt_notes_wrapper") notes_div = DivWdg() td.add(notes_div) from tactic.ui.widget.discussion_wdg import DiscussionWdg discussion_wdg = DiscussionWdg(search_key=my.search_key, context_hidden=False, show_note_expand=False) notes_div.add(discussion_wdg) notes_div.add_style("min-width: 300px") notes_div.add_style("height: 200") notes_div.add_style("overflow-y: auto") notes_div.add_class("spt_resizable") # get the process if my.parent: process = my.sobject.get_value("process") else: process = '' # content tr = table.add_row() td = table.add_cell() td.add_attr("colspan", "5") #td.add_attr("colspan", "3") # create a state for tab. The tab only passes a search key # parent key search_key = SearchKey.get_by_sobject(my.sobject) parent_key = "" if search_key.startswith("sthpw/"): parent = my.sobject.get_parent() if parent: parent_key = parent.get_search_key() state = { 'search_key': search_key, 'parent_key': parent_key, 'process': process, } WebState.get().push(state) config_xml = my.get_config_xml() config = WidgetConfig.get(view="tab", xml=config_xml) if process: custom_view = "tab_config_%s" % process else: custom_view = "tab_config" search = Search("config/widget_config") search.add_filter("category", "TabWdg") search.add_filter("search_type", my.search_type) search.add_filter("view", custom_view) custom_config_sobj = search.get_sobject() if custom_config_sobj: custom_config_xml = custom_config_sobj.get_value("config") custom_config = WidgetConfig.get(view=custom_view, xml=custom_config_xml) config = WidgetConfigView(search_type='TabWdg', view=custom_view, configs=[custom_config, config]) #menu = my.get_extra_menu() #tab = TabWdg(config=config, state=state, extra_menu=menu) tab = TabWdg(config=config, state=state, show_add=False, show_remove=False, tab_offset=5) tab.add_style("margin: 0px -2px -2px -2px") td.add(tab) td.add_style("padding-top: 10px") return top
def execute(my): web = WebContainer.get_web() alter_mode = my.kwargs.get("alter_mode") title = my.kwargs.get("title") config_mode = web.get_form_value("config_mode") view = web.get_form_value('view') constraint = web.get_form_value("config_constraint") data_type = '' if config_mode == "advanced": config_string = web.get_form_value("config_xml") if config_string: xml = Xml() xml.read_string(config_string) node = xml.get_root_node() data_type = xml.get_attribute(node, "data_type") nullable = xml.get_attribute(node, "nullable") in ['true', 'True'] else: data_type = web.get_form_value("config_data_type") if data_type == 'Other...': data_type = web.get_form_value("config_data_type_custom") cb = CheckboxWdg("config_nullable") nullable = cb.is_checked() # if advanced is selected in the Widget Column view, data_type is '' # read from UI if not data_type and view == 'definition': data_type = web.get_form_value("config_data_type") if data_type == 'Other...': data_type = web.get_form_value("config_data_type_custom") cb = CheckboxWdg("config_nullable") nullable = cb.is_checked() column_name = web.get_form_value("column_name") search_type = web.get_form_value("target_search_type") if alter_mode == ManageSearchTypeDetailWdg.REMOVE_COLUMN: cmd = ColumnDropCmd(search_type, column_name) Command.execute_cmd(cmd) # delete widget config from definition view widget_config = WidgetDbConfig.get_by_search_type( search_type, 'definition') if widget_config: config = WidgetConfig.get( 'definition', xml=widget_config.get_xml_value('config')) config.remove_xml_element(column_name) new_xml = config.get_xml().to_string() widget_config.set_value("config", new_xml) widget_config.commit() # set cache to {} from pyasm.common import Container Container.put("WidgetConfigView:config_cache", {}) #Container.put("WidgetConfig:config_cache", {}) elif alter_mode == ManageSearchTypeDetailWdg.MODIFY_COLUMN: cmd = ColumnAlterCmd(search_type, column_name, data_type, nullable) Command.execute_cmd(cmd) element_options = {} element_options['type'] = data_type if title: element_options['title'] = title # handle the "default" view # update the widget config data type in the xml view = my.DEFAULT_VIEW config = WidgetDbConfig.get_by_search_type(search_type, view) if config: config.append_display_element(column_name, options={}, \ element_attrs=element_options) config.commit_config() elif alter_mode == ManageSearchTypeDetailWdg.ADD_COLUMN: cmd = ColumnAddCmd(search_type, column_name, data_type, nullable) Command.execute_cmd(cmd) if constraint: # add constraint from pyasm.command import ColumnAddIndexWdg cmd = ColumnAddIndexWdg() cmd.execute() else: # remove constraint pass
def _get_predefined_url(cls, key, hash): # make some predefined fake urls if key in ["link", "tab", "admin"]: # this is called by PageNav if key == "admin": expression = "/admin/link/{link}" else: expression = "/%s/{link}" % key options = Common.extract_dict(hash, expression) link = options.get("link") if not link: return None # test link security project_code = Project.get_project_code() security = Environment.get_security() keys = [ { "element": link }, { "element": "*" }, { "element": link, "project": project_code }, { "element": "*", "project": project_code } ] if not security.check_access("link", keys, "allow", default="deny"): return None from tactic.ui.panel import SideBarBookmarkMenuWdg personal = False if '.' in link: personal = True config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", link, personal=personal) options = config.get_display_options(link) if not options: from pyasm.biz import Schema config_xml = [] config_xml.append( ''' <config> ''') config_schema = Schema.get_predefined_schema('config') SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml) schema = Schema.get_admin_schema() SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml) config_xml.append( ''' </config> ''') xml = "".join(config_xml) from pyasm.widget import WidgetConfig schema_config = WidgetConfig.get(view="_admin_schema", xml=xml) options = schema_config.get_display_options(link) if not options: schema_config.set_view("_config_schema") options = schema_config.get_display_options(link) if not options: return None class_name = options.get("class_name") widget_key = options.get("widget_key") if widget_key: class_name = WidgetClassHandler().get_display_handler(widget_key) elif not class_name: class_name = 'tactic.ui.panel.ViewPanelWdg' if key in ["admin", "tab"]: use_index = "false" else: use_index = "true" if key in ['admin']: use_admin = "true" else: use_admin = "false" xml = [] xml.append('''<element admin="%s" index="%s">''' % (use_admin, use_index)) xml.append(''' <display class="%s">''' % class_name) for name, value in options.items(): xml.append("<%s>%s</%s>" % (name, value, name) ) xml.append(''' </display>''') xml.append('''</element>''') xml = "\n".join(xml) sobject = SearchType.create("config/url") sobject.set_value("url", "/%s/{value}" % key) sobject.set_value("widget", xml ) return sobject else: return None
def get_config(cls, search_type, view, default=None, personal=False): # personal doesn't mean much here since this is only for Project view definition """ if view == "__column__": xml == ''' <config> <element name="tttt" type="__database__"/> <element name="uuuu" type="__database__"/> <element name="vvvv" type="__database__"/> </config> ''' """ widget_config = None config_view = None widget_config_list = [] # get all the configs relevant to this search_type configs = [] from pyasm.widget import WidgetConfigView if view == "definition": if default: try: default_config_view = WidgetConfigView.get_by_search_type( search_type, view, use_cache=False, local_search=True) user_config_view = WidgetConfigView.get_by_search_type( search_type, view) #merge the user config view from db into the default config view in xml file default_config = default_config_view.get_definition_config( ) user_config = user_config_view.get_definition_config() if user_config: user_element_names = user_config.get_element_names() # make sure it's unique, there is a new validate function for # WidgetDbConfig to ensure that also user_element_names = Common.get_unique_list( user_element_names) for elem in user_element_names: user_node = user_config.get_element_node(elem) default_config.append_xml_element(elem, node=user_node) except SqlException as e: print "Search ERROR: ", e.__str__() default_config = None if default_config: default_config.get_xml().clear_xpath_cache() widget_config_list = [default_config] else: config_view = WidgetConfigView.get_by_search_type( search_type, view, use_cache=True) elif view == "database_definition": schema_config = SearchType.get_schema_config(search_type) widget_config_list = [schema_config] elif view == 'template': base_dir = Environment.get_install_dir() file_path = "%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir if os.path.exists(file_path): widget_config = WidgetConfig.get(file_path=file_path, view=view) widget_config_list = [widget_config] ''' elif default == True : base_dir = Environment.get_install_dir() file_path="%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir if os.path.exists(file_path): widget_config = WidgetConfig.get(file_path=file_path, view="default_definition") widget_config_list = [widget_config] ''' elif view == "custom_definition": # look for a definition in the database search = Search("config/widget_config") search.add_filter("search_type", 'SearchTypeSchema') search.add_filter("view", view) config = search.get_sobject() # this is really just a custom made definition #view = "definition" if config: widget_config_list = [config] else: widget_config_list = [] elif view == "db_column": # look for a definition in the database """ view = "definition" from pyasm.search import SObjectDefaultConfig default = SObjectDefaultConfig(search_type=search_type,view=view) xml = default.get_xml() config = WidgetConfig.get(view=view, xml=xml) widget_config_list = [config] """ try: # add the schema config definiiton schema_config = SearchType.get_schema_config(search_type) widget_config_list = [schema_config] except SqlException as e: widget_config_list = [] if not config_view: config_view = WidgetConfigView(search_type, view, widget_config_list) return config_view
def get_display(self): from tactic.ui.panel import CustomLayoutWdg top = self.top top.add_class("spt_content_box") top.add_class("spt_content_box_inline") top.add_style("min-width: 200px") #top.add_style("opacity: 0.1") """ top.add_behavior( { 'type': 'loadX', 'cbjs_action': ''' new Fx.Tween(bvr.src_el, {duration: 500}).start("opacity", 1.0); ''' } ) """ colors = { #"color3": top.get_color("color3"), #"background3": top.get_color("background3"), #"background3": "rgba(18, 50, 91, 1.0)", "background3": "#323232", "color3": "#FFF", "border": top.get_color("border", -10), } style = HtmlElement.style() top.add(style) style.add(''' .spt_content_box_inline { margin: 15px; } .spt_content_box_max { margin: 0px; width: 100%%; height: 100%%; background: rgba(0,0,0,0.0); z-index: 1000; position: fixed; top: 0px; left: 0px; } .spt_content_box_max .spt_content_box_content { //height: 100%% !important; } .spt_content_box .spt_content_box_title { width: auto; border: none; background: %(background3)s; color: %(color3)s; height: 18px; padding: 6px 8px; font-weight: bold; font-size: 1.2em; border: solid 1px %(border)s; } .spt_content_box .spt_content_box_shelf { margin-top: 0px; border: solid 1px #AAA; padding: 8px 15px; height: 23px; background: #F8F8F8; } .spt_content_box .spt_content_box_content { width: auto; margin-top: -1px; margin-bottom: 5px; border: solid 1px #AAA; padding: 15px 0px 0px 0px; background: #FFF; overflow-x: auto; } .spt_content_box .spt_content_box_footer { margin-top: -1px; border: solid 1px #AAA; padding: 8px 15px; height: 23px; background: #F8F8F8; } ''' % colors) top.add(self.get_title_wdg()) inner = DivWdg() top.add(inner) inner.add_class("spt_content_box_inner") inner.add_style("overflow: hidden") inner.add_style("margin-top: 0px") # handle the shelf shelf_view = self.kwargs.get("shelf_view") if shelf_view: shelf_div = DivWdg() inner.add(shelf_div) shelf_div.add_class("spt_content_box_shelf") if shelf_view == "true": pass else: layout = CustomLayoutWdg(view=shelf_view) shelf_div.add(layout) content_div = DivWdg() content_div.add_class("spt_content_box_content") inner.add(content_div) content_div.add_style("width: auto") content_height = self.kwargs.get("content_height") if content_height: content_div.add_style("height: %s" % content_height) content_div.add_style("overflow-x: auto") content_view = self.kwargs.get("content_view") #content_div.add(content_view) if content_view: layout = CustomLayoutWdg(view=content_view) content_div.add(layout) content_margin = self.kwargs.get("content_margin") if content_margin: layout.add_style("margin", content_margin) config_xml = self.kwargs.get("config_xml") if config_xml: config = WidgetConfig.get(view="tab", xml=config_xml) layout = config.get_display_widget("content") content_div.add(layout) content_wdg = self.get_widget("content") if not content_wdg and self.widgets: content_wdg = self.widgets[0] if content_wdg: content_div.add(content_wdg) # handle the footer footer_view = self.kwargs.get("footer_view") if footer_view: footer_div = DivWdg() inner.add(footer_div) footer_div.add_class("spt_content_box_footer") layout = CustomLayoutWdg(view=footer_view) shelf_div.add(layout) return top
def get_display(my): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_gradient("background", "background", 0, -5) #top.add_style("height: 550px") top.add_behavior({ 'type': 'load', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|hide", {} ); ''' }) project = Project.get() title = TitleWdg(title='Client Home') top.add(title) shelf = DivWdg() top.add(shelf) shelf.add_style("margin-left: -8px") shelf.add_style("width: 130px") security = Environment.get_security() view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow') if view_side_bar: button_div = DivWdg() shelf.add(button_div) button_div.add_style("float: left") button_div.add_style("margin-top: -3px") button = IconButtonWdg(title="Side Bar", icon=IconWdg.ARROW_LEFT) button_div.add(button) shelf.add("Toggle Side Bar") button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' }) shelf.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' spt.named_events.fire_event("side_bar|toggle"); ''' }) shelf.add_class("hand") else: shelf.add(" ") search_wdg = DivWdg() search_wdg.add_class("spt_main_top") top.add(search_wdg) search_wdg.add_style("padding: 10px") search_wdg.add_style("margin: 10px auto") search_wdg.add_style("width: 430px") search_wdg.add("Search: ") search_wdg.add(" " * 3) custom_cbk = {} custom_cbk['enter'] = ''' var top = bvr.src_el.getParent(".spt_main_top"); var search_el = top.getElement(".spt_main_search"); var keywords = search_el.value; if (keywords != '') { var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': 'sthpw/sobject_list', 'view': 'table', 'keywords': keywords, 'simple_search_view': 'simple_search', //'show_shelf': false, } spt.tab.set_main_body_tab(); spt.tab.add_new("Search Results", "Search Results", class_name, kwargs); } ''' from tactic.ui.input import TextInputWdg, LookAheadTextInputWdg #text = TextInputWdg(name="search") text = LookAheadTextInputWdg(name="search", custom_cbk=custom_cbk) #text = TextWdg("search") text.add_class("spt_main_search") text.add_style("width: 290px") search_wdg.add(text) search_wdg.add_style("font-weight: bold") search_wdg.add_style("font-size: 16px") button = ActionButtonWdg(title="Search") #search_wdg.add(button) button.add_style("float: right") #button.add_style("margin-top: -28px") icon_div = DivWdg() search_wdg.add(icon_div) icon_div.add_style("width: 38px") icon_div.add_style("height: 27px") icon_div.add_style("padding-top: 3px") icon_div.add_style("padding-left: 4px") icon_div.add_style("text-align: center") #icon_div.add_gradient("background", "background3", 15, -10) icon_div.add_color("background", "background3", 10) over_color = icon_div.get_color("background3", 0) out_color = icon_div.get_color("background3", 10) icon_div.set_round_corners(5) icon_div.set_box_shadow("1px 1px 1px 1px") icon = IconWdg("Search", IconWdg.SEARCH_32, width=24) icon_div.add(icon) icon_div.add_style("float: right") icon_div.add_style("margin-top: -5px") button = icon_div icon_div.add_class("hand") icon_div.add_behavior({ 'type': 'mouseover', 'color': over_color, 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.color); ''' }) icon_div.add_behavior({ 'type': 'mouseout', 'color': out_color, 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.color); bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999"); bvr.src_el.setStyle("margin-top", "-5"); bvr.src_el.setStyle("margin-right", "0"); ''' }) icon_div.add_behavior({ 'type': 'click', 'color': out_color, 'cbjs_action': ''' bvr.src_el.setStyle("box-shadow", "0px 0px 1px 1px #999"); bvr.src_el.setStyle("margin-top", "-3"); bvr.src_el.setStyle("margin-right", "-2"); ''' }) icon_div.add_behavior({ 'type': 'click_up', 'color': out_color, 'cbjs_action': ''' bvr.src_el.setStyle("box-shadow", "1px 1px 1px 1px #999"); bvr.src_el.setStyle("margin-top", "-5"); bvr.src_el.setStyle("margin-right", "0"); ''' }) button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_main_top"); var search_el = top.getElement(".spt_main_search"); var keywords = search_el.value; if (keywords == '') { return; } var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { 'search_type': 'sthpw/sobject_list', 'view': 'table', 'keywords': keywords, 'simple_search_view': 'simple_search', //'show_shelf': false, } spt.tab.set_main_body_tab(); spt.tab.add_new("Search Results", "Search Results", class_name, kwargs); ''' }) #desc = DivWdg() #top.add(desc) #desc.add("Dashboard") #desc.add_style("width: 600px") # create a bunch of panels table = Table() table.add_color("color", "color") table.add_style("margin-bottom: 20px") table.center() top.add(table) table.add_row() td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "My Approvals" description = '''View all pending items for approval<br/><br/> ''' #image = "<img src='/context/images/getting_started_pipeline.png'/>" image = "<img src='/context/icons/64x64/dashboard_64.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.panel.ViewPanelWdg'; var kwargs = { search_type: 'sthpw/sobject_list', view: 'client_approval', show_shelf: false, show_select: false, element_names: ['preview', 'name', 'description', 'task_pipeline_vertical','notes'], is_editable: false, //expression: "@SOBJECT(sthpw/task['project_code','fickle3'].fickle3/cars.sthpw/sobject_list)" }; spt.tab.add_new("approvals", "Approvals", class_name, kwargs); ''' } config_wdg = my.get_section_wdg(title, description, image, behavior) td.add(config_wdg) td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "My Dashboard" image = "<img src='/context/icons/64x64/dashboard_64.png'/>" description = '''Dashboards display key project data in single views. Drill down further to work on tasks, make status changes or add notes.''' # read the config file from pyasm.widget import WidgetConfig tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path = "%s/../config/dashboard-conf.xml" % (dir_name) config = WidgetConfig.get(file_path=file_path, view="definition") #element_name = "my_dashboard" element_name = "my_dashboard" attrs = config.get_element_attributes(element_name) dashboard_data = {} kwargs = config.get_display_options(element_name) class_name = kwargs.get('class_name') dashboard_data['class_name'] = class_name dashboard_data['kwargs'] = kwargs dashboard_data['title'] = attrs.get("title") dashboard_data['description'] = attrs.get("description") dashboard_data['image'] = attrs.get("image") behavior = { 'type': 'click_up', 'dashboard': dashboard_data, 'cbjs_action': ''' var class_name = 'tactic.ui.startup.dashboards_wdg.DashboardsWdg'; var kwargs = {}; spt.tab.set_main_body_tab(); spt.tab.add_new("my_dashboard", "My Dashboard", bvr.dashboard.class_name, bvr.dashboard.kwargs); ''' } pipeline_wdg = my.get_section_wdg(title, description, image, behavior) td.add(pipeline_wdg) td = table.add_cell() td.add_style("padding: 3px") td.add_style("vertical-align: top") title = "My Reports" image = "<img src='/context/icons/64x64/report_64.png'/>" description = '''TACTIC provides a number of predefined reports that project managers can access instantly to get real-time analytics.''' behavior = { 'type': 'click_up', 'cbjs_action': ''' var class_name = 'tactic.ui.startup.reports_wdg.ReportsWdg'; var kwargs = {}; spt.tab.set_main_body_tab(); spt.tab.add_new("reports", "Reports", class_name, kwargs); //spt.panel.load_popup("Reports", class_name, kwargs); ''' } side_bar_wdg = my.get_section_wdg(title, description, image, behavior) td.add(side_bar_wdg) """ td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = "Documentation" description = '''TACTIC Documentation. <br/><br/> * Project Setup Documentation<br/> <br/> * End User Documentation<br/> <br/> * Developer Documentation<br/> <br/> * System Administrator Documentation<br/> <br/> ''' image = "<img src='/context/images/getting_started_pipeline.png'/>" behavior = { 'type': 'click_up', 'cbjs_action': ''' spt.help.load_alias("main") ''' } doc_wdg = my.get_section_wdg(title, description, image, behavior) td.add(doc_wdg) """ tr, td = table.add_row_cell() td.add_style("font-size: 14px") td.add("<br/>" * 2) quick_links_wdg = QuickLinksWdg() td.add(quick_links_wdg) return top
def get_display(my): top = DivWdg() top.add_border() top.add_style("padding: 10px") top.add_color("color", "color") top.add_gradient("background", "background", 0, -5) #top.add_style("height: 550px") top.add_class("spt_reports_top") my.set_as_panel(top) inner = DivWdg() top.add(inner) title = DivWdg() title.add("Reports") title.add_style("font-size: 18px") title.add_style("font-weight: bold") title.add_style("text-align: center") title.add_style("padding: 10px") title.add_style("margin: -10px -10px 0px -10px") inner.add(title) title.add_gradient("background", "background3", 5, -10) from tactic.ui.widget import TitleWdg subtitle = TitleWdg(name_of_title='List of Built in Reports',help_alias='main') inner.add(subtitle) inner.add("<br/>") button_div = DivWdg() inner.add(button_div) button_div.add_class("spt_buttons_top") button_div.add_style("margin-top: -5px") button_div.add_style("margin-bottom: 30px") button_div.add_border() button_div.add_style("margin-top: -15px") button_div.add_style("margin-bottom: 0px") button_div.add_style("width: 100%") button_div.add_style("height: 33px") button_div.add_color("background", "background2") button_div.add_style("margin-left: auto") button_div.add_style("margin-right: auto") button = SingleButtonWdg(title="Collapse", icon=IconWdg.HOME) button_div.add(button) button.add_style("float: left") button.add_style("left: 5px") button.add_style("top: 5px") # FIXME: get home for the user #home = 'tactic.ui.startup.ContentCreatorWdg' home = 'tactic.ui.startup.MainWdg' button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.startup.MainWdg'; var kwargs = { help_alias: 'main' }; spt.tab.add_new("_startup", "Startup", class_name, kwargs); ''' } ) """ button = SingleButtonWdg(title="Collapse", icon=IconWdg.ARROW_UP) button_div.add(button) button.add_class("spt_collapse") inner.add(button_div) button.add_style("float: left") button.add_style("left: 5px") button.add_style("top: 5px") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_reports_top"); var element = top.getElement(".spt_reports_list"); var buttons = bvr.src_el.getParent(".spt_buttons_top"); expand = buttons.getElement(".spt_expand"); new Fx.Tween(element).start('margin-top', "-400px"); expand.setStyle("display", ""); bvr.src_el.setStyle("display", "none"); ''' } ) button = SingleButtonWdg(title="Expand", icon=IconWdg.ARROW_DOWN) button.add_style("display: none") button.add_class("spt_expand") button_div.add(button) button.add_style("left: 5px") button.add_style("top: 5px") inner.add(button_div) button.add_style("float: left") button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_reports_top"); var element = top.getElement(".spt_reports_list"); var buttons = bvr.src_el.getParent(".spt_buttons_top"); collapse = buttons.getElement(".spt_collapse"); new Fx.Tween(element).start('margin-top', "0px"); collapse.setStyle("display", ""); bvr.src_el.setStyle("display", "none"); ''' } ) """ reports = [] # read the config file from pyasm.widget import WidgetConfig tmp_path = __file__ dir_name = os.path.dirname(tmp_path) file_path="%s/../config/reports-conf.xml" % (dir_name) config = WidgetConfig.get(file_path=file_path, view="definition") category = my.kwargs.get('category') # get all of the configs from the database if not category or category in ["custom_reports", "custom_charts"]: search = Search("config/widget_config") search.add_op("begin") if category == "custom_reports": search.add_filter("widget_type", "report") elif category == "custom_charts": search.add_filter("widget_type", "chart") elif not category: search.add_filters("widget_type", ["chart","report"]) search.add_op("or") db_configs = search.get_sobjects() else: db_configs = [] element_names = my.kwargs.get("element_names") if element_names is None: element_names = config.get_element_names() project = Project.get() for element_name in element_names: key = {'project': project.get_code(), 'element': element_name} key2 = {'project': project.get_code(), 'element': '*'} key3 = {'element': element_name} key4 = {'element': '*'} keys = [key, key2, key3, key4] if not top.check_access("link", keys, "view", default="deny"): continue attrs = config.get_element_attributes(element_name) report_data = {} kwargs = config.get_display_options(element_name) class_name = kwargs.get('class_name') # the straight xml definition contains the sidebar class_name # with LinkWdg ... we shouldn't use this, so build the # element from scratch #xml = config.get_element_xml(element_name) from pyasm.search import WidgetDbConfig xml = WidgetDbConfig.build_xml_definition(class_name, kwargs) report_data['class_name'] = class_name report_data['kwargs'] = kwargs report_data['title'] = attrs.get("title") report_data['description'] = attrs.get("description") report_data['image'] = attrs.get("image") report_data['xml'] = xml reports.append(report_data) for db_config in db_configs: element_name = db_config.get_value("view") key = {'project': project.get_code(), 'element': element_name} key2 = {'project': project.get_code(), 'element': '*'} key3 = {'element': element_name} key4 = {'element': '*'} keys = [key, key2, key3, key4] if not top.check_access("link", keys, "view", default="deny"): continue report_data = {} view = db_config.get_value("view") kwargs = { 'view': view } parts = view.split(".") title = Common.get_display_title(parts[-1]) xml = db_config.get_value("config") report_data['class_name'] = "tactic.ui.panel.CustomLayoutWdg" report_data['kwargs'] = kwargs report_data['title'] = title report_data['description'] = title report_data['image'] = None report_data['xml'] = xml report_data['widget_type'] = db_config.get_value("widget_type") if report_data['widget_type'] == 'report': report_data['category'] = "custom_reports" elif report_data['widget_type'] == 'chart': report_data['category'] = "custom_charts" reports.append(report_data) """ report_data = { 'title': 'Tasks Completed This Week', 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'kwargs': { 'search_type': 'sthpw/task', 'view': 'table' }, } reports.append(report_data) """ if category == 'list_item_reports' or not category: search_types = Project.get().get_search_types() for search_type in search_types: base_key = search_type.get_base_key() key = {'project': project.get_code(), 'code': base_key} key2 = {'project': project.get_code(), 'code': '*'} key3 = {'code': base_key} key4 = {'code': '*'} keys = [key, key2, key3, key4] if not top.check_access("search_type", keys, "view", default="deny"): continue if not SearchType.column_exists(base_key, "pipeline_code"): continue thumb_div = DivWdg() image = thumb_div thumb_div.add_border() thumb_div.set_box_shadow("1px 1px 1px 1px") thumb_div.add_style("width: 60px") thumb = ThumbWdg() thumb_div.add(thumb) thumb.set_sobject(search_type) thumb.set_icon_size(60) report_data = { 'title': '%s Workflow Status' % search_type.get_title(), 'description': 'Number of items in each process', 'class_name': 'tactic.ui.report.stype_report_wdg.STypeReportWdg', 'kwargs': { 'search_type': base_key }, 'image': thumb_div } reports.append(report_data) report_data = { 'title': '%s Labor Cost Report' % search_type.get_title(), 'description': 'Labor Cost Breakdown for each Item', 'class_name': 'tactic.ui.panel.ViewPanelWdg', 'kwargs': { 'search_type': search_type.get_code(), 'view': "table", 'show_header': False, 'mode': 'simple', 'element_names': "preview,code,title,cost_breakdown,bid_hours,bid_cost,actual_hours,actual_cost,overbudget,variance" }, 'image': IconWdg("", IconWdg.REPORT_03) } reports.append(report_data) table2 = Table() inner.add(table2) table2.add_style("width: 100%") categories_div = DivWdg() td = table2.add_cell(categories_div) td.add_style("vertical-align: top") td.add_style("width: 200px") td.add_color("background", "background3") td.add_border() #categories_div.add_style("margin: -1px 0px 0px -1px") categories_div.add_style("padding-top: 10px") #categories_div.add_style("float: left") categories_div.add_color("color", "color3") categories = config.get_all_views() categories.insert(-1, "list_item_reports") categories.insert(-1, "custom_charts") categories.insert(-1, "custom_reports") table_div = DivWdg() td = table2.add_cell(table_div) td.add_style("vertical-align: top") table_div.add_class("spt_reports_list") table_div.add_border() table_div.add_color("background", "background", -5) table_div.add_style("min-height: 500px") for i, category in enumerate(categories): if i == len(categories) - 1: categories_div.add("<hr/>") config.set_view(category) element_names = config.get_element_names() if category == "definition": title = "All Reports" else: title = Common.get_display_title(category) category_div = DivWdg() categories_div.add(category_div) category_div.add(title) category_div.add_style("padding: 5px") category_div.add_class("hand") category_div.add_behavior( { 'type': 'click_up', 'category': category, 'element_names': element_names, 'class_name': Common.get_full_class_name(my), 'cbjs_action': ''' var kwargs = { is_refresh: true, category: bvr.category, element_names: bvr.element_names } //spt.panel.refresh(top, kwargs); var top = bvr.src_el.getParent(".spt_reports_top"); spt.panel.load(top, bvr.class_name, kwargs); ''' } ) bgcolor = category_div.get_color("background3", -10) category_div.add_behavior( { 'type': 'mouseover', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background", bvr.bgcolor); ''' } ) category_div.add_behavior( { 'type': 'mouseout', 'bgcolor': bgcolor, 'cbjs_action': ''' bvr.src_el.setStyle("background", ""); ''' } ) # create a bunch of panels table = Table() table_div.add(table) table.add_color("color", "color") table.add_style("margin-top: 20px") table.center() table_div.add_style("margin: -3px -3px -1px -2px") if not reports: tr = table.add_row() td = table.add_cell() td.add("There are no reports defined.") td.add_style("padding: 50px") if my.kwargs.get("is_refresh") in ['true', True]: return inner else: return top for i, report in enumerate(reports): #if i == 0 or i%4 == 0: if i%3 == 0: tr = table.add_row() td = table.add_cell() td.add_style("vertical-align: top") td.add_style("padding: 3px") title = report #description = '''The schema is used to layout the basic components of your project. Each component represents a list of items that you use in your business everyday.''' description = report.get("title") # Each node will contain a list of "items" and will be stored as a table in the database.''' class_name = report.get("class_name") kwargs = report.get("kwargs") title = report.get("title") description = report.get("description") widget_type = report.get("widget_type") image = report.get("image") icon = report.get("icon") xml = report.get("xml") if image: div = DivWdg() if isinstance(image, basestring): image = image.upper() image = eval("IconWdg('', IconWdg.%s)" % image) div.add_style("margin-left: 15px") div.add_style("margin-top: 5px") else: image = image div.add(image) image = div elif icon: icon = icon.upper() image = eval("IconWdg('', IconWdg.%s)" % icon) else: div = DivWdg() """ import random num = random.randint(0,3) if num == 1: image = IconWdg("Bar Chart", IconWdg.GRAPH_BAR_01) elif num == 2: image = IconWdg("Bar Chart", IconWdg.GRAPH_LINE_01) else: image = IconWdg("Bar Chart", IconWdg.GRAPH_BAR_02) """ if widget_type == "chart": image = IconWdg("Chart", IconWdg.GRAPH_BAR_02) else: image = IconWdg("No Image", IconWdg.WARNING) div.add_style("margin-left: 15px") div.add_style("margin-top: 5px") div.add(image) image = div behavior = { 'type': 'click_up', 'title': title, 'class_name': class_name, 'kwargs': kwargs, 'cbjs_action': ''' spt.tab.set_main_body_tab(); //var top = bvr.src_el.getParent(".spt_reports_top"); //spt.tab.set_tab_top(top); spt.tab.add_new(bvr.title, bvr.title, bvr.class_name, bvr.kwargs); ''' } schema_wdg = my.get_section_wdg(title, description, image, behavior) schema_wdg.add_behavior( { 'type': 'load', 'title': title, 'class_name': class_name, 'xml': xml, 'kwargs': kwargs, 'cbjs_action': ''' var report_top = bvr.src_el; report_top.kwargs = bvr.kwargs; report_top.class_name = bvr.class_name; report_top.element_name = bvr.title; report_top.xml = bvr.xml; ''' } ) td.add(schema_wdg) inner.add("<br/>") #from tactic.ui.container import TabWdg #tab = TabWdg(show_add=False) #inner.add(tab) if my.kwargs.get("is_refresh") in ['true', True]: return inner else: return top
def get_display(my): my.sobject = my.get_sobject() top = DivWdg() top.add_class("spt_detail_top") top.add_color("background", "background") top.add_color("color", "color") if not my.sobject: top.add("No SObject defined for this widget") return top if my.parent: my.search_type = my.parent.get_base_search_type() my.search_key = SearchKey.get_by_sobject(my.parent) top.add_attr("spt_parent_key", my.search_key) my.pipeline_code = my.parent.get_value("pipeline_code", no_exception=True) my.full_search_type = my.parent.get_search_type() else: my.pipeline_code = my.sobject.get_value("pipeline_code", no_exception=True) my.search_type = my.sobject.get_base_search_type() my.search_key = SearchKey.get_by_sobject(my.sobject) my.full_search_type = my.sobject.get_search_type() if not my.pipeline_code: my.pipeline_code = 'default' top.add_style("text-align: left") my.set_as_panel(top) table = Table() #from tactic.ui.container import ResizableTableWdg #table = ResizableTableWdg() table.add_color("background", "background") table.add_color("color", "color") top.add(table) table.set_max_width() table.add_row() # left #td = table.add_cell(resize=False) td = table.add_cell() #td.add_style("padding: 10px") td.add_style("width: 200px") td.add_style("min-width: 200px") td.add_style("vertical-align: top") #td.add_border() #td.add_style("border-style: solid") #td.add_style("border-width: 1px 0 1px 1px") #td.add_color("border-color", "border") #td.add_color("background", "background", -10) if my.parent: code = my.parent.get_code() else: code = my.sobject.get_code() # add the tile title = DivWdg() td.add(title) title.add_gradient("background", "background3", 0, -10) title.add_style("height: 20px") title.add_style("padding: 4px") title.add_style("font-weight: bold") title.add_style("font-size: 1.4em") title.add("%s" % code) title.add_border() div = DivWdg() td.add(div) div.add_class("spt_sobject_detail_top") thumb_table = Table() div.add(thumb_table) thumb_table.add_row() thumb = ThumbWdg() # use a larger version for clearer display thumb.set_icon_type('web') # prefer to see the original image, then web thumb.set_option('image_link_order', 'main|web|icon') thumb.set_option("detail", "false") thumb.set_option("icon_size", "100%") td = thumb_table.add_cell(thumb) td.add_style("vertical-align: top") td.add_style("width: 240px") td.add_style("padding: 15px") if my.parent: thumb.set_sobject(my.parent) else: thumb.set_sobject(my.sobject) sobject_info_wdg = my.get_sobject_info_wdg() sobject_info_wdg.add_style("width: 200px") td.add(sobject_info_wdg) if my.search_type == 'sthpw/task' and not my.parent: pass else: sobject_info_wdg = my.get_sobject_detail_wdg() td = table.add_cell() td.add(sobject_info_wdg) td.add_style("vertical-align: top") td.add_style("overflow: hidden") # right td = table.add_cell() td.add_style("text-align: left") td.add_style("vertical-align: top") #td.add_color("background", "background", -10) td.add_class("spt_notes_wrapper") #td.add_border() # add the title title = DivWdg() td.add(title) title.add_gradient("background", "background3", 0, -10) title.add_style("height: 20px") title.add_style("padding: 4px") title.add_style("font-weight: bold") title.add("Notes") title.add_border() notes_div = DivWdg() td.add(notes_div) from tactic.ui.widget.discussion_wdg import DiscussionWdg discussion_wdg = DiscussionWdg(search_key=my.search_key, context_hidden=False, show_note_expand=False) notes_div.add(discussion_wdg) notes_div.add_style("min-width: 300px") notes_div.add_style("height: 200") notes_div.add_style("overflow-y: auto") notes_div.add_class("spt_resizable") # get the process if my.parent: process = my.sobject.get_value("process") else: process = '' # content tr = table.add_row() td = table.add_cell() td.add_attr("colspan", "5") #td.add_attr("colspan", "3") # create a state for tab. The tab only passes a search key # parent key search_key = SearchKey.get_by_sobject(my.sobject) parent = my.sobject.get_parent() if parent: parent_key = parent.get_search_key() else: parent_key = "" state = { 'search_key': search_key, 'parent_key': parent_key, 'process': process, } WebState.get().push(state) config_xml = my.get_config_xml() config = WidgetConfig.get(view="tab", xml=config_xml) if process: custom_view = "tab_config_%s" % process else: custom_view = "tab_config" search = Search("config/widget_config") search.add_filter("category", "TabWdg") search.add_filter("search_type", my.search_type) search.add_filter("view", custom_view) custom_config_sobj = search.get_sobject() if custom_config_sobj: custom_config_xml = custom_config_sobj.get_value("config") custom_config = WidgetConfig.get(view=custom_view, xml=custom_config_xml) config = WidgetConfigView(search_type='TabWdg', view=custom_view, configs=[custom_config, config]) #menu = my.get_extra_menu() #tab = TabWdg(config=config, state=state, extra_menu=menu) tab = TabWdg(config=config, state=state, show_add=False, show_remove=False, tab_offset=5) tab.add_style("margin: 0px -2px -2px -2px") td.add(tab) td.add_style("padding-top: 10px") return top
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
if default_config: default_config.get_xml().clear_xpath_cache() widget_config_list = [default_config] else: config_view = WidgetConfigView.get_by_search_type( search_type, view, use_cache=True) elif view == "database_definition": schema_config = SearchType.get_schema_config(search_type) widget_config_list = [schema_config] elif view == 'template': base_dir = Environment.get_install_dir() file_path = "%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir if os.path.exists(file_path): widget_config = WidgetConfig.get(file_path=file_path, view=view) widget_config_list = [widget_config] ''' elif default == True : base_dir = Environment.get_install_dir() file_path="%s/src/config2/search_type/search/DEFAULT-conf.xml" % base_dir if os.path.exists(file_path): widget_config = WidgetConfig.get(file_path=file_path, view="default_definition") widget_config_list = [widget_config] ''' elif view == "custom_definition": # look for a definition in the database search = Search("config/widget_config") search.add_filter("search_type", 'SearchTypeSchema') search.add_filter("view", view) config = search.get_sobject()
def init(my): my.is_refresh = my.kwargs.get("refresh") my.search_key = my.kwargs.get("search_key") my.ticket_key = my.kwargs.get("ticket") my.parent_key = my.kwargs.get("parent_key") my.expression = my.kwargs.get("expression") # This assumed parent can cause errors as it tries to find a # relationship between to stypes that don't exist ... or worse, # try to bind them when one stype does not have the sufficent columns # ie: pipeline_code #if not my.parent_key: # project = Project.get() # my.parent_key = project.get_search_key() my.code = my.kwargs.get("code") sobject = None if my.search_key: sobject = Search.get_by_search_key(my.search_key) my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() if sobject.is_insert(): my.mode = 'insert' else: my.mode = 'edit' elif my.expression: sobject = Search.eval(my.expression, single=True) my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() my.mode = 'edit' elif my.ticket_key: from pyasm.security import Ticket, Login ticket = Ticket.get_by_valid_key(my.ticket_key) if not ticket: raise TacticException("No valid ticket") login_code = ticket.get_value("login") login = Login.get_by_code(login_code) my.search_type = "sthpw/login" my.search_id = login.get_id() my.mode = 'edit' elif my.code: my.search_type = my.kwargs.get("search_type") search = Search(my.search_type) search.add_filter("code", my.code) sobject = search.get_sobject() my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() my.mode = 'edit' else: my.search_type = my.kwargs.get("search_type") my.search_id = my.kwargs.get("search_id") if not my.search_id: my.search_id = -1 my.search_id = int(my.search_id) if my.search_id != -1: my.mode = "edit" else: my.mode = "insert" # explicit override if my.kwargs.get("mode"): my.mode = my.kwargs.get("mode") my.view = my.kwargs.get("view") if not my.view: my.view = my.kwargs.get("config_base") if not my.view: my.view = "edit" default_data = my.kwargs.get('default') if not default_data: default_data = {} elif isinstance(default_data, basestring): try: default_data = jsonloads(default_data) except: #may be it's regular dictionary try: default_data = eval(default_data) except: print "Warning: Cannot evaluate [%s]" %default_data default_data = {} if sobject: my.set_sobjects([sobject], None) else: my.do_search() # TODO: get_config() is going the right direction (less features) but the more complicated method is biased # towards edit and insert view.. and so it needs improvement as well if my.view not in ["insert", "edit"]: # try a new smaller way to get config only when an explicit view # is set my.config = my.get_config() else: my.config = WidgetConfigView.get_by_search_type(my.search_type, my.view, use_cache=False) # for inline config definitions config_xml = my.kwargs.get("config_xml") if config_xml: #from pyasm.common import Xml #xml = Xml() #xml.read_string(config_xml) #node = xml.get_node("config/%s" % my.view) #xml.set_attribute(node, "class", "tactic.ui.panel.EditWdg") #config = WidgetConfig.get(view=my.view, xml=xml) config_xml = config_xml.replace("&", "&") config = WidgetConfig.get(view="tab", xml=config_xml) my.config.insert_config(0, config) my.skipped_element_names = [] # if there is a layout view, then find the element names using that layout_view = my.kwargs.get("layout_view") if layout_view: layout_view = layout_view.replace("/", ".") search = Search("config/widget_config") search.add_filter("view", layout_view) layout_config = search.get_sobject() xml = layout_config.get_xml_value("config") my.element_names = xml.get_values("config//html//element/@name") else: my.element_names = my.config.get_element_names() ignore = my.kwargs.get("ignore") if isinstance(ignore, basestring): ignore = ignore.split("|") if not ignore: ignore = [] my.element_titles = [] my.element_descriptions = [] for element_name in my.element_names: my.element_titles.append( my.config.get_element_title(element_name) ) my.element_descriptions.append( my.config.get_element_description(element_name) ) #my.element_titles = my.config.get_element_titles() #my.element_descriptions = my.config.get_element_descriptions() # MongoDb # Default columns if not my.element_names: impl = SearchType.get_database_impl_by_search_type(my.search_type) if impl.get_database_type() == "MongoDb": my.element_names = impl.get_default_columns() my.element_titles = ['Code', 'Name', 'Description'] my.element_descriptions = ['Code', 'Name', 'Description'] my.input_prefix = my.kwargs.get('input_prefix') if not my.input_prefix: my.input_prefix = 'edit' security = Environment.get_security() default_access = "edit" project_code = Project.get_project_code() for i, element_name in enumerate(my.element_names): if element_name in ignore: my.skipped_element_names.append(element_name) continue # check security access access_key2 = { 'search_type': my.search_type, 'project': project_code } access_key1 = { 'search_type': my.search_type, 'key': element_name, 'project': project_code } access_keys = [access_key1, access_key2] is_editable = security.check_access('element', access_keys, "edit", default=default_access) if not is_editable: my.skipped_element_names.append(element_name) continue widget = my.config.get_display_widget(element_name, kbd_handler=False) # some element could be disabled due to its data_type e.g. sql_timestamp if not widget: my.skipped_element_names.append(element_name) continue widget.set_sobject(my.sobjects[0]) default_value = default_data.get(element_name) if default_value: widget.set_value(default_value) attrs = my.config.get_element_attributes(element_name) editable = widget.is_editable() if editable: editable = attrs.get("edit") editable = editable != "false" if not editable: my.skipped_element_names.append(element_name) continue # set parent widget.set_parent_wdg(my) # set parent_key in insert mode for now if my.mode =='insert' and my.parent_key: widget.set_option('parent_key', my.parent_key) title = my.element_titles[i] if title: widget.set_title(title) my.widgets.append(widget) description = my.element_descriptions[i] widget.add_attr("title", description)
def get_display(my): is_admin_project = Project.get().is_admin() security = Environment.get_security() if is_admin_project and not security.check_access("builtin", "view_site_admin", "allow"): return Error403Wdg() # create the elements config = WidgetConfig.get(xml=my.config_xml, view="application") left_nav_handler = config.get_display_handler("left_nav") left_nav_options = config.get_display_options("left_nav") view_side_bar = None if left_nav_handler: left_nav_wdg = Common.create_from_class_path(left_nav_handler, [], left_nav_options) # caching side_bar_cache = my.get_side_bar_cache(left_nav_wdg) else: view_side_bar = False # create the main table core_table = Table() core_table.add_tbody() core_table.set_style("border: 0px; border-collapse: collapse; width: 100%;") # add a spacer row #spacer_tr = core_table.add_row() #spacer_tr.add_style("width: 100%") #td = core_table.add_cell() #td.set_style("min-height: 1px; height: 1px;") #core_table.add_cell() #core_table.add_cell() # determine if the side bar is visible if view_side_bar == None: view_side_bar = security.check_access("builtin", "view_side_bar", "allow", default='allow') # add the main cells tr, td = core_table.add_row_cell() td.add_style("padding: 0px") td.add_style("margin: 0px") # add the main resizable table from tactic.ui.container import ResizableTableWdg main_table = ResizableTableWdg() main_table.set_keep_table_size() main_table.add_style("width: 100%") td.add(main_table) left_nav_td = main_table.add_cell() if view_side_bar: left_nav_td.add_class("spt_panel") left_nav_td.add_style("padding: 0px") main_body_td = main_table.add_cell(resize=False) main_body_td.add_style("padding: 10px") main_body_td.set_style( "width: 100%; vertical-align: top; text-align: center; padding-top: 3px" ) if view_side_bar: left_nav_td.set_style( "vertical-align: top" ) # create the left navigation panel left_nav_div = DivWdg() left_nav_td.add(left_nav_div) left_nav_div.set_id("side_bar" ) # add the detail to the panel left_nav_div.add_attr("spt_class_name", left_nav_handler) for name, value in left_nav_options.items(): left_nav_div.add_attr("spt_%s" % name, value) left_nav_div.add_style("max_width: 185px") left_nav_div.add_style("width: 185px") left_nav_div.add_style("text-align: right") left_nav_div.add_style("vertical-align: top") left_nav_div.add_style("overflow: hidden") left_nav_div.add_class("spt_resizable") side_bar_inner = DivWdg() left_nav_div.add(side_bar_inner) #side_bar_inner.add_style("padding-left: 1px") side_bar_inner.add_style("width: 100%") # add side bar to nav side_bar_inner.add(side_bar_cache) left_nav_div.add_style("border-style: solid") left_nav_div.add_style("border-width: 0px 1px 0px 0px") #left_nav_div.add_color("border-color", "border") left_nav_div.add_color("border-color", "border", -10) web = WebContainer.get_web() browser = web.get_browser() if browser in ['Qt','Webkit']: min_width = "1px" else: min_width = "0px" left_nav_div.add_behavior( { 'type': 'listen', 'event_name': 'side_bar|hide_now', 'min_width': min_width, 'cbjs_action': ''' var size = bvr.src_el.getSize(); bvr.src_el.setAttribute("spt_size", size.x); bvr.src_el.setStyle("width", bvr.min_width); ''' } ) left_nav_div.add_behavior( { 'type': 'listen', 'event_name': 'side_bar|hide', 'min_width': min_width, 'cbjs_action': ''' var size = bvr.src_el.getSize(); bvr.src_el.setAttribute("spt_size", size.x); new Fx.Tween(bvr.src_el, {duration:'short'}).start('width', bvr.min_width); ''' } ) left_nav_div.add_behavior( { 'type': 'listen', 'event_name': 'side_bar|show', 'min_width': min_width, 'cbjs_action': ''' var width = bvr.src_el.getAttribute("spt_size"); if (!width) { width = 185; } if (parseInt(width) < 5) { width = 185; } //bvr.src_el.setStyle("width", width + "px"); new Fx.Tween(bvr.src_el, {duration:'short'}).start('width', bvr.min_width, width+"px"); ''' } ) left_nav_div.add_behavior( { 'type': 'listen', 'event_name': 'side_bar|toggle', 'cbjs_action': ''' var size = bvr.src_el.getSize(); if (size.x < 5) { spt.named_events.fire_event("side_bar|show", {} ); } else { spt.named_events.fire_event("side_bar|hide", {} ); } ''' } ) # create the main body panel palette = WebContainer.get_palette() color = palette.color("background2") main_body_rounded = DivWdg() main_body_inner = main_body_rounded main_body_inner.add_style("min-height: 500px") # DEBREACATED """ # add a breadcrumb breadcrumb_wdg = DivWdg() # hide the breadcrumb breadcrumb_wdg.add_style("display", "none") Container.put("breadcrumb", breadcrumb_wdg) breadcrumb_wdg.set_id("breadcrumb") breadcrumb_wdg.add_style("text-align: left") breadcrumb_wdg.add_looks( "fnt_title_3" ) main_body_inner.add(breadcrumb_wdg) """ main_body_panel = DivWdg() main_body_panel.set_id("main_body") main_body_panel.add_class("spt_main_panel") main_body_inner.add(main_body_panel) tab = MainBodyTabWdg() main_body_panel.add(tab) # TEST: NEW LAYOUT if Config.get_value("install", "layout") == "fixed": main_body_panel.add_style("margin-top: 31px") main_body_rounded.add_color("background", "background") main_body_rounded.add_style("padding: 3px 0px 0px 0px") # add the content to the main body panel try: if my.widget: tab.add(my.widget) element_name = my.widget.get_name() else: main_body_handler = config.get_display_handler("main_body") main_body_options = config.get_display_options("main_body") element_name = main_body_options.get("element_name") title = main_body_options.get("title") main_body_content = Common.create_from_class_path(main_body_handler, [], main_body_options) # get the web values from top_layout main_body_values = config.get_web_options("main_body") web = WebContainer.get_web() if isinstance(main_body_values, dict): for name, value in main_body_values.items(): web.set_form_value(name, value) main_body_content.set_name(element_name) tab.add(main_body_content, element_name, title) my.set_as_panel(main_body_panel, class_name=main_body_handler, kwargs=main_body_options) main_body_panel.add_behavior( { 'type': 'load', 'element_name': element_name, 'cbjs_action': ''' if (spt.help) spt.help.set_view(bvr.element_name); ''' } ) except Exception, e: # handle an error in the drawing buffer = my.get_buffer_on_exception() error_wdg = my.handle_exception(e) main_body_content = DivWdg() main_body_content.add(error_wdg) main_body_content = main_body_content.get_buffer_display() tab.add(main_body_content, element_name, title)
def get_element_wdg(my, xml, def_config): element_node = xml.get_node("config/tmp/element") attrs = Xml.get_attributes(element_node) element_name = attrs.get("name") widget = my.get_widget(element_name) if widget: return widget if not element_name: import random num = random.randint(0, 100000) element_name = "element%s" % num xml.set_attribute(element_node, "name", element_name) # enable an ability to have a widget only loaded once in a request if attrs.get('load_once') in ['true', True]: widgets = Container.get("CustomLayoutWdg:widgets") if widgets == None: widgets = {} Container.put("CustomLayoutWdg:widgets", widgets) else: if widgets[element_name] == True: return None widgets[element_name] = True # provide the ability to have shorthand format # ie: <element display_class="tactic.ui..." /> display_node = xml.get_node("config/tmp/element/display") if display_node is None: view = attrs.get("view") type = attrs.get("type") if type == "reference": search_type = attrs.get("search_type") my.config = WidgetConfigView.get_by_search_type(search_type, view) # check if definition has no name. Don't use element_name if not attrs.get("name"): return element_wdg = my.config.get_display_widget(element_name, extra_options=attrs) container = DivWdg() container.add(element_wdg) return container if not view: element_wdg = my.config.get_display_widget(element_name, extra_options=attrs) container = DivWdg() container.add(element_wdg) return container # look at the attributes class_name = attrs.get("display_class") if not class_name: class_name = "tactic.ui.panel.CustomLayoutWdg" display_node = xml.create_element("display") xml.set_attribute(display_node, "class", class_name) xml.append_child(element_node, display_node) for name, value in attrs.items(): # replace the spt_ in the name. # NOTE: should this be restricted to only spt_ attributes? name = name.replace("spt_", "") attr_node = xml.create_element(name) xml.set_node_value(attr_node, value) xml.append_child(display_node, attr_node) load = attrs.get("load") if load in ["async", "sequence"]: return my.get_async_element_wdg(xml, element_name, load) use_container = attrs.get('use_container') == 'true' if use_container: # DEPRECATED container = my.get_container(xml) else: container = DivWdg() # add in attribute from the element definition # DEPRECATED: does this make any sense to have this here? for name, value in attrs.items(): if name == 'name': continue container.add_style(name, value) # add the content try: view_node = xml.get_node("config/tmp/element/display/view") if view_node is not None: view = xml.get_node_value(view_node) if view.startswith("."): if my.view_folder: xml.set_node_value(view_node, "%s%s" %(my.view_folder,view)) tmp_config = WidgetConfig.get('tmp', xml=xml) configs = [] configs.append(tmp_config) # add the def_config if it exists if def_config: configs.append(def_config) config = WidgetConfigView('CustomLayoutWdg', 'tmp', configs, state=my.state) # NOTE: this doesn't work too well when we go to an abasolute # view. parent_view = my.kwargs.get("parent_view") if parent_view: parent_view = parent_view.replace(".", "/") parent_view = "%s/%s" % (parent_view, my.view) else: parent_view = my.view # NOTE: need some protection code for infinite loops includes = my.kwargs.get("include") element_wdg = config.get_display_widget(element_name, extra_options={"include":includes, "parent_view":parent_view}) element_top = element_wdg.get_top() for name, value in attrs.items(): if name == 'class': for item in value.split(" "): element_top.add_class(item) elif name == 'style': for item in value.split(";"): element_top.add_style(item) else: element_top.set_attr(name, value) # make a provision if this custom widget is in a table if my.layout: sobject = my.get_current_sobject() element_wdg.set_sobject(sobject) except Exception, e: from pyasm.widget import ExceptionWdg log = ExceptionWdg(e) element_wdg = log
def get_element_wdg(my, xml, def_config): element_node = xml.get_node("config/tmp/element") attrs = Xml.get_attributes(element_node) element_name = attrs.get("name") widget = my.get_widget(element_name) if widget: return widget if not element_name: import random num = random.randint(0, 100000) element_name = "element%s" % num xml.set_attribute(element_node, "name", element_name) # enable an ability to have a widget only loaded once in a request if attrs.get('load_once') in ['true', True]: widgets = Container.get("CustomLayoutWdg:widgets") if widgets == None: widgets = {} Container.put("CustomLayoutWdg:widgets", widgets) else: if widgets[element_name] == True: return None widgets[element_name] = True # provide the ability to have shorthand format # ie: <element display_class="tactic.ui..." /> display_node = xml.get_node("config/tmp/element/display") if display_node is None: view = attrs.get("view") type = attrs.get("type") if type == "reference": search_type = attrs.get("search_type") my.config = WidgetConfigView.get_by_search_type(search_type, view) # check if definition has no name. Don't use element_name if not attrs.get("name"): return element_wdg = my.config.get_display_widget(element_name, extra_options=attrs) container = DivWdg() container.add(element_wdg) return container class_name = attrs.get("display_class") # if no class name is defined and not view is defined look # at predefined elements if not view and not class_name: element_wdg = my.config.get_display_widget(element_name, extra_options=attrs) container = DivWdg() container.add(element_wdg) return container # look at the attributes if not class_name: class_name = "tactic.ui.panel.CustomLayoutWdg" display_node = xml.create_element("display") xml.set_attribute(display_node, "class", class_name) xml.append_child(element_node, display_node) for name, value in attrs.items(): # replace the spt_ in the name. # NOTE: should this be restricted to only spt_ attributes? name = name.replace("spt_", "") attr_node = xml.create_element(name) xml.set_node_value(attr_node, value) xml.append_child(display_node, attr_node) load = attrs.get("load") if load in ["async", "sequence"]: return my.get_async_element_wdg(xml, element_name, load) use_container = attrs.get('use_container') == 'true' if use_container: # DEPRECATED container = my.get_container(xml) else: container = DivWdg() # add in attribute from the element definition # DEPRECATED: does this make any sense to have this here? for name, value in attrs.items(): if name == 'name': continue container.add_style(name, value) # add the content try: view_node = xml.get_node("config/tmp/element/display/view") if view_node is not None: view = xml.get_node_value(view_node) if view.startswith("."): if my.view_folder: xml.set_node_value(view_node, "%s%s" %(my.view_folder,view)) tmp_config = WidgetConfig.get('tmp', xml=xml) configs = [] configs.append(tmp_config) # add the def_config if it exists if def_config: configs.append(def_config) config = WidgetConfigView('CustomLayoutWdg', 'tmp', configs, state=my.state) # NOTE: this doesn't work too well when we go to an abasolute # view. parent_view = my.kwargs.get("parent_view") if parent_view: parent_view = parent_view.replace(".", "/") parent_view = "%s/%s" % (parent_view, my.view) else: parent_view = my.view # NOTE: need some protection code for infinite loops includes = my.kwargs.get("include") element_wdg = config.get_display_widget(element_name, extra_options={"include":includes, "parent_view":parent_view}) element_top = element_wdg.get_top() for name, value in attrs.items(): if name == 'class': for item in value.split(" "): element_top.add_class(item) elif name == 'style': for item in re.split(";\ ?", value): element_top.add_style(item) else: element_top.set_attr(name, value) # make a provision if this custom widget is in a table if my.layout: sobject = my.get_current_sobject() element_wdg.set_sobject(sobject) except Exception, e: from pyasm.widget import ExceptionWdg log = ExceptionWdg(e) element_wdg = log
def get_display(self): top = self.top top.add_class("spt_switcher_top") ''' This supports supports two menu definitions: menu - specifies a view for SideBarWdg which will be ingected as menu config_xml - specifies menu entries. For example: <display class="tactic.ui.widget.LayoutSwitcherWdg"> <!-- config_xml --> <config> <!-- Menu item 1 --> <element name="self_tasks_default" title="My Tasks" target=spt_my_tasks_table_top"> <display class="tactic.ui.panel.ViewPanelWdg"> <search_type>sthpw/task</search_type> <show_shelf>false</show_shelf> <view>my_tasks_default</view> </display> </element> <!-- Menu item 2 --> <element ... > <display ... > </display> </element> </config> </display> target - specifies target div to load views when using "menu" kwarg use_href - updates address bar hash (this is TODO) ''' menu = self.kwargs.get("menu") config_xml = self.kwargs.get("config_xml") target = self.kwargs.get("target") #default default_layout = self.kwargs.get("default_layout") # find the save state value, if state is to be saved save_state = self.kwargs.get("save_state") if save_state in [False, 'false']: save_state = None show_first = False else: show_first = True state_value = None if save_state: state_value = WidgetSettings.get_value_by_key(save_state) elif default_layout: state_value = default_layout title = self.kwargs.get("title") if not title and state_value: title = state_value if not title: title = "Switch Layout" mode = self.kwargs.get("mode") if mode == "button": color = self.kwargs.get("color") or "default" activator = DivWdg("<button class='btn btn-%s dropdown-toggle' style='width: 160px'><span class='spt_title'>%s</span> <span class='caret'></span></button>" % (color, title)) elif mode == "div": color = self.kwargs.get("color") or "" background = self.kwargs.get("background") or "transparent" activator = DivWdg("<button class='btn dropdown-toggle' style='width: 160px; background: %s; color: %s; font-weight: bold'><span class='spt_title'>%s</span> <span class='caret'></span></button>" % (background, color, title)) else: activator = IconButtonWdg( name="Layout Switcher", icon="BS_TH_LIST") top.add(activator) activator.add_class("spt_switcher_activator") activator.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var activator = bvr.src_el; var top = activator.getParent(".spt_switcher_top"); var menu = top.getElement(".spt_switcher_menu"); if (top.hasClass("spt_selected")) { top.removeClass("spt_selected"); menu.setStyle("display", "none"); } else { top.addClass("spt_selected"); menu.setStyle("display", ""); var pos = activator.getPosition(); var button_size = activator.getSize(); var menu_size = menu.getSize(); var offset = { x: button_size.x - menu_size.x, y: button_size.y } menu.position({position: 'upperleft', relativeTo: activator, offset: offset}); spt.body.add_focus_element(menu); var pointer = menu.getElement(".spt_switcher_popup_pointer"); pointer.setStyle("margin-left", menu_size.x - button_size.x); } ''' } ) outer_wdg = DivWdg() top.add(outer_wdg) # menu_wdg menu_wdg = DivWdg() outer_wdg.add(menu_wdg) menu_wdg.add_color("color", "color") menu_wdg.add_color("background", "background") menu_wdg.add_border() menu_wdg.add_class("spt_switcher_menu") menu_wdg.add_style("display: none") menu_wdg.add_style("margin-top", "20px") menu_wdg.add_style("position", "absolute") menu_wdg.add_style("z-index", "101") menu_wdg.add_behavior( { 'type': 'mouseleave', 'cbjs_action': ''' var menu = bvr.src_el; var top = menu.getParent(".spt_switcher_top"); top.removeClass("spt_selected"); menu.setStyle("display", "none") ''' } ) border_color = menu_wdg.get_color("border") # Pointer under activator pointer_wdg = DivWdg() menu_wdg.add(pointer_wdg) pointer_wdg.add(''' <div class="spt_switcher_first_arrow_div"> </div> <div class="spt_switcher_second_arrow_div"> </div> ''') pointer_wdg.add_class("spt_switcher_popup_pointer") style = HtmlElement.style(''' .spt_switcher_menu .spt_switcher_popup_pointer { z-index: 10; position: absolute; top: -15px; right: 15px; } .spt_switcher_menu .spt_switcher_first_arrow_div { border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) %s; top: -15px; z-index: 1; border-width: 0 15px 15px; height: 0; width: 0; border-style: dashed dashed solid; left: 15px; } .spt_switcher_menu .spt_switcher_second_arrow_div{ border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #fff; z-index: 1; border-width: 0 15px 15px; height: 0; width: 0; border-style: dashed dashed solid; margin-top: -14px; position: absolute; left: 0px; top: 15px; } ''' % border_color) pointer_wdg.add(style) if menu: from tactic.ui.panel import SimpleSideBarWdg simple_sidebar = SimpleSideBarWdg(view=menu, search_type="SidebarWdg", target=target) menu_wdg.add(simple_sidebar) else: style = self.get_style() top.add(style) self.view = 'tab' config = WidgetConfig.get(view=self.view, xml=config_xml) element_names = config.get_element_names() if not element_names: outer_wdg.add_style("display: none") if not state_value: if not element_names: state_value = "" else: state_value = element_names[0] for element_name in element_names: item_div = DivWdg() menu_wdg.add(item_div) item_div.add_class("spt_switcher_item") item_div.add_class("tactic_hover") item_div.add_style("width: 100%") attrs = config.get_element_attributes(element_name) title = attrs.get("title") if not title: title = Common.get_display_title(element_name) for name, value in attrs.items(): if name in ['title', 'class']: continue item_div.add_attr(name, value) css_class = attrs.get("class") if css_class: item_div.add_class(css_class) item_div.add(title) item_div.add_attr("spt_title", title) target = attrs.get("target") if not target: target = "spt_content" display_class = config.get_display_handler(element_name) display_options = config.get_display_options(element_name) if show_first != False: if element_name == state_value: item_div.add_behavior( { 'type': 'load', 'cbjs_action': ''' bvr.src_el.click(); ''' } ) if display_class: item_div.add_behavior( { 'type': 'click_up', 'display_class': display_class, 'display_options': display_options, 'element_name': element_name, 'target': target, 'save_state': save_state, 'cbjs_action': ''' var menu_item = bvr.src_el; var top = menu_item.getParent(".spt_switcher_top"); var menu = menu_item.getParent(".spt_switcher_menu"); // Get target class var target_class = bvr.target; if (target_class.indexOf(".") != -1) { var parts = target_class.split("."); target_class = parts[1]; target_top_class = parts[0]; } else { target_top_class = null; } if (target_top_class) { var target_top = bvr.src_el.getParent("."+target_top_class); } else { var target_top = $(document.body); } var target = target_top.getElement("."+target_class); if (target) { spt.panel.load(target, bvr.display_class, bvr.display_options); } menu.setStyle("display", "none"); top.removeClass("spt_selected"); var title = bvr.src_el.getAttribute("spt_title"); var title_el = top.getElement(".spt_title"); if (title_el) title_el.innerHTML = title if (bvr.save_state) { var server = TacticServerStub.get() server.set_widget_setting(bvr.save_state, bvr.element_name); } ''' } ) return top
def init(self): # create all of the display elements if not self.config: # it shouldn't use the self.search_type_obj here as it would absorb the project info self.config = WidgetConfigView.get_by_search_type(self.search_type, self.config_base) self.element_names = self.config.get_element_names() self.element_titles = self.config.get_element_titles() # TODO: should probably be all the attrs self.element_widths = self.config.get_element_widths() simple_view = self.kwargs.get("show_simple_view") if simple_view == "true": simple_view = True else: simple_view = False self.extra_data = self.kwargs.get("extra_data") if self.extra_data and isinstance(self.extra_data, basestring): try: self.extra_data = jsonloads(self.extra_data) except: self.extra_data = self.extra_data.replace("'", '"') self.extra_data = jsonloads(self.extra_data) # go through each element name and construct the handlers for idx, element_name in enumerate(self.element_names): # check to see if these are removed for this production #if element_name in invisible_elements: # continue simple_element = None display_handler = self.config.get_display_handler(element_name) new_display_handler = self.remap_display_handler(display_handler) if new_display_handler: display_handler = new_display_handler if not display_handler: # else get it from default of this type display_handler = self.get_default_display_handler(element_name) # get the display options display_options = self.config.get_display_options(element_name) # add in extra_data if self.extra_data: for key, value in self.extra_data.items(): display_options[key] = value try: if not display_handler: element = self.config.get_display_widget(element_name) else: display_options['element_name'] = element_name element = WidgetConfig.create_widget( display_handler, display_options=display_options ) except Exception as e: from tactic.ui.common import WidgetTableElementWdg element = WidgetTableElementWdg() # FIXME: not sure why this doesn't work #from pyasm.widget import ExceptionWdg #log = ExceptionWdg(e) #element.add(log) # FIXME: not sure why this doesn't work from pyasm.widget import IconWdg icon = IconWdg("Error", IconWdg.ERROR) element.add(icon) element.add(e) # skip the empty elements like ThumbWdg if simple_element and not element.is_simple_viewable(): continue # make simple_element the element if it exists if simple_element: element = simple_element # if the element failed to create, then continue if element == None: continue element.set_name(element_name) title = self.element_titles[idx] element.set_title(title) # FIXME: this causes a circular reference which means the # Garbage collector can't clean it up # make sure the element knows about its layout engine element.set_layout_wdg(self) # TODO: should convert this to ATTRS or someting like that. Not # just width if idx >= len(self.element_widths): element.width = 150 else: element.width = self.element_widths[idx] if self.input_prefix: element.set_input_prefix(self.input_prefix) # get the display options #display_options = self.config.get_display_options(element_name) #for key in display_options.keys(): element.set_options(display_options) self.add_widget(element,element_name) # layout widgets also categorize their widgets based on type if element_name == "Filter": section_name = 'filter' else: section_name = 'default' section = self.sections.get(section_name) if not section: section = [] self.sections[section_name] = section section.append(element) # go through each widget and pass them the filter_data object from tactic.ui.filter import FilterData filter_data = FilterData.get() if not filter_data: filter_data = {} for widget in self.widgets: widget.set_filter_data(filter_data) # initialize all of the child widgets super(BaseConfigWdg,self).init()
def _get_predefined_url(cls, key, hash): # only allow people with site admin security = Environment.get_security() is_admin = security.is_admin() if not is_admin and key == "admin": return None # make some predefined fake urls if key in ["link", "tab", "admin"]: # this is called by PageNav if key == "admin": expression = "/admin/link/{link}" else: expression = "/%s/{link}" % key options = Common.extract_dict(hash, expression) link = options.get("link") if not link: return None from tactic.ui.panel import SideBarBookmarkMenuWdg personal = False if '.' in link: # put in a check to ensure this is a user parts = link.split(".") user = Environment.get_user_name() def is_personal(user, parts): '''See if parts contains period seperated form of username.''' acc = "" for part in parts: if acc == "": acc = part else: acc = "%s.%s" % (acc, part) if user == acc: return True return False personal = is_personal(user, parts) # test link security project_code = Project.get_project_code() security = Environment.get_security() keys = [ { "element": link }, { "element": "*" }, { "element": link, "project": project_code }, { "element": "*", "project": project_code } ] if not personal and not security.check_access("link", keys, "allow", default="deny"): print "Not allowed" return None # This is used to find a sub menu (?) #view = link view = "definition" config = SideBarBookmarkMenuWdg.get_config("SideBarWdg", view, personal=personal) view = config.get_element_attribute(link, 'view') if view: options['widget_key'] = 'custom_layout' options['view'] = view class_name = None else: options = config.get_display_options(link) class_name = config.get_display_handler(link) if not options: from pyasm.biz import Schema config_xml = [] config_xml.append( ''' <config> ''') config_schema = Schema.get_predefined_schema('config') SideBarBookmarkMenuWdg.get_schema_snippet("_config_schema", config_schema, config_xml) schema = Schema.get_admin_schema() SideBarBookmarkMenuWdg.get_schema_snippet("_admin_schema", schema, config_xml) config_xml.append( ''' </config> ''') xml = "".join(config_xml) from pyasm.widget import WidgetConfig schema_config = WidgetConfig.get(view="_admin_schema", xml=xml) options = schema_config.get_display_options(link) if not options: schema_config.set_view("_config_schema") options = schema_config.get_display_options(link) if not options: return None if not class_name or class_name == "LinkWdg": class_name = options.get("class_name") widget_key = options.get("widget_key") if widget_key: class_name = WidgetClassHandler().get_display_handler(widget_key) elif not class_name: class_name = 'tactic.ui.panel.ViewPanelWdg' if key in ["admin", "tab"]: use_index = "false" else: use_index = "true" if key in ['admin']: use_admin = "true" else: use_admin = "false" xml = [] xml.append('''<element admin="%s" index="%s">''' % (use_admin, use_index)) xml.append(''' <display class="%s">''' % class_name) for name, value in options.items(): xml.append("<%s>%s</%s>" % (name, value, name) ) xml.append(''' </display>''') xml.append('''</element>''') xml = "\n".join(xml) sobject = SearchType.create("config/url") sobject.set_value("url", "/%s/{value}" % key) sobject.set_value("widget", xml ) return sobject elif key == "rest": xml = '''<element widget='true'> <display class='tactic.protocol.APIRestHandler'> </display> </element>''' sobject = SearchType.create("config/url") sobject.set_value("url", "/rest") sobject.set_value("widget", xml ) return sobject else: return None
def get_display(self): top = self.top top.add_class("spt_switcher_top") ''' This supports supports two menu definitions: menu - specifies a view for SideBarWdg which will be ingected as menu config_xml - specifies menu entries. For example: <display class="tactic.ui.widget.LayoutSwitcherWdg"> <!-- config_xml --> <config> <!-- Menu item 1 --> <element name="self_tasks_default" title="My Tasks" target=spt_my_tasks_table_top"> <display class="tactic.ui.panel.ViewPanelWdg"> <search_type>sthpw/task</search_type> <show_shelf>false</show_shelf> <view>my_tasks_default</view> </display> </element> <!-- Menu item 2 --> <element ... > <display ... > </display> </element> </config> </display> target - specifies target div to load views when using "menu" kwarg use_href - updates address bar hash (this is TODO) ''' menu = self.kwargs.get("menu") config_xml = self.kwargs.get("config_xml") target = self.kwargs.get("target") #default default_layout = self.kwargs.get("default_layout") # find the save state value, if state is to be saved save_state = self.kwargs.get("save_state") if save_state in [False, 'false']: save_state = None show_first = False else: show_first = True state_value = None if save_state: state_value = WidgetSettings.get_value_by_key(save_state) elif default_layout: state_value = default_layout title = self.kwargs.get("title") if not title and state_value: title = state_value if not title: title = "Switch Layout" mode = self.kwargs.get("mode") if mode == "button": color = self.kwargs.get("color") or "default" activator = DivWdg( "<button class='btn btn-%s dropdown-toggle' style='width: 160px'><span class='spt_title'>%s</span> <span class='caret'></span></button>" % (color, title)) elif mode == "div": color = self.kwargs.get("color") or "" background = self.kwargs.get("background") or "transparent" activator = DivWdg( "<button class='btn dropdown-toggle' style='width: 160px; background: %s; color: %s; font-weight: bold'><span class='spt_title'>%s</span> <span class='caret'></span></button>" % (background, color, title)) else: activator = IconButtonWdg(name="Layout Switcher", icon="BS_TH_LIST") top.add(activator) activator.add_class("spt_switcher_activator") activator.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var activator = bvr.src_el; var top = activator.getParent(".spt_switcher_top"); var menu = top.getElement(".spt_switcher_menu"); if (top.hasClass("spt_selected")) { top.removeClass("spt_selected"); menu.setStyle("display", "none"); } else { top.addClass("spt_selected"); menu.setStyle("display", ""); var pos = activator.getPosition(); var button_size = activator.getSize(); var menu_size = menu.getSize(); var offset = { x: button_size.x - menu_size.x, y: button_size.y } menu.position({position: 'upperleft', relativeTo: activator, offset: offset}); spt.body.add_focus_element(menu); var pointer = menu.getElement(".spt_switcher_popup_pointer"); pointer.setStyle("margin-left", menu_size.x - button_size.x); } ''' }) outer_wdg = DivWdg() top.add(outer_wdg) # menu_wdg menu_wdg = DivWdg() outer_wdg.add(menu_wdg) menu_wdg.add_color("color", "color") menu_wdg.add_color("background", "background") menu_wdg.add_border() menu_wdg.add_class("spt_switcher_menu") menu_wdg.add_style("display: none") menu_wdg.add_style("margin-top", "20px") menu_wdg.add_style("position", "absolute") menu_wdg.add_style("z-index", "101") menu_wdg.add_behavior({ 'type': 'mouseleave', 'cbjs_action': ''' var menu = bvr.src_el; var top = menu.getParent(".spt_switcher_top"); top.removeClass("spt_selected"); menu.setStyle("display", "none") ''' }) border_color = menu_wdg.get_color("border") # Pointer under activator pointer_wdg = DivWdg() menu_wdg.add(pointer_wdg) pointer_wdg.add(''' <div class="spt_switcher_first_arrow_div"> </div> <div class="spt_switcher_second_arrow_div"> </div> ''') pointer_wdg.add_class("spt_switcher_popup_pointer") style = HtmlElement.style(''' .spt_switcher_menu .spt_switcher_popup_pointer { z-index: 10; position: absolute; top: -15px; right: 15px; } .spt_switcher_menu .spt_switcher_first_arrow_div { border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) %s; top: -15px; z-index: 1; border-width: 0 15px 15px; height: 0; width: 0; border-style: dashed dashed solid; left: 15px; } .spt_switcher_menu .spt_switcher_second_arrow_div{ border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #fff; z-index: 1; border-width: 0 15px 15px; height: 0; width: 0; border-style: dashed dashed solid; margin-top: -14px; position: absolute; left: 0px; top: 15px; } ''' % border_color) pointer_wdg.add(style) if menu: from tactic.ui.panel import SimpleSideBarWdg simple_sidebar = SimpleSideBarWdg(view=menu, search_type="SidebarWdg", target=target) menu_wdg.add(simple_sidebar) else: style = self.get_style() top.add(style) self.view = 'tab' config = WidgetConfig.get(view=self.view, xml=config_xml) element_names = config.get_element_names() if not element_names: outer_wdg.add_style("display: none") if not state_value: if not element_names: state_value = "" else: state_value = element_names[0] for element_name in element_names: item_div = DivWdg() menu_wdg.add(item_div) item_div.add_class("spt_switcher_item") item_div.add_class("tactic_hover") item_div.add_style("width: 100%") attrs = config.get_element_attributes(element_name) title = attrs.get("title") if not title: title = Common.get_display_title(element_name) for name, value in attrs.items(): if name in ['title', 'class']: continue item_div.add_attr(name, value) css_class = attrs.get("class") if css_class: item_div.add_class(css_class) item_div.add(title) item_div.add_attr("spt_title", title) target = attrs.get("target") if not target: target = "spt_content" display_class = config.get_display_handler(element_name) display_options = config.get_display_options(element_name) if show_first != False: if element_name == state_value: item_div.add_behavior({ 'type': 'load', 'cbjs_action': ''' bvr.src_el.click(); ''' }) if display_class: item_div.add_behavior({ 'type': 'click_up', 'display_class': display_class, 'display_options': display_options, 'element_name': element_name, 'target': target, 'save_state': save_state, 'cbjs_action': ''' var menu_item = bvr.src_el; var top = menu_item.getParent(".spt_switcher_top"); var menu = menu_item.getParent(".spt_switcher_menu"); // Get target class var target_class = bvr.target; if (target_class.indexOf(".") != -1) { var parts = target_class.split("."); target_class = parts[1]; target_top_class = parts[0]; } else { target_top_class = null; } if (target_top_class) { var target_top = bvr.src_el.getParent("."+target_top_class); } else { var target_top = $(document.body); } var target = target_top.getElement("."+target_class); if (target) { spt.panel.load(target, bvr.display_class, bvr.display_options); } menu.setStyle("display", "none"); top.removeClass("spt_selected"); var title = bvr.src_el.getAttribute("spt_title"); var title_el = top.getElement(".spt_title"); if (title_el) title_el.innerHTML = title if (bvr.save_state) { var server = TacticServerStub.get() server.set_widget_setting(bvr.save_state, bvr.element_name); } ''' }) return top
def __init__(my): key = "WidgetClassHandler:config" my.config = Container.get(key) if my.config != None: return base_config = ''' <config> <widget_definition> <element name='simple'> <display class='tactic.ui.common.SimpleTableElementWdg'/> </element> <element name='default'> <display class='tactic.ui.common.SimpleTableElementWdg'/> </element> <element name='raw_data' help='main'> <display class='tactic.ui.common.RawTableElementWdg'/> </element> <element name='format' help='format-element-wdg'> <display class='tactic.ui.table.FormatElementWdg'/> </element> <element name='expression' help='search'> <display class='tactic.ui.table.ExpressionElementWdg'/> </element> <element name='expression_value' help='expression-value-element-wdg'> <display class='tactic.ui.table.ExpressionValueElementWdg'/> </element> <element name='link' help='link-element-wdg'> <display class='tactic.ui.table.LinkElementWdg'/> </element> <element name='completion' help='task-completion-wdg'> <display class='tactic.ui.table.TaskCompletionWdg'/> </element> <element name='gantt' help='gantt-wdg'> <display class='tactic.ui.table.GanttElementWdg'/> </element> <element name='button'> <display class='tactic.ui.table.ButtonElementWdg'/> </element> <element name='custom_layout' help='custom-layout-wdg'> <!-- <display class='tactic.ui.panel.CustomLayoutWdg'/> --> <display class='tactic.ui.table.CustomLayoutElementWdg'/> </element> <element name='freeform_layout'> <display class='tactic.ui.table.FreeFormLayoutElementWdg'/> </element> <element name='delete'> <display class='tactic.ui.table.DeleteElementWdg'/> </element> <element name='edit_layout'> <display class='tactic.ui.panel.EditWdg'/> </element> <element name='table_layout'> <display class='tactic.ui.panel.TableLayoutWdg'/> </element> <element name='fast_table_layout'> <display class='tactic.ui.panel.FastTableLayoutWdg'/> </element> <element name='tile_layout'> <display class='tactic.ui.panel.TileLayoutWdg'/> </element> <element name='fast_layout'> <display class='tactic.ui.panel.table_layout_wdg.FastTableLayoutWdg'/> </element> <element name='view_panel'> <display class='tactic.ui.panel.ViewPanelWdg'/> </element> <element name='freeform_layout'> <display class='tactic.ui.tools.freeform_layout_wdg.FreeFormLayoutWdg'/> </element> <element name='explorer'> <display class='tactic.ui.table.ExploreElementWdg'/> </element> <element name='hidden_row'> <!-- <display class='pyasm.widget.HiddenRowToggleWdg'/> --> <display class='tactic.ui.table.HiddenRowElementWdg'/> </element> <element name='text'> <!-- <display class='tactic.ui.input.TextInputWdg'/> --> <display class='pyasm.widget.TextWdg'/> </element> <element name='select'> <display class='pyasm.widget.SelectWdg'/> </element> <element name='calendar'> <display class='tactic.ui.widget.CalendarInputWdg'/> </element> <element name='calendar_time'> <display class='tactic.ui.widget.CalendarInputWdg'> <show_time>true</show_time> </display> </element> <element name='time'> <display class='tactic.ui.widget.TimeInputWdg'/> </element> <element name='color'> <display class='tactic.ui.input.ColorInputWdg'/> </element> <element name='drop_item' help='drop-element-wdg'> <display class='tactic.ui.table.DropElementWdg'/> </element> <element name='file_list'> <display class="tactic.ui.table.SObjectFilesElementWdg"/> </element> <element name='metadata'> <display class="tactic.ui.table.MetadataElementWdg"/> </element> <element name='python'> <display class="tactic.ui.table.PythonElementWdg"/> </element> </widget_definition> </config> ''' from pyasm.widget import WidgetConfig my.config = WidgetConfig.get(view='widget_definition', xml=base_config) # customize config to register widgets #path = "xxx.conf" Container.put(key, my.config)
def init(my): # create all of the display elements if not my.config: # it shouldn't use the my.search_type_obj here as it would absorb the project info my.config = WidgetConfigView.get_by_search_type( my.search_type, my.config_base) my.element_names = my.config.get_element_names() my.element_titles = my.config.get_element_titles() # TODO: should probably be all the attrs my.element_widths = my.config.get_element_widths() simple_view = my.kwargs.get("show_simple_view") if simple_view == "true": simple_view = True else: simple_view = False # go through each element name and construct the handlers for idx, element_name in enumerate(my.element_names): # check to see if these are removed for this production #if element_name in invisible_elements: # continue simple_element = None display_handler = my.config.get_display_handler(element_name) new_display_handler = my.remap_display_handler(display_handler) if new_display_handler: display_handler = new_display_handler if not display_handler: # else get it from default of this type display_handler = my.get_default_display_handler(element_name) # get the display options display_options = my.config.get_display_options(element_name) try: if not display_handler: element = my.config.get_display_widget(element_name) else: element = WidgetConfig.create_widget( display_handler, display_options=display_options) except Exception, e: from tactic.ui.common import WidgetTableElementWdg element = WidgetTableElementWdg() # FIXME: not sure why this doesn't work #from pyasm.widget import ExceptionWdg #log = ExceptionWdg(e) #element.add(log) # FIXME: not sure why this doesn't work from pyasm.widget import IconWdg icon = IconWdg("Error", IconWdg.ERROR) element.add(icon) element.add(e) # skip the empty elements like ThumbWdg if simple_element and not element.is_simple_viewable(): continue # make simple_element the element if it exists if simple_element: element = simple_element # if the element failed to create, then continue if element == None: continue element.set_name(element_name) title = my.element_titles[idx] element.set_title(title) # FIXME: this causes a circular reference which means the # Garbage collector can't clean it up # make sure the element knows about its layout engine element.set_layout_wdg(my) # TODO: should convert this to ATTRS or someting like that. Not # just width element.width = my.element_widths[idx] if my.input_prefix: element.set_input_prefix(my.input_prefix) # get the display options #display_options = my.config.get_display_options(element_name) #for key in display_options.keys(): element.set_options(display_options) my.add_widget(element, element_name) # layout widgets also categorize their widgets based on type if element_name == "Filter": section_name = 'filter' else: section_name = 'default' section = my.sections.get(section_name) if not section: section = [] my.sections[section_name] = section section.append(element)
def get_display(self): top = self.top top.add_class("spt_panel_layout_top") self.set_as_panel(top) inner = DivWdg() top.add(inner) self.view = self.kwargs.get("view") # Define some views that are pages. Pages are views that are self # contained and do not require arguments. They are often created # by users search = Search("config/widget_config") search.add_column("view") search.add_filter("category", "CustomLayoutWdg") search.add_filter("view", "pages.%", op="like") sobjects = search.get_sobjects() self.pages = SObject.get_values(sobjects, "view") config = None is_test = False if self.view: search = Search("config/widget_config") search.add_filter("category", "PanelLayoutWdg") search.add_filter("view", self.view) config = search.get_sobject() elif is_test: config_xml = ''' <config> <elements> <element name="a"> <display class="tactic.ui.panel.CustomLayoutWdg"> <view>pages.test1</view> </display> </element> <element name="b"> <display class="tactic.ui.panel.StaticTableLayoutWdg"> <search_type>sthpw/login_group</search_type> <element_names>login_group</element_names> <show_shelf>false</show_shelf> </display> </element> <element name="c"> <display class="tactic.ui.panel.CustomLayoutWdg"> <view>test.search</view> </display> </element> <element name="d"> <display class="tactic.ui.panel.StaticTableLayoutWdg"> <search_type>sthpw/login_group</search_type> <element_names>login_group</element_names> <show_shelf>false</show_shelf> </display> </element> </elements> </config> ''' config = WidgetConfig.get(view="elements", xml=config_xml) if not config: config_xml = ''' <config> <elements> </elements> </config> ''' config = WidgetConfig.get(view="elements", xml=config_xml) grid = self.kwargs.get("grid") if not grid: grid = config.get_view_attribute("grid") if grid: if isinstance(grid, basestring): grid = [int(x) for x in grid.split("x")] else: grid = (3, 1) is_owner = True table = DivWdg() inner.add(table) table.add_style("margin: 20px") table.add_style("box-sizing: border-box") if is_owner: menu = self.get_action_menu() #SmartMenu.add_smart_menu_set( top, { 'BUTTON_MENU': menu } ) element_names = config.get_element_names() index = 0 for y in range(grid[1]): row = DivWdg() table.add(row) row.add_class("row") row.add_style("box-sizing: border-box") num_cols = grid[0] size = 12 / num_cols for x in range(grid[0]): col = DivWdg() row.add(col) col.add_class("col-sm-%s" % size) col.add_style("box-sizing: border-box") col.add_style("overflow: auto") col.add_class("spt_panel_top") if is_owner: header = DivWdg() col.add(header) menu_wdg = DivWdg() header.add(menu_wdg) menu_wdg.add_style("float: right") menu_wdg.add("<i class='fa fa-bars'> </i>") menu_wdg.add_class("hand") SmartMenu.add_smart_menu_set(menu_wdg, {'BUTTON_MENU': menu}) SmartMenu.assign_as_local_activator( menu_wdg, "BUTTON_MENU", True) element = None title = None if index < len(element_names): element_name = element_names[index] #element_name = "%s,%s" % (x,y) element = config.get_display_widget(element_name) title = config.get_element_title(element_name) if not title: title = Common.get_display_title(element_name) if not element: element = DivWdg() element.add("No content") element.add_style("height: 100%") element.add_style("width: 100%") element.add_style("text-align: center") element.add_border() else: try: element = element.get_buffer_display() except: element = DivWdg() element.add("No content") element.add_style("height: 100%") element.add_style("width: 100%") element.add_style("text-align: center") element.add_border() if is_owner: if title: header.add(title) else: header.add("Panel: %s,%s" % (x, y)) col.add("<hr/>") content = DivWdg() col.add(content) content.add_class("spt_panel_content") content.add_style("min-height: 200px;") content.add(element) index += 1 if self.kwargs.get("is_refresh"): return inner else: return top
def get_display(my): my.sobject = my.get_sobject() top = DivWdg() top.add_class("spt_detail_top") top.add_color("background", "background") top.add_color("color", "color") if not my.sobject: top.add("No SObject defined for this widget") return top if my.parent: my.search_type = my.parent.get_base_search_type() my.search_key = SearchKey.get_by_sobject(my.parent) top.add_attr("spt_parent_key", my.search_key) my.pipeline_code = my.parent.get_value("pipeline_code", no_exception=True) my.full_search_type = my.parent.get_search_type() else: my.pipeline_code = my.sobject.get_value("pipeline_code", no_exception=True) my.search_type = my.sobject.get_base_search_type() my.search_key = SearchKey.get_by_sobject(my.sobject) my.full_search_type = my.sobject.get_search_type() if not my.pipeline_code: my.pipeline_code = 'default' top.add_style("text-align: left") my.set_as_panel(top) table = Table() #from tactic.ui.container import ResizableTableWdg #table = ResizableTableWdg() table.add_color("background", "background") table.add_color("color", "color") top.add(table) table.set_max_width() table.add_row() # left #td = table.add_cell(resize=False) td = table.add_cell() #td.add_style("padding: 10px") td.add_style("width: 200px") td.add_style("min-width: 200px") td.add_style("vertical-align: top") #td.add_border() #td.add_style("border-style: solid") #td.add_style("border-width: 1px 0 1px 1px") #td.add_color("border-color", "border") #td.add_color("background", "background", -10) if my.parent: code = my.parent.get_code() else: code = my.sobject.get_code() # add the tile title = DivWdg() td.add(title) title.add_gradient("background", "background3", 0, -10) title.add_style("height: 20px") title.add_style("padding: 4px") title.add_style("font-weight: bold") title.add_style("font-size: 1.4em") title.add("%s" % code) title.add_border() div = DivWdg() td.add(div) div.add_class("spt_sobject_detail_top") thumb_table = Table() div.add(thumb_table) thumb_table.add_row() thumb = ThumbWdg() # use a larger version for clearer display thumb.set_icon_type('web') # prefer to see the original image, then web thumb.set_option('image_link_order', 'main|web|.swf') thumb.set_option("detail", "false") thumb.set_option("icon_size", "100%") td = thumb_table.add_cell(thumb) td.add_style("vertical-align: top") td.add_style("width: 200px") td.add_style("padding: 20px") if my.parent: thumb.set_sobject(my.parent) else: thumb.set_sobject(my.sobject) sobject_info_wdg = my.get_sobject_info_wdg() sobject_info_wdg.add_style("width: 200px") td.add(sobject_info_wdg) if my.search_type == 'sthpw/task' and not my.parent: pass else: sobject_info_wdg = my.get_sobject_detail_wdg() td = table.add_cell() td.add(sobject_info_wdg) td.add_style("vertical-align: top") #td.add_color("background", "background", -10) td.add_style("overflow: hidden") #td.add_style("border-style: solid") #td.add_style("border-width: 1px 1px 1px 0px") #td.add_color("border-color", "border") # right td = table.add_cell() td.add_style("text-align: left") td.add_style("vertical-align: top") #td.add_color("background", "background", -10) td.add_class("spt_notes_wrapper") #td.add_border() # add the title title = DivWdg() td.add(title) title.add_gradient("background", "background3", 0, -10) title.add_style("height: 20px") title.add_style("padding: 4px") title.add_style("font-weight: bold") title.add("Notes") title.add_border() notes_div = DivWdg() td.add(notes_div) from tactic.ui.widget.discussion_wdg import DiscussionWdg discussion_wdg = DiscussionWdg(search_key=my.search_key, context_hidden=False, show_note_expand=False) notes_div.add(discussion_wdg) notes_div.add_style("min-width: 300px") notes_div.add_style("height: 200") notes_div.add_style("overflow-y: auto") notes_div.add_class("spt_resizable") # get the process if my.parent: process = my.sobject.get_value("process") else: process = '' # content tr = table.add_row() td = table.add_cell() td.add_attr("colspan", "5") #td.add_attr("colspan", "3") # create a state for tab. The tab only passes a search key # parent key search_key = SearchKey.get_by_sobject(my.sobject) parent = my.sobject.get_parent() if parent: parent_key = parent.get_search_key() else: parent_key = "" state = { 'search_key': search_key, 'parent_key': parent_key, 'process': process, } WebState.get().push(state) config_xml = my.get_config_xml() config = WidgetConfig.get(view="tab", xml=config_xml) if process: custom_view = "tab_config_%s" % process else: custom_view = "tab_config" search = Search("config/widget_config") search.add_filter("category", "TabWdg") search.add_filter("search_type", my.search_type) search.add_filter("view", custom_view) custom_config_sobj = search.get_sobject() if custom_config_sobj: custom_config_xml = custom_config_sobj.get_value("config") custom_config = WidgetConfig.get(view=custom_view, xml=custom_config_xml) config = WidgetConfigView(search_type='TabWdg', view=custom_view, configs=[custom_config, config]) #menu = my.get_extra_menu() #tab = TabWdg(config=config, state=state, extra_menu=menu) tab = TabWdg(config=config, state=state, show_add=False, show_remove=False, tab_offset=5 ) tab.add_style("margin: 0px -2px -2px -2px") td.add(tab) td.add_style("padding-top: 10px") return top
def get_display(self): search_type = self.kwargs.get("search_type") view = self.kwargs.get("view") assert search_type assert view #self.handle_search() config_xml = self.kwargs.get("config_xml") if not config_xml: config_xml = "<config/>" # extraneous variables inherited from TableLayoutWdg self.edit_permission = False top = DivWdg() top.add_class("spt_freeform_layout_top") self.set_as_panel(top) top.add_color("background", "background") top.add_color("color", "color") top.add_style("height: 100%") top.add_style("width: 100%") border_color = top.get_color("border") top.add_style("border: dashed 1px %s" % border_color) is_refresh = self.kwargs.get("is_refresh") config = WidgetConfig.get(view=view, xml=config_xml) # define canvas canvas = top canvas.add_class("spt_freeform_canvas") canvas.add_style("position: relative") self.kwargs['view'] = view element_names = config.get_element_names() view_attrs = config.get_view_attributes() canvas_height = view_attrs.get("height") if not canvas_height: canvas_height = '400px' canvas.add_style("height: %s" % canvas_height) canvas_width = view_attrs.get("width") if not canvas_width: width = '600px' canvas.add_style("width: %s" % canvas_width) if not self.sobjects: search = Search(search_type) sobject = search.get_sobject() else: sobject = self.sobjects[0] dialog_id = self.kwargs.get("dialog_id") canvas.add_behavior({ 'type': 'smart_click_up', 'search_type': search_type, 'view': view, 'bvr_match_class': 'SPT_ELEMENT_SELECT', 'cbjs_action': ''' var element = bvr.src_el; var top = bvr.src_el.getParent(".spt_freeform_top"); var attr = top.getElement(".spt_freeform_attr_top"); var element_id = element.getAttribute("spt_element_id"); var attrs = element.attrs; if (!attrs) { attrs = {}; } var class_name = 'tactic.ui.tools.freeform_layout_wdg.FreeFormAttrWdg'; var kwargs = { element_id: element_id, element_name: element.getAttribute("spt_element_name"), display_handler: element.getAttribute("spt_display_handler"), display_options: attrs } spt.panel.load(attr, class_name, kwargs); var dialog_id = '%s'; spt.show( $(dialog_id) ); ''' % dialog_id }) canvas.add_behavior({ 'type': 'load', 'cbjs_action': self.get_onload_js() }) canvas.add_behavior({ 'type': 'load', 'cbjs_action': ''' var top = bvr.src_el; spt.freeform.init(top); ''' }) for element_name in element_names: widget_div = DivWdg() canvas.add(widget_div) widget_div.add_style("position: absolute") widget_div.add_style("vertical-align: top") widget_div.add_class("SPT_ELEMENT_SELECT") widget_div.add_behavior({ 'type': 'load', 'cbjs_action': ''' bvr.src_el.makeDraggable() ''' }) el_attrs = config.get_element_attributes(element_name) height = el_attrs.get("height") if height: widget_div.add_style("height: %s" % height) width = el_attrs.get("width") if width: widget_div.add_style("width: %s" % width) display_handler = config.get_display_handler(element_name) display_options = config.get_display_options(element_name) widget_div.add_attr("spt_display_handler", display_handler) widget_div.add_behavior({ 'type': 'load', 'display_options': display_options, 'cbjs_action': ''' bvr.src_el.attrs = bvr.display_options; ''' }) try: widget = config.get_display_widget(element_name) except: continue widget.set_sobject(sobject) widget_div.add_attr("spt_element_name", element_name) widget_div.add_class("spt_element") content = DivWdg() widget_div.add(content) content.add_class("spt_element_content") content.add(widget) try: is_resizable = widget.is_resizable() except: is_resizable = False number = random.randint(0, 10000) element_id = "element%s" % number widget_div.set_attr("spt_element_id", element_id) # HACK for action button widget. This widget takes over the # mouse hover very strongly, so need some padding to have # the widget_div trigger first if isinstance(widget, ActionButtonWdg): widget_div.add_style("padding: 2px") widget_div.add_style("height: 30px") # right now, the hover behavior has to be put on each element widget_div.add_behavior({ 'type': 'hover', 'cbjs_action_over': ''' var size = bvr.src_el.getSize(); var buttons = bvr.src_el.getElement(".spt_freeform_button_top"); var buttons_size = buttons.getSize(); spt.show(buttons); if (size.y < 32) { size.y = 32; } buttons.setStyle("width", size.x + 20); buttons.setStyle("height", size.y ); buttons.setStyle("border", "solid 1px blue"); ''', 'cbjs_action_out': ''' var buttons = bvr.src_el.getElement(".spt_freeform_button_top"); spt.hide(buttons); buttons.setStyle("width", "100%") buttons.setStyle("height", "100%") ''' }) dummy = TextWdg("foo") widget_div.add(dummy) dummy.add_class("spt_foo") dummy.add_style("position: absolute") dummy.add_style("left: -100000") widget_div.add_behavior({ 'type': 'mouseover', 'cbjs_action': ''' var foo = bvr.src_el.getElement(".spt_foo"); foo.focus(); ''' }) widget_div.add_behavior({ 'type': 'mouseleave', 'cbjs_action': ''' var foo = bvr.src_el.getElement(".spt_foo"); foo.blur(); ''' }) dummy.add_behavior({ 'type': 'keyup', 'cbjs_action': ''' var keys = ['tab','enter','delete','left','right','up','down']; var key = evt.key; //console.log(key); if (keys.indexOf(key) > -1) evt.stop(); var element = bvr.src_el.getParent(".SPT_ELEMENT_SELECT"); var canvas = bvr.src_el.getParent(".spt_freeform_canvas"); var pos = element.getPosition(); var cpos = canvas.getPosition(); pos = { x: pos.x - cpos.x -1, y: pos.y - cpos.y -1 }; if (key == 'delete') { element.destroy() } var step = 1; if (evt.shift == true) { step = 10; } if (key == 'left') { pos.x = pos.x - step; } else if (key == 'right') { pos.x = pos.x + step; } else if (key == 'up') { pos.y = pos.y - step; } else if (key == 'down') { pos.y = pos.y + step; } element.position(pos); ''' }) xpos = el_attrs.get("xpos") if not xpos: xpos = '100px' widget_div.add_style("left: %s" % xpos) ypos = el_attrs.get("ypos") if not ypos: ypos = '100px' widget_div.add_style("top: %s" % ypos) buttons_div = DivWdg() widget_div.add(buttons_div) buttons_div.add_class("spt_freeform_button_top") buttons_div.add_style("display: none") buttons_div.add_style("position: absolute") buttons_div.add_style("top: 0px") buttons_div.add_style("left: -10px") buttons_div.add_style("height: 100%") buttons_div.add_style("width: 105%") buttons_div.add_class("hand") buttons_div.add_border() #icon = IconWdg('Move', icon=IconWdg.ADD) #buttons_div.add(icon) #icon.add_class("move") is_resizable = True if is_resizable: icon_div = DivWdg() icon_div.add_style("cursor: move") buttons_div.add(icon_div) icon_div.add_style("position: absolute") icon_div.add_style("bottom: 0px") icon_div.add_style("right: 0px") icon = IconWdg('Scale', icon=IconWdg.RESIZE_CORNER) icon_div.add(icon) icon_div.add_behavior({ 'type': 'drag', "drag_el": '@', "cb_set_prefix": 'spt.freeform.resize_element_drag' }) #icon.add_class("spt_resize_element") # for TableLayoutWdg?? top.add_class("spt_table_top") class_name = Common.get_full_class_name(self) top.add_attr("spt_class_name", class_name) top.add("<br clear='all'/>") icon_div = DivWdg() top.add(icon_div) icon_div.add_class("spt_resize_canvas") icon_div.add_style("cursor: nw-resize") icon_div.add_style("z-index: 1000") icon_div.add_class("spt_popup_resize") icon_div.add_style("top: %s" % canvas_height) icon_div.add_style("left: %s" % canvas_width) icon_div.add_style("margin-left: -15px") icon_div.add_style("margin-top: -15px") icon_div.add_style("position: absolute") icon_div.add_behavior({ 'type': 'drag', "drag_el": '@', "cb_set_prefix": 'spt.freeform.resize_drag' }) icon = IconWdg("Resize", IconWdg.RESIZE_CORNER) icon_div.add(icon) size_div = DivWdg() icon_div.add(size_div) size_div.add_class("spt_resize_title") size_div.add_style("display: none") size_div.add_style("margin-left: -60px") size_div.add_style("margin-top: -30px") size_div.add_style("width: 150px") return top
def get_display(my): top = my.top top.add_class("spt_switcher_top") ''' This supports supports two menu definitions: menu - specifies a view for SideBarWdg which will be ingected as menu config_xml - specifies menu entries. For example: <display class="tactic.ui.widget.LayoutSwitcherWdg"> <!-- config_xml --> <config> <!-- Menu item 1 --> <element name="my_tasks_default" title="My Tasks"> <display class="tactic.ui.panel.ViewPanelWdg"> <search_type>sthpw/task</search_type> <show_shelf>false</show_shelf> <view>my_tasks_default</view> <target>spt_my_tasks_table_top</target> </display> </element> <!-- Menu item 2 --> <element ... > <display ... > <target ... /> </display> </element> </config> </display> target - specifies target div to load views when using "menu" kwarg use_href - updates address bar hash (this is TODO) ''' menu = my.kwargs.get("menu") config_xml = my.kwargs.get("config_xml") target = my.kwargs.get("target") # TODO: use_href to go to specific layout switcher view # use_href = my.kwrags.get("use_href") # Layout switcher button displays menu and assumes right hand position of screen activator = IconButtonWdg(name="Layout Switcher", icon="BS_TH_LIST") top.add(activator) activator.add_class("spt_switcher_activator") activator.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var activator = bvr.src_el; var top = activator.getParent(".spt_switcher_top"); var menu = top.getElement(".spt_switcher_menu"); if (top.hasClass("spt_selected")) { top.removeClass("spt_selected"); menu.setStyle("display", "none"); } else { top.addClass("spt_selected"); menu.setStyle("display", ""); var pos = activator.getPosition(); var button_size = activator.getSize(); var menu_size = menu.getSize(); var offset = { x: button_size.x - menu_size.x, y: button_size.y } menu.position({position: 'upperleft', relativeTo: activator, offset: offset}); var pointer = menu.getElement(".spt_popup_pointer"); pointer.setStyle("margin-left", menu_size.x - button_size.x); } ''' }) # menu_wdg menu_wdg = DivWdg() top.add(menu_wdg) menu_wdg.add_color("background", "background") menu_wdg.add_border() menu_wdg.add_class("spt_switcher_menu") menu_wdg.add_style("display: none") menu_wdg.add_style("margin-top", "15px") menu_wdg.add_style("position", "absolute") menu_wdg.add_style("z-index", "10") menu_wdg.add_behavior({ 'type': 'mouseleave', 'cbjs_action': ''' var menu = bvr.src_el; var top = menu.getParent(".spt_switcher_top"); top.removeClass("spt_selected"); menu.setStyle("display", "none") ''' }) # Pointer under activator pointer_wdg = DivWdg() menu_wdg.add(pointer_wdg) pointer_wdg.add(''' <div class="spt_first_arrow_div"> </div> <div class="spt_second_arrow_div"> </div> ''') pointer_wdg.add_class("spt_popup_pointer") style = HtmlElement.style(''' .spt_switcher_menu .spt_popup_pointer { z-index: 10; margin-top: -15px; margin-left: 100px; } .spt_switcher_menu .spt_first_arrow_div { border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #ccc; top: -15px; z-index: 1; border-width: 0 15px 15px; height: 0; width: 0; border-style: dashed dashed solid; left: 15px; } .spt_switcher_menu .spt_second_arrow_div{ border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #fff; z-index: 1; border-width: 0 15px 15px; height: 0; width: 0; border-style: dashed dashed solid; margin-top: -14px; position: absolute; } ''') pointer_wdg.add(style) if menu: from tactic.ui.panel import SimpleSideBarWdg simple_sidebar = SimpleSideBarWdg(view=menu, search_type="SidebarWdg", target=target) menu_wdg.add(simple_sidebar) else: style = my.get_style() top.add(style) my.view = 'tab' config = WidgetConfig.get(view=my.view, xml=config_xml) element_names = config.get_element_names() for element_name in element_names: item_div = DivWdg() menu_wdg.add(item_div) item_div.add_class("spt_switcher_item") item_div.add_class("tactic_hover") attrs = config.get_element_attributes(element_name) title = attrs.get("title") if not title: title = Common.get_display_title(element_name) item_div.add(title) target = attrs.get("target") if not target: target = "spt_content" display_class = config.get_display_handler(element_name) display_options = config.get_display_options(element_name) item_div.add_behavior({ 'type': 'click_up', 'display_class': display_class, 'display_options': display_options, 'target': target, 'cbjs_action': ''' var menu_item = bvr.src_el; var top = menu_item.getParent(".spt_switcher_top"); var menu = menu_item.getParent(".spt_switcher_menu"); // Get target class var target_class = bvr.target; if (target_class.indexOf(".") != -1) { var parts = target_class.split("."); target_class = parts[1]; } var target = $(document.body).getElement("."+target_class); if (target) { spt.panel.load(target, bvr.display_class, bvr.display_options); } menu.setStyle("display", "none"); top.removeClass("spt_selected"); ''' }) return top