示例#1
0
    def _get_target_span(self):
        # get the target span
        search = Search(self.container_cls)
        self._order_search(search)
        groups = search.get_sobjects()
        if groups:
            self.container_sobj = groups[0]

        target_span = SpanWdg(css='med')
        group_table = Table(self.GROUP_TABLE_NAME, css='table')
        group_table.add_style('width', '30em')
        group_table.add_col(css='small')
        group_table.add_col(css='small')
        group_table.add_col()

        target_span.add(group_table)
        group_table.add_row_cell(search.get_search_type_obj()\
            .get_description(), "heading")
        checkbox = CheckboxWdg()
        checkbox.set_option("onclick", \
            "a=new Elements('container_ids');a.toggle_all(this);")
        group_table.add_row()
        group_table.add_cell(checkbox)
        col_name = group_table.get_next_col_name()

        toggle_control = HiddenRowToggleWdg(col_name=col_name,
                                            is_control=True,
                                            auto_index=True)

        group_table.add_cell(toggle_control)
        group_table.add_cell('MASTER CONTROL')

        remove_cmd = HiddenWdg(SObjectGroupCmd.REMOVE_CMD)
        self.add(remove_cmd)
        for group in groups:
            group_table.add_row()
            checkbox = CheckboxWdg("container_ids")
            checkbox.set_option("value", group.get_primary_key_value())

            toggle = HiddenRowToggleWdg(col_name, auto_index=True)
            toggle.store_event()

            group_details = ItemInContainerWdg(group, self.item_sobj,
                                               self.item_cls,
                                               self.grouping_cls)

            # set the target content of the toggle
            toggle.set_static_content(group_details)

            group_table.add_cell(checkbox)
            group_table.add_cell(toggle, add_hidden_wdg=True)
            group_table.add_cell(group.get_description())
            num_items = group_details.get_num_items()
            if num_items:
                td = group_table.add_cell("( %s )" % num_items, 'no_wrap')
                td.add_color(color)
            else:
                group_table.add_blank_cell()

        return target_span
示例#2
0
 def _get_target_span(my):
     # get the target span
     search = Search(my.container_cls)
     my._order_search(search)
     groups = search.get_sobjects()
     if groups:
         my.container_sobj = groups[0]
     
     target_span = SpanWdg(css='med')
     group_table = Table(my.GROUP_TABLE_NAME, css='table')
     group_table.add_style('width','30em')
     group_table.add_col(css='small')
     group_table.add_col(css='small')    
     group_table.add_col()    
         
     target_span.add(group_table)
     group_table.add_row_cell(search.get_search_type_obj()\
         .get_description(), "heading")
     checkbox = CheckboxWdg()
     checkbox.set_option("onclick", \
         "a=new Elements('container_ids');a.toggle_all(this);")
     group_table.add_row()
     group_table.add_cell(checkbox)
     col_name = group_table.get_next_col_name() 
     
     toggle_control = HiddenRowToggleWdg(col_name=col_name, is_control=True, auto_index=True)
   
     group_table.add_cell(toggle_control)
     group_table.add_cell('MASTER CONTROL')
     
     remove_cmd = HiddenWdg(SObjectGroupCmd.REMOVE_CMD)
     my.add(remove_cmd)
     for group in groups:
         group_table.add_row()
         checkbox = CheckboxWdg("container_ids")
         checkbox.set_option("value", group.get_primary_key_value() )
         
         toggle = HiddenRowToggleWdg(col_name, auto_index=True)
         toggle.store_event()
      
         group_details = ItemInContainerWdg( group, my.item_sobj, my.item_cls, my.grouping_cls )
        
         # set the target content of the toggle
         toggle.set_static_content(group_details)
        
         group_table.add_cell( checkbox )
         group_table.add_cell( toggle, add_hidden_wdg=True )
         group_table.add_cell( group.get_description())
         num_items = group_details.get_num_items()
         if num_items:
             td = group_table.add_cell( "( %s )" % num_items, 'no_wrap')
             td.add_color(color)
         else:
             group_table.add_blank_cell()
    
     
     return target_span
