From ca695d107a52881f5a945e9a98419895f3edd67c Mon Sep 17 00:00:00 2001 From: Artur Date: Fri, 11 Aug 2017 09:55:22 -0300 Subject: [PATCH] Creating events for next() and goto() Those functions are now emitting events `onstepcomplete` and `gotostepcomplete` respectively. Changed also on the mdStep.tpl from ng-if to ng-show to validate all steps of the form as one. --- demo/material-steppers-tpl.js | 4 ++-- demo/material-steppers.js | 13 ++++++++----- demo/material-steppers.min.js | 13 ++++++++----- dist/material-steppers.js | 13 ++++++++----- dist/material-steppers.min.js | 2 +- lib/material-steppers.ts | 10 +++++++--- lib/mdStep.tpl.html | 2 +- 7 files changed, 35 insertions(+), 22 deletions(-) diff --git a/demo/material-steppers-tpl.js b/demo/material-steppers-tpl.js index de3cfdf..541e759 100644 --- a/demo/material-steppers-tpl.js +++ b/demo/material-steppers-tpl.js @@ -1,2 +1,2 @@ -angular.module("mdSteppers").run(["$templateCache", function($templateCache) {$templateCache.put("mdSteppers/mdStep.tpl.html","
\r\n \r\n \r\n
\r\n {{stepper.feedbackMessage}}\r\n
\r\n
\r\n \r\n
"); -$templateCache.put("mdSteppers/mdStepper.tpl.html","
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n

\r\n {{stepper.labelStep}} {{stepper.currentStep+1}} {{stepper.labelOf}} {{stepper.steps.length}}\r\n

\r\n
\r\n
\r\n
\r\n
\r\n {{stepper.feedbackMessage}}\r\n
\r\n
\r\n \r\n
\r\n
");}]); \ No newline at end of file +angular.module("mdSteppers").run(["$templateCache", function($templateCache) {$templateCache.put("mdSteppers/mdStep.tpl.html","
\n \n \n
\n {{stepper.feedbackMessage}}\n
\n
\n \n
"); +$templateCache.put("mdSteppers/mdStepper.tpl.html","
\n
\n \n \n \n \n \n \n
\n

\n {{stepper.labelStep}} {{stepper.currentStep+1}} {{stepper.labelOf}} {{stepper.steps.length}}\n

\n
\n
\n
\n
\n {{stepper.feedbackMessage}}\n
\n
\n \n
\n
");}]); \ No newline at end of file diff --git a/demo/material-steppers.js b/demo/material-steppers.js index cdcaec1..e6576d8 100644 --- a/demo/material-steppers.js +++ b/demo/material-steppers.js @@ -1,8 +1,9 @@ var StepperCtrl = (function () { - function StepperCtrl($mdComponentRegistry, $attrs, $log) { + function StepperCtrl($mdComponentRegistry, $attrs, $log, $scope) { this.$mdComponentRegistry = $mdComponentRegistry; this.$attrs = $attrs; this.$log = $log; + this.$scope = $scope; this.labelStep = 'Step'; this.labelOf = 'of'; /* End of bindings */ @@ -51,6 +52,7 @@ var StepperCtrl = (function () { this.clearError(); this.currentStep++; this.clearFeedback(); + this.$scope.$emit('onstepcomplete', this.currentStep); return true; } return false; @@ -116,6 +118,7 @@ var StepperCtrl = (function () { if (stepNumber < this.steps.length) { this.currentStep = stepNumber; this.clearFeedback(); + this.$scope.$emit('gotostepcomplete', this.currentStep); return true; } return false; @@ -138,14 +141,14 @@ var StepperCtrl = (function () { StepperCtrl.prototype.isCompleted = function (stepNumber) { return this.linear && stepNumber < this.currentStep; }; - ; StepperCtrl.prototype.isActiveStep = function (step) { return this.steps.indexOf(step) === this.currentStep; }; StepperCtrl.$inject = [ '$mdComponentRegistry', '$attrs', - '$log' + '$log', + '$scope' ]; return StepperCtrl; }()); @@ -246,5 +249,5 @@ angular.module('mdSteppers', ['ngMaterial']) $templateCache.put("mdSteppers/ic_warning_24px.svg", "\r\n \r\n \r\n"); }]); -angular.module("mdSteppers").run(["$templateCache", function($templateCache) {$templateCache.put("mdSteppers/mdStep.tpl.html","
\r\n \r\n \r\n
\r\n {{stepper.feedbackMessage}}\r\n
\r\n
\r\n \r\n
"); -$templateCache.put("mdSteppers/mdStepper.tpl.html","
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n

\r\n {{stepper.labelStep}} {{stepper.currentStep+1}} {{stepper.labelOf}} {{stepper.steps.length}}\r\n

\r\n
\r\n
\r\n
\r\n
\r\n {{stepper.feedbackMessage}}\r\n
\r\n
\r\n \r\n
\r\n
");}]); \ No newline at end of file +angular.module("mdSteppers").run(["$templateCache", function($templateCache) {$templateCache.put("mdSteppers/mdStep.tpl.html","
\n \n \n
\n {{stepper.feedbackMessage}}\n
\n
\n \n
"); +$templateCache.put("mdSteppers/mdStepper.tpl.html","
\n
\n \n \n \n \n \n \n
\n

\n {{stepper.labelStep}} {{stepper.currentStep+1}} {{stepper.labelOf}} {{stepper.steps.length}}\n

\n
\n
\n
\n
\n {{stepper.feedbackMessage}}\n
\n
\n \n
\n
");}]); \ No newline at end of file diff --git a/demo/material-steppers.min.js b/demo/material-steppers.min.js index cdcaec1..e6576d8 100644 --- a/demo/material-steppers.min.js +++ b/demo/material-steppers.min.js @@ -1,8 +1,9 @@ var StepperCtrl = (function () { - function StepperCtrl($mdComponentRegistry, $attrs, $log) { + function StepperCtrl($mdComponentRegistry, $attrs, $log, $scope) { this.$mdComponentRegistry = $mdComponentRegistry; this.$attrs = $attrs; this.$log = $log; + this.$scope = $scope; this.labelStep = 'Step'; this.labelOf = 'of'; /* End of bindings */ @@ -51,6 +52,7 @@ var StepperCtrl = (function () { this.clearError(); this.currentStep++; this.clearFeedback(); + this.$scope.$emit('onstepcomplete', this.currentStep); return true; } return false; @@ -116,6 +118,7 @@ var StepperCtrl = (function () { if (stepNumber < this.steps.length) { this.currentStep = stepNumber; this.clearFeedback(); + this.$scope.$emit('gotostepcomplete', this.currentStep); return true; } return false; @@ -138,14 +141,14 @@ var StepperCtrl = (function () { StepperCtrl.prototype.isCompleted = function (stepNumber) { return this.linear && stepNumber < this.currentStep; }; - ; StepperCtrl.prototype.isActiveStep = function (step) { return this.steps.indexOf(step) === this.currentStep; }; StepperCtrl.$inject = [ '$mdComponentRegistry', '$attrs', - '$log' + '$log', + '$scope' ]; return StepperCtrl; }()); @@ -246,5 +249,5 @@ angular.module('mdSteppers', ['ngMaterial']) $templateCache.put("mdSteppers/ic_warning_24px.svg", "\r\n \r\n \r\n"); }]); -angular.module("mdSteppers").run(["$templateCache", function($templateCache) {$templateCache.put("mdSteppers/mdStep.tpl.html","
\r\n \r\n \r\n
\r\n {{stepper.feedbackMessage}}\r\n
\r\n
\r\n \r\n
"); -$templateCache.put("mdSteppers/mdStepper.tpl.html","
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n

\r\n {{stepper.labelStep}} {{stepper.currentStep+1}} {{stepper.labelOf}} {{stepper.steps.length}}\r\n

\r\n
\r\n
\r\n
\r\n
\r\n {{stepper.feedbackMessage}}\r\n
\r\n
\r\n \r\n
\r\n
");}]); \ No newline at end of file +angular.module("mdSteppers").run(["$templateCache", function($templateCache) {$templateCache.put("mdSteppers/mdStep.tpl.html","
\n \n \n
\n {{stepper.feedbackMessage}}\n
\n
\n \n
"); +$templateCache.put("mdSteppers/mdStepper.tpl.html","
\n
\n \n \n \n \n \n \n
\n

\n {{stepper.labelStep}} {{stepper.currentStep+1}} {{stepper.labelOf}} {{stepper.steps.length}}\n

\n
\n
\n
\n
\n {{stepper.feedbackMessage}}\n
\n
\n \n
\n
");}]); \ No newline at end of file diff --git a/dist/material-steppers.js b/dist/material-steppers.js index cdcaec1..e6576d8 100644 --- a/dist/material-steppers.js +++ b/dist/material-steppers.js @@ -1,8 +1,9 @@ var StepperCtrl = (function () { - function StepperCtrl($mdComponentRegistry, $attrs, $log) { + function StepperCtrl($mdComponentRegistry, $attrs, $log, $scope) { this.$mdComponentRegistry = $mdComponentRegistry; this.$attrs = $attrs; this.$log = $log; + this.$scope = $scope; this.labelStep = 'Step'; this.labelOf = 'of'; /* End of bindings */ @@ -51,6 +52,7 @@ var StepperCtrl = (function () { this.clearError(); this.currentStep++; this.clearFeedback(); + this.$scope.$emit('onstepcomplete', this.currentStep); return true; } return false; @@ -116,6 +118,7 @@ var StepperCtrl = (function () { if (stepNumber < this.steps.length) { this.currentStep = stepNumber; this.clearFeedback(); + this.$scope.$emit('gotostepcomplete', this.currentStep); return true; } return false; @@ -138,14 +141,14 @@ var StepperCtrl = (function () { StepperCtrl.prototype.isCompleted = function (stepNumber) { return this.linear && stepNumber < this.currentStep; }; - ; StepperCtrl.prototype.isActiveStep = function (step) { return this.steps.indexOf(step) === this.currentStep; }; StepperCtrl.$inject = [ '$mdComponentRegistry', '$attrs', - '$log' + '$log', + '$scope' ]; return StepperCtrl; }()); @@ -246,5 +249,5 @@ angular.module('mdSteppers', ['ngMaterial']) $templateCache.put("mdSteppers/ic_warning_24px.svg", "\r\n \r\n \r\n"); }]); -angular.module("mdSteppers").run(["$templateCache", function($templateCache) {$templateCache.put("mdSteppers/mdStep.tpl.html","
\r\n \r\n \r\n
\r\n {{stepper.feedbackMessage}}\r\n
\r\n
\r\n \r\n
"); -$templateCache.put("mdSteppers/mdStepper.tpl.html","
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n

\r\n {{stepper.labelStep}} {{stepper.currentStep+1}} {{stepper.labelOf}} {{stepper.steps.length}}\r\n

\r\n
\r\n
\r\n
\r\n
\r\n {{stepper.feedbackMessage}}\r\n
\r\n
\r\n \r\n
\r\n
");}]); \ No newline at end of file +angular.module("mdSteppers").run(["$templateCache", function($templateCache) {$templateCache.put("mdSteppers/mdStep.tpl.html","
\n \n \n
\n {{stepper.feedbackMessage}}\n
\n
\n \n
"); +$templateCache.put("mdSteppers/mdStepper.tpl.html","
\n
\n \n \n \n \n \n \n
\n

\n {{stepper.labelStep}} {{stepper.currentStep+1}} {{stepper.labelOf}} {{stepper.steps.length}}\n

\n
\n
\n
\n
\n {{stepper.feedbackMessage}}\n
\n
\n \n
\n
");}]); \ No newline at end of file diff --git a/dist/material-steppers.min.js b/dist/material-steppers.min.js index 1fcccf8..3e620b3 100644 --- a/dist/material-steppers.min.js +++ b/dist/material-steppers.min.js @@ -1 +1 @@ -var StepperCtrl=function(){function e(e,t,r){this.$mdComponentRegistry=e,this.$attrs=t,this.$log=r,this.labelStep="Step",this.labelOf="of",this.steps=[],this.currentStep=0}return e.prototype.$onInit=function(){""===this.$attrs.mdMobileStepText&&(this.mobileStepText=!0),""===this.$attrs.mdLinear&&(this.linear=!0),""===this.$attrs.mdAlternative&&(this.alternative=!0)},e.prototype.$postLink=function(){this.$attrs.id||this.$log.warn("You must set an id attribute to your stepper"),this.registeredStepper=this.$mdComponentRegistry.register(this,this.$attrs.id)},e.prototype.$onDestroy=function(){this.registeredStepper&&this.registeredStepper()},e.prototype.$addStep=function(e){return this.steps.push(e)-1},e.prototype.next=function(){return this.currentStep0&&(this.clearError(),this.currentStep--,this.clearFeedback(),!0)},e.prototype.skip=function(){var e=this.steps[this.currentStep];return!!e.optional&&(this.currentStep++,this.clearFeedback(),!0)},e.prototype.error=function(e){var t=this.steps[this.currentStep];t.hasError=!0,t.message=e,this.clearFeedback()},e.prototype.clearError=function(){var e=this.steps[this.currentStep];e.hasError=!1},e.prototype["goto"]=function(e){return e\n
\n \n
');e(p)(t),r.find(".md-steppers-scope").append(p)}}t.$ctrl.$stepper=p,t.$watch(function(){return t.$ctrl.isActive()},function(e){e?(r.addClass("md-active"),n()):r.removeClass("md-active")})},templateUrl:"mdSteppers/mdStep.tpl.html"}}]).config(["$mdIconProvider",function(e){e.icon("steppers-check","mdSteppers/ic_check_24px.svg"),e.icon("steppers-warning","mdSteppers/ic_warning_24px.svg")}]).run(["$templateCache",function(e){e.put("mdSteppers/ic_check_24px.svg",'\r\n \r\n \r\n'),e.put("mdSteppers/ic_warning_24px.svg",'\r\n \r\n \r\n')}]),angular.module("mdSteppers").run(["$templateCache",function(e){e.put("mdSteppers/mdStep.tpl.html",'
\r\n \r\n \r\n
\r\n {{stepper.feedbackMessage}}\r\n
\r\n
\r\n \r\n
'),e.put("mdSteppers/mdStepper.tpl.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n

\r\n {{stepper.labelStep}} {{stepper.currentStep+1}} {{stepper.labelOf}} {{stepper.steps.length}}\r\n

\r\n
\r\n
\r\n
\r\n
\r\n {{stepper.feedbackMessage}}\r\n
\r\n
\r\n \r\n
\r\n
')}]); \ No newline at end of file +var StepperCtrl=function(){function e(e,t,r,s){this.$mdComponentRegistry=e,this.$attrs=t,this.$log=r,this.$scope=s,this.labelStep="Step",this.labelOf="of",this.steps=[],this.currentStep=0}return e.prototype.$onInit=function(){""===this.$attrs.mdMobileStepText&&(this.mobileStepText=!0),""===this.$attrs.mdLinear&&(this.linear=!0),""===this.$attrs.mdAlternative&&(this.alternative=!0)},e.prototype.$postLink=function(){this.$attrs.id||this.$log.warn("You must set an id attribute to your stepper"),this.registeredStepper=this.$mdComponentRegistry.register(this,this.$attrs.id)},e.prototype.$onDestroy=function(){this.registeredStepper&&this.registeredStepper()},e.prototype.$addStep=function(e){return this.steps.push(e)-1},e.prototype.next=function(){return this.currentStep0&&(this.clearError(),this.currentStep--,this.clearFeedback(),!0)},e.prototype.skip=function(){var e=this.steps[this.currentStep];return!!e.optional&&(this.currentStep++,this.clearFeedback(),!0)},e.prototype.error=function(e){var t=this.steps[this.currentStep];t.hasError=!0,t.message=e,this.clearFeedback()},e.prototype.clearError=function(){var e=this.steps[this.currentStep];e.hasError=!1},e.prototype["goto"]=function(e){return e\n
\n \n
');e(p)(t),r.find(".md-steppers-scope").append(p)}}t.$ctrl.$stepper=p,t.$watch(function(){return t.$ctrl.isActive()},function(e){e?(r.addClass("md-active"),n()):r.removeClass("md-active")})},templateUrl:"mdSteppers/mdStep.tpl.html"}}]).config(["$mdIconProvider",function(e){e.icon("steppers-check","mdSteppers/ic_check_24px.svg"),e.icon("steppers-warning","mdSteppers/ic_warning_24px.svg")}]).run(["$templateCache",function(e){e.put("mdSteppers/ic_check_24px.svg",'\r\n \r\n \r\n'),e.put("mdSteppers/ic_warning_24px.svg",'\r\n \r\n \r\n')}]),angular.module("mdSteppers").run(["$templateCache",function(e){e.put("mdSteppers/mdStep.tpl.html",'
\n \n \n
\n {{stepper.feedbackMessage}}\n
\n
\n \n
'),e.put("mdSteppers/mdStepper.tpl.html",'
\n
\n \n \n \n \n \n \n
\n

\n {{stepper.labelStep}} {{stepper.currentStep+1}} {{stepper.labelOf}} {{stepper.steps.length}}\n

\n
\n
\n
\n
\n {{stepper.feedbackMessage}}\n
\n
\n \n
\n
')}]); \ No newline at end of file diff --git a/lib/material-steppers.ts b/lib/material-steppers.ts index 04abb4b..5dfeba5 100644 --- a/lib/material-steppers.ts +++ b/lib/material-steppers.ts @@ -3,7 +3,8 @@ class StepperCtrl { public static $inject = [ '$mdComponentRegistry', '$attrs', - '$log' + '$log', + '$scope' ]; /* Bindings */ @@ -27,7 +28,8 @@ class StepperCtrl { constructor( private $mdComponentRegistry, private $attrs, - private $log + private $log, + private $scope: ng.IScope ) { } @@ -77,6 +79,7 @@ class StepperCtrl { this.clearError(); this.currentStep++; this.clearFeedback(); + this.$scope.$emit('onstepcomplete', this.currentStep); return true; } return false; @@ -148,6 +151,7 @@ class StepperCtrl { if (stepNumber < this.steps.length) { this.currentStep = stepNumber; this.clearFeedback(); + this.$scope.$emit('gotostepcomplete', this.currentStep); return true; } return false; @@ -173,7 +177,7 @@ class StepperCtrl { isCompleted(stepNumber: number) { return this.linear && stepNumber < this.currentStep; - }; + } isActiveStep(step: StepCtrl) { return this.steps.indexOf(step) === this.currentStep; diff --git a/lib/mdStep.tpl.html b/lib/mdStep.tpl.html index c7387f8..7dc9f3d 100644 --- a/lib/mdStep.tpl.html +++ b/lib/mdStep.tpl.html @@ -28,5 +28,5 @@ {{stepper.feedbackMessage}} - + \ No newline at end of file