client/app/components/app_service.js
changeset 146 c6fa8ee3f562
parent 106 cb13a9009bf5
child 172 ffdfe491869c
--- a/client/app/components/app_service.js	Tue Jun 09 19:09:29 2015 +0200
+++ b/client/app/components/app_service.js	Tue Jun 09 19:10:45 2015 +0200
@@ -4,11 +4,11 @@
     
     angular.module('ammicoCommon', ['ngRoute'])
     .factory('Book', function($resource, context) {
-        var books = $resource(context.urls.ammicoUrl+'/books/:idBook', {idBook:'@id'}, {update: { method: 'PUT'}});
+        var books = $resource(context.urls.ammicoUrl+'books/:idBook', {idBook:'@id', idExpo: context.idExpo}, {update: { method: 'PUT'}});
         return books;
     })
-    .factory('Slide', function($resource, context) {
-        var slides = $resource(context.urls.ammicoUrl+'/slides/:idSlide', {idSlide:'@id'}, {update: { method: 'PUT'}});
+    .factory('Slide', function($resource, context, $modal) {
+        var slides = $resource(context.urls.ammicoUrl+'slides/:idSlide', {idSlide:'@id'}, {update: { method: 'PUT'}});
         
         angular.extend(slides.prototype, {
 
@@ -16,6 +16,24 @@
                 this.favorite = !this.favorite;
                 this.$update();
             },
+            addToBook: function () {
+                var _this = this;
+                var modalInstance = $modal.open({
+                    templateUrl: 'books/add_book_modal.html',
+                    controller: 'ModalAddBookCtrl',
+                    size: 'sm'
+                });
+
+                modalInstance.result.then(function (idBook) {
+                    var newSlide = _this;
+                    newSlide.book = idBook;
+                    delete newSlide["id"];
+                    slides.save(newSlide);
+                });
+            },
+            update: function(){
+                console.log('test');
+            },
             remove: function (array) {
                 var _this = this;
                 if(window.confirm('Êtes-vous sûr(e) de vouloir effacer cet élément ? Cette action est irrémédiable.')){
@@ -23,6 +41,7 @@
                         if (array){
                             array.splice(array.indexOf(_this), 1);
                         }
+                        //$scope.$emit("slideDeleted", array);
                     },
                     function(error) {
                         if (error.status === 404 && array){
@@ -36,7 +55,7 @@
         return slides;
     })
     .factory('Order', function($resource, context) {
-        return $resource(context.urls.ammicoUrl+'/books/:idBook/order', {idBook:'@id'});
+        return $resource(context.urls.ammicoUrl+'books/:idBook/order', {idBook:'@id'});
     })
     .service('Utils', function($resource, context, $sce) {
         this.sanitizeUrls = function(data){
@@ -48,10 +67,10 @@
         };
     })
     .service('authApi', function($resource, context) {
-        this.login = $resource(context.urls.ammicoUrl+'/auth/api-token-auth');
-        this.logout = $resource(context.urls.ammicoUrl+'/auth/logout');
-        this.user = $resource(context.urls.ammicoUrl+'/auth/user');
-        this.test = $resource(context.urls.ammicoUrl+'/auth/auth');
+        this.login = $resource(context.urls.ammicoUrl+'auth/api-token-auth', {idExpo: context.idExpo});
+        this.logout = $resource(context.urls.ammicoUrl+'auth/logout');
+        this.user = $resource(context.urls.ammicoUrl+'auth/user');
+        this.test = $resource(context.urls.ammicoUrl+'auth/auth');
     })
     .service('searchApi', function($resource, context) {
         this.searchResource = function(params){