示例#3
0
    def init(my):
        
 
        my.item_cls = my.kwargs.get('left_search_type')
        my.container_cls = my.kwargs.get('right_search_type')
        my.grouping_cls  = my.kwargs.get('search_type')

        my.item_sobj = my.container_sobj = None 
        
        # List the items
        search = Search(my.item_cls)
        my._order_search(search)    
        
        items = search.get_sobjects()
        if items:
            my.item_sobj = items[0]
        #select = MultiSelectWdg("item_ids")
        #select.set_search_for_options(search,"login", "get_full_name()")

        user_span = SpanWdg(css='med')
        
        user_table = Table(css='table')
        user_table.add_style("margin-left: 6px")
        user_table.set_max_width()
        user_table.add_col(css='small')
        user_table.add_col()
        
        user_table.add_style("min-width: 14em")
        user_table.add_row_cell(search.get_search_type_obj()\
            .get_description(), "heading")

        for item in items:
            user_table.add_row()
            checkbox = CheckboxWdg("item_ids")
            checkbox.set_option("value", item.get_primary_key_value() )
            user_table.add_cell( checkbox )

            project_code = item.get_value("project_code", no_exception=True)
            if project_code:
                user_table.add_cell( "[ %s ]" % project_code )
            else:
                user_table.add_cell( "[ * ]" )

            user_table.add_cell( item.get_description() )
        user_span.add(user_table)

        # control widget in the middle
        control_div = DivWdg()
        control_div.add_style('padding: 100px 10px 0 10px')

        button = IconSubmitWdg(my.ADD_LABEL, "stock_insert-slide.png", True)
        button.add_style('padding: 2px 30px 4px 30px')
        control_div.add(button)
        
        
        main_table = Table(css='collapse')
        main_table.set_max_width()
        main_table.add_row(css='plain_bg')
        main_table.add_cell(user_span, 'valign_top')
        td = main_table.add_cell(control_div, 'valign_top')
        td.add_style('width','12em')
        main_table.add_cell(my._get_target_span(), 'valign_top')

        my.add(main_table)
    
        # register command here
        if my.item_sobj and my.container_sobj:
            marshaller = WebContainer.register_cmd("pyasm.widget.SObjectGroupCmd")
            marshaller.set_option("grouping_search_type", my.grouping_cls)
            marshaller.set_option("item_foreign_key", my.item_sobj.get_foreign_key())
            marshaller.set_option("container_foreign_key", my.container_sobj.get_foreign_key())
