示例#1
0
    def get_xmlrpc_mode_wdg(my):
        div = DivWdg()
        div.add_style("margin-top: 15px")
        div.add_style("margin-bottom: 15px")
        div.add_class("spt_xmlrpc_mode")
        div.add_style("display: none")

        div.add("Server: ")
        text = TextWdg("host")
        text.add_style("width: 300px")
        div.add(text)

        div.add("<br/>" * 2)

        div.add(
            "Each server requires an authentication that will be used to enable sending transactions to the remote server.  The remote server must have this ticket defined in order to recieve the transaction."
        )

        div.add("<br/>" * 2)
        div.add("Authentication Ticket: ")
        text = TextWdg("auth_ticket")
        text.add_style("width: 300px")
        div.add(text)

        return div
 def txtbox(my, name, val, code, old_val, width='200px', js='no'):
     txt = TextWdg(name)
     txt.add_attr('id', name)
     txt.add_attr('code', code)
     txt.add_attr('old_val', old_val)
     txt.add_style('width: %s;' % width)
     txt.set_value(val)
     if js == 'yes':
         txt.add_behavior(my.get_nums_only())
     return txt
 def txtbox(my, name, val, code, old_val, width='200px', js='no'):
     txt = TextWdg(name)
     txt.add_attr('id', name)
     txt.add_attr('code', code)
     txt.add_attr('old_val', old_val)
     txt.add_style('width: %s;' % width)
     txt.set_value(val)
     if js == 'yes':
         txt.add_behavior(my.get_nums_only())
     return txt
示例#4
0
    def get_display(my):
        assert my.load_script

        widget = DivWdg()
        widget.add_style('float', 'right')

        load_button = TextOptionBtnWdg(label='   Load   ', size='medium')
        load_button.get_top_el().add_style('float', 'left')
        load_button.get_top_el().set_id(my.LOAD_BUTTON_ID)
        load_button.add_behavior(
                {'type': "click_up",
                "cbjs_action":
                "setTimeout(function() {%s}, 200) "% my.load_script
                })
        widget.add(load_button)
        arrow_button = load_button.get_option_widget()
        #widget.add(arrow_button)
        suffix = "ASSET_LOADER_FUNCTIONS"
        menus_in = [ my.smart_menu_data ]


        SmartMenu.add_smart_menu_set( arrow_button,  menus_in)
        SmartMenu.assign_as_local_activator(arrow_button, None, True)

        #SmartMenu.attach_smart_context_menu( load_button, menus_in, False )
        x_div = FloatDivWdg("x")
        x_div.add_color('color','color')
        x_div.add_style('margin-right: 6px')
        widget.add(x_div)
        multiplier = TextWdg()
        multiplier.set_id("load_multiplier")
        multiplier.set_option("size", "1.5")
        multiplier.add_style("font-size: 0.8em")
        multiplier.add_style("float: left")
        multiplier.add_class("load_multiplier")
        widget.add( multiplier )
        return widget
示例#5
0
    def get_xmlrpc_mode_wdg(self):
        div = DivWdg()
        div.add_style("margin-top: 15px")
        div.add_style("margin-bottom: 15px")
        div.add_class("spt_xmlrpc_mode")
        div.add_style("display: none")

        div.add("Server: ")
        text = TextWdg("host")
        text.add_style("width: 300px")
        div.add(text)

        div.add("<br/>"*2)

        div.add("Each server requires an authentication that will be used to enable sending transactions to the remote server.  The remote server must have this ticket defined in order to recieve the transaction.")

        div.add("<br/>"*2)
        div.add("Authentication Ticket: ")
        text = TextWdg("auth_ticket")
        text.add_style("width: 300px")
        div.add(text)


        return div
    def get_display(my):
        from tactic_client_lib import TacticServerStub
        widget = DivWdg()
        server = TacticServerStub.get()
        allowed_groups = ['admin','audio','billing and accounts receivable','compression','compression supervisor','edeliveries','edit','edit supervisor','executives','it','machine room','machine room supervisor','management','media vault','media vault supervisor','office employees','qc','qc supervisor','sales','sales supervisor','scheduling','scheduling supervisor','senior_staff','streamz','technical services']
        sobject = None
        code = None
        user_name = None 
        do_inserted_msg = False
        table = Table() 
        table.add_attr('class','source_security_wdg')
        if 'source_code' in my.kwargs.keys():
            code = str(my.kwargs.get('source_code'))    
        if code in [None,'']:
            if 'code' in my.kwargs.keys():
                code = my.kwargs.get('code')
        if 'user_name' in my.kwargs.keys():
            user_name = my.kwargs.get('user_name')
        else:
            login = Environment.get_login()
            user_name = login.get_login()
        if 'from' in my.kwargs.keys():
            if my.kwargs.get('from') == 'insert':
                do_inserted_msg = True
                table.add_attr('from','insert')
        if not do_inserted_msg:
            table.add_attr('from','i dunno')
        group = None
        login_in_groups = server.eval("@SOBJECT(sthpw/login_in_group['login','%s']['login_group','not in','user|client'])" % user_name)
        for lg in login_in_groups:
            if not group:
                group = lg.get('login_group')
            if 'supervisor' in lg.get('login_group'): 
                group = lg.get('login_group')
        
        
        checks = server.eval("@SOBJECT(twog/source_req['source_code','%s'])" % code)
        visi = 'display: none;'
        if len(checks) > 0:
            visi = 'display: table-row;';
        if do_inserted_msg:
            table.add_row()
            inserted_row = table.add_cell('<font color="#f0000">!!!Please Enter the High Security Requirements!!!</font>')
            colspan = 2
            if group in allowed_groups:
                colspan = 3
            inserted_row.add_attr('colspan',colspan)
        top_row = table.add_row()
        top_row.add_style(visi)
        if group in allowed_groups:
            table.add_cell(' ')
        table.add_cell(' ')
        table.add_cell('Satisfied?')
        for check in checks:
            check_row = table.add_row()
            check_row.add_attr('class','row_%s' % check.get('__search_key__'))
            if group in allowed_groups:
                killer = table.add_cell(my.x_butt)
                killer.add_style('cursor: pointer;')
                killer.add_behavior(my.get_killer_behavior(check.get('__search_key__')))
            table.add_cell(check.get('requirement'))
            checkbox = CheckboxWdg('satisfied_%s' % check.get('__search_key__'))
            #checkbox.set_persistence()
            if check.get('satisfied'): 
                checkbox.set_value(True)
            else:
                checkbox.set_value(False)
            checkbox.add_behavior(my.get_change_satisfied(check.get('__search_key__')))
            table.add_cell(checkbox)
        
        table.add_row()
        if group in allowed_groups:
            table.add_cell(' ')
        req_text = TextWdg('new_source_req')
        req_text.add_style('width: 500px')
        req_text.add_behavior(my.get_insert_new_req_from_change(code, user_name))
        table.add_cell(req_text)
        add_button = table.add_cell('<input type="button" class="add_req_button" value="+"/>')
        add_button.add_behavior(my.get_insert_new_req(code, user_name))
        if do_inserted_msg:
            table.add_row()
            inserted_row = table.add_cell('<font color="#f0000">!!!Please Enter the High Security Requirements!!!</font>')
            colspan = 2
            if group in allowed_groups:
                colspan = 3
            inserted_row.add_attr('colspan',colspan)
 
        widget.add(table)
        return widget
