text: YUI.add("wireit-app",function(e,t){function n(t){function i(e){var t;if(t=r[e])delete r[e],u();return t}function s(){var e="",t=4;while(t--)e+=((1+Math.random())*65536|0).toString(16).substring(1);return e}function o(t){return t?r[t]:e.Object.values(r)}function u(){n&&n.setItem(t,e.JSON.stringify(r))}function a(t){var n=t.toJSON(),i=t.idAttribute;return e.Lang.isValue(n[i])||(n[i]=s()),r[n[i]]=n,u(),n}var n;t||e.error("No storage key specified."),e.config.win.localStorage&&(n=e.config.win.localStorage);var r=e.JSON.parse(n&&n.getItem(t)||"{}");return function(t,n,r){var s=e.Model&&this instanceof e.Model;switch(t){case"create":case"update":r(null,a(this));return;case"read":r(null,o(s&&this.get("id")));return;case"delete":r(null,i(s&&this.get("id")));return}}}e.WiringModel=e.Base.create("wiringModel",e.Model,[],{sync:n("wireit-app")},{ATTRS:{id:{value:null},name:{value:""},containers:{value:[]},description:{value:""},wires:{value:[]}}}),e.WiringModelList=e.Base.create("wiringModelList",e.ModelList,[],{sync:n("wireit-app"),model:e.WiringModel}),e.WiringListView=e.Base.create("wiringListView",e.View,[],{template:e.Handlebars.compile(e.one("#t-wiring-list").getContent()),render:function(){var e=this.template({wirings:this.get("modelList").toJSON()});return this.get("container").setContent(e),this}}),e.ContainerType=e.Base.create("containerModel",e.Model,[],{idAttribute:"name"},{ATTRS:{name:{value:null},description:{value:null},config:{value:null}}}),e.ContainerTypeList=e.Base.create("containerTypeList",e.ModelList,[],{model:e.ContainerType}),e.EditorView=e.Base.create("editorView",e.View,[],{template:e.Handlebars.compile(e.one("#t-editor").getContent()),events:{"#wiring-save-btn":{click:"saveWiring"}},render:function(){var t=this.template({containerTypes:this.get("containerTypes").toJSON()});this.get("container").setContent(t);var n=this;return this.get("container").all(".containerType-name").each(function(t){var r=(new e.DD.Drag({node:t,groups:["containerType"]})).plug(e.Plugin.DDProxy,{cloneNode:!0,moveOnEnd:!1});r._containerTypeName=t._node.attributes["app-container-name"].value,r.on("drag:drophit",function(e){var t=n.layer.get("boundingBox").getXY();n._addContainerFromName(e.drag._containerTypeName,{x:e.drag.lastXY[0]-t[0],y:e.drag.lastXY[1]-t[1]})},this)}),this._renderLayer(),this},_renderLayer:function(){this.layer=new e.Layer({height:500});var t=new e.DD.Drop({node:this.layer.get("contentBox"),groups:["containerType"]});this.layer.render(this.get("container").one("#layer-container"));var n=this.get("model");n&&this.setWiring(n)},saveWiring:function(t){var n={name:e.one("#wiring-name").get("value")||"Unnamed"};n.containers=[],e.Array.each(this.layer._items,function(e){n.containers.push({containerType:e.containerTypeName,config:e.toJSON()})}),n.wires=[];var r=this.layer;e.Array.each(this.layer._wires,function(e){var t=e.get("src"),i=e.get("tgt");n.wires.push({src:{container:r._items.indexOf(t.get("parent")),terminal:t.get("name")},tgt:{container:r._items.indexOf(i.get("parent")),terminal:i.get("name")},config:e.toJSON()})}),this.get("model")?this.get("model").setAttrs(n):this.set("model",new e.WiringModel(n)),this.get("model").save();var i=e.Node.create('<div class="alert-message bg-warning" style="width: 300px; z-index: 10001;"><p>Saved !</p></div>').appendTo(document.body),s=new e.Anim({node:i,duration:.5,easing:e.Easing.easeOut,from:{xy:[400,-50]},to:{xy:[400,2]}});s.on("end",function(){e.later(1e3,this,function(){(new e.Anim({node:i,duration:.5,easing:e.Easing.easeOut,to:{xy:[400,-50]}})).run()})}),s.run()},setWiring:function(t){var n=this,r=this.layer;e.Array.each(t.get("containers"),function(r){n._addContainerFromName(r.containerType,r.config),e.on("available",function(n){e.one("#wiring-name").set("value",t.get("name"))},"#wiring-name")}),e.Array.each(t.get("wires"),function(t){if(!t.src||!t.tgt)return;var n=r.item(t.src.container),i=n.getTerminal(t.src.terminal),s=r.item(t.tgt.container),o=s.getTerminal(t.tgt.terminal),u=r.graphic.addShape({type:e.BezierWire,stroke:{weight:4,color:"rgb(173,216,230)"},src:i,tgt:o})}),e.later(200,this,function(){r.redrawAllWires()})},_addContainerFromName:function(t,n){var r=this.get("containerTypes").getById(t),i=e.mix({},r.get("config"));i=e.mix(i,n),this.layer.add(i);var s=this.layer.item(this.layer.size()-1);s.containerTypeName=t}},{ATTRS:{containerTypes:{value:null}}}),e.WireItApp=new e.Base.create("contributorsApp",e.App,[],{views:{editorPage:{type:e.EditorView},wiringListPage:{type:e.WiringListView}},initializer:function(){this.on("navigate",this.indicateLoading),this.once("ready",function(e){this.hasRoute(this.getPath())?this.dispatch():this.showWiringListPage()})},indicateLoading:function(e){this.get("activeView").get("container").addClass("loading")},handleWiring:function(e,t,n){var r=e.params.wiring,i=this.get("modelList"),s=i.getById(r);this.set("wiring",s),n()},showEditorPage:function(){this.showView("editorPage",{containerTypes:this.get("containerTypes"),wirings:this.get("modelList"),model:this.get("wiring")})},blankEditorPage:function(){this.showView("editorPage",{containerTypes:this.get("containerTypes"),wirings:this.get("modelList"),model:null})},showWiringListPage:function(){var t=new e.WiringModelList;t.load(),this.set("modelList",t),this.showView("wiringListPage",{modelList:this.get("modelList")})}},{ATTRS:{containerTypes:{value:new e.ContainerTypeList},modelList:{value:new e.WiringModelList},wiring:{value:null},routes:{value:[{path:"/",callback:"showWiringListPage"},{path:"/wirings/:wiring/*",callback:"handleWiring"},{path:"/wirings/:wiring/edit",callback:"showEditorPage"},{path:"/wirings/new",callback:"blankEditorPage"}]}}})},"@VERSION@",{requires:["app","handlebars","model","model-list","json","view","layer","bezier-wire","anim"]});
  