示例#4
0
    def get_display(my): 

        top = my.top
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("padding: 10px")
        top.add_style("min-width: 400px")

        from tactic.ui.app import HelpButtonWdg
        help_wdg = HelpButtonWdg(alias="exporting-csv-data")
        top.add(help_wdg)
        help_wdg.add_style("float: right")
        help_wdg.add_style("margin-top: -3px")
        
        if not my.check(): 
            top.add(DivWdg('Error: %s' %my.error_msg))
            top.add(HtmlElement.br(2))
            return super(CsvExportWdg, my).get_display()

        if my.search_type_list and my.search_type_list[0] != my.search_type:
            st = SearchType.get(my.search_type_list[0])
            title_div =DivWdg('Exporting related items [%s]' % st.get_title())
            top.add(title_div)
            top.add(HtmlElement.br())
            my.search_type = my.search_type_list[0]
            my.view = my.related_view

        if my.mode != 'export_all':
            num = len(my.selected_search_keys)
        else:
            search = Search(my.search_type)
            num = search.get_count()
        msg_div = DivWdg('Total: %s items to export'% num)
        msg_div.add_style("font-size: 12px")
        msg_div.add_style("font-weight: bold")
        msg_div.add_style('margin-left: 4px')
        top.add(msg_div)
        if num > 300:
            msg_div.add_behavior({'type':'load',
            'cbjs_action': "spt.alert('%s items are about to be exported. It may take a while.')" %num})
                
        top.add(HtmlElement.br())

        div  = DivWdg(css='spt_csv_export', id='csv_export_action')
        div.add_color("background", "background", -10)
        div.add_style("padding: 10px")
        div.add_style("margin: 5px")
        
        div.add_styles('max-height: 350px; overflow: auto')
        table = Table( css='minimal')
        table.add_color("color", "color")
        div.add(table)
        table.set_id('csv_export_table')
        table.center()
        
        
        cb_name = 'csv_column_name'
        master_cb = CheckboxWdg('master_control')
        master_cb.set_checked()
        master_cb.add_behavior({'type': 'click_up',
            'propagate_evt': True,
            'cbjs_action': '''
                var inputs = spt.api.Utility.get_inputs(bvr.src_el.getParent('.spt_csv_export'),'%s');
                for (var i = 0; i < inputs.length; i++)
                    inputs[i].checked = !inputs[i].checked;
                    ''' %cb_name})


        span = SpanWdg('Select Columns To Export')
        span.add_style('font-weight','600')
        table.add_row_cell(span)
        table.add_row_cell(HtmlElement.br())

        tr = table.add_row()
        tr.add_style('border-bottom: 1px groove #777')
        td = table.add_cell(master_cb)
        label = HtmlElement.i('toggle all')
        label.add_style('color: #888')
        table.add_cell(label)


        col1 = table.add_col()
        col1.add_style('width: 35px')
        col2 = table.add_col()
        
        if not my.search_type or not my.view:
            return table

        
        # use overriding element names and derived titles if available
        config = WidgetConfigView.get_by_search_type(my.search_type, my.view)
        if my.element_names and config:
            filtered_columns = my.element_names
            titles = []
            for name in my.element_names:
                title = config.get_element_title(name)
                titles.append(title)

        else:
            
            # excluding FunctionalTableElement
            filtered_columns = []
            titles = []
            if not config:
                columns = search.get_columns()
                filtered_columns = columns
                titles = ['n/a'] * len(filtered_columns)
            else:
                columns = config.get_element_names()
                
                filtered_columns = columns
                titles = config.get_element_titles()

        
            """
            # commented out until it is decided 2.5 widgets will 
            # use this class to differentiate between reg and functional element
            from pyasm.widget import FunctionalTableElement
            for column in columns:
                widget = config.get_display_widget(column)

                if isinstance(widget, FunctionalTableElement):
                    continue
                filtered_columns.append(column)
            """

        for idx, column in enumerate(filtered_columns):
            table.add_row()
            cb = CheckboxWdg(cb_name)
            cb.set_option('value', column)
            cb.set_checked()
            table.add_cell(cb)
            
            
            title = titles[idx]
            table.add_cell('<b>%s</b> (%s) '%(title, column))

        action_div = DivWdg()
        widget = DivWdg()
        table.add_row_cell(widget)
        widget.add_style("margin: 20px 0 10px 0px")
        cb = CheckboxWdg('include_id', label=" Include ID")
        cb.set_default_checked()
        widget.add(cb)
        hint = HintWdg('To update entries with specific ID later, please check this option. For new inserts in this or other table later on, uncheck this option.') 
        widget.add(hint)

        label = string.capwords(my.mode.replace('_', ' '))
        button = ActionButtonWdg(title=label)

        is_export_all  = my.mode == 'export_all'
        button.add_behavior({
            'type': "click_up",
            'cbfn_action': 'spt.dg_table_action.csv_export',
            'element': 'csv_export',
            'column_names': 'csv_column_name',
            'search_type': my.search_type,
            'view': my.view,
            'search_keys' : my.selected_search_keys,
            'is_export_all' : is_export_all
            
        })

        my.close_action = "var popup = bvr.src_el.getParent('.spt_popup');spt.popup.close(popup)"
        if my.close_action:
            close_button = ActionButtonWdg(title='Close')
            close_button.add_behavior({
                'type': "click",
                'cbjs_action': my.close_action
            })


        table = Table()
        action_div.add(table)
        table.center()
        table.add_row()
        td = table.add_cell(button)
        td.add_style("width: 130px")
        table.add_cell(close_button)

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

        top.add(div)
        top.add(HtmlElement.br())
        top.add(action_div)
        return top
