'use strict';

var SettingsCtrl = ['$scope', '$http', 'lockDate', function ($scope, $http, lockDate) {
    $scope.lockDate = lockDate.data['Lock Date'];
    $scope.setLockDate = function () {
        $http({method: 'POST', url: '/api/LockDate', params: {Date: $scope.lockDate}}).
            success(function (data) {
                $scope.lockDate = data['Lock Date'];
                $scope.toasts.push({Type: 'Success', Message: ''});
            }).
            error(function (errorMessage) {
                $scope.toasts.push({Type: 'Error', Message: errorMessage});
            });
    };
    $scope.clearLockDate = function () {
        $http({method: 'POST', url: '/api/LockDate', params: {Clear: ''}}).
            success(function (data) {
                $scope.lockDate = data['Lock Date'];
                $scope.toasts.push({Type: 'Success', Message: ''});
            }).
            error(function (errorMessage) {
                $scope.toasts.push({Type: 'Error', Message: errorMessage});
            });
    };
}]

SettingsCtrl.resolve = {
    lockDate: ['$http', function ($http) {
        return $http.get('/api/LockDate', {});
    }]
};

