/** * An element which displays a linear workflow of sections, each completed in order before the next * step is made visible. */ angular.module('quay').directive('linearWorkflow', function () { var directiveDefinitionObject = { priority: 0, templateUrl: '/static/directives/linear-workflow.html', replace: false, transclude: true, restrict: 'C', scope: { 'workflowState': '=?workflowState', 'workflowComplete': '&workflowComplete', 'doneTitle': '@doneTitle' }, controller: function($scope, $element, $timeout) { $scope.sections = []; $scope.nextSection = function() { if (!$scope.currentSection.valid) { return; } var currentIndex = $scope.currentSection.index; if (currentIndex + 1 >= $scope.sections.length) { $scope.workflowComplete(); return; } $scope.workflowState = $scope.sections[currentIndex + 1].id; }; this.registerSection = function(sectionScope, sectionElement) { // Add the section to the list. var sectionInfo = { 'index': $scope.sections.length, 'id': sectionScope.sectionId, 'title': sectionScope.sectionTitle, 'scope': sectionScope, 'element': sectionElement }; $scope.sections.push(sectionInfo); // Add a watch on the `sectionValid` value on the section itself. If/when this value // changes, we copy it over to the sectionInfo, so that the overall workflow can watch // the change. sectionScope.$watch('sectionValid', function(isValid) { sectionInfo['valid'] = isValid; if (!isValid) { // Reset the sections back to this section. updateState(); } }); // Bind the `submitSection` callback to move to the next section when the user hits // enter (which calls this method on the scope via an ng-submit set on a wrapping //