summaryrefslogtreecommitdiff
path: root/framework/Web/UI/JuiControls
diff options
context:
space:
mode:
authorDaniel <darthdaniel85@gmail.com>2013-12-24 17:59:22 -0500
committerDaniel <darthdaniel85@gmail.com>2013-12-24 17:59:22 -0500
commitf235957dd296183ff6c427290c7c52397ad95078 (patch)
treea528753ba3fd3bae43ac982295978a8714031364 /framework/Web/UI/JuiControls
parentec9ebfe3f0680b6f451829bf0111eb69fe092b24 (diff)
parentde198e5bca106ab71ac1d62b45e332aef0601708 (diff)
all ready
Diffstat (limited to 'framework/Web/UI/JuiControls')
-rw-r--r--framework/Web/UI/JuiControls/TJuiAutoComplete.php425
-rw-r--r--framework/Web/UI/JuiControls/TJuiControlAdapter.php177
-rw-r--r--framework/Web/UI/JuiControls/TJuiDraggable.php91
-rw-r--r--framework/Web/UI/JuiControls/TJuiDroppable.php188
-rw-r--r--framework/Web/UI/JuiControls/TJuiResizable.php94
-rw-r--r--framework/Web/UI/JuiControls/TJuiSelectable.php171
-rw-r--r--framework/Web/UI/JuiControls/TJuiSortable.php168
7 files changed, 1314 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..a8bf2d81
--- /dev/null
+++ b/framework/Web/UI/JuiControls/TJuiAutoComplete.php
@@ -0,0 +1,425 @@
+<?php
+/**
+ * TJuiAutoComplete class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2013 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id: TJuiAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @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>
+ * @version $Id: TJuiAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @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');
+ }
+
+ /**
+ * @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>
+ * @version $Id: TJuiAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @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>
+ * @version $Id: TJuiAutoComplete.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @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..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 &copy; 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 &copy; 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 &copy; 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 &copy; 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 &copy; 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 &copy; 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 &copy; 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