var Timestamp = Class.create(JSControl, { initialize: function($super, element, params){ $super(element); this.controls_ = {"clock": params.clock, "calendar": params.calendar}; this.button_ = Element.down(this.element, "button.SetCurrent"); this.time_first_ = this.element.getAttribute("order") == "TD"; if (this.button_) Event.observe(this.button_, "click", function(event){ this.SetValue(Time.Current()); this.onchange(); this.finalize(); }.bind(this)); var evtnam = ["WM_INIT", "CHANGE", "FINALIZE", "CLICK"]; var awnd = AControl.GetParentWindow($(this.ID())); if (awnd){ for (var iii = 0; iii < evtnam.length; ++iii) awnd.Subscribe(evtnam[iii], this.onAEVENT, this); }else{ for (var iii = 0; iii < evtnam.length; ++iii) SubscribeOnEvent(evtnam[iii], "document", this.onAEVENT, this); } }, SetTabOrder: function(tabbase){ var jscontrols = []; if (this.time_first_) jscontrols.push(this.controls_.clock, this.controls_.calendar); else jscontrols.push(this.controls_.calendar, this.controls_.clock); jscontrols.each(function(jscontrol){ if (jscontrol && jscontrol.SetTabOrder) tabbase = jscontrol.SetTabOrder(tabbase); }); if (this.button_) this.button_.tabIndex = tabbase++; return tabbase; }, finalize: function(){ new AEvent("FINALIZE", {}, this); }, Value: function(){ return new Time(this.controls_.calendar.Value(), this.controls_.clock.Value()); }, SetValue: function(dt){ var date=new ADate(); var time=new ATime(); if (Object.isUndefined(dt) || dt === null){ // do nothing } else if (dt=="current"){ date = "today"; time = "current"; } else if (dt instanceof Time){ if (!dt.IsIncorrect()) { var offs = typeof(dt.atime.GetTimezoneOffset) == "function" ? dt.atime.GetTimezoneOffset() : 0; var ud=new Date(Date.UTC(dt.adate.year, dt.adate.month - 1, dt.adate.day, dt.atime.hh, dt.atime.mm, dt.atime.ss) - offs * 60 * 1000); var d=new ADate(ud.getUTCFullYear(), ud.getUTCMonth()+1, ud.getUTCDate()); var t=new ATime(ud.getUTCHours(), ud.getUTCMinutes(), ud.getUTCSeconds()); dt=new Time(d,t); date=d; time=t; } } else if (["year", "month", "day", "hh", "mm", "ss"].collect(function(key) { // TODO: wipe this code, it should not be used LogE("Timestamp: should not execute this"); return !Object.isUndefined(dt[key]); }).all()){ date = time = dt; } if (this.controls_.calendar) this.controls_.calendar.SetValue(date); if (this.controls_.clock) this.controls_.clock.SetValue(time); }, onAEVENT: function(aevent){ var emitter = aevent.Emitter(); if ([this.controls_.clock, this.controls_.calendar].indexOf(emitter) !== -1){ aevent.Stop(); if (aevent.Name() === "FINALIZE" &&// emitter !== (this.time_first_ ? this.controls_.calendar : this.controls_.clock)) return; new AEvent(aevent.Name(), aevent.Data(), this); } } });