<?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>Andrey Vystavkin Blog &#187; jQuery</title>
	<atom:link href="http://j4vk.com/wordpress/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://j4vk.com/wordpress</link>
	<description>Life and work in Cyprus</description>
	<lastBuildDate>Wed, 08 Sep 2010 08:05:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CakePHP, draggable/droppable in jQuery</title>
		<link>http://j4vk.com/wordpress/2010/03/cakephp-draggabledroppable-in-jquery/</link>
		<comments>http://j4vk.com/wordpress/2010/03/cakephp-draggabledroppable-in-jquery/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 09:41:13 +0000</pubDate>
		<dc:creator>Andrey Vystavkin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Stack]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://j4vk.com/wordpress/?p=430</guid>
		<description><![CDATA[Working on bunch of CRUD routines in CakePHP, I finally got tired of multiple checkboxes and decided to write a small helper for jQuery UI drag-n-drop functionality. In response to Teknoid post, I&#8217;ve made couple of additional tweaks to dynamic select boxes, and got quite nice combination of selectboxes and dynamic lists. The main requirement [...]]]></description>
			<content:encoded><![CDATA[<p>Working on bunch of CRUD routines in CakePHP, I finally got tired of multiple checkboxes and decided to write a small helper for jQuery UI drag-n-drop functionality.</p>
<p>In response to<a title="Dynamic Select boxes in CakePHP" href="http://teknoid.wordpress.com/2010/03/10/use-cakephp-jquery-to-build-dynamic-selects/"> Teknoid</a> post, I&#8217;ve made couple of additional tweaks to dynamic select boxes, and got quite nice combination of selectboxes and dynamic lists.</p>
<p>The main requirement of the script was:</p>
<ol>
<li>On Selectbox value changed, return the list of related items (in #base-list div-element)</li>
<li>Add drag/drop functionality to the base-list ul elements as well as add arrow-west/arrow-east addition/deletion of the elements</li>
<li>After all the movements are over, to be able to save dragged values in CakePHP form to be saved.</li>
<li>Result: <a href="http://j4vk.com/wordpress/uploads/2010/03/droppable_cakephp.zip" title="Download Droppable Helper for CakePHP"><strong>here</strong></a>.</li>
<li>Sample MySQL DB file: <a href="http://j4vk.com/wordpress/uploads//2010/03/droppable_test_sql.zip" title="Download Droppable CakePHP database sample">Here</a>
</ol>
<p>The view/helpers/droppable.php looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> tag
    <span style="color: #339933;">*/</span>
    <span style="color: #000000; font-weight: bold;">function</span> droppableElements<span style="color: #009900;">&#40;</span><span style="color: #000088;">$outside</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$js_code</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$js_code</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'
                    var $baseDiv = $(\'#base-list\');
                    var $targetDiv = $(\'#target-list\');
&nbsp;
                    $(\'li\', \'#baseUl\' ).draggable({
                        accept: \'#baseUl &gt; li\',
                        revert: \'invalid\',
                        helper: \'clone\',
                        cursor: \'move\'
                    }); 
&nbsp;
                    $(\'li\', \'#targetUl\' ).draggable({
                        accept: \'#targetUl &gt; li\',
                        revert: \'invalid\',
                        helper: \'clone\',
                        cursor: \'move\'
                    }); 
&nbsp;
                    $targetDiv.droppable({
                        accept: \'#baseUl &gt; li\',
                        activeClass: \'ui-state-highlight\',
                        drop: function(ev, ui) {
                            moveItem(ui.draggable, $targetDiv);
                        }
                    });
&nbsp;
                    $baseDiv.droppable({
                        accept: \'#targetUl &gt; li\',
                        activeClass: \'ui-state-highlight\',
                        drop: function(ev,ui) {
                            moveItem(ui.draggable, $baseDiv);
                        }
                    });
&nbsp;
                    $(\'#baseUl &gt; li\').click(function(ev){
                        moveItemClicked($(this), $(this).parent());
                    });
&nbsp;
                    $(\'#targetUl &gt; li\').click(function(ev){
                        moveItemClicked($(this), $(this).parent());
                    });'</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$outside</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>out <span style="color: #339933;">.=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">codeBlock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$js_code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">out</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #000088;">$js_code</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/*
    *   @var string $boxId - observed selectBox id element
    *   @var string $eventType - default 'change'
    *   @var string $jsonAction - method call, i.e '/departments/ajax_get_list/departments/company_id/'
    */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> observeSelectBox<span style="color: #009900;">&#40;</span><span style="color: #000088;">$boxId</span><span style="color: #339933;">,</span> <span style="color: #000088;">$eventType</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'change'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$jsonAction</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$js_script</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$js_script</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">'
          $(\'#'</span><span style="color: #339933;">.</span><span style="color: #000088;">$boxId</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\').live(\''</span><span style="color: #339933;">.</span><span style="color: #000088;">$eventType</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\', function(){
            if($(this).val().length != 0) {
            $.getJSON(\''</span><span style="color: #339933;">.</span><span style="color: #000088;">$jsonAction</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\',
                {searchParam: $(this).val() }, 
&nbsp;
                function(items) {
                    $(\'.jq_list\').remove();
                    generateBaseList(items);
&nbsp;
                '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">droppableElements</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'
                }
            );
        }
        } );'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">out</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">codeBlock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$js_script</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">out</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>For using so-called ajax_get_list method, I&#8217;ve written a small function in <code>app/app_controller.php</code> that get all the id,name list array based on couple of arguments:</p>
<p>In order to use this method, you should have a small layout in related views folder, that looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #666666; font-style: italic;">// somewhere in views/departments/ajax_get_list.ctp</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The view of ajax_get_list method will output serialized array of the method. For the initial view, you need to add 2 div-elements and one select box. Div elements have static id&#8217;s which are used by jQuery script to look-up (base-list, and target-list).<br />
In our view, it should look like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$droppable</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">observeSelectBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'company-id'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'change'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/departments/ajax_get_list/departments/company_id/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
        &lt;label&gt; Load company departments: &lt;/label&gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">print</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Company.id'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$companies</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'company-id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Company Departments);?&gt;
&nbsp;
        &lt;?php print $html-&gt;div('</span>right block<span style="color: #0000ff;">', $html-&gt;div('</span>target<span style="color: #339933;">-</span>title<span style="color: #0000ff;">', '</span>Container<span style="color: #0000ff;">', array(), false),array('</span>id<span style="color: #0000ff;">'=&gt;'</span>target<span style="color: #339933;">-</span><span style="color: #990000;">list</span><span style="color: #0000ff;">'),false);?&gt; 
&nbsp;
        &lt;?php print $html-&gt;div(null,null, array('</span>id<span style="color: #0000ff;">'=&gt;'</span>base<span style="color: #339933;">-</span><span style="color: #990000;">list</span><span style="color: #0000ff;">'));
?&gt;</span></pre></div></div>

<p>And that&#8217;s about it, once you finish dragging the li-elements to the target-list, and save the form, its values will appear in <code>['Container']['item_ids']</code> array where you can do whatever you want with it.<br />
To make things simple, you can download a small sample of code of these files <a href="http://j4vk.com/wordpress/uploads/2010/03/droppable_cakephp.zip" title="Download Droppable Helper for CakePHP"><strong>here</strong></a>, as well as database sample <a href="http://j4vk.com/wordpress/uploads//2010/03/droppable_test_sql.zip" title ="Download Droppable MySQL test sample">file</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://j4vk.com/wordpress/2010/03/cakephp-draggabledroppable-in-jquery/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>CakePHP: jQuery styling of flash messages</title>
		<link>http://j4vk.com/wordpress/2009/01/cakephp-jquery-styling-of-flash-messages/</link>
		<comments>http://j4vk.com/wordpress/2009/01/cakephp-jquery-styling-of-flash-messages/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 14:38:30 +0000</pubDate>
		<dc:creator>Andrey Vystavkin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Stack]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://j4vk.com/wordpress/?p=347</guid>
		<description><![CDATA[CakePHP session flash messages is one of the most useful things for usability, and user notification. Trying to make it more fancy, I came to jQuery framework with its HighlightFade plugin. Adding just a couple of lines, we can get nice effects, looking the same as WordPress messages in Posting/Editing: var $j = jQuery.noConflict&#40;&#41;; //I'm [...]]]></description>
			<content:encoded><![CDATA[<p>CakePHP session <a title="Rail-like Flash messages" href="http://shabadeehoob.com/2007/03/17/rails-like-flash-messages-in-cakephp/" target="_self">flash messages</a> is one of the most useful things for usability, and user notification. Trying to make it more fancy, I came to <a title="jQuery: javascript framework" href="http://jquery.com/">jQuery</a> framework with its <a title="jQuery Highlight Fade Plugin" href="http://jquery.offput.ca/highlightFade/old.php" target="_self">HighlightFade</a> plugin.</p>
<p>Adding just a couple of lines, we can get nice effects, looking the same as WordPress messages in Posting/Editing:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">      <span style="color: #003366; font-weight: bold;">var</span> $j <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">noConflict</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//I'm using Prototype as well, so we don't need conflicts</span>
$j<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> $j<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#flashMessage&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
          $j<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#flashMessage&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">highlightFade</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">'#24F273'</span><span style="color: #339933;">,</span>speed<span style="color: #339933;">:</span><span style="color: #CC0000;">2000</span><span style="color: #339933;">,</span> iterator<span style="color: #339933;">:</span><span style="color: #3366CC;">'exponential'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Thus, next time you will pass <code lang="php">$this->Session->setFlash('Foo');</code>, your  flash message with default <br/></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;flashMessage&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flash</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;</pre></div></div>

<p>will be used with above HighLight effect.</p>
]]></content:encoded>
			<wfw:commentRss>http://j4vk.com/wordpress/2009/01/cakephp-jquery-styling-of-flash-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
