client/app/app.js
author rougeronj
Thu, 02 Apr 2015 12:06:51 +0200
changeset 54 ccb586464a6f
parent 52 ce9aefce6e41
child 55 10fd23382e76
permissions -rw-r--r--
clean js and minor update in html and css
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
27
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
     4
  angular.module('ammico', [ 'ngRoute','ammicoHome', 'ammicoBooks', 'ammicoSlides', 'ammicoSlideshow', 'ammicoSearch', 'ammicoAuth', 'templates' ])
0
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
        controller: 'homeCtrl',
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
        templateUrl: 'home/home.html'
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
      }).
27
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    11
      when('/books', {
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    12
          controller: 'booksCtrl',
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    13
          templateUrl: 'books/books.html'
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    14
      }).
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    15
      when('/books/:idBook', {
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    16
        controller: 'bookCtrl',
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    17
        templateUrl: 'books/book.html'
0
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
      }).
47
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 40
diff changeset
    19
      when('/books/:idBook/add/:searched', {
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 40
diff changeset
    20
    	  controller: 'booksCtrl',
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 40
diff changeset
    21
    	  templateUrl: 'books/book.html'
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 40
diff changeset
    22
      }).
32
802ba9793507 add delete request to delete a slide - rename some .ressources fonctions
rougeronj
parents: 27
diff changeset
    23
      when('/slide/:idSlide', {
27
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    24
          controller: 'slidesCtrl',
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    25
          templateUrl: 'slides/slides.html'
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    26
       }).
40
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    27
      when('/slideshow/', {
1
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    28
          controller: 'slideshowCtrl',
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    29
          templateUrl: 'slideshow/slideshow.html'
2
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    30
      }).
4
28208a0ad8b9 edit slide by url
cavaliet
parents: 2
diff changeset
    31
      when('/slideshow/:iSlide', {
2
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    32
          controller: 'slideshowCtrl',
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    33
          templateUrl: 'slideshow/slideshow.html'
4
28208a0ad8b9 edit slide by url
cavaliet
parents: 2
diff changeset
    34
      }).
1
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    35
      when('/search/:q', {
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    36
          controller: 'searchCtrl',
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    37
          templateUrl: 'search/search.html'
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    38
      }).
27
2b508b65571a add routes for books and slides
rougeronj
parents: 14
diff changeset
    39
      when('/login', {
40
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    40
          controller: 'authCtrl',
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    41
          templateUrl: 'auth/auth.html'
13
08f34bbc70ee set up django rest framework
rougeronj
parents: 8
diff changeset
    42
      }).
0
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
      otherwise({
1
74bbdd739878 views, path, search...
cavaliet
parents: 0
diff changeset
    44
        redirectTo: '/'
0
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
    })
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    // .config(function ($routeProvider) {
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
    //   $routeProvider
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    //     .otherwise({
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    //       redirectTo: '/'
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    //   });
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    // });
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    .config(function($logProvider){
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
      $logProvider.debugEnabled(true);
2
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    55
    })
40
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    56
    .service('searchApi', function($resource, context, $sce) {
2
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    57
        this.searchResource = function(params){
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    58
            return $resource(context.urls.searchUrl,  
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    59
                {
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    60
                    callback: 'JSON_CALLBACK'
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    61
                },
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    62
                {
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    63
                    getJsonp: {
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    64
                        method: 'JSONP',
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    65
                        params: params,
8
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    66
                        isArray: false,
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    67
                        transformResponse: function(data){
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    68
                            // Transform meta list into meta dict
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    69
                            var nb = data.hits.length;
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    70
                            for(var i=0;i<nb;i++){
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    71
                                var nb_metas = data.hits[i].metas.length;
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    72
                                data.hits[i].metas_dict = {};
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    73
                                for(var j=0;j<nb_metas;j++){
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    74
                                    if(typeof data.hits[i].metas[j].images==='undefined'){
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    75
                                        data.hits[i].metas_dict[data.hits[i].metas[j].name] = data.hits[i].metas[j].value;
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    76
                                    }
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    77
                                    else{
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    78
                                        data.hits[i].metas_dict.images = data.hits[i].metas[j].images[0].value;
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    79
                                    }
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    80
                                }
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    81
                            }
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    82
                            return data;
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    83
                        }
2
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    84
                    }
8
824c87a9084c (really) better management of slideshowModel with new api.
cavaliet
parents: 4
diff changeset
    85
                });
2
36ccc573af9a clean search resource
cavaliet
parents: 1
diff changeset
    86
        };
47
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 40
diff changeset
    87
        this.listBooks = $resource(context.urls.ammicoUrl+'/books');
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 40
diff changeset
    88
        this.book = $resource(context.urls.ammicoUrl+'/books/:idBook', {idBook:'@idBook'});
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 40
diff changeset
    89
        this.order = $resource(context.urls.ammicoUrl+'/books/:idBook/order', {idBook:'@idBook'});
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 40
diff changeset
    90
        this.booksSlides = $resource(context.urls.ammicoUrl+'/books/:idBook/slides', {idBook:'@idBook'});
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 40
diff changeset
    91
        this.listSlides= $resource(context.urls.ammicoUrl+'/slides');
dd750778535c udate add fonction from a research and add a modal to select the book we want to add the slide
rougeronj
parents: 40
diff changeset
    92
        this.slide = $resource(context.urls.ammicoUrl+'/slides/:idSlide', {idSlide:'@idSlide'});
40
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    93
        this.sanitizeUrls = function(data){
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    94
        	data.details.audio = $sce.trustAsResourceUrl(data.details.audio);
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    95
        	data.details.video = $sce.trustAsResourceUrl(data.details.video);
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    96
        	data.audio = $sce.trustAsResourceUrl(data.audio);
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    97
        	data.video = $sce.trustAsResourceUrl(data.video);
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    98
        	return data;
4b3bebe4355d add sanitize function to accept url from the request response - enable edit on dbclick - improve html
rougeronj
parents: 32
diff changeset
    99
        };
52
ce9aefce6e41 add auth Service with API authentication url
rougeronj
parents: 47
diff changeset
   100
    })
ce9aefce6e41 add auth Service with API authentication url
rougeronj
parents: 47
diff changeset
   101
  .service('authApi', function($resource, context) {
ce9aefce6e41 add auth Service with API authentication url
rougeronj
parents: 47
diff changeset
   102
	  this.login = $resource(context.urls.ammicoUrl+'/auth/api-token-auth');
ce9aefce6e41 add auth Service with API authentication url
rougeronj
parents: 47
diff changeset
   103
	  this.logout = $resource(context.urls.ammicoUrl+'/auth/logout');
ce9aefce6e41 add auth Service with API authentication url
rougeronj
parents: 47
diff changeset
   104
	  this.user = $resource(context.urls.ammicoUrl+'/auth/user');
ce9aefce6e41 add auth Service with API authentication url
rougeronj
parents: 47
diff changeset
   105
	  this.test = $resource(context.urls.ammicoUrl+'/auth/auth');
ce9aefce6e41 add auth Service with API authentication url
rougeronj
parents: 47
diff changeset
   106
  });
0
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
cef349423167 add basic file org + client prototype
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
})();