'use strict';
/** 
 * @controller ClassificationEditController
 * @property scope 
 * @property route
 * @property location
 * @property System
 * @property ClassificationService
 */
var ClassificationEditController = angular.module('classifications.controllers.edit', [
    'system'
])
    .controller('ClassificationEditController', [
        '$scope',
        '$route',
        '$location',
        'System',
        'ClassificationService',
        function($scope, $route, $location, System, ClassificationService) {

            $scope.Id = $route.current.params["id"];
            $scope.classification = {};
            
            $(".tooltip").tooltip();

            /**
            * @method get
            * @param Id
            * @description ClassificationService gets Classification data by its id
            */
            ClassificationService.getEdit($scope.Id)
                .then(function (data) {
                    $scope.classification = data;
                });

            /**
            * @method update
            * @description ClassificationService updates Classification data after successful edit
            * 
            */
            $scope.update = function () {
                ClassificationService.update($scope.classification)
                    .then(function (response) {
                        if (response.Errors) {
                            $scope.errors = response.Errors;
                            System.Message.error($scope.$resource('utility.changeNotSave'));
                        } else {
                            $location.url('/classifications');
                            System.Message.success($scope.$resource('classifications.ClassUpdated'));
                        }
                        
                    });
            };
            
            /**
            * @action back returns to location /classifications
            */
            $scope.back = function () {
                $location.url('/classifications');
            };
        }
    ]);