diff options
| author | ctrlaltca@gmail.com <> | 2012-03-24 21:28:08 +0000 | 
|---|---|---|
| committer | ctrlaltca@gmail.com <> | 2012-03-24 21:28:08 +0000 | 
| commit | fd1a685c494bc183adae9b1748ee79e66c4ff7c2 (patch) | |
| tree | a5f4179b4eb7efc57edcd9ce9c926077c5f3ea24 | |
| parent | e0de4ef01a644bccae872f60b3584a1755dcbc1f (diff) | |
committed alternative patch for #181
14 files changed, 400 insertions, 225 deletions
| diff --git a/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js b/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js index e187f650..2f02594f 100644 --- a/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js +++ b/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js @@ -78,9 +78,9 @@ Prado.WebUI.TActiveTextBox = Class.extend(Prado.WebUI.TTextBox,  	{
  		this.options=options;
  		if(options['TextMode'] != 'MultiLine')
 -			Event.observe(this.element, "keydown", this.handleReturnKey.bind(this));
 +			this.observe(this.element, "keydown", this.handleReturnKey.bind(this));
  		if(this.options['AutoPostBack']==true)
 -			Event.observe(this.element, "change", this.doCallback.bindEvent(this,options));
 +			this.observe(this.element, "change", this.doCallback.bindEvent(this,options));
  	},
  	doCallback : function(event, options)
 @@ -177,26 +177,25 @@ Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete,  /**
   * Time Triggered Callback class.
   */
 -Prado.WebUI.TTimeTriggeredCallback = Base.extend(
 +Prado.WebUI.TTimeTriggeredCallback = Class.create(Prado.WebUI.Control,
  {
 -	constructor : function(options)
 +	onInit : function(options)
  	{
  		this.options = Object.extend({ Interval : 1	}, options || {});
 -		Prado.WebUI.TTimeTriggeredCallback.register(this);
 -		Prado.Registry.set(options.ID, this);
 +		Prado.WebUI.TTimeTriggeredCallback.registerTimer(this);
  	},
  	startTimer : function()
  	{
  		if(typeof(this.timer) == 'undefined' || this.timer == null)
 -			this.timer = setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
 +			this.timer = this.setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
  	},
  	stopTimer : function()
  	{
  		if(typeof(this.timer) != 'undefined')
  		{
 -			clearInterval(this.timer);
 +			this.clearInterval(this.timer);
  			this.timer = null;
  		}
  	},
 @@ -205,9 +204,9 @@ Prado.WebUI.TTimeTriggeredCallback = Base.extend(  	{
  		if(typeof(this.timer) != 'undefined')
  		{
 -			clearInterval(this.timer);
 +			this.clearInterval(this.timer);
  			this.timer = null;
 -			this.timer = setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
 +			this.timer = this.setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
  		}
  	},
 @@ -217,19 +216,28 @@ Prado.WebUI.TTimeTriggeredCallback = Base.extend(  		request.dispatch();
  	},
 -	setInterval : function(value)
 +	setTimerInterval : function(value)
  	{
  		if (this.options.Interval != value){
  			this.options.Interval = value;
  			this.resetTimer();
  		}
 +	},
 +
 +	onDone: function()
 +	{
 +		this.stopTimer();
  	}
 -},
 -//class methods
 +});
 +
 +Object.extend(Prado.WebUI.TTimeTriggeredCallback, 
  {
 +
 +	//class methods
 +
  	timers : {},
 -	register : function(timer)
 +	registerTimer : function(timer)
  	{
  		Prado.WebUI.TTimeTriggeredCallback.timers[timer.options.ID] = timer;
  	},
 @@ -246,23 +254,21 @@ Prado.WebUI.TTimeTriggeredCallback = Base.extend(  			Prado.WebUI.TTimeTriggeredCallback.timers[id].stopTimer();
  	},
 -	setInterval : function (id,value)
 +	setTimerInterval : function (id,value)
  	{
  		if(Prado.WebUI.TTimeTriggeredCallback.timers[id])
 -			Prado.WebUI.TTimeTriggeredCallback.timers[id].setInterval(value);
 +			Prado.WebUI.TTimeTriggeredCallback.timers[id].setTimerInterval(value);
  	}
  });
 -Prado.WebUI.ActiveListControl = Base.extend(
 +Prado.WebUI.ActiveListControl = Class.create(Prado.WebUI.Control,
  {
 -	constructor : function(options)
 +	onInit : function(options)
  	{
 -		this.element = $(options.ID);
 -		Prado.Registry.set(options.ID, this);
  		if(this.element)
  		{
  			this.options = options;
 -			Event.observe(this.element, "change", this.doCallback.bind(this));
 +			this.observe(this.element, "change", this.doCallback.bind(this));
  		}
  	},
 @@ -274,20 +280,19 @@ Prado.WebUI.ActiveListControl = Base.extend(  	}
  });
 -Prado.WebUI.TActiveDropDownList = Prado.WebUI.ActiveListControl;
 -Prado.WebUI.TActiveListBox = Prado.WebUI.ActiveListControl;
 +Prado.WebUI.TActiveDropDownList = Class.create(Prado.WebUI.ActiveListControl);
 +Prado.WebUI.TActiveListBox = Class.create(Prado.WebUI.ActiveListControl);
  /**
   * Observe event of a particular control to trigger a callback request.
   */
 -Prado.WebUI.TEventTriggeredCallback = Base.extend(
 +Prado.WebUI.TEventTriggeredCallback = Class.create(Prado.WebUI.Control,
  {
 -	constructor : function(options)
 +	onInit : function(options)
  	{
 -		this.options = options;
  		var element = $(options['ControlID']);
  		if(element)
 -			Event.observe(element, this.getEventName(element), this.doCallback.bind(this));
 +			this.observe(element, this.getEventName(element), this.doCallback.bind(this));
  	},
  	getEventName : function(element)
 @@ -320,32 +325,30 @@ Prado.WebUI.TEventTriggeredCallback = Base.extend(  /**
   * Observe changes to a property of a particular control to trigger a callback.
   */
 -Prado.WebUI.TValueTriggeredCallback = Base.extend(
 +Prado.WebUI.TValueTriggeredCallback = Class.create(Prado.WebUI.Control,
  {
  	count : 1,
  	observing : true,
 -	constructor : function(options)
 +	onInit : function(options)
  	{
 -		this.options = options;
  		this.options.PropertyName = this.options.PropertyName || 'value';
  		var element = $(options['ControlID']);
  		this.value = element ? element[this.options.PropertyName] : undefined;
  		Prado.WebUI.TValueTriggeredCallback.register(this);
 -		Prado.Registry.set(options.ID, this);
  		this.startObserving();
  	},
  	stopObserving : function()
  	{
 -		clearTimeout(this.timer);
 +		this.clearTimeout(this.timer);
  		this.observing = false;
  	},
  	startObserving : function()
  	{
 -		this.timer = setTimeout(this.checkChanges.bind(this), this.options.Interval*1000);
 +		this.timer = this.setTimeout(this.checkChanges.bind(this), this.options.Interval*1000);
  	},
  	checkChanges : function()
 @@ -363,7 +366,7 @@ Prado.WebUI.TValueTriggeredCallback = Base.extend(  			else
  				this.count = this.count + this.options.Decay;
  			if(this.observing)
 -				this.time = setTimeout(this.checkChanges.bind(this),
 +				this.time = this.setTimeout(this.checkChanges.bind(this),
  					parseInt(this.options.Interval*1000*this.count));
  		}
  	},
 @@ -374,10 +377,19 @@ Prado.WebUI.TValueTriggeredCallback = Base.extend(  		var param = {'OldValue' : oldValue, 'NewValue' : newValue};
  		request.setCallbackParameter(param);
  		request.dispatch();
 +	},
 +
 +	onDone : function()
 +	{
 +		if (this.observing)
 +			this.stopObserving();
  	}
 -},
 -//class methods
 +});
 +
 +Object.extend(Prado.WebUI.TTimeTriggeredCallback, 
  {
 +	//class methods
 +
  	timers : {},
  	register : function(timer)
 @@ -391,5 +403,5 @@ Prado.WebUI.TValueTriggeredCallback = Base.extend(  	}
  });
 -Prado.WebUI.TActiveTableCell = Class.extend(Prado.WebUI.CallbackControl);
 -Prado.WebUI.TActiveTableRow = Class.extend(Prado.WebUI.CallbackControl);
 +Prado.WebUI.TActiveTableCell = Class.create(Prado.WebUI.CallbackControl);
 +Prado.WebUI.TActiveTableRow = Class.create(Prado.WebUI.CallbackControl);
 diff --git a/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js b/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js index 8857ee05..a04a0243 100755 --- a/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js +++ b/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js @@ -1,9 +1,9 @@  /**
   * TActiveDatePicker control
   */
 -Prado.WebUI.TActiveDatePicker = Class.extend(Prado.WebUI.TDatePicker,
 +Prado.WebUI.TActiveDatePicker = Class.create(Prado.WebUI.TDatePicker,
  {
 -	initialize : function(options)
 +	onInit : function(options)
  	{
  		this.options = options || [];
  		this.control = $(options.ID);
 @@ -14,9 +14,6 @@ Prado.WebUI.TActiveDatePicker = Class.extend(Prado.WebUI.TDatePicker,  		this.positionMode = 'Bottom';
 -		// Issue 181
 -		$(this.control).stopObserving();
 -        
  		//which element to trigger to show the calendar
  		if(this.options.Trigger)
  		{
 @@ -29,10 +26,6 @@ Prado.WebUI.TActiveDatePicker = Class.extend(Prado.WebUI.TDatePicker,  			var triggerEvent = this.options.TriggerEvent || "focus";
  		}
 -		// Issue 181
 -		if(this.trigger)
 -			$(this.trigger).stopObserving();
 -		
  		// Popup position
  		if(this.options.PositionMode == 'Top')
  		{
 @@ -42,21 +35,21 @@ Prado.WebUI.TActiveDatePicker = Class.extend(Prado.WebUI.TDatePicker,  		Object.extend(this,options);
  		if (this.options.ShowCalendar)
 -			Event.observe(this.trigger, triggerEvent, this.show.bindEvent(this));
 +			this.observe(this.trigger, triggerEvent, this.show.bindEvent(this));
  		// Listen to change event 
  		if(this.options.InputMode == "TextBox")
  		{
 -			Event.observe(this.control, "change", this.onDateChanged.bindEvent(this));
 +			this.observe(this.control, "change", this.onDateChanged.bindEvent(this));
  		} 
  		else
  		{
  			var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
  			var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
  			var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
 -			if (day) Event.observe (day, "change", this.onDateChanged.bindEvent(this));
 -			if (month) Event.observe (month, "change", this.onDateChanged.bindEvent(this));
 -			if (year) Event.observe (year, "change", this.onDateChanged.bindEvent(this));
 +			if (day) this.observe (day, "change", this.onDateChanged.bindEvent(this));
 +			if (month) this.observe (month, "change", this.onDateChanged.bindEvent(this));
 +			if (year) this.observe (year, "change", this.onDateChanged.bindEvent(this));
  		}
 diff --git a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js index 2d410375..11eec5a4 100644 --- a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js +++ b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js @@ -248,6 +248,8 @@ Object.extend(Prado.CallbackRequest,  			{
  				if(typeof(Logger) != "undefined")
  					self.Exception.onException(null,e);
 +				else
 +					debugger;
  			}
  		}
  	},
 diff --git a/framework/Web/Javascripts/source/prado/activecontrols/dragdrop.js b/framework/Web/Javascripts/source/prado/activecontrols/dragdrop.js index efec6a69..59c62cc2 100755 --- a/framework/Web/Javascripts/source/prado/activecontrols/dragdrop.js +++ b/framework/Web/Javascripts/source/prado/activecontrols/dragdrop.js @@ -2,11 +2,9 @@   * DropContainer control
   */
 -Prado.WebUI.DropContainer = Class.extend(Prado.WebUI.CallbackControl);
 -
 -Object.extend(Prado.WebUI.DropContainer.prototype,
 +Prado.WebUI.DropContainer = Class.create(Prado.WebUI.CallbackControl,
  {
 -	initialize: function(options)
 +	onInit: function(options)
  	{
  		this.options = options;
  		Object.extend (this.options, 
 @@ -15,7 +13,6 @@ Object.extend(Prado.WebUI.DropContainer.prototype,  		});
  		Droppables.add (options.ID, this.options);
 -		Prado.Registry.set(options.ID, this);
  	},
  	onDrop: function(dragElement, dropElement, event)
 diff --git a/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js b/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js index 74d45515..a53ac8fd 100644 --- a/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js +++ b/framework/Web/Javascripts/source/prado/activecontrols/inlineeditor.js @@ -1,6 +1,6 @@ -Prado.WebUI.TInPlaceTextBox = Base.extend(
 +Prado.WebUI.TInPlaceTextBox = Class.create(Prado.WebUI.Control,
  {
 -	constructor : function(options)
 +	onInit : function(options)
  	{
  		this.isSaving = false;
 @@ -18,8 +18,6 @@ Prado.WebUI.TInPlaceTextBox = Base.extend(  		Prado.WebUI.TInPlaceTextBox.register(this);
  		this.createEditorInput();
  		this.initializeListeners();
 -
 -		Prado.Registry.set(options.ID, this);
  	},
  	/**
 @@ -28,13 +26,9 @@ Prado.WebUI.TInPlaceTextBox = Base.extend(  	initializeListeners : function()
  	{
  		this.onclickListener = this.enterEditMode.bindAsEventListener(this);
 -		Event.observe(this.element, 'click', this.onclickListener);
 +		this.observe(this.element, 'click', this.onclickListener);
  		if (this.options.ExternalControl)
 -		{
 -			// Issue 181
 -			$(this.options.ExternalControl).stopObserving('click', this.onclickListener);
 -			Event.observe($(this.options.ExternalControl), 'click', this.onclickListener);
 -		}
 +			this.observe($(this.options.ExternalControl), 'click', this.onclickListener);
  	},
  	/**
 @@ -132,13 +126,10 @@ Prado.WebUI.TInPlaceTextBox = Base.extend(  		this.editField.style.display="none";
  		this.element.parentNode.insertBefore(this.editField,this.element)
 -        // Issue 181
 -        $(this.editField).stopObserving();
 -        
  		//handle return key within single line textbox
  		if(this.options.TextMode == 'SingleLine')
  		{
 -			Event.observe(this.editField, "keydown", function(e)
 +			this.observe(this.editField, "keydown", function(e)
  			{
  				 if(Event.keyCode(e) == Event.KEY_RETURN)
  		        {
 @@ -152,8 +143,8 @@ Prado.WebUI.TInPlaceTextBox = Base.extend(  			});
  		}
 -		Event.observe(this.editField, "blur", this.onTextBoxBlur.bind(this));
 -		Event.observe(this.editField, "keypress", this.onKeyPressed.bind(this));
 +		this.observe(this.editField, "blur", this.onTextBoxBlur.bind(this));
 +		this.observe(this.editField, "keypress", this.onKeyPressed.bind(this));
  	},
  	/**
 @@ -272,8 +263,13 @@ Prado.WebUI.TInPlaceTextBox = Base.extend(  		if(typeof(this.options.onFailure)=="function")
  			this.options.onFailure(sender,parameter);
  	}
 -},
 +});
 +
 +
 +Object.extend(Prado.WebUI.TInPlaceTextBox, 
  {
 +	//class methods
 +
  	textboxes : {},
  	register : function(obj)
 diff --git a/framework/Web/Javascripts/source/prado/activefileupload/activefileupload.js b/framework/Web/Javascripts/source/prado/activefileupload/activefileupload.js index e25b5bed..b16179c0 100755 --- a/framework/Web/Javascripts/source/prado/activefileupload/activefileupload.js +++ b/framework/Web/Javascripts/source/prado/activefileupload/activefileupload.js @@ -1,6 +1,6 @@ -Prado.WebUI.TActiveFileUpload = Base.extend( +Prado.WebUI.TActiveFileUpload = Class.create(Prado.WebUI.Control,  { -	constructor : function(options) +	onInit : function(options)  	{  		this.options = options || {};  		Prado.WebUI.TActiveFileUpload.register(this); @@ -13,11 +13,9 @@ Prado.WebUI.TActiveFileUpload = Base.extend(  		this.complete = $(options.completeID);  		this.error = $(options.errorID); -		Prado.Registry.set(options.inputID, this); -  		// set up events  		if (options.autoPostBack){ -			Event.observe(this.input,"change",this.fileChanged.bind(this)); +			this.observe(this.input,"change",this.fileChanged.bind(this));  		}  	}, @@ -74,9 +72,12 @@ Prado.WebUI.TActiveFileUpload = Base.extend(         		}  	} -}, +}); + +Object.extend(Prado.WebUI.TActiveFileUpload,   { -// class methods +	//class methods +  	controls : {},  	register : function(control) diff --git a/framework/Web/Javascripts/source/prado/controls/accordion.js b/framework/Web/Javascripts/source/prado/controls/accordion.js index e6af5e2e..90d01316 100644 --- a/framework/Web/Javascripts/source/prado/controls/accordion.js +++ b/framework/Web/Javascripts/source/prado/controls/accordion.js @@ -7,16 +7,8 @@   * http://creativecommons.org/licenses/by-sa/3.0/us/   */ -Prado.WebUI.TAccordion = Class.create(); -Prado.WebUI.TAccordion.prototype = +Prado.WebUI.TAccordion = Class.create(Prado.WebUI.Control,  { -	initialize : function(options) -	{ -		this.element = $(options.ID); -		this.onInit(options); -		Prado.Registry.set(options.ID, this); -	}, -      	onInit : function(options)  	{  		this.accordion = $(options.ID); @@ -40,8 +32,7 @@ Prado.WebUI.TAccordion.prototype =  			var header = $(view+'_0');  			if(header)  			{ -				Event.stopObserving(header, "click"); -				Event.observe(header, "click", this.elementClicked.bindEvent(this,view)); +				this.observe(header, "click", this.elementClicked.bindEvent(this,view));  				if(this.hiddenField.value == i)  				{  					this.currentView = view; @@ -175,5 +166,5 @@ Prado.WebUI.TAccordion.prototype =  			}.bind(this)  		});  	} -}; +}); diff --git a/framework/Web/Javascripts/source/prado/controls/controls.js b/framework/Web/Javascripts/source/prado/controls/controls.js index 9dadff18..42fc77ff 100644 --- a/framework/Web/Javascripts/source/prado/controls/controls.js +++ b/framework/Web/Javascripts/source/prado/controls/controls.js @@ -1,33 +1,248 @@  Prado.WebUI = Class.create();
 -Prado.WebUI.PostBackControl = Class.create();
 +Prado.WebUI.Control = Class.create({
 -Prado.WebUI.PostBackControl.prototype =
 -{
  	initialize : function(options)
  	{
 -	
 -		this._elementOnClick = null, //capture the element's onclick function
 +	        this.registered = false;
 +		this.ID = options.ID;
 +		this.element = $(this.ID);
 +		this.observers = new Array();
 +		this.intervals = new Array();
 +		var e;
 +		if (e = Prado.Registry.get(this.ID))
 +			this.replace(e, options);
 +		else
 +			this.register(options);
 -		this.element = $(options.ID);
 -		Prado.Registry.set(options.ID, this);
 -		if(this.element)
 +		if (this === Prado.Registry.get(this.ID))
  		{
 -			// Issue 181
 -		    this.element.stopObserving();
 +			this.registered = true;
  			if(this.onInit)
  				this.onInit(options);
  		}
  	},
 -	onInit : function(options)
 +	/**
 +	 * Registers the control wrapper in the Prado client side control registry
 +	 * @param array control wrapper options
 +	 */
 +	register : function(options)
  	{
 -		if(typeof(this.element.onclick)=="function")
 -		{
 -			this._elementOnClick = this.element.onclick.bind(this.element);
 -			this.element.onclick = null;
 +		return Prado.Registry.set(options.ID, this);
 +	},
 +
 +	/**
 +	 * De-registers the control wrapper in the Prado client side control registry
 +	 */
 +	deregister : function()
 +	{
 +		// extra check so we don't ever deregister another wrapper
 +		if (Prado.Registry.get(this.ID)===this)
 +			return Prado.Registry.unset(this.ID);
 +		else
 +			debugger; // invoke debugger - this should never happen
 +	},
 +
 +	/**
 +	 * Replaces and control wrapper for an already existing control in the Prado client side control registry
 +	 * @param object reference to the old wrapper
 +	 * @param array control wrapper options
 +	 */
 +	replace : function(oldwrapper, options)
 +	{
 +		// if there's some advanced state management in the wrapper going on, then
 +		// this method could be used either to copy the current state of the control
 +		// from the old wrapper to this new one (which then could live on, while the old
 +		// one could get destroyed), or to copy the new, changed options to the old wrapper,
 +		// (which could then left intact to keep working, while this new wrapper could be
 +		// disposed of by exiting its initialization without installing any handlers or 
 +		// leaving any references to it)
 +		//
 +
 +		// for now this method is simply deinitializing and deregistering the old wrapper, 
 +		// and then registering the new wrapper for the control id
 +
 +		if (oldwrapper.deinitialize)
 +			oldwrapper.deinitialize();
 +
 +		return this.register(options);
 +	},
 +
 +	/**
 +	 * Registers an event observer which will be automatically disposed of when the wrapper 
 +	 * is deregistered
 +	 * @param element DOM element reference or id to attach the event handler to
 +	 * @param string event name to observe
 +         * @param handler event handler function
 +	 */
 +	observe: function(element, eventName, handler)
 +	{
 +		var e = { _element: element, _eventName: eventName, _handler: handler };
 +		this.observers.push(e);
 +		return Event.observe(e._element,e._eventName,e._handler);
 +	},
 +
 +	/**
 +	 * Checks whether an event observer is installed and returns its index
 +	 * @param element DOM element reference or id the event handler was attached to
 +	 * @param string event name observed
 +         * @param handler event handler function
 +	 * @result int false if the event handler is not installed, or 1-based index when installed
 +	 */
 +	findObserver: function(element, eventName, handler)
 +	{
 +		var e = { _element: element, _eventName: eventName, _handler: handler };
 +		var idx = -1;
 +		for(var i=0;i<this.observers.length;i++)
 +		{	
 +			var o = this.observers[i];
 +			if ((o._element===element) && (o._eventName===eventName) && (o._handler===handler))
 +			{
 +				idx = i;
 +				break;
 +			}
  		}
 -		Event.observe(this.element, "click", this.elementClicked.bindEvent(this,options));
 +		return idx;
 +	},
 +	
 +
 +	/**
 +	 * Degisters an event observer from the list of automatically disposed handlers
 +	 * @param element DOM element reference or id the event handler was attached to
 +	 * @param string event name observed
 +         * @param handler event handler function
 +	 */
 +	stopObserving: function(element, eventName, handler)
 +	{
 +		var idx = this.findObserver(element,eventName,handler);
 +		if (idx!=-1)
 +			this.observers = this.observers.without(this.observers[idx]);
 +		else
 +			debugger; // shouldn't happen
 +
 +		return Event.stopObserving(element,eventName,handler);
 +	},
 +
 +	/**
 +	 * Registers a code snippet or function to be executed after a delay, if the
 +	 * wrapper hasn't been destroyed in the meantime
 +	 * @param code function or code snippet to execute
 +	 * @param int number of milliseconds to wait before executing
 +	 * @return int unique ID that can be used to cancel the scheduled execution 
 +	 */
 +	setTimeout: function(func, delay)
 +	{
 +		if (!Object.isFunction(func)) 
 +		{
 +			var expr = func;
 +			func = function() { return eval(expr); }
 +		};
 +		var obj = this;
 +		return window.setTimeout(function() {
 +			if (!obj.isLingering())
 +				func();
 +			obj = null;
 +		},delay);
 +	},
 +
 +	/**
 +	 * Cancels a previously scheduled code snippet or function
 +	 * @param int unique ID returned by setTimeout()
 +	 */
 +	clearTimeout: function(timeoutid)
 +	{
 +		return window.clearTimeout(timeoutid);
 +	},
 +
 +	/**
 +	 * Registers a code snippet or function to be executed periodically, up until the
 +	 * wrapper gets destroyed or the schedule cancelled using cancelInterval()
 +	 * @param code function or code snippet to execute
 +	 * @param int number of milliseconds to wait before executing
 +	 * @return int unique ID that can be used to cancel the interval (see clearInterval() method)
 +	 */
 +	setInterval: function(func, delay)
 +	{
 +		if (!Object.isFunction(func)) func = function() { eval(func); };
 +		var obj = this;
 +		var h = window.setInterval(function() {
 +			if (!obj.isLingering())
 +				func();
 +		},delay);
 +		this.intervals.push(h);
 +		return h;
 +	},
 +
 +	/**
 +	 * Deregisters a snipper or function previously registered with setInterval()
 +	 * @param int unique ID of interval (returned by setInterval() previously)
 +	 */
 +	clearInterval: function(intervalid)
 +	{
 +		window.clearInterval(intervalid);
 +		this.intervals = this.intervals.without(intervalid);
 +	},
 +
 +	/**
 +	 * Tells whether this is a wrapper that has already been deregistered and is lingering
 +	 * @return bool true if object
 +	 */
 +	isLingering: function()
 +	{
 +		return !this.registered;
 +	},
 +
 +	/**
 +	 * Deinitializes the control wrapper by calling the onDone method and the deregistering it
 +	 * @param array control wrapper options
 +	 */
 +	deinitialize : function()
 +	{
 +		if (this.registered)
 +			{
 +				if(this.onDone)
 +					this.onDone();
 +
 +				// automatically stop all intervals
 +				while (this.intervals.length>0)	
 +					window.clearInterval(this.intervals.pop());
 +
 +				// automatically deregister all installed observers
 +				while (this.observers.length>0)	
 +				{
 +					var e = this.observers.pop();
 +					Event.stopObserving(e._element,e._eventName,e._handler);
 +				}
 +			}
 +		else
 +			debugger; // shouldn't happen
 +
 +		this.deregister();
 +
 +		this.registered = false;
 +	}
 +
 +});
 +
 +Prado.WebUI.PostBackControl = Class.create(Prado.WebUI.Control, {
 +
 +	onInit : function(options)
 +	{
 +		this._elementOnClick = null;
 +
 +		if (!this.element) 
 +			debugger; // element not found
 +		else
 +			{
 +				//capture the element's onclick function
 +				if(typeof(this.element.onclick)=="function")
 +				{
 +					this._elementOnClick = this.element.onclick.bind(this.element);
 +					this.element.onclick = null;
 +				}
 +				this.observe(this.element, "click", this.elementClicked.bindEvent(this,options));
 +			}
  	},
  	elementClicked : function(event, options)
 @@ -52,20 +267,20 @@ Prado.WebUI.PostBackControl.prototype =  	{
  		Prado.PostBack(event,options);
  	}
 -};
 -Prado.WebUI.TButton = Class.extend(Prado.WebUI.PostBackControl);
 -Prado.WebUI.TLinkButton = Class.extend(Prado.WebUI.PostBackControl);
 -Prado.WebUI.TCheckBox = Class.extend(Prado.WebUI.PostBackControl);
 -Prado.WebUI.TBulletedList = Class.extend(Prado.WebUI.PostBackControl);
 -Prado.WebUI.TImageMap = Class.extend(Prado.WebUI.PostBackControl);
 +});
 +
 +Prado.WebUI.TButton = Class.create(Prado.WebUI.PostBackControl);
 +Prado.WebUI.TLinkButton = Class.create(Prado.WebUI.PostBackControl);
 +Prado.WebUI.TCheckBox = Class.create(Prado.WebUI.PostBackControl);
 +Prado.WebUI.TBulletedList = Class.create(Prado.WebUI.PostBackControl);
 +Prado.WebUI.TImageMap = Class.create(Prado.WebUI.PostBackControl);
  /**
   * TImageButton client-side behaviour. With validation, Firefox needs
   * to capture the x,y point of the clicked image in hidden form fields.
   */
 -Prado.WebUI.TImageButton = Class.extend(Prado.WebUI.PostBackControl);
 -Object.extend(Prado.WebUI.TImageButton.prototype,
 +Prado.WebUI.TImageButton = Class.create(Prado.WebUI.PostBackControl, 
  {
  	/**
  	 * Override parent onPostBack function, tried to add hidden forms
 @@ -131,31 +346,29 @@ Object.extend(Prado.WebUI.TImageButton.prototype,  /**
   * Radio button, only initialize if not already checked.
   */
 -Prado.WebUI.TRadioButton = Class.extend(Prado.WebUI.PostBackControl);
 -Prado.WebUI.TRadioButton.prototype.onRadioButtonInitialize = Prado.WebUI.TRadioButton.prototype.initialize;
 -Object.extend(Prado.WebUI.TRadioButton.prototype,
 +Prado.WebUI.TRadioButton = Class.create(Prado.WebUI.PostBackControl,
  {
 -	initialize : function(options)
 +	initialize : function($super, options)
  	{
  		this.element = $(options['ID']);
  		if(this.element)
  		{
  			if(!this.element.checked)
 -				this.onRadioButtonInitialize(options);
 +				$super(options);
  		}
  	}
  });
 -Prado.WebUI.TTextBox = Class.extend(Prado.WebUI.PostBackControl,
 +Prado.WebUI.TTextBox = Class.create(Prado.WebUI.PostBackControl,
  {
  	onInit : function(options)
  	{
  		this.options=options;
 -		if(options['TextMode'] != 'MultiLine')
 -			Event.observe(this.element, "keydown", this.handleReturnKey.bind(this));
 +		if(this.options['TextMode'] != 'MultiLine')
 +			this.observe(this.element, "keydown", this.handleReturnKey.bind(this));
  		if(this.options['AutoPostBack']==true)
 -			Event.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
 +			this.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
  	},
  	handleReturnKey : function(e)
 @@ -183,27 +396,23 @@ Prado.WebUI.TTextBox = Class.extend(Prado.WebUI.PostBackControl,  	}
  });
 -Prado.WebUI.TListControl = Class.extend(Prado.WebUI.PostBackControl,
 +Prado.WebUI.TListControl = Class.create(Prado.WebUI.PostBackControl,
  {
  	onInit : function(options)
  	{
 -		Event.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
 +		this.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
  	}
  });
 -Prado.WebUI.TListBox = Class.extend(Prado.WebUI.TListControl);
 -Prado.WebUI.TDropDownList = Class.extend(Prado.WebUI.TListControl);
 +Prado.WebUI.TListBox = Class.create(Prado.WebUI.TListControl);
 +Prado.WebUI.TDropDownList = Class.create(Prado.WebUI.TListControl);
 -Prado.WebUI.DefaultButton = Class.create();
 -Prado.WebUI.DefaultButton.prototype =
 +Prado.WebUI.DefaultButton = Class.create(Prado.WebUI.Control,
  {
 -	initialize : function(options)
 +	onInit : function(options)
  	{
 -        // Issue 181
 -		$(options['Panel']).stopObserving();
  		this.options = options;
 -		this._event = this.triggerEvent.bindEvent(this);
 -		Event.observe(options['Panel'], 'keydown', this._event);
 +		this.observe(options['Panel'], 'keydown', this.triggerEvent.bindEvent(this));
  	},
  	triggerEvent : function(ev, target)
 @@ -223,10 +432,10 @@ Prado.WebUI.DefaultButton.prototype =  			}
  		}
  	}
 -};
 +});
 -Prado.WebUI.TTextHighlighter=Class.create();
 -Prado.WebUI.TTextHighlighter.prototype=
 +Prado.WebUI.TTextHighlighter = Class.create();
 +Prado.WebUI.TTextHighlighter.prototype =
  {
  	initialize:function(id)
  	{
 diff --git a/framework/Web/Javascripts/source/prado/controls/htmlarea.js b/framework/Web/Javascripts/source/prado/controls/htmlarea.js index 5ee01c05..595b7928 100644 --- a/framework/Web/Javascripts/source/prado/controls/htmlarea.js +++ b/framework/Web/Javascripts/source/prado/controls/htmlarea.js @@ -8,12 +8,12 @@  */
 -Prado.WebUI.THtmlArea = Class.create();
 -Prado.WebUI.THtmlArea.prototype =
 +Prado.WebUI.THtmlArea = Class.create(Prado.WebUI.Control,
  {
 -	initialize : function(options)
 +	initialize: function($super, options)
  	{
 -		this.onInit(options);
 +		options.ID = options.elements;
 +		$super(options);
  	},
      	onInit : function(options)
 @@ -22,20 +22,14 @@ Prado.WebUI.THtmlArea.prototype =  			throw "TinyMCE libraries must be loaded first";
  		this.options = options;
 -		this.id = options.elements;
 -
 -		var p = Prado.Registry.get(this.id);
 -		if (p) p.deinitialize();
  		tinyMCE.init(options);
 -		Prado.Registry.set(this.id, this);
 -
  		var obj = this;
  		this.ajaxresponder = {
  			onComplete : function(request) 
  			{
 -				if(request && request instanceof Prado.AjaxRequest)
 +				if(request && (request instanceof Prado.AjaxRequest))
  					obj.checkInstance();
  			}
  		};
 @@ -44,18 +38,18 @@ Prado.WebUI.THtmlArea.prototype =  	checkInstance: function()
  	{
 -		if (!document.getElementById(this.id))
 +		if (!document.getElementById(this.ID))
  			this.deinitialize();
  	},
  	removePreviousInstance: function()
  	{
  		for(var i=0;i<tinyMCE.editors.length;i++)
 -			if (tinyMCE.editors[i].id==this.id)
 +			if (tinyMCE.editors[i].id==this.ID)
  			{
 -				tinyMCE.editors = tinyMCE.editors.slice(0,i-1).concat(tinyMCE.editors.slice(i+1)); // ugly hack, but works
 +				tinyMCE.editors.splice(i,1); // ugly hack, but works
  				this.deRegisterAjaxHook();
 -				Prado.Registry.unset(this.id);
 +				this.deregister();
  				i--;
  			}
  	},
 @@ -75,15 +69,15 @@ Prado.WebUI.THtmlArea.prototype =  				Ajax.Responders.unregister(this.ajaxresponder);
  	},
 -	deinitialize: function()
 +	onDone: function()
  	{
  		// check for previous tinyMCE registration, and try to remove it gracefully first
 -		var prev = tinyMCE.get(this.id);
 +		var prev = tinyMCE.get(this.ID);
  		if (prev)
  		try
  		{
 -			tinyMCE.execCommand('mceFocus', false, this.id); 
 -			tinyMCE.execCommand('mceRemoveControl', false, this.id);
 +			tinyMCE.execCommand('mceFocus', false, this.ID); 
 +			tinyMCE.execCommand('mceRemoveControl', false, this.ID);
  		}
  		catch (e) 
  		{
 @@ -96,5 +90,5 @@ Prado.WebUI.THtmlArea.prototype =  		this.deRegisterAjaxHook();
  	}
 -}
 +});
 diff --git a/framework/Web/Javascripts/source/prado/controls/keyboard.js b/framework/Web/Javascripts/source/prado/controls/keyboard.js index b808a46c..5b8a6b15 100644 --- a/framework/Web/Javascripts/source/prado/controls/keyboard.js +++ b/framework/Web/Javascripts/source/prado/controls/keyboard.js @@ -1,13 +1,5 @@ -Prado.WebUI.TKeyboard = Class.create();
 -Prado.WebUI.TKeyboard.prototype =
 +Prado.WebUI.TKeyboard = Class.create(Prado.WebUI.Control,
  {
 -	initialize : function(options)
 -	{
 -		this.element = $(options.ID);
 -		this.onInit(options);
 -		Prado.Registry.set(options.ID, this);
 -	},
 -
  	onInit : function(options)
      {
  		this.cssClass = options['CssClass'];
 @@ -166,4 +158,4 @@ Prado.WebUI.TKeyboard.prototype =              this.forControl.selectionEnd = selectStart + value.length;
          }
      }
 -};
 +});
 diff --git a/framework/Web/Javascripts/source/prado/controls/slider.js b/framework/Web/Javascripts/source/prado/controls/slider.js index f4c9b2f3..2e26ee51 100644 --- a/framework/Web/Javascripts/source/prado/controls/slider.js +++ b/framework/Web/Javascripts/source/prado/controls/slider.js @@ -19,13 +19,6 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl,  		this.minimum   = this.options.minimum || this.range.start;  		this.hiddenField=$(this.options.ID+'_1'); -		// Issue 181 -		this.element.stopObserving(); -		this.track.stopObserving(); -		this.handle.stopObserving(); -		if (this.progress) this.progress.stopObserving(); -		this.hiddenField.stopObserving(); -		  		// Will be used to align the handle onto the track, if necessary  		this.alignX = parseInt(this.options.alignX || - this.track.offsetLeft);  		this.alignY = parseInt(this.options.alignY || - this.track.offsetTop); @@ -57,34 +50,22 @@ Prado.WebUI.TSlider = Class.extend(Prado.WebUI.PostBackControl,  		// Initialize handle  		this.setValue(parseFloat(slider.options.sliderValue));  		Element.makePositioned(this.handle); // fix IE -		Event.observe (this.handle, "mousedown", this.eventMouseDown); +		this.observe (this.handle, "mousedown", this.eventMouseDown); -		Event.observe (this.track, "mousedown", this.eventMouseDown); -		if (this.progress) Event.observe (this.progress, "mousedown", this.eventMouseDown); +		this.observe (this.track, "mousedown", this.eventMouseDown); +		if (this.progress) this.observe (this.progress, "mousedown", this.eventMouseDown); -		// Issue 181 -		document.stopObserving("mouseup", this.eventMouseUp); -		document.stopObserving("mousemove", this.eventMouseMove); -		Event.observe (document, "mouseup", this.eventMouseUp); -		Event.observe (document, "mousemove", this.eventMouseMove); +		this.observe (document, "mouseup", this.eventMouseUp); +		this.observe (document, "mousemove", this.eventMouseMove);  		this.initialized=true;  		if(this.options['AutoPostBack']==true) -			Event.observe(this.hiddenField, "change", Prado.PostBack.bindEvent(this,options)); +			this.observe(this.hiddenField, "change", Prado.PostBack.bindEvent(this,options));  	}, -	dispose: function() { -		var slider = this;     -		Event.stopObserving(this.track, "mousedown", this.eventMouseDown); -		Event.stopObserving(document, "mouseup", this.eventMouseUp); -		Event.stopObserving(document, "mousemove", this.eventMouseMove); -	 -		Event.stopObserving(this.handle, "mousedown", slider.eventMouseDown); - 	}, - 	  	setDisabled: function(){  		this.disabled = true;  	}, diff --git a/framework/Web/Javascripts/source/prado/controls/tabpanel.js b/framework/Web/Javascripts/source/prado/controls/tabpanel.js index f613a677..900dfcb3 100644 --- a/framework/Web/Javascripts/source/prado/controls/tabpanel.js +++ b/framework/Web/Javascripts/source/prado/controls/tabpanel.js @@ -1,13 +1,5 @@ -Prado.WebUI.TTabPanel = Class.create();
 -Prado.WebUI.TTabPanel.prototype =
 +Prado.WebUI.TTabPanel = Class.create(Prado.WebUI.Control,
  {
 -	initialize : function(options)
 -	{
 -		this.element = $(options.ID);
 -		this.onInit(options);
 -		Prado.Registry.set(options.ID, this);
 -	},
 -
  	onInit : function(options)
  	{
  		this.views = options.Views;
 @@ -20,21 +12,22 @@ Prado.WebUI.TTabPanel.prototype =  		{
  			var item = options.Views[i];
  			var element = $(item+'_0');
 -			if (options.ViewsVis[i])
 -			{
 -				Event.observe(element, "click", this.elementClicked.bindEvent(this,item));
 -			}
 +			if (element)
 +			 if (options.ViewsVis[i])
 +				this.observe(element, "click", this.elementClicked.bindEvent(this,item));
  			if(element)
  			{
 -				if(this.hiddenField.value == i)
 -				{
 -					element.className=this.activeCssClass;
 -					$(options.Views[i]).show();
 -				} else {
 -					element.className=this.normalCssClass;
 -					$(options.Views[i]).hide();
 -				}
 +				var view = $(options.Views[i]);
 +				if (view)
 +					if(this.hiddenField.value == i)
 +					{
 +						element.className=this.activeCssClass;
 +						view.show();
 +					} else {
 +						element.className=this.normalCssClass;
 +						view.hide();
 +					}
  			}
  		}
  	},
 @@ -61,4 +54,4 @@ Prado.WebUI.TTabPanel.prototype =  			}
  		}
  	}
 -};
 +});
 diff --git a/framework/Web/Javascripts/source/prado/scriptaculous-adapter.js b/framework/Web/Javascripts/source/prado/scriptaculous-adapter.js index 4dba8e0e..23b49f56 100644 --- a/framework/Web/Javascripts/source/prado/scriptaculous-adapter.js +++ b/framework/Web/Javascripts/source/prado/scriptaculous-adapter.js @@ -294,6 +294,7 @@ Prado.Element =  			}
  			catch(e)
  			{
 +				debugger;
  				throw "Error in evaluating '"+value+"' for attribute "+attribute+" for element "+element.id;
  			}
  		}
 @@ -451,7 +452,18 @@ Prado.Element =  	 */
  	evaluateScript : function(content)
  	{
 -		content.evalScripts();
 +		try
 +		{
 +			content.evalScripts();
 +		}
 +		catch(e)
 +		{
 +			if(typeof(Logger) != "undefined")
 +				Logger.error('Error during evaluation of script "'+content+'"');
 +			else
 +				debugger;
 +			throw e;
 +		}
  	},
  	/**
 diff --git a/framework/Web/Javascripts/source/prado/validator/validation3.js b/framework/Web/Javascripts/source/prado/validator/validation3.js index 7cbb5e65..597b4b5b 100644 --- a/framework/Web/Javascripts/source/prado/validator/validation3.js +++ b/framework/Web/Javascripts/source/prado/validator/validation3.js @@ -776,8 +776,7 @@ Prado.WebUI.TValidationSummary.prototype =   * 
   * @class Prado.WebUI.TBaseValidator
   */
 -Prado.WebUI.TBaseValidator = Class.create();
 -Prado.WebUI.TBaseValidator.prototype =
 +Prado.WebUI.TBaseValidator = Class.create(Prado.WebUI.Control,
  {
  	/**
  	 * Initialize TBaseValidator.
 @@ -800,6 +799,9 @@ Prado.WebUI.TBaseValidator.prototype =  	 */
  	initialize : function(options)
  	{
 +		this.observers = new Array();
 +		this.intervals = new Array();
 +
  	/*	options.OnValidate = options.OnValidate || Prototype.emptyFunction;
  		options.OnSuccess = options.OnSuccess || Prototype.emptyFunction;
  		options.OnError = options.OnError || Prototype.emptyFunction;
 @@ -1053,7 +1055,7 @@ Prado.WebUI.TBaseValidator.prototype =  		{
  			var validator = this;
 -			Event.observe(control, 'change', function()
 +			this.observe(control, 'change', function()
  			{
  				if(validator.visible)
  				{
 @@ -1323,7 +1325,7 @@ Prado.WebUI.TBaseValidator.prototype =  		var selection = this.getSelectedValuesAndChecks(elements, initial);
  		return selection.values.length > 0 ? selection.values[0] : initial;
  	}
 -}
 +});
  /**
 @@ -1906,7 +1908,7 @@ Prado.WebUI.TCaptchaValidator = Class.extend(Prado.WebUI.TBaseValidator,   * @class Prado.WebUI.TReCaptchaValidator
   * @extends Prado.WebUI.TBaseValidator
   */
 -Prado.WebUI.TReCaptchaValidator = Class.extend(Prado.WebUI.TBaseValidator,
 +Prado.WebUI.TReCaptchaValidator = Class.create(Prado.WebUI.TBaseValidator,
  {
  	onInit : function()
  	{
 @@ -1915,8 +1917,8 @@ Prado.WebUI.TReCaptchaValidator = Class.extend(Prado.WebUI.TBaseValidator,  		if (elements)
  		 if (elements.length>=1)
  		 {
 -		  Event.observe(elements[0],'change',function() { obj.responseChanged() });
 -		  Event.observe(elements[0],'keydown',function() { obj.responseChanged() });
 +		  this.observe(elements[0],'change',function() { obj.responseChanged() });
 +		  this.observe(elements[0],'keydown',function() { obj.responseChanged() });
  		 }
  	},
 | 