示例#5
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
示例#6
0
    def get_upload_wdg(self):
        widget = Widget()

        # get the search type
        widget.add("1. Select type of asset: ")

        # 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")

        table = Table()
        table.add_style("margin: 10px 20px")
        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)

        # or use a pre-existing one
        search_type_select = SearchTypeSelectWdg("filter|search_type")
        search_type_select.add_empty_option("-- Select --")
        search_type_select.set_persist_on_submit()
        search_type_select.set_submit_onchange()
        widget.add(search_type_select)

        self.search_type = search_type_select.get_value()
        if self.search_type:
            sobj = SObjectFactory.create(self.search_type)
            required_columns = sobj.get_required_columns()

            widget.add(SpanWdg("Required Columns: ", css='med'))
            if not required_columns:
                required_columns = ['n/a']
            widget.add(SpanWdg(', '.join(required_columns), css='med'))

        widget.add(HtmlElement.br(2))
        widget.add("2. Upload a csv file: ")
        upload_wdg = HtmlElement.upload("uploaded_file")
        widget.add(upload_wdg)
        submit = IconSubmitWdg("Upload", IconWdg.UPLOAD, True)
        widget.add(submit)

        web = WebContainer.get_web()
        field_storage = web.get_form_value("uploaded_file")
        if field_storage != "":
            upload = FileUpload()
            upload.set_field_storage(field_storage)
            upload.set_create_icon(False)
            upload.execute()

            files = upload.get_files()
            if files:
                self.file_path = files[0]
            else:
                self.file_path = web.get_form_value("file_path")

        if self.file_path:
            hidden = HiddenWdg("file_path", self.file_path)
            widget.add(hidden)

        return widget
示例#7
0
    def get_display(my):
        div = DivWdg()

        sobject = my.get_sobject_from_kwargs()
        if not sobject:
            div.add("SObject not found")
            return div

        search_type_obj = sobject.get_search_type_obj()
        title = search_type_obj.get_title()
        title_wdg = DivWdg()
        title_wdg.add_style("font-size: 1.8em")
        title_wdg.add("%s: %s" % (title, sobject.get_code() ) )

        div.add(title_wdg)
        div.add(HtmlElement.hr())


        table = Table()
        table.set_max_width()

        col1 = table.add_col()
        col1.add_style('width: 200px')
        col2 = table.add_col()
        col2.add_style('width: 320px')
        col3 = table.add_col()
        col3.add_style('width: 400px')
        table.add_row()

        from pyasm.widget import ThumbWdg, DiscussionWdg, SObjectTaskTableElement

        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("border-right: solid 1px")
        title = DivWdg()
        title.add_class("maq_search_bar")
        #x = DivWdg("[?] [x]")
        #x.add_style("float: right")
        #title.add(x)
        title.add("Info")
        td.add(title)
        thumb = ThumbWdg()
        thumb.set_sobject(sobject)
        thumb.set_option("detail", "false")
        td.add(thumb)
        from pyasm.prod.web import AssetInfoWdg
        info = AssetInfoWdg()
        info.thumb = thumb
        info.set_sobject(sobject)
        td.add(info)

        # tasks
        td = table.add_cell()
        td.add_style("vertical-align: top")
        td.add_style("padding-left: 5px")
        td.add_style("border-right: solid 1px")
        title = DivWdg()
        title.add_class("maq_search_bar")
        #x = DivWdg("[x]")
        #x.add_style("float: right")
        #title.add(x)
        title.add("Tasks")
        td.add(title)
        task_wdg = SObjectTaskTableElement()
        task_wdg.set_sobject(sobject)
        td.add(task_wdg)
        td.add_style('cell-padding','10')


        # discussion
        td = table.add_cell()
        #td.add_style("min-width: 300px")
        #td.add_style("width: 600px")
        td.add_style("vertical-align: top")
        td.add_style("padding-left: 5px")
        td.add_style("border-right: solid 1px")
       
        title = DivWdg()
        title.add_class("maq_search_bar")
        #x = DivWdg("[x]")
        #x.add_style("float: right")
        #title.add(x)
        title.add("Notes")
        td.add(title)
        discussion_wdg = DiscussionWdg()
        discussion_wdg.preprocess()
        discussion_wdg.set_sobject(sobject)
        td.add(discussion_wdg)
        note_panel = discussion_wdg.get_note_menu()
        td.add(note_panel)

        div.add(table)
       

        div.add(HtmlElement.hr())
        div.add(HtmlElement.br(clear="all"))

        title_wdg = DivWdg()
        title_wdg.add_class("maq_search_bar")
        #x = DivWdg("[x]")
        #x.add_style("float: right")
        #title_wdg.add(x)
        #title_wdg.add_style("font-size: 1.5em")
        title_wdg.add("Detail" )
        div.add(title_wdg)
        div.add(HtmlElement.br())



        # TEST getting schema
        search_type = sobject.get_base_search_type()
        schema = Schema.get_by_sobject(sobject)
        child_types = schema.get_child_types(search_type)




        # add a second table
        table = Table()
        table.set_max_width()


        # show the snapshots for this sobject
        search_type = "sthpw/snapshot"
        search = Search(search_type)
        search.add_sobject_filter(sobject)
        search.set_limit(25)
        sobjects = search.get_sobjects()


        table.add_row()
        nav_td = table.add_cell()
        nav_td.add_style("width: 100px")
        nav_td.add_style("vertical-align: top")
        section_wdg = my.get_section_wdg(sobject)
        nav_td.add( section_wdg )

        parent_key = SearchKey.get_by_sobject(sobject)
        content_wdg = ViewPanelWdg(search_type=search_type, element_name='Snapshots', \
            title='Snapshots', view='table', parent_key=parent_key, do_search=True)
        #content_wdg.set_sobjects(sobjects)
        content_td = table.add_cell()
        content_td.set_id("sobject_relation")
        content_td.add_style("display: table-cell")
        content_td.add_style("vertical-align: top")
        content_td.add_style("padding-left: 10px")
        content_td.add(content_wdg)

        div.add(table)

        return div
