From fce93c67db81e6867c639c6d2c7a28c8ff3932c5 Mon Sep 17 00:00:00 2001 From: Hugh Messenger Date: Wed, 8 Feb 2017 00:54:13 -0600 Subject: [PATCH] Apply TZ offset to the allow dates in date element. --- plugins/fabrik_element/date/date-min.js | 2 +- plugins/fabrik_element/date/date.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/fabrik_element/date/date-min.js b/plugins/fabrik_element/date/date-min.js index 83642997099..63446dbd1f8 100644 --- a/plugins/fabrik_element/date/date-min.js +++ b/plugins/fabrik_element/date/date-min.js @@ -1,2 +1,2 @@ /*! Fabrik */ -define(["jquery","fab/element"],function(jQuery,FbElement){return window.FbDateTime=new Class({Extends:FbElement,options:{dateTimeFormat:"",locale:"en-GB",calendarSetup:{eventName:"click",ifFormat:"%Y/%m/%d",daFormat:"%Y/%m/%d",singleClick:!0,align:"Tl",range:[1900,2999],showsTime:!1,timeFormat:"24",electric:!0,step:2,cache:!1,showOthers:!1,advanced:!1,allowedDates:[]}},initialize:function(a,b){return this.setPlugin("fabrikdate"),this.parent(a,b)?(Locale.use(this.options.locale),this.hour="0",this.minute="00",this.buttonBg="#ffffff",this.buttonBgSelected="#88dd33",this.startElement=a,this.setUpDone=!1,this.convertAllowedDates(),void this.setUp()):!1},convertAllowedDates:function(){for(var a=0;a0){for(var matched=!1,i=0;i=0;){var f=b.multiple[a],g=f.print("%Y%m%d");this.cal.multiple[g]=f}this.cal.showsOtherMonths=b.showOthers,this.cal.yearStep=b.step,this.cal.setRange(b.range[0],b.range[1]),this.cal.params=b,this.cal.getDateText=b.dateText,this.cal.setDateFormat(e),this.cal.create(),this.cal.refresh(),this.cal.hide(),Fabrik.fireEvent("fabrik.element.date.calendar.created",this)},disableTyping:function(){return"null"===typeOf(this.element)?void fconsole(element+": not date element container - is this a custom template with a missing $element->containerClass div/li surrounding the element?"):(this.element.setProperty("readonly","readonly"),void this.element.getElements(".fabrikinput").each(function(a){a.addEvent("focus",function(b){this._disabledShowCalTime(a,b)}.bind(this)),a.addEvent("click",function(b){this._disabledShowCalTime(a,b)}.bind(this))}.bind(this)))},_disabledShowCalTime:function(a,b){"null"!==typeOf(b)&&(b.target.hasClass("timeField")?this.getContainer().getElement(".timeButton").fireEvent("click"):(this.options.calendarSetup.inputField=b.target.id,this.options.calendarSetup.button=this.element.id+"_img",this.cal.showAtElement(a,this.cal.params.align),"undefined"!=typeof this.cal.wrapper&&this.cal.wrapper.getParent().position({relativeTo:this.cal.params.inputField,position:"topLeft"})))},getValue:function(){var a;if(!this.options.editable)return this.options.value;if(this.getElement(),this.cal){var b=this.getDateField().value;if(""===b)return"";var c=new RegExp("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}");if(null!==b.match(c))return b;a=this.cal.date}else{if(""===this.options.value||null===this.options.value||"0000-00-00 00:00:00"===this.options.value)return"";a=new Date.parse(this.options.value)}return a=this.setTimeFromField(a),a.format("db")},hasSeconds:function(){if(this.options.showtime===!0&&this.timeElement){if(this.options.dateTimeFormat.contains("%S"))return!0;if(this.options.dateTimeFormat.contains("%T"))return!0;if(this.options.dateTimeFormat.contains("s"))return!0}return!1},setTimeFromField:function(a){if("date"===typeOf(a)){if(this.options.showtime===!0&&this.timeElement){var b=this.timeElement.get("value").toUpperCase(),c=b.contains("PM")?!0:!1;b=b.replace("PM","").replace("AM","");var d=b.split(":"),e=d[0]?d[0].toInt():0;c&&(e+=12);var f=d[1]?d[1].toInt():0;if(a.setHours(e),a.setMinutes(f),d[2]&&this.hasSeconds()){var g=d[2]?d[2].toInt():0;a.setSeconds(g)}else a.setSeconds(0)}else""===this.options.dateTimeFormat&&(a.setHours(0),a.setMinutes(0),a.setSeconds(0));return a}},watchButtons:function(){this.options.showtime&&this.options.editable&&(this.getTimeField(),this.getTimeButton(),this.timeButton&&(this.timeButton.removeEvents("click"),this.timeButton.addEvent("click",function(a){a.stop(),this.showTime()}.bind(this)),this.setUpDone||this.timeElement&&(this.dropdown=this.makeDropDown(),this.setActive(),this.dropdown.getElement("a.close-time").addEvent("click",function(a){a.stop(),this.hideTime()}.bind(this)),this.setUpDone=!0)))},addNewEventAux:function(action,js){"change"===action?Fabrik.addEvent("fabrik.date.select",function(w){if(w.baseElementId===this.baseElementId){var e="fabrik.date.select";"function"===typeOf(js)?js.delay(0,this,this):eval(js)}}.bind(this)):this.element.getElements("input").each(function(i){i.addEvent(action,function(e){"event"===typeOf(e)&&e.stop(),"function"===typeOf(js)?js.delay(0,this,this):eval(js)})}.bind(this))},update:function(a,b){if(b=b?b:["change"],this.getElement(),"invalid date"===a)return void fconsole(this.element.id+": date not updated as not valid");var c;if("string"===typeOf(a)){if(c=Date.parse(a),null===c)return this._getSubElements().each(function(a){a.value=""}),this.cal&&(this.cal.date=new Date),void(this.options.editable||"null"!==typeOf(this.element)&&this.element.set("html",a))}else c=a;var d=this.options.calendarSetup.ifFormat;if(""!==this.options.dateTimeFormat&&this.options.showtime&&(d+=" "+this.options.dateTimeFormat),b.length>0&&this.fireEvents(b),"null"!==typeOf(a)&&a!==!1){if(!this.options.editable)return void("null"!==typeOf(this.element)&&this.element.set("html",c.format(d)));if(this.options.hidden)return c=c.format(d),void(this.getDateField().value=c);this.getTimeField(),this.hour=c.get("hours"),this.minute=c.get("minutes"),this.second=c.get("seconds"),this.stateTime(),this.cal.date=c,this.getDateField().value=c.format(this.options.calendarSetup.ifFormat)}},getDateField:function(){return this.element.getElement(".fabrikinput")},getTimeField:function(){return this.timeElement=this.getContainer().getElement(".timeField"),this.timeElement},getTimeButton:function(){return this.timeButton=this.getContainer().getElement(".timeButton"),this.timeButton},showCalendar:function(){},getAbsolutePos:function(a){var b={x:a.offsetLeft,y:a.offsetTop};if(a.offsetParent){var c=this.getAbsolutePos(a.offsetParent);b.x+=c.x,b.y+=c.y}return b},makeDropDown:function(){var a,b,c=null,d=new Element("div.draggable.modal-header",{styles:{height:"20px",curor:"move",padding:"2px;"},id:this.startElement+"_handle"}).set("html",' '+this.options.timelabel+''),e=new Element("div.fbDateTime.fabrikWindow",{styles:{"z-index":999999,display:"none",width:"300px",height:"180px"}});e.appendChild(d),b=new Element("div.itemContentPadder"),b.adopt(new Element("p").set("text","Hours")),b.adopt(this.hourButtons(0,12)),b.adopt(this.hourButtons(12,24)),b.adopt(new Element("p").set("text","Minutes"));var f=new Element("div.btn-group",{styles:{clear:"both",paddingTop:"5px"}});for(a=0;12>a;a++)c=new Element("a.btn.fbdateTime-minute.btn-mini",{styles:{width:"10px"}}),c.innerHTML=5*a,f.appendChild(c),document.id(c).addEvent("click",function(a){this.minute=this.formatMinute(a.target.innerHTML),this.stateTime(),this.setActive()}.bind(this)),c.addEvent("mouseover",function(a){var b=a.target;this.minute!==this.formatMinute(b.innerHTML)&&a.target.addClass("btn-info")}.bind(this)),c.addEvent("mouseout",function(a){var b=a.target;this.minute!==this.formatMinute(b.innerHTML)&&a.target.removeClass("btn-info")}.bind(this));b.appendChild(f),e.appendChild(b),document.addEvent("click",function(a){if(this.timeActive){var b=a.target;b!==this.timeButton&&b!==this.timeElement&&(b.within(this.dropdown)||this.hideTime())}}.bind(this)),e.inject(document.body);var g=(new Drag.Move(e),d.getElement("a.close"));return"null"!==typeOf(g)&&g.addEvent("click",function(a){a.stop(),this.hideTime()}.bind(this)),e},hourButtons:function(a,b){var c,d=this.getValue();if(""===d)this.hour=0,this.minute=0;else{var e=Date.parse(d);this.hour=e.get("hours"),this.minute=e.get("minutes")}for(var f=new Element("div.btn-group"),g=a;b>g;g++)c=new Element("a.btn.btn-mini.fbdateTime-hour",{styles:{width:"10px"}}).set("html",g),f.appendChild(c),document.id(c).addEvent("click",function(a){this.hour=a.target.innerHTML,this.stateTime(),this.setActive(),a.target.addClass("btn-successs").removeClass("badge-info")}.bind(this)),document.id(c).addEvent("mouseover",function(a){this.hour!==a.target.innerHTML&&a.target.addClass("btn-info")}.bind(this)),document.id(c).addEvent("mouseout",function(a){this.hour!==a.target.innerHTML&&a.target.removeClass("btn-info")}.bind(this));return f},toggleTime:function(){"none"===this.dropdown.style.display?this.doShowTime():this.hideTime()},doShowTime:function(){this.dropdown.show(),this.timeActive=!0,Fabrik.fireEvent("fabrik.date.showtime",this)},hideTime:function(){this.timeActive=!1,this.dropdown.hide(),this.options.validations!==!1&&this.form.doElementValidation(this.element.id),Fabrik.fireEvent("fabrik.date.hidetime",this),Fabrik.fireEvent("fabrik.date.select",this),window.fireEvent("fabrik.date.select",this)},formatMinute:function(a){return a=a.replace(":",""),a.pad("2","0","left"),a},stateTime:function(){if(this.timeElement){var a=this.hour.toString().pad("2","0","left")+":"+this.minute.toString().pad("2","0","left");this.second&&(a+=":"+this.second.toString().pad("2","0","left"));var b=this.timeElement.value!==a;this.timeElement.value=a,b&&this.fireEvents(["change"])}},showTime:function(){this.dropdown.position({relativeTo:this.timeElement,position:"topRight"}),this.toggleTime(),this.setActive()},setActive:function(){var a=this.dropdown.getElements(".fbdateTime-hour");a.removeClass("btn-success").removeClass("btn-info");var b=this.dropdown.getElements(".fbdateTime-minute");b.removeClass("btn-success").removeClass("btn-info"),"null"!==typeOf(b[this.minute/5])&&b[this.minute/5].addClass("btn-success");var c=a[this.hour.toInt()];"null"!==typeOf(c)&&c.addClass("btn-success")},addEventToCalOpts:function(){this.options.calendarSetup.onSelect=function(a,b){this.calSelect(a,b)}.bind(this),this.options.calendarSetup.dateStatusFunc=function(a){return this.dateSelect(a)}.bind(this),this.options.calendarSetup.onClose=function(a){this.calClose(a)}.bind(this)},cloned:function(a){this.setUpDone=!1,this.hour=0,delete this.cal;var b=this.element.getElement("img");b&&(b.id=this.element.id+"_cal_img");var c=this.element.getElement("input");c.id=this.element.id+"_cal",this.options.calendarSetup.inputField=c.id,this.options.calendarSetup.button=this.element.id+"_img",this.makeCalendar(),this.cal.hide(),this.setUp(),this.parent(a)}}),window.FbDateTime}); \ No newline at end of file +define(["jquery","fab/element"],function(jQuery,FbElement){return window.FbDateTime=new Class({Extends:FbElement,options:{dateTimeFormat:"",locale:"en-GB",calendarSetup:{eventName:"click",ifFormat:"%Y/%m/%d",daFormat:"%Y/%m/%d",singleClick:!0,align:"Tl",range:[1900,2999],showsTime:!1,timeFormat:"24",electric:!0,step:2,cache:!1,showOthers:!1,advanced:!1,allowedDates:[]}},initialize:function(a,b){return this.setPlugin("fabrikdate"),this.parent(a,b)?(Locale.use(this.options.locale),this.hour="0",this.minute="00",this.buttonBg="#ffffff",this.buttonBgSelected="#88dd33",this.startElement=a,this.setUpDone=!1,this.convertAllowedDates(),void this.setUp()):!1},convertAllowedDates:function(){for(var a=0;a0){for(var matched=!1,i=0;i=0;){var f=b.multiple[a],g=f.print("%Y%m%d");this.cal.multiple[g]=f}this.cal.showsOtherMonths=b.showOthers,this.cal.yearStep=b.step,this.cal.setRange(b.range[0],b.range[1]),this.cal.params=b,this.cal.getDateText=b.dateText,this.cal.setDateFormat(e),this.cal.create(),this.cal.refresh(),this.cal.hide(),Fabrik.fireEvent("fabrik.element.date.calendar.created",this)},disableTyping:function(){return"null"===typeOf(this.element)?void fconsole(element+": not date element container - is this a custom template with a missing $element->containerClass div/li surrounding the element?"):(this.element.setProperty("readonly","readonly"),void this.element.getElements(".fabrikinput").each(function(a){a.addEvent("focus",function(b){this._disabledShowCalTime(a,b)}.bind(this)),a.addEvent("click",function(b){this._disabledShowCalTime(a,b)}.bind(this))}.bind(this)))},_disabledShowCalTime:function(a,b){"null"!==typeOf(b)&&(b.target.hasClass("timeField")?this.getContainer().getElement(".timeButton").fireEvent("click"):(this.options.calendarSetup.inputField=b.target.id,this.options.calendarSetup.button=this.element.id+"_img",this.cal.showAtElement(a,this.cal.params.align),"undefined"!=typeof this.cal.wrapper&&this.cal.wrapper.getParent().position({relativeTo:this.cal.params.inputField,position:"topLeft"})))},getValue:function(){var a;if(!this.options.editable)return this.options.value;if(this.getElement(),this.cal){var b=this.getDateField().value;if(""===b)return"";var c=new RegExp("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}");if(null!==b.match(c))return b;a=this.cal.date}else{if(""===this.options.value||null===this.options.value||"0000-00-00 00:00:00"===this.options.value)return"";a=new Date.parse(this.options.value)}return a=this.setTimeFromField(a),a.format("db")},hasSeconds:function(){if(this.options.showtime===!0&&this.timeElement){if(this.options.dateTimeFormat.contains("%S"))return!0;if(this.options.dateTimeFormat.contains("%T"))return!0;if(this.options.dateTimeFormat.contains("s"))return!0}return!1},setTimeFromField:function(a){if("date"===typeOf(a)){if(this.options.showtime===!0&&this.timeElement){var b=this.timeElement.get("value").toUpperCase(),c=b.contains("PM")?!0:!1;b=b.replace("PM","").replace("AM","");var d=b.split(":"),e=d[0]?d[0].toInt():0;c&&(e+=12);var f=d[1]?d[1].toInt():0;if(a.setHours(e),a.setMinutes(f),d[2]&&this.hasSeconds()){var g=d[2]?d[2].toInt():0;a.setSeconds(g)}else a.setSeconds(0)}else""===this.options.dateTimeFormat&&(a.setHours(0),a.setMinutes(0),a.setSeconds(0));return a}},watchButtons:function(){this.options.showtime&&this.options.editable&&(this.getTimeField(),this.getTimeButton(),this.timeButton&&(this.timeButton.removeEvents("click"),this.timeButton.addEvent("click",function(a){a.stop(),this.showTime()}.bind(this)),this.setUpDone||this.timeElement&&(this.dropdown=this.makeDropDown(),this.setActive(),this.dropdown.getElement("a.close-time").addEvent("click",function(a){a.stop(),this.hideTime()}.bind(this)),this.setUpDone=!0)))},addNewEventAux:function(action,js){"change"===action?Fabrik.addEvent("fabrik.date.select",function(w){if(w.baseElementId===this.baseElementId){var e="fabrik.date.select";"function"===typeOf(js)?js.delay(0,this,this):eval(js)}}.bind(this)):this.element.getElements("input").each(function(i){i.addEvent(action,function(e){"event"===typeOf(e)&&e.stop(),"function"===typeOf(js)?js.delay(0,this,this):eval(js)})}.bind(this))},update:function(a,b){if(b=b?b:["change"],this.getElement(),"invalid date"===a)return void fconsole(this.element.id+": date not updated as not valid");var c;if("string"===typeOf(a)){if(c=Date.parse(a),null===c)return this._getSubElements().each(function(a){a.value=""}),this.cal&&(this.cal.date=new Date),void(this.options.editable||"null"!==typeOf(this.element)&&this.element.set("html",a))}else c=a;var d=this.options.calendarSetup.ifFormat;if(""!==this.options.dateTimeFormat&&this.options.showtime&&(d+=" "+this.options.dateTimeFormat),b.length>0&&this.fireEvents(b),"null"!==typeOf(a)&&a!==!1){if(!this.options.editable)return void("null"!==typeOf(this.element)&&this.element.set("html",c.format(d)));if(this.options.hidden)return c=c.format(d),void(this.getDateField().value=c);this.getTimeField(),this.hour=c.get("hours"),this.minute=c.get("minutes"),this.second=c.get("seconds"),this.stateTime(),this.cal.date=c,this.getDateField().value=c.format(this.options.calendarSetup.ifFormat)}},getDateField:function(){return this.element.getElement(".fabrikinput")},getTimeField:function(){return this.timeElement=this.getContainer().getElement(".timeField"),this.timeElement},getTimeButton:function(){return this.timeButton=this.getContainer().getElement(".timeButton"),this.timeButton},showCalendar:function(){},getAbsolutePos:function(a){var b={x:a.offsetLeft,y:a.offsetTop};if(a.offsetParent){var c=this.getAbsolutePos(a.offsetParent);b.x+=c.x,b.y+=c.y}return b},makeDropDown:function(){var a,b,c=null,d=new Element("div.draggable.modal-header",{styles:{height:"20px",curor:"move",padding:"2px;"},id:this.startElement+"_handle"}).set("html",' '+this.options.timelabel+''),e=new Element("div.fbDateTime.fabrikWindow",{styles:{"z-index":999999,display:"none",width:"300px",height:"180px"}});e.appendChild(d),b=new Element("div.itemContentPadder"),b.adopt(new Element("p").set("text","Hours")),b.adopt(this.hourButtons(0,12)),b.adopt(this.hourButtons(12,24)),b.adopt(new Element("p").set("text","Minutes"));var f=new Element("div.btn-group",{styles:{clear:"both",paddingTop:"5px"}});for(a=0;12>a;a++)c=new Element("a.btn.fbdateTime-minute.btn-mini",{styles:{width:"10px"}}),c.innerHTML=5*a,f.appendChild(c),document.id(c).addEvent("click",function(a){this.minute=this.formatMinute(a.target.innerHTML),this.stateTime(),this.setActive()}.bind(this)),c.addEvent("mouseover",function(a){var b=a.target;this.minute!==this.formatMinute(b.innerHTML)&&a.target.addClass("btn-info")}.bind(this)),c.addEvent("mouseout",function(a){var b=a.target;this.minute!==this.formatMinute(b.innerHTML)&&a.target.removeClass("btn-info")}.bind(this));b.appendChild(f),e.appendChild(b),document.addEvent("click",function(a){if(this.timeActive){var b=a.target;b!==this.timeButton&&b!==this.timeElement&&(b.within(this.dropdown)||this.hideTime())}}.bind(this)),e.inject(document.body);var g=(new Drag.Move(e),d.getElement("a.close"));return"null"!==typeOf(g)&&g.addEvent("click",function(a){a.stop(),this.hideTime()}.bind(this)),e},hourButtons:function(a,b){var c,d=this.getValue();if(""===d)this.hour=0,this.minute=0;else{var e=Date.parse(d);this.hour=e.get("hours"),this.minute=e.get("minutes")}for(var f=new Element("div.btn-group"),g=a;b>g;g++)c=new Element("a.btn.btn-mini.fbdateTime-hour",{styles:{width:"10px"}}).set("html",g),f.appendChild(c),document.id(c).addEvent("click",function(a){this.hour=a.target.innerHTML,this.stateTime(),this.setActive(),a.target.addClass("btn-successs").removeClass("badge-info")}.bind(this)),document.id(c).addEvent("mouseover",function(a){this.hour!==a.target.innerHTML&&a.target.addClass("btn-info")}.bind(this)),document.id(c).addEvent("mouseout",function(a){this.hour!==a.target.innerHTML&&a.target.removeClass("btn-info")}.bind(this));return f},toggleTime:function(){"none"===this.dropdown.style.display?this.doShowTime():this.hideTime()},doShowTime:function(){this.dropdown.show(),this.timeActive=!0,Fabrik.fireEvent("fabrik.date.showtime",this)},hideTime:function(){this.timeActive=!1,this.dropdown.hide(),this.options.validations!==!1&&this.form.doElementValidation(this.element.id),Fabrik.fireEvent("fabrik.date.hidetime",this),Fabrik.fireEvent("fabrik.date.select",this),window.fireEvent("fabrik.date.select",this)},formatMinute:function(a){return a=a.replace(":",""),a.pad("2","0","left"),a},stateTime:function(){if(this.timeElement){var a=this.hour.toString().pad("2","0","left")+":"+this.minute.toString().pad("2","0","left");this.second&&(a+=":"+this.second.toString().pad("2","0","left"));var b=this.timeElement.value!==a;this.timeElement.value=a,b&&this.fireEvents(["change"])}},showTime:function(){this.dropdown.position({relativeTo:this.timeElement,position:"topRight"}),this.toggleTime(),this.setActive()},setActive:function(){var a=this.dropdown.getElements(".fbdateTime-hour");a.removeClass("btn-success").removeClass("btn-info");var b=this.dropdown.getElements(".fbdateTime-minute");b.removeClass("btn-success").removeClass("btn-info"),"null"!==typeOf(b[this.minute/5])&&b[this.minute/5].addClass("btn-success");var c=a[this.hour.toInt()];"null"!==typeOf(c)&&c.addClass("btn-success")},addEventToCalOpts:function(){this.options.calendarSetup.onSelect=function(a,b){this.calSelect(a,b)}.bind(this),this.options.calendarSetup.dateStatusFunc=function(a){return this.dateSelect(a)}.bind(this),this.options.calendarSetup.onClose=function(a){this.calClose(a)}.bind(this)},cloned:function(a){this.setUpDone=!1,this.hour=0,delete this.cal;var b=this.element.getElement("img");b&&(b.id=this.element.id+"_cal_img");var c=this.element.getElement("input");c.id=this.element.id+"_cal",this.options.calendarSetup.inputField=c.id,this.options.calendarSetup.button=this.element.id+"_img",this.makeCalendar(),this.cal.hide(),this.setUp(),this.parent(a)}}),window.FbDateTime}); \ No newline at end of file diff --git a/plugins/fabrik_element/date/date.js b/plugins/fabrik_element/date/date.js index 70ea2f22719..0ca1d0b96b5 100644 --- a/plugins/fabrik_element/date/date.js +++ b/plugins/fabrik_element/date/date.js @@ -57,6 +57,10 @@ define(['jquery', 'fab/element'], function (jQuery, FbElement) { convertAllowedDates: function () { for (var i = 0; i < this.options.allowedDates.length; i++) { this.options.allowedDates[i] = new Date(this.options.allowedDates[i]); + // apply the TZ offset, otherwise if (say) GMT -6, 2017-02-15 will become 2017-01-15 18:00:00 + this.options.allowedDates[i].setTime( + this.options.allowedDates[i].getTime() + this.options.allowedDates[i].getTimezoneOffset()*60*1000 + ); } }, @@ -317,7 +321,7 @@ define(['jquery', 'fab/element'], function (jQuery, FbElement) { this.cal.weekNumbers = params.weekNumbers; if (params.multiple) { - cal.multiple = {}; + this.cal.multiple = {}; for (i = params.multiple.length; --i >= 0;) { var d = params.multiple[i]; var ds = d.print('%Y%m%d');