'use strict';

var DaybookCtrl = ['$scope', '$location', 'dateFilter', 'info', function ($scope, $location, dateFilter, info) {
    $scope.info = info;
    $scope.show = function () {
        if (angular.isDate($scope.info.StartDate)) {
            $scope.info.StartDate = dateFilter($scope.info.StartDate, 'dd-MMM-yyyy');
        }
        if (angular.isDate($scope.info.FinishDate)) {
            $scope.info.FinishDate = dateFilter($scope.info.FinishDate, 'dd-MMM-yyyy');
        }
        $location.path('/Daybook').search({StartDate:$scope.info.StartDate, FinishDate:$scope.info.FinishDate});
    };
    $('#txtStartDate').focus();
}];
DaybookCtrl.resolve = {
    info:['$route', 'Daybook', function ($route, Daybook) {
        var start_date = $route.current.params.StartDate,
            finish_date = $route.current.params.FinishDate;

        if (typeof start_date === 'undefined' || typeof finish_date === 'undefined') {
            return Daybook.get({}).$promise;
        } else {
            return Daybook.get({StartDate:start_date, FinishDate:finish_date}).$promise;
        }
    }]
};