电子档案
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.

51 lines
2.5 KiB

  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. angular.module('flowableModeler')
  14. .controller('AppDefinitionToolbarController', ['$scope', '$http', '$modal', '$q', '$rootScope', '$translate', '$location', function ($scope, $http, $modal, $q, $rootScope, $translate, $location) {
  15. var toolbarItems = APP_DEFINITION_TOOLBAR_CONFIG.items;
  16. $scope.items = [];
  17. for (var i = 0; i < toolbarItems.length; i++)
  18. {
  19. $scope.items.push(toolbarItems[i]);
  20. }
  21. $scope.secondaryItems = APP_DEFINITION_TOOLBAR_CONFIG.secondaryItems;
  22. // Call configurable click handler (From http://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string)
  23. var executeFunctionByName = function(functionName, context /*, args */) {
  24. var args = Array.prototype.slice.call(arguments).splice(2);
  25. var namespaces = functionName.split(".");
  26. var func = namespaces.pop();
  27. for(var i = 0; i < namespaces.length; i++) {
  28. context = context[namespaces[i]];
  29. }
  30. return context[func].apply(this, args);
  31. };
  32. // Click handler for toolbar buttons
  33. $scope.toolbarButtonClicked = function(buttonIndex) {
  34. // Default behaviour
  35. var buttonClicked = $scope.items[buttonIndex];
  36. var services = { '$scope' : $scope, '$rootScope' : $rootScope, '$http' : $http, '$modal' : $modal, '$q' : $q, '$translate' : $translate};
  37. executeFunctionByName(buttonClicked.action, window, services);
  38. };
  39. // Click handler for secondary toolbar buttons
  40. $scope.toolbarSecondaryButtonClicked = function(buttonIndex) {
  41. var buttonClicked = $scope.secondaryItems[buttonIndex];
  42. var services = { '$scope' : $scope, '$rootScope' : $rootScope, '$http' : $http, '$modal' : $modal, '$q' : $q, '$translate' : $translate, '$location': $location};
  43. executeFunctionByName(buttonClicked.action, window, services);
  44. };
  45. }]);