def get_color(my): color = Xml.get_attribute( my.node, "color" ) from pyasm.web import Palette theme = Palette.get().get_theme() if theme == 'dark': color = Common.modify_color(color, -50) return color
def get_default_task_xml(): global TASK_PIPELINE from pyasm.web import Palette palette = Palette.get() xml = Xml() xml.read_string(TASK_PIPELINE) nodes = Xml.get_nodes(xml, "pipeline/process") for node in nodes: process = Xml.get_attribute(node, "name") color = Task.get_default_color(process) Xml.set_attribute(node, "color", color) return xml.to_string()
def get_default_color(process): global default_xml global OTHER_COLORS #MTM added the if statements linked to statuses if process.title() == 'Pending': return "#d7d7d7" elif process.title() == 'Ready': return "#b2cee8" elif process.title() == 'On_Hold': return "#e8b2b8" elif process.title() == 'Client Response': return "#ddd5b8" elif process.title() == 'Internal Rejection': return "#ff0000" elif process.title() == 'External Rejection': return "#ff0000" elif process.title() == 'Failed QC': return "#ff0000" elif process.title() == 'Rejected': return "#ff0000" elif process.title() == 'Fix Needed': return "#c466a1" elif process.title() == 'In_Progress': return "#f5f3a4" elif process.title() == 'DR In_Progress': return "#d6e0a4" elif process.title() == 'BATON In_Progress': return "#c6e0a4" elif process.title() == 'Export In_Progress': return "#796999" elif process.title() == 'Need Buddy Check': return "#e3701a" elif process.title() == 'Buddy Check In_Progress': return "#1aade3" elif process.title() == 'Completed': return "#b7e0a5" node = default_xml.get_node("pipeline/process[@name='%s']" % process.title()) if node is None: return OTHER_COLORS.get(process.title()) color = default_xml.get_attribute(node, "color") if not color: color = OTHER_COLORS.get(process.title()) from pyasm.web import Palette theme = Palette.get() if theme == 'dark': color = Common.modify_color(color, -50) return color
def get_default_color(process): global default_xml global OTHER_COLORS node = default_xml.get_node("pipeline/process[@name='%s']" % process.title()) if node is None: return OTHER_COLORS.get(process.title()) color = default_xml.get_attribute(node, "color") if not color: color = OTHER_COLORS.get(process.title()) from pyasm.web import Palette theme = Palette.get() if theme == 'dark': color = Common.modify_color(color, -50) return color
def __init__(self): self.data = {} self.data['elements'] = [] palette = Palette.get() background = palette.color("background") color = palette.color("background3") self.data['bg_colour'] = background self.data['y_axis'] = { 'grid-colour': color, 'grid-visible': True, 'colour': color, } self.data['x_axis'] = { 'grid-colour': color, 'grid-visible': False, 'colour': color, }
def __init__(my): my.data = {} my.data['elements'] = [] palette = Palette.get() background = palette.color("background") color = palette.color("background3") my.data['bg_colour'] = background my.data['y_axis'] = { 'grid-colour': color, 'grid-visible': True, 'colour': color, } my.data['x_axis'] = { 'grid-colour': color, 'grid-visible': False, 'colour': color, }
def get_display(my): web = WebContainer.get_web() widget = Widget() html = HtmlElement("html") is_xhtml = False if is_xhtml: web.set_content_type("application/xhtml+xml") widget.add('''<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ''') html.add_attr("xmlns", "http://www.w3.org/1999/xhtml") #html.add_attr("xmlns:svg", "http://www.w3.org/2000/svg") # add the copyright widget.add(my.get_copyright_wdg()) widget.add(html) # create the header head = HtmlElement("head") html.add(head) head.add( '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n' ) head.add('<meta http-equiv="X-UA-Compatible" content="IE=edge"/>\n') # Add the tactic favicon head.add( '<link rel="shortcut icon" href="/context/favicon.ico" type="image/x-icon"/>' ) # add the css styling head.add(my.get_css_wdg()) # add the title in the header project = Project.get() project_code = project.get_code() project_title = project.get_value("title") if web.is_admin_page(): is_admin = " - Admin" else: is_admin = "" if project_code == 'admin': head.add("<title>TACTIC Site Admin</title>\n") else: head.add("<title>%s%s</title>\n" % (project_title, is_admin)) # add the javascript libraries head.add(JavascriptImportWdg()) # add the body body = my.body html.add(body) body.add_event('onload', 'spt.onload_startup(this)') top = my.top # Add a NOSCRIPT tag block here to provide a warning message on browsers where 'Enable JavaScript' # is not checked ... TODO: clean up and re-style to make look nicer top.add(""" <NOSCRIPT> <div style="border: 2px solid black; background-color: #FFFF99; color: black; width: 600px; height: 70px; padding: 20px;"> <img src="%s" style="border: none;" /> <b>Javascript is not enabled on your browser!</b> <p>This TACTIC powered, web-based application requires JavaScript to be enabled in order to function. In your browser's options/preferences, please make sure that the 'Enable JavaScript' option is checked on, click OK to accept the settings change, and then refresh this web page.</p> </div> </NOSCRIPT> """ % (IconWdg.get_icon_path("ERROR"))) # add the content content_div = DivWdg() top.add(content_div) Container.put("TopWdg::content", content_div) # add a dummy button for global behaviors from tactic.ui.widget import ButtonNewWdg, IconButtonWdg ButtonNewWdg(title="DUMMY", icon=IconWdg.FILM) IconButtonWdg(title="DUMMY", icon=IconWdg.FILM) # NOTE: it does not need to be in the DOM. Just needs to be # instantiated #content_div.add(button) if my.widgets: content_wdg = my.get_widget('content') else: content_wdg = Widget() my.add(content_wdg) content_div.add(content_wdg) # add a calendar wdg from tactic.ui.widget import CalendarWdg cal_wdg = CalendarWdg(css_class='spt_calendar_template_top') cal_wdg.top.add_style('display: none') content_div.add(cal_wdg) if web.is_admin_page(): from tactic_branding_wdg import TacticCopyrightNoticeWdg branding = TacticCopyrightNoticeWdg(show_license_info=True) top.add(branding) # add the admin bar security = Environment.get_security() if not web.is_admin_page() and security.check_access( "builtin", "view_site_admin", "allow"): div = DivWdg() top.add(div) top.add_style("padding-top: 21px") div.add_class("spt_admin_bar") div.add_style("height: 15px") div.add_style("padding: 3px 0px 3px 15px") #div.add_style("margin-bottom: -5px") div.add_style("position: fixed") div.add_style("top: 0px") div.add_style("left: 0px") div.add_style("opacity: 0.7") div.add_style("width: 100%") #div.add_gradient("background", "background2", 20, 10) div.add_style("background-color", "#000") div.add_style("color", "#FFF") div.add_style("z-index", "1000") div.add_class("hand") div.set_box_shadow("0px 5px 5px") # remove icon_div = DivWdg() div.add(icon_div) icon_div.add_style("float: right") icon_div.add_style("margin-right: 10px") icon_div.add_style("margin-top: -3px") icon_button = IconButtonWdg(title="Remove Admin Bar", icon=IconWdg.G_CLOSE) icon_div.add(icon_button) icon_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var parent = bvr.src_el.getParent(".spt_admin_bar"); bvr.src_el.getParent(".spt_top").setStyle("padding-top", "0px"); spt.behavior.destroy_element(parent); ''' }) div.add("<b>ADMIN >></b>") div.add_behavior({ 'type': 'listen', 'event_name': 'close_admin_bar', 'cbjs_action': ''' bvr.src_el.getParent(".spt_top").setStyle("padding-top", "0px"); spt.behavior.destroy_element(bvr.src_el); ''' }) div.add_behavior({ 'type': 'mouseover', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.85) //new Fx.Tween(bvr.src_el).start('height', "30px"); ''' }) div.add_behavior({ 'type': 'mouseout', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.7) //new Fx.Tween(bvr.src_el).start('height', "15px"); ''' }) project_code = Project.get_project_code() div.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var url = "/tactic/%s/admin/link/_startup"; window.open(url); ''' % project_code }) # Add the script editor listener load_div = DivWdg() top.add(load_div) load_div.add_behavior({ 'type': 'listen', 'event_name': 'show_script_editor', 'cbjs_action': ''' var js_popup_id = "TACTIC Script Editor"; var js_popup = $(js_popup_id); if( js_popup ) { spt.popup.toggle_display( js_popup_id, false ); } else { spt.panel.load_popup(js_popup_id, "tactic.ui.app.ShelfEditWdg", {}, {"load_once": true} ); } ''' }) # deal with the palette defined in /index which can override the palette if my.kwargs.get("hash") == (): key = "index" search = Search("config/url") search.add_filter("url", "/%s/%%" % key, "like") search.add_filter("url", "/%s" % key) search.add_where("or") url = search.get_sobject() if url: xml = url.get_xml_value("widget") palette_key = xml.get_value("element/@palette") # look up palette the expression for index from pyasm.web import Palette palette = Palette.get() palette.set_palette(palette_key) colors = palette.get_colors() colors = jsondumps(colors) script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_colors(%s); env.set_palette('%s'); ''' % (colors, palette_key)) top.add(script) env = Environment.get() client_handoff_dir = env.get_client_handoff_dir(include_ticket=False, no_exception=True) client_asset_dir = env.get_client_repo_dir() login = Environment.get_login() user_name = login.get_value("login") user_id = login.get_id() login_groups = Environment.get_group_names() # add environment information script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_project('%s'); env.set_user('%s'); env.set_user_id('%s'); var login_groups = '%s'.split('|'); env.set_login_groups(login_groups); env.set_client_handoff_dir('%s'); env.set_client_repo_dir('%s'); ''' % (Project.get_project_code(), user_name, user_id, '|'.join(login_groups), client_handoff_dir, client_asset_dir)) top.add(script) # add a global container for commonly used widgets div = DivWdg() top.add(div) div.set_id("global_container") # add in the app busy widget # find out if there is an override for this search = Search("config/url") search.add_filter("url", "/app_busy") url = search.get_sobject() if url: busy_div = DivWdg() div.add(busy_div) busy_div.add_class("SPT_PUW") busy_div.add_styles( "display: none; position: absolute; z-index: 1000") busy_div.add_class("app_busy_msg_block") busy_div.add_style("width: 300px") busy_div.add_style("height: 100px") busy_div.add_style("padding: 20px") busy_div.add_color("background", "background3") busy_div.add_border() busy_div.set_box_shadow() busy_div.set_round_corners(20) busy_div.set_attr("id", "app_busy_msg_block") # put the custom url here title_wdg = DivWdg() busy_div.add(title_wdg) title_wdg.add_style("font-size: 20px") title_wdg.add_class("spt_app_busy_title") busy_div.add("<hr/>") msg_div = DivWdg() busy_div.add(msg_div) msg_div.add_class("spt_app_busy_msg") else: from page_header_wdg import AppBusyWdg div.add(AppBusyWdg()) # popup parent popup = DivWdg() popup.set_id("popup") div.add(popup) # create another general popup popup_div = DivWdg() popup_div.set_id("popup_container") popup_div.add_class("spt_panel") popup = PopupWdg(id="popup_template", destroy_on_close=True) popup_div.add(popup) div.add(popup_div) inner_html_div = DivWdg() inner_html_div.set_id("inner_html") div.add(inner_html_div) # add in a global color from tactic.ui.input import ColorWdg color = ColorWdg() div.add(color) # add in a global notify wdg from notify_wdg import NotifyWdg widget.add(NotifyWdg()) return widget
def get_display(my): from pyasm.biz import Project security = Environment.get_security() if not security.check_access("builtin", "side_bar_schema", "allow", default="deny"): return DivWdg() section_div = LabeledHidableWdg(label="Schema Views") section_div.set_attr('spt_class_name', Common.get_full_class_name(my) ) palette = Palette.get() color = palette.color("background3") project_div = RoundedCornerDivWdg(hex_color_code=color,corner_size="10") project_div.set_dimensions( width_str='175px', content_height_str='100px' ) project = Project.get() project_code = project.get_code() project_type = project.get_type() div = DivWdg() section_div.add(project_div) project_div.add(div) # get project type schema schema = Schema.get_by_code(project_code) if schema: div.add( my.get_schema_wdg(schema) ) #if not project_type: # raise SetupException("Project type not found for this [%s]" %project_code) if project_type: schema = Schema.get_predefined_schema(project_type) if schema: div.add( my.get_schema_wdg(schema) ) schema = Schema.get_predefined_schema('config') div.add( my.get_schema_wdg(schema) ) schema = Schema.get_admin_schema() div.add( my.get_schema_wdg(schema) ) return section_div # create a fake schema project = Project.get() db_name = project.get_database() sql = DbContainer.get(db_name) tables = sql.get_tables() tables.sort() tables_str = "\n".join( ['<search_type name="%s"/>'%x for x in tables] ) # look at all of the search objects for mapped tables search = Search("sthpw/search_object") #search.add_where('''"namespace" = 'MMS' or namespace = '{project}' ''') search.add_filter("namespace", 'MMS') search.add_filter("namespace", '{project}') search.add_where("or") search_types = search.get_sobjects() #for search_type in search_types: # print "hhhh: ", search_type schema_xml = ''' <schema> %s </schema> ''' % tables_str schema = SearchType.create("sthpw/schema") schema.set_value("code", "table") schema.set_value("schema", schema_xml) #div.add( my.get_schema_wdg(schema) ) return section_div
def get_display(my): my.sobject = my.get_current_sobject() if not my.sobject: my.sobject = my.get_sobject_from_kwargs() if my.sobject and my.sobject.is_insert(): return DivWdg() if my.sobject: my.search_key = SearchKey.get_by_sobject(my.sobject) my.kwargs['search_key'] = my.search_key else: my.search_key = my.kwargs.get('search_key') html = my.kwargs.get('html') if not html: html = "" # DEPRECATED my.state = my.kwargs.get("state") my.state = BaseRefreshWdg.process_state(my.state) if not my.state: my.state = my.kwargs my.state['search_key'] = my.search_key my.view = my.kwargs.get('view') my.view = my.view.replace("/", ".") my.view_folder = "" if my.view.startswith("."): my.view_folder = my.kwargs.get("__view_folder__") if my.view_folder: my.view = "%s%s" % (my.view_folder, my.view) parts = my.view.split(".") my.view_folder = ".".join(parts[:-1]) if not my.view and not html: raise TacticException("No view defined in custom layout") # If html is not a string, then convert it? if not isinstance(html, basestring): html = str(html) my.view_attrs = {} my.category = my.kwargs.get("category") my.search_type = my.kwargs.get("search_type") my.encoding = my.kwargs.get("encoding") if not my.encoding: my.encoding = 'utf-8' my.plugin = None xml = None # if html is not provided, then get it from the config config = None if not html: if my.config != None: config = my.config else: config = my.kwargs.get("config") if not config: config = my.get_config() if not config: #div = DivWdg() #div.add("No config defined for view [%s] for custom layout" % my.view) #return div raise TacticException("No config defined for view [%s] for custom layout" % my.view) if isinstance(config, WidgetDbConfig): config_str = config.get_value("config") else: config_str = '' if config_str.startswith("<html>"): html = config_str my.def_config = None else: xml = config.get_xml() if my.def_config == None: my.def_config = my.get_def_config(xml) # get the view attributes if isinstance(config, WidgetConfigView): top_config = config.get_configs()[0] else: top_config = config view_node = top_config.get_view_node() if view_node is None: div = DivWdg("No view node found in xml. Invalid XML entry found") return div my.view_attrs = xml.get_attributes(view_node) nodes = xml.get_nodes("config/%s/html/*" % my.view) if not nodes: div = DivWdg("No definition found") return div # convert html tag to a div html = cStringIO.StringIO() for node in nodes: # unfortunately, html does not recognize <textarea/> # so we have to make sure it becomes <textarea></textarea> text = xml.to_string(node) text = text.encode('utf-8') keys = ['textarea','input'] for key in keys: p = re.compile("(<%s.*?/>)" % key) m = p.search(text) if m: for group in m.groups(): xx = group.replace("/", "") xx = "%s</%s>" % (xx, key) text = text.replace(group, xx) text = text.replace("<%s/>" % key, "<%s></%s>" % (key, key)) # add linebreaks to element tag key = 'element' # reg full tag <element><display...></element> p = re.compile(r"(<%s\b[^>]*>(?:.*?)</%s>)" % (key, key)) # short-hand tag <element/> p1 = re.compile("(</%s>|<%s.*?/>)" %(key, key)) m = p.search(text) m1 = p1.search(text) if m: for group in m.groups(): if group: text = text.replace(group, '\n%s\n'%group) if m1: for group in m1.groups(): if group: text = text.replace(group, '\n%s\n'%group) html.write(text) html = html.getvalue() my.config = config #my.def_config = config # This is unnessary? # try to get the sobject if this is in a table element widget if my.search_key: try: # this will raise an exception if it is not in a table element sobject = my.get_current_sobject() except: sobject = SearchKey.get_by_search_key(my.search_key) sobjects = [sobject] else: try: # this will raise an exception if it is not in a table element sobject = my.get_current_sobject() if sobject: sobjects = [sobject] else: sobjects = [] except: sobject = my.sobjects my.layout = my.get_layout_wdg() # preprocess using mako include_mako = my.kwargs.get("include_mako") if not include_mako: include_mako = my.view_attrs.get("include_mako") if xml: mako_node = xml.get_node("config/%s/mako" % my.view) if mako_node is not None: mako_str = xml.get_node_value(mako_node) html = "<%%\n%s\n%%>\n%s" % (mako_str, html) from pyasm.web import Palette num_palettes = Palette.num_palettes() #if include_mako in ['true', True]: if include_mako not in ['false', False]: html = html.replace("<", "<") html = html.replace(">", ">") html = my.process_mako(html) # preparse out expressions # use relative expressions - [expr]xxx[/expr] p = re.compile('\[expr\](.*?)\[\/expr\]') parser = ExpressionParser() matches = p.finditer(html) for m in matches: full_expr = m.group() expr = m.groups()[0] result = parser.eval(expr, sobjects, single=True, state=my.state) if isinstance(result, basestring): result = Common.process_unicode_string(result) else: result = str(result) html = html.replace(full_expr, result ) # use absolute expressions - [expr]xxx[/expr] p = re.compile('\[abs_expr\](.*?)\[\/abs_expr\]') parser = ExpressionParser() matches = p.finditer(html) for m in matches: full_expr = m.group() expr = m.groups()[0] result = parser.eval(expr, single=True) if isinstance(result, basestring): result = Common.process_unicode_string(result) else: result = str(result) html = html.replace(full_expr, result ) # need a top widget that can be used to refresh top = my.top my.set_as_panel(top) top.add_class("spt_custom_top") ignore_events = my.kwargs.get("ignore_events") in ['true', True] if ignore_events: top.add_style("pointer-events: none") # create the content div content = DivWdg() content.add_class("spt_custom_content") content.add_style("position: relative") if ignore_events: content.add_style("pointer-events: none") top.add(content) my.content = content is_test = Container.get("CustomLayout::is_test") if not is_test: is_test = my.kwargs.get("is_test") in [True, 'true'] if is_test: Container.put("CustomLayout::is_test", True) my.handle_is_test(content) html = my.replace_elements(html) content.add(html) if xml: my.add_behaviors(content, xml) # remove all the extra palettes created while True: extra_palettes = Palette.num_palettes() - num_palettes if extra_palettes > 0: Palette.pop_palette() else: break if my.kwargs.get("is_top") in ['true', True]: return html elif my.kwargs.get("is_refresh"): return content else: return top
def get_display(my): web = WebContainer.get_web() widget = Widget() html = HtmlElement("html") is_xhtml = False if is_xhtml: web.set_content_type("application/xhtml+xml") widget.add('''<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ''') html.add_attr("xmlns", "http://www.w3.org/1999/xhtml") #html.add_attr("xmlns:svg", "http://www.w3.org/2000/svg") # add the copyright widget.add( my.get_copyright_wdg() ) widget.add(html) # create the header head = HtmlElement("head") html.add(head) head.add('<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>\n') head.add('<meta http-equiv="X-UA-Compatible" content="IE=edge"/>\n') # Add the tactic favicon head.add('<link rel="shortcut icon" href="/context/favicon.ico" type="image/x-icon"/>') # add the css styling head.add(my.get_css_wdg()) # add the title in the header project = Project.get() project_code = project.get_code() project_title = project.get_value("title") if web.is_admin_page(): is_admin = " - Admin" else: is_admin = "" if project_code == 'admin': head.add("<title>TACTIC Site Admin</title>\n" ) else: head.add("<title>%s%s</title>\n" % (project_title, is_admin) ) # add the javascript libraries head.add( JavascriptImportWdg() ) # add the body body = my.body html.add( body ) # Add a NOSCRIPT tag block here to provide a warning message on browsers where 'Enable JavaScript' # is not checked ... TODO: clean up and re-style to make look nicer body.add( """ <NOSCRIPT> <div style="border: 2px solid black; background-color: #FFFF99; color: black; width: 600px; height: 70px; padding: 20px;"> <img src="%s" style="border: none;" /> <b>Javascript is not enabled on your browser!</b> <p>This TACTIC powered, web-based application requires JavaScript to be enabled in order to function. In your browser's options/preferences, please make sure that the 'Enable JavaScript' option is checked on, click OK to accept the settings change, and then refresh this web page.</p> </div> </NOSCRIPT> """ % ( IconWdg.get_icon_path("ERROR") ) ) # add the content if my.widgets: content_wdg = my.get_widget('content') else: content_wdg = Widget() my.add(content_wdg) body.add( content_wdg ) body.add_event('onload', 'spt.onload_startup(this)') if web.is_admin_page(): from tactic_branding_wdg import TacticCopyrightNoticeWdg branding = TacticCopyrightNoticeWdg(show_license_info=True) body.add(branding) # add the admin bar security = Environment.get_security() if not web.is_admin_page() and security.check_access("builtin", "view_site_admin", "allow"): div = DivWdg() body.add(div) body.add_style("padding-top: 21px") div.add_class("spt_admin_bar") div.add_style("height: 15px") div.add_style("padding: 3px 0px 3px 15px") #div.add_style("margin-bottom: -5px") div.add_style("position: fixed") div.add_style("top: 0px") div.add_style("left: 0px") div.add_style("opacity: 0.7") div.add_style("width: 100%") #div.add_gradient("background", "background2", 20, 10) div.add_style("background-color", "#000") div.add_style("color", "#FFF") div.add_style("z-index", "1000") div.add_class("hand") div.set_box_shadow("0px 5px 5px") # remove icon_div = DivWdg() div.add(icon_div) icon_div.add_style("float: right") icon_div.add_style("margin-right: 10px") icon_div.add_style("margin-top: -3px") icon_button = IconButtonWdg(title="Remove Admin Bar", icon=IconWdg.POPUP_WIN_CLOSE) icon_div.add(icon_button) icon_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var parent = bvr.src_el.getParent(".spt_admin_bar"); spt.behavior.destroy_element(parent); $(document.body).setStyle("padding-top", "0px"); ''' } ) div.add("<b>ADMIN >></b>") div.add_behavior( { 'type': 'listen', 'event_name': 'close_admin_bar', 'cbjs_action': ''' spt.behavior.destroy_element(bvr.src_el); $(document.body).setStyle("padding-top", "0px"); ''' } ) div.add_behavior( { 'type': 'mouseover', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.85) //new Fx.Tween(bvr.src_el).start('height', "30px"); ''' } ) div.add_behavior( { 'type': 'mouseout', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", 0.7) //new Fx.Tween(bvr.src_el).start('height', "15px"); ''' } ) project_code = Project.get_project_code() div.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var url = "/tactic/%s/link/_startup"; window.open(url); ''' % project_code } ) # Add the script editor listener load_div = DivWdg() body.add(load_div) load_div.add_behavior( { 'type': 'listen', 'event_name': 'show_script_editor', 'cbjs_action': ''' var js_popup_id = "TACTIC Script Editor"; var js_popup = $(js_popup_id); if( js_popup ) { spt.popup.toggle_display( js_popup_id, false ); } else { spt.panel.load_popup(js_popup_id, "tactic.ui.app.ShelfEditWdg", {}, {"load_once": true} ); } '''} ) # deal with the palette defined in /index which can override the palette if my.kwargs.get("hash") == (): key = "index" search = Search("config/url") search.add_filter("url", "/%s/%%"%key, "like") search.add_filter("url", "/%s"%key) search.add_where("or") url = search.get_sobject() if url: xml = url.get_xml_value("widget") palette_key = xml.get_value("element/@palette") # look up palette the expression for index from pyasm.web import Palette palette = Palette.get() palette.set_palette(palette_key) colors = palette.get_colors() colors = jsondumps(colors) script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_colors(%s); env.set_palette('%s'); ''' % (colors, palette_key) ) body.add(script) env = Environment.get() client_handoff_dir = env.get_client_handoff_dir(include_ticket=False, no_exception=True) client_asset_dir = env.get_client_repo_dir() login = Environment.get_login() user_name = login.get_value("login") user_id = login.get_id() login_groups = Environment.get_group_names() # add environment information script = HtmlElement.script(''' var env = spt.Environment.get(); env.set_project('%s'); env.set_user('%s'); env.set_user_id('%s'); var login_groups = '%s'.split('|'); env.set_login_groups(login_groups); env.set_client_handoff_dir('%s'); env.set_client_repo_dir('%s'); ''' % (Project.get_project_code(), user_name, user_id, '|'.join(login_groups), client_handoff_dir,client_asset_dir)) body.add(script) # add a global container for commonly used widgets div = DivWdg() body.add(div) div.set_id("global_container") # add in the app busy widget # find out if there is an override for this search = Search("config/url") search.add_filter("url", "/app_busy") url = search.get_sobject() if url: busy_div = DivWdg() div.add(busy_div) busy_div.add_class( "SPT_PUW" ) busy_div.add_styles( "display: none; position: absolute; z-index: 1000" ) busy_div.add_class("app_busy_msg_block") busy_div.add_style("width: 300px") busy_div.add_style("height: 100px") busy_div.add_style("padding: 20px") busy_div.add_color("background", "background3") busy_div.add_border() busy_div.set_box_shadow() busy_div.set_round_corners(20) busy_div.set_attr("id","app_busy_msg_block") # put the custom url here title_wdg = DivWdg() busy_div.add(title_wdg) title_wdg.add_style("font-size: 20px") title_wdg.add_class("spt_app_busy_title") busy_div.add("<hr/>") msg_div = DivWdg() busy_div.add(msg_div) msg_div.add_class("spt_app_busy_msg") else: from page_header_wdg import AppBusyWdg div.add( AppBusyWdg() ) # popup parent popup = DivWdg() popup.set_id("popup") div.add(popup) # create another general popup popup_div = DivWdg() popup_div.set_id("popup_container") popup_div.add_class("spt_panel") popup = PopupWdg(id="popup_template",destroy_on_close=True) popup_div.add(popup) div.add(popup_div) # popup parent inner_html_div = DivWdg() inner_html_div.set_id("inner_html") div.add(inner_html_div) # add in a global color from tactic.ui.input import ColorWdg color = ColorWdg() div.add(color) # add in a global notify wdg from notify_wdg import NotifyWdg widget.add(NotifyWdg()) return widget
def get_display(my): my.sobject = my.get_current_sobject() if not my.sobject: my.sobject = my.get_sobject_from_kwargs() if my.sobject and my.sobject.is_insert(): return DivWdg() if my.sobject: my.search_key = SearchKey.get_by_sobject(my.sobject) my.kwargs['search_key'] = my.search_key else: my.search_key = my.kwargs.get('search_key') html = my.kwargs.get('html') if not html: html = "" # DEPRECATED my.state = my.kwargs.get("state") my.state = BaseRefreshWdg.process_state(my.state) if not my.state: my.state = my.kwargs my.state['search_key'] = my.search_key my.view = my.kwargs.get('view') my.view = my.view.replace("/", ".") my.view_folder = "" if my.view.startswith("."): my.view_folder = my.kwargs.get("__view_folder__") if my.view_folder: my.view = "%s%s" % (my.view_folder, my.view) parts = my.view.split(".") my.view_folder = ".".join(parts[:-1]) if not my.view and not html: raise TacticException("No view defined in custom layout") # If html is not a string, then convert it? if not isinstance(html, basestring): html = str(html) my.view_attrs = {} my.category = my.kwargs.get("category") my.search_type = my.kwargs.get("search_type") my.encoding = my.kwargs.get("encoding") if not my.encoding: my.encoding = 'utf-8' my.plugin = None xml = None # if html is not provided, then get it from the config config = None if not html: if my.config != None: config = my.config else: config = my.kwargs.get("config") if not config: config = my.get_config() if not config: #div = DivWdg() #div.add("No config defined for view [%s] for custom layout" % my.view) #return div raise TacticException("No config defined for view [%s] for custom layout" % my.view) if isinstance(config, WidgetDbConfig): config_str = config.get_value("config") else: config_str = '' if config_str.startswith("<html>"): html = config_str my.def_config = None else: xml = config.get_xml() if my.def_config == None: my.def_config = my.get_def_config(xml) # get the view attributes if isinstance(config, WidgetConfigView): top_config = config.get_configs()[0] else: top_config = config view_node = top_config.get_view_node() if view_node is None: div = DivWdg("No view node found in xml. Invalid XML entry found") return div my.view_attrs = xml.get_attributes(view_node) nodes = xml.get_nodes("config/%s/html/*" % my.view) if not nodes: div = DivWdg("No definition found") return div # convert html tag to a div html = cStringIO.StringIO() for node in nodes: # unfortunately, html does not recognize <textarea/> # so we have to make sure it becomes <textarea></textarea> text = xml.to_string(node) text = text.encode('utf-8') keys = ['textarea','input'] for key in keys: p = re.compile("(<%s.*?/>)" % key) m = p.search(text) if m: for group in m.groups(): xx = group.replace("/", "") xx = "%s</%s>" % (xx, key) text = text.replace(group, xx) text = text.replace("<%s/>" % key, "<%s></%s>" % (key, key)) # add linebreaks to element tag key = 'element' # reg full tag <element><display...></element> p = re.compile(r"(<%s\b[^>]*>(?:.*?)</%s>)" % (key, key)) # short-hand tag <element/> p1 = re.compile("(</%s>|<%s.*?/>)" %(key, key)) m = p.search(text) m1 = p1.search(text) if m: for group in m.groups(): if group: text = text.replace(group, '\n%s\n'%group) if m1: for group in m1.groups(): if group: text = text.replace(group, '\n%s\n'%group) html.write(text) html = html.getvalue() my.config = config #my.def_config = config # This is unnessary? # try to get the sobject if this is in a table element widget if my.search_key: try: # this will raise an exception if it is not in a table element sobject = my.get_current_sobject() except: sobject = SearchKey.get_by_search_key(my.search_key) sobjects = [sobject] else: try: # this will raise an exception if it is not in a table element sobject = my.get_current_sobject() if sobject: sobjects = [sobject] else: sobjects = [] except: sobject = my.sobjects my.layout = my.get_layout_wdg() # preprocess using mako include_mako = my.kwargs.get("include_mako") if not include_mako: include_mako = my.view_attrs.get("include_mako") if xml: mako_node = xml.get_node("config/%s/mako" % my.view) if mako_node is not None: mako_str = xml.get_node_value(mako_node) html = "<%%\n%s\n%%>\n%s" % (mako_str, html) from pyasm.web import Palette num_palettes = Palette.num_palettes() #if include_mako in ['true', True]: if include_mako not in ['false', False]: html = html.replace("<", "<") html = html.replace(">", ">") html = my.process_mako(html) # preparse out expressions # use relative expressions - [expr]xxx[/expr] p = re.compile('\[expr\](.*?)\[\/expr\]') parser = ExpressionParser() matches = p.finditer(html) for m in matches: full_expr = m.group() expr = m.groups()[0] result = parser.eval(expr, sobjects, single=True, state=my.state) if isinstance(result, basestring): result = Common.process_unicode_string(result) else: result = str(result) html = html.replace(full_expr, result ) # use absolute expressions - [expr]xxx[/expr] p = re.compile('\[abs_expr\](.*?)\[\/abs_expr\]') parser = ExpressionParser() matches = p.finditer(html) for m in matches: full_expr = m.group() expr = m.groups()[0] result = parser.eval(expr, single=True) if isinstance(result, basestring): result = Common.process_unicode_string(result) else: result = str(result) html = html.replace(full_expr, result ) # need a top widget that can be used to refresh top = my.top my.set_as_panel(top) top.add_class("spt_custom_top") # create the content div content = DivWdg() content.add_class("spt_custom_content") content.add_style("position: relative") top.add(content) my.content = content is_test = Container.get("CustomLayout::is_test") if not is_test: is_test = my.kwargs.get("is_test") in [True, 'true'] if is_test: Container.put("CustomLayout::is_test", True) my.handle_is_test(content) html = my.replace_elements(html) content.add(html) if xml: my.add_behaviors(content, xml) # remove all the extra palettes created while True: extra_palettes = Palette.num_palettes() - num_palettes if extra_palettes > 0: Palette.pop_palette() else: break if my.kwargs.get("is_refresh"): return content else: return top
def get_display(self): from pyasm.biz import Project security = Environment.get_security() if not security.check_access("builtin", "side_bar_schema", "allow", default="deny"): return DivWdg() section_div = LabeledHidableWdg(label="Schema Views") section_div.set_attr('spt_class_name', Common.get_full_class_name(self) ) palette = Palette.get() color = palette.color("background3") project_div = RoundedCornerDivWdg(hex_color_code=color,corner_size="10") project_div.set_dimensions( width_str='175px', content_height_str='100px' ) project = Project.get() project_code = project.get_code() project_type = project.get_type() div = DivWdg() section_div.add(project_div) project_div.add(div) # get project type schema schema = Schema.get_by_code(project_code) if schema: div.add( self.get_schema_wdg(schema) ) #if not project_type: # raise SetupException("Project type not found for this [%s]" %project_code) if project_type: schema = Schema.get_predefined_schema(project_type) if schema: div.add( self.get_schema_wdg(schema) ) schema = Schema.get_predefined_schema('config') div.add( self.get_schema_wdg(schema) ) schema = Schema.get_admin_schema() div.add( self.get_schema_wdg(schema) ) return section_div # create a fake schema project = Project.get() db_name = project.get_database() sql = DbContainer.get(db_name) tables = sql.get_tables() tables.sort() tables_str = "\n".join( ['<search_type name="%s"/>'%x for x in tables] ) # look at all of the search objects for mapped tables search = Search("sthpw/search_object") #search.add_where('''"namespace" = 'MMS' or namespace = '{project}' ''') search.add_filter("namespace", 'MMS') search.add_filter("namespace", '{project}') search.add_where("or") search_types = search.get_sobjects() schema_xml = ''' <schema> %s </schema> ''' % tables_str schema = SearchType.create("sthpw/schema") schema.set_value("code", "table") schema.set_value("schema", schema_xml) #div.add( self.get_schema_wdg(schema) ) return section_div