data libraries: permissions UI and API work, library router fixes, security addition for retrieving paginated roles for given dataset

This commit is contained in:
Martin Cech
2014-05-16 18:13:26 -04:00
parent 573ce4babe
commit f599e9b01c
14 changed files with 238 additions and 95 deletions
+69
View File
@@ -208,6 +208,75 @@ class GalaxyRBACAgent( RBACAgent ):
roles.add( role )
return self.sort_by_attr( [ role for role in roles ], 'name' )
def get_valid_dataset_roles( self, trans, dataset, query, page, page_limit ):
"""
This method retrieves the list of possible roles that user can select
in the dataset permissions form. Admins can select any role so the
results are paginated in order to save the bandwidth and to speed
things up.
Standard users can select their own private role, any fo their
sharing roles and any public role (not private and not sharing).
"""
roles = []
if query is not None:
query = query.replace( '_', '/_' ).replace( '%', '/%' ).replace( '/', '//' )
search_query = query + '%'
# Limit the query only to get the page needed
limit = page * page_limit
# Admins see it all
if trans.user_is_admin():
# Add all roles that fit the query
db_query = trans.sa_session.query( trans.app.model.Role ).filter( self.model.Role.table.c.deleted == False )
if query is not None:
db_query = db_query.filter( self.model.Role.table.c.name.like( search_query, escape='/' ) )
for role in ( db_query.order_by( self.model.Role.table.c.name ).limit( limit ) ):
roles.append( role )
# Take last page of the selection
roles = roles[ ( -page_limit ): ]
# Non-admins see the list of relevant roles
else:
if self.dataset_is_public( dataset ):
# Add the current user's private role
roles.append( self.get_private_user_role( trans.user ) )
# Add the current user's sharing roles
for role in self.get_sharing_roles( trans.user ):
roles.append( role )
# Add all remaining non-private, non-sharing roles
for role in trans.sa_session.query( trans.app.model.Role ) \
.filter( and_( self.model.Role.table.c.deleted == False,
self.model.Role.table.c.type != self.model.Role.types.PRIVATE,
self.model.Role.table.c.type != self.model.Role.types.SHARING ) ) \
.order_by( self.model.Role.table.c.name ):
roles.append( role )
else:
# If item has roles associated with the access permission, we need to start with them.
access_roles = dataset.get_access_roles( trans )
for role in access_roles:
if trans.user_is_admin() or self.ok_to_display( trans.user, role ):
roles.append( role )
# Each role potentially has users. We need to find all roles that each of those users have.
for ura in role.users:
user = ura.user
for ura2 in user.roles:
if trans.user_is_admin() or self.ok_to_display( trans.user, ura2.role ):
roles.append( ura2.role )
# Each role also potentially has groups which, in turn, have members ( users ). We need to
# find all roles that each group's members have.
for gra in role.groups:
group = gra.group
for uga in group.users:
user = uga.user
for ura in user.roles:
if trans.user_is_admin() or self.ok_to_display( trans.user, ura.role ):
roles.append( ura.role )
# Omit duplicated roles by converting to set
return_roles = set( roles )
return self.sort_by_attr( [ role for role in return_roles ], 'name' )
def get_legitimate_roles( self, trans, item, cntrller ):
"""
Return a sorted list of legitimate roles that can be associated with a permission on
+28 -7
View File
@@ -75,9 +75,16 @@ class LibraryDatasetsController( BaseAPIController, UsesVisualizationMixin ):
for a given dataset permission.
"""
current_user_roles = trans.get_current_user_roles()
page = int( kwd.get( 'page', None ) )
page_limit = int( kwd.get( 'page_limit', None ) )
query = kwd.get ( 'q', None )
page = kwd.get( 'page', None )
if page is not None:
page = int( page )
page_limit = kwd.get( 'page_limit', None )
if page_limit is not None:
page_limit = int( page_limit )
query = kwd.get( 'q', None )
if page is None:
page = 1
@@ -96,11 +103,8 @@ class LibraryDatasetsController( BaseAPIController, UsesVisualizationMixin ):
if not can_manage:
raise exceptions.InsufficientPermissionsException( 'You do not have proper permissions to access permissions.' )
cntrller = 'standard_user'
if trans.user_is_admin():
cntrller = 'library_admin'
roles = trans.app.security_agent.get_valid_dataset_roles( trans, dataset, query, page, page_limit )
roles = trans.app.security_agent.get_legitimate_roles( trans, library, cntrller )
total_roles = len( roles )
return_roles = []
for role in roles:
@@ -108,6 +112,23 @@ class LibraryDatasetsController( BaseAPIController, UsesVisualizationMixin ):
return dict( roles=return_roles, page=page, page_limit=page_limit, total=total_roles )
@expose_api
def get_roles( self, trans, encoded_dataset_id, **kwd ):
try:
library_dataset = self.get_library_dataset( trans, id=encoded_dataset_id, check_ownership=False, check_accessible=False )
except Exception, e:
raise exceptions.ObjectNotFound( 'Requested dataset was not found.' + str(e) )
dataset = library_dataset.library_dataset_dataset_association.dataset
roles = dataset.get_access_roles( trans )
# roles = dataset.get_manage_permissions_roles( trans )
# roles = trans.app.security_agent.get_current_dataset_roles( trans, dataset, trans.app.security_agent.permitted_actions.DATASET_ACCESS )
# Omit duplicated roles by converting to set
roles = set( roles )
return [ role.name for role in roles ]
@expose_api
def delete( self, trans, encoded_dataset_id, **kwd ):
"""
+6
View File
@@ -224,6 +224,12 @@ def app_factory( global_conf, **kwargs ):
action='show_roles',
conditions=dict( method=[ "GET" ] ) )
webapp.mapper.connect( 'show_legitimate_lda_roles',
'/api/libraries/datasets/:encoded_dataset_id/permissions/current',
controller='lda_datasets',
action='get_roles',
conditions=dict( method=[ "GET" ] ) )
webapp.mapper.connect( 'delete_lda_item',
'/api/libraries/datasets/:encoded_dataset_id',
controller='lda_datasets',
+10 -2
View File
@@ -74,6 +74,7 @@ var GalaxyLibrary = Backbone.View.extend({
library_router: null,
folderToolbarView: null,
folderListView: null,
datasetView: null,
initialize : function(){
Galaxy.libraries = this;
@@ -106,10 +107,17 @@ var GalaxyLibrary = Backbone.View.extend({
});
this.library_router.on('route:dataset_detail', function(folder_id, dataset_id){
new mod_library_dataset_view.LibraryDatasetView({id: dataset_id})
if (Galaxy.libraries.datasetView){
Galaxy.libraries.datasetView.$el.unbind('click');
}
Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id});
});
this.library_router.on('route:dataset_permissions', function(folder_id, dataset_id){
new mod_library_dataset_view.LibraryDatasetView({id: dataset_id, show_permissions: true})
if (Galaxy.libraries.datasetView){
Galaxy.libraries.datasetView.$el.unbind('click');
}
Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: dataset_id, show_permissions: true});
});
Backbone.history.start({pushState: false});
@@ -20,10 +20,15 @@ var LibraryDatasetView = Backbone.View.extend({
events: {
"click .toolbtn_modify_dataset" : "enableModification",
"click .toolbtn_cancel_modifications" : "render",
"click .toolbtn_change_permissions" : "showPermissions",
"click .toolbtn-download-dataset" : "downloadDataset",
"click .toolbtn-import-dataset" : "importIntoHistory",
"click .toolbtn-share-dataset" : "shareDataset"
"click .toolbtn-share-dataset" : "shareDataset",
// missing features below
"click .toolbtn_save_modifications" : "comingSoon",
"click .btn-remove-restrictions" : "comingSoon",
"click .btn-make-private" : "comingSoon",
"click .btn-share-dataset" : "comingSoon"
},
@@ -132,7 +137,7 @@ var LibraryDatasetView = Backbone.View.extend({
},
importCurrentIntoHistory: function(){
var self = this;
// var self = this;
var history_id = $(this.modal.elMain).find('select[name=dataset_import_single] option:selected').val();
var historyItem = new mod_library_model.HistoryItem();
historyItem.url = historyItem.urlRoot + history_id + '/contents';
@@ -165,88 +170,102 @@ var LibraryDatasetView = Backbone.View.extend({
mod_toastr.info('Feature coming soon.');
},
goBack: function(){
Galaxy.libraries.library_router.back();
},
showPermissions: function(){
$(".tooltip").remove();
var template = this.templateDatasetPermissions();
this.$el.html(template({item: this.model}));
// Select works different for admins
var is_admin = false;
if (Galaxy.currUser){
is_admin = Galaxy.currUser.isAdmin();
}
var self = this;
this.access_perm = new mod_select.View({
css: 'access_perm',
multiple:true,
placeholder: 'Click to select a role',
container: self.$el.find('#access_perm'),
ajax: {
url: "/api/libraries/datasets/5969b1f7201f12ae/permissions",
dataType: 'json',
quietMillis: 100,
data: function (term, page) { // page is the one-based page number tracked by Select2
return {
q: term, //search term
page_limit: 10, // page size
page: page // page number
};
},
results: function (data, page) {
var more = (page * 10) < data.total; // whether or not there are more results available
// notice we return the value of more so Select2 knows if more results can be loaded
return {results: data.roles, more: more};
}
},
formatResult : function roleFormatResult(role) {
return role.name;
},
// load all current permissions
$.get( "/api/libraries/datasets/" + self.id + "/permissions/current").done(function(fetched_permissions) {
var selected_roles = [];
for (var i = 0; i < fetched_permissions.length; i++) {
selected_roles.push(fetched_permissions[i] + ':' + fetched_permissions[i]);
}
// ACCESS PERMISSIONS
if (is_admin){ // Admin has a special select that allows remote searching
var access_select_options = {
minimumInputLength: 1,
css: 'access_perm',
multiple:true,
placeholder: 'Click to select a role',
container: self.$el.find('#access_perm'),
ajax: {
url: "/api/libraries/datasets/" + self.id + "/permissions",
dataType: 'json',
quietMillis: 100,
data: function (term, page) { // page is the one-based page number tracked by Select2
return {
q: term, //search term
page_limit: 10, // page size
page: page // page number
};
},
results: function (data, page) {
var more = (page * 10) < data.total; // whether or not there are more results available
// notice we return the value of more so Select2 knows if more results can be loaded
return {results: data.roles, more: more};
}
},
formatResult : function roleFormatResult(role) {
return role.name + ' type: ' + role.type;
},
formatSelection: function roleFormatSelection(role) {
return role.name;
},
initSelection: function(element, callback) {
// the input tag has a value attribute preloaded that points to a preselected role's id
// this function resolves that id attribute to an object that select2 can render
// using its formatResult renderer - that way the role name is shown preselected
var data = [];
$(element.val().split(",")).each(function(i) {
var item = this.split(':');
data.push({
id: item[1],
name: item[1]
});
formatSelection: function roleFormatSelection(role) {
return role.name;
},
initSelection: function(element, callback) {
// the input tag has a value attribute preloaded that points to a preselected role's id
// this function resolves that id attribute to an object that select2 can render
// using its formatResult renderer - that way the role name is shown preselected
var data = [];
$(element.val().split(",")).each(function() {
var item = this.split(':');
data.push({
id: item[1],
name: item[1]
});
});
callback(data);
},
initialData: selected_roles.join(','),
dropdownCssClass: "bigdrop" // apply css that makes the dropdown taller
};
this.accessSelectObject = new mod_select.View(access_select_options);
} else { // Non-admins have select with pre-loaded options
var template = this.templateAccessSelect();
$.get( "/api/libraries/datasets/" + self.id + "/permissions", function( data ) {
$('.access_perm').html(template({options:data.roles}));
this.accessSelectObject = $('#access_select').select2();
}).fail(function() {
mod_toastr.error('An error occurred while fetching data with permissions. :(');
});
callback(data);
},
initialData: 'marten@bx.psu.edu:marten@bx.psu.edu',
dropdownCssClass: "bigdrop" // apply css that makes the dropdown taller
}
}).fail(function(){
mod_toastr.error('An error occurred while fetching data with permissions. :(');
});
// this.access_perm.$el.append($('<option>', {value:"NEWVAL", text: "New Option Text"}));
// this.modify_perm = new mod_select.View({
// css: 'modify_perm',
// placeholder: 'Select a role',
// // onchange : function() {
// // self.model.set('access_perm', self.select_genome.value());
// // },
// data: [{id:'test',text:'testik'}, {id:'dududu', text:'dadada'}],
// container: self.$el.find('#modify_perm'),
// multiple: true
// // value: self.model.get('access_perm')
// });
// this.modify_perm.$el.append($('<option>', {value:"NEWVAL", text: "New Option Text"}));
// this.manage_perm = new mod_select.View({
// css: 'manage_perm',
// placeholder: 'Select a role',
// // onchange : function() {
// // self.model.set('access_perm', self.select_genome.value());
// // },
// data: [{id:'test',text:'testik'}, {id:'dududu', text:'dadada'}],
// container: self.$el.find('#manage_perm'),
// multiple: true
// // value: self.model.get('access_perm')
// });
// this.manage_perm.$el.append($('<option>', {value:"NEWVAL", text: "New Option Text"}));
//TODO add permissions for modification and management of datasets
$("#center [data-toggle]").tooltip();
//hack to show scrollbars
$("#center").css('overflow','auto');
},
comingSoon: function(){
mod_toastr.warning('Feature coming soon');
},
@@ -259,7 +278,7 @@ var LibraryDatasetView = Backbone.View.extend({
tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Download dataset" class="btn btn-default toolbtn-download-dataset primary-button" type="button"><span class="fa fa-download"></span> Download</span></button>');
tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Import dataset into history" class="btn btn-default toolbtn-import-dataset primary-button" type="button"><span class="fa fa-book"></span> to History</span></button>');
tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Modify dataset" class="btn btn-default toolbtn_modify_dataset primary-button" type="button"><span class="fa fa-pencil"></span> Modify</span></button>');
tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Change permissions" class="btn btn-default toolbtn_change_permissions primary-button" type="button"><span class="fa fa-group"></span> Permissions</span></button>');
tmpl_array.push(' <a href="#folders/<%- item.get("folder_id") %>/datasets/<%- item.id %>/permissions"><button data-toggle="tooltip" data-placement="top" title="Change permissions" class="btn btn-default toolbtn_change_permissions primary-button" type="button"><span class="fa fa-group"></span> Permissions</span></button></a>');
tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Share dataset" class="btn btn-default toolbtn-share-dataset primary-button" type="button"><span class="fa fa-share"></span> Share</span></button>');
tmpl_array.push(' </div>');
@@ -481,8 +500,8 @@ var LibraryDatasetView = Backbone.View.extend({
tmpl_array.push('<div class="library_style_container">');
tmpl_array.push(' <div id="library_toolbar">');
tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Cancel modifications" class="btn btn-default toolbtn_cancel_modifications primary-button" type="button"><span class="fa fa-times"></span> Cancel</span></button>');
tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Save modifications" class="btn btn-default toolbtn_save_modifications primary-button" type="button"><span class="fa fa-floppy-o"></span> Save</span></button>');
tmpl_array.push(' <a href="#folders/<%- item.get("folder_id") %>"><button data-toggle="tooltip" data-placement="top" title="Go back to folder" class="btn btn-default primary-button" type="button"><span class="fa fa-folder-open-o"></span> go to Folder</span></button></a>');
tmpl_array.push(' <a href="#folders/<%- item.get("folder_id") %>/datasets/<%- item.id %>"><button data-toggle="tooltip" data-placement="top" title="Go back to dataset" class="btn btn-default primary-button" type="button"><span class="fa fa-file-o"></span> see the Dataset</span></button><a>');
tmpl_array.push(' </div>');
@@ -511,11 +530,16 @@ var LibraryDatasetView = Backbone.View.extend({
tmpl_array.push('<button data-toggle="tooltip" data-placement="top" title="Only you will be able to see the dataset." class="btn btn-default btn-make-private primary-button" type="button"><span class="fa fa-key"></span> Make private</span></button>');
tmpl_array.push('</p>');
tmpl_array.push('<p>You can share this dataset with another Galaxy user. ');
tmpl_array.push('<button data-toggle="tooltip" data-placement="top" title="Only you and the other user will be able to see the dataset." class="btn btn-default btn-share-dataset primary-button" type="button"><span class="fa fa-share"></span> Share</span></button>');
tmpl_array.push('</p>');
tmpl_array.push('<h2>Advanced permissions</h2>');
tmpl_array.push('<p>You can assign any number of roles to any of the following three dataset permissions:</p>');
tmpl_array.push('<p>You can assign any number of roles to any of the following three dataset permission types. However please read carefully the implications of such actions.</p>');
tmpl_array.push('<h3>Access Roles</h3>');
tmpl_array.push('<div class="alert alert-info">User has to have <strong>all these roles</strong> in order to see this dataset.</div>');
tmpl_array.push('<div id="access_perm" class="access_perm roles-selection"></div>');
tmpl_array.push('<button data-toggle="tooltip" data-placement="top" title="Save modifications" class="btn btn-default toolbtn_save_modifications primary-button" type="button"><span class="fa fa-floppy-o"></span> Save</span></button>');
tmpl_array.push('<h3>Modify Roles</h3>');
tmpl_array.push('<div class="alert alert-info">Users with <strong>any</strong> of these roles can modify the information about this dataset.</div>');
tmpl_array.push('<div id="modify_perm" class="modify_perm"></div>');
@@ -532,7 +556,7 @@ var LibraryDatasetView = Backbone.View.extend({
return _.template(tmpl_array.join(''));
},
templateBulkImportInModal : function(){
templateBulkImportInModal: function(){
var tmpl_array = [];
tmpl_array.push('<span id="history_modal_combo_bulk" style="width:90%; margin-left: 1em; margin-right: 1em; ">');
@@ -545,8 +569,22 @@ templateBulkImportInModal : function(){
tmpl_array.push('</span>');
return _.template(tmpl_array.join(''));
}
},
templateAccessSelect: function(){
var tmpl_array = [];
tmpl_array.push('<select id="access_select" multiple>');
tmpl_array.push(' <% _.each(options, function(option) { %>');
tmpl_array.push(' <option value="<%- option.name %>"><%- option.name %></option>');
tmpl_array.push(' <% }); %>');
tmpl_array.push('</select>');
return _.template(tmpl_array.join(''));
}
});
return {
@@ -46,7 +46,7 @@ var FolderRowView = Backbone.View.extend({
},
showDatasetDetails : function(){
this.dataset_view = new mod_library_dataset_view.LibraryDatasetView({id: this.id});
Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: this.id});
},
/**
@@ -520,7 +520,7 @@ var FolderToolbarView = Backbone.View.extend({
tmpl_array.push('<div class="library_style_container">');
// TOOLBAR
tmpl_array.push('<div id="library_toolbar">');
tmpl_array.push('<span data-toggle="tooltip" data-placement="top" class="logged-dataset-manipulation" title="Include deleted datasets" style="display:none;"><input id="include_deleted_datasets_chk" style="margin: 0;" type="checkbox"> <span class="fa fa-trash-o fa-lg"></span></input></span>');
tmpl_array.push('<span data-toggle="tooltip" data-placement="top" class="logged-dataset-manipulation" title="Include deleted datasets" style="display:none;"><input id="include_deleted_datasets_chk" style="margin: 0;" type="checkbox"> include deleted</input></span>');
tmpl_array.push('<div class="btn-group add-library-items" style="display:none;">');
tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Create New Folder" id="toolbtn_create_folder" class="btn btn-default primary-button" type="button"><span class="fa fa-plus"></span> <span class="fa fa-folder"></span></button>');
tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Add Datasets to Current Folder" id="toolbtn_add_files" class="btn btn-default toolbtn_add_files primary-button" type="button"><span class="fa fa-plus"></span> <span class="fa fa-file"></span></span></button>');
@@ -118,7 +118,7 @@ var LibraryToolbarView = Backbone.View.extend({
tmpl_array.push(' <div id="toolbar_form">');
tmpl_array.push(' <% if(admin_user === true) { %>');
tmpl_array.push(' <div id="library_toolbar">');
tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Include deleted libraries"><input id="include_deleted_chk" style="margin: 0;" type="checkbox"> <span class="fa fa-trash-o fa-lg"></span></input></span>');
tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Include deleted libraries"><input id="include_deleted_chk" style="margin: 0;" type="checkbox"> include deleted</input></span>');
tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Create New Library"><button id="create_new_library_btn" class="primary-button btn-xs" type="button"><span class="fa fa-plus"></span> New Library</button><span>');
tmpl_array.push(' </div>');
tmpl_array.push(' <% } %>');
+1
View File
@@ -17,6 +17,7 @@ var View = Backbone.View.extend(
value : null,
multiple : false,
minimumInputLength : 0,
// example format of initial data: "id:name,55:anotherrole@role.com,27:role@role.com"
initialData : ''
},
+1 -1
View File
@@ -1 +1 @@
define(["galaxy.masthead","utils/utils","libs/toastr","mvc/base-mvc","mvc/library/library-model","mvc/library/library-folderlist-view","mvc/library/library-librarylist-view","mvc/library/library-librarytoolbar-view","mvc/library/library-foldertoolbar-view","mvc/library/library-dataset-view"],function(f,c,h,l,i,a,g,e,j,d){var m=Backbone.Router.extend({initialize:function(){this.routesHit=0;Backbone.history.on("route",function(){this.routesHit++},this)},routes:{"":"libraries","folders/:id":"folder_content","folders/:folder_id/datasets/:dataset_id":"dataset_detail","folders/:folder_id/datasets/:dataset_id/permissions":"dataset_permissions","folders/:folder_id/download/:format":"download"},back:function(){if(this.routesHit>1){window.history.back()}else{this.navigate("#",{trigger:true,replace:true})}}});var k=l.SessionStorageModel.extend({defaults:{with_deleted:false,sort_order:"asc",sort_by:"name"}});var b=Backbone.View.extend({libraryToolbarView:null,libraryListView:null,library_router:null,folderToolbarView:null,folderListView:null,initialize:function(){Galaxy.libraries=this;this.preferences=new k({id:"global-lib-prefs"});this.library_router=new m();this.library_router.on("route:libraries",function(){Galaxy.libraries.libraryToolbarView=new e.LibraryToolbarView();Galaxy.libraries.libraryListView=new g.LibraryListView()});this.library_router.on("route:folder_content",function(n){if(Galaxy.libraries.folderToolbarView){Galaxy.libraries.folderToolbarView.$el.unbind("click")}Galaxy.libraries.folderToolbarView=new j.FolderToolbarView({id:n});Galaxy.libraries.folderListView=new a.FolderListView({id:n})});this.library_router.on("route:download",function(n,o){if($("#folder_list_body").find(":checked").length===0){h.info("You have to select some datasets to download");Galaxy.libraries.library_router.navigate("folders/"+n,{trigger:true,replace:true})}else{Galaxy.libraries.folderToolbarView.download(n,o);Galaxy.libraries.library_router.navigate("folders/"+n,{trigger:false,replace:true})}});this.library_router.on("route:dataset_detail",function(o,n){new d.LibraryDatasetView({id:n})});this.library_router.on("route:dataset_permissions",function(o,n){new d.LibraryDatasetView({id:n,show_permissions:true})});Backbone.history.start({pushState:false})}});return{GalaxyApp:b}});
define(["galaxy.masthead","utils/utils","libs/toastr","mvc/base-mvc","mvc/library/library-model","mvc/library/library-folderlist-view","mvc/library/library-librarylist-view","mvc/library/library-librarytoolbar-view","mvc/library/library-foldertoolbar-view","mvc/library/library-dataset-view"],function(f,c,h,l,i,a,g,e,j,d){var m=Backbone.Router.extend({initialize:function(){this.routesHit=0;Backbone.history.on("route",function(){this.routesHit++},this)},routes:{"":"libraries","folders/:id":"folder_content","folders/:folder_id/datasets/:dataset_id":"dataset_detail","folders/:folder_id/datasets/:dataset_id/permissions":"dataset_permissions","folders/:folder_id/download/:format":"download"},back:function(){if(this.routesHit>1){window.history.back()}else{this.navigate("#",{trigger:true,replace:true})}}});var k=l.SessionStorageModel.extend({defaults:{with_deleted:false,sort_order:"asc",sort_by:"name"}});var b=Backbone.View.extend({libraryToolbarView:null,libraryListView:null,library_router:null,folderToolbarView:null,folderListView:null,datasetView:null,initialize:function(){Galaxy.libraries=this;this.preferences=new k({id:"global-lib-prefs"});this.library_router=new m();this.library_router.on("route:libraries",function(){Galaxy.libraries.libraryToolbarView=new e.LibraryToolbarView();Galaxy.libraries.libraryListView=new g.LibraryListView()});this.library_router.on("route:folder_content",function(n){if(Galaxy.libraries.folderToolbarView){Galaxy.libraries.folderToolbarView.$el.unbind("click")}Galaxy.libraries.folderToolbarView=new j.FolderToolbarView({id:n});Galaxy.libraries.folderListView=new a.FolderListView({id:n})});this.library_router.on("route:download",function(n,o){if($("#folder_list_body").find(":checked").length===0){h.info("You have to select some datasets to download");Galaxy.libraries.library_router.navigate("folders/"+n,{trigger:true,replace:true})}else{Galaxy.libraries.folderToolbarView.download(n,o);Galaxy.libraries.library_router.navigate("folders/"+n,{trigger:false,replace:true})}});this.library_router.on("route:dataset_detail",function(o,n){if(Galaxy.libraries.datasetView){Galaxy.libraries.datasetView.$el.unbind("click")}Galaxy.libraries.datasetView=new d.LibraryDatasetView({id:n})});this.library_router.on("route:dataset_permissions",function(o,n){if(Galaxy.libraries.datasetView){Galaxy.libraries.datasetView.$el.unbind("click")}Galaxy.libraries.datasetView=new d.LibraryDatasetView({id:n,show_permissions:true})});Backbone.history.start({pushState:false})}});return{GalaxyApp:b}});
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
define(["libs/toastr","mvc/library/library-model"],function(b,a){var c=Backbone.View.extend({el:"#center",events:{"click #create_new_library_btn":"show_library_modal","click #include_deleted_chk":"check_include_deleted"},initialize:function(){this.render()},render:function(){var f=this.templateToolBar();var e=false;var d=true;if(Galaxy.currUser){e=Galaxy.currUser.isAdmin();d=Galaxy.currUser.isAnonymous()}this.$el.html(f({admin_user:e,anon_user:d}));if(e){this.$el.find("#include_deleted_chk")[0].checked=Galaxy.libraries.preferences.get("with_deleted")}},show_library_modal:function(e){e.preventDefault();e.stopPropagation();var d=this;this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Library",body:this.templateNewLibraryInModal(),buttons:{Create:function(){d.create_new_library_event()},Close:function(){d.modal.hide()}}})},create_new_library_event:function(){var f=this.serialize_new_library();if(this.validate_new_library(f)){var e=new a.Library();var d=this;e.save(f,{success:function(g){Galaxy.libraries.libraryListView.collection.add(g);d.modal.hide();d.clear_library_modal();Galaxy.libraries.libraryListView.render();b.success("Library created")},error:function(h,g){if(typeof g.responseJSON!=="undefined"){b.error(g.responseJSON.err_msg)}else{b.error("An error occured :(")}}})}else{b.error("Library's name is missing")}return false},clear_library_modal:function(){$("input[name='Name']").val("");$("input[name='Description']").val("");$("input[name='Synopsis']").val("")},serialize_new_library:function(){return{name:$("input[name='Name']").val(),description:$("input[name='Description']").val(),synopsis:$("input[name='Synopsis']").val()}},validate_new_library:function(d){return d.name!==""},check_include_deleted:function(d){if(d.target.checked){Galaxy.libraries.preferences.set({with_deleted:true});Galaxy.libraries.libraryListView.render()}else{Galaxy.libraries.preferences.set({with_deleted:false});Galaxy.libraries.libraryListView.render()}},templateToolBar:function(){tmpl_array=[];tmpl_array.push('<div class="library_style_container">');tmpl_array.push(' <div id="toolbar_form">');tmpl_array.push(" <% if(admin_user === true) { %>");tmpl_array.push(' <div id="library_toolbar">');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Include deleted libraries"><input id="include_deleted_chk" style="margin: 0;" type="checkbox"> <span class="fa fa-trash-o fa-lg"></span></input></span>');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Create New Library"><button id="create_new_library_btn" class="primary-button btn-xs" type="button"><span class="fa fa-plus"></span> New Library</button><span>');tmpl_array.push(" </div>");tmpl_array.push(" <% } %>");tmpl_array.push(" </div>");tmpl_array.push(' <div id="libraries_element">');tmpl_array.push(" </div>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))},templateNewLibraryInModal:function(){tmpl_array=[];tmpl_array.push('<div id="new_library_modal">');tmpl_array.push(" <form>");tmpl_array.push(' <input type="text" name="Name" value="" placeholder="Name">');tmpl_array.push(' <input type="text" name="Description" value="" placeholder="Description">');tmpl_array.push(' <input type="text" name="Synopsis" value="" placeholder="Synopsis">');tmpl_array.push(" </form>");tmpl_array.push("</div>");return tmpl_array.join("")}});return{LibraryToolbarView:c}});
define(["libs/toastr","mvc/library/library-model"],function(b,a){var c=Backbone.View.extend({el:"#center",events:{"click #create_new_library_btn":"show_library_modal","click #include_deleted_chk":"check_include_deleted"},initialize:function(){this.render()},render:function(){var f=this.templateToolBar();var e=false;var d=true;if(Galaxy.currUser){e=Galaxy.currUser.isAdmin();d=Galaxy.currUser.isAnonymous()}this.$el.html(f({admin_user:e,anon_user:d}));if(e){this.$el.find("#include_deleted_chk")[0].checked=Galaxy.libraries.preferences.get("with_deleted")}},show_library_modal:function(e){e.preventDefault();e.stopPropagation();var d=this;this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Library",body:this.templateNewLibraryInModal(),buttons:{Create:function(){d.create_new_library_event()},Close:function(){d.modal.hide()}}})},create_new_library_event:function(){var f=this.serialize_new_library();if(this.validate_new_library(f)){var e=new a.Library();var d=this;e.save(f,{success:function(g){Galaxy.libraries.libraryListView.collection.add(g);d.modal.hide();d.clear_library_modal();Galaxy.libraries.libraryListView.render();b.success("Library created")},error:function(h,g){if(typeof g.responseJSON!=="undefined"){b.error(g.responseJSON.err_msg)}else{b.error("An error occured :(")}}})}else{b.error("Library's name is missing")}return false},clear_library_modal:function(){$("input[name='Name']").val("");$("input[name='Description']").val("");$("input[name='Synopsis']").val("")},serialize_new_library:function(){return{name:$("input[name='Name']").val(),description:$("input[name='Description']").val(),synopsis:$("input[name='Synopsis']").val()}},validate_new_library:function(d){return d.name!==""},check_include_deleted:function(d){if(d.target.checked){Galaxy.libraries.preferences.set({with_deleted:true});Galaxy.libraries.libraryListView.render()}else{Galaxy.libraries.preferences.set({with_deleted:false});Galaxy.libraries.libraryListView.render()}},templateToolBar:function(){tmpl_array=[];tmpl_array.push('<div class="library_style_container">');tmpl_array.push(' <div id="toolbar_form">');tmpl_array.push(" <% if(admin_user === true) { %>");tmpl_array.push(' <div id="library_toolbar">');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Include deleted libraries"><input id="include_deleted_chk" style="margin: 0;" type="checkbox"> include deleted</input></span>');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Create New Library"><button id="create_new_library_btn" class="primary-button btn-xs" type="button"><span class="fa fa-plus"></span> New Library</button><span>');tmpl_array.push(" </div>");tmpl_array.push(" <% } %>");tmpl_array.push(" </div>");tmpl_array.push(' <div id="libraries_element">');tmpl_array.push(" </div>");tmpl_array.push("</div>");return _.template(tmpl_array.join(""))},templateNewLibraryInModal:function(){tmpl_array=[];tmpl_array.push('<div id="new_library_modal">');tmpl_array.push(" <form>");tmpl_array.push(' <input type="text" name="Name" value="" placeholder="Name">');tmpl_array.push(' <input type="text" name="Description" value="" placeholder="Description">');tmpl_array.push(' <input type="text" name="Synopsis" value="" placeholder="Synopsis">');tmpl_array.push(" </form>");tmpl_array.push("</div>");return tmpl_array.join("")}});return{LibraryToolbarView:c}});