PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/templates/grid_base.mako

https://bitbucket.org/cistrome/cistrome-harvard/
Mako | 251 lines | 190 code | 30 blank | 31 comment | 7 complexity | 98b581f79c0f69ec1d99cfe667608d53 MD5 | raw file
  1<%!
  2    from galaxy.web.framework.helpers.grids import TextColumn
  3    def inherit(context):
  4        if context.get('use_panels'):
  5            if context.get('webapp'):
  6                webapp = context.get('webapp')
  7            else:
  8                webapp = 'galaxy'
  9            return '/webapps/%s/base_panels.mako' % webapp
 10        else:
 11            return '/base.mako'
 12%>
 13
 14## import/inherit makos
 15<%inherit file="${inherit(context)}"/>
 16<%namespace file="/display_common.mako" import="get_class_plural" />
 17
 18## creates grid
 19<%def name="load(embedded=False, insert=None)">
 20
 21    ## create dictionary
 22    ${self.init(embedded, insert)}
 23    
 24    ## imports
 25    ${h.css( "autocomplete_tagging", "jquery.rating" )}
 26    ${h.js("libs/jquery/jquery.autocomplete", "galaxy.autocom_tagging", "libs/jquery/jquery.rating" )}
 27
 28    ## grid container
 29    <div id="grid-container"><div>
 30
 31    ## load javascript
 32    <script type="text/javascript">
 33        var gridView = null;
 34        function add_tag_to_grid_filter (tag_name, tag_value)
 35        {
 36            ## Put tag name and value together.
 37            var tag = tag_name + (tag_value !== undefined && tag_value !== "" ? ":" + tag_value : "");
 38            var advanced_search = $('#advanced-search').is(":visible");
 39            if (!advanced_search)
 40            {
 41                $('#standard-search').slideToggle('fast');
 42                $('#advanced-search').slideToggle('fast');
 43            }
 44            gridView.add_filter_condition("tags", tag);
 45        };
 46
 47        ## load grid viewer
 48        $(function() {
 49            require(['mvc/grid/grid-view'], function(GridView) {
 50                gridView = new GridView(${h.to_json_string(self.grid_config)});
 51            });
 52        });
 53    </script>
 54</%def>
 55
 56## generates dictionary
 57<%def name="init(embedded=False, insert=None)">
 58<%
 59    self.has_left_panel         = False
 60    self.has_right_panel        = False
 61    self.message_box_visible    = False
 62    self.overlay_visible        = False
 63    self.active_view            = 'user'
 64
 65    self.grid_config = {
 66        'title'                         : grid.title,
 67        'url_base'                      : trans.request.path_url,
 68        'async'                         : grid.use_async,
 69        'async_ops'                     : [],
 70        'categorical_filters'           : {},
 71        'filters'                       : cur_filter_dict,
 72        'sort_key'                      : sort_key,
 73        'show_item_checkboxes'          : context.get('show_item_checkboxes', False),
 74        'cur_page_num'                  : cur_page_num,
 75        'num_pages'                     : num_pages,
 76        'num_page_links'                : num_page_links,
 77        'history_tag_autocomplete_url'  : url( controller='tag', action='tag_autocomplete_data', item_class='History' ),
 78        'history_name_autocomplete_url' : url( controller='history', action='name_autocomplete_data' ),
 79        'status'                        : status,
 80        'message'                       : util.restore_text(message),
 81        'global_actions'                : [],
 82        'operations'                    : [],
 83        'items'                         : [],
 84        'columns'                       : [],
 85        'get_class_plural'              : get_class_plural( grid.model_class ).lower(),
 86        'use_paging'                    : grid.use_paging,
 87        'legend'                        : grid.legend,
 88        'current_item_id'               : False,
 89        'use_panels'                    : context.get('use_panels'),
 90        'use_hide_message'              : grid.use_hide_message,
 91        'insert'                        : insert,
 92        'default_filter_dict'           : default_filter_dict,
 93        'advanced_search'               : advanced_search,
 94        'refresh_frames'                : [],
 95        'embedded'                      : embedded,
 96        'info_text'                     : grid.info_text,
 97        'url'                           : url(dict())
 98    }
 99
