bitcoin-atm
bitcoin atm for pyc inc.
git clone https://9o.is/git/bitcoin-atm.git
angular-wizard.js
(6562B)
1 /**
2 * Easy to use Wizard library for AngularJS
3 * @version v0.4.0 - 2014-05-17 * @link https://github.com/mgonto/angular-wizard
4 * @author Martin Gontovnikas <martin@gon.to>
5 * @license MIT License, http://www.opensource.org/licenses/MIT
6 */
7 angular.module('templates-angularwizard', ['step.html', 'wizard.html']);
8
9 angular.module("step.html", []).run(["$templateCache", function($templateCache) {
10 $templateCache.put("step.html",
11 "<section ng-show=\"selected\" ng-class=\"{current: selected, done: completed}\" class=\"step\" ng-transclude>\n" +
12 "</section>");
13 }]);
14
15 angular.module("wizard.html", []).run(["$templateCache", function($templateCache) {
16 $templateCache.put("wizard.html",
17 "<div>\n" +
18 " <div class=\"steps\" ng-transclude></div>\n" +
19 "</div>\n" +
20 "");
21 }]);
22
23 angular.module('mgo-angular-wizard', ['templates-angularwizard']);
24
25 angular.module('mgo-angular-wizard').directive('wzStep', function() {
26 return {
27 restrict: 'EA',
28 replace: true,
29 transclude: true,
30 scope: {
31 wzTitle: '@',
32 title: '@screen'
33 },
34 require: '^wizard',
35 templateUrl: function(element, attributes) {
36 return attributes.template || "step.html";
37 },
38 link: function($scope, $element, $attrs, wizard) {
39 $scope.title = $scope.title || $scope.wzTitle;
40 wizard.addStep($scope);
41 }
42 };
43 });
44
45 angular.module('mgo-angular-wizard').directive('wizard', function() {
46 return {
47 restrict: 'EA',
48 replace: true,
49 transclude: true,
50 scope: {
51 currentStep: '=',
52 onFinish: '&',
53 hideIndicators: '=',
54 editMode: '=',
55 name: '@'
56 },
57 templateUrl: function(element, attributes) {
58 return attributes.template || "wizard.html";
59 },
60 controller: ['$scope', '$element', 'WizardHandler', function($scope, $element, WizardHandler) {
61
62 WizardHandler.addWizard($scope.name || WizardHandler.defaultName, this);
63 $scope.$on('$destroy', function() {
64 WizardHandler.removeWizard($scope.name || WizardHandler.defaultName);
65 });
66
67 $scope.steps = [];
68
69 $scope.$watch('currentStep', function(step) {
70 if (!step) return;
71 var stepTitle = $scope.selectedStep.title || $scope.selectedStep.wzTitle;
72 if ($scope.selectedStep && stepTitle !== $scope.currentStep) {
73 $scope.goTo(_.findWhere($scope.steps, {title: $scope.currentStep}));
74 }
75
76 });
77
78 $scope.$watch('[editMode, steps.length]', function() {
79 var editMode = $scope.editMode;
80 if (_.isUndefined(editMode) || _.isNull(editMode)) return;
81
82 if (editMode) {
83 _.each($scope.steps, function(step) {
84 step.completed = true;
85 });
86 }
87 }, true);
88
89 this.addStep = function(step) {
90 $scope.steps.push(step);
91 if ($scope.steps.length === 1) {
92 $scope.goTo($scope.steps[0]);
93 }
94 };
95
96 $scope.goTo = function(step) {
97 unselectAll();
98 $scope.selectedStep = step;
99 if (!_.isUndefined($scope.currentStep)) {
100 $scope.currentStep = step.title || step.wzTitle;
101 }
102 step.selected = true;
103 $scope.$emit('wizard:stepChanged', {step: step, index: _.indexOf($scope.steps , step)});
104 };
105
106 function unselectAll() {
107 _.each($scope.steps, function (step) {
108 step.selected = false;
109 });
110 $scope.selectedStep = null;
111 }
112
113 this.next = function(draft) {
114 var index = _.indexOf($scope.steps , $scope.selectedStep);
115 if (!draft) {
116 $scope.selectedStep.completed = true;
117 }
118 if (index === $scope.steps.length - 1) {
119 this.finish();
120 } else {
121 $scope.goTo($scope.steps[index + 1]);
122 }
123 };
124
125 this.goTo = function(step) {
126 var stepTo;
127 if (_.isNumber(step)) {
128 stepTo = $scope.steps[step];
129 } else {
130 stepTo = _.findWhere($scope.steps, {title: step});
131 }
132 $scope.goTo(stepTo);
133 };
134
135 this.finish = function() {
136 if ($scope.onFinish) {
137 $scope.onFinish();
138 }
139 };
140
141 this.cancel = this.previous = function() {
142 var index = _.indexOf($scope.steps , $scope.selectedStep);
143 if (index === 0) {
144 throw new Error("Can't go back. It's already in step 0");
145 } else {
146 $scope.goTo($scope.steps[index - 1]);
147 }
148 };
149 }]
150 };
151 });
152
153 function wizardButtonDirective(action) {
154 angular.module('mgo-angular-wizard')
155 .directive(action, function() {
156 return {
157 restrict: 'A',
158 replace: false,
159 require: '^wizard',
160 link: function($scope, $element, $attrs, wizard) {
161
162 $element.on("click", function(e) {
163 e.preventDefault();
164 $scope.$apply(function() {
165 $scope.$eval($attrs[action]);
166 wizard[action.replace("wz", "").toLowerCase()]();
167 });
168 });
169 }
170 };
171 });
172 }
173
174 wizardButtonDirective('wzNext');
175 wizardButtonDirective('wzPrevious');
176 wizardButtonDirective('wzFinish');
177 wizardButtonDirective('wzCancel');
178
179 angular.module('mgo-angular-wizard').factory('WizardHandler', function() {
180 var service = {};
181
182 var wizards = {};
183
184 service.defaultName = "defaultWizard";
185
186 service.addWizard = function(name, wizard) {
187 wizards[name] = wizard;
188 };
189
190 service.removeWizard = function(name) {
191 delete wizards[name];
192 };
193
194 service.wizard = function(name) {
195 var nameToUse = name;
196 if (!name) {
197 nameToUse = service.defaultName;
198 }
199
200 return wizards[nameToUse];
201 };
202
203 return service;
204 });