String.prototype.paddingLeft = function (paddingValue) {
return String(paddingValue + this).slice(-paddingValue.length);
};
angular.module("app/scripts/ng_js_att_tpls/datepicker/dateTimePickerPopup.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("app/scripts/ng_js_att_tpls/datepicker/dateTimePickerPopup.html",
"
\n" +
"
\n" +
" \n" +
" \n" +
"
\n" +
'
'
+ '
'
+ '
'
+ '- '
+ 'Date'
+ '
'
+ '- '
+ 'Time'
+ '
'
+ '
'
+ '
'
+ '
'
+'
'
+'
'
+ '
{{displayMonth}} {{year}}
'
+ '
'
+ '
'
+ '
{{day | limitTo: 1}}
'
+ '
{{d}}
'
+ '
{{d}}
'
+ '
{{d}}
'
+ '
'
+ '
'
+ '
'
+ '
'
+ '
{{hour}}:{{minute}}
'
+ '
'
+ '
'
+ '
AM
'
+ '
PM
'
+ '
'
+ '
'
+ '
{{time}}
'
+ '
'
+ '
'
+ '
'
+ '
'
+ '
' +
"
\n" +
"");
}]);
angular.module('quantum').requires.push("app/scripts/ng_js_att_tpls/datepicker/dateTimePickerPopup.html");
angular.module('quantum')
.directive('dateTimePickerPopup', ['$document', 'datepickerService', '$isElement', '$documentBind', function($document, datepickerService, $isElement, $documentBind) {
var link = function (scope, elem, attr) {
datepickerService.bindScope(attr, scope);
scope.isOpen = false;
var toggle = scope.toggle = function (show) {
if(show === true || show === false) {
scope.isOpen = show;
} else {
scope.isOpen = !scope.isOpen;
}
};
// scope.$watch('current', function () {
// toggle(false);
// });
var outsideClick = function (e) {
var isElement = $isElement(angular.element(e.target), elem, $document);
if(!isElement) {
toggle(false);
scope.$apply();
}
};
$documentBind.click('isOpen', outsideClick, scope);
scope.tabs = [{
title: 'DATE',
url: '#option1'
}, {
title: 'TIME',
url: '#option2',
selected: true
}
];
//--------------------------------------
scope.state = false;
scope.tab = 'time';
scope.setTab = function(tab){
scope.tab = tab;
};
scope.config = {
modal: true,
color:'rgba(5, 116, 172, 1)',
backgroundColor: 'rgba(0,0,0,0.75)'
};
scope.months = ["January","February","March","April","May","June","July","Augusta","September","October","November","December"];
scope.dayNames = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
scope.$watch('current',function(value){
var m;
if(value)
m = moment(value);
else
m = moment();
m = m.minute(5*Math.ceil(m.minute()/5));
scope.display = m.format('YYYY-MM-DD hh:mm A');
scope.days = scope.getDaysInMonth(m.year(),m.month());
scope.minute = m.minute();
scope.meridian = m.format('A');
scope.hour = scope.meridian == 'PM' ? m.hour() - 12: m.hour();
if(scope.hour==0) scope.hour = 12;
scope.datePreview = m.format('YYYY-MM-DD');
scope.timePreview = m.format('hh:mm A');
scope.displayMonth = scope.months[m.month()];
scope.day = m.date();
scope.year = m.year();
});
scope.setDay = function(date){
scope.current = moment(scope.current).date(date).toDate();
};
scope.setState = function(state){
scope.state = false;
};
scope.setHour = function(hour){
if(scope.meridian == 'PM' && hour < 12)
hour = hour + 12;
if(scope.meridian == 'AM' && hour == 12)
hour = hour - 12;
scope.current = moment(scope.current).hour(hour).toDate();
};
scope.setMeridian = function(meridian){
var m = moment(scope.current);
if(meridian == 'AM'){
if(m.hours()>=12){
m = m.add(-12,'hours');
scope.current = m.toDate();
}
}else{
if(m.hours()<12){
m = m.add(12,'hours');
scope.current = m.toDate();
}
}
};
scope.setMinutes = function(minutes){
scope.current = moment(scope.current).minute(minutes).toDate();
};
var days = [];
for(var i=1;i<=31;i++){
days.push(i);
}
scope.getDaysInMonth = function(year,month){
var firstDayOfWeek = 0;
var firstDayOfMonth = new Date(year, month, 1),
lastDayOfMonth = new Date(year, month + 1, 0),
lastDayOfPreviousMonth = new Date(year, month, 0),
daysInMonth = lastDayOfMonth.getDate(),
daysInLastMonth = lastDayOfPreviousMonth.getDate(),
dayOfWeek = firstDayOfMonth.getDay(),
leadingDays = (dayOfWeek - firstDayOfWeek + 7) % 7 || 7,
trailingDays = days.slice(0, 6 * 7 - (leadingDays + daysInMonth));
if (trailingDays.length > 7) {
trailingDays = trailingDays.slice(0, trailingDays.length-7);
}
return {
year: year,
month: month,
days: days.slice(0, daysInMonth),
leadingDays: days.slice(- leadingDays - (31 - daysInLastMonth), daysInLastMonth),
trailingDays: trailingDays
};
};
scope.addMonth = function(increment){
scope.current = moment(scope.current).add(increment,'months').toDate();
};
};
return {
restrict: 'EA',
replace: true,
transclude: true,
templateUrl: 'app/scripts/ng_js_att_tpls/datepicker/dateTimePickerPopup.html',
scope: {
current: "=current"
},
compile: function (elem, attr) {
var wrapperElement = elem.find('span').eq(1);
wrapperElement.attr('current', 'current');
datepickerService.setAttributes(attr, wrapperElement);
return link;
}
};
}])
.directive('attDateTimePicker', ['$log', function($log) {
return {
restrict: 'A',
require: 'ngModel',
scope: {},
controller: ['$scope', '$element', '$attrs', '$compile', 'datepickerConfig', 'datepickerService', function($scope, $element, $attrs, $compile, datepickerConfig, datepickerService) {
var dateFormatString = angular.isDefined($attrs.dateFormat) ? $scope.$parent.$eval($attrs.dateFormat) : datepickerConfig.dateFormat;
var selectedDateMessage = 'the date you selected is {{$parent.current | date : \'' + dateFormatString + '\'}}
';
$element.removeAttr('att-date-time-picker');
$element.removeAttr('ng-model');
$element.attr('ng-model', '$parent.current');
$element.attr('aria-describedby', 'datepicker');
$element.attr('format-date', dateFormatString);
$element.attr('att-input-deny', '[^0-9ampAMP \/:-]');
$element.attr('maxlength', 20);
var wrapperElement = angular.element('');
wrapperElement.attr('date-time-picker-popup', '');
wrapperElement.attr('current', 'current');
datepickerService.setAttributes($attrs, wrapperElement);
datepickerService.bindScope($attrs, $scope);
wrapperElement.html('');
wrapperElement.append($element.prop('outerHTML'));
if (navigator.userAgent.match(/MSIE 8/) === null) {
wrapperElement.append(selectedDateMessage);
}
var elm = wrapperElement.prop('outerHTML');
elm = $compile(elm)($scope);
$element.replaceWith(elm);
}],
link: function(scope, elem, attr, ctrl) {
if (!ctrl) {
// do nothing if no ng-model
$log.error("ng-model is required.");
return;
}
scope.$watch('current', function(value) {
ctrl.$setViewValue(value);
});
ctrl.$render = function() {
scope.current = ctrl.$viewValue;
};
}
};
}]);