/gi,"");},createEditField:function(){var text;if(this.options.loadTextURL){text=this.options.loadingText;}else{text=this.getText();} +var obj=this;if(this.options.rows==1&&!this.hasHTMLLineBreaks(text)){this.options.textarea=false;var textField=document.createElement("input");textField.obj=this;textField.type="text";textField.name="value";textField.value=text;textField.style.backgroundColor=this.options.highlightcolor;textField.className='editor_field';var size=this.options.size||this.options.cols||0;if(size!=0)textField.size=size;if(this.options.submitOnBlur) +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;} +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();} +Element.addClassName(this.element,this.options.hoverClassName)},leaveHover:function(){if(this.options.backgroundColor){this.element.style.backgroundColor=this.oldBackground;} +Element.removeClassName(this.element,this.options.hoverClassName) +if(this.saving)return;this.effect=new Effect.Highlight(this.element,{startcolor:this.options.highlightcolor,endcolor:this.options.highlightendcolor,restorecolor:this.originalBackground});},leaveEditMode:function(){Element.removeClassName(this.element,this.options.savingClassName);this.removeForm();this.leaveHover();this.element.style.backgroundColor=this.originalBackground;Element.show(this.element);if(this.options.externalControl){Element.show(this.options.externalControl);} +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) +{new Prado.CallbackRequest(options.EventTarget,options);Event.stop(event);}});Prado.WebUI.TActiveButton=Class.extend(Prado.WebUI.CallbackControl);Prado.WebUI.TAutoComplete=Class.extend(Autocompleter.Base,{initialize:function(options) +{this.options=options;this.baseInitialize(options.ID,options.ResultPanel,options);Object.extend(this.options,{onSuccess:this.onComplete.bind(this)});},getUpdatedChoices:function() +{Prado.Callback(this.options.EventTarget,this.getToken(),null,this.options);},onComplete:function(request,boundary) +{result=Prado.Element.extractContent(request.responseText,boundary);this.updateChoices(result);}}); \ No newline at end of file diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js index 9442ed26..c09cf64c 100644 --- a/framework/Web/Javascripts/js/prado.js +++ b/framework/Web/Javascripts/js/prado.js @@ -265,9 +265,12 @@ el.options[el.options.length]=new Option(options[i][0],options[i][1]);}},focus:f {var obj=$(element);if(typeof(obj)!="undefined"&&typeof(obj.focus)!="undefined") setTimeout(function(){obj.focus();},100);return false;},replace:function(element,method,content,boundary,transport) {if(boundary) -{var f=RegExp('()([\\s\\S\\w\\W]*)()',"m");var result=transport.responseText.match(f);if(result&&result.length>=2) -content=result[2];} -method.toFunction().apply(this,[element,content]);}} +{result=Prado.Element.extractContent(transport.responseText,boundary);if(result!=null) +content=result;} +method.toFunction().apply(this,[element,content]);},extractContent:function(text,boundary) +{f=RegExp('()([\\s\\S\\w\\W]*)()',"m");result=text.match(f);if(result&&result.length>=2) +return result[2];else +return null;}} Prado.Element.Selection={inputValue:function(el,value) {switch(el.type.toLowerCase()) {case'checkbox':case'radio':return el.checked=value;}},selectValue:function(el,value) diff --git a/framework/Web/Javascripts/prado/activecontrols3.js b/framework/Web/Javascripts/prado/activecontrols3.js new file mode 100644 index 00000000..c22af98c --- /dev/null +++ b/framework/Web/Javascripts/prado/activecontrols3.js @@ -0,0 +1,43 @@ +/** + * Generic postback control. + */ +Prado.WebUI.CallbackControl = Class.extend(Prado.WebUI.PostBackControl, +{ + onPostBack : function(event, options) + { + new Prado.CallbackRequest(options.EventTarget, options); + Event.stop(event); + } +}); + +/** + * TActiveButton control. + */ +Prado.WebUI.TActiveButton = Class.extend(Prado.WebUI.CallbackControl); + +/** + * TAutoComplete control. + */ +Prado.WebUI.TAutoComplete = Class.extend(Autocompleter.Base, +{ + initialize : function(options) + { + this.options = options; + this.baseInitialize(options.ID, options.ResultPanel, options); + Object.extend(this.options, + { + onSuccess : this.onComplete.bind(this) + }); + }, + + getUpdatedChoices : function() + { + Prado.Callback(this.options.EventTarget, this.getToken(), null, this.options); + }, + + onComplete : function(request, boundary) + { + result = Prado.Element.extractContent(request.responseText, boundary); + this.updateChoices(result); + } +}); \ No newline at end of file diff --git a/framework/Web/Javascripts/prado/element.js b/framework/Web/Javascripts/prado/element.js index eec7fb92..0ff0e8fa 100644 --- a/framework/Web/Javascripts/prado/element.js +++ b/framework/Web/Javascripts/prado/element.js @@ -67,12 +67,21 @@ Prado.Element = { if(boundary) { - var f = RegExp('()([\\s\\S\\w\\W]*)()',"m"); - var result = transport.responseText.match(f); - if(result && result.length >= 2) - content = result[2]; + result = Prado.Element.extractContent(transport.responseText, boundary); + if(result != null) + content = result; } method.toFunction().apply(this,[element,content]); + }, + + extractContent : function(text, boundary) + { + f = RegExp('()([\\s\\S\\w\\W]*)()',"m"); + result = text.match(f); + if(result && result.length >= 2) + return result[2]; + else + return null; } } diff --git a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php index 2409d9fe..1cdd5d73 100644 --- a/framework/Web/UI/ActiveControls/TActiveControlAdapter.php +++ b/framework/Web/UI/ActiveControls/TActiveControlAdapter.php @@ -14,9 +14,11 @@ class TActiveControlAdapter extends TControlAdapter { if(!self::$_renderedPosts) { + $cs = $this->getPage()->getClientScript(); + $cs->registerPradoScript('ajax'); $options = TJavascript::encode($this->getPage()->getPostDataLoaders(),false); $script = "Prado.CallbackRequest.PostDataLoaders = {$options};"; - $this->getPage()->getClientScript()->registerEndScript(get_class($this), $script); + $cs->registerEndScript(get_class($this), $script); self::$_renderedPosts = true; } parent::render($writer); diff --git a/framework/Web/UI/ActiveControls/TActivePageAdapter.php b/framework/Web/UI/ActiveControls/TActivePageAdapter.php index 11c3303e..e92c9cdc 100644 --- a/framework/Web/UI/ActiveControls/TActivePageAdapter.php +++ b/framework/Web/UI/ActiveControls/TActivePageAdapter.php @@ -257,7 +257,7 @@ class TCallbackEventParameter extends TEventParameter */ public function getOutput() { - return $this->_response->createHtmlWriter(); + return $this->_response->createHtmlWriter(null,$this); } /** diff --git a/framework/Web/UI/ActiveControls/TAutoComplete.php b/framework/Web/UI/ActiveControls/TAutoComplete.php new file mode 100644 index 00000000..2ebba495 --- /dev/null +++ b/framework/Web/UI/ActiveControls/TAutoComplete.php @@ -0,0 +1,186 @@ +getSuggestions()->setDataSource($data); + } + + public function getResultPanel() + { + if(is_null($this->_resultPanel)) + $this->_resultPanel = $this->createResultPanel(); + return $this->_resultPanel; + } + + protected function createResultPanel() + { + $panel = Prado::createComponent('System.Web.UI.WebControls.TPanel'); + $this->getControls()->add($panel); + $panel->setID('result'); + return $panel; + } + + /** + * @return TRepeater suggestion list repeater + */ + public function getSuggestions() + { + if(is_null($this->_repeater)) + $this->_repeater = $this->createRepeater(); + return $this->_repeater; + } + + /** + * + */ + protected function createRepeater() + { + $repeater = Prado::createComponent('System.Web.UI.WebControls.TRepeater'); + $repeater->setHeaderTemplate(new TAutoCompleteTemplate('