Jump to content


Photo

Retrieve checked items in RelatedistView


  • Please log in to reply
11 replies to this topic

#1 k1000o

k1000o

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationMadrid

Posted 07 June 2012 - 09:07 PM

Hello
I added a new column adapter to the RelatedListView in order to apply action on the selected items CheckColumnAdapter.png

After that a new ActionElement has been added on the header on the table to trigger an action that will act on the selected lines.

CustomAction.png .

How can i retrieve in the code of the action the list of elements that have been selected?

#2 Jason

Jason

    Administrator

  • Administrators
  • 716 posts
  • LocationChicago

Posted 07 June 2012 - 09:55 PM

Check out ListViewUtils.js.

jQuery.each($('#' + gridViewId + "-selectedIds")

if you know the gridViewId, you can get it.

Let me know if that helps.

Jason Green
Zurmo Team
Need support? Upgrade now


#3 k1000o

k1000o

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationMadrid

Posted 08 June 2012 - 01:28 PM

After analyzing the standard Zurmo structure i changed the strategy to be closer to the standard, so in this way we should normally retrieve the behavior you describe.

Instead of creating a new column on the relatedListView to check the columns, create a new view called RelatedSelectableListView based on RelatedListView but making some modifications to make the select column appear.
RelatedListView.png

The result is o.k , the column appears.

columns.png

but I am unable to retrieve in my action the value of the checked lines. When I try to catch the selected elements with this function the system fails.

$misIds = trim($_GET['selectedIds'], " ,");

Did I need to change something in the way the action is called so it includes the selectedIds?

array('type'				=> 'C_invoicedetailDeleteAllFromRelatedListLink',
'routeModuleId'		 => 'eval:$this->moduleId',
'routeParameters'	   => 'eval:$this->getCreateLinkRouteParameters()',
'portletId'			 => 'eval:$this->params["portletId"]',
'relationAttributeName' => 'eval:$this->getRelationAttributeName()',
'relationModelId'	   => 'eval:$this->params["relationModel"]->id',
'relationModuleId'	  => 'eval:$this->params["relationModuleId"]',
'uniqueLayoutId'		=> 'eval:$this->uniqueLayoutId',
'htmlOptions'		   => array('id'					=> 'SelectDetailsForInvoiceFromRelatedListLink',
'class'				 => 'icon-edit',
'live'				  => false) //This is there are no double bindings
),

Posted Image

#4 Jason

Jason

    Administrator

  • Administrators
  • 716 posts
  • LocationChicago

Posted 08 June 2012 - 01:29 PM

After analyzing the standard Zurmo structure i changed the strategy to be closer to the standard, so in this way we should normally retrieve the behavior you describe.

Instead of creating a new column on the relatedListView to check the columns, create a new view called RelatedSelectableListView based on RelatedListView but making some modifications to make the select column appear.
RelatedListView.png

The result is o.k , the column appears.

columns.png

but I am unable to retrieve in my action the value of the checked lines. When I try to catch the selected elements with this function the system fails.

$misIds = trim($_GET['selectedIds'], " ,");

What do you mean the system fails?

Jason Green
Zurmo Team
Need support? Upgrade now


#5 k1000o

k1000o

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationMadrid

Posted 08 June 2012 - 01:36 PM

The execution stops, the parameter selected Ids is not retrieved.
The value of $_GETis null.

#6 Jason

Jason

    Administrator

  • Administrators
  • 716 posts
  • LocationChicago

Posted 08 June 2012 - 08:54 PM

Are you calling Ajax after you check a box? Or what controller action are you calling when you expect to read the selectedIds ?

Jason Green
Zurmo Team
Need support? Upgrade now


#7 k1000o

k1000o

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationMadrid

Posted 08 June 2012 - 10:31 PM

In the view the parameters are defined like this.

	abstract class C_invoicedetailsRelatedListView extends SecuredRelatedSelectableListView
	{
		public static function getDefaultMetadata()
		{
			$metadata = array(
				'perUser' => array(
					'title'			=> "eval:Yii::t('Default', 'C_invoicedetailsModulePluralLabel', LabelUtil::getTranslationParamsForAllModules())",
					'searchAttributes' => array('ownedItemsOnly' => true),
				),
				'global'		 => array(
					'toolbar' => array(
						'elements' => array(
							array('type'			=> 'CreateFromRelatedListLink',
								'routeModuleId'   => 'eval:$this->moduleId',
								'routeParameters' => 'eval:$this->getCreateLinkRouteParameters()'),
							array('type'				  => 'C_invoicedetailDeleteAllFromRelatedListLink',
								'portletId'			 => 'eval:$this->params["portletId"]',
								'relationAttributeName' => 'eval:$this->getRelationAttributeName()',
								'relationModelId'	   => 'eval:$this->params["relationModel"]->id',
								'relationModuleId'	  => 'eval:$this->params["relationModuleId"]',
								'uniqueLayoutId'		=> 'eval:$this->uniqueLayoutId',
								'selectedIds'		   => 'sdfsdfsdf',
								'htmlOptions'		   => array('id'					=> 'SelectDetailsForInvoiceFromRelatedListLink',
									'class'				 => 'icon-edit',
									'live'				  => false) //This is there are no double bindings
							),
						),
					),


So the view is calling C_invoicedetailDeleteAllFromRelatedListLink

Which is an AjaxLinkActionElement

	 class C_invoicedetailDeleteAllFromRelatedListLinkActionElement extends AjaxLinkActionElement
	{
		 public function getActionType()
		{
			return null;
		}
		protected function getDefaultLabel()
		{
			return Yii::t('Default', 'CBR');
		}
		protected function getDefaultRoute()
		{
			return Yii::app()->createUrl($this->moduleId . '/default/DeleteSelectedFromRelatedList/',
					array(
					'uniqueLayoutId'		  => $this->getUniqueLayoutId(),
					'portletId'			   => $this->getPortletId(),
					'relationAttributeName'   => $this->params['relationAttributeName'],
					'relationModelId'		 => $this->params['relationModelId'],
					'relationModuleId'		=> $this->params['relationModuleId'],
					'selectedIds'			 => $this->params['selectedIds'],
					)
			);
		}

Who is calling a method in the default controller of the class C_invoicedetailsDefaultController

	public function actionDeleteSelectedFromRelatedList($portletId, $uniqueLayoutId, $relationAttributeName,
			$relationModelId, $relationModuleId, $selectedIds, $pageTitle = null, $stateMetadataAdapterClassName = null) {

I just discovered that the hidden field that holds the ids is called list-view-selectedIds. The values in this field is what I need to send to the Ajax method.
selected ids.png

#8 Jason

Jason

    Administrator

  • Administrators
  • 716 posts
  • LocationChicago

Posted 09 June 2012 - 03:02 AM

In the view the parameters are defined like this.

	abstract class C_invoicedetailsRelatedListView extends SecuredRelatedSelectableListView
	{
		public static function getDefaultMetadata()
		{
			$metadata = array(
				'perUser' => array(
					'title'			=> "eval:Yii::t('Default', 'C_invoicedetailsModulePluralLabel', LabelUtil::getTranslationParamsForAllModules())",
					'searchAttributes' => array('ownedItemsOnly' => true),
				),
				'global'		 => array(
					'toolbar' => array(
						'elements' => array(
							array('type'			=> 'CreateFromRelatedListLink',
								'routeModuleId'   => 'eval:$this->moduleId',
								'routeParameters' => 'eval:$this->getCreateLinkRouteParameters()'),
							array('type'				  => 'C_invoicedetailDeleteAllFromRelatedListLink',
								'portletId'			 => 'eval:$this->params["portletId"]',
								'relationAttributeName' => 'eval:$this->getRelationAttributeName()',
								'relationModelId'	   => 'eval:$this->params["relationModel"]->id',
								'relationModuleId'	  => 'eval:$this->params["relationModuleId"]',
								'uniqueLayoutId'		=> 'eval:$this->uniqueLayoutId',
								'selectedIds'		   => 'sdfsdfsdf',
								'htmlOptions'		   => array('id'					=> 'SelectDetailsForInvoiceFromRelatedListLink',
									'class'				 => 'icon-edit',
									'live'				  => false) //This is there are no double bindings
							),
						),
					),


So the view is calling C_invoicedetailDeleteAllFromRelatedListLink

Which is an AjaxLinkActionElement

	 class C_invoicedetailDeleteAllFromRelatedListLinkActionElement extends AjaxLinkActionElement
	{
		 public function getActionType()
		{
			return null;
		}
		protected function getDefaultLabel()
		{
			return Yii::t('Default', 'CBR');
		}
		protected function getDefaultRoute()
		{
			return Yii::app()->createUrl($this->moduleId . '/default/DeleteSelectedFromRelatedList/',
					array(
					'uniqueLayoutId'		  => $this->getUniqueLayoutId(),
					'portletId'			   => $this->getPortletId(),
					'relationAttributeName'   => $this->params['relationAttributeName'],
					'relationModelId'		 => $this->params['relationModelId'],
					'relationModuleId'		=> $this->params['relationModuleId'],
					'selectedIds'			 => $this->params['selectedIds'],
					)
			);
		}

Who is calling a method in the default controller of the class C_invoicedetailsDefaultController

	public function actionDeleteSelectedFromRelatedList($portletId, $uniqueLayoutId, $relationAttributeName,
			$relationModelId, $relationModuleId, $selectedIds, $pageTitle = null, $stateMetadataAdapterClassName = null) {

I just discovered that the hidden field that holds the ids is called list-view-selectedIds. The values in this field is what I need to send to the Ajax method.
selected ids.png

Because right now you are just sending the selectedIds via params, instead of using jscript. You need to use jscript. Do you now see what you need to do? If not let me know.

Jason Green
Zurmo Team
Need support? Upgrade now


#9 k1000o

k1000o

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationMadrid

Posted 09 June 2012 - 06:41 AM

I think solved it!!!!!
But i need some help with the usage of the action ActionElement, I'm not sure if I am using it the proper way.

The code used is the following but I made made trick in the Render() and getDefaultRoute() functions.

 
class C_invoicedetailDelSelFromRelListLinkActionElement extends ActionElement
{
 
public function getActionType()
{
return null;
}
 
protected function getDefaultLabel()
{
return Yii::t('Default',
 'CBR');
}
 
public function render()
{
return $this->route;
}
 
protected function getDefaultRoute()
{
$content = CHtml::link("CBR",
  "#",
  array("onclick" => "DelSelDetailFRelation()", "confirm" => "Are you sure you want to all selected elements??"));
 
Yii::app()->clientScript->registerScript('delSelDetailFromListViewScript',
"
function DelSelDetailFRelation()
{                
$.ajax({
url : '" . Yii::app()->createUrl('c_invoicedetails/default/DelSelFRelListFromAjax') . "'  ,
type : 'GET',
dataType : 'json',
data : {'checkedIds': document.getElementById('list-view-selectedIds').value},
success : function(data)
{
//remove row    
},
error : function()
{
//todo: error call
}
});
}
",
CClientScript::POS_END);
return $content;
}
 
protected function getUniqueLayoutId()
{
if (isset($this->params['uniqueLayoutId'])) {
return $this->params['uniqueLayoutId'];
}
return null;
}
 
protected function getPortletId()
{
if (isset($this->params['portletId'])) {
return $this->params['portletId'];
}
return null;
}
}


#10 Jason

Jason

    Administrator

  • Administrators
  • 716 posts
  • LocationChicago

Posted 11 June 2012 - 01:56 PM

In render method, i would probably have renderLink and renderScripts methods. Then in render link you can get the route and make your link, and in renderScripts you can register your script.

Jason Green
Zurmo Team
Need support? Upgrade now


#11 k1000o

k1000o

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationMadrid

Posted 11 June 2012 - 06:21 PM

Thanks, information seems more ordered this way
 
		public function render()
		{
			$this->renderScripts();
			return $this->renderLink();
		}
 
		protected function renderLink()
		{
			return CHtml::link("CBR",
							   "#",
							   array("onclick" => "DelSelDetailFRelation()", "confirm" => "Are you sure you want to all selected elements??"));
		}
 
		protected function renderScripts()
		{
			Yii::app()->clientScript->registerScript('delSelDetailFromListViewScript',
													 "
			function DelSelDetailFRelation()
			{				
					$.ajax({
						url : '" . Yii::app()->createUrl('c_invoicedetails/default/DelSelFRelListFromAjax') . "'  ,
						type : 'GET',
						dataType : 'json',
						data : {'checkedIds': document.getElementById('list-view-selectedIds').value},
						success : function(data)
						{
							//remove row	
						},
						error : function()
						{
							//todo: error call
						}
					});
			}
		",  CClientScript::POS_END);
		}
 
		protected function getDefaultRoute()
		{
			if (Yii::app()->request->getParam('redirectUrl') != null) {
				return Yii::app()->request->getParam('redirectUrl');
			}
			elseif (!empty($this->params["relationModelId"]) && $this->params["relationModelId"] > 0) {
				return Yii::app()->createUrl($this->params["relationModuleId"] . '/' . $this->controllerId . '/details/',
											 array('id' => $this->params["relationModelId"]));
			}
			else {
				return Yii::app()->createUrl($this->params["relationModuleId"] . '/' . $this->controllerId);
			}
		}


#12 Jason

Jason

    Administrator

  • Administrators
  • 716 posts
  • LocationChicago

Posted 12 June 2012 - 02:55 PM

Great

Jason Green
Zurmo Team
Need support? Upgrade now





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users