Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / form / custom-form.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 Ext.Loader.setConfig({enabled: true});
16 Ext.Loader.setPath('Ext.ux', '../ux');
17 Ext.require([
18     'Ext.data.*',
19     'Ext.panel.Panel',
20     'Ext.view.View',
21     'Ext.layout.container.Fit',
22     'Ext.toolbar.Paging',
23     'Ext.ux.form.SearchField'
24 ]);
25
26 Ext.define('Post', {
27     extend: 'Ext.data.Model',
28     idProperty: 'post_id',
29     fields: [
30         {name: 'postId', mapping: 'post_id'},
31         {name: 'title', mapping: 'topic_title'},
32         {name: 'topicId', mapping: 'topic_id'},
33         {name: 'author', mapping: 'author'},
34         {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
35         {name: 'excerpt', mapping: 'post_text'}
36     ]
37 });
38
39 Ext.onReady(function(){
40     
41     var forumId = 4;
42
43     var store = Ext.create('Ext.data.Store', {
44         model: 'Post',
45         proxy: {
46             type: 'jsonp',
47             url: 'http://sencha.com/forum/topics-remote.php',
48             extraParams: {
49                 forumId: forumId
50             },
51             reader: {
52                 type: 'json',
53                 root: 'topics',
54                 totalProperty: 'totalCount'
55             }
56         },
57         listeners: {
58             beforeload: function(){
59                 var params = store.getProxy().extraParams;
60                 if (params.query) {
61                     delete params.forumId;
62                 } else {
63                     params.forumId = forumId;
64                 }
65             }
66         }
67     });
68     store.loadPage(1);
69
70     var resultTpl = Ext.create('Ext.XTemplate',
71         '<tpl for=".">',
72         '<div class="search-item">',
73             '<h3><span>{lastPost:this.formatDate}<br />by {author}</span>',
74             '<a href="http://sencha.com/forum/showthread.php?t={topicId}&p={postId}" target="_blank">{title}</a></h3>',
75             '<p>{excerpt}</p>',
76         '</div></tpl>',
77     {
78         formatDate: function(value){
79             return Ext.Date.format(value, 'M j, Y');
80         }
81     });
82
83     var panel = Ext.create('Ext.panel.Panel', {
84         title: 'Forum Search',
85         height: 300,
86         width: 600,
87         renderTo: 'search-panel',
88         id: 'search-results',
89         layout: 'fit',
90         items: {
91             autoScroll: true,
92             xtype: 'dataview',
93             tpl: resultTpl,
94             store: store,
95             itemSelector: 'div.search-item'
96         },
97         dockedItems: [{
98             dock: 'top',
99             xtype: 'toolbar',
100             items: {
101                 width: 400,
102                 fieldLabel: 'Search',
103                 labelWidth: 50,
104                 xtype: 'searchfield',
105                 store: store
106             }
107         }, {
108             dock: 'bottom',
109             xtype: 'pagingtoolbar',
110             store: store,
111             pageSize: 25,
112             displayInfo: true,
113             displayMsg: 'Topics {0} - {1} of {2}',
114             emptyMsg: 'No topics to display'
115         }]
116     });
117 });
118