properties-assignment-controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. * Activiti Modeler component part of the Activiti project
  3. * Copyright 2005-2014 Alfresco Software, Ltd. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /*
  19. * Assignment
  20. */
  21. var KisBpmAssignmentCtrl = ['$scope', '$modal', '$http', function ($scope, $modal, $http) {
  22. // Config for the modal window
  23. var opts = {
  24. template: 'editor-app/configuration/properties/assignment-popup.html?version=' + Date.now(),
  25. scope: $scope
  26. };
  27. // Open the dialog
  28. $modal(opts);
  29. }];
  30. var KisBpmAssignmentPopupCtrl = ['$scope', '$modal', '$http', function ($scope, $modal, $http) {
  31. // Put json representing assignment on scope
  32. if ($scope.property.value !== undefined && $scope.property.value !== null
  33. && $scope.property.value.assignment !== undefined
  34. && $scope.property.value.assignment !== null) {
  35. $scope.assignment = $scope.property.value.assignment;
  36. } else {
  37. $scope.assignment = {};
  38. }
  39. if ($scope.assignment.candidateUsers == undefined || $scope.assignment.candidateUsers.length == 0) {
  40. $scope.assignment.candidateUsers = [{value: ''}];
  41. }
  42. if ($scope.assignment.assignee == undefined || $scope.assignment.assignee == '') {
  43. $scope.assignment.assignee = '';
  44. }
  45. // Click handler for + button after enum value
  46. var userValueIndex = 1;
  47. $scope.addCandidateUserValue = function (index) {
  48. $scope.assignment.candidateUsers.splice(index + 1, 0, {value: 'value ' + userValueIndex++});
  49. };
  50. // Click handler for - button after enum value
  51. $scope.removeCandidateUserValue = function (index) {
  52. $scope.assignment.candidateUsers.splice(index, 1);
  53. };
  54. if ($scope.assignment.candidateGroups == undefined || $scope.assignment.candidateGroups.length == 0) {
  55. $scope.assignment.candidateGroups = [{value: ''}];
  56. }
  57. var groupValueIndex = 1;
  58. $scope.addCandidateGroupValue = function (index) {
  59. $scope.assignment.candidateGroups.splice(index + 1, 0, {value: 'value ' + groupValueIndex++});
  60. };
  61. // Click handler for - button after enum value
  62. $scope.removeCandidateGroupValue = function (index) {
  63. $scope.assignment.candidateGroups.splice(index, 1);
  64. };
  65. //Open the dialog to select users
  66. $scope.choseAssignment = function (flag) {
  67. var opts = {
  68. template: 'editor-app/configuration/properties/assignment-popup-popup.html?version=' + Date.now(),
  69. scope: $scope
  70. };
  71. $scope.choseAssignmentFlag = flag;
  72. // Open the dialog
  73. $modal(opts);
  74. };
  75. //Open the dialog to select candidateGroups
  76. $scope.choseCandidateGroups = function () {
  77. var opts = {
  78. template: 'editor-app/configuration/properties/assignment-candidateGroup.html?version=' + Date.now(),
  79. scope: $scope
  80. };
  81. // Open the dialog
  82. $modal(opts);
  83. };
  84. $scope.dynCandidateUser = function (position) {
  85. $scope.assignment.assignee = "${" + position.code + "}";
  86. $scope.assignment.assigneeshowname = position.name;
  87. if (typeof $scope.property.value === 'string') {
  88. $scope.property.value = {};
  89. }
  90. $scope.property.value.assignment = $scope.assignment;
  91. $scope.updatePropertyInModel($scope.property);
  92. $scope.close();
  93. };
  94. $scope.save = function () {
  95. $scope.property.value = {};
  96. handleAssignmentInput($scope);
  97. $scope.property.value.assignment = $scope.assignment;
  98. $scope.updatePropertyInModel($scope.property);
  99. $scope.close();
  100. };
  101. // Close button handler
  102. $scope.close = function () {
  103. handleAssignmentInput($scope);
  104. $scope.property.mode = 'read';
  105. $scope.$hide();
  106. };
  107. var handleAssignmentInput = function ($scope) {
  108. if ($scope.assignment.candidateUsers) {
  109. var emptyUsers = true;
  110. var toRemoveIndexes = [];
  111. for (var i = 0; i < $scope.assignment.candidateUsers.length; i++) {
  112. if ($scope.assignment.candidateUsers[i].value != '') {
  113. emptyUsers = false;
  114. } else {
  115. toRemoveIndexes[toRemoveIndexes.length] = i;
  116. }
  117. }
  118. for (var i = 0; i < toRemoveIndexes.length; i++) {
  119. $scope.assignment.candidateUsers.splice(toRemoveIndexes[i], 1);
  120. }
  121. if (emptyUsers) {
  122. $scope.assignment.candidateUsers = undefined;
  123. }
  124. }
  125. if ($scope.assignment.candidateGroups) {
  126. var emptyGroups = true;
  127. var toRemoveIndexes = [];
  128. for (var i = 0; i < $scope.assignment.candidateGroups.length; i++) {
  129. if ($scope.assignment.candidateGroups[i].value != '') {
  130. emptyGroups = false;
  131. } else {
  132. toRemoveIndexes[toRemoveIndexes.length] = i;
  133. }
  134. }
  135. for (var i = 0; i < toRemoveIndexes.length; i++) {
  136. $scope.assignment.candidateGroups.splice(toRemoveIndexes[i], 1);
  137. }
  138. if (emptyGroups) {
  139. $scope.assignment.candidateGroups = undefined;
  140. }
  141. }
  142. };
  143. //因新打开的界面上选定的数据要传输到当前modal中,所以使用此方式,这是angular.js中不同控制器之间传输数据的方式
  144. $scope.$on('choseAssigneesStr', function (event, data, nameData) {
  145. var infos = data.split(",");
  146. var nameInfos = nameData.split(",");
  147. // $scope.assignment.candidateUsers= [];
  148. for (var i = 0; i < infos.length; i++) {
  149. $scope.assignment.candidateUsers.push({value: infos[i], nameValue: nameInfos[i]});
  150. // $scope.assignment.candidateUsers[i].value = infos[i];
  151. }
  152. //清空第一个
  153. if ((!$scope.assignment.candidateUsers[0].value) || $scope.assignment.candidateUsers[0] == '') {
  154. //清空第一个元素
  155. $scope.assignment.candidateUsers.splice(0, 1);
  156. }
  157. });
  158. $scope.$on('choseAssigneeStr', function (event, data) {
  159. $scope.assignment.assignee = data;
  160. });
  161. $scope.$on('choseAssigneeNameStr', function (event, data) {
  162. $scope.assignment.assigneeshowname = data;
  163. });
  164. $scope.$on('choseCandidateGroupsStr', function (event, data, nameData) {
  165. // $scope.assignment.candidateGroups[0].value = data;
  166. var infos = data.split(",");
  167. var nameInfos = nameData.split(",");
  168. for (var i = 0; i < infos.length; i++) {
  169. // $scope.assignment.candidateGroups[i].value = infos[i];
  170. $scope.assignment.candidateGroups.push({value: infos[i], nameValue: nameInfos[i]});
  171. }
  172. //清空第一个
  173. if ((!$scope.assignment.candidateGroups[0].value) || $scope.assignment.candidateGroups[0] == '') {
  174. //清空第一个元素
  175. $scope.assignment.candidateGroups.splice(0, 1);
  176. }
  177. });
  178. }];
  179. // 用户列表
  180. var KisBpmChoseAssignmentCtrl = ['$scope', '$http', function ($scope, $http) {
  181. $scope.keyword = '';
  182. $scope.reload = true;
  183. $scope.paginationConf = {
  184. currentPage: 1,
  185. totalItems: 100,
  186. itemsPerPage: 10,
  187. pagesLength: 5,
  188. perPageOptions: [10, 20, 30, 40, 50],
  189. onChange: function () {
  190. if (!$scope.reload) {
  191. return;
  192. }
  193. $scope.reloadList();//重新加载 这个方法会重复调用两次
  194. $scope.reload = false;
  195. setTimeout(function () {
  196. $scope.reload = true;
  197. }, 200);
  198. }
  199. };
  200. // 刷新列表方法
  201. $scope.reloadList = function () {
  202. $scope.findPage($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  203. }
  204. // 分页方法,请求数据
  205. $scope.findPage = function (page, limit) {
  206. let accounts = [];
  207. $http({
  208. method: 'get',
  209. headers: {
  210. 'Accept': 'application/json',
  211. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  212. },
  213. url: ACTIVITI.CONFIG.baseUrl + '/service/act/user/actUserList' + '/' + page + '/' + limit + "?keyword=" + $scope.keyword
  214. })
  215. .success(function (data, status, headers, config) {
  216. //封装数据
  217. let obj = data.result;
  218. if (data != null && data.code == 200) {
  219. obj.forEach(function (e, i) {
  220. accounts.push({id: e.id, code: e.firstName, name: e.firstName, index: i, checked: false,selected: false});
  221. })
  222. }
  223. $scope.accounts = accounts;
  224. $scope.paginationConf.totalItems = data.total;
  225. })
  226. .error(function (data, status, headers, config) {
  227. });
  228. }
  229. //模态框左侧组的点击事件:根据所点击的组获取当前组的所有用户
  230. $scope.queryByRole = function (value) {
  231. //初始化表格
  232. $scope.keyword = '';
  233. $scope.paginationConf.currentPage = 1;
  234. $scope.reloadList();
  235. };
  236. $scope.queryByKeyword = function () {
  237. $scope.paginationConf.currentPage = 1;
  238. $scope.reloadList();
  239. }
  240. $scope.reset = function () {
  241. $scope.keyword = "";
  242. $scope.paginationConf.currentPage = 1;
  243. $scope.reloadList();
  244. }
  245. //初始化左边菜单栏数据,并触发第一个菜单的点击事件
  246. let roles = [];
  247. $scope.getAllRoles = function (successCallback) {
  248. $http({
  249. method: 'get',
  250. headers: {
  251. 'Accept': 'application/json',
  252. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  253. 'X-Access-Token': ACTIVITI.CONFIG.token
  254. },
  255. url: ACTIVITI.CONFIG.baseUrl + '/service/act/role/getRoleList'
  256. })
  257. .success(function (data, status, headers, config) {
  258. let obj = data;
  259. for (var i = 0; i < obj.length; i++) {
  260. roles.push({id: obj[i].id, name: obj[i].name});
  261. }
  262. $scope.roles = roles;
  263. })
  264. .error(function (data, status, headers, config) {
  265. });
  266. };
  267. $scope.getAllRoles(function () {
  268. });
  269. // Close button handler
  270. $scope.close = function () {
  271. $scope.$hide();
  272. };
  273. $scope.formData = {};
  274. $scope.candidateUser = {};
  275. //Save Data
  276. $scope.save = function () {
  277. if ($scope.choseAssignmentFlag == "assignee") {
  278. var choseAssignees = $scope.accounts;
  279. var choseAssigneesStr = "";
  280. var choseAssigneesNameStr = "";
  281. for (var i = 0; i < choseAssignees.length; i++) {
  282. if (choseAssignees[i].checked) {
  283. choseAssigneesStr = choseAssignees[i].id;
  284. choseAssigneesNameStr = choseAssignees[i].name;
  285. break;
  286. }
  287. }
  288. $scope.$emit('choseAssigneeStr', choseAssigneesStr);
  289. $scope.$emit('choseAssigneeNameStr', choseAssigneesNameStr);
  290. } else if ($scope.choseAssignmentFlag == "assignees") {
  291. var choseAssignees = $scope.accounts;
  292. var choseAssigneesStr = "";
  293. var choseAssigneesNameStr = "";
  294. for (var i = 0; i < choseAssignees.length; i++) {
  295. if (choseAssignees[i].selected) {
  296. choseAssigneesStr += choseAssignees[i].id + ",";
  297. choseAssigneesNameStr += choseAssignees[i].name + ",";
  298. }
  299. }
  300. choseAssigneesStr = choseAssigneesStr.substring(0, choseAssigneesStr.length - 1);
  301. choseAssigneesNameStr = choseAssigneesNameStr.substring(0, choseAssigneesNameStr.length - 1);
  302. $scope.$emit('choseAssigneesStr', choseAssigneesStr, choseAssigneesNameStr);
  303. }
  304. $scope.close();
  305. };
  306. $scope.selectAll = function () {
  307. var choseAssignees = $scope.accounts;
  308. for (var i = 0; i < choseAssignees.length; i++) {
  309. choseAssignees[i].selected = true;
  310. }
  311. $scope.accounts = choseAssignees;
  312. };
  313. $scope.rowClick = function (id) {
  314. var type = $scope.choseAssignmentFlag;
  315. var choseAssignees = $scope.accounts;
  316. for (var i = 0; i < choseAssignees.length; i++) {
  317. if (type == "assignee") {
  318. if (choseAssignees[i].id == id) {
  319. choseAssignees[i].checked = true;
  320. } else {
  321. choseAssignees[i].checked = false;
  322. }
  323. } else if (type == "assignees") {
  324. if (choseAssignees[i].id == id) {
  325. choseAssignees[i].selected = choseAssignees[i].selected ? false : true;
  326. }
  327. }
  328. }
  329. $scope.accounts = choseAssignees;
  330. }
  331. }];
  332. var KisBpmChoseCandidateGroupsCtrl = ['$scope', '$http', function ($scope, $http) {
  333. var candidateGroups = [];
  334. $scope.getAllRoles = function (successCallback) {
  335. $http({
  336. method: 'get',
  337. headers: {
  338. 'Accept': 'application/json',
  339. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  340. },
  341. url: ACTIVITI.CONFIG.baseUrl + '/service/act/role/getRoleList'
  342. })
  343. .success(function (data, status, headers, config) {
  344. let obj = data;
  345. for (let i = 0; i < obj.length; i++) {
  346. candidateGroups.push({id: obj[i].id, name: obj[i].name, description: obj[i].id});
  347. }
  348. $scope.candidateGroups = candidateGroups;
  349. })
  350. .error(function (data, status, headers, config) {
  351. });
  352. };
  353. $scope.getAllRoles(function () {
  354. });
  355. // Close button handler
  356. $scope.close = function () {
  357. $scope.$hide();
  358. };
  359. $scope.save = function () {
  360. var choseCandidateGroups = $scope.candidateGroups;
  361. var choseCandidateGroupsStr = "";
  362. var choseAssigneesNameStr = "";
  363. for (var i = 0; i < choseCandidateGroups.length; i++) {
  364. if (choseCandidateGroups[i].selected) {
  365. choseCandidateGroupsStr += choseCandidateGroups[i].id + ",";
  366. choseAssigneesNameStr += choseCandidateGroups[i].name + ",";//---------id改name
  367. }
  368. }
  369. choseCandidateGroupsStr = choseCandidateGroupsStr.substring(0, choseCandidateGroupsStr.length - 1);
  370. choseAssigneesNameStr = choseAssigneesNameStr.substring(0, choseAssigneesNameStr.length - 1);
  371. $scope.$emit('choseCandidateGroupsStr', choseCandidateGroupsStr, choseAssigneesNameStr);
  372. $scope.close();
  373. }
  374. $scope.selectAll = function () {
  375. var candidateGroups = $scope.candidateGroups;
  376. for (var i = 0; i < candidateGroups.length; i++) {
  377. candidateGroups[i].selected = true;
  378. }
  379. $scope.candidateGroups = candidateGroups;
  380. };
  381. $scope.rowClick = function (id) {
  382. var candidateGroups = $scope.candidateGroups;
  383. for (var i = 0; i < candidateGroups.length; i++) {
  384. if (candidateGroups[i].id == id) {
  385. candidateGroups[i].selected = candidateGroups[i].selected ? false : true;
  386. }
  387. }
  388. $scope.candidateGroups = candidateGroups;
  389. }
  390. }];