define(["mvc/workflow/workflow-connector"],function(a){function b(a,b){this.app=a,this.canvas_container=b,this.id_counter=0,this.nodes={},this.name=null,this.has_changes=!1,this.active_form_has_changes=!1}return $.extend(b.prototype,{create_node:function(a,b,c){var d=this.app.prebuildNode(a,b,c);return this.add_node(d),this.fit_canvas_to_nodes(),this.app.canvas_manager.draw_overview(),this.activate_node(d),d},add_node:function(a){a.id=this.id_counter,a.element.attr("id","wf-node-step-"+a.id),this.id_counter++,this.nodes[a.id]=a,this.has_changes=!0,a.workflow=this},remove_node:function(a){this.active_node==a&&this.clear_active_node(),delete this.nodes[a.id],this.has_changes=!0},remove_all:function(){wf=this,$.each(this.nodes,function(a,b){b.destroy(),wf.remove_node(b)})},rectify_workflow_outputs:function(){var a=!1,b=!1;if($.each(this.nodes,function(c,d){d.workflow_outputs&&d.workflow_outputs.length>0&&(a=!0),$.each(d.post_job_actions,function(a,c){"HideDatasetAction"===c.action_type&&(b=!0)})}),a!==!1||b!==!1){var c=this;$.each(this.nodes,function(b,d){if("tool"===d.type){var e=!1;null==d.post_job_actions&&(d.post_job_actions={},e=!0);var f=[];$.each(d.post_job_actions,function(a,b){"HideDatasetAction"==b.action_type&&f.push(a)}),f.length>0&&$.each(f,function(a,b){e=!0,delete d.post_job_actions[b]}),a&&$.each(d.output_terminals,function(a,b){var c=!0;if($.each(d.workflow_outputs,function(a,d){b.name===d&&(c=!1)}),c===!0){e=!0;var f={action_type:"HideDatasetAction",output_name:b.name,action_arguments:{}};d.post_job_actions["HideDatasetAction"+b.name]=null,d.post_job_actions["HideDatasetAction"+b.name]=f}}),c.active_node==d&&e===!0&&c.reload_active_node()}})}},to_simple:function(){var a={};return $.each(this.nodes,function(b,c){var d={};$.each(c.input_terminals,function(a,b){d[b.name]=null;var c=[];$.each(b.connectors,function(a,e){c[a]={id:e.handle1.node.id,output_name:e.handle1.name},d[b.name]=c})});var e={};c.post_job_actions&&$.each(c.post_job_actions,function(a,b){var c={action_type:b.action_type,output_name:b.output_name,action_arguments:b.action_arguments};e[b.action_type+b.output_name]=null,e[b.action_type+b.output_name]=c}),c.workflow_outputs||(c.workflow_outputs=[]);var f={id:c.id,type:c.type,tool_id:c.tool_id,tool_state:c.tool_state,tool_errors:c.tool_errors,input_connections:d,position:$(c.element).position(),annotation:c.annotation,post_job_actions:c.post_job_actions,uuid:c.uuid,label:c.label,workflow_outputs:c.workflow_outputs};a[c.id]=f}),{steps:a}},from_simple:function(b){wf=this;var c=0;wf.name=b.name;var d=!1;$.each(b.steps,function(a,b){var e=wf.app.prebuildNode(b.type,b.name,b.tool_id);e.init_field_data(b),b.position&&e.element.css({top:b.position.top,left:b.position.left}),e.id=b.id,wf.nodes[e.id]=e,c=Math.max(c,parseInt(a)),d||"tool"!==e.type||(e.workflow_outputs.length>0?d=!0:$.each(e.post_job_actions,function(a,b){"HideDatasetAction"===b.action_type&&(d=!0)}))}),wf.id_counter=c+1,$.each(b.steps,function(b,c){var e=wf.nodes[b];$.each(c.input_connections,function(b,c){c&&($.isArray(c)||(c=[c]),$.each(c,function(c,d){var f=wf.nodes[d.id],g=new a;g.connect(f.output_terminals[d.output_name],e.input_terminals[b]),g.redraw()}))}),d&&"tool"===e.type&&$.each(e.output_terminals,function(a,b){void 0===e.post_job_actions["HideDatasetAction"+b.name]&&(e.workflow_outputs.push(b.name),callout=$(e.element).find(".callout."+b.name),callout.find("img").attr("src",galaxy_config.root+"static/images/fugue/asterisk-small.png"),wf.has_changes=!0)})})},check_changes_in_active_form:function(){this.active_form_has_changes&&(this.has_changes=!0,$("#right-content").find("form").submit(),this.active_form_has_changes=!1)},reload_active_node:function(){if(this.active_node){var a=this.active_node;this.clear_active_node(),this.activate_node(a)}},clear_active_node:function(){this.active_node&&(this.active_node.make_inactive(),this.active_node=null),this.app.showToolForm("