示例#8
0
    def get_upload_wdg(my):
        widget = Widget()

        # get the search type
        widget.add( "1. Select type of asset: ")

        # 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")

        table = Table()
        table.add_style("margin: 10px 20px")
        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)


        # or use a pre-existing one
        search_type_select = SearchTypeSelectWdg("filter|search_type")
        search_type_select.add_empty_option("-- Select --")
        search_type_select.set_persist_on_submit()
        search_type_select.set_submit_onchange()
        widget.add(search_type_select)
        

        my.search_type = search_type_select.get_value()
        if my.search_type:
            sobj = SObjectFactory.create(my.search_type)
            required_columns = sobj.get_required_columns()
            
            widget.add(SpanWdg("Required Columns: ", css='med'))
            if not required_columns:
                required_columns = ['n/a']
            widget.add(SpanWdg(', '.join(required_columns), css='med'))

        widget.add( HtmlElement.br(2) )
        widget.add( "2. Upload a csv file: ")
        upload_wdg = HtmlElement.upload("uploaded_file")
        widget.add(upload_wdg)
        submit = IconSubmitWdg("Upload", IconWdg.UPLOAD, True)
        widget.add(submit)

        web = WebContainer.get_web()
        field_storage = web.get_form_value("uploaded_file")
        if field_storage != "":
            upload = FileUpload()
            upload.set_field_storage(field_storage)
            upload.set_create_icon(False)
            upload.execute()

            files = upload.get_files()
            if files:
                my.file_path = files[0]
            else:
                my.file_path = web.get_form_value("file_path")


        if my.file_path:
            hidden = HiddenWdg("file_path", my.file_path)
            widget.add(hidden)

        return widget
