懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
提交 | 用户 | 时间
1ac2bc 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 /*
20  * Assignment
21  */
22 var KisBpmAssignmentCtrl = [ '$scope', '$modal', function($scope, $modal) {
23
24     // Config for the modal window
25     var opts = {
26         template:  'editor-app/configuration/properties/assignment-popup.html?version=' + Date.now(),
27         scope: $scope
28     };
29
30     // Open the dialog
31     $modal(opts);
32 }];
33
34 var KisBpmAssignmentPopupCtrl = [ '$scope', function($scope) {
35         
36     // Put json representing assignment on scope
37     if ($scope.property.value !== undefined && $scope.property.value !== null
38         && $scope.property.value.assignment !== undefined
39         && $scope.property.value.assignment !== null) 
40     {
41         $scope.assignment = $scope.property.value.assignment;
42     } else {
43         $scope.assignment = {};
44     }
45
46     if ($scope.assignment.candidateUsers == undefined || $scope.assignment.candidateUsers.length == 0)
47     {
48         $scope.assignment.candidateUsers = [{value: ''}];
49     }
50     
51     // Click handler for + button after enum value
52     var userValueIndex = 1;
53     $scope.addCandidateUserValue = function(index) {
54         $scope.assignment.candidateUsers.splice(index + 1, 0, {value: 'value ' + userValueIndex++});
55     };
56
57     // Click handler for - button after enum value
58     $scope.removeCandidateUserValue = function(index) {
59         $scope.assignment.candidateUsers.splice(index, 1);
60     };
61     
62     if ($scope.assignment.candidateGroups == undefined || $scope.assignment.candidateGroups.length == 0)
63     {
64         $scope.assignment.candidateGroups = [{value: ''}];
65     }
66     
67     var groupValueIndex = 1;
68     $scope.addCandidateGroupValue = function(index) {
69         $scope.assignment.candidateGroups.splice(index + 1, 0, {value: 'value ' + groupValueIndex++});
70     };
71
72     // Click handler for - button after enum value
73     $scope.removeCandidateGroupValue = function(index) {
74         $scope.assignment.candidateGroups.splice(index, 1);
75     };
76
77     $scope.save = function() {
78
79         $scope.property.value = {};
80         handleAssignmentInput($scope);
81         $scope.property.value.assignment = $scope.assignment;
82         
83         $scope.updatePropertyInModel($scope.property);
84         $scope.close();
85     };
86
87     // Close button handler
88     $scope.close = function() {
89         handleAssignmentInput($scope);
90         $scope.property.mode = 'read';
91         $scope.$hide();
92     };
93     
94     var handleAssignmentInput = function($scope) {
95         if ($scope.assignment.candidateUsers)
96         {
97             var emptyUsers = true;
98             var toRemoveIndexes = [];
99             for (var i = 0; i < $scope.assignment.candidateUsers.length; i++)
100             {
101                 if ($scope.assignment.candidateUsers[i].value != '')
102                 {
103                     emptyUsers = false;
104                 }
105                 else
106                 {
107                     toRemoveIndexes[toRemoveIndexes.length] = i;
108                 }
109             }
110             
111             for (var i = 0; i < toRemoveIndexes.length; i++)
112             {
113                 $scope.assignment.candidateUsers.splice(toRemoveIndexes[i], 1);
114             }
115             
116             if (emptyUsers)
117             {
118                 $scope.assignment.candidateUsers = undefined;
119             }
120         }
121         
122         if ($scope.assignment.candidateGroups)
123         {
124             var emptyGroups = true;
125             var toRemoveIndexes = [];
126             for (var i = 0; i < $scope.assignment.candidateGroups.length; i++)
127             {
128                 if ($scope.assignment.candidateGroups[i].value != '')
129                 {
130                     emptyGroups = false;
131                 }
132                 else
133                 {
134                     toRemoveIndexes[toRemoveIndexes.length] = i;
135                 }
136             }
137             
138             for (var i = 0; i < toRemoveIndexes.length; i++)
139             {
140                 $scope.assignment.candidateGroups.splice(toRemoveIndexes[i], 1);
141             }
142             
143             if (emptyGroups)
144             {
145                 $scope.assignment.candidateGroups = undefined;
146             }
147         }
148     };
149 }];