|
1 | 1 | (function () {
|
2 | 2 | 'use strict';
|
3 |
| - function pfWizardButtonComponent (action) { |
4 |
| - angular.module('patternfly.wizard') |
5 |
| - .component(action, { |
6 |
| - bindings: { |
7 |
| - callback: "=?" |
8 |
| - }, |
9 |
| - controller: function ($element, $scope) { |
10 |
| - var ctrl = this; |
11 |
| - |
12 |
| - var findWizard = function (scope) { |
13 |
| - var wizard; |
14 |
| - |
15 |
| - if (scope) { |
16 |
| - if (angular.isDefined(scope.wizard)) { |
17 |
| - wizard = scope.wizard; |
18 |
| - } else { |
19 |
| - wizard = findWizard(scope.$parent); |
20 |
| - } |
21 |
| - } |
22 |
| - |
23 |
| - return wizard; |
24 |
| - }; |
25 |
| - |
26 |
| - ctrl.$onInit = function () { |
27 |
| - $scope.wizard = findWizard($scope); |
28 |
| - }; |
29 |
| - |
30 |
| - ctrl.$postLink = function () { |
31 |
| - $element.on("click", function (e) { |
32 |
| - e.preventDefault(); |
33 |
| - $scope.$apply(function () { |
34 |
| - // scope apply in button module |
35 |
| - $scope.wizard[action.replace("pfWiz", "").toLowerCase()](ctrl.callback); |
36 |
| - }); |
37 |
| - }); |
38 |
| - }; |
39 |
| - } |
| 3 | + |
| 4 | + var findWizard = function (scope) { |
| 5 | + var wizard; |
| 6 | + |
| 7 | + if (scope) { |
| 8 | + if (angular.isDefined(scope.wizard)) { |
| 9 | + wizard = scope.wizard; |
| 10 | + } else { |
| 11 | + wizard = findWizard(scope.$parent); |
| 12 | + } |
| 13 | + } |
| 14 | + |
| 15 | + return wizard; |
| 16 | + }; |
| 17 | + |
| 18 | + var setupCallback = function (scope, button, fnName, callback) { |
| 19 | + button.on("click", function (e) { |
| 20 | + e.preventDefault(); |
| 21 | + scope.$apply(function () { |
| 22 | + // scope apply in button module |
| 23 | + scope.wizard[fnName](callback); |
40 | 24 | });
|
41 |
| - } |
| 25 | + }); |
| 26 | + }; |
| 27 | + |
| 28 | + angular.module('patternfly.wizard').component('pfWizNext', { |
| 29 | + bindings: { |
| 30 | + callback: "=?" |
| 31 | + }, |
| 32 | + controller: function ($element, $scope) { |
| 33 | + var ctrl = this; |
| 34 | + |
| 35 | + ctrl.$onInit = function () { |
| 36 | + $scope.wizard = findWizard($scope); |
| 37 | + }; |
| 38 | + |
| 39 | + ctrl.$postLink = function () { |
| 40 | + setupCallback($scope, $element, 'next', ctrl.callback); |
| 41 | + }; |
| 42 | + } |
| 43 | + }); |
| 44 | + |
| 45 | + angular.module('patternfly.wizard').component('pfWizPrevious', { |
| 46 | + bindings: { |
| 47 | + callback: "=?" |
| 48 | + }, |
| 49 | + controller: function ($element, $scope) { |
| 50 | + var ctrl = this; |
| 51 | + |
| 52 | + ctrl.$onInit = function () { |
| 53 | + $scope.wizard = findWizard($scope); |
| 54 | + }; |
| 55 | + |
| 56 | + ctrl.$postLink = function () { |
| 57 | + setupCallback($scope, $element, 'previous', ctrl.callback); |
| 58 | + }; |
| 59 | + } |
| 60 | + }); |
| 61 | + |
| 62 | + angular.module('patternfly.wizard').component('pfWizFinish', { |
| 63 | + bindings: { |
| 64 | + callback: "=?" |
| 65 | + }, |
| 66 | + controller: function ($element, $scope) { |
| 67 | + var ctrl = this; |
| 68 | + |
| 69 | + ctrl.$onInit = function () { |
| 70 | + $scope.wizard = findWizard($scope); |
| 71 | + }; |
| 72 | + |
| 73 | + ctrl.$postLink = function () { |
| 74 | + setupCallback($scope, $element, 'finish', ctrl.callback); |
| 75 | + }; |
| 76 | + } |
| 77 | + }); |
| 78 | + |
| 79 | + angular.module('patternfly.wizard').component('pfWizCancel', { |
| 80 | + bindings: { |
| 81 | + callback: "=?" |
| 82 | + }, |
| 83 | + controller: function ($element, $scope) { |
| 84 | + var ctrl = this; |
| 85 | + |
| 86 | + ctrl.$onInit = function () { |
| 87 | + $scope.wizard = findWizard($scope); |
| 88 | + }; |
| 89 | + |
| 90 | + ctrl.$postLink = function () { |
| 91 | + setupCallback($scope, $element, 'cancel', ctrl.callback); |
| 92 | + }; |
| 93 | + } |
| 94 | + }); |
| 95 | + |
| 96 | + angular.module('patternfly.wizard').component('pfWizReset', { |
| 97 | + bindings: { |
| 98 | + callback: "=?" |
| 99 | + }, |
| 100 | + controller: function ($element, $scope) { |
| 101 | + var ctrl = this; |
| 102 | + |
| 103 | + ctrl.$onInit = function () { |
| 104 | + $scope.wizard = findWizard($scope); |
| 105 | + }; |
42 | 106 |
|
43 |
| - pfWizardButtonComponent('pfWizNext'); |
44 |
| - pfWizardButtonComponent('pfWizPrevious'); |
45 |
| - pfWizardButtonComponent('pfWizFinish'); |
46 |
| - pfWizardButtonComponent('pfWizCancel'); |
47 |
| - pfWizardButtonComponent('pfWizReset'); |
| 107 | + ctrl.$postLink = function () { |
| 108 | + setupCallback($scope, $element, 'reset', ctrl.callback); |
| 109 | + }; |
| 110 | + } |
| 111 | + }); |
48 | 112 | })();
|
0 commit comments