示例#9
0
    def init(self):

        self.item_cls = self.kwargs.get('left_search_type')
        self.container_cls = self.kwargs.get('right_search_type')
        self.grouping_cls = self.kwargs.get('search_type')

        self.item_sobj = self.container_sobj = None

        # List the items
        search = Search(self.item_cls)
        self._order_search(search)

        items = search.get_sobjects()
        if items:
            self.item_sobj = items[0]
        #select = MultiSelectWdg("item_ids")
        #select.set_search_for_options(search,"login", "get_full_name()")

        user_span = SpanWdg(css='med')

        user_table = Table(css='table')
        user_table.add_style("margin-left: 6px")
        user_table.set_max_width()
        user_table.add_col(css='small')
        user_table.add_col()

        user_table.add_style("min-width: 14em")
        user_table.add_row_cell(search.get_search_type_obj()\
            .get_description(), "heading")

        for item in items:
            user_table.add_row()
            checkbox = CheckboxWdg("item_ids")
            checkbox.set_option("value", item.get_primary_key_value())
            user_table.add_cell(checkbox)

            project_code = item.get_value("project_code", no_exception=True)
            if project_code:
                user_table.add_cell("[ %s ]" % project_code)
            else:
                user_table.add_cell("[ * ]")

            user_table.add_cell(item.get_description())
        user_span.add(user_table)

        # control widget in the middle
        control_div = DivWdg()
        control_div.add_style('padding: 100px 10px 0 10px')

        button = IconSubmitWdg(self.ADD_LABEL, "stock_insert-slide.png", True)
        button.add_style('padding: 2px 30px 4px 30px')
        control_div.add(button)

        main_table = Table(css='collapse')
        main_table.set_max_width()
        main_table.add_row(css='plain_bg')
        main_table.add_cell(user_span, 'valign_top')
        td = main_table.add_cell(control_div, 'valign_top')
        td.add_style('width', '12em')
        main_table.add_cell(self._get_target_span(), 'valign_top')

        self.add(main_table)

        # register command here
        if self.item_sobj and self.container_sobj:
            marshaller = WebContainer.register_cmd(
                "pyasm.widget.SObjectGroupCmd")
            marshaller.set_option("grouping_search_type", self.grouping_cls)
            marshaller.set_option("item_foreign_key",
                                  self.item_sobj.get_foreign_key())
            marshaller.set_option("container_foreign_key",
                                  self.container_sobj.get_foreign_key())