示例#7
0
    def get_display(my):

        my.doc_mode = my.kwargs.get("doc_mode")
        path = my.kwargs.get("path")
        my.search_type = my.kwargs.get("search_type")

        my.last_path = None

        doc_key = my.kwargs.get("doc_key")
        if doc_key:
            my.doc = Search.get_by_search_key(doc_key)
            snapshot = Snapshot.get_latest_by_sobject(my.doc)
            if snapshot:
                my.last_path = snapshot.get_lib_path_by_type('main')

            path = my.doc.get_value("link")

        # TEST TEST TEST
        if not path:
            #path = "/home/apache/pdf/mongodb.txt"
            #path = "/home/apache/assets/google_docs.html"
            #path = "/home/apache/pdf/star_wars.txt"
            path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true"

            path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub"

            #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html"
            path = "/home/apache/tactic/doc/alias.json"

        if not my.search_type:
            my.search_type = "test3/shot"

        my.column = "description"

        top = my.top
        top.add_class("spt_document_top")
        my.set_as_panel(top)

        #table = Table()
        table = ResizableTableWdg()

        top.add(table)
        table.add_row()
        table.set_max_width()

        left_td = table.add_cell()
        left_td.add_style("vertical-align: top")

        title = DivWdg()
        left_td.add(title)
        title.add_style("padding: 10px")
        title.add_color("background", "background3")

        button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH)
        title.add(button)
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            spt.app_busy.show("Reloading Document");
            var top = bvr.src_el.getParent(".spt_document_top");
            spt.panel.refresh(top);
            spt.app_busy.hide();
            '''
        })
        button.add_style("float: left")

        button = IconButtonWdg(title="Save", icon=IconWdg.SAVE)
        title.add(button)
        button.add_behavior({
            'type': 'click_up',
            'cbjs_action': '''
            '''
        })
        button.add_style("float: left")

        if not my.doc_mode:
            my.doc_mode = "text"
        select = SelectWdg("doc_mode")
        select.set_option("values", "text|formatted")
        title.add(select)
        select.set_value(my.doc_mode)
        select.add_behavior({
            'type':
            'change',
            'cbjs_action':
            '''
            spt.app_busy.show("Reloading Document");
            var top = bvr.src_el.getParent(".spt_document_top");
            var value = bvr.src_el.value;
            top.setAttribute("spt_doc_mode", value);
            spt.panel.refresh(top);
            spt.app_busy.hide();
            '''
        })

        title.add("<br clear='all'/>")

        #title.add(path)

        text_wdg = DivWdg()
        text_wdg.add_class("spt_document_content")
        left_td.add(text_wdg)

        #if path.startswith("https://docs.google.com/spreadsheet"):
        #    #path = "http://www.southpawtech.com.com"
        #    text_wdg.add('''
        #    <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe>
        #    ''' % path)
        #    text_wdg.add_style("overflow-x: hidden")
        if True:

            if not my.last_path and my.doc:
                tmp_dir = Environment.get_tmp_dir()
                tmp_path = '%s/last_path.txt' % tmp_dir
                f = open(tmp_path, 'w')

                text = my.get_text(path, highlight=False)

                f.write(text)
                f.close()

                cmd = FileCheckin(my.doc, tmp_path)
                Command.execute_cmd(cmd)

            else:
                save = False
                if save:
                    # open up the last path
                    f = open(my.last_path, 'r')
                    last_text = f.read()
                    text = my.get_text(path, None, highlight=False)

                    if last_text != text:

                        tmp_dir = Environment.get_tmp_dir()
                        tmp_path = '%s/last_path.txt' % tmp_dir
                        f = open(tmp_path, 'w')
                        f.write(text)
                        f.write(text)
                        f.close()

                        cmd = FileCheckin(my.doc, tmp_path)
                        Command.execute_cmd(cmd)

                text = my.get_text(path, my.last_path)

            lines = text.split("\n")

            if my.doc_mode == "text":

                num_lines = len(lines)
                """
                line_div = HtmlElement.pre()
                text_wdg.add(line_div)
                line_div.add_style("width: 20px")
                line_div.add_style("float: left")
                line_div.add_style("text-align: right")
                line_div.add_style("opacity: 0.3")
                line_div.add_style("padding-right: 10px")
                for i in range(0, num_lines*2):
                    line_div.add(i+1)
                    line_div.add("<br/>")
                """

            if my.doc_mode == "text":
                pre = HtmlElement.pre()
                pre.add_style("white-space: pre-wrap")
            else:
                pre = DivWdg()
            pre = DivWdg()
            text_wdg.add(pre)

            text_wdg.add_style("padding: 10px 5px")
            text_wdg.add_style("max-height: 600px")
            text_wdg.add_style("overflow-y: auto")
            text_wdg.add_style("width: 600px")
            text_wdg.add_class("spt_resizable")

            pre.add_style("font-family: courier")

            if my.doc_mode == "formatted":
                pre.add(text)

            else:
                line_table = Table()
                pre.add(line_table)
                line_table.add_style("width: 100%")
                count = 1
                for line in lines:
                    #line = line.replace(" ", "&nbsp;")
                    tr = line_table.add_row()
                    if count % 2 == 0:
                        tr.add_color("background", "background", -2)

                    td = line_table.add_cell()

                    # FIXME: hacky
                    if line.startswith('''<span style='background: #CFC'>'''):
                        is_new = True
                    else:
                        td.add_style("vertical-align: top")
                        text = TextWdg()
                        text.add_style("border", "none")
                        text.add_style("text-align", "right")
                        text.add_style("width", "25px")
                        text.add_style("margin", "0 10 0 0")
                        text.add_style("opacity", "0.5")
                        text.set_value(count)
                        td.add(text)
                        count += 1
                        is_new = False

                    td = line_table.add_cell()
                    if not is_new:
                        SmartMenu.assign_as_local_activator(td, 'TEXT_CTX')
                        tr.add_class("spt_line")
                    else:
                        SmartMenu.assign_as_local_activator(td, 'TEXT_NEW_CTX')
                        tr.add_class("spt_new_line")

                    td.add_class("spt_line_content")
                    td.add(line)

            #from tactic.ui.app import AceEditorWdg
            #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px")
            #text_wdg.add(editor)

        # add a click on spt_item
        text_wdg.add_relay_behavior({
            'type':
            'mouseup',
            'bvr_match_class':
            'spt_document_item',
            'search_type':
            my.search_type,
            'cbjs_action':
            '''

            var top = bvr.src_el.getParent(".spt_document_top");
            var data_el = top.getElement(".spt_document_data");

            var search_key = bvr.src_el.getAttribute("spt_search_key");

            var class_name = 'tactic.ui.panel.ViewPanelWdg';
            var kwargs = {
                'search_type': bvr.search_type,
                'search_key': search_key,
            }
            spt.panel.load(data_el, class_name, kwargs);
            '''
        })

        # add a double click on spt_item
        bgcolor = text_wdg.get_color("background", -10)
        text_wdg.add_relay_behavior({
            'type':
            'mouseover',
            'bvr_match_class':
            'spt_document_item',
            'search_type':
            my.search_type,
            'bgcolor':
            bgcolor,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("opacity", "1.0");
            //bvr.src_el.setStyle("font-weight", "normal");
            bvr.src_el.setStyle("background", bvr.bgcolor);
            '''
        })

        # add a double click on spt_item
        text_wdg.add_relay_behavior({
            'type':
            'mouseout',
            'bvr_match_class':
            'spt_document_item',
            'search_type':
            my.search_type,
            'cbjs_action':
            '''
            bvr.src_el.setStyle("opacity", "1.0");
            //bvr.src_el.setStyle("font-weight", "bold");
            bvr.src_el.setStyle("background", "");
            '''
        })

        # add a context menu
        ctx_menu = my.get_text_context_menu()
        ctx_new_menu = my.get_text_new_context_menu()
        menus_in = {
            'TEXT_CTX': ctx_menu,
            'TEXT_NEW_CTX': ctx_new_menu,
        }
        SmartMenu.attach_smart_context_menu(text_wdg, menus_in, False)

        panel = ViewPanelWdg(search_type=my.search_type, layout="blah")

        right_td = table.add_cell()
        right_td.add_style("vertical-align: top")

        panel_div = DivWdg()
        panel_div.add_class("spt_document_data")
        right_td.add(panel_div)
        panel_div.add(panel)

        text_wdg.add_behavior({
            'type':
            'load',
            'cbjs_action':
            r'''

spt.document = {};

spt.document.selected_text = null;

spt.document.get_selected_text = function(frame)
{

    var t = '';

    if (frame) {
        var rng = frame.contentWindow.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }

    else if (window.getSelection) // FF4 with one tab open?
    {
        var rng = window.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }
    else if (document.getSelection) // FF4 with multiple tabs open?
    {
        var rng = document.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }
    else if (document.selection) // IE8
    {
        var rng = document.selection.createRange();
        // expand range to enclose any word partially enclosed in it
        rng.expand("word");
        t = rng.text;
    }

    // convert newline chars to spaces, collapse whitespace, and trim non-word chars
    return t.replace(/^\W+|\W+$/g, '');
    //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, '');
}

// expand FF range to enclose any word partially enclosed in it
spt.document.expandtoword = function(range)
{
    if (range.collapsed) {
        return;
    }

    while (range.startOffset > 0 && range.toString()[0].match(/\w/)) {
        range.setStart(range.startContainer, range.startOffset - 1);
    }

    while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/))
    {
        range.setEnd(range.endContainer, range.endOffset + 1);
    }
}
            '''
        })

        top.add_relay_behavior({
            'type':
            'mouseup',
            'bvr_match_class':
            'spt_document_content',
            'cbjs_action':
            r'''
            //spt.ace_editor.set_editor_top(bvr.src_el);
            //var text = spt.ace_editor.get_selection();
            var text = spt.document.get_selected_text();
            text = text.replace(/\n\n/mg, "\n");
            text = text.replace(/\n\n/mg, "\n");
            spt.document.selected_text = text + "";
            '''
        })

        return top
示例#8
0
    def get_display(my):
        top = my.top
        my.set_as_panel(top)
        top.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            spt.named_events.fire_event("side_bar|hide")
            '''
        } )
        top.add_style("width: 100%")
        top.add_color("background", "background", -10)
        top.add_style("padding-top: 10px")
        top.add_style("padding-bottom: 50px")
        top.add_class("spt_project_top")

        inner = DivWdg()
        top.add(inner)
        inner.add_style("width: 700px")
        inner.add_style("float: center")
        inner.add_border()
        inner.center()
        inner.add_style("padding: 30px")
        inner.add_color("background", "background")


        from tactic.ui.container import WizardWdg


        title = DivWdg()
        title.add("Create A New Project")

        wizard = WizardWdg(title=title, width="100%")
        inner.add(wizard)


        help_button = ActionButtonWdg(title="?", tip="Create Project Help", size='s')
        title.add(help_button)
        help_button.add_style("float: right")
        help_button.add_style("margin-top: -20px")
        help_button.add_style("margin-right: -10px")
        help_button.add_behavior({
            'type': 'click_up',
            'cbjs_action': '''
            spt.help.set_top();
            spt.help.load_alias("create-new-project");
            '''
        })




        info_page = DivWdg()
        wizard.add(info_page, 'Info')
        info_page.add_class("spt_project_top")
        info_page.add_style("font-size: 12px")
        info_page.add_color("background", "background")
        info_page.add_color("color", "color")
        info_page.add_style("padding: 20px")



        from tactic.ui.input import TextInputWdg

        info_page.add("<b>Project Title:</b> &nbsp;&nbsp;")
    
        text = TextWdg("project_title")
        text.add_behavior( {
            'type': 'blur',
            'cbjs_action': '''
            if (bvr.src_el.value == '') {
                spt.alert("You must enter a project title");
                return;
            }
        '''})

        #text = TextInputWdg(title="project_title")
        info_page.add(text)
        text.add_style("width: 250px")
        info_page.add(HtmlElement.br(3))
        span = DivWdg()
        info_page.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add_color("background", "background3")
        span.add("The project title can be descriptive and contain spaces and special characters.")
        info_page.add("<br/><br/><hr/><br/><br/>")
        text.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var title = bvr.src_el.value;
        if (title.length > 100) {
            spt.alert("Title cannot exceed 100 characters.");
            return;
        }
        var code = spt.convert_to_alpha_numeric(title);
        code = code.substring(0,30);
        var top = bvr.src_el.getParent(".spt_project_top");
        var code_el = top.getElement(".spt_project_code");
        code_el.value = code;
        '''
        } )


        info_page.add("<b>Project Code: &nbsp;&nbsp;</b>")
        text = TextWdg("project_code")
        #text = TextInputWdg(title="project_code")
        text.add_behavior( {
            'type': 'blur',
            'cbjs_action': '''
            var value = bvr.src_el.value;
            var code = spt.convert_to_alpha_numeric(value);
            bvr.src_el.value = code;
            
            if (code == '') {
                spt.alert("You must enter a project code.");
                return;
            }
            if (spt.input.has_special_chars(code)) {
                spt.alert("Project code cannot contain special characters.");
                return;
            }
        
            if (code.test(/^\d/)) {
                spt.alert("Project code cannot start with a number.");
                return;
            }
            if (code.length > 30) {
                 spt.alert("Project code cannot exceed 30 characters.");
                return;
            }
       
            '''
        } )


        info_page.add(text)
        text.add_style("width: 250px")
        text.add_class("spt_project_code")
        info_page.add(HtmlElement.br(4))

        span = DivWdg()
        info_page.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add_color("background", "background3")
        span.add("The project code is a very important key that will tie many components of the project together.")
        span.add("<br/><br/>")
        span.add("* Note: the project code must contain only alphanumeric characters [A-Z]/[0-9] and only an '_' as a separator")
        info_page.add(span)

        info_page.add("<br/>"*2)


        projects = Project.get_all_projects()

        info_page.add("<b>Is Main Project? </b>")

        checkbox = CheckboxWdg("is_main_project")
        default_project_code = Config.get_value("install", "default_project")
        info_page.add(checkbox)
        if default_project_code:
            default_project = Project.get_by_code(default_project_code)
        else:
            default_project = None

        if default_project:
            default_title = default_project.get_value("title")
            info_span = SpanWdg()
            info_page.add(info_span)
            info_span.add("%sCurrent: %s (%s)" % ("&nbsp;"*3, default_title, default_project_code))
            info_span.add_style("font-size: 0.9em")
            info_span.add_style("font-style: italic")
        else:
            if len(projects) == 0:
                checkbox.set_checked()

        info_page.add("<br/>"*2)

        span = DivWdg()
        info_page.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add_color("background", "background3")
        span.add("A TACTIC installation can have multiple projects, but one can be designated as the main project.  This project will appear at the root of the url. This is meant for building custom project launcher which is based on a main project.")
        span.add("<br/>"*2)
        span.add("* Note: TACTIC may need to be restarted in order for this to take effect")
        info_page.add(span)

        info_page.add("<br/>")









        # add an icon for this project
        image_div = DivWdg()
        wizard.add(image_div, 'Preview Image')
        image_div.add_class("spt_image_top")
        image_div.add_color("background", "background")
        image_div.add_color("color", "color")
        image_div.add_style("padding: 20px")


        image_div.add("<b>Project Image: </b>")
        image_div.add("<br/>"*3)
        on_complete = '''var server = TacticServerStub.get();
        var file = spt.html5upload.get_file(); 
        if (file) { 

            var top = bvr.src_el.getParent(".spt_image_top");
            var text = top.getElement(".spt_image_path");
            var display = top.getElement(".spt_path_display");
            var check_icon = top.getElement(".spt_check_icon");

            var server = TacticServerStub.get();
            var ticket = spt.Environment.get().get_ticket();


            display.innerHTML = "Uploaded: " + file.name;
            display.setStyle("padding", "10px");
            check_icon.setStyle("display", "");
          
          
            var filename = file.name;
            filename = spt.path.get_filesystem_name(filename);
            var kwargs = {
                ticket: ticket,
                filename: filename
            }
            try {
                var ret_val = server.execute_cmd("tactic.command.CopyFileToAssetTempCmd", kwargs);
                var info = ret_val.info;
                var path = info.web_path;
                text.value = info.lib_path;
                display.innerHTML = display.innerHTML + "<br/><br/><div style='text-align: center'><img style='width: 80px;' src='"+path+"'/></div>";
            }
            catch(e) {
                spt.alert(spt.exception.handler(e));
            }
            spt.app_busy.hide();
            }
        else {
            spt.alert('Error: file object cannot be found.') 
        }
            spt.app_busy.hide();
        '''
        button = UploadButtonWdg(title="Browse", on_complete=on_complete) 
        button.add_style("margin-left: auto")
        button.add_style("margin-right: auto")
        image_div.add(button)


        text = HiddenWdg("project_image_path")
        text.add_class("spt_image_path")
        image_div.add(text)

        check_div = DivWdg()
        image_div.add(check_div)
        check_div.add_class("spt_check_icon")
        check_icon = IconWdg("Image uploaded", IconWdg.CHECK)
        check_div.add(check_icon)
        check_div.add_style("display: none")
        check_div.add_style("float: left")
        check_div.add_style("padding-top: 8px")

        path_div = DivWdg()
        image_div.add(path_div)
        path_div.add_class("spt_path_display")

        image_div.add(HtmlElement.br(3))
        span = DivWdg()
        image_div.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add_color("background", "background3")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add("The project image is a small image that will be used in various places as a visual representation of this project.")

        info_page.add("<br/><br/>")





        # get all of the template projects that are installed
        copy_div = DivWdg()
        wizard.add(copy_div, "Template")
        copy_div.add_style("padding-top: 20px")





        template = ActionButtonWdg(title="Manage", tip="Manage Templates")
        copy_div.add(template)
        template.add_style("float: right")
        template.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
                var class_name = 'tactic.ui.app.ProjectTemplateWdg'
                spt.panel.load_popup("Templates", class_name)
            '''
        } )
        template.add_style("margin-top: -5px")




        copy_div.add("<b>Copy From Template: &nbsp;&nbsp;</b>")



        search = Search("sthpw/project")
        search.add_filter("is_template", True)
        template_projects = search.get_sobjects()
        values = [x.get_value("code") for x in template_projects]
        labels = [x.get_value("title") for x in template_projects]


        # find all of the template projects installed
        template_dir = Environment.get_template_dir()
        import os
        if not os.path.exists(template_dir):
            paths = []
        else:
            paths = os.listdir(template_dir);


            file_values = []
            file_labels = []
            for path in paths:
                if path.endswith("zip"):
                    orig_path = '%s/%s'%(template_dir, path)
                    path = path.replace(".zip", "")
                    parts = path.split("-")
                    plugin_code = parts[0]

                    # skip if there is a matching project in the database
                    #match_project = plugin_code.replace("_template", "")
                    
                    match_project = plugin_code
                    old_style_plugin_code = re.sub( '_template$', '', plugin_code)

                    if match_project in values:
                        continue
                    elif old_style_plugin_code in values:
                        continue

                    label = "%s (from file)" % Common.get_display_title(match_project)

                    # for zip file, we want the path as well
                    value = '%s|%s'%(plugin_code, orig_path)
                    file_values.append(value)
                    file_labels.append(label)

            if file_values:
                values.extend(file_values)
                labels.extend(file_labels)


        values.insert(0, "_empty")
        labels.insert(0, "- Empty Project -")

        select = SelectWdg("project_source")
        copy_div.add(select)
        select.set_option("values", values)
        select.set_option("labels", labels)
        #select.add_empty_option("-- Select --")

        select.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        var top = bvr.src_el.getParent(".spt_project_top");
        var type = top.getElement(".spt_custom_project_top");
        var namespace_option = top.getElement(".spt_custom_namespace_top");

        var theme_el = top.getElement(".spt_theme_top");

        if (bvr.src_el.value == "_empty") {
            spt.show(type);
            spt.show(namespace_option);

            spt.show(theme_el);

        }
        else {
            spt.hide(type);
            spt.hide(namespace_option);

            spt.hide(theme_el);
        }
        '''
        } )



        copy_div.add(HtmlElement.br(3))
        span = DivWdg()
        copy_div.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add_color("background", "background3")
        span.add("This will use the selected project template as a basis and copy all of the configuration elements.  Only template projects should be copied.")

        #copy_div.add(HtmlElement.br(2))
        #span = DivWdg("This will create an empty project with no predefined configuration.")
        #copy_div.add(span)

        #
        # Theme
        #
        theme_div = DivWdg()
        theme_div.add_class("spt_theme_top")
        theme_div.add_style("padding: 10px")
        theme_div.add_style("margin-top: 20px")
        copy_div.add(theme_div)
        theme_div.add("<b>Theme: </b>&nbsp; ")
        theme_div.add_style('padding-right: 6px')

        theme_select = SelectWdg('project_theme')
        theme_div.add(theme_select)



        # look in the plugins for all of the themes?
        from pyasm.biz import PluginUtil
        plugin_util = PluginUtil()
        data = plugin_util.get_plugins_data("theme")

        builtin_dir = Environment.get_builtin_plugin_dir()
        plugin_util = PluginUtil(base_dir=builtin_dir)

        data2 = plugin_util.get_plugins_data("theme")


        data = dict(data.items() + data2.items())

        themes = data.keys()
        themes.sort()




        theme_select.set_option("values", themes)
        theme_select.add_empty_option('- No Theme -')
        default_theme = "TACTIC/default_theme"
        theme_select.set_value(default_theme)

        theme_select.add_behavior( {
            'type': 'change',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_project_top");
            var img_div = top.getElement(".spt_project_theme_div");
            var theme = bvr.src_el.value;

            var img_els = img_div.getElements(".spt_project_theme_image");
            for (var i = 0; i < img_els.length; i++) {
                if (theme == img_els[i].getAttribute("spt_theme") ) {
                    img_els[i].setStyle("display", "");
                }
                else {
                    img_els[i].setStyle("display", "none");
                }
            }
            '''
        } )

        theme_img_div = DivWdg()
        theme_div.add(theme_img_div)
        theme_img_div.add_class("spt_project_theme_div")

        for theme in themes:
            theme_item = DivWdg()
            theme_item.add_style("margin: 15px")
            theme_img_div.add(theme_item)
            theme_item.add_attr("spt_theme", theme)
            theme_item.add_class("spt_project_theme_image")
            if theme != default_theme:
                theme_item.add_style("display: none")

            table = Table()
            theme_item.add(table)
            table.add_row()

            if Environment.is_builtin_plugin(theme):
                theme_img = HtmlElement.img(src="/tactic/builtin_plugins/%s/media/screenshot.jpg" % theme)
            else:
                theme_img = HtmlElement.img(src="/tactic/plugins/%s/media/screenshot.jpg" % theme)
            theme_img.add_border()
            theme_img.set_box_shadow("1px 1px 1px 1px")
            theme_img.add_style("margin: 20px 10px")
            theme_img.add_style("width: 240px")

            plugin_data = data.get(theme)

            description = plugin_data.get("description")
            if not description:
                description = "No Description"

            table.add_cell(theme_img)
            table.add_cell( description )



        theme_img_div.add_style("text-align: center")
        theme_img_div.add_style("margin: 10px")

 

        #
        # namespace
        #
        ns_div = DivWdg()
        ns_div.add_class("spt_custom_namespace_top")
        ns_div.add_style("padding: 10px")
        copy_div.add(ns_div)
        ns_div.add("<br/>")
        ns = HtmlElement.b("Namespace:")
        ns.add_style('padding-right: 6px')
        ns_div.add(ns)

        text = TextWdg('custom_namespace')
        text.add_class("spt_custom_namespace")
        text.add_behavior( {
            'type': 'blur',
            'cbjs_action': '''
                 var project_namespace = bvr.src_el.value;
                 if (['sthpw','prod'].contains(project_namespace)) 
                    spt.alert('Namespace [' + project_namespace + '] is reserved.');

                 if (project_namespace.strip()=='') 
                    spt.alert('A "default" namespace will be used if you leave it empty.');
            
            '''})

        ns_div.add(text)

        hint = HintWdg('This will be used as the prefix for your sTypes. You can use your company name for instance')
        ns_div.add(hint)

        # is_template
        is_template_div = DivWdg()
        #is_template_div.add_style('display: none')

        is_template_div.add_class("spt_custom_project_top")
        is_template_div.add_style("padding: 10px")
        copy_div.add(is_template_div)
        is_template_div.add("<br/>")
        is_template_div.add("<b>Is this project a template: </b>")

        text = CheckboxWdg("custom_is_template")
        text.add_class("spt_custom_is_template")
        is_template_div.add(text)

        is_template_div.add(HtmlElement.br(2))
        span = DivWdg("Template projects are used as a blueprint for generating new projects.")
        is_template_div.add(span)



        # Disabling for now ... advanced feature and may not be necessary
        #stypes_div = my.get_stypes_div()
        #is_template_div.add(stypes_div)








        last_page = DivWdg()
        wizard.add(last_page, "Complete")

        last_page.add_style("padding-top: 80px")
        last_page.add_style("padding-left: 30px")

        cb = RadioWdg('jump_project', label='Jump to New Project')
        cb.set_option("value", "project")
        #cb.set_option('disabled','disabled')
        cb.set_checked()
        last_page.add(cb)

        last_page.add(HtmlElement.br(2))

        cb = RadioWdg('jump_project', label='Jump to Project Admin')
        cb.set_option("value", "admin")
        last_page.add(cb)


        last_page.add(HtmlElement.br(2))

        cb = RadioWdg('jump_project', label='Create Another Project')
        cb.set_option("value", "new")
        last_page.add(cb)




        last_page.add(HtmlElement.br(5))


        button_div = DivWdg()

        create_button = ActionButtonWdg(title="Create >>", tip="Create new project")
        wizard.add_submit_button(create_button)
        #button_div.add(create_button)
        create_button.add_style("float: right")

        create_button.add_behavior({
        'type': "click_up",
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_project_top");
        var values = spt.api.Utility.get_input_values(top, null, null, null, {cb_boolean: true});

        var project_code = values['project_code'][0];
        if (project_code == '') {
            spt.alert("You must enter a project code.");
            return;
        }
        if (spt.input.has_special_chars(project_code)) {
            spt.alert("Project code cannot contain special characters.");
            return;
        }
        
        if (project_code.test(/^\d/)) {
            spt.alert("Project code cannot start with a number.");
            return;
        }
        if (values['project_title'] == '') {
            spt.alert("You must enter a project title");
            return;
        }

        var project_source = values.project_source[0];

        var project_image_path = values['project_image_path'][0];

        var project_theme = values['project_theme'][0];

        var options = {
            'project_code': project_code,
            'project_title': values['project_title'][0],
            'project_image_path': project_image_path,
            'project_theme': project_theme,
        }

        //'copy_pipelines': values['copy_pipelines'][0]

        var class_name;
        var busy_title;
        var busy_msg;
        var use_transaction;
        if (project_source == '') {
            spt.alert("Please select a template to copy or select create an empty project");
            return;
        }
        else if (project_source != '_empty') {
            busy_title = "Copying Project"; 
            busy_msg = "Copying project ["+project_source+"] ...";
            use_transaction = false;

            class_name = 'tactic.command.ProjectTemplateInstallerCmd';
            if (project_source.test(/\|/)) {
                var tmps = project_source.split('|');
                project_source = tmps[0];
                var path = tmps[1];
                options['path'] = path;
            }
            options['template_code'] = project_source;
            options['force_database'] = true;

        }
        else {
            class_name = "tactic.command.CreateProjectCmd";
            busy_title = "Creating New Project"; 
            busy_msg = "Creating new project based on project info ...";
            use_transaction = true;

            // use project code as the project type if namespace is not specified
            var project_namespace = values['custom_namespace'][0];
            if (['sthpw','prod'].contains(project_namespace)) {
                spt.alert('Namespace [' + project_namespace + '] is reserved.');
                return;
            }
            options['project_type'] =  project_namespace ? project_namespace : project_code
            var is_template = values['custom_is_template'];
            if (is_template) {
                options['is_template'] = is_template[0];
            }
            // This has been commented out in the UI
            //options['project_stype'] = values['project_stype'].slice(1);


            var is_main_project = values['is_main_project'];
            if (is_main_project) {
                options['is_main_project'] = is_main_project[0];
            }

        }

        // Display app busy pop-up until create project command
        // has completed executing.
        spt.app_busy.show( busy_title, busy_msg ); 

        setTimeout( function() {

            var ret_val = '';
            var server = TacticServerStub.get();
            try {
                ret_val = server.execute_cmd(class_name, options, {}, {use_transaction: true});
            }
            catch(e) {
                spt.app_busy.hide();
                spt.alert("Error: " + spt.exception.handler(e));
                return;
                throw(e);
            }
            spt.api.Utility.clear_inputs(top);

            // show feedback at the end
            var jump = values['jump_project'][0];
            if (jump == 'project' || jump == 'admin') {
                var location;
                if (jump == 'admin') {
                    location = "/tactic/" + project_code + "/admin";
                }
                else if (project_theme) {
                    location = "/tactic/" + project_code + "/";
                }
                else {
                    location = "/tactic/" + project_code + "/admin/link/_startup";
                }
                setTimeout( function() {
                    document.location = location;
                    }, 1000);
            }
            else { 
                // Refresh header
                spt.panel.refresh(top);
                setTimeout( function() {
                    spt.panel.refresh('ProjectSelectWdg');
                }, 2800);


                spt.app_busy.hide();
            }

            // don't hide because it gives the false impression that nothing
            // happened as it waits for the timeout
            //spt.app_busy.hide();
        }, 0 );

        '''


        })


        cancel_script = my.kwargs.get("cancel_script")
        if cancel_script:
            cancel_button = ActionButtonWdg(title="Cancel")
            cancel_button.add_style("float: left")

            cancel_button.add_behavior({
                'type': "click_up",
                'cbjs_action': cancel_script
            })

            button_div.add(cancel_button)

            create_button.add_style("margin-right: 15px")
            create_button.add_style("margin-left: 75px")


        button_div.add("<br clear='all'/>")

        last_page.add(button_div)


        inner.add(HtmlElement.br())
   
        return top
示例#9
0
    def get_set_limit_wdg(my):
        limit_content = DivWdg()
        limit_content.add_style("font-size: 10px")
        #limit_content.add_style("padding", "5px")
        #limit_content.add_border()

        limit_content.add("Show ")

        limit_select = SelectWdg("limit_select")
        limit_select.add_class("spt_search_limit_select")
        limit_select.set_option("values", "10|20|50|100|200|Custom")
        limit_select.add_style("font-size: 10px")
        limit_content.add(limit_select)
        limit_content.add(" items per page<br/>")

        if my.search_limit in [10,20,50,100,200]:
            limit_select.set_value(my.search_limit)
            is_custom = False
        else:
            limit_select.set_value("Custom")
            is_custom = True

        limit_select.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            var top = bvr.src_el.getParent(".spt_search_limit_top");
            var value = bvr.src_el.value;
            var custom = top.getElement(".spt_search_limit_custom");
            if (value == 'Custom') {
                custom.setStyle("display", "");
            }
            else {
                custom.setStyle("display", "none");
            }

            '''
        } )


        custom_limit = DivWdg()
        limit_content.add(custom_limit)
        custom_limit.add_class("spt_search_limit_custom")
        custom_limit.add("<br/>Custom: ")
        text = TextWdg("custom_limit")
        text.add_class("spt_search_limit_custom_text")
        text.add_style("width: 50px")
        if not is_custom:
            custom_limit.add_style("display: none")
        else:
            text.set_value(my.search_limit)
        custom_limit.add(text)
        text.add(" items")
        behavior = {
                'type': 'keydown',
                'cbjs_action': '''
                 if (evt.key=='enter') {
                    // register this as changed item
                    var value = bvr.src_el.value;
                    if (isNaN(value) || value.test(/[\.-]/)) {
                        spt.error('You have to use an integer.');
                    }
                }
        '''}

        
        text.add_behavior(behavior)

        return limit_content
