Merge: Reworked crypto.nit to introduce basic XOR attacks
[nit.git] / lib / popcorn / examples / angular / www / javascripts / ng-example.js
1 /*
2 * Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 (function() {
18 angular
19
20 .module('ng-example', ['ngRoute'])
21
22 .factory('CounterModel', ['$http', function($http) {
23 return {
24 load: function(cb, cbErr) {
25 $http.get('/counter')
26 .success(cb)
27 .error(cbErr);
28 },
29 increment: function(cb, cbErr) {
30 $http.post('/counter')
31 .success(cb)
32 .error(cbErr);
33 }
34 };
35 }])
36
37 .controller('CounterCtrl', ['CounterModel', function(CounterModel) {
38 var $this = this;
39
40 this.loadCounter = function() {
41 CounterModel.load(
42 function(data) {
43 $this.counter = data;
44 }, function(err) {
45 $this.error = err;
46 });
47 };
48
49 this.incrementCounter = function() {
50 CounterModel.increment(
51 function(data) {
52 $this.counter = data;
53 }, function(err) {
54 $this.error = err;
55 });
56 };
57
58 this.loadCounter();
59 }])
60
61 .config(function($routeProvider, $locationProvider) {
62 $routeProvider
63 .when('/', {
64 templateUrl: 'views/index.html',
65 controller: 'CounterCtrl',
66 controllerAs: 'counterCtrl'
67 })
68 .otherwise({
69 redirectTo: '/'
70 });
71 $locationProvider.html5Mode(true);
72 });
73 })();