From 2db708960f4435e2b98518f8fa84cc036ac9f2eb Mon Sep 17 00:00:00 2001 From: wei <> Date: Tue, 29 Aug 2006 12:53:23 +0000 Subject: Update active controls. --- .gitattributes | 2 + framework/Web/Javascripts/js/ajax.js | 13 +++--- framework/Web/Javascripts/prado/controls.js | 1 - .../Web/UI/ActiveControls/TActiveDropDownList.php | 17 ------- framework/Web/UI/ActiveControls/TActiveListBox.php | 16 ------- framework/Web/UI/ActiveControls/TActiveTextBox.php | 25 ---------- .../Web/UI/ActiveControls/TBaseActiveControl.php | 4 +- .../Web/UI/ActiveControls/TInPlaceTextBox.php | 22 --------- framework/Web/UI/TPage.php | 16 ++++++- .../protected/pages/TInPlaceTextBoxTest.page | 53 ++++++++++++++++++++++ .../protected/pages/TInPlaceTextBoxTest.php | 16 +++++++ .../tests/ActiveListBoxTestCase.php | 6 --- 12 files changed, 96 insertions(+), 95 deletions(-) create mode 100644 tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.php diff --git a/.gitattributes b/.gitattributes index 07d26923..4620c7a8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1878,6 +1878,8 @@ tests/FunctionalTests/active-controls/protected/pages/EventTriggeredCallback.pag tests/FunctionalTests/active-controls/protected/pages/EventTriggeredCallback.php -text tests/FunctionalTests/active-controls/protected/pages/ReplaceContentTest.page -text tests/FunctionalTests/active-controls/protected/pages/ReplaceContentTest.php -text +tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.page -text +tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.php -text tests/FunctionalTests/active-controls/protected/pages/TextBoxValidationCallback.page -text tests/FunctionalTests/active-controls/protected/pages/TextBoxValidationCallback.php -text tests/FunctionalTests/active-controls/protected/pages/ValueTriggerCallbackTest.page -text diff --git a/framework/Web/Javascripts/js/ajax.js b/framework/Web/Javascripts/js/ajax.js index ada940df..b54996da 100644 --- a/framework/Web/Javascripts/js/ajax.js +++ b/framework/Web/Javascripts/js/ajax.js @@ -143,21 +143,22 @@ break;case'n':if(next()=='u'&&next()=='l'&&next()=='l'){next();return null;} break;} error("Syntax error");} function value(){white();switch(ch){case'{':return object();case'[':return array();case'"':return string();case'-':return number();default:return ch>='0'&&ch<='9'?number():word();}} -return value();}};var Autocompleter={} +return value();}};if(typeof Effect=='undefined') +throw("controls.js requires including script.aculo.us' effects.js library");var Autocompleter={} Autocompleter.Base=function(){};Autocompleter.Base.prototype={baseInitialize:function(element,update,options){this.element=$(element);this.update=$(update);this.hasFocus=false;this.changed=false;this.active=false;this.index=0;this.entryCount=0;if(this.setOptions) this.setOptions(options);else this.options=options||{};this.options.paramName=this.options.paramName||this.element.name;this.options.tokens=this.options.tokens||[];this.options.frequency=this.options.frequency||0.4;this.options.minChars=this.options.minChars||1;this.options.onShow=this.options.onShow||function(element,update){if(!update.style.position||update.style.position=='absolute'){update.style.position='absolute';Position.clone(element,update,{setHeight:false,offsetTop:element.offsetHeight});} Effect.Appear(update,{duration:0.15});};this.options.onHide=this.options.onHide||function(element,update){new Effect.Fade(update,{duration:0.15})};if(typeof(this.options.tokens)=='string') this.options.tokens=new Array(this.options.tokens);this.observer=null;this.element.setAttribute('autocomplete','off');Element.hide(this.update);Event.observe(this.element,"blur",this.onBlur.bindAsEventListener(this));Event.observe(this.element,"keypress",this.onKeyPress.bindAsEventListener(this));},show:function(){if(Element.getStyle(this.update,'display')=='none')this.options.onShow(this.element,this.update);if(!this.iefix&&(navigator.appVersion.indexOf('MSIE')>0)&&(navigator.userAgent.indexOf('Opera')<0)&&(Element.getStyle(this.update,'position')=='absolute')){new Insertion.After(this.update,'');this.iefix=$(this.update.id+'_iefix');} -if(this.iefix)setTimeout(this.fixIEOverlapping.bind(this),50);},fixIEOverlapping:function(){Position.clone(this.update,this.iefix);this.iefix.style.zIndex=1;this.update.style.zIndex=2;Element.show(this.iefix);},hide:function(){this.stopIndicator();if(Element.getStyle(this.update,'display')!='none')this.options.onHide(this.element,this.update);if(this.iefix)Element.hide(this.iefix);},startIndicator:function(){if(this.options.indicator)Element.show(this.options.indicator);},stopIndicator:function(){if(this.options.indicator)Element.hide(this.options.indicator);},onKeyPress:function(event){if(this.active) +if(this.iefix)setTimeout(this.fixIEOverlapping.bind(this),50);},fixIEOverlapping:function(){Position.clone(this.update,this.iefix,{setTop:(!this.update.style.height)});this.iefix.style.zIndex=1;this.update.style.zIndex=2;Element.show(this.iefix);},hide:function(){this.stopIndicator();if(Element.getStyle(this.update,'display')!='none')this.options.onHide(this.element,this.update);if(this.iefix)Element.hide(this.iefix);},startIndicator:function(){if(this.options.indicator)Element.show(this.options.indicator);},stopIndicator:function(){if(this.options.indicator)Element.hide(this.options.indicator);},onKeyPress:function(event){if(this.active) switch(event.keyCode){case Event.KEY_TAB:case Event.KEY_RETURN:this.selectEntry();Event.stop(event);case Event.KEY_ESC:this.hide();this.active=false;Event.stop(event);return;case Event.KEY_LEFT:case Event.KEY_RIGHT:return;case Event.KEY_UP:this.markPrevious();this.render();if(navigator.appVersion.indexOf('AppleWebKit')>0)Event.stop(event);return;case Event.KEY_DOWN:this.markNext();this.render();if(navigator.appVersion.indexOf('AppleWebKit')>0)Event.stop(event);return;} else if(event.keyCode==Event.KEY_TAB||event.keyCode==Event.KEY_RETURN||(navigator.appVersion.indexOf('AppleWebKit')>0&&event.keyCode==0))return;this.changed=true;this.hasFocus=true;if(this.observer)clearTimeout(this.observer);this.observer=setTimeout(this.onObserverEvent.bind(this),this.options.frequency*1000);},activate:function(){this.changed=false;this.hasFocus=true;this.getUpdatedChoices();},onHover:function(event){var element=Event.findElement(event,'LI');if(this.index!=element.autocompleteIndex) {this.index=element.autocompleteIndex;this.render();} Event.stop(event);},onClick:function(event){var element=Event.findElement(event,'LI');this.index=element.autocompleteIndex;this.selectEntry();this.hide();},onBlur:function(event){setTimeout(this.hide.bind(this),250);this.hasFocus=false;this.active=false;},render:function(){if(this.entryCount>0){for(var i=0;i0)this.index-- -else this.index=this.entryCount-1;},markNext:function(){if(this.index0)value=Element.collectTextNodes(nodes[0],this.options.select);}else value=Element.collectTextNodesIgnoreClass(selectedElement,'informal');var lastTokenPos=this.findLastToken();if(lastTokenPos!=-1){var newValue=this.element.value.substr(0,lastTokenPos+1);var whitespace=this.element.value.substr(lastTokenPos+1).match(/^\s+/);if(whitespace) newValue+=whitespace[0];this.element.value=newValue+value;}else{this.element.value=value;} @@ -181,7 +182,7 @@ Ajax.InPlaceEditor=Class.create();Ajax.InPlaceEditor.defaultHighlightColor="#FFF if(this.options.externalControl){this.options.externalControl=$(this.options.externalControl);} this.originalBackground=Element.getStyle(this.element,'background-color');if(!this.originalBackground){this.originalBackground="transparent";} this.element.title=this.options.clickToEditText;this.onclickListener=this.enterEditMode.bindAsEventListener(this);this.mouseoverListener=this.enterHover.bindAsEventListener(this);this.mouseoutListener=this.leaveHover.bindAsEventListener(this);Event.observe(this.element,'click',this.onclickListener);Event.observe(this.element,'mouseover',this.mouseoverListener);Event.observe(this.element,'mouseout',this.mouseoutListener);if(this.options.externalControl){Event.observe(this.options.externalControl,'click',this.onclickListener);Event.observe(this.options.externalControl,'mouseover',this.mouseoverListener);Event.observe(this.options.externalControl,'mouseout',this.mouseoutListener);}},enterEditMode:function(evt){if(this.saving)return;if(this.editing)return;this.editing=true;this.onEnterEditMode();if(this.options.externalControl){Element.hide(this.options.externalControl);} -Element.hide(this.element);this.createForm();this.element.parentNode.insertBefore(this.form,this.element);Field.scrollFreeActivate(this.editField);if(evt){Event.stop(evt);} +Element.hide(this.element);this.createForm();this.element.parentNode.insertBefore(this.form,this.element);if(!this.options.loadTextURL)Field.scrollFreeActivate(this.editField);if(evt){Event.stop(evt);} return false;},createForm:function(){this.form=document.createElement("form");this.form.id=this.options.formId;Element.addClassName(this.form,this.options.formClassName) this.form.onsubmit=this.onSubmit.bind(this);this.createEditField();if(this.options.textarea){var br=document.createElement("br");this.form.appendChild(br);} if(this.options.okButton){okButton=document.createElement("input");okButton.type="submit";okButton.value=this.options.okText;okButton.className='editor_ok_button';this.form.appendChild(okButton);} @@ -190,7 +191,7 @@ var obj=this;if(this.options.rows==1&&!this.hasHTMLLineBreaks(text)){this.option textField.onblur=this.onSubmit.bind(this);this.editField=textField;}else{this.options.textarea=true;var textArea=document.createElement("textarea");textArea.obj=this;textArea.name="value";textArea.value=this.convertHTMLLineBreaks(text);textArea.rows=this.options.rows;textArea.cols=this.options.cols||40;textArea.className='editor_field';if(this.options.submitOnBlur) textArea.onblur=this.onSubmit.bind(this);this.editField=textArea;} if(this.options.loadTextURL){this.loadExternalText();} -this.form.appendChild(this.editField);},getText:function(){return this.element.innerHTML;},loadExternalText:function(){Element.addClassName(this.form,this.options.loadingClassName);this.editField.disabled=true;new Ajax.Request(this.options.loadTextURL,Object.extend({asynchronous:true,onComplete:this.onLoadedExternalText.bind(this)},this.options.ajaxOptions));},onLoadedExternalText:function(transport){Element.removeClassName(this.form,this.options.loadingClassName);this.editField.disabled=false;this.editField.value=transport.responseText.stripTags();},onclickCancel:function(){this.onComplete();this.leaveEditMode();return false;},onFailure:function(transport){this.options.onFailure(transport);if(this.oldInnerHTML){this.element.innerHTML=this.oldInnerHTML;this.oldInnerHTML=null;} +this.form.appendChild(this.editField);},getText:function(){return this.element.innerHTML;},loadExternalText:function(){Element.addClassName(this.form,this.options.loadingClassName);this.editField.disabled=true;new Ajax.Request(this.options.loadTextURL,Object.extend({asynchronous:true,onComplete:this.onLoadedExternalText.bind(this)},this.options.ajaxOptions));},onLoadedExternalText:function(transport){Element.removeClassName(this.form,this.options.loadingClassName);this.editField.disabled=false;this.editField.value=transport.responseText.stripTags();Field.scrollFreeActivate(this.editField);},onclickCancel:function(){this.onComplete();this.leaveEditMode();return false;},onFailure:function(transport){this.options.onFailure(transport);if(this.oldInnerHTML){this.element.innerHTML=this.oldInnerHTML;this.oldInnerHTML=null;} return false;},onSubmit:function(){var form=this.form;var value=this.editField.value;this.onLoading();if(this.options.evalScripts){new Ajax.Request(this.url,Object.extend({parameters:this.options.callback(form,value),onComplete:this.onComplete.bind(this),onFailure:this.onFailure.bind(this),asynchronous:true,evalScripts:true},this.options.ajaxOptions));}else{new Ajax.Updater({success:this.element,failure:null},this.url,Object.extend({parameters:this.options.callback(form,value),onComplete:this.onComplete.bind(this),onFailure:this.onFailure.bind(this)},this.options.ajaxOptions));} if(arguments.length>1){Event.stop(arguments[0]);} return false;},onLoading:function(){this.saving=true;this.removeForm();this.leaveHover();this.showSaving();},showSaving:function(){this.oldInnerHTML=this.element.innerHTML;this.element.innerHTML=this.options.savingText;Element.addClassName(this.element,this.options.savingClassName);this.element.style.backgroundColor=this.originalBackground;Element.show(this.element);},removeForm:function(){if(this.form){if(this.form.parentNode)Element.remove(this.form);this.form=null;}},enterHover:function(){if(this.saving)return;this.element.style.backgroundColor=this.options.highlightcolor;if(this.effect){this.effect.cancel();} diff --git a/framework/Web/Javascripts/prado/controls.js b/framework/Web/Javascripts/prado/controls.js index c31d783d..25e1315b 100644 --- a/framework/Web/Javascripts/prado/controls.js +++ b/framework/Web/Javascripts/prado/controls.js @@ -146,7 +146,6 @@ Object.extend(Prado.WebUI.TImageButton.prototype, 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); } }); diff --git a/framework/Web/UI/ActiveControls/TActiveDropDownList.php b/framework/Web/UI/ActiveControls/TActiveDropDownList.php index 0a6a3832..302b0afa 100644 --- a/framework/Web/UI/ActiveControls/TActiveDropDownList.php +++ b/framework/Web/UI/ActiveControls/TActiveDropDownList.php @@ -66,23 +66,6 @@ class TActiveDropDownList extends TDropDownList implements ICallbackEventHandler return 'Prado.WebUI.TActiveDropDownList'; } - /** - * Loads user input data. - * Disables ActiveControl.EnableUpdate subproperty during loading post data - * to avoid duplicating selection changes. - * @param string the key that can be used to retrieve data from the input data collection - * @param array the input data collection - * @return boolean whether the data of the component has been changed - */ - public function loadPostData($key,$values) - { - $enabled = $this->getActiveControl()->getEnableUpdate(); - $this->getActiveControl()->setEnableUpdate(false); - $result = parent::loadPostData($key, $values); - $this->getActiveControl()->setEnableUpdate($enabled); - return $result; - } - /** * Creates a collection object to hold list items. A specialized * TActiveListItemCollection is created to allow the drop down list options diff --git a/framework/Web/UI/ActiveControls/TActiveListBox.php b/framework/Web/UI/ActiveControls/TActiveListBox.php index 30eeba2c..cb982be2 100644 --- a/framework/Web/UI/ActiveControls/TActiveListBox.php +++ b/framework/Web/UI/ActiveControls/TActiveListBox.php @@ -50,22 +50,6 @@ class TActiveListBox extends TListBox implements IActiveControl, ICallbackEventH return 'Prado.WebUI.TActiveListBox'; } - /** - * Loads user input data. Disables the client-side update during loading - * and restore the EnableUpdate of ActiveControl after loading. - * @param string the key that can be used to retrieve data from the input data collection - * @param array the input data collection - * @return boolean whether the data of the component has been changed - */ - public function loadPostData($key,$values) - { - $enabled = $this->getActiveControl()->getEnableUpdate(); - $this->getActiveControl()->setEnableUpdate(false); - $result = parent::loadPostData($key, $values); - $this->getActiveControl()->setEnableUpdate($enabled); - return $result; - } - /** * Sets the selection mode of the list control (Single, Multiple) * on the client-side if the {@link setEnableUpdate EnableUpdate} diff --git a/framework/Web/UI/ActiveControls/TActiveTextBox.php b/framework/Web/UI/ActiveControls/TActiveTextBox.php index c5f0f152..20358a36 100644 --- a/framework/Web/UI/ActiveControls/TActiveTextBox.php +++ b/framework/Web/UI/ActiveControls/TActiveTextBox.php @@ -84,31 +84,6 @@ class TActiveTextBox extends TTextBox implements ICallbackEventHandler, IActiveC $this->raiseEvent('OnCallback', $this, $param); } - /** - * Loads user input data. - * This method is primarly used by framework developers. - * @param string the key that can be used to retrieve data from the input data collection - * @param array the input data collection - * @return boolean whether the data of the component has been changed - */ - public function loadPostData($key,$values) - { - $value=$values[$key]; - if($this->getAutoTrim()) - $value=trim($value); - if(!$this->getReadOnly() && $this->getText()!==$value) - { - $enabled = $this->getActiveControl()->getEnableUpdate(); - $this->getActiveControl()->setEnableUpdate(false); - $this->setText($value); - $this->getActiveControl()->setEnableUpdate($enabled); - return true; - } - else - return false; - } - - /** * Renders the javascript for textbox. */ diff --git a/framework/Web/UI/ActiveControls/TBaseActiveControl.php b/framework/Web/UI/ActiveControls/TBaseActiveControl.php index e5fe8f16..ed2e50db 100644 --- a/framework/Web/UI/ActiveControls/TBaseActiveControl.php +++ b/framework/Web/UI/ActiveControls/TBaseActiveControl.php @@ -119,13 +119,15 @@ class TBaseActiveControl extends TComponent /** * Returns true if callback response is allowed to update the browser contents. * Is is true if the control is initilized, and is a callback request and - * the {@link setEnableUpdate EnabledUpdate} property is true. + * the {@link setEnableUpdate EnabledUpdate} property is true and + * the page is not loading post data. * @return boolean true if the callback response is allowed update * client-side contents. */ public function canUpdateClientSide() { return $this->getControl()->getHasChildInitialized() + && $this->getPage()->getIsLoadingPostData() == false && $this->getPage()->getIsCallback() && $this->getEnableUpdate(); } diff --git a/framework/Web/UI/ActiveControls/TInPlaceTextBox.php b/framework/Web/UI/ActiveControls/TInPlaceTextBox.php index b783be88..b131da24 100644 --- a/framework/Web/UI/ActiveControls/TInPlaceTextBox.php +++ b/framework/Web/UI/ActiveControls/TInPlaceTextBox.php @@ -190,28 +190,6 @@ class TInPlaceTextBox extends TLabel implements $this->setViewState('ValidationGroup',$value,''); } - /** - * Loads user input data. - * This method is primarly used by framework developers. - * @param string the key that can be used to retrieve data from the input data collection - * @param array the input data collection - * @return boolean whether the data of the component has been changed - */ - public function loadPostData($key,$values) - { - $value=$values[$key]; - if($this->getText()!==$value) - { - $enabled = $this->getActiveControl()->getEnableUpdate(); - $this->getActiveControl()->setEnableUpdate(false); - $this->setText($value); - $this->getActiveControl()->setEnableUpdate($enabled); - return true; - } - else - return false; - } - public function raisePostDataChangedEvent() { $this->onTextChanged(null); diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index 60586fab..2bdfd3cf 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -153,6 +153,10 @@ class TPage extends TTemplateControl * @var array post data loader IDs. */ private $_postDataLoaders=array(); + /** + * @var boolean true if loading post data. + */ + private $_isLoadingPostData=false; /** * Constructor. @@ -271,7 +275,7 @@ class TPage extends TTemplateControl protected function processCallbackRequest($writer) { Prado::using('System.Web.UI.ActiveControls.TActivePageAdapter'); - + $this->setAdapter(new TActivePageAdapter($this)); Prado::trace("Page onPreInit()",'System.Web.UI.TPage'); @@ -825,6 +829,7 @@ class TPage extends TTemplateControl */ protected function processPostData($postData,$beforeLoad) { + $this->_isLoadingPostData=true; if($beforeLoad) $this->_restPostData=new TMap; foreach($postData as $key=>$value) @@ -859,6 +864,15 @@ class TPage extends TTemplateControl unset($this->_controlsRequiringPostData[$key]); } } + $this->_isLoadingPostData=false; + } + + /** + * @return boolean true if loading post data. + */ + public function getIsLoadingPostData() + { + return $this->_isLoadingPostData; } /** diff --git a/tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.page b/tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.page new file mode 100644 index 00000000..54e38c2c --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.page @@ -0,0 +1,53 @@ + + + + +

TInPlaceTextBox Functional Test

+ + + + Edit + + + + + + +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.php b/tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.php new file mode 100644 index 00000000..3fa5c7e2 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/TInPlaceTextBoxTest.php @@ -0,0 +1,16 @@ +Text = "muahaha"; + } + + function label1_changed($sender, $param) + { + $this->status->Text = "Status: ". $sender->Text; + } +} + +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/tests/ActiveListBoxTestCase.php b/tests/FunctionalTests/active-controls/tests/ActiveListBoxTestCase.php index 24f8099d..96f56b30 100644 --- a/tests/FunctionalTests/active-controls/tests/ActiveListBoxTestCase.php +++ b/tests/FunctionalTests/active-controls/tests/ActiveListBoxTestCase.php @@ -29,12 +29,6 @@ class ActiveListBoxTestCase extends SeleniumTestCase $this->pause(800); $this->assertEmptySelection("list1"); - $this->click('button7'); - $this->pause(800); - $this->click("button1"); - $this->pause(800); - $this->assertSelectedIndexes('list1', '3'); - $this->click('button6'); $this->pause(800); $this->click("button1"); -- cgit v1.2.3