'use strict';

var ClassificationMainController =  angular.module('classifications.controllers.main', [
    'system'
])
    .controller('ClassificationMainController', [
        '$scope',
        '$route',
        '$window',
        '$location',
        'System',
        'ClassificationService',
        function($scope, $route, $window, $location, System, ClassificationService) {
            $scope.query = $route.current.params || { };
            $scope.newClassification = { ClassificationType: 0 };       
            $(".tooltip").tooltip();

          
            $scope.refresh = function () {
                ClassificationService.query($scope.query).then(function(data) {
                    $scope.classifications = data.classifications;
                });
            };
              
            $scope.reset = function () {
                $location.search(($scope.query = {}));
                $scope.refresh();
            };
            
            $scope.search = function (q, reset) {
                reset ? $scope.query = q : angular.extend($scope.query, q);
                $location.search($scope.query);
                $scope.refresh();
            };
            
            $scope.isSearch = function () {
                return Object.keys($scope.query).length !== 0;
            };


            $scope.select = function(classification) {
                $location.url('/classifications/' + classification.Alias);
            };


            $scope.refresh();
        }
    ]);