diff options
Diffstat (limited to 'framework/Web/UI')
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiAutoComplete.php (renamed from framework/Web/UI/ActiveControls/TAutoComplete.php) | 128 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiControlAdapter.php | 177 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiDraggable.php | 91 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiDroppable.php | 188 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiResizable.php | 94 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiSelectable.php | 171 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiSortable.php | 168 | ||||
-rw-r--r-- | framework/Web/UI/TClientScriptManager.php | 7 |
8 files changed, 950 insertions, 74 deletions
diff --git a/framework/Web/UI/ActiveControls/TAutoComplete.php b/framework/Web/UI/JuiControls/TJuiAutoComplete.php index 5e144040..a8bf2d81 100644 --- a/framework/Web/UI/ActiveControls/TAutoComplete.php +++ b/framework/Web/UI/JuiControls/TJuiAutoComplete.php @@ -1,12 +1,12 @@ <?php /** - * TAutoComplete class file. + * TJuiAutoComplete class file. * * @author Wei Zhuo <weizhuo[at]gamil[dot]com> * @link http://www.pradosoft.com/ * @copyright Copyright © 2005-2013 PradoSoft * @license http://www.pradosoft.com/license/ - * @version $Id: TAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @version $Id: TJuiAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $ * @package System.Web.UI.ActiveControls */ @@ -15,14 +15,14 @@ */ Prado::using('System.Web.UI.ActiveControls.TActiveTextBox'); Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter'); - +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); /** - * TAutoComplete class. + * TJuiAutoComplete class. * - * TAutoComplete is a textbox that provides a list of suggestion on + * TJuiAutoComplete is a textbox that provides a list of suggestion on * the current partial word typed in the textbox. The suggestions are * requested using callbacks, and raises the {@link onSuggestion OnSuggestion} - * event. The events of the TActiveText (from which TAutoComplete is extended from) + * event. The events of the TActiveText (from which TJuiAutoComplete is extended from) * and {@link onSuggestion OnSuggestion} are mutually exculsive. That is, * if {@link onTextChange OnTextChange} and/or {@link onCallback OnCallback} * events are raise, then {@link onSuggestion OnSuggestion} will not be raise, and @@ -31,7 +31,7 @@ Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter'); * The list of suggestions should be set in the {@link onSuggestion OnSuggestion} * event handler. The partial word to match the suggestion is in the * {@link TCallbackEventParameter::getCallbackParameter TCallbackEventParameter::CallbackParameter} - * property. The datasource of the TAutoComplete must be set using {@link setDataSource} + * property. The datasource of the TJuiAutoComplete must be set using {@link setDataSource} * method. This sets the datasource for the suggestions repeater, available through * the {@link getSuggestions Suggestions} property. Header, footer templates and * other properties of the repeater can be access via the {@link getSuggestions Suggestions} @@ -63,7 +63,7 @@ Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter'); * {@link TCallbackEventParameter::getCallbackParameter TCallbackEventParameter::CallbackParameter} * property contains the index of the selected suggestion. * - * TAutoComplete allows multiple suggestions within one textbox with each + * TJuiAutoComplete allows multiple suggestions within one textbox with each * word or phrase separated by any characters specified in the * {@link setSeparator Separator} property. The {@link setFrequency Frequency} * and {@link setMinChars MinChars} properties sets the delay and minimum number @@ -77,11 +77,11 @@ Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter'); * "informal" are ignored as text for suggestions. * * @author Wei Zhuo <weizhuo[at]gmail[dot]com> - * @version $Id: TAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @version $Id: TJuiAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $ * @package System.Web.UI.ActiveControls * @since 3.1 */ -class TAutoComplete extends TActiveTextBox implements INamingContainer +class TJuiAutoComplete extends TActiveTextBox implements INamingContainer, IJuiOptions { /** * @var ITemplate template for repeater items @@ -93,52 +93,35 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer private $_resultPanel=null; /** - * @return string word or token separators (delimiters). - */ - public function getSeparator() - { - return $this->getViewState('tokens', ''); - } - - /** - * @return string word or token separators (delimiters). - */ - public function setSeparator($value) - { - $this->setViewState('tokens', TPropertyValue::ensureString($value), ''); - } - - /** - * @return float maximum delay (in seconds) before requesting a suggestion. + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. */ - public function getFrequency() + public function __construct() { - return $this->getViewState('frequency', ''); + parent::__construct(); + $this->setAdapter(new TJuiControlAdapter($this)); } /** - * @param float maximum delay (in seconds) before requesting a suggestion. - * Default is 0.4. + * Object containing defined javascript options + * @return TJuiControlOptions */ - public function setFrequency($value) + public function getOptions() { - $this->setViewState('frequency', TPropertyValue::ensureFloat($value),''); - } - - /** - * @return integer minimum number of characters before requesting a suggestion. - */ - public function getMinChars() - { - return $this->getViewState('minChars',''); + static $options; + if($options===null) + $options=new TJuiControlOptions($this); + return $options; } /** - * @param integer minimum number of characters before requesting a suggestion. + * Array containing valid javascript options + * @return array() */ - public function setMinChars($value) + public function getValidOptions() { - $this->setViewState('minChars', TPropertyValue::ensureInteger($value), ''); + return array('appendTo', 'autoFocus', 'delay', 'disabled', 'minLength', 'position', 'source'); } /** @@ -172,14 +155,14 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer $token = $param->getCallbackParameter(); if(is_array($token) && count($token) == 2) { - if($token[1] === '__TAutoComplete_onSuggest__') + if($token[1] === '__TJuiAutoComplete_onSuggest__') { - $parameter = new TAutoCompleteEventParameter($this->getResponse(), $token[0]); + $parameter = new TJuiAutoCompleteEventParameter($this->getResponse(), $token[0]); $this->onSuggest($parameter); } - else if($token[1] === '__TAutoComplete_onSuggestionSelected__') + else if($token[1] === '__TJuiAutoComplete_onSuggestionSelected__') { - $parameter = new TAutoCompleteEventParameter($this->getResponse(), null, $token[0]); + $parameter = new TJuiAutoCompleteEventParameter($this->getResponse(), null, $token[0]); $this->onSuggestionSelected($parameter); } } @@ -267,10 +250,7 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer protected function createRepeater() { $repeater = Prado::createComponent('System.Web.UI.WebControls.TRepeater'); - $repeater->setHeaderTemplate(new TAutoCompleteTemplate('<ul>')); - $repeater->setFooterTemplate(new TAutoCompleteTemplate('</ul>')); - $repeater->setItemTemplate(new TTemplate('<li><%# $this->DataItem %></li>',null)); - $repeater->setEmptyTemplate(new TAutoCompleteTemplate('<ul></ul>')); + $repeater->setItemTemplate(new TTemplate('<%# $this->Data %>',null)); $this->getControls()->add($repeater); return $repeater; } @@ -280,7 +260,6 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer */ public function renderEndTag($writer) { - $this->getPage()->getClientScript()->registerPradoScript('effects'); parent::renderEndTag($writer); $this->renderResultPanel($writer); } @@ -311,9 +290,17 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer { if($this->getActiveControl()->canUpdateClientSide()) { - $this->getSuggestions()->render($writer); - $boundary = $writer->getWriter()->getBoundary(); - $this->getResponse()->getAdapter()->setResponseData($boundary); + $data=array(); + $items=$this->getSuggestions()->getItems(); + $writer = new TTextWriter; + for($i=0; $i<$items->Count; $i++) + { + $items->itemAt($i)->render($writer); + $item=$writer->flush(); + $data[]=array( 'id' => $i, 'label' => $item); + } + + $this->getResponse()->getAdapter()->setResponseData($data); } } @@ -324,27 +311,25 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer { //disallow page state update ? //$this->getActiveControl()->getClientSide()->setEnablePageStateUpdate(false); - $options = array(); + $options = $this->getOptions()->toArray(); + /* if(strlen($string = $this->getSeparator())) { $string = strtr($string,array('\t'=>"\t",'\n'=>"\n",'\r'=>"\r")); $token = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); $options['tokens'] = $token; } + */ if($this->getAutoPostBack()) { $options = array_merge($options,parent::getPostBackOptions()); $options['AutoPostBack'] = true; } - if(strlen($select = $this->getTextCssClass())) - $options['select'] = $select; - $options['ResultPanel'] = $this->getResultPanel()->getClientID(); + if(strlen($textCssClass = $this->getTextCssClass())) + $options['textCssClass'] = $textCssClass; + $options['appendTo'] = '#'.$this->getResultPanel()->getClientID(); $options['ID'] = $this->getClientID(); $options['EventTarget'] = $this->getUniqueID(); - if(($minchars=$this->getMinChars())!=='') - $options['minChars'] = $minchars; - if(($frequency=$this->getFrequency())!=='') - $options['frequency'] = $frequency; $options['CausesValidation'] = $this->getCausesValidation(); $options['ValidationGroup'] = $this->getValidationGroup(); return $options; @@ -363,7 +348,7 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer */ protected function getClientClassName() { - return 'Prado.WebUI.TAutoComplete'; + return 'Prado.WebUI.TJuiAutoComplete'; } } @@ -375,11 +360,11 @@ class TAutoComplete extends TActiveTextBox implements INamingContainer * suggestion selected by the user, -1 if not suggestion is selected. * * @author Wei Zhuo <weizhuo[at]gmail[dot]com> - * @version $Id: TAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @version $Id: TJuiAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $ * @package System.Web.UI.ActiveControls * @since 3.1 */ -class TAutoCompleteEventParameter extends TCallbackEventParameter +class TJuiAutoCompleteEventParameter extends TCallbackEventParameter { private $_selectedIndex=-1; @@ -410,17 +395,17 @@ class TAutoCompleteEventParameter extends TCallbackEventParameter } /** - * TAutoCompleteTemplate class. + * TJuiAutoCompleteTemplate class. * - * TAutoCompleteTemplate is the default template for TAutoCompleteTemplate + * TJuiAutoCompleteTemplate is the default template for TJuiAutoCompleteTemplate * item template. * * @author Wei Zhuo <weizhuo[at]gmail[dot]com> - * @version $Id: TAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @version $Id: TJuiAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $ * @package System.Web.UI.ActiveControls * @since 3.1 */ -class TAutoCompleteTemplate extends TComponent implements ITemplate +class TJuiAutoCompleteTemplate extends TComponent implements ITemplate { private $_template; @@ -438,4 +423,3 @@ class TAutoCompleteTemplate extends TComponent implements ITemplate $parent->getControls()->add($this->_template); } } - diff --git a/framework/Web/UI/JuiControls/TJuiControlAdapter.php b/framework/Web/UI/JuiControls/TJuiControlAdapter.php new file mode 100644 index 00000000..d92809d3 --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiControlAdapter.php @@ -0,0 +1,177 @@ +<?php +/** + * TJuiControlAdapter class file. + * + * @author Fabio Bas <ctrlaltca@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2013 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id: TJuiControl.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter'); + +/** + * TJuiControlAdapter class + * + * TJuiControlAdapter is the base adapter class for controls that are + * derived from a jQuery-ui widget. + * + * @author Fabio Bas <ctrlaltca@gmail.com> + * @version $Id: TJuiControlAdapter.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiControlAdapter extends TActiveControlAdapter +{ + const SCRIPT_PATH = 'jquery'; + const CSS_PATH = 'css'; + const BASE_CSS_FILENAME ='jquery-ui.css'; + + /** + * @param string set the jquery-ui style + */ + public function setJuiBaseStyle($value) + { + $this->getControl()->setViewState('JuiBaseStyle', $value, 'base'); + } + + /** + * @return string current jquery-ui style + */ + public function getJuiBaseStyle() + { + return $this->getControl()->getViewState('JuiBaseStyle', 'base'); + } + + /** + * Inject jquery script and styles before render + */ + public function onPreRender($param) + { + parent::onPreRender($param); + $this->getPage()->getClientScript()->registerPradoScript('jqueryui'); + $this->publishJuiStyle(self::BASE_CSS_FILENAME); + } + + /** + * @param string jQuery asset file in the self::SCRIPT_PATH directory. + * @return string jQuery asset url. + */ + protected function getAssetUrl($file='') + { + $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl(); + return $base.'/'.self::SCRIPT_PATH.'/'.$file; + } + + /** + * Publish the jQuery-ui style Css asset file. + * @param file name + * @return string Css file url. + */ + public function publishJuiStyle($file) + { + $url = $this->getAssetUrl(self::CSS_PATH.'/'.$this->getJuiBaseStyle().'/'.$file); + $cs = $this->getPage()->getClientScript(); + if(!$cs->isStyleSheetFileRegistered($url)) + $cs->registerStyleSheetFile($url, $url); + return $url; + } + +} + +/** + * IJuiOptions interface + * + * IJuiOptions is the interface that must be implemented by controls using + * {@link TJuiControlOptions}. + * + * @author Fabio Bas <ctrlaltca@gmail.com> + * @version $Id: TJuiControlAdapter.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +interface IJuiOptions +{ + public function getOptions(); + public function getValidOptions(); +} + +/** + * TJuiControlOptions interface + * + * TJuiControlOptions is an helper class that can collect a series of options + * for a control. The control must implement {@link IJuiOptions}. + * The options are validated againg an array of valid options provided by the control. + * Since component properties are case insensitive, the array of valid options is used + * to ensure the option name has the correct case. + * The options array can then get retrieved using {@link toArray} and applied to the jQuery-ui widget. + * + * @author Fabio Bas <ctrlaltca@gmail.com> + * @version $Id: TJuiControlAdapter.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiControlOptions +{ + /** + * @var TMap map of javascript options. + */ + private $_options; + + private $_control; + + public function __construct($control) + { + if(!$control instanceof IJuiOptions) + throw new THttpException(500,'juioptions_control_invalid',$control->ID); + $this->_control=$control; + } + /** + * Sets a named options with a value. Options are used to store and retrive + * named values for the javascript control. + * @param string option name. + * @param mixed new value. + * @param mixed default value. + * @return mixed options value. + */ + public function __set($name,$value) + { + if($this->_options===null) + $this->_options=array(); + foreach($this->_control->getValidOptions() as $option) + { + if($name == strtolower($option)) + { + $this->_options[$option] = $value; + return; + } + } + throw new THttpException(500,'juioptions_option_invalid',$control->ID, $name); + } + + /** + * Gets an option named value. Options are used to store and retrive + * named values for the base active controls. + * @param string option name. + * @param mixed default value. + * @return mixed options value. + */ + public function __get($name) + { + if($this->_options===null) + $this->_options=array(); + return isset($this->_options[$name]) ? $this->_options[$name] : null; + } + + /** + * @return TMap active control options + */ + public function toArray() + { + if($this->_options===null) + $this->_options=array(); + return $this->_options; + } +} diff --git a/framework/Web/UI/JuiControls/TJuiDraggable.php b/framework/Web/UI/JuiControls/TJuiDraggable.php new file mode 100644 index 00000000..eb174eb0 --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiDraggable.php @@ -0,0 +1,91 @@ +<?php +/** + * TJuiDraggable class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2013 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id: TJuiDraggable.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); + +/** + * TJuiDraggable class. + * + * + * <code> + * <com:TJuiDraggable + * ID="drag1" + * Style="border: 1px solid red; width:100px;height:100px" + * Options.Axis="y" + * > + * drag me + * </com:TJuiDraggable> + * </code> + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @version $Id: TJuiDraggable.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiDraggable extends TActivePanel implements IJuiOptions +{ + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TJuiControlAdapter($this)); + } + + /** + * Object containing defined javascript options + * @return TJuiControlOptions + */ + public function getOptions() + { + static $options; + if($options===null) + $options=new TJuiControlOptions($this); + return $options; + } + + /** + * Array containing valid javascript options + * @return array() + */ + public function getValidOptions() + { + return array('addClasses', 'appendTo', 'axis', 'cancel', 'connectToSortable', 'containment', 'cursor', 'cursorAt', 'delay', 'disabled', 'distance', 'grid', 'handle', 'helper', 'iframeFix', 'opacity', 'refreshPositions', 'revert', 'revertDuration', 'scope', 'scroll', 'scrollSensitivity', 'scrollSpeed', 'snap', 'snapMode', 'snapTolerance', 'stack', 'zIndex'); + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + $options = $this->getOptions()->toArray(); + return $options; + } + + /** + * Ensure that the ID attribute is rendered and registers the javascript code + * for initializing the active control. + */ + protected function addAttributesToRender($writer) + { + parent::addAttributesToRender($writer); + + $writer->addAttribute('id',$this->getClientID()); + $options=TJavascript::encode($this->getPostBackOptions()); + $cs=$this->getPage()->getClientScript(); + $code="jQuery('#".$this->getClientId()."').draggable(".$options.");"; + $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); + } +} diff --git a/framework/Web/UI/JuiControls/TJuiDroppable.php b/framework/Web/UI/JuiControls/TJuiDroppable.php new file mode 100644 index 00000000..e54d4eac --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiDroppable.php @@ -0,0 +1,188 @@ +<?php +/** + * TJuiDroppable class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2013 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id: TJuiDroppable.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); +Prado::using('System.Web.UI.ActiveControls.TActivePanel'); + +/** + * TJuiDroppable class. + * + * <code> + * <com:TJuiDraggable + * ID="drag1" + * Style="border: 1px solid red; width:100px;height:100px;background-color: #fff" + * > + * drag me + * </com:TJuiDraggable> + * + * <com:TJuiDroppable + * ID="drop1" + * Style="border: 1px solid blue; width:600px;height:600px; background-color: lime" + * OnDrop="drop1_ondrop" + * > + * drop it over me + * </com:TJuiDroppable> + * </code> + * + * <code> + * public function drop1_ondrop($sender, $param) + * { + * $draggable=$param->getDroppedControl()->ID; + * $this->drop1->Controls->clear(); + * $this->drop1->Controls->add("Dropped ".$draggable." at: <br/>Top=".$param->getOffsetTop()." Left=".$param->getOffsetLeft()); + * // it's still an active panel, after all + * $this->drop1->render($param->NewWriter); + * } + * </code> + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @version $Id: TJuiDroppable.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiDroppable extends TActivePanel implements IJuiOptions, ICallbackEventHandler +{ + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TJuiControlAdapter($this)); + } + + /** + * Object containing defined javascript options + * @return TJuiControlOptions + */ + public function getOptions() + { + static $options; + if($options===null) + $options=new TJuiControlOptions($this); + return $options; + } + + /** + * Array containing valid javascript options + * @return array() + */ + public function getValidOptions() + { + return array('addClasses', 'appendTo', 'axis', 'cancel', 'connectToSortable', 'containment', 'cursor', 'cursorAt', 'delay', 'disabled', 'distance', 'grid', 'handle', 'helper', 'iframeFix', 'opacity', 'refreshPositions', 'revert', 'revertDuration', 'scope', 'scroll', 'scrollSensitivity', 'scrollSpeed', 'snap', 'snapMode', 'snapTolerance', 'stack', 'zIndex'); + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + $options = $this->getOptions()->toArray(); + $options['drop'] = new TJavaScriptLiteral("function( event, ui ) { Prado.Callback(".TJavascript::encode($this->getUniqueID()).", { 'offset' : { 'left' : ui.offset.left - $(this).offset().left, 'top' : ui.offset.top - $(this).offset().top }, 'position' : ui.position, 'draggable' : ui.draggable.get(0).id }) }"); + return $options; + } + + /** + * Raises callback event. This method is required bu {@link ICallbackEventHandler} + * interface. + * It raises the {@link onDrop OnDrop} event, then, the {@link onCallback OnCallback} event + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the parameter associated with the callback event + */ + public function raiseCallbackEvent($param) + { + $this->onDrop($param->getCallbackParameter()); + $this->onCallback($param); + } + + /** + * Raises the onDrop event. + * The drop parameters are encapsulated into a {@link TDropContainerEventParameter} + * + * @param object $dropControlId + */ + public function onDrop ($dropParams) + { + $this->raiseEvent('OnDrop', $this, new TJuiDroppableEventParameter ($this->getResponse(), $dropParams)); + + } + + /** + * This method is invoked when a callback is requested. The method raises + * 'OnCallback' event to fire up the event handlers. If you override this + * method, be sure to call the parent implementation so that the event + * handler can be invoked. + * @param TCallbackEventParameter event parameter to be passed to the event handlers + */ + public function onCallback($param) + { + $this->raiseEvent('OnCallback', $this, $param); + } + + /** + * Ensure that the ID attribute is rendered and registers the javascript code + * for initializing the active control. + */ + protected function addAttributesToRender($writer) + { + parent::addAttributesToRender($writer); + + $writer->addAttribute('id',$this->getClientID()); + $options=TJavascript::encode($this->getPostBackOptions()); + $cs=$this->getPage()->getClientScript(); + $code="jQuery('#".$this->getClientId()."').droppable(".$options.");"; + $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); + } +} + +/** + * TJuiDroppableEventParameter class + * + * TJuiDroppableEventParameter encapsulate the parameter + * data for <b>OnDrop</b> event of TJuiDroppable components + * + * @author Christophe BOULAIN (Christophe.Boulain@ceram.fr) + * @copyright Copyright © 2008, PradoSoft + * @license http://www.pradosoft.com/license + * @version $Id: TDropContainer.php 3285 2013-04-11 07:28:07Z ctrlaltca $ + * @package System.Web.UI.JuiControls + */ +class TJuiDroppableEventParameter extends TCallbackEventParameter +{ + public function getDragElementId() { return $this->getCallbackParameter()->draggable; } + public function getPositionTop() { return $this->getCallbackParameter()->position->top; } + public function getPositionLeft() { return $this->getCallbackParameter()->position->left; } + public function getOffsetTop() { return $this->getCallbackParameter()->offset->top; } + public function getOffsetLeft() { return $this->getCallbackParameter()->offset->left; } + + /** + * GetDroppedControl + * + * Compatibility method to get the dropped control + * @return TControl dropped control, or null if not found + */ + public function getDroppedControl() + { + $control=null; + $service=prado::getApplication()->getService(); + if ($service instanceof TPageService) + { + // Find the control + // Warning, this will not work if you have a '_' in your control Id ! + $dropControlId=str_replace(TControl::CLIENT_ID_SEPARATOR,TControl::ID_SEPARATOR,$this->getCallbackParameter()->draggable); + $control=$service->getRequestedPage()->findControl($dropControlId); + } + return $control; + } +}
\ No newline at end of file diff --git a/framework/Web/UI/JuiControls/TJuiResizable.php b/framework/Web/UI/JuiControls/TJuiResizable.php new file mode 100644 index 00000000..5d70ebf3 --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiResizable.php @@ -0,0 +1,94 @@ +<?php +/** + * TJuiResizable class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2013 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id: TJuiResizable.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); + +/** + * TJuiResizable class. + * + * + * <code> + * <com:TJuiResizable + * ID="resize1" + * Style="border: 1px solid green; width:100px;height:100px;background-color: #00dd00" + * Options.maxHeight="250" + * Options.maxWidth="350" + * Options.minHeight="150" + * Options.minWidth="200" + * > + * resize me + * </com:TJuiResizable> + * </code> + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @version $Id: TJuiResizable.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiResizable extends TActivePanel implements IJuiOptions +{ + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TJuiControlAdapter($this)); + } + + /** + * Object containing defined javascript options + * @return TJuiControlOptions + */ + public function getOptions() + { + static $options; + if($options===null) + $options=new TJuiControlOptions($this); + return $options; + } + + /** + * Array containing valid javascript options + * @return array() + */ + public function getValidOptions() + { + return array('alsoResize', 'animate', 'animateDuration', 'animateEasing', 'aspectRatio', 'autoHide', 'cancel', 'containment', 'delay', 'disabled', 'distance', 'ghost', 'grid', 'handles', 'helper', 'maxHeight', 'maxWidth', 'minHeight', 'minWidth'); + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + $options = $this->getOptions()->toArray(); + return $options; + } + + /** + * Ensure that the ID attribute is rendered and registers the javascript code + * for initializing the active control. + */ + protected function addAttributesToRender($writer) + { + parent::addAttributesToRender($writer); + + $writer->addAttribute('id',$this->getClientID()); + $options=TJavascript::encode($this->getPostBackOptions()); + $cs=$this->getPage()->getClientScript(); + $code="jQuery('#".$this->getClientId()."').resizable(".$options.");"; + $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); + } +} diff --git a/framework/Web/UI/JuiControls/TJuiSelectable.php b/framework/Web/UI/JuiControls/TJuiSelectable.php new file mode 100644 index 00000000..0818a1fc --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiSelectable.php @@ -0,0 +1,171 @@ +<?php +/** + * TJuiSelectable class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2013 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id: TJuiSelectable.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); + +/** + * TJuiSelectable class. + * + * + * <code> + * <style> + * .ui-selecting { background: #FECA40; } + * .ui-selected { background: #F39814; color: white; } + * </style> + * <com:TJuiSelectable ID="repeater1" /> + * </code> + * + * <code> + * $this->repeater1->DataSource=array('home', 'office', 'car', 'boat', 'plane'); + * $this->repeater1->dataBind(); + * </code> + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @version $Id: TJuiSelectable.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiSelectable extends TActivePanel implements IJuiOptions +{ + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TJuiControlAdapter($this)); + } + + /** + * Object containing defined javascript options + * @return TJuiControlOptions + */ + public function getOptions() + { + static $options; + if($options===null) + $options=new TJuiControlOptions($this); + return $options; + } + + /** + * Array containing valid javascript options + * @return array() + */ + public function getValidOptions() + { + return array('appendTo', 'autoRefresh', 'cancel', 'delay', 'disabled', 'distance', 'filter', 'tolerance'); + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + $options = $this->getOptions()->toArray(); + return $options; + } + + /** + * Ensure that the ID attribute is rendered and registers the javascript code + * for initializing the active control. + */ + protected function addAttributesToRender($writer) + { + parent::addAttributesToRender($writer); + $writer->addAttribute('id',$this->getClientID()); + $options=TJavascript::encode($this->getPostBackOptions()); + $cs=$this->getPage()->getClientScript(); + $code="jQuery('#".$this->getClientId()."_0').selectable(".$options.");"; + $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); + } + + /** + * @var ITemplate template for repeater items + */ + private $_repeater=null; + + /** + * @param array data source for Selectables. + */ + public function setDataSource($data) + { + $this->getSelectables()->setDataSource($data); + } + + /** + * Overrides parent implementation. Callback {@link renderSelectables()} when + * page's IsCallback property is true. + */ + public function dataBind() + { + parent::dataBind(); + if($this->getPage()->getIsCallback()) + $this->renderSelectables($this->getResponse()->createHtmlWriter()); + } + + /** + * @return TRepeater suggestion list repeater + */ + public function getSelectables() + { + if($this->_repeater===null) + $this->_repeater = $this->createRepeater(); + return $this->_repeater; + } + + /** + * @return TRepeater new instance of TRepater to render the list of Selectables. + */ + protected function createRepeater() + { + $repeater = Prado::createComponent('System.Web.UI.WebControls.TRepeater'); + $repeater->setHeaderTemplate(new TJuiSelectableTemplate('<ul id="'.$this->getClientId().'_0'.'">')); + $repeater->setFooterTemplate(new TJuiSelectableTemplate('</ul>')); + $repeater->setItemTemplate(new TTemplate('<li><%# $this->DataItem %></li>',null)); + $repeater->setEmptyTemplate(new TJuiSelectableTemplate('<ul></ul>')); + $this->getControls()->add($repeater); + return $repeater; + } +} + + +/** + * TJuiSelectableTemplate class. + * + * TJuiSelectableTemplate is the default template for TJuiSelectableTemplate + * item template. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @version $Id: TJuiAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.ActiveControls + * @since 3.1 + */ +class TJuiSelectableTemplate extends TComponent implements ITemplate +{ + private $_template; + + public function __construct($template) + { + $this->_template = $template; + } + /** + * Instantiates the template. + * It creates a {@link TDataList} control. + * @param TControl parent to hold the content within the template + */ + public function instantiateIn($parent) + { + $parent->getControls()->add($this->_template); + } +}
\ No newline at end of file diff --git a/framework/Web/UI/JuiControls/TJuiSortable.php b/framework/Web/UI/JuiControls/TJuiSortable.php new file mode 100644 index 00000000..bada066f --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiSortable.php @@ -0,0 +1,168 @@ +<?php +/** + * TJuiSortable class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2013 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id: TJuiSortable.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); + +/** + * TJuiSortable class. + * + * + * <code> + * <com:TJuiSortable ID="repeater1" /> + * </code> + * + * <code> + * $this->repeater1->DataSource=array('home', 'office', 'car', 'boat', 'plane'); + * $this->repeater1->dataBind(); + * </code> + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @version $Id: TJuiSortable.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiSortable extends TActivePanel implements IJuiOptions +{ + /** + * Creates a new callback control, sets the adapter to + * TActiveControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. + */ + public function __construct() + { + parent::__construct(); + $this->setAdapter(new TJuiControlAdapter($this)); + } + + /** + * Object containing defined javascript options + * @return TJuiControlOptions + */ + public function getOptions() + { + static $options; + if($options===null) + $options=new TJuiControlOptions($this); + return $options; + } + + /** + * Array containing valid javascript options + * @return array() + */ + public function getValidOptions() + { + return array('appendTo', 'axis', 'cancel', 'connectWith', 'containment', 'cursor', 'cursorAt', 'delay', 'disabled', 'distance', 'dropOnEmpty', 'forceHelperSize', 'forcePlaceholderSize', 'grid', 'handle', 'helper', 'items', 'opacity', 'placeholder', 'revert', 'scroll', 'scrollSensitivity', 'scrollSpeed', 'tolerance', 'zIndex'); + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + $options = $this->getOptions()->toArray(); + return $options; + } + + /** + * Ensure that the ID attribute is rendered and registers the javascript code + * for initializing the active control. + */ + protected function addAttributesToRender($writer) + { + parent::addAttributesToRender($writer); + $writer->addAttribute('id',$this->getClientID()); + $options=TJavascript::encode($this->getPostBackOptions()); + $cs=$this->getPage()->getClientScript(); + $code="jQuery('#".$this->getClientId()."_0').sortable(".$options.");"; + $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); + } + + /** + * @var ITemplate template for repeater items + */ + private $_repeater=null; + + /** + * @param array data source for Selectables. + */ + public function setDataSource($data) + { + $this->getSelectables()->setDataSource($data); + } + + /** + * Overrides parent implementation. Callback {@link renderSelectables()} when + * page's IsCallback property is true. + */ + public function dataBind() + { + parent::dataBind(); + if($this->getPage()->getIsCallback()) + $this->renderSelectables($this->getResponse()->createHtmlWriter()); + } + + /** + * @return TRepeater suggestion list repeater + */ + public function getSelectables() + { + if($this->_repeater===null) + $this->_repeater = $this->createRepeater(); + return $this->_repeater; + } + + /** + * @return TRepeater new instance of TRepater to render the list of Selectables. + */ + protected function createRepeater() + { + $repeater = Prado::createComponent('System.Web.UI.WebControls.TRepeater'); + $repeater->setHeaderTemplate(new TJuiSortableTemplate('<ul id="'.$this->getClientId().'_0'.'">')); + $repeater->setFooterTemplate(new TJuiSortableTemplate('</ul>')); + $repeater->setItemTemplate(new TTemplate('<li><%# $this->DataItem %></li>',null)); + $repeater->setEmptyTemplate(new TJuiSortableTemplate('<ul></ul>')); + $this->getControls()->add($repeater); + return $repeater; + } +} + + +/** + * TJuiSortableTemplate class. + * + * TJuiSortableTemplate is the default template for TJuiSortableTemplate + * item template. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @version $Id: TJuiAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $ + * @package System.Web.UI.ActiveControls + * @since 3.1 + */ +class TJuiSortableTemplate extends TComponent implements ITemplate +{ + private $_template; + + public function __construct($template) + { + $this->_template = $template; + } + /** + * Instantiates the template. + * It creates a {@link TDataList} control. + * @param TControl parent to hold the content within the template + */ + public function instantiateIn($parent) + { + $parent->getControls()->add($this->_template); + } +}
\ No newline at end of file diff --git a/framework/Web/UI/TClientScriptManager.php b/framework/Web/UI/TClientScriptManager.php index a9f6c5b4..fd550ff1 100644 --- a/framework/Web/UI/TClientScriptManager.php +++ b/framework/Web/UI/TClientScriptManager.php @@ -729,8 +729,11 @@ class TClientScriptManager extends TApplicationComponent */ public function flushScriptFiles($writer, $control=null) { - $this->_page->ensureRenderInForm($control); - $this->renderAllPendingScriptFiles($writer); + if(!$this->_page->getIsCallback()) + { + $this->_page->ensureRenderInForm($control); + $this->renderAllPendingScriptFiles($writer); + } } /** |