100    ## add refresh frames
101    if refresh_frames:
102        self.grid_config['refresh_frames'] = refresh_frames
103
104    ## add current item if exists
105    if current_item:
106        self.grid_config['current_item_id'] = current_item.id
107    endif
108
109    ## column
110    for column in grid.columns:
111        
112        ## add column sort links
113        href = None
114        extra = ''
115        if column.sortable:
116            if sort_key.endswith(column.key):
117                if not sort_key.startswith("-"):
118                    href = url( sort=( "-" + column.key ) )
119                    extra = "&darr;"
120                else:
121                    href = url( sort=( column.key ) )
122                    extra = "&uarr;"
123            else:
124                href = url( sort=column.key )
125
126        ## add to configuration
127        self.grid_config['columns'].append({
128            'key'               : column.key,
129            'visible'           : column.visible,
130            'nowrap'            : column.nowrap,
131            'attach_popup'      : column.attach_popup,
132            'label_id_prefix'   : column.label_id_prefix,
133            'sortable'          : column.sortable,
134            'label'             : column.label,
135            'filterable'        : column.filterable,
136            'is_text'           : isinstance(column, TextColumn),
137            'href'              : href,
138            'extra'             : extra
139        })
140    endfor
141    
142    ## operations
143    for operation in grid.operations:
144        self.grid_config['operations'].append({
145            'allow_multiple'        : operation.allow_multiple,
146            'allow_popup'           : operation.allow_popup,
147            'target'                : operation.target,
148            'label'                 : operation.label,
149            'confirm'               : operation.confirm,
150            'inbound'               : operation.inbound,
151            'global_operation'      : False
152        })
153        if operation.allow_multiple:
154            self.grid_config['show_item_checkboxes'] = True
155            
156        if operation.global_operation:
157            self.grid_config['global_operation'] = url( ** (operation.global_operation()) )
158    endfor
159
160    ## global actions
161    for action in grid.global_actions:
162        self.grid_config['global_actions'].append({
163            'url_args'  : url(**action.url_args),
164            'label'     : action.label,
165            'inbound'   : action.inbound
166        })
167    endfor
168
169    ## Operations that are async (AJAX) compatible.
170    for operation in [op for op in grid.operations if op.async_compatible]:
171        self.grid_config['async_ops'].append(operation.label.lower());
172    endfor
173
174    ## Filter values for categorical filters.
175    for column in grid.columns:
176        if column.filterable is not None and not isinstance( column, TextColumn ):
177            self.grid_config['categorical_filters'][column.key] = dict([ (filter.label, filter.args) for filter in column.get_accepted_filters() ])
178        endif
179    endfor
180    
181    # items
182    for i, item in enumerate( query ):
183        item_dict = {
184            'id'                    : item.id,
185            'encode_id'             : trans.security.encode_id(item.id),
186            'link'                  : [],
187            'operation_config'      : {},
188            'column_config'         : {}
189        }
190
191        ## data columns
192        for column in grid.columns:
193            if column.visible:
194                ## get link
195                link = column.get_link(trans, grid, item)
196                if link:
197                    link = url(**link)
198                else:
199                    link = None
200                endif
201
202                ## inbound
203                inbound = column.inbound
204
205                ## get value
206                value = column.get_value( trans, grid, item )
207
208                # Handle non-ascii chars.
209                if isinstance(value, str):
210                    value = unicode(value, 'utf-8')
211                    value = value.replace('/', '//')
212                endif
213
214                ## Item dictionary
215                item_dict['column_config'][column.label] = {
216                    'link'      : link,
217                    'value'     : value,
218                    'inbound'   : inbound
219                }
220            endif
221        endfor
222        ## add operation details to item
223        for operation in grid.operations:
224            item_dict['operation_config'][operation.label] = {
225                'allowed'   : operation.allowed(item),
226                'url_args'  : url( **operation.get_url_args( item ) )
227            }
228        endfor
229
230        ## add item to list
231        self.grid_config['items'].append(item_dict)
232    endfor
233%>
234</%def>
235
236##
237## Override methods from base.mako and base_panels.mako
238##
239
240## render title
241<%def name="title()">${self.grid_config['title']}</%def>
242
243## render in center panel
244<%def name="center_panel()">
245    ${self.load()}
246</%def>
247
248## render in body
249<%def name="body()">
250    ${self.load()}
251</%def>