PageRenderTime 42ms CodeModel.GetById 20ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/templates/library/common/browse_library.mako

https://bitbucket.org/cistrome/cistrome-harvard/
Mako | 619 lines | 573 code | 38 blank | 8 comment | 18 complexity | f3190a0dfcac682441982f9af1b3e89f MD5 | raw file
  1<%namespace file="/message.mako" import="render_msg" />
  2<%namespace file="/library/common/library_item_info.mako" import="render_library_item_info" />
  3<%namespace file="/library/common/common.mako" import="render_actions_on_multiple_items" />
  4<%namespace file="/library/common/common.mako" import="render_compression_types_help" />
  5<%namespace file="/library/common/common.mako" import="common_javascripts" />
  6
  7<%!
  8    def inherit(context):
  9        if context.get('use_panels'):
 10            return '/webapps/galaxy/base_panels.mako'
 11        else:
 12            return '/base.mako'
 13%>
 14<%inherit file="${inherit(context)}"/>
 15
 16<%def name="init()">
 17<%
 18    self.has_left_panel=False
 19    self.has_right_panel=False
 20    self.message_box_visible=False
 21    self.active_view="user"
 22    self.overlay_visible=False
 23    self.has_accessible_datasets = False
 24%>
 25</%def>
 26
 27##
 28## Override methods from base.mako and base_panels.mako
 29##
 30<%def name="center_panel()">
 31   <div style="overflow: auto; height: 100%;">
 32       <div class="page-container" style="padding: 10px;">
 33           ${render_content()}
 34       </div>
 35   </div>
 36</%def>
 37
 38## Render the grid's basic elements. Each of these elements can be subclassed.
 39<%def name="body()">
 40    ${render_content()}
 41</%def>
 42
 43<%def name="title()">Browse data library</%def>
 44<%def name="stylesheets()">
 45    ${parent.stylesheets()}
 46    ${h.css( "library" )}
 47</%def>
 48
 49<%def name="javascripts()">
 50    ${parent.javascripts()}
 51    ${h.js("jstorage")}
 52    ${common_javascripts()}
 53    ${self.grid_javascripts()}
 54</%def>
 55
 56<%def name="grid_javascripts()">
 57    <script type="text/javascript">
 58        var init_libraries = function() {
 59            var storage_id = "library-expand-state-${trans.security.encode_id(library.id)}";
 60            
 61            var restore_folder_state = function() {
 62                var state = $.jStorage.get(storage_id);
 63                if (state) {
 64                    for (var id in state) {
 65                        if (state[id] === true) {
 66                            var row = $("#" + id),
 67                                index = row.parent().children().index(row);
 68                            row.addClass("expanded").show();
 69                            row.siblings().filter("tr[parent='" + index + "']").show();
 70                        }
 71                    }
 72                }
 73            };
 74            
 75            var save_folder_state = function() {
 76                var state = {};
 77                $("tr.folderRow").each( function() {
 78                    var folder = $(this);
 79                    state[folder.attr("id")] = folder.hasClass("expanded");
 80                });
 81                $.jStorage.set(storage_id, state);
 82            };
 83            
 84            $("#library-grid").each(function() {
 85                var child_of_parent_cache = {};
 86                // Recursively fill in children and descendents of each row
 87                var process_row = function(q, parents) {
 88                    // Find my index
 89                    var parent = q.parent(),
 90                        this_level = child_of_parent_cache[parent] || (child_of_parent_cache[parent] = parent.children());
 91                        
 92                    var index = this_level.index(q);
 93                    // Find my immediate children
 94                    var children = $(par_child_dict[index]);
 95                    // Recursively handle them
 96                    var descendents = children;
 97                    children.each( function() {
 98                        child_descendents = process_row( $(this), parents.add(q) );
 99                        descendents = descendents.add(child_descendents);
100                    });
101                    // Set up expand / hide link
102                    var expand_fn = function() {
103                        if ( q.hasClass("expanded") ) {
104                            descendents.hide();
105                            descendents.removeClass("expanded");
106                            q.removeClass("expanded");
107                        } else {
108                            children.show();
109                            q.addClass("expanded");
110                        }
111                        save_folder_state();
112                    };
113                    $("." + q.attr("id") + "-click").click(expand_fn);
114                    // Check/uncheck boxes in subfolders.
115                    q.children("td").children("input[type=checkbox]").click( function() {
116                        if ( $(this).is(":checked") ) {
117                            descendents.find("input[type=checkbox]").attr("checked", true);
118                        } else {
119                            descendents.find("input[type=checkbox]").attr("checked", false);
120                            // If you uncheck a lower level checkbox, uncheck the boxes above it
121                            // (since deselecting a child means the parent is not fully selected any more).
122                            parents.children("td").children("input[type=checkbox]").attr("checked", false);
123                        }
124                    });
125                    // return descendents for use by parent
126                    return descendents;
127                }
128                
129                // Initialize dict[parent_id] = rows_which_have_that_parent_id_as_parent_attr
130                var par_child_dict = {},
131                    no_parent = [];
132                
133                $(this).find("tbody tr").each( function() {
134                    if ( $(this).attr("parent")) {
135                        var parent = $(this).attr("parent");
136                        if (par_child_dict[parent] !== undefined) {
137                            par_child_dict[parent].push(this);
138                        } else {
139                            par_child_dict[parent] = [this];
140                        }
141                    } else {
142                        no_parent.push(this);
143                    }                        
144                });
145                
146                $(no_parent).each( function() {
147                    descendents = process_row( $(this), $([]) );
148                    descendents.hide();
149               });
150            });
151            
152            restore_folder_state();
153        };
154        $(function() {
155            init_libraries();
156        });
157        
158        // Looks for changes in dataset state using an async request. Keeps
159        // calling itself (via setTimeout) until all datasets are in a terminal
160        // state.
161        var updater = function ( tracked_datasets ) {
162            // Check if there are any items left to track
163            var empty = true;
164            for ( i in tracked_datasets ) {
165                empty = false;
166                break;
167            }
168            if ( ! empty ) {
169                setTimeout( function() { updater_callback( tracked_datasets ) }, 3000 );
170            }
171        };
172        var updater_callback = function ( tracked_datasets ) {
173            // Build request data
174            var ids = []
175            var states = []
176            $.each( tracked_datasets, function ( id, state ) {
177                ids.push( id );
178                states.push( state );
179            });
180            // Make ajax call
181            $.ajax( {
182                type: "POST",
183                url: "${h.url_for( controller='library_common', action='library_item_updates' )}",
184                dataType: "json",
185                data: { ids: ids.join( "," ), states: states.join( "," ) },
186                success : function ( data ) {
187                    $.each( data, function( id, val ) {
188                        // Replace HTML
189                        var cell = $("#libraryItem-" + id).find("#libraryItemInfo");
190                        cell.html( val.html );
191                        // If new state was terminal, stop tracking
192                        if (( val.state == "ok") || ( val.state == "error") || ( val.state == "empty") || ( val.state == "deleted" ) || ( val.state == "discarded" )) {
193                            delete tracked_datasets[ parseInt(id) ];
194                        } else {
195                            tracked_datasets[ parseInt(id) ] = val.state;
196                        }
197                    });
198                    updater( tracked_datasets ); 
199                },
200                error: function() {
201                    // Just retry, like the old method, should try to be smarter
202                    updater( tracked_datasets );
203                }
204            });
205        };
206    </script>
207</%def>
208
209<%def name="render_dataset( cntrller, ldda, library_dataset, selected, library, folder, pad, parent, row_counter, tracked_datasets, show_deleted=False, simple=False )">
210    <%
211        ## The received ldda must always be a LibraryDatasetDatasetAssociation object.  The object id passed to methods
212        ## from the drop down menu should be the ldda id to prevent id collision ( which could happen when displaying
213        ## children, which are always lddas ).  We also need to make sure we're displaying the latest version of this
214        ## library_dataset, so we display the attributes from the ldda.
215        
216        from galaxy.web.controllers.library_common import branch_deleted
217        
218        is_admin = trans.user_is_admin() and cntrller == 'library_admin'
219        
220        if ldda.user:
221            uploaded_by = ldda.user.email
222        else:
223            uploaded_by = 'anonymous'
224        if ldda == library_dataset.library_dataset_dataset_association:
225            current_version = True
226            if is_admin:
227                can_modify = can_manage = True
228            elif cntrller in [ 'library', 'requests' ]:
229                can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, library_dataset )
230                can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, library_dataset )
231            else:
232                can_modify = can_manage = False
233        else:
234            current_version = False
235        if current_version and ldda.state not in ( 'ok', 'error', 'empty', 'deleted', 'discarded' ):
236            tracked_datasets[ldda.id] = ldda.state
237        info_association, inherited = ldda.get_info_association( restrict=True )
238        form_type = trans.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE
239    %>
240    %if current_version and ( not ldda.library_dataset.deleted or show_deleted ):
241        <tr class="datasetRow"
242            %if parent is not None:
243                parent="${parent}"
244            %endif
245            id="libraryItem-${ldda.id}">
246            <td style="padding-left: ${pad+20}px;">
247                <input style="float: left;" type="checkbox" name="ldda_ids" id="${trans.security.encode_id( ldda.id )}" value="${trans.security.encode_id( ldda.id )}"
248                %if selected:
249                    checked="checked"
250                %endif
251                />
252                %if simple:
253                    <label for="${trans.security.encode_id( ldda.id )}">${ldda.name}</label>
254                %else:
255                    <div style="float: left; margin-left: 1px;" class="menubutton split popup" id="dataset-${ldda.id}-popup">
256                        <a class="view-info" href="${h.url_for( controller='library_common', action='ldda_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">
257                            %if ldda.library_dataset.deleted:
258                                <div class="libraryItem-error">${ldda.name}</div>
259                            %else:
260                                ${ldda.name}
261                            %endif     
262                        </a>
263                    </div>
264                    %if not library.deleted:
265                        <div popupmenu="dataset-${ldda.id}-popup">
266                            %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and can_modify:
267                                <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_edit_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit information</a>
268                                <a class="action-button" href="${h.url_for( controller='library_common', action='move_library_item', cntrller=cntrller, item_type='ldda', item_id=trans.security.encode_id( ldda.id ), source_library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Move this dataset</a>
269                            %else:
270                                <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_info', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">View information</a>
271                            %endif
272                            %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and can_modify and not info_association:
273                                <a class="action-button" href="${h.url_for( controller='library_common', action='add_template', cntrller=cntrller, item_type='ldda', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), ldda_id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Use template</a>
274                            %endif
275                            %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and can_modify and info_association:
276                                <a class="action-button" href="${h.url_for( controller='library_common', action='edit_template', cntrller=cntrller, item_type='ldda', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), ldda_id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit template</a>
277                                <a class="action-button" href="${h.url_for( controller='library_common', action='delete_template', cntrller=cntrller, item_type='ldda', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), ldda_id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Unuse template</a>
278                            %endif
279                            %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and can_manage:
280                                %if not trans.app.security_agent.dataset_is_public( ldda.dataset ):
281                                    <a class="action-button" href="${h.url_for( controller='library_common', action='make_library_item_public', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_type='ldda', id=trans.security.encode_id( ldda.dataset.id ), use_panels=use_panels, show_deleted=show_deleted )}">Make public</a>
282                                %endif
283                                <a class="action-button" href="${h.url_for( controller='library_common', action='ldda_permissions', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), id=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit permissions</a>
284                            %endif
285                            %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and can_modify:
286                                <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), replace_id=trans.security.encode_id( library_dataset.id ), show_deleted=show_deleted )}">Upload a new version of this dataset</a>
287                            %endif
288                            %if not branch_deleted( folder ) and not ldda.library_dataset.deleted and ldda.has_data:
289                                <a class="action-button" href="${h.url_for( controller='library_common', action='import_datasets_to_histories', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), ldda_ids=trans.security.encode_id( ldda.id ), use_panels=use_panels, show_deleted=show_deleted )}">Import this dataset into selected histories</a>
290                                <a class="action-button" href="${h.url_for( controller='library_common', action='download_dataset_from_folder', cntrller=cntrller, id=trans.security.encode_id( ldda.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels )}">Download this dataset</a>
291                            %endif
292                            %if can_modify:
293                                %if not library.deleted and not branch_deleted( folder ) and not ldda.library_dataset.deleted:
294                                    <a class="action-button" confirm="Click OK to delete dataset '${ldda.name}'." href="${h.url_for( controller='library_common', action='delete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library_dataset.id ), item_type='library_dataset', show_deleted=show_deleted )}">Delete this dataset</a>
295                                %elif not library.deleted and not branch_deleted( folder ) and not ldda.library_dataset.purged and ldda.library_dataset.deleted:
296                                    <a class="action-button" href="${h.url_for( controller='library_common', action='undelete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library_dataset.id ), item_type='library_dataset', show_deleted=show_deleted )}">Undelete this dataset</a>
297                                %endif
298                            %endif
299                        </div>
300                    %endif
301                %endif
302            </td>
303            % if not simple:
304                <td id="libraryItemInfo">${render_library_item_info( ldda )}</td>
305                <td>${uploaded_by}</td>
306            % endif
307            <td>${ldda.create_time.strftime( "%Y-%m-%d" )}</td>
308            <td>${ldda.get_size( nice_size=True )}</td>
309        </tr>
310        <%
311            my_row = row_counter.count
312            row_counter.increment()
313        %>
314    %endif
315</%def>
316
317<%def name="render_folder( cntrller, folder, folder_pad, created_ldda_ids, library, hidden_folder_ids, tracked_datasets, show_deleted=False, parent=None, row_counter=None, root_folder=False, simple=False )">
318    <%
319        from galaxy.web.controllers.library_common import active_folders, active_folders_and_library_datasets, activatable_folders_and_library_datasets, branch_deleted
320        
321        is_admin = trans.user_is_admin() and cntrller == 'library_admin'
322        has_accessible_library_datasets = trans.app.security_agent.has_accessible_library_datasets( trans, folder, trans.user, current_user_roles, search_downward=False )
323        
324        if root_folder:
325            pad = folder_pad
326            expander = h.url_for("/static/images/silk/resultset_bottom.png")
327            folder_img = h.url_for("/static/images/silk/folder_page.png")
328        else:
329            pad = folder_pad + 20
330            expander = h.url_for("/static/images/silk/resultset_next.png")
331            folder_img = h.url_for("/static/images/silk/folder.png")
332        if created_ldda_ids:
333            created_ldda_ids = util.listify( created_ldda_ids )
334        if str( folder.id ) in hidden_folder_ids:
335            return ""
336        my_row = None
337        if is_admin:
338            can_add = can_modify = can_manage = True
339        elif cntrller in [ 'library' ]:
340            can_access, folder_ids = trans.app.security_agent.check_folder_contents( trans.user, current_user_roles, folder )
341            if not can_access:
342                can_show, folder_ids = \
343                    trans.app.security_agent.show_library_item( trans.user,
344                                                                current_user_roles,
345                                                                folder,
346                                                                [ trans.app.security_agent.permitted_actions.LIBRARY_ADD,
347                                                                  trans.app.security_agent.permitted_actions.LIBRARY_MODIFY,
348                                                                  trans.app.security_agent.permitted_actions.LIBRARY_MANAGE ] )
349                if not can_show:
350                    return ""
351            can_add = trans.app.security_agent.can_add_library_item( current_user_roles, folder )
352            can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, folder )
353            can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, folder )
354        else:
355            can_add = can_modify = can_manage = False
356            
357        form_type = trans.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE
358        info_association, inherited = folder.get_info_association( restrict=True )
359    %>
360    %if not root_folder and ( not folder.deleted or show_deleted ):
361        <% encoded_id = trans.security.encode_id( folder.id ) %>
362        <tr id="folder-${encoded_id}" class="folderRow libraryOrFolderRow"
363            %if parent is not None:
364                parent="${parent}"
365                style="display: none;"
366            %endif
367            >
368            <td style="padding-left: ${folder_pad}px;">
369                <input type="checkbox" class="folderCheckbox"/>
370                <span class="expandLink folder-${encoded_id}-click">
371                    <div style="float: left; margin-left: 2px;" class="menubutton split popup" id="folder_img-${folder.id}-popup">
372                        <a class="folder-${encoded_id}-click" href="javascript:void(0);">
373                            <span class="rowIcon"></span>
374                            %if folder.deleted:
375                                <div class="libraryItem-error">${folder.name}</div>
376                            %else:
377                                ${folder.name}
378                            %endif
379                        </a>
380                    </div>
381                </span>
382                %if not library.deleted:
383                    <div popupmenu="folder_img-${folder.id}-popup">
384                        %if not branch_deleted( folder ) and can_add:
385                            <a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Add datasets</a>
386                            <a class="action-button" href="${h.url_for( controller='library_common', action='create_folder', cntrller=cntrller, parent_id=trans.security.encode_id( folder.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Add sub-folder</a>
387                        %endif
388                        %if not branch_deleted( folder ):
389                            %if has_accessible_library_datasets:
390                                <a class="action-button" href="${h.url_for( controller='library_common', action='import_datasets_to_histories', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Select datasets for import into selected histories</a>
391                            %endif
392                            %if can_modify:
393                                <a class="action-button" href="${h.url_for( controller='library_common', action='folder_info', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit information</a>
394                                <a class="action-button" href="${h.url_for( controller='library_common', action='move_library_item', cntrller=cntrller, item_type='folder', item_id=trans.security.encode_id( folder.id ), source_library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Move this folder</a>
395                            %else:
396                                <a class="action-button" class="view-info" href="${h.url_for( controller='library_common', action='folder_info', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">View information</a>
397                            %endif
398                        %endif
399                        %if not branch_deleted( folder ) and can_modify and not info_association:
400                            <a class="action-button" href="${h.url_for( controller='library_common', action='add_template', cntrller=cntrller, item_type='folder', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Use template</a>
401                        %endif
402                        %if not branch_deleted( folder ) and can_modify and info_association:
403                            <a class="action-button" href="${h.url_for( controller='library_common', action='edit_template', cntrller=cntrller, item_type='folder', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit template</a>
404                            <a class="action-button" href="${h.url_for( controller='library_common', action='delete_template', cntrller=cntrller, item_type='folder', form_type=form_type, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Unuse template</a>
405                        %endif
406                        %if not branch_deleted( folder ) and can_manage:
407                           %if not trans.app.security_agent.folder_is_public( folder ):
408                               <a class="action-button" href="${h.url_for( controller='library_common', action='make_library_item_public', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_type='folder', id=trans.security.encode_id( folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Make public</a>
409                           %endif
410                            <a class="action-button" href="${h.url_for( controller='library_common', action='folder_permissions', cntrller=cntrller, id=trans.security.encode_id( folder.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit permissions</a>
411                        %endif
412                        %if can_modify:
413                            %if not library.deleted and not folder.deleted:
414                                <a class="action-button" confirm="Click OK to delete the folder '${folder.name}.'" href="${h.url_for( controller='library_common', action='delete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( folder.id ), item_type='folder', show_deleted=show_deleted )}">Delete this folder</a>
415                            %elif not library.deleted and folder.deleted and not folder.purged:
416                                <a class="action-button" href="${h.url_for( controller='library_common', action='undelete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( folder.id ), item_type='folder', show_deleted=show_deleted )}">Undelete this folder</a>
417                            %endif
418                        %endif
419                    </div>
420                %endif
421            <td>
422            %if folder.description:
423                ${folder.description}
424            %endif
425            <td colspan="3"></td>
426        </tr>
427        <%
428            my_row = row_counter.count
429            row_counter.increment()
430        %>
431    %endif
432    <%
433        if show_deleted:
434            sub_folders, library_datasets = activatable_folders_and_library_datasets( trans, folder )
435        else:
436            sub_folders, library_datasets = active_folders_and_library_datasets( trans, folder )
437    %>
438    %if is_admin:
439        %for sub_folder in sub_folders:
440            ${render_folder( cntrller, sub_folder, pad, created_ldda_ids, library, [], tracked_datasets, show_deleted=show_deleted, parent=my_row, row_counter=row_counter, root_folder=False )}
441        %endfor 
442        %for library_dataset in library_datasets:
443            <%
444                ldda = library_dataset.library_dataset_dataset_association
445                if ldda:
446                    # There should always be an ldda, but some users running their own instances have reported that
447                    # some of their LibraryDatasets have no associated lddas
448                    selected = created_ldda_ids and str( ldda.id ) in created_ldda_ids
449            %>
450            %if ldda:
451                ${render_dataset( cntrller, ldda, library_dataset, selected, library, folder, pad, my_row, row_counter, tracked_datasets, show_deleted=show_deleted )}
452            %endif
453        %endfor
454    %else:
455        %for sub_folder in sub_folders:
456            ${render_folder( cntrller, sub_folder, pad, created_ldda_ids, library, hidden_folder_ids, tracked_datasets, show_deleted=show_deleted, parent=my_row, row_counter=row_counter, root_folder=False, simple=simple )}
457        %endfor
458        %for library_dataset in library_datasets:
459            <%
460                ldda = library_dataset.library_dataset_dataset_association
461                if ldda:
462                    # There should always be an ldda, but some users running their own instances have reported that
463                    # some of their LibraryDatasets have no associated lddas
464                    can_access = trans.app.security_agent.can_access_dataset( current_user_roles, ldda.dataset )
465                    selected = created_ldda_ids and str( ldda.id ) in created_ldda_ids
466                else:
467                    can_access = False
468            %>
469            %if can_access:
470                ${render_dataset( cntrller, ldda, library_dataset, selected, library, folder, pad, my_row, row_counter, tracked_datasets, show_deleted=show_deleted, simple=simple )}
471            %endif
472        %endfor
473    %endif
474</%def>
475
476<%def name="render_content(simple=False)">
477    <%
478        from galaxy import util
479        from galaxy.web.controllers.library_common import branch_deleted
480        from time import strftime
481        
482        is_admin = trans.user_is_admin() and cntrller == 'library_admin'
483        
484        if is_admin:
485            can_add = can_modify = can_manage = True
486        elif cntrller in [ 'library', 'requests' ]:
487            can_add = trans.app.security_agent.can_add_library_item( current_user_roles, library )
488            can_modify = trans.app.security_agent.can_modify_library_item( current_user_roles, library )
489            can_manage = trans.app.security_agent.can_manage_library_item( current_user_roles, library )
490        else:
491            can_add = can_modify = can_manage = False
492            
493        info_association, inherited = library.get_info_association()
494        form_type = trans.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE
495        
496        self.has_accessible_datasets = trans.app.security_agent.has_accessible_library_datasets( trans, library.root_folder, trans.user, current_user_roles )
497        root_folder_has_accessible_library_datasets = trans.app.security_agent.has_accessible_library_datasets( trans, library.root_folder, trans.user, current_user_roles, search_downward=False )
498        has_accessible_folders = is_admin or trans.app.security_agent.has_accessible_folders( trans, library.root_folder, trans.user, current_user_roles )
499        
500        tracked_datasets = {}
501        
502        class RowCounter( object ):
503            def __init__( self ):
504                self.count = 0
505            def increment( self ):
506                self.count += 1
507            def __str__( self ):
508                return str( self.count )
509    %>
510    
511    <h2>Data Library &ldquo;${library.name}&rdquo;</h2>
512    
513     <ul class="manage-table-actions">
514         %if not library.deleted and ( is_admin or can_add ):
515             <li><a class="action-button" href="${h.url_for( controller='library_common', action='upload_library_dataset', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( library.root_folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Add datasets</a></li>
516             <li><a class="action-button" href="${h.url_for( controller='library_common', action='create_folder', cntrller=cntrller, parent_id=trans.security.encode_id( library.root_folder.id ), library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Add folder</a></li>
517         %endif
518         %if ( ( not library.deleted ) and ( can_modify or can_manage ) ) or ( can_modify and not library.purged ) or ( library.purged ):
519             <li><a class="action-button" id="library-${library.id}-popup" class="menubutton">Library Actions</a></li>
520             <div popupmenu="library-${library.id}-popup">
521                 %if not library.deleted:
522                     %if can_modify:
523                         <a class="action-button" href="${h.url_for( controller='library_common', action='library_info', cntrller=cntrller, id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit information</a>
524                         <a class="action-button" confirm="Click OK to delete the library named '${library.name}'." href="${h.url_for( controller='library_common', action='delete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library.id ), item_type='library' )}">Delete this data library</a>
525                         %if show_deleted:
526                             <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=False )}">Hide deleted items</a>
527                         %else:
528                             <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=True )}">Show deleted items</a>
529                         %endif
530                     %endif
531                     %if can_modify and not library.info_association:
532                         <a class="action-button" href="${h.url_for( controller='library_common', action='add_template', cntrller=cntrller, item_type='library', form_type=form_type, library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Use template</a>
533                     %endif
534                     %if can_modify and info_association:
535                         <a class="action-button" href="${h.url_for( controller='library_common', action='edit_template', cntrller=cntrller, item_type='library', form_type=form_type, library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit template</a>
536                         <a class="action-button" href="${h.url_for( controller='library_common', action='delete_template', cntrller=cntrller, item_type='library', form_type=form_type, library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Unuse template</a>
537                     %endif
538                     %if can_manage:
539                         %if not trans.app.security_agent.library_is_public( library, contents=True ):
540                             <a class="action-button" href="${h.url_for( controller='library_common', action='make_library_item_public', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_type='library', id=trans.security.encode_id( library.id ), contents=True, use_panels=use_panels, show_deleted=show_deleted )}">Make public</a>
541                         %endif
542                         <a class="action-button" href="${h.url_for( controller='library_common', action='library_permissions', cntrller=cntrller, id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">Edit permissions</a>
543                     %endif
544                     %if root_folder_has_accessible_library_datasets:
545                        <a class="action-button" href="${h.url_for( controller='library_common', action='import_datasets_to_histories', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), folder_id=trans.security.encode_id( library.root_folder.id ), use_panels=use_panels, show_deleted=show_deleted )}">Select datasets for import into selected histories</a>
546                     %endif
547                 %elif can_modify and not library.purged:
548                     <a class="action-button" href="${h.url_for( controller='library_common', action='undelete_library_item', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), item_id=trans.security.encode_id( library.id ), item_type='library', use_panels=use_panels )}">Undelete this data library</a>
549                 %elif library.purged:
550                     <a class="action-button" href="${h.url_for( controller='library_common', action='browse_library', cntrller=cntrller, id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}">This data library has been purged</a>
551                 %endif
552             </div>
553         %endif
554    </ul>
555    
556    %if message:
557        ${render_msg( message, status )}
558    %endif
559
560    %if library.synopsis not in [ '', 'None', None ]:
561        <div class="libraryItemBody">
562            ${library.synopsis}
563        </div>
564    %endif
565    
566    %if self.has_accessible_datasets:
567        <form name="act_on_multiple_datasets" action="${h.url_for( controller='library_common', action='act_on_multiple_datasets', cntrller=cntrller, library_id=trans.security.encode_id( library.id ), use_panels=use_panels, show_deleted=show_deleted )}" onSubmit="javascript:return checkForm();" method="post">
568    %endif
569    %if has_accessible_folders:
570        <table cellspacing="0" cellpadding="0" border="0" width="100%" class="grid" id="library-grid">
571            <thead>
572                <tr class="libraryTitle">
573                    <th>
574                        %if self.has_accessible_datasets:
575                            <input type="checkbox" id="checkAll" name=select_all_datasets_checkbox value="true" onclick='checkAllFields(1);'/><input type="hidden" name=select_all_datasets_checkbox value="true"/>
576                        %endif
577                        Name
578                    </th>
579                    % if not simple:
580                        <th>Message</th>
581                        <th>Uploaded By</th>
582                    % endif
583                    <th>Date</th>
584                    <th>File Size</th>
585                </tr>
586            </thead>
587            <% row_counter = RowCounter() %>
588            %if cntrller in [ 'library', 'requests' ]:
589                ${self.render_folder( 'library', library.root_folder, 0, created_ldda_ids, library, hidden_folder_ids, tracked_datasets, show_deleted=show_deleted, parent=None, row_counter=row_counter, root_folder=True, simple=simple )}
590                %if not library.deleted and self.has_accessible_datasets and not simple:
591                    ${render_actions_on_multiple_items()}
592                %endif
593            %elif ( trans.user_is_admin() and cntrller in [ 'library_admin', 'requests_admin' ] ):
594                ${self.render_folder( 'library_admin', library.root_folder, 0, created_ldda_ids, library, [], tracked_datasets, show_deleted=show_deleted, parent=None, row_counter=row_counter, root_folder=True )}
595                %if not library.deleted and not show_deleted and self.has_accessible_datasets:
596                    ${render_actions_on_multiple_items()}
597                %endif
598            %endif
599        </table>
600    %endif
601    %if self.has_accessible_datasets:
602        </form>
603    %endif
604     
605    %if tracked_datasets:
606        <script type="text/javascript">
607            // Updater
608            updater({${ ",".join( [ '"%s" : "%s"' % ( k, v ) for k, v in tracked_datasets.iteritems() ] ) }});
609        </script>
610        <!-- running: do not change this comment, used by TwillTestCase.library_wait -->
611    %endif
612    
613    %if self.has_accessible_datasets and not simple:
614        ${render_compression_types_help( comptypes )}
615    %endif
616    %if not has_accessible_folders:
617        The data library '${library.name}' does not contain any datasets that you can access.
618    %endif
619</%def>