UNPKG

pip-webui

Version:

HTML5 UI for LOB applications

69 lines (58 loc) 2.46 kB
/** * @file Time control * @copyright Digital Living Software Corp. 2014-2016 */ (function (angular, _) { 'use strict'; var thisModule = angular.module('pipTimeRange', ['pipUtils']); thisModule.directive('pipTimeRange', function (pipUtils) { return { restrict: 'EA', scope: { pipStartDate: '=', pipEndDate: '=' }, templateUrl: 'time_range/time_range.html', link: function ($scope, $element, $attrs) { function getDateJSON(value) { return value ? new Date(value) : null; } function defineStartDate() { if ($scope.pipStartDate !== null && $scope.pipStartDate !== undefined) { $scope.data.start = _.isDate($scope.pipStartDate) ? $scope.pipStartDate : getDateJSON($scope.pipStartDate); } } function defineEndDate() { if ($scope.pipEndDate !== null && $scope.pipEndDate !== undefined) { $scope.data.end = _.isDate($scope.pipEndDate) ? $scope.pipEndDate : getDateJSON($scope.pipEndDate); } } $scope.data = {}; $scope.data.start = null; $scope.data.end = null; defineStartDate(); defineEndDate(); if (pipUtils.toBoolean($attrs.pipRebind)) { $scope.$watch('pipStartDate', function () { $scope.data.start = null; defineStartDate(); } ); $scope.$watch('pipEndDate', function () { $scope.data.end = null; defineEndDate(); } ); } // Add class $element.addClass('pip-time-range'); } }; } ); })(window.angular, window._);