From: Tim Otten Date: Thu, 30 Oct 2014 05:38:00 +0000 (-0700) Subject: CRM-15578 - crmUiWizard - Basic implementation X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6717e4b9f3bc439d54439aa0652cb5a586c68f18;p=civicrm-core.git CRM-15578 - crmUiWizard - Basic implementation --- diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index 571f56a699..ba90939ac0 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -2,6 +2,11 @@ (function (angular, $, _) { var idCount = 0; + var partialUrl = function (relPath) { + return CRM.resourceUrls['civicrm'] + '/partials/crmUi/' + relPath; + }; + + angular.module('crmUi', []) // example
...content...
@@ -168,32 +173,113 @@ }; }) - // example:
...
...
+ // example:
...
...
+ // Note: "myWizardCtrl" has various actions/properties like next() and $first(). + // WISHLIST: Allow each step to determine if it is "complete" / "valid" / "selectable" + // WISHLIST: Allow each step to enable/disable (show/hide) itself .directive('crmUiWizard', function() { return { - template: '
', + restrict: 'EA', + scope: { + crmUiWizard: '@' + }, + templateUrl: partialUrl('wizard.html'), transclude: true, + controllerAs: 'crmUiWizardCtrl', + controller: function($scope, $parse) { + var steps = $scope.steps = []; // array<$scope> + var crmUiWizardCtrl = this; + var maxVisited = 0; + var selectedIndex = null; + + var findIndex = function() { + var found = null; + angular.forEach(steps, function(step, stepKey) { + if (step.selected) found = stepKey; + }); + return found; + }; + + /// @return int the index of the current step + this.$index = function() { return selectedIndex; }; + /// @return bool whether the currentstep is first + this.$first = function() { return this.$index() === 0; }; + /// @return bool whether the current step is last + this.$last = function() { return this.$index() === steps.length -1; }; + this.$maxVisit = function() { return maxVisited; } + this.iconFor = function(index) { + if (index < this.$index()) return '√'; + if (index === this.$index()) return '»'; + return ' '; + } + this.isSelectable = function(step) { + if (step.selected) return false; + var result = false; + angular.forEach(steps, function(otherStep, otherKey) { + if (step === otherStep && otherKey <= maxVisited) result = true; + }); + return result; + }; + + /*** @param Object step the $scope of the step */ + this.select = function(step) { + angular.forEach(steps, function(otherStep, otherKey) { + otherStep.selected = (otherStep === step); + if (otherStep === step && maxVisited < otherKey) maxVisited = otherKey; + }); + selectedIndex = findIndex(); + }; + /*** @param Object step the $scope of the step */ + this.add = function(step) { + if (steps.length === 0) { + step.selected = true; + selectedIndex = 0; + } + steps.push(step); + }; + this.goto = function(index) { + if (index < 0) index = 0; + if (index >= steps.length) index = steps.length-1; + this.select(steps[index]); + }; + this.previous = function() { this.goto(this.$index()-1); }; + this.next = function() { this.goto(this.$index()+1); }; + if ($scope.crmUiWizard) { + $parse($scope.crmUiWizard).assign($scope.$parent, this) + } + }, link: function (scope, element, attrs) {} }; }) - .directive('crmUiWizardFooter', function() { + // Use this to add extra markup to wizard + .directive('crmUiWizardButtons', function() { return { - template: '
', + require: '^crmUiWizard', + restrict: 'EA', + scope: {}, + template: '', transclude: true, - link: function (scope, element, attrs) {} + link: function (scope, element, attrs, crmUiWizardCtrl) { + var realButtonsEl = $(element).closest('.crm-wizard').find('.crm-wizard-buttons'); + $(element).appendTo(realButtonsEl); + } }; }) // example
...content...
.directive('crmUiWizardStep', function() { return { + require: '^crmUiWizard', + restrict: 'EA', scope: { crmTitle: '@' }, - template: '
(Step: {{$parent.$eval(crmTitle)}})
', + template: '
', transclude: true, - link: function (scope, element, attrs) {} + link: function (scope, element, attrs, crmUiWizardCtrl) { + crmUiWizardCtrl.add(scope); + } }; }) diff --git a/partials/crmMailing2/edit.html b/partials/crmMailing2/edit.html index 35bafd955c..ffdfb59e6f 100644 --- a/partials/crmMailing2/edit.html +++ b/partials/crmMailing2/edit.html @@ -37,11 +37,10 @@ gotoListing();">Schedule -
- + -
- - + + + \ No newline at end of file diff --git a/partials/crmUi/wizard.html b/partials/crmUi/wizard.html new file mode 100644 index 0000000000..524e3a8bb0 --- /dev/null +++ b/partials/crmUi/wizard.html @@ -0,0 +1,15 @@ +
+ +
+
+ + +
+
\ No newline at end of file