client/app/slideshow/slideshow_controller.js
changeset 0 cef349423167
child 1 74bbdd739878
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/app/slideshow/slideshow_controller.js	Wed Jun 11 01:26:59 2014 +0200
@@ -0,0 +1,76 @@
+(function(){
+  'use strict';
+
+  angular.module('ammicoSlideshow',['ngResource', 'ngRoute', 'ui.bootstrap'])
+    .config(function ($routeProvider) {
+      $routeProvider
+        .when('/', {
+          templateUrl: 'slideshow/slideshow.html',
+          controller: 'slideshowCtrl'
+        });
+    })
+    .service('slideshowApi', function($resource, context) {
+      this.slideshow = $resource(context.urls.slideshowUrl,
+        {
+          get: {
+            method: 'GET',
+            isArray: false
+          },
+          save:{
+            method:'PUT',
+            isArray:false//, headers:{'X-CSRFToken':context.csrf_token}
+          }
+        });
+    })
+    .service('slideshowModel', function(slideshowApi, context) {
+      console.log('6',this);
+      if(typeof context.slideshow === 'undefined') {
+          console.log('6-1');
+          this.slideshow = slideshowApi.slideshow.get();
+      }
+      else {
+          console.log('6-2');
+          this.slideshow = new slideshowApi.slideshow(context.slideshow);
+      }
+    })
+    .controller('slideshowCtrl', function($scope, $location, slideshowModel){
+      console.log('6',$scope, $location, slideshowModel);
+      $scope.slideshow = slideshowModel.slideshow;
+
+      $scope.save = function(){
+        $scope.slideshow
+          .$save()
+          .then(
+              function(response) {
+                  console.log('NICE SAVING!', response);
+              },
+              function(reason){
+                  alert('An error occured while saving : ' + reason);
+              }
+          );
+      };
+    })
+    //.directive('slideEditor', function(context) {
+    .directive('slideEditor', function() {
+      return {
+          restrict: 'AE',
+          replace: true,
+          scope: false,
+          templateUrl: 'slideshow/dataEditor.html',
+          //controller: function($scope, $element, $attrs){
+          controller: function($scope){
+              $scope.slidesave = function(){
+                  if(typeof $scope.slide.tags === 'string'){
+                      $scope.slide.tags = $scope.slide.tags.split(',');
+                  }
+                  for (var i = $scope.slide.tags.length - 1; i >= 0; i--) {
+                      $scope.slide.tags[i] = $scope.slide.tags[i].trim();
+                  }
+                  $scope.editMode = false;
+                  $scope.save();
+              };
+          }
+      };
+  });
+
+})();