Skip to content

Commit 4844ad2

Browse files
Optimize next and previous functions.
1 parent 6d1eba9 commit 4844ad2

File tree

2 files changed

+23
-49
lines changed

2 files changed

+23
-49
lines changed

src/wizard/wizard-directive.js

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -635,32 +635,22 @@ angular.module('patternfly.wizard').directive('pfWizard', function ($window) {
635635
}
636636

637637
// Check if callback is a function
638-
if (angular.isFunction(callback)) {
639-
if (callback($scope.selectedStep)) {
640-
if (index <= enabledSteps.length - 1) {
641-
// Go to the next step
642-
if (enabledSteps[index + 1].substeps) {
643-
enabledSteps[index + 1].resetNav();
644-
}
645-
} else {
646-
this.finish();
647-
return;
648-
}
638+
if (!angular.isFunction(callback) || callback($scope.selectedStep)) {
639+
// Completed property set on scope which is used to add class/remove class from progress bar
640+
$scope.selectedStep.completed = true;
641+
642+
// Check to see if this is the last step. If it is next behaves the same as finish()
643+
if (index === enabledSteps.length - 1) {
644+
this.finish();
649645
} else {
650-
return;
646+
// Go to the next step
647+
if (enabledSteps[index + 1].substeps) {
648+
enabledSteps[index + 1].resetNav();
649+
}
650+
// Go to the next step
651+
$scope.goTo(enabledSteps[index + 1]);
651652
}
652653
}
653-
654-
// Completed property set on scope which is used to add class/remove class from progress bar
655-
$scope.selectedStep.completed = true;
656-
657-
// Check to see if this is the last step. If it is next behaves the same as finish()
658-
if (index === enabledSteps.length - 1) {
659-
this.finish();
660-
} else {
661-
// Go to the next step
662-
$scope.goTo(enabledSteps[index + 1]);
663-
}
664654
};
665655

666656
this.previous = function (callback) {
@@ -673,15 +663,7 @@ angular.module('patternfly.wizard').directive('pfWizard', function ($window) {
673663
}
674664

675665
// Check if callback is a function
676-
if (angular.isFunction(callback)) {
677-
if (callback($scope.selectedStep)) {
678-
if (index === 0) {
679-
throw new Error("Can't go back. It's already in step 0");
680-
} else {
681-
$scope.goTo($scope.getEnabledSteps()[index - 1]);
682-
}
683-
}
684-
} else {
666+
if (!angular.isFunction(callback) || callback($scope.selectedStep)) {
685667
if (index === 0) {
686668
throw new Error("Can't go back. It's already in step 0");
687669
} else {

src/wizard/wizard-step-directive.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -348,33 +348,25 @@ angular.module('patternfly.wizard').directive('pfWizardStep', function () {
348348
// Method used for next button within step
349349
$scope.next = function (callback) {
350350
var enabledSteps = $scope.getEnabledSteps();
351+
var goNext = false;
351352

352353
// Save the step you were on when next() was invoked
353354
var index = stepIdx($scope.selectedStep);
354355

355356
// Check if callback is a function
356-
if (angular.isFunction (callback)) {
357-
if (callback($scope.selectedStep)) {
358-
if (index === enabledSteps.length - 1) {
359-
return false;
360-
}
357+
if (!angular.isFunction (callback) || callback($scope.selectedStep)) {
358+
359+
// Completed property set on scope which is used to add class/remove class from progress bar
360+
$scope.selectedStep.completed = true;
361+
362+
if (index < enabledSteps.length - 1) {
361363
// Go to the next step
362364
$scope.goTo(enabledSteps[index + 1]);
363-
return true;
365+
goNext = true;
364366
}
365-
return true;
366367
}
367368

368-
// Completed property set on scope which is used to add class/remove class from progress bar
369-
$scope.selectedStep.completed = true;
370-
371-
// Check to see if this is the last step. If it is next behaves the same as finish()
372-
if (index === enabledSteps.length - 1) {
373-
return false;
374-
}
375-
// Go to the next step
376-
$scope.goTo(enabledSteps[index + 1]);
377-
return true;
369+
return goNext;
378370
};
379371

380372
$scope.previous = function (callback) {

0 commit comments

Comments
 (0)