2015-02-19 21:21:54 +00:00
|
|
|
/**
|
|
|
|
* An element which displays the steps of the wizard-like dialog, changing them as each step
|
|
|
|
* is completed.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('stepView', function ($compile) {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/step-view.html',
|
|
|
|
replace: true,
|
|
|
|
transclude: true,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'nextStepCounter': '=nextStepCounter',
|
|
|
|
'currentStepValid': '=currentStepValid',
|
|
|
|
|
|
|
|
'stepsCompleted': '&stepsCompleted'
|
|
|
|
},
|
|
|
|
controller: function($scope, $element, $rootScope) {
|
2015-04-30 19:33:19 +00:00
|
|
|
var currentStepIndex = -1;
|
|
|
|
var steps = [];
|
|
|
|
var watcher = null;
|
2015-02-19 21:21:54 +00:00
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
// Members on 'this' are accessed by the individual steps.
|
|
|
|
this.register = function(scope, element) {
|
|
|
|
element.hide();
|
|
|
|
|
|
|
|
steps.push({
|
|
|
|
'scope': scope,
|
|
|
|
'element': element
|
|
|
|
});
|
|
|
|
|
|
|
|
nextStep();
|
|
|
|
};
|
|
|
|
|
|
|
|
var getCurrentStep = function() {
|
|
|
|
return steps[currentStepIndex];
|
2015-02-19 21:21:54 +00:00
|
|
|
};
|
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
var reset = function() {
|
|
|
|
currentStepIndex = -1;
|
|
|
|
for (var i = 0; i < steps.length; ++i) {
|
|
|
|
steps[i].element.hide();
|
2015-02-19 21:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.currentStepValid = false;
|
|
|
|
};
|
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
var next = function() {
|
|
|
|
if (currentStepIndex >= 0) {
|
|
|
|
var currentStep = getCurrentStep();
|
2015-02-19 21:21:54 +00:00
|
|
|
if (!currentStep || !currentStep.scope) { return; }
|
|
|
|
|
|
|
|
if (!currentStep.scope.completeCondition) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentStep.element.hide();
|
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
if (unwatch) {
|
|
|
|
unwatch();
|
|
|
|
unwatch = null;
|
2015-02-19 21:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
currentStepIndex++;
|
2015-02-19 21:21:54 +00:00
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
if (currentStepIndex < steps.length) {
|
|
|
|
var currentStep = getCurrentStep();
|
2015-02-19 21:21:54 +00:00
|
|
|
currentStep.element.show();
|
|
|
|
currentStep.scope.load()
|
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
unwatch = currentStep.scope.$watch('completeCondition', function(cc) {
|
2015-02-19 21:21:54 +00:00
|
|
|
$scope.currentStepValid = !!cc;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$scope.stepsCompleted();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
var nextStep = function() {
|
|
|
|
if (!steps || !steps.length) { return; }
|
2015-02-19 21:21:54 +00:00
|
|
|
|
2015-04-30 19:33:19 +00:00
|
|
|
if ($scope.nextStepCounter >= 0) {
|
|
|
|
next();
|
2015-02-19 21:21:54 +00:00
|
|
|
} else {
|
2015-04-30 19:33:19 +00:00
|
|
|
reset();
|
2015-02-19 21:21:54 +00:00
|
|
|
}
|
2015-04-30 19:33:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$watch('nextStepCounter', nextStep);
|
2015-02-19 21:21:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A step in the step view.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('stepViewStep', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 1,
|
|
|
|
require: '^stepView',
|
|
|
|
templateUrl: '/static/directives/step-view-step.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: true,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'completeCondition': '=completeCondition',
|
|
|
|
'loadCallback': '&loadCallback',
|
|
|
|
'loadMessage': '@loadMessage'
|
|
|
|
},
|
|
|
|
link: function(scope, element, attrs, controller) {
|
|
|
|
controller.register(scope, element);
|
|
|
|
},
|
|
|
|
controller: function($scope, $element) {
|
|
|
|
$scope.load = function() {
|
|
|
|
$scope.loading = true;
|
|
|
|
$scope.loadCallback({'callback': function() {
|
|
|
|
$scope.loading = false;
|
|
|
|
}});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|