diff --git a/app/js/app.js b/app/js/app.js index 04e449a6..bfa1c99e 100755 --- a/app/js/app.js +++ b/app/js/app.js @@ -33,6 +33,8 @@ function($rootScope, $location, $window, $doc, $state, CArr, shipPurpose, sz, hp $rootScope.SZ = sz; $rootScope.HPC = hpc; $rootScope.GMAP = GroupMap; + $rootScope.insurance = { opts: [{ name: 'Standard', pct: 0.05 }, { name: 'Alpha', pct: 0.025 }, { name: 'Beta', pct: 0.035 }] }; + $rootScope.discounts = { opts: [{ name: 'None', pct: 1 }, { name: 'Founders World - 10%', pct: 0.90 }] }; $rootScope.STATUS = ['', 'DISABLED', 'OFF', 'ON']; $rootScope.STATUS_CLASS = ['', 'disabled', 'warning', 'secondary-disabled']; $rootScope.title = 'Coriolis'; diff --git a/app/js/directives/directive-header.js b/app/js/directives/directive-header.js index c6beeebe..0925089a 100755 --- a/app/js/directives/directive-header.js +++ b/app/js/directives/directive-header.js @@ -12,17 +12,9 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers scope.allComparisons = Persist.comparisons; scope.bs = Persist.state; - // Insurance options and management here for now. - $rootScope.insurance = { - opts: [ - { name: 'Standard', pct: 0.05 }, - { name: 'Alpha', pct: 0.025 }, - { name: 'Beta', pct: 0.035 } - ] - }; - var insIndex = _.findIndex($rootScope.insurance.opts, 'name', Persist.getInsurance()); $rootScope.insurance.current = $rootScope.insurance.opts[insIndex != -1 ? insIndex : 0]; + $rootScope.discounts.current = $rootScope.discounts.opts[Persist.getDiscount() || 0]; // Close menus if a navigation change event occurs $rootScope.$on('$stateChangeStart', function() { @@ -42,6 +34,13 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers Persist.setInsurance($rootScope.insurance.current.name); }; + /** + * Save selected discount option + */ + scope.updateDiscount = function() { + Persist.setDiscount($rootScope.discounts.opts.indexOf($rootScope.discounts.current)); + }; + scope.openMenu = function(e, menu) { e.stopPropagation(); if (menu == scope.openedMenu) { diff --git a/app/js/service-persist.js b/app/js/service-persist.js index bf7c9e30..6e065377 100755 --- a/app/js/service-persist.js +++ b/app/js/service-persist.js @@ -183,6 +183,27 @@ angular.module('app').service('Persist', ['$window', 'lodash', function($window, } }; + /** + * Persist selected discount + * @param {number} val Discount value/amount + */ + this.setDiscount = function(val) { + if (this.lsEnabled) { + return localStorage.setItem('discount', val); + } + }; + + /** + * Get the saved discount + * @return {number} val Discount value/amount + */ + this.getDiscount = function() { + if (this.lsEnabled) { + return localStorage.getItem('discount'); + } + return null; + }; + /** * Retrieve the last router state from local storage * @param {object} state State object containing state name and params diff --git a/app/views/_header.html b/app/views/_header.html index b7580acc..ce8d926f 100755 --- a/app/views/_header.html +++ b/app/views/_header.html @@ -51,6 +51,10 @@
+