def get_display(my):

        dd_activator = DivWdg()

        if my.style:
            dd_activator.add_styles( my.style )

        dd_activator.add_style( "width: %spx" % my.width )
        dd_activator.add_class("SPT_DTS");

        if my.nudge_menu_horiz != 0:
            dd_activator.set_attr("spt_nudge_menu_horiz", my.nudge_menu_horiz)

        if my.nudge_menu_vert != 0:
            dd_activator.set_attr("spt_nudge_menu_vert", my.nudge_menu_vert)

        # Generate button ...
        #
        table = Table()
        table.add_row()
        table.add_styles("width: 100%; padding: 0px; margin: 0px;")
        td = table.add_cell()
        td.add_looks("menu border curs_default")
        td.add_styles( "padding: 0px; width: 100%; overflow: hidden; height: 12px; max-height: 12px;" )

        title_div = DivWdg()
        title_div.add_styles( "padding: 0px; margin-left: 4px; margin-top: 1px;" )
        if my.icon_path:
            img = HtmlElement.img()
            img.set_attr("src", my.icon_path)
            img.set_attr("title", my.title)
            img.add_styles("padding: 0px; padding-bottom: 1px; margin: 0px; text-decoration: none;")
            title_div.add(img)
            title_div.add_looks("menu")
        else:
            title_div.add(my.title)
            title_div.add_looks("menu fnt_text")

        td.add( title_div )

        td = table.add_cell()
        # -- Example of setting only some of the borders with dotted style ...
        # td.add_looks( "menu_btn_icon clear_borders border_bottom border_right dotted" )
        td.add_looks( "menu_btn_icon border curs_default" )
        td.add_styles( "padding: 0px; text-align: center; overflow: hidden; " \
                       "width: 15px; min-width: 15px;" \
                       "height: 12px; max-height: 12px;" )

        arrow_img = HtmlElement.img("/context/icons/silk/_spt_bullet_arrow_down_dark_8x8.png")
        arrow_img.add_styles( "border: 0px; margin-left: 1px; margin-top: 0px;" )
        td.add( arrow_img )

        dd_activator.add(table)

        dd_activator.add( my.kwargs.get("smart_menu_set") )
        dd_activator.add_class("SPT_SMENU_ACTIVATOR")
        dd_activator.add_behavior( { 'type': 'click_up', 'activator_type' : 'smart_menu',
                                     'cbjs_action': 'spt.smenu.show_on_dropdown_click_cbk( evt, bvr )' } )

        return dd_activator
示例#2
0
    def get_display(self):

        dd_activator = DivWdg()

        if self.style:
            dd_activator.add_styles( self.style )

        dd_activator.add_style( "width: %spx" % self.width )
        dd_activator.add_class("SPT_DTS");

        if self.nudge_menu_horiz != 0:
            dd_activator.set_attr("spt_nudge_menu_horiz", self.nudge_menu_horiz)

        if self.nudge_menu_vert != 0:
            dd_activator.set_attr("spt_nudge_menu_vert", self.nudge_menu_vert)

        # Generate button ...
        #
        table = Table()
        table.add_row()
        table.add_styles("width: 100%; padding: 0px; margin: 0px;")
        td = table.add_cell()
        td.add_looks("menu border curs_default")
        td.add_styles( "padding: 0px; width: 100%; overflow: hidden; height: 12px; max-height: 12px;" )

        title_div = DivWdg()
        title_div.add_styles( "padding: 0px; margin-left: 4px; margin-top: 1px;" )
        if self.icon_path:
            img = HtmlElement.img()
            img.set_attr("src", self.icon_path)
            img.set_attr("title", self.title)
            img.add_styles("padding: 0px; padding-bottom: 1px; margin: 0px; text-decoration: none;")
            title_div.add(img)
            title_div.add_looks("menu")
        else:
            title_div.add(self.title)
            title_div.add_looks("menu fnt_text")

        td.add( title_div )

        td = table.add_cell()
        # -- Example of setting only some of the borders with dotted style ...
        # td.add_looks( "menu_btn_icon clear_borders border_bottom border_right dotted" )
        td.add_looks( "menu_btn_icon border curs_default" )
        td.add_styles( "padding: 0px; text-align: center; overflow: hidden; " \
                       "width: 15px; min-width: 15px;" \
                       "height: 12px; max-height: 12px;" )

        arrow_img = HtmlElement.img("/context/icons/silk/_spt_bullet_arrow_down_dark_8x8.png")
        arrow_img.add_styles( "border: 0px; margin-left: 1px; margin-top: 0px;" )
        td.add( arrow_img )

        dd_activator.add(table)

        dd_activator.add( self.kwargs.get("smart_menu_set") )
        dd_activator.add_class("SPT_SMENU_ACTIVATOR")
        dd_activator.add_behavior( { 'type': 'click_up', 'activator_type' : 'smart_menu',
                                     'cbjs_action': 'spt.smenu.show_on_dropdown_click_cbk( evt, bvr )' } )

        return dd_activator
示例#3
0
    def get_display(self):

        table = Table()
        table.add_row()

        count = 0
        for btn_wdg in self.button_widgets:
            td = table.add_cell()
            if self.spacing and count:
                td.add_styles("padding-left: %spx;" % self.spacing)
            count += 1
            td.add(btn_wdg)

        if self.float:
            table.add_styles("float: %s;" % self.float)
        if self.align:
            if self.align == "left":
                table.push_left()
            elif self.align == "right":
                table.push_right()
            elif self.align == "center":
                table.center()

        return table
示例#4
0
    def get_display(my):
        
        table = Table()
        table.add_row()

        count = 0
        for btn_wdg in my.button_widgets:
            td = table.add_cell()
            if my.spacing and count:
                td.add_styles( "padding-left: %spx;" % my.spacing )
            count += 1
            td.add( btn_wdg )

        if my.float:
            table.add_styles("float: %s;" % my.float)
        if my.align:
            if my.align == "left":
                table.push_left()
            elif my.align == "right":
                table.push_right()
            elif my.align == "center":
                table.center()

        return table
