client/app/slideshow/slideshow_controller.js
author cavaliet
Thu, 02 Oct 2014 13:24:57 +0200
changeset 1 74bbdd739878
parent 0 cef349423167
child 2 36ccc573af9a
permissions -rw-r--r--
views, path, search...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
(function(){
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
  'use strict';
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
  angular.module('ammicoSlideshow',['ngResource', 'ngRoute', 'ui.bootstrap'])
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
    .config(function ($routeProvider) {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
      $routeProvider
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
        .when('/', {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
          templateUrl: 'slideshow/slideshow.html',
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
          controller: 'slideshowCtrl'
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
        });
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    })
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    .service('slideshowApi', function($resource, context) {
1
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    13
      console.log('5',this);
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    14
      this.slideshow = $resource(context.urls.slideshowUrl);
0
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    })
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    .service('slideshowModel', function(slideshowApi, context) {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
      console.log('6',this);
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
      if(typeof context.slideshow === 'undefined') {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
          console.log('6-1');
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
          this.slideshow = slideshowApi.slideshow.get();
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
      }
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
      else {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
          console.log('6-2');
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
          this.slideshow = new slideshowApi.slideshow(context.slideshow);
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
      }
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    })
1
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    27
    .controller('slideshowCtrl', function($scope, $location, $routeParams, slideshowModel){
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    28
      console.log('7',$scope, $location, slideshowModel);
0
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
      $scope.slideshow = slideshowModel.slideshow;
1
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    30
      $scope.iSlide = parseInt($routeParams.iSlide) || 0;
0
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
      $scope.save = function(){
1
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    33
          console.log('8 call save POST',$scope.slideshow);
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    34
          $scope.slideshow
0
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
          .$save()
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
          .then(
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
              function(response) {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
                  console.log('NICE SAVING!', response);
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
              },
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
              function(reason){
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
                  alert('An error occured while saving : ' + reason);
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
              }
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
          );
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
      };
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
    })
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    //.directive('slideEditor', function(context) {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    .directive('slideEditor', function() {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
      return {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
          restrict: 'AE',
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
          replace: true,
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
          scope: false,
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
          templateUrl: 'slideshow/dataEditor.html',
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
          //controller: function($scope, $element, $attrs){
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
          controller: function($scope){
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
              $scope.slidesave = function(){
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
                  if(typeof $scope.slide.tags === 'string'){
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
                      $scope.slide.tags = $scope.slide.tags.split(',');
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
                  }
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
                  for (var i = $scope.slide.tags.length - 1; i >= 0; i--) {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
                      $scope.slide.tags[i] = $scope.slide.tags[i].trim();
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
                  }
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
                  $scope.editMode = false;
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
                  $scope.save();
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
              };
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
          }
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
      };
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
  });
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
})();