<?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; JavaScript</title>
	<atom:link href="http://blog.itopia.de/category/programmierung/javascript/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: Instruct browser to refresh CSS and JS files</title>
		<link>http://blog.itopia.de/symfony-instruct-browser-to-refresh-css-and-js-files/339</link>
		<comments>http://blog.itopia.de/symfony-instruct-browser-to-refresh-css-and-js-files/339#comments</comments>
		<pubDate>Fri, 13 May 2011 13:31:30 +0000</pubDate>
		<dc:creator>TBA</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.itopia.de/?p=339</guid>
		<description><![CDATA[In Symfony the stylesheets and javascript files are defined in the view.yml. Sometimes the problem appears that the browsers cache<a href="http://blog.itopia.de/symfony-instruct-browser-to-refresh-css-and-js-files/339" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>In Symfony the stylesheets and javascript files are defined in the <strong><em>view.yml</em></strong>. Sometimes the problem appears that the browsers cache these files, even if there where some changes in the last release without refreshing the new contents.</p>
<p>There is a common technique to instruct the browser to take the new file version: Browsers store different file versions for different GET paramters. So if you include a CSS file like this:</p>
<pre class="brush:xml">&lt;script type="text/javascript" src="css/styles.css?v=21"&gt;&lt;/script&gt;</pre>
<p>and in the next version with a higher version number (v=22), the browser will use  (and cache) the newer version.</p>
<p>In our case we save the current version number (SVN) into the <em><strong>app.yml</strong></em> and we use this number as increasing GET-Parameter to force a cache refresh:</p>
<pre class="brush:plain">default:
  stylesheets: [styles.css?v=&lt;?php echo sfConfig::get('app_revision'); ?&gt;]</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.itopia.de/symfony-instruct-browser-to-refresh-css-and-js-files/339/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>JavaScript: unterminated string literal</title>
		<link>http://blog.itopia.de/javascript-unterminated-string-literal/114</link>
		<comments>http://blog.itopia.de/javascript-unterminated-string-literal/114#comments</comments>
		<pubDate>Tue, 06 May 2008 08:35:52 +0000</pubDate>
		<dc:creator>TBA</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Error]]></category>

		<guid isPermaLink="false">http://blog.itopia.de/2008/05/06/javascript-unterminated-string-literal/</guid>
		<description><![CDATA[Was hab ich mich damit rum geschlagen und kein einziges Suchergebnis bei g* konnte mir die LÃ¶sung bieten. Kurz zum<a href="http://blog.itopia.de/javascript-unterminated-string-literal/114" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p>Was hab ich mich damit rum geschlagen und kein einziges Suchergebnis bei g* konnte mir die LÃ¶sung bieten.<br />
Kurz zum Problem. Ich lese mit PHP Text aus einer MySQL-Datenbank, welcher auch ZeilenumbrÃ¼che enthalten kann.<br />
Diese ZeilenumbrÃ¼che werden mit </p>
<p><code>\n</code> </p>
<p>oder </p>
<p><code>\r\n</code> </p>
<p>codiert. Ich weiÃŸ, dass in JS ZeilenumbrÃ¼che in Strings verboten sind und wollte diese nun ersetzten. DafÃ¼r gibt es mich folgende MÃ¶glichkeiten:</p>
<ul>
<li><a href="http://de.php.net/manual/de/function.nl2br.php">php: nl2br</a></li>
<li><a href="http://de.php.net/manual/de/function.str-replace.php">php: str_replace</a></li>
<li><a href="http://de.php.net/manual/de/function.preg-replace.php">php: preg_replace</a></li>
</ul>
<p><em>nl2br</em> brachte nichts und kann in der AusfÃ¼hrung auch nicht wirklich beeinflusst werden. Ok dann  mit <em>str_replace</em> oder <em>preg_replace</em>.<br />
Was ich versucht habe war nun folgendes:</p>
<p><code>$str = str_replace('\r\n','<br />',$str);<br />
$str = str_replace('\r','<br />',$str);<br />
$str = str_replace('\n','<br />',$str);</code></p>
<p>Nichts hat geholfen, der Fehler war noch da und der Umbruch war sogar noch im Quellcode zu sehen.<br />
Dann fiehl mir Gott sei Dank ein, dass PHP einen Unterschied macht ob man SingleQuotes (&#8216;) oder DoubleQuotes (&#8220;) benutzt. Code in SingleQuotes wird bspw. nicht nach PHP-Variablen geparst. Also versuchte ich es mal so:</p>
<p><code>$str = str_replace("\r\n","<br />",$str);</code></p>
<p>Und siehe da, die Sonderzeichen wurden wie gewÃ¼nscht ersetzt und der JavaScript-Fehler <strong>unterminated string literal</strong> war verschwunden. Bitte. Danke.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.itopia.de/javascript-unterminated-string-literal/114/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

