| author | rougeronj |
| Thu, 04 Jun 2015 20:03:04 +0200 | |
| changeset 108 | 4a152f5f4a09 |
| parent 99 | c7c424e9eed5 |
| child 146 | c6fa8ee3f562 |
| permissions | -rw-r--r-- |
| 91 | 1 |
(function(){ |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
2 |
'use strict'; |
| 91 | 3 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
4 |
angular.module('ammicoMyvisit',['ngRoute', 'ui.sortable']) |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
5 |
.controller('my_visitCtrl', function($scope, $location, $modal, Book, Slide){ |
| 91 | 6 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
7 |
//get list book |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
8 |
$scope.books = Book.query({format:'json'}, function(data){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
9 |
data.sort(function (a, b) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
10 |
return a.date < b.date; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
11 |
}); |
| 91 | 12 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
13 |
for (var i = 0; i < data.length; i++) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
14 |
if (data[i].idArticle){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
15 |
data[i].slides = Slide.query({idBook:data[i].id, format:'json'}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
16 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
17 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
18 |
}); |
| 91 | 19 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
20 |
$scope.addBook = function (idParent) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
21 |
$modal.open({ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
22 |
templateUrl: 'my_visit/add_modal_my_visit.html', |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
23 |
controller: 'ModalAddMyvisitCtrl' |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
24 |
}).result.then(function (title) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
25 |
//add book with the title written in the modal |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
26 |
Book.save({idParent:idParent, title: title}, function(newBook){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
27 |
$scope.books.push(newBook); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
28 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
29 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
30 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
31 |
}) |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
32 |
.controller('ModalAddMyvisitCtrl', function ($scope, $modalInstance) { |
| 91 | 33 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
34 |
$scope.add = function(){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
35 |
$modalInstance.close($scope.title); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
36 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
37 |
$scope.cancel = function () { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
38 |
$modalInstance.dismiss('cancel'); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
39 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
40 |
$scope.share = function () { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
41 |
$modalInstance($scope.book); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
42 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
91
diff
changeset
|
43 |
}); |
| 91 | 44 |
})(); |
45 |