pyc-website
main website for pyc inc.
git clone https://9o.is/git/pyc-website.git
commit f23d83d840947eb39569b7a0b1a98ca87867caa2 parent f0b69babefa2add884c2720144ecb8ef328a3bd6 Author: Jul <jul@9o.is> Date: Wed, 25 Jun 2014 10:55:00 -0400 installed angular-wizard js Diffstat:
| M | build.config.js | | | 3 | ++- |
| M | src/main/webapp/app/App.js | | | 2 | +- |
| A | src/main/webapp/vendor/angular-wizard.js | | | 209 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 212 insertions(+), 2 deletions(-)
diff --git a/build.config.js b/build.config.js @@ -64,7 +64,8 @@ module.exports = { "<%= dirs.vendor %>/ui-mask.js", "<%= dirs.vendor %>/liftAjax.js", "<%= dirs.vendor %>/angular-file-upload.js", - "<%= dirs.vendor %>/angular-google-analytics.js" + "<%= dirs.vendor %>/angular-google-analytics.js", + "<%= dirs.vendor %>/angular-wizard.js" ], css: [ ], diff --git a/src/main/webapp/app/App.js b/src/main/webapp/app/App.js @@ -1,7 +1,7 @@ var app = angular.module("app", [ 'google-maps', 'ui.bootstrap', 'ui.router', 'ui.mask', 'angularFileUpload', 'angular-google-analytics', 'ngThumb', - 'match', 'disabler', 'ngAlert', 'Forms']); + 'match', 'disabler', 'ngAlert', 'Forms', 'mgo-angular-wizard']); var ZIP_CODE_REGEXP = /^(\d{5}(-\d{4})?|[A-Z]\d[A-Z] *\d[A-Z]\d)$/; var PASSWORD_REGEXP = /^(?=.*[^a-zA-Z])\S{8,}$/; diff --git a/src/main/webapp/vendor/angular-wizard.js b/src/main/webapp/vendor/angular-wizard.js @@ -0,0 +1,209 @@ +/** + * Easy to use Wizard library for AngularJS + * @version v0.4.0 - 2014-05-17 * @link https://github.com/mgonto/angular-wizard + * @author Martin Gontovnikas <martin@gon.to> + * @license MIT License, http://www.opensource.org/licenses/MIT + */ +angular.module('templates-angularwizard', ['step.html', 'wizard.html']); + +angular.module("step.html", []).run(["$templateCache", function($templateCache) { + $templateCache.put("step.html", + "<section ng-show=\"selected\" ng-class=\"{current: selected, done: completed}\" class=\"step\" ng-transclude>\n" + + "</section>"); +}]); + +angular.module("wizard.html", []).run(["$templateCache", function($templateCache) { + $templateCache.put("wizard.html", + "<div>\n" + + " <ul class=\"steps-indicator steps-{{steps.length}}\" ng-if=\"!hideIndicators\">\n" + + " <li ng-class=\"{default: !step.completed && !step.selected, current: step.selected && !step.completed, done: step.completed && !step.selected, editing: step.selected && step.completed}\" ng-repeat=\"step in steps\">\n" + + " <a ng-click=\"goTo(step)\">{{step.title || step.wzTitle}}</a>\n" + + " </li>\n" + + " </ul>\n" + + " <div class=\"steps\" ng-transclude></div>\n" + + "</div>\n" + + ""); +}]); + +angular.module('mgo-angular-wizard', ['templates-angularwizard']); + +angular.module('mgo-angular-wizard').directive('wzStep', function() { + return { + restrict: 'EA', + replace: true, + transclude: true, + scope: { + wzTitle: '@', + title: '@' + }, + require: '^wizard', + templateUrl: function(element, attributes) { + return attributes.template || "step.html"; + }, + link: function($scope, $element, $attrs, wizard) { + $scope.title = $scope.title || $scope.wzTitle; + wizard.addStep($scope); + } + }; +}); + +angular.module('mgo-angular-wizard').directive('wizard', function() { + return { + restrict: 'EA', + replace: true, + transclude: true, + scope: { + currentStep: '=', + onFinish: '&', + hideIndicators: '=', + editMode: '=', + name: '@' + }, + templateUrl: function(element, attributes) { + return attributes.template || "wizard.html"; + }, + controller: ['$scope', '$element', 'WizardHandler', function($scope, $element, WizardHandler) { + + WizardHandler.addWizard($scope.name || WizardHandler.defaultName, this); + $scope.$on('$destroy', function() { + WizardHandler.removeWizard($scope.name || WizardHandler.defaultName); + }); + + $scope.steps = []; + + $scope.$watch('currentStep', function(step) { + if (!step) return; + var stepTitle = $scope.selectedStep.title || $scope.selectedStep.wzTitle; + if ($scope.selectedStep && stepTitle !== $scope.currentStep) { + $scope.goTo(_.findWhere($scope.steps, {title: $scope.currentStep})); + } + + }); + + $scope.$watch('[editMode, steps.length]', function() { + var editMode = $scope.editMode; + if (_.isUndefined(editMode) || _.isNull(editMode)) return; + + if (editMode) { + _.each($scope.steps, function(step) { + step.completed = true; + }); + } + }, true); + + this.addStep = function(step) { + $scope.steps.push(step); + if ($scope.steps.length === 1) { + $scope.goTo($scope.steps[0]); + } + }; + + $scope.goTo = function(step) { + unselectAll(); + $scope.selectedStep = step; + if (!_.isUndefined($scope.currentStep)) { + $scope.currentStep = step.title || step.wzTitle; + } + step.selected = true; + $scope.$emit('wizard:stepChanged', {step: step, index: _.indexOf($scope.steps , step)}); + }; + + function unselectAll() { + _.each($scope.steps, function (step) { + step.selected = false; + }); + $scope.selectedStep = null; + } + + this.next = function(draft) { + var index = _.indexOf($scope.steps , $scope.selectedStep); + if (!draft) { + $scope.selectedStep.completed = true; + } + if (index === $scope.steps.length - 1) { + this.finish(); + } else { + $scope.goTo($scope.steps[index + 1]); + } + }; + + this.goTo = function(step) { + var stepTo; + if (_.isNumber(step)) { + stepTo = $scope.steps[step]; + } else { + stepTo = _.findWhere($scope.steps, {title: step}); + } + $scope.goTo(stepTo); + }; + + this.finish = function() { + if ($scope.onFinish) { + $scope.onFinish(); + } + }; + + this.cancel = this.previous = function() { + var index = _.indexOf($scope.steps , $scope.selectedStep); + if (index === 0) { + throw new Error("Can't go back. It's already in step 0"); + } else { + $scope.goTo($scope.steps[index - 1]); + } + }; + }] + }; +}); + +function wizardButtonDirective(action) { + angular.module('mgo-angular-wizard') + .directive(action, function() { + return { + restrict: 'A', + replace: false, + require: '^wizard', + link: function($scope, $element, $attrs, wizard) { + + $element.on("click", function(e) { + e.preventDefault(); + $scope.$apply(function() { + $scope.$eval($attrs[action]); + wizard[action.replace("wz", "").toLowerCase()](); + }); + }); + } + }; + }); +} + +wizardButtonDirective('wzNext'); +wizardButtonDirective('wzPrevious'); +wizardButtonDirective('wzFinish'); +wizardButtonDirective('wzCancel'); + +angular.module('mgo-angular-wizard').factory('WizardHandler', function() { + var service = {}; + + var wizards = {}; + + service.defaultName = "defaultWizard"; + + service.addWizard = function(name, wizard) { + wizards[name] = wizard; + }; + + service.removeWizard = function(name) { + delete wizards[name]; + }; + + service.wizard = function(name) { + var nameToUse = name; + if (!name) { + nameToUse = service.defaultName; + } + + return wizards[nameToUse]; + }; + + return service; +});