From 91d04c64771832a0b8815ffbe1f0f9920320d94d Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Tue, 14 Feb 2017 19:41:00 -0500 Subject: Initial OpenECOMP policy/engine commit Change-Id: I7dbff37733b661643dd4d1caefa3d7dccc361b6e Signed-off-by: Pamela Dragosh --- .../static/fusion/raptor/ebz/date_time_picker.js | 277 +++++++++++++++++++++ 1 file changed, 277 insertions(+) create mode 100644 ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/date_time_picker.js (limited to 'ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/date_time_picker.js') diff --git a/ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/date_time_picker.js b/ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/date_time_picker.js new file mode 100644 index 000000000..ae69a913d --- /dev/null +++ b/ecomp-sdk-app/src/main/webapp/static/fusion/raptor/ebz/date_time_picker.js @@ -0,0 +1,277 @@ + 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}}
' + + '
' + + '
' + + '
{{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; + }; + } + }; +}]); + + -- cgit 1.2.3-korg