图书馆智能管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.7 KiB

5 months ago
  1. /* Licensed under the Apache License, Version 2.0 (the "License");
  2. * you may not use this file except in compliance with the License.
  3. * You may obtain a copy of the License at
  4. *
  5. * http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. /*
  14. * Controller for morph shape selection
  15. */
  16. var FlowableDefineDataCtrl = [ '$rootScope', '$scope', 'dialog', '$timeout', '$translate', function($rootScope, $scope, dialog, $timeout, $translate) {
  17. $scope.definedDataItems = [];
  18. $scope.selectedDataItems = [];
  19. // Config for grid
  20. $scope.gridOptions = {
  21. data: 'definedDataItems',
  22. enableRowSelection: true,
  23. headerRowHeight: 28,
  24. multiSelect: false,
  25. keepLastSelected : false,
  26. selectedItems: $scope.selectedDataItems,
  27. enableHorizontalScrollbar: 0,
  28. enableColumnMenus: false,
  29. enableSorting: false,
  30. columnDefs: [{ field: 'name', displayName: 'Name'},
  31. { field: 'value', displayName: 'Value'}]
  32. };
  33. // Click handler for add button
  34. $scope.addNewDataItem = function() {
  35. $scope.definedDataItems.push({ name : '',
  36. value : ''});
  37. };
  38. // Click handler for remove button
  39. $scope.removeDataItem = function() {
  40. if ($scope.selectedDataItems.length > 0) {
  41. var index = $scope.definedDataItems.indexOf($scope.selectedDataItems[0]);
  42. $scope.gridOptions.selectItem(index, false);
  43. $scope.definedDataItems.splice(index, 1);
  44. $scope.selectedDataItems.length = 0;
  45. if (index < $scope.definedDataItems.length) {
  46. $scope.gridOptions.selectItem(index + 1, true);
  47. } else if ($scope.definedDataItems.length > 0) {
  48. $scope.gridOptions.selectItem(index - 1, true);
  49. }
  50. }
  51. };
  52. // Click handler for up button
  53. $scope.moveDataItemUp = function() {
  54. if ($scope.selectedParameters.length > 0) {
  55. var index = $scope.definedDataItems.indexOf($scope.selectedDataItems[0]);
  56. if (index != 0) { // If it's the first, no moving up of course
  57. // Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272
  58. var temp = $scope.definedDataItems[index];
  59. $scope.definedDataItems.splice(index, 1);
  60. $timeout(function(){
  61. $scope.definedDataItems.splice(index + -1, 0, temp);
  62. }, 100);
  63. }
  64. }
  65. };
  66. // Click handler for down button
  67. $scope.moveDataItemDown = function() {
  68. if ($scope.selectedParameters.length > 0) {
  69. var index = $scope.definedDataItems.indexOf($scope.selectedDataItems[0]);
  70. if (index != $scope.definedDataItems.length - 1) { // If it's the last element, no moving down of course
  71. // Reason for funny way of swapping, see https://github.com/angular-ui/ng-grid/issues/272
  72. var temp = $scope.definedDataItems[index];
  73. $scope.definedDataItems.splice(index, 1);
  74. $timeout(function(){
  75. $scope.definedDataItems.splice(index + 1, 0, temp);
  76. }, 100);
  77. }
  78. }
  79. };
  80. $scope.save = function() {
  81. dialog.close();
  82. };
  83. $scope.cancel = function() {
  84. dialog.close();
  85. };
  86. // Close button handler
  87. $scope.close = function() {
  88. dialog.close();
  89. };
  90. }];