"use strict"; angular.module('raz') .component('resourceList', { templateUrl: '/js/angular/book-grid/resource-list.html', controller: 'ResourceList', bindings: { initialData: '@', type: '@', classicBookTitle : '@', languageId :'@', sortingMap :'@', filters :'@', limitRange :'@', levelId :'@', id: '@' } }) .controller('ResourceList', ['$http', 'messageHandler','ResourceList', function ResourceListCtrl($http, messageHandler,ResourceList) { var ctrl = this; ctrl.resources = null; ctrl.pending = true; ctrl.$onInit = function () { if (ctrl.initialData != undefined) { try { ctrl.resources = JSON.parse(atob(ctrl.initialData)); } catch (err) { ctrl.resources = null; console.log(err); } } if (ctrl.resources == null) { var config = { classicBookTitle: ctrl.classicBookTitle, type: ctrl.type, languageId: ctrl.languageId, sortingMap: ctrl.sortingMap, filters: ctrl.filters, limitRange: ctrl.limitRange, levelId: ctrl.levelId }; ResourceList.getResources(config) .then( function(response) { ctrl.resources = response.data; ctrl.pending = false; }) .catch( function ( reason){ console.log(reason); ctrl.pending = false; messageHandler.publishError("There was a problem processing your request"); }); } else { ctrl.pending = false; } }; ctrl.$postLink = function () { var element = $j('#' + ctrl.id); if (element.length > 0) { element.removeAttr('initial-data'); } }; ctrl.isLastItem = function(index) { return ctrl.resources != null && index == ctrl.resources.length - 1; } }]);