| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 | 
							- /**
 
-  * Created by Zhong on 2017/8/14.
 
-  */
 
- $(function () {
 
-     let dispNameArr;
 
-     let compilationsArr;
 
-     let usedCom;
 
-     getCompilationList(function (datas) {
 
-         compilationsArr = datas;
 
-         getAllGljLib(function (dispNames, compilationsUsedArr) {
 
-             usedCom = compilationsUsedArr;
 
-             dispNameArr = dispNames;
 
-             //添加
 
-             $('#addBtn').click(function () {
 
-                 let compilationName = $('#compilationSels option:selected').text();
 
-                 let compilationId = $('#compilationSels option:selected').val();
 
-                 let libName = $('#libNameTxt').val();
 
-                 if(libName.trim().length === 0){
 
-                     alert('名称不可为空!');
 
-                     $('#libNameTxt').val('')
 
-                 }
 
-                 else if(compilationsUsedArr.indexOf(compilationId) !== -1){// compilationsUsedArr;//在该编办下已建库,限制一个编办只能有一个库
 
-                     alert('该编办已被绑定!');
 
-                     $('#libNameTxt').val('')
 
-                 }
 
-                 else if(dispNames.indexOf(libName) !== -1){
 
-                     alert('此人材机库已存在!');
 
-                     $('#libNameTxt').val('')
 
-                 }
 
-                 else if(compilationName.trim().length === 0){
 
-                     alert('编办不可为空!');
 
-                 }
 
-                 else{
 
-                     let newGljLib = {};
 
-                     newGljLib.dispName = libName;
 
-                     newGljLib.compilationId = compilationId;
 
-                     newGljLib.compilationName = compilationName;
 
-                     newGljLib.creator = oprtor;
 
-                     newGljLib.appType = "建筑";
 
-                     $('#libNameTxt').val('');
 
-                     createGljLib(newGljLib, dispNameArr, usedCom);
 
-                 }
 
-             });
 
-             //重命名
 
-             $("#showArea").on("click", "[data-target = '#edit']", function(){
 
-                 let renameId = $(this).parent().parent().attr("id");
 
-                 let compilationName = $(this).parent().parent().children()[1].textContent;
 
-                 $('#compilationEdit option').text(compilationName);
 
-                 $("#renameA").attr("renameId", renameId);
 
-             });
 
-             $("#renameA").click(function(){
 
-                 let newName = $("#renameText").val();
 
-                 let libId = $(this).attr("renameId");
 
-                 let jqSel = "#" + libId + " td:first" + " a";
 
-                 let orgName = $(jqSel).text();
 
-                 if(newName.trim().length === 0){
 
-                     alert("名称不可为空!");
 
-                     $("#renameText").val('');
 
-                 }
 
-                 else if(dispNameArr.indexOf(newName) !== -1){
 
-                     alert("该人材机库已存在!");
 
-                     $("#renameText").val('');
 
-                 }
 
-                 else{
 
-                     renameGljLib({ID: libId, newName: newName, orgName: orgName}, dispNameArr);
 
-                 }
 
-             });
 
-             //删除
 
-             $("#showArea").on("click", "[data-target = '#del']", function(){
 
-                 let deleteId = $(this).parent().parent().attr("id");
 
-                 $("#deleteA").attr("deleteId", deleteId);
 
-             });
 
-             $("#deleteA").click(function(){
 
-                 let deleteId = $(this).attr("deleteId");
 
-                 let jqSel = "#" + deleteId + " td:first" + " a";
 
-                 let libName = $(jqSel).text();
 
-                 let compilationName = $("#" + deleteId + " td:eq(1)").text();
 
-                 for(let i = 0, len = compilationsArr.length; i < len; i++){
 
-                     if(compilationsArr[i].name === compilationName.trim()){
 
-                         usedCom.splice(usedCom.indexOf(compilationsArr[i]._id), 1);
 
-                         break;
 
-                     }
 
-                 }
 
-                 removeGljLib({libId: deleteId, libName: libName}, dispNameArr);
 
-             });
 
-         });
 
-     });
 
- });
 
