| author | nowmad@23.1.168.192.in-addr.arpa |
| Wed, 02 Dec 2015 18:07:42 +0100 | |
| changeset 197 | 8b87432acffc |
| parent 184 | 4d01c2d04359 |
| permissions | -rw-r--r-- |
|
93
4b167851ee7d
Starting a better management of the 'models' and the requests
rougeronj
parents:
0
diff
changeset
|
1 |
|
|
4b167851ee7d
Starting a better management of the 'models' and the requests
rougeronj
parents:
0
diff
changeset
|
2 |
(function(){ |
|
4b167851ee7d
Starting a better management of the 'models' and the requests
rougeronj
parents:
0
diff
changeset
|
3 |
'use strict'; |
|
197
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
4 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
5 |
angular.module('ammicoCommon', ['ngRoute']) |
|
93
4b167851ee7d
Starting a better management of the 'models' and the requests
rougeronj
parents:
0
diff
changeset
|
6 |
.factory('Book', function($resource, context) { |
|
146
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
7 |
var books = $resource(context.urls.ammicoUrl+'books/:idBook', {idBook:'@id', idExpo: context.idExpo}, {update: { method: 'PUT'}}); |
|
93
4b167851ee7d
Starting a better management of the 'models' and the requests
rougeronj
parents:
0
diff
changeset
|
8 |
return books; |
|
4b167851ee7d
Starting a better management of the 'models' and the requests
rougeronj
parents:
0
diff
changeset
|
9 |
}) |
|
146
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
10 |
.factory('Slide', function($resource, context, $modal) { |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
11 |
var slides = $resource(context.urls.ammicoUrl+'slides/:idSlide', {idSlide:'@id'}, {update: { method: 'PUT'}}); |
|
197
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
12 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
13 |
angular.extend(slides.prototype, { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
14 |
|
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
15 |
toggleFavorite: function () { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
16 |
this.favorite = !this.favorite; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
17 |
this.$update(); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
18 |
}, |
|
146
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
19 |
addToBook: function () { |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
20 |
var _this = this; |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
21 |
var modalInstance = $modal.open({ |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
22 |
templateUrl: 'books/add_book_modal.html', |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
23 |
controller: 'ModalAddBookCtrl', |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
24 |
size: 'sm' |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
25 |
}); |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
26 |
|
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
27 |
modalInstance.result.then(function (idBook) { |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
28 |
var newSlide = _this; |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
29 |
newSlide.book = idBook; |
| 172 | 30 |
delete newSlide.id; |
|
146
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
31 |
slides.save(newSlide); |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
32 |
}); |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
33 |
}, |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
34 |
update: function(){ |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
35 |
console.log('test'); |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
36 |
}, |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
37 |
remove: function (array) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
38 |
var _this = this; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
39 |
if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
40 |
this.$delete(function(){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
41 |
if (array){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
42 |
array.splice(array.indexOf(_this), 1); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
43 |
} |
| 172 | 44 |
//$scope.$emit('slideDeleted', array); |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
45 |
}, |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
46 |
function(error) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
47 |
if (error.status === 404 && array){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
48 |
array.splice(array.indexOf(_this), 1); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
49 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
50 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
51 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
52 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
53 |
}); |
|
197
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
54 |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
55 |
return slides; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
56 |
}) |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
57 |
.factory('Order', function($resource, context) { |
|
146
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
58 |
return $resource(context.urls.ammicoUrl+'books/:idBook/order', {idBook:'@id'}); |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
59 |
}) |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
60 |
.service('Utils', function($resource, context, $sce) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
61 |
this.sanitizeUrls = function(data){ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
62 |
data.details.audio = $sce.trustAsResourceUrl(data.details.audio); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
63 |
data.details.video = $sce.trustAsResourceUrl(data.details.video); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
64 |
data.audio = $sce.trustAsResourceUrl(data.audio); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
65 |
data.video = $sce.trustAsResourceUrl(data.video); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
66 |
return data; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
67 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
68 |
}) |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
69 |
.service('authApi', function($resource, context) { |
|
146
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
70 |
this.login = $resource(context.urls.ammicoUrl+'auth/api-token-auth', {idExpo: context.idExpo}); |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
71 |
this.logout = $resource(context.urls.ammicoUrl+'auth/logout'); |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
72 |
this.user = $resource(context.urls.ammicoUrl+'auth/user'); |
|
c6fa8ee3f562
refactor idArticle to id_article and idInventory to id_inventory
rougeronj
parents:
106
diff
changeset
|
73 |
this.test = $resource(context.urls.ammicoUrl+'auth/auth'); |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
74 |
}) |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
75 |
.service('searchApi', function($resource, context) { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
76 |
this.searchResource = function(params){ |
|
197
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
77 |
return $resource(context.urls.searchUrl, |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
78 |
{ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
79 |
callback: 'JSON_CALLBACK' |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
80 |
}, |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
81 |
{ |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
82 |
getJsonp: { |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
83 |
method: 'JSONP', |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
84 |
params: params, |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
85 |
isArray: false, |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
86 |
transformResponse: function(data){ |
|
197
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
87 |
if (data.success){ |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
88 |
data = data.response[0]; |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
89 |
for (var i=0; i<data.count; i++){ |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
90 |
data.collect[i].name = data.collect[i].name || data.collect[i].title_stop || ''; |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
91 |
data.collect[i].description = data.collect[i].description_record || data.collect[i].description_stop || ''; |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
92 |
data.collect[i].url = data.collect[i].url_cnhi || ''; |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
93 |
data.collect[i].date = data.collect[i].displaydates || ''; |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
94 |
data.collect[i].id_stop = data.collect[i].id_stop || ''; |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
95 |
data.collect[i].inventorynumber = data.collect[i].inventorynumber || ''; |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
96 |
data.collect[i].tags = data.collect[i].tags_stop || []; |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
97 |
data.collect[i].images = data.collect[i].images || []; |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
98 |
} |
|
197
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
99 |
} |
|
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
100 |
return data; |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
101 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
102 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
103 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
104 |
}; |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
105 |
}) |
| 172 | 106 |
.directive('imgType', function(){ |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
107 |
return { |
| 172 | 108 |
restrict: 'AE', |
109 |
link: function(scope, elem) { |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
110 |
elem.bind('error', function() { |
| 178 | 111 |
elem.parent().addClass('no-img'); |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
112 |
elem.remove(); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
113 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
114 |
elem.on('load', function() { |
| 172 | 115 |
var w = elem.width(), |
116 |
h = elem.height(); |
|
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
117 |
if (w > h){ |
| 172 | 118 |
elem.addClass('img-landscape'); |
|
99
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
119 |
} |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
120 |
}); |
|
c7c424e9eed5
refactor the ammicoApi service and put it into a specific module (ammicoCommon). Use factory to serve the resources
rougeronj
parents:
93
diff
changeset
|
121 |
} |
| 172 | 122 |
}; |
|
93
4b167851ee7d
Starting a better management of the 'models' and the requests
rougeronj
parents:
0
diff
changeset
|
123 |
}); |
|
197
8b87432acffc
Update search to match the new response from exalead
nowmad@23.1.168.192.in-addr.arpa
parents:
184
diff
changeset
|
124 |
|
|
93
4b167851ee7d
Starting a better management of the 'models' and the requests
rougeronj
parents:
0
diff
changeset
|
125 |
})(); |