广州市综治平台后端
xusd
2 days ago c490640493f04e2ed0fc5c4c8fbc92ebdd4d5380
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
/*
 * Escalation definitions
 */
 
angular.module('flowableModeler').controller('FlowableEscalationDefinitionsCtrl', ['$scope', '$modal', function ($scope, $modal) {
 
    // Config for the modal window
    var opts = {
        template: 'editor-app/configuration/properties/escalation-definitions-popup.html?version=' + Date.now(),
        scope: $scope
    };
 
    // Open the dialog
    _internalCreateModal(opts, $modal, $scope);
}]);
 
//Need a separate controller for the modal window due to https://github.com/angular-ui/bootstrap/issues/259
// Will be fixed in a newer version of Angular UI
angular.module('flowableModeler').controller('FlowableEscalationDefinitionsPopupCtrl',
    ['$scope', '$q', '$translate', '$timeout', function ($scope, $q, $translate, $timeout) {
 
        // Put json representing signal definitions on scope
        if ($scope.property.value !== undefined && $scope.property.value !== null && $scope.property.value.length > 0) {
 
            if ($scope.property.value.constructor == String) {
                $scope.escalationDefinitions = JSON.parse($scope.property.value);
            }
            else {
                // Note that we clone the json object rather then setting it directly,
                // this to cope with the fact that the user can click the cancel button and no changes should have happened
                $scope.escalationDefinitions = angular.copy($scope.property.value);
            }
 
        } else {
            $scope.escalationDefinitions = [];
        }
 
        // Array to contain selected signal definitions (yes - we only can select one, but ng-grid isn't smart enough)
        $scope.selectedEscalationDefinition = undefined;
        $scope.translationsRetrieved = false;
 
        $scope.labels = {};
 
        var idPromise = $translate('PROPERTY.ESCALATIONDEFINITIONS.ID');
        var namePromise = $translate('PROPERTY.ESCALATIONDEFINITIONS.NAME');
 
        $q.all([idPromise, namePromise]).then(function (results) {
 
            $scope.labels.idLabel = results[0];
            $scope.labels.nameLabel = results[1];
            $scope.translationsRetrieved = true;
 
            // Config for grid
            $scope.gridOptions = {
                data: $scope.escalationDefinitions,
                headerRowHeight: 28,
                enableRowSelection: true,
                enableRowHeaderSelection: false,
                multiSelect: false,
                modifierKeysToMultiSelect: false,
                enableHorizontalScrollbar: 0,
                enableColumnMenus: false,
                enableSorting: false,
                columnDefs: [
                    {field: 'id', displayName: $scope.labels.idLabel},
                    {field: 'name', displayName: $scope.labels.nameLabel}]
            };
 
            $scope.gridOptions.onRegisterApi = function (gridApi) {
                //set gridApi on scope
                $scope.gridApi = gridApi;
                gridApi.selection.on.rowSelectionChanged($scope, function (row) {
                    $scope.selectedEscalationDefinition = row.entity;
                });
            };
        });
 
        // Click handler for add button
        $scope.addNewEscalationDefinition = function () {
            var newEscalationDefinition = {id: '', name: ''};
 
            $scope.escalationDefinitions.push(newEscalationDefinition);
            $timeout(function () {
                $scope.gridApi.selection.toggleRowSelection(newEscalationDefinition);
            });
        };
 
        // Click handler for remove button
        $scope.removeEscalationDefinition = function () {
            var selectedItems = $scope.gridApi.selection.getSelectedRows();
            if (selectedItems && selectedItems.length > 0) {
                var index = $scope.escalationDefinitions.indexOf(selectedItems[0]);
                $scope.gridApi.selection.toggleRowSelection(selectedItems[0]);
                $scope.escalationDefinitions.splice(index, 1);
 
                if ($scope.escalationDefinitions.length == 0) {
                    $scope.selectedEscalationDefinition = undefined;
                }
 
                $timeout(function () {
                    if ($scope.escalationDefinitions.length > 0) {
                        $scope.gridApi.selection.toggleRowSelection($scope.escalationDefinitions[0]);
                    }
                });
            }
        };
 
        // Click handler for save button
        $scope.save = function () {
 
            if ($scope.escalationDefinitions.length > 0) {
                $scope.property.value = $scope.escalationDefinitions;
            } else {
                $scope.property.value = null;
            }
 
            $scope.updatePropertyInModel($scope.property);
            $scope.close();
        };
 
        $scope.cancel = function () {
            $scope.property.mode = 'read';
            $scope.$hide();
        };
 
        // Close button handler
        $scope.close = function () {
            $scope.property.mode = 'read';
            $scope.$hide();
        };
 
    }]);