define("mvc/workflow/workflow-globals",{}),define(["utils/utils","mvc/workflow/workflow-globals","mvc/workflow/workflow-manager","mvc/workflow/workflow-canvas","mvc/workflow/workflow-node","mvc/tools/tools-form-workflow"],function(a,b,c,d,e,f){return Backbone.View.extend({initialize:function(a){function c(){h.workflow.layout(),h.workflow.fit_canvas_to_nodes(),h.scroll_to_nodes(),h.canvas_manager.draw_overview()}function e(){h.workflow.clear_active_node(),$(".right-content").hide(),$("#edit-attributes").show()}function f(){$.jStorage.set("overview-off",!1),$("#overview-border").css("right","0px"),$("#close-viewport").css("background-position","0px 0px")}function g(){$.jStorage.set("overview-off",!0),$("#overview-border").css("right","20000px"),$("#close-viewport").css("background-position","12px 0px")}var h=b.app=this;this.options=a,this.urls=a&&a.urls||{},this.active_ajax_call=!1;var i=function(){h.workflow.check_changes_in_active_form(),workflow&&h.workflow.has_changes?(do_close=function(){window.onbeforeunload=void 0,window.document.location=h.urls.workflow_index},window.show_modal("Close workflow editor","There are unsaved changes to your workflow which will be lost.",{Cancel:hide_modal,"Save Changes":function(){j(null,do_close)}},{"Don't Save":do_close})):window.document.location=h.urls.workflow_index},j=function(a,b){if(show_message("Saving workflow","progress"),h.workflow.check_changes_in_active_form(),!h.workflow.has_changes)return hide_modal(),void(b&&b());h.workflow.rectify_workflow_outputs();var c=function(a){$.ajax({url:h.urls.save_workflow,type:"POST",data:{id:h.options.id,workflow_data:function(){return JSON.stringify(h.workflow.to_simple())},_:"true"},dataType:"json",success:function(b){var c=$("
");$.each(b.errors,function(a,b){$("").text(b).appendTo(d)}),c.append(d)}else c.addClass("donemark");h.workflow.name=b.name,h.workflow.has_changes=!1,h.workflow.stored=!0,h.showWorkflowParameters(),b.errors?window.show_modal("Saving workflow",c,{Ok:hide_modal}):(a&&a(),hide_modal())}})};h.active_ajax_call?$(document).bind("ajaxStop.save_workflow",function(){$(document).unbind("ajaxStop.save_workflow"),c(),$(document).unbind("ajaxStop.save_workflow"),h.active_ajax_call=!1}):c(b)};if(window.lt_ie_7)return void window.show_modal("Browser not supported","Sorry, the workflow editor is not supported for IE6 and below.");$("#tool-search-query").click(function(){$(this).focus(),$(this).select()}).keyup(function(){if($(this).css("font-style","normal"),this.value.length<3)reset_tool_search(!1);else if(this.value!=this.lastValue){$(this).addClass("search_active");var a=this.value;this.timer&&clearTimeout(this.timer),$("#search-spinner").show(),this.timer=setTimeout(function(){$.get(h.urls.tool_search,{q:a},function(a){if($("#search-no-results").hide(),$(".toolSectionWrapper").hide(),$(".toolSectionWrapper").find(".toolTitle").hide(),0!=a.length){var b=$.map(a,function(a){return"link-"+a});$(b).each(function(a,b){$("[id='"+b+"']").parent().addClass("search_match"),$("[id='"+b+"']").parent().show().parent().parent().show().parent().show()}),$(".toolPanelLabel").each(function(){for(var a=$(this),b=a.next(),c=!0;0!==b.length&&b.hasClass("toolTitle");){if(b.is(":visible")){c=!1;break}b=b.next()}c&&a.hide()})}else $("#search-no-results").show();$("#search-spinner").hide()},"json")},400)}this.lastValue=this.value}),this.canvas_manager=b.canvas_manager=new d(this,$("#canvas-viewport"),$("#overview")),this.reset(),this.datatypes=JSON.parse($.ajax({url:galaxy_config.root+"api/datatypes",async:!1}).responseText),this.datatypes_mapping=JSON.parse($.ajax({url:galaxy_config.root+"api/datatypes/mapping",async:!1}).responseText),this.ext_to_type=this.datatypes_mapping.ext_to_class_name,this.type_to_type=this.datatypes_mapping.class_to_classes,$.ajax({url:h.urls.load_workflow,data:{id:h.options.id,_:"true"},dataType:"json",cache:!1,success:function(a){h.reset(),h.workflow.from_simple(a),h.workflow.has_changes=!1,h.workflow.fit_canvas_to_nodes(),h.scroll_to_nodes(),h.canvas_manager.draw_overview(),upgrade_message="",$.each(a.upgrade_messages,function(a,b){upgrade_message+="
"}),upgrade_message?window.show_modal("Workflow loaded with changes","Problems were encountered loading this workflow (possibly a result of tool upgrades). Please review the following parameters and then save.
"+upgrade_message+"
",{Continue:hide_modal}):hide_modal(),h.showWorkflowParameters()},beforeSubmit:function(){show_message("Loading workflow","progress")}}),$(document).ajaxStart(function(){h.active_ajax_call=!0,$(document).bind("ajaxStop.global",function(){h.active_ajax_call=!1})}),$(document).ajaxError(function(a,b){var c=b.responseText||b.statusText||"Could not connect to server";return window.show_modal("Server error",c,{"Ignore error":hide_modal}),!1}),window.make_popupmenu&&make_popupmenu($("#workflow-options-button"),{Save:j,Run:function(){window.location=h.urls.run_workflow},"Edit Attributes":e,"Auto Re-layout":c,Close:i}),overview_size=$.jStorage.get("overview-size"),void 0!==overview_size&&$("#overview-border").css({width:overview_size,height:overview_size}),$.jStorage.get("overview-off")?g():f(),$("#overview-border").bind("dragend",function(a,b){var c=$(this).offsetParent(),d=c.offset(),e=Math.max(c.width()-(b.offsetX-d.left),c.height()-(b.offsetY-d.top));$.jStorage.set("overview-size",e+"px")}),$("#close-viewport").click(function(){"0px"===$("#overview-border").css("right")?g():f()}),window.onbeforeunload=function(){return workflow&&h.workflow.has_changes?"There are unsaved changes to your workflow which will be lost.":void 0},$("div.toolSectionBody").hide(),$("div.toolSectionTitle > span").wrap("");var k=null;$("div.toolSectionTitle").each(function(){var a=$(this).next("div.toolSectionBody");$(this).click(function(){a.is(":hidden")?(k&&k.slideUp("fast"),k=a,a.slideDown("fast")):(a.slideUp("fast"),k=null)})}),window.async_save_text&&(async_save_text("workflow-name","workflow-name",h.urls.rename_async,"new_name"),$("#workflow-tag").click(function(){return $(".tag-area").click(),!1}),async_save_text("workflow-annotation","workflow-annotation",h.urls.annotate_async,"new_annotation",25,!0,4))},reset:function(){this.workflow&&this.workflow.remove_all(),this.workflow=b.workflow=new c(this,$("#canvas-container"))},scroll_to_nodes:function(){var a,b,c=$("#canvas-viewport"),d=$("#canvas-container");b=d.width().toolForm:last>.toolFormTitle>.buttons").click(function(){action_to_rem=$(this).closest(".toolForm",".action_tag").children(".action_tag:first").text(),$(this).closest(".toolForm").remove(),delete c.workflow.active_node.post_job_actions[action_to_rem],c.workflow.active_form_has_changes=!0})},display_pja_list:function(){return pja_list},display_file_list:function(a){addlist="",addlist},new_pja:function(a,b,c){if(void 0===c.post_job_actions&&(c.post_job_actions={}),void 0===c.post_job_actions[a+b]){var d={};return d.action_type=a,d.output_name=b,c.post_job_actions[a+b]=null,c.post_job_actions[a+b]=d,display_pja(d,c),this.workflow.active_form_has_changes=!0,!0}return!1},showWorkflowParameters:function(){var a=/\$\{.+?\}/g,b=[],c=$("#workflow-parameters-container"),d=$("#workflow-parameters-box"),e="",f=[];$.each(this.workflow.nodes,function(c,d){var e=d.form_html.match(a);e&&(f=f.concat(e)),d.post_job_actions&&($.each(d.post_job_actions,function(b,c){c.action_arguments&&$.each(c.action_arguments,function(b,c){var d=c.match(a);d&&(f=f.concat(d))})}),f&&$.each(f,function(a,c){-1===$.inArray(c,b)&&b.push(c)}))}),b&&0!==b.length?($.each(b,function(a,b){e+="