/******************************************** * 后台管理 - 资源编目 * *******************************************/ //控制器:ResCatalogController //----------------------------------------- //F0 标签窗口初始化 //F1.排序界面初始化 //F2.资源排序界面初始化 //F3.新增子集界面 //F4.编目调整方法 //F5.页面初始化 //F6.删除方法 //F7.新增同级方法 //F8.修改界面方法 //F9.提交面目修改方法 //F10.目录新增方法 //F11.资源调整,子树初始化方法 //F12.资源位置调整界面 //F13.资源位置调整方法 //F14 初始化资源排序列表 //------------------------------------------ //F0 标签窗口初始化 var f_node_def = function () { var div = $("#tabContent"); var actionkeep = "BasicInfo"; var _VIEW = 0, _EDIT = 1, _AddBrother = 2, _AddSon = 3; var mode = _VIEW; this.setId = function (id) {//设置区域ID,点击树节点时触发 muluid = id; this.onTab(); }; //切换页签的方法 this.onTab = function (action, params) { isTop(); var url = ""; var myaction = actionkeep; if (action != null) { actionkeep = action; } if (mode == _EDIT) { myaction = actionkeep + "_Editor"; } else if (mode == _AddBrother) { myaction = actionkeep + "_AddBrother"; } else if (mode == _AddSon) { myaction = actionkeep + "_AddSon"; } else { myaction = actionkeep; } if (action == "Sort") { var id = document.getElementById("muluid").value; initPaiXu(); $("#tabContent2").show(); $("#tabContent").css("display", "none"); $("#tabContent3").css("display", "none"); } if (action == "BasicInfo") { $("#tabContent").show(); $("#tabContent2").css("display", "none"); $("#tabContent3").css("display", "none"); } if (action == "ZiYuanSort") { var id = document.getElementById("muluid").value; initZyPaiXu(); $("#tabContent3").show(); $("#tabContent").css("display", "none"); $("#tabContent2").css("display", "none"); } }; //返回按钮绑定事件 this.forView = function (id) { $("#btnAddBrother").css("display", ""); $("#btnAddSon").css("display", ""); $("#btnEdit").css("display", ""); $("#btnReturn").css("display", "none"); $("#btnDelete").css("display", "none"); $("#divTabs2").css("display", "none"); $("#divTabs").css("display", ""); $("#tabSort").css("display", ""); $("#ZiYuanSort").css("display", ""); $("#tabRight").css("display", ""); $("#tabOther").css("display", ""); $("#btnMerge").css("display", ""); $("#tabBasicInfo").html("查看"); $("#tabContent").show(); $("#tabContent1").css("display", "none"); if (id != null) { muluid = id; } mode = _VIEW; this.onTab(); }; //判断是否根目录 function isTop() { if (mode != _VIEW) return; if ($("muluid").val() == "" || $("muluid").val() == "0") { $("#btnAddBrother").css("display", "none"); $("#btnEdit").css("display", "none"); } else { $("#btnAddBrother").css("display", ""); $("#btnEdit").css("display", ""); } } }; //对象初始化 var f_node = new f_node_def(); //F1 排序界面初始化 function initPaiXu() { var Tree = document.getElementById("OrderTree"); var id = document.getElementById("muluid").value; Tree.innerHTML = ""; $.ajax({ type: 'post', url: 'initsort', data: {id: id}, success: function (data) { var json = data; Tree.size = json.count; var List = json.children; for (i = 0; i < List.length; i++) { Tree.innerHTML+="
  • " + "" + "" + List[i].name + "" + ""; } }, error: function (data) { alert("未知错误"); window.location = window.location; } }); } //F2 资源排序界面初始化 function initZyPaiXu() { var Tree = document.getElementById("ZyOrderTree"); var id = document.getElementById("muluid").value; Tree.innerHTML = ""; $.ajax({ type: 'post', url: 'initzysort', data: {id: id}, success: function (data) { var json = data; Tree.size = json.count; var List = json.children; for (i = 0; i < List.length; i++) { Tree.innerHTML += "
  • " + "" + "" + List[i].name + "" + ""; } }, error: function (data) { alert("未知错误"); window.location = window.location; } }); } //F3 新增子集界面 function Add() { $("#tabBasicInfo").click() $("#btnAddBrother").css("display", "none"); $("#btnAddSon").css("display", "none"); $("#btnEdit").css("display", "none"); $("#btnReturn").css("display", ""); $("#btnDelete").css("display", "none"); $("#tabSort").css("display", "none"); $("#ZiYuanSort").css("display", "none"); $("#tabRight").css("display", "none"); $("#tabOther").css("display", "none"); $("#tabBasicInfo").html("增加"); $("#tabContent1").show(); $("#tabContent").css("display", "none"); $("#butSave").css("display", ""); $("#butEdit").css("display", "none"); var id = $("#muluid").val(); if (id == "") id = 0; $.ajax({ type: 'post', url: 'addchildren', data: {id: id}, success: function (data) { var json = eval("(" + data + ")"); $("#afname").val(json.name); $("#afid").val(json.id); $("#abianma").val(json.oId); $("#amingzi").val(""); $("#firstZM").val(""); $("#ashuoming").val(""); $("#abeizhu").val(""); $("#aicon").val(""); }, error: function (data) { alert("请选择目标父级"); window.location = window.location; } }); } //F4 编目调整方法 function Sort() { var id = ""; var list = $("#OrderTree li"); for (var i = 0; i < list.length; i++) { if (i > 0) id += "|"; id += list[i].getAttribute("resourceid"); } var Tree = document.getElementById("OrderTree"); var pid = document.getElementById("muluid").value; $.ajax({ type: 'post', url: 'sort', data: {id: id, pid: pid}, success: function (data) { var json = data; Tree.innerHTML = ""; Tree.size = json.count; var List = json.children; for (i = 0; i < List.length; i++) { Tree.innerHTML += "
  • " + "" + "" + List[i].name + "" + ""; } alert("排序成功!"); }, error: function (data) { alert("未知错误"); window.location = window.location; } }); } //F5 资源调整方法 function ZySort() { var ids = ""; var list = $("#ZyOrderTree li"); for (var i = 0; i < list.length; i++) { if (i > 0) ids += "|"; ids += list[i].getAttribute("resourceid"); } var Tree = document.getElementById("ZyOrderTree"); var pid = document.getElementById("muluid").value; $.ajax({ type: 'post', url: 'zysort', data: {ids: ids, pid: pid}, success: function (data) { var json = data; Tree.innerHTML = ""; //Tree.size = json.count; var List = json.children; for (i = 0; i < List.length; i++) { Tree.innerHTML += "
  • " + "" + "" + List[i].name + "" + ""; } alert("排序成功!"); }, error: function (data) { alert("未知错误"); window.location = window.location; } }); } //F6 删除方法 function Delete() { var id = $("#muluid").val(); $.ajax({ type: 'post', url: 'isDelete', data: {id: id}, success: function (data) { if(data == "-1") { if(confirm("该目录下存在资源,删除该目录将会删除该目录下的资源,是否确定删除?")) { $.ajax({ type: 'post', url: 'delete', data: {id: id}, success: function (data) { alert(data); window.location = window.location; } }) } } else { alert(data); window.location = window.location; } } }) } //F7 新增同级方法 function AddBrother() { $("#tabBasicInfo").click() $("#btnAddBrother").css("display", "none"); $("#btnAddSon").css("display", "none"); $("#btnEdit").css("display", "none"); $("#btnReturn").css("display", ""); $("#btnDelete").css("display", "none"); $("#tabSort").css("display", "none"); $("#ZiYuanSort").css("display", "none"); $("#tabRight").css("display", "none"); $("#tabOther").css("display", "none"); $("#tabBasicInfo").html("增加"); $("#tabContent1").show(); $("#tabContent").css("display", "none"); $("#butSave").css("display", ""); $("#butEdit").css("display", "none"); var id = $("#muluid").val(); if (id == "") id = 0; $.ajax({ type: 'post', url: 'addbrother', data: {id: id}, success: function (data) { var json = eval("(" + data + ")"); $("#afname").val(json.name); $("#afid").val(json.pId); $("#abianma").val(json.oId); $("#amingzi").val(""); $("#firstZM").val(""); $("#ashuoming").val(""); $("#abeizhu").val(""); $("#aicon").val(""); }, error: function (data) { alert("请选择目标父级"); window.location = window.location; } }); } //F8 修改界面方法 function Edit() { var div = $("#tabContent"); $("#tabBasicInfo").click() $("#btnAddBrother").css("display", "none"); $("#btnAddSon").css("display", "none"); $("#btnEdit").css("display", "none"); $("#btnReturn").css("display", ""); $("#btnDelete").css("display", "none"); $("#tabSort").css("display", "none"); $("#ZiYuanSort").css("display", "none"); $("#tabRight").css("display", "none"); $("#tabOther").css("display", "none"); $("#tabBasicInfo").html("修改"); $("#tabContent1").show(); $("#tabContent").css("display", "none"); $("#butSave").css("display", "none"); $("#butEdit").css("display", ""); var id = $("#muluid").val(); $.ajax({ type: 'post', url: 'edit', data: {id: id}, dataType: 'json', success: function (data) { // var json = eval("(" + data + ")"); var json = data.result; $("#afname").val(json.fname); $("#aid").val(json.id); $("#afid").val(json.Pid); $("#abianma").val(json.oId); $("#amingzi").val(json.name); $("#firstZM").val(json.firstPY); $("#ashuoming").val(json.descrip); if (json.remark != "null") { $("#abeizhu").val(json.remark); } if (json.icon != "null"&&json.icon!="") { $("#aicon").val(json.icon); $("#photo").attr("src","/uploadPath/"+json.icon); } }, error: function (data) { //alert("error"); alert(data); } }); } //F9 提交面目修改方法 function Editpost() { if (form2.valid()) { var image = $('#uploadInput')[0].files[0]; if (image != null) { var formdata = new FormData(); formdata.append('myFile', $('#uploadInput')[0].files[0]); $.ajax({ url: "/res/testuploadimg", type: "POST", data: formdata, cache: false, async: false, processData: false, // 告诉jQuery不要去处理发送的数据 contentType: false, // 告诉jQuery不要去设置Content-Type请求头 success: function (data) { if (data == -1) { alert("文件格式不正确,请重新上传!"); } else if (data == 0) { alert("上传图片失败"); } else { $("#aicon").val(data); jQuery('#formBasicInfo').ajaxSubmit({ url: 'saveedit', type: 'post', success: function (data) { alert(data); window.location = window.location; } }) } } }) } else{ jQuery('#formBasicInfo').ajaxSubmit({ url: 'saveedit', type: 'post', success: function (data) { alert(data); window.location = window.location; } }) } } } //F10 目录新增方法 function Insert() { if (form2.valid()) { var image = $('#uploadInput')[0].files[0]; if (image != null) { var formdata = new FormData(); formdata.append('myFile', $('#uploadInput')[0].files[0]); $.ajax({ url: "/res/testuploadimg", type: "POST", data: formdata, cache: false, async: false, processData: false, // 告诉jQuery不要去处理发送的数据 contentType: false, // 告诉jQuery不要去设置Content-Type请求头 success: function (data) { if (data == -1) { alert("文件格式不正确,请重新上传!"); } else if (data == 0) { alert("上传图片失败"); } else { $("#aicon").val(data); jQuery('#formBasicInfo').ajaxSubmit({ url: 'insert', type: 'post', success: function (data) { alert(data); window.location = window.location; } }); } } }) } else{ jQuery('#formBasicInfo').ajaxSubmit({ url: 'insert', type: 'post', success: function (data) { alert(data); window.location = window.location; } }); } } } //F11 资源调整,子树初始化方法 function initSonTree() { var setting1 = { view: { selectedMulti: false }, check: { enable: true }, data: { simpleData: { enable: true } }, callback: { //点击节点 //onClick: onClick, //展开节点 //onExpand: onExpand, //拖动结束之前 //beforeDrop: beforeDrop, //拖动结束 //onDrop: onDrop }, async: { enable: true, url: 'selectmuluandziyuan', autoParam: ["id"] }, edit: { enable: true, showRemoveBtn: false, showRenameBtn: false, drag: { autoExpandTrigger: true, isCopy: false, isMove: true, prev: true, next: true, inner: true, borderMax: 20, borderMin: -10, minMoveSize: 10, maxShowNodeNum: 10, autoOpenTime: 10 } } }; var zNodes1 = {id: 0, name: "原目录", pId: -1, isParent: true, "nocheck": true,iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'}; var setting = { view: { selectedMulti: false }, check: { enable: true, chkboxType: {"Y": "s", "N": "s"} }, data: { simpleData: { enable: true } }, callback: { //点击节点 //onClick: onClick, //展开节点 //onExpand: onExpand, //拖动结束之前 //beforeDrop: beforeDrop, //拖动结束 //onDrop: onDrop }, async: { enable: true, url: 'selectmulu', autoParam: ["id"] }, edit: { enable: true, showRemoveBtn: false, showRenameBtn: false, drag: { autoExpandTrigger: true, isCopy: false, isMove: true, prev: true, next: true, inner: true, borderMax: 20, borderMin: -10, minMoveSize: 10, maxShowNodeNum: 10, autoOpenTime: 10 } } }; var zNodes = {id: 0, name: "目标目录", pId: -1, isParent: true, "nocheck": true,iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'}; $.fn.zTree.init($("#zytreesonl"), setting1, zNodes1); //初始化zTree $.fn.zTree.init($("#zytreesonr"), setting, zNodes); } //F12 资源位置调整界面 function Merge() { $("#divTabs").css("display", "none"); $("#divTabs2").css("display", ""); $("#btnReturn").css("display", ""); $("#btnAddSon").css("display", "none"); $("#btnMerge").css("display", "none"); $("#btnDelete").css("display", "none"); $("#btnEdit").css("display", "none"); initSonTree(); } //F13 资源位置调整方法 function GetCheckedAll() { var ids = ""; var treeObj = $.fn.zTree.getZTreeObj("zytreesonl"); var nodes = treeObj.getCheckedNodes(true); if (nodes.length < 1) { alert("请选择要调整的资源") return; } for (var i = 0; i < nodes.length; i++) { if(nodes[i].isParent) { continue; } ids = ids + nodes[i].id + ";"; } var treeObj2 = $.fn.zTree.getZTreeObj("zytreesonr"); var nodes2 = treeObj2.getCheckedNodes(true); if (nodes2.length > 1) { alert("目标目录只能是一个"); return; } if (nodes2 < 1) { alert("请选择目标目录"); return; } var fid = nodes2[0].id; $.ajax({ type: 'post', url: '/res/OnemapCatalog/manage/catalog/merge', data: {ids: ids, fid: fid}, success: function (data) { alert(data); window.location = window.location; } }); } //F14 初始化资源排序列表 function initZyPaiXu() { var Tree = document.getElementById("ZyOrderTree"); var id = document.getElementById("muluid").value; Tree.innerHTML = ""; $.ajax({ type: 'post', url: 'initzysort', data: {id: id}, success: function (data) { var json = data; Tree.size = json.count; var List = json.children; for (i = 0; i < List.length; i++) { Tree.innerHTML += "
  • " + "" + "" + List[i].name + "" + ""; } }, error: function (data) { alert("未知错误"); window.location = window.location; } }); }