Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.     'use strict';
  3.  
  4.     angular
  5.         .module('app')
  6.         .directive('navButton', navigationDirective);
  7.  
  8.     navigationDirective.$inject = ['$window', '$location'];
  9.  
  10.     function navigationDirective($window, location) {
  11.         // Usage:
  12.         //     <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>
  13.         //     <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>
  14.         // Creates:
  15.         //
  16.         var directive = {
  17.             link: link,
  18.             restrict: 'E',
  19.             scope: {
  20.                 direction: '@',
  21.                 isDriver: '=',
  22.                 type: '@',
  23.                 targetForm: '='
  24.             },
  25.             replace: true,
  26.             transclude: false,
  27.             template: '<div class="controls" data-ng-switch="direction">' +
  28.                 '<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>' +
  29.                 '<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>' +
  30.             '</div>',
  31.         };
  32.  
  33.         var driverPageOrder = [
  34.             '/Intro',
  35.             '/Personal',
  36.             '/Contact',
  37.             '/AddressHistory',
  38.             '/JobInfo',
  39.             '/Q1',
  40.             '/Q2',
  41.             '/Military',
  42.             '/EmploymentHistory',
  43.             '/HighSchool',
  44.             '/College',
  45.             '/Graduate',
  46.             '/TradeSchool',
  47.             '/DrivingExp',
  48.             '/DrivingExpCont',
  49.             '/Licenses',
  50.             '/Accidents',
  51.             '/Convictions',
  52.             '/Skills',
  53.             '/References',
  54.             '/Agreement'
  55.         ];
  56.  
  57.         var standardPageOrder = [
  58.             '/Intro',
  59.             '/Personal',
  60.             '/Contact',
  61.             '/Military',
  62.             '/JobInfo',
  63.             '/Q1',
  64.             '/Q2',
  65.             '/EmploymentHistory',
  66.             '/HighSchool',
  67.             '/College',
  68.             '/Graduate',
  69.             '/TradeSchool',
  70.             '/Skills',
  71.             '/References',
  72.             '/Agreement'
  73.         ];
  74.  
  75.         return directive;
  76.  
  77.         function link(scope, element, attrs) {
  78.             element.on('click', function () {
  79.                 function goForward(isDriver) {
  80.                     var currentPageIndex = null;
  81.                     if (isDriver) {
  82.                         currentPageIndex = driverPageOrder.indexOf(location.path());
  83.                         return driverPageOrder[currentPageIndex + 1];
  84.                     }
  85.                     else {
  86.                         currentPageIndex = standardPageOrder.indexOf(location.path());
  87.                         return standardPageOrder[currentPageIndex + 1];
  88.                     }
  89.                 };
  90.                 function goBack(isDriver) {
  91.                     var currentPageIndex = null;
  92.                     if (isDriver) {
  93.                         currentPageIndex = driverPageOrder.indexOf(location.path());
  94.  
  95.                         if (currentPageIndex - 1 < 0) {
  96.                             currentPageIndex = 1;
  97.                         }
  98.                         return driverPageOrder[currentPageIndex - 1];
  99.                     }
  100.                     else {
  101.                         currentPageIndex = standardPageOrder.indexOf(location.path());
  102.  
  103.                         if (currentPageIndex - 1 < 0) {
  104.                             currentPageIndex = 1;
  105.                         }
  106.                         return standardPageOrder[currentPageIndex - 1];
  107.                     }
  108.                 }
  109.  
  110.                 switch (scope.direction) {
  111.                     case "back":
  112.                         location.path(goBack(scope.isDriver));
  113.                         scope.$apply();
  114.                         break;
  115.                     case "forward":
  116.                         if (!scope.targetForm || scope.targetForm.$valid)
  117.                         {
  118.                             location.path(goForward(scope.isDriver));
  119.                             scope.$apply();
  120.                         }
  121.                         break;
  122.                     default:
  123.                 }
  124.  
  125.             });
  126.  
  127.         }
  128.     }
  129. })();
  130.  
  131. (function() {
  132.     'use strict';
  133.     angular
  134.         .module('TSLEmployment')
  135.         .directive('saveInfo', saveInfo);
  136.  
  137.     saveInfo.$inject = ['$window', 'GeneralRepo'];
  138.    
  139.     function saveInfo ($window, GeneralRepo) {
  140.         // Usage:
  141.         //     <saveInfo></saveInfo>
  142.         // Creates:
  143.         //
  144.         var directive = {
  145.             link: link,
  146.             restrict: 'A',
  147.             scope: {
  148.                 objectToSave: '='
  149.             },
  150.            
  151.         };
  152.         return directive;
  153.  
  154.         function link(scope, element, attrs) {
  155.             GeneralRepo.addApplicationData(scope.objectToSave);
  156.         }
  157.     }
  158.  
  159. })();
  160.  
  161. // The Useage I want: right now I get this error
  162. // 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">
  163. //
  164.  
  165.  
  166. <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