/* * DateOrPeriod - jQuery Plugin * Opens dialog to select date and / or period * * Version: 1.0 * Requires: jQuery v1.8+, jQuery-UI 1.9+ * * How to use: * * $('#myinput').dateorperiod(); * * Where input class should be 'date' or 'datetime' */ ;(function($) { var methods = { init: function(){ $(this).click( function() { $(this).dateorperiod("showDialog"); } ); }, showDialog: function(){ var $this = $(this); var isDate = $this.hasClass('date'); var pattern = isDate? '%m/%d/%Y': '%m/%d/%Y %H:%M'; var dlg = $("
"); dlg.load('/common/dateOrPeriod.html;jsessionid=C7B837CD66E2F755FCD69B88A3A4E9DE?value='+escape($this.val()), function(responseText, textStatus, XMLHttpRequest) { if (textStatus=='success') { dlg.dialog({ autoOpen:false, width:850, modal:true, title:'Date \/ date period', buttons:[ { text : 'Copy', 'class' : 'btn btn-primary btn-sm', click : function() { var date = dlg.find("#datePart").val(); var years = dlg.find("#years").val(); var months = dlg.find("#months").val(); var weeks = dlg.find("#weeks").val(); var days = dlg.find("#days").val(); var hours = dlg.find("#hours").val(); var minutes = dlg.find("#minutes").val(); if (date || years || months || weeks || days || hours || minutes ) { $this.val(date + ((years || months || weeks || days || hours || minutes)? ("P" + ((years || months || weeks || days) ? (years + months + weeks + days) : "") + ((hours || minutes) ? ("T" + hours + minutes) : "") ) : "") ); } else { $this.val(""); } dlg.dialog("close"); } }, { text : 'Clear', 'class' : 'btn btn-primary btn-sm', click : function() { $this.val(""); dlg.dialog("close"); } }, { text : 'Cancel', 'class' : 'btn btn-primary btn-sm', click : function() { dlg.dialog("close"); } } ], close: function() { dlg.dialog("destroy"); dlg.remove(); dlg = null; } }); dlg.dialog("open"); Calendar.setup({ showsTime: !isDate, singleClick: isDate, step: 1, displayArea: "datePartOption", onSelect: function(cal, value) { var elem = document.getElementById('datePart'); elem.options[1].value = value; elem.options[1].text = value; elem.selectedIndex = 1; }, button: "datePartButton", daFormat: pattern }); } else { dlg.remove(); dlg = null; alert('An unexpected error has ocurred. Please contact support@in1touch.com to help improve the quality of our service.'); } }); } }; $.fn.dateorperiod = function( method ) { if ( methods[method] ) { return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); } else if ( typeof method === 'object' || ! method ) { return methods.init.apply( this, arguments ); } else { $.error( 'Method ' + method + ' does not exist on jQuery.dateorperiod' ); } }; })(jQuery);