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-signal-definitions-controller.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. angular.module('activitiModeler').controller('ActivitiSignalDefinitionsCtrl', ['$scope', '$modal', function ($scope, $modal) {
  19. // Config for the modal window
  20. var opts = {
  21. template: 'editor-app/configuration/properties/signal-definitions-popup.html?version=' + Date.now(),
  22. scope: $scope
  23. };
  24. // Open the dialog
  25. $modal(opts);
  26. }]);
  27. //Need a separate controller for the modal window due to https://github.com/angular-ui/bootstrap/issues/259
  28. // Will be fixed in a newer version of Angular UI
  29. angular.module('activitiModeler').controller('ActivitiSignalDefinitionsPopupCtrl',
  30. ['$scope', '$q', '$translate', '$timeout', function ($scope, $q, $translate, $timeout) {
  31. // Put json representing signal definitions on scope
  32. if ($scope.property.value !== undefined && $scope.property.value !== null && $scope.property.value.length > 0) {
  33. if ($scope.property.value.constructor == String) {
  34. $scope.signalDefinitions = JSON.parse($scope.property.value);
  35. }
  36. else {
  37. // Note that we clone the json object rather then setting it directly,
  38. // this to cope with the fact that the user can click the cancel button and no changes should have happened
  39. $scope.signalDefinitions = angular.copy($scope.property.value);
  40. }
  41. } else {
  42. $scope.signalDefinitions = [];
  43. }
  44. // Array to contain selected signal definitions (yes - we only can select one, but ng-grid isn't smart enough)
  45. $scope.selectedSignals = [];
  46. $scope.translationsRetrieved = false;
  47. $scope.labels = {};
  48. var idPromise = $translate('PROPERTY.SIGNALDEFINITIONS.ID');
  49. var namePromise = $translate('PROPERTY.SIGNALDEFINITIONS.NAME');
  50. var scopePromise = $translate('PROPERTY.SIGNALDEFINITIONS.SCOPE');
  51. $q.all([idPromise, namePromise, scopePromise]).then(function (results) {
  52. $scope.labels.idLabel = results[0];
  53. $scope.labels.nameLabel = results[1];
  54. $scope.labels.scopeLabel = results[2];
  55. $scope.translationsRetrieved = true;
  56. // Config for grid
  57. $scope.gridOptions = {
  58. data: 'signalDefinitions',
  59. headerRowHeight: 28,
  60. enableRowSelection: true,
  61. enableRowHeaderSelection: false,
  62. multiSelect: false,
  63. keepLastSelected : false,
  64. selectedItems: $scope.selectedSignals,
  65. columnDefs: [
  66. {field: 'id', displayName: $scope.labels.idLabel},
  67. {field: 'name', displayName: $scope.labels.nameLabel},
  68. {field: 'scope', displayName: $scope.labels.scopeLabel}]
  69. };
  70. });
  71. // Click handler for add button
  72. $scope.addNewSignalDefinition = function () {
  73. var newSignalDefinition = {id: '', name: '', scope: 'global'};
  74. $scope.signalDefinitions.push(newSignalDefinition);
  75. $timeout(function () {
  76. $scope.gridOptions.selectItem($scope.signalDefinitions.length - 1, true);
  77. });
  78. };
  79. // Click handler for remove button
  80. $scope.removeSignalDefinition = function () {
  81. if ($scope.selectedSignals && $scope.selectedSignals.length > 0) {
  82. var index = $scope.signalDefinitions.indexOf($scope.selectedSignals[0]);
  83. $scope.gridOptions.selectItem(index, false);
  84. $scope.signalDefinitions.splice(index, 1);
  85. $scope.selectedSignals.length = 0;
  86. if (index < $scope.signalDefinitions.length) {
  87. $scope.gridOptions.selectItem(index + 1, true);
  88. } else if ($scope.signalDefinitions.length > 0) {
  89. $scope.gridOptions.selectItem(index - 1, true);
  90. }
  91. }
  92. };
  93. // Click handler for save button
  94. $scope.save = function () {
  95. if ($scope.signalDefinitions.length > 0) {
  96. $scope.property.value = $scope.signalDefinitions;
  97. } else {
  98. $scope.property.value = null;
  99. }
  100. $scope.updatePropertyInModel($scope.property);
  101. $scope.close();
  102. };
  103. $scope.cancel = function () {
  104. $scope.property.mode = 'read';
  105. $scope.$hide();
  106. };
  107. // Close button handler
  108. $scope.close = function () {
  109. $scope.property.mode = 'read';
  110. $scope.$hide();
  111. };
  112. }]);