Files
galaxy/static/scripts/mvc/workflow/workflow.js
T
2017-09-08 12:31:54 -04:00

2 lines
8.6 KiB
JavaScript

define(["libs/toastr","mvc/tag","mvc/workflow/workflow-model"],function(a,b,c){var d=Backbone.View.extend({tagName:"tr",initialize:function(){_.bindAll(this,"render","_rowTemplate","renderTagEditor","_templateActions","removeWorkflow","copyWorkflow"),a.options.timeOut=1500},events:{"click #show-in-tool-panel":"showInToolPanel","click #delete-workflow":"removeWorkflow","click #rename-workflow":"renameWorkflow","click #copy-workflow":"copyWorkflow"},render:function(){return $(this.el).html(this._rowTemplate()),this},showInToolPanel:function(){this.model.set("show_in_tool_panel",!this.model.get("show_in_tool_panel")),this.model.save(),window.location=Galaxy.root+"workflow"},removeWorkflow:function(){var b=this.model.get("name");confirm("Are you sure you want to delete workflow '"+b+"'?")&&(this.model.destroy({success:function(){a.success("Successfully deleted workflow '"+b+"'")}}),this.remove())},renameWorkflow:function(){var b=this.model.get("name"),c=prompt("Enter a new Name for workflow '"+b+"'",b);c&&(this.model.save({name:c},{success:function(){a.success("Successfully renamed workflow '"+b+"' to '"+c+"'")}}),this.render())},copyWorkflow:function(){self=this;var b=this.model.get("name");$.getJSON(this.model.urlRoot+"/"+this.model.id+"/download",function(c){var d="Copy of "+b,e=self.model.get("owner");e!=Galaxy.user.attributes.username&&(d+=" shared by user "+e),c.name=d,self.collection.create(c,{at:0,wait:!0,success:function(){a.success("Successfully copied workflow '"+b+"' to '"+d+"'")},error:function(b,c,d){a.error(d.errorThrown)}})}).error(function(b){a.error(b.responseJSON.err_msg)})},_rowTemplate:function(){var a=this.model.get("show_in_tool_panel"),b=this.model.id,c='<input id="show-in-tool-panel" type="checkbox" class="show-in-tool-panel" '+(a?'checked="'+a+'"':"")+' value="'+b+'">',d='<td><div class="dropdown"><button class="menubutton" type="button" data-toggle="dropdown">'+_.escape(this.model.get("name"))+'<span class="caret"></span></button>'+this._templateActions()+'</div></td><td><span><div class="'+b+' tags-display"></div></td><td>'+(this.model.get("owner")===Galaxy.user.attributes.username?"You":this.model.get("owner"))+"</span></td><td>"+this.model.get("number_of_steps")+"</td><td>"+(this.model.get("published")?"Yes":"No")+"</td><td>"+c+"</td>";return d},renderTagEditor:function(){var a=new b.TagsEditor({model:this.model,el:$.find("."+this.model.id+".tags-display"),workflow_mode:!0});a.toggle(!0),a.render()},_templateActions:function(){return this.model.get("owner")===Galaxy.user.attributes.username?'<ul class="dropdown-menu action-dpd"><li><a href="'+Galaxy.root+"workflow/editor?id="+this.model.id+'">Edit</a></li><li><a href="'+Galaxy.root+"workflow/run?id="+this.model.id+'">Run</a></li><li><a href="'+Galaxy.root+"workflow/sharing?id="+this.model.id+'">Share</a></li><li><a href="'+Galaxy.root+"api/workflows/"+this.model.id+'/download?format=json-download">Download</a></li><li><a id="copy-workflow" style="cursor: pointer;">Copy</a></li><li><a id="rename-workflow" style="cursor: pointer;">Rename</a></li><li><a href="'+Galaxy.root+"workflow/display_by_id?id="+this.model.id+'">View</a></li><li><a id="delete-workflow" style="cursor: pointer;">Delete</a></li></ul>':'<ul class="dropdown-menu action-dpd"><li><a href="'+Galaxy.root+"workflow/display_by_username_and_slug?username="+workflow.owner+"&slug="+workflow.slug+'">View</a></li><li><a href="'+Galaxy.root+"workflow/run?id="+this.model.id+'">Run</a></li><li><a id="copy-workflow" style="cursor: pointer;">Copy</a></li><li><a class="link-confirm-shared-'+this.model.id+'" href="'+Galaxy.root+"workflow/sharing?unshare_me=True&id="+this.model.id+'">Remove</a></li></ul>'}}),e=Backbone.View.extend({title:"Workflows",initialize:function(){this.setElement("<div/>"),_.bindAll(this,"adjustActiondropdown"),this.collection=new c.WorkflowCollection,this.collection.fetch().done(this.render()),this.collection.bind("add",this.appendItem),this.collection.on("sync",this.render,this)},events:{dragleave:"unhighlightDropZone",drop:"drop",dragover:function(a){$(".hidden_description_layer").addClass("dragover"),$(".menubutton").addClass("background-none"),a.preventDefault()}},unhighlightDropZone:function(){$(".hidden_description_layer").removeClass("dragover"),$(".menubutton").removeClass("background-none")},drop:function(a){this.unhighlightDropZone(),a.preventDefault();for(var b,c=a.dataTransfer.files,d=this,e=0;b=c[e];e++)d.readWorkflowFiles(b)},readWorkflowFiles:function(b){var c=this,d=new FileReader;d.onload=function(){try{var e=JSON.parse(d.result)}catch(f){a.error("Could not read file '"+b.name+"'. Verify it is a valid Galaxy workflow"),e=null}e&&c.collection.create(e,{at:0,wait:!0,success:function(){a.success("Successfully imported workflow '"+e.name+"'")},error:function(b,c,d){a.error(d.errorThrown)}})},d.readAsText(b,"utf-8")},render:function(){var a=this._templateHeader(),b=this._templateActionButtons(),c=this._templateWorkflowTable();this.$el.html(a+b+c);var d=this;_(this.collection.models).each(function(a){d.appendItem(a),d.confirmDelete(a)},this);var e=3;return this.searchWorkflow(this.$(".search-wf"),this.$(".workflow-search tr"),e),this.adjustActiondropdown(),this},appendItem:function(a){var b=new d({model:a,collection:this.collection});$(".workflow-search").append(b.render().el),b.renderTagEditor()},confirmDelete:function(a){var b=this.$(".link-confirm-shared-"+a.id);b.click(function(){return confirm("Are you sure you want to remove the shared workflow '"+a.attributes.name+"'?")})},searchWorkflow:function(a,b,c){a.on("keyup",function(){var a=$(this).val();if(a.length>=c){var d=new RegExp(a,"i");b.hide(),b.filter(function(){return d.test($(this).text())}).show()}else b.show()})},adjustActiondropdown:function(){$(this.el).on("show.bs.dropdown",function(){$(this.el).css("overflow","inherit")}),$(this.el).on("hide.bs.dropdown",function(){$(this.el).css("overflow","auto")})},_templateNoWorkflow:function(){return'<div class="wf-nodata"> You have no workflows. </div>'},_templateActionButtons:function(){return'<ul class="manage-table-actions"><li><input class="search-wf form-control" type="text" autocomplete="off" placeholder="search for workflow..."></li><li><a class="action-button fa fa-plus wf-action" id="new-workflow" title="Create new workflow" href="'+Galaxy.root+'workflow/create"></a></li><li><a class="action-button fa fa-upload wf-action" id="import-workflow" title="Upload or import workflow" href="'+Galaxy.root+'workflow/import_workflow"></a></li></ul>'},_templateWorkflowTable:function(){var a='<table class="table colored"><thead><tr class="header"><th>Name</th><th>Tags</th><th>Owner</th><th># of Steps</th><th>Published</th><th>Show in tools panel</th></tr></thead>';return a+'<tbody class="workflow-search "><div class="hidden_description_layer"><p>Drop workflow files here to import</p></tbody></table></div>'},_templateHeader:function(){return'<div class="page-container"><div class="user-workflows wf"><div class="response-message"></div><h2>Your workflows</h2></div></div>'}}),f=Backbone.View.extend({initialize:function(){this.setElement("<div/>"),this.render()},render:function(){var a=this;$.getJSON(Galaxy.root+"workflow/upload_import_workflow",function(b){a.$el.empty().append(a._mainTemplate(b))})},_mainTemplate:function(a){return"<div class='toolForm'><div class='toolFormTitle'>Import Galaxy workflow</div><div class='toolFormBody'><form name='import_workflow' id='import_workflow' action='"+Galaxy.root+"workflow/upload_import_workflow' enctype='multipart/form-data' method='POST'><div class='form-row'><label>Galaxy workflow URL:</label><input type='text' name='url' class='input-url' value='"+a.url+"' size='40'><div class='toolParamHelp' style='clear: both;'>If the workflow is accessible via a URL, enter the URL above and click <b>Import</b>.</div><div style='clear: both'></div></div><div class='form-row'><label>Galaxy workflow file:</label><div class='form-row-input'><input type='file' name='file_data' class='input-file'/></div><div class='toolParamHelp' style='clear: both;'>If the workflow is in a file on your computer, choose it and then click <b>Import</b>.</div><div style='clear: both'></div></div><div class='form-row'><input type='submit' class='primary-button wf-import' name='import_button' value='Import'></div></form><hr/><div class='form-row'><label>Import a Galaxy workflow from myExperiment:</label><div class='form-row-input'><a href='"+a.myexperiment_target_url+"'> Visit myExperiment</a></div><div class='toolParamHelp' style='clear: both;'>Click the link above to visit myExperiment and browse for Galaxy workflows.</div><div style='clear: both'></div></div></div></div>"}});return{View:e,ImportWorkflowView:f}});
//# sourceMappingURL=../../../maps/mvc/workflow/workflow.js.map