From c14d433871d7911fa60701062ff98e67a751953b Mon Sep 17 00:00:00 2001 From: Martin Cech Date: Wed, 15 Jan 2014 18:11:09 -0500 Subject: [PATCH] javascript library and modal refactoring, automatic even binding if flag provided --- lib/galaxy/webapps/galaxy/api/lda_datasets.py | 4 +- static/scripts/galaxy.library.js | 15 ++-- static/scripts/galaxy.modal.js | 89 +++++++++++-------- static/scripts/packed/galaxy.library.js | 2 +- static/scripts/packed/galaxy.modal.js | 2 +- 5 files changed, 62 insertions(+), 50 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/lda_datasets.py b/lib/galaxy/webapps/galaxy/api/lda_datasets.py index bb2ef0ca49a..fbb37f76904 100644 --- a/lib/galaxy/webapps/galaxy/api/lda_datasets.py +++ b/lib/galaxy/webapps/galaxy/api/lda_datasets.py @@ -14,9 +14,9 @@ import urllib import urllib2 import zipfile from paste.httpexceptions import HTTPBadRequest +from galaxy import util, web from galaxy.exceptions import ItemAccessibilityException, MessageException, ItemDeletionException, ObjectNotFound from galaxy.security import Action -from galaxy import util, web from galaxy.util.streamball import StreamBall from galaxy.web.base.controller import BaseAPIController, UsesVisualizationMixin @@ -39,14 +39,12 @@ class LibraryDatasetsController( BaseAPIController, UsesVisualizationMixin ): :returns: detailed dataset information from base controller .. seealso:: :attr:`galaxy.web.base.controller.UsesLibraryMixinItems.get_library_dataset` """ - # Get dataset. try: dataset = self.get_library_dataset( trans, id = id, check_ownership=False, check_accessible=True ) except Exception, e: trans.response.status = 500 return str( e ) try: - # Default: return dataset as dict. rval = dataset.to_dict() except Exception, e: rval = "Error in dataset API at listing contents: " + str( e ) diff --git a/static/scripts/galaxy.library.js b/static/scripts/galaxy.library.js index 1ff2f6e6063..40f89acb12d 100644 --- a/static/scripts/galaxy.library.js +++ b/static/scripts/galaxy.library.js @@ -122,7 +122,7 @@ var FolderContentView = Backbone.View.extend({ // CONTAINER tmpl_array.push('
'); - tmpl_array.push('

New Data Libraries. This is work in progress. Report problems & ideas to Marten.

'); + tmpl_array.push('

Data Libraries Beta Test. This is work in progress. Please report problems & ideas via email and Trello.

'); // TOOLBAR tmpl_array.push('
'); @@ -457,6 +457,7 @@ var FolderContentView = Backbone.View.extend({ var self = this; this.modal = new mod_modal.GalaxyModal({ destructible : true, + bindClosingEvents: true, title : 'Dataset Details', body : template, buttons : { @@ -477,7 +478,6 @@ var FolderContentView = Backbone.View.extend({ $(this.modal.elMain).find('#dataset_import_single').val(self.lastSelectedHistory); } } - this.modal.bindEvents(); this.modal.show(); }, @@ -614,6 +614,7 @@ var FolderContentView = Backbone.View.extend({ var history_modal_tmpl = _.template(self.templateBulkImportInModal(), {histories : histories.models}); self.modal = new mod_modal.GalaxyModal({ destructible : true, + bindClosingEvents: true, title : 'Import into History', body : history_modal_tmpl, buttons : { @@ -621,7 +622,6 @@ var FolderContentView = Backbone.View.extend({ 'Close' : function() {self.modal.hideOrDestroy();} } }); - self.modal.bindEvents(); self.modal.show(); }, error: function(){ @@ -724,6 +724,7 @@ var FolderContentView = Backbone.View.extend({ //send request $('
'+inputs+'
') .appendTo('body').submit().remove(); + mod_toastr.info('Your download will begin soon'); }; }, @@ -737,6 +738,7 @@ var FolderContentView = Backbone.View.extend({ var self = this; this.modal = new mod_modal.GalaxyModal({ destructible : true, + bindClosingEvents: true, title : 'Create New Folder', body : this.templateNewFolderInModal(), buttons : { @@ -744,7 +746,6 @@ var FolderContentView = Backbone.View.extend({ 'Close' : function() {self.modal.hideOrDestroy(); self.modal = null;} } }); - this.modal.bindEvents(); this.modal.show(); }, @@ -810,7 +811,7 @@ var GalaxyLibraryview = Backbone.View.extend({ tmpl_array = []; tmpl_array.push('
'); tmpl_array.push(''); - tmpl_array.push('

New Data Libraries. This is work in progress. Report problems & ideas to Marten.

'); + tmpl_array.push('

Data Libraries Beta Test. This is work in progress. Please report problems & ideas via email and Trello.

'); tmpl_array.push('New Library'); tmpl_array.push(''); tmpl_array.push(' '); @@ -866,7 +867,7 @@ var GalaxyLibraryview = Backbone.View.extend({ }, error: function(model, response){ if (response.statusCode().status === 403){ - mod_toastr.error('Please log in first. Redirecting to login page in 3s.'); + mod_toastr.info('Please log in first. Redirecting to login page in 3s.'); setTimeout(that.redirectToLogin, 3000); } else { mod_toastr.error('An error occured. Please try again.'); @@ -894,6 +895,7 @@ var GalaxyLibraryview = Backbone.View.extend({ var self = this; this.modal = new mod_modal.GalaxyModal({ destructible : true, + bindClosingEvents: true, title : 'Create New Library', body : this.templateNewLibraryInModal(), buttons : { @@ -901,7 +903,6 @@ var GalaxyLibraryview = Backbone.View.extend({ 'Close' : function() {self.modal.hideOrDestroy();} } }); - this.modal.bindEvents(); this.modal.show(); }, diff --git a/static/scripts/galaxy.modal.js b/static/scripts/galaxy.modal.js index 2d3c84a8ff4..df7fb8b3de6 100644 --- a/static/scripts/galaxy.modal.js +++ b/static/scripts/galaxy.modal.js @@ -16,50 +16,72 @@ var GalaxyModal = Backbone.View.extend( height : null, width : null }, + + // flag whether the closing events are bound + eventsBound: false, // options options : { // by default the modal cannot be removed by the self.destroy() method // but only hidden through self.hide() - destructible: false + destructible: false, + // by default don't bind the events + bindClosingEvents: false }, // initialize initialize : function(options) { self = this; - if (options) + if (options){ this.create(options); + } }, hideOrDestroy: function(){ - if (this.options.destructible){ - self.destroy(); + self.visible = false; + + //unbinds event for ALL modals? + self.unbindEvents(); + + if (self.options.destructible){ + self.$el.remove(); // destroy } else { self.hide(); } }, + // hide modal, shouldn't be called directly but through hideOrDestroy() + // however hide() remains for backwards compatibility + hide: function(){ + this.visible = false; + this.$el.fadeOut('fast'); + }, + // bind the click-to-hide function bindEvents: function() { // bind the ESC key to hideOrDestroy() function $(document).on('keyup', function(event){ - if (event.keyCode == 27) { self.hideOrDestroy() } + if (event.keyCode == 27) { + self.hideOrDestroy() + } }) // bind the 'click anywhere' to hideOrDestroy() function... - $('html').on('click', function(event){ - self.hideOrDestroy() - }) + $('html').on('click', self.hideOrDestroy) // ...but don't hide if the click is on modal content $('.modal-content').on('click', function(event){ event.stopPropagation(); }) + + self.eventsBound = true; }, // unbind the click-to-hide function unbindEvents: function(){ // unbind the ESC key to hideOrDestroy() function $(document).off('keyup', function(event){ - if (event.keyCode == 27) { self.hideOrDestroy() } + if (event.keyCode == 27) { + self.hideOrDestroy() + } }) // unbind the 'click anywhere' to hideOrDestroy() function... $('html').off('click', function(event){ @@ -68,6 +90,8 @@ var GalaxyModal = Backbone.View.extend( $('.modal-content').off('click', function(event){ event.stopPropagation(); }) + + self.eventsBound = false; }, // adds and displays a new frame/window @@ -76,59 +100,43 @@ var GalaxyModal = Backbone.View.extend( this.initialize(options); // fix height - if (this.options.height) - { + if (this.options.height){ this.$body.css('height', this.options.height); this.$body.css('overflow', 'hidden'); - } else + } else{ this.$body.css('max-height', $(window).height() / 2); + } // fix width - if (this.options.width) + if (this.options.width){ this.$dialog.css('width', this.options.width); + } // show - if (this.visible) + if (this.visible){ this.$el.show(); - else + } else { this.$el.fadeIn('fast'); + } // set flag this.visible = true; }, - // hide modal, shouldn't be called directly but through hideOrDestroy() - hide: function(){ - // fade out - this.$el.fadeOut('fast'); - // set flag - this.visible = false; - // unbind events - this.unbindEvents(); - }, - - // destroy modal, shouldn't be called directly but through hideOrDestroy() - destroy: function(){ - // set flag - this.visible = false; - // unbind events - this.unbindEvents(); - // remove - this.$el.remove(); - }, - // create create: function(options) { // configure options this.options = _.defaults(options, this.optionsDefault); // check for progress bar request - if (this.options.body == 'progress') + if (this.options.body == 'progress'){ this.options.body = $('
'); + } // remove former element - if (this.$el) + if (this.$el){ this.$el.remove(); + } // create new element this.setElement(this.template(this.options.title)); @@ -144,8 +152,9 @@ var GalaxyModal = Backbone.View.extend( this.$body.html(this.options.body); // configure background - if (!this.options.backdrop) + if (!this.options.backdrop){ this.$backdrop.removeClass('in'); + } // append buttons if (this.options.buttons) { @@ -160,6 +169,10 @@ var GalaxyModal = Backbone.View.extend( // append to main element $(this.elMain).append($(this.el)); + + if (this.options.bindClosingEvents && !this.eventsBound){ + this.bindEvents(); + } }, // enable buttons diff --git a/static/scripts/packed/galaxy.library.js b/static/scripts/packed/galaxy.library.js index 20a6df10c17..61fb82dcc1d 100644 --- a/static/scripts/packed/galaxy.library.js +++ b/static/scripts/packed/galaxy.library.js @@ -1 +1 @@ -var view=null;var library_router=null;var responses=[];define(["galaxy.modal","galaxy.masthead","utils/galaxy.utils","libs/toastr"],function(k,l,h,n){var f=Backbone.Model.extend({urlRoot:"/api/libraries"});var c=Backbone.Model.extend({urlRoot:"/api/folders"});var o=Backbone.Collection.extend({url:"/api/libraries",model:f});var i=Backbone.Model.extend({urlRoot:"/api/libraries/datasets"});var d=Backbone.Collection.extend({model:i});var e=Backbone.Model.extend({defaults:{folder:new d(),full_path:"unknown",urlRoot:"/api/folders/",id:"unknown"},parse:function(r){this.full_path=r[0].full_path;this.get("folder").reset(r[1].folder_contents);return r}});var b=Backbone.Model.extend({urlRoot:"/api/histories/"});var j=Backbone.Model.extend({url:"/api/histories/"});var p=Backbone.Collection.extend({url:"/api/histories",model:j});var q=Backbone.Router.extend({routes:{"":"libraries","folders/:id":"folder_content","folders/:folder_id/download/:format":"download"}});var m=Backbone.View.extend({el:"#center",progress:0,progressStep:1,lastSelectedHistory:"",modal:null,folders:null,initialize:function(){this.folders=[];this.queue=jQuery.Deferred();this.queue.resolve()},templateFolder:function(){var r=[];r.push('
');r.push('

New Data Libraries. This is work in progress. Report problems & ideas to Marten.

');r.push('
');r.push(' ');r.push(' ');r.push(' ");r.push("
");r.push('
');r.push('Libraries | ');r.push("<% _.each(path, function(path_item) { %>");r.push("<% if (path_item[0] != id) { %>");r.push('<%- path_item[1] %> | ');r.push("<% } else { %>");r.push('<%- path_item[1] %>');r.push("<% } %>");r.push("<% }); %>");r.push("
");r.push('
');r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(' ');r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(" <% _.each(items, function(content_item) { %>");r.push(' ');r.push(' <% if (content_item.get("type") === "folder") { %>');r.push(" ");r.push(' ');r.push(' ");r.push(" ");r.push(' ');r.push(" <% } else { %>");r.push(' ');r.push(" ");r.push(' ');r.push(' ');r.push(' ');r.push(" <% } %> ");r.push(' ');r.push(" ");r.push(" <% }); %>");r.push(" ");r.push(" ");r.push("
viewnamedata typesizedate (UTC)
<%- content_item.get("name") %>');r.push(' <% if (content_item.get("item_count") === 0) { %>');r.push(' (empty folder)');r.push(" <% } %>");r.push(" folder<%= _.escape(content_item.get("item_count")) %> item(s)");r.push(' ");r.push(" <%- content_item.get("name") %><%= _.escape(content_item.get("data_type")) %><%= _.escape(content_item.get("readable_size")) %><%= _.escape(content_item.get("time_updated")) %>
");r.push("
");return r.join("")},templateDatasetModal:function(){var r=[];r.push('
');r.push(' ');r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(' ');r.push(" ");r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(' ');r.push(' ');r.push(' ');r.push(" ");r.push(' ');r.push(' <% if (item.get("metadata_comment_lines") === "") { %>');r.push(' ');r.push(" <% } else { %>");r.push(' ');r.push(" <% } %>");r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push("
">Name<%= _.escape(item.get("name")) %>
Data type<%= _.escape(item.get("data_type")) %>
Genome build<%= _.escape(item.get("genome_build")) %>
Size<%= _.escape(size) %>
Date uploaded (UTC)<%= _.escape(item.get("date_uploaded")) %>
Uploaded by<%= _.escape(item.get("uploaded_by")) %>
Data Lines<%= _.escape(item.get("metadata_data_lines")) %>
Comment Lines<%= _.escape(item.get("metadata_comment_lines")) %>unknown
Number of Columns<%= _.escape(item.get("metadata_columns")) %>
Column Types<%= _.escape(item.get("metadata_column_types")) %>
Miscellaneous information<%= _.escape(item.get("misc_blurb")) %>
");r.push('
');r.push("   
");r.push("
");return r.join("")},templateHistorySelectInModal:function(){var r=[];r.push('');r.push("Select history: ");r.push('");r.push("");return r.join("")},templateBulkImportInModal:function(){var r=[];r.push('');r.push("Select history: ");r.push('");r.push("");return r.join("")},templateProgressBar:function(){var r=[];r.push('
');r.push("Importing selected datasets to history <%= _.escape(history_name) %>");r.push("
");r.push('
');r.push('
');r.push(' 0% Complete');r.push("
");r.push("
");r.push("");return r.join("")},templateNewFolderInModal:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push('');tmpl_array.push('');tmpl_array.push("
");tmpl_array.push("
");return tmpl_array.join("")},events:{"click #select-all-checkboxes":"selectAll","click .folder_row":"selectClickedRow","click #toolbtn_bulk_import":"modalBulkImport","click #toolbtn_dl":"bulkDownload","click .library-dataset":"showDatasetDetails","click #toolbtn_create_folder":"createFolderFromModal","click .btn_open_folder":"navigateToFolder"},render:function(r){$("#center").css("overflow","auto");view=this;var t=this;var s=new e({id:r.id});s.url=s.attributes.urlRoot+r.id+"/contents";s.fetch({success:function(u){for(var w=0;w=100000000000){r=r/100000000000;s="TB"}else{if(r>=100000000){r=r/100000000;s="GB"}else{if(r>=100000){r=r/100000;s="MB"}else{if(r>=100){r=r/100;s="KB"}else{r=r*10;s="b"}}}}return(Math.round(r)/10)+s},navigateToFolder:function(s){var r=$(s.target).attr("data-id");if(typeof r==="undefined"){return false}else{if(r==="0"){library_router.navigate("#",{trigger:true,replace:true})}else{library_router.navigate("folders/"+r,{trigger:true,replace:true})}}},showDatasetDetails:function(u){u.preventDefault();var v=$(u.target).parent().parent().attr("id");var t=new i();var s=new p();t.id=v;var r=this;t.fetch({success:function(w){s.fetch({success:function(x){r.renderModalAfterFetch(w,x)},error:function(){n.error("An error occured during fetching histories:(");r.renderModalAfterFetch(w)}})},error:function(){n.error("An error occured during loading dataset details :(")}})},renderModalAfterFetch:function(w,t){var u=this.size_to_string(w.get("file_size"));var v=_.template(this.templateDatasetModal(),{item:w,size:u});var s=this;this.modal=new k.GalaxyModal({destructible:true,title:"Dataset Details",body:v,buttons:{Import:function(){s.importCurrentIntoHistory()},Download:function(){s.downloadCurrent()},Close:function(){s.modal.hideOrDestroy()}}});$(".peek").html(w.get("peek"));if(typeof history.models!==undefined){var r=_.template(this.templateHistorySelectInModal(),{histories:t.models});$(this.modal.elMain).find(".buttons").prepend(r);if(s.lastSelectedHistory.length>0){$(this.modal.elMain).find("#dataset_import_single").val(s.lastSelectedHistory)}}this.modal.bindEvents();this.modal.show()},downloadCurrent:function(){this.modal.disableButton("Import");this.modal.disableButton("Download");var r=[];r.push($("#id_row").attr("data-id"));var s="/api/libraries/datasets/download/uncompressed";var t={ldda_ids:r};folderContentView.processDownload(s,t);this.modal.enableButton("Import");this.modal.enableButton("Download")},importCurrentIntoHistory:function(){this.modal.disableButton("Import");this.modal.disableButton("Download");var t=$(this.modal.elMain).find("select[name=dataset_import_single] option:selected").val();this.lastSelectedHistory=t;var r=$("#id_row").attr("data-id");var u=new b();var s=this;u.url=u.urlRoot+t+"/contents";u.save({content:r,source:"library"},{success:function(){n.success("Dataset imported");s.modal.enableButton("Import");s.modal.enableButton("Download")},error:function(){n.error("An error occured! Dataset not imported. Please try again.");s.modal.enableButton("Import");s.modal.enableButton("Download")}})},selectAll:function(s){var r=s.target.checked;that=this;$(":checkbox").each(function(){this.checked=r;$row=$(this.parentElement.parentElement);(r)?that.makeDarkRow($row):that.makeWhiteRow($row)});this.checkTools()},selectClickedRow:function(s){var u="";var r;var t;if(s.target.localName==="input"){u=s.target;r=$(s.target.parentElement.parentElement);t="input"}else{if(s.target.localName==="td"){u=$("#"+s.target.parentElement.id).find(":checkbox")[0];r=$(s.target.parentElement);t="td"}}if(u===""){s.stopPropagation();return}if(u===undefined){s.stopPropagation();return}if(u.checked){if(t==="td"){u.checked="";this.makeWhiteRow(r)}else{if(t==="input"){this.makeDarkRow(r)}}}else{if(t==="td"){u.checked="selected";this.makeDarkRow(r)}else{if(t==="input"){this.makeWhiteRow(r)}}}this.checkTools()},makeDarkRow:function(r){r.removeClass("light");r.find("a").removeClass("light");r.addClass("dark");r.find("a").addClass("dark")},makeWhiteRow:function(r){r.removeClass("dark");r.find("a").removeClass("dark");r.addClass("light");r.find("a").addClass("light")},checkTools:function(){var r=$("#folder_table").find(":checked");if(r.length>0){$("#toolbtn_bulk_import").show();$("#toolbtn_dl").show()}else{$("#toolbtn_bulk_import").hide();$("#toolbtn_dl").hide()}},modalBulkImport:function(){var s=this;var r=new p();r.fetch({success:function(t){var u=_.template(s.templateBulkImportInModal(),{histories:t.models});s.modal=new k.GalaxyModal({destructible:true,title:"Import into History",body:u,buttons:{Import:function(){s.importAllIntoHistory()},Close:function(){s.modal.hideOrDestroy()}}});s.modal.bindEvents();s.modal.show()},error:function(){n.error("An error occured :(")}})},importAllIntoHistory:function(){this.modal.disableButton("Import");var t=$("select[name=dataset_import_bulk] option:selected").val();var x=$("select[name=dataset_import_bulk] option:selected").text();var z=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!=""){z.push(this.parentElement.parentElement.id)}});var y=_.template(this.templateProgressBar(),{history_name:x});$(this.modal.elMain).find(".modal-body").html(y);var u=100/z.length;this.initProgress(u);var r=[];for(var s=z.length-1;s>=0;s--){library_dataset_id=z[s];var v=new b();var w=this;v.url=v.urlRoot+t+"/contents";v.content=library_dataset_id;v.source="library";r.push(v)}this.chainCall(r)},chainCall:function(s){var r=this;var t=s.pop();if(typeof t==="undefined"){n.success("All datasets imported");this.modal.hideOrDestroy();return}var u=$.when(t.save({content:t.content,source:t.source})).done(function(v){r.updateProgress();responses.push(v);r.chainCall(s)})},initProgress:function(r){this.progress=0;this.progressStep=r},updateProgress:function(){this.progress+=this.progressStep;$(".progress-bar-import").width(Math.round(this.progress)+"%");txt_representation=Math.round(this.progress)+"% Complete";$(".completion_span").text(txt_representation)},download:function(r,v){var t=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!=""){t.push(this.parentElement.parentElement.id)}});var s="/api/libraries/datasets/download/"+v;var u={ldda_ids:t};this.processDownload(s,u,"get")},processDownload:function(s,t,u){if(s&&t){t=typeof t=="string"?t:$.param(t);var r="";$.each(t.split("&"),function(){var v=this.split("=");r+=''});$('
'+r+"
").appendTo("body").submit().remove();n.info("Your download will begin soon")}},createFolderFromModal:function(){event.preventDefault();event.stopPropagation();var r=this;this.modal=new k.GalaxyModal({destructible:true,title:"Create New Folder",body:this.templateNewFolderInModal(),buttons:{Create:function(){r.create_new_folder_event()},Close:function(){r.modal.hideOrDestroy();r.modal=null}}});this.modal.bindEvents();this.modal.show()},create_new_folder_event:function(){var r=this.serialize_new_folder();if(this.validate_new_folder(r)){var t=new c();url_items=Backbone.history.fragment.split("/");current_folder_id=url_items[url_items.length-1];t.url=t.urlRoot+"/"+current_folder_id;var s=this;t.save(r,{success:function(u){s.modal.hideOrDestroy();n.success("Folder created");s.render({id:current_folder_id})},error:function(){n.error("An error occured :(")}})}else{n.error("Folder's name is missing")}return false},serialize_new_folder:function(){return{name:$("input[name='Name']").val(),description:$("input[name='Description']").val()}},validate_new_folder:function(r){return r.name!==""}});var a=Backbone.View.extend({el:"#center",events:{"click #create_new_library_btn":"show_library_modal"},initialize:function(){},templateLibraryList:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("");tmpl_array.push('

New Data Libraries. This is work in progress. Report problems & ideas to Marten.

');tmpl_array.push('New Library');tmpl_array.push('');tmpl_array.push(" ");tmpl_array.push(' ');tmpl_array.push(" ");tmpl_array.push(" ");tmpl_array.push(" ");tmpl_array.push(" ");tmpl_array.push(" ");tmpl_array.push(" ");tmpl_array.push(" <% _.each(libraries, function(library) { %>");tmpl_array.push(" ");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(" ");tmpl_array.push(" <% }); %>");tmpl_array.push(" ");tmpl_array.push("
namedescriptionsynopsismodel type
<%- library.get("name") %><%= _.escape(library.get("description")) %><%= _.escape(library.get("synopsis")) %><%= _.escape(library.get("model_class")) %>
");tmpl_array.push("
");return tmpl_array.join("")},templateNewLibraryInModal:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push("
");tmpl_array.push("
");return tmpl_array.join("")},render:function(){$("#center").css("overflow","auto");var r=this;libraries=new o();libraries.fetch({success:function(s){var t=_.template(r.templateLibraryList(),{libraries:s.models});r.$el.html(t)},error:function(t,s){if(s.statusCode().status===403){n.error("Please log in first. Redirecting to login page in 3s.");setTimeout(r.redirectToLogin,3000)}else{n.error("An error occured. Please try again.")}}})},redirectToHome:function(){window.location="../"},redirectToLogin:function(){window.location="/user/login"},modal:null,show_library_modal:function(s){s.preventDefault();s.stopPropagation();var r=this;this.modal=new k.GalaxyModal({destructible:true,title:"Create New Library",body:this.templateNewLibraryInModal(),buttons:{Create:function(){r.create_new_library_event()},Close:function(){r.modal.hideOrDestroy()}}});this.modal.bindEvents();this.modal.show()},create_new_library_event:function(){var t=this.serialize_new_library();if(this.validate_new_library(t)){var s=new f();var r=this;s.save(t,{success:function(u){r.modal.hideOrDestroy();r.clear_library_modal();r.render();n.success("Library created")},error:function(){n.error("An error occured :(")}})}else{n.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(r){return r.name!==""}});var g=Backbone.View.extend({folderContentView:null,galaxyLibraryview:null,initialize:function(){folderContentView=new m();galaxyLibraryview=new a();library_router=new q();library_router.on("route:libraries",function(){galaxyLibraryview.render()});library_router.on("route:folder_content",function(r){folderContentView.render({id:r})});library_router.on("route:download",function(r,s){if($("#center").find(":checked").length===0){library_router.navigate("folders/"+r,{trigger:true,replace:true})}else{folderContentView.download(r,s);library_router.navigate("folders/"+r,{trigger:false,replace:true})}});Backbone.history.start();return this}});return{GalaxyApp:g}}); \ No newline at end of file +var view=null;var library_router=null;var responses=[];define(["galaxy.modal","galaxy.masthead","utils/galaxy.utils","libs/toastr"],function(k,l,h,n){var f=Backbone.Model.extend({urlRoot:"/api/libraries"});var c=Backbone.Model.extend({urlRoot:"/api/folders"});var o=Backbone.Collection.extend({url:"/api/libraries",model:f});var i=Backbone.Model.extend({urlRoot:"/api/libraries/datasets"});var d=Backbone.Collection.extend({model:i});var e=Backbone.Model.extend({defaults:{folder:new d(),full_path:"unknown",urlRoot:"/api/folders/",id:"unknown"},parse:function(r){this.full_path=r[0].full_path;this.get("folder").reset(r[1].folder_contents);return r}});var b=Backbone.Model.extend({urlRoot:"/api/histories/"});var j=Backbone.Model.extend({url:"/api/histories/"});var p=Backbone.Collection.extend({url:"/api/histories",model:j});var q=Backbone.Router.extend({routes:{"":"libraries","folders/:id":"folder_content","folders/:folder_id/download/:format":"download"}});var m=Backbone.View.extend({el:"#center",progress:0,progressStep:1,lastSelectedHistory:"",modal:null,folders:null,initialize:function(){this.folders=[];this.queue=jQuery.Deferred();this.queue.resolve()},templateFolder:function(){var r=[];r.push('
');r.push('

Data Libraries Beta Test. This is work in progress. Please report problems & ideas via email and Trello.

');r.push('
');r.push(' ');r.push(' ');r.push(' ");r.push("
");r.push('
');r.push('Libraries | ');r.push("<% _.each(path, function(path_item) { %>");r.push("<% if (path_item[0] != id) { %>");r.push('<%- path_item[1] %> | ');r.push("<% } else { %>");r.push('<%- path_item[1] %>');r.push("<% } %>");r.push("<% }); %>");r.push("
");r.push('');r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(' ');r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(" ");r.push(" <% _.each(items, function(content_item) { %>");r.push(' ');r.push(' <% if (content_item.get("type") === "folder") { %>');r.push(" ");r.push(' ');r.push(' ");r.push(" ");r.push(' ');r.push(" <% } else { %>");r.push(' ');r.push(" ");r.push(' ');r.push(' ');r.push(' ');r.push(" <% } %> ");r.push(' ');r.push(" ");r.push(" <% }); %>");r.push(" ");r.push(" ");r.push("
viewnamedata typesizedate (UTC)
<%- content_item.get("name") %>');r.push(' <% if (content_item.get("item_count") === 0) { %>');r.push(' (empty folder)');r.push(" <% } %>");r.push(" folder<%= _.escape(content_item.get("item_count")) %> item(s)");r.push(' ");r.push(" <%- content_item.get("name") %><%= _.escape(content_item.get("data_type")) %><%= _.escape(content_item.get("readable_size")) %><%= _.escape(content_item.get("time_updated")) %>
");r.push("
");return r.join("")},templateDatasetModal:function(){var r=[];r.push('
');r.push(' ');r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(' ');r.push(" ");r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(' ');r.push(' ');r.push(' ');r.push(" ");r.push(' ');r.push(' <% if (item.get("metadata_comment_lines") === "") { %>');r.push(' ');r.push(" <% } else { %>");r.push(' ');r.push(" <% } %>");r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push(" ");r.push(' ');r.push(' ');r.push(" ");r.push("
">Name<%= _.escape(item.get("name")) %>
Data type<%= _.escape(item.get("data_type")) %>
Genome build<%= _.escape(item.get("genome_build")) %>
Size<%= _.escape(size) %>
Date uploaded (UTC)<%= _.escape(item.get("date_uploaded")) %>
Uploaded by<%= _.escape(item.get("uploaded_by")) %>
Data Lines<%= _.escape(item.get("metadata_data_lines")) %>
Comment Lines<%= _.escape(item.get("metadata_comment_lines")) %>unknown
Number of Columns<%= _.escape(item.get("metadata_columns")) %>
Column Types<%= _.escape(item.get("metadata_column_types")) %>
Miscellaneous information<%= _.escape(item.get("misc_blurb")) %>
");r.push('
');r.push("   
");r.push("
");return r.join("")},templateHistorySelectInModal:function(){var r=[];r.push('');r.push("Select history: ");r.push('");r.push("");return r.join("")},templateBulkImportInModal:function(){var r=[];r.push('');r.push("Select history: ");r.push('");r.push("");return r.join("")},templateProgressBar:function(){var r=[];r.push('
');r.push("Importing selected datasets to history <%= _.escape(history_name) %>");r.push("
");r.push('
');r.push('
');r.push(' 0% Complete');r.push("
");r.push("
");r.push("");return r.join("")},templateNewFolderInModal:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push('');tmpl_array.push('');tmpl_array.push("
");tmpl_array.push("
");return tmpl_array.join("")},events:{"click #select-all-checkboxes":"selectAll","click .folder_row":"selectClickedRow","click #toolbtn_bulk_import":"modalBulkImport","click #toolbtn_dl":"bulkDownload","click .library-dataset":"showDatasetDetails","click #toolbtn_create_folder":"createFolderFromModal","click .btn_open_folder":"navigateToFolder"},render:function(r){$("#center").css("overflow","auto");view=this;var t=this;var s=new e({id:r.id});s.url=s.attributes.urlRoot+r.id+"/contents";s.fetch({success:function(u){for(var w=0;w=100000000000){r=r/100000000000;s="TB"}else{if(r>=100000000){r=r/100000000;s="GB"}else{if(r>=100000){r=r/100000;s="MB"}else{if(r>=100){r=r/100;s="KB"}else{r=r*10;s="b"}}}}return(Math.round(r)/10)+s},navigateToFolder:function(s){var r=$(s.target).attr("data-id");if(typeof r==="undefined"){return false}else{if(r==="0"){library_router.navigate("#",{trigger:true,replace:true})}else{library_router.navigate("folders/"+r,{trigger:true,replace:true})}}},showDatasetDetails:function(u){u.preventDefault();var v=$(u.target).parent().parent().attr("id");var t=new i();var s=new p();t.id=v;var r=this;t.fetch({success:function(w){s.fetch({success:function(x){r.renderModalAfterFetch(w,x)},error:function(){n.error("An error occured during fetching histories:(");r.renderModalAfterFetch(w)}})},error:function(){n.error("An error occured during loading dataset details :(")}})},renderModalAfterFetch:function(w,t){var u=this.size_to_string(w.get("file_size"));var v=_.template(this.templateDatasetModal(),{item:w,size:u});var s=this;this.modal=new k.GalaxyModal({destructible:true,bindClosingEvents:true,title:"Dataset Details",body:v,buttons:{Import:function(){s.importCurrentIntoHistory()},Download:function(){s.downloadCurrent()},Close:function(){s.modal.hideOrDestroy()}}});$(".peek").html(w.get("peek"));if(typeof history.models!==undefined){var r=_.template(this.templateHistorySelectInModal(),{histories:t.models});$(this.modal.elMain).find(".buttons").prepend(r);if(s.lastSelectedHistory.length>0){$(this.modal.elMain).find("#dataset_import_single").val(s.lastSelectedHistory)}}this.modal.show()},downloadCurrent:function(){this.modal.disableButton("Import");this.modal.disableButton("Download");var r=[];r.push($("#id_row").attr("data-id"));var s="/api/libraries/datasets/download/uncompressed";var t={ldda_ids:r};folderContentView.processDownload(s,t);this.modal.enableButton("Import");this.modal.enableButton("Download")},importCurrentIntoHistory:function(){this.modal.disableButton("Import");this.modal.disableButton("Download");var t=$(this.modal.elMain).find("select[name=dataset_import_single] option:selected").val();this.lastSelectedHistory=t;var r=$("#id_row").attr("data-id");var u=new b();var s=this;u.url=u.urlRoot+t+"/contents";u.save({content:r,source:"library"},{success:function(){n.success("Dataset imported");s.modal.enableButton("Import");s.modal.enableButton("Download")},error:function(){n.error("An error occured! Dataset not imported. Please try again.");s.modal.enableButton("Import");s.modal.enableButton("Download")}})},selectAll:function(s){var r=s.target.checked;that=this;$(":checkbox").each(function(){this.checked=r;$row=$(this.parentElement.parentElement);(r)?that.makeDarkRow($row):that.makeWhiteRow($row)});this.checkTools()},selectClickedRow:function(s){var u="";var r;var t;if(s.target.localName==="input"){u=s.target;r=$(s.target.parentElement.parentElement);t="input"}else{if(s.target.localName==="td"){u=$("#"+s.target.parentElement.id).find(":checkbox")[0];r=$(s.target.parentElement);t="td"}}if(u===""){s.stopPropagation();return}if(u===undefined){s.stopPropagation();return}if(u.checked){if(t==="td"){u.checked="";this.makeWhiteRow(r)}else{if(t==="input"){this.makeDarkRow(r)}}}else{if(t==="td"){u.checked="selected";this.makeDarkRow(r)}else{if(t==="input"){this.makeWhiteRow(r)}}}this.checkTools()},makeDarkRow:function(r){r.removeClass("light");r.find("a").removeClass("light");r.addClass("dark");r.find("a").addClass("dark")},makeWhiteRow:function(r){r.removeClass("dark");r.find("a").removeClass("dark");r.addClass("light");r.find("a").addClass("light")},checkTools:function(){var r=$("#folder_table").find(":checked");if(r.length>0){$("#toolbtn_bulk_import").show();$("#toolbtn_dl").show()}else{$("#toolbtn_bulk_import").hide();$("#toolbtn_dl").hide()}},modalBulkImport:function(){var s=this;var r=new p();r.fetch({success:function(t){var u=_.template(s.templateBulkImportInModal(),{histories:t.models});s.modal=new k.GalaxyModal({destructible:true,bindClosingEvents:true,title:"Import into History",body:u,buttons:{Import:function(){s.importAllIntoHistory()},Close:function(){s.modal.hideOrDestroy()}}});s.modal.show()},error:function(){n.error("An error occured :(")}})},importAllIntoHistory:function(){this.modal.disableButton("Import");var t=$("select[name=dataset_import_bulk] option:selected").val();var x=$("select[name=dataset_import_bulk] option:selected").text();var z=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!=""){z.push(this.parentElement.parentElement.id)}});var y=_.template(this.templateProgressBar(),{history_name:x});$(this.modal.elMain).find(".modal-body").html(y);var u=100/z.length;this.initProgress(u);var r=[];for(var s=z.length-1;s>=0;s--){library_dataset_id=z[s];var v=new b();var w=this;v.url=v.urlRoot+t+"/contents";v.content=library_dataset_id;v.source="library";r.push(v)}this.chainCall(r)},chainCall:function(s){var r=this;var t=s.pop();if(typeof t==="undefined"){n.success("All datasets imported");this.modal.hideOrDestroy();return}var u=$.when(t.save({content:t.content,source:t.source})).done(function(v){r.updateProgress();responses.push(v);r.chainCall(s)})},initProgress:function(r){this.progress=0;this.progressStep=r},updateProgress:function(){this.progress+=this.progressStep;$(".progress-bar-import").width(Math.round(this.progress)+"%");txt_representation=Math.round(this.progress)+"% Complete";$(".completion_span").text(txt_representation)},download:function(r,v){var t=[];$("#folder_table").find(":checked").each(function(){if(this.parentElement.parentElement.id!=""){t.push(this.parentElement.parentElement.id)}});var s="/api/libraries/datasets/download/"+v;var u={ldda_ids:t};this.processDownload(s,u,"get")},processDownload:function(s,t,u){if(s&&t){t=typeof t=="string"?t:$.param(t);var r="";$.each(t.split("&"),function(){var v=this.split("=");r+=''});$('
'+r+"
").appendTo("body").submit().remove();n.info("Your download will begin soon")}},createFolderFromModal:function(){event.preventDefault();event.stopPropagation();var r=this;this.modal=new k.GalaxyModal({destructible:true,bindClosingEvents:true,title:"Create New Folder",body:this.templateNewFolderInModal(),buttons:{Create:function(){r.create_new_folder_event()},Close:function(){r.modal.hideOrDestroy();r.modal=null}}});this.modal.show()},create_new_folder_event:function(){var r=this.serialize_new_folder();if(this.validate_new_folder(r)){var t=new c();url_items=Backbone.history.fragment.split("/");current_folder_id=url_items[url_items.length-1];t.url=t.urlRoot+"/"+current_folder_id;var s=this;t.save(r,{success:function(u){s.modal.hideOrDestroy();n.success("Folder created");s.render({id:current_folder_id})},error:function(){n.error("An error occured :(")}})}else{n.error("Folder's name is missing")}return false},serialize_new_folder:function(){return{name:$("input[name='Name']").val(),description:$("input[name='Description']").val()}},validate_new_folder:function(r){return r.name!==""}});var a=Backbone.View.extend({el:"#center",events:{"click #create_new_library_btn":"show_library_modal"},initialize:function(){},templateLibraryList:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("");tmpl_array.push('

Data Libraries Beta Test. This is work in progress. Please report problems & ideas via email and Trello.

');tmpl_array.push('New Library');tmpl_array.push('');tmpl_array.push(" ");tmpl_array.push(' ');tmpl_array.push(" ");tmpl_array.push(" ");tmpl_array.push(" ");tmpl_array.push(" ");tmpl_array.push(" ");tmpl_array.push(" ");tmpl_array.push(" <% _.each(libraries, function(library) { %>");tmpl_array.push(" ");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(" ");tmpl_array.push(" <% }); %>");tmpl_array.push(" ");tmpl_array.push("
namedescriptionsynopsismodel type
<%- library.get("name") %><%= _.escape(library.get("description")) %><%= _.escape(library.get("synopsis")) %><%= _.escape(library.get("model_class")) %>
");tmpl_array.push("
");return tmpl_array.join("")},templateNewLibraryInModal:function(){tmpl_array=[];tmpl_array.push('
');tmpl_array.push("
");tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push(' ');tmpl_array.push("
");tmpl_array.push("
");return tmpl_array.join("")},render:function(){$("#center").css("overflow","auto");var r=this;libraries=new o();libraries.fetch({success:function(s){var t=_.template(r.templateLibraryList(),{libraries:s.models});r.$el.html(t)},error:function(t,s){if(s.statusCode().status===403){n.info("Please log in first. Redirecting to login page in 3s.");setTimeout(r.redirectToLogin,3000)}else{n.error("An error occured. Please try again.")}}})},redirectToHome:function(){window.location="../"},redirectToLogin:function(){window.location="/user/login"},modal:null,show_library_modal:function(s){s.preventDefault();s.stopPropagation();var r=this;this.modal=new k.GalaxyModal({destructible:true,bindClosingEvents:true,title:"Create New Library",body:this.templateNewLibraryInModal(),buttons:{Create:function(){r.create_new_library_event()},Close:function(){r.modal.hideOrDestroy()}}});this.modal.show()},create_new_library_event:function(){var t=this.serialize_new_library();if(this.validate_new_library(t)){var s=new f();var r=this;s.save(t,{success:function(u){r.modal.hideOrDestroy();r.clear_library_modal();r.render();n.success("Library created")},error:function(){n.error("An error occured :(")}})}else{n.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(r){return r.name!==""}});var g=Backbone.View.extend({folderContentView:null,galaxyLibraryview:null,initialize:function(){folderContentView=new m();galaxyLibraryview=new a();library_router=new q();library_router.on("route:libraries",function(){galaxyLibraryview.render()});library_router.on("route:folder_content",function(r){folderContentView.render({id:r})});library_router.on("route:download",function(r,s){if($("#center").find(":checked").length===0){library_router.navigate("folders/"+r,{trigger:true,replace:true})}else{folderContentView.download(r,s);library_router.navigate("folders/"+r,{trigger:false,replace:true})}});Backbone.history.start();return this}});return{GalaxyApp:g}}); \ No newline at end of file diff --git a/static/scripts/packed/galaxy.modal.js b/static/scripts/packed/galaxy.modal.js index 255976e571d..56df506b7f7 100644 --- a/static/scripts/packed/galaxy.modal.js +++ b/static/scripts/packed/galaxy.modal.js @@ -1 +1 @@ -define([],function(){var a=Backbone.View.extend({elMain:"#everything",optionsDefault:{title:"galaxy-modal",body:"",backdrop:true,height:null,width:null},options:{destructible:false},initialize:function(b){self=this;if(b){this.create(b)}},hideOrDestroy:function(){if(this.options.destructible){self.destroy()}else{self.hide()}},bindEvents:function(){$(document).on("keyup",function(b){if(b.keyCode==27){self.hideOrDestroy()}});$("html").on("click",function(b){self.hideOrDestroy()});$(".modal-content").on("click",function(b){b.stopPropagation()})},unbindEvents:function(){$(document).off("keyup",function(b){if(b.keyCode==27){self.hideOrDestroy()}});$("html").off("click",function(b){self.hideOrDestroy()});$(".modal-content").off("click",function(b){b.stopPropagation()})},show:function(b){this.initialize(b);if(this.options.height){this.$body.css("height",this.options.height);this.$body.css("overflow","hidden")}else{this.$body.css("max-height",$(window).height()/2)}if(this.options.width){this.$dialog.css("width",this.options.width)}if(this.visible){this.$el.show()}else{this.$el.fadeIn("fast")}this.visible=true},hide:function(){this.$el.fadeOut("fast");this.visible=false;this.unbindEvents()},destroy:function(){this.visible=false;this.unbindEvents();this.$el.remove()},create:function(c){this.options=_.defaults(c,this.optionsDefault);if(this.options.body=="progress"){this.options.body=$('
')}if(this.$el){this.$el.remove()}this.setElement(this.template(this.options.title));this.$dialog=(this.$el).find(".modal-dialog");this.$body=(this.$el).find(".modal-body");this.$footer=(this.$el).find(".modal-footer");this.$buttons=(this.$el).find(".buttons");this.$backdrop=(this.$el).find(".modal-backdrop");this.$body.html(this.options.body);if(!this.options.backdrop){this.$backdrop.removeClass("in")}if(this.options.buttons){var b=this;$.each(this.options.buttons,function(d,e){b.$buttons.append($('').text(d).click(e)).append(" ")})}else{this.$footer.hide()}$(this.elMain).append($(this.el))},enableButton:function(b){this.$buttons.find("#"+String(b).toLowerCase()).prop("disabled",false)},disableButton:function(b){this.$buttons.find("#"+String(b).toLowerCase()).prop("disabled",true)},hideButton:function(b){this.$buttons.find("#"+String(b).toLowerCase()).hide()},showButton:function(b){this.$buttons.find("#"+String(b).toLowerCase()).show()},scrollTop:function(){return this.$body.scrollTop()},template:function(b){return'