design.ui.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. let nodes = '';
  2. window.clickSubmit = function()
  3. {
  4. nodes = $('[name=nodes]').val();
  5. nodes = JSON.parse(nodes);
  6. if(nodes.length <= 2)
  7. {
  8. zui.Messager.show({content: warningLang['needReview'], close: false});
  9. return false;
  10. }
  11. }
  12. window.genID = function()
  13. {
  14. return Math.random().toString(36).substr(2);
  15. }
  16. window.clickConditionNode = function(event)
  17. {
  18. var $pa = $(event.target).closest('.editor-node').parent().closest('.editor-node');
  19. var id = $pa.data('id');
  20. getNode(id, function(index, father, index2, grandpa)
  21. {
  22. if(index == 'default') return;
  23. var selectedFather = father.branches;
  24. var node = selectedFather[index];
  25. node.type = 'conditions';
  26. $.post(link, {nodes: JSON.stringify(nodes), 'type': 'update', 'node': JSON.stringify(node)}, function(data)
  27. {
  28. $('#modal').html($(data).find('#modal').html()).zuiInit();
  29. zui.Modal.open({id: 'modal'});
  30. });
  31. });
  32. }
  33. window.clickNode = function(event)
  34. {
  35. var $pa = $(event.target).closest('.editor-node');
  36. var id = $pa.data('id');
  37. getNode(id, function(index, father, index2, grandpa)
  38. {
  39. if(index == 'default') return;
  40. var node = father[index];
  41. node.nodeIndex = index2;
  42. $.post(link, {nodes: JSON.stringify(nodes), 'type': 'update', 'node': JSON.stringify(node)}, function(data)
  43. {
  44. $('#modal').html($(data).find('#modal').html()).zuiInit();
  45. zui.Modal.open({id: 'modal', size: 'lg'});
  46. });
  47. });
  48. }
  49. window.hideAddType = function()
  50. {
  51. $('#editor .add-node-types').remove();
  52. $('#editor .add-node-btn-active').removeClass('add-node-btn-active');
  53. }
  54. window.addNodeType = function(event)
  55. {
  56. hideAddType();
  57. const addText = $('#addNode').html();
  58. $obj = $(event.target).closest('.add-node-btn');
  59. $obj.addClass('add-node-btn-active');
  60. $obj.append(addText);
  61. return false;
  62. }
  63. window.addNode = function(event)
  64. {
  65. let $pa = $(event.target).closest('.editor-node');
  66. const type = $(event.target).closest('.node-type').data('type');
  67. const isCondition = $pa.hasClass('condition');
  68. if(isCondition && type == 'reviewer') $pa = $pa.parent().closest('.editor-node');
  69. if(isCondition && type != 'reviewer') $pa = $pa.next('.editor-node');
  70. const id = $pa.data('id');
  71. getNode(id, function(index, father, index2, grandpa)
  72. {
  73. index = isCondition ? index : parseInt(index) + 1;
  74. if(isCondition && type == 'reviewer')
  75. {
  76. father = (index == 'default') ? father.default.nodes : father.branches[index].nodes;
  77. index = 0;
  78. }
  79. let node = {};
  80. if(type == 'reviewer') node = {id: genID(), title: nodeTypeLang['approval'], reviewType: 'manual', type: 'approval', reviewers: [{type: 'select'}], agentType: 'pass', ccs: [{type: 'select'}]};
  81. if(type == 'cc') node = {id: genID(), title: nodeTypeLang['cc'], type: 'cc', ccs: [{type: 'select'}]};
  82. if(type == 'condition' || type == 'parallel')
  83. {
  84. node = {
  85. id: genID(),
  86. type: 'branch',
  87. branchType: type,
  88. branches: [{
  89. id: genID(),
  90. conditions: [],
  91. nodes:[{id: genID(), type: 'approval', reviewers: [{type: 'select'}]}]
  92. }],
  93. default: {
  94. id: genID(),
  95. nodes: [{id: genID(), type: 'approval', reviewers: [{type: 'select'}]}]
  96. }
  97. };
  98. }
  99. father.splice(index, 0, node);
  100. $.post(link, {nodes: JSON.stringify(nodes), 'type': 'update'}, function(data)
  101. {
  102. $('#editor').html($(data).find('#editor').html()).zuiInit();
  103. });
  104. })
  105. }
  106. window.getNode = function(nodeID, callback)
  107. {
  108. nodes = $('[name=nodes]').val();
  109. nodes = JSON.parse(nodes);
  110. if(nodeID == 'start')
  111. {
  112. callback(0, nodes);
  113. return [0];
  114. }
  115. else if(nodeID == 'end')
  116. {
  117. callback(nodes.length-1, nodes);
  118. return [nodes.length-1];
  119. }
  120. else
  121. {
  122. return findFromNodes(nodeID, nodes, callback);
  123. }
  124. }
  125. window.findFromNodes = function(nodeID, nodes, callback, parentIndex)
  126. {
  127. for(let index in nodes)
  128. {
  129. var node = nodes[index];
  130. if(node.id == nodeID)
  131. {
  132. callback(index, nodes, parentIndex ? (parseInt(parentIndex) + parseInt(index)) : index);
  133. return [index];
  134. }
  135. if(node.type == 'branch')
  136. {
  137. for(var index2 in node.branches)
  138. {
  139. var path = [index, 'branches', index2];
  140. var branch = node.branches[index2];
  141. if(branch.id == nodeID)
  142. {
  143. callback(index2, node, index, nodes);
  144. return path;
  145. }
  146. var result = findFromNodes(nodeID, branch.nodes, callback, index);
  147. if(result.length > 0)
  148. {
  149. path.push('nodes');
  150. return path.concat(result);
  151. }
  152. }
  153. // default
  154. var path = [index, 'default'];
  155. var branch = node.default;
  156. if(branch.id == nodeID)
  157. {
  158. callback('default', node, index, nodes);
  159. return path;
  160. }
  161. var result = findFromNodes(nodeID, branch.nodes, callback, index);
  162. if(result.length > 0) return path.concat(result);
  163. }
  164. }
  165. return [];
  166. }
  167. window.deleteNode = function(event)
  168. {
  169. var id = $(event.target).closest('.editor-node').data('id');
  170. getNode(id, function(index, father)
  171. {
  172. father.splice(index,1)
  173. $.post(link, {nodes: JSON.stringify(nodes), 'type': 'update'}, function(data)
  174. {
  175. $('#editor').html($(data).find('#editor').html()).zuiInit();
  176. });
  177. })
  178. };
  179. window.deleteBranch = function(event)
  180. {
  181. var id = $(event.target).closest('.branch').data('id');
  182. getNode(id, function(index, father, index2, grandpa)
  183. {
  184. father.branches.splice(index, 1);
  185. if(father.branches.length == 0) grandpa.splice(index2, 1)
  186. $.post(link, {nodes: JSON.stringify(nodes), 'type': 'update'}, function(data)
  187. {
  188. $('#editor').html($(data).find('#editor').html()).zuiInit();
  189. });
  190. })
  191. };
  192. window.addCondition = function(event)
  193. {
  194. var id = $(event.target).closest('.editor-node').data('id');
  195. getNode(id, function(index, father)
  196. {
  197. father[index].branches.push({
  198. id: genID(),
  199. conditions: [],
  200. nodes: [{id: genID(), reviewType: 'manual', type: 'approval', reviewers: [{type: 'select'}]}]
  201. });
  202. $.post(link, {nodes: JSON.stringify(nodes), 'type': 'update'}, function(data)
  203. {
  204. $('#editor').html($(data).find('#editor').html()).zuiInit();
  205. });
  206. });
  207. }
  208. window.saveCondition = function(event)
  209. {
  210. const id = $(event.target).closest('button').data('id');
  211. const formData = new FormData($(event.target).closest('form').eq(0)[0]);
  212. getNode(id, function(index1, father, index2, grandpa)
  213. {
  214. var conditions = {};
  215. for(var d of formData)
  216. {
  217. var index = parseInt(d[0].match(/\d+/)[0]);
  218. var type = d[0].match(/[a-zA-Z]+/)[0];
  219. if(index == 1 && type == 'conditionLogical') continue;
  220. conditions[index] = conditions[index] || {};
  221. conditions[index][type] = d[1];
  222. }
  223. var message = checkConditions(conditions);
  224. if(message)
  225. {
  226. zui.Messager.show({content:message, close: false});
  227. return;
  228. }
  229. var arrayConditions = [];
  230. for(var i in conditions) arrayConditions.push(conditions[i]);
  231. father.branches[index1].conditions = arrayConditions;
  232. $.post(link, {nodes: JSON.stringify(nodes), 'type': 'update'}, function(data)
  233. {
  234. $('body').data('zui.Modal').hide();
  235. $('#editor').html($(data).find('#editor').html()).zuiInit();
  236. });
  237. })
  238. }
  239. window.checkConditions = function(conditions)
  240. {
  241. for(var i in conditions)
  242. {
  243. var condition = conditions[i];
  244. if(!condition.conditionValue) return warningLang['needValue'];
  245. }
  246. return '';
  247. }
  248. window.saveNode = function(event)
  249. {
  250. var data = {};
  251. const id = $(event.target).closest('button').data('id');
  252. const formData = new FormData($(event.target).closest('form').eq(0)[0]);
  253. getNode(id, function(index1, father, index2, grandpa)
  254. {
  255. var ccs = {};
  256. var reviewers = {};
  257. var node = father[index1];
  258. if(node.type != 'start' && node.type != 'end') data.id = node.id;
  259. data.type = node.type;
  260. for(var d of formData)
  261. {
  262. if(d[0] == 'title')
  263. {
  264. if(node.type == 'approval' || node.type == 'cc') data.title = d[1]; // 审批和抄送可以设置标题
  265. }
  266. else if (node.type == 'approval') // 只有审批节点可以设置审批人
  267. {
  268. if(d[0] == 'reviewType')
  269. {
  270. data.reviewType = d[1];
  271. if(d[1] != 'manual') continue;
  272. }
  273. if(data.reviewType == 'manual')
  274. {
  275. if(d[0].indexOf('type') === 0)
  276. {
  277. var index = parseInt(d[0].substring(5));
  278. reviewers[index] = {type: d[1]};
  279. if(d[1] == 'select')
  280. {
  281. reviewers[index].users = [];
  282. reviewers[index].roles = [];
  283. reviewers[index].depts = [];
  284. reviewers[index].positions = [];
  285. }
  286. if(d[1] == 'appointee') reviewers[index].users = [];
  287. if(d[1] == 'role') reviewers[index].roles = [];
  288. if(d[1] == 'position') reviewers[index].positions = [];
  289. if(d[1] == 'productRole') reviewers[index].productRoles = [];
  290. if(d[1] == 'projectRole') reviewers[index].projectRoles = [];
  291. if(d[1] == 'superiorList') reviewers[index].superiorList = '';
  292. if(d[1] == 'executionRole') reviewers[index].executionRoles = [];
  293. if(d[1] == 'required') reviewers[index].required = '';
  294. }
  295. else if(d[0].indexOf('roles') === 0)
  296. {
  297. var index = parseInt(d[0].substring(6));
  298. if(reviewers[index].type == 'role') reviewers[index].roles.push(d[1]); // 角色
  299. }
  300. else if(d[0].indexOf('positions') === 0)
  301. {
  302. var index = parseInt(d[0].substring(10));
  303. if(reviewers[index].type == 'position') reviewers[index].positions.push(d[1]); // 职位
  304. }
  305. else if(d[0].indexOf('productRoles') === 0)
  306. {
  307. var index = parseInt(d[0].substring(13));
  308. if(reviewers[index].type == 'productRole') reviewers[index].productRoles.push(d[1]); // 产品角色
  309. }
  310. else if(d[0].indexOf('projectRoles') === 0)
  311. {
  312. var index = parseInt(d[0].substring(13));
  313. if(reviewers[index].type == 'projectRole') reviewers[index].projectRoles.push(d[1]); // 项目角色
  314. }
  315. else if(d[0].indexOf('executionRoles') === 0)
  316. {
  317. var index = parseInt(d[0].substring(15));
  318. if(reviewers[index].type == 'executionRole') reviewers[index].executionRoles.push(d[1]); // 执行角色
  319. }
  320. else if(d[0].indexOf('superiorList') === 0)
  321. {
  322. var index = parseInt(d[0].substring(13));
  323. if(reviewers[index].type == 'superiorList') reviewers[index].superiorList = d[1]; // 连续上级
  324. }
  325. else if(d[0].indexOf('users') === 0)
  326. {
  327. var index = parseInt(d[0].substring(6));
  328. if(reviewers[index].type == 'appointee') reviewers[index].users.push(d[1]); // 指定人员
  329. }
  330. else if(d[0].indexOf('rangeuser') === 0)
  331. {
  332. var index = parseInt(d[0].substring(10));
  333. if(reviewers[index].type == 'select') reviewers[index].users.push(d[1]); // 人员范围
  334. }
  335. else if(d[0].indexOf('rangerole') === 0)
  336. {
  337. var index = parseInt(d[0].substring(10));
  338. if(reviewers[index].type == 'select') reviewers[index].roles.push(d[1]); // 角色范围
  339. }
  340. else if(d[0].indexOf('rangeposition') === 0)
  341. {
  342. var index = parseInt(d[0].substring(14));
  343. if(reviewers[index].type == 'select') reviewers[index].positions.push(d[1]); // 职位范围
  344. }
  345. else if(d[0].indexOf('rangedept') === 0)
  346. {
  347. var index = parseInt(d[0].substring(10));
  348. if(reviewers[index].type == 'select') reviewers[index].depts.push(d[1]); // 部门范围
  349. }
  350. else if(d[0].indexOf('userRange') === 0)
  351. {
  352. var index = parseInt(d[0].substring(10));
  353. if(reviewers[index].type == 'select') reviewers[index].userRange = d[1]; // 指定范围
  354. }
  355. else if(d[0].indexOf('required') === 0)
  356. {
  357. var index = parseInt(d[0].substring(9));
  358. if(reviewers[index].type == 'select') reviewers[index].required = d[1]; // 审批人必填
  359. }
  360. if(d[0] == 'needAll') data.needAll = 1;
  361. if(d[0] == 'percent') data.percent = d[1];
  362. if(d[0] == 'multiple') data.multiple = d[1];
  363. if(d[0] == 'commentType') data.commentType = d[1];
  364. if(d[0] == 'agentType') data.agentType = d[1];
  365. if(d[0] == 'deletedType') data.deletedType = d[1];
  366. if(d[0] == 'selfType') data.selfType = d[1];
  367. if(d[0] == 'agentUser' && data.agentType == 'appointee') data.agentUser = d[1];
  368. if(d[0] == 'setUser' && data.deletedType == 'setUser') data.setUser = d[1];
  369. if(d[0] == 'priv')
  370. {
  371. if(!data.priv) data.priv = [];
  372. data.priv.push(d[1]);
  373. }
  374. }
  375. }
  376. if(data.reviewType != 'reject')
  377. {
  378. if(d[0].indexOf('ccType') === 0) // 设置抄送
  379. {
  380. var index = parseInt(d[0].substring(7));
  381. ccs[index] = {type: d[1]}; // 支持指定人员,发起人自选,上级,角色
  382. if(d[1] == 'select')
  383. {
  384. ccs[index].users = [];
  385. ccs[index].roles = [];
  386. ccs[index].depts = [];
  387. ccs[index].positions = [];
  388. }
  389. if(d[1] == 'appointee') ccs[index].users = []; // 指定人员
  390. if(d[1] == 'role') ccs[index].roles = []; // 角色
  391. if(d[1] == 'position') ccs[index].positions = []; // 职位
  392. }
  393. else if(d[0].indexOf('ccusers') === 0) //设置抄送人
  394. {
  395. var index = parseInt(d[0].substring(8));
  396. if(ccs[index].type == 'appointee') ccs[index].users.push(d[1]);
  397. }
  398. else if(d[0].indexOf('ccroles') === 0) //设置抄送角色
  399. {
  400. var index = parseInt(d[0].substring(8));
  401. if(ccs[index].type == 'role') ccs[index].roles.push(d[1]);
  402. }
  403. else if(d[0].indexOf('ccpositions') === 0) //设置抄送职位
  404. {
  405. var index = parseInt(d[0].substring(12));
  406. if(ccs[index].type == 'position') ccs[index].positions.push(d[1]);
  407. }
  408. else if(d[0].indexOf('ccrangeuser') === 0) // 人员范围
  409. {
  410. var index = parseInt(d[0].substring(12));
  411. if(ccs[index].type == 'select') ccs[index].users.push(d[1]);
  412. }
  413. else if(d[0].indexOf('ccrangerole') === 0) // 角色范围
  414. {
  415. var index = parseInt(d[0].substring(12));
  416. if(ccs[index].type == 'select') ccs[index].roles.push(d[1]);
  417. }
  418. else if(d[0].indexOf('ccrangeposition') === 0) // 职位范围
  419. {
  420. var index = parseInt(d[0].substring(16));
  421. if(ccs[index].type == 'select') ccs[index].positions.push(d[1]);
  422. }
  423. else if(d[0].indexOf('ccrangedept') === 0) // 部门范围
  424. {
  425. var index = parseInt(d[0].substring(12));
  426. if(ccs[index].type == 'select') ccs[index].depts.push(d[1]);
  427. }
  428. else if(d[0].indexOf('ccuserRange') === 0) // 指定范围
  429. {
  430. var index = parseInt(d[0].substring(12));
  431. if(ccs[index].type == 'select') ccs[index].userRange = d[1];
  432. }
  433. }
  434. }
  435. if(node.type == 'approval')
  436. {
  437. data.reviewers = [];
  438. for(var i in reviewers) data.reviewers.push(reviewers[i]);
  439. }
  440. data.ccs = [];
  441. for(var i in ccs) data.ccs.push(ccs[i]);
  442. var message = checkNode(node.type, data)
  443. if(message)
  444. {
  445. zui.Messager.show({content:message, close: false});
  446. return;
  447. }
  448. father[index1] = data;
  449. $.post(link, {nodes: JSON.stringify(nodes), 'type': 'update'}, function(data)
  450. {
  451. $('body').data('zui.Modal').hide();
  452. $('#editor').html($(data).find('#editor').html()).zuiInit();
  453. });
  454. });
  455. return false;
  456. }
  457. window.checkNode = function(type, data)
  458. {
  459. var reviewerSelectCount = 0;
  460. if(typeof data.reviewers === 'undefined' || data.reviewers.length == 0)
  461. {
  462. if(type == 'approval' && data.reviewType == 'manual') return warningLang['needReviewer'];
  463. }
  464. else
  465. {
  466. for(var reviewer of data.reviewers)
  467. {
  468. if(reviewer.type == 'appointee' && (reviewer.users.length === 0 || reviewer.users == '')) return warningLang['selectUser'];
  469. if(reviewer.type == 'role' && (reviewer.roles.length === 0 || reviewer.roles == '')) return warningLang['selectRole'];
  470. if(reviewer.type == 'position' && (reviewer.positions.length === 0 || reviewer.roles == '')) return warningLang['selectPosition'];
  471. if(reviewer.type == 'select' || reviewer.type == 'setByPrev')
  472. {
  473. if(reviewerSelectCount !== 0) return warningLang['oneSelect'];
  474. reviewerSelectCount ++;
  475. }
  476. }
  477. }
  478. var ccSelectCount = 0;
  479. if(typeof data.ccs !== 'undefined')
  480. {
  481. for(var cc of data.ccs)
  482. {
  483. if(cc.type == 'appointee' && (cc.users.length === 0 || cc.users == '')) return warningLang['selectUser'];
  484. if(cc.type == 'role' && (cc.roles.length === 0 || cc.roles == '')) return warningLang['selectRole'];
  485. if(cc.type == 'position' && (cc.positions.length === 0 || cc.positions == '')) return warningLang['selectPosition'];
  486. if(cc.type == 'select')
  487. {
  488. if(ccSelectCount !== 0) return warningLang['oneSelect'];
  489. ccSelectCount ++;
  490. }
  491. }
  492. }
  493. return '';
  494. }
  495. window.renderRowData = function($row, index, row)
  496. {
  497. if(row)
  498. {
  499. if(row.type || row.ccType)
  500. {
  501. const type = row.type ? row.type : row.ccType;
  502. $row.find('[data-name=approval] .picker-box').addClass('hidden');
  503. $row.find("[data-type='" + type + "']").removeClass('hidden');
  504. if(row.type == 'select') $row.find('[data-type=required]').removeClass('hidden');
  505. if(type == 'self' || type == 'upLevel' || type == 'setByPrev' || type == 'superior')
  506. {
  507. $row.find('[data-name=type]').attr('colspan', '2');
  508. $row.find('[data-name=ccType]').attr('colspan', '2');
  509. $row.find('[data-name=approval]').addClass('hidden');
  510. }
  511. else
  512. {
  513. $row.find('[data-name=type]').attr('colspan', '1');
  514. $row.find('[data-name=ccType]').attr('colspan', '1');
  515. $row.find('[data-name=approval]').removeClass('hidden');
  516. }
  517. }
  518. if(row.userRange || row.ccuserRange)
  519. {
  520. const option = row.userRange ? ('range' + row.userRange) : ('ccrange' + row.ccuserRange);
  521. $row.find('[data-type=range]').addClass('hidden');
  522. $row.find('[data-type=ccrange]').addClass('hidden');
  523. $row.find('[data-type=' + option + ']').removeClass('hidden');
  524. }
  525. }
  526. }
  527. window.renderConditionRowData = function($row, index, row)
  528. {
  529. // 第一行不显示逻辑运算符控件
  530. if(index == 0) $row.find('[data-name=conditionLogical] > div').addClass('hidden');
  531. // ajax获取字段控件
  532. let field;
  533. let value;
  534. if(typeof row !== 'undefined')
  535. {
  536. // 条件有数据的情况
  537. field = row?.conditionField;
  538. value = row?.conditionValue;
  539. }
  540. else
  541. {
  542. // 条件无数据的情况
  543. field = 'submitUsers';
  544. value = '';
  545. }
  546. changeFieldControl($row, index, field, value);
  547. }
  548. window.changeFieldControl = function($row, index, field, value)
  549. {
  550. const url = $.createLink('approvalflow', 'ajaxGetFieldControl', `field=${field}&module=${workflow}`);
  551. $.get(url, function(data)
  552. {
  553. data = JSON.parse(data);
  554. $row.find('[data-name=conditionValue]').html(`<div class='controlBox'></div>`);
  555. const controlBox = $row.find('.controlBox');
  556. const options = data.options;
  557. const control = data.control;
  558. const name = `conditionValue[${index + 1}]`;
  559. if(control == 'picker')
  560. {
  561. new zui.Picker(controlBox, {
  562. items: options,
  563. defaultValue: value,
  564. name: name,
  565. required: true
  566. });
  567. }
  568. else if(control == 'datePicker')
  569. {
  570. const datePicker = new zui.DatePicker(controlBox, {name: name});
  571. setTimeout(() => datePicker.$.setValue(value), 50);
  572. }
  573. else if(control == 'datetimePicker')
  574. {
  575. const datetimePicker = new zui.DatetimePicker(controlBox, {name: name});
  576. setTimeout(() => datetimePicker.$.setValue(value), 50);
  577. }
  578. else
  579. {
  580. controlBox.html(`<input type='text' class='form-control' name='${name}' value='${value}' required>`);
  581. }
  582. });
  583. }
  584. window.changeReviewType = function(event)
  585. {
  586. $('#reviewTypeBox').toggleClass('hidden', $(event.target).val() == 'reject');
  587. $('#reviewTypeBox li[data-key=reviewer]').toggleClass('hidden', $(event.target).val() == 'pass');
  588. $('#reviewTypeBox li[data-key=approvalflow]').toggleClass('hidden', $(event.target).val() == 'pass');
  589. if($(event.target).val() == 'pass') $('#reviewTypeBox li[data-key=ccer] > a').trigger('click');
  590. if($(event.target).val() == 'manual') $('#reviewTypeBox li[data-key=reviewer] > a').trigger('click');
  591. }
  592. window.changeType = function(event)
  593. {
  594. const $row = $(event.target).closest('tr');
  595. const type = $(event.target).val();
  596. $row.find('[data-name=approval] .picker-box').addClass('hidden');
  597. $row.find("[data-type='" + type + "']").removeClass('hidden');
  598. $row.find("[data-type='" + type + "'] .pick-value").trigger('change');
  599. if(type == 'select') $row.find('[data-type=required]').removeClass('hidden');
  600. if(type == 'self' || type == 'upLevel' || type == 'setByPrev' || type == 'superior')
  601. {
  602. $row.find('[data-name=type]').attr('colspan', '2');
  603. $row.find('[data-name=ccType]').attr('colspan', '2');
  604. $row.find('[data-name=approval]').addClass('hidden');
  605. }
  606. else
  607. {
  608. $row.find('[data-name=type]').attr('colspan', '1');
  609. $row.find('[data-name=ccType]').attr('colspan', '1');
  610. $row.find('[data-name=approval]').removeClass('hidden');
  611. }
  612. }
  613. window.changeOption = function(event)
  614. {
  615. const $row = $(event.target).closest('tr');
  616. const option = $(event.target).val();
  617. if(!option || typeof(option) != 'string') return;
  618. $row.find('.picker-box[data-name^=range]').addClass('hidden');
  619. $row.find(".picker-box[data-name^='range" + option + "']").removeClass('hidden');
  620. $row.find('.picker-box[data-name^=ccrange]').addClass('hidden');
  621. $row.find(".picker-box[data-name^='ccrange" + option + "']").removeClass('hidden');
  622. }
  623. window.changeMultiple = function(event)
  624. {
  625. $('#reviewTypeBox [name=needAll]').parent().addClass('hidden');
  626. $(event.target).parent().find('[name=needAll]').parent().removeClass('hidden');
  627. $('#reviewTypeBox [name=percent]').parent().toggleClass('hidden', $(event.target).val() != 'percent');
  628. }
  629. window.changeAgentType = function(event)
  630. {
  631. $('#reviewTypeBox [name=agentUser]').closest('.picker-box').toggleClass('hidden', $(event.target).val() != 'appointee');
  632. }
  633. window.changeDeletedType = function(event)
  634. {
  635. $('#reviewTypeBox [name=setUser]').closest('.picker-box').toggleClass('hidden', $(event.target).val() != 'setUser');
  636. }
  637. window.changeConditionField = function(event)
  638. {
  639. const $row = $(event.target).closest('tr');
  640. const index = $row.data('index');
  641. const field = $(event.target).val();
  642. changeFieldControl($row, index, field, '');
  643. }
  644. window.checkPercent = function(e)
  645. {
  646. const percent = parseInt(e.target.value);
  647. if(percent < 1 || percent > 100 || isNaN(percent) || percent != e.target.value)
  648. {
  649. $('#percent').val('50');
  650. zui.Modal.alert(warningLang['percent']);
  651. }
  652. }