From 887da1b3668499821f046665b461aeadb0a9fb2e Mon Sep 17 00:00:00 2001 From: wei <> Date: Sun, 27 Aug 2006 04:18:31 +0000 Subject: Adding TActiveImage and TActiveImageButton --- framework/Web/Javascripts/js/ajax.js | 11 +++-- framework/Web/Javascripts/js/prado.js | 10 +++- framework/Web/Javascripts/prado/activecontrols3.js | 16 +++++-- framework/Web/Javascripts/prado/ajax3.js | 4 +- framework/Web/Javascripts/prado/controls.js | 55 +++++++++++++++------- 5 files changed, 67 insertions(+), 29 deletions(-) (limited to 'framework/Web/Javascripts') diff --git a/framework/Web/Javascripts/js/ajax.js b/framework/Web/Javascripts/js/ajax.js index 95869ade..5d929f77 100644 --- a/framework/Web/Javascripts/js/ajax.js +++ b/framework/Web/Javascripts/js/ajax.js @@ -23,10 +23,10 @@ setTimeout(this.onComplete.bind(this),10);}}});Ajax.PeriodicalUpdater=Class.crea this.timer=setTimeout(this.onTimerEvent.bind(this),this.decay*this.frequency*1000);},onTimerEvent:function(){this.updater=new Ajax.Updater(this.container,this.url,this.options);}});Object.extend(Ajax.Request.prototype,{respondToReadyState:function(readyState) {var event=Ajax.Request.Events[readyState];var transport=this.transport,json=this.getHeaderData(Prado.CallbackRequest.DATA_HEADER);if(event=='Complete') {try -{Prado.CallbackRequest.updatePageState(this,transport);Ajax.Responders.dispatch('on'+transport.status,this,transport,json);Prado.CallbackRequest.dispatchActions(transport,this.getHeaderData(Prado.CallbackRequest.ACTION_HEADER));(this.options['on'+this.transport.status]||this.options['on'+(this.responseIsSuccess()?'Success':'Failure')]||Prototype.emptyFunction)(transport,json);}catch(e){this.dispatchException(e);} +{Prado.CallbackRequest.updatePageState(this,transport);Ajax.Responders.dispatch('on'+transport.status,this,transport,json);Prado.CallbackRequest.dispatchActions(transport,this.getHeaderData(Prado.CallbackRequest.ACTION_HEADER));(this.options['on'+this.transport.status]||this.options['on'+(this.responseIsSuccess()?'Success':'Failure')]||Prototype.emptyFunction)(this,json);}catch(e){this.dispatchException(e);} if((this.header('Content-type')||'').match(/^text\/javascript/i)) this.evalResponse();} -try{(this.options['on'+event]||Prototype.emptyFunction)(transport,json);Ajax.Responders.dispatch('on'+event,this,transport,json);}catch(e){this.dispatchException(e);} +try{(this.options['on'+event]||Prototype.emptyFunction)(this,json);Ajax.Responders.dispatch('on'+event,this,transport,json);}catch(e){this.dispatchException(e);} if(event=='Complete') this.transport.onreadystatechange=Prototype.emptyFunction;},getHeaderData:function(name) {try @@ -200,7 +200,8 @@ if(this.saving)return;this.effect=new Effect.Highlight(this.element,{startcolor: this.editing=false;this.saving=false;this.oldInnerHTML=null;this.onLeaveEditMode();},onComplete:function(transport){this.leaveEditMode();this.options.onComplete.bind(this)(transport,this.element);},onEnterEditMode:function(){},onLeaveEditMode:function(){},dispose:function(){if(this.oldInnerHTML){this.element.innerHTML=this.oldInnerHTML;} this.leaveEditMode();Event.stopObserving(this.element,'click',this.onclickListener);Event.stopObserving(this.element,'mouseover',this.mouseoverListener);Event.stopObserving(this.element,'mouseout',this.mouseoutListener);if(this.options.externalControl){Event.stopObserving(this.options.externalControl,'click',this.onclickListener);Event.stopObserving(this.options.externalControl,'mouseover',this.mouseoverListener);Event.stopObserving(this.options.externalControl,'mouseout',this.mouseoutListener);}}};Ajax.InPlaceCollectionEditor=Class.create();Object.extend(Ajax.InPlaceCollectionEditor.prototype,Ajax.InPlaceEditor.prototype);Object.extend(Ajax.InPlaceCollectionEditor.prototype,{createEditField:function(){if(!this.cached_selectTag){var selectTag=document.createElement("select");var collection=this.options.collection||[];var optionTag;collection.each(function(e,i){optionTag=document.createElement("option");optionTag.value=(e instanceof Array)?e[0]:e;if(this.options.value==optionTag.value)optionTag.selected=true;optionTag.appendChild(document.createTextNode((e instanceof Array)?e[1]:e));selectTag.appendChild(optionTag);}.bind(this));this.cached_selectTag=selectTag;} this.editField=this.cached_selectTag;if(this.options.loadTextURL)this.loadExternalText();this.form.appendChild(this.editField);this.options.callback=function(form,value){return"value="+encodeURIComponent(value);}}});Form.Element.DelayedObserver=Class.create();Form.Element.DelayedObserver.prototype={initialize:function(element,delay,callback){this.delay=delay||0.5;this.element=$(element);this.callback=callback;this.timer=null;this.lastValue=$F(this.element);Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));},delayedListener:function(event){if(this.lastValue==$F(this.element))return;if(this.timer)clearTimeout(this.timer);this.timer=setTimeout(this.onTimerEvent.bind(this),this.delay*1000);this.lastValue=$F(this.element);},onTimerEvent:function(){this.timer=null;this.callback(this.element,$F(this.element));}};Prado.WebUI.CallbackControl=Class.extend(Prado.WebUI.PostBackControl,{onPostBack:function(event,options) -{request=new Prado.CallbackRequest(options.EventTarget,options);request.dispatch();Event.stop(event);}});Prado.WebUI.TActiveButton=Class.extend(Prado.WebUI.CallbackControl);Prado.WebUI.TActiveLinkButton=Class.extend(Prado.WebUI.CallbackControl);Prado.WebUI.TActiveCheckBox=Class.extend(Prado.WebUI.CallbackControl,{onPostBack:function(event,options) +{request=new Prado.CallbackRequest(options.EventTarget,options);request.dispatch();Event.stop(event);}});Prado.WebUI.TActiveButton=Class.extend(Prado.WebUI.CallbackControl);Prado.WebUI.TActiveLinkButton=Class.extend(Prado.WebUI.CallbackControl);Prado.WebUI.TActiveImageButton=Class.extend(Prado.WebUI.TImageButton,{onPostBack:function(event,options) +{this.addXYInput(event,options);request=new Prado.CallbackRequest(options.EventTarget,options);request.dispatch();Event.stop(event);}});Prado.WebUI.TActiveCheckBox=Class.extend(Prado.WebUI.CallbackControl,{onPostBack:function(event,options) {request=new Prado.CallbackRequest(options.EventTarget,options);request.dispatch();}});Prado.WebUI.TActiveRadioButton=Class.extend(Prado.WebUI.TActiveCheckBox);Prado.WebUI.TActiveTextBox=Class.extend(Prado.WebUI.TTextBox,{onInit:function(options) {if(options['TextMode']!='MultiLine') Event.observe(this.element,"keydown",this.handleReturnKey.bind(this));Event.observe(this.element,"change",this.doCallback.bindEvent(this,options));},doCallback:function(event,options) @@ -212,9 +213,9 @@ this.onInit(options);},doCallback:function(event,options) {var element=Event.findElement(event,'LI');this.index=element.autocompleteIndex;this.selectEntry();this.hide();Event.fireEvent(this.element,"change");},getUpdatedChoices:function() {options=new Array(this.getToken(),"__TAutoComplete_onSuggest__");Prado.Callback(this.options.EventTarget,options,null,this.options);},onComplete:function(request,boundary) {result=Prado.Element.extractContent(request.responseText,boundary);if(typeof(result)=="string"&&result.length>0) -this.updateChoices(result);}});Prado.WebUI.TPeriodicCallback=Base.extend({count:0,timeout:0,constructor:function(options) +this.updateChoices(result);}});Prado.WebUI.TTimeTriggeredCallback=Base.extend({count:0,timeout:0,constructor:function(options) {this.options=Object.extend({Interval:1,DecayRate:0},options||{}) -this.onComplete=this.options.onComplete;Prado.WebUI.TPeriodicCallback.register(this);},startTimer:function() +this.onComplete=this.options.onComplete;Prado.WebUI.TTimeTriggeredCallback.register(this);},startTimer:function() {this.options.onComplete=this.onRequestComplete.bind(this);setTimeout(this.onTimerEvent.bind(this),200);},stopTimer:function() {(this.onComplete||Prototype.emptyFunction).apply(this,arguments);this.options.onComplete=undefined;clearTimeout(this.timer);this.timer=undefined;this.count=0;},onTimerEvent:function() {this.options.params=this.timeout/1000;request=new Prado.CallbackRequest(this.options.ID,this.options);request.dispatch();},onRequestComplete:function() diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js index e3930cfd..87996c28 100644 --- a/framework/Web/Javascripts/js/prado.js +++ b/framework/Web/Javascripts/js/prado.js @@ -360,7 +360,15 @@ Event.stop(event);},onPostBack:function(event,options) {if(!this.hasXYInput) {this.addXYInput(event,options);this.hasXYInput=true;} Prado.PostBack(event,options);},addXYInput:function(event,options) -{var imagePos=Position.cumulativeOffset(this.element);var clickedPos=[event.clientX,event.clientY];var x=clickedPos[0]-imagePos[0]+1;var y=clickedPos[1]-imagePos[1]+1;var id=options['EventTarget'];var x_input=INPUT({type:'hidden',name:id+'_x',value:x});var y_input=INPUT({type:'hidden',name:id+'_y',value:y});this.element.parentNode.appendChild(x_input);this.element.parentNode.appendChild(y_input);}});Prado.WebUI.TRadioButton=Class.extend(Prado.WebUI.PostBackControl);Prado.WebUI.TRadioButton.prototype.onRadioButtonInitialize=Prado.WebUI.TRadioButton.prototype.initialize;Object.extend(Prado.WebUI.TRadioButton.prototype,{initialize:function(options) +{imagePos=Position.cumulativeOffset(this.element);clickedPos=[event.clientX,event.clientY];x=clickedPos[0]-imagePos[0]+1;y=clickedPos[1]-imagePos[1]+1;x=x<0?0:x;y=y<0?0:y;id=options['EventTarget'];x_input=$(id+"_x");y_input=$(id+"_y");if(x_input) +{x_input.value=x;} +else +{x_input=INPUT({type:'hidden',name:id+'_x','id':id+'_x',value:x});this.element.parentNode.appendChild(x_input);} +if(y_input) +{y_input.value=y;} +else +{y_input=INPUT({type:'hidden',name:id+'_y','id':id+'_y',value:y});this.element.parentNode.appendChild(y_input);} +Logger.info("x="+x+", y="+y);}});Prado.WebUI.TRadioButton=Class.extend(Prado.WebUI.PostBackControl);Prado.WebUI.TRadioButton.prototype.onRadioButtonInitialize=Prado.WebUI.TRadioButton.prototype.initialize;Object.extend(Prado.WebUI.TRadioButton.prototype,{initialize:function(options) {this.element=$(options['ID']);if(!this.element.checked) this.onRadioButtonInitialize(options);}});Prado.WebUI.TTextBox=Class.extend(Prado.WebUI.PostBackControl,{onInit:function(options) {if(options['TextMode']!='MultiLine') diff --git a/framework/Web/Javascripts/prado/activecontrols3.js b/framework/Web/Javascripts/prado/activecontrols3.js index ca1d5b37..bd8aa6a5 100644 --- a/framework/Web/Javascripts/prado/activecontrols3.js +++ b/framework/Web/Javascripts/prado/activecontrols3.js @@ -20,6 +20,16 @@ Prado.WebUI.TActiveButton = Class.extend(Prado.WebUI.CallbackControl); */ Prado.WebUI.TActiveLinkButton = Class.extend(Prado.WebUI.CallbackControl); +Prado.WebUI.TActiveImageButton = Class.extend(Prado.WebUI.TImageButton, +{ + onPostBack : function(event, options) + { + this.addXYInput(event,options); + request = new Prado.CallbackRequest(options.EventTarget, options); + request.dispatch(); + Event.stop(event); + } +}); /** * Active check box. */ @@ -112,9 +122,9 @@ Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete, }); /** - * Period Callback class. + * Time Triggered Callback class. */ -Prado.WebUI.TPeriodicCallback = Base.extend( +Prado.WebUI.TTimeTriggeredCallback = Base.extend( { count : 0, timeout : 0, @@ -128,7 +138,7 @@ Prado.WebUI.TPeriodicCallback = Base.extend( }, options || {}) this.onComplete = this.options.onComplete; - Prado.WebUI.TPeriodicCallback.register(this); + Prado.WebUI.TTimeTriggeredCallback.register(this); }, startTimer : function() diff --git a/framework/Web/Javascripts/prado/ajax3.js b/framework/Web/Javascripts/prado/ajax3.js index de5af4ca..c5683139 100644 --- a/framework/Web/Javascripts/prado/ajax3.js +++ b/framework/Web/Javascripts/prado/ajax3.js @@ -22,7 +22,7 @@ Object.extend(Ajax.Request.prototype, (this.options['on' + this.transport.status] || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')] - || Prototype.emptyFunction)(transport, json); + || Prototype.emptyFunction)(this, json); } catch (e) { this.dispatchException(e); } @@ -31,7 +31,7 @@ Object.extend(Ajax.Request.prototype, } try { - (this.options['on' + event] || Prototype.emptyFunction)(transport, json); + (this.options['on' + event] || Prototype.emptyFunction)(this, json); Ajax.Responders.dispatch('on' + event, this, transport, json); } catch (e) { this.dispatchException(e); diff --git a/framework/Web/Javascripts/prado/controls.js b/framework/Web/Javascripts/prado/controls.js index 285374a3..c31d783d 100644 --- a/framework/Web/Javascripts/prado/controls.js +++ b/framework/Web/Javascripts/prado/controls.js @@ -7,12 +7,12 @@ Prado.WebUI.PostBackControl.prototype = initialize : function(options) { this.element = $(options['ID']); - + /* if(options.CausesValidation && typeof(Prado.Validation) != 'undefined') { Prado.Validation.registerTarget(options); } - + //TODO: what do the following options do? //options['PostBackUrl'] //options['ClientSubmit'] @@ -35,7 +35,7 @@ Prado.WebUI.TButton = Prado.WebUI.createPostBackComponent(); */ Prado.WebUI.PostBackControl = Class.create(); -Prado.WebUI.PostBackControl.prototype = +Prado.WebUI.PostBackControl.prototype = { _elementOnClick : null, //capture the element's onclick function @@ -45,7 +45,7 @@ Prado.WebUI.PostBackControl.prototype = if(this.onInit) this.onInit(options); }, - + onInit : function(options) { if(typeof(this.element.onclick)=="function") @@ -53,7 +53,7 @@ Prado.WebUI.PostBackControl.prototype = this._elementOnClick = this.element.onclick; this.element.onclick = null; } - Event.observe(this.element, "click", this.elementClicked.bindEvent(this,options)); + Event.observe(this.element, "click", this.elementClicked.bindEvent(this,options)); }, elementClicked : function(event, options) @@ -87,7 +87,7 @@ Prado.WebUI.TBulletedList = Class.extend(Prado.WebUI.PostBackControl); Prado.WebUI.TImageMap = Class.extend(Prado.WebUI.PostBackControl); /** - * TImageButton client-side behaviour. With validation, Firefox needs + * 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); @@ -97,7 +97,7 @@ Object.extend(Prado.WebUI.TImageButton.prototype, * Only add the hidden inputs once. */ hasXYInput : false, - + /** * Override parent onPostBack function, tried to add hidden forms * inputs to capture x,y clicked point. @@ -111,7 +111,7 @@ Object.extend(Prado.WebUI.TImageButton.prototype, } Prado.PostBack(event, options); }, - + /** * Add hidden inputs to capture the x,y point clicked on the image. * @param event DOM click event. @@ -119,15 +119,34 @@ Object.extend(Prado.WebUI.TImageButton.prototype, */ addXYInput : function(event,options) { - var imagePos = Position.cumulativeOffset(this.element); - var clickedPos = [event.clientX, event.clientY]; - var x = clickedPos[0]-imagePos[0]+1; - var y = clickedPos[1]-imagePos[1]+1; - var id = options['EventTarget']; - var x_input = INPUT({type:'hidden',name:id+'_x',value:x}); - var y_input = INPUT({type:'hidden',name:id+'_y',value:y}); - this.element.parentNode.appendChild(x_input); - this.element.parentNode.appendChild(y_input); + imagePos = Position.cumulativeOffset(this.element); + clickedPos = [event.clientX, event.clientY]; + x = clickedPos[0]-imagePos[0]+1; + y = clickedPos[1]-imagePos[1]+1; + x = x < 0 ? 0 : x; + y = y < 0 ? 0 : y; + id = options['EventTarget']; + x_input = $(id+"_x"); + y_input = $(id+"_y"); + if(x_input) + { + x_input.value = x; + } + else + { + x_input = INPUT({type:'hidden',name:id+'_x','id':id+'_x',value:x}); + this.element.parentNode.appendChild(x_input); + } + if(y_input) + { + y_input.value = y; + } + else + { + y_input = INPUT({type:'hidden',name:id+'_y','id':id+'_y',value:y}); + this.element.parentNode.appendChild(y_input); + } + Logger.info("x="+x+", y="+y); } }); @@ -183,7 +202,7 @@ Prado.WebUI.TListBox = Class.extend(Prado.WebUI.TListControl); Prado.WebUI.TDropDownList = Class.extend(Prado.WebUI.TListControl); Prado.WebUI.DefaultButton = Class.create(); -Prado.WebUI.DefaultButton.prototype = +Prado.WebUI.DefaultButton.prototype = { initialize : function(options) { -- cgit v1.2.3