<?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>Midstride Solutions &#187; ajax</title>
	<atom:link href="http://blog.midstride.com/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.midstride.com</link>
	<description>Powerful, simple &#38; easy to use.</description>
	<lastBuildDate>Sat, 18 Apr 2009 20:21:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Integrating AJAX/Dojo into the Zend MVC in 8 steps.</title>
		<link>http://blog.midstride.com/2008/08/26/integrating-ajaxdojo-into-the-zend-mvc-in-8-steps/</link>
		<comments>http://blog.midstride.com/2008/08/26/integrating-ajaxdojo-into-the-zend-mvc-in-8-steps/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 04:39:23 +0000</pubDate>
		<dc:creator>andre</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://blog.midstride.com/?p=7</guid>
		<description><![CDATA[If you have been following the Zend Framework at all, you'll know that Dojo has been selected as the UI library to be adopted into the Zend Framework. The question is what does this exactly mean? ]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p><a href="http://blog.midstride.com/wp-content/uploads/2008/09/zend_dojo.jpg"><img class="alignnone size-thumbnail wp-image-14 alignleft" style="float: left;" title="zend_dojo" src="http://blog.midstride.com/wp-content/uploads/2008/09/zend_dojo-150x118.jpg" alt="" width="150" height="118" /></a>If you have been following the <a href="http://framework.zend.com/" target="_blank">Zend Framework</a> at all, you&#8217;ll know that <a href="http://dojotoolkit.org/">Dojo </a>has been selected as the UI library to be adopted into the Zend Framework.  The question is what does this exactly mean?  I&#8217;m still trying to figure out how they are going to use dojo, but right now with release 1.6 you can create dojo widgets (e.g. &#8211; date pickers, currency boxes, specialized buttons etc&#8230;) in code with the Zend_Dojo object.   That being said, you still need to learn a few more things to create a useful and reusable AjAX framework with Zend.<br />
<span id="more-7"></span></p>
<h3>The Goal</h3>
<p>This tutorial will explain how to create a reusable UI AJAX layer with dojo that communicates to the Zend controller class.  I&#8217;ll provide some basic code that will show you one way of creating a reusable framework that makes it easier to organize your javascript/ajax and controller layer.</p>
<h3>Prerequisites</h3>
<p>Before you proceed, you&#8217;ll need to read up on how to setup the Zend MVC framework.</p>
<ul>
<li><a href="http://framework.zend.com/manual/en/zend.controller.html">Zend Framework with a MVC structure</a></li>
<li><a href="http://dojotoolkit.org/downloads">Dojo framework</a></li>
</ul>
<h3>The Steps</h3>
<p>1. Setup the Zend Framework and a MVC structure</p>
<p>2. Create the controller class file (e.g. &#8211; MidstrideController.php)</p>
<p>3. Create the view folder &#8220;midstride&#8221; in the view/scripts directory.</p>
<p>4. Create the file &#8220;index.phtml&#8221; in the midstride views/scripts folder.</p>
<p>5. Create an empty javascript file called ajaxmethods.js and place it in your javascript folder.</p>
<p><em><strong>-check up-<br />
</strong></em>Your file structure should look something like this now:</p>
<p>-/application/controller/MidstrideController.php<br />
-/application/views/scripts/midstride/index.phtml<br />
-/www/javascript/ajaxmethods.js<br />
-/www/scriptslib/dojo-release-1.1.1</p>
<p>Where application is your MVC folder and www is the directory for your assets and index.php bootstrap file.</p>
<p>5. Add the javascript code to the header of index.phtml</p>
<pre class="programlisting"> <code>
<span style="color: #000000;">
&lt;script type="text/javascript" src="&lt;?php echo $this-&gt;baseUrl; ?&gt;/javascript/ajaxmethods.js"&gt;&lt;/script&gt;

&lt;script type="text/javascript" src="&lt;?php echo $this-&gt;baseUrl;?&gt;/scriptslib/dojo-release-1.1.1/dojo/dojo.js"         djConfig="parseOnLoad: true"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;

dojo.require("dojo.parser");

&lt;/script&gt;

</span>
</code></pre>
<p>In this case, the baseUrl is a short cut variable defined in your controller class<br />
e.g. &#8211; $this-&gt;view-&gt;baseUrl = $this-&gt;_request-&gt;getBaseUrl();   //gets the root of your application</p>
<p>6. Add some sample form information to index.phml</p>
<pre class="programlisting"> <code>
<span style="color: #000000;">
&lt;div id="status_message"&gt;&lt;!-- ajax messages go here--&gt;&lt;/div&gt;

&lt;form id="ajax_form"&gt;

&lt;input type="text" name="test_input" value="12345" /&gt;

&lt;input id="submit_button" type="submit"

value="submit"

onclick="formPost('&lt;?php echo $this-&gt;baseUrl ?&gt;/midstride/ajaxcall',"ajax_form","ajax_loader","submit_button") /&gt;

&lt;div id="ajax_loader" class="ajax_loader" style="display:none;"  /&gt;

&lt;/form&gt;

</span>
</code></pre>
<p>This form will call the javascript function &#8220;formPost&#8221; with the id of the ajax loader which is currently hidden.  The next step is to define the javascript function which will do the ajax call.</p>
<p>7. Code a reusable javascript ajax function</p>
<pre class="programlisting"> <code>
<span style="color: #000000;">
function formPost(destinationUrl, formId, loaderId, submitId)

{

var useAjaxLoader= true;

var hideSubmitAction = true;

if (loaderId===undefined) {     useAjaxLoader = false; }

if (submitId===undefined) {     hideSubmitAction  = false; }

var postParams = { url: destinationUrl,

load: function(data) {

dojo.eval(data);

//hide ajax loader

if (useAjaxLoader)    { dojo.byId(loaderId).style.display = "none";}

if (hideSubmitAction) { dojo.byId(submitId).style.display = "";} },

error: function(data) { console.debug("An error occurred: ", data); },

form: formId,

timeout: 4000,

headers: { "X-Requested-With": "XMLHttpRequest" }

};

//show ajax loader

if (hideSubmitAction) {dojo.byId(submitId).style.display = "none";}

if (useAjaxLoader)    {dojo.byId(loaderId).style.display = "";} //block

dojo.xhrPost(postParams);

}

</span>
</code></pre>
<p>There&#8217;s a lot going on in this code but it&#8217;s not that complex.  In short:</p>
<ul>
<li>destinationUrl = the HTTP address you want to call (a controller action method).</li>
<li>formId = the id of the form that is making the call.</li>
<li>loaderId = the id of the ajax loader (optional)</li>
<li>submitId = the id of the submit button (optional)</li>
</ul>
<p>The loaderId and submitId are used to show a loading icon and hide the submit button.  This provides the nice ajax feedback and makes sure the user doesn&#8217;t click twice.</p>
<p>The destinationUrl is the same address as in the GET or POST URL.  We need to pass the formId so that the parameters can be passed.  I&#8217;ll explain at the end other ways of passing parameters.</p>
<p>8.  Create some sample php code in the controller class &#8220;MidstrideController.php&#8221;</p>
<pre class="programlisting"> <code>
<span style="color: #000000;">
[in MidstrideController.php]

public function ajaxcallAction()

//only handle ajax calls

if ($this-&gt;_request-&gt;isXmlHttpRequest())

{

//don't render the page - no view script is needed{

$this-&gt;_helper-&gt;viewRenderer-&gt;setNoRender();

//json is the intermediate language to pass messages between the server and client

$jsonData = "";  //initialize to nothing
//get the parameter as normal

$testValue = $this-&gt;_request-&gt;getParam("test_value");

//prepare a fancy highlight response back

$jsonData =  "var highlight = dojo.animateProperty(

{

node: 'status_message',duration: 500,

properties: {

color:         { start: 'white', end: 'black' },

backgroundColor:{ start: '#fffecc', end: '#ffffff' }

}

});highlight.play();"

$this-&gt;_response-&gt;appendBody($jsonData);

}

}

</span>
</code></pre>
<p>This action method listens for the ajax called made by the javascript function.  It only deals with <strong>XmlHttpRequests (AJAX)</strong> and then sets the controller to not render anything.  The no rendering option means you don&#8217;t need to create a view (phtml) script.  Next, you just handle the form data as you would normally and prepare a JSON response to send back.  In this case, I&#8217;ve prepared a dojo animation to make a nice highlight on a status box.  In practice, you may not want to include any javascript in your controller class, as this is technically UI logic that could be in the ajax (JS) layer.  I prefer including dojo javascript because I don&#8217;t like writing javascript <img src='http://blog.midstride.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>The last call <strong>$this-&gt;_response-&gt;appendBody($jsonData)</strong> returns a javascript string which is evaluated in your javascript function by <strong>dojo.eval(data)</strong>.</p>
<h3>You&#8217;re done</h3>
<p>That&#8217;s it!  You now have a simple way of making ajax calls and keeping your main logic in the controller layer, where it should be.   If you wanted to  pass more parameters to the controller class, you would have to modify the formPost() function to have this:</p>
<blockquote><p>contentParams =  { &#8220;paramOne&#8221;:&#8221;1&#8243;,&#8221;paramTwo&#8221;:&#8221;2  };</p></blockquote>
<p>and then pass this to the var post params like:</p>
<blockquote><p>var postParams { content:contentParams, &#8230;other parameters}</p></blockquote>
<p>This can be useful when you have hidden values or other non traditional form inputs to pass in.</p>
<h3>Pros</h3>
<p>-8 steps to a reusable ajax layer.<br />
-You can easily customize the ajax post effects with dojo&#8217;s large animation library.<br />
-A very customizable and flexible framework for any project.</p>
<h3>Cons</h3>
<p>-Technical level:  It can take a while to learn the MVC and Dojo library.</p>
<h3>Conclusion</h3>
<p>That wraps up my first article on AJAX and the Zend Framework.  Future upcoming AJAX articles will discuss how to integrate Zend in scenarios where you want a real progress bar, modal popups, and captcha services.  Please let me know if you have any comments or questions.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=Midstride%20Solutions&amp;siteurl=http%3A%2F%2Fblog.midstride.com%2F&amp;linkname=Integrating%20AJAX%2FDojo%20into%20the%20Zend%20MVC%20in%208%20steps.&amp;linkurl=http%3A%2F%2Fblog.midstride.com%2F2008%2F08%2F26%2Fintegrating-ajaxdojo-into-the-zend-mvc-in-8-steps%2F"><img src="http://blog.midstride.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Integrating AJAX/Dojo into the Zend MVC in 8 steps.";
		a2a_linkurl="http://blog.midstride.com/2008/08/26/integrating-ajaxdojo-into-the-zend-mvc-in-8-steps/";
						    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.midstride.com/2008/08/26/integrating-ajaxdojo-into-the-zend-mvc-in-8-steps/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Creating custom tooltips by extending Dojo&#8217;s Dijits &#8211; in 8 Steps</title>
		<link>http://blog.midstride.com/2008/08/25/creating-custom-tooltips-by-extending-dojos-dijits-in-8-steps/</link>
		<comments>http://blog.midstride.com/2008/08/25/creating-custom-tooltips-by-extending-dojos-dijits-in-8-steps/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 20:15:07 +0000</pubDate>
		<dc:creator>andre</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[dijittooltip]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[tooltip]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://blog.midstride.com/?p=5</guid>
		<description><![CDATA[Tooltips are nice small additions that can improve the user experience. They are so common that Dojo and other javascript frameworks provide precanned ways of creating them.]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p><img class="alignleft" style="float: left;" src="http://blog.midstride.com/wp-admin/resources/tooltip2.png" alt="dojo tooltip" />Tooltips are nice small additions that can improve the user experience.  They are so common that <a title="dojotoolkit" href="http://dojotoolkit.org/" target="_blank">Dojo</a> and other javascript frameworks provide precanned ways of creating them.  In dojo, they provide <a title="dojo dijit" href="http://dojotoolkit.org/projects/dijit" target="_blank">dijits</a> (their widgets) that can do some amazing things on the user interaction side.  That being said, when you want to customize them in any way, you can run into many walls.<br />
<span id="more-5"></span></p>
<p><strong>Dojo tooltip</strong><br />
<img src="http://blog.midstride.com/wp-admin/resources/tooltip.png" alt="dojo tooltip" width="90" height="30" /></p>
<h3>Problem &amp; Goal of this Article</h3>
<p>The main goal of this article is to show you how to stylize the tooltips so that you can create your own type of tooltip.  This article will go through the css required and how to structure your code so that you can create more than one tooltip.</p>
<p>To extend the style of dojo&#8217;s dijit, it&#8217;s best to copy one of the existing themes and create your own custom theme.  In this tutorial, I&#8217;ve copied the &#8220;tundra&#8221; theme so all the following css code will use the &#8220;tundra&#8221; selector.  You could replace the tundra selectors with your own custom name, but it may be more work than it&#8217;s worth.</p>
<h3>Prerequisites &#8211; tools you&#8217;ll need setup:</h3>
<ul>
<li> <a title="Firefox" href="http://www.firefox.com" target="_blank">Firefox</a><br />
<em>You should have this</em></li>
<li>IE 6 or <a href="http://www.my-debugbar.com/wiki/IETester/HomePage" target="_blank">IETester</a><br />
<em>You&#8217;ll want to make it IE6 compliant right?  Or maybe not&#8230; <img src='http://blog.midstride.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </em></li>
<li><a href="http://getfirebug.com/">Firebug</a><br />
<em> Every developer and especially UI developer should have this.</em></li>
<li><a title="dojo framework" href="http://dojotoolkit.org/" target="_blank">Dojo framework setup</a><br />
<em> Follow their <a href="http://sitepen.com/labs/guides/?guide=DojoQuickStart">documentation </a>on setting up the includes</em></li>
</ul>
<h3>The Steps</h3>
<p><strong>1. Setup a new theme</strong><br />
-Open up the dojo dijit theme folder<br />
-dojo-release-1.1.1dijitthemes<br />
<strong>2. Create a copy of the &#8220;tundra&#8221; folder.</strong><br />
<strong>3. Rename it to the name of your theme.  (e.g. &#8211;  &#8220;tundraextended&#8221;)</strong><br />
<strong>4. Include the dojo style and your extended theme in your header code:</strong></p>
<blockquote><p>&lt;style type=&#8221;text/css&#8221;&gt;<br />
@import &#8220;pathtodojo/dojo-release-1.1.1/dijit/themes/tundraextended/tundra.css&#8221;;<br />
@import &#8220;pathtodojo/dojo-release-1.1.1/dojo/resources/dojo.css&#8221;<br />
&lt;/style&gt;</p></blockquote>
<p><strong>5.  Include the tool tip dijit:</strong></p>
<blockquote><p>&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
dojo.require(&#8221;dojo.parser&#8221;);<br />
dojo.require(&#8221;dijit.Tooltip&#8221;);<br />
&lt;/script&gt;</p></blockquote>
<p><strong>6. Add the tool tip code</strong></p>
<blockquote><p>&lt;body class=&#8221;tundra&#8221;&gt; &lt;!&#8211; you need to set the body to load the dijit styles &#8211;&gt;</p>
<p>&lt;a id=&#8221;theId&#8221; href=&#8221;#&#8221;&gt;Hover over this&lt;/a&gt;</p>
<p>&lt;div dojoType=&#8221;dijit.Tooltip&#8221; style=&#8221;display:none&#8221; position=&#8221;left&#8221; connectId=&#8221;theId&#8221;&gt;<br />
&lt;div class=&#8221;custom_tooltip&#8221;&gt;tool tip content&lt;/div&gt;<br />
&lt;/div&gt;</p></blockquote>
<p><em>Note the attribute &#8220;position=left&#8221;.  This should remain the same for all tooltips that are defined by the inner class &#8220;custom_tooltip&#8221;.  I don&#8217;t really use the position attribute and rely on css position.<br />
</em><br />
At this point you should have a simple tool tip hover when the mouse goes over the link.  If you don&#8217;t, then open up firebug and see if you have any errors.  If you do, then you most likely didn&#8217;t setup dojo properly.</p>
<p>If all is good now, then you have a nice basic tooltip.  Now, the hard part is how to extend the look:<br />
<strong>7. Create a new css file &#8211; dojoextended.css</strong><br />
This style sheet should be included last.  As its name suggests, it extends (overrides and resets) the dojo stylesheet.</p>
<blockquote><p>&lt;style type=&#8221;text/css&#8221;&gt;<br />
@import &#8220;pathtodojo/dojo-release-1.1.1/dijit/themes/tundraextended/tundra.css&#8221;;<br />
@import &#8220;pathtodojo/dojo-release-1.1.1/dojo/resources/dojo.css&#8221;<br />
<strong>@import &#8220;pathtocss/dojoextended.css&#8221;</strong><br />
&lt;/style&gt;</p></blockquote>
<p><strong>8. Add the following css to the extended css file</strong></p>
<blockquote><p>/*Reset the generic tooltip container */<br />
.tundra .dijitTooltipContainer<br />
{<br />
background:none;<br />
padding:0;<br />
margin:0;<br />
border:none;<br />
height:auto;<br />
width:auto;<br />
}</p>
<p>/*defines the div inside the tooltip &#8211; your custom tooltip*/<br />
.custom_tooltip<br />
{<br />
/*this defines your tooltip*/<br />
position:relative;<br />
left:5px; /*use left and top to position it */<br />
top:15px;<br />
width:125px;<br />
height:100px;<br />
background-image:url(&#8221;yourimage.png&#8221;);<br />
}</p>
<p>/*if your tooltip uses transparency, define a ie6 specific one below */<br />
.dj_ie6 .tundra  .custom_tooltip<br />
{<br />
background-image:url(&#8221;yourimage_ie6.png&#8221;); /*an 8-bit png*/<br />
}</p>
<p>/*hide the connector &#8211; an arrow that connects the tooltip to the hovered item */</p>
<p>.tundra  .dijitTooltipAbove .dijitTooltipConnector  { background:none; }<br />
.tundra .dijitTooltipLeft .dijitTooltipConnector { background:none; }<br />
.tundra .dijitTooltipBelow .dijitTooltipConnector { background:none; }<br />
.tundra .dijitTooltipRight .dijitTooltipConnector { background:none; }</p></blockquote>
<h3>You&#8217;re done!</h3>
<p>You can now create as many styles for your tooltips as you need by defining a specific div and a new style (e.g. &#8211; custom_tooltip2).  You will likely have to do a lot of tweaking on the positioning image, but it&#8217;s pretty straightforward when you look at it.  The longest part is determining which css selectors you need to use, if you look at the tundra.css class you&#8217;ll notice there are more selectors I didn&#8217;t look at.</p>
<h3>Pros</h3>
<p>-Quick to code.<br />
-Easy to understand, there&#8217;s only one div to deal with.<br />
-IE6 compliant.  It&#8217;s always a bonus <img src='http://blog.midstride.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
-Extendability.  You can now create as many tooltips as you want for one project.  With the standard tooltip, you would be stuck with one tooltip for an entire project.</p>
<h3>Cons</h3>
<p>-Inefficient: Resetting styles is cumbersome and requires more data to be loaded.<br />
-Upgrading dojo could break the custom tooltips if they change the way the tooltip are rendered.<br />
-Tooltipconnector: I didn&#8217;t use the tooltipconnector which allows you to position the tooltip in various positions easily.</p>
<p><strong>Conclusion<br />
</strong>That wraps up the first tutorial on dojo.   I hope you found it useful, and I appreciate all feedback.  If you have a better way, I would like to know about it.  My next article will look at how to combine dojo&#8217;s ajax with the zend framework.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/share_save?sitename=Midstride%20Solutions&amp;siteurl=http%3A%2F%2Fblog.midstride.com%2F&amp;linkname=Creating%20custom%20tooltips%20by%20extending%20Dojo%E2%80%99s%20Dijits%20%E2%80%93%20in%208%20Steps&amp;linkurl=http%3A%2F%2Fblog.midstride.com%2F2008%2F08%2F25%2Fcreating-custom-tooltips-by-extending-dojos-dijits-in-8-steps%2F"><img src="http://blog.midstride.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Creating custom tooltips by extending Dojo’s Dijits – in 8 Steps";
		a2a_linkurl="http://blog.midstride.com/2008/08/25/creating-custom-tooltips-by-extending-dojos-dijits-in-8-steps/";
						    </script>
    <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://blog.midstride.com/2008/08/25/creating-custom-tooltips-by-extending-dojos-dijits-in-8-steps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
