Files
galaxy/static/scripts/mvc/workflow/workflow.js
T

3 lines
8.8 KiB
JavaScript

"use strict";define(["libs/toastr","mvc/tag","mvc/workflow/workflow-model","utils/query-string-parsing"],function(o,e,t,r){var l=Backbone.View.extend({tagName:"tr",initialize:function(){_.bindAll(this,"render","_rowTemplate","renderTagEditor","_templateActions","removeWorkflow","copyWorkflow"),o.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 e=this.model.get("name");window.confirm("Are you sure you want to delete workflow '"+e+"'?")&&(this.model.destroy({success:function(){o.success("Successfully deleted workflow '"+e+"'")}}),this.remove())},renameWorkflow:function(){var e=this.model.get("name"),t=window.prompt("Enter a new Name for workflow '"+e+"'",e);t&&(this.model.save({name:t},{success:function(){o.success("Successfully renamed workflow '"+e+"' to '"+t+"'")}}),this.render())},copyWorkflow:function(){var e=this,t=this.model.get("name");$.getJSON(this.model.urlRoot+"/"+this.model.id+"/download",function(r){var l="Copy of "+t,i=e.model.get("owner");i!=Galaxy.user.attributes.username&&(l+=" shared by user "+i),r.name=l,e.collection.create(r,{at:0,wait:!0,success:function(){o.success("Successfully copied workflow '"+t+"' to '"+l+"'")},error:function(e,t,r){o.error(r.errorThrown)}})}).error(function(e,t,r){o.error(e.responseJSON.err_msg)})},_rowTemplate:function(){var o=this.model.get("show_in_tool_panel"),e=this.model.id,t='<input id="show-in-tool-panel" type="checkbox" class="show-in-tool-panel" '+(o?'checked="'+o+'"':"")+' value="'+e+'">';return'<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="'+e+' 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>"+t+"</td>"},renderTagEditor:function(){var o=new e.TagsEditor({model:this.model,el:$.find("."+this.model.id+".tags-display"),workflow_mode:!0});o.toggle(!0),o.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="+this.model.get("owner")+"&slug="+this.model.get("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>'}});return{View:Backbone.View.extend({title:"Workflows",initialize:function(){this.setElement("<div/>"),_.bindAll(this,"adjustActiondropdown"),this.collection=new t.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(o){$(".hidden_description_layer").addClass("dragover"),$(".menubutton").addClass("background-none"),o.preventDefault()}},unhighlightDropZone:function(){$(".hidden_description_layer").removeClass("dragover"),$(".menubutton").removeClass("background-none")},drop:function(o){this.unhighlightDropZone(),o.preventDefault();for(var e,t=o.dataTransfer.files,r=this,l=0;e=t[l];l++)r.readWorkflowFiles(e)},readWorkflowFiles:function(e){var t=this,r=new FileReader;r.onload=function(l){var i;try{i=JSON.parse(r.result)}catch(t){o.error("Could not read file '"+e.name+"'. Verify it is a valid Galaxy workflow"),i=null}i&&t.collection.create(i,{at:0,wait:!0,success:function(){o.success("Successfully imported workflow '"+i.name+"'")},error:function(e,t,r){o.error(r.errorThrown)}})},r.readAsText(e,"utf-8")},_showArgErrors:_.once(function(){var e=r.get("message");"error"===r.get("status")?o.error(_.escape(e||"Unknown Error, please report this to an administrator.")):e&&o.info(_.escape(e))}),render:function(){var o=this._templateHeader(),e=this._templateActionButtons(),t=this._templateWorkflowTable();this.$el.html(o+e+t);var r=this;_(this.collection.models).each(function(o){r.appendItem(o),r.confirmDelete(o)},this);return this.searchWorkflow(this.$(".search-wf"),this.$(".workflow-search tr"),3),this.adjustActiondropdown(),this._showArgErrors(),this},appendItem:function(o){var e=new l({model:o,collection:this.collection});$(".workflow-search").append(e.render().el),e.renderTagEditor()},confirmDelete:function(o){this.$(".link-confirm-shared-"+o.id).click(function(){return window.confirm("Are you sure you want to remove the shared workflow '"+o.attributes.name+"'?")})},searchWorkflow:function(o,e,t){o.on("keyup",function(){var o=$(this).val();if(o.length>=t){var r=new RegExp(o,"i");e.hide(),e.filter(function(){return r.test($(this).text())}).show()}else e.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(){return'<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><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>'}}),ImportWorkflowView:Backbone.View.extend({initialize:function(){this.setElement("<div/>"),this.render()},render:function(){var o=this;$.getJSON(Galaxy.root+"workflow/upload_import_workflow",function(e){o.$el.empty().append(o._mainTemplate(e))})},_mainTemplate:function(o){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='"+o.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='"+o.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>"}})}});
//# sourceMappingURL=../../../maps/mvc/workflow/workflow.js.map