diff options
Diffstat (limited to 'framework/Web/UI/JuiControls')
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiAutoComplete.php | 430 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiControlAdapter.php | 292 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiDraggable.php | 150 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiDroppable.php | 201 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiProgressbar.php | 137 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiResizable.php | 153 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiSelectable.php | 261 | ||||
-rw-r--r-- | framework/Web/UI/JuiControls/TJuiSortable.php | 314 |
8 files changed, 1938 insertions, 0 deletions
diff --git a/framework/Web/UI/JuiControls/TJuiAutoComplete.php b/framework/Web/UI/JuiControls/TJuiAutoComplete.php new file mode 100644 index 00000000..115969c5 --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiAutoComplete.php @@ -0,0 +1,430 @@ +<?php +/** + * TJuiAutoComplete class file. + * + * @author Wei Zhuo <weizhuo[at]gamil[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI.ActiveControls + */ + +/** + * Load active text box. + */ +Prado::using('System.Web.UI.ActiveControls.TActiveTextBox'); +Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter'); +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); +/** + * TJuiAutoComplete class. + * + * 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 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 + * vice versa. + * + * 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 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} + * property and its sub-properties. + * + * The {@link setTextCssClass TextCssClass} property if set is used to find + * the element within the Suggestions.ItemTemplate and Suggestions.AlternatingItemTemplate + * that contains the actual text for the suggestion selected. That is, + * only text inside elements with CSS class name equal to {@link setTextCssClass TextCssClass} + * will be used as suggestions. + * + * To return the list of suggestions back to the browser, supply a non-empty data source + * and call databind. For example, + * <code> + * function autocomplete_suggestion($sender, $param) + * { + * $token = $param->getToken(); //the partial word to match + * $sender->setDataSource($this->getSuggestionsFor($token)); //set suggestions + * $sender->dataBind(); + * } + * </code> + * + * The suggestion will be rendered when the {@link dataBind()} method is called + * <strong>during a callback request</strong>. + * + * When an suggestion is selected, that is, when the use has clicked, pressed + * the "Enter" key, or pressed the "Tab" key, the {@link onSuggestionSelected OnSuggestionSelected} + * event is raised. The + * {@link TCallbackEventParameter::getCallbackParameter TCallbackEventParameter::CallbackParameter} + * property contains the index of the selected suggestion. + * + * 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 + * of characters typed, respectively, before requesting for sugggestions. + * + * Use {@link onTextChange OnTextChange} and/or {@link onCallback OnCallback} events + * to handle post backs due to {@link setAutoPostBack AutoPostBack}. + * + * In the {@link getSuggestions Suggestions} TRepater item template, all HTML text elements + * are considered as text for the suggestion. Text within HTML elements with CSS class name + * "informal" are ignored as text for suggestions. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @package System.Web.UI.ActiveControls + * @since 3.1 + */ +class TJuiAutoComplete extends TActiveTextBox implements INamingContainer, IJuiOptions +{ + /** + * @var ITemplate template for repeater items + */ + private $_repeater=null; + /** + * @var TPanel result panel holding the suggestion items. + */ + private $_resultPanel=null; + + /** + * 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', 'autoFocus', 'delay', 'disabled', 'minLength', 'position', 'source'); + } + + /** + * Array containing valid javascript events + * @return array() + */ + public function getValidEvents() + { + return array(); + } + + /** + * @param string Css class name of the element to use for suggestion. + */ + public function setTextCssClass($value) + { + $this->setViewState('TextCssClass', $value); + } + + /** + * @return string Css class name of the element to use for suggestion. + */ + public function getTextCssClass() + { + return $this->getViewState('TextCssClass'); + } + + /** + * Raises the callback event. This method is overrides the parent implementation. + * If {@link setAutoPostBack AutoPostBack} is enabled it will raise + * {@link onTextChanged OnTextChanged} event event and then the + * {@link onCallback OnCallback} event. The {@link onSuggest OnSuggest} event is + * raise if the request is to find sugggestions, the {@link onTextChanged OnTextChanged} + * and {@link onCallback OnCallback} events are <b>NOT</b> raised. + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the event parameter + */ + public function raiseCallbackEvent($param) + { + $token = $param->getCallbackParameter(); + if(is_array($token) && count($token) == 2) + { + if($token[1] === '__TJuiAutoComplete_onSuggest__') + { + $parameter = new TJuiAutoCompleteEventParameter($this->getResponse(), $token[0]); + $this->onSuggest($parameter); + } + else if($token[1] === '__TJuiAutoComplete_onSuggestionSelected__') + { + $parameter = new TJuiAutoCompleteEventParameter($this->getResponse(), null, $token[0]); + $this->onSuggestionSelected($parameter); + } + } + else if($this->getAutoPostBack()) + parent::raiseCallbackEvent($param); + } + + /** + * This method is invoked when an autocomplete suggestion is requested. + * The method raises 'OnSuggest' event. 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 onSuggest($param) + { + $this->raiseEvent('OnSuggest', $this, $param); + } + + /** + * This method is invoked when an autocomplete suggestion is selected. + * The method raises 'OnSuggestionSelected' event. 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 onSuggestionSelected($param) + { + $this->raiseEvent('OnSuggestionSelected', $this, $param); + } + + /** + * @param array data source for suggestions. + */ + public function setDataSource($data) + { + $this->getSuggestions()->setDataSource($data); + } + + /** + * Overrides parent implementation. Callback {@link renderSuggestions()} when + * page's IsCallback property is true. + */ + public function dataBind() + { + parent::dataBind(); + if($this->getPage()->getIsCallback()) + $this->renderSuggestions($this->getResponse()->createHtmlWriter()); + } + + /** + * @return TPanel suggestion results panel. + */ + public function getResultPanel() + { + if($this->_resultPanel===null) + $this->_resultPanel = $this->createResultPanel(); + return $this->_resultPanel; + } + + /** + * @return TPanel new instance of result panel. Default uses TPanel. + */ + 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($this->_repeater===null) + $this->_repeater = $this->createRepeater(); + return $this->_repeater; + } + + /** + * @return TRepeater new instance of TRepater to render the list of suggestions. + */ + protected function createRepeater() + { + $repeater = Prado::createComponent('System.Web.UI.WebControls.TRepeater'); + $repeater->setItemTemplate(new TTemplate('<%# $this->Data %>',null)); + $this->getControls()->add($repeater); + return $repeater; + } + + /** + * Renders the end tag and registers javascript effects library. + */ + public function renderEndTag($writer) + { + parent::renderEndTag($writer); + $this->renderResultPanel($writer); + } + + /** + * Renders the result panel. + * @param THtmlWriter the renderer. + */ + protected function renderResultPanel($writer) + { + $this->getResultPanel()->render($writer); + } + + /** + * Renders the suggestions during a callback respones. + * @param THtmlWriter the renderer. + */ + public function renderCallback($writer) + { + $this->renderSuggestions($writer); + } + + /** + * Renders the suggestions repeater. + * @param THtmlWriter the renderer. + */ + public function renderSuggestions($writer) + { + if($this->getActiveControl()->canUpdateClientSide()) + { + $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); + } + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + //disallow page state update ? + //$this->getActiveControl()->getClientSide()->setEnablePageStateUpdate(false); + $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($textCssClass = $this->getTextCssClass())) + $options['textCssClass'] = $textCssClass; + $options['appendTo'] = '#'.$this->getResultPanel()->getClientID(); + $options['ID'] = $this->getClientID(); + $options['EventTarget'] = $this->getUniqueID(); + $options['CausesValidation'] = $this->getCausesValidation(); + $options['ValidationGroup'] = $this->getValidationGroup(); + return $options; + } + + /** + * Override parent implementation, no javascript is rendered here instead + * the javascript required for active control is registered in {@link addAttributesToRender}. + */ + protected function renderClientControlScript($writer) + { + } + + /** + * @return string corresponding javascript class name for this TActiveButton. + */ + protected function getClientClassName() + { + return 'Prado.WebUI.TJuiAutoComplete'; + } +} + +/** + * TAutCompleteEventParameter contains the {@link getToken Token} requested by + * the user for a partial match of the suggestions. + * + * The {@link getSelectedIndex SelectedIndex} is a zero-based index of the + * suggestion selected by the user, -1 if not suggestion is selected. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @package System.Web.UI.ActiveControls + * @since 3.1 + */ +class TJuiAutoCompleteEventParameter extends TCallbackEventParameter +{ + private $_selectedIndex=-1; + + /** + * Creates a new TCallbackEventParameter. + */ + public function __construct($response, $parameter, $index=-1) + { + parent::__construct($response, $parameter); + $this->_selectedIndex=$index; + } + + /** + * @return int selected suggestion zero-based index, -1 if not selected. + */ + public function getSelectedIndex() + { + return $this->_selectedIndex; + } + + /** + * @return string token for matching a list of suggestions. + */ + public function getToken() + { + return $this->getCallbackParameter(); + } +} + +/** + * TJuiAutoCompleteTemplate class. + * + * TJuiAutoCompleteTemplate is the default template for TJuiAutoCompleteTemplate + * item template. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @package System.Web.UI.ActiveControls + * @since 3.1 + */ +class TJuiAutoCompleteTemplate 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); + } +} diff --git a/framework/Web/UI/JuiControls/TJuiControlAdapter.php b/framework/Web/UI/JuiControls/TJuiControlAdapter.php new file mode 100644 index 00000000..3668a8b4 --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiControlAdapter.php @@ -0,0 +1,292 @@ +<?php +/** + * TJuiControlAdapter class file. + * + * @author Fabio Bas <ctrlaltca@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @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. It exposes convenience methods to + * publish jQuery-UI javascript and css assets. + * + * @author Fabio Bas <ctrlaltca@gmail.com> + * @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> + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +interface IJuiOptions +{ + public function getOptions(); + public function getValidOptions(); + public function getValidEvents(); +} + +/** + * TJuiControlOptions interface + * + * TJuiControlOptions is an helper class that can collect a list 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 itself. + * 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. + * In addition to the options, this class will render the needed javascript to raise a callback + * for any event for which an handler is defined in the control. + * + * @author Fabio Bas <ctrlaltca@gmail.com> + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiControlOptions +{ + /** + * @var TMap map of javascript options. + */ + private $_options; + /** + * @var TControl parent control. + */ + 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 option value. + * @throws THttpException + */ + public function __set($name,$value) + { + if($this->_options===null) + $this->_options=array(); + + foreach($this->_control->getValidOptions() as $option) + { + if(0 == strcasecmp($name, $option)) + { + $low = strtolower($value); + if($low === 'null') + { + $this->_options[$option] = null; + } elseif($low === 'true') { + $this->_options[$option] = true; + } elseif($low === 'false') { + $this->_options[$option] = false; + } elseif(is_numeric($value)) { + // trick to get float or integer automatically when needed + $this->_options[$option] = $value + 0; + } else { + $this->_options[$option] = $value; + } + return; + } + } + + throw new THttpException(500,'juioptions_option_invalid',$this->_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. + * @return mixed options value or null if not set. + */ + public function __get($name) + { + if($this->_options===null) + $this->_options=array(); + + foreach($this->_control->getValidOptions() as $option) + { + if(0 == strcasecmp($name, $option) && isset($this->_options[$option])) + { + return $this->_options[$option]; + } + } + + return null; + } + + /** + * @return Array of active control options + */ + public function toArray() + { + $ret= ($this->_options===null) ? array() : $this->_options; + + foreach($this->_control->getValidEvents() as $event) + if($this->_control->hasEventHandler('on'.$event)) + $ret[$event]=new TJavaScriptLiteral("function( event, ui ) { Prado.JuiCallback(".TJavascript::encode($this->_control->getUniqueID()).", ".TJavascript::encode($event).", event, ui, this); }"); + + return $ret; + } + + /** + * Raise the specific callback event handler of the target control. + * @param mixed callback parameters + */ + public function raiseCallbackEvent($param) + { + $callbackParam=$param->CallbackParameter; + if(isset($callbackParam->event)) + { + $eventName = 'On'.ucfirst($callbackParam->event); + if($this->_control->hasEventHandler($eventName)) + { + $this->_control->$eventName( new TJuiEventParameter( + $this->_control->getResponse(), + isset($callbackParam->ui) ? $callbackParam->ui : null) + ); + } + } + } +} + +/** + * TJuiEventParameter class + * + * TJuiEventParameter encapsulate the parameters for callback + * events of TJui* components. + * Any parameter representing a control is identified by its + * clientside ID. + * TJuiEventParameter contains a {@link getControl} helper method + * that retrieves an existing PRADO control on che current page from its + * clientside ID as returned by the callback. + * For example, if the parameter contains a "draggable" item (as returned in + * {@link TJuiDroppable}::OnDrop event), the relative PRADO control can be + * retrieved using: + * <code> + * $draggable = $param->getControl($param->getCallbackParameter()->draggable); + * </code> + * + * A shortcut __get() method is implemented, too: + * <code> + * $draggable = $param->DraggableControl; + * </code> + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @license http://www.pradosoft.com/license + * @package System.Web.UI.JuiControls + */ +class TJuiEventParameter extends TCallbackEventParameter +{ + /** + * getControl + * + * Compatibility method to get a control from its clientside id + * @return TControl control, or null if not found + */ + public function getControl($id) + { + $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 ! + $controlId=str_replace(TControl::CLIENT_ID_SEPARATOR,TControl::ID_SEPARATOR,$id); + $control=$service->getRequestedPage()->findControl($controlId); + } + return $control; + } + + /** + * Gets a control instance named after a returned control id. + * Example: if a $param->draggable control id is returned from clientside, + * calling $param->DraggableControl will return the control instance + * @return mixed control or null if not set. + */ + public function __get($name) + { + $pos=strpos($name, 'Control',1); + $name=strtolower(substr($name, 0, $pos)); + + $cp=$this->getCallbackParameter(); + if(!isset($cp->$name) || $cp->$name=='') + return null; + + return $this->getControl($cp->$name); + } +}
\ No newline at end of file diff --git a/framework/Web/UI/JuiControls/TJuiDraggable.php b/framework/Web/UI/JuiControls/TJuiDraggable.php new file mode 100644 index 00000000..56e6c7e7 --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiDraggable.php @@ -0,0 +1,150 @@ +<?php +/** + * TJuiDraggable class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); +Prado::using('System.Web.UI.ActiveControls.TActivePanel'); + +/** + * TJuiDraggable class. + * + * TJuiDraggable is an extension to {@link TActivePanel} based on jQuery-UI's + * {@link http://jqueryui.com/draggable/ Draggable} interaction. + * The panel can be moved using the mouse, and eventually dropped over a + * {@link TJuiDroppable}. + * + * <code> + * <com:TJuiDraggable + * ID="drag1" + * Style="border: 1px solid red; width:100px;height:100px" + * Options.Axis="y" + * OnStop="drag1_dragged" + * > + * drag me + * </com:TJuiDraggable> + * </code> + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiDraggable extends TActivePanel implements IJuiOptions, ICallbackEventHandler +{ + protected $_options; + + /** + * 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() + { + if($this->_options===null) + $this->_options=new TJuiControlOptions($this); + return $this->_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'); + } + + /** + * Array containing valid javascript events + * @return array() + */ + public function getValidEvents() + { + return array('create', 'drag', 'start', 'stop'); + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + return $this->getOptions()->toArray(); + } + + /** + * 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); + } + + /** + * Raises callback event. This method is required by the {@link ICallbackEventHandler} + * interface. + * @param TCallbackEventParameter the parameter associated with the callback event + */ + public function raiseCallbackEvent($param) + { + $this->getOptions()->raiseCallbackEvent($param); + } + + /** + * Raises the OnCreate event + * @param object $params event parameters + */ + public function onCreate ($params) + { + $this->raiseEvent('OnCreate', $this, $params); + } + + /** + * Raises the OnDrag event + * @param object $params event parameters + */ + public function onDrag ($params) + { + $this->raiseEvent('OnDrag', $this, $params); + } + + /** + * Raises the OnStart event + * @param object $params event parameters + */ + public function onStart ($params) + { + $this->raiseEvent('OnStart', $this, $params); + } + + /** + * Raises the OnStop event + * @param object $params event parameters + */ + public function onStop ($params) + { + $this->raiseEvent('OnStop', $this, $params); + } +} diff --git a/framework/Web/UI/JuiControls/TJuiDroppable.php b/framework/Web/UI/JuiControls/TJuiDroppable.php new file mode 100644 index 00000000..2d2ed6b9 --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiDroppable.php @@ -0,0 +1,201 @@ +<?php +/** + * TJuiDroppable class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); +Prado::using('System.Web.UI.ActiveControls.TActivePanel'); + +/** + * TJuiDroppable class. + * + * TJuiDroppable is an extension to {@link TActivePanel} based on jQuery-UI's + * {@link http://jqueryui.com/droppable/ Droppable} interaction. + * When a {@link TJuiDraggable} is dropped over a TJuiDroppable panel, the + * {@link onDrop OnDrop} event will be triggered. The event hanler will receive + * a {@link TJuiEventParameter} object containing a reference to the dropped control + * in the <tt>DraggableControl</tt> property. + * + * <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->DraggableControl; + * $offset=$param->getCallbackParameter()->offset; + * $target=$param->getCallbackParameter()->target->offset; + * $top=$offset->top - $target->top; + * $left=$offset->left - $target->left; + * $this->label1->Text="Dropped ".$draggable->ID." at: <br/>Top=".$top." Left=".$left; + * } + * </code> + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiDroppable extends TActivePanel implements IJuiOptions, ICallbackEventHandler +{ + protected $_options; + + /** + * 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() + { + if($this->_options===null) + $this->_options=new TJuiControlOptions($this); + return $this->_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'); + } + + /** + * Array containing valid javascript events + * @return array() + */ + public function getValidEvents() + { + return array('activate', 'create', 'deactivate', 'drop', 'out', 'over'); + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + return $this->getOptions()->toArray(); + } + + /** + * 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); + } + + /** + * Raises callback event. This method is required by the {@link ICallbackEventHandler} + * interface. + * @param TCallbackEventParameter the parameter associated with the callback event + */ + public function raiseCallbackEvent($param) + { + $this->getOptions()->raiseCallbackEvent($param); + } + + /** + * Raises the OnActivate event + * @param object $params event parameters + */ + public function onActivate ($params) + { + $this->raiseEvent('OnActivate', $this, $params); + } + + /** + * Raises the OnCreate event + * @param object $params event parameters + */ + public function onCreate ($params) + { + $this->raiseEvent('OnCreate', $this, $params); + } + + /** + * Raises the OnDeactivate event + * @param object $params event parameters + */ + public function onDeactivate ($params) + { + $this->raiseEvent('OnDeactivate', $this, $params); + } + + /** + * Raises the OnDrop event + * @param object $params event parameters + */ + public function onDrop ($params) + { + $this->raiseEvent('OnDrop', $this, $params); + } + + /** + * Raises the OnOut event + * @param object $params event parameters + */ + public function OnOut ($params) + { + $this->raiseEvent('OnOut', $this, $params); + } + + /** + * Raises the OnOver event + * @param object $params event parameters + */ + public function OnOver ($params) + { + $this->raiseEvent('OnOver', $this, $params); + } + + /** + * 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); + } +} diff --git a/framework/Web/UI/JuiControls/TJuiProgressbar.php b/framework/Web/UI/JuiControls/TJuiProgressbar.php new file mode 100644 index 00000000..41f3eab4 --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiProgressbar.php @@ -0,0 +1,137 @@ +<?php +/** + * TJuiProgressbar class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); +Prado::using('System.Web.UI.ActiveControls.TActivePanel'); + +/** + * TJuiProgressbar class. + * + * TJuiProgressbar is an extension to {@link TActivePanel} based on jQuery-UI's + * {@link http://jqueryui.com/progressbar/ Progressbar} widget. + * + * <code> + * <com:TJuiProgressbar + * ID="pbar1" + * Options.Max="100" + * Options.Value="75" + * OnChange="pbar1_changed" + * /> + * </code> + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiProgressbar extends TActivePanel implements IJuiOptions, ICallbackEventHandler +{ + protected $_options; + + /** + * 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() + { + if($this->_options===null) + $this->_options=new TJuiControlOptions($this); + return $this->_options; + } + + /** + * Array containing valid javascript options + * @return array() + */ + public function getValidOptions() + { + return array('disabled', 'max', 'value'); + } + + /** + * Array containing valid javascript events + * @return array() + */ + public function getValidEvents() + { + return array('change', 'complete', 'create'); + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + return $this->getOptions()->toArray(); + } + + /** + * 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()."').progressbar(".$options.");"; + $cs->registerEndScript(sprintf('%08X', crc32($code)), $code); + } + + /** + * Raises callback event. This method is required by the {@link ICallbackEventHandler} + * interface. + * @param TCallbackEventParameter the parameter associated with the callback event + */ + public function raiseCallbackEvent($param) + { + $this->getOptions()->raiseCallbackEvent($param); + } + + /** + * Raises the OnChange event + * @param object $params event parameters + */ + public function onChange($params) + { + $this->raiseEvent('OnChange', $this, $params); + } + + /** + * Raises the OnComplete event + * @param object $params event parameters + */ + public function onComplete($params) + { + $this->raiseEvent('OnComplete', $this, $params); + } + + /** + * Raises the OnCreate event + * @param object $params event parameters + */ + public function onCreate($params) + { + $this->raiseEvent('OnCreate', $this, $params); + } +} diff --git a/framework/Web/UI/JuiControls/TJuiResizable.php b/framework/Web/UI/JuiControls/TJuiResizable.php new file mode 100644 index 00000000..5e1f8d31 --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiResizable.php @@ -0,0 +1,153 @@ +<?php +/** + * TJuiResizable class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); +Prado::using('System.Web.UI.ActiveControls.TActivePanel'); + +/** + * TJuiResizable class. + * + * TJuiResizable is an extension to {@link TActivePanel} based on jQuery-UI's + * {@link http://jqueryui.com/resizable/ Resizable} interaction. + * A small handle is shown on the bottom right corner of the panel, that permits + * the panel to be resized using the mouse. + * + * <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> + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiResizable extends TActivePanel implements IJuiOptions, ICallbackEventHandler +{ + protected $_options; + + /** + * 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() + { + if($this->_options===null) + $this->_options=new TJuiControlOptions($this); + return $this->_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'); + } + + /** + * Array containing valid javascript events + * @return array() + */ + public function getValidEvents() + { + return array('create', 'resize', 'start', 'stop'); + } + + /** + * @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); + } + + /** + * Raises callback event. This method is required by the {@link ICallbackEventHandler} + * interface. + * @param TCallbackEventParameter the parameter associated with the callback event + */ + public function raiseCallbackEvent($param) + { + $this->getOptions()->raiseCallbackEvent($param); + } + + /** + * Raises the OnCreate event + * @param object $params event parameters + */ + public function onCreate ($params) + { + $this->raiseEvent('OnCreate', $this, $params); + } + + /** + * Raises the OnResize event + * @param object $params event parameters + */ + public function onResize ($params) + { + $this->raiseEvent('OnResize', $this, $params); + } + + /** + * Raises the OnStart event + * @param object $params event parameters + */ + public function onStart ($params) + { + $this->raiseEvent('OnStart', $this, $params); + } + + /** + * Raises the OnStop event + * @param object $params event parameters + */ + public function onStop ($params) + { + $this->raiseEvent('OnStop', $this, $params); + } +} diff --git a/framework/Web/UI/JuiControls/TJuiSelectable.php b/framework/Web/UI/JuiControls/TJuiSelectable.php new file mode 100644 index 00000000..b370d14a --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiSelectable.php @@ -0,0 +1,261 @@ +<?php +/** + * TJuiSelectable class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); +Prado::using('System.Web.UI.ActiveControls.TActivePanel'); + +/** + * TJuiSelectable class. + * + * TJuiSelectable is an extension to {@link TActivePanel} based on jQuery-UI's + * {@link http://jqueryui.com/selectable/ Selectable} interaction. + * TJuiSelectable can be feed a {@link setDataSource DataSource} and will interally + * render a {@link TRepeater} that displays items in an unordered list. + * Items can be selected by clicking on them, individually or in a group. + * + * <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> + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiSelectable extends TActivePanel implements IJuiOptions, ICallbackEventHandler +{ + protected $_options; + + /** + * 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() + { + if($this->_options===null) + $this->_options=new TJuiControlOptions($this); + return $this->_options; + } + + /** + * Array containing valid javascript options + * @return array() + */ + public function getValidOptions() + { + return array('appendTo', 'autoRefresh', 'cancel', 'delay', 'disabled', 'distance', 'filter', 'tolerance'); + } + + /** + * Array containing valid javascript events + * @return array() + */ + public function getValidEvents() + { + return array('create', 'selected', 'selecting', 'start', 'stop', 'unselected', 'unselecting'); + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + $options = $this->getOptions()->toArray(); + // overload the "OnStop" event to add information about the current selected items + if(isset($options['stop'])) + { + $options['stop']=new TJavaScriptLiteral('function( event, ui ) { ui.index = new Array(); jQuery(\'#'.$this->getClientID().' .ui-selected\').each(function(idx, item){ ui.index.push(item.id) }); Prado.JuiCallback('.TJavascript::encode($this->getUniqueID()).', \'stop\', event, ui, this); }'); + } + 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); + } + + /** + * Raises callback event. This method is required by the {@link ICallbackEventHandler} + * interface. + * @param TCallbackEventParameter the parameter associated with the callback event + */ + public function raiseCallbackEvent($param) + { + $this->getOptions()->raiseCallbackEvent($param); + } + + /** + * Raises the OnCreate event + * @param object $params event parameters + */ + public function onCreate ($params) + { + $this->raiseEvent('OnCreate', $this, $params); + } + + /** + * Raises the OnSelected event + * @param object $params event parameters + */ + public function onSelected ($params) + { + $this->raiseEvent('OnSelected', $this, $params); + } + + /** + * Raises the OnSelecting event + * @param object $params event parameters + */ + public function onSelecting ($params) + { + $this->raiseEvent('OnSelecting', $this, $params); + } + + /** + * Raises the OnStart event + * @param object $params event parameters + */ + public function onStart ($params) + { + $this->raiseEvent('OnStart', $this, $params); + } + + /** + * Raises the OnStop event + * @param object $params event parameters + */ + public function onStop ($params) + { + $this->raiseEvent('OnStop', $this, $params); + } + + /** + * Raises the OnUnselected event + * @param object $params event parameters + */ + public function onUnselected ($params) + { + $this->raiseEvent('OnUnselected', $this, $params); + } + + /** + * Raises the OnUnselecting event + * @param object $params event parameters + */ + public function onUnselecting ($params) + { + $this->raiseEvent('OnUnselecting', $this, $params); + } + + /** + * @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 id="<%# $this->ItemIndex %>"><%# $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> + * @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); + } +} diff --git a/framework/Web/UI/JuiControls/TJuiSortable.php b/framework/Web/UI/JuiControls/TJuiSortable.php new file mode 100644 index 00000000..2fdf80dc --- /dev/null +++ b/framework/Web/UI/JuiControls/TJuiSortable.php @@ -0,0 +1,314 @@ +<?php +/** + * TJuiSortable class file. + * + * @author Fabio Bas <ctrlaltca[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2013-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.UI.JuiControls + */ + +Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter'); +Prado::using('System.Web.UI.ActiveControls.TActivePanel'); + +/** + * TJuiSortable class. + * + * TJuiSortable is an extension to {@link TActivePanel} based on jQuery-UI's + * {@link http://jqueryui.com/sortable/ Sortable} interaction. + * The panel can be feed a {@link setDataSource DataSource} and will interally + * render a {@link TRepeater} that displays items in an unordered list. + * Items can be sortered dragging and dropping them. + * + * <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> + * @package System.Web.UI.JuiControls + * @since 3.3 + */ +class TJuiSortable extends TActivePanel implements IJuiOptions, ICallbackEventHandler +{ + protected $_options; + + /** + * 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() + { + if($this->_options===null) + $this->_options=new TJuiControlOptions($this); + return $this->_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'); + } + + /** + * Array containing valid javascript events + * @return array() + */ + public function getValidEvents() + { + return array('activate', 'beforeStop', 'change', 'create', 'deactivate', 'out', 'over', 'receive', 'remove', 'sort', 'start', 'stop', 'update'); + } + + /** + * @return array list of callback options. + */ + protected function getPostBackOptions() + { + $options = $this->getOptions()->toArray(); + // overload some events to add information about the items order + foreach($options as $event => $implementation) + { + if($event=='sort' || $event=='stop') + $options[$event]=new TJavaScriptLiteral('function( event, ui ) { ui.index = jQuery(this).sortable(\'toArray\'); Prado.JuiCallback('.TJavascript::encode($this->getUniqueID()).', \''.$event.'\', event, ui, this); }'); + } + 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); + } + + /** + * Raises callback event. This method is required by the {@link ICallbackEventHandler} + * interface. + * @param TCallbackEventParameter the parameter associated with the callback event + */ + public function raiseCallbackEvent($param) + { + $this->getOptions()->raiseCallbackEvent($param); + } + + /** + * Raises the OnActivate event + * @param object $params event parameters + */ + public function onActivate ($params) + { + $this->raiseEvent('OnActivate', $this, $params); + } + + /** + * Raises the OnBeforeStop event + * @param object $params event parameters + */ + public function onBeforeStop ($params) + { + $this->raiseEvent('OnBeforeStop', $this, $params); + } + + /** + * Raises the OnChange event + * @param object $params event parameters + */ + public function onChange ($params) + { + $this->raiseEvent('OnChange', $this, $params); + } + + /** + * Raises the OnCreate event + * @param object $params event parameters + */ + public function onCreate ($params) + { + $this->raiseEvent('OnCreate', $this, $params); + } + + /** + * Raises the OnDeactivate event + * @param object $params event parameters + */ + public function onDeactivate ($params) + { + $this->raiseEvent('OnDeactivate', $this, $params); + } + + /** + * Raises the OnOut event + * @param object $params event parameters + */ + public function onOut ($params) + { + $this->raiseEvent('OnOut', $this, $params); + } + + /** + * Raises the OnOver event + * @param object $params event parameters + */ + public function onOver ($params) + { + $this->raiseEvent('OnOver', $this, $params); + } + + /** + * Raises the OnReceive event + * @param object $params event parameters + */ + public function onReceive ($params) + { + $this->raiseEvent('OnReceive', $this, $params); + } + + /** + * Raises the OnRemove event + * @param object $params event parameters + */ + public function onRemove ($params) + { + $this->raiseEvent('OnRemove', $this, $params); + } + + /** + * Raises the OnSort event + * @param object $params event parameters + */ + public function onSort ($params) + { + $this->raiseEvent('OnSort', $this, $params); + } + + /** + * Raises the OnStart event + * @param object $params event parameters + */ + public function onStart ($params) + { + $this->raiseEvent('OnStart', $this, $params); + } + + /** + * Raises the OnStop event + * @param object $params event parameters + */ + public function OnStop ($params) + { + $this->raiseEvent('OnStop', $this, $params); + } + + /** + * Raises the OnUpdate event + * @param object $params event parameters + */ + public function onUpdate ($params) + { + $this->raiseEvent('OnUpdate', $this, $params); + } + + /** + * @var ITemplate template for repeater items + */ + private $_repeater=null; + + /** + * @param array data source for Sortables. + */ + public function setDataSource($data) + { + $this->getSortables()->setDataSource($data); + } + + /** + * Overrides parent implementation. Callback {@link renderSortables()} when + * page's IsCallback property is true. + */ + public function dataBind() + { + parent::dataBind(); + if($this->getPage()->getIsCallback()) + $this->renderSortables($this->getResponse()->createHtmlWriter()); + } + + /** + * @return TRepeater suggestion list repeater + */ + public function getSortables() + { + if($this->_repeater===null) + $this->_repeater = $this->createRepeater(); + return $this->_repeater; + } + + /** + * @return TRepeater new instance of TRepater to render the list of Sortables. + */ + 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 id="<%# $this->ItemIndex %>"><%# $this->Data %></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> + * @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); + } +} |