efilterwidget / EFilterWidget.php

 * EFilterWidget 
 *	Please refer to README about details.
 * @uses CWidget
 * @version 1.0 
 * @author Christian Salazar <> 
 * @license FREE BSD
class EFilterWidget extends CWidget {

	public $id;					// HTML MAIN DIV ID
	public $findButtonLabel;	// "Find >>"
	public $okButtonLabel;		// "OK"
	public $pleaseSelectText;	// "-please select-"
	public $fields;				// array. see doc.
	public $action;				// action array URL

	public $actionInputArgumentID; // input tag ID, containing data 
								 // to be attached to the action URL
								 // so the action will read it and acts
								 // in response to this argument.
	// WAW1: using an ID as receptor for selected value uppon user clicks "OK"
	public $receptorId; 
	// WAY2: using onSuccess event handler fired when user clicks "OK"
	public $onSuccess;			// successfull user selection handler
	// onError will always be called on any error.
	public $onError;			// error handler
	public $backgroundColor;	// widget bg color. default none.

	private $_baseUrl;
	public $debug;

	public function init(){
		if($this->pleaseSelectText == null)
			$this->pleaseSelectText = '-please select-';
		if($this->onSuccess == null)
			$this->onSuccess = "function(){}";
		if($this->onError == null)
			$this->onError = "function(){}";
		if($this->backgroundColor == null)
			$this->backgroundColor = '';

	public function run(){

		$keys = array();
		$html = "<ul class='efilterwidget-ul'>";
		foreach($this->fields as $key=>$field){
			$keys[] = $key;
			$html .= $this->_buildFieldUI(
				isset($field['options']) ? $field['options'] : array(),
				isset($field['size']) ? $field['size'] : ""
		$html .= "</ul>";

		$findid = $this->id."-find";
		$findsel = $this->id."-sel";
		$findok = $this->id."-ok";
		$loading = $this->_baseUrl . '/loading.gif';

		if($this->backgroundColor != '')
			$ss = "style='background-color: ".$this->backgroundColor.";'";

		// main html layout for this UI component
<!-- efilterwidget extension by: -->
<div id={$this->id} class='efilterwidget' {$ss}>
	<div class='finder'>
		<input id='{$findid}' type='button' value='"
		<select id='{$findsel}' class='efilterwidget-results'></select>
		<input id='{$findok}' class='okbutton' type='button' value='"
		<img src='{$loading}' style='display: none;' id='{$imgloading}'>

		// options passed by to main jQuery script
		$options = CJavaScript::encode(array(
			'onSuccess'=>new CJavaScriptExpression($this->onSuccess),
			'onError'=>new CJavaScriptExpression($this->onError),
				,"new EFilterWidget({$options})");
	}// end run()

	public function _prepareAssets(){
		$localAssetsDir = dirname(__FILE__) . '/assets';
		$this->_baseUrl = Yii::app()->getAssetManager()->publish(

		if($this->debug == true)
		$this->_baseUrl = 'protected/extensions/efilterwidget/assets';

        $cs = Yii::app()->getClientScript();
		foreach(scandir($localAssetsDir) as $f){
			$_f = strtolower($f);

	private function _buildFieldUI($key,$ui, $label, $value, $options, $size){
		if($ui == 'text'){
			return $this->_buildTextUI($key,$label, $value, $size);
		}elseif($ui == 'list'){
			return $this->_buildListUI($key,$label, $value, $options, $size);
			throw new Exception("Invalid argument value for UI."
					." must be 'text' or 'list'");

	private function _buildTextUI($key, $label, $value, $size){
		$ss=''; if($size != '') $ss = "size={$size}";
<li class='efilterwidget-ui-text' id='{$key}'>
   <input type='text' class='efilterwidget-value' {$ss} value='{$value}'>

	private function _buildListUI($key, $label, $value,$options, $size){
		$list = CHtml::dropDownList($key.'-list',$value,$options,
<li class='efilterwidget-ui-list' id='{$key}'>

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.