Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- 'use strict';
- angular
- .module('app')
- .directive('navButton', navigationDirective);
- navigationDirective.$inject = ['$window', '$location'];
- function navigationDirective($window, location) {
- // Usage:
- // <button data-ng-switch-when="back" style="button" is-driver="ctrl.isDriver" direction="back" ><span style="vertical-align:middle" class="glyphicon glyphicon-chevron-left"></span> Back</button>
- // <button data-ng-switch-when="forward" style="button" is-driver="ctrl.isDriver" direction="forward" >Forward <span style="vertical-align:middle" class="glyphicon glyphicon-chevron-right"></span></button>
- // Creates:
- //
- var directive = {
- link: link,
- restrict: 'E',
- scope: {
- direction: '@',
- isDriver: '=',
- type: '@',
- targetForm: '='
- },
- replace: true,
- transclude: false,
- template: '<div class="controls" data-ng-switch="direction">' +
- '<button data-ng-switch-when="back" class="btn btn-default" type="{{type}}" ><span style="vertical-align:middle" class="glyphicon glyphicon-chevron-left"></span> Back</button>' +
- '<button data-ng-switch-when="forward" class="btn btn-default" type="{{type}}" >Forward <span style="vertical-align:middle" class="glyphicon glyphicon-chevron-right"></span></button>' +
- '</div>',
- };
- var driverPageOrder = [
- '/Intro',
- '/Personal',
- '/Contact',
- '/AddressHistory',
- '/JobInfo',
- '/Q1',
- '/Q2',
- '/Military',
- '/EmploymentHistory',
- '/HighSchool',
- '/College',
- '/Graduate',
- '/TradeSchool',
- '/DrivingExp',
- '/DrivingExpCont',
- '/Licenses',
- '/Accidents',
- '/Convictions',
- '/Skills',
- '/References',
- '/Agreement'
- ];
- var standardPageOrder = [
- '/Intro',
- '/Personal',
- '/Contact',
- '/Military',
- '/JobInfo',
- '/Q1',
- '/Q2',
- '/EmploymentHistory',
- '/HighSchool',
- '/College',
- '/Graduate',
- '/TradeSchool',
- '/Skills',
- '/References',
- '/Agreement'
- ];
- return directive;
- function link(scope, element, attrs) {
- element.on('click', function () {
- function goForward(isDriver) {
- var currentPageIndex = null;
- if (isDriver) {
- currentPageIndex = driverPageOrder.indexOf(location.path());
- return driverPageOrder[currentPageIndex + 1];
- }
- else {
- currentPageIndex = standardPageOrder.indexOf(location.path());
- return standardPageOrder[currentPageIndex + 1];
- }
- };
- function goBack(isDriver) {
- var currentPageIndex = null;
- if (isDriver) {
- currentPageIndex = driverPageOrder.indexOf(location.path());
- if (currentPageIndex - 1 < 0) {
- currentPageIndex = 1;
- }
- return driverPageOrder[currentPageIndex - 1];
- }
- else {
- currentPageIndex = standardPageOrder.indexOf(location.path());
- if (currentPageIndex - 1 < 0) {
- currentPageIndex = 1;
- }
- return standardPageOrder[currentPageIndex - 1];
- }
- }
- switch (scope.direction) {
- case "back":
- location.path(goBack(scope.isDriver));
- scope.$apply();
- break;
- case "forward":
- if (!scope.targetForm || scope.targetForm.$valid)
- {
- location.path(goForward(scope.isDriver));
- scope.$apply();
- }
- break;
- default:
- }
- });
- }
- }
- })();
- (function() {
- 'use strict';
- angular
- .module('TSLEmployment')
- .directive('saveInfo', saveInfo);
- saveInfo.$inject = ['$window', 'GeneralRepo'];
- function saveInfo ($window, GeneralRepo) {
- // Usage:
- // <saveInfo></saveInfo>
- // Creates:
- //
- var directive = {
- link: link,
- restrict: 'A',
- scope: {
- objectToSave: '='
- },
- };
- return directive;
- function link(scope, element, attrs) {
- GeneralRepo.addApplicationData(scope.objectToSave);
- }
- }
- })();
- // The Useage I want: right now I get this error
- // Error: [$compile:multidir] Multiple directives [navButton, saveInfo] asking for new/isolated scope on: <div class="pull-right controls" data-ng-switch="direction" tabindex="14" is-driver="ctrl.isDriver" target-form="personalForm" direction="forward" type="submit" save-info="" object-to-save="ctrl.tslApplication">
- //
- <nav-button tabindex="14" is-driver="ctrl.isDriver" target-form="personalForm" direction="forward" type="submit" class="pull-right" save-info object-to-save="ctrl.ApplicationData"></nav-button>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement