1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/10bf4bbcc3fa/ Changeset: 10bf4bbcc3fa User: guerler Date: 2014-09-26 15:39:32+00:00 Summary: ToolForm: Add wait modal and error modal Affected #: 12 files diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 client/galaxy/scripts/mvc/tools/tools-form.js --- a/client/galaxy/scripts/mvc/tools/tools-form.js +++ b/client/galaxy/scripts/mvc/tools/tools-form.js @@ -24,6 +24,13 @@ // link this var self = this; + // link galaxy modal or create one + if (parent.Galaxy && parent.Galaxy.modal) { + this.modal = parent.Galaxy.modal; + } else { + this.modal = new Ui.Modal.View(); + } + // link options this.options = options; diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 client/galaxy/scripts/mvc/tools/tools-jobs.js --- a/client/galaxy/scripts/mvc/tools/tools-jobs.js +++ b/client/galaxy/scripts/mvc/tools/tools-jobs.js @@ -32,23 +32,41 @@ console.debug('tools-jobs::submit - Submission canceled. Validation failed.'); return; } - console.log(job_def); + + // debug + console.debug(job_def); + + // show progress modal + this.app.modal.show({title: 'Please wait...', body: 'progress'}); // post job Utils.request('POST', galaxy_config.root + 'api/tools', job_def, // success handler function(response) { + self.app.modal.hide(); self.app.message(ToolTemplate.success(response)); self._refreshHdas(); }, // error handler - function(response) { - console.debug(response); + function(response, response_full) { + self.app.modal.hide(); if (response && response.message && response.message.data) { var error_messages = self.app.tree.matchResponse(response.message.data); for (var input_id in error_messages) { self._foundError(input_id, error_messages[input_id]); } + } else { + // show modal with error message + self.app.modal.show({ + title: response_full.statusText, + body: ToolTemplate.error(job_def), + closing_events: true, + buttons: { + 'Close': function() { + self.app.modal.hide(); + } + } + }); } } ); diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 client/galaxy/scripts/mvc/tools/tools-template.js --- a/client/galaxy/scripts/mvc/tools/tools-template.js +++ b/client/galaxy/scripts/mvc/tools/tools-template.js @@ -40,6 +40,17 @@ return tmpl; }, + error: function(job_def) { + return '<div>' + + '<p>' + + 'Sorry, the server could not complete the request. Please contact the Galaxy Team if this error is persistent.' + + '</p>' + + '<textarea class="ui-textarea" disabled style="color: black;" rows="6">' + + JSON.stringify(job_def, undefined, 4) + + '</textarea>' + + '</div>'; + }, + batchMode: function() { return '<div class="ui-table-form-info">' + '<i class="fa fa-sitemap" style="font-size: 1.2em; padding: 2px 5px;"/>' + diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 client/galaxy/scripts/utils/utils.js --- a/client/galaxy/scripts/utils/utils.js +++ b/client/galaxy/scripts/utils/utils.js @@ -13,6 +13,12 @@ // generic function to send json to url function request (method, url, data, success, error) { + // configure + var ajaxConfig = { + url : url, + type : method, + 'contentType' : 'application/json' + } // encode data into url if (method == 'GET' || method == 'DELETE') { @@ -22,40 +28,25 @@ url += '&'; } url += $.param(data) + } else { + ajaxConfig['data'] = JSON.stringify(data); + ajaxConfig['dataType'] = 'json'; } - // prepare request - var xhr = new XMLHttpRequest(); - xhr.open(method, url, true); - xhr.setRequestHeader('Accept', 'application/json'); - xhr.setRequestHeader('Cache-Control', 'no-cache'); - xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); - xhr.setRequestHeader('Content-Type', 'application/json'); - xhr.onloadend = function() { - // get status - var status = xhr.status; - - // read response + // make request + $.ajax(ajaxConfig) + .done(function(response) { + success && success(response); + }) + .fail(function(response) { + var response_text = null; try { - response = jQuery.parseJSON(xhr.responseText); + response_text = jQuery.parseJSON(response.responseText); } catch (e) { - response = xhr.responseText; + response_text = response.responseText; } - - // parse response - if (status == 200) { - success && success(response); - } else { - error && error(response); - } - }; - - // make request - if (method == 'GET' || method == 'DELETE') { - xhr.send(); - } else { - xhr.send(JSON.stringify(data)); - } + error && error(response_text, response); + }); }; // get css value diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 static/scripts/mvc/tools/tools-form.js --- a/static/scripts/mvc/tools/tools-form.js +++ b/static/scripts/mvc/tools/tools-form.js @@ -24,6 +24,13 @@ // link this var self = this; + // link galaxy modal or create one + if (parent.Galaxy && parent.Galaxy.modal) { + this.modal = parent.Galaxy.modal; + } else { + this.modal = new Ui.Modal.View(); + } + // link options this.options = options; diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 static/scripts/mvc/tools/tools-jobs.js --- a/static/scripts/mvc/tools/tools-jobs.js +++ b/static/scripts/mvc/tools/tools-jobs.js @@ -32,23 +32,41 @@ console.debug('tools-jobs::submit - Submission canceled. Validation failed.'); return; } - console.log(job_def); + + // debug + console.debug(job_def); + + // show progress modal + this.app.modal.show({title: 'Please wait...', body: 'progress'}); // post job Utils.request('POST', galaxy_config.root + 'api/tools', job_def, // success handler function(response) { + self.app.modal.hide(); self.app.message(ToolTemplate.success(response)); self._refreshHdas(); }, // error handler - function(response) { - console.debug(response); + function(response, response_full) { + self.app.modal.hide(); if (response && response.message && response.message.data) { var error_messages = self.app.tree.matchResponse(response.message.data); for (var input_id in error_messages) { self._foundError(input_id, error_messages[input_id]); } + } else { + // show modal with error message + self.app.modal.show({ + title: response_full.statusText, + body: ToolTemplate.error(job_def), + closing_events: true, + buttons: { + 'Close': function() { + self.app.modal.hide(); + } + } + }); } } ); diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 static/scripts/mvc/tools/tools-template.js --- a/static/scripts/mvc/tools/tools-template.js +++ b/static/scripts/mvc/tools/tools-template.js @@ -40,6 +40,17 @@ return tmpl; }, + error: function(job_def) { + return '<div>' + + '<p>' + + 'Sorry, the server could not complete the request. Please contact the Galaxy Team if this error is persistent.' + + '</p>' + + '<textarea class="ui-textarea" disabled style="color: black;" rows="6">' + + JSON.stringify(job_def, undefined, 4) + + '</textarea>' + + '</div>'; + }, + batchMode: function() { return '<div class="ui-table-form-info">' + '<i class="fa fa-sitemap" style="font-size: 1.2em; padding: 2px 5px;"/>' + diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 static/scripts/packed/mvc/tools/tools-form.js --- a/static/scripts/packed/mvc/tools/tools-form.js +++ b/static/scripts/packed/mvc/tools/tools-form.js @@ -1,1 +1,1 @@ -define(["mvc/ui/ui-portlet","mvc/ui/ui-misc","mvc/citation/citation-model","mvc/citation/citation-view","mvc/tools","mvc/tools/tools-template","mvc/tools/tools-datasets","mvc/tools/tools-section","mvc/tools/tools-tree","mvc/tools/tools-jobs"],function(h,l,j,a,f,d,i,k,c,g){var e=Backbone.Model.extend({initialize:function(m){this.url=galaxy_config.root+"api/tools/"+m.id+"?io_details=true"}});var b=Backbone.View.extend({container:"body",initialize:function(n){var m=this;this.options=n;this.setElement("<div/>");$(this.container).append(this.$el);this.model=new e({id:n.id});this.tree=new c(this);this.job_handler=new g(this);this.field_list={};this.input_list={};this.element_list={};this.datasets=new i({history_id:this.options.history_id,success:function(){m._initializeToolForm()}})},message:function(m){$(this.container).empty();$(this.container).append(m)},reset:function(){for(var m in this.element_list){this.element_list[m].reset()}},refresh:function(){this.tree.refresh();for(var m in this.field_list){this.field_list[m].trigger("change")}console.debug("tools-form::refresh() - Recreated tree structure. Refresh.")},_initializeToolForm:function(){var n=this;var o=new l.ButtonIcon({icon:"fa-question-circle",title:"Question?",tooltip:"Ask a question about this tool (Biostar)",onclick:function(){window.open(n.options.biostar_url+"/p/new/post/")}});var p=new l.ButtonIcon({icon:"fa-search",title:"Search",tooltip:"Search help for this tool (Biostar)",onclick:function(){window.open(n.options.biostar_url+"/t/"+n.options.id+"/")}});var m=new l.ButtonIcon({icon:"fa-share",title:"Share",tooltip:"Share this tool",onclick:function(){prompt("Copy to clipboard: Ctrl+C, Enter",galaxy_config.root+"root?tool_id="+n.options.id)}});this.model.fetch({error:function(q){console.debug("tools-form::_initializeToolForm() : Attempt to fetch tool model failed.")},success:function(){n.inputs=n.model.get("inputs");n.portlet=new h.View({icon:"fa-wrench",title:"<b>"+n.model.get("name")+"</b> "+n.model.get("description"),buttons:{execute:new l.ButtonIcon({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",floating:"clear",onclick:function(){n.job_handler.submit()}})},operations:{button_question:o,button_search:p,button_share:m}});if(!n.options.biostar_url){o.$el.hide();p.$el.hide()}n.$el.append(n.portlet.$el);if(n.options.help!=""){n.$el.append(d.help(n.options.help))}if(n.options.citations){n.$el.append(d.citations());var q=new j.ToolCitationCollection();q.tool_id=n.options.id;var r=new a.CitationListView({collection:q});r.render();q.fetch()}n.setElement(n.portlet.content());n.section=new k.View(n,{inputs:n.model.get("inputs"),cls:"ui-table-plain"});n.portlet.append(n.section.$el);n.refresh()}})}});return{View:b}}); \ No newline at end of file +define(["mvc/ui/ui-portlet","mvc/ui/ui-misc","mvc/citation/citation-model","mvc/citation/citation-view","mvc/tools","mvc/tools/tools-template","mvc/tools/tools-datasets","mvc/tools/tools-section","mvc/tools/tools-tree","mvc/tools/tools-jobs"],function(h,l,j,a,f,d,i,k,c,g){var e=Backbone.Model.extend({initialize:function(m){this.url=galaxy_config.root+"api/tools/"+m.id+"?io_details=true"}});var b=Backbone.View.extend({container:"body",initialize:function(n){var m=this;if(parent.Galaxy&&parent.Galaxy.modal){this.modal=parent.Galaxy.modal}else{this.modal=new l.Modal.View()}this.options=n;this.setElement("<div/>");$(this.container).append(this.$el);this.model=new e({id:n.id});this.tree=new c(this);this.job_handler=new g(this);this.field_list={};this.input_list={};this.element_list={};this.datasets=new i({history_id:this.options.history_id,success:function(){m._initializeToolForm()}})},message:function(m){$(this.container).empty();$(this.container).append(m)},reset:function(){for(var m in this.element_list){this.element_list[m].reset()}},refresh:function(){this.tree.refresh();for(var m in this.field_list){this.field_list[m].trigger("change")}console.debug("tools-form::refresh() - Recreated tree structure. Refresh.")},_initializeToolForm:function(){var n=this;var o=new l.ButtonIcon({icon:"fa-question-circle",title:"Question?",tooltip:"Ask a question about this tool (Biostar)",onclick:function(){window.open(n.options.biostar_url+"/p/new/post/")}});var p=new l.ButtonIcon({icon:"fa-search",title:"Search",tooltip:"Search help for this tool (Biostar)",onclick:function(){window.open(n.options.biostar_url+"/t/"+n.options.id+"/")}});var m=new l.ButtonIcon({icon:"fa-share",title:"Share",tooltip:"Share this tool",onclick:function(){prompt("Copy to clipboard: Ctrl+C, Enter",galaxy_config.root+"root?tool_id="+n.options.id)}});this.model.fetch({error:function(q){console.debug("tools-form::_initializeToolForm() : Attempt to fetch tool model failed.")},success:function(){n.inputs=n.model.get("inputs");n.portlet=new h.View({icon:"fa-wrench",title:"<b>"+n.model.get("name")+"</b> "+n.model.get("description"),buttons:{execute:new l.ButtonIcon({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",floating:"clear",onclick:function(){n.job_handler.submit()}})},operations:{button_question:o,button_search:p,button_share:m}});if(!n.options.biostar_url){o.$el.hide();p.$el.hide()}n.$el.append(n.portlet.$el);if(n.options.help!=""){n.$el.append(d.help(n.options.help))}if(n.options.citations){n.$el.append(d.citations());var q=new j.ToolCitationCollection();q.tool_id=n.options.id;var r=new a.CitationListView({collection:q});r.render();q.fetch()}n.setElement(n.portlet.content());n.section=new k.View(n,{inputs:n.model.get("inputs"),cls:"ui-table-plain"});n.portlet.append(n.section.$el);n.refresh()}})}});return{View:b}}); \ No newline at end of file diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 static/scripts/packed/mvc/tools/tools-jobs.js --- a/static/scripts/packed/mvc/tools/tools-jobs.js +++ b/static/scripts/packed/mvc/tools/tools-jobs.js @@ -1,1 +1,1 @@ -define(["utils/utils","mvc/tools/tools-template"],function(b,a){return Backbone.Model.extend({initialize:function(d,c){this.app=d;this.options=b.merge(c,this.optionsDefault)},submit:function(){var c=this;var d={tool_id:this.app.options.id,inputs:this.app.tree.finalize()};this.app.reset();if(!this._validation(d)){console.debug("tools-jobs::submit - Submission canceled. Validation failed.");return}console.log(d);b.request("POST",galaxy_config.root+"api/tools",d,function(e){c.app.message(a.success(e));c._refreshHdas()},function(e){console.debug(e);if(e&&e.message&&e.message.data){var g=c.app.tree.matchResponse(e.message.data);for(var f in g){c._foundError(f,g[f])}}})},_foundError:function(c,d){var e=this.app.element_list[c];e.error(d||"Please verify this parameter.");if(this.valid){$(this.app.container).animate({scrollTop:e.$el.offset().top-20},500);this.valid=false}},_validation:function(g){var c=g.inputs;this.valid=true;var k=-1;for(var i in c){var e=c[i];var j=this.app.tree.match(i);var d=this.app.field_list[j];var h=this.app.input_list[j];if(h&&!h.optional&&d&&d.validate&&!d.validate()){this._foundError(j)}if(e.batch){var f=e.values.length;if(k===-1){k=f}else{if(k!==f){this._foundError(j,"Please make sure that you select the same number of inputs for all batch mode fields. This field contains <b>"+f+"</b> selection(s) while a previous field contains <b>"+k+"</b>.")}}}}return this.valid},_refreshHdas:function(){if(parent.Galaxy&&parent.Galaxy.currHistoryPanel){parent.Galaxy.currHistoryPanel.refreshContents()}}})}); \ No newline at end of file +define(["utils/utils","mvc/tools/tools-template"],function(b,a){return Backbone.Model.extend({initialize:function(d,c){this.app=d;this.options=b.merge(c,this.optionsDefault)},submit:function(){var c=this;var d={tool_id:this.app.options.id,inputs:this.app.tree.finalize()};this.app.reset();if(!this._validation(d)){console.debug("tools-jobs::submit - Submission canceled. Validation failed.");return}console.debug(d);this.app.modal.show({title:"Please wait...",body:"progress"});b.request("POST",galaxy_config.root+"api/tools",d,function(e){c.app.modal.hide();c.app.message(a.success(e));c._refreshHdas()},function(e,g){c.app.modal.hide();if(e&&e.message&&e.message.data){var h=c.app.tree.matchResponse(e.message.data);for(var f in h){c._foundError(f,h[f])}}else{c.app.modal.show({title:g.statusText,body:a.error(d),closing_events:true,buttons:{Close:function(){c.app.modal.hide()}}})}})},_foundError:function(c,d){var e=this.app.element_list[c];e.error(d||"Please verify this parameter.");if(this.valid){$(this.app.container).animate({scrollTop:e.$el.offset().top-20},500);this.valid=false}},_validation:function(g){var c=g.inputs;this.valid=true;var k=-1;for(var i in c){var e=c[i];var j=this.app.tree.match(i);var d=this.app.field_list[j];var h=this.app.input_list[j];if(h&&!h.optional&&d&&d.validate&&!d.validate()){this._foundError(j)}if(e.batch){var f=e.values.length;if(k===-1){k=f}else{if(k!==f){this._foundError(j,"Please make sure that you select the same number of inputs for all batch mode fields. This field contains <b>"+f+"</b> selection(s) while a previous field contains <b>"+k+"</b>.")}}}}return this.valid},_refreshHdas:function(){if(parent.Galaxy&&parent.Galaxy.currHistoryPanel){parent.Galaxy.currHistoryPanel.refreshContents()}}})}); \ No newline at end of file diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 static/scripts/packed/mvc/tools/tools-template.js --- a/static/scripts/packed/mvc/tools/tools-template.js +++ b/static/scripts/packed/mvc/tools/tools-template.js @@ -1,1 +1,1 @@ -define([],function(){return{help:function(a){return'<div class="toolHelp"><div class="toolHelpBody">'+a+"</div></div>"},citations:function(){return'<div id="citations"></div>'},success:function(c){var a=c.jobs.length;var d="";if(a==1){d="1 job has"}else{d=a+" jobs have been"}var b='<div class="donemessagelarge"><p>'+d+" been successfully added to the queue - resulting in the following datasets:</p>";for(var e in c.outputs){b+='<p style="padding: 10px 20px;"><b>'+(parseInt(e)+1)+": "+c.outputs[e].name+"</b></p>"}b+="<p>You can check the status of queued jobs and view the resulting data by refreshing the History pane. When the job has been run the status will change from 'running' to 'finished' if completed successfully or 'error' if problems were encountered.</p></div>";return b},batchMode:function(){return'<div class="ui-table-form-info"><i class="fa fa-sitemap" style="font-size: 1.2em; padding: 2px 5px;"/>This is a batch mode input field. A separate job will be triggered for each dataset.';"</div>"}}}); \ No newline at end of file +define([],function(){return{help:function(a){return'<div class="toolHelp"><div class="toolHelpBody">'+a+"</div></div>"},citations:function(){return'<div id="citations"></div>'},success:function(c){var a=c.jobs.length;var d="";if(a==1){d="1 job has"}else{d=a+" jobs have been"}var b='<div class="donemessagelarge"><p>'+d+" been successfully added to the queue - resulting in the following datasets:</p>";for(var e in c.outputs){b+='<p style="padding: 10px 20px;"><b>'+(parseInt(e)+1)+": "+c.outputs[e].name+"</b></p>"}b+="<p>You can check the status of queued jobs and view the resulting data by refreshing the History pane. When the job has been run the status will change from 'running' to 'finished' if completed successfully or 'error' if problems were encountered.</p></div>";return b},error:function(a){return'<div><p>Sorry, the server could not complete the request. Please contact the Galaxy Team if this error is persistent.</p><textarea class="ui-textarea" disabled style="color: black;" rows="6">'+JSON.stringify(a,undefined,4)+"</textarea></div>"},batchMode:function(){return'<div class="ui-table-form-info"><i class="fa fa-sitemap" style="font-size: 1.2em; padding: 2px 5px;"/>This is a batch mode input field. A separate job will be triggered for each dataset.';"</div>"}}}); \ No newline at end of file diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 static/scripts/packed/utils/utils.js --- a/static/scripts/packed/utils/utils.js +++ b/static/scripts/packed/utils/utils.js @@ -1,1 +1,1 @@ -define(["libs/underscore"],function(j){function d(l,m,k){g("GET",l,{},m,k)}function g(p,l,m,o,k){if(p=="GET"||p=="DELETE"){if(l.indexOf("?")==-1){l+="?"}else{l+="&"}l+=$.param(m)}var n=new XMLHttpRequest();n.open(p,l,true);n.setRequestHeader("Accept","application/json");n.setRequestHeader("Cache-Control","no-cache");n.setRequestHeader("X-Requested-With","XMLHttpRequest");n.setRequestHeader("Content-Type","application/json");n.onloadend=function(){var q=n.status;try{response=jQuery.parseJSON(n.responseText)}catch(r){response=n.responseText}if(q==200){o&&o(response)}else{k&&k(response)}};if(p=="GET"||p=="DELETE"){n.send()}else{n.send(JSON.stringify(m))}}function h(n,k){var l=$('<div class="'+n+'"></div>');l.appendTo(":eq(0)");var m=l.css(k);l.remove();return m}function f(k){if(!$('link[href^="'+k+'"]').length){$('<link href="'+galaxy_config.root+k+'" rel="stylesheet">').appendTo("head")}}function i(k,l){if(k){return j.defaults(k,l)}else{return l}}function b(l,n){var m="";if(l>=100000000000){l=l/100000000000;m="TB"}else{if(l>=100000000){l=l/100000000;m="GB"}else{if(l>=100000){l=l/100000;m="MB"}else{if(l>=100){l=l/100;m="KB"}else{if(l>0){l=l*10;m="b"}else{return"<strong>-</strong>"}}}}}var k=(Math.round(l)/10);if(n){return k+" "+m}else{return"<strong>"+k+"</strong> "+m}}function a(){return"x"+Math.random().toString(36).substring(2,9)}function c(k){var l=$("<p></p>");l.append(k);return l}function e(){var m=new Date();var k=(m.getHours()<10?"0":"")+m.getHours();var l=(m.getMinutes()<10?"0":"")+m.getMinutes();var n=m.getDate()+"/"+(m.getMonth()+1)+"/"+m.getFullYear()+", "+k+":"+l;return n}return{cssLoadFile:f,cssGetAttribute:h,get:d,merge:i,bytesToString:b,uuid:a,time:e,wrap:c,request:g}}); \ No newline at end of file +define(["libs/underscore"],function(j){function d(l,m,k){g("GET",l,{},m,k)}function g(p,m,n,o,l){var k={url:m,type:p,contentType:"application/json"};if(p=="GET"||p=="DELETE"){if(m.indexOf("?")==-1){m+="?"}else{m+="&"}m+=$.param(n)}else{k.data=JSON.stringify(n);k.dataType="json"}$.ajax(k).done(function(q){o&&o(q)}).fail(function(r){var q=null;try{q=jQuery.parseJSON(r.responseText)}catch(s){q=r.responseText}l&&l(q,r)})}function h(n,k){var l=$('<div class="'+n+'"></div>');l.appendTo(":eq(0)");var m=l.css(k);l.remove();return m}function f(k){if(!$('link[href^="'+k+'"]').length){$('<link href="'+galaxy_config.root+k+'" rel="stylesheet">').appendTo("head")}}function i(k,l){if(k){return j.defaults(k,l)}else{return l}}function b(l,n){var m="";if(l>=100000000000){l=l/100000000000;m="TB"}else{if(l>=100000000){l=l/100000000;m="GB"}else{if(l>=100000){l=l/100000;m="MB"}else{if(l>=100){l=l/100;m="KB"}else{if(l>0){l=l*10;m="b"}else{return"<strong>-</strong>"}}}}}var k=(Math.round(l)/10);if(n){return k+" "+m}else{return"<strong>"+k+"</strong> "+m}}function a(){return"x"+Math.random().toString(36).substring(2,9)}function c(k){var l=$("<p></p>");l.append(k);return l}function e(){var m=new Date();var k=(m.getHours()<10?"0":"")+m.getHours();var l=(m.getMinutes()<10?"0":"")+m.getMinutes();var n=m.getDate()+"/"+(m.getMonth()+1)+"/"+m.getFullYear()+", "+k+":"+l;return n}return{cssLoadFile:f,cssGetAttribute:h,get:d,merge:i,bytesToString:b,uuid:a,time:e,wrap:c,request:g}}); \ No newline at end of file diff -r 95bcb99ad2b467ca0176a1e5e747bb18cd3cc61f -r 10bf4bbcc3fa0ade8b325aa814b21655c3b33ba1 static/scripts/utils/utils.js --- a/static/scripts/utils/utils.js +++ b/static/scripts/utils/utils.js @@ -13,6 +13,12 @@ // generic function to send json to url function request (method, url, data, success, error) { + // configure + var ajaxConfig = { + url : url, + type : method, + 'contentType' : 'application/json' + } // encode data into url if (method == 'GET' || method == 'DELETE') { @@ -22,40 +28,25 @@ url += '&'; } url += $.param(data) + } else { + ajaxConfig['data'] = JSON.stringify(data); + ajaxConfig['dataType'] = 'json'; } - // prepare request - var xhr = new XMLHttpRequest(); - xhr.open(method, url, true); - xhr.setRequestHeader('Accept', 'application/json'); - xhr.setRequestHeader('Cache-Control', 'no-cache'); - xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); - xhr.setRequestHeader('Content-Type', 'application/json'); - xhr.onloadend = function() { - // get status - var status = xhr.status; - - // read response + // make request + $.ajax(ajaxConfig) + .done(function(response) { + success && success(response); + }) + .fail(function(response) { + var response_text = null; try { - response = jQuery.parseJSON(xhr.responseText); + response_text = jQuery.parseJSON(response.responseText); } catch (e) { - response = xhr.responseText; + response_text = response.responseText; } - - // parse response - if (status == 200) { - success && success(response); - } else { - error && error(response); - } - }; - - // make request - if (method == 'GET' || method == 'DELETE') { - xhr.send(); - } else { - xhr.send(JSON.stringify(data)); - } + error && error(response_text, response); + }); }; // get css value 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.