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='',d='
'+(this.model.get("owner")===Galaxy.user.attributes.username?"You":this.model.get("owner"))+"
"+this.model.get("number_of_steps")+""+(this.model.get("published")?"Yes":"No")+""+c+"";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?'':''}}),e=Backbone.View.extend({title:"Workflows",initialize:function(){this.setElement("
"),_.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'
You have no workflows.
'},_templateActionButtons:function(){return''},_templateWorkflowTable:function(){var a='';return a+'

Drop workflow files here to import

NameTagsOwner# of StepsPublishedShow in tools panel
'},_templateHeader:function(){return'

Your workflows

'}}),f=Backbone.View.extend({initialize:function(){this.setElement("
"),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"
Import Galaxy workflow
If the workflow is accessible via a URL, enter the URL above and click Import.
If the workflow is in a file on your computer, choose it and then click Import.

Click the link above to visit myExperiment and browse for Galaxy workflows.
"}});return{View:e,ImportWorkflowView:f}}); //# sourceMappingURL=../../../maps/mvc/workflow/workflow.js.map