all files / components/taxonomy/ taxonomy.controller.js

3.33% Statements 1/30
0% Branches 0/10
0% Functions 0/6
3.33% Lines 1/30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                                                                                                                                
angular.module('webmapp')
 
    .controller('TaxonomyController', function TaxonomyController(
        $rootScope,
        $scope,
        $state,
        $translate,
        CONFIG,
        PackageService,
        Utils
    ) {
        var vm = {};
 
        var registeredEvents = [];
 
        vm.title = CONFIG.OPTIONS.title;
        vm.currentLang = $translate.preferredLanguage() ? $translate.preferredLanguage() : "it";
        vm.defaultLang = CONFIG.LANGUAGES && CONFIG.LANGUAGES.actual ? CONFIG.LANGUAGES.actual : 'it';
        vm.taxonomy = {};
        vm.loading = true;
        vm.firstLoading = true;
 
        vm.goTo = function (id) {
            Utils.goTo('taxonomy/' + $state.params.id + '/' + id);
        };
 
        vm.doRefresh = function (refresher) {
            vm.firstLoading = false;
            vm.loading = true;
            PackageService.getTaxonomy($state.params.id, true);
        };
 
        registeredEvents.push(
            $rootScope.$on('taxonomy-' + $state.params.id + '-updated', function (e, value) {
                vm.taxonomy = value.taxonomy;
                if (vm.loading !== value.loading) {
                    vm.loading = value.loading;
                }
                if (!vm.loading) {
                    $scope.$broadcast('scroll.refreshComplete');
                    vm.firstLoading = false;
                }
 
                Utils.forceDigest();
            })
        );
 
        registeredEvents.push(
            $scope.$on('$ionicView.enter', function () {
                PackageService.getTaxonomy($state.params.id);
            })
        );
 
        registeredEvents.push(
            $scope.$on('$ionicView.beforeLeave', function () {
                for (var i in registeredEvents) {
                    registeredEvents[i]();
                }
                delete registeredEvents;
            })
        );
 
 
        return vm;
    });