<?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>Superdit.com &#187; Extjs</title>
	<atom:link href="http://superdit.com/category/extjs/feed/" rel="self" type="application/rss+xml" />
	<link>http://superdit.com</link>
	<description>blogging, design, tech, and web</description>
	<lastBuildDate>Thu, 19 Jan 2012 07:50:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ExtJS: Simple File Browser</title>
		<link>http://superdit.com/2011/06/01/extjs-simple-file-browser/</link>
		<comments>http://superdit.com/2011/06/01/extjs-simple-file-browser/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 06:59:01 +0000</pubDate>
		<dc:creator>aditia rahman</dc:creator>
				<category><![CDATA[Extjs]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://superdit.com/?p=6871</guid>
		<description><![CDATA[ExtJS has a lot of great components to build complete web application that can be look like desktop application, In today post I want to show how to create a very simple file browser in ExtJS, with PHP backend we can easily get file and folder on the system. First this example have some limitation,<a href="http://superdit.com/2011/06/01/extjs-simple-file-browser/" class="read-more">Continue Reading</a>]]></description>
			<content:encoded><![CDATA[<p>ExtJS has a lot of great components to build complete web application that can be look like desktop application, In today post I want to show how to create a very simple file browser in ExtJS, with PHP backend we can easily get file and folder on the system.</p>
<p><a title="ExtJS Simple File Browser" href="http://superdit.com/2011/06/01/extjs-simple-file-browser/" target="_blank"><img class="alignnone size-full wp-image-6873" title="ExtJS File Browser" src="http://superdit.com/wp-content/uploads/2011/06/screenshot.jpg" alt="ExtJS File Browser" width="540" height="200" /></a></p>
<p>First this example have some limitation, I try it on my XAMPP localhost, so I assumed the it is the top parent of all directories, the tree directory only load once when the page is loaded, file preview only in grid component.<span id="more-6871"></span></p>
<p style="text-align: center;"><a title="ExtJS File Browser Download" href="http://www.box.net/shared/eoby0n0ti5" target="_blank" class="button large green">download</a></p>
<h5>ExtJS</h5>
<p>The example container is based on window component, which have two items inside, they are treePanel and gridPanel, the gridPanel will load dynamically, trigerred when user click on of the tree node.</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.onReady(function() {
    store_dir = Ext.create('Ext.data.TreeStore', {
        proxy: {
            type: 'ajax',
            url: 'get_dir.php'
        }
    });

    tree_dir = Ext.create('Ext.tree.Panel', {
        title: 'Localhost Directory',
        rootVisible: false,
        store: store_dir,
        split: true,
        region: 'west',
        collapsible: true,
        floatable: false,
        width: 200,
        useArrows: true,
        listeners: {
            itemclick: {
                fn: function(view, record, item, index, event) {
                    store_file.load({
                        url: 'get_file.php?dir=' + record.data.id
                    });

                    nodeId = record.data.id;
                    htmlId = item.id;
                }
            }

        }
    });

    Ext.define('File', {
       extend: 'Ext.data.Model',
       fields: ['filename', 'filesize', 'filedate']
    });

    store_file = Ext.create('Ext.data.Store', {
        model: 'File',
        proxy: {
          type: 'ajax',
          url: 'get_file.php',
          reader: {
              type: 'json',
              root: 'files'
          }
        }
    });

    grid_file = Ext.create('Ext.grid.Panel', {
        title: 'File List',
        region: 'center',
        store: store_file,
        columns: [
            { header: 'Name', width: 170, dataIndex: 'filename' },
            { header: 'Size', width: 100, dataIndex: 'filesize' },
            { header: 'Last Modified', width: 200, dataIndex: 'filedate' }
        ],
        viewConfig: {
            stripeRows: true
        }
    });

    win = Ext.create('widget.window', {
        title: 'ExtJS Simple File Browser',
        width: 700,
        height: 400,
        layout: 'border',
        bodyStyle: 'padding: 5px;',
        items: [tree_dir, grid_file]
    });

    win.show();
});
</pre>
<h5>PHP (get_dir.php)</h5>
<p>This file is for fetching all directory on your XAMPP htdocs directory, using <em>$_SERVER['DOCUMENT_ROOT']</em> variable. If you have many directory on htdocs, it will take time to load. In this php file I used a recursive function to get all the directory with all the sub directory by one call function, that&#8217;s why it will take time to load, and create a json format from it.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

class MyDirectory {

    public $json = '[';

    public function get_children($dir, $child) {
        $dh = opendir($dir);
        while (($file = readdir($dh)) !== false) {
            if ($file != '.' AND $file != '..' ) {
                if (filetype($dir . $file) == 'dir') {
                    // must be checked if this folder have other subfolder
                    if ($this-&gt;count_sub_dir($dir . $file . '/') == 0) {
                        $this-&gt;json .= '{text:&quot;'.$file.'&quot;, leaf: true, id: &quot;'.$dir . $file.'&quot;},';
                    } else {
                        $this-&gt;json .= '{text:&quot;'.$file.'&quot;, id: &quot;'.$dir . $file.'&quot;, children: [';
                        $this-&gt;get_children($dir . $file . '/', true);
                    }
                }
            }
        }
        if ($child) {
            $this-&gt;json .=  ']},';
        }
        closedir($dh);
    }

    public function count_sub_dir($dir) {
        $dh = opendir($dir);
        $countdir = 0;
        while (($file = readdir($dh)) !== false) {
            if ($file != '.' AND $file != '..' ) {
                if (filetype($dir . $file) == 'dir') {
                    $countdir++;
                }
            }
        }
        closedir($dh);
        return $countdir;
    }
}

$host_dir = $_SERVER['DOCUMENT_ROOT'].&quot;/&quot;;

$dir = new MyDirectory();

$dir-&gt;get_children($host_dir, false);

$dir-&gt;json .= ']';
$dir-&gt;json = str_replace(&quot;,]&quot;, &quot;]&quot;, $dir-&gt;json);

echo($dir-&gt;json);

?&gt;
</pre>
<h5>PHP (get_file.php)</h5>
<p>And this is the last file to get all the file (without any directory) in specific directory, the parameter sent from ExtJS tree node, when it clicked.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

$dir = $_GET['dir'] . &quot;/&quot;;

$dh = opendir($dir);
$files = array();
while (($file = readdir($dh)) !== false) {
    if ($file != '.' AND $file != '..' ) {
        if (filetype($dir . $file) == 'file') {
            $files[] = array(
                'filename' =&gt; $file,
                'filesize' =&gt; filesize($dir . $file). ' bytes',
                'filedate' =&gt; date(&quot;F d Y H:i:s&quot;, filemtime($dir . $file))
            );
        }
    }
}
closedir($dh);

echo(json_encode(array('files' =&gt; $files)));

?&gt;
</pre>
<p>Well that all hope can give some idea to create much larger application or adding some more feature like icons view (using DataView component), create, edit, delete file, etc.</p>
<p style="text-align: center;"><a title="ExtJS File Browser Donwload" href="http://www.box.net/shared/eoby0n0ti5" target="_blank" class="button large green">download</a><br />
<img class="alignnone size-full wp-image-6872" title="ExtJS File Browser" src="http://superdit.com/wp-content/uploads/2011/06/screenshot-2.png" alt="ExtJS File Browser" width="540" height="318" /></p>
]]></content:encoded>
			<wfw:commentRss>http://superdit.com/2011/06/01/extjs-simple-file-browser/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>ExtJS: Load Grid From Another Grid</title>
		<link>http://superdit.com/2011/05/23/extjs-load-grid-from-another-grid/</link>
		<comments>http://superdit.com/2011/05/23/extjs-load-grid-from-another-grid/#comments</comments>
		<pubDate>Mon, 23 May 2011 09:54:46 +0000</pubDate>
		<dc:creator>aditia rahman</dc:creator>
				<category><![CDATA[Extjs]]></category>
		<category><![CDATA[grid]]></category>

		<guid isPermaLink="false">http://superdit.com/?p=6752</guid>
		<description><![CDATA[About last week I got a question from a friend in ExtJS subject, like this pst title said he asking how to load a grid from another grid, which mean the first grid loaded when the page load, and the second grid loads when a row in the first grid clicked. This is really simple<a href="http://superdit.com/2011/05/23/extjs-load-grid-from-another-grid/" class="read-more">Continue Reading</a>]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">About last week I got a question from a friend in ExtJS subject, like this pst title said he asking how to load a grid from another grid, which mean the first grid loaded when the page load, and the second grid loads when a row in the first grid clicked.</p>
<p style="text-align: center;"><a title="ExtJS: Load Grid From Another Grid" href="http://superdit.com/2011/05/23/extjs-load-grid-from-another-grid/"><img class="alignnone size-full wp-image-6755" title="Extjs load grid from other grid" src="http://superdit.com/wp-content/uploads/2011/05/Extjs_load_grid_from_other_grid.jpg" alt="Extjs load grid from other grid" width="524" height="158" /></a></p>
<p style="text-align: left;">This is really simple actually, in this example I&#8217;m using static json file as a data source, the data are the company list and the company product list, i get all this data from wikipedia.<span id="more-6752"></span></p>
<p style="text-align: center;"><a title="ExtJS: load grid fro others grid demo" href="http://demo.superdit.com/extjs/load_grid_from_other_grid/" target="_blank">view demo</a> | <a title="ExtJS load grid from another grid download" href="http://www.box.net/shared/7dz1cam6eg" target="_blank">download source</a></p>
<p style="text-align: left;">First let define the data by creating two json file, I named <em>company.json</em> and <em>products.json</em>, these two data connected by <em>company_id </em>property that defined in products.json. Here the code look a like.</p>
<h5 style="text-align: left;">Company.json</h5>
<pre class="brush: jscript; title: ; notranslate">
{'companies': [{
    'id': '1',
    'name': 'Google',
    'founded': 'September 4, 1998',
    'people': 'Sergey Brin, Larry Page'
}, {
    'id': '2',
    'name': 'Microsoft',
    'founded': 'April 4, 1975',
    'people': 'Bill Gates, Paul Allen'
}, {
    'id': '3',
    'name': 'Yahoo',
    'founded': 'March 1, 1995',
    'people': 'Jerry Yang, David Filo'
}
]}
</pre>
<h5 style="text-align: left;">Products.js</h5>
<pre class="brush: jscript; title: ; notranslate">
{'products': [{
    'company_id': '1',
    'name': 'Google Analytics',
    'type': 'Web Statistics'
}, {
    'company_id': '1',
    'name': 'Gmail',
    'type': 'Communication'
}, {
    'company_id': '2',
    'name': 'Xbox',
    'type': 'Game Console'
}, {
    'company_id': '2',
    'name': 'Bing',
    'type': 'Web Search'
}, {
    'company_id': '3',
    'name': 'Yahoo! Publisher Network',
    'type': 'Web Advertising'
}
]}
</pre>
<h5 style="text-align: left;">Full Source Code</h5>
<pre class="brush: jscript; title: ; notranslate">
Ext.onReady(function() {
   Ext.define('Company', {
       extend: 'Ext.data.Model',
       fields: ['id', 'name', 'founded', 'people']
   });

   var store_company = new Ext.data.Store({
      model: 'Company',
      proxy: {
          type: 'ajax',
          url: 'company.json',
          reader: {
              type: 'json',
              root: 'companies'
          }
      }
   });

    var grid_company = Ext.create('Ext.grid.Panel', {
        store: store_company,
        columns: [
            {
                text     : 'Company Name',
                dataIndex: 'name'
            },
            {
                text     : 'Founded',
                width    : 200,
                dataIndex: 'founded'
            },
            {
                text     : 'Key People',
                width    : 250,
                dataIndex: 'people'
            }
        ],
        height: 200,
        width: 550,
        title: 'Company List',
        renderTo: 'grid-company',
        viewConfig: {
            stripeRows: true
        },
        listeners: {
            itemclick : function() {
                var data = grid_company.getSelectionModel().selected.items[0].data;
                grid_product.setTitle(data.name + ' Products List');
                store_product.clearFilter();
                store_product.filter('company_id', data.id);
                store_product.load();
            }
        }
    });

    store_company.load();

    Ext.define('Product', {
       extend: 'Ext.data.Model',
       fields: ['company_id', 'name', 'type']
    });

    var store_product = new Ext.data.Store({
      model: 'Product',
      proxy: {
          type: 'ajax',
          url: 'products.json',
          reader: {
              type: 'json',
              root: 'products'
          }
      }
    });

    var grid_product = Ext.create('Ext.grid.Panel', {
        store: store_product,
        columns: [
            {
                text     : 'Product Name',
                dataIndex: 'name',
                width    : 350,
            },
            {
                text     : 'Type',
                width    : 200,
                dataIndex: 'type'
            }
        ],
        height: 200,
        width: 550,
        title: 'Product List',
        renderTo: 'grid-product',
        viewConfig: {
            stripeRows: true
        }
    });
});
</pre>
<p style="text-align: left;">The main function in this example is the <em>itemclick </em>listener on the company name grid, we can directly filter the store by using <em>filter()</em> method, but remember to use <em>clearFilter()</em> too, otherwise each time the filter called, the filter condition will be stacked, somekind the &#8220;and&#8221; operator in programming.</p>
<pre class="brush: jscript; title: ; notranslate">
listeners: {
    itemclick : function() {
        var data = grid_company.getSelectionModel().selected.items[0].data;
        grid_product.setTitle(data.name + ' Products List');
        store_product.clearFilter();
        store_product.filter('company_id', data.id);
        store_product.load();
    }
}
</pre>
<p style="text-align: left;">That a simple example using the static json data, to use other data like array or dynamic data, like fetching from php, you can modified the store component for example using the arraystore.</p>
<p style="text-align: center;"><a title="ExtJS: load grid fro others grid demo" href="http://demo.superdit.com/extjs/load_grid_from_other_grid/" target="_blank">view demo</a> | <a title="ExtJS load grid from another grid download" href="http://www.box.net/shared/7dz1cam6eg" target="_blank">download source</a></p>
<p style="text-align: center;"><a href="http://demo.superdit.com/extjs/load_grid_from_other_grid/" target="_blank"><img class="alignnone size-full wp-image-6756" title="Extjs load grid from other grid" src="http://superdit.com/wp-content/uploads/2011/05/Extjs_load_grid_from_other_grid.png" alt="Extjs load grid from other grid" width="540" height="440" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://superdit.com/2011/05/23/extjs-load-grid-from-another-grid/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>ExtJS Displaying Default ComboBox Value</title>
		<link>http://superdit.com/2011/02/15/extjs-displaying-default-combobox-value/</link>
		<comments>http://superdit.com/2011/02/15/extjs-displaying-default-combobox-value/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 04:02:21 +0000</pubDate>
		<dc:creator>aditia rahman</dc:creator>
				<category><![CDATA[Extjs]]></category>
		<category><![CDATA[combobox]]></category>

		<guid isPermaLink="false">http://superdit.com/?p=5196</guid>
		<description><![CDATA[In this sort post I want to share how to displaying default combobox value in ExtJS, I write this post because last week one of my friend asking how to do this, the condition are there is a data grid with edit button in the toolbar, when user choose one row in the grid and<a href="http://superdit.com/2011/02/15/extjs-displaying-default-combobox-value/" class="read-more">Continue Reading</a>]]></description>
			<content:encoded><![CDATA[<p>In this sort post I want to share how to displaying default combobox value in ExtJS, I write this post because last week one of my friend asking how to do this, the condition are there is a data grid with edit button in the toolbar, when user choose one row in the grid and click the edit button, the window component with form inside it appear, to editing data.</p>
<pre class="brush: jscript; title: ; notranslate">
strGroup2.load();
Ext.getCmp('txgroup_id').setValue(sel.data.group_id);
</pre>
<p><span id="more-5196"></span></p>
<p>The problem is we have the combobox value but we want to display the matched record text, it displaying the value not the text, and for the illustration this the little example solution code.</p>
<pre class="brush: jscript; title: ; notranslate">
var strGroup2 = new Ext.data.Store({
    reader: new Ext.data.JsonReader({
        fields: ['id', 'name'], root: 'groups'
    }),
    proxy: new Ext.data.HttpProxy({
        url: BASE_URL + 'group/ext_get_all', method: 'POST'
    })
});

strGroup2.load();

// grid component
var tbUsers = new Ext.Toolbar({
    items: [{
        text: 'Edit',
        id: 'tbUserEdit',
        handler: function() {
            var sm = gridUsers.getSelectionModel();
            var sel = sm.getSelected();
            Ext.getCmp('txgroup_id').setValue(sel.data.group_id);
        }
    }]
});

var formUserEdit = new Ext.FormPanel({
    frame: true,
    border: false,
    items: [{
        xtype:'fieldset',
        title: 'Login Detail',
        collapsible: true,
        autoHeight:true,
        defaultType: 'textfield',
        items: [{
            xtype: 'combo', fieldLabel: 'Group', width: 120,
            emptyText: 'Choose a group ...', allowBlank: false,
            mode: 'local', name: 'group_id', hiddenName: 'group_id',
            store: strGroup2, triggerAction: 'all',
            displayField: 'name', valueField: 'id',
            editable: 'false', id: 'txgroup_id'
        }]
    }]
    }
});
</pre>
<p>You can see on the code above, I assume the solution is the store have to be loaded when the page is loaded, not loaded when the edit button clicked, in my previous post about <a title="Extjs: Simple User Managament Using Codeigniter" href="http://superdit.com/2010/12/09/extjs-simple-user-managament-using-codeigniter/" target="_blank">ExtJS simple user management</a>, I&#8217;m not doing this so I have to tricking in the server side code. At least I know it right now.</p>
]]></content:encoded>
			<wfw:commentRss>http://superdit.com/2011/02/15/extjs-displaying-default-combobox-value/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ExtJS Thumb Viewer Using Dataview</title>
		<link>http://superdit.com/2011/02/11/extjs-thumb-viewer-using-dataview/</link>
		<comments>http://superdit.com/2011/02/11/extjs-thumb-viewer-using-dataview/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 06:25:24 +0000</pubDate>
		<dc:creator>aditia rahman</dc:creator>
				<category><![CDATA[Extjs]]></category>
		<category><![CDATA[dataview]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://superdit.com/?p=4925</guid>
		<description><![CDATA[In this post I want to create an example thumb viewer in ExtJS, if you have tried old software like gqview, you may familiar with this thumb viewer, well not really complicated actually, just love to use it when reading my favorite comic. View Demo &#124; Download Source The ExtJS The main component of this<a href="http://superdit.com/2011/02/11/extjs-thumb-viewer-using-dataview/" class="read-more">Continue Reading</a>]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-5117" title="extjs thumb viewer dataview" src="http://superdit.com/wp-content/uploads/2011/02/extjs_thumb_viewer_dataview.png" alt="extjs thumb viewer dataview" width="540" height="150" /></p>
<p>In this post I want to create an example thumb viewer in ExtJS, if you have tried old software like <a title="gqview" href="http://gqview.sourceforge.net/" target="_blank">gqview</a>, you may familiar with this thumb viewer, well not really complicated actually, just love to use it when reading my favorite comic.<span id="more-4925"></span></p>
<p style="text-align: center;"><a href="http://demo.superdit.com/ext_thumb_dataview" target="_blank">View Demo</a> | <a href="http://www.box.net/shared/6m48fb9fsd" target="_blank">Download Source</a></p>
<h5>The ExtJS</h5>
<p>The main component of this viewer is two dataview, one for thumbnails and another one for the original image. When a thumbnail clicked the relevant image show in the dataview that contain the original image, using some old html trick, jump to some html element based on id, like <em>#divid</em>.</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.onReady(function() {
    /* =======================================
     * start component for thumbnails panel */
    var storeThumbs = new Ext.data.JsonStore({
        proxy: new Ext.data.HttpProxy({
            url: 'get-images.php', method: 'POST'
        }),
        root: 'images',
        fields: [
            'id', 'name', 'url',
            { name: 'size', type: 'float' },
            'thumb_url'
        ]
    });

    storeThumbs.load();

    var tplThumbs = new Ext.XTemplate(
        '&lt;tpl for=&quot;.&quot;&gt;',
            '&lt;div class=&quot;thumb-box&quot;&gt;',
                '&lt;a href=&quot;#{id}&quot;&gt;',
                    '&lt;img src=&quot;{thumb_url}&quot; title=&quot;{name}&quot;&gt;',
                '&lt;/a&gt;',
            '&lt;/div&gt;',
        '&lt;/tpl&gt;'
    );

    var dvThumbs = new Ext.DataView({
        autoScroll: true, store: storeThumbs, tpl: tplThumbs,
        autoHeight: false, height: 410, multiSelect: true,
        overClass: 'x-view-over', itemSelector: 'div.thumb-wrap',
        emptyText: 'No images to display',
        border: false
    });

    // Panel for the thumbnails
    var panelThumbs = new Ext.Panel({
        region: 'west',
        split: false,
        width: 160,
        margins:'5 5 5 0',
        items: [dvThumbs]
    });
    /* end component for thumbnails panel
     * =================================== */

    /* =======================================
     * start component for large panel */
    var storeLarge = new Ext.data.JsonStore({
        proxy: new Ext.data.HttpProxy({
            url: 'get-images.php', method: 'POST'
        }),
        root: 'images',
        fields: [
            'id', 'name', 'url',
            { name: 'size', type: 'float' },
            'thumb_url'
        ]
    });
    storeLarge.load();

    var tplLarge = new Ext.XTemplate(
        '&lt;tpl for=&quot;.&quot;&gt;',
            '&lt;div class=&quot;large-box&quot; id=&quot;{id}&quot;&gt;',
                '&lt;img src=&quot;{url}&quot; title=&quot;{name}&quot;&gt;',
            '&lt;/div&gt;',
        '&lt;/tpl&gt;'
    );

    var dvLarge = new Ext.DataView({
        autoScroll: true, store: storeLarge, tpl: tplLarge,
        autoHeight: false, height: 410, multiSelect: true,
        overClass: 'x-view-over', itemSelector: 'div.thumb-wrap',
        emptyText: 'No images to display',
        border: false
    });

    // Panel for large images
    var panelLarge = new Ext.Panel({
        region: 'center',
        margins:'5 0 5 0',
        items:[dvLarge]
    });
    /* end component for large panel
     * =================================== */

    var win = new Ext.Window({
        title: 'ExtJS Images Viewer',
        closable: false,
        width: 620,
        height: 450,
        border: false,
        plain: true,
        layout: 'border',
        items: [panelThumbs, panelLarge]
    });

    win.show(this);
});
</pre>
<h5>The PHP</h5>
<p>This php code is very similar to the script from the <a title="ExExtjs: Simple Image Gallery Using DataView and PHP" href="http://superdit.com/2010/07/21/extjs-simple-image-gallery-using-dataview-and-php/" target="_blank">ExtJS image gallery post</a>, just add an <em>id</em> inside the array.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$dir = &quot;img/large/&quot;;
$dir_thumbs = &quot;img/thumbs/&quot;;

$images = array();
$d = dir($dir);
$loop = 0;
while($name = $d-&gt;read()){
    if(!preg_match('/\.(jpg|gif|png)$/', $name)) continue;
    $size = filesize($dir.$name);
    $thumb = $name;
    $loop++;
    $images[] = array('id'=&gt; 'img_'.$loop, 'name' =&gt; $name,
                    'size' =&gt; $size, 'url' =&gt; $dir.$name,
                    'thumb_url' =&gt; $dir_thumbs.$thumb);
}
$d-&gt;close();
$o = array('images'=&gt;$images);
echo json_encode($o);
</pre>
<h5>Dataview CSS</h5>
<pre class="brush: css; title: ; notranslate">
.thumb-box  {
    width: 100px;
    padding: 5px;
    text-align: center;
    margin: 13px auto;
    background: #ccd8e7;
    border: 1px solid #99BBE8;
    -webkit-border-radius: .5em;
    -moz-border-radius: .5em;
    border-radius: .5em;
}

.thumb-box:hover {
    background: #999999;
    border-color: #999999;
}

.large-box {
    width: 375px;
    margin: 15px auto;
}
</pre>
<p style="text-align: center;"><a href="http://demo.superdit.com/ext_thumb_dataview" target="_blank">View Demo</a> | <a href="http://www.box.net/shared/6m48fb9fsd" target="_blank">Download Source</a></p>
<p style="text-align: center;"><a href="http://demo.superdit.com/ext_thumb_dataview/" target="_blank"><img class="aligncenter size-full wp-image-5122" title="extjs thumb viewer dataview" src="http://superdit.com/wp-content/uploads/2011/02/extjs_thumb_viewer_dataview_capture.png" alt="extjs thumb viewer dataview" width="540" height="394" /></a></p>
<p><em>Credit Images: <a href="http://flickr.com" target="_blank">Flickr</a></em><em> [ <a href="http://www.flickr.com/photos/libertymorningstar/5428014531/" target="_blank">images 1</a> ], [ <a href="http://www.flickr.com/photos/96919150@N00/103439599/" target="_blank">images 2</a> ], [ <a href="http://www.flickr.com/photos/flaviocb/3880246186/" target="_blank">images 3</a> ], [ <a href="http://www.flickr.com/photos/joorgawt/3375087291/" target="_blank">images 4</a> ], [ <a href="http://www.flickr.com/photos/arihahn/314472601/" target="_blank">images 5</a> ]</em></p>
]]></content:encoded>
			<wfw:commentRss>http://superdit.com/2011/02/11/extjs-thumb-viewer-using-dataview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Web Seach With ExtJS Grid and PHP</title>
		<link>http://superdit.com/2011/01/24/google-web-seach-with-extjs-grid-and-php/</link>
		<comments>http://superdit.com/2011/01/24/google-web-seach-with-extjs-grid-and-php/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 06:02:31 +0000</pubDate>
		<dc:creator>aditia rahman</dc:creator>
				<category><![CDATA[Extjs]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://superdit.com/?p=4138</guid>
		<description><![CDATA[This time I want to make a simple example in displaying google web search result in ExtJS grid, other ExtJS component that can be used to displaying this result is dataview, but grid is more common in displaying data in ExtJS, to use google search API you have to signup to get an API key,<a href="http://superdit.com/2011/01/24/google-web-seach-with-extjs-grid-and-php/" class="read-more">Continue Reading</a>]]></description>
			<content:encoded><![CDATA[<p>This time I want to make a simple example in displaying google web search result in ExtJS grid, other ExtJS component that can be used to displaying this result is dataview, but grid is more common in displaying data in ExtJS, to use google search API you have to <a href="http://code.google.com/apis/loader/signup.html" target="_blank">signup</a> to get an API key, one key is only for one domain.</p>
<p><a title="Google API Key Signup" href="http://code.google.com/apis/loader/signup.html" target="_blank"><img class="aligncenter size-full wp-image-4507" title="Google API Key" src="http://superdit.com/wp-content/uploads/2011/01/api-key.png" alt="Google API Key" width="540" height="210" /><span id="more-4138"></span></a></p>
<p>If you want to know the detail about google search API, you can refer this <a href="http://code.google.com/apis/websearch/docs/reference.html" target="_blank">link</a>.</p>
<h6>The ExtJS Code</h6>
<p>The ExtJS code contains Windows, gridPanel, pagingToolbar, searchField</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.onReady(function() {
    var store = new Ext.data.JsonStore({
        root: 'results',
        totalProperty: 'totalCount',
        remoteSort: true,

        fields: [
            'GsearchResultClass',
            'unescapedUrl',
            'url',
            'visibleUrl',
            'cacheUrl',
            'title',
            'titleNoFormatting',
            'content'
        ],

        proxy: new Ext.data.HttpProxy({
            url: 'search.php'
        })
    });

    function renderResult(value, p, record){
        return String.format(
            '&lt;a class=&quot;link&quot; href=&quot;{1}&quot; target=&quot;_blank&quot;&gt;{0}&lt;/a&gt;',
            record.data.title, record.data.unescapedUrl);
    }

    var grid = new Ext.grid.GridPanel({
        border: false,
        width: 485,
        height: 430,
        store: store,
        loadMask: true,
        columns: [{
            header: 'Results',
            dataIndex: 'title',
            width: 480,
            renderer: renderResult
        }],

        viewConfig: {
            forceFit:true,
            enableRowBody:true,
            showPreview:true,
            getRowClass : function(record, rowIndex, p, store){
                p.body = '&lt;p class=&quot;excerpt&quot;&gt;'+record.data.content+'&lt;/p&gt;';
            }
        },
        tbar: [
            '-&gt;',
            new Ext.ux.form.SearchField({
                store: store,
                width: 200,
                emptyText: 'Google Search'
            })
        ],
        bbar: new Ext.PagingToolbar({
            pageSize: 8,
            store: store,
            displayInfo: true
        })
    });

    var window = new Ext.Window({
        title: 'Google Web Search - ExtJS &amp; PHP',
        width: 500,
        height: 460,
        closable: false,
        resizable: false,
        items: [grid]
    }).show();
});
</pre>
<p><strong>The Search Field</strong> used is from the <em>ExtJS ux</em> you can found it on the example section, and it placed in the gridPanel toolbar, inside the <strong>GridPanel</strong> there is a <em>viewConfig, </em>I&#8217;m following this <a href="http://dev.sencha.com/deploy/dev/examples/grid/paging.html" target="_blank">example</a>, this is for displaying search result content (short description)</p>
<h6>The PHP Code</h6>
<p>The PHP code used to make me easier generating json format so ExtJS can be easily read all the data</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 8;

$q = str_replace(&quot; &quot;, &quot;%20&quot;, $_REQUEST['query']);
$key = &quot;insert your key&quot;;

$url = 'https://ajax.googleapis.com/ajax/services/search/web?v=1.0&amp;q='.$q.'&amp;start='.$start.'&amp;rsz='.$limit.'&amp;key='.$key;

$content = file_get_contents($url);
$array = json_decode($content);

$data = array();

foreach ($array-&gt;responseData-&gt;results as $var =&gt; $value)
{
    $data[] = array(
        &quot;GsearchResultClass&quot; =&gt; $value-&gt;GsearchResultClass,
        &quot;unescapedUrl&quot;       =&gt; $value-&gt;unescapedUrl,
        &quot;visibleUrl&quot;         =&gt; $value-&gt;visibleUrl,
        &quot;cacheUrl&quot;           =&gt; $value-&gt;cacheUrl,
        &quot;title&quot;              =&gt; $value-&gt;title,
        &quot;titleNoFormatting&quot;  =&gt; $value-&gt;titleNoFormatting,
        &quot;content&quot;            =&gt; $value-&gt;content
    );
}

$out = array(
    &quot;success&quot; =&gt; true,
    &quot;totalCount&quot; =&gt; $array-&gt;responseData-&gt;cursor-&gt;estimatedResultCount,
    &quot;results&quot; =&gt; $data
);

echo json_encode($out);

?&gt;
</pre>
<h6>The CSS Code</h6>
<p>This is the simple CSS code for customizing the grid row style</p>
<pre class="brush: css; title: ; notranslate">
.link {
    color: #333;
    line-height: 25px;
    text-decoration: none;
    font-size: 13px;
    padding: 5px 10px;
    display: block;
    -webkit-border-radius: 1.0em;
    -moz-border-radius: 1.0em;
    border-radius: 1.0em;
}
.link:hover {
    background: #333;
    color: #f3f3f3;
}
.excerpt {
    padding: 5px 20px;
    color: #999;
}
</pre>
<p>Here is the result</p>
<p style="text-align: center;"><a href="http://demo.superdit.com/ext_php_google/" target="_blank"><img class="aligncenter size-full wp-image-4498" title="Google Web Search With ExtJS &amp; PHP" src="http://superdit.com/wp-content/uploads/2011/01/screenshot.png" alt="Google Web Search With ExtJS &amp; PHP" width="509" height="471" /></a></p>
<h6 style="text-align: center;"><a href="http://demo.superdit.com/ext_php_google/" target="_blank">View Demo</a> | <a href="http://www.box.net/shared/iyf2x8or8h" target="_blank">Download Source</a></h6>
]]></content:encoded>
			<wfw:commentRss>http://superdit.com/2011/01/24/google-web-seach-with-extjs-grid-and-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extjs DataView With Pagination</title>
		<link>http://superdit.com/2011/01/11/extjs-dataview-with-pagination/</link>
		<comments>http://superdit.com/2011/01/11/extjs-dataview-with-pagination/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 09:11:44 +0000</pubDate>
		<dc:creator>aditia rahman</dc:creator>
				<category><![CDATA[Extjs]]></category>
		<category><![CDATA[dataview]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://superdit.com/?p=3910</guid>
		<description><![CDATA[It&#8217;s quite a long time since I write post about ExtJS, just want to add ExtJS to my post collection, this time I want to show it that the dataview component can be applied with paging toolbar, maybe you want to create a gallery that have a lot of images, and basically I using my<a href="http://superdit.com/2011/01/11/extjs-dataview-with-pagination/" class="read-more">Continue Reading</a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s quite a long time since I write post about ExtJS, just want to add ExtJS to my post collection, this time I want to show it that the dataview component can be applied with paging toolbar, maybe you want to create a gallery that have a lot of images, and basically I using my older source about <a title="Extjs: Simple Image Gallery Using DataView and PHP" href="http://superdit.com/2010/07/21/extjs-simple-image-gallery-using-dataview-and-php/" target="_blank">Image Gallery in ExtJS</a>, actually not much change in the code and I only post some part of code from this example, but of course you can download the full source code or view the online demo.</p>
<p><a href="http://superdit.com/2011/01/11/extjs-dataview-with-pagination/"><img class="aligncenter size-full wp-image-3953" title="extjs_dataview_pagination" src="http://superdit.com/wp-content/uploads/2011/01/extjs_dataview_pagination.png" alt="" width="500" height="164" /></a></p>
<h6 style="text-align: center;"><a title="extjs dataview pagination example" href="http://demo.superdit.com/ext_dataview_pagination/" target="_blank"><span id="more-3910"></span>View Demo</a> | <a title="extjs dataview pagination download source" href="http://www.box.net/shared/kofn7umxx6" target="_blank">Download Source</a></h6>
<p>First I modified the store component</p>
<pre class="brush: jscript; title: ; notranslate">
var store = new Ext.data.Store({
    reader: new Ext.data.JsonReader({
        root:'images', totalProperty: 'result'
        }, [ 'name', 'thumb_url' ]
    ),
    proxy: new Ext.data.HttpProxy({
        url: 'get-images.php', method: 'POST'
    })
});
</pre>
<p>The store varible I changed to <em>Ext.data.Store</em> component and the reader must be in JsonReader otherwise it will not work for me, and now create the paging toolbar component</p>
<pre class="brush: jscript; title: ; notranslate">
var pagingbar = new Ext.PagingToolbar({
    style: 'border:1px solid #99BBE8;',
    store: store,
    pageSize: 5,
    displayInfo: true
});
</pre>
<p>The <em>Ext.PagingToolbar</em> is a subclass of the <em>Ext.Toolbar</em> so it can be included in panel component as an items, here what it look like</p>
<pre class="brush: jscript; title: ; notranslate">
var panelMain = new Ext.Panel({
    id: 'images-view',
    frame: true,
    width: 640,
    height: 200,
    autoHeight: true,
    layout: 'auto',
    title: 'ExtJS DataView With Pagination',
    items: [pagingbar,datav]
});
</pre>
<p>And lastly is the PHP code that I modified</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$dir_thumbs = &quot;img/thumbs/&quot;;

$images = array();
$d = dir($dir_thumbs);

$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 5;

while($name = $d-&gt;read()){
    if(!preg_match('/\.(jpg|gif|png)$/', $name)) continue;
    $size = filesize($dir_thumbs.$name);
    $lastmod = filemtime($dir_thumbs.$name)*1000;
    $images[] = array(
        'name' =&gt; $name,
        'thumb_url' =&gt; $dir_thumbs.$name
    );
}

$result = count($images);

if ($start == 0) {
    $finish = $limit;
} else {
    $finish = $start + $limit;
}

$fetch_images = array();
for ($i = $start; $i &lt; $finish; $i++) {
    $fetch_images[] = $images[$i];
}

$d-&gt;close();
$o = array('result' =&gt; $result, 'images' =&gt; $fetch_images);
echo json_encode($o);
</pre>
<p>The data I fetched by reading all files in the a location in the directory, with adding the pagination feature, you can modified it whether you want to get data from database, and using some sql limit function, it&#8217;s up to you.</p>
<h6 style="text-align: center;"><a title="extjs dataview pagination example" href="http://demo.superdit.com/ext_dataview_pagination/" target="_blank">View Demo</a> | <a title="extjs dataview pagination download source" href="http://www.box.net/shared/kofn7umxx6" target="_blank">Download Source</a></h6>
]]></content:encoded>
			<wfw:commentRss>http://superdit.com/2011/01/11/extjs-dataview-with-pagination/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extjs: Simple User Managament Using Codeigniter</title>
		<link>http://superdit.com/2010/12/09/extjs-simple-user-managament-using-codeigniter/</link>
		<comments>http://superdit.com/2010/12/09/extjs-simple-user-managament-using-codeigniter/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 08:07:28 +0000</pubDate>
		<dc:creator>aditia rahman</dc:creator>
				<category><![CDATA[Codeigniter]]></category>
		<category><![CDATA[Extjs]]></category>
		<category><![CDATA[user management]]></category>

		<guid isPermaLink="false">http://superdit.com/?p=1718</guid>
		<description><![CDATA[Hello again this is another post of ExtJS, this post is to showing my little idea how to manage user permission in ExtJS component, In this post I not showing the full source code, just a little part of the code to get the idea how it works, however the complete source code still available<a href="http://superdit.com/2010/12/09/extjs-simple-user-managament-using-codeigniter/" class="read-more">Continue Reading</a>]]></description>
			<content:encoded><![CDATA[<p>Hello again this is another post of ExtJS, this post is to showing my little idea how to manage user permission in ExtJS component, In this post I not showing the full source code, just a little  part of the code to get the idea how it works, however the complete source code still  available on the download link at the end of this post.</p>
<p><img class="size-full wp-image-3265 alignleft" title="Ext User Management File-Structure" src="http://superdit.com/wp-content/uploads/2010/12/File-Structure.png" alt="" width="217" height="288" /></p>
<p>This example is a simple user management that user can manipulate other user data and users groups, user need to logged in to the system to do some action, and the feature are:</p>
<p>- Add, Update, Delete Users<br />
- Add, Update, Delete Groups<br />
- Administrator cannot be deleted or updated</p>
<p>Which  mean it will take different action button in the application screen, depend on the  users groups, what is not handled in this example is user   restriction, if a group have granted to modify certain user,   it can modify whole user although it is the administrator.</p>
<p>The image is the file structure that I have created on this example, there will be a form and two grid panel in this application, a usual login form with label and textfield, a grid contain user data with the toolbar menu and a grid contain group data.</p>
<p>In the database we need to make a relation between user and groups and here the sql code that I created, for both groups and users table<span id="more-1718"></span></p>
<pre class="brush: sql; title: ; notranslate">
-- Table structure for table `groups`

CREATE TABLE IF NOT EXISTS `groups` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `user_add` int(1) NOT NULL,
  `user_edit` int(1) NOT NULL,
  `user_delete` int(1) NOT NULL,
  `group_add` int(1) NOT NULL,
  `group_edit` int(1) NOT NULL,
  `group_delete` int(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;

-- Table structure for table `users`

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `group_id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `password` varchar(100) NOT NULL,
  `real_name` varchar(150) NOT NULL,
  `email` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;</pre>
<p>The groups table contains id, group name and all the action that user can do to the application, from the user_add field until group_delete column the value only contains 1 or 0, which mean 1 for user can do this action and zero otherwise, The idea to managing user interface is by  disabling the button on the toolbar based on the user group permissions and this are generated from groups table,  so we need to give a unique Id for each button.</p>
<p>As well in the controller there are two controller that we need to create, user controller in <em>application/controllers/user.php </em>and group controller in <em>application/controllers/group.php</em>. Inside the user controller create the function for login and fetching users session inside user controller</p>
<pre class="brush: php; title: ; notranslate">
public function ext_login()
{
    $cond = array(
        'username' =&gt; $_POST['textusername'],
        'password' =&gt; $_POST['textpassword']
    );
    $query = $this-&gt;db-&gt;get_where('users', $cond);
    if ($query-&gt;num_rows() != 0)
    {
        $row = $query-&gt;row();

        // get group detail
        $g_cond = array(
            'id' =&gt; $row-&gt;group_id
        );
        $g_query = $this-&gt;db-&gt;get_where('groups', $g_cond);
        $g_row = $g_query-&gt;row();

        // pass the the info to session
        $this-&gt;session-&gt;set_userdata('u_id', $row-&gt;id);
        $this-&gt;session-&gt;set_userdata('u_name', $_POST['textusername']);
        $this-&gt;session-&gt;set_userdata('g_id', $g_row-&gt;id);
        $this-&gt;session-&gt;set_userdata('g_u_add', $g_row-&gt;user_add);
        $this-&gt;session-&gt;set_userdata('g_u_edit', $g_row-&gt;user_edit);
        $this-&gt;session-&gt;set_userdata('g_u_delete', $g_row-&gt;user_delete);
        $this-&gt;session-&gt;set_userdata('g_g_add', $g_row-&gt;group_add);
        $this-&gt;session-&gt;set_userdata('g_g_edit', $g_row-&gt;group_edit);
        $this-&gt;session-&gt;set_userdata('g_g_delete', $g_row-&gt;group_delete);

        echo &quot;{success:true}&quot;;
    }
    else
    {
        echo &quot;{success:false, error:'User not found!'}&quot;;
    }
}

public function ext_get_session()
{
    $output = &quot;{success:true, sessions: {&quot;;
    $output .= &quot;u_id: '&quot;.$this-&gt;session-&gt;userdata('u_id').&quot;',&quot;;
    $output .= &quot;u_name: '&quot;.$this-&gt;session-&gt;userdata('u_name').&quot;',&quot;;
    $output .= &quot;g_id: '&quot;.$this-&gt;session-&gt;userdata('g_id').&quot;',&quot;;
    $output .= &quot;g_u_add: '&quot;.$this-&gt;session-&gt;userdata('g_u_add').&quot;',&quot;;
    $output .= &quot;g_u_edit: '&quot;.$this-&gt;session-&gt;userdata('g_u_edit').&quot;',&quot;;
    $output .= &quot;g_u_delete: '&quot;.$this-&gt;session-&gt;userdata('g_u_delete').&quot;',&quot;;
    $output .= &quot;g_g_add: '&quot;.$this-&gt;session-&gt;userdata('g_g_add').&quot;',&quot;;
    $output .= &quot;g_g_edit: '&quot;.$this-&gt;session-&gt;userdata('g_g_edit').&quot;',&quot;;
    $output .= &quot;g_g_delete: '&quot;.$this-&gt;session-&gt;userdata('g_g_delete').&quot;'&quot;;
    $output .= &quot;}}&quot;;
    echo $output;
}
</pre>
<p>The ext_get_sessions function above is to get session and pass it to the browser, and in the login function the session value will be defined when user logged in to the system, ext_get_sessions function will be used in the <em>permissions.js</em>, I&#8217;m sure you can add the logout function contain the code to unset all the sessions value and here the permissions function look like inside the <em>permissions.js</em></p>
<pre class="brush: php; title: ; notranslate">
 function setPermissions() {
    Ext.Ajax.request({
        url: BASE_URL + 'user/ext_get_session',
        method: 'POST',
        success: function(o) {
            var obj = Ext.util.JSON.decode(o.responseText);
            // set enable/disable grid panel
            if (obj.sessions.u_id != '') {
                Ext.getCmp('fLogin').setDisabled(true);
                Ext.getCmp('gUsers').setDisabled(false);
                Ext.getCmp('gGroups').setDisabled(false);
                Ext.getCmp('userLabel').setText('Welcome &quot;'+obj.sessions.u_name+'&quot;');
            } else {
                Ext.getCmp('fLogin').setDisabled(false);
                Ext.getCmp('gUsers').setDisabled(true);
                Ext.getCmp('gGroups').setDisabled(true);
                Ext.getCmp('userLabel').setText('Please Login');
            }

            // set users toolbar button
            if (obj.sessions.g_u_add == '1') {
                Ext.getCmp('tbUserAdd').setDisabled(false);
            } else {
                Ext.getCmp('tbUserAdd').setDisabled(true);
            }
            if (obj.sessions.g_u_edit == '1') {
                Ext.getCmp('tbUserEdit').setDisabled(false);
            } else {
                Ext.getCmp('tbUserEdit').setDisabled(true);
            }
            if (obj.sessions.g_u_delete == '1') {
                Ext.getCmp('tbUserDelete').setDisabled(false);
            } else {
                Ext.getCmp('tbUserDelete').setDisabled(true);
            }

            // set groups toolbar button
            if (obj.sessions.g_g_add == '1') {
                Ext.getCmp('tbGroupAdd').setDisabled(false);
            } else {
                Ext.getCmp('tbGroupAdd').setDisabled(true);
            }
            if (obj.sessions.g_g_edit == '1') {
                Ext.getCmp('tbGroupEdit').setDisabled(false);
            } else {
                Ext.getCmp('tbGroupEdit').setDisabled(true);
            }
            if (obj.sessions.g_g_delete == '1') {
                Ext.getCmp('tbGroupDelete').setDisabled(false);
            } else {
                Ext.getCmp('tbGroupDelete').setDisabled(true);
            }
        }
    });
}
</pre>
<p>As you can see on the code above, I manipulate the ExtJS component based on &#8220;Id&#8221;, so we need to to add Id properties for the required component,  here a part of login form script and the form id I called it &#8216;fLogin&#8217; (<em> assets/js/login.js </em>)</p>
<pre class="brush: jscript; title: ; notranslate">
// part of login.js
var loginForm = new Ext.FormPanel({
    id: 'fLogin'
});

function fnLogin() {
    loginForm.getForm().submit({
        success: function() {
            setPermissions();
            strUsers.load();
        },
        failure: function(form, o) {
            if (typeof(o.response) != 'undefined') {
                var json = o.response.responseText;
                var r = Ext.util.JSON.decode(json);
                Ext.Msg.alert('Login failed', r.error);
            }
        }
    });
}</pre>
<p>Now part of the user script in ExtJS (<em> assets/js/user.js </em>)</p>
<pre class="brush: jscript; title: ; notranslate">
// part of user.js
var tbUsers = new Ext.Toolbar({
    items: [{
        text: 'Add',
        id: 'tbUserAdd'
    }, '-', {
        text: 'Edit',
        id: 'tbUserEdit'
    }, '-', {
        text: 'Delete',
        id: 'tbUserDelete'
    }, '-&gt;', {
        text: '',
        xtype: 'label',
        style: 'color:#0066cc;font-weight:bold;',
        id: 'userLabel'
    }, '-', {
        text: 'Logout'
    }]
});

var gridUsers = new Ext.grid.GridPanel({
    id: 'gUsers'
});
</pre>
<p>In the group script (<em>assets/js/group.js</em>)</p>
<pre class="brush: jscript; title: ; notranslate">
var tbGroups = new Ext.Toolbar({
    items: [{
        text: 'Add',
        id: 'tbGroupAdd'
    }, '-', {
        text: 'Edit',
        id: 'tbGroupEdit'
    }, '-', {
        text: 'Delete',
        id: 'tbGroupDelete'
    }]
});

var gridGroups = new Ext.grid.GridPanel({
    id: 'gGroups'
});
</pre>
<p>For the adding and editing users and group I&#8217;m using a pop up window that have form to be submitted inside it, and for delete action I&#8217;m just using simple alert confirmation box. Well I think it is too much if I show all the code in this post, just go to the download link if you want to see full source code of this example, and here some of the screen capture.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-3366" title="Extjs User Management - Index" src="http://superdit.com/wp-content/uploads/2010/12/Extjs-User-Management-Index.png" alt="" width="500" height="212" /></p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-3367" title="Extjs User Management - Edit User" src="http://superdit.com/wp-content/uploads/2010/12/ExtUserMan-Edit-User.png" alt="" width="500" height="379" /></p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-3368" title="Extjs User Management - Edit Group" src="http://superdit.com/wp-content/uploads/2010/12/ExtUserMan-Edit-Group.png" alt="" width="500" height="300" /></p>
<p style="text-align: center;"><a href="http://www.box.net/shared/m91x1k4z1m" target="_blank">Download Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://superdit.com/2010/12/09/extjs-simple-user-managament-using-codeigniter/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>ExtJS: Custom Right Click Menu in Dataview</title>
		<link>http://superdit.com/2010/10/05/extjs-custom-right-click-menu-in-dataview/</link>
		<comments>http://superdit.com/2010/10/05/extjs-custom-right-click-menu-in-dataview/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 04:22:57 +0000</pubDate>
		<dc:creator>aditia rahman</dc:creator>
				<category><![CDATA[Extjs]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://superdit.com/?p=3023</guid>
		<description><![CDATA[Sometimes we need to add a custom menu in mouse right click event function, and this is possible in ExtJS, why would I create  this, just my though to create file explorer like using ExtJS, and what I think to list all the file that available is in Dataview, maybe this useful in the future,<a href="http://superdit.com/2010/10/05/extjs-custom-right-click-menu-in-dataview/" class="read-more">Continue Reading</a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes we need to add a custom menu in mouse right click event function, and this is possible in ExtJS, why would I create  this, just my though to create file explorer like using ExtJS, and what I think to list all the file that available is in Dataview, maybe this useful in the future, actually this is very simple here the part of the code.</p>
<p>First we create the menu that we want</p>
<pre class="brush: jscript; title: ; notranslate">
var menu1 = new Ext.menu.Menu({
    items: [
        {
            text: 'I like Ext',
            checked: true
        }, '-', {
            text: 'Open With',
            menu: {
                items: [{
                    text: 'Notepad ++'
                }, {
                    text: 'GIMP 2.0'
                }, {
                    text: 'Firefox'
                }]
            }
        }, '-', {
            text: 'Cut'
        }, {
            text: 'Copy'
        }, {
            text: 'Delete'
        }, '-', {
            text: 'Rename'
        }
    ]
});
</pre>
<p><span id="more-3023"></span></p>
<p>You can freely create any custom menu cause in this post there are no function handler in each menu, And the dataview, this is the part in my previous post about creating <a title="Image Gallery Using ExtJS Dataview" href="http://superdit.com/2010/07/21/extjs-simple-image-gallery-using-dataview-and-php/" target="_blank">image gallery using dataview</a></p>
<pre class="brush: jscript; title: ; notranslate">
var datav = new Ext.DataView({
    autoScroll: true, store: store, tpl: tpl,
    autoHeight: false, height: 250, multiSelect: true,
    overClass: 'x-view-over', itemSelector: 'div.thumb-wrap',
    emptyText: 'No images to display',
    style: 'border:1px solid #99BBE8;',
    listeners: {
        render: {
            fn: function() {
                 Ext.getBody().on(&quot;contextmenu&quot;, Ext.emptyFn,
                    null, {preventDefault: true});
            }
        },
        contextmenu: {
            fn: function(obj, index, node, event) {
                x = event.browserEvent.clientX;
                y = event.browserEvent.clientY;
                menu1.showAt([x, y]);
            }
        }
    }
});
</pre>
<p>When the data view is rendered it disabling the default right click web browser menu, I get it from this <a title="ExtJS : How to disable browser context menu" href="http://iamtotti.com/blog/2010/02/extjs-how-to-disable-browser-context-menuxt/" target="_blank">blog post</a>, this is called in listeners &#8220;render&#8221; event and &#8220;contexmenu&#8221; event is for detecting right click mouse event, capture the mouse cursor position and displaying the menu. Here the screenshot, source code and the online demo.</p>
<p style="text-align: center;"><img class="size-full wp-image-3033 alignnone" title="Extjs Custom Rightclick menu in Dataview" src="http://superdit.com/wp-content/uploads/2010/10/localhost_8080_ext_dataview_rightclick.png" alt="Extjs Custom Rightclick menu in Dataview" width="500" height="276" /></p>
<p style="text-align: center;"><a href="http://www.box.net/shared/8f3ok75ure" target="_blank">Download Source</a> | <a href="http://demo.superdit.com/ext_dataview_rightclick/" target="_blank">View Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://superdit.com/2010/10/05/extjs-custom-right-click-menu-in-dataview/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Sticky Notes Using ExtJS Window and HTML5 Web SQL Database</title>
		<link>http://superdit.com/2010/09/30/sticky-notes-using-extjs-window-and-html5-web-sql-database/</link>
		<comments>http://superdit.com/2010/09/30/sticky-notes-using-extjs-window-and-html5-web-sql-database/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 02:59:49 +0000</pubDate>
		<dc:creator>aditia rahman</dc:creator>
				<category><![CDATA[Extjs]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://superdit.com/?p=2759</guid>
		<description><![CDATA[In this post I want to share how to creating very simple sticky notes application using HTML 5 Web SQL Database and ExtJS Windows, this post is continuation from my previous post about creating dynamic window in extjs, since this post using HTML 5 Web SQL Database, this code for now only working on Google<a href="http://superdit.com/2010/09/30/sticky-notes-using-extjs-window-and-html5-web-sql-database/" class="read-more">Continue Reading</a>]]></description>
			<content:encoded><![CDATA[<p>In this post I want to share how to creating very simple sticky notes application using HTML 5 Web SQL Database and ExtJS Windows, this post is continuation from my previous post about creating <a title="Dynamic Window in ExtJS" href="http://superdit.com/2010/09/11/dynamic-window-in-extjs/" target="_blank">dynamic window in extjs</a>, since this post using HTML 5 Web SQL Database, this code for now only working on <strong>Google Chrome</strong>, <strong>Apple Safari</strong> and <strong>Opera</strong>. The feature that I will create in this post are basic insert, update, delete feature.</p>
<p>All the sql operation written in javascript code, first initializing database</p>
<pre class="brush: jscript; title: ; notranslate">
var db = openDatabase('mydb', '1.0', 'my first database',
            2 * 1024 * 1024);

db.transaction(function (tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS ' +
      'notes (id INTEGER PRIMARY KEY, notes text, '+
      'x INTERGER, y INTEGER)');
});
</pre>
<p><span id="more-2759"></span></p>
<p>The database name is &#8220;mydb&#8221; and create table &#8220;notes&#8221;, the &#8220;x&#8221; and &#8220;y&#8221; table fields is for storing the last window component position from each notes. The next code below is to saving the new notes or updating existing notes.</p>
<pre class="brush: jscript; title: ; notranslate">
function save(obj, x, y) {
    var notesid = obj.replace(&quot;notes&quot;, &quot;&quot;);
    var notesval = document.getElementById(obj).value;
    db.transaction(function (tx) {
        tx.executeSql('SELECT * FROM notes WHERE id = ?', [notesid],
        function (tx, results) {
            if (results.rows.length == 1) {
                // do update
                db.transaction(function (tx) {
                    tx.executeSql('UPDATE notes SET notes = ? ' +
                        'WHERE id = ?', [notesval, notesid]);
                });
            } else {
                // insert new row
                db.transaction(function (tx) {
                    tx.executeSql('INSERT INTO ' +
                        'notes(id, notes, x, y) VALUES (?,?,?,?)',
                        [notesid, notesval, x, y]);
                });
                document.getElementById(obj).style.backgroundColor  = '#FFCC00';
                document.getElementById(obj).style.color  = '#333';
            }
        });
    });
}
</pre>
<p>This function is will be applied on textarea inside the window component and triggered with &#8220;onchange&#8221; event, it will check the existing notes id if exist, it will updating the note, otherwise insert new note and changing the textarea stlye and here is the code for the extjs window</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.onReady(function(){
    var win = new Array();
    var button = Ext.get('show-windows');
    var counter = 1;

    function createWindow(notes, x, y) {
        if (typeof(notes) == 'object') {
            // setting new notes config, default text and position
            notes = 'Write new notes here ... ';
            x = 50 + (15 * Math.floor(Math.random()*11));
            y = 50 + (15 * Math.floor(Math.random()*11));
            cssnotes = 'txareanew';
        } else {
            cssnotes = 'txarea';
        }
        win[counter] = new Ext.Window({
            id: 'win' + counter,
            resizable: false,
            html: '&lt;textarea class=&quot;'+cssnotes+'&quot; maxlength=&quot;100&quot; ' +
                    'onchange=&quot;save(this.id, '+x+', '+y+')&quot; ' +
                    'id=&quot;notes'+counter+'&quot;&gt;' + notes + '&lt;/textarea&gt;',
            pageX: x,
            pageY: y,
            width: 300,
            closable: false,
            height: 290,
            plain: false,
            border: false,
            listeners: {
                'move': function() {
                    wid = this.id.replace(&quot;win&quot;, &quot;&quot;);
                    winx = this.x;
                    winy = this.y;
                    db.transaction(function (tx) {
                        tx.executeSql('UPDATE notes ' +
                            'SET x = ?, y = ? WHERE id = ?',
                            [winx, winy, wid]);
                    });
                }
            },
            buttons: [{
                id: 'delbtn' + counter,
                text: 'Delete',
                handler: function() {
                    nid = this.id.replace('delbtn', '');
                    db.transaction(function (tx) {
                        tx.executeSql('DELETE FROM notes ' +
                            'WHERE id = ?', [nid]);
                    });
                    win[nid].close();
                }
            }]
        }).show();
        counter = counter + 1;
    }

    // init existing notes
    db.transaction(function (tx) {
        tx.executeSql('SELECT * FROM notes', [], function (tx, results) {
            var len = results.rows.length, i;
            for (i = 1; i &lt;= len; i++) {
                counter = results.rows.item(i-1).id;
                createWindow(
                    results.rows.item(i-1).notes,
                    results.rows.item(i-1).x,
                    results.rows.item(i-1).y
                );
            }
        });
    });

    button.on('click', createWindow);
});
</pre>
<p>The first conditional statement in <em>createWindow</em> function is to check whether the window that we will create is for the existing note or for new note, if for new note the window position (x, y) will be generated, otherwise the (x, y) position is fetched from database, and here the additional code (html and css)</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;ext/resources/css/ext-all.css&quot;/&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;ext/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;ext/ext-all.js&quot;&gt;&lt;/script&gt;

    &lt;script type=&quot;text/javascript&quot;&gt;
    // The above javascript code goes here
    &lt;/script&gt;
    &lt;style type=&quot;text/css&quot;&gt;
        p {
            background: #e3e3e3;
            padding: 10px;
        }
        p input {
            width: 120px;
            height: 30px;
        }
        .txarea {
            width:290px; height:300px; background:#FFCC00; padding:5px;
            font-style:italic; border:none; color:#333;
            font-size:28px; font-family:&quot;Times New Roman&quot;;
        }
        .txareanew {
            width:290px; height:300px; background:#e3e3e3; padding:5px;
            font-style:italic; border:none; color:#999;
            font-size:28px; font-family:&quot;Times New Roman&quot;;
        }
    &lt;/style&gt;
    &lt;title&gt;Extjs Dynamic Windows&lt;/title&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;p&gt;
      &lt;input type=&quot;button&quot; id=&quot;show-windows&quot; value=&quot;Create New Note&quot;/&gt;
    &lt;/p&gt;
    &lt;div id=&quot;container&quot;&gt;&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>That&#8217;s all I can do for now you can see the screenshot, live demo and download all the source following the link below</p>
<p style="text-align: center;"><img class="size-full wp-image-2874 alignnone" title="sticky notes using extjs html5 web sql database screenshot" src="http://superdit.com/wp-content/uploads/2010/09/ext-sticky-notes.png" alt="sticky notes using extjs html5 web sql database screenshot" width="500" height="481" /></p>
<p style="text-align: center;"><a title="ExtJS HTML 5 Sticky Notes Source Code" href="http://www.box.net/shared/oxfkjqn2ok" target="_blank">Download Source</a> | <a title="ExtJS HTML 5 Sticky Notes Demo" href="http://demo.superdit.com/ext_html5_sticky_notes/" target="_blank">View Demo</a></p>
<p style="text-align: center;"><em>note: only working on <strong>Google Chrome</strong>, <strong>Apple Safari</strong> and <strong>Opera</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://superdit.com/2010/09/30/sticky-notes-using-extjs-window-and-html5-web-sql-database/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple Checkbox ListView Using DataView In ExtJS</title>
		<link>http://superdit.com/2010/09/20/simple-checkbox-listview-using-dataview-in-extjs/</link>
		<comments>http://superdit.com/2010/09/20/simple-checkbox-listview-using-dataview-in-extjs/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 14:29:35 +0000</pubDate>
		<dc:creator>aditia rahman</dc:creator>
				<category><![CDATA[Extjs]]></category>
		<category><![CDATA[dataview]]></category>
		<category><![CDATA[listview]]></category>

		<guid isPermaLink="false">http://superdit.com/?p=2829</guid>
		<description><![CDATA[In this post I want to share how to create listview using dataview in ExtJS, although there is available listview example on the official site, somewhat maybe you to make the different listview, I get the idea when my friend Erwin Draft asking me how to do this, thanks for the idea. Here the backend<a href="http://superdit.com/2010/09/20/simple-checkbox-listview-using-dataview-in-extjs/" class="read-more">Continue Reading</a>]]></description>
			<content:encoded><![CDATA[<p>In this post I want to share how to create listview using dataview in ExtJS, although there is available <a title="ExtJS List View Example" href="http://dev.sencha.com/deploy/dev/examples/view/list-view.html" target="_blank">listview example</a> on the official site, somewhat maybe you to make the different listview, I get the idea when my friend <a title="Erwindraft" href="http://erwindraft.com/" target="_blank">Erwin Draft</a> asking me how to do this, thanks for the idea.</p>
<p>Here the backend PHP code, I called <strong>get-data.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

$data = array();

for ($i = 1; $i &lt;= 10; $i++) {
    $data[] = array(
        'id' =&gt; $i,
        'message' =&gt; 'Raw data number ' . $i
    );
}

$o = array('data' =&gt; $data);

echo json_encode($o);

?&gt;
</pre>
<p><span id="more-2829"></span></p>
<p>The backend PHP is to getting server data, I just declaring simple data, you can change it whatever you like.</p>
<p>ExtJS Javascript code is inside the html file, my file named <strong>index.html</strong></p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;

function oncheck(str) {
    if (Ext.fly('box' + str).hasClass('checked')) {
        Ext.fly('box' + str).removeClass('checked');
        document.getElementById('check'+str).checked = false;
    } else {
        Ext.fly('box' + str).addClass('checked');
        document.getElementById('check'+str).checked = true;
    }
}

Ext.onReady(function(){
    var proxyData = new Ext.data.HttpProxy({
        url: 'get-data.php'
    });

    var strData = new Ext.data.JsonStore({
        proxy: proxyData,
        root: 'data',
        fields: [
            'id', 'message'
        ]
    });

    var tplData = new Ext.XTemplate(
        '&lt;tpl for=&quot;.&quot;&gt;',
            '&lt;div class=&quot;databox&quot; id=&quot;box{id}&quot; onclick=&quot;oncheck({id})&quot;&gt;',
            '&lt;input type=&quot;checkbox&quot; id=&quot;check{id}&quot; value=&quot;c{id}&quot;&gt; ',
            '&amp;nbsp;{message}&lt;/div&gt;',
        '&lt;/tpl&gt;',
        '&lt;div class=&quot;x-clear&quot;&gt;&lt;/div&gt;'
    );

    var dataV = new Ext.DataView({
        autoScroll: true, store: strData, tpl: tplData,
        autoHeight: false, height: 265,
        multiSelect: true, itemSelector: 'div.thumb-wrap',
        emptyText: 'No data to display',
        loadingText: 'Please Wait...',
        style: 'border:1px solid #99BBE8;background:#fff;'
    });

    function checkvalue() {
        var obj = Ext.select('input[type=checkbox]').elements;
        var i = 0;
        var cb = '';
        var total = 0;
        for (i=0; i&lt;obj.length; i++) {
            if (obj[i].checked) {
               cb = cb + ' ' + obj[i].value;
               total++;
            }
        }
        Ext.MessageBox.alert('Checked', 'You clicked ' + total + ' checkbox, they value are ' + cb);
    }

    var panel = new Ext.Panel({
        title: 'List Data View', frame: true, width: 400,
        height: 340, id: 'panelBottom', style: 'margin: 0 auto;',
        renderTo: 'bottom', items: [dataV],
        buttons: [{
            text: 'Get Checked',
            handler: checkvalue
        }]
    });

    strData.load();
});
&lt;/script&gt;
</pre>
<p>As you can see on the code above the script is to showing dataview inside panel component, dataview render the template declaration that defined in XTemplate component, every rendered data have its own unique id, see code below (a part of ExtJS code above)</p>
<pre class="brush: jscript; title: ; notranslate">
var tplData = new Ext.XTemplate(
    '&lt;tpl for=&quot;.&quot;&gt;',
        '&lt;div class=&quot;databox&quot; id=&quot;box{id}&quot; onclick=&quot;oncheck({id})&quot;&gt;',
        '&lt;input type=&quot;checkbox&quot; id=&quot;check{id}&quot; value=&quot;c{id}&quot;&gt; ',
        '&amp;nbsp;{message}&lt;/div&gt;',
    '&lt;/tpl&gt;',
    '&lt;div class=&quot;x-clear&quot;&gt;&lt;/div&gt;'
);
</pre>
<p>Every time the users click on the div (which have css class &#8220;databox&#8221;) the checkbox will be checked or unchecked and the div style changing, I&#8217;m using the Ext.fly function inside <em>oncheck(str) </em>function to do this, the<em> oncheck(str) </em>function must be placed outside the Ext.onReady(function()) otherwise it will not work, I still don&#8217;t know why this is happen.</p>
<p>And the last is to get checked value, I achieve this by putting handler inside a button, this is another part of the ExtJS code above</p>
<pre class="brush: jscript; title: ; notranslate">
function checkvalue() {
    var obj = Ext.select('input[type=checkbox]').elements;
    var i = 0;
    var cb = '';
    var total = 0;
    for (i=0; i&lt;obj.length; i++) {
        if (obj[i].checked) {
           cb = cb + ' ' + obj[i].value;
           total++;
        }
    }
    Ext.MessageBox.alert('Checked', 'You clicked ' + total + ' checkbox, they value are ' + cb);
}
</pre>
<p>What I do this is selecting all the checkbox elements in HTML an looping through all the detected checbox and getting the value to showed is ExtJS MessageBox. Yup that all, as usual you can see the example screenshot below, download all the code and see the online example.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-2848" src="http://superdit.com/wp-content/uploads/2010/09/localhost_ext_list_view.png" alt="" width="447" height="371" /></p>
<p style="text-align: center;"><a title="ExtJS ListView using DataView Demo" href="http://demo.superdit.com/ext_listview_dataview/" target="_blank">View Demo</a> | <a title="ExtJS ListView using DataView Source" href="http://www.box.net/shared/faca6730e6" target="_blank">Download Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://superdit.com/2010/09/20/simple-checkbox-listview-using-dataview-in-extjs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

