properties-assignment-controller.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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', function($scope, $modal) {
  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', function($scope) {
  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. {
  36. $scope.assignment = $scope.property.value.assignment;
  37. } else {
  38. $scope.assignment = {};
  39. }
  40. if ($scope.assignment.candidateUsers == undefined || $scope.assignment.candidateUsers.length == 0)
  41. {
  42. $scope.assignment.candidateUsers = [{value: ''}];
  43. }
  44. // Click handler for + button after enum value
  45. var userValueIndex = 1;
  46. $scope.addCandidateUserValue = function(index) {
  47. $scope.assignment.candidateUsers.splice(index + 1, 0, {value: 'value ' + userValueIndex++});
  48. };
  49. // Click handler for - button after enum value
  50. $scope.removeCandidateUserValue = function(index) {
  51. $scope.assignment.candidateUsers.splice(index, 1);
  52. };
  53. if ($scope.assignment.candidateGroups == undefined || $scope.assignment.candidateGroups.length == 0)
  54. {
  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. $scope.openUserSelectDialog = function(index) {
  62. jp.openUserSelectDialog(false,function(ids, names, loginNames){
  63. if(index != -1){
  64. $scope.assignment.candidateUsers[index].value = loginNames;
  65. $scope.$apply();
  66. }else{
  67. $scope.assignment.assignee = loginNames;
  68. $scope.$apply();
  69. }
  70. })
  71. };
  72. $scope.openRoleSelectDialog = function(index) {
  73. jp.openRoleSelectDialog(false,function(ids, names){
  74. $scope.assignment.candidateGroups[index].value = names;
  75. $scope.$apply();
  76. })
  77. };
  78. // Click handler for - button after enum value
  79. $scope.removeCandidateGroupValue = function(index) {
  80. $scope.assignment.candidateGroups.splice(index, 1);
  81. };
  82. $scope.save = function() {
  83. $scope.property.value = {};
  84. handleAssignmentInput($scope);
  85. $scope.property.value.assignment = $scope.assignment;
  86. $scope.updatePropertyInModel($scope.property);
  87. $scope.close();
  88. };
  89. // Close button handler
  90. $scope.close = function() {
  91. handleAssignmentInput($scope);
  92. $scope.property.mode = 'read';
  93. $scope.$hide();
  94. };
  95. var handleAssignmentInput = function($scope) {
  96. if ($scope.assignment.candidateUsers)
  97. {
  98. var emptyUsers = true;
  99. var toRemoveIndexes = [];
  100. for (var i = 0; i < $scope.assignment.candidateUsers.length; i++)
  101. {
  102. if ($scope.assignment.candidateUsers[i].value != '')
  103. {
  104. emptyUsers = false;
  105. }
  106. else
  107. {
  108. toRemoveIndexes[toRemoveIndexes.length] = i;
  109. }
  110. }
  111. for (var i = 0; i < toRemoveIndexes.length; i++)
  112. {
  113. $scope.assignment.candidateUsers.splice(toRemoveIndexes[i], 1);
  114. }
  115. if (emptyUsers)
  116. {
  117. $scope.assignment.candidateUsers = undefined;
  118. }
  119. }
  120. if ($scope.assignment.candidateGroups)
  121. {
  122. var emptyGroups = true;
  123. var toRemoveIndexes = [];
  124. for (var i = 0; i < $scope.assignment.candidateGroups.length; i++)
  125. {
  126. if ($scope.assignment.candidateGroups[i].value != '')
  127. {
  128. emptyGroups = false;
  129. }
  130. else
  131. {
  132. toRemoveIndexes[toRemoveIndexes.length] = i;
  133. }
  134. }
  135. for (var i = 0; i < toRemoveIndexes.length; i++)
  136. {
  137. $scope.assignment.candidateGroups.splice(toRemoveIndexes[i], 1);
  138. }
  139. if (emptyGroups)
  140. {
  141. $scope.assignment.candidateGroups = undefined;
  142. }
  143. }
  144. };
  145. }];