summaryrefslogtreecommitdiff
path: root/framework/Web/UI/JuiControls/TJuiSelectable.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI/JuiControls/TJuiSelectable.php')
-rw-r--r--framework/Web/UI/JuiControls/TJuiSelectable.php57
1 files changed, 55 insertions, 2 deletions
diff --git a/framework/Web/UI/JuiControls/TJuiSelectable.php b/framework/Web/UI/JuiControls/TJuiSelectable.php
index 6c020951..e895c1f8 100644
--- a/framework/Web/UI/JuiControls/TJuiSelectable.php
+++ b/framework/Web/UI/JuiControls/TJuiSelectable.php
@@ -31,7 +31,7 @@ Prado::using('System.Web.UI.JuiControls.TJuiControlAdapter');
* @package System.Web.UI.JuiControls
* @since 3.3
*/
-class TJuiSelectable extends TActivePanel implements IJuiOptions
+class TJuiSelectable extends TActivePanel implements IJuiOptions, ICallbackEventHandler
{
/**
* Creates a new callback control, sets the adapter to
@@ -71,6 +71,7 @@ class TJuiSelectable extends TActivePanel implements IJuiOptions
protected function getPostBackOptions()
{
$options = $this->getOptions()->toArray();
+ $options['stop'] = new TJavaScriptLiteral('function( event, ui ) { var selected = new Array(); jQuery(\'#'.$this->getClientID().' .ui-selected\').each(function(idx, item){ selected.push(item.id) }); Prado.Callback('.TJavascript::encode($this->getUniqueID()).', { \'indexes\' : selected }) }');
return $options;
}
@@ -89,6 +90,43 @@ class TJuiSelectable extends TActivePanel implements IJuiOptions
}
/**
+ * Raises callback event. This method is required bu {@link ICallbackEventHandler}
+ * interface.
+ * It raises the {@link onSelectedIndexChanged onSelectedIndexChanged} 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->onSelectedIndexChanged($param->getCallbackParameter());
+ $this->onCallback($param);
+ }
+
+ /**
+ * Raises the onSelect event.
+ * The selection parameters are encapsulated into a {@link TJuiSelectableEventParameter}
+ *
+ * @param object $params
+ */
+ public function onSelectedIndexChanged($params)
+ {
+ $this->raiseEvent('onSelectedIndexChanged', $this, new TJuiSelectableEventParameter ($this->getResponse(), $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);
+ }
+
+ /**
* @var ITemplate template for repeater items
*/
private $_repeater=null;
@@ -130,7 +168,7 @@ class TJuiSelectable extends TActivePanel implements IJuiOptions
$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->setItemTemplate(new TTemplate('<li id="<%# $this->ItemIndex %>"><%# $this->DataItem %></li>',null));
$repeater->setEmptyTemplate(new TJuiSelectableTemplate('<ul></ul>'));
$this->getControls()->add($repeater);
return $repeater;
@@ -165,4 +203,19 @@ class TJuiSelectableTemplate extends TComponent implements ITemplate
{
$parent->getControls()->add($this->_template);
}
+}
+
+/**
+ * TJuiSelectableEventParameter class
+ *
+ * TJuiSelectableEventParameter encapsulate the parameter
+ * data for <b>OnSelectedIndexChanged</b> event of TJuiSelectable components
+ *
+ * @author Fabio Bas <ctrlaltca[at]gmail[dot]com>
+ * @license http://www.pradosoft.com/license
+ * @package System.Web.UI.JuiControls
+ */
+class TJuiSelectableEventParameter extends TCallbackEventParameter
+{
+ public function getSelectedIndexes() { return $this->getCallbackParameter()->indexes; }
} \ No newline at end of file