|
1 | 1 | (function () {
|
2 | 2 | 'use strict';
|
3 |
| - function pfWizardButtonDirective (action) { |
| 3 | + function pfWizardButtonComponent (action) { |
4 | 4 | angular.module('patternfly.wizard')
|
5 |
| - .directive(action, function () { |
6 |
| - return { |
7 |
| - restrict: 'A', |
8 |
| - require: '^pfWizard', |
9 |
| - scope: { |
10 |
| - callback: "=?" |
11 |
| - }, |
12 |
| - link: function ($scope, $element, $attrs, 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 () { |
13 | 31 | $element.on("click", function (e) {
|
14 | 32 | e.preventDefault();
|
15 | 33 | $scope.$apply(function () {
|
16 | 34 | // scope apply in button module
|
17 |
| - $scope.$eval($attrs[action]); |
18 |
| - wizard[action.replace("pfWiz", "").toLowerCase()]($scope.callback); |
| 35 | + $scope.wizard[action.replace("pfWiz", "").toLowerCase()]($scope.callback); |
19 | 36 | });
|
20 | 37 | });
|
21 |
| - } |
22 |
| - }; |
| 38 | + }; |
| 39 | + } |
23 | 40 | });
|
24 | 41 | }
|
25 | 42 |
|
26 |
| - pfWizardButtonDirective('pfWizNext'); |
27 |
| - pfWizardButtonDirective('pfWizPrevious'); |
28 |
| - pfWizardButtonDirective('pfWizFinish'); |
29 |
| - pfWizardButtonDirective('pfWizCancel'); |
30 |
| - pfWizardButtonDirective('pfWizReset'); |
| 43 | + pfWizardButtonComponent('pfWizNext'); |
| 44 | + pfWizardButtonComponent('pfWizPrevious'); |
| 45 | + pfWizardButtonComponent('pfWizFinish'); |
| 46 | + pfWizardButtonComponent('pfWizCancel'); |
| 47 | + pfWizardButtonComponent('pfWizReset'); |
31 | 48 | })();
|
0 commit comments