示例#10
0
    def get_display(my):
        widget = DivWdg()
        table = Table()
        table.add_attr('class','client_deliverable_wdg')
        table.add_row()
        table2 = Table()
        table2.add_style('border-spacing: 5px;')
        table2.add_style('border-collapse: separate;')
        table2.add_row()

        c1 = table2.add_cell('Order Code:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('order_code')
        tb1.add_attr('id','order_code')
        tb1.add_attr('disabled','disabled')
        tb1.set_value(my.sob['order_code'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('PO Number:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('po_number')
        tb1.add_attr('id','po_number')
        tb1.add_attr('disabled','disabled')
        tb1.set_value(my.sob['po_number'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Title Code:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('title_code')
        tb1.add_attr('id','title_code')
        tb1.add_attr('disabled','disabled')
        tb1.set_value(my.sob['title_code'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Platform:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('platform')
        tb1.add_attr('id','platform')
        tb1.add_attr('disabled','disabled')
        tb1.set_value(my.sob['platform'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Client:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('client_name')
        tb1.add_attr('id','client_name')
        tb1.add_attr('disabled','disabled')
        tb1.set_value(my.sob['client_name'])
        table2.add_cell(tb1)

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Title Source(s):')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('original_source_code')
        tb1.add_attr('id','original_source_code')
        tb1.add_attr('disabled','disabled')
        tb1.add_style('width','200px')
        tb1.set_value(my.sob['original_source_code'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','2')

        c1 = table2.add_cell('Title Source Barcodes(s):')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('original_source_barcode')
        tb1.add_attr('id','original_source_barcode')
        tb1.add_attr('disabled','disabled')
        tb1.add_style('width','200px')
        tb1.set_value(my.sob['original_source_barcode'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','2')

        c1 = table2.add_cell('Ancestors:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('ancestors')
        tb1.add_attr('id','ancestors')
        tb1.add_attr('disabled','disabled')
        tb1.add_style('width','300px')
        tb1.set_value(my.sob['ancestors'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','3')

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Destination:')
        c1.add_attr('nowrap','nowrap')
        destination_sel = SelectWdg('destination')
        destination_sel.add_attr('id','destination')
        destination_sel.append_option('--Select--','')
        for c in my.all_clients:
            destination_sel.append_option(c.get('name'),c.get('name'))
        if my.sob.get('destination') == None:
            my.sob['destination'] = ''
        destination_sel.set_value(my.sob.get('destination'))
        table2.add_cell(destination_sel)


        if my.sob.get('record_id') in [None,'']:
            next_id_sob = my.server.eval("@SOBJECT(twog/global_resource['name','sony_next_unique_id'])")[0]
            next_id = int(next_id_sob.get('description'))
            my.sob['record_id'] = next_id
            my.server.update(next_id_sob.get('__search_key__'), {'description': next_id + 1}, triggers=False)
        c1 = table2.add_cell('Record ID:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('record_id')
        tb1.add_attr('id','record_id')
        tb1.set_value(my.sob['record_id'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Alpha ID:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('alpha_id')
        tb1.add_attr('id','alpha_id')
        tb1.set_value(my.sob['alpha_id'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Client Barcode:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('client_barcode')
        tb1.add_attr('id','client_barcode')
        tb1.set_value(my.sob['client_barcode'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Release Number:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('release_number')
        tb1.add_attr('id','release_number')
        tb1.set_value(my.sob['release_number'])
        table2.add_cell(tb1)

        table2.add_row()

        c1 = table2.add_cell('Title ID:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('title_id')
        tb1.add_attr('id','title_id')
        tb1.set_value(my.sob['title_id'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Title Name:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('title_name')
        tb1.add_attr('id','title_name')
        tb1.set_value(my.sob['title_name'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Title Type:')
        c1.add_attr('nowrap','nowrap')
        title_type_sel = SelectWdg('title_type')
        title_type_sel.add_attr('id','title_type')
        title_type_sel.append_option('--Select--','')
        for type in my.title_types:
            title_type_sel.append_option(type,type)
        if my.sob.get('title_type') == None:
            my.sob['title_type'] = ''
        title_type_sel.set_value(my.sob.get('title_type'))
        table2.add_cell(title_type_sel)

        c1 = table2.add_cell('Title Comment:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('title_comment')
        tb1.add_attr('id','title_comment')
        tb1.add_style('width','300px')
        tb1.set_value(my.sob['title_comment'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','3')

        table2.add_row()

        c1 = table2.add_cell('Clip Id:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('clip_id')
        tb1.add_attr('id','clip_id')
        tb1.set_value(my.sob['clip_id'])
        table2.add_cell(tb1)

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Trailer Number:')
        c1.add_attr('nowrap','nowrap')
        trailer_number_sel = SelectWdg('trailer_number')
        trailer_number_sel.add_attr('id','trailer_number')
        trailer_number_sel.append_option('--Select--','')
        for number in my.trailer_numbers:
            trailer_number_sel.append_option(number,number)
        if my.sob.get('trailer_number') == None:
            my.sob['trailer_number'] = ''
        trailer_number_sel.set_value(my.sob.get('trailer_number'))
        table2.add_cell(trailer_number_sel)

        c1 = table2.add_cell('Trailer Rev Number:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('trailer_rev_number')
        tb1.add_attr('id','trailer_rev_number')
        tb1.set_value(my.sob['trailer_rev_number'])
        table2.add_cell(tb1)

        c1 = table2.add_cell('Trailer Type:')
        c1.add_attr('nowrap','nowrap')
        trailer_type_sel = SelectWdg('trailer_type')
        trailer_type_sel.add_attr('id','trailer_type')
        trailer_type_sel.append_option('--Select--','')
        for type in my.trailer_types:
            trailer_type_sel.append_option(type,type)
        if my.sob.get('trailer_type') == None:
            my.sob['trailer_type'] = ''
        trailer_type_sel.set_value(my.sob.get('trailer_type'))
        table2.add_cell(trailer_type_sel)

        c1 = table2.add_cell('Trailer Version:')
        c1.add_attr('nowrap','nowrap')
        trailer_version_sel = SelectWdg('trailer_version')
        trailer_version_sel.add_attr('id','trailer_version')
        trailer_version_sel.append_option('--Select--','')
        for version in my.trailer_versions:
            trailer_version_sel.append_option(version,version)
        if my.sob.get('trailer_version') == None:
            my.sob['trailer_version'] = ''
        trailer_version_sel.set_value(my.sob.get('trailer_version'))
        table2.add_cell(trailer_version_sel)

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Language Audio:')
        c1.add_attr('nowrap','nowrap')
        language_audio_sel = SelectWdg('language_audio')
        language_audio_sel.append_option('--Select--','')
        for language in my.audio_languages:
            language_audio_sel.append_option(language,language)
        if my.sob.get('language_audio') == None:
            my.sob['language_audio'] = ''
        language_audio_sel.set_value(my.sob.get('language_audio'))
        table2.add_cell(language_audio_sel)

        c1 = table2.add_cell('Language Subtitled:')
        c1.add_attr('nowrap','nowrap')
        language_subtitled_sel = SelectWdg('language_subtitled')
        language_subtitled_sel.add_attr('id','language_subtitled')
        language_subtitled_sel.append_option('--Select--','')
        for language in my.subtitle_languages:
            language_subtitled_sel.append_option(language,language)
        if my.sob.get('language_subtitled') == None:
            my.sob['language_subtitled'] = ''
        language_subtitled_sel.set_value(my.sob.get('language_subtitled'))
        table2.add_cell(language_subtitled_sel)

        c1 = table2.add_cell('Language Text:')
        c1.add_attr('nowrap','nowrap')
        language_text_sel = SelectWdg('language_text')
        language_text_sel.add_attr('id','language_text')
        language_text_sel.append_option('--Select--','')
        for language in my.text_languages:
            language_text_sel.append_option(language,language)
        if my.sob.get('language_text') == None:
            my.sob['language_text'] = ''
        language_text_sel.set_value(my.sob.get('language_text'))
        table2.add_cell(language_text_sel)

        c1 = table2.add_cell('Original Language:')
        c1.add_attr('nowrap','nowrap')
        original_language_sel = SelectWdg('original_language')
        original_language_sel.add_attr('id','original_language')
        original_language_sel.append_option('--Select--','')
        for language in my.original_languages:
            original_language_sel.append_option(language,language)
        if my.sob.get('original_language') == None:
            my.sob['original_language'] = ''
        original_language_sel.set_value(my.sob.get('original_language'))
        table2.add_cell(original_language_sel)

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Source:')
        c1.add_attr('nowrap','nowrap')
        source_sel = SelectWdg('source')
        source_sel.add_attr('id','source')
        source_sel.append_option('--Select--','')
        for s in my.sources:
            source_sel.append_option(s,s)
        if my.sob.get('source') == None:
            my.sob['source'] = ''
        source_sel.set_value(my.sob.get('source'))
        table2.add_cell(source_sel)

        c1 = table2.add_cell('Audio Config:')
        c1.add_attr('nowrap','nowrap')
        audio_config_sel = SelectWdg('audio_config')
        audio_config_sel.add_attr('id','audio_config')
        audio_config_sel.append_option('--Select--','')
        for a in my.audio_configs:
            audio_config_sel.append_option(a,a)
        if my.sob.get('audio_config') == None:
            my.sob['audio_config'] = ''
        audio_config_sel.set_value(my.sob.get('audio_config'))
        table2.add_cell(audio_config_sel)

        c1 = table2.add_cell('Master Audio Config:')
        c1.add_attr('nowrap','nowrap')
        master_audio_config_sel = SelectWdg('master_audio_config')
        master_audio_config_sel.add_attr('id','master_audio_config')
        master_audio_config_sel.append_option('--Select--','')
        for a in my.audio_configs:
            master_audio_config_sel.append_option(a,a)
        if my.sob.get('master_audio_config') == None:
            my.sob['master_audio_config'] = ''
        master_audio_config_sel.set_value(my.sob.get('master_audio_config'))
        table2.add_cell(master_audio_config_sel)
         
        c1 = table2.add_cell('Run Time Calc:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('run_time_calc')
        tb1.add_attr('id','run_time_calc')
        tb1.set_value(my.sob['run_time_calc'])
        #Might want to add the : timestamp js here -- from qc reports
        table2.add_cell(tb1)
   
        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Narrative:')
        c1.add_attr('nowrap','nowrap')
        narrative_sel = SelectWdg('narrative')
        narrative_sel.add_attr('id','narrative')
        narrative_sel.append_option('--Select--','')
        for n in my.narratives:
            narrative_sel.append_option(n,n)
        if my.sob.get('narrative') == None:
            my.sob['narrative'] = ''
        narrative_sel.set_value(my.sob.get('narrative'))
        table2.add_cell(narrative_sel)

        c1 = table2.add_cell('Texted/Textless:')
        c1.add_attr('nowrap','nowrap')
        tt_sel = SelectWdg('texted_textless')
        tt_sel.add_attr('id','texted_textless')
        tt_sel.append_option('--Select--','')
        for t in my.texted_textless:
            tt_sel.append_option(t,t)
        if my.sob.get('texted_textless') == None:
            my.sob['texted_textless'] = ''
        tt_sel.set_value(my.sob.get('texted_textless'))
        table2.add_cell(tt_sel)

        c1 = table2.add_cell('Aspect Ratio:')
        c1.add_attr('nowrap','nowrap')
        aspect_ratio_sel = SelectWdg('aspect_ratio')
        aspect_ratio_sel.add_attr('id','aspect_ratio')
        aspect_ratio_sel.append_option('--Select--','')
        for a in my.aspect_ratios:
            aspect_ratio_sel.append_option(a,a)
        if my.sob.get('aspect_ratio') == None:
            my.sob['aspect_ratio'] = ''
        aspect_ratio_sel.set_value(my.sob.get('aspect_ratio'))
        table2.add_cell(aspect_ratio_sel)

        c1 = table2.add_cell('Standard:')
        c1.add_attr('nowrap','nowrap')
        standard_sel = SelectWdg('standard')
        standard_sel.add_attr('id','standard')
        standard_sel.append_option('--Select--','')
        for s in my.standards:
            standard_sel.append_option(s,s)
        if my.sob.get('standard') == None:
            my.sob['standard'] = ''
        standard_sel.set_value(my.sob.get('standard'))
        table2.add_cell(standard_sel)

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('HD:')
        c1.add_attr('nowrap','nowrap')
        hd_sel = SelectWdg('hd')
        hd_sel.add_attr('id','hd')
        hd_sel.append_option('--Select--','')
        for s in my.hd:
            hd_sel.append_option(s,s)
        if my.sob.get('hd') == None:
            my.sob['hd'] = ''
        hd_sel.set_value(my.sob.get('hd'))
        table2.add_cell(hd_sel)

#        c1 = table2.add_cell('Genre:')
#        c1.add_attr('nowrap','nowrap')
#        tb1 = TextWdg('genre')
#        tb1.add_attr('id','genre')
#        tb1.set_value(my.sob['genre'])
#        table2.add_cell(tb1)

        c1 = table2.add_cell('MPAA:')
        c1.add_attr('nowrap','nowrap')
        mpaa_sel = SelectWdg('mpaa')
        mpaa_sel.add_attr('id','mpaa')
        mpaa_sel.append_option('--Select--','')
        for s in my.mpaa:
            mpaa_sel.append_option(s,s)
        if my.sob.get('mpaa') == None:
            my.sob['mpaa'] = ''
        mpaa_sel.set_value(my.sob.get('mpaa'))
        table2.add_cell(mpaa_sel)

        c1 = table2.add_cell('MPAA Ratings:')
        c1.add_attr('nowrap','nowrap')
        mpaa_ratings_sel = SelectWdg('mpaa_ratings')
        mpaa_ratings_sel.add_attr('id','mpaa_ratings')
        mpaa_ratings_sel.append_option('--Select--','')
        for s in my.mpaa_ratings:
            mpaa_ratings_sel.append_option(s,s)
        if my.sob.get('mpaa_ratings') == None:
            my.sob['mpaa_ratings'] = ''
        mpaa_ratings_sel.set_value(my.sob.get('mpaa_ratings'))
        table2.add_cell(mpaa_ratings_sel)

        table2.add_row()
        table2.add_cell(table2.hr())
#        table2.add_row()
#
#        c1 = table2.add_cell('UK Ratings:')
#        c1.add_attr('nowrap','nowrap')
#        uk_ratings_sel = SelectWdg('uk_ratings')
#        uk_ratings_sel.add_attr('id','uk_ratings')
#        uk_ratings_sel.append_option('--Select--','')
#        for s in my.uk_ratings:
#            uk_ratings_sel.append_option(s,s)
#        if my.sob.get('uk_ratings') == None:
#            my.sob['uk_ratings'] = ''
#        uk_ratings_sel.set_value(my.sob.get('uk_ratings'))
#        table2.add_cell(uk_ratings_sel)
#
#        c1 = table2.add_cell('Australia Ratings:')
#        c1.add_attr('nowrap','nowrap')
#        australia_ratings_sel = SelectWdg('australia_ratings')
#        australia_ratings_sel.add_attr('id','australia_ratings')
#        australia_ratings_sel.append_option('--Select--','')
#        for s in my.australia_ratings:
#            australia_ratings_sel.append_option(s,s)
#        if my.sob.get('australia_ratings') == None:
#            my.sob['australia_ratings'] = ''
#        australia_ratings_sel.set_value(my.sob.get('australia_ratings'))
#        table2.add_cell(australia_ratings_sel)
#
#        c1 = table2.add_cell('Germany Ratings:')
#        c1.add_attr('nowrap','nowrap')
#        germany_ratings_sel = SelectWdg('germany_ratings')
#        germany_ratings_sel.add_attr('id','germany_ratings')
#        germany_ratings_sel.append_option('--Select--','')
#        for s in my.germany_ratings:
#            germany_ratings_sel.append_option(s,s)
#        if my.sob.get('germany_ratings') == None:
#            my.sob['germany_ratings'] = ''
#        germany_ratings_sel.set_value(my.sob.get('germany_ratings'))
#        table2.add_cell(germany_ratings_sel)
#
#        table2.add_row()
#        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('Legal Rights:')
        c1.add_attr('nowrap','nowrap')
        legal_rights_sel = SelectWdg('legal_right')
        legal_rights_sel.add_attr('id','legal_right')
        legal_rights_sel.append_option('--Select--','')
        for s in my.legal_rights:
            legal_rights_sel.append_option(s,s)
        if my.sob.get('legal_right') == None:
            my.sob['legal_right'] = ''
        legal_rights_sel.set_value(my.sob.get('legal_right'))
        table2.add_cell(legal_rights_sel)
        

        from tactic.ui.widget import CalendarInputWdg, ActionButtonWdg
        ld = table2.add_cell('Legal Date: ')
        ld.add_attr('nowrap','nowrap')
        legal_date = CalendarInputWdg("legal_date")
        if my.sob.get('legal_date') not in [None,'']:
            legal_date.set_option('default', my.fix_date(my.sob.get('legal_date')))
        legal_date.set_option('show_activator', True)
        legal_date.set_option('show_confirm', False)
        #legal_date.set_option('show_text', True)
        legal_date.set_option('show_today', False)
        #legal_date.set_option('read_only', False)    
        legal_date.add_attr('id','legal_date')
        table2.add_cell(legal_date)

        c1 = table2.add_cell('Legal Comment:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('legal_comment')
        tb1.add_attr('id','legal_comment')
        tb1.add_style('width','300px')
        tb1.set_value(my.sob['legal_comment'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','3')

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('HE Creative Comment:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('he_creative_comment')
        tb1.add_attr('id','he_creative_comment')
        tb1.add_style('width','300px')
        tb1.set_value(my.sob['he_creative_comment'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','3')

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()

        c1 = table2.add_cell('URL:')
        c1.add_attr('nowrap','nowrap')
        tb1 = TextWdg('url')
        tb1.add_attr('id','url')
        tb1.add_style('width','300px')
        tb1.set_value(my.sob['url'])
        c2 = table2.add_cell(tb1)
        c2.add_attr('colspan','3')

        table2.add_row()
        table2.add_cell(table2.hr())
        table2.add_row()
        
        #ta1 = table2.add_cell('Cast Info:')
        #table2.add_row() 
        #ta1 = table2.add_cell('<textarea cols="90" rows="10" class="spt_input" name="cast_info" id="cast_info">%s</textarea>' % my.sob.get('cast_info'))

        #table2.add_row()
        submit = table2.add_cell('<input type="button" value="Submit"/>')
        sk = ''
        if not my.is_insert:
            sk = my.sob.get('__search_key__')
        submit.add_behavior(my.get_submit(sk))
        if not my.is_insert:
            xml = table2.add_cell('<input type="button" value="Generate XML"/>')
            xml.add_behavior(my.get_xml(sk))

         


        table.add_cell(table2)
        widget.add(table)
        return widget
示例#11
0
    def get_bottom_wdg(my, search_keys=[]):
        # check if the user has enabled it
        info = my.check_bottom_wdg()

        if info.get('check') == False:
            return None

        if info.get('mode') != 'total':
            top = DivWdg()
            top.add("Only [total] is supported. Please change it in Edit Column Definition")
            return top

        my.today = datetime.date.today()

        if my.is_refresh:
            top = Widget()
        else:
            top = DivWdg()
           
        days = []
        for date in my.dates:
            days.append( date.strftime("%Y_%m_%d") )

        today = my.today.strftime("%Y_%m_%d")

        table = Table()
        top.add(table)

        row_list = [my.ST_ROW]
        if my.show_overtime:
            row_list.append( my.OT_ROW)
            
        for row_to_draw in row_list:

            table.add_row()
            table.add_color("color", "color")
            table.add_styles("width: %spx; float: left"%my.table_width)

            td = table.add_blank_cell()
            td.add_style("min-width: %spx" % (my.MONTH_WIDTH + my.LEFT_WIDTH+8))
            time_prefix = ''
            if row_to_draw == my.OT_ROW:
                time_prefix = 'ot'
                div = DivWdg()
                div.add("OT")
               
                div.add_styles('text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)
            elif row_to_draw == my.STT_ROW:
                time_prefix = 'stt'
                div = DivWdg()
                div.add("ST")
               
                div.add_styles('text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)
            elif row_to_draw == my.ENT_ROW:
                time_prefix = 'ent'
                div = DivWdg()
                div.add("ET")
               
                div.add_styles('text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)


            for idx, day in enumerate(days):
                day_wdg = DivWdg()
                day_wdg.add(day)
                
                td = table.add_cell()
                td.add_style("width: %spx" % my.day_width)
                # keep it as text input for consistent alignment
                text = TextWdg("%sday_%s" % (time_prefix, day) )

                if row_to_draw == my.OT_ROW:
                    sobj_daily_dict = my.summary_ot[idx]
                else:
                    sobj_daily_dict = my.summary_st[idx]

                if search_keys:
                    sobj_daily_sub_dict = Common.subset_dict(sobj_daily_dict, search_keys)
                else:
                    sobj_daily_sub_dict = sobj_daily_dict

                daily_total = 0
                for value in sobj_daily_sub_dict.values():
                    if value:
                        daily_total += value

                text.set_value(daily_total)
                td.add(text)

                text.add_class("spt_day%s" % (time_prefix))
                text.add_style("width: %spx"%(my.day_width-2))
                #text.add_style("width: 100%")
                text.add_style("text-align: right")
                text.add_style("padding-left: 2px")
                text.add_style('font-weight: 500')
                text.set_attr("readonly", "readonly")
                # grey out the text color
                text.add_color('color', 'color', +40)

                if day == today:
                    text.add_style("border: solid 1px black")
                elif idx in [0,6]:
                    if row_to_draw == my.OT_ROW:
                        # FOOTER: Overtime, weekends
                        text.add_color("background", "background2", modifier=[-15,0,5])
                    else:
                        # FOOTER: Straight time, weekends
                        text.add_color("background", "background2", modifier=[0,15,20])


            text = TextWdg("total")
            daily_total = 0
            if row_to_draw == my.OT_ROW:
                sobj_daily_dict = my.summary_ot[7]
            else:
                sobj_daily_dict = my.summary_st[7]

            if search_keys:
                sobj_daily_sub_dict = Common.subset_dict(sobj_daily_dict, search_keys)
            else:
                sobj_daily_sub_dict = sobj_daily_dict
            for value in sobj_daily_sub_dict.values():
                if value:
                    daily_total += value
            text.set_value(daily_total)

            td = table.add_cell(text)
            text.add_class("spt_total%s" % (time_prefix))
            # does not look good in FF
            #td.add_style("border-width: 0 0 0 1")
            #td.add_style("border-style: solid")
            td.add_style("width: %spx"%my.day_width)
            text.add_styles("font-weight: 500;width: %spx; text-align: right; padding-left: 2px"%(my.day_width))
            
            text.set_attr("readonly", "readonly")
            text.add_color('color', 'color', +40)

            if row_to_draw == my.OT_ROW:
                # FOOTER: Overtime, total.
                text.add_color("background", "background2", modifier=[5,-15,0])
            else:
                # FOOTER: Straight time, total
                text.add_color("background", "background2", modifier=[20,0,15])

            td = table.add_blank_cell()
            td.add_style('width','100%')

        return top
示例#12
0
    def get_display(my):

        search_type_obj = SearchType.get(my.search_type)
        sobj_title = search_type_obj.get_title()

        my.color_mode = my.kwargs.get("color_mode")
        if not my.color_mode:
            my.color_mode = "default"


        top_div = my.top
        top_div.add_class("spt_edit_top")

        if not my.is_refresh:
            my.set_as_panel(top_div)
        content_div = DivWdg()
        content_div.add_class("spt_edit_top")
        content_div.add_class("spt_edit_form_top")
        content_div.set_attr("spt_search_key", my.search_key)

        if not Container.get_dict("JSLibraries", "spt_edit"):
            content_div.add_behavior( {
                'type': 'load',
                'cbjs_action': my.get_onload_js()
            } )



        layout_view = my.kwargs.get("layout_view")
        if layout_view:
            layout_wdg = my.get_custom_layout_wdg(layout_view)
            content_div.add(layout_wdg)

            return content_div



        # add close listener
        # NOTE: this is an absolute search, but is here for backwards
        # compatibility
        content_div.add_named_listener('close_EditWdg', '''
            var popup = bvr.src_el.getParent( ".spt_popup" );
            if (popup)
                spt.popup.close(popup);
        ''')


        attrs = my.config.get_view_attributes()
        default_access = attrs.get("access")

        if not default_access:
            default_access = "edit"

        project_code = Project.get_project_code()

        security = Environment.get_security()
        base_key =  search_type_obj.get_base_key()
        key = {
            'search_type': base_key,
            'project': project_code
        }
        access = security.check_access("sobject", key, "edit", default=default_access)
        if not access:
            my.is_disabled = True
        else:
            my.is_disabled = False

        disable_wdg = None
        if my.is_disabled:
            # TODO: This overlay doesn't work in IE, size, position, 
            # and transparency all fail. 
            disable_wdg = DivWdg(id='edit_wdg')
            disable_wdg.add_style("position: absolute")
            disable_wdg.add_style("height: 90%")
            disable_wdg.add_style("width: 100%")
            disable_wdg.add_style("left: 0px")
            #disable_wdg.add_style("bottom: 0px")
            #disable_wdg.add_style("top: 0px")

            disable_wdg.add_style("opacity: 0.2")
            disable_wdg.add_style("background: #fff")
            #disable_wdg.add_style("-moz-opacity: 0.2")
            disable_wdg.add_style("filter: Alpha(opacity=20)")
            disable_wdg.add("<center>EDIT DISABLED</center>")
            content_div.add(disable_wdg)


        attrs = my.config.get_view_attributes()

        inner = DivWdg()
        content_div.add(inner)
        menu = my.get_header_context_menu()
        menus = [menu.get_data()]
        menus_in = {
            'HEADER_CTX': menus,
        }
        SmartMenu.attach_smart_context_menu( inner, menus_in, False )






        table = Table()
        inner.add(table)
        if my.color_mode == "default":
            table.add_color("background", "background")
        elif my.color_mode == "transparent":
            table.add_style("background", "transparent")
        table.add_color("color", "color")



        width = attrs.get('width')
        if not width:
            width = my.kwargs.get("width")
        if not width:
            width = 600
        table.add_style("width: %s" % width)

        height = attrs.get('height')
        if height:
            table.add_style("height: %s" % height)

        
        tr = table.add_row()


        show_header = my.kwargs.get("show_header")
        if show_header not in ['false', False]:
            my.add_header(table, sobj_title)

        single = my.kwargs.get("single")
        if single in ['false', False] and my.mode == 'insert':
            multi_div = DivWdg()
            multi_div.add_style("text-align: left")

            multi_div.add("Specify the number of items that will be added with this form:<br/><br/>")


            multi_div.add("<b># of new items to add: </b>")
            multi_div.add("&nbsp;"*4)


            multi_text = TextWdg("multiplier")
            multi_text.add_style("width: 30px")
            multi_div.add(multi_text)

            tr, td = table.add_row_cell( multi_div )

            if my.color_mode == "default":
                td.add_color("border-color", "table_border", default="border")
                td.add_style("border-width: 1px")
                td.add_style("border-style: solid")

            td.add_style("padding: 8 3 8 3")
            td.add_color("background", "background3")
            td.add_color("color", "color3")
        
        security = Environment.get_security()

        # break the widgets up in columns
        num_columns = attrs.get('num_columns')
        if not num_columns:
            num_columns = my.kwargs.get('num_columns')

        if not num_columns:
            num_columns = 1
        else:
            num_columns = int(num_columns)

        # go through each widget and draw it
        for i, widget in enumerate(my.widgets):

            # since a widget name called code doesn't necessariy write to code column, it is commented out for now
            """
            key = { 'search_type' : search_type_obj.get_base_key(),
                'column' : widget.get_name(),
                'project': project_code}
            # check security on widget
            if not security.check_access( "sobject_column",\
                key, "edit"):
                my.skipped_element_names.append(widget.get_name())
                continue
            """

            if not hasattr(widget, 'set_input_prefix'): 
                msg = DivWdg("Warning: The widget definition for [%s] uses [%s] and is not meant for use in Edit Layout. Please revise the edit_definition in widget config."% (widget.get_name(), widget.__class__.__name__ ))
                msg.add_style('color: orange')
                content_div.add(msg)
                content_div.add(HtmlElement.br())
                continue
            if my.input_prefix:
                widget.set_input_prefix(my.input_prefix)

            # Bootstrap
            widget.add_class("form-control")
            widget.add_style("width: 100%")


            class EditTitleWdg(BaseRefreshWdg):
                pass

            #if isinstance(widget, EditTitleWdg):
            """
            has_title = True
            if has_title and i % 3 == 0:
                tr, td = table.add_row_cell()
                tr.add_color("background", "background", -5)
                td.add("TITLE")
                td.add_style("height", "30px")
                td.add_style("padding", "0px 10px")
            """


           
            if isinstance(widget, HiddenWdg):
                content_div.add(widget)
                continue


            # Set up any validations configured on the widget ...
            from tactic.ui.app import ValidationUtil
            v_util = ValidationUtil( widget=widget )
            v_bvr = v_util.get_validation_bvr()
            if v_bvr:
                if (isinstance(widget, CalendarInputWdg)):
                    widget.set_validation( v_bvr.get('cbjs_validation'), v_bvr.get('validation_warning') );
                else:
                    widget.add_behavior( v_bvr )
                    widget.add_behavior( v_util.get_input_onchange_bvr() )
                  


            new_row = i % num_columns == 0
            if new_row:
                tr = table.add_row()


                if my.color_mode == "default":
                    if i % 2 == 0:
                        tr.add_color("background", "background")
                    else:
                        tr.add_color("background", "background", -2 )



           
            show_title = widget.get_option("show_title")
            if not show_title:
                show_title = my.kwargs.get("show_title")

            if show_title in ['false', False]:
                show_title = False
            else:
                show_title = True



            if show_title:
                title = widget.get_title()

                td = table.add_cell(title)
                td.add_style("padding: 10px 15px 10px 5px")
                td.add_style("vertical-align: top")

 
                title_width = my.kwargs.get("title_width")
                if title_width:
                    td.add_style("width: %s" % title_width)
                else:
                    td.add_style("width: 150px")

                security = Environment.get_security()
                if security.check_access("builtin", "view_site_admin", "allow"):
                    SmartMenu.assign_as_local_activator( td, 'HEADER_CTX' )

                if my.color_mode == "default":
                    td.add_color("border-color", "table_border", default="border")
                    td.add_style("border-width: 1" )
                    td.add_style("border-style: solid" )

                td.add_style("text-align: right" )

                hint = widget.get_option("hint")
                if hint:
                    #hint_wdg = HintWdg(hint)
                    #hint_wdg.add_style("float: right")
                    #td.add( hint_wdg )
                    td.add_attr("title", hint)


            if not show_title:
                th, td = table.add_row_cell( widget )
                continue
            else:
                td = table.add_cell( widget )
                #td = table.add_cell( widget.get_value() )
                td.add_style("min-width: 300px")
                td.add_style("padding: 10px 15px 10px 5px")
                td.add_style("vertical-align: top")

                if my.color_mode == "default":
                    td.add_color("border-color", "table_border", default="border")
                    td.add_style("border-width: 1" )
                    td.add_style("border-style: solid" )



        if not my.is_disabled and not my.mode == 'view':
            tr, td = table.add_row_cell( my.get_action_html() )
        
        if my.input_prefix:
            prefix = HiddenWdg("input_prefix", my.input_prefix)
            tr, td = table.add_row_cell()
            td.add(prefix)

        top_div.add(content_div) 
        return top_div
示例#13
0
    def get_scale_wdg(my):

        if my.scale_called == True:
            return None
        my.scale_called = True

        show_scale = my.kwargs.get("show_scale")

        div = DivWdg()
        if show_scale in [False, 'false']:
            div.add_style("display: none")
        div.add_style("padding: 5px")
        div.add_class("spt_table_search")
        hidden = HiddenWdg("prefix", "tile_layout")
        div.add(hidden)
        div.add_behavior( {
            'type': 'load',
            'scale_prefix':  my.scale_prefix,
            'default_scale': my.scale,
            'aspect_ratio': my.aspect_ratio,
            'cbjs_action': '''
spt.tile_layout = {}
spt.tile_layout.layout = null;

spt.tile_layout.set_layout = function(layout) {
    if (!layout.hasClass("spt_layout")) {
        layout = layout.getParent(".spt_layout");
    }
    spt.tile_layout.layout = layout;
    return layout;
}

spt.tile_layout.get_scale = function() {
    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    var value = scale_value.value;
    value = parseInt(value);
    return value;
}


spt.tile_layout.set_scale = function(scale) {

    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    scale_value.value = scale;

    var size_x = bvr.aspect_ratio[0]*scale/100;
    var size_y = bvr.aspect_ratio[1]*scale/100;

    //var top = bvr.src_el.getParent(".spt_tile_layout_top");
    var top = spt.tile_layout.layout;
    var els = top.getElements(".spt_tile_content");
    for (var i = 0; i < els.length; i++) {
        var el = els[i];
        el.setStyle( "width",  size_x);
        el.setStyle( "height", size_y);
    }

    var container_id = "tile_layout::scale"+bvr.scale_prefix;
    spt.container.set_value( container_id, scale);
}


spt.tile_layout.drag_start_x = null;
spt.tile_layout.drag_start_value = null;

spt.tile_layout.drag_setup = function(evt, bvr, mouse_411) {
    spt.tile_layout.set_layout(bvr.src_el);
    spt.tile_layout.drag_start_x = mouse_411.curr_x;
    var src_el = spt.behavior.get_bvr_src( bvr );
    if (!src_el.value) {
        src_el.value = 0;
    }
    spt.tile_layout.drag_start_value = src_el.value;
    src_el.focus();
    src_el.select();
}
spt.tile_layout.drag_motion = function(evt, bvr, mouse_411) {
    var start_value = spt.tile_layout.drag_start_value; 
    if (isNaN(parseInt(start_value))) {
        return;
    }
    var dx = mouse_411.curr_x - spt.tile_layout.drag_start_x;
    var increment = parseInt(dx / 5);
    var multiplier;
    if (increment < 0)
        multiplier = 0.975;
    else
        multiplier = 1 / 0.975;
    increment = Math.abs(increment);
    var scale = spt.tile_layout.drag_start_value;
    for (var i = 0; i < increment; i++) {
        scale = scale * multiplier;
    }
    if (scale > 400)
        scale = 400;
    scale = parseInt(scale);
    spt.tile_layout.set_scale(scale);

}
spt.tile_layout.setup_control = function() {
   var slider = spt.tile_layout.layout.getElement('.spt_slider');
   var container_id = "tile_layout::scale"+bvr.scale_prefix;
   var initial_value = spt.container.get_value(container_id) ?  spt.container.get_value(container_id) : bvr.default_scale;

   spt.tile_layout.set_scale(initial_value);
   new Slider(slider, slider.getElement('.knob'), {
    range: [30, 400],
    steps: 74,
    initialStep: initial_value,
    onChange: function(value){
      if (value) spt.tile_layout.set_scale(value);
    }
  });
}



spt.tile_layout.image_drag_setup = function(evt, bvr, mouse_411) {
    bvr.use_copy = true;
    bvr.use_delta = true;
    //bvr.border_color = border_color;
    bvr.dx = 10;
    bvr.dy = 10;
    bvr.drop_code = 'DROP_ROW';


}

spt.tile_layout.image_drag_motion = function(evt, bvr, mouse_411) {

    spt.mouse._smart_default_drag_motion(evt, bvr, mouse_411);
    var target_el = spt.get_event_target(evt);
    target_el = spt.mouse.check_parent(target_el, bvr.drop_code);
    if (target_el) {
        var orig_border_color = target_el.getStyle('border-color');
        var orig_border_style = target_el.getStyle('border-style');
        target_el.setStyle('border','dashed 2px ' + bvr.border_color);
        if (!target_el.getAttribute('orig_border_color')) {
            target_el.setAttribute('orig_border_color', orig_border_color);
            target_el.setAttribute('orig_border_style', orig_border_style);
        }
    }

}

spt.tile_layout.image_drag_action = function(evt, bvr, mouse_411) {
    if (spt.drop) {
        spt.drop.sobject_drop_action(evt, bvr);
    }
    else {
        if( bvr._drag_copy_el ) {
            spt.behavior.destroy_element(bvr._drag_copy_el);
        }
    }
}

        ''' } )


        scale = my.kwargs.get("scale")


        div.add_behavior( {
        'type': 'load',
        'scale': scale,
        'cbjs_action': '''
        spt.tile_layout.set_layout(bvr.src_el);

        spt.tile_layout.setup_control();

        if (bvr.scale) {
            spt.tile_layout.set_scale(bvr.scale);
        }
      
        '''
        } )

        table = Table()
        div.add(table)
        table.add_row()

        """
        # TO BE DELETED
        less_div = DivWdg()
        less_div.add("<input type='button' value='&lt;&lt;'/>")
        table.add_cell(less_div)

        less_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale * 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )
        """

        dark_color = div.get_color("background", -5)
        light_color = div.get_color('color')
        med_color = div.get_color('color2')
        
        slider_div = DivWdg(css='spt_slider')
        slider_div.add_styles('valign: bottom; background: %s; height: 6px; width: 100px;'% light_color)
        knob_div = DivWdg(css='knob')
        knob_div.add_behavior({'type':'click',
                'cbjs_action': 'spt.tile_layout.set_layout(bvr.src_el)'
                })
        knob_div.add_styles('background: %s; bottom: 4px;\
                height: 16px; width: 12px; border-radius: 6px 6px 0 0;\
                border: 1px %s solid'\
                %(dark_color, med_color ))
        slider_div.add(knob_div)
        td = table.add_cell(slider_div)
        value_wdg = TextWdg("scale")
        value_wdg.add_class("spt_scale_value")
        td = table.add_cell(value_wdg)
        td.add("&nbsp;%")

        td.add_style("padding: 3px 8px")

        """
        # TO BE DELETED
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix("tile_layout")
        if data_list:
            data = data_list[0]
        else:
            data = {}
        my.scale = data.get("scale")
        if my.scale == None:
            my.scale = my.kwargs.get("scale")
        """
        if my.scale:
            value_wdg.set_value(my.scale)
        value_wdg.add_style("width: 28px")
        value_wdg.add_style("text-align: center")
        value_wdg.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )
        value_wdg.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        if (!value) {
            value = 100;
        }
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )



 
        value_wdg.add_behavior( {
            'type': 'smart_drag',
            'bvr_match_class': 'spt_scale_value',
            'ignore_default_motion' : True,
            "cbjs_setup": 'spt.tile_layout.drag_setup( evt, bvr, mouse_411 );',
            "cbjs_motion": 'spt.tile_layout.drag_motion( evt, bvr, mouse_411 );'
        } )

        
        """
        # TO BE DELETED
        more_div = DivWdg()
        more_div.add("<input type='button' value='&gt;&gt;'/>")
        table.add_cell(more_div)

        more_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale / 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )

        """


       

        return div
示例#14
0
    def get_upload_wdg(my):
        '''get search type select and upload wdg'''
        widget = DivWdg(css='spt_import_csv')
        widget.add_color('color','color')
        widget.add_color('background','background')
        widget.add_style('width: 600px')

        # get the search type
        title = DivWdg("<b>Select sType to import data into:</b>&nbsp;&nbsp;")
        widget.add( title )
        title.add_style("float: left")

        # handle new search_types
        new_search_type = CheckboxWdg("new_search_type_checkbox")
        new_search_type.add_event("onclick", "toggle_display('new_search_type_div')")
        #span = SpanWdg(css="med")
        #span.add(new_search_type)
        #span.add("Create new type")
        #span.add(" ... or ... ")
        #widget.add(span)

        new_search_type_div = DivWdg()
        new_search_type_div.set_id("new_search_type_div")

        name_input = TextWdg("asset_name")
        title = TextWdg("asset_title")
        description = TextAreaWdg("asset_description")

        
 
        key='csv_import'
        table = Table()
        table.set_id('csv_main_body')
        table.add_style("margin: 10px 10px")
        table.add_col().set_attr('width','140')
        table.add_col().set_attr('width','400')
        
        table.add_row()
        table.add_header("Search Type: ").set_attr('align','left')
        table.add_cell(name_input)
        table.add_row()
        table.add_header("Title: ").set_attr('align','left')
        table.add_cell(title)
        table.add_row()
        table.add_header("Description: ").set_attr('align','left')
        table.add_cell(description)
        new_search_type_div.add(table)
        new_search_type_div.add_style("display: none")
        #widget.add(new_search_type_div)

        div = DivWdg()

       
        search_type_select = SearchTypeSelectWdg("search_type_filter", mode=SearchTypeSelectWdg.ALL)
        search_type_select.add_empty_option("-- Select --")
        if not search_type_select.get_value():
            search_type_select.set_value(my.search_type)
        search_type_select.set_persist_on_submit()
       

        div.add(search_type_select)

        widget.add(div)

        search_type_select.add_behavior( {'type': 'change', \
                                  'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\
                                    'search_type_filter': bvr.src_el.value});" %(Common.get_full_class_name(my)) } )

        if my.search_type:
            sobj = None
            try:
                sobj = SObjectFactory.create(my.search_type)
            except ImportError:
                widget.add(HtmlElement.br())
                widget.add(SpanWdg('WARNING: Import Error encountered. Please choose another search type.', css='warning')) 
                return widget

            required_columns = sobj.get_required_columns()
           
            if required_columns:
                widget.add(HtmlElement.br())
                req_span = SpanWdg("Required Columns: ", css='med')
                req_span.add_color('color','color')
                widget.add(req_span)
                #required_columns = ['n/a']
                req_span.add(', '.join(required_columns))

            widget.add( HtmlElement.br() )



            if my.file_path:
                hidden = HiddenWdg("file_path", my.file_path)
                widget.add(hidden)
                
                if my.web_url:
                    file_span = FloatDivWdg('URL: <i>%s</i>&nbsp;&nbsp;&nbsp;' %my.web_url, css='med')
                else:
                    file_span = FloatDivWdg('File uploaded: <i>%s</i>&nbsp;&nbsp;&nbsp;' %os.path.basename(my.file_path), css='med')
                file_span.add_color('color','color')
                file_span.add_style('margin: 8px 0 0 10px')
                file_span.add_style('font-size: 14px')
                widget.add(file_span)

                button = ActionButtonWdg(title='Change')
                button.add_style('float','left')
                button.add_behavior( {'type': 'click_up', \
                                   'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\
                                    'search_type_filter': '%s'});" %(Common.get_full_class_name(my), my.search_type) } )
                widget.add(button)
                widget.add("<br clear='all'/>")
                widget.add(HtmlElement.br())
                return widget

            widget.add("<br/>")
            widget.add_style("overflow-y: auto")

            msg = DivWdg()
            widget.add(msg)
            msg.add( "<div style='float: left; padding-left: 100px; padding-top: 6px'><b>Upload a csv file: </b></div>")
            msg.add_border()
            msg.add_style("width: 400px")
            msg.add_color("background", "background3")
            msg.add_style("padding: 20px")
            msg.add_style("margin: 30 auto")
            msg.add_style("text-align: center")

            ticket = Environment.get_security().get_ticket_key()

            
            on_complete = '''var server = TacticServerStub.get();
            var file = spt.html5upload.get_file();
            if (file) {
                var file_name = file.name;
                // clean up the file name the way it is done in the server
                //file_name = spt.path.get_filesystem_name(file_name);    
                var server = TacticServerStub.get();

                var class_name = 'tactic.ui.widget.CsvImportWdg';
                var values = spt.api.Utility.get_input_values('csv_import_main');
                values['is_refresh'] = true;
                values['file_name'] = file_name;
                values['html5_ticket'] = '%s';
                try {
                    var info = spt.panel.load('csv_import_main', class_name, {}, values);
                    spt.app_busy.hide();
                }
                catch(e) {
                    spt.alert(spt.exception.handler(e));
                }
            }
            else  {
              alert('Error: file object cannot be found.')
            }
            spt.app_busy.hide();'''%ticket
            from tactic.ui.input import UploadButtonWdg
            browse = UploadButtonWdg(name='new_csv_upload', title="Browse", tip="Click to choose a csv file",\
                    on_complete=on_complete, ticket=ticket)
            browse.add_style('float: left')
            msg.add(browse)




            
            # this is now only used in the copy and paste Upload button for backward-compatibility
            upload_wdg = SimpleUploadWdg(key=key, show_upload=False)
            upload_wdg.add_style('display: none')
            msg.add(upload_wdg)
          
            #widget.add(span)
            msg.add("<br/><br/>-- OR --</br/><br/>")

            msg.add("<b>Published URL: </b>") 
            text = TextWdg("web_url")
            msg.add(text)
 


            msg.add("<br/><br/>-- OR --</br/><br/>")

            msg.add("<b>Copy and Paste from a Spreadsheet: </b>") 
            text = TextAreaWdg("data")
            text.add_style('width: 33em')
            text.add_class("spt_import_cut_paste")
            msg.add(text)
            button = ActionButtonWdg(title="Parse")
            button.add_style("margin: 5px auto")
            msg.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                var top = bvr.src_el.getParent(".spt_import_top");
                var el = top.getElement(".spt_import_cut_paste");
                var applet = spt.Applet.get();

                var value = el.value;
                var csv = [];
                // convert to a csv file!
                lines = value.split("\\n");
                for (var i = 0; i < lines.length; i++) {
                    if (lines[i] == '') {
                        continue;
                    }
                    var parts = lines[i].split("\\t");
                    var new_line = [];
                    for (var j = 0; j < parts.length; j++) {
                        if (parts[j] == '') {
                            new_line.push('');
                        }
                        else {
                            new_line.push('"'+parts[j]+'"');
                        }
                    }
                    new_line = new_line.join(",");
                    csv.push(new_line);
                }

                csv = csv.join("\\n")

                // FIXME: need to get a local temp directory
                var path = spt.browser.os_is_Windows() ? "C:/sthpw/copy_n_paste.csv" : "/tmp/sthpw/copy_n_paste.csv";
                applet.create_file(path, csv);

                // upload the file
                applet.upload_file(path)
                applet.rmtree(path);

                var top = bvr.src_el.getParent(".spt_import_csv");
                var hidden = top.getElement(".spt_upload_hidden");
                hidden.value = path;

                var file_name = spt.path.get_basename(hidden.value);
                file_name = spt.path.get_filesystem_name(file_name); 
                var class_name = 'tactic.ui.widget.CsvImportWdg';
                var values = spt.api.Utility.get_input_values('csv_import_main');
                values['is_refresh'] = true;
                values['file_name'] = file_name;
                var info = spt.panel.load('csv_import_main', class_name, {}, values);
                '''
            } )

        
        return widget
示例#15
0
    def get_display(my):

        my.search_type = my.kwargs.get('search_type')
        my.element_name = my.kwargs.get('element_name')
        assert my.search_type
        assert my.element_name

        class_name = 'tactic.ui.app.aggregate_wdg.AggregateCmd'
        interval = 120
        priority = None

        if my.kwargs.get('is_refresh'):
            user = Environment.get_user_name()

            # these interval jobs need to have a specific code
            code = "aggregate|%s|%s" % (my.search_type, my.element_name)

            # check to see if the job exists
            #job = Search.get_by_code("sthpw/queue", code)
            job = None
            if not job:
                job = SearchType.create("sthpw/queue")
                #job.set_value("code", code)

                job.set_value("project_code", Project.get_project_code() )
                job.set_value("class_name", class_name)
                job.set_value("command", class_name)
                job.set_value("serialized", str(my.kwargs) )
                job.set_value("interval", 120)
                job.set_value("state", 'pending')
                job.set_value("queue", 'interval')
                job.set_value("priority", 9999)
                job.set_value("login", user) 
                job.commit()




        my.view = my.kwargs.get('view')
        if not my.view:
            my.view = 'definition'

        
        top = DivWdg()
        my.set_as_panel(top)

        action_div = DivWdg()
        top.add(action_div)

        refresh = IconButtonWdg("Refresh", IconWdg.REFRESH)
        refresh.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_panel");
        spt.panel.refresh(top);
        '''
        } )
        action_div.add(refresh)



        register_div = DivWdg()
        register_div.add_class("spt_queue_register")
        top.add(register_div)
        register_div.add_style("border: solid 1px black")
        register_div.add_style("padding: 20px")
        register_div.add("Register new interval aggregate")

        table = Table()
        table.add_style("margin: 15px")
        register_div.add(table)
        table.add_row()
        table.add_cell("command: ")
        table.add_cell(class_name)

        #table.add_row()
        #table.add_cell("priority: ")
        #table.add_cell(priority)

        table.add_row()
        table.add_cell("interval: ")
        td = table.add_cell("every ")
        td.set_attr("title", "Recalculation interval")
        text = TextWdg("interval")
        text.add_style("width: 30px")
        text.set_value(interval)
        td.add(text)

        unit_select = SelectWdg("unit")
        unit_select.set_value(interval)
        unit_select.set_option("values", "seconds|minutes|hours|days")
        td.add(" ")
        td.add(unit_select)

        table.add_row()
        table.add_cell("queue: ")
        table.add_cell("interval")


        from pyasm.widget import ProdIconButtonWdg
        button = ProdIconButtonWdg("Register")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        var top = bvr.src_el.getParent(".spt_queue_register")
        var values = spt.api.get_input_values(top);
        var top = bvr.src_el.getParent(".spt_panel");
        spt.panel.refresh(top);
        '''
        } )
        register_div.add(button)


        from pyasm.widget import ProdIconButtonWdg
        button = ProdIconButtonWdg("Cancel")
        button.add_behavior( {
        'type': 'click_up',
        'cbjs_action': '''
        alert('cancel');
        '''
        } )
        register_div.add(button)


        '''
        cmd = AggregateCmd(**my.kwargs)

        print "registering scheduled task"
        scheduler = Scheduler.get()
        scheduler.start_thread()
        task = AggregateRefreshTask(name="cow", command=cmd)
        scheduler.add_interval_task(task, 10, mode='forked')
        scheduler.cancel_task("cow", delay=35)
        '''


        top.add("<br/>")
        top.add("<b>Current Job Queue</b>")
        top.add("<br/><br/>")
        from tactic.ui.panel import TableLayoutWdg
        table = TableLayoutWdg(search_type='sthpw/queue',view='test')
        top.add(table)

        return top
示例#16
0
    def get_page_one(my):

        info_page = DivWdg()
        
        #info_page.add_class("spt_project_top")
        info_page.add_style("font-size: 12px")
        info_page.add_color("background", "background")
        info_page.add_color("color", "color")
        info_page.add_style("padding: 20px")



        from tactic.ui.input import TextInputWdg

        info_page.add("<b>Title:</b> &nbsp;&nbsp;")
    
        text = TextWdg("order_title")
        #text = TextInputWdg(title="project_title")
        info_page.add(text)
        text.add_style("width: 250px")
        info_page.add(HtmlElement.br(3))
        span = DivWdg()
        info_page.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add_color("background", "background3")
        span.add("The order title can be descriptive and contain spaces and special characters.")
        info_page.add("<br/><br/><hr/><br/><br/>")
        text.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var title = bvr.src_el.value;
        var code = spt.convert_to_alpha_numeric(title);
        var top = bvr.src_el.getParent(".twog_wizard_top");
        var code_el = top.getElement(".spt_project_code");
        code_el.value = code;
        '''
        } )


        info_page.add("<b>Client Name: &nbsp;&nbsp;</b>")
        text = TextWdg("client_name")
        text.add_style("width: 250px")
        text.add_class("spt_client_name")
        info_page.add(text)

        # line breaks
        info_page.add(HtmlElement.br(2))

        info_page.add("<b>Special code: &nbsp;&nbsp;</b>")
        text = TextWdg("special code")
        text.add_style("width: 250px")

        # this is just meant for DOM element search covenience
        text.add_class("spt_special_code")

       
        # this behavior is go for eliminlating special symbols
        #MTM this will help get rid of the stupid ascii errors
        text.add_behavior( {
            'type': 'blur',
            'cbjs_action': '''
            var value = bvr.src_el.value;
            var code = spt.convert_to_alpha_numeric(value);
            bvr.src_el.value = code;
            '''
        } )

        info_page.add(text)

        
        info_page.add(HtmlElement.br(4))

        span = DivWdg()
        info_page.add(span)
        span.add_style("padding: 20px 20px 20px 20px")
        span.add(IconWdg("INFO", IconWdg.CREATE))
        span.add_color("background", "background3")
        span.add("Some more info here.")
     
        info_page.add(span)

        info_page.add("<br/>")


        return info_page
示例#17
0
    def get_display(my):

        search_type = my.kwargs.get("search_type")
        view = my.kwargs.get("view")
        assert search_type
        assert view

        # my.handle_search()

        config_xml = my.kwargs.get("config_xml")
        if not config_xml:
            config_xml = "<config/>"

        # extraneous variables inherited from TableLayoutWdg
        my.edit_permission = False

        top = DivWdg()
        top.add_class("spt_freeform_layout_top")
        my.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 = my.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")

        my.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 my.sobjects:
            search = Search(search_type)
            sobject = search.get_sobject()
        else:
            sobject = my.sobjects[0]

        dialog_id = my.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": my.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(my)
        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
示例#18
0
    def get_set_limit_wdg(my):
        limit_content = DivWdg()
        limit_content.add_style("font-size: 10px")
        #limit_content.add_style("padding", "5px")
        #limit_content.add_border()

        limit_content.add("Show ")

        limit_select = SelectWdg("limit_select")
        limit_select.add_class("spt_search_limit_select")
        limit_select.set_option("values", "10|20|50|100|200|Custom")
        limit_select.add_style("font-size: 10px")
        limit_content.add(limit_select)
        limit_content.add(" items per page<br/>")

        if my.search_limit in [10, 20, 50, 100, 200]:
            limit_select.set_value(my.search_limit)
            is_custom = False
        else:
            limit_select.set_value("Custom")
            is_custom = True

        limit_select.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
            var top = bvr.src_el.getParent(".spt_search_limit_top");
            var value = bvr.src_el.value;
            var custom = top.getElement(".spt_search_limit_custom");
            if (value == 'Custom') {
                custom.setStyle("display", "");
            }
            else {
                custom.setStyle("display", "none");
            }

            '''
        })

        custom_limit = DivWdg()
        limit_content.add(custom_limit)
        custom_limit.add_class("spt_search_limit_custom")
        custom_limit.add("<br/>Custom: ")
        text = TextWdg("custom_limit")
        text.add_class("spt_search_limit_custom_text")
        text.add_style("width: 50px")
        if not is_custom:
            custom_limit.add_style("display: none")
        else:
            text.set_value(my.search_limit)
        custom_limit.add(text)
        text.add(" items")
        behavior = {
            'type':
            'keydown',
            'cbjs_action':
            '''
                 if (evt.key=='enter') {
                    // register this as changed item
                    var value = bvr.src_el.value;
                    if (isNaN(value) || value.test(/[\.-]/)) {
                        spt.error('You have to use an integer.');
                    }
                }
        '''
        }

        text.add_behavior(behavior)

        return limit_content
示例#19
0
 def txtbox(my, name, val, width='200px'):
     txt = TextWdg(name)
     txt.add_attr('id',name)
     txt.add_style('width: %s;' % width)
     txt.set_value(val)
     return txt
示例#20
0
    def get_display(my):
        web = WebContainer.get_web()

        top = my.top
        top.add_class("spt_ace_editor_top")

        script = my.kwargs.get("custom_script")
        if script:
            language = script.get_value("language")
        else:
            language = my.kwargs.get("language")
            if not language:
                language = 'javascript'

        code = my.kwargs.get("code")
        if not code:
            code = ""


        show_options = my.kwargs.get("show_options")
        if show_options in ['false', False]:
            show_options = False
        else:
            show_options = True

        options_div = DivWdg()
        top.add(options_div)
        if not show_options:
            options_div.add_style("display: none")
        options_div.add_color("background", "background3")
        options_div.add_border()
        options_div.add_style("text-align: center")
        options_div.add_style("padding: 2px")



        select = SelectWdg("language")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.add_class("spt_language")
        select.set_option("values", "javascript|server_js|python|expression|xml")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var value = bvr.src_el.value;
            spt.ace_editor.set_language(value);

            //register_change(bvr);

            '''
        } )
 
        select = SelectWdg("font_size")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "8 pt|9 pt|10 pt|11 pt|12 pt|14 pt|16 pt")
        select.set_option("values", "8 pt|9pt|10pt|11pt|12pt|14pt|16pt")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'click_up',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var value = bvr.src_el.value;
            $(editor_id).setStyle("font-size", value)
            //editor.resize();
            '''
        } )



        select = SelectWdg("keybinding")
        select.add_style("width: 100px")
        #options_div.add(select)
        select.set_option("labels", "Ace|Vim|Emacs")
        select.set_option("values", "ace|vim|emacs")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var vim = require("ace/keyboard/keybinding/vim").Vim;
            editor.setKeyboardHandler(vim)
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)


        if code:
            load_div = DivWdg()
            top.add(load_div)
            readonly = my.kwargs.get("readonly")
            if readonly in ['true', True]:
                readonly = True
            else:
                readonly = False

            load_div.add_behavior( {
                'type': 'load',
                'code': code,
                'language': language,
                'editor_id': my.get_editor_id(),
                'readonly': readonly,
                'cbjs_action': '''
                spt.ace_editor.set_editor(bvr.editor_id);
                var func = function() {
                    var editor = spt.ace_editor.editor;
                    var document = editor.getSession().getDocument();
                    if (bvr.code) {
                        spt.ace_editor.set_value(bvr.code);
                    }
                    spt.ace_editor.set_language(bvr.language);
                    editor.setReadOnly(bvr.readonly);


                    var session = editor.getSession();
                    //session.setUseWrapMode(true);
                    //session.setWrapLimitRange(120, 120);
                };

                var editor = spt.ace_editor.editor;
                if (!editor) {
                    setTimeout( func, 1000);
                }
                else {
                    func();
                }

                '''
            } )




        # theme
        select = SelectWdg("theme")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "Eclipse|Twilight|TextMate|Vibrant Ink|Merbivore|Clouds")
        select.set_option("values", "eclipse|twilight|textmate|vibrant_ink|merbivore|clouds")
        select.set_value("twilight")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;
            value = bvr.src_el.value;

            editor.setTheme("ace/theme/" + value);
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)




        my.text_area.add_style("margin-top: -1px")
        my.text_area.add_style("margin-bottom: 0px")
        my.text_area.add_color("background", "background")
        my.text_area.add_style("font-family: courier new")
        my.text_area.add_border()
        editor_div.add(my.text_area)
        my.text_area.add_style("position: relative")
        #text_area.add_style("margin: 20px")


        size = web.get_form_value("size")
        if size:
            width, height = size.split(",")
        else:
            width = my.kwargs.get("width")
            if not width:
                width = "650px"
            height = my.kwargs.get("height")
            if not height:
                height = "450px"
        my.text_area.add_style("width: %s" % width)
        my.text_area.add_style("height: %s" % height)



        bottom_div = DivWdg()
        top.add(bottom_div)
        bottom_div.add_color("background", "background3")
        bottom_div.add_border()
        bottom_div.add_style("text-align: center")
        bottom_div.add_style("padding: 2px")
        bottom_div.add_style("height: 20px")

        bottom_title = "Script Editor"
        bottom_div.add(bottom_title)

        icon = IconWdg("Resize Editor", IconWdg.RESIZE_CORNER)
        bottom_div.add(icon)
        icon.add_style("float: right")
        icon.add_style("margin-right: -4px")
        icon.add_style("cursor: se-resize")
        icon.add_behavior( {
            'type': 'drag',
            "cb_set_prefix": 'spt.ace_editor.drag_resize',
        } )


        #hidden = HiddenWdg("size")
        hidden = TextWdg("size")
        bottom_div.add(hidden)
        hidden.add_style("width: 85px")
        hidden.add_style("text-align: center")
        hidden.add_style("float: right")
        hidden.add_class("spt_size")
        hidden.set_value("%s,%s" % (width, height))

        theme = top.get_theme()
        if theme == 'dark':
            theme = 'twilight'
        else:
            theme = 'eclipse'

        print "theme: ", theme

        top.add_behavior( {
            'type': 'load',
            'unique_id': my.unique_id,
            'theme': theme,
            'cbjs_action': '''

if (typeof(ace) == 'undefined') {

// fist time loading
spt.ace_editor = {}
spt.ace_editor.editor = null;
spt.ace_editor.editor_id = bvr.unique_id;
spt.ace_editor.theme = bvr.theme;


spt.ace_editor.set_editor = function(editor_id) {
    spt.ace_editor.editor_id = editor_id;
    spt.ace_editor.editor = $(editor_id).editor;
}

spt.ace_editor.set_editor_top = function(top_el) {
    if (!top_el.hasClass("spt_ace_editor")) {
        top_el = top_el.getElement(".spt_ace_editor");
    }

    var editor_id = top_el.getAttribute("id");
    spt.ace_editor.set_editor(editor_id);
}




spt.ace_editor.get_editor = function() {
    return spt.ace_editor.editor;

}



spt.ace_editor.clear_selection = function() {
    var editor = spt.ace_editor.editor;
    editor.clearSelection();

}



spt.ace_editor.get_selection = function() {
    var editor = spt.ace_editor.editor;
    //return editor.getSelection();
    return editor.getCopyText();
}





spt.ace_editor.get_value = function() {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    var value = document.getValue();
    return value;
}



spt.ace_editor.set_value = function(value) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    document.setValue(value);
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
}

spt.ace_editor.goto_line = function(number) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
 

}


spt.ace_editor.insert = function(value) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertInLine(position, value);
}

 
spt.ace_editor.insert_lines = function(values) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertLines(position.row, values);
}



spt.ace_editor.get_document = function() {
    var document = spt.ace_editor.editor.getSession().getDocument()
    return document;

}




spt.ace_editor.set_language = function(value) {
    if (!value) {
        value = 'javascript';
    }

    var editor = spt.ace_editor.editor;
    var top = $(spt.ace_editor.editor_id).getParent(".spt_ace_editor_top");
    var lang_el = top.getElement(".spt_language");

    for ( var i = 0; i < lang_el.options.length; i++ ) {
        if ( lang_el.options[i].value == value ) {
            lang_el.options[i].selected = true;
            break;
        }
    }



    var session = editor.getSession();
    var mode;
    if (value == 'python') {
        mode = require("ace/mode/python").Mode;
    }
    else if (value == 'xml') {
        mode = require("ace/mode/xml").Mode;
    }
    else if (value == 'expression') {
        mode = require("ace/mode/xml").Mode;
    }
    else {
        mode = require("ace/mode/javascript").Mode;
    }
    session.setMode( new mode() );
}

spt.ace_editor.drag_start_x;
spt.ace_editor.drag_start_y;
spt.ace_editor.drag_size;
spt.ace_editor.drag_editor_el;
spt.ace_editor.drag_size_el;
spt.ace_editor.drag_resize_setup = function(evt, bvr, mouse_411)
{
    var editor = spt.ace_editor.editor;
    var editor_id = spt.ace_editor.editor_id;

    spt.ace_editor.drag_start_x = mouse_411.curr_x;
    spt.ace_editor.drag_start_y = mouse_411.curr_y;

    var editor_el = $(editor_id);
    spt.ace_editor.drag_editor_el = editor_el;
    spt.ace_editor.drag_size = editor_el.getSize();

    var top = bvr.src_el.getParent(".spt_ace_editor_top");
    spt.ace_editor.drag_size_el = top.getElement(".spt_size");
}


spt.ace_editor.drag_resize_motion = function(evt, bvr, mouse_411)
{
    var diff_x = parseFloat(mouse_411.curr_x - spt.ace_editor.drag_start_x);
    var diff_y = parseFloat(mouse_411.curr_y - spt.ace_editor.drag_start_y);

    var size = spt.ace_editor.drag_size;


    var editor_el = spt.ace_editor.drag_editor_el;

    var width = size.x + diff_x
    if (width < 300) {
        width = 300;
    }
    var height = size.y + diff_y
    if (height < 200) {
        height = 200;
    }

    editor_el.setStyle("width", width);
    editor_el.setStyle("height", height);

    spt.ace_editor.drag_size_el.value = width + "," + height;

    var editor = spt.ace_editor.editor;
    editor.resize();

}
    var js_files = [
        "ace/ace-0.2.0/src/ace.js",
        //"ace/ace-0.2.0/src/ace-uncompressed.js",
    ];


   

    var ace_setup =  function() {
        var editor = ace.edit(bvr.unique_id);
        spt.ace_editor.editor = editor;

        // put the editor into the dom
        spt.ace_editor.editor_id = bvr.unique_id;
        $(bvr.unique_id).editor = editor;

        editor.setTheme("ace/theme/" + spt.ace_editor.theme);
        var JavaScriptMode = require("ace/mode/javascript").Mode;
        editor.getSession().setMode(new JavaScriptMode())
    }

    


    spt.dom.load_js(js_files, function() { 
    
        ace; require; define; 

        var core_js_files = [
        "ace/ace-0.2.0/src/mode-javascript.js",
         "ace/ace-0.2.0/src/mode-xml.js",
            "ace/ace-0.2.0/src/mode-python.js",
             "ace/ace-0.2.0/src/theme-twilight.js",
               
            "ace/ace-0.2.0/src/theme-textmate.js",
            "ace/ace-0.2.0/src/theme-vibrant_ink.js",
            "ace/ace-0.2.0/src/theme-merbivore.js",
            "ace/ace-0.2.0/src/theme-clouds.js",
            "ace/ace-0.2.0/src/theme-eclipse.js"
        ];
        //var supp_js_files = [];
           
         
        

        spt.dom.load_js(core_js_files, ace_setup);
        //spt.dom.load_js(supp_js_files);      
        });
   

    





}
else {
    var editor = ace.edit(bvr.unique_id);
    editor.setTheme("ace/theme/" +  bvr.theme);
    var JavaScriptMode = require("ace/mode/javascript").Mode;
   
    editor.getSession().setMode(new JavaScriptMode())

    spt.ace_editor.editor_id = bvr.unique_id;
    spt.ace_editor.editor = editor;
    $(bvr.unique_id).editor = editor;

}
            '''
        } )


        return top
示例#21
0
文件: edit_wdg.py 项目: 0-T-0/TACTIC
    def get_display(my):

        search_type_obj = SearchType.get(my.search_type)
        sobj_title = search_type_obj.get_title()

        my.color_mode = my.kwargs.get("color_mode")
        if not my.color_mode:
            my.color_mode = "default"


        top_div = my.top
        top_div.add_class("spt_edit_top")

        if not my.is_refresh:
            my.set_as_panel(top_div)
        content_div = DivWdg()
        content_div.add_class("spt_edit_top")
        content_div.add_class("spt_edit_form_top")
        content_div.set_attr("spt_search_key", my.search_key)

        if not Container.get_dict("JSLibraries", "spt_edit"):
            content_div.add_behavior( {
                'type': 'load',
                'cbjs_action': my.get_onload_js()
            } )



        layout_view = my.kwargs.get("layout_view")
        if layout_view:
            layout_wdg = my.get_custom_layout_wdg(layout_view)
            content_div.add(layout_wdg)

            return content_div



        # add close listener
        # NOTE: this is an absolute search, but is here for backwards
        # compatibility
        content_div.add_named_listener('close_EditWdg', '''
            var popup = bvr.src_el.getParent( ".spt_popup" );
            if (popup)
                spt.popup.close(popup);
        ''')


        attrs = my.config.get_view_attributes()
        default_access = attrs.get("access")

        if not default_access:
            default_access = "edit"

        project_code = Project.get_project_code()

        security = Environment.get_security()
        base_key =  search_type_obj.get_base_key()
        key = {
            'search_type': base_key,
            'project': project_code
        }
        access = security.check_access("sobject", key, "edit", default=default_access)
        if not access:
            my.is_disabled = True
        else:
            my.is_disabled = False

        disable_wdg = None
        if my.is_disabled:
            # TODO: This overlay doesn't work in IE, size, position, 
            # and transparency all fail. 
            disable_wdg = DivWdg(id='edit_wdg')
            disable_wdg.add_style("position: absolute")
            disable_wdg.add_style("height: 90%")
            disable_wdg.add_style("width: 100%")
            disable_wdg.add_style("left: 0px")
            #disable_wdg.add_style("bottom: 0px")
            #disable_wdg.add_style("top: 0px")

            disable_wdg.add_style("opacity: 0.2")
            disable_wdg.add_style("background: #fff")
            #disable_wdg.add_style("-moz-opacity: 0.2")
            disable_wdg.add_style("filter: Alpha(opacity=20)")
            disable_wdg.add("<center>EDIT DISABLED</center>")
            content_div.add(disable_wdg)


        attrs = my.config.get_view_attributes()

        #inner doesn't get styled. 
        inner = DivWdg()
        content_div.add(inner)
        menu = my.get_header_context_menu()
        menus = [menu.get_data()]
        menus_in = {
            'HEADER_CTX': menus,
        }
        SmartMenu.attach_smart_context_menu( inner, menus_in, False )

        #insert the header before body into inner
        show_header = my.kwargs.get("show_header")
        if show_header not in ['false', False]:
            my.add_header(inner, sobj_title)


        #insert table into a body container so styling gets applied
        table = Table()
        body_container = DivWdg()
        body_container.add_class("spt_popup_body")
        body_container.add(table)
        inner.add(body_container)


        if my.color_mode == "default":
            table.add_color("background", "background")
        elif my.color_mode == "transparent":
            table.add_style("background", "transparent")
        table.add_color("color", "color")



        width = attrs.get('width')
        if not width:
            width = my.kwargs.get("width")
        if not width:
            width = 600

        height = attrs.get('height')
        if height:
            table.add_style("height: %s" % height)


        tr = table.add_row()

        stype_type = search_type_obj.get_value("type", no_exception=True)
        if my.mode != 'insert' and stype_type in ['media'] and my.sobjects:

            td = table.add_cell()

            width += 300

            from tactic.ui.panel import ThumbWdg2
            thumb = ThumbWdg2()
            thumb.set_sobject(my.sobjects[0])
            td.add(thumb)
            thumb.add_style("margin: 0px 10px")
            path = thumb.get_lib_path()

            td.add_style("padding: 10px")
            td.add_attr("rowspan", len(my.widgets)+2)
            td.add_style("min-width: 250px")
            td.add_style("vertical-align: top")
            td.add_border(direction="right")

            if path:

                td.add("<h3>File Information</h3>")
                td.add("<br/>")

                from pyasm.checkin import BaseMetadataParser
                parser = BaseMetadataParser.get_parser_by_path(path)

                data = parser.get_tactic_metadata()
                data_table = Table()
                data_table.add_style("margin: 15px")
                td.add(data_table)
                for name, value in data.items():
                    data_table.add_row()
                    display_name = Common.get_display_title(name)
                    dtd = data_table.add_cell("%s: " % display_name)
                    dtd.add_style("width: 150px")
                    dtd.add_style("padding: 3px")
                    dtd = data_table.add_cell(value)
                    dtd.add_style("padding: 3px")

            else:
                td.add("<h3>No Image</h3>")
                td.add("<br/>")


        # set the width
        table.add_style("width: %s" % width)



        single = my.kwargs.get("single")
        if single in ['false', False] and my.mode == 'insert':
            multi_div = DivWdg()
            multi_div.add_style("text-align: left")
            multi_div.add_style("padding: 5px 10px")


            multi_div.add("<b>Specify number of new items to add: </b>")
            multi_div.add("&nbsp;"*4)


            multi_text = TextWdg("multiplier")
            multi_text.add_class("form-control")
            multi_div.add(multi_text)
            multi_text.add_style("display: inline-block")
            multi_text.add_style("width: 60px")

            tr, td = table.add_row_cell( multi_div )

            if my.color_mode == "defaultX":
                td.add_color("border-color", "table_border", default="border")
                td.add_style("border-width: 1px")
                td.add_style("border-style: solid")

            td.add_style("padding: 8 3 8 3")
            td.add_color("background", "background3")
            td.add_color("color", "color3")
        
        security = Environment.get_security()

        # break the widgets up in columns
        num_columns = attrs.get('num_columns')
        if not num_columns:
            num_columns = my.kwargs.get('num_columns')

        if not num_columns:
            num_columns = 1
        else:
            num_columns = int(num_columns)

        # go through each widget and draw it
        index =  0
        for i, widget in enumerate(my.widgets):

            # since a widget name called code doesn't necessariy write to code column, it is commented out for now
            """
            key = { 'search_type' : search_type_obj.get_base_key(),
                'column' : widget.get_name(),
                'project': project_code}
            # check security on widget
            if not security.check_access( "sobject_column",\
                key, "edit"):
                my.skipped_element_names.append(widget.get_name())
                continue
            """

            if not hasattr(widget, 'set_input_prefix'): 
                msg = DivWdg("Warning: The widget definition for [%s] uses [%s] and is not meant for use in Edit Layout. Please revise the edit_definition in widget config."% (widget.get_name(), widget.__class__.__name__ ))
                msg.add_style('color: orange')
                content_div.add(msg)
                content_div.add(HtmlElement.br())
                continue
            if my.input_prefix:
                widget.set_input_prefix(my.input_prefix)

            # Bootstrap
            widget.add_class("form-control")

            if not isinstance(widget, CheckboxWdg):
                widget.add_style("width: 100%")


            if isinstance(widget, EditTitleWdg):
                tr, td = table.add_row_cell()
                tr.add_color("background", "background", -5)
                td.add_style("height", "30px")
                td.add_style("padding", "0px 10px")

                td.add(widget)

                index = 0

                continue


           
            if isinstance(widget, HiddenWdg):
                content_div.add(widget)
                continue


            # Set up any validations configured on the widget ...
            from tactic.ui.app import ValidationUtil
            v_util = ValidationUtil( widget=widget )
            v_bvr = v_util.get_validation_bvr()
            if v_bvr:
                if (isinstance(widget, CalendarInputWdg)):
                    widget.set_validation( v_bvr.get('cbjs_validation'), v_bvr.get('validation_warning') );
                else:
                    widget.add_behavior( v_bvr )
                    widget.add_behavior( v_util.get_input_onchange_bvr() )
                  


            new_row = index % num_columns == 0
            if new_row:
                tr = table.add_row()


                if my.color_mode == "default":
                    if index % 2 == 0:
                        tr.add_color("background", "background")
                    else:
                        tr.add_color("background", "background", -1 )


            index += 1

           
            show_title = widget.get_option("show_title")
            if not show_title:
                show_title = my.kwargs.get("show_title")

            if show_title in ['false', False]:
                show_title = False
            else:
                show_title = True



            if show_title:
                title = widget.get_title()

                td = table.add_cell(title)
                td.add_style("padding: 15px 15px 10px 5px")
                td.add_style("vertical-align: top")

 
                title_width = my.kwargs.get("title_width")
                if title_width:
                    td.add_style("width: %s" % title_width)
                else:
                    td.add_style("width: 150px")

                security = Environment.get_security()
                if security.check_access("builtin", "view_site_admin", "allow"):
                    SmartMenu.assign_as_local_activator( td, 'HEADER_CTX' )

                if my.color_mode == "defaultX":
                    td.add_color("border-color", "table_border", default="border")
                    td.add_style("border-width: 1" )
                    td.add_style("border-style: solid" )

                td.add_style("text-align: right" )

                hint = widget.get_option("hint")
                if hint:
                    #hint_wdg = HintWdg(hint)
                    #hint_wdg.add_style("float: right")
                    #td.add( hint_wdg )
                    td.add_attr("title", hint)


            if not show_title:
                th, td = table.add_row_cell( widget )
                continue
            else:
                td = table.add_cell( widget )
                #td = table.add_cell( widget.get_value() )
                td.add_style("min-width: 300px")
                td.add_style("padding: 10px 25px 10px 5px")
                td.add_style("vertical-align: top")

                if my.color_mode == "defaultX":
                    td.add_color("border-color", "table_border", default="border")
                    td.add_style("border-width: 1" )
                    td.add_style("border-style: solid" )



        if not my.is_disabled and not my.mode == 'view':
            inner.add( my.get_action_html() )

        if my.input_prefix:
            prefix = HiddenWdg("input_prefix", my.input_prefix)
            tr, td = table.add_row_cell()
            td.add(prefix)

        top_div.add(content_div) 
        return top_div
示例#22
0
    def handle_item_div(my, item_div, dirname, basename):


        table = Table()
        item_div.add(table)
        table.add_row()
        table.add_style("width: 100%")



        icon_string = my.get_file_icon(dirname, basename)

        icon_div = DivWdg()
        td = table.add_cell(icon_div)
        td.add_style("width: 15px")

        icon = IconWdg("%s/%s" % (dirname, basename), icon_string)
        icon_div.add(icon)
        icon_div.add_style("float: left")
        icon_div.add_style("margin-top: -1px")



        path = "%s/%s" % (dirname, basename)
        status = my.path_info.get(path)
        margin_left = -16
        if status == 'same':
            check = IconWdg( "No Changes", IconWdg.CHECK, width=12 )
        elif status == 'added':
            check = IconWdg( "Added", IconWdg.NEW, width=16 )
            margin_left = -18
        elif status == 'unversioned':
            check = IconWdg( "Unversioned", IconWdg.HELP, width=12 )
        elif status == 'missing':
            check = IconWdg( "Missing", IconWdg.WARNING, width=12 )
        elif status == 'editable':
            check = IconWdg( "Editable", IconWdg.EDIT, width=12 )
        elif status == 'modified':
            check = IconWdg( "Modified", IconWdg.WARNING, width=12 )
        else:
            check = IconWdg( "Error (unknown status)", IconWdg.ERROR, width=12 )

        if check:
            td = table.add_cell(check)
            td.add_style("width: 3px")
            check.add_style("float: left")
            check.add_style("margin-left: %spx" % margin_left)
            check.add_style("margin-top: 4px")
            item_div.add_color("color", "color", [0, 0, 50])

            if status == 'missing':
                item_div.add_style("opacity: 0.3")

        else:
            item_div.add_style("opacity: 0.8")


        name_div = DivWdg()
        td = table.add_cell(name_div)
        name_div.add(basename)
        name_div.add_style("float: left")

        if status != "same":
            name_div.add(" <i style='opacity: 0.5; font-size: 10px'>(%s)</i>" % status)

        spath = path.replace(" ", "_")


        # add the size of the file
        size_div = DivWdg()
        td = table.add_cell(size_div)
        td.add_style("width: 60px")

        size = my.sizes.get(spath)
        if size is None or size == -1:
            size_div.add("-")
        else:
            size_div.add(FormatValue().get_format_value(size, 'KB'))

        size_div.add_style("margin-right: 5px")
        size_div.add_style('text-align: right')



        # FIXME: this still is needed right now, although really used.
        my.subcontext_options = []
        if not my.subcontext_options:
            subcontext = TextWdg("subcontext")
            subcontext = HiddenWdg("subcontext")
            subcontext.add_class("spt_subcontext")
            subcontext.add_style("float: right")

        else:
            subcontext = SelectWdg("subcontext")
            subcontext = HiddenWdg("subcontext")
            subcontext.set_option("show_missing", False)
            subcontext.set_option("values", my.subcontext_options)
            subcontext.add_empty_option("----")


        subcontext.add_behavior( {
            'type': 'click_up',
            'propagate_evt': False,
            'cbjs_action': '''
            bvr.src_el.focus();
            '''
        } )

        subcontext.add_style("display: none")
        item_div.add(subcontext)
示例#23
0
    def get_scale_wdg(my):

        if my.scale_called == True:
            return None
        my.scale_called = True

        show_scale = my.kwargs.get("show_scale")

        div = DivWdg()
        if show_scale in [False, 'false']:
            div.add_style("display: none")
        div.add_style("padding: 5px")
        div.add_class("spt_table_search")
        hidden = HiddenWdg("prefix", "tile_layout")
        div.add(hidden)
        div.add_behavior( {
            'type': 'load',
            'scale_prefix':  my.scale_prefix,
            'default_scale': my.scale,
            'aspect_ratio': my.aspect_ratio,
            'cbjs_action': '''
spt.tile_layout = {}
spt.tile_layout.layout = null;

spt.tile_layout.set_layout = function(layout) {
    if (!layout.hasClass("spt_layout")) {
        layout = layout.getParent(".spt_layout");
    }
    spt.tile_layout.layout = layout;
    return layout;
}

spt.tile_layout.get_scale = function() {
    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    var value = scale_value.value;
    value = parseInt(value);
    return value;
}


spt.tile_layout.set_scale = function(scale) {

    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    scale_value.value = scale;

    var size_x = bvr.aspect_ratio[0]*scale/100;
    var size_y = bvr.aspect_ratio[1]*scale/100;

    //var top = bvr.src_el.getParent(".spt_tile_layout_top");
    var top = spt.tile_layout.layout;
    var els = top.getElements(".spt_tile_content");
    for (var i = 0; i < els.length; i++) {
        var el = els[i];
        el.setStyle( "width",  size_x);
        el.setStyle( "height", size_y);
    }

    var container_id = "tile_layout::scale"+bvr.scale_prefix;
    spt.container.set_value( container_id, scale);
}


spt.tile_layout.drag_start_x = null;
spt.tile_layout.drag_start_value = null;

spt.tile_layout.drag_setup = function(evt, bvr, mouse_411) {
    spt.tile_layout.set_layout(bvr.src_el);
    spt.tile_layout.drag_start_x = mouse_411.curr_x;
    var src_el = spt.behavior.get_bvr_src( bvr );
    if (!src_el.value) {
        src_el.value = 0;
    }
    spt.tile_layout.drag_start_value = src_el.value;
    src_el.focus();
    src_el.select();
}
spt.tile_layout.drag_motion = function(evt, bvr, mouse_411) {
    var start_value = spt.tile_layout.drag_start_value; 
    if (isNaN(parseInt(start_value))) {
        return;
    }
    var dx = mouse_411.curr_x - spt.tile_layout.drag_start_x;
    var increment = parseInt(dx / 5);
    var multiplier;
    if (increment < 0)
        multiplier = 0.975;
    else
        multiplier = 1 / 0.975;
    increment = Math.abs(increment);
    var scale = spt.tile_layout.drag_start_value;
    for (var i = 0; i < increment; i++) {
        scale = scale * multiplier;
    }
    if (scale > 400)
        scale = 400;
    scale = parseInt(scale);
    spt.tile_layout.set_scale(scale);

}
spt.tile_layout.setup_control = function() {
   var slider = spt.tile_layout.layout.getElement('.spt_slider');
   var container_id = "tile_layout::scale"+bvr.scale_prefix;
   var initial_value = spt.container.get_value(container_id) ?  spt.container.get_value(container_id) : bvr.default_scale;

   spt.tile_layout.set_scale(initial_value);
   new Slider(slider, slider.getElement('.knob'), {
    range: [30, 400],
    steps: 74,
    initialStep: initial_value,
    onChange: function(value){
      if (value) spt.tile_layout.set_scale(value);
    }
  });
}



spt.tile_layout.image_drag_setup = function(evt, bvr, mouse_411) {
    bvr.use_copy = true;
    bvr.use_delta = true;
    //bvr.border_color = border_color;
    bvr.dx = 10;
    bvr.dy = 10;
    bvr.drop_code = 'DROP_ROW';
    bvr.accepted_search_type = bvr.search_type;


}

spt.tile_layout.image_drag_motion = function(evt, bvr, mouse_411) {

    spt.mouse._smart_default_drag_motion(evt, bvr, mouse_411);
    var target_el = spt.get_event_target(evt);
    target_el = spt.mouse.check_parent(target_el, bvr.drop_code);
    if (target_el) {
        var orig_border_color = target_el.getStyle('border-color');
        var orig_border_style = target_el.getStyle('border-style');
        target_el.setStyle('border','dashed 2px ' + bvr.border_color);
        if (!target_el.getAttribute('orig_border_color')) {
            target_el.setAttribute('orig_border_color', orig_border_color);
            target_el.setAttribute('orig_border_style', orig_border_style);
        }
    }

}

spt.tile_layout.image_drag_action = function(evt, bvr, mouse_411) {
    if (spt.drop) {

        spt.drop.sobject_drop_action(evt, bvr);
    }
    else {
        if( bvr._drag_copy_el ) {
            spt.behavior.destroy_element(bvr._drag_copy_el);
        }
    }
}

        ''' } )


        scale = my.kwargs.get("scale")


        div.add_behavior( {
        'type': 'load',
        'scale': scale,
        'cbjs_action': '''
        spt.tile_layout.set_layout(bvr.src_el);

        spt.tile_layout.setup_control();

        if (bvr.scale) {
            spt.tile_layout.set_scale(bvr.scale);
        }
      
        '''
        } )

        table = Table()
        div.add(table)
        table.add_row()

        """
        # TO BE DELETED
        less_div = DivWdg()
        less_div.add("<input type='button' value='&lt;&lt;'/>")
        table.add_cell(less_div)

        less_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale * 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )
        """

        dark_color = div.get_color("background", -5)
        light_color = div.get_color('color')
        med_color = div.get_color('color2')
        
        slider_div = DivWdg(css='spt_slider')
        slider_div.add_styles('valign: bottom; background: %s; height: 6px; width: 100px;'% light_color)
        knob_div = DivWdg(css='knob')
        knob_div.add_behavior({'type':'click',
                'cbjs_action': 'spt.tile_layout.set_layout(bvr.src_el)'
                })
        knob_div.add_styles('background: %s; bottom: 4px;\
                height: 16px; width: 12px; border-radius: 6px 6px 0 0;\
                border: 1px %s solid'\
                %(dark_color, med_color ))
        slider_div.add(knob_div)
        td = table.add_cell(slider_div)
        value_wdg = TextWdg("scale")
        value_wdg.add_class("spt_scale_value")
        td = table.add_cell(value_wdg)
        td.add("&nbsp;%")

        td.add_style("padding: 3px 8px")

        """
        # TO BE DELETED
        from tactic.ui.filter import FilterData
        filter_data = FilterData.get()
        data_list = filter_data.get_values_by_prefix("tile_layout")
        if data_list:
            data = data_list[0]
        else:
            data = {}
        my.scale = data.get("scale")
        if my.scale == None:
            my.scale = my.kwargs.get("scale")
        """
        if my.scale:
            value_wdg.set_value(my.scale)
        value_wdg.add_style("width: 28px")
        value_wdg.add_style("text-align: center")
        value_wdg.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )
        value_wdg.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        if (!value) {
            value = 100;
        }
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )



 
        value_wdg.add_behavior( {
            'type': 'smart_drag',
            'bvr_match_class': 'spt_scale_value',
            'ignore_default_motion' : True,
            "cbjs_setup": 'spt.tile_layout.drag_setup( evt, bvr, mouse_411 );',
            "cbjs_motion": 'spt.tile_layout.drag_motion( evt, bvr, mouse_411 );'
        } )

        
        """
        # TO BE DELETED
        more_div = DivWdg()
        more_div.add("<input type='button' value='&gt;&gt;'/>")
        table.add_cell(more_div)

        more_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale / 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )

        """


       

        return div
示例#24
0
文件: edit_wdg.py 项目: funic/TACTIC
    def get_display(my):

        search_type_obj = SearchType.get(my.search_type)
        sobj_title = search_type_obj.get_title()

        my.color_mode = my.kwargs.get("color_mode")
        if not my.color_mode:
            my.color_mode = "default"


        top_div = my.top
        top_div.add_class("spt_edit_top")

        if not my.is_refresh:
            my.set_as_panel(top_div)
        content_div = DivWdg()
        content_div.add_class("spt_edit_top")
        content_div.add_class("spt_edit_form_top")
        content_div.set_attr("spt_search_key", my.search_key)

        if not Container.get_dict("JSLibraries", "spt_edit"):
            content_div.add_behavior( {
                'type': 'load',
                'cbjs_action': my.get_onload_js()
            } )



        layout_view = my.kwargs.get("layout_view")
        if layout_view:
            layout_wdg = my.get_custom_layout_wdg(layout_view)
            content_div.add(layout_wdg)

            return content_div



        # add close listener
        # NOTE: this is an absolute search, but is here for backwards
        # compatibility
        content_div.add_named_listener('close_EditWdg', '''
            var popup = bvr.src_el.getParent( ".spt_popup" );
            if (popup)
                spt.popup.close(popup);
        ''')


        attrs = my.config.get_view_attributes()
        default_access = attrs.get("access")

        if not default_access:
            default_access = "edit"

        project_code = Project.get_project_code()

        security = Environment.get_security()
        base_key =  search_type_obj.get_base_key()
        key = {
            'search_type': base_key,
            'project': project_code
        }
        access = security.check_access("sobject", key, "edit", default=default_access)
        if not access:
            my.is_disabled = True
        else:
            my.is_disabled = False

        disable_wdg = None
        if my.is_disabled:
            # TODO: This overlay doesn't work in IE, size, position, 
            # and transparency all fail. 
            disable_wdg = DivWdg(id='edit_wdg')
            disable_wdg.add_style("position: absolute")
            disable_wdg.add_style("height: 90%")
            disable_wdg.add_style("width: 100%")
            disable_wdg.add_style("left: 0px")
            #disable_wdg.add_style("bottom: 0px")
            #disable_wdg.add_style("top: 0px")

            disable_wdg.add_style("opacity: 0.2")
            disable_wdg.add_style("background: #fff")
            #disable_wdg.add_style("-moz-opacity: 0.2")
            disable_wdg.add_style("filter: Alpha(opacity=20)")
            disable_wdg.add("<center>EDIT DISABLED</center>")
            content_div.add(disable_wdg)


        attrs = my.config.get_view_attributes()

        inner = DivWdg()
        content_div.add(inner)
        menu = my.get_header_context_menu()
        menus = [menu.get_data()]
        menus_in = {
            'HEADER_CTX': menus,
        }
        SmartMenu.attach_smart_context_menu( inner, menus_in, False )






        table = Table()
        inner.add(table)
        if my.color_mode == "default":
            table.add_color("background", "background")
        table.add_color("color", "color")



        width = attrs.get('width')
        if not width:
            width = my.kwargs.get("width")
        if not width:
            width = 500
        table.add_style("width: %s" % width)

        height = attrs.get('height')
        if height:
            table.add_style("height: %s" % height)

        
        tr = table.add_row()


        show_header = my.kwargs.get("show_header")
        if show_header not in ['false', False]:
            my.add_header(table, sobj_title)

        single = my.kwargs.get("single")
        if single in ['false', False] and my.mode == 'insert':
            multi_div = DivWdg()
            multi_div.add_style("text-align: left")

            multi_div.add("Specify the number of items that will be added with this form:<br/><br/>")


            multi_div.add("<b># of new items to add: </b>")
            multi_div.add("&nbsp;"*4)


            multi_text = TextWdg("multiplier")
            multi_text.add_style("width: 30px")
            multi_div.add(multi_text)

            tr, td = table.add_row_cell( multi_div )

            if my.color_mode == "default":
                td.add_color("border-color", "table_border", default="border")
                td.add_style("border-width: 1px")
                td.add_style("border-style: solid")

            td.add_style("padding: 8 3 8 3")
            td.add_color("background", "background3")
            td.add_color("color", "color3")
        
        security = Environment.get_security()

        # break the widgets up in columns
        num_columns = attrs.get('num_columns')
        if not num_columns:
            num_columns = my.kwargs.get('num_columns')

        if not num_columns:
            num_columns = 1
        else:
            num_columns = int(num_columns)

        # go through each widget and draw it
        for i, widget in enumerate(my.widgets):

            # since a widget name called code doesn't necessariy write to code column, it is commented out for now
            """
            key = { 'search_type' : search_type_obj.get_base_key(),
                'column' : widget.get_name(),
                'project': project_code}
            # check security on widget
            if not security.check_access( "sobject_column",\
                key, "edit"):
                my.skipped_element_names.append(widget.get_name())
                continue
            """

            if not hasattr(widget, 'set_input_prefix'): 
                msg = DivWdg("Warning: The widget definition for [%s] uses [%s] and is not meant for use in Edit Layout. Please revise the edit_definition in widget config."% (widget.get_name(), widget.__class__.__name__ ))
                msg.add_style('color: orange')
                content_div.add(msg)
                content_div.add(HtmlElement.br())
                continue
            if my.input_prefix:
                widget.set_input_prefix(my.input_prefix)

           
            if isinstance(widget, HiddenWdg):
                content_div.add(widget)
                continue


            # Set up any validations configured on the widget ...
            from tactic.ui.app import ValidationUtil
            v_util = ValidationUtil( widget=widget )
            v_bvr = v_util.get_validation_bvr()
            if v_bvr:
                if (isinstance(widget, CalendarInputWdg)):
                    widget.set_validation( v_bvr.get('cbjs_validation'), v_bvr.get('validation_warning') );
                else:
                    widget.add_behavior( v_bvr )
                    widget.add_behavior( v_util.get_input_onchange_bvr() )
                  



            new_row = i % num_columns == 0
            if new_row:
                tr = table.add_row()


                if my.color_mode == "default":
                    if i % 2 == 0:
                        tr.add_color("background", "background")
                    else:
                        tr.add_color("background", "background", -5)



           
            show_title = (widget.get_option("show_title") != "false")
            if show_title:
                title = widget.get_title()

                td = table.add_cell(title)
                td.add_style("padding: 10px 15px 10px 5px")
                td.add_style("vertical-align: top")

                title_width = my.kwargs.get("title_width")
                if title_width:
                    td.add_style("width: %s" % title_width)
                else:
                    td.add_style("width: 100px")

                security = Environment.get_security()
                if security.check_access("builtin", "view_site_admin", "allow"):
                    SmartMenu.assign_as_local_activator( td, 'HEADER_CTX' )

                if my.color_mode == "default":
                    td.add_color("border-color", "table_border", default="border")
                    td.add_style("border-width: 1" )
                    td.add_style("border-style: solid" )

                td.add_style("text-align: right" )
 

            if not show_title:
                th, td = table.add_row_cell( widget )
                #td.add_border()

                continue
            else:
                td = table.add_cell( widget )
                #td = table.add_cell( widget.get_value() )
                td.add_style("min-width: 300px")
                td.add_style("padding: 10px 15px 10px 5px")
                td.add_style("vertical-align: top")

                if my.color_mode == "default":
                    td.add_color("border-color", "table_border", default="border")
                    td.add_style("border-width: 1" )
                    td.add_style("border-style: solid" )

                hint = widget.get_option("hint")
                if hint:
                    table.add_data( HintWdg(hint) ) 


        if not my.is_disabled and not my.mode == 'view':
            tr, td = table.add_row_cell( my.get_action_html() )
        
        if my.input_prefix:
            prefix = HiddenWdg("input_prefix", my.input_prefix)
            tr, td = table.add_row_cell()
            td.add(prefix)

        top_div.add(content_div) 
        return top_div
示例#25
0
    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
示例#26
0
    def handle_item_div(my, item_div, dirname, basename):

        table = Table()
        item_div.add(table)
        table.add_row()
        table.add_style("width: 100%")

        icon_string = my.get_file_icon(dirname, basename)

        icon_div = DivWdg()
        td = table.add_cell(icon_div)
        td.add_style("width: 15px")

        icon = IconWdg("%s/%s" % (dirname, basename), icon_string)
        icon_div.add(icon)
        icon_div.add_style("float: left")
        icon_div.add_style("margin-top: -1px")

        path = "%s/%s" % (dirname, basename)
        status = my.path_info.get(path)
        margin_left = -16
        if status == 'same':
            check = IconWdg("No Changes", IconWdg.CHECK, width=12)
        elif status == 'added':
            check = IconWdg("Added", IconWdg.NEW, width=16)
            margin_left = -18
        elif status == 'unversioned':
            check = IconWdg("Unversioned", IconWdg.HELP, width=12)
        elif status == 'missing':
            check = IconWdg("Missing", IconWdg.WARNING, width=12)
        elif status == 'editable':
            check = IconWdg("Editable", IconWdg.EDIT, width=12)
        elif status == 'modified':
            check = IconWdg("Modified", IconWdg.WARNING, width=12)
        else:
            check = IconWdg("Error (unknown status)", IconWdg.ERROR, width=12)

        if check:
            td = table.add_cell(check)
            td.add_style("width: 3px")
            check.add_style("float: left")
            check.add_style("margin-left: %spx" % margin_left)
            check.add_style("margin-top: 4px")
            item_div.add_color("color", "color", [0, 0, 50])

            if status == 'missing':
                item_div.add_style("opacity: 0.3")

        else:
            item_div.add_style("opacity: 0.8")

        name_div = DivWdg()
        td = table.add_cell(name_div)
        name_div.add(basename)
        name_div.add_style("float: left")

        if status != "same":
            name_div.add(" <i style='opacity: 0.5; font-size: 10px'>(%s)</i>" %
                         status)

        spath = path.replace(" ", "_")

        # add the size of the file
        size_div = DivWdg()
        td = table.add_cell(size_div)
        td.add_style("width: 60px")

        size = my.sizes.get(spath)
        if size is None or size == -1:
            size_div.add("-")
        else:
            size_div.add(FormatValue().get_format_value(size, 'KB'))

        size_div.add_style("margin-right: 5px")
        size_div.add_style('text-align: right')

        # FIXME: this still is needed right now, although really used.
        my.subcontext_options = []
        if not my.subcontext_options:
            subcontext = TextWdg("subcontext")
            subcontext = HiddenWdg("subcontext")
            subcontext.add_class("spt_subcontext")
            subcontext.add_style("float: right")

        else:
            subcontext = SelectWdg("subcontext")
            subcontext = HiddenWdg("subcontext")
            subcontext.set_option("show_missing", False)
            subcontext.set_option("values", my.subcontext_options)
            subcontext.add_empty_option("----")

        subcontext.add_behavior({
            'type':
            'click_up',
            'propagate_evt':
            False,
            'cbjs_action':
            '''
            bvr.src_el.focus();
            '''
        })

        subcontext.add_style("display: none")
        item_div.add(subcontext)
示例#27
0
    def get_scale_wdg(my):

        show_scale = my.kwargs.get("show_scale")

        div = DivWdg()
        if show_scale in [False, 'false']:
            div.add_style("display: none")
        div.add_style("padding: 5px")
        div.add_class("spt_table_search")
        hidden = HiddenWdg("prefix", "tile_layout")
        div.add(hidden)

        div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
spt.tile_layout = {}
spt.tile_layout.layout = null;

spt.tile_layout.set_layout = function(layout) {
    if (!layout.hasClass("spt_layout")) {
        layout = layout.getParent(".spt_layout");
    }
    spt.tile_layout.layout = layout;
    return layout;
}

spt.tile_layout.get_scale = function() {
    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    var value = scale_value.value;
    value = parseInt(value);
    return value;
}


spt.tile_layout.set_scale = function(scale) {

    var scale_value = spt.tile_layout.layout.getElement(".spt_scale_value");
    scale_value.value = scale;

    var size_x = 240*scale/100;
    var size_y = 160*scale/100;

    //var top = bvr.src_el.getParent(".spt_tile_layout_top");
    var top = spt.tile_layout.layout;
    var els = top.getElements(".spt_tile_content");
    for (var i = 0; i < els.length; i++) {
        var el = els[i];
        el.setStyle( "width",  size_x);
        el.setStyle( "height", size_y);
    }

    spt.container.set_value("tile_layout::scale", scale);

}


spt.tile_layout.drag_start_x = null;
spt.tile_layout.drag_start_value = null;

spt.tile_layout.drag_setup = function(evt, bvr, mouse_411) {
    spt.tile_layout.set_layout(bvr.src_el);
    spt.tile_layout.drag_start_x = mouse_411.curr_x;
    var src_el = spt.behavior.get_bvr_src( bvr );
    if (!src_el.value) {
        src_el.value = 0;
    }
    spt.tile_layout.drag_start_value = src_el.value;
    src_el.focus();
    src_el.select();
}
spt.tile_layout.drag_motion = function(evt, bvr, mouse_411) {
    var start_value = spt.tile_layout.drag_start_value; 
    if (isNaN(parseInt(start_value))) {
        return;
    }
    var dx = mouse_411.curr_x - spt.tile_layout.drag_start_x;
    var increment = parseInt(dx / 5);
    var multiplier;
    if (increment < 0)
        multiplier = 0.975;
    else
        multiplier = 1 / 0.975;
    increment = Math.abs(increment);
    var scale = spt.tile_layout.drag_start_value;
    for (var i = 0; i < increment; i++) {
        scale = scale * multiplier;
    }
    scale = parseInt(scale);
    spt.tile_layout.set_scale(scale);

}


        ''' } )



        div.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        spt.tile_layout.set_layout(bvr.src_el);
        var scale = spt.container.get_value("tile_layout::scale");
        if (scale) {
            spt.tile_layout.set_scale(scale);
        }
        '''
        } )


        table = Table()
        div.add(table)
        table.add_row()

        less_div = DivWdg()
        less_div.add("<input type='button' value='&lt;&lt;'/>")
        table.add_cell(less_div)

        less_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale * 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )


 
        value_wdg = TextWdg("scale")
        value_wdg.add_class("spt_scale_value")
        td = table.add_cell(value_wdg)
        td.add("&nbsp;%")
        td.add_style("padding: 3px 8px")
        if my.scale:
            value_wdg.set_value(my.scale)
        value_wdg.add_style("width: 24px")
        value_wdg.add_style("text-align: center")
        value_wdg.add_behavior( {
        'type': 'change',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )
        value_wdg.add_behavior( {
        'type': 'load',
        'cbjs_action': '''
        var value = bvr.src_el.value;
        if (!value) {
            value = 100;
        }
        var scale = parseInt(value);
        spt.tile_layout.set_layout(bvr.src_el);
        spt.tile_layout.set_scale(scale);
        '''
        } )



 
        value_wdg.add_behavior( {
            'type': 'smart_drag',
            'bvr_match_class': 'spt_scale_value',
            'ignore_default_motion' : True,
            "cbjs_setup": 'spt.tile_layout.drag_setup( evt, bvr, mouse_411 );',
            "cbjs_motion": 'spt.tile_layout.drag_motion( evt, bvr, mouse_411 );'
        } )



        more_div = DivWdg()
        more_div.add("<input type='button' value='&gt;&gt;'/>")
        table.add_cell(more_div)

        more_div.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.tile_layout.set_layout(bvr.src_el);
            var scale = spt.tile_layout.get_scale();
            scale = scale / 0.95;
            scale = parseInt(scale);
            spt.tile_layout.set_scale(scale);
            '''
        } )



        return div
示例#28
0
    def get_display(my):
        web = WebContainer.get_web()

        top = my.top
        top.add_class("spt_ace_editor_top")

        script = my.kwargs.get("custom_script")
        if script:
            language = script.get_value("language")
        else:
            language = my.kwargs.get("language")
            if not language:
                language = 'javascript'

        code = my.kwargs.get("code")
        if not code:
            code = ""


        show_options = my.kwargs.get("show_options")
        if show_options in ['false', False]:
            show_options = False
        else:
            show_options = True

        options_div = DivWdg()
        top.add(options_div)
        if not show_options:
            options_div.add_style("display: none")
        options_div.add_color("background", "background3")
        options_div.add_border()
        options_div.add_style("text-align: center")
        options_div.add_style("padding: 2px")



        select = SelectWdg("language")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.add_class("spt_language")
        select.set_option("values", "javascript|python|expression|xml")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var value = bvr.src_el.value;
            spt.ace_editor.set_language(value);

            //register_change(bvr);

            '''
        } )
 
        select = SelectWdg("font_size")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "8 pt|9 pt|10 pt|11 pt|12 pt|14 pt|16 pt")
        select.set_option("values", "8 pt|9pt|10pt|11pt|12pt|14pt|16pt")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'click_up',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var value = bvr.src_el.value;
            $(editor_id).setStyle("font-size", value)
            //editor.resize();
            '''
        } )



        select = SelectWdg("keybinding")
        select.add_style("width: 100px")
        #options_div.add(select)
        select.set_option("labels", "Ace|Vim|Emacs")
        select.set_option("values", "ace|vim|emacs")
        select.set_value("10pt")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;

            var vim = require("ace/keyboard/keybinding/vim").Vim;
            editor.setKeyboardHandler(vim)
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)


        if code:
            load_div = DivWdg()
            top.add(load_div)
            readonly = my.kwargs.get("readonly")
            if readonly in ['true', True]:
                readonly = True
            else:
                readonly = False

            load_div.add_behavior( {
                'type': 'load',
                'code': code,
                'language': language,
                'editor_id': my.get_editor_id(),
                'readonly': readonly,
                'cbjs_action': '''
                spt.ace_editor.set_editor(bvr.editor_id);
                var func = function() {
                    var editor = spt.ace_editor.editor;
                    var document = editor.getSession().getDocument();
                    if (bvr.code) {
                        spt.ace_editor.set_value(bvr.code);
                    }
                    spt.ace_editor.set_language(bvr.language);
                    editor.setReadOnly(bvr.readonly);


                    var session = editor.getSession();
                    //session.setUseWrapMode(true);
                    //session.setWrapLimitRange(120, 120);
                };

                var editor = spt.ace_editor.editor;
                if (!editor) {
                    setTimeout( func, 1000);
                }
                else {
                    func();
                }

                '''
            } )




        # theme
        select = SelectWdg("theme")
        select.add_style("width: 100px")
        select.add_style("display: inline")
        options_div.add(select)
        select.set_option("labels", "Eclipse|Twilight|TextMate|Vibrant Ink|Merbivore|Clouds")
        select.set_option("values", "eclipse|twilight|textmate|vibrant_ink|merbivore|clouds")
        select.set_value("twilight")
        select.add_behavior( {
            'type': 'change',
            'editor_id': my.get_editor_id(),
            'cbjs_action': '''
            spt.ace_editor.set_editor(bvr.editor_id);
            var editor = spt.ace_editor.editor;
            var editor_id = spt.ace_editor.editor_id;
            value = bvr.src_el.value;

            editor.setTheme("ace/theme/" + value);
            '''
        } )


        editor_div = DivWdg()
        top.add(editor_div)




        my.text_area.add_style("margin-top: -1px")
        my.text_area.add_style("margin-bottom: 0px")
        my.text_area.add_color("background", "background")
        my.text_area.add_style("font-family: courier new")
        my.text_area.add_border()
        editor_div.add(my.text_area)
        my.text_area.add_style("position: relative")
        #text_area.add_style("margin: 20px")


        size = web.get_form_value("size")
        if size:
            width, height = size.split(",")
        else:
            width = my.kwargs.get("width")
            if not width:
                width = "650px"
            height = my.kwargs.get("height")
            if not height:
                height = "450px"
        my.text_area.add_style("width: %s" % width)
        my.text_area.add_style("height: %s" % height)



        bottom_div = DivWdg()
        top.add(bottom_div)
        bottom_div.add_color("background", "background3")
        bottom_div.add_border()
        bottom_div.add_style("text-align: center")
        bottom_div.add_style("padding: 2px")
        bottom_div.add_style("height: 20px")

        bottom_title = "Script Editor"
        bottom_div.add(bottom_title)

        icon = IconWdg("Resize Editor", IconWdg.RESIZE_CORNER)
        bottom_div.add(icon)
        icon.add_style("float: right")
        icon.add_style("margin-right: -4px")
        icon.add_style("cursor: se-resize")
        icon.add_behavior( {
            'type': 'drag',
            "cb_set_prefix": 'spt.ace_editor.drag_resize',
        } )


        #hidden = HiddenWdg("size")
        hidden = TextWdg("size")
        bottom_div.add(hidden)
        hidden.add_style("width: 85px")
        hidden.add_style("text-align: center")
        hidden.add_style("float: right")
        hidden.add_class("spt_size")
        hidden.set_value("%s,%s" % (width, height))

        theme = top.get_theme()
        if theme == 'dark':
            theme = 'twilight'
        else:
            theme = 'eclipse'

        print "theme: ", theme

        top.add_behavior( {
            'type': 'load',
            'unique_id': my.unique_id,
            'theme': theme,
            'cbjs_action': '''

if (typeof(ace) == 'undefined') {

// fist time loading
spt.ace_editor = {}
spt.ace_editor.editor = null;
spt.ace_editor.editor_id = bvr.unique_id;
spt.ace_editor.theme = bvr.theme;


spt.ace_editor.set_editor = function(editor_id) {
    spt.ace_editor.editor_id = editor_id;
    spt.ace_editor.editor = $(editor_id).editor;
}

spt.ace_editor.set_editor_top = function(top_el) {
    if (!top_el.hasClass("spt_ace_editor")) {
        top_el = top_el.getElement(".spt_ace_editor");
    }

    var editor_id = top_el.getAttribute("id");
    spt.ace_editor.set_editor(editor_id);
}




spt.ace_editor.get_editor = function() {
    return spt.ace_editor.editor;

}



spt.ace_editor.clear_selection = function() {
    var editor = spt.ace_editor.editor;
    editor.clearSelection();

}



spt.ace_editor.get_selection = function() {
    var editor = spt.ace_editor.editor;
    //return editor.getSelection();
    return editor.getCopyText();
}





spt.ace_editor.get_value = function() {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    var value = document.getValue();
    return value;
}



spt.ace_editor.set_value = function(value) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    document.setValue(value);
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
}

spt.ace_editor.goto_line = function(number) {
    var editor = spt.ace_editor.editor;
    var document = editor.getSession().getDocument()
    editor.gotoLine(2);
    editor.resize();
    editor.focus();
 

}


spt.ace_editor.insert = function(value) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertInLine(position, value);
}

 
spt.ace_editor.insert_lines = function(values) {
    var editor = spt.ace_editor.editor;
    var position = editor.getCursorPosition();
    var doc = editor.getSession().getDocument()
    doc.insertLines(position.row, values);
}



spt.ace_editor.get_document = function() {
    var document = spt.ace_editor.editor.getSession().getDocument()
    return document;

}




spt.ace_editor.set_language = function(value) {
    if (!value) {
        value = 'javascript';
    }

    var editor = spt.ace_editor.editor;
    var top = $(spt.ace_editor.editor_id).getParent(".spt_ace_editor_top");
    var lang_el = top.getElement(".spt_language");

    for ( var i = 0; i < lang_el.options.length; i++ ) {
        if ( lang_el.options[i].value == value ) {
            lang_el.options[i].selected = true;
            break;
        }
    }



    var session = editor.getSession();
    var mode;
    if (value == 'python') {
        mode = require("ace/mode/python").Mode;
    }
    else if (value == 'xml') {
        mode = require("ace/mode/xml").Mode;
    }
    else if (value == 'expression') {
        mode = require("ace/mode/xml").Mode;
    }
    else {
        mode = require("ace/mode/javascript").Mode;
    }
    session.setMode( new mode() );
}

spt.ace_editor.drag_start_x;
spt.ace_editor.drag_start_y;
spt.ace_editor.drag_size;
spt.ace_editor.drag_editor_el;
spt.ace_editor.drag_size_el;
spt.ace_editor.drag_resize_setup = function(evt, bvr, mouse_411)
{
    var editor = spt.ace_editor.editor;
    var editor_id = spt.ace_editor.editor_id;

    spt.ace_editor.drag_start_x = mouse_411.curr_x;
    spt.ace_editor.drag_start_y = mouse_411.curr_y;

    var editor_el = $(editor_id);
    spt.ace_editor.drag_editor_el = editor_el;
    spt.ace_editor.drag_size = editor_el.getSize();

    var top = bvr.src_el.getParent(".spt_ace_editor_top");
    spt.ace_editor.drag_size_el = top.getElement(".spt_size");
}


spt.ace_editor.drag_resize_motion = function(evt, bvr, mouse_411)
{
    var diff_x = parseFloat(mouse_411.curr_x - spt.ace_editor.drag_start_x);
    var diff_y = parseFloat(mouse_411.curr_y - spt.ace_editor.drag_start_y);

    var size = spt.ace_editor.drag_size;


    var editor_el = spt.ace_editor.drag_editor_el;

    var width = size.x + diff_x
    if (width < 300) {
        width = 300;
    }
    var height = size.y + diff_y
    if (height < 200) {
        height = 200;
    }

    editor_el.setStyle("width", width);
    editor_el.setStyle("height", height);

    spt.ace_editor.drag_size_el.value = width + "," + height;

    var editor = spt.ace_editor.editor;
    editor.resize();

}
    var js_files = [
        "ace/ace-0.2.0/src/ace.js",
        //"ace/ace-0.2.0/src/ace-uncompressed.js",
    ];


   

    var ace_setup =  function() {
        var editor = ace.edit(bvr.unique_id);
        spt.ace_editor.editor = editor;

        // put the editor into the dom
        spt.ace_editor.editor_id = bvr.unique_id;
        $(bvr.unique_id).editor = editor;

        editor.setTheme("ace/theme/" + spt.ace_editor.theme);
        var JavaScriptMode = require("ace/mode/javascript").Mode;
        editor.getSession().setMode(new JavaScriptMode())
    }

    


    spt.dom.load_js(js_files, function() { 
    
        ace; require; define; 

        var core_js_files = [
        "ace/ace-0.2.0/src/mode-javascript.js",
         "ace/ace-0.2.0/src/mode-xml.js",
            "ace/ace-0.2.0/src/mode-python.js",
             "ace/ace-0.2.0/src/theme-twilight.js",
               
            "ace/ace-0.2.0/src/theme-textmate.js",
            "ace/ace-0.2.0/src/theme-vibrant_ink.js",
            "ace/ace-0.2.0/src/theme-merbivore.js",
            "ace/ace-0.2.0/src/theme-clouds.js",
            "ace/ace-0.2.0/src/theme-eclipse.js"
        ];
        //var supp_js_files = [];
           
         
        

        spt.dom.load_js(core_js_files, ace_setup);
        //spt.dom.load_js(supp_js_files);      
        });
   

    





}
else {
    var editor = ace.edit(bvr.unique_id);
    editor.setTheme("ace/theme/" +  bvr.theme);
    var JavaScriptMode = require("ace/mode/javascript").Mode;
   
    editor.getSession().setMode(new JavaScriptMode())

    spt.ace_editor.editor_id = bvr.unique_id;
    spt.ace_editor.editor = editor;
    $(bvr.unique_id).editor = editor;

}
            '''
        } )


        return top
示例#29
0
    def get_display(self):

        self.search_type = self.kwargs.get('search_type')
        self.element_name = self.kwargs.get('element_name')
        assert self.search_type
        assert self.element_name

        class_name = 'tactic.ui.app.aggregate_wdg.AggregateCmd'
        interval = 120
        priority = None

        if self.kwargs.get('is_refresh'):
            user = Environment.get_user_name()

            # these interval jobs need to have a specific code
            code = "aggregate|%s|%s" % (self.search_type, self.element_name)

            # check to see if the job exists
            #job = Search.get_by_code("sthpw/queue", code)
            job = None
            if not job:
                job = SearchType.create("sthpw/queue")
                #job.set_value("code", code)

                job.set_value("project_code", Project.get_project_code())
                job.set_value("class_name", class_name)
                job.set_value("command", class_name)
                job.set_value("serialized", str(self.kwargs))
                job.set_value("interval", 120)
                job.set_value("state", 'pending')
                job.set_value("queue", 'interval')
                job.set_value("priority", 9999)
                job.set_value("login", user)
                job.commit()

        self.view = self.kwargs.get('view')
        if not self.view:
            self.view = 'definition'

        top = DivWdg()
        self.set_as_panel(top)

        action_div = DivWdg()
        top.add(action_div)

        refresh = IconButtonWdg("Refresh", IconWdg.REFRESH)
        refresh.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_panel");
        spt.panel.refresh(top);
        '''
        })
        action_div.add(refresh)

        register_div = DivWdg()
        register_div.add_class("spt_queue_register")
        top.add(register_div)
        register_div.add_style("border: solid 1px black")
        register_div.add_style("padding: 20px")
        register_div.add("Register new interval aggregate")

        table = Table()
        table.add_style("margin: 15px")
        register_div.add(table)
        table.add_row()
        table.add_cell("command: ")
        table.add_cell(class_name)

        #table.add_row()
        #table.add_cell("priority: ")
        #table.add_cell(priority)

        table.add_row()
        table.add_cell("interval: ")
        td = table.add_cell("every ")
        td.set_attr("title", "Recalculation interval")
        text = TextWdg("interval")
        text.add_style("width: 30px")
        text.set_value(interval)
        td.add(text)

        unit_select = SelectWdg("unit")
        unit_select.set_value(interval)
        unit_select.set_option("values", "seconds|minutes|hours|days")
        td.add(" ")
        td.add(unit_select)

        table.add_row()
        table.add_cell("queue: ")
        table.add_cell("interval")

        from pyasm.widget import ProdIconButtonWdg
        button = ProdIconButtonWdg("Register")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        var top = bvr.src_el.getParent(".spt_queue_register")
        var values = spt.api.get_input_values(top);
        var top = bvr.src_el.getParent(".spt_panel");
        spt.panel.refresh(top);
        '''
        })
        register_div.add(button)

        from pyasm.widget import ProdIconButtonWdg
        button = ProdIconButtonWdg("Cancel")
        button.add_behavior({
            'type':
            'click_up',
            'cbjs_action':
            '''
        alert('cancel');
        '''
        })
        register_div.add(button)
        '''
        cmd = AggregateCmd(**self.kwargs)

        print "registering scheduled task"
        scheduler = Scheduler.get()
        scheduler.start_thread()
        task = AggregateRefreshTask(name="cow", command=cmd)
        scheduler.add_interval_task(task, 10, mode='forked')
        scheduler.cancel_task("cow", delay=35)
        '''

        top.add("<br/>")
        top.add("<b>Current Job Queue</b>")
        top.add("<br/><br/>")
        from tactic.ui.panel import TableLayoutWdg
        table = TableLayoutWdg(search_type='sthpw/queue', view='test')
        top.add(table)

        return top
示例#30
0
    def get_bottom_wdg(my, search_keys=[]):
        # check if the user has enabled it
        info = my.check_bottom_wdg()

        if info.get('check') == False:
            return None

        if info.get('mode') != 'total':
            top = DivWdg()
            top.add(
                "Only [total] is supported. Please change it in Edit Column Definition"
            )
            return top

        my.today = datetime.date.today()

        if my.is_refresh:
            top = Widget()
        else:
            top = DivWdg()

        days = []
        for date in my.dates:
            days.append(date.strftime("%Y_%m_%d"))

        today = my.today.strftime("%Y_%m_%d")

        table = Table()
        top.add(table)

        row_list = [my.ST_ROW]
        if my.show_overtime:
            row_list.append(my.OT_ROW)

        for row_to_draw in row_list:

            table.add_row()
            table.add_color("color", "color")
            table.add_styles("width: %spx; float: left" % my.table_width)

            td = table.add_blank_cell()
            td.add_style("min-width: %spx" %
                         (my.MONTH_WIDTH + my.LEFT_WIDTH + 8))
            time_prefix = ''
            if row_to_draw == my.OT_ROW:
                time_prefix = 'ot'
                div = DivWdg()
                div.add("OT")

                div.add_styles(
                    'text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)
            elif row_to_draw == my.STT_ROW:
                time_prefix = 'stt'
                div = DivWdg()
                div.add("ST")

                div.add_styles(
                    'text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)
            elif row_to_draw == my.ENT_ROW:
                time_prefix = 'ent'
                div = DivWdg()
                div.add("ET")

                div.add_styles(
                    'text-align: right; margin-right: 4px; margin-bottom: 6px')
                td.add(div)

            for idx, day in enumerate(days):
                day_wdg = DivWdg()
                day_wdg.add(day)

                td = table.add_cell()
                td.add_style("width: %spx" % my.day_width)
                # keep it as text input for consistent alignment
                text = TextWdg("%sday_%s" % (time_prefix, day))

                if row_to_draw == my.OT_ROW:
                    sobj_daily_dict = my.summary_ot[idx]
                else:
                    sobj_daily_dict = my.summary_st[idx]

                if search_keys:
                    sobj_daily_sub_dict = Common.subset_dict(
                        sobj_daily_dict, search_keys)
                else:
                    sobj_daily_sub_dict = sobj_daily_dict

                daily_total = 0
                for value in sobj_daily_sub_dict.values():
                    if value:
                        daily_total += value

                text.set_value(daily_total)
                td.add(text)

                text.add_class("spt_day%s" % (time_prefix))
                text.add_style("width: %spx" % (my.day_width - 2))
                #text.add_style("width: 100%")
                text.add_style("text-align: right")
                text.add_style("padding-left: 2px")
                text.add_style('font-weight: 500')
                text.set_attr("readonly", "readonly")
                # grey out the text color
                text.add_color('color', 'color', +40)

                if day == today:
                    text.add_style("border: solid 1px black")
                elif idx in [0, 6]:
                    if row_to_draw == my.OT_ROW:
                        # FOOTER: Overtime, weekends
                        text.add_color("background",
                                       "background2",
                                       modifier=[-15, 0, 5])
                    else:
                        # FOOTER: Straight time, weekends
                        text.add_color("background",
                                       "background2",
                                       modifier=[0, 15, 20])

            text = TextWdg("total")
            daily_total = 0
            if row_to_draw == my.OT_ROW:
                sobj_daily_dict = my.summary_ot[7]
            else:
                sobj_daily_dict = my.summary_st[7]

            if search_keys:
                sobj_daily_sub_dict = Common.subset_dict(
                    sobj_daily_dict, search_keys)
            else:
                sobj_daily_sub_dict = sobj_daily_dict
            for value in sobj_daily_sub_dict.values():
                if value:
                    daily_total += value
            text.set_value(daily_total)

            td = table.add_cell(text)
            text.add_class("spt_total%s" % (time_prefix))
            # does not look good in FF
            #td.add_style("border-width: 0 0 0 1")
            #td.add_style("border-style: solid")
            td.add_style("width: %spx" % my.day_width)
            text.add_styles(
                "font-weight: 500;width: %spx; text-align: right; padding-left: 2px"
                % (my.day_width))

            text.set_attr("readonly", "readonly")
            text.add_color('color', 'color', +40)

            if row_to_draw == my.OT_ROW:
                # FOOTER: Overtime, total.
                text.add_color("background",
                               "background2",
                               modifier=[5, -15, 0])
            else:
                # FOOTER: Straight time, total
                text.add_color("background",
                               "background2",
                               modifier=[20, 0, 15])

            td = table.add_blank_cell()
            td.add_style('width', '100%')

        return top
示例#31
0
    def get_upload_wdg(my):
        '''get search type select and upload wdg'''
        widget = DivWdg(css='spt_import_csv')
        widget.add_color('color','color')
        widget.add_color('background','background')
        widget.add_style('width: 600px')

        # get the search type
        title = DivWdg("<b>Select sType to import data into:</b>&nbsp;&nbsp;")
        widget.add( title )
        title.add_style("float: left")

        # handle new search_types
        new_search_type = CheckboxWdg("new_search_type_checkbox")
        new_search_type.add_event("onclick", "toggle_display('new_search_type_div')")
        #span = SpanWdg(css="med")
        #span.add(new_search_type)
        #span.add("Create new type")
        #span.add(" ... or ... ")
        #widget.add(span)

        new_search_type_div = DivWdg()
        new_search_type_div.set_id("new_search_type_div")

        name_input = TextWdg("asset_name")
        title = TextWdg("asset_title")
        description = TextAreaWdg("asset_description")

        
 
        key='csv_import'
        table = Table()
        table.set_id('csv_main_body')
        table.add_style("margin: 10px 10px")
        table.add_col().set_attr('width','140')
        table.add_col().set_attr('width','400')
        
        table.add_row()
        table.add_header("Search Type: ").set_attr('align','left')
        table.add_cell(name_input)
        table.add_row()
        table.add_header("Title: ").set_attr('align','left')
        table.add_cell(title)
        table.add_row()
        table.add_header("Description: ").set_attr('align','left')
        table.add_cell(description)
        new_search_type_div.add(table)
        new_search_type_div.add_style("display: none")
        #widget.add(new_search_type_div)

        div = DivWdg()

       
        search_type_select = SearchTypeSelectWdg("search_type_filter", mode=SearchTypeSelectWdg.ALL)
        search_type_select.add_empty_option("-- Select --")
        if not search_type_select.get_value():
            search_type_select.set_value(my.search_type)
        search_type_select.set_persist_on_submit()
       

        div.add(search_type_select)

        widget.add(div)

        search_type_select.add_behavior( {'type': 'change', \
                                  'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\
                                    'search_type_filter': bvr.src_el.value});" %(Common.get_full_class_name(my)) } )

        if my.search_type:
            sobj = None
            try:
                sobj = SObjectFactory.create(my.search_type)
            except ImportError:
                widget.add(HtmlElement.br())
                widget.add(SpanWdg('WARNING: Import Error encountered. Please choose another search type.', css='warning')) 
                return widget

            required_columns = sobj.get_required_columns()
           
            if required_columns:
                widget.add(HtmlElement.br())
                req_span = SpanWdg("Required Columns: ", css='med')
                req_span.add_color('color','color')
                widget.add(req_span)
                #required_columns = ['n/a']
                req_span.add(', '.join(required_columns))

            widget.add( HtmlElement.br() )



            if my.file_path:
                hidden = HiddenWdg("file_path", my.file_path)
                widget.add(hidden)
                
                if my.web_url:
                    file_span = FloatDivWdg('URL: <i>%s</i>&nbsp;&nbsp;&nbsp;' %my.web_url, css='med')
                else:
                    file_span = FloatDivWdg('File uploaded: <i>%s</i>&nbsp;&nbsp;&nbsp;' %os.path.basename(my.file_path), css='med')
                file_span.add_color('color','color')
                file_span.add_style('margin: 8px 0 0 10px')
                file_span.add_style('font-size: 14px')
                widget.add(file_span)

                button = ActionButtonWdg(title='Change')
                button.add_style('float','left')
                button.add_behavior( {'type': 'click_up', \
                                   'cbjs_action': "spt.panel.load('csv_import_main','%s', {}, {\
                                    'search_type_filter': '%s'});" %(Common.get_full_class_name(my), my.search_type) } )
                widget.add(button)
                widget.add("<br clear='all'/>")
                widget.add(HtmlElement.br())
                return widget

            widget.add("<br/>")
            widget.add_style("overflow-y: auto")

            msg = DivWdg()
            widget.add(msg)
            msg.add( "<div style='float: left; padding-left: 100px; padding-top: 6px'><b>Upload a csv file: </b></div>")
            msg.add_border()
            msg.add_style("width: 400px")
            msg.add_color("background", "background3")
            msg.add_style("padding: 20px")
            msg.add_style("margin: 30 auto")
            msg.add_style("text-align: center")

            ticket = Environment.get_security().get_ticket_key()

            
            on_complete = '''var server = TacticServerStub.get();
            var file = spt.html5upload.get_file();
            if (file) {
                var file_name = file.name;
                // clean up the file name the way it is done in the server
                file_name = spt.path.get_filesystem_name(file_name);    
                var server = TacticServerStub.get();

                var class_name = 'tactic.ui.widget.CsvImportWdg';
                var values = spt.api.Utility.get_input_values('csv_import_main');
                values['is_refresh'] = true;
                values['file_name'] = file_name;
                values['html5_ticket'] = '%s';
                try {
                    var info = spt.panel.load('csv_import_main', class_name, {}, values);
                    spt.app_busy.hide();
                }
                catch(e) {
                    spt.alert(spt.exception.handler(e));
                }
            }
            else  {
              alert('Error: file object cannot be found.')
            }
            spt.app_busy.hide();'''%ticket
            from tactic.ui.input import UploadButtonWdg
            browse = UploadButtonWdg(name='new_csv_upload', title="Browse", tip="Click to choose a csv file",\
                    on_complete=on_complete, ticket=ticket)
            browse.add_style('float: left')
            msg.add(browse)




            
            # this is now only used in the copy and paste Upload button for backward-compatibility
            upload_wdg = SimpleUploadWdg(key=key, show_upload=False)
            upload_wdg.add_style('display: none')
            msg.add(upload_wdg)
          
            #widget.add(span)
            msg.add("<br/><br/>-- OR --</br/><br/>")

            msg.add("<b>Published URL: </b>") 
            text = TextWdg("web_url")
            msg.add(text)
 


            msg.add("<br/><br/>-- OR --</br/><br/>")

            msg.add("<b>Copy and Paste from a Spreadsheet: </b>") 
            text = TextAreaWdg("data")
            text.add_style('width: 33em')
            text.add_class("spt_import_cut_paste")
            msg.add(text)
            button = ActionButtonWdg(title="Parse")
            button.add_style("margin: 5px auto")
            msg.add(button)
            button.add_behavior( {
                'type': 'click_up',
                'cbjs_action': '''
                var top = bvr.src_el.getParent(".spt_import_top");
                var el = top.getElement(".spt_import_cut_paste");
                var applet = spt.Applet.get();

                var value = el.value;
                var csv = [];
                // convert to a csv file!
                lines = value.split("\\n");
                for (var i = 0; i < lines.length; i++) {
                    if (lines[i] == '') {
                        continue;
                    }
                    var parts = lines[i].split("\\t");
                    var new_line = [];
                    for (var j = 0; j < parts.length; j++) {
                        if (parts[j] == '') {
                            new_line.push('');
                        }
                        else {
                            new_line.push('"'+parts[j]+'"');
                        }
                    }
                    new_line = new_line.join(",");
                    csv.push(new_line);
                }

                csv = csv.join("\\n")

                // FIXME: need to get a local temp directory
                var path = spt.browser.os_is_Windows() ? "C:/sthpw/copy_n_paste.csv" : "/tmp/sthpw/copy_n_paste.csv";
                applet.create_file(path, csv);

                // upload the file
                applet.upload_file(path)
                applet.rmtree(path);

                var top = bvr.src_el.getParent(".spt_import_csv");
                var hidden = top.getElement(".spt_upload_hidden");
                hidden.value = path;

                var file_name = spt.path.get_basename(hidden.value);
                file_name = spt.path.get_filesystem_name(file_name); 
                var class_name = 'tactic.ui.widget.CsvImportWdg';
                var values = spt.api.Utility.get_input_values('csv_import_main');
                values['is_refresh'] = true;
                values['file_name'] = file_name;
                var info = spt.panel.load('csv_import_main', class_name, {}, values);
                '''
            } )

        
        return widget
示例#32
0
    def get_display(self):

        self.doc_mode = self.kwargs.get("doc_mode")
        path = self.kwargs.get("path")
        self.search_type = self.kwargs.get("search_type")

        self.last_path = None

        doc_key = self.kwargs.get("doc_key")
        if doc_key:
            self.doc = Search.get_by_search_key(doc_key)
            snapshot = Snapshot.get_latest_by_sobject(self.doc)
            if snapshot:
                self.last_path = snapshot.get_lib_path_by_type('main')

            path = self.doc.get_value("link")


        # TEST TEST TEST
        if not path:
            #path = "/home/apache/pdf/mongodb.txt"
            #path = "/home/apache/assets/google_docs.html"
            #path = "/home/apache/pdf/star_wars.txt"
            path = "https://docs.google.com/document/d/1AC_YR8X8wbKsshkJ1h8EjZuFIr41guvqXq3_PXgaqJ0/pub?embedded=true"

            path = "https://docs.google.com/document/d/1WPUmXYoSkR2cz0NcyM2vqQYO6OGZW8BAiDL31YEj--M/pub"

            #path = "https://docs.google.com/spreadsheet/pub?key=0Al0xl-XktnaNdExraEE4QkxVQXhaOFh1SHIxZmZMQ0E&single=true&gid=0&output=html"
            path = "/home/apache/tactic/doc/alias.json"

        if not self.search_type:
            self.search_type = "test3/shot"


        self.column = "description"

        top = self.top
        top.add_class("spt_document_top")
        self.set_as_panel(top)

        #table = Table()
        table = ResizableTableWdg()

        top.add(table)
        table.add_row()
        table.set_max_width()

        left_td = table.add_cell()
        left_td.add_style("vertical-align: top")


        title = DivWdg()
        left_td.add(title)
        title.add_style("padding: 10px")
        title.add_color("background", "background3")

        button = IconButtonWdg(title="Refresh", icon=IconWdg.REFRESH)
        title.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            spt.app_busy.show("Reloading Document");
            var top = bvr.src_el.getParent(".spt_document_top");
            spt.panel.refresh(top);
            spt.app_busy.hide();
            '''
        } )
        button.add_style("float: left")


        button = IconButtonWdg(title="Save", icon=IconWdg.SAVE)
        title.add(button)
        button.add_behavior( {
            'type': 'click_up',
            'cbjs_action': '''
            '''
        } )
        button.add_style("float: left")


        if not self.doc_mode:
            self.doc_mode = "text"
        select = SelectWdg("doc_mode")
        select.set_option("values", "text|formatted")
        title.add(select)
        select.set_value(self.doc_mode)
        select.add_behavior( {
            'type': 'change',
            'cbjs_action': '''
            spt.app_busy.show("Reloading Document");
            var top = bvr.src_el.getParent(".spt_document_top");
            var value = bvr.src_el.value;
            top.setAttribute("spt_doc_mode", value);
            spt.panel.refresh(top);
            spt.app_busy.hide();
            '''
        } )


        title.add("<br clear='all'/>")

        #title.add(path)


        text_wdg = DivWdg()
        text_wdg.add_class("spt_document_content")
        left_td.add(text_wdg)

        #if path.startswith("https://docs.google.com/spreadsheet"):
        #    #path = "http://www.southpawtech.com.com"
        #    text_wdg.add('''
        #    <iframe class="spt_document_iframe" style="width: 100%%; height: auto; min-height: 600px; font-size: 1.0em" src="%s"></iframe>
        #    ''' % path)
        #    text_wdg.add_style("overflow-x: hidden")
        if True:

            if not self.last_path and self.doc:
                tmp_dir = Environment.get_tmp_dir()
                tmp_path = '%s/last_path.txt' % tmp_dir
                f = open(tmp_path, 'w')

                text = self.get_text(path, highlight=False)

                f.write(text)
                f.close()

                cmd = FileCheckin(self.doc, tmp_path)
                Command.execute_cmd(cmd)

            else:
                save = False
                if save:
                    # open up the last path
                    f = open(self.last_path, 'r')
                    last_text = f.read()
                    text = self.get_text(path, None, highlight=False)

                    if last_text != text:

                        tmp_dir = Environment.get_tmp_dir()
                        tmp_path = '%s/last_path.txt' % tmp_dir
                        f = open(tmp_path, 'w')
                        f.write(text)
                        f.write(text)
                        f.close()

                        cmd = FileCheckin(self.doc, tmp_path)
                        Command.execute_cmd(cmd)

                text = self.get_text(path, self.last_path)


            lines = text.split("\n") 

            if self.doc_mode == "text":

                num_lines = len(lines)

                """
                line_div = HtmlElement.pre()
                text_wdg.add(line_div)
                line_div.add_style("width: 20px")
                line_div.add_style("float: left")
                line_div.add_style("text-align: right")
                line_div.add_style("opacity: 0.3")
                line_div.add_style("padding-right: 10px")
                for i in range(0, num_lines*2):
                    line_div.add(i+1)
                    line_div.add("<br/>")
                """



            if self.doc_mode == "text":
                pre = HtmlElement.pre()
                pre.add_style("white-space: pre-wrap")
            else:
                pre = DivWdg()
            pre = DivWdg()
            text_wdg.add(pre)

            text_wdg.add_style("padding: 10px 5px")
            text_wdg.add_style("max-height: 600px")
            text_wdg.add_style("overflow-y: auto")
            text_wdg.add_style("width: 600px")
            text_wdg.add_class("spt_resizable")


            pre.add_style("font-family: courier")


            if self.doc_mode == "formatted":
                pre.add(text)

            else:
                line_table = Table()
                pre.add(line_table)
                line_table.add_style("width: 100%")
                count = 1
                for line in lines:
                    #line = line.replace(" ", "&nbsp;")
                    tr = line_table.add_row()
                    if count % 2 == 0:
                        tr.add_color("background", "background", -2)

                    td = line_table.add_cell()

                    # FIXME: hacky
                    if line.startswith('''<span style='background: #CFC'>'''):
                        is_new = True
                    else:
                        td.add_style("vertical-align: top")
                        text = TextWdg()
                        text.add_style("border", "none")
                        text.add_style("text-align", "right")
                        text.add_style("width", "25px")
                        text.add_style("margin", "0 10 0 0")
                        text.add_style("opacity", "0.5")
                        text.set_value(count)
                        td.add(text)
                        count += 1
                        is_new = False

                    td = line_table.add_cell()
                    if not is_new:
                        SmartMenu.assign_as_local_activator( td,'TEXT_CTX' )
                        tr.add_class("spt_line");
                    else:
                        SmartMenu.assign_as_local_activator( td,'TEXT_NEW_CTX' )
                        tr.add_class("spt_new_line");

                    td.add_class("spt_line_content");
                    td.add(line)




            #from tactic.ui.app import AceEditorWdg
            #editor = AceEditorWdg(code=text, show_options=False, readonly=True, height="600px")
             #text_wdg.add(editor)



        # add a click on spt_item
        text_wdg.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': 'spt_document_item',
            'search_type': self.search_type,
            'cbjs_action': '''

            var top = bvr.src_el.getParent(".spt_document_top");
            var data_el = top.getElement(".spt_document_data");

            var search_key = bvr.src_el.getAttribute("spt_search_key");

            var class_name = 'tactic.ui.panel.ViewPanelWdg';
            var kwargs = {
                'search_type': bvr.search_type,
                'search_key': search_key,
            }
            spt.panel.load(data_el, class_name, kwargs);
            '''
        } )


        # add a double click on spt_item
        bgcolor = text_wdg.get_color("background", -10)
        text_wdg.add_relay_behavior( {
            'type': 'mouseover',
            'bvr_match_class': 'spt_document_item',
            'search_type': self.search_type,
            'bgcolor': bgcolor,
            'cbjs_action': '''
            bvr.src_el.setStyle("opacity", "1.0");
            //bvr.src_el.setStyle("font-weight", "normal");
            bvr.src_el.setStyle("background", bvr.bgcolor);
            '''
        } )

        # add a double click on spt_item
        text_wdg.add_relay_behavior( {
            'type': 'mouseout',
            'bvr_match_class': 'spt_document_item',
            'search_type': self.search_type,
            'cbjs_action': '''
            bvr.src_el.setStyle("opacity", "1.0");
            //bvr.src_el.setStyle("font-weight", "bold");
            bvr.src_el.setStyle("background", "");
            '''
        } )






        # add a context menu
        ctx_menu = self.get_text_context_menu()
        ctx_new_menu = self.get_text_new_context_menu()
        menus_in = {
            'TEXT_CTX': ctx_menu,
            'TEXT_NEW_CTX': ctx_new_menu,
        }
        SmartMenu.attach_smart_context_menu( text_wdg, menus_in, False )



        panel = ViewPanelWdg(
                search_type=self.search_type,
                layout="blah"
        )


        right_td = table.add_cell()
        right_td.add_style("vertical-align: top")

        panel_div = DivWdg()
        panel_div.add_class("spt_document_data")
        right_td.add(panel_div)
        panel_div.add(panel)


        text_wdg.add_behavior( {
            'type': 'load',
            'cbjs_action': r'''

spt.document = {};

spt.document.selected_text = null;

spt.document.get_selected_text = function(frame)
{

    var t = '';

    if (frame) {
        var rng = frame.contentWindow.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }

    else if (window.getSelection) // FF4 with one tab open?
    {
        var rng = window.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }
    else if (document.getSelection) // FF4 with multiple tabs open?
    {
        var rng = document.getSelection().getRangeAt(0);
        spt.document.expandtoword(rng);
        t = rng.toString();
    }
    else if (document.selection) // IE8
    {
        var rng = document.selection.createRange();
        // expand range to enclose any word partially enclosed in it
        rng.expand("word");
        t = rng.text;
    }

    // convert newline chars to spaces, collapse whitespace, and trim non-word chars
    return t.replace(/^\W+|\W+$/g, '');
    //return t.replace(/\r?\n/g, " ").replace(/\s+/g, " ").replace(/^\W+|\W+$/g, '');
}

// expand FF range to enclose any word partially enclosed in it
spt.document.expandtoword = function(range)
{
    if (range.collapsed) {
        return;
    }

    while (range.startOffset > 0 && range.toString()[0].match(/\w/)) {
        range.setStart(range.startContainer, range.startOffset - 1);
    }

    while (range.endOffset < range.endContainer.length && range.toString()[range.toString().length - 1].match(/\w/))
    {
        range.setEnd(range.endContainer, range.endOffset + 1);
    }
}
            '''
        } )

        top.add_relay_behavior( {
            'type': 'mouseup',
            'bvr_match_class': 'spt_document_content',
            'cbjs_action': r'''
            //spt.ace_editor.set_editor_top(bvr.src_el);
            //var text = spt.ace_editor.get_selection();
            var text = spt.document.get_selected_text();
            text = text.replace(/\n\n/mg, "\n");
            text = text.replace(/\n\n/mg, "\n");
            spt.document.selected_text = text + "";
            '''
        } )




        return top
示例#33
0
    def get_page_three(my):

        # draw a Movement insert page, followed by Add Tape and Add Physel at the bottom
        div = DivWdg()
        div.add_class('twog_order_top')
        edit_wdg = EditWdg(element_name='general', mode='insert', search_type='twog/movement',\
                title='Add Movement',view='insert', widget_key='edit_layout', cbjs_insert_path='movement/add_item')
        movement_div = edit_wdg

        div.add(movement_div)
        div.add(HtmlElement.br(2))
        add_div = DivWdg()
        add_div.add_class('move_add')
        div.add(add_div)
        table = Table()

        
        table.add_style('width','100%')
        add_div.add(table)
        
        table.add_row()

        select = MovementSelectWdg(name='movement_select')

       

        table.add_row_cell(select)

        table.add_row()
        td = table.add_cell('Add Tape(s)')
        td.add_style('width','300px')
        td = table.add_cell('Add Physel(s)')
        td.add_style('width','300px')
        table.add_row()
        text = TextWdg('add_tape')
        text.add_class('move_add_tape')
        text.add_style('float: left')
        td = table.add_cell(text)
        button = ActionButtonWdg(tip='add', title='+')
        
        bvr = {'type':'click_up',
                'cbjs_action': '''var parent = spt.api.get_parent(bvr.src_el, '.move_add');
                                 var text = spt.api.get_element(parent, '.move_add_tape');
                                 var movement_sel = spt.api.get_element(parent, '.twog_move_select');
                                 var server = TacticServerStub.get();
                                 try {
                                     if (!text.value) {
                                        spt.alert('Tape code is empty.');
                                        return;
                                     }
                                     else {
                                        var tape_sk = server.build_search_key('twog/tape', text.value);
                                        try {
                                        var tape = server.get_by_search_key(tape_sk);
                                        }
                                        catch(e) {
                                        // this above should raise an error already if it doesn't exist
                                        spt.error('This tape does not exist in the system.');
                                        return;
                                        }
                                     }
                                     if (!movement_sel.value) {
                                        spt.alert('You need to select a Movement.');
                                        return;
                                     }
                                
                                 
                                    server.insert('twog/asset_to_movement', {'tape_code':text.value,
                                        'movement_code':movement_sel.value});
                                 } catch(e) {
                                        spt.alert(spt.exception.handler(e));
                                 }'''}
        button.add_behavior(bvr)
        td.add(button)
        text = TextWdg('add_physel')
        text.add_style('float: left')
        td = table.add_cell(text)
        button = ActionButtonWdg(tip='add', title='+')
        button.add_behavior(bvr)
        td.add(button)

        div.add(HtmlElement.br(2))
        # finally add the asset_to_movement table layout
        association_div = DivWdg(HtmlElement.b('Assets in Movement'))
        div.add(association_div)
        div.add(HtmlElement.br())
        layout = FastTableLayoutWdg(search_type='twog/asset_to_movement', view='table')
        div.add(layout)

        return div