diff --git a/plugins/fabrik_element/date/date-min.js b/plugins/fabrik_element/date/date-min.js index 1e53262f2f7..1a33325f4ff 100644 --- a/plugins/fabrik_element/date/date-min.js +++ b/plugins/fabrik_element/date/date-min.js @@ -1,3 +1,3 @@ /*! Fabrik */ -define(["jquery","fab/element"],function(jQuery,FbElement){return window.FbDateTime=new Class({Extends:FbElement,options:{dateTimeFormat:"",locale:"en-GB",allowedDates:[],allowedClasses:[],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}},initialize:function(t,e){if(this.setPlugin("fabrikdate"),!this.parent(t,e))return!1;Locale.use(this.options.locale),this.hour="0",this.minute="00",this.buttonBg="#ffffff",this.buttonBgSelected="#88dd33",this.startElement=t,this.setUpDone=!1,this.convertAllowedDates(),this.setUp()},convertAllowedDates:function(){for(var t=0;tcontainerClass div/li surrounding the element?")},_disabledShowCalTime:function(t,e){"null"!==typeOf(e)&&(e.target.hasClass("timeField")?this.getContainer().getElement(".timeButton").fireEvent("click"):(this.options.calendarSetup.inputField=e.target.id,this.options.calendarSetup.button=this.element.id+"_cal_img",this.cal.showAtElement(t,this.cal.params.align),void 0!==this.cal.wrapper&&this.cal.wrapper.getParent().position({relativeTo:this.cal.params.inputField,position:"topLeft"})))},getValue:function(){var t;if(!this.options.editable)return this.options.value;if(this.getElement(),this.cal){var e=this.getDateField().value;if(""===e)return"";var i=new RegExp("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}");if(null!==e.match(i))return e;t=this.cal.date}else{if(""===this.options.value||null===this.options.value||"0000-00-00 00:00:00"===this.options.value)return"";t=new Date.parse(this.options.value)}return(t=this.setTimeFromField(t)).format("db")},hasSeconds:function(){if(!0===this.options.showtime&&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(t){if("date"===typeOf(t)){if(!0===this.options.showtime&&this.timeElement){var e=this.timeElement.get("value").toUpperCase(),i=!!e.contains("PM"),n=(e=e.replace("PM","").replace("AM","")).split(":"),s=n[0]?n[0].toInt():0;i&&(s+=12);var a=n[1]?n[1].toInt():0;if(t.setHours(s),t.setMinutes(a),n[2]&&this.hasSeconds()){var o=n[2]?n[2].toInt():0;t.setSeconds(o)}else t.setSeconds(0)}else""===this.options.dateTimeFormat&&(t.setHours(0),t.setMinutes(0),t.setSeconds(0));return t}},watchButtons:function(){this.options.showtime&&this.options.editable&&(this.getTimeField(),this.getTimeButton(),this.timeButton&&(this.timeButton.removeEvents("click"),this.timeButton.addEvent("click",function(t){t.stop(),this.showTime()}.bind(this)),this.setUpDone||this.timeElement&&(this.dropdown=this.makeDropDown(),this.setActive(),this.dropdown.getElement("a.close-time").addEvent("click",function(t){t.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(t,e){if(e=e||["change"],this.getElement(),"invalid date"!==t){var i;if("string"===typeOf(t)){if(""===t)return this._getSubElements().each(function(t){t.value=""}),this.cal&&(this.cal.date=new Date),void(this.options.editable||"null"!==typeOf(this.element)&&this.element.set("html",t));i=this.options.advanced?Date.parseExact(t,Date.normalizeFormat("%Y-%m-%d %H:%M:%S")):Date.parseDate(t,"%Y-%m-%d %H:%M")}else i=t;var n=this.options.calendarSetup.ifFormat;if(""!==this.options.dateTimeFormat&&this.options.showtime&&(n+=" "+this.options.dateTimeFormat),0 '+this.options.timelabel+''),s=new Element("div.fbDateTime.fabrikWindow",{styles:{"z-index":999999,display:"none",width:"300px",height:"180px"}});s.appendChild(n),(e=new Element("div.itemContentPadder")).adopt(new Element("p").set("text","Hours")),e.adopt(this.hourButtons(0,12)),e.adopt(this.hourButtons(12,24)),e.adopt(new Element("p").set("text","Minutes"));var a=new Element("div.btn-group",{styles:{clear:"both",paddingTop:"5px"}});for(t=0;t<12;t++)(i=new Element("a.btn.fbdateTime-minute.btn-mini",{styles:{width:"10px"}})).innerHTML=5*t,a.appendChild(i),document.id(i).addEvent("click",function(t){this.minute=this.formatMinute(t.target.innerHTML),this.stateTime(),this.setActive()}.bind(this)),i.addEvent("mouseover",function(t){var e=t.target;this.minute!==this.formatMinute(e.innerHTML)&&t.target.addClass("btn-info")}.bind(this)),i.addEvent("mouseout",function(t){var e=t.target;this.minute!==this.formatMinute(e.innerHTML)&&t.target.removeClass("btn-info")}.bind(this));e.appendChild(a),s.appendChild(e),document.addEvent("click",function(t){if(this.timeActive){var e=t.target;e!==this.timeButton&&e!==this.timeElement&&(e.within(this.dropdown)||this.hideTime())}}.bind(this)),s.inject(document.body);new Drag.Move(s);var o=n.getElement("a.close");return"null"!==typeOf(o)&&o.addEvent("click",function(t){t.stop(),this.hideTime()}.bind(this)),s},hourButtons:function(t,e){var i,n=this.getValue();if(""===n)this.hour=0,this.minute=0;else{var s=Date.parse(n);this.hour=s.get("hours"),this.minute=s.get("minutes")}for(var a=new Element("div.btn-group"),o=t;ocontainerClass div/li surrounding the element?")},_disabledShowCalTime:function(t,e){"null"!==typeOf(e)&&(e.target.hasClass("timeField")?this.getContainer().getElement(".timeButton").fireEvent("click"):(this.options.calendarSetup.inputField=e.target.id,this.options.calendarSetup.button=this.element.id+"_cal_img",this.cal.showAtElement(t,this.cal.params.align),void 0!==this.cal.wrapper&&this.cal.wrapper.getParent().position({relativeTo:this.cal.params.inputField,position:"topLeft"})))},getValue:function(){var t;if(!this.options.editable)return this.options.value;if(this.getElement(),this.cal){var e=this.getDateField().value;if(""===e)return"";var i=new RegExp("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}");if(null!==e.match(i))return e;t=this.cal.date}else{if(""===this.options.value||null===this.options.value||"0000-00-00 00:00:00"===this.options.value)return"";t=new Date.parse(this.options.value)}return(t=this.setTimeFromField(t)).format("db")},hasSeconds:function(){if(!0===this.options.showtime&&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(t){if("date"===typeOf(t)){if(!0===this.options.showtime&&this.timeElement){var e=this.timeElement.get("value").toUpperCase(),i=!!e.contains("PM"),n=(e=e.replace("PM","").replace("AM","")).split(":"),s=n[0]?n[0].toInt():0;i&&(s+=12);var a=n[1]?n[1].toInt():0;if(t.setHours(s),t.setMinutes(a),n[2]&&this.hasSeconds()){var o=n[2]?n[2].toInt():0;t.setSeconds(o)}else t.setSeconds(0)}else""===this.options.dateTimeFormat&&(t.setHours(0),t.setMinutes(0),t.setSeconds(0));return t}},watchButtons:function(){this.options.showtime&&this.options.editable&&(this.getTimeField(),this.getTimeButton(),this.timeButton&&(this.timeButton.removeEvents("click"),this.timeButton.addEvent("click",function(t){t.stop(),this.showTime()}.bind(this)),this.setUpDone||this.timeElement&&(this.dropdown=this.makeDropDown(),this.setActive(),this.dropdown.getElement("a.close-time").addEvent("click",function(t){t.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(t,e){if(e=e||["change"],this.getElement(),"invalid date"!==t){var i;if("string"===typeOf(t)){if(""===t)return this._getSubElements().each(function(t){t.value=""}),this.cal&&(this.cal.date=new Date),void(this.options.editable||"null"!==typeOf(this.element)&&this.element.set("html",t));i=this.options.advanced?Date.parseExact(t,Date.normalizeFormat("%Y-%m-%d %H:%M:%S")):Date.parseDate(t,"%Y-%m-%d %H:%M")}else i=t;var n=this.options.calendarSetup.ifFormat;if(""!==this.options.dateTimeFormat&&this.options.showtime&&(n+=" "+this.options.dateTimeFormat),0 '+this.options.timelabel+''),s=new Element("div.fbDateTime.fabrikWindow",{styles:{"z-index":999999,display:"none",width:"300px",height:"180px"}});s.appendChild(n),(e=new Element("div.itemContentPadder")).adopt(new Element("p").set("text","Hours")),e.adopt(this.hourButtons(0,12)),e.adopt(this.hourButtons(12,24)),e.adopt(new Element("p").set("text","Minutes"));var a=new Element("div.btn-group",{styles:{clear:"both",paddingTop:"5px"}});for(t=0;t<12;t++)(i=new Element("a.btn.fbdateTime-minute.btn-mini",{styles:{width:"10px"}})).innerHTML=5*t,a.appendChild(i),document.id(i).addEvent("click",function(t){this.minute=this.formatMinute(t.target.innerHTML),this.stateTime(),this.setActive()}.bind(this)),i.addEvent("mouseover",function(t){var e=t.target;this.minute!==this.formatMinute(e.innerHTML)&&t.target.addClass("btn-info")}.bind(this)),i.addEvent("mouseout",function(t){var e=t.target;this.minute!==this.formatMinute(e.innerHTML)&&t.target.removeClass("btn-info")}.bind(this));e.appendChild(a),s.appendChild(e),document.addEvent("click",function(t){if(this.timeActive){var e=t.target;e!==this.timeButton&&e!==this.timeElement&&(e.within(this.dropdown)||this.hideTime())}}.bind(this)),s.inject(document.body);new Drag.Move(s);var o=n.getElement("a.close");return"null"!==typeOf(o)&&o.addEvent("click",function(t){t.stop(),this.hideTime()}.bind(this)),s},hourButtons:function(t,e){var i,n=this.getValue();if(""===n)this.hour=0,this.minute=0;else{var s=Date.parse(n);this.hour=s.get("hours"),this.minute=s.get("minutes")}for(var a=new Element("div.btn-group"),o=t;o