示例#10
0
    def get_display(my): 

        top = my.top
        top.add_color("background", "background")
        top.add_color("color", "color")
        top.add_style("padding: 10px")
        top.add_style("min-width: 400px")

        from tactic.ui.app import HelpButtonWdg
        help_wdg = HelpButtonWdg(alias="exporting-csv-data")
        top.add(help_wdg)
        help_wdg.add_style("float: right")
        help_wdg.add_style("margin-top: -3px")
        
        if not my.check(): 
            top.add(DivWdg('Error: %s' %my.error_msg))
            top.add(HtmlElement.br(2))
            return super(CsvExportWdg, my).get_display()

        if my.search_type_list and my.search_type_list[0] != my.search_type:
            st = SearchType.get(my.search_type_list[0])
            title_div =DivWdg('Exporting related items [%s]' % st.get_title())
            top.add(title_div)
            top.add(HtmlElement.br())
            my.search_type = my.search_type_list[0]
            my.view = my.related_view

        if my.mode != 'export_all':
            num = len(my.selected_search_keys)
        else:
            search = Search(my.search_type)
            num = search.get_count()
        msg_div = DivWdg('Total: %s items to export'% num)
        msg_div.add_style("font-size: 12px")
        msg_div.add_style("font-weight: bold")
        msg_div.add_style('margin-left: 4px')
        top.add(msg_div)
        if num > 300:
            msg_div.add_behavior({'type':'load',
            'cbjs_action': "spt.alert('%s items are about to be exported. It may take a while.')" %num})
                
        top.add(HtmlElement.br())

        div  = DivWdg(css='spt_csv_export', id='csv_export_action')
        div.add_color("background", "background", -10)
        div.add_style("padding: 10px")
        div.add_style("margin: 5px")
        
        div.add_styles('max-height: 350px; overflow: auto')
        table = Table( css='minimal')
        table.add_color("color", "color")
        div.add(table)
        table.set_id('csv_export_table')
        table.center()
        
        
        cb_name = 'csv_column_name'
        master_cb = CheckboxWdg('master_control')
        master_cb.set_checked()
        master_cb.add_behavior({'type': 'click_up',
            'propagate_evt': True,
            'cbjs_action': '''
                var inputs = spt.api.Utility.get_inputs(bvr.src_el.getParent('.spt_csv_export'),'%s');
                for (var i = 0; i < inputs.length; i++)
                    inputs[i].checked = !inputs[i].checked;
                    ''' %cb_name})


        span = SpanWdg('Select Columns To Export')
        span.add_style('font-weight','600')
        table.add_row_cell(span)
        table.add_row_cell(HtmlElement.br())

        tr = table.add_row()
        tr.add_style('border-bottom: 1px groove #777')
        td = table.add_cell(master_cb)
        label = HtmlElement.i('toggle all')
        label.add_style('color: #888')
        table.add_cell(label)


        col1 = table.add_col()
        col1.add_style('width: 35px')
        col2 = table.add_col()
        
        if not my.search_type or not my.view:
            return table

        # use overriding element names and derived titles if available
        config = WidgetConfigView.get_by_search_type(my.search_type, my.view)
        if my.element_names and config:
            filtered_columns = my.element_names
            titles = []
            for name in my.element_names:
                title = config.get_element_title(name)
                titles.append(title)

        else:
            
            # excluding FunctionalTableElement
            filtered_columns = []
            titles = []
            if not config:
                columns = search.get_columns()
                filtered_columns = columns
                titles = ['n/a'] * len(filtered_columns)
            else:
                columns = config.get_element_names()
                
                filtered_columns = columns
                titles = config.get_element_titles()

        
            """
            # commented out until it is decided 2.5 widgets will 
            # use this class to differentiate between reg and functional element
            from pyasm.widget import FunctionalTableElement
            for column in columns:
                widget = config.get_display_widget(column)

                if isinstance(widget, FunctionalTableElement):
                    continue
                filtered_columns.append(column)
            """

        for idx, column in enumerate(filtered_columns):
            table.add_row()
            cb = CheckboxWdg(cb_name)
            cb.set_option('value', column)
            cb.set_checked()
            table.add_cell(cb)
            
            
            title = titles[idx]
            table.add_cell('<b>%s</b> (%s) '%(title, column))

        action_div = DivWdg()
        widget = DivWdg()
        table.add_row_cell(widget)
        widget.add_style("margin: 20px 0 10px 0px")
        cb = CheckboxWdg('include_id', label=" Include ID")
        cb.set_default_checked()
        widget.add(cb)
        hint = HintWdg('To update entries with specific ID later, please check this option. For new inserts in this or other table later on, uncheck this option.') 
        widget.add(hint)

        label = string.capwords(my.mode.replace('_', ' '))
        button = ActionButtonWdg(title=label, size='l')
        is_export_all  = my.mode == 'export_all'
        button.add_behavior({
            'type': "click_up",
            'cbfn_action': 'spt.dg_table_action.csv_export',
            'element': 'csv_export',
            'column_names': 'csv_column_name',
            'search_type': my.search_type,
            'view': my.view,
            'search_keys' : my.selected_search_keys,
            'is_export_all' : is_export_all
            
        })

        my.close_action = "var popup = bvr.src_el.getParent('.spt_popup');spt.popup.close(popup)"
        if my.close_action:
            close_button = ActionButtonWdg(title='Close')
            close_button.add_behavior({
                'type': "click",
                'cbjs_action': my.close_action
            })


        table = Table()
        action_div.add(table)
        table.center()
        table.add_row()
        td = table.add_cell(button)
        td.add_style("width: 130px")
        table.add_cell(close_button)

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

        top.add(div)
        top.add(HtmlElement.br())
        top.add(action_div)

        if my.is_test:
            rtn_data = {'columns': my.element_names, 'count': len(my.selected_search_keys)}
            if my.mode == 'export_matched':
                rtn_data['sql'] =  my.table.search_wdg.search.get_statement()
            from pyasm.common import jsondumps
            rtn_data = jsondumps(rtn_data)
            return rtn_data

        return top
示例#11
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