示例#5
0
    def get_display(my):

        dd_activator = DivWdg()
        dd_activator.set_id( my.id )

        if my.style:
            dd_activator.add_styles( my.style )

        dd_activator.add_style( "width: %spx" % my.width )
        dd_activator.add_class("SPT_DTS");

        if my.nudge_menu_horiz != 0:
            dd_activator.set_attr("spt_nudge_menu_horiz", my.nudge_menu_horiz)

        if my.nudge_menu_vert != 0:
            dd_activator.set_attr("spt_nudge_menu_vert", my.nudge_menu_vert)

        # Generate button ...
        #
        table = Table()
        table.add_row()
        table.add_styles("width: 100%; padding: 0px; margin: 0px;")
        td = table.add_cell()
        td.add_looks("menu border curs_default")
        td.add_styles( "padding: 0px; width: 100%; overflow: hidden; height: 12px; max-height: 12px;" )

        title_div = DivWdg()
        title_div.add_styles( "padding: 0px; margin-left: 4px; margin-top: 1px;" )
        title_div.add_looks("menu fnt_text")
        title_div.add(my.title)

        td.add( title_div )

        td = table.add_cell()
        # -- Example of setting only some of the borders with dotted style ...
        # td.add_looks( "menu_btn_icon clear_borders border_bottom border_right dotted" )
        td.add_looks( "menu_btn_icon border curs_default" )
        td.add_styles( "padding: 0px; text-align: center; overflow: hidden; " \
                       "width: 15px; min-width: 15px;" \
                       "height: 12px; max-height: 12px;" )

        arrow_img = HtmlElement.img("/context/icons/silk/_spt_bullet_arrow_down_dark_8x8.png")
        arrow_img.add_styles( "border: 0px; margin-left: 1px; margin-top: 0px;" )
        td.add( arrow_img )

        dd_activator.add(table)

        # Now generate the main drop down menu and any needed sub-menus ...
        #
        dd_map = my.menus[0]
        if not dd_map.has_key('allow_icons'):
            dd_map['allow_icons'] = True  # default is to allow icons
        if my.match_width:
            dd_map['width'] = my.width

        dd_menu_wdg = DropdownMenuWdg( activator_wdg=dd_activator, menu_id=dd_map['menu_id'],
                                       width=dd_map['width'], opt_spec_list=dd_map['opt_spec_list'],
                                       allow_icons=dd_map['allow_icons'] )
        dd_activator.add( dd_menu_wdg )

        sm_map_list = my.menus[1:]
        for sm_map in sm_map_list:
            if not sm_map.has_key('allow_icons'):
                sm_map['allow_icons'] = True
            submenu_wdg = SubMenuWdg( menu_id=sm_map['menu_id'], width=sm_map['width'],
                                          opt_spec_list=sm_map['opt_spec_list'], allow_icons=sm_map['allow_icons'] )
            dd_activator.add( submenu_wdg )

        return dd_activator
    def get_display(my):

        smenu_div = DivWdg()
        smenu_div.add_class( "SPT_SMENU" )
        smenu_div.add_class( "SPT_SMENU_%s" % my.menu_tag_suffix )
        smenu_div.set_box_shadow()
        smenu_div.add_border()
        smenu_div.add_color("background", "background")
        smenu_div.add_color("color", "color")

        smenu_div.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            spt.dom.load_js( ["ctx_menu.js"], function() {
                    spt.dom.load_js( ["smart_menu.js"], function() {
                } )
            } );
            '''
        } )

        if my.setup_cbfn:
            smenu_div.set_attr( "SPT_SMENU_SETUP_CBFN", my.setup_cbfn )

        smenu_div.set_z_start( 300 )
        #smenu_div.add_looks( "smenu border curs_default" )
        # smenu_div.add_styles( "padding-top: 3px; padding-bottom: 5px;" )

        m_width = my.width - 2
        smenu_div.add_style( ("width: %spx" % m_width) )

        smenu_div.add_style("overflow-x: hidden")

        icon_width = 16
        icon_col_width = 0
        if my.allow_icons:
            icon_col_width = icon_width + 2
        label_width = m_width - icon_col_width - icon_width

        menu_table = Table()
        menu_table.add_styles( "text-align: left; text-indent: 3px; border-collapse: collapse;" )
        #menu_table.add_color("background", "background")
        menu_table.add_color("color", "color")

        options = my.opt_spec_list
        opt_count = 0

        if options[0].get('type') != 'title':
            my._add_spacer_row(menu_table, 3, icon_width, icon_col_width, label_width)


        """
        menu_table.add_relay_behavior( {
            'type': 'mouseenter',
            'bvr_match_class': 'SPT_SMENU_ENTRY',
            'bgcolor': menu_table.get_color("side_bar_title", -15, default="background3"),
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", bvr.bgcolor);
            bvr.src_el.setStyle("color", bvr.bgcolor);
            spt.smenu.entry_over( evt, bvr );
            '''
        } )

        menu_table.add_relay_behavior( {
            'type': 'mouseleave',
            'bvr_match_class': 'SPT_SMENU_ENTRY',
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", "");
            spt.smenu.entry_out( evt, bvr );
            '''
        } )
        """


        for opt in options:

            # if entry is a title, then add a spacer before
            if opt.get('type') == 'title' and opt_count:
                my._add_spacer_row(menu_table, 6, icon_width, icon_col_width, label_width)

            tbody = menu_table.add_tbody()
            tbody.add_style("display","table-row-group")

            tr = menu_table.add_row()
            #tr.add_looks( "smenu" )

            tr.add_class( "SPT_SMENU_ENTRY" )
            tr.add_class( "SPT_SMENU_ENTRY_%s" % opt['type'].upper() )

            if opt.has_key('enabled_check_setup_key'):
                tr.set_attr( "SPT_ENABLED_CHECK_SETUP_KEY", opt.get('enabled_check_setup_key') )

            if opt.has_key('hide_when_disabled') and opt.get('hide_when_disabled'):
                tr.set_attr( "SPT_HIDE_WHEN_DISABLED", "true" )

            if opt['type'] in [ 'action', 'toggle' ]:

                hover_bvr = {'type':'hover', 'add_looks': 'smenu_hilite',
                             'cbjs_action_over': 'spt.smenu.entry_over( evt, bvr );',
                             'cbjs_action_out': 'spt.smenu.entry_out( evt, bvr );' }
                if opt.has_key('hover_bvr_cb'):
                    hover_bvr.update( opt.get('hover_bvr_cb') )
                tr.add_behavior( hover_bvr )
                tr.add_class("hand")

            if opt['type'] == 'action':
                if opt.has_key('bvr_cb') and type(opt['bvr_cb']) == dict:
                    bvr = {}
                    bvr.update( opt['bvr_cb'] )
                    bvr['cbjs_action_for_menu_item'] = bvr['cbjs_action']
                    bvr['cbjs_action'] = 'spt.smenu.cbjs_action_wrapper( evt, bvr );'
                    bvr.update( { 'type': 'click_up' } )
                    tr.add_behavior( bvr )

            if opt['type'] == 'submenu':
                hover_bvr = { 'type': 'hover', 'add_looks': 'smenu_hilite',
                              'cbjs_action_over': 'spt.smenu.submenu_entry_over( evt, bvr );',
                              'cbjs_action_out': 'spt.smenu.submenu_entry_out( evt, bvr );',
                              'submenu_tag': "SPT_SMENU_%s" % opt['submenu_tag_suffix'],
                            }
                if opt.has_key('hover_bvr_cb'):
                    hover_bvr.update( opt.get('hover_bvr_cb') )
                tr.add_behavior( hover_bvr )
                # now trap click on submenu, so that it doesn't make the current menu disappear ...
                tr.add_behavior( { 'type': 'click', 'cbjs_action': ';', 'activator_type': 'smart_menu' } )

            tr.add_looks( "curs_default" )

            # Left icon cell ...
            if my.allow_icons:
                td = menu_table.add_cell()
                td.add_styles("text-align: center; vertical-align: middle; width: %spx;" % icon_col_width)
                #td.add_looks("smenu_icon_column")
                td.add_color("color", "color3")
                td.add_color("background", "background3")

                if opt.has_key( 'icon' ):
                    icon_wdg = IconWdg("", opt['icon'])
                    icon_wdg.add_class("SPT_ENABLED_ICON_LOOK")
                    td.add( icon_wdg )
                    #   if disabled:
                    #       icon_wdg.add_style( "opacity: .4" )
                    #       icon_wdg.add_style( "filter: alpha(opacity=40)" )

            # Menu option label cell ...
            td = menu_table.add_cell()
            td.add_style("width", ("%spx" % label_width))
            td.add_style("height", ("%spx" % icon_col_width))
            #if opt.get('type') != 'title':
            #    td.add_style( "padding-left: 6px" )
            #td.add_style( "padding-top: 2px" )
            td.add_style("padding: 6px 4px")

            if opt.has_key( 'label' ):
                label_str = opt.get('label').replace('"','"')
                td.add_class("SPT_LABEL")
                td.add( label_str )
                td.set_attr( "SPT_ORIG_LABEL", label_str )
                #td.add_looks("fnt_text")
                td.add_style("font-size: 1.0em")
                if opt.get('type') == 'title':
                    #td.add_looks("smenu_title")
                    td.add_color("background", "background2")
                    td.add_color("color", "color2")
                    td.add_style("font-weight", "bold")
                    td.add_style("padding", "3px")
            elif opt.get('type') == 'separator':
                hr = HtmlElement("hr")
                hr.add_looks( "smenu_separator" )
                td.add( hr )

            td.add_class("SPT_ENABLED_LOOK")

            #   if disabled:
            #       td.add_style( "opacity: .2" )
            #       td.add_style( "filter: alpha(opacity=20)" )

            # Submenu arrow icon cell ...
            td = menu_table.add_cell()
            td.add_style("width", ("%spx" % icon_width))

            if opt['type'] == 'submenu':
                icon_wdg = IconWdg("", IconWdg.ARROWHEAD_DARK_RIGHT)
                td.add(icon_wdg)
                td.add_class("SPT_ENABLED_ICON_LOOK")

            # extend title entry styling into the submenu arrow cell and add some spacing after
            if opt.get('type') == 'title':
                #td.add_looks("smenu_title")
                td.add_color("background", "background2")
                td.add_color("color", "color2")
                td.add_style("font-weight", "bold")
                td.add_style("padding", "3px")
                my._add_spacer_row(menu_table, 3, icon_width, icon_col_width, label_width)

            #   if disabled:
            #       td.add_style( "opacity: .4" )
            #       td.add_style( "filter: alpha(opacity=40)" )

            opt_count += 1


        my._add_spacer_row(menu_table, 5, icon_width, icon_col_width, label_width)

        smenu_div.add( menu_table )
        smenu_div.add_style( "display: none" )
        smenu_div.add_style( "position: absolute" )
        return smenu_div
    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
    def get_display(my):

        if not my.preprocessed:
            my.preprocess()

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

            hidden = HiddenWdg('workhour_data')
            hidden.add_class('spt_workhour_data')

            header_data = {'start_date': str(my.start_date)}
            header_data = jsondumps(header_data).replace('"', """)
            hidden.set_value(header_data, set_form_value=False)
            top.add(hidden)

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

        if not my.is_refresh:
            my.set_as_panel(top)

        entries = my.entries.get(task.get_code())
        if isinstance(task, Task):
            parent = task.get_parent()
            if not parent:
                disabled = True
            else:
                disabled = False
        else:
            disabled = False

        if not entries:
            entries = {}

        table = Table()
        top.add(table)

        if my.use_straight_time:
            row_list = [my.ST_ROW]
            if my.show_overtime:
                row_list.append(my.OT_ROW)
            prefix_list = ['', 'ot']
        else:
            row_list = [my.STT_ROW, my.ENT_ROW]
            prefix_list = ['stt', 'ent']
        text = HiddenWdg(my.get_name())
        text.add_class("spt_data")

        table.add_color("color", "color")
        table.add_styles("width: %spx; float: left" % my.table_width)
        for row_to_draw in row_list:
            tr = table.add_row()
            tr.add_style('line-height', '8px')

            td = table.add_blank_cell()
            offset_width = my.MONTH_WIDTH + my.LEFT_WIDTH + 8
            td.add_style("min-width: %spx" % offset_width)
            td.add(text)

            # go through each day and draw an input for overtime
            total_hours_st = 0
            total_hours_ot = 0
            search_key = task.get_search_key()

            # Add a label to indicate if the row is straight time or overtime

            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')
                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: 0 4px 4px 0')
                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: 0 4px 4px 0')
                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)

                text = TextWdg('%sday_%s' % (time_prefix, day))

                if disabled:
                    text.set_option('read_only', 'true')
                    text.set_attr('disabled', 'disabled')

                td.add(text)
                text.add_class('spt_day%s' % (time_prefix))
                text.add_styles(
                    "width: %spx;text-align: right;padding-left: 2px" %
                    (my.day_width - 2))
                #text.add_styles("width: 100%;text-align: right;padding-left: 2px")
                if day == today:
                    text.add_style("border: solid 1px black")

                week_day = my.weekday_dict[idx]
                if week_day in ['Sat', 'Sun']:
                    # MAIN: Overtime, weekend
                    if row_to_draw == my.OT_ROW:
                        text.add_color("background",
                                       "background2",
                                       modifier=[-15, 0, 5])
                    else:
                        text.add_color("background",
                                       "background2",
                                       modifier=[0, 15, 20])

                if row_to_draw == my.OT_ROW:
                    text.add_attr('input_field_type', 'ot')
                else:
                    text.add_attr('input_field_type', 'st')

                if my.kwargs.get('show_all_users') == 'false':
                    pass
                else:
                    text.set_option('read_only', 'true')
                #TODO: while we may have multiple entries per task, we will only use the latest one here
                # for now, making the UI cleaner

                # if a corresponding entry exists, display its value
                entry_list_dict = entries.get(day)
                daily_sum = 0
                value = 0
                entry_list = []
                if entry_list_dict:
                    row_key = my.ROW_DICT.get(row_to_draw)
                    entry_list = entry_list_dict.get(row_key)
                if entry_list:

                    for entry in entry_list:
                        # Check if there is something in the category column.
                        category = entry.get_value("category")
                        if row_to_draw == my.OT_ROW:
                            # Skip if the category field does not have a 'ot' indicated.
                            if not category:
                                print "Warning this work_hour entry has no category [%s]" % entry.get_code(
                                )
                                continue

                        # Check if there exist a value in the straight_time column
                        value, delta = my.get_time_value(entry, row_to_draw)
                        if value:

                            text.set_value(value)
                            text.add_attr('orig_input_value', value)

                            if row_to_draw == my.OT_ROW:
                                total_hours_ot += float(delta)
                            else:
                                total_hours_st += float(delta)

                            daily_sum += delta

                # we only use value instead of the sum "daily_sum" for now
                if row_to_draw == my.OT_ROW:
                    my.summary_ot[idx].update({search_key: daily_sum})
                else:
                    my.summary_st[idx].update({search_key: daily_sum})

                script = '''
                        var orig_value = bvr.src_el.getAttribute("orig_input_value");
                        var input_field_type = bvr.src_el.getAttribute("input_field_type");
                    
                        bvr.src_el.value = bvr.src_el.value.strip();
                        if (bvr.src_el.value == '') {
                            if (orig_value) {
                                bvr.src_el.value = 0;
                            }
                            else {
                                return;
                            }
                        }
                        else if (bvr.src_el.value == orig_value) {
                            return;
                        }

                       
                        bvr.prefix_list.splice( bvr.prefix_list.indexOf(bvr.time_prefix),1)
                        var other_time_prefix = bvr.prefix_list[0];
                        spt.work_hour.update_total(bvr, '.spt_day' + bvr.time_prefix);

                        // register this as changed item
                        var all_top_el = bvr.src_el.getParent(".spt_work_hours_top");

                        var values1 = spt.api.Utility.get_input_values(all_top_el, '.spt_day'+ bvr.time_prefix, false);
                        var values2 = spt.api.Utility.get_input_values(all_top_el, '.spt_day'+ other_time_prefix, false);

                        // Merge values from straight time and overtime fields in values variable.
                        for (var attr in values2) {
                            values1[attr] = values2[attr];
                        }

                        for (val in values1) {
                            if (values1[val] && isNaN(values1[val])) {
                                spt.error('You have non-numeric values in your work hours. Please correct it: ' + values[val]);
                                return;
                            }
                        }
                        delete values1.data; 
                        var value_wdg = all_top_el.getElement(".spt_data");

                        var value = JSON.stringify(values1);
                        value_wdg.value = value;
                        
                        var layout = bvr.src_el.getParent(".spt_layout");
                        var version = layout.getAttribute("spt_version");
                        if (version == "2") {
                            spt.table.set_layout(layout);
                            spt.table.accept_edit(all_top_el, value, false);
                        }
                        else {
                            var cached_data = {};
                            spt.dg_table.edit.widget = all_top_el;
                            spt.dg_table.inline_edit_cell_cbk( value_wdg, cached_data );
                        }
                        '''
                # accept on pressing Enter
                behavior = {
                    'type':
                    'keydown',
                    'time_prefix':
                    time_prefix,
                    'prefix_list':
                    prefix_list,
                    'cbjs_action':
                    '''
                   if (evt.key=='enter') {
                       %s
                    }

                ''' % script
                }

                text.add_behavior(behavior)

                behavior = {
                    'type':
                    'blur',
                    'time_prefix':
                    time_prefix,
                    'prefix_list':
                    prefix_list,
                    'cbjs_action':
                    '''
                        %s

                ''' % script
                }
                text.add_behavior(behavior)

            text = TextWdg("total")
            td = table.add_cell(text)
            td.add_style("width: 35px")

            text.add_attr('spt_total', '.spt_total%s' % (time_prefix))
            text.add_class('spt_total%s' % (time_prefix))
            text.add_styles(
                "width: %spx; text-align: right; padding-right: 3px" %
                my.day_width)
            text.set_attr("readonly", "readonly")

            # MAIN: Overtime, total.
            if row_to_draw == my.OT_ROW:
                text.add_color("background",
                               "background2",
                               modifier=[5, -15, 0])
                if total_hours_ot:
                    text.set_value("%0.1f" % total_hours_ot)
                my.summary_ot[7].update({search_key: total_hours_ot})
            else:
                text.add_color("background",
                               "background2",
                               modifier=[20, 0, 15])
                if total_hours_st:
                    text.set_value("%0.1f" % total_hours_st)
                my.summary_st[7].update({search_key: total_hours_st})
            td = table.add_blank_cell()
            td.add_style('width: 100%')

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

        dd_activator = DivWdg()
        dd_activator.set_id(self.id)

        if self.style:
            dd_activator.add_styles(self.style)

        dd_activator.add_style("width: %spx" % self.width)
        dd_activator.add_class("SPT_DTS")

        if self.nudge_menu_horiz != 0:
            dd_activator.set_attr("spt_nudge_menu_horiz",
                                  self.nudge_menu_horiz)

        if self.nudge_menu_vert != 0:
            dd_activator.set_attr("spt_nudge_menu_vert", self.nudge_menu_vert)

        # Generate button ...
        #
        table = Table()
        table.add_row()
        table.add_styles("width: 100%; padding: 0px; margin: 0px;")
        td = table.add_cell()
        td.add_looks("menu border curs_default")
        td.add_styles(
            "padding: 0px; width: 100%; overflow: hidden; height: 12px; max-height: 12px;"
        )

        title_div = DivWdg()
        title_div.add_styles(
            "padding: 0px; margin-left: 4px; margin-top: 1px;")
        title_div.add_looks("menu fnt_text")
        title_div.add(self.title)

        td.add(title_div)

        td = table.add_cell()
        # -- Example of setting only some of the borders with dotted style ...
        # td.add_looks( "menu_btn_icon clear_borders border_bottom border_right dotted" )
        td.add_looks("menu_btn_icon border curs_default")
        td.add_styles( "padding: 0px; text-align: center; overflow: hidden; " \
                       "width: 15px; min-width: 15px;" \
                       "height: 12px; max-height: 12px;" )

        arrow_img = HtmlElement.img(
            "/context/icons/silk/_spt_bullet_arrow_down_dark_8x8.png")
        arrow_img.add_styles("border: 0px; margin-left: 1px; margin-top: 0px;")
        td.add(arrow_img)

        dd_activator.add(table)

        # Now generate the main drop down menu and any needed sub-menus ...
        #
        dd_map = self.menus[0]
        if not dd_map.has_key('allow_icons'):
            dd_map['allow_icons'] = True  # default is to allow icons
        if self.match_width:
            dd_map['width'] = self.width

        dd_menu_wdg = DropdownMenuWdg(activator_wdg=dd_activator,
                                      menu_id=dd_map['menu_id'],
                                      width=dd_map['width'],
                                      opt_spec_list=dd_map['opt_spec_list'],
                                      allow_icons=dd_map['allow_icons'])
        dd_activator.add(dd_menu_wdg)

        sm_map_list = self.menus[1:]
        for sm_map in sm_map_list:
            if not sm_map.has_key('allow_icons'):
                sm_map['allow_icons'] = True
            submenu_wdg = SubMenuWdg(menu_id=sm_map['menu_id'],
                                     width=sm_map['width'],
                                     opt_spec_list=sm_map['opt_spec_list'],
                                     allow_icons=sm_map['allow_icons'])
            dd_activator.add(submenu_wdg)

        return dd_activator
示例#10
0
    def get_display(my):

        smenu_div = DivWdg()
        smenu_div.add_class("SPT_SMENU")
        smenu_div.add_class("SPT_SMENU_%s" % my.menu_tag_suffix)
        smenu_div.set_box_shadow()
        smenu_div.add_border()
        smenu_div.add_color("background", "background")
        smenu_div.add_color("color", "color")

        smenu_div.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
            spt.dom.load_js( ["ctx_menu.js"], function() {
                    spt.dom.load_js( ["smart_menu.js"], function() {
                } )
            } );
            '''
        })

        if my.setup_cbfn:
            smenu_div.set_attr("SPT_SMENU_SETUP_CBFN", my.setup_cbfn)

        smenu_div.set_z_start(300)
        #smenu_div.add_looks( "smenu border curs_default" )
        # smenu_div.add_styles( "padding-top: 3px; padding-bottom: 5px;" )

        m_width = my.width - 2
        smenu_div.add_style(("width: %spx" % m_width))

        smenu_div.add_style("overflow-x: hidden")

        icon_width = 16
        icon_col_width = 0
        if my.allow_icons:
            icon_col_width = icon_width + 2
        label_width = m_width - icon_col_width - icon_width

        menu_table = Table()
        menu_table.add_styles(
            "text-align: left; text-indent: 3px; border-collapse: collapse;")
        #menu_table.add_color("background", "background")
        menu_table.add_color("color", "color")

        options = my.opt_spec_list
        opt_count = 0

        if options[0].get('type') != 'title':
            my._add_spacer_row(menu_table, 3, icon_width, icon_col_width,
                               label_width)
        """
        menu_table.add_relay_behavior( {
            'type': 'mouseenter',
            'bvr_match_class': 'SPT_SMENU_ENTRY',
            'bgcolor': menu_table.get_color("side_bar_title", -15, default="background3"),
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", bvr.bgcolor);
            bvr.src_el.setStyle("color", bvr.bgcolor);
            spt.smenu.entry_over( evt, bvr );
            '''
        } )

        menu_table.add_relay_behavior( {
            'type': 'mouseleave',
            'bvr_match_class': 'SPT_SMENU_ENTRY',
            'cbjs_action': '''
            bvr.src_el.setStyle("background-color", "");
            spt.smenu.entry_out( evt, bvr );
            '''
        } )
        """

        for opt in options:

            # if entry is a title, then add a spacer before
            if opt.get('type') == 'title' and opt_count:
                my._add_spacer_row(menu_table, 6, icon_width, icon_col_width,
                                   label_width)

            tbody = menu_table.add_tbody()
            tbody.add_style("display", "table-row-group")

            tr = menu_table.add_row()
            #tr.add_looks( "smenu" )

            tr.add_class("SPT_SMENU_ENTRY")
            tr.add_class("SPT_SMENU_ENTRY_%s" % opt['type'].upper())

            if opt.has_key('enabled_check_setup_key'):
                tr.set_attr("SPT_ENABLED_CHECK_SETUP_KEY",
                            opt.get('enabled_check_setup_key'))

            if opt.has_key('hide_when_disabled') and opt.get(
                    'hide_when_disabled'):
                tr.set_attr("SPT_HIDE_WHEN_DISABLED", "true")

            if opt['type'] in ['action', 'toggle']:

                hover_bvr = {
                    'type': 'hover',
                    'add_looks': 'smenu_hilite',
                    'cbjs_action_over': 'spt.smenu.entry_over( evt, bvr );',
                    'cbjs_action_out': 'spt.smenu.entry_out( evt, bvr );'
                }
                if opt.has_key('hover_bvr_cb'):
                    hover_bvr.update(opt.get('hover_bvr_cb'))
                tr.add_behavior(hover_bvr)
                tr.add_class("hand")

            if opt['type'] == 'action':
                if opt.has_key('bvr_cb') and type(opt['bvr_cb']) == dict:
                    bvr = {}
                    bvr.update(opt['bvr_cb'])
                    bvr['cbjs_action_for_menu_item'] = bvr['cbjs_action']
                    bvr['cbjs_action'] = 'spt.smenu.cbjs_action_wrapper( evt, bvr );'
                    bvr.update({'type': 'click_up'})
                    tr.add_behavior(bvr)

            if opt['type'] == 'submenu':
                hover_bvr = {
                    'type': 'hover',
                    'add_looks': 'smenu_hilite',
                    'cbjs_action_over':
                    'spt.smenu.submenu_entry_over( evt, bvr );',
                    'cbjs_action_out':
                    'spt.smenu.submenu_entry_out( evt, bvr );',
                    'submenu_tag': "SPT_SMENU_%s" % opt['submenu_tag_suffix'],
                }
                if opt.has_key('hover_bvr_cb'):
                    hover_bvr.update(opt.get('hover_bvr_cb'))
                tr.add_behavior(hover_bvr)
                # now trap click on submenu, so that it doesn't make the current menu disappear ...
                tr.add_behavior({
                    'type': 'click',
                    'cbjs_action': ';',
                    'activator_type': 'smart_menu'
                })

            tr.add_looks("curs_default")

            # Left icon cell ...
            if my.allow_icons:
                td = menu_table.add_cell()
                td.add_styles(
                    "text-align: center; vertical-align: middle; width: %spx;"
                    % icon_col_width)
                #td.add_looks("smenu_icon_column")
                td.add_color("color", "color3")
                td.add_color("background", "background3")

                if opt.has_key('icon'):
                    icon_wdg = IconWdg("", opt['icon'])
                    icon_wdg.add_class("SPT_ENABLED_ICON_LOOK")
                    td.add(icon_wdg)
                    #   if disabled:
                    #       icon_wdg.add_style( "opacity: .4" )
                    #       icon_wdg.add_style( "filter: alpha(opacity=40)" )

            # Menu option label cell ...
            td = menu_table.add_cell()
            td.add_style("width", ("%spx" % label_width))
            td.add_style("height", ("%spx" % icon_col_width))
            if opt.get('type') != 'title':
                td.add_style("padding-left: 6px")
            td.add_style("padding-top: 2px")

            if opt.has_key('label'):
                label_str = opt.get('label').replace('"', '"')
                td.add_class("SPT_LABEL")
                td.add(label_str)
                td.set_attr("SPT_ORIG_LABEL", label_str)
                #td.add_looks("fnt_text")
                td.add_style("font-size: 11px")
                if opt.get('type') == 'title':
                    #td.add_looks("smenu_title")
                    td.add_color("background", "background2")
                    td.add_color("color", "color2")
                    td.add_style("font-weight", "bold")
                    td.add_style("padding", "3px")
            elif opt.get('type') == 'separator':
                hr = HtmlElement("hr")
                hr.add_looks("smenu_separator")
                td.add(hr)

            td.add_class("SPT_ENABLED_LOOK")

            #   if disabled:
            #       td.add_style( "opacity: .2" )
            #       td.add_style( "filter: alpha(opacity=20)" )

            # Submenu arrow icon cell ...
            td = menu_table.add_cell()
            td.add_style("width", ("%spx" % icon_width))

            if opt['type'] == 'submenu':
                icon_wdg = IconWdg("", IconWdg.ARROWHEAD_DARK_RIGHT)
                td.add(icon_wdg)
                td.add_class("SPT_ENABLED_ICON_LOOK")

            # extend title entry styling into the submenu arrow cell and add some spacing after
            if opt.get('type') == 'title':
                #td.add_looks("smenu_title")
                td.add_color("background", "background2")
                td.add_color("color", "color2")
                td.add_style("font-weight", "bold")
                td.add_style("padding", "3px")
                my._add_spacer_row(menu_table, 3, icon_width, icon_col_width,
                                   label_width)

            #   if disabled:
            #       td.add_style( "opacity: .4" )
            #       td.add_style( "filter: alpha(opacity=40)" )

            opt_count += 1

        my._add_spacer_row(menu_table, 5, icon_width, icon_col_width,
                           label_width)

        smenu_div.add(menu_table)
        smenu_div.add_style("display: none")
        smenu_div.add_style("position: absolute")
        return smenu_div
    def get_example_display(self):

        font_div = DivWdg()

        font_div.add_styles( "background: #CCCCCC; color: #000000; border: 3px solid black; width: 750px;" )


        font_table = Table()
        font_table.add_styles( "margin-top: 6px;" )
        font_table.add_row()

        ft_style = "border: 1px solid black; border-collapse: collapse; padding: 3px; " \
                   "color: #000000; cursor: pointer; %s"

        td = font_table.add_cell()
        td.add_styles( "border: 0px; border-collapse: collapse; padding: 0px; width: 6px; background: #CCCCCC;" )
        td.add( " " )

        td = font_table.add_cell()
        td.set_id("SPT_FONT_EXAMPLE_BTN")
        td.add_styles( ft_style % "background: #CCCCCC;" )
        td.add( "normal" )
        td.add_behavior( { 'type': 'click_up',
                           'cbjs_action': '$("SPT_FONT_EXAMPLE").setStyle("display","block"); ' \
                                        '$("SPT_FONT_EXAMPLE_ITALIC").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_ITALIC").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_BTN").setStyle("background","#CCCCCC"); ' \
                                        '$("SPT_FONT_EXAMPLE_ITALIC_BTN").setStyle("background","#777777"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_BTN").setStyle("background","#777777"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_ITALIC_BTN").setStyle("background","#777777"); ' } )

        td = font_table.add_cell()
        td.add_styles( "border: 0px; border-collapse: collapse; padding: 0px; width: 6px; background: #CCCCCC;" )
        td.add( " " )

        td = font_table.add_cell()
        td.set_id("SPT_FONT_EXAMPLE_ITALIC_BTN")
        td.add_styles( ft_style % "background: #777777;" )
        td.add( "<i>italic</i>" )
        td.add_behavior( { 'type': 'click_up',
                           'cbjs_action': '$("SPT_FONT_EXAMPLE").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_ITALIC").setStyle("display","block"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_ITALIC").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_BTN").setStyle("background","#777777"); ' \
                                        '$("SPT_FONT_EXAMPLE_ITALIC_BTN").setStyle("background","#CCCCCC"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_BTN").setStyle("background","#777777"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_ITALIC_BTN").setStyle("background","#777777"); ' } )

        td = font_table.add_cell()
        td.add_styles( "border: 0px; border-collapse: collapse; padding: 0px; width: 6px; background: #CCCCCC;" )
        td.add( "&nbsp;" )

        td = font_table.add_cell()
        td.set_id("SPT_FONT_EXAMPLE_BOLD_BTN")
        td.add_styles( ft_style % "background: #777777;" )
        td.add( "<b>bold</b>" )
        td.add_behavior( { 'type': 'click_up',
                           'cbjs_action': '$("SPT_FONT_EXAMPLE").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_ITALIC").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD").setStyle("display","block"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_ITALIC").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_BTN").setStyle("background","#777777"); ' \
                                        '$("SPT_FONT_EXAMPLE_ITALIC_BTN").setStyle("background","#777777"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_BTN").setStyle("background","#CCCCCC"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_ITALIC_BTN").setStyle("background","#777777"); ' } )

        td = font_table.add_cell()
        td.add_styles( "border: 0px; border-collapse: collapse; padding: 0px; width: 6px; background: #CCCCCC;" )
        td.add( "&nbsp;" )

        td = font_table.add_cell()
        td.set_id("SPT_FONT_EXAMPLE_BOLD_ITALIC_BTN")
        td.add_styles( ft_style % "background: #777777;" )
        td.add( "<b><i>bold italic</i></b>" )
        td.add_behavior( { 'type': 'click_up',
                           'cbjs_action': '$("SPT_FONT_EXAMPLE").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_ITALIC").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD").setStyle("display","none"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_ITALIC").setStyle("display","block"); ' \
                                        '$("SPT_FONT_EXAMPLE_BTN").setStyle("background","#777777"); ' \
                                        '$("SPT_FONT_EXAMPLE_ITALIC_BTN").setStyle("background","#777777"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_BTN").setStyle("background","#777777"); ' \
                                        '$("SPT_FONT_EXAMPLE_BOLD_ITALIC_BTN").setStyle("background","#CCCCCC"); ' } )

        font_div.add( font_table )


        font_palettes = [ 'fnt_title_1', 'fnt_title_2', 'fnt_title_3', 'fnt_title_4', 'fnt_title_5',
                          'fnt_text', 'fnt_text_small', 'fnt_serif', 'fnt_code' ]

        font_modifiers = [ 'fnt_italic', 'fnt_bold', 'fnt_bold fnt_italic' ]

        font_example_div = DivWdg()
        font_example_div.set_id( "SPT_FONT_EXAMPLE" )
        for fnt_pal in font_palettes:
            font_palette_div = DivWdg()
            font_palette_div.add_looks( fnt_pal )
            font_palette_div.add_styles( "color: black; padding-top: 10px; padding-left: 10px;" )
            font_palette_div.add( 'Here is example TEXT showing text that is given font palette "' + fnt_pal + '"' )
            font_example_div.add( font_palette_div )
        font_div.add( font_example_div )

        for fnt_mod in font_modifiers:
            fm_name = fnt_mod.replace(" ","_")
            font_example_div = DivWdg()
            font_example_div.set_id( "SPT_FONT_EXAMPLE_%s" % fm_name.upper().replace("FNT_","") )
            font_example_div.add_styles( "display: none;" )
            for fnt_pal in font_palettes:
                font_palette_div = DivWdg()
                font_palette_div.add_looks( "%s %s" % (fnt_pal,fnt_mod) )
                font_palette_div.add_styles( "color: black; padding-top: 10px; padding-left: 10px;" )
                font_palette_div.add( 'Here is example TEXT showing text that is given font palette "' + fnt_pal + '"' )
                font_example_div.add( font_palette_div )
            font_div.add( font_example_div )

        font_div.add( '<br/><br/>' )
        return font_div
