mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
javascript library and modal refactoring, automatic even binding if flag provided
This commit is contained in:
@@ -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 )
|
||||
|
||||
@@ -122,7 +122,7 @@ var FolderContentView = Backbone.View.extend({
|
||||
|
||||
// CONTAINER
|
||||
tmpl_array.push('<div id="library_container" style="width: 90%; margin: auto; margin-top: 2em; ">');
|
||||
tmpl_array.push('<h3>New Data Libraries. This is work in progress. Report problems & ideas to <a href="mailto:marten@bx.psu.edu?Subject=DataLibraries_Feedback" target="_blank">Marten</a>.</h3>');
|
||||
tmpl_array.push('<h3>Data Libraries Beta Test. This is work in progress. Please report problems & ideas via <a href="mailto:galaxy-bugs@bx.psu.edu?Subject=DataLibrariesBeta_Feedback" target="_blank">email</a> and <a href="https://trello.com/c/nwYQNFPK/56-data-library-ui-progressive-display-of-folders" target="_blank">Trello</a>.</h3>');
|
||||
|
||||
// TOOLBAR
|
||||
tmpl_array.push('<div id="library_folder_toolbar" >');
|
||||
@@ -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
|
||||
$('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
|
||||
.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('<div id="library_container" style="width: 90%; margin: auto; margin-top: 2em; overflow: auto !important; ">');
|
||||
tmpl_array.push('');
|
||||
tmpl_array.push('<h3>New Data Libraries. This is work in progress. Report problems & ideas to <a href="mailto:marten@bx.psu.edu?Subject=DataLibraries_Feedback" target="_blank">Marten</a>.</h3>');
|
||||
tmpl_array.push('<h3>Data Libraries Beta Test. This is work in progress. Please report problems & ideas via <a href="mailto:galaxy-bugs@bx.psu.edu?Subject=DataLibrariesBeta_Feedback" target="_blank">email</a> and <a href="https://trello.com/c/nwYQNFPK/56-data-library-ui-progressive-display-of-folders" target="_blank">Trello</a>.</h3>');
|
||||
tmpl_array.push('<a href="" id="create_new_library_btn" class="btn btn-primary file ">New Library</a>');
|
||||
tmpl_array.push('<table class="table table-condensed">');
|
||||
tmpl_array.push(' <thead>');
|
||||
@@ -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();
|
||||
},
|
||||
|
||||
|
||||
@@ -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 = $('<div class="progress progress-striped active"><div class="progress-bar progress-bar-info" style="width:100%"></div></div>');
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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=$('<div class="progress progress-striped active"><div class="progress-bar progress-bar-info" style="width:100%"></div></div>')}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($('<button id="'+String(d).toLowerCase()+'"></button>').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'<div class="modal"><div class="modal-backdrop fade in" style="z-index: -1;"></div><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" style="display: none;">×</button><h4 class="title">'+b+'</h4></div><div class="modal-body"></div><div class="modal-footer"><div class="buttons" style="float: right;"></div></div></div</div></div>'}});return{GalaxyModal:a}});
|
||||
define([],function(){var a=Backbone.View.extend({elMain:"#everything",optionsDefault:{title:"galaxy-modal",body:"",backdrop:true,height:null,width:null},eventsBound:false,options:{destructible:false,bindClosingEvents:false},initialize:function(b){self=this;if(b){this.create(b)}},hideOrDestroy:function(){self.visible=false;self.unbindEvents();if(self.options.destructible){self.$el.remove()}else{self.hide()}},hide:function(){this.visible=false;this.$el.fadeOut("fast")},bindEvents:function(){$(document).on("keyup",function(b){if(b.keyCode==27){self.hideOrDestroy()}});$("html").on("click",self.hideOrDestroy);$(".modal-content").on("click",function(b){b.stopPropagation()});self.eventsBound=true},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()});self.eventsBound=false},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},create:function(c){this.options=_.defaults(c,this.optionsDefault);if(this.options.body=="progress"){this.options.body=$('<div class="progress progress-striped active"><div class="progress-bar progress-bar-info" style="width:100%"></div></div>')}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($('<button id="'+String(d).toLowerCase()+'"></button>').text(d).click(e)).append(" ")})}else{this.$footer.hide()}$(this.elMain).append($(this.el));if(this.options.bindClosingEvents&&!this.eventsBound){this.bindEvents()}},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'<div class="modal"><div class="modal-backdrop fade in" style="z-index: -1;"></div><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" style="display: none;">×</button><h4 class="title">'+b+'</h4></div><div class="modal-body"></div><div class="modal-footer"><div class="buttons" style="float: right;"></div></div></div</div></div>'}});return{GalaxyModal:a}});
|
||||
Reference in New Issue
Block a user