$(function(){var l,n=!(obj={schema_add:function(){Strack.open_dialog("dialog",{title:StrackLang.Add_Schema,width:480,height:350,content:Strack.dialog_dom({type:"normal",items:[{case:1,id:"Nname",lang:StrackLang.Name,name:"name",valid:"1,128",value:""},{case:1,id:"Ncode",lang:StrackLang.Code,name:"code",valid:"1,128",value:""},{case:2,id:"Ntype",lang:StrackLang.Type,name:"type",valid:"1",value:""},{case:2,id:"Nschema",lang:StrackLang.Copy_Schema,name:"id",valid:"",value:""}],footer:[{obj:"schema_add_submit",type:1,title:StrackLang.Submit},{obj:"dialog_cancel",type:8,title:StrackLang.Cancel}]}),inits:function(){Strack.combobox_widget("#Ntype",{url:SchemaPHP.getSchemaTypeCombobox,valueField:"id",textField:"name"}),Strack.combobox_widget("#Nschema",{url:SchemaPHP.getSchemaCombobox,valueField:"id",textField:"name"})},close:function(){o()}})},schema_add_submit:function(){Strack.ajax_dialog_form("#st_dialog_form .dialog-widget-val","",SchemaPHP.addSchema,{back:function(e){200===parseInt(e.status)?(Strack.dialog_cancel(),obj.schema_right_hide(),Strack.top_message({bg:"g",msg:e.message})):layer.msg(e.message,{icon:7,time:1200,anim:6})}})},schema_modify:function(){var e=$("#hide_schema_id").val(),a=$("#hide_schema_name").val(),t=$("#hide_schema_code").val();Strack.open_dialog("dialog",{title:StrackLang.Modify_Schema,width:480,height:240,content:Strack.dialog_dom({type:"normal",hidden:[{case:101,id:"Minfo_id",type:"hidden",name:"id",valid:1,value:e}],items:[{case:1,id:"name",lang:StrackLang.Name,name:"name",valid:"1,128",value:a},{case:1,id:"code",lang:StrackLang.Code,name:"code",valid:"1,128",value:t}],footer:[{obj:"schema_modify_submit",type:1,title:StrackLang.Update},{obj:"dialog_cancel",type:8,title:StrackLang.Cancel}]}),close:function(){o()}})},schema_modify_submit:function(){Strack.ajax_dialog_form("#st_dialog_form .dialog-widget-val","",SchemaPHP.modifySchema,{back:function(e){200===parseInt(e.status)?(Strack.dialog_cancel(),Strack.top_message({bg:"g",msg:e.message})):layer.msg(e.message,{icon:7,time:1200,anim:6})}},{extra:function(e){return $("#hide_schema_name").val(e.name),$("#hide_schema_code").val(e.code),e}})},schema_delete:function(){var a=$("#hide_schema_id").val();0<a?$.messager.confirm(StrackLang.Confirmation_Box,StrackLang.Delete_Schema_Notice,function(e){e&&$.ajax({type:"POST",url:SchemaPHP.deleteSchema,dataType:"json",data:{schema_id:a},success:function(e){200===parseInt(e.status)?(o(),obj.schema_right_hide(),Strack.top_message({bg:"g",msg:e.message})):layer.msg(e.message,{icon:7,time:1200,anim:6})}})}):layer.msg(StrackPHP.Please_Select_One,{icon:2,time:1200,anim:6})},select_schema:function(e){obj.schema_right_show();var a,t=$(e).attr("data-schemaid"),o=$(e).attr("data-name"),i=$(e).attr("data-code");$("#hide_schema_id").val(t),$("#hide_schema_name").val(o),$("#hide_schema_code").val(i),$(".templates-items").removeClass("templates-active"),$(e).parent().addClass("templates-active"),a=t,$.ajax({type:"POST",url:SchemaPHP.getSchemaModuleList,dataType:"json",data:{schema_id:a},beforeSend:function(){$("#module_wrap").append(Strack.loading_dom("white","","module"))},success:function(a){var c,o="";["entity","fixed"].forEach(function(e){o+='<li class="module-items-title">'+e+"</li>",a.module_list[e]&&a.module_list[e].forEach(function(e){var a,t;o+=(t="",t+='<li id="module_'+(a=e).id+'" class="nation-items" data-moduleid ="'+a.id+'" data-modulecode ="'+a.code+'" data-moduletype="'+a.type+'" data-icon ="'+a.icon+'" data-name ="'+a.name+'"><div class="nation-items-wrap min"><div class="aign-left"><i class="'+a.icon+' icon-left"></i><span>'+a.name+"</span></div></div></li>")})}),$("#module_list").empty().append(o),$("#st-load_module").remove(),n&&(jsPlumb.empty("schema_graph"),l=null),c=a.schema_list,$("#schema_graph").append('<div class="jtk-demo-canvas"><div class="controls"><i class="fa icon-uniF047 selected-mode" mode="pan" title="Pan Mode"></i><i class="fa icon-uniE684" mode="select" title="Select Mode"></i><i class="fa  icon-uniE9AD" reset title="Zoom To Fit"></i></div><div class="miniview"></div></div>'),jsPlumb.ready(function(){var e=document.querySelector("#schema_graph"),a=e.querySelector(".jtk-demo-canvas"),t=e.querySelector(".miniview"),o=document.querySelector("#module_list"),i=e.querySelector(".controls");l=jsPlumbToolkit.newInstance({idFunction:function(e){return e.id},typeFunction:function(e){return e.type},nodeFactory:function(e,a,t){a.type="module",a.text=e.module_name,a.module_id=e.module_id,a.module_code=e.module_code,a.module_type=e.module_type,a.id=jsPlumbToolkitUtil.uuid(),t(a)},beforeStartConnect:function(e,a){return!("start"===e.data.type&&0<e.getEdges().length)&&{label:"..."}}});function n(a,e){if(a.source.id!==a.target.id){Strack.build_dialog("dialog");var t="";0<=$.inArray(a.data.label,["has_one","belong_to","has_many","many_to_many"])&&(t=a.data.label),$("#dialog").dialog({title:StrackLang.Schema_Link_Type,width:460,height:220,closed:!1,cache:!1,modal:!0,closable:!1,content:Strack.dialog_dom({type:"normal",items:[{case:1,id:"Mschema_link_type",type:"text",lang:StrackLang.Type,name:"link_type",valid:1,value:t}],footer:[]}),onOpen:function(){Strack.combobox_widget("#Mschema_link_type",{url:SchemaPHP.getSchemaConnectType,valueField:"id",textField:"name"})},onClose:function(){$(this).dialog("destroy")},buttons:[{text:StrackLang.Save,handler:function(){var e=$("#Mschema_link_type").combobox("getValue");0<e.length?(l.updateEdge(a,{label:e||""}),Strack.dialog_cancel()):layer.msg(StrackLang.Please_Select_One,{icon:2,time:1200,anim:6})}},{text:StrackLang.Delete,handler:function(){Strack.dialog_cancel(),l.removeEdge(a)}},{text:StrackLang.Cancel,handler:function(){var e=$("#Mschema_link_type").combobox("getValue");0<e.length?l.updateEdge(a,{label:e||""}):l.removeEdge(a),Strack.dialog_cancel()}}]})}else l.removeEdge(a)}var d=window.renderer=l.render({container:a,view:{nodes:{selectable:{events:{tap:function(e){l.toggleSelection(e.node)}}},module:{parent:"selectable",template:"tmplModule"}},edges:{default:{anchor:"AutoDefault",endpoint:"Blank",connector:["Flowchart",{cornerRadius:5}],paintStyle:{strokeWidth:2,stroke:"#f76258",outlineWidth:3,outlineStroke:"transparent"},hoverPaintStyle:{strokeWidth:2,stroke:"rgb(67,67,67)"},events:{dblclick:function(e){jsPlumbToolkit.Dialogs.show({id:"dlgConfirm",data:{msg:"Delete Edge"},onOK:function(){l.removeEdge(e.edge)}})}},overlays:[["Arrow",{location:1,width:10,length:10}],["Arrow",{location:.3,width:10,length:10}]]},connection:{parent:"default",overlays:[["Label",{label:"${label}",events:{click:function(e){n(e.edge)}}}]]}},ports:{start:{edgeType:"default"},source:{maxConnections:-1,edgeType:"connection"},target:{maxConnections:-1,isTarget:!0,dropOptions:{hoverClass:"connection-drop"}}}},layout:{type:"Absolute"},events:{canvasClick:function(e){l.clearSelection()},edgeAdded:function(e){e.addedByMouse&&n(e.edge)},nodeDropped:function(e){console.log("node ",e.source.id,"dropped on ",e.target.id)}},miniview:{container:t},lassoInvert:!0,elementsDroppable:!0,consumeRightClick:!1,dragOptions:{filter:".jtk-draw-handle, .node-action, .node-action i",magnetize:!0},dropManager:!0});l.load({data:c}),d.bind("modeChanged",function(e){jsPlumb.removeClass(i.querySelectorAll("[mode]"),"selected-mode"),jsPlumb.addClass(i.querySelectorAll("[mode='"+e+"']"),"selected-mode")}),jsPlumb.on(i,"tap","[mode]",function(){d.setMode(this.getAttribute("mode"))}),jsPlumb.on(i,"tap","[reset]",function(){l.clearSelection(),d.zoomToFit()}),new jsPlumbToolkit.DrawingTools({renderer:d}),jsPlumb.on(a,"tap",".node-delete",function(){var e=d.getObjectInfo(this);l.removeNode(e.obj)}),d.registerDroppableNodes({droppables:o.querySelectorAll("li.nation-items"),dragOptions:{zIndex:5e4,cursor:"move",clone:!0},typeExtractor:function(e){return{module_id:e.getAttribute("data-moduleid"),module_code:e.getAttribute("data-modulecode"),module_type:e.getAttribute("data-moduletype"),module_icon:e.getAttribute("data-icon"),module_name:e.getAttribute("data-name")}},dataGenerator:function(e){return{w:120,h:80}}})}),n=!0}})},schema_save:function(){var t,o=$("#hide_schema_id").val(),e=l.getGraph().vertices,i=[],n=[];e.forEach(function(a){(t=a.getEdges()).forEach(function(e){e.source.id===a.data.id?(i.push({schema_id:o,module_id:a.data.module_id,type:e.data.label,src_module_id:a.data.module_id,dst_module_id:e.target.data.module_id,link_id:1,node_config:{node_data:{source:a.data,target:e.target.data},edges:{source:e.source.id,target:e.target.id,data:{label:e.data.label,type:e.data.type}}}}),n.push(a.data.module_id),n.push(e.target.data.module_id)):t.length<=1&&$.inArray(a.data.module_id,n)<0&&i.push({schema_id:o,module_id:a.data.module_id,type:e.data.label,src_module_id:a.data.module_id,dst_module_id:e.target.data.module_id,link_id:1,node_config:{node_data:{source:a.data,target:e.target.data},edges:{}}})})}),0<i.length?$.ajax({type:"POST",url:SchemaPHP.saveModuleRelation,dataType:"json",contentType:"application/json",data:JSON.stringify({schema_id:o,schema_data:i}),success:function(e){Strack.top_message({bg:"g",msg:e.message})}}):layer.msg(StrackLang.Please_Select_Module,{icon:7,time:1200,anim:6})},schema_filter:function(){var e=$("#search_val").val(),a="";0<e.length&&(a=e),o(a)},schema_right_hide:function(){$(".structure-m-list").hide(),$(".structure-m-wrap").hide(),$(".temp-setlist-no").show(),$(".templates-items").removeClass("templates-active")},schema_right_show:function(){$(".structure-m-list").show(),$(".structure-m-wrap").show(),$(".temp-setlist-no").hide()}});function o(e){$.ajax({type:"POST",url:SchemaPHP.getSchemaList,dataType:"json",data:{filter:e},beforeSend:function(){$("#schema_list").empty().append(Strack.loading_dom("null"))},success:function(e){var o="",a=$("#schema_list"),t=$("#hide_schema_id").val();e.forEach(function(e){var a,t;o+=(t="",t+='<li id="sinfo_id_'+(a=e).id+'" class="templates-items" ><a href="javascript:;" class="list-item" onclick="obj.select_schema(this);" data-schemaid="'+a.id+'" data-name="'+a.name+'" data-code="'+a.code+'">'+a.name+"</a></li>")}),o?($("#schema_null_notice").remove(),a.append(o)):0===$("#schema_null_notice").length&&a.before('<div id="schema_null_notice" class="datagrid-empty-no">'+StrackLang.Datagird_No_Data+"</div>"),0<t&&$("#sinfo_id_"+t).addClass("templates-active"),$("#st-load").remove()}})}o(),Strack.listen_keyboard_event(function(e,a){"enter"===a.code&&$("#search_val").is(":focus")&&(e.preventDefault(),obj.schema_filter(Strack.get_obj_by_id("search_schema_bnt")))})});