Jump to content


Photo

Refresh Portlet via Ajax

Refresh Portlet Ajax

  • Please log in to reply
2 replies to this topic

#1 k1000o

k1000o

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationMadrid

Posted 11 June 2012 - 09:14 PM

Hello
I am trying to refresh list view portlet via ajax after deleting one of the values in the success action.
How would you approach this in zurmo?

My first approach has been to:
1) Create the getDefaultRoute method as follows

		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"],
							'portletId'	  => $this->params["portletId"],
							'uniqueLayoutId' => $this->params["uniqueLayoutId"],
							'clearCache'	 => '1'
						));
			}
			else {
				return Yii::app()->createUrl($this->params["relationModuleId"] . '/' . $this->controllerId);
			}
		}

2) then in the ajax scripts use the defaultroute as the redirect to refresh the portlet
 
		protected function renderLink()
		{
			$ModelId = $this->params["relationModelId"];
			$attribName = $this->params["relationAttributeName"];
			$redirectUrl = $this->getDefaultRoute();
			return CHtml::link("CBR",
							   "#",
							   array("onclick" => "DelSelDetailFRelation (this,'$attribName','$ModelId', '$redirectUrl')", "confirm" => "Are you sure you want to delete this detail?"));
		}
 
		 protected function renderScripts()
		{
			Yii::app()->clientScript->registerScript('delSelDetailFromListViewScript',
													 "
			function DelSelDetailFRelation(element,relName, invoiceId, redirectUrl)
			{				
					$.ajax({
						url : '" . Yii::app()->createUrl('c_invoicedetails/default/DelSelFRelListFromAjax') . "'  ,
						type : 'GET',
						dataType : 'json',
						data : {'checkedIds': document.getElementById('list-view-selectedIds').value, 'relName': relName },
						success : function(data)
						{
							//refresh portlet
							window.location.href = redirectUrl;();
						},
						error : function()
						{
							//todo: error call
						}
					});
			}
		",
																																																															   CClientScript::POS_END);
		}

Where redirect URL is like this

app/index.php/c_invoicehdrs/default/details?id=2&portletId=8&uniqueLayoutId=C_invoicehdrDetailsAndRelationsViewLeftBottomView_8&clearCache=1


Thanks

#2 Jason

Jason

    Administrator

  • Administrators
  • 717 posts
  • LocationChicago

Posted 12 June 2012 - 02:51 PM

Look for $.fn.yiiGridView.update in the application. You will find some spots where this is used to spefically refresh the listview. 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 13 June 2012 - 12:08 PM

In the success section of the ajax call something like this must be added. It's working fine for me.

 
		protected function renderScripts()
		{
			Yii::app()->clientScript->registerScript('delSelDetailFromListViewScript',
													 "
			function DelSelDetailFRelation(element,relName, invoiceId)
			{				
					$.ajax({
						url : '" . Yii::app()->createUrl('c_invoicedetails/default/DelSelFRelListFromAjax') . "'  ,
						type : 'GET',
						dataType : 'json',
						data : {'checkedIds': document.getElementById('list-view-selectedIds').value, 'relName': relName },
						success : function(data)
						{
 
							$('#list-view-selectedIds').val(null);
						$.fn.yiiGridView.update('list-view',
						{
							data: $(this).serialize() + '&C_invoicedetail_page=&C_invoicedetail_sort=&filteredListId=' // Not Coding Standard
						 }
						);
						return false;
						},
						error : function()
						{
							//todo: error call
						}
					});
			}
		",
																																																												  CClientScript::POS_END);
		}






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users