Adding founders world discount

This commit is contained in:
Colin McLeod
2015-06-12 23:40:32 -07:00
parent 0d09607d30
commit 5649dc9079
5 changed files with 41 additions and 15 deletions

View File

@@ -33,6 +33,8 @@ function($rootScope, $location, $window, $doc, $state, CArr, shipPurpose, sz, hp
$rootScope.SZ = sz; $rootScope.SZ = sz;
$rootScope.HPC = hpc; $rootScope.HPC = hpc;
$rootScope.GMAP = GroupMap; $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 = ['', 'DISABLED', 'OFF', 'ON'];
$rootScope.STATUS_CLASS = ['', 'disabled', 'warning', 'secondary-disabled']; $rootScope.STATUS_CLASS = ['', 'disabled', 'warning', 'secondary-disabled'];
$rootScope.title = 'Coriolis'; $rootScope.title = 'Coriolis';

View File

@@ -12,17 +12,9 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
scope.allComparisons = Persist.comparisons; scope.allComparisons = Persist.comparisons;
scope.bs = Persist.state; 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()); var insIndex = _.findIndex($rootScope.insurance.opts, 'name', Persist.getInsurance());
$rootScope.insurance.current = $rootScope.insurance.opts[insIndex != -1 ? insIndex : 0]; $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 // Close menus if a navigation change event occurs
$rootScope.$on('$stateChangeStart', function() { $rootScope.$on('$stateChangeStart', function() {
@@ -42,6 +34,13 @@ angular.module('app').directive('shipyardHeader', ['lodash', '$rootScope', 'Pers
Persist.setInsurance($rootScope.insurance.current.name); 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) { scope.openMenu = function(e, menu) {
e.stopPropagation(); e.stopPropagation();
if (menu == scope.openedMenu) { if (menu == scope.openedMenu) {

View File

@@ -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 * Retrieve the last router state from local storage
* @param {object} state State object containing state name and params * @param {object} state State object containing state name and params

View File

@@ -51,6 +51,10 @@
<ul> <ul>
Insurance Insurance
<li><select ng-model="insurance.current" ng-options="ins.name for (i,ins) in insurance.opts" ng-change="updateInsurance()"></select></li> <li><select ng-model="insurance.current" ng-options="ins.name for (i,ins) in insurance.opts" ng-change="updateInsurance()"></select></li>
</ul><br>
<ul>
Discount
<li><select ng-model="discounts.current" ng-options="d.name for (i,d) in discounts.opts" ng-change="updateDiscount()"></select></li>
</ul> </ul>
<hr /> <hr />
<ul> <ul>

View File

@@ -242,21 +242,21 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr class="toggleable" ng-repeat="c in costList | orderBy:costPredicate:costDesc" ng-if="c.c.cost > 0" ng-class="{disabled:!c.incCost}" ng-click="toggleCost(c)"> <tr ng-repeat="c in costList | orderBy:costPredicate:costDesc" ng-if="c.c.cost > 0" ng-class="{disabled:!c.incCost}">
<td style="width:1em;">{{c.c.class}}{{c.c.rating}}</td> <td class="toggleable" style="width:1em;" ng-click="toggleCost(c)">{{c.c.class}}{{c.c.rating}}</td>
<td class="le shorten" ng-bind="cName(c)"></td> <td class="le toggleable shorten" ng-bind="cName(c)" ng-click="toggleCost(c)"></td>
<td class="ri">{{fCrd(c.c.cost)}} <u>CR</u></td> <td class="ri toggleable" ng-click="toggleCost(c)">{{fCrd(discounts.current.pct * c.c.cost)}} <u>CR</u></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<table class="total"> <table class="total">
<tr class="ri"> <tr class="ri">
<td class="lbl">Total</td> <td class="lbl">Total</td>
<td>{{fCrd(ship.totalCost)}} <u>CR</u></td> <td>{{fCrd(ship.totalCost * discounts.current.pct)}} <u>CR</u></td>
</tr> </tr>
<tr class="ri"> <tr class="ri">
<td class="lbl">Insurance</td> <td class="lbl">Insurance</td>
<td>{{fCrd(ship.totalCost * insurance.current.pct)}} <u>CR</u></td> <td>{{fCrd(ship.totalCost * discounts.current.pct * insurance.current.pct)}} <u>CR</u></td>
</tr> </tr>
</table> </table>
</div> </div>