11angular . module ( 'ionic.wizard' , [ ] )
2-
2+ . directive ( 'ionWizardContent' , [ 'ionContentDirective' , function ( ionContentDirective ) {
3+ return angular . extend ( { } , ionContentDirective [ 0 ] , { scope : false } ) ;
4+ } ] )
35 . directive ( 'ionWizard' , [ '$rootScope' , '$ionicSlideBoxDelegate' , function ( $rootScope , $ionicSlideBoxDelegate ) {
46 return {
57 restrict : 'EA' ,
@@ -10,8 +12,8 @@ angular.module('ionic.wizard', [])
1012 conditions . push ( condition ) ;
1113 } ;
1214
13- this . isStepValid = function ( index ) {
14- return angular . isDefined ( conditions [ index ] ) ? conditions [ index ] ( ) : true ;
15+ this . getCondition = function ( index ) {
16+ return conditions [ index ] ;
1517 } ;
1618
1719 } ] ,
@@ -26,11 +28,12 @@ angular.module('ionic.wizard', [])
2628 $ionicSlideBoxDelegate . previous ( ) ;
2729 } ) ;
2830 scope . $on ( "wizard:Next" , function ( ) {
29- if ( controller . isStepValid ( currentIndex ) ) {
31+ var fn = controller . getCondition ( currentIndex ) ;
32+ fn ( ) . then ( function ( ) {
3033 $ionicSlideBoxDelegate . next ( ) ;
31- } else {
34+ } , function ( ) {
3235 $rootScope . $broadcast ( "wizard:StepFailed" , { index : currentIndex } ) ;
33- }
36+ } )
3437 } ) ;
3538
3639 scope . $on ( "slideBox.slideChanged" , function ( e , index ) {
@@ -40,19 +43,34 @@ angular.module('ionic.wizard', [])
4043 }
4144
4245 } ] )
43- . directive ( 'ionWizardStep' , [ function ( ) {
46+ . directive ( 'ionWizardStep' , [ '$q' , function ( $q ) {
4447 return {
4548 restrict : 'EA' ,
4649 scope : {
4750 conditionFn : '&condition'
4851 } ,
4952 require : '^^ionWizard' ,
5053 link : function ( scope , element , attrs , controller ) {
51- controller . addCondition ( attrs . condition ? scope . conditionFn : undefined ) ;
54+ var fn = function ( ) {
55+ var deferred = $q . defer ( ) ;
56+
57+ if ( angular . isUndefined ( attrs . condition ) ) {
58+ deferred . resolve ( ) ;
59+ } else {
60+ if ( scope . conditionFn ( ) ) {
61+ deferred . resolve ( ) ;
62+ } else {
63+ deferred . reject ( ) ;
64+ }
65+ }
66+
67+ return deferred . promise ;
68+ } ;
69+ controller . addCondition ( fn ) ;
5270 }
5371 }
5472 } ] )
55- . directive ( 'ionWizardPrevious' , [ '$rootScope' , '$ionicSlideBoxDelegate' , function ( $rootScope , $ionicSlideBoxDelegate ) {
73+ . directive ( 'ionWizardPrevious' , [ '$rootScope' , '$ionicSlideBoxDelegate' , function ( $rootScope ) {
5674 return {
5775 restrict : 'EA' ,
5876 scope : { } ,
@@ -61,7 +79,6 @@ angular.module('ionic.wizard', [])
6179 element . addClass ( 'ng-hide' ) ;
6280
6381 element . on ( 'click' , function ( ) {
64- //$ionicSlideBoxDelegate.previous();
6582 $rootScope . $broadcast ( "wizard:Previous" ) ;
6683 } ) ;
6784
0 commit comments