示例#12
0
    def get_display(my):

        #content.add_event("oncontextmenu", "spt.side_bar.manage_context_menu_action_cbk(); return false")
        context_menu = DivWdg()
        context_menu.add_class('spt_menu_top')
        context_menu.add_behavior({
            'type':
            'load',
            'cbjs_action':
            '''
            spt.finger_menu = {};
            spt.finger_menu.timeout_id = -1;
            '''
        })
        context_menu.add_behavior({
            'type':
            'mouseover',
            'cbjs_action':
            '''
            if (spt.finger_menu.timeout_id != -1) {
                clearTimeout(spt.finger_menu.timeout_id);
                spt.finger_menu.timeout_id = -1;
            }
            '''
        })

        #context_menu.set_box_shadow(color='#fff')
        # this may not be needed as it is set in JS
        context_menu.add_style("z-index: 200")

        # set up what happens when the mouse leaves the actual menu
        my._set_menu_out(context_menu)

        width = my.kwargs.get('width')
        height = my.kwargs.get('height')
        if not height:
            height = 20
        if not width:
            width = 35
        font_size = my.kwargs.get('font_size')
        if not font_size:
            font_size = 'smaller'

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

        if my.mode == 'horizontal':
            div = DivWdg(css='spt_finger_menu')
            if force:
                div.add_attr("spt_finger_force", force)

            div.add_style("border-color: #aaa")
            div.add_style("border-style: solid")

            if force == "left":
                div.add_style("border-width: 1px 0px 1px 1px")
                div.add_style("border-radius: 12px 0px 0px 12px")
            else:
                div.add_style("border-width: 1px 1px 1px 0px")
                div.add_style("border-radius: 0px 12px 12px 0px")

            div.set_box_shadow(value="0px 0px 2px 1px")
            #div.add_style("z-index: 1000")

            total_width = width * len(my.items) + 15
            div.add_style('width', total_width)
            div.add_styles('height: %spx; padding: 2px;' % height)
            context_menu.add(div)

            div.add_color('background', 'background', -10)
            palette = div.get_palette()

            sb_title_bg = palette.color('side_bar_title')
            bg_color = div.get_color('background', -10)
            color = div.get_color('color')

            for item in my.items:
                mouse_enter_bvr = {
                    'type':
                    'mouseenter',
                    'cbjs_action':
                    '''
                    bvr.src_el.setStyles({'background': '%s', 'color': 'white'})'''
                    % sb_title_bg
                }
                mouse_leave_bvr = {
                    'type':
                    'mouseleave',
                    'cbjs_action':
                    '''
                    bvr.src_el.setStyles({'background': '%s', 'color': '%s'})'''
                    % (bg_color, color)
                }

                menu_item = FloatDivWdg(css='unselectable hand')
                menu_item.add_color('background', 'background', -10)
                menu_item.add(item.get_option('label'))

                menu_item.add_behavior(mouse_enter_bvr)
                menu_item.add_behavior(mouse_leave_bvr)

                # add the passed-in bvr
                bvr = item.get_option('bvr_cb')
                menu_item.add_behavior(bvr)

                menu_item.add_styles(
                    'margin: 0px 0 0 0; padding: 2px 0 2px 0; text-align: center; font-size: %s; width: %s; height: %spx'
                    % (font_size, width, height - 4))
                menu_item.add_behavior({
                    'type':
                    'click_up',
                    'cbjs_action':
                    '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);'''
                })
                div.add(menu_item)

        else:
            # this width only matters in vertical mode
            context_menu.add_style("width: %s" % width)
            menu_table = Table()
            menu_table.add_styles(
                "text-align: left; text-indent: 4px; border-collapse: collapse; cell-padding: 8px; border-radius: 32px;"
            )
            context_menu.add(menu_table)
            my._add_spacer_row(menu_table, 3, width)
            for widget in my.widgets:
                tbody = menu_table.add_tbody()
                tbody.add_style("display", "table-row-group")

                tr = menu_table.add_row()
                tr.add_looks("smenu")
                #tr.add_class( "SPT_SMENU_ENTRY" )
                hover_bvr = {'type': 'hover', 'add_looks': 'smenu_hilite'}
                #'cbjs_action_over': 'spt.smenu.entry_over( evt, bvr );',
                #'cbjs_action_out': 'spt.smenu.entry_out( evt, bvr );' }
                tr.add_behavior(hover_bvr)

                menu_item = menu_table.add_cell()
                font_size = '4px'
                menu_item.add_styles(
                    'padding: 0px 0 0 6px; font-size: %s; width: %s; height: 16px'
                    % (font_size, width))
                menu_item.add_behavior({
                    'type':
                    'click_up',
                    'cbjs_action':
                    '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);'''
                })
                menu_item.add(widget)

            my._add_spacer_row(menu_table, 3, width)

        return context_menu
