Ext.ns("Ext.ux.form");Ext.ux.form.DateTime=Ext.extend(Ext.form.Field,{dateValidator:null,defaultAutoCreate:{tag:"input",type:"hidden"},dtSeparator:" ",hiddenFormat:"Y-m-d H:i:s",otherToNow:true,timePosition:"right",timeValidator:null,timeWidth:100,dateFormat:"m/d/y",timeFormat:"g:i A",initComponent:function(){Ext.ux.form.DateTime.superclass.initComponent.call(this);var b=Ext.apply({},{id:this.id+"-date",format:this.dateFormat||Ext.form.DateField.prototype.format,width:this.timeWidth,selectOnFocus:this.selectOnFocus,validator:this.dateValidator,listeners:{blur:{scope:this,fn:this.onBlur},focus:{scope:this,fn:this.onFocus}}},this.dateConfig);this.df=new Ext.form.DateField(b);this.df.ownerCt=this;delete (this.dateFormat);var a=Ext.apply({},{id:this.id+"-time",format:this.timeFormat||Ext.form.TimeField.prototype.format,width:this.timeWidth,selectOnFocus:this.selectOnFocus,validator:this.timeValidator,listeners:{blur:{scope:this,fn:this.onBlur},focus:{scope:this,fn:this.onFocus}}},this.timeConfig);this.tf=new Ext.form.TimeField(a);this.tf.ownerCt=this;delete (this.timeFormat);this.relayEvents(this.df,["focus","specialkey","invalid","valid"]);this.relayEvents(this.tf,["focus","specialkey","invalid","valid"]);this.on("specialkey",this.onSpecialKey,this)},onRender:function(c,a){if(this.isRendered){return}Ext.ux.form.DateTime.superclass.onRender.call(this,c,a);var b;if("below"===this.timePosition||"bellow"===this.timePosition){b=Ext.DomHelper.append(c,{tag:"table",style:"border-collapse:collapse",children:[{tag:"tr",children:[{tag:"td",style:"padding-bottom:1px",cls:"ux-datetime-date"}]},{tag:"tr",children:[{tag:"td",cls:"ux-datetime-time"}]}]},true)}else{b=Ext.DomHelper.append(c,{tag:"table",style:"border-collapse:collapse",children:[{tag:"tr",children:[{tag:"td",style:"padding-right:4px",cls:"ux-datetime-date"},{tag:"td",cls:"ux-datetime-time"}]}]},true)}this.tableEl=b;this.wrap=b.wrap({cls:"x-form-field-wrap"});this.wrap.on("mousedown",this.onMouseDown,this,{delay:10});this.df.render(b.child("td.ux-datetime-date"));this.tf.render(b.child("td.ux-datetime-time"));this.df.el.swallowEvent(["keydown","keypress"]);this.tf.el.swallowEvent(["keydown","keypress"]);if("side"===this.msgTarget){var d=this.el.findParent(".x-form-element",10,true);if(d){this.errorIcon=d.createChild({cls:"x-form-invalid-icon"})}var e={errorIcon:this.errorIcon,msgTarget:"side",alignErrorIcon:this.alignErrorIcon.createDelegate(this)};Ext.apply(this.df,e);Ext.apply(this.tf,e)}this.el.dom.name=this.hiddenName||this.name||this.id;this.df.el.dom.removeAttribute("name");this.tf.el.dom.removeAttribute("name");this.isRendered=true;this.updateHidden()},adjustSize:Ext.BoxComponent.prototype.adjustSize,alignErrorIcon:function(){this.errorIcon.alignTo(this.tableEl,"tl-tr",[2,0])},initDateValue:function(){this.dateValue=this.otherToNow?new Date():new Date(1970,0,1,0,0,0)},clearInvalid:function(){this.df.clearInvalid();this.tf.clearInvalid()},markInvalid:function(a){this.df.markInvalid(a);this.tf.markInvalid(a)},beforeDestroy:function(){if(this.isRendered){this.wrap.removeAllListeners();this.wrap.remove();this.tableEl.remove();this.df.destroy();this.tf.destroy()}},disable:function(){if(this.isRendered){this.df.disabled=this.disabled;this.df.onDisable();this.tf.onDisable()}this.disabled=true;this.df.disabled=true;this.tf.disabled=true;this.fireEvent("disable",this);return this},enable:function(){if(this.rendered){this.df.onEnable();this.tf.onEnable()}this.disabled=false;this.df.disabled=false;this.tf.disabled=false;this.fireEvent("enable",this);return this},focus:function(){this.df.focus()},getPositionEl:function(){return this.wrap},getResizeEl:function(){return this.wrap},getValue:function(){return this.dateValue?new Date(this.dateValue):""},isValid:function(){return this.df.isValid()&&this.tf.isValid()},isVisible:function(){return this.df.rendered&&this.df.getActionEl().isVisible()},onBlur:function(a){if(this.wrapClick){a.focus();this.wrapClick=false}if(a===this.df){this.updateDate()}else{this.updateTime()}this.updateHidden();this.validate();(function(){if(!this.df.hasFocus&&!this.tf.hasFocus){var b=this.getValue();if(String(b)!==String(this.startValue)){this.fireEvent("change",this,b,this.startValue)}this.hasFocus=false;this.fireEvent("blur",this)}}).defer(100,this)},onFocus:function(){if(!this.hasFocus){this.hasFocus=true;this.startValue=this.getValue();this.fireEvent("focus",this)}},onMouseDown:function(a){if(!this.disabled){this.wrapClick="td"===a.target.nodeName.toLowerCase()}},onSpecialKey:function(b,c){var a=c.getKey();if(a===c.TAB){if(b===this.df&&!c.shiftKey){c.stopEvent();this.tf.focus()}if(b===this.tf&&c.shiftKey){c.stopEvent();this.df.focus()}this.updateValue()}if(a===c.ENTER){this.updateValue()}},reset:function(){this.df.reset(this.originalValue);this.tf.reset(this.originalValue)},setDate:function(a){this.df.setValue(a)},setTime:function(a){this.tf.setValue(a)},setSize:function(a,b){if(!a){return}if("below"===this.timePosition){this.df.setSize(a,b);this.tf.setSize(a,b);if(Ext.isIE){this.df.el.up("td").setWidth(a);this.tf.el.up("td").setWidth(a)}}else{this.df.setSize(a-this.timeWidth-4,b);this.tf.setSize(this.timeWidth,b);if(Ext.isIE){this.df.el.up("td").setWidth(a-this.timeWidth-4);this.tf.el.up("td").setWidth(this.timeWidth)}}},setValue:function(b){if(!b&&true===this.emptyToNow){this.setValue(new Date());return}else{if(!b){this.setDate("");this.setTime("");this.updateValue();return}}if("number"===typeof b){b=new Date(b)}else{if("string"===typeof b&&this.hiddenFormat){b=Date.parseDate(b,this.hiddenFormat)}}b=b?b:new Date(1970,0,1,0,0,0);var a;if(b instanceof Date){this.setDate(b);this.setTime(b);this.dateValue=new Date(Ext.isIE?b.getTime():b)}else{a=b.split(this.dtSeparator);this.setDate(a[0]);if(a[1]){if(a[2]){a[1]+=a[2]}this.setTime(a[1])}}this.updateValue()},setVisible:function(a){if(a){this.df.show();this.tf.show()}else{this.df.hide();this.tf.hide()}return this},show:function(){return this.setVisible(true)},hide:function(){return this.setVisible(false)},updateDate:function(){var a=this.df.getValue();if(a){if(!(this.dateValue instanceof Date)){this.initDateValue();if(!this.tf.getValue()){this.setTime(this.dateValue)}}this.dateValue.setMonth(0);this.dateValue.setFullYear(a.getFullYear());this.dateValue.setMonth(a.getMonth(),a.getDate())}else{this.dateValue="";this.setTime("")}},updateTime:function(){var a=this.tf.getValue();if(a&&!(a instanceof Date)){a=Date.parseDate(a,this.tf.format)}if(a&&!this.df.getValue()){this.initDateValue();this.setDate(this.dateValue)}if(this.dateValue instanceof Date){if(a){this.dateValue.setHours(a.getHours());this.dateValue.setMinutes(a.getMinutes());this.dateValue.setSeconds(a.getSeconds())}else{this.dateValue.setHours(0);this.dateValue.setMinutes(0);this.dateValue.setSeconds(0)}}},updateHidden:function(){if(this.isRendered){var a=this.dateValue instanceof Date?this.dateValue.format(this.hiddenFormat):"";this.el.dom.value=a}},updateValue:function(){this.updateDate();this.updateTime();this.updateHidden();return},validate:function(){return this.df.validate()&&this.tf.validate()},renderer:function(c){var b=c.editor.dateFormat||Ext.ux.form.DateTime.prototype.dateFormat;b+=" "+(c.editor.timeFormat||Ext.ux.form.DateTime.prototype.timeFormat);var a=function(e){var d=Ext.util.Format.date(e,b);return d};return a}});Ext.reg("xdatetime",Ext.ux.form.DateTime);