objectKey.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. //------------------------Utility------------------------
  2. function findPosX(obj) { //辅助函数 得到元素左边与浏览器左边的边距
  3. var curleft = 0;
  4. if (obj && obj.offsetParent) {
  5. while (obj.offsetParent) {
  6. curleft += obj.offsetLeft;
  7. obj = obj.offsetParent;
  8. }
  9. } else if (obj && obj.x)
  10. curleft += obj.x;
  11. return curleft; // + document.body.scrollLeft - document.body.clientLeft;
  12. }
  13. function findPosY(obj) { //辅助函数 得到元素上边与浏览器上边的边距
  14. var curtop = 0;
  15. if (obj && obj.offsetParent) {
  16. while (obj.offsetParent) {
  17. curtop += obj.offsetTop;
  18. obj = obj.offsetParent;
  19. }
  20. } else if (obj && obj.y)
  21. curtop += obj.y;
  22. return curtop; // + document.body.scrollTop - document.body.clientTop;
  23. }
  24. var dragGhost = document.createElement("div");
  25. dragGhost.style.border = "dashed 1px #CCCCCC";
  26. dragGhost.style.background = "white";
  27. dragGhost.style.display = "none";
  28. dragGhost.style.margin = "10px";
  29. dragGhost.style.width = "100%";
  30. var container;
  31. var keys;
  32. var columns = [];
  33. var groups = [];
  34. //------------------------Start Here------------------------
  35. $(document).ready(function () {
  36. // init();
  37. DM.getDrager().itemClick=function(){
  38. console.log(this);
  39. console.log(this.children())
  40. if(!this.parentid){
  41. // DM.getDrager().optionList.reload()
  42. // DM.getDrager().selectedList.reload()
  43. var thisItem=this;
  44. if(thisItem.id.indexOf("-") == -1){
  45. DM.getDrager().optionList.empty();
  46. var allcodebook=$(thisItem.element).find(".allcodebook");
  47. var selectedList=DM.getDrager().selectedList.getAllItems()
  48. selectedId={};
  49. for(var i=0;i<selectedList.length;i++){
  50. selectedId[selectedList[i].id]=true;
  51. }
  52. var optionList=allcodebook.filter(function(){
  53. var identify=$(this).find(".receiveCodebook").attr("identify");
  54. if(selectedId[identify])return false;
  55. return true;
  56. }).clone().each(function(){
  57. var identify=$(this).find(".receiveCodebook").attr("identify");
  58. $(this).removeClass("allcodebook").attr("ssObjId",identify); // ("wdObjectId",。Lin
  59. DM.getDrager().optionList.append(this);
  60. })
  61. optionList.show();
  62. DM.getDrager().optionList.reload();
  63. }
  64. }
  65. }
  66. })
  67. function initDrag() {
  68. // console.info("come init()");
  69. groups = [];
  70. columns = [];
  71. container = document.getElementById("containers");
  72. for (var i = 0; i < container.childNodes.length; i++) {
  73. if ($(container.childNodes[i]).hasClass("column")) { //筛选出所有的列 ff下的childNodes不可靠 :\
  74. columns.push(container.childNodes[i]);
  75. }
  76. }
  77. for (var i = 0; i < columns.length; i++) {
  78. var column = columns[i];
  79. for (var j = 0; j < column.childNodes.length; j++) {
  80. var group = column.childNodes[j];
  81. if (typeof group.className != "undefined") {
  82. if ($(group).hasClass("group")) {
  83. group.column = column;
  84. group.items = group.getElementsByClassName("items")[0];
  85. groups.push(group);
  86. }
  87. }
  88. }
  89. }
  90. // console.log(groups.length)
  91. for (var i = 0; i < groups.length; i++) {
  92. var group = groups[i];
  93. var items = group.querySelectorAll(".item");
  94. for (var j = 0; j < items.length; j++) {
  95. items[j].group = group;
  96. new dragItem(items[j]);
  97. }
  98. }
  99. }
  100. function init() {
  101. setTimeout(function () {
  102. var groups = document.querySelectorAll("#keys .group")
  103. console.log(groups)
  104. //修复属性名称被修改是,导致显示正确
  105. for (var i = 0; i < groups.length; i++) {
  106. var group = groups[i];
  107. var codebooks = group.querySelectorAll(".codebook");
  108. var items = group.querySelectorAll(".item");
  109. for (var j = 0; j < items.length; j++) {
  110. var item = items[j];
  111. for (var k = 0; k < codebooks.length; k++) {
  112. var codebook = codebooks[k]
  113. if (item.getAttribute("value") == codebook.getAttribute("value")) {
  114. // console.log(item)
  115. // console.log(codebook)
  116. if (item.getAttribute("html") != codebook.getAttribute("html")) {
  117. if (window.confirm("类别\"" + codebook.getAttribute("desc") + "\""
  118. + ",所选\""
  119. +item.getAttribute("html") + "\"最新为\""
  120. +codebook.getAttribute("html") + "\""
  121. + "\n 是否要更新?")) {
  122. item.setAttribute("html", codebook.getAttribute("html"))
  123. item.innerHTML = codebook.getAttribute("html")
  124. }
  125. }
  126. }
  127. }
  128. }
  129. // console.log(codebooks)
  130. }
  131. }, 3000)
  132. // console.info("init >>>>>>>");
  133. //绑定事件,选中并且拖选初始化
  134. var keys = document.getElementById("keys");
  135. keys.onclick = function (e) {
  136. // console.log("click")
  137. if (!e) {
  138. e = window.event
  139. }
  140. var target = e.target;
  141. var currentTarget = e.currentTarget;
  142. var groupNode = null
  143. for (var i = 0; i < currentTarget.childNodes.length; i++) {
  144. if (typeof currentTarget.childNodes[i].className == "undefined") {
  145. continue;
  146. }
  147. //定位位置
  148. if ($(currentTarget.childNodes[i]).hasClass("group")) {
  149. var aa = currentTarget.childNodes[i].compareDocumentPosition(target);
  150. if (aa == 0 || aa == 20) {
  151. groupNode = currentTarget.childNodes[i];
  152. }
  153. }
  154. }
  155. //找不到 ,返回
  156. if (groupNode == null) {
  157. return;
  158. }
  159. //点击显示控制
  160. //移除选中状态
  161. $(currentTarget).children(".selected").removeClass("selected")
  162. $("#candidate .item").remove();
  163. if (lastNode == groupNode) {
  164. //重复点击关闭
  165. //移除选中状态
  166. $(groupNode).removeClass("selected");
  167. //删除待选
  168. $(".useobject").remove();
  169. $(currentTarget).children(".selected").removeClass("selected")
  170. lastNode = null;
  171. } else {
  172. //选中标记
  173. $(groupNode).addClass("selected");
  174. $(".useobject").remove();
  175. // console.log(groupNode)
  176. $(groupNode).find(".item").each(function (index, element) {
  177. settingItemMessage(element);
  178. // console.log(element)
  179. })
  180. // 右侧栏显示拖动选项
  181. $(groupNode).children(".codebook").each(function (index, element) {
  182. var temp = element.cloneNode(true)
  183. temp.className = "item list-normal list-background";
  184. // console.log(codebookname+" "+codebookvalue);
  185. //排重
  186. var exit = false;
  187. $(groupNode).children(".items").children(".item").each(function (ind, ele) {
  188. if ($(ele).attr("value") == $(temp).attr("value")) {
  189. exit = true;
  190. }
  191. })
  192. if (exit) {
  193. return;
  194. }
  195. settingItemMessage(temp);
  196. // $(temp).append("<span style=\"color:red;\">(部门内)</span>");
  197. $("#candidate .items").append(temp).hide();
  198. })
  199. $("#candidate .items").fadeIn(500)
  200. //重复点击判断
  201. lastNode = groupNode;
  202. //拖动初始化
  203. initDrag()
  204. }
  205. }
  206. }
  207. //重复点击
  208. var lastNode;
  209. var isIE = document.all;
  210. //------------------------Drag Item------------------------
  211. function dragItem(item) {
  212. var handle = item;
  213. if (!handle)
  214. return;
  215. Drag.init(handle, item);
  216. item.onDragStart = function (left, top, mouseX, mouseY) {
  217. this.lock = this.lockDrag();
  218. if (this.lock) {
  219. return
  220. };
  221. //将ghost插入到当前位置
  222. dragGhost.style.display = "block";
  223. //开始拖动的时候设置透明度
  224. this.style.opacity = "0.5";
  225. this.style.filter = "alpha(opacity=50)";
  226. dragGhost.style.height = (isIE ? this.offsetHeight : this.offsetHeight - 2) + "px";
  227. //this指的是item
  228. this.style.width = this.offsetWidth + "px"; //因为初始的width为auto
  229. var scrollTop = this.parentNode.scrollTop;
  230. this.style.left = (findPosX(this) - 5) + "px";
  231. this.style.top = (findPosY(this) - scrollTop) + "px";
  232. this.style.position = "absolute";
  233. // console.log(this.group)
  234. // this.group.insertBefore(dragGhost,this);
  235. // console.log(this.group.items)
  236. this.group.items.insertBefore(dragGhost, this);
  237. //记录每一列的左边距 在拖动过程中判断拖动对象所在的列会用到
  238. this.columnsX = [];
  239. for (var i = 0; i < columns.length; i++) {
  240. this.columnsX.push(findPosX(columns[i]));
  241. }
  242. this.groupsY = [];
  243. for (var i = 0; i < groups.length; i++) {
  244. this.groupsY.push([findPosY(groups[i]), groups[i].column]);
  245. }
  246. }
  247. item.onDrag = function (left, top, mouseX, mouseY) {
  248. if (this.lock) {
  249. return
  250. }
  251. //先要判断在哪一列移动
  252. var columnIndex = 0;
  253. for (var i = 0; i < this.columnsX.length; i++) {
  254. if ((findPosX(this) + this.offsetWidth / 2) > this.columnsX[i]) {
  255. columnIndex = i;
  256. }
  257. }
  258. var column = columns[columnIndex];
  259. var groupIndex = null;
  260. //选择group
  261. for (var i = 0; i < this.groupsY.length; i++) {
  262. if (this.groupsY[i][1] == column) {
  263. if (column.id == "keys") {
  264. if ($(groups[i]).hasClass("selected")) {
  265. groupIndex = i;
  266. }
  267. } else if (column.id == "candidate") {
  268. groupIndex = i;
  269. }
  270. }
  271. }
  272. var group = groups[groupIndex];
  273. if (this.group != group) {
  274. this.group = group;
  275. // group.appendChild(dragGhost);
  276. group.items.appendChild(dragGhost);
  277. }
  278. var currentNode = null;
  279. for (var i = 0; i < this.group.items.childNodes.length; i++) {
  280. // var item=this.group.childNodes[i];
  281. var tempitem = this.group.items.childNodes[i];
  282. // if(item.className=="item"
  283. // &&item!=this
  284. // &&top<findPosY(item)){
  285. // currentNode=item;
  286. // }
  287. if (tempitem.className == "item" && tempitem != this && findPosY(this) < findPosY(tempitem) && findPosX(this) < findPosX(tempitem)) {
  288. // console.log(groupIndex+" " + i+" "+findPosY(tempitem));
  289. currentNode = tempitem
  290. break
  291. }
  292. }
  293. if (currentNode) {
  294. // this.group.insertBefore(dragGhost,currentNode);
  295. this.group.items.insertBefore(dragGhost, currentNode);
  296. } else { //拖到最下边 没有任何一个元素的上边距比拖动元素的top大 则添加到列的最后
  297. // this.group.appendChild(dragGhost);
  298. this.group.items.appendChild(dragGhost)
  299. }
  300. }
  301. item.onDragEnd = function (left, top, mouseX, mouseY) {
  302. if (this.lock) {
  303. return
  304. }
  305. this.style.opacity = "1";
  306. this.style.filter = "alpha(opacity=100)";
  307. // this.group.insertBefore(this,dragGhost);
  308. this.group.items.insertBefore(this, dragGhost);
  309. this.style.position = "static";
  310. this.style.display = "block";
  311. // this.style.width = "80%";
  312. this.style.width = "auto";
  313. dragGhost.style.display = "none";
  314. }
  315. //返回true无法拖动
  316. //false 可拖动
  317. item.lockDrag = function () {
  318. console.info("<<<<<<<>>>>>3");
  319. //没有选中
  320. if ($("#keys .selected").length == 0) {
  321. console.log("no selected");
  322. return true;
  323. }
  324. //其他未选中的,同时拖动被初始化,无法拖动
  325. if (this.parentNode.parentNode.parentNode.id == "keys" && !$(this.parentNode.parentNode).hasClass("selected")) {
  326. return true;
  327. }
  328. return false;
  329. }
  330. }
  331. function setKeyConfirm(thisDiv) {
  332. console.info("<<<<<<<>>>>>2");
  333. var URL = document.getElementById("saveURL").value
  334. var datass = document.getElementById("jsonData").innerHTML;
  335. if (datass.length == 0) {
  336. datass = '{nodes:{},lines:{}}'
  337. }
  338. var alldata = eval("(" + datass + ")")
  339. var objectKey;
  340. if (alldata.objectKey) {
  341. objectKey = alldata.objectKey
  342. } else {
  343. objectKey = []
  344. }
  345. var key = {}
  346. var data = {}
  347. var codebook = {}
  348. var temp = {}
  349. var temp2 = []
  350. var inputName = document.getElementById("inputName").value;
  351. var inputDesc = document.getElementById("inputDesc").value;
  352. var submitName = document.getElementById("submitName").value;
  353. var showName = document.getElementById("showName").value;
  354. var bgmbid = document.getElementById("bgmbid") ? document.getElementById("bgmbid").value : null;
  355. // submitName=inputName
  356. if (inputName.length == 0||submitName.length==0) {
  357. alert("名称和申请名称不能为空")
  358. return;
  359. }
  360. var version = 0;
  361. for (var i = 0; i < objectKey.length; i++) {
  362. var v = parseInt(objectKey[i].version);
  363. if (v >= version) {
  364. version = v;
  365. }
  366. }
  367. version++;
  368. temp2 = parseTabToJson()
  369. console.log(temp2)
  370. temp.name = inputName;
  371. temp.desc = inputDesc;
  372. temp.submitName = submitName
  373. temp.codebooks = temp2;
  374. temp.version = version;
  375. temp.nodes = {}
  376. temp.lines = {}
  377. if (bgmbid) {
  378. temp.bgmbid = bgmbid
  379. }
  380. if(showName){
  381. temp.showName=showName;
  382. }
  383. // alert(objectKey.length)
  384. objectKey.push(temp)
  385. console.log(objectKey)
  386. // return;
  387. $.post(URL, {
  388. "fileName": document.getElementById("fileName").value,
  389. "objectKey": JSON.stringify(objectKey)
  390. }, function (result) {
  391. // alert(result)
  392. if (result.indexOf("保存成功") != -1) {
  393. //刷新设计页面,关闭窗口
  394. wd.display.showMsgPopup(result);
  395. // wd.display.getwdDialogOpener().frames[0].location.reload();
  396. wd.display.getwdDialogOpener().location.reload();
  397. wd.display.closeDialog();
  398. } else {
  399. alert(result)
  400. }
  401. })
  402. }
  403. function alterKeyConfirm(thisdiv) {
  404. console.info("<<<<<<<>>>>>1");
  405. var URL = document.getElementById("saveURL").value
  406. var datass = document.getElementById("jsonData").innerHTML;
  407. if (datass.length == 0) {
  408. datass = '{nodes:{},lines:{}}'
  409. }
  410. var alldata = eval("(" + datass + ")")
  411. var objectKey;
  412. if (alldata.objectKey) {
  413. objectKey = alldata.objectKey
  414. } else {
  415. objectKey = [];
  416. }
  417. var key = {}
  418. var data = {}
  419. var codebook = {}
  420. var temp = {}
  421. var temp2 = []
  422. var inputName = document.getElementById("inputName").value;
  423. var inputDesc = document.getElementById("inputDesc").value;
  424. var submitName = document.getElementById("submitName").value;
  425. var showName = document.getElementById("showName").value;
  426. var bgmbid = document.getElementById("bgmbid") ? document.getElementById("bgmbid").value : null;
  427. // submitName=inputName
  428. var version = $("#version").val();
  429. if (inputName.length == 0||submitName.length==0) {
  430. alert("名称和申请名称不能为空");
  431. return;
  432. }
  433. var code = parseTabToJson()
  434. console.log(code)
  435. // return
  436. temp.name = inputName;
  437. temp.desc = inputDesc;
  438. temp.codebooks = temp2;
  439. for (var i = 0; i < objectKey.length; i++) {
  440. if (objectKey[i].version == version) {
  441. objectKey[i].name = inputName;
  442. objectKey[i].submitName = submitName;
  443. if(showName){
  444. objectKey[i].showName = showName;
  445. }else{
  446. delete objectKey[i].showName;
  447. }
  448. objectKey[i].desc = inputDesc;
  449. objectKey[i].codebooks = code;
  450. if (bgmbid) {
  451. objectKey[i].bgmbid = bgmbid
  452. } else {
  453. delete objectKey[i].bgmbid;
  454. }
  455. // if(showName){
  456. // objectKey[i].showName=showName;
  457. // }else{
  458. // delete objectKey[i].showName;
  459. // }
  460. console.log(objectKey[i])
  461. }
  462. }
  463. $.post(URL, {
  464. "fileName": document.getElementById("fileName").value,
  465. "objectKey": JSON.stringify(objectKey)
  466. }, function (result) {
  467. // alert(result);
  468. if (result.indexOf("保存成功") != -1) {
  469. //刷新设计页面,关闭窗口
  470. wd.display.showMsgPopup(result);
  471. // window.location.reload();
  472. wd.display.getwdDialogOpener().frames[0].location.reload();
  473. // wd.display.getwdDialogOpener().location.reload();
  474. wd.display.closeDialog();
  475. } else {
  476. alert(result)
  477. }
  478. })
  479. }
  480. function parseTabToJson() {
  481. console.info("<<<<<<<>>>>>0");
  482. var result = [];
  483. // $("#keys .items").each(function (index, element) {
  484. // var templist = []
  485. // $(element).children(".item").each(function (ind, ele) {
  486. // // <div class="codebook" codebook="${item.codebook}" name="${item.name}" value="${codebookKey}" desc="${item.desc}" html="${codebookValue}">${codebookValue}</div>
  487. // // </codebook:iterate>
  488. // var code = {};
  489. // code.codebook = ele.getAttribute("codebook");
  490. // code.name = ele.getAttribute("name");
  491. // code.value = ele.getAttribute("value");
  492. // code.desc = ele.getAttribute("desc");
  493. // code.html = ele.getAttribute("html");
  494. // templist.push(code);
  495. // })
  496. // // if(templist.length>0){
  497. // result.push(templist);
  498. // // }
  499. // })
  500. var selectedList=DM.getDrager().selectedList.getAllItems()
  501. var allItems={};
  502. for(var i=0;i<selectedList.length;i++){
  503. var item=selectedList[i];
  504. var id=item.id;
  505. var pid=item.parentid;
  506. if(!pid){
  507. allItems[id]=[];
  508. }
  509. }
  510. for(var i=0;i<selectedList.length;i++){
  511. var item=selectedList[i];
  512. var id=item.id;
  513. var pid=item.parentid;
  514. if(pid){
  515. allItems[pid].push(item);
  516. }
  517. }
  518. console.log(allItems);
  519. for(var key in allItems){
  520. var templist = [];
  521. for(var i=0;i<allItems[key].length;i++){
  522. var ele=allItems[key][i].element.querySelector(".receiveCodebook");
  523. var code = {};
  524. code.objName = ele.getAttribute("objName"); // 再增加,<key 字段的对象名,增加支持 <key 字段不在流程的对象里 -- 支持单独提交 二级对象,不聚合到一级对象。Lin
  525. code.codebook = ele.getAttribute("codebook");
  526. code.name = ele.getAttribute("name");
  527. code.value = ele.getAttribute("value");
  528. code.desc = ele.getAttribute("desc");
  529. code.html = ele.getAttribute("html");
  530. templist.push(code);
  531. }
  532. if(templist.length>0){
  533. result.push(templist);
  534. }
  535. }
  536. return result
  537. }
  538. function settingItemMessage(item) {
  539. if(true)return
  540. var codebookname = item.getAttribute("codebook");
  541. var codebookvalue = item.getAttribute("value");
  542. var version = $("#version").val();
  543. var datass = document.getElementById("jsonData").innerHTML;
  544. if (datass.length == 0) {
  545. datass = '{nodes:{},lines:{}}'
  546. }
  547. var alldata = eval("(" + datass + ")")
  548. var objectKey;
  549. if (alldata.objectKey) {
  550. objectKey = alldata.objectKey
  551. } else {
  552. objectKey = [];
  553. }
  554. for (var i = 0; i < objectKey.length; i++) {
  555. var objectname = objectKey[i].name;
  556. var codebooks = objectKey[i]["codebooks"];
  557. if (version == objectKey[i].version) {
  558. continue
  559. }
  560. if ((function () {
  561. if (codebooks && codebooks.length == 0)
  562. return false;
  563. for (var j = 0; codebooks && j < codebooks.length; j++) {
  564. if (codebooks[j].length == 0)
  565. continue;
  566. var codebookname2 = codebooks[j][0].codebook;
  567. if (codebookname2 == codebookname) {
  568. for (var k = 0; k < codebooks[j].length; k++) {
  569. if (codebooks[j][k].value == codebookvalue) {
  570. return true;
  571. }
  572. }
  573. }
  574. }
  575. })()) {
  576. $(item).append("<span class=\"useobject\" style=\"color:red;\">(" + objectname + ")</span>");
  577. }
  578. }
  579. }
  580. function changeComponentName(ele){
  581. window.location.href=document.getElementById("setObjectKeyURL").value+"&fileName="+ele.value;
  582. }