示例#13
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
示例#14
0
    def get_display(my):

        if not my.preprocessed:
            my.preprocess()

        if my.is_refresh:
            top = Widget()
        else:
            top = DivWdg()
            top.add_class("spt_work_hours_top")
            
            hidden = HiddenWdg('workhour_data')
            hidden.add_class('spt_workhour_data')

            header_data = {'start_date': str(my.start_date)}
            header_data = jsondumps(header_data).replace('"', "&quot;")
            hidden.set_value(header_data, set_form_value=False )
            top.add(hidden)
        
        days = []
        for date in my.dates:
            days.append( date.strftime("%Y_%m_%d") )
        today = my.today.strftime("%Y_%m_%d")
        task = my.get_current_sobject()
            
        if not my.is_refresh:
            my.set_as_panel(top)
        
        entries = my.entries.get(task.get_code())
        if isinstance(task, Task):
            parent = task.get_parent()
            if not parent:
                disabled = True
            else:
                disabled = False
        else:
            disabled = False

        if not entries:
            entries = {}

        table = Table()
        top.add(table)

        

        if my.use_straight_time:
            row_list = [my.ST_ROW]
            if my.show_overtime:
                row_list.append(my.OT_ROW)
            prefix_list = ['','ot']    
        else:
            row_list = [my.STT_ROW, my.ENT_ROW]
            prefix_list = ['stt','ent']    
        text = HiddenWdg(my.get_name() )
        text.add_class("spt_data")

        table.add_color("color", "color")
        table.add_styles("width: %spx; float: left"%my.table_width)
        for row_to_draw in row_list:
            tr = table.add_row()
            tr.add_style('line-height','8px')
            
            td = table.add_blank_cell()
            offset_width = my.MONTH_WIDTH + my.LEFT_WIDTH+8
            td.add_style("min-width: %spx" % offset_width)
            td.add(text)

            # go through each day and draw an input for overtime
            total_hours_st = 0
            total_hours_ot = 0
            search_key = task.get_search_key() 

            # Add a label to indicate if the row is straight time or overtime
           
            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')
                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: 0 4px 4px 0')
                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: 0 4px 4px 0')
                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)

                
                text = TextWdg('%sday_%s' % (time_prefix, day))
                
                if disabled:
                    text.set_option('read_only','true')
                    text.set_attr('disabled','disabled')

                td.add(text)
                text.add_class('spt_day%s' % (time_prefix))
                text.add_styles("width: %spx;text-align: right;padding-left: 2px" %(my.day_width-2))
                #text.add_styles("width: 100%;text-align: right;padding-left: 2px")
                if day == today:
                    text.add_style("border: solid 1px black")
                else:
                    text.add_border()

                week_day = my.weekday_dict[idx]
                if week_day in ['Sat','Sun']:
                    # MAIN: Overtime, weekend
                    if row_to_draw == my.OT_ROW:
                        text.add_color("background", "background2", modifier=[-15,0,5])
                    else:
                        text.add_color("background", "background2", modifier= [0,15,20])

                text.add_style("margin: 0px 1px")

                if row_to_draw == my.OT_ROW:
                    text.add_attr('input_field_type', 'ot')
                else:
                    text.add_attr('input_field_type', 'st')

                if my.kwargs.get('show_all_users')=='true':
                    text.set_option('read_only','true')

                #TODO: while we may have multiple entries per task, we will only use the latest one here
                # for now, making the UI cleaner

                # if a corresponding entry exists, display its value
                entry_list_dict = entries.get(day)
                daily_sum = 0
                value = 0
                entry_list = []
                if entry_list_dict:
                    row_key = my.ROW_DICT.get(row_to_draw)
                    entry_list = entry_list_dict.get(row_key)
                if entry_list:

                    for entry in entry_list:
                        # Check if there is something in the category column.
                        category = entry.get_value("category")
                        if row_to_draw == my.OT_ROW:
                            # Skip if the category field does not have a 'ot' indicated.
                            if not category:
                                print "Warning this work_hour entry has no category [%s]" % entry.get_code()
                                continue
                       
                        # Check if there exist a value in the straight_time column
                        value, delta = my.get_time_value(entry, row_to_draw)
                        if value:

                            text.set_value(value)
                            text.add_attr('orig_input_value', value)
                            
                            if row_to_draw == my.OT_ROW:
                                total_hours_ot += float(delta)
                            else:
                                total_hours_st += float(delta)

                            daily_sum += delta


                # we only use value instead of the sum "daily_sum" for now
                if row_to_draw == my.OT_ROW:
                    my.summary_ot[idx].update({search_key: daily_sum})
                else:
                    my.summary_st[idx].update({search_key: daily_sum})
                
                script = '''
                        var orig_value = bvr.src_el.getAttribute("orig_input_value");
                        var input_field_type = bvr.src_el.getAttribute("input_field_type");
                    
                        bvr.src_el.value = bvr.src_el.value.strip();
                        if (bvr.src_el.value == '') {
                            if (orig_value) {
                                bvr.src_el.value = 0;
                            }
                            else {
                                return;
                            }
                        }
                        else if (bvr.src_el.value == orig_value) {
                            return;
                        }

                       
                        bvr.prefix_list.splice( bvr.prefix_list.indexOf(bvr.time_prefix),1)
                        var other_time_prefix = bvr.prefix_list[0];
                        spt.work_hour.update_total(bvr, '.spt_day' + bvr.time_prefix);

                        // register this as changed item
                        var all_top_el = bvr.src_el.getParent(".spt_work_hours_top");

                        var values1 = spt.api.Utility.get_input_values(all_top_el, '.spt_day'+ bvr.time_prefix, false);
                        var values2 = spt.api.Utility.get_input_values(all_top_el, '.spt_day'+ other_time_prefix, false);

                        // Merge values from straight time and overtime fields in values variable.
                        for (var attr in values2) {
                            values1[attr] = values2[attr];
                        }

                        for (val in values1) {
                            if (values1[val] && isNaN(values1[val])) {
                                spt.error('You have non-numeric values in your work hours. Please correct it: ' + values[val]);
                                return;
                            }
                        }
                        delete values1.data; 
                        var value_wdg = all_top_el.getElement(".spt_data");

                        var value = JSON.stringify(values1);
                        value_wdg.value = value;
                        
                        var layout = bvr.src_el.getParent(".spt_layout");
                        var version = layout.getAttribute("spt_version");
                        if (version == "2") {
                            spt.table.set_layout(layout);
                            spt.table.accept_edit(all_top_el, value, false);
                        }
                        else {
                            var cached_data = {};
                            spt.dg_table.edit.widget = all_top_el;
                            spt.dg_table.inline_edit_cell_cbk( value_wdg, cached_data );
                        }
                        '''
                # accept on pressing Enter
                behavior = {
                   'type': 'keydown',
                   'time_prefix': time_prefix,
                   'prefix_list': prefix_list,
                   'cbjs_action': '''
                   if (evt.key=='enter') {
                       %s
                    }

                '''%script}     

                text.add_behavior(behavior)
                
                behavior = {
                   'type': 'blur',
                   'time_prefix': time_prefix,
                   'prefix_list': prefix_list,
                   'cbjs_action': '''
                        %s

                '''%script}     
                text.add_behavior(behavior)


            text = TextWdg("total")
            td = table.add_cell(text)
            td.add_style("width: 35px")
            text.add_border()

            text.add_attr('spt_total', '.spt_total%s' % (time_prefix))
            text.add_class('spt_total%s' % (time_prefix))
            text.add_styles("width: %spx; text-align: right; padding-right: 3px"%my.day_width)
            text.set_attr("readonly", "readonly")

            # MAIN: Overtime, total.
            if row_to_draw == my.OT_ROW:
                text.add_color("background", "background2", modifier=[5,-15,0])
                if total_hours_ot:
                    text.set_value("%0.1f" % total_hours_ot)
                my.summary_ot[7].update({search_key: total_hours_ot})
            else:
                text.add_color("background", "background2", modifier=[20,0,15])
                if total_hours_st:
                    text.set_value("%0.1f" % total_hours_st)
                my.summary_st[7].update({search_key: total_hours_st})
            td = table.add_blank_cell()
            td.add_style('width: 100%')

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

        #content.add_event("oncontextmenu", "spt.side_bar.manage_context_menu_action_cbk(); return false")
        context_menu = DivWdg()
        context_menu.add_class('spt_menu_top')
        context_menu.add_behavior( {
            'type': 'load',
            'cbjs_action': '''
            spt.finger_menu = {};
            spt.finger_menu.timeout_id = -1;
            '''
        } )
        context_menu.add_behavior( {
            'type': 'mouseover',
            'cbjs_action': '''
            if (spt.finger_menu.timeout_id != -1) {
                clearTimeout(spt.finger_menu.timeout_id);
                spt.finger_menu.timeout_id = -1;
            }
            '''
        } )

 


        #context_menu.set_box_shadow(color='#fff')
        # this may not be needed as it is set in JS
        context_menu.add_style("z-index: 200")

        # set up what happens when the mouse leaves the actual menu
        my._set_menu_out(context_menu)


        width = my.kwargs.get('width')
        height = my.kwargs.get('height')
        if not height:
            height = 20
        if not width:
            width = 35
        font_size = my.kwargs.get('font_size')
        if not font_size:
            font_size = 'smaller'


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

        if my.mode == 'horizontal':
            div = DivWdg(css='spt_finger_menu')
            if force:
                div.add_attr("spt_finger_force", force)

            div.add_style("border-color: #aaa")
            div.add_style("border-style: solid")

            if force == "left":
                div.add_style("border-width: 1px 0px 1px 1px")
                div.add_style("border-radius: 12px 0px 0px 12px")
            else:
                div.add_style("border-width: 1px 1px 1px 0px")
                div.add_style("border-radius: 0px 12px 12px 0px")


            div.set_box_shadow(value="0px 0px 2px 1px")
            #div.add_style("z-index: 1000")

            total_width = width * len(my.items) + 15
            div.add_style('width', total_width)
            div.add_styles('height: %spx; padding: 2px;' %height)
            context_menu.add(div)

            div.add_color('background','background', -10)
            palette = div.get_palette()

            sb_title_bg = palette.color('side_bar_title')
            bg_color = div.get_color('background', -10)
            color = div.get_color('color')
            
            for item in my.items:
                mouse_enter_bvr = {'type':'mouseenter', 'cbjs_action': '''
                    bvr.src_el.setStyles({'background': '%s', 'color': 'white'})''' %sb_title_bg}
                mouse_leave_bvr = {'type':'mouseleave', 'cbjs_action': '''
                    bvr.src_el.setStyles({'background': '%s', 'color': '%s'})''' %(bg_color, color)}

                menu_item = FloatDivWdg(css='unselectable hand')
                menu_item.add_color('background','background', -10)
                menu_item.add(item.get_option('label'))

                menu_item.add_behavior( mouse_enter_bvr )
                menu_item.add_behavior( mouse_leave_bvr )

                # add the passed-in bvr
                bvr = item.get_option('bvr_cb')
                menu_item.add_behavior(bvr )


                menu_item.add_styles('margin: 0px 0 0 0; padding: 2px 0 2px 0; text-align: center; font-size: %s; width: %s; height: %spx'%(font_size, width, height-4))
                menu_item.add_behavior({'type': 'click_up',
                    'cbjs_action': '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);'''})
                div.add(menu_item)
        
        else:
            # this width only matters in vertical mode
            context_menu.add_style("width: %s" %width)
            menu_table = Table()
            menu_table.add_styles( "text-align: left; text-indent: 4px; border-collapse: collapse; cell-padding: 8px; border-radius: 32px;" )
            context_menu.add(menu_table)
            my._add_spacer_row(menu_table, 3, width)
            for widget in my.widgets:
                tbody = menu_table.add_tbody()
                tbody.add_style("display","table-row-group")

               
                tr = menu_table.add_row()
                tr.add_looks( "smenu" )
                #tr.add_class( "SPT_SMENU_ENTRY" )
                hover_bvr = {'type':'hover', 'add_looks': 'smenu_hilite'}
                                 #'cbjs_action_over': 'spt.smenu.entry_over( evt, bvr );',
                                 #'cbjs_action_out': 'spt.smenu.entry_out( evt, bvr );' }
                tr.add_behavior( hover_bvr )


                menu_item = menu_table.add_cell()
                font_size = '4px'
                menu_item.add_styles('padding: 0px 0 0 6px; font-size: %s; width: %s; height: 16px'%(font_size, width))
                menu_item.add_behavior({'type': 'click_up',
                    'cbjs_action': '''var menu = bvr.src_el.getParent('.spt_menu_top'); spt.hide(menu);'''})
                menu_item.add(widget)

               

            my._add_spacer_row(menu_table, 3, width)

        return context_menu