compass-web/v2/vendor/angular-daterangepicker/ng-bs-daterangepicker.js
Shuai Zhu c8105bb29a Added User Setting Page and User Log Page
Adjusted some other files and made css adjustments

Change-Id: Ib497e148f6775d625179adef0f5515a5a34b9e24
2014-09-05 16:08:37 -07:00

71 lines
2.5 KiB
JavaScript

/**
* @license ng-bs-daterangepicker v0.0.1
* (c) 2013 Luis Farzati http://github.com/luisfarzati/ng-bs-daterangepicker
* License: MIT
*/
(function (angular) {
'use strict';
angular.module('ngBootstrap', []).directive('input', function ($compile, $parse) {
return {
restrict: 'E',
require: '?ngModel',
link: function ($scope, $element, $attributes, ngModel) {
if ($attributes.type !== 'daterange' || ngModel === null ) return;
var options = {};
options.format = $attributes.format || 'YYYY-MM-DD';
options.separator = $attributes.separator || ' - ';
options.minDate = $attributes.minDate && moment($attributes.minDate);
options.maxDate = $attributes.maxDate && moment($attributes.maxDate);
options.dateLimit = $attributes.limit && moment.duration.apply(this, $attributes.limit.split(' ').map(function (elem, index) { return index === 0 && parseInt(elem, 10) || elem; }) );
options.ranges = $attributes.ranges && $parse($attributes.ranges)($scope);
options.locale = $attributes.locale && $parse($attributes.locale)($scope);
options.opens = $attributes.opens && $parse($attributes.opens)($scope);
options.timePicker = $attributes.enabletimepicker && $parse($attributes.enabletimepicker)($scope);
function format(date) {
return date.format(options.format);
}
function formatted(dates) {
return [format(dates.startDate), format(dates.endDate)].join(options.separator);
}
ngModel.$formatters.unshift(function (modelValue) {
if (!modelValue) return '';
return modelValue;
});
ngModel.$parsers.unshift(function (viewValue) {
return viewValue;
});
ngModel.$render = function () {
if (!ngModel.$viewValue || !ngModel.$viewValue.startDate) return;
$element.val(formatted(ngModel.$viewValue));
};
$scope.$watch($attributes.ngModel, function (modelValue) {
if (!modelValue || (!modelValue.startDate)) {
ngModel.$setViewValue({ startDate: moment().subtract(3, 'days'), endDate: moment().startOf('day') });
return;
}
$element.data('daterangepicker').startDate = modelValue.startDate;
$element.data('daterangepicker').endDate = modelValue.endDate;
$element.data('daterangepicker').updateView();
$element.data('daterangepicker').updateCalendars();
$element.data('daterangepicker').updateInputText();
});
$element.daterangepicker(options, function(start, end) {
$scope.$apply(function () {
ngModel.$setViewValue({ startDate: start, endDate: end });
ngModel.$render();
});
});
}
};
});
})(angular);