<?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>GustavoHenrique.net &#187; extjs</title>
	<atom:link href="http://blog.gustavohenrique.net/category/extjs/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gustavohenrique.net</link>
	<description>Tecnologia e Software Livre</description>
	<lastBuildDate>Mon, 05 Mar 2012 10:50:09 +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>Introdução ao padrão MVC no Ext JS 4</title>
		<link>http://blog.gustavohenrique.net/2012/02/introducao-ao-padrao-mvc-no-ext-js-4/</link>
		<comments>http://blog.gustavohenrique.net/2012/02/introducao-ao-padrao-mvc-no-ext-js-4/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 11:17:47 +0000</pubDate>
		<dc:creator>gustavohenrique</dc:creator>
				<category><![CDATA[extjs]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://blog.gustavohenrique.net/?p=448</guid>
		<description><![CDATA[Ext JS 4 trouxe uma nova maneira de construir interfaces ricas com a introdução do padrão MVC. Ao permtir a separação das regras de negócios e componentes visuais é obtido um código mais limpo e fácil de dar manuntenção. A arquitetura do padrão MVC usado pelo extjs4 é definido da seguinte maneira: Model: é uma [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.gustavohenrique.net/2012/02/introducao-ao-padrao-mvc-no-ext-js-4/extjs-logo/" rel="attachment wp-att-449"><img src="http://blog.gustavohenrique.net/wp-content/uploads/2012/02/extjs-logo.jpg" alt="ext js logo" title="ext js logo" width="150" height="95" class="aligncenter size-full wp-image-449" /></a></p>
<p>Ext JS 4 trouxe uma nova maneira de construir interfaces ricas com a introdução do padrão MVC. Ao permtir a separação das regras de negócios e componentes visuais é obtido um código mais limpo e fácil de dar manuntenção.<br />
<span id="more-448"></span></p>
<p>A arquitetura do padrão MVC usado pelo extjs4 é definido da seguinte maneira:</p>
<ul>
<li><b>Model:</b> é uma classe que representa uma tabela do banco de dados.</li>
<li><b>View:</b> é um componente visual como por exemplo datagrid, combobox, panel&#8230;</li>
<li><b>Controller:</b> é onde fica o código que faz a aplicação funcionar. Serve como uma ponte entre o Model e a View, possui regras de negócio e renderiza componentes.</li>
</ul>
<p>ExtJS utiliza convenções para facilitar a vida do desenvolvedor.</p>
<p>Estrutura de arquivos:<br />
Um diretório <code>app</code> para cada projeto e dentro dele os diretórios <code>model</code>, <code>controller</code>, <code>view</code> e <code>store</code>. O arquivo <code>app.js</code> no mesmo nível do diretório <code>app</code>.<br />
Dentro do diretório <code>view</code> deve ser criado um subdiretório com o nome de cada controller que renderiza alguma view.</p>
<p>Nomes de arquivos:</p>
<ul>
<li><b>Models:</b> CamelCase no singular.</li>
<li><b>View:</b> um subdiretório com o nome do controller em minúsculo e dentro CamelCase para o nome do componente.</li>
<li><b>Controllers:</b> CamelCase no plural.</li>
<li><b>Stores:</b> CamelCase no plural.</li>
</ul>
<p>Como exemplo, vou mostrar como criar um projeto usando a estrutura abaixo:<br />
<a href="http://blog.gustavohenrique.net/2012/02/introducao-ao-padrao-mvc-no-ext-js-4/extjs4-tree/" rel="attachment wp-att-450"><img src="http://blog.gustavohenrique.net/wp-content/uploads/2012/02/extjs4-tree.jpg" alt="extjs4-mvc-tutorial tree" title="extjs4-mvc-tutorial tree" width="208" height="457" class="aligncenter size-full wp-image-450" /></a></p>
<p>Primeiramente instale um servidor web tal como Apache ou Nginx. A configuração padrão já é suficiente para o propósito desse artigo. Faça o download da versão gratuita do ExtJS 4 em <a href="http://www.sencha.com/products/extjs/download?page=a" title="Download ExtJS4">http://www.sencha.com/products/extjs/download?page=a</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ mkdir -p /var/www/html/extjs4-mvc-tutorial/js
$ cd /var/www/html/extjs4-mvc-tutorial/js
$ wget http://cdn.sencha.io/ext-4.0.7-gpl.zip
$ unzip ext-4.0.7-gpl.zip
$ mkdir -p app/model
$ mkdir -p app/controller
$ mkdir -p app/view/contatos
$ mkdir -p app/store</pre></div></div>

<p>Crie o arquivo <code>/var/www/html/extjs4-mvc-tutorial/index.html</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;/&gt;
  &lt;title&gt;Ext JS 4 MVC Tutorial&lt;/title&gt;
  &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;js/ext-4.0.7-gpl/resources/css/ext-all-gray.css&quot; /&gt;
  &lt; type=&quot;text/java&quot; src=&quot;js/ext-4.0.7-gpl/ext-all-debug.js&quot;&gt;&lt;/&gt;
  &lt; type=&quot;text/java&quot; src=&quot;js/app.js&quot;&gt;&lt;/&gt;
&lt;/head&gt;
&lt;body&gt;&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Agora o arquivo <code>/var/www/html/extjs4-mvc-tutorial/js/app.js</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Ext.<span style="color: #006633;">Loader</span>.<span style="color: #006633;">setConfig</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>enabled<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Ext.<span style="color: #006633;">application</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    name<span style="color: #339933;">:</span> <span style="color: #0000ff;">'extjs4-mvc-tutorial'</span>,
    appFolder<span style="color: #339933;">:</span> <span style="color: #0000ff;">'/extjs4-mvc-tutorial/js/app'</span>,
    autoCreateViewport<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>,
&nbsp;
    controllers<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Contatos'</span>,<span style="color: #009900;">&#93;</span>,
&nbsp;
    launch<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        viewport <span style="color: #339933;">=</span> Ext.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Ext.container.Viewport'</span>, <span style="color: #009900;">&#123;</span>
            id<span style="color: #339933;">:</span> <span style="color: #0000ff;">'viewport'</span>,
            layout<span style="color: #339933;">:</span> <span style="color: #0000ff;">'border'</span>,
            items<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>
                region<span style="color: #339933;">:</span> <span style="color: #0000ff;">'center'</span>,
                border<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>,
                autoScroll<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>,
                items<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>
                    xtype<span style="color: #339933;">:</span> <span style="color: #0000ff;">'contatosGrid'</span>,
                    store<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Contatos'</span>,
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</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><code>app.js</code> cria a aplicação extjs4-mvc-tutorial e define o caminho da <code>appFolder</code>. <code>autoCreateViewport: false</code> permite que eu crie uma viewport assim que a aplicação for criada.<br />
A linha <code>Ext.Loader.setConfig({enabled:true})</code> é necessária para o carregamento dinâmico das dependências do projeto.<br />
Adicionei um controller na aplicação. Devido a convenção utilizada, extjs sabe exatamente onde onde procurar essa classe controller dentro do appFolder. Ao carregar o controller dinamicante, suas dependências também são carregadas, como por exemplo o store <code>Contatos</code> e a view <code>contatosGrid</code>.</p>
<p>Crie o model <code>/var/www/html/extjs4-mvc-tutorial/js/app/model/Pessoa.js</code></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Ext.<span style="color: #006633;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'extjs4-mvc-tutorial.model.Pessoa'</span>, <span style="color: #009900;">&#123;</span>
    extend<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Ext.data.Model'</span>,
    fields<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span>, <span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span>,
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Um model extende de Ext.data.Model e automaticamente ganha os métodos set() e get(). Na versão 4 é possível inserir um Proxy dentro do Model e com isso obtém um funcionamento semelhante ao padrão <a href="http://pt.wikipedia.org/wiki/Active_record" title="Link active record wikipedia">Active Record</a>.</p>
<p>Crie também a store <code>/var/www/html/extjs4-mvc-tutorial/js/app/store/Contatos.js</code></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Ext.<span style="color: #006633;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'extjs4-mvc-tutorial.store.Contatos'</span>, <span style="color: #009900;">&#123;</span>
    extend<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Ext.data.Store'</span>,
&nbsp;
    model<span style="color: #339933;">:</span> <span style="color: #0000ff;">'extjs4-mvc-tutorial.model.Pessoa'</span>,
    autoLoad<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>,
    autoSync<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>,
    pageSize<span style="color: #339933;">:</span> <span style="color: #cc66cc;">30</span>,
&nbsp;
    proxy<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        type<span style="color: #339933;">:</span> <span style="color: #0000ff;">'rest'</span>,
&nbsp;
        api<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            read<span style="color: #339933;">:</span> <span style="color: #0000ff;">'/extjs4-mvc-tutorial/contatos/read'</span>,
            create<span style="color: #339933;">:</span> <span style="color: #0000ff;">'/extjs4-mvc-tutorial/contatos/create'</span>,
            update<span style="color: #339933;">:</span> <span style="color: #0000ff;">'/extjs4-mvc-tutorial/contatos/update'</span>,
            destroy<span style="color: #339933;">:</span> <span style="color: #0000ff;">'/extjs4-mvc-tutorial/contatos/delete'</span>
        <span style="color: #009900;">&#125;</span>,
&nbsp;
        reader<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            type<span style="color: #339933;">:</span> <span style="color: #0000ff;">'json'</span>,
            root<span style="color: #339933;">:</span> <span style="color: #0000ff;">'data'</span>,
            successProperty<span style="color: #339933;">:</span> <span style="color: #0000ff;">'success'</span>,
            totalProperty<span style="color: #339933;">:</span> <span style="color: #0000ff;">'total'</span>
        <span style="color: #009900;">&#125;</span>,
&nbsp;
        writer<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            type<span style="color: #339933;">:</span> <span style="color: #0000ff;">'json'</span>,
            root<span style="color: #339933;">:</span> <span style="color: #0000ff;">'data'</span>,
        <span style="color: #009900;">&#125;</span>,
&nbsp;
        listeners<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            exception<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>proxy, response, operation<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                var message <span style="color: #339933;">=</span> Ext.<span style="color: #006633;">JSON</span>.<span style="color: #006633;">decode</span><span style="color: #009900;">&#40;</span>response.<span style="color: #006633;">responseText</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">message</span><span style="color: #339933;">;</span>
                Ext.<span style="color: #006633;">Msg</span>.<span style="color: #006633;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Ocorreu um erro'</span>, message<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;">&#125;</span>,
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Crie a view <code>/var/www/html/extjs4-mvc-tutorial/js/app/view/contatos/Grid.js</code></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Ext.<span style="color: #006633;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'extjs4-mvc-tutorial.view.contatos.Grid'</span>, <span style="color: #009900;">&#123;</span>
    extend<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Ext.grid.Panel'</span>,
    alias<span style="color: #339933;">:</span> <span style="color: #0000ff;">'widget.contatosGrid'</span>,
&nbsp;
    plugins<span style="color: #339933;">:</span> Ext.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Ext.grid.plugin.CellEditing'</span><span style="color: #009900;">&#41;</span>,
&nbsp;
    columns<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>
        xtype<span style="color: #339933;">:</span> <span style="color: #0000ff;">'rownumberer'</span>,
        width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">30</span>,
    <span style="color: #009900;">&#125;</span>, <span style="color: #009900;">&#123;</span>
        text<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Nome'</span>,
        sortable<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>,
        dataIndex<span style="color: #339933;">:</span> <span style="color: #0000ff;">'nome'</span>,
        field<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            xtype<span style="color: #339933;">:</span> <span style="color: #0000ff;">'textfield'</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>, <span style="color: #009900;">&#123;</span>
        text<span style="color: #339933;">:</span> <span style="color: #0000ff;">'E-mail'</span>,
        flex<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span>,
        sortable<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>,
        dataIndex<span style="color: #339933;">:</span> <span style="color: #0000ff;">'email'</span>,
        width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">120</span>,
        field<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            xtype<span style="color: #339933;">:</span> <span style="color: #0000ff;">'textfield'</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>,
&nbsp;
    initComponent<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">dockedItems</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>
            xtype<span style="color: #339933;">:</span> <span style="color: #0000ff;">'toolbar'</span>,
            items<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>
                text<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Adicionar'</span>,
                action<span style="color: #339933;">:</span> <span style="color: #0000ff;">'adicionar'</span>
            <span style="color: #009900;">&#125;</span>, <span style="color: #009900;">&#123;</span>
                text<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Deletar'</span>,
                action<span style="color: #339933;">:</span> <span style="color: #0000ff;">'deletar'</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
        <span style="color: #009900;">&#125;</span>, <span style="color: #009900;">&#123;</span>
            store<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getStore</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
            displayInfo<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>,
            xtype<span style="color: #339933;">:</span> <span style="color: #0000ff;">'pagingtoolbar'</span>,
            dock<span style="color: #339933;">:</span> <span style="color: #0000ff;">'bottom'</span>,
            beforePageText <span style="color: #339933;">:</span> <span style="color: #0000ff;">'Pagina '</span>,
            displayMsg<span style="color: #339933;">:</span> <span style="color: #0000ff;">'{0} - {1} de {2}'</span>,
            emptyMsg<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Nada para ser exibido'</span>,
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">callParent</span><span style="color: #009900;">&#40;</span>arguments<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>A linha <code>plugins: Ext.create('Ext.grid.plugin.CellEditing')</code> adiciona o plugin para editar células no grid.</p>
<p>Por fim, crie o controller <code>/var/www/html/extjs4-mvc-tutorial/js/app/controller/Contatos.js</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Ext.<span style="color: #006633;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'extjs4-mvc-tutorial.controller.Contatos'</span>, <span style="color: #009900;">&#123;</span>
    extend<span style="color: #339933;">:</span> <span style="color: #0000ff;">'Ext.app.Controller'</span>,
&nbsp;
    models<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Pessoa'</span><span style="color: #009900;">&#93;</span>,
    stores<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Contatos'</span><span style="color: #009900;">&#93;</span>,
    views <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'contatos.Grid'</span>,<span style="color: #009900;">&#93;</span>,
&nbsp;
    init<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">control</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #0000ff;">'contatosGrid button[action=adicionar]'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>click<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">adicionar</span><span style="color: #009900;">&#125;</span>,
            <span style="color: #0000ff;">'contatosGrid button[action=deletar]'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>click<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">deletar</span><span style="color: #009900;">&#125;</span>,
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>,
&nbsp;
    adicionar<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>button<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        button.<span style="color: #006633;">up</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'grid'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStore</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Pessoa'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>,
&nbsp;
    deletar<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>button<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        var grid <span style="color: #339933;">=</span> button.<span style="color: #006633;">up</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'grid'</span><span style="color: #009900;">&#41;</span>,
            store <span style="color: #339933;">=</span> grid.<span style="color: #006633;">getStore</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
            record <span style="color: #339933;">=</span> grid.<span style="color: #006633;">getSelectionModel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSelection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>record<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>confirm<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tem certeza?'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                store.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>record<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;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>O controller contém a lógica da aplicação, isolando o model e a view.<br />
Para testar esse exemplo, crie o arquivo <code>/var/www/html/extjs4-mvc-tutorial/contatos/read</code> contendo:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">$ vim <span style="color: #339933;">/</span>var<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>html<span style="color: #339933;">/</span>extjs4<span style="color: #339933;">-</span>mvc<span style="color: #339933;">-</span>tutorial<span style="color: #339933;">/</span>contatos<span style="color: #339933;">/</span>read
<span style="color: #009900;">&#123;</span> success<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>, total<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span>, data<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">:</span> <span style="color: #cc66cc;">1</span>, <span style="color: #0000ff;">'nome'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'Gustavo'</span>, <span style="color: #0000ff;">'email'</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">'eu@gustavohenrique.net'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ao carregar a aplicação será exibido no grid o conteúdo do arquivo acima.</p>
<p>Como não foi utilizada nenhuma linguagem de backend, ao tentar cadastrar, deletar ou atualizar um registro no grid ocasionará um erro 404. Mas se testar no firefox ou chrome usando o firebug vai perceber que são enviados requests do tipo POST, DELETE e PUT, afinal o proxy na store foi configurado para trabalhar como REST.</p>
<h2>Links</h2>
<p><a href="http://docs.sencha.com/ext-js/4-0/" title="Documentacao oficial">http://docs.sencha.com/ext-js/4-0/</a><br />
<a href="http://www.sencha.com/learn/architecting-your-app-in-ext-js-4-part-1" title="Architecting your app in extjs4">http://www.sencha.com/learn/architecting-your-app-in-ext-js-4-part-1</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gustavohenrique.net/2012/02/introducao-ao-padrao-mvc-no-ext-js-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Apresentando a ExtJS</title>
		<link>http://blog.gustavohenrique.net/2009/12/apresentando-a-extjs/</link>
		<comments>http://blog.gustavohenrique.net/2009/12/apresentando-a-extjs/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 13:08:06 +0000</pubDate>
		<dc:creator>gustavohenrique</dc:creator>
				<category><![CDATA[extjs]]></category>

		<guid isPermaLink="false">http://www.gustavohenrique.net/brogui/?p=145</guid>
		<description><![CDATA[ExtJS é uma biblioteca Javascript para criar aplicações ricas para internet (Rich Internet Application). Com ela é possível construir interfaces gráficas com aparência de uma aplicação para desktop. Suas principais características são: Alta performance e possibilidade de customizar componentes Bem desenhada, documentada e as classes dos componentes são extensíveis Possui uma versão Open Source Pode [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_149" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/extjs.jpg"><img class="size-medium wp-image-149 " title="Layout com Viewports" src="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/extjs-300x170.jpg" alt="layout usando componentes da ExtJS" width="300" height="170" /></a><p class="wp-caption-text">layout usando componentes da ExtJS</p></div>
<p>ExtJS é uma biblioteca Javascript para criar aplicações ricas para internet (Rich Internet Application). Com ela é possível construir interfaces gráficas com aparência de uma aplicação para desktop. Suas principais características são:</p>
<ul>
<li>Alta performance e possibilidade de customizar componentes</li>
<li>Bem desenhada, documentada e as classes dos componentes são<br />
extensíveis</li>
<li>Possui uma versão Open Source</li>
<li>Pode trabalhar em conjunto com outras bibliotecas como JQuery,<br />
Mootools, Protoype&#8230;</li>
<li>Fácil de usar</li>
<li>Integração entre cada um dos seus componentes</li>
</ul>
<p><span id="more-145"></span></p>
<h2>Exemplos de Componentes</h2>
<p></p>
<h3>Grid</h3>
<p>Um Grid é uma ótima maneira de apresentar uma listagem de dados. A ExtJS provê avançados recursos para construção de grids, como células editáveis, agrupamento de dados, paginação de resultado, barra de ferramentas, utilização de imagens, ordenação por campo, etc.<br />
<div id="attachment_153" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/grid.jpg"><img src="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/grid-300x150.jpg" alt="Grid simples" title="GridPane" width="300" height="150" class="size-medium wp-image-153" /></a><p class="wp-caption-text">Grid simples</p></div></p>
<h3>Window</h3>
<p>É possível criar janelas que podem ser redimensionadas, maximizadas, minimizadas e arrastadas. Também podem ser modais ou não modais. Um janela pode conter outros componentes como grid, tabs, forms, etc.<br />
<div id="attachment_154" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/window.jpg"><img src="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/window-300x178.jpg" alt="Window contendo TabPanel" title="Window" width="300" height="178" class="size-medium wp-image-154" /></a><p class="wp-caption-text">Window contendo TabPanel</p></div></p>
<h3>Form</h3>
<p>Componente para criação de formulários. Cada campo do form pode conter regras de validação que podem ser customizadas. Por padrão, um Form envia os dados no modo ajax (via POST usando o formato JSON).<br />
<div id="attachment_155" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/form.jpg"><img src="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/form-300x178.jpg" alt="Form simples" title="FormPanel" width="300" height="178" class="size-medium wp-image-155" /></a><p class="wp-caption-text">Form simples</p></div></p>
<h3>Tree</h3>
<p>Estrutura em forma de árvore semelhante ao <em>Windows Explorer</em>.<br />
Pode usar imagens como ícones e o recurso de arrastar e soltar para movimentar os elementos.<br />
<div id="attachment_156" class="wp-caption aligncenter" style="width: 260px"><a href="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/tree.jpg"><img src="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/tree-250x300.jpg" alt="TreePanel padrão" title="tree" width="250" height="300" class="size-medium wp-image-156" /></a><p class="wp-caption-text">TreePanel padrão</p></div></p>
<h3>Toolbar e Menu</h3>
<p>Barra de ferramentas e menus também podem ser utilizados dentro de outros elementos, como Window e GridPanel.<br />
<div id="attachment_157" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/menu.jpg"><img src="http://blog.gustavohenrique.net/wp-content/uploads/2009/12/menu-300x149.jpg" alt="Toolbar e MenuBar" title="Toolbar e Menu" width="300" height="149" class="size-medium wp-image-157" /></a><p class="wp-caption-text">Toolbar e MenuBar</p></div></p>
<h2>Conclusão</h2>
<p>A idéia desse texto foi apenas despertar a curiosidade sobre essa incrível biblioteca Javascript. Há muito mais recursos e exemplos que não mencionei, mas que podem ser vistos no <a href="http://www.extjs.com" target="_blank">site</a> do projeto.<br />
Tenho utilizado bastante em projetos de sistemas web em conjunto com o Django e com isso consegui mais agilidade já que não preciso mais me preocupar com assuntos referentes ao design, como cores e tipografia.</p>
<p>Sites relacionados:</p>
<ul>
<li><a href="http://www.extjs.com" target="_blank">ExtJS</a></li>
<li><a href="http://www.extjs.com/deploy/dev/examples/samples.html" target="_blank">Exemplos e     Demonstrações</a></li>
<li><a href="http://extjs.com.br/forum" target="_blank">Fórum Brasileiro</a></li>
<li><a href="http://www.extdesenv.com.br" target="_blank">Ext Desenv</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.gustavohenrique.net/2009/12/apresentando-a-extjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

