<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iTopiaBlog &#187; AJAX/AXAH</title>
	<atom:link href="http://blog.itopia.de/category/programmierung/ajaxaxah/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.itopia.de</link>
	<description>liVe iN oRder tO lEArN</description>
	<lastBuildDate>Thu, 26 Jan 2012 16:41:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>symfony: How to build a dojo dijit autocompleter sfForm widget</title>
		<link>http://blog.itopia.de/symfony-how-to-dojo-dijit-autocompleter-sfform-widget/260</link>
		<comments>http://blog.itopia.de/symfony-how-to-dojo-dijit-autocompleter-sfform-widget/260#comments</comments>
		<pubDate>Thu, 29 Oct 2009 13:20:36 +0000</pubDate>
		<dc:creator>TBA</dc:creator>
				<category><![CDATA[AJAX/AXAH]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Web2.0]]></category>
		<category><![CDATA[autocompleter]]></category>
		<category><![CDATA[dijit]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[sfform]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://blog.itopia.de/?p=260</guid>
		<description><![CDATA[I was searching long time for a good auto completer widget, but I couldn&#8217;t find one. So I created it<a href="http://blog.itopia.de/symfony-how-to-dojo-dijit-autocompleter-sfform-widget/260" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>I was searching long time for a good auto completer widget, but I couldn&#8217;t find one. So I created it by my self.<br />
I did the same with the build in symfony auto completer widget. When I have time I&#8217;ll post it, too.<br />
I hope I could help someboby with this small tutorial. Please give me feedback if there are any questions or suggestions.</p>
<p>Now lets start:</p>
<p><strong>1. Copy the dojo package to the js folder</strong><br />
Resulting path to dojo.js: <em>web/js/dojoToolkit/dojo/dojo.js</em></p>
<p><strong>2. Enable dojo.js</strong><br />
If not yet happend elsewhere:<br />
Modify the view.yml: <em>apps/[YOUR_APP]/config/view.yml</em><br />
<code><br />
</code></p>
<pre class="brush:plain">default:
javascripts: [dojoToolkit/dojo/dojo.js]</pre>
<p><strong>3. Create the widget</strong><br />
<em>lib/widget/itWidgetFormInputTextDijitAutocomplete.php</em></p>
<pre class="brush:php">class itWidgetFormInputTextDijitAutocomplete extends sfWidgetForm
{
/**
* Constructor.
*
* Available options:
*
* * model: Name of the Model
* * searchfield: Table field in which will be searched
* * action: Optional: request action or url
* * value_method: Optional: getter for form field value
* * output_method: Optional: getter for form field name
* * criteria_method: Optional: getter for additional cirteria
* * add_empty: Optional: add emtpy value option to the list
* * choices: An array of possible choices (n/a)
* * formatter: A callable to call to format the checkbox choices
*
* @see sfWidgetForm
*/
protected function configure($options = array(), $attributes = array())
{
$this-&gt;addRequiredOption('model');
$this-&gt;addRequiredOption('search_field');
$this-&gt;addOption('action', 'default/ajaxAutocomplete');
$this-&gt;addOption('value_method', 'getPrimaryKey');
$this-&gt;addOption('output_method', 'getPrimaryKey');
$this-&gt;addOption('choices', array());
$this-&gt;addOption('criteria_method', '');
$this-&gt;addOption('formatter', array($this, 'formatter'));
$this-&gt;addOption('add_empty', false);
}

/**
* Renders the widget as HTML.
*
* @param string The name of the HTML widget
* @param mixed The value of the widget
* @param array An array of HTML attributes
* @param array An array of errors
*
* @return string A HTML representation of the widget
*
* @see sfWidgetForm
*/
public function render($name, $value = null, $attributes = array(), $errors = array())
{
$choices = $this-&gt;getOption('choices');
if ($choices instanceof sfCallable)
{
$choices = $choices-&gt;call();
}

$baseAttributes = array(
'action' =&gt; $this-&gt;getOption('action'),
'name' =&gt; $name,
'type' =&gt; 'text',
'value' =&gt; $value,
'id' =&gt; $id = $this-&gt;generateId($name, self::escapeOnce($name)),
);

return call_user_func($this-&gt;getOption('formatter'), $this, $baseAttributes);
}

/**
* Renders the input fields as HTML.
*
* @param widget
* @param attributes
*
* @return string A HTML representation of the input fields
*/
public function formatter($widget, $attributes)
{
sfLoader::loadHelpers(array('Form', 'Url'));
$request = sfContext::getInstance()-&gt;getRequest();
$field_id = $attributes['id'];
$field_name = $attributes['name'];
$ajax_field_id = 'ajax_'.$attributes['id'];
$out_field_id = 'out_'.$attributes['id'];
$object = @call_user_func(array($this-&gt;getOption('model').'Peer', 'retrieveByPk'), $attributes['value']);
$default_out = $request-&gt;getParameter('ajax_'.$attributes['name'], is_object($object) ? call_user_func(array(&amp;$object, $this-&gt;getOption('output_method'))) : '');
$default_value = $request-&gt;getParameter($attributes['name'], is_object($object) ? $attributes['value'] : '');

$html = '';
$ajaxParams=array(
'model' =&gt; $this-&gt;getOption('model'),
'value_method' =&gt; $this-&gt;getOption('value_method'),
'output_method' =&gt; $this-&gt;getOption('output_method'),
'search_field' =&gt; $this-&gt;getOption('search_field'),
'criteria_method' =&gt; $this-&gt;getOption('criteria_method'),
'field_name' =&gt; 'ajax_'.$attributes['name']
);
if($this-&gt;getOption('add_empty')===false) $ajaxParams['add_empty'] = 'false';
elseif($this-&gt;getOption('add_empty')===true) $ajaxParams['add_empty'] = 'true';
else $ajaxParams['add_empty'] = $this-&gt;getOption('add_empty');

$requestUrl = url_for($attributes['action'].'?'.http_build_query($ajaxParams), true);
$requestUrl = str_replace('frontend_dev.php/', '', $requestUrl);
$requestUrl = str_replace('backend_dev.php/', 'backend.php/', $requestUrl);

$html .= &lt;&lt;
&lt;script type="text/javascript"&gt;
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dijit.form.FilteringSelect");
&lt;/script&gt;
&lt;div dojoType="dojo.data.ItemFileReadStore"
jsId="{$field_id}Store" url="{$requestUrl}"&gt;&lt;/div&gt;
EOF;

$input_text = &lt;&lt;
&lt;input dojoType="dijit.form.FilteringSelect"
store="{$field_id}Store"
class="medium"
id="{$field_id}"
name="{$field_name}"
value="{$default_value}"
hasDownArrow="true",
invalidMessage="",
ignoreCase="true" /&gt;
}</pre>
<p><strong>4. Create action for the AJAX request</strong><br />
<em>apps/[APP_NAME]/modules/default/actions/actions.class.php</em></p>
<pre class="brush:php">&lt;?php
class defaultActions extends sfActions
{
public function executeAjaxAutocomplete($request)
{
$model = $request-&gt;getParameter('model');
$criteria_method = $request-&gt;getParameter('criteria_method');
$add_empty = $request-&gt;getParameter('add_empty', 'false');
$this-&gt;value_method = $request-&gt;getParameter('value_method');
$this-&gt;output_method = $request-&gt;getParameter('output_method');

$peer_object = $model.'Peer';

if($criteria_method!='') $criteria = call_user_func(array($peer_object, $criteria_method));
else $criteria = new Criteria();

$search_field = $request-&gt;getParameter('search_field');
$field_name = $request-&gt;getParameter('field_name');
$var = $request-&gt;getParameter($field_name);

$j_object = array('identifier' =&gt; 'abbreviation', 'items'=&gt;array());

$search_field = strtoupper($search_field);

$sql_field = constant($peer_object.'::'.$search_field);

$c = $criteria;
$c-&gt;add($sql_field, $var . '%', Criteria::LIKE);
$this-&gt;list = call_user_func(array($peer_object,'doSelect'), $c);

if($add_empty!='false')
{
$j_object['items'][] = array(
'name' =&gt; $add_empty=='true' ? '' : $add_empty,
'label' =&gt; '',
'abbreviation' =&gt; ''
);
}

foreach($this-&gt;list AS $v)
{
$j_object['items'][] = array(
'name' =&gt; call_user_func(array(&amp;$v, $this-&gt;output_method)),
'label' =&gt; call_user_func(array(&amp;$v, $this-&gt;output_method)),
'abbreviation' =&gt; call_user_func(array(&amp;$v, $this-&gt;value_method))
);
}
$this-&gt;j_object = $j_object;
}
}</pre>
<p><strong>5. Create template for the AJAX request</strong><br />
<em>apps/[APP_NAME]/modules/default/templates/ajaxAutocompleteSuccess.php</em><br />
<code></p>
<pre class="brush:php">&lt;?php decorate_with(false); ?&gt;
&lt;?php print_r(json_encode($j_object)); ?&gt;</pre>
<p></code></p>
<p><strong>6. Insert the new widget into your sfForm</strong><br />
<em>apps/[APP_NAME]/modules/default/templates/ajaxAutocompleteSuccess.php</em><br />
<code></p>
<pre class="brush:php">...
# $widgets['user_id'] = new sfWidgetFormInput();
$widgets['user_id'] = new stWidgetFormInputTextDijitAutocomplete(array(
'model' =&gt; 'User',
'search_field' =&gt; 'username',
'value_method' =&gt; 'getId',
'output_method' =&gt; 'getUsername',
'criteria_method' =&gt; 'getCriteriaRegisteredUsers'
));</pre>
<p></code></p>
<p><strong>6. Clear symfony cache</strong></p>
<p><strong>Links:</strong></p>
<ul>
<li>http://api.dojotoolkit.org/jsdoc/1.3.2/dijit.form.FilteringSelect</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.itopia.de/symfony-how-to-dojo-dijit-autocompleter-sfform-widget/260/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Funktion mit Parameter an event listener Ã¼bergeben</title>
		<link>http://blog.itopia.de/funktion-mit-parameter-an-event-listener-ubergeben/61</link>
		<comments>http://blog.itopia.de/funktion-mit-parameter-an-event-listener-ubergeben/61#comments</comments>
		<pubDate>Thu, 21 Sep 2006 03:14:24 +0000</pubDate>
		<dc:creator>TBA</dc:creator>
				<category><![CDATA[AJAX/AXAH]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.itopia.de/?p=61</guid>
		<description><![CDATA[Am meisten Kopfzerbrechen bereitete mir die ParameterÃ¼bergabe beim Funktionsaufruf Ã¼ber einen eventListener. Ich musste erst unzÃ¤hlige Seiten im Netz durchforsten<a href="http://blog.itopia.de/funktion-mit-parameter-an-event-listener-ubergeben/61" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Am meisten Kopfzerbrechen bereitete mir die ParameterÃ¼bergabe beim Funktionsaufruf Ã¼ber einen eventListener. Ich musste erst unzÃ¤hlige Seiten im Netz durchforsten bis ich eine LÃ¶ssung fÃ¼r mein Problem gefunden hatte.</p>
<p>Im folgenden liste ich die fehlgeschlagenen AnsÃ¤tze auf gefolgt von der erfolgreichen LÃ¶sung:</p>
<p>[syntax,param_hand_over.js,javascript]</p>
<p>Links:<br />
<a href="http://prototype.conio.net/">Prototype</a><br />
<a href="http://particletree.com/features/quick-guide-to-prototype/">Quick Guide To Prototype</a><br />
<a href="http://www.sergiopereira.com/articles/prototype.js.html">Inoffizielle Prototype Dokumentation</a><br />
<a href="http://wiki.script.aculo.us/scriptaculous/show/Prototype"><br />
wiki.script.aculo.us</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.itopia.de/funktion-mit-parameter-an-event-listener-ubergeben/61/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

