'use strict';

var DaybookCtrl = ['$scope', '$location', 'asDateFilter', 'info', function ($scope, $location, asDate, info) {
    $scope.info = info;
    $scope.show = function () {
        var startDate = asDate($scope.info.StartDate),
            finishDate = asDate($scope.info.FinishDate);
        $location.path('/Daybook').search({StartDate: startDate, FinishDate: finishDate});
    };
    $('#txtStartDate').focus();
}];
DaybookCtrl.resolve = {
    info: ['$route', 'Daybook', function ($route, Daybook) {
        var startDate = $route.current.params.StartDate,
            finishDate = $route.current.params.FinishDate;

        if (angular.isUndefined(startDate) || angular.isUndefined(finishDate)) {
            return Daybook.get({}).$promise;
        } else {
            return Daybook.get({StartDate: startDate, FinishDate: finishDate}).$promise;
        }
    }]
};