From 8688b46370d380adea0207429f18fda4d2351298 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 13 Dec 2014 23:25:44 -0800 Subject: [PATCH] CRM-15578 - crmUiWizard - Allow conditional steps --- js/angular-crm-ui.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index 72c57d33c6..8bd92becbb 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -556,6 +556,19 @@ selectedIndex = 0; } steps.push(step); + steps.sort(function(a,b){ + return a.crmUiWizardStep - b.crmUiWizardStep; + }); + selectedIndex = findIndex(); + }; + this.remove = function(step) { + var key = null; + angular.forEach(steps, function(otherStep, otherKey) { + if (otherStep === step) key = otherKey; + }); + if (key != null) { + steps.splice(key, 1); + } }; this.goto = function(index) { if (index < 0) index = 0; @@ -587,18 +600,30 @@ }; }) - // example
...content...
+ // example:
...content...
+ // If there are any conditional steps, then be sure to set a weight explicitly on *all* steps to maintain ordering. + // example:
...content...
.directive('crmUiWizardStep', function() { + var nextWeight = 1; return { require: '^crmUiWizard', restrict: 'EA', scope: { - crmTitle: '@' + crmTitle: '@', // expression, evaluates to a printable string + crmUiWizardStep: '@' // int, a weight which determines the ordering of the steps }, template: '
', transclude: true, link: function (scope, element, attrs, crmUiWizardCtrl) { + if (scope.crmUiWizardStep) { + scope.crmUiWizardStep = parseInt(scope.crmUiWizardStep); + } else { + scope.crmUiWizardStep = nextWeight++; + } crmUiWizardCtrl.add(scope); + element.on('$destroy', function(){ + crmUiWizardCtrl.remove(scope); + }); } }; }) -- 2.25.1