Digital Office Automation System Backend
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

properties-form-properties-controller.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. * Form Properties
  20. */
  21. var KisBpmFormPropertiesCtrl = [ '$scope', '$modal', '$timeout', '$translate', function($scope, $modal, $timeout, $translate) {
  22. // Config for the modal window
  23. var opts = {
  24. template: 'editor-app/configuration/properties/form-properties-popup.html?version=' + Date.now(),
  25. scope: $scope
  26. };
  27. // Open the dialog
  28. $modal(opts);
  29. }];
  30. var KisBpmFormPropertiesPopupCtrl = ['$scope', '$q', '$translate', '$timeout', function($scope, $q, $translate, $timeout) {
  31. // Put json representing form properties on scope
  32. if ($scope.property.value !== undefined && $scope.property.value !== null
  33. && $scope.property.value.formProperties !== undefined
  34. && $scope.property.value.formProperties !== null) {
  35. // Note that we clone the json object rather then setting it directly,
  36. // this to cope with the fact that the user can click the cancel button and no changes should have happended
  37. $scope.formProperties = angular.copy($scope.property.value.formProperties);
  38. for (var i = 0; i < $scope.formProperties.length; i++) {
  39. var formProperty = $scope.formProperties[i];
  40. if (formProperty.enumValues && formProperty.enumValues.length > 0) {
  41. for (var j = 0; j < formProperty.enumValues.length; j++) {
  42. var enumValue = formProperty.enumValues[j];
  43. if (!enumValue.id && !enumValue.name && enumValue.value) {
  44. enumValue.id = enumValue.value;
  45. enumValue.name = enumValue.value;
  46. }
  47. }
  48. }
  49. }
  50. } else {
  51. $scope.formProperties = [];
  52. }
  53. // Array to contain selected properties (yes - we only can select one, but ng-grid isn't smart enough)
  54. $scope.selectedProperties = [];
  55. $scope.selectedEnumValues = [];
  56. $scope.translationsRetrieved = false;
  57. $scope.labels = {};
  58. var idPromise = $translate('PROPERTY.FORMPROPERTIES.ID');
  59. var namePromise = $translate('PROPERTY.FORMPROPERTIES.NAME');
  60. var typePromise = $translate('PROPERTY.FORMPROPERTIES.TYPE');
  61. $q.all([idPromise, namePromise, typePromise]).then(function(results) {
  62. $scope.labels.idLabel = results[0];
  63. $scope.labels.nameLabel = results[1];
  64. $scope.labels.typeLabel = results[2];
  65. $scope.translationsRetrieved = true;
  66. // Config for grid
  67. $scope.gridOptions = {
  68. data: 'formProperties',
  69. enableRowReordering: true,
  70. headerRowHeight: 28,
  71. multiSelect: false,
  72. keepLastSelected : false,
  73. selectedItems: $scope.selectedProperties,
  74. columnDefs: [{ field: 'id', displayName: $scope.labels.idLabel },
  75. { field: 'name', displayName: $scope.labels.nameLabel},
  76. { field: 'type', displayName: $scope.labels.typeLabel}]
  77. };
  78. $scope.enumGridOptions = {
  79. data: 'selectedProperties[0].enumValues',
  80. enableRowReordering: true,
  81. headerRowHeight: 28,
  82. multiSelect: false,
  83. keepLastSelected : false,
  84. selectedItems: $scope.selectedEnumValues,
  85. columnDefs: [{ field: 'id', displayName: $scope.labels.idLabel },
  86. { field: 'name', displayName: $scope.labels.nameLabel}]
  87. }
  88. });
  89. // Handler for when the value of the type dropdown changes
  90. $scope.propertyTypeChanged = function() {
  91. // Check date. If date, show date pattern
  92. if ($scope.selectedProperties[0].type === 'date') {
  93. $scope.selectedProperties[0].datePattern = 'MM-dd-yyyy hh:mm';
  94. } else {
  95. delete $scope.selectedProperties[0].datePattern;
  96. }
  97. // Check enum. If enum, show list of options
  98. if ($scope.selectedProperties[0].type === 'enum') {
  99. $scope.selectedProperties[0].enumValues = [ {id: 'value1', name: 'Value 1'}, {id: 'value2', name: 'Value 2'}];
  100. } else {
  101. delete $scope.selectedProperties[0].enumValues;
  102. }
  103. };
  104. // Click handler for add button
  105. var propertyIndex = 1;
  106. $scope.addNewProperty = function() {
  107. $scope.formProperties.push({ id : 'new_property_' + propertyIndex++,
  108. name : '',
  109. type : 'string',
  110. readable: true,
  111. writable: true});
  112. $timeout(function(){
  113. $scope.gridOptions.selectItem($scope.formProperties.length - 1, true);
  114. });
  115. };
  116. // Click handler for remove button
  117. $scope.removeProperty = function() {
  118. if ($scope.selectedProperties.length > 0) {
  119. var index = $scope.formProperties.indexOf($scope.selectedProperties[0]);
  120. $scope.gridOptions.selectItem(index, false);
  121. $scope.formProperties.splice(index, 1);
  122. $scope.selectedProperties.length = 0;
  123. if (index < $scope.formProperties.length) {
  124. $scope.gridOptions.selectItem(index + 1, true);
  125. } else if ($scope.formProperties.length > 0) {
  126. $scope.gridOptions.selectItem(index - 1, true);
  127. }
  128. }
  129. };
  130. // Click handler for up button
  131. $scope.movePropertyUp = function() {
  132. if ($scope.selectedProperties.length > 0) {
  133. var index = $scope.formProperties.indexOf($scope.selectedProperties[0]);
  134. if (index != 0) { // If it's the first, no moving up of course
  135. // Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272
  136. var temp = $scope.formProperties[index];
  137. $scope.formProperties.splice(index, 1);
  138. $timeout(function(){
  139. $scope.formProperties.splice(index + -1, 0, temp);
  140. }, 100);
  141. }
  142. }
  143. };
  144. // Click handler for down button
  145. $scope.movePropertyDown = function() {
  146. if ($scope.selectedProperties.length > 0) {
  147. var index = $scope.formProperties.indexOf($scope.selectedProperties[0]);
  148. if (index != $scope.formProperties.length - 1) { // If it's the last element, no moving down of course
  149. // Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272
  150. var temp = $scope.formProperties[index];
  151. $scope.formProperties.splice(index, 1);
  152. $timeout(function(){
  153. $scope.formProperties.splice(index + 1, 0, temp);
  154. }, 100);
  155. }
  156. }
  157. };
  158. $scope.addNewEnumValue = function() {
  159. if ($scope.selectedProperties.length > 0) {
  160. $scope.selectedProperties[0].enumValues.push({ id : '', name : ''});
  161. }
  162. $timeout(function(){
  163. $scope.enumGridOptions.selectItem($scope.selectedProperties[0].enumValues.length - 1, true);
  164. });
  165. };
  166. // Click handler for remove button
  167. $scope.removeEnumValue = function() {
  168. if ($scope.selectedProperties.length > 0 && $scope.selectedEnumValues.length > 0) {
  169. var index = $scope.selectedProperties[0].enumValues.indexOf($scope.selectedEnumValues[0]);
  170. $scope.enumGridOptions.selectItem(index, false);
  171. $scope.selectedProperties[0].enumValues.splice(index, 1);
  172. $scope.selectedEnumValues.length = 0;
  173. if (index < $scope.selectedProperties[0].enumValues.length) {
  174. $timeout(function(){
  175. $scope.enumGridOptions.selectItem(index + 1, true);
  176. });
  177. } else if ($scope.selectedProperties[0].enumValues.length > 0) {
  178. $timeout(function(){
  179. $scope.enumGridOptions.selectItem(index - 1, true);
  180. });
  181. }
  182. }
  183. };
  184. // Click handler for up button
  185. $scope.moveEnumValueUp = function() {
  186. if ($scope.selectedProperties.length > 0 && $scope.selectedEnumValues.length > 0) {
  187. var index = $scope.selectedProperties[0].enumValues.indexOf($scope.selectedEnumValues[0]);
  188. if (index != 0) { // If it's the first, no moving up of course
  189. // Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272
  190. var temp = $scope.selectedProperties[0].enumValues[index];
  191. $scope.selectedProperties[0].enumValues.splice(index, 1);
  192. $timeout(function(){
  193. $scope.selectedProperties[0].enumValues.splice(index + -1, 0, temp);
  194. });
  195. }
  196. }
  197. };
  198. // Click handler for down button
  199. $scope.moveEnumValueDown = function() {
  200. if ($scope.selectedProperties.length > 0 && $scope.selectedEnumValues.length > 0) {
  201. var index = $scope.selectedProperties[0].enumValues.indexOf($scope.selectedEnumValues[0]);
  202. if (index != $scope.selectedProperties[0].enumValues.length - 1) { // If it's the last element, no moving down of course
  203. // Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272
  204. var temp = $scope.selectedProperties[0].enumValues[index];
  205. $scope.selectedProperties[0].enumValues.splice(index, 1);
  206. $timeout(function(){
  207. $scope.selectedProperties[0].enumValues.splice(index + 1, 0, temp);
  208. });
  209. }
  210. }
  211. };
  212. // Click handler for save button
  213. $scope.save = function() {
  214. if ($scope.formProperties.length > 0) {
  215. $scope.property.value = {};
  216. $scope.property.value.formProperties = $scope.formProperties;
  217. } else {
  218. $scope.property.value = null;
  219. }
  220. $scope.updatePropertyInModel($scope.property);
  221. $scope.close();
  222. };
  223. $scope.cancel = function() {
  224. $scope.$hide();
  225. $scope.property.mode = 'read';
  226. };
  227. // Close button handler
  228. $scope.close = function() {
  229. $scope.$hide();
  230. $scope.property.mode = 'read';
  231. };
  232. }];