Skip to content

Commit

Permalink
Added cookie support
Browse files Browse the repository at this point in the history
  • Loading branch information
mycaule committed Jan 1, 2015
1 parent f1173b5 commit 29afcd8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<title>{{ 'TITLE' | translate }}</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.28/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bower-angular-translate/2.5.2/angular-translate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.28/angular-cookies.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.4.0/MathJax.js?config=TeX-AMS_HTML">
</script>
</head>
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
"karma": "~0.12.28",
"karma-jasmine": "~0.3.2",
"karma-phantomjs-launcher": "~0.1.4",
"protractor": "~1.5.0",
"http-server": "~0.7.4",
"jasmine-core": "~2.1.3",
"angular": "~1.2.28",
"angular-mocks": "~1.2.28",
"angular-translate": "~2.5.2"
"angular-translate": "~2.5.2",
"angular-cookies": "~1.2.28",
"lodash": "~2.4.1"
}
}
16 changes: 13 additions & 3 deletions salaryController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
'use strict';

var app = angular.module('calculator', ['pascalprecht.translate']);
var lodash = angular.module('lodash', []);
lodash.factory('_', function() {
return window._;
})

var app = angular.module('calculator', ['pascalprecht.translate', 'ngCookies', 'lodash']);

app.config(function($translateProvider) {
$translateProvider
Expand Down Expand Up @@ -71,7 +76,9 @@ function getGNFactor(rate) {
return 1-rate/100;
}

function salaryController($translate, $scope) {
function salaryController($translate, $cookies, $scope, _) {
$scope.favCountry = $cookies.favCountry;

// Default values
$scope.mg = 2500; // Gross Monthly Salary
$scope.hw = 35; // Number of hours worked by week
Expand All @@ -82,8 +89,10 @@ function salaryController($translate, $scope) {
{ label: 'USA', value: 'en-US'},
{ label: 'France', value: 'fr-FR'}
];
var defCountry = _.find($scope.countries, {value: $cookies.favCountry});

$scope.country = $scope.countries[0];
$scope.country = defCountry ? defCountry : $scope.countries[0];
$translate.use($scope.country.value);

$scope.withExplain = false;

Expand Down Expand Up @@ -146,6 +155,7 @@ function salaryController($translate, $scope) {
};

$scope.setLang = function() {
$cookies.favCountry = $scope.country.value;
$translate.use($scope.country.value);
};
}
2 changes: 2 additions & 0 deletions test/karma-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module.exports = function(config) {
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'node_modules/angular-translate/dist/angular-translate.js',
'node_modules/angular-cookies/angular-cookies.js',
'node_modules/lodash/dist/lodash.js',
'salaryController.js',
'test/spec.js'
],
Expand Down

0 comments on commit 29afcd8

Please sign in to comment.