- function getAllGljLib(callback){
 
-     $.ajax({
 
-         type: 'post',
 
-         url: 'api/getAllGljLib',
 
-         dataType: 'json',
 
-         success: function (result) {
 
-             let dispNames = [];
 
-             let compilationsUsedArr = [];
 
-             if(result.data.length > 0){
 
-                 for(let i = 0; i < result.data.length; i++){
 
-                     compilationsUsedArr.push(result.data[i].compilationId);//已建库的编办
 
-                     let id = result.data[i].ID;
 
-                     let libName = result.data[i].dispName;
 
-                     let createDate = result.data[i].createDate.split(' ')[0];
 
-                     let compilationName = result.data[i].compilationName;
 
-                     let rationLibs = result.data[i].rationLibs;
 
-                     let rationLibsName = '';
 
-                     for(let j = 0; j < rationLibs.length; j++){
 
-                         rationLibsName += rationLibs[j].dispName + "</br>";
 
-                     }
 
-                     dispNames.push(result.data[i].dispName);
 
-                     $("#showArea").append(
 
-                         "<tr id='tempId'>" +
 
-                         "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
 
-                         "<td>"+compilationName+" </td>" +
 
-                         "<td>"+rationLibsName+" </td>" +
 
-                         "<td>"+createDate+" </td>" +
 
-                         "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
 
-                         "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
 
-                         "<i class='fa fa-remove'></i></a></td></tr>");
 
-                     var newHref = "/stdGljRepository/glj?gljLibId="+id;
 
-                     $("#tempId td:first a").attr("href", newHref);
 
-                     $("#tempId").attr("id", id);
 
-                 }
 
-             }
 
-             callback(dispNames, compilationsUsedArr);
 
-         }
 
-     });
 
- }
 
- function getCompilationList(callback){
 
-     $.ajax({
 
-         type: 'post',
 
-         url: 'api/getCompilationList',
 
-         dataType: 'json',
 
-         success: function (result) {
 
-             //addoptions
 
-             for(let i = 0; i < result.data.length; i++){
 
-                 let $option =  $("<option >"+ result.data[i].name +"</option>");
 
-                 $option.val( result.data[i]._id);
 
-                 $('#compilationSels').append($option);
 
-             }
 
-             $('#compilationSels').on("change", function () {
 
-             });
 
-             callback(result.data);
 
-         }
 
-     });
 
- }
 
- function createGljLib(gljLibObj, dispNamesArr, usedCom){
 
-     $.ajax({
 
-         type: 'post',
 
-         url: 'api/createGljLib',
 
-         data: {gljLibObj: JSON.stringify(gljLibObj)},
 
-         dataType: 'json',
 
-         success: function (result) {
 
-             if(result.data){
 
-                 let id = result.data.ID;
 
-                 let libName = result.data.dispName;
 
-                 let createDate = result.data.createDate.split(' ')[0];
 
-                 let compilationName = result.data.compilationName;
 
-                 dispNamesArr.push(libName);
 
-                 usedCom.push(gljLibObj.compilationId);
 
-                 $("#showArea").append(
 
-                     "<tr id='tempId'>" +
 
-                     "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
 
-                     "<td>"+compilationName+" </td>" +
 
-                     "<td>"+''+" </td>" +
 
-                     "<td>"+createDate+" </td>" +
 
-                     "<td><a href='javascript:void(0);' data-toggle='modal' data-target='#edit' title='编辑'>" +
 
-                     "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
 
-                     "<i class='fa fa-remove'></i></a></td></tr>");
 
-                 var newHref = "/stdGljRepository/glj?gljLibId="+id;
 
-                 $("#tempId td:first a").attr("href", newHref);
 
-                 $("#tempId").attr("id", id);
 
-             }
 
-             $('#cancelBtn').click();
 
-         }
 
-     })
 
- }
 
- function renameGljLib(renameObj, dispNames){
 
-     $.ajax({
 
-         type: 'post',
 
-         url: 'api/renameGljLib',
 
-         data: {oprtor: oprtor, renameObj: JSON.stringify(renameObj)},
 
-         dataType: 'json',
 
-         success: function (result) {
 
-             if(!result.error){
 
-                 let jqSel = "#" + renameObj.ID + " td:first" + " a";
 
-                 $(jqSel).text(renameObj.newName);
 
-                 let index = dispNames.indexOf(renameObj.orgName);
 
-                 dispNames.splice(index, 1);
 
-                 dispNames.splice(index, 0, renameObj.newName);
 
-             }
 
-             $('#editCancelBtn').click();
 
-             $('#renameText').val('');
 
-         }
 
-     })
 
- }
 
- function removeGljLib(delObj, dispNames){
 
-     $.ajax({
 
-         type: 'post',
 
-         url: 'api/removeGljLib',
 
-         data: {oprtor: oprtor, libId: delObj.libId},
 
-         dataType: 'json',
 
-         success: function (result) {
 
-             if(!result.error){
 
-                 if(result.message === '人材机库已被引用!'){
 
-                     $('#delCancelBtn').click();
 
-                     alert("此人材机库已被引用,不可删除!");
 
-                 }
 
-                 else if(result.message === '删除成功'){
 
-                     var jqSel = "#"+ delObj.libId;
 
-                     $(jqSel).remove();
 
-                     let index = dispNames.indexOf(delObj.libName);
 
-                     dispNames.splice(index, 1);
 
-                     $('#delCancelBtn').click();
 
-                 }
 
-             }
 
-         }
 
-     })
 
- }
 
 
  |