seblucas/cops-html-ui

View on GitHub
app/book/book-list.controller.js

Summary

Maintainability
B
4 hrs
Test Coverage
'use strict';

angular.module('Cops.book')
  .config(function (LightboxProvider) {
    // set a custom template
    LightboxProvider.templateUrl = 'book/lightbox.html';
    LightboxProvider.fullScreenMode = true;
  })
  .controller('bookListController', ['$scope',
                                           'Lightbox',
                                           '$stateParams',
                                           'Restangular',
                                           'bookListHelperServices',
                                           'controllerHelperServices', function($scope, Lightbox, $stateParams, Restangular, bookListHelperServices, controllerHelperServices) {
    $scope.books = [];
    $scope.defaultTemplate = 'th';
    $scope.bookListHelper = bookListHelperServices;

    $scope.pageChanged = function() {
      controllerHelperServices.setPageSizeValue(true, $scope.itemsPerPage).then(function() {});
      bookListHelperServices.loadPage(Restangular.one('databases', $stateParams.db), $scope)
                            .then(function(list) {
        $scope.covers = bookListHelperServices.getCovers(list);
        $scope.books = list;
      });
    };

    $scope.gridListChange = function(newValue) {
      controllerHelperServices.setTemplateValue(true, newValue);
    };

    $scope.openLightboxModal = function (index) {
      Lightbox.openModal($scope.covers, index);
    };

    controllerHelperServices.initControllerWithPaging(true)
                            .then(function(paging) {
      $scope.itemsPerPage = paging.itemsPerPage;
      $scope.itemsPerPageList = paging.itemsPerPageList;
      $scope.maxSize = paging.maxSize;
      $scope.currentPage = paging.currentPage;
      $scope.defaultTemplate = paging.currentTemplate;
      $scope.preferedFormats = paging.preferedFormats;

      $scope.pageChanged ();
    });
  }]);