All pastes #2070469 Raw Edit

Untitled

public text v1 · immutable
#2070469 ·published 2011-05-27 15:50 UTC
rendered paste body
Index: model/state.php
===================================================================
--- model/state.php	(revision 3384)
+++ model/state.php	(working copy)
@@ -270,4 +270,20 @@
     {
         return $this->getData();
     }
+	
+	/**
+     * Return an associative array of the data.
+     *
+     * @return array
+     */
+    public function getList()
+    {
+    	$data = array();
+		
+    	foreach($this->_state as $name => $state){
+        	$data[$name] = $state->value;
+		}
+		
+		return $data;
+    }
 }
\ No newline at end of file

Index: template/helper/grid.php
===================================================================
--- template/helper/grid.php	(revision 3384)
+++ template/helper/grid.php	(working copy)
@@ -250,7 +250,35 @@
 
 		return $html;
 	}
+	
+	/**
+	 * Render a state reset field
+	 *
+	 * @return	string	Html
+	 */
+	public function reset($config = array())
+	{
+		$config = new KConfig($config);
+		$config->append(array(
+			'model'  		=> null,
+			'option'  		=> null,
+		));
+		
+		$urls = array();
+		$state = KFactory::get('admin::com.'.$config->option.'.model.'.$config->model)->getState()->getList();
+		
+		foreach($state as $k => $v){
+			$urls[]= $k.'=';
+		}
+		
+		$url = 'option=com_'.$config->option.'&view='.$config->model.'&';
+		$url .= implode('&', $urls);
+		
+		$html = '<a href="'.KRequest::base().'/index.php?'.$url.'">'.JText::_('Reset State').'</a>';
 
+		return $html;
+	}
+
 	protected function _createUrl(KConfig $config)
 	{
 		if(!$url = $config->url)