1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/3c169a33c510/ Changeset: 3c169a33c510 User: martenson Date: 2014-04-02 23:18:51 Summary: libraries: more refactoring fun; full UI for permissions handling; repainting from cache should be ready for stable Affected #: 4 files
diff -r 1344876d770a4441864bc58e33e50eba860ef7b3 -r 3c169a33c5107c242d7cc455cce8b30d17437894 static/scripts/mvc/library/library-librarylist-view.js --- a/static/scripts/mvc/library/library-librarylist-view.js +++ b/static/scripts/mvc/library/library-librarylist-view.js @@ -18,11 +18,6 @@ el: '#libraries_element',
events: { - 'click .edit_library_btn' : 'edit_button_event', - 'click .save_library_btn' : 'save_library_modification', - 'click .cancel_library_btn' : 'cancel_library_modification', - 'click .delete_library_btn' : 'delete_library', - 'click .undelete_library_btn' : 'undelete_library', 'click .sort-libraries-link' : 'sort_clicked' },
@@ -90,7 +85,8 @@ for (var i = 0; i < libraries_to_render.length; i++) { var library = libraries_to_render[i]; var cachedView = _.findWhere(this.rowViews, {id: library.get('id')}); - if (cachedView !== undefined){ + if (cachedView !== undefined && this instanceof Backbone.View){ + cachedView.delegateEvents(); this.$el.find('#library_list_body').append(cachedView.el); } else { var rowView = new mod_library_libraryrow_view.LibraryRowView(library); @@ -101,18 +97,6 @@ }; },
- /** Handle the user toggling the deleted visibility by: - * (1) storing the new value in the persistent storage - * (2) re-rendering the list - * @returns {Boolean} new show_hidden setting - */ - // toggleShowHidden : function( show ){ - // show = ( show !== undefined )?( show ):( !this.storage.get( 'show_hidden' ) ); - // this.storage.set( 'show_hidden', show ); - // this.renderRows(); - // return this.storage.get( 'show_hidden' ); - // }, - sort_clicked : function(){ if (Galaxy.libraries.preferences.get('sort_order') === 'asc'){ this.sortLibraries('name','desc'); @@ -145,7 +129,6 @@ } this.collection.sort(); } - },
// MMMMMMMMMMMMMMMMMM @@ -175,7 +158,6 @@
return _.template(tmpl_array.join('')); }, -
templateNewLibraryInModal: function(){ tmpl_array = []; @@ -191,153 +173,6 @@ return tmpl_array.join(''); },
- save_library_modification: function(event){ - var $library_row = $(event.target).closest('tr'); - var library = this.collection.get($library_row.data('id')); - - var is_changed = false; - - var new_name = $library_row.find('.input_library_name').val(); - if (typeof new_name !== 'undefined' && new_name !== library.get('name') ){ - if (new_name.length > 2){ - library.set("name", new_name); - is_changed = true; - } else{ - mod_toastr.warning('Library name has to be at least 3 characters long'); - return - } - } - - var new_description = $library_row.find('.input_library_description').val(); - if (typeof new_description !== 'undefined' && new_description !== library.get('description') ){ - library.set("description", new_description); - is_changed = true; - } - - var new_synopsis = $library_row.find('.input_library_synopsis').val(); - if (typeof new_synopsis !== 'undefined' && new_synopsis !== library.get('synopsis') ){ - library.set("synopsis", new_synopsis); - is_changed = true; - } - - if (is_changed){ - library.save(null, { - patch: true, - success: function(library) { - mod_toastr.success('Changes to library saved'); - Galaxy.libraries.libraryListView.toggle_library_modification($library_row); - }, - error: function(model, response){ - mod_toastr.error('An error occured during updating the library :('); - } - }); - } - }, - - edit_button_event: function(event){ - this.toggle_library_modification($(event.target).closest('tr')); - }, - - toggle_library_modification: function($library_row){ - var library = this.collection.get($library_row.data('id')); - - $library_row.find('.public_lib_ico').toggle(); - $library_row.find('.deleted_lib_ico').toggle(); - $library_row.find('.edit_library_btn').toggle(); - $library_row.find('.upload_library_btn').toggle(); - $library_row.find('.permission_library_btn').toggle(); - $library_row.find('.save_library_btn').toggle(); - $library_row.find('.cancel_library_btn').toggle(); - if (library.get('deleted')){ - // $library_row.find('.undelete_library_btn').toggle(); - } else { - $library_row.find('.delete_library_btn').toggle(); - } - - if ($library_row.find('.edit_library_btn').is(':hidden')){ - // library name - var current_library_name = library.get('name'); - var new_html = '<input type="text" class="form-control input_library_name" placeholder="name">'; - $library_row.children('td').eq(0).html(new_html); - if (typeof current_library_name !== undefined){ - $library_row.find('.input_library_name').val(current_library_name); - } - // library description - var current_library_description = library.get('description'); - var new_html = '<input type="text" class="form-control input_library_description" placeholder="description">'; - $library_row.children('td').eq(1).html(new_html); - if (typeof current_library_description !== undefined){ - $library_row.find('.input_library_description').val(current_library_description); - } - // library synopsis - var current_library_synopsis = library.get('synopsis'); - var new_html = '<input type="text" class="form-control input_library_synopsis" placeholder="synopsis">'; - $library_row.children('td').eq(2).html(new_html); - if (typeof current_library_synopsis !== undefined){ - $library_row.find('.input_library_synopsis').val(current_library_synopsis); - } - } else { - // missing ICON + LINK....needs refactoring to separate view - $library_row.children('td').eq(0).html(library.get('name')); - $library_row.children('td').eq(1).html(library.get('description')); - $library_row.children('td').eq(2).html(library.get('synopsis')); - } - - }, - - cancel_library_modification: function(event){ - var $library_row = $(event.target).closest('tr'); - var library = this.collection.get($library_row.data('id')); - this.toggle_library_modification($library_row); - - $library_row.children('td').eq(0).html(library.get('name')); - $library_row.children('td').eq(1).html(library.get('description')); - $library_row.children('td').eq(2).html(library.get('synopsis')); - }, - - undelete_library: function(event){ - var $library_row = $(event.target).closest('tr'); - var library = this.collection.get($library_row.data('id')); - this.toggle_library_modification($library_row); - - // mark the library undeleted - library.url = library.urlRoot + library.id + '?undelete=true'; - library.destroy({ - success: function (library) { - // add the newly undeleted library back to the collection - // backbone does not accept changes through destroy, so update it too - library.set('deleted', false); - Galaxy.libraries.libraryListView.collection.add(library); - $library_row.removeClass('active'); - mod_toastr.success('Library has been undeleted'); - }, - error: function(){ - mod_toastr.error('An error occured while undeleting the library :('); - } - }); - }, - - delete_library: function(event){ - var $library_row = $(event.target).closest('tr'); - var library = this.collection.get($library_row.data('id')); - this.toggle_library_modification($library_row); - - // mark the library deleted - library.destroy({ - success: function (library) { - // add the new deleted library back to the collection - $library_row.remove(); - library.set('deleted', true); - Galaxy.libraries.libraryListView.collection.add(library); - mod_toastr.success('Library has been marked deleted'); - }, - error: function(){ - mod_toastr.error('An error occured during deleting the library :('); - } - }); - - }, - redirectToHome: function(){ window.location = '../'; },
diff -r 1344876d770a4441864bc58e33e50eba860ef7b3 -r 3c169a33c5107c242d7cc455cce8b30d17437894 static/scripts/mvc/library/library-libraryrow-view.js --- a/static/scripts/mvc/library/library-libraryrow-view.js +++ b/static/scripts/mvc/library/library-libraryrow-view.js @@ -11,6 +11,17 @@
// galaxy library row view var LibraryRowView = Backbone.View.extend({ + events: { + 'click .edit_library_btn' : 'edit_button_clicked', + 'click .cancel_library_btn' : 'cancel_library_modification', + 'click .save_library_btn' : 'save_library_modification', + 'click .delete_library_btn' : 'delete_library', + 'click .undelete_library_btn' : 'undelete_library', + 'click .upload_library_btn' : 'upload_to_library', + 'click .permission_library_btn' : 'permissions_on_library' + }, + + edit_mode: false,
element_visibility_config: { upload_library_btn: false, @@ -27,42 +38,243 @@ },
render: function(library){ + if (typeof library === 'undefined'){ + var library = Galaxy.libraries.libraryListView.collection.get(this.$el.data('id')); + } + this.prepareButtons(library); var tmpl = this.templateRow(); - this.prepareButtons(library); - this.setElement(tmpl({library:library, button_config: this.element_visibility_config})); + this.setElement(tmpl({library:library, button_config: this.element_visibility_config, edit_mode: this.edit_mode})); this.$el.show(); - // this.set_up_visual_features(library); + return this; + }, + + repaint: function(library){ + /* need to hide manually because of the element removal in setElement + invoked in render() */ + $(".tooltip").hide(); + /* we need to store the old element to be able to replace it with + new one */ + var old_element = this.$el; + /* if user canceled the library param is undefined, + if user saved and succeeded the updated library is rendered */ + this.render(library); + old_element.replaceWith(this.$el); + /* now we attach new tooltips to the newly created row element */ + this.$el.find("[data-toggle]").tooltip(); },
prepareButtons: function(library){ - if (library.get('deleted') === true ){ - if (Galaxy.currUser.isAdmin()){ - this.element_visibility_config.undelete_library_btn = true; - this.element_visibility_config.upload_library_btn = false; - this.element_visibility_config.edit_library_btn = false; - this.element_visibility_config.permission_library_btn = false; + vis_config = this.element_visibility_config; + + if (this.edit_mode === false){ + vis_config.save_library_btn = false; + vis_config.cancel_library_btn = false; + vis_config.delete_library_btn = false; + if (library.get('deleted') === true ){ + // if (Galaxy.currUser.isAdmin()){ + vis_config.undelete_library_btn = true; + vis_config.upload_library_btn = false; + vis_config.edit_library_btn = false; + vis_config.permission_library_btn = false; + // } + } else if (library.get('deleted') === false ) { + vis_config.save_library_btn = false; + vis_config.cancel_library_btn = false; + vis_config.undelete_library_btn = false; + if (library.get('can_user_add') === true){ + vis_config.upload_library_btn = true; + } + if (library.get('can_user_modify') === true){ + vis_config.edit_library_btn = true; + } + if (library.get('can_user_manage') === true){ + vis_config.permission_library_btn = true; + } } - } else if (library.get('deleted') === false ) { - this.element_visibility_config.undelete_library_btn = false; - if (library.get('can_user_add') === true){ - this.element_visibility_config.upload_library_btn = true; - } - if (library.get('can_user_modify') === true){ - this.element_visibility_config.edit_library_btn = true; - } - if (library.get('can_user_manage') === true){ - this.element_visibility_config.permission_library_btn = true; - } + } else if (this.edit_mode === true){ + vis_config.upload_library_btn = false; + vis_config.edit_library_btn = false; + vis_config.permission_library_btn = false; + vis_config.save_library_btn = true; + vis_config.cancel_library_btn = true; + vis_config.delete_library_btn = true; } + + this.element_visibility_config = vis_config; + }, + + upload_to_library: function(){ + mod_toastr.info('Coming soon. Stay tuned.'); + }, + + permissions_on_library: function(){ + mod_toastr.info('Coming soon. Stay tuned.'); + }, + + /* User clicked the 'edit' button on row so we render a new row + that allows editing */ + edit_button_clicked: function(){ + this.edit_mode = true; + this.repaint(); + }, + + /* User clicked the 'cancel' button so we render normal rowView */ + cancel_library_modification: function(){ + mod_toastr.info('Modifications canceled'); + this.edit_mode = false; + this.repaint(); + }, + + save_library_modification: function(){ + var library = Galaxy.libraries.libraryListView.collection.get(this.$el.data('id')); + var is_changed = false; + + var new_name = this.$el.find('.input_library_name').val(); + if (typeof new_name !== 'undefined' && new_name !== library.get('name') ){ + if (new_name.length > 2){ + library.set("name", new_name); + is_changed = true; + } else{ + mod_toastr.warning('Library name has to be at least 3 characters long'); + return + } + } + + var new_description = this.$el.find('.input_library_description').val(); + if (typeof new_description !== 'undefined' && new_description !== library.get('description') ){ + library.set("description", new_description); + is_changed = true; + } + + var new_synopsis = this.$el.find('.input_library_synopsis').val(); + if (typeof new_synopsis !== 'undefined' && new_synopsis !== library.get('synopsis') ){ + library.set("synopsis", new_synopsis); + is_changed = true; + } + + if (is_changed){ + var row_view = this; + library.save(null, { + patch: true, + success: function(library) { + row_view.edit_mode = false; + row_view.repaint(library); + mod_toastr.success('Changes to library saved'); + }, + error: function(model, response){ + mod_toastr.error('An error occured during updating the library :('); + } + }); + } else { + this.edit_mode = false; + this.repaint(library); + mod_toastr.info('Nothing has changed'); + } + }, + + delete_library: function(){ + var library = Galaxy.libraries.libraryListView.collection.get(this.$el.data('id')); + var row_view = this; + // mark the library deleted + library.destroy({ + success: function (library) { + library.set('deleted', true); + // add the new deleted library back to the collection (Galaxy specialty) + Galaxy.libraries.libraryListView.collection.add(library); + row_view.edit_mode = false; + if (Galaxy.libraries.preferences.get('with_deleted') === false){ + $(".tooltip").hide(); + row_view.$el.remove(); + } else if (Galaxy.libraries.preferences.get('with_deleted') === true){ + row_view.repaint(library); + } + mod_toastr.success('Library has been marked deleted'); + }, + error: function(){ + mod_toastr.error('An error occured during deleting the library :('); + } + }); + }, + + undelete_library: function(){ + var library = Galaxy.libraries.libraryListView.collection.get(this.$el.data('id')); + var row_view = this; + + // mark the library undeleted + library.url = library.urlRoot + library.id + '?undelete=true'; + library.destroy({ + success: function (library) { + // add the newly undeleted library back to the collection + // backbone does not accept changes through destroy, so update it too + library.set('deleted', false); + Galaxy.libraries.libraryListView.collection.add(library); + row_view.edit_mode = false; + row_view.repaint(library); + mod_toastr.success('Library has been undeleted'); + }, + error: function(){ + mod_toastr.error('An error occured while undeleting the library :('); + } + }); + }, + + toggle_library_modification: function($library_row){ + var library = this.collection.get($library_row.data('id')); + + $library_row.find('.public_lib_ico').toggle(); + $library_row.find('.deleted_lib_ico').toggle(); + $library_row.find('.edit_library_btn').toggle(); + $library_row.find('.upload_library_btn').toggle(); + $library_row.find('.permission_library_btn').toggle(); + $library_row.find('.save_library_btn').toggle(); + $library_row.find('.cancel_library_btn').toggle(); + if (library.get('deleted')){ + } else { + $library_row.find('.delete_library_btn').toggle(); + } + + if ($library_row.find('.edit_library_btn').is(':hidden')){ + // library name + var current_library_name = library.get('name'); + var new_html = '<input type="text" class="form-control input_library_name" placeholder="name">'; + $library_row.children('td').eq(0).html(new_html); + if (typeof current_library_name !== undefined){ + $library_row.find('.input_library_name').val(current_library_name); + } + // library description + var current_library_description = library.get('description'); + var new_html = '<input type="text" class="form-control input_library_description" placeholder="description">'; + $library_row.children('td').eq(1).html(new_html); + if (typeof current_library_description !== undefined){ + $library_row.find('.input_library_description').val(current_library_description); + } + // library synopsis + var current_library_synopsis = library.get('synopsis'); + var new_html = '<input type="text" class="form-control input_library_synopsis" placeholder="synopsis">'; + $library_row.children('td').eq(2).html(new_html); + if (typeof current_library_synopsis !== undefined){ + $library_row.find('.input_library_synopsis').val(current_library_synopsis); + } + } else { + $library_row.children('td').eq(0).html(library.get('name')); + $library_row.children('td').eq(1).html(library.get('description')); + $library_row.children('td').eq(2).html(library.get('synopsis')); + } },
templateRow: function() { tmpl_array = [];
tmpl_array.push(' <tr class="<% if(library.get("deleted") === true) { print("active") } %>" style="display:none;" data-id="<%- library.get("id") %>">'); - tmpl_array.push(' <td><a href="#folders/<%- library.get("root_folder_id") %>"><%- library.get("name") %></a></td>'); - tmpl_array.push(' <td><%= _.escape(library.get("description")) %></td>'); - tmpl_array.push(' <td><%= _.escape(library.get("synopsis")) %></td>'); + tmpl_array.push(' <% if(!edit_mode) { %>'); + tmpl_array.push(' <td><a href="#folders/<%- library.get("root_folder_id") %>"><%- library.get("name") %></a></td>'); + tmpl_array.push(' <td><%= _.escape(library.get("description")) %></td>'); + tmpl_array.push(' <td><%= _.escape(library.get("synopsis")) %></td>'); + tmpl_array.push(' <% } else if(edit_mode){ %>'); + tmpl_array.push(' <td><input type="text" class="form-control input_library_name" placeholder="name" value="<%- library.get("name") %>"></td>'); + tmpl_array.push(' <td><input type="text" class="form-control input_library_description" placeholder="description" value="<%- library.get("description") %>"></td>'); + tmpl_array.push(' <td><input type="text" class="form-control input_library_synopsis" placeholder="synopsis" value="<%- library.get("synopsis") %>"></td>'); + tmpl_array.push(' <% } %>'); tmpl_array.push(' <td class="right-center">'); tmpl_array.push(' <% if(library.get("deleted") === true) { %>'); tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Marked deleted" style="color:grey;" class="fa fa-ban fa-lg deleted_lib_ico"></span>');
diff -r 1344876d770a4441864bc58e33e50eba860ef7b3 -r 3c169a33c5107c242d7cc455cce8b30d17437894 static/scripts/packed/mvc/library/library-librarylist-view.js --- a/static/scripts/packed/mvc/library/library-librarylist-view.js +++ b/static/scripts/packed/mvc/library/library-librarylist-view.js @@ -1,1 +1,1 @@ -define(["galaxy.masthead","mvc/base-mvc","utils/utils","libs/toastr","mvc/library/library-model","mvc/library/library-libraryrow-view"],function(b,g,d,e,c,a){var f=Backbone.View.extend({el:"#libraries_element",events:{"click .edit_library_btn":"edit_button_event","click .save_library_btn":"save_library_modification","click .cancel_library_btn":"cancel_library_modification","click .delete_library_btn":"delete_library","click .undelete_library_btn":"undelete_library","click .sort-libraries-link":"sort_clicked"},modal:null,collection:null,rowViews:{},initialize:function(){var h=this;this.rowViews={};this.collection=new c.Libraries();this.collection.fetch({success:function(i){h.render()},error:function(j,i){e.error("An error occured. Please try again.")}})},render:function(i){var j=this.templateLibraryList();var k=null;var h=true;var h=Galaxy.libraries.preferences.get("with_deleted");var l=null;if(typeof i!=="undefined"){h=typeof i.with_deleted!=="undefined"?i.with_deleted:false;l=typeof i.models!=="undefined"?i.models:null}if(this.collection!==null&&l===null){if(h){k=this.collection.models}else{k=this.collection.where({deleted:false})}}else{if(l!==null){k=l}else{k=[]}}this.$el.html(j({length:k.length,order:Galaxy.libraries.preferences.get("sort_order")}));this.renderRows(k);$("#center [data-toggle]").tooltip();$("#center").css("overflow","auto")},renderRows:function(m){for(var l=0;l<m.length;l++){var k=m[l];var j=_.findWhere(this.rowViews,{id:k.get("id")});if(j!==undefined){this.$el.find("#library_list_body").append(j.el)}else{var h=new a.LibraryRowView(k);this.$el.find("#library_list_body").append(h.el);this.rowViews[k.get("id")]=h}}},sort_clicked:function(){if(Galaxy.libraries.preferences.get("sort_order")==="asc"){this.sortLibraries("name","desc");Galaxy.libraries.preferences.set({sort_order:"desc"})}else{this.sortLibraries("name","asc");Galaxy.libraries.preferences.set({sort_order:"asc"})}this.render()},sortLibraries:function(i,h){if(i==="name"){if(h==="asc"){this.collection.comparator=function(k,j){if(k.get("name").toLowerCase()>j.get("name").toLowerCase()){return 1}if(j.get("name").toLowerCase()>k.get("name").toLowerCase()){return -1}return 0}}else{if(h==="desc"){this.collection.comparator=function(k,j){if(k.get("name").toLowerCase()>j.get("name").toLowerCase()){return -1}if(j.get("name").toLowerCase()>k.get("name").toLowerCase()){return 1}return 0}}}this.collection.sort()}},templateLibraryList:function(){tmpl_array=[];tmpl_array.push('<div class="library_container table-responsive">');tmpl_array.push("<% if(length === 0) { %>");tmpl_array.push("<div>I see no libraries. Why don't you create one?</div>");tmpl_array.push("<% } else{ %>");tmpl_array.push('<table class="grid table table-condensed">');tmpl_array.push(" <thead>");tmpl_array.push(' <th style="width:30%;"><a class="sort-libraries-link" title="Click to reverse order" href="#">name</a><span title="Sorted alphabetically" class="fa fa-sort-alpha-<%- order %>"></span></th>');tmpl_array.push(' <th style="width:22%;">description</th>');tmpl_array.push(' <th style="width:22%;">synopsis</th> ');tmpl_array.push(' <th style="width:26%;"></th> ');tmpl_array.push(" </thead>");tmpl_array.push(' <tbody id="library_list_body">');tmpl_array.push(" </tbody>");tmpl_array.push("</table>");tmpl_array.push("<% }%>");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("")},save_library_modification:function(k){var j=$(k.target).closest("tr");var h=this.collection.get(j.data("id"));var i=false;var m=j.find(".input_library_name").val();if(typeof m!=="undefined"&&m!==h.get("name")){if(m.length>2){h.set("name",m);i=true}else{e.warning("Library name has to be at least 3 characters long");return}}var l=j.find(".input_library_description").val();if(typeof l!=="undefined"&&l!==h.get("description")){h.set("description",l);i=true}var n=j.find(".input_library_synopsis").val();if(typeof n!=="undefined"&&n!==h.get("synopsis")){h.set("synopsis",n);i=true}if(i){h.save(null,{patch:true,success:function(o){e.success("Changes to library saved");Galaxy.libraries.libraryListView.toggle_library_modification(j)},error:function(p,o){e.error("An error occured during updating the library :(")}})}},edit_button_event:function(h){this.toggle_library_modification($(h.target).closest("tr"))},toggle_library_modification:function(k){var h=this.collection.get(k.data("id"));k.find(".public_lib_ico").toggle();k.find(".deleted_lib_ico").toggle();k.find(".edit_library_btn").toggle();k.find(".upload_library_btn").toggle();k.find(".permission_library_btn").toggle();k.find(".save_library_btn").toggle();k.find(".cancel_library_btn").toggle();if(h.get("deleted")){}else{k.find(".delete_library_btn").toggle()}if(k.find(".edit_library_btn").is(":hidden")){var i=h.get("name");var m='<input type="text" class="form-control input_library_name" placeholder="name">';k.children("td").eq(0).html(m);if(typeof i!==undefined){k.find(".input_library_name").val(i)}var j=h.get("description");var m='<input type="text" class="form-control input_library_description" placeholder="description">';k.children("td").eq(1).html(m);if(typeof j!==undefined){k.find(".input_library_description").val(j)}var l=h.get("synopsis");var m='<input type="text" class="form-control input_library_synopsis" placeholder="synopsis">';k.children("td").eq(2).html(m);if(typeof l!==undefined){k.find(".input_library_synopsis").val(l)}}else{k.children("td").eq(0).html(h.get("name"));k.children("td").eq(1).html(h.get("description"));k.children("td").eq(2).html(h.get("synopsis"))}},cancel_library_modification:function(j){var i=$(j.target).closest("tr");var h=this.collection.get(i.data("id"));this.toggle_library_modification(i);i.children("td").eq(0).html(h.get("name"));i.children("td").eq(1).html(h.get("description"));i.children("td").eq(2).html(h.get("synopsis"))},undelete_library:function(j){var i=$(j.target).closest("tr");var h=this.collection.get(i.data("id"));this.toggle_library_modification(i);h.url=h.urlRoot+h.id+"?undelete=true";h.destroy({success:function(k){k.set("deleted",false);Galaxy.libraries.libraryListView.collection.add(k);i.removeClass("active");e.success("Library has been undeleted")},error:function(){e.error("An error occured while undeleting the library :(")}})},delete_library:function(j){var i=$(j.target).closest("tr");var h=this.collection.get(i.data("id"));this.toggle_library_modification(i);h.destroy({success:function(k){i.remove();k.set("deleted",true);Galaxy.libraries.libraryListView.collection.add(k);e.success("Library has been marked deleted")},error:function(){e.error("An error occured during deleting the library :(")}})},redirectToHome:function(){window.location="../"},redirectToLogin:function(){window.location="/user/login"},show_library_modal:function(i){i.preventDefault();i.stopPropagation();var h=this;this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Library",body:this.templateNewLibraryInModal(),buttons:{Create:function(){h.create_new_library_event()},Close:function(){h.modal.hide()}}})},create_new_library_event:function(){var j=this.serialize_new_library();if(this.validate_new_library(j)){var i=new c.Library();var h=this;i.save(j,{success:function(k){h.collection.add(k);h.modal.hide();h.clear_library_modal();h.render();e.success("Library created")},error:function(){e.error("An error occured :(")}})}else{e.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(h){return h.name!==""}});return{LibraryListView:f}}); \ No newline at end of file +define(["galaxy.masthead","mvc/base-mvc","utils/utils","libs/toastr","mvc/library/library-model","mvc/library/library-libraryrow-view"],function(b,g,d,e,c,a){var f=Backbone.View.extend({el:"#libraries_element",events:{"click .sort-libraries-link":"sort_clicked"},modal:null,collection:null,rowViews:{},initialize:function(){var h=this;this.rowViews={};this.collection=new c.Libraries();this.collection.fetch({success:function(i){h.render()},error:function(j,i){e.error("An error occured. Please try again.")}})},render:function(i){var j=this.templateLibraryList();var k=null;var h=true;var h=Galaxy.libraries.preferences.get("with_deleted");var l=null;if(typeof i!=="undefined"){h=typeof i.with_deleted!=="undefined"?i.with_deleted:false;l=typeof i.models!=="undefined"?i.models:null}if(this.collection!==null&&l===null){if(h){k=this.collection.models}else{k=this.collection.where({deleted:false})}}else{if(l!==null){k=l}else{k=[]}}this.$el.html(j({length:k.length,order:Galaxy.libraries.preferences.get("sort_order")}));this.renderRows(k);$("#center [data-toggle]").tooltip();$("#center").css("overflow","auto")},renderRows:function(m){for(var l=0;l<m.length;l++){var k=m[l];var j=_.findWhere(this.rowViews,{id:k.get("id")});if(j!==undefined&&this instanceof Backbone.View){j.delegateEvents();this.$el.find("#library_list_body").append(j.el)}else{var h=new a.LibraryRowView(k);this.$el.find("#library_list_body").append(h.el);this.rowViews[k.get("id")]=h}}},sort_clicked:function(){if(Galaxy.libraries.preferences.get("sort_order")==="asc"){this.sortLibraries("name","desc");Galaxy.libraries.preferences.set({sort_order:"desc"})}else{this.sortLibraries("name","asc");Galaxy.libraries.preferences.set({sort_order:"asc"})}this.render()},sortLibraries:function(i,h){if(i==="name"){if(h==="asc"){this.collection.comparator=function(k,j){if(k.get("name").toLowerCase()>j.get("name").toLowerCase()){return 1}if(j.get("name").toLowerCase()>k.get("name").toLowerCase()){return -1}return 0}}else{if(h==="desc"){this.collection.comparator=function(k,j){if(k.get("name").toLowerCase()>j.get("name").toLowerCase()){return -1}if(j.get("name").toLowerCase()>k.get("name").toLowerCase()){return 1}return 0}}}this.collection.sort()}},templateLibraryList:function(){tmpl_array=[];tmpl_array.push('<div class="library_container table-responsive">');tmpl_array.push("<% if(length === 0) { %>");tmpl_array.push("<div>I see no libraries. Why don't you create one?</div>");tmpl_array.push("<% } else{ %>");tmpl_array.push('<table class="grid table table-condensed">');tmpl_array.push(" <thead>");tmpl_array.push(' <th style="width:30%;"><a class="sort-libraries-link" title="Click to reverse order" href="#">name</a><span title="Sorted alphabetically" class="fa fa-sort-alpha-<%- order %>"></span></th>');tmpl_array.push(' <th style="width:22%;">description</th>');tmpl_array.push(' <th style="width:22%;">synopsis</th> ');tmpl_array.push(' <th style="width:26%;"></th> ');tmpl_array.push(" </thead>");tmpl_array.push(' <tbody id="library_list_body">');tmpl_array.push(" </tbody>");tmpl_array.push("</table>");tmpl_array.push("<% }%>");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("")},redirectToHome:function(){window.location="../"},redirectToLogin:function(){window.location="/user/login"},show_library_modal:function(i){i.preventDefault();i.stopPropagation();var h=this;this.modal=Galaxy.modal;this.modal.show({closing_events:true,title:"Create New Library",body:this.templateNewLibraryInModal(),buttons:{Create:function(){h.create_new_library_event()},Close:function(){h.modal.hide()}}})},create_new_library_event:function(){var j=this.serialize_new_library();if(this.validate_new_library(j)){var i=new c.Library();var h=this;i.save(j,{success:function(k){h.collection.add(k);h.modal.hide();h.clear_library_modal();h.render();e.success("Library created")},error:function(){e.error("An error occured :(")}})}else{e.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(h){return h.name!==""}});return{LibraryListView:f}}); \ No newline at end of file
diff -r 1344876d770a4441864bc58e33e50eba860ef7b3 -r 3c169a33c5107c242d7cc455cce8b30d17437894 static/scripts/packed/mvc/library/library-libraryrow-view.js --- a/static/scripts/packed/mvc/library/library-libraryrow-view.js +++ b/static/scripts/packed/mvc/library/library-libraryrow-view.js @@ -1,1 +1,1 @@ -define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model"],function(b,d,e,c){var a=Backbone.View.extend({element_visibility_config:{upload_library_btn:false,edit_library_btn:false,permission_library_btn:false,save_library_btn:false,cancel_library_btn:false,delete_library_btn:false,undelete_library_btn:false},initialize:function(f){this.render(f)},render:function(g){var f=this.templateRow();this.prepareButtons(g);this.setElement(f({library:g,button_config:this.element_visibility_config}));this.$el.show()},prepareButtons:function(f){if(f.get("deleted")===true){if(Galaxy.currUser.isAdmin()){this.element_visibility_config.undelete_library_btn=true;this.element_visibility_config.upload_library_btn=false;this.element_visibility_config.edit_library_btn=false;this.element_visibility_config.permission_library_btn=false}}else{if(f.get("deleted")===false){this.element_visibility_config.undelete_library_btn=false;if(f.get("can_user_add")===true){this.element_visibility_config.upload_library_btn=true}if(f.get("can_user_modify")===true){this.element_visibility_config.edit_library_btn=true}if(f.get("can_user_manage")===true){this.element_visibility_config.permission_library_btn=true}}}},templateRow:function(){tmpl_array=[];tmpl_array.push(' <tr class="<% if(library.get("deleted") === true) { print("active") } %>" style="display:none;" data-id="<%- library.get("id") %>">');tmpl_array.push(' <td><a href="#folders/<%- library.get("root_folder_id") %>"><%- library.get("name") %></a></td>');tmpl_array.push(' <td><%= _.escape(library.get("description")) %></td>');tmpl_array.push(' <td><%= _.escape(library.get("synopsis")) %></td>');tmpl_array.push(' <td class="right-center">');tmpl_array.push(' <% if(library.get("deleted") === true) { %>');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Marked deleted" style="color:grey;" class="fa fa-ban fa-lg deleted_lib_ico"></span>');tmpl_array.push(' <% } else if(library.get("public") === true) { %>');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Public" style="color:grey;" class="fa fa-globe fa-lg public_lib_ico"></span>');tmpl_array.push(" <% }%>");tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Upload to library" class="primary-button btn-xs upload_library_btn" type="button" style="<% if(button_config.upload_library_btn === false) { print("display:none;") } %>"><span class="fa fa-upload"></span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Modify library" class="primary-button btn-xs edit_library_btn" type="button" style="<% if(button_config.edit_library_btn === false) { print("display:none;") } %>"><span class="fa fa-pencil"></span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Modify permissions" class="primary-button btn-xs permission_library_btn" type="button" style="<% if(button_config.permission_library_btn === false) { print("display:none;") } %>"><span class="fa fa-group"></span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Save changes" class="primary-button btn-xs save_library_btn" type="button" style="<% if(button_config.save_library_btn === false) { print("display:none;") } %>"><span class="fa fa-floppy-o"> Save</span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Discard changes" class="primary-button btn-xs cancel_library_btn" type="button" style="<% if(button_config.cancel_library_btn === false) { print("display:none;") } %>"><span class="fa fa-times"> Cancel</span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Delete library (can be undeleted later)" class="primary-button btn-xs delete_library_btn" type="button" style="<% if(button_config.delete_library_btn === false) { print("display:none;") } %>"><span class="fa fa-trash-o"> Delete</span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Undelete library" class="primary-button btn-xs undelete_library_btn" type="button" style="<% if(button_config.undelete_library_btn === false) { print("display:none;") } %>"><span class="fa fa-unlock"> Undelete</span></button>');tmpl_array.push(" </td>");tmpl_array.push(" </tr>");return _.template(tmpl_array.join(""))}});return{LibraryRowView:a}}); \ No newline at end of file +define(["galaxy.masthead","utils/utils","libs/toastr","mvc/library/library-model"],function(b,d,e,c){var a=Backbone.View.extend({events:{"click .edit_library_btn":"edit_button_clicked","click .cancel_library_btn":"cancel_library_modification","click .save_library_btn":"save_library_modification","click .delete_library_btn":"delete_library","click .undelete_library_btn":"undelete_library"},edit_mode:false,element_visibility_config:{upload_library_btn:false,edit_library_btn:false,permission_library_btn:false,save_library_btn:false,cancel_library_btn:false,delete_library_btn:false,undelete_library_btn:false},initialize:function(f){this.render(f)},render:function(g){if(typeof g==="undefined"){var g=Galaxy.libraries.libraryListView.collection.get(this.$el.data("id"))}this.prepareButtons(g);var f=this.templateRow();this.setElement(f({library:g,button_config:this.element_visibility_config,edit_mode:this.edit_mode}));this.$el.show();return this},repaint:function(f){$(".tooltip").hide();var g=this.$el;this.render(f);g.replaceWith(this.$el);this.$el.find("[data-toggle]").tooltip()},prepareButtons:function(f){vis_config=this.element_visibility_config;if(this.edit_mode===false){vis_config.save_library_btn=false;vis_config.cancel_library_btn=false;vis_config.delete_library_btn=false;if(f.get("deleted")===true){vis_config.undelete_library_btn=true;vis_config.upload_library_btn=false;vis_config.edit_library_btn=false;vis_config.permission_library_btn=false}else{if(f.get("deleted")===false){vis_config.save_library_btn=false;vis_config.cancel_library_btn=false;vis_config.undelete_library_btn=false;if(f.get("can_user_add")===true){vis_config.upload_library_btn=true}if(f.get("can_user_modify")===true){vis_config.edit_library_btn=true}if(f.get("can_user_manage")===true){vis_config.permission_library_btn=true}}}}else{if(this.edit_mode===true){vis_config.upload_library_btn=false;vis_config.edit_library_btn=false;vis_config.permission_library_btn=false;vis_config.save_library_btn=true;vis_config.cancel_library_btn=true;vis_config.delete_library_btn=true}}this.element_visibility_config=vis_config},edit_button_clicked:function(){this.edit_mode=true;this.repaint()},cancel_library_modification:function(){e.info("Modifications canceled");this.edit_mode=false;this.repaint()},save_library_modification:function(){var g=Galaxy.libraries.libraryListView.collection.get(this.$el.data("id"));var h=false;var j=this.$el.find(".input_library_name").val();if(typeof j!=="undefined"&&j!==g.get("name")){if(j.length>2){g.set("name",j);h=true}else{e.warning("Library name has to be at least 3 characters long");return}}var i=this.$el.find(".input_library_description").val();if(typeof i!=="undefined"&&i!==g.get("description")){g.set("description",i);h=true}var k=this.$el.find(".input_library_synopsis").val();if(typeof k!=="undefined"&&k!==g.get("synopsis")){g.set("synopsis",k);h=true}if(h){var f=this;g.save(null,{patch:true,success:function(l){f.edit_mode=false;f.repaint(l);e.success("Changes to library saved")},error:function(m,l){e.error("An error occured during updating the library :(")}})}else{this.edit_mode=false;this.repaint(g);e.info("Nothing has changed")}},delete_library:function(){var g=Galaxy.libraries.libraryListView.collection.get(this.$el.data("id"));var f=this;g.destroy({success:function(h){h.set("deleted",true);Galaxy.libraries.libraryListView.collection.add(h);f.edit_mode=false;if(Galaxy.libraries.preferences.get("with_deleted")===false){$(".tooltip").hide();f.$el.remove()}else{if(Galaxy.libraries.preferences.get("with_deleted")===true){f.repaint(h)}}e.success("Library has been marked deleted")},error:function(){e.error("An error occured during deleting the library :(")}})},undelete_library:function(){var g=Galaxy.libraries.libraryListView.collection.get(this.$el.data("id"));var f=this;g.url=g.urlRoot+g.id+"?undelete=true";g.destroy({success:function(h){h.set("deleted",false);Galaxy.libraries.libraryListView.collection.add(h);f.edit_mode=false;f.repaint(h);e.success("Library has been undeleted")},error:function(){e.error("An error occured while undeleting the library :(")}})},toggle_library_modification:function(i){var f=this.collection.get(i.data("id"));i.find(".public_lib_ico").toggle();i.find(".deleted_lib_ico").toggle();i.find(".edit_library_btn").toggle();i.find(".upload_library_btn").toggle();i.find(".permission_library_btn").toggle();i.find(".save_library_btn").toggle();i.find(".cancel_library_btn").toggle();if(f.get("deleted")){}else{i.find(".delete_library_btn").toggle()}if(i.find(".edit_library_btn").is(":hidden")){var g=f.get("name");var k='<input type="text" class="form-control input_library_name" placeholder="name">';i.children("td").eq(0).html(k);if(typeof g!==undefined){i.find(".input_library_name").val(g)}var h=f.get("description");var k='<input type="text" class="form-control input_library_description" placeholder="description">';i.children("td").eq(1).html(k);if(typeof h!==undefined){i.find(".input_library_description").val(h)}var j=f.get("synopsis");var k='<input type="text" class="form-control input_library_synopsis" placeholder="synopsis">';i.children("td").eq(2).html(k);if(typeof j!==undefined){i.find(".input_library_synopsis").val(j)}}else{i.children("td").eq(0).html(f.get("name"));i.children("td").eq(1).html(f.get("description"));i.children("td").eq(2).html(f.get("synopsis"))}},templateRow:function(){tmpl_array=[];tmpl_array.push(' <tr class="<% if(library.get("deleted") === true) { print("active") } %>" style="display:none;" data-id="<%- library.get("id") %>">');tmpl_array.push(" <% if(!edit_mode) { %>");tmpl_array.push(' <td><a href="#folders/<%- library.get("root_folder_id") %>"><%- library.get("name") %></a></td>');tmpl_array.push(' <td><%= _.escape(library.get("description")) %></td>');tmpl_array.push(' <td><%= _.escape(library.get("synopsis")) %></td>');tmpl_array.push(" <% } else if(edit_mode){ %>");tmpl_array.push(' <td><input type="text" class="form-control input_library_name" placeholder="name" value="<%- library.get("name") %>"></td>');tmpl_array.push(' <td><input type="text" class="form-control input_library_description" placeholder="description" value="<%- library.get("description") %>"></td>');tmpl_array.push(' <td><input type="text" class="form-control input_library_synopsis" placeholder="synopsis" value="<%- library.get("synopsis") %>"></td>');tmpl_array.push(" <% } %>");tmpl_array.push(' <td class="right-center">');tmpl_array.push(' <% if(library.get("deleted") === true) { %>');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Marked deleted" style="color:grey;" class="fa fa-ban fa-lg deleted_lib_ico"></span>');tmpl_array.push(' <% } else if(library.get("public") === true) { %>');tmpl_array.push(' <span data-toggle="tooltip" data-placement="top" title="Public" style="color:grey;" class="fa fa-globe fa-lg public_lib_ico"></span>');tmpl_array.push(" <% }%>");tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Upload to library" class="primary-button btn-xs upload_library_btn" type="button" style="<% if(button_config.upload_library_btn === false) { print("display:none;") } %>"><span class="fa fa-upload"></span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Modify library" class="primary-button btn-xs edit_library_btn" type="button" style="<% if(button_config.edit_library_btn === false) { print("display:none;") } %>"><span class="fa fa-pencil"></span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Modify permissions" class="primary-button btn-xs permission_library_btn" type="button" style="<% if(button_config.permission_library_btn === false) { print("display:none;") } %>"><span class="fa fa-group"></span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Save changes" class="primary-button btn-xs save_library_btn" type="button" style="<% if(button_config.save_library_btn === false) { print("display:none;") } %>"><span class="fa fa-floppy-o"> Save</span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Discard changes" class="primary-button btn-xs cancel_library_btn" type="button" style="<% if(button_config.cancel_library_btn === false) { print("display:none;") } %>"><span class="fa fa-times"> Cancel</span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Delete library (can be undeleted later)" class="primary-button btn-xs delete_library_btn" type="button" style="<% if(button_config.delete_library_btn === false) { print("display:none;") } %>"><span class="fa fa-trash-o"> Delete</span></button>');tmpl_array.push(' <button data-toggle="tooltip" data-placement="top" title="Undelete library" class="primary-button btn-xs undelete_library_btn" type="button" style="<% if(button_config.undelete_library_btn === false) { print("display:none;") } %>"><span class="fa fa-unlock"> Undelete</span></button>');tmpl_array.push(" </td>");tmpl_array.push(" </tr>");return _.template(tmpl_array.join(""))}});return{LibraryRowView:a}}); \ No newline at end of file
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.