properties-in-parameters-controller.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. * Input parameters for call activity
  20. */
  21. var KisBpmInParametersCtrl = [ '$scope', '$modal', '$timeout', '$translate', function($scope, $modal, $timeout, $translate) {
  22. // Config for the modal window
  23. var opts = {
  24. template: 'editor-app/configuration/properties/in-parameters-popup.html?version=' + Date.now(),
  25. scope: $scope
  26. };
  27. // Open the dialog
  28. $modal(opts);
  29. }];
  30. var KisBpmInParametersPopupCtrl = ['$scope', '$q', '$translate', function($scope, $q, $translate) {
  31. // Put json representing form properties on scope
  32. if ($scope.property.value !== undefined && $scope.property.value !== null
  33. && $scope.property.value.inParameters !== undefined
  34. && $scope.property.value.inParameters !== 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 happened
  37. $scope.parameters = angular.copy($scope.property.value.inParameters);
  38. } else {
  39. $scope.parameters = [];
  40. }
  41. // Array to contain selected properties (yes - we only can select one, but ng-grid isn't smart enough)
  42. $scope.selectedParameters = [];
  43. $scope.translationsRetrieved = false;
  44. $scope.labels = {};
  45. var sourcePromise = $translate('PROPERTY.PARAMETER.SOURCE');
  46. var sourceExpressionPromise = $translate('PROPERTY.PARAMETER.SOURCEEXPRESSION');
  47. var targetPromise = $translate('PROPERTY.PARAMETER.TARGET');
  48. $q.all([sourcePromise, sourceExpressionPromise, targetPromise]).then(function(results) {
  49. $scope.labels.sourceLabel = results[0];
  50. $scope.labels.sourceExpressionLabel = results[1];
  51. $scope.labels.targetLabel = results[2];
  52. $scope.translationsRetrieved = true;
  53. // Config for grid
  54. $scope.gridOptions = {
  55. data: 'parameters',
  56. enableRowReordering: true,
  57. headerRowHeight: 28,
  58. multiSelect: false,
  59. keepLastSelected : false,
  60. selectedItems: $scope.selectedParameters,
  61. columnDefs: [{ field: 'source', displayName: $scope.labels.sourceLabel },
  62. { field: 'sourceExpression', displayName: $scope.labels.sourceExpressionLabel },
  63. { field: 'target', displayName: $scope.labels.targetLabel }]
  64. };
  65. });
  66. // Click handler for add button
  67. $scope.addNewParameter = function() {
  68. $scope.parameters.push({ source : '',
  69. sourceExpression : '',
  70. target : ''});
  71. };
  72. // Click handler for remove button
  73. $scope.removeParameter = function() {
  74. if ($scope.selectedParameters.length > 0) {
  75. var index = $scope.parameters.indexOf($scope.selectedParameters[0]);
  76. $scope.gridOptions.selectItem(index, false);
  77. $scope.parameters.splice(index, 1);
  78. $scope.selectedParameters.length = 0;
  79. if (index < $scope.parameters.length) {
  80. $scope.gridOptions.selectItem(index + 1, true);
  81. } else if ($scope.parameters.length > 0) {
  82. $scope.gridOptions.selectItem(index - 1, true);
  83. }
  84. }
  85. };
  86. // Click handler for up button
  87. $scope.moveParameterUp = function() {
  88. if ($scope.selectedParameters.length > 0) {
  89. var index = $scope.parameters.indexOf($scope.selectedParameters[0]);
  90. if (index != 0) { // If it's the first, no moving up of course
  91. // Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272
  92. var temp = $scope.parameters[index];
  93. $scope.parameters.splice(index, 1);
  94. $timeout(function(){
  95. $scope.parameters.splice(index + -1, 0, temp);
  96. }, 100);
  97. }
  98. }
  99. };
  100. // Click handler for down button
  101. $scope.moveParameterDown = function() {
  102. if ($scope.selectedParameters.length > 0) {
  103. var index = $scope.parameters.indexOf($scope.selectedParameters[0]);
  104. if (index != $scope.parameters.length - 1) { // If it's the last element, no moving down of course
  105. // Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272
  106. var temp = $scope.parameters[index];
  107. $scope.parameters.splice(index, 1);
  108. $timeout(function(){
  109. $scope.parameters.splice(index + 1, 0, temp);
  110. }, 100);
  111. }
  112. }
  113. };
  114. // Click handler for save button
  115. $scope.save = function() {
  116. if ($scope.parameters.length > 0) {
  117. $scope.property.value = {};
  118. $scope.property.value.inParameters = $scope.parameters;
  119. } else {
  120. $scope.property.value = null;
  121. }
  122. $scope.updatePropertyInModel($scope.property);
  123. $scope.close();
  124. };
  125. $scope.cancel = function() {
  126. $scope.close();
  127. };
  128. // Close button handler
  129. $scope.close = function() {
  130. $scope.property.mode = 'read';
  131. $scope.$hide();
  132. };
  133. }];