]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.require([\r |
2 | 'Ext.grid.*',\r | |
3 | 'Ext.data.*',\r | |
4 | 'Ext.util.*',\r | |
5 | 'Ext.ux.form.SearchField'\r | |
6 | ]);\r | |
7 | \r | |
8 | Ext.onReady(function(){\r | |
9 | Ext.define('ForumThread', {\r | |
10 | extend: 'Ext.data.Model',\r | |
11 | fields: [{\r | |
12 | name: 'title',\r | |
13 | mapping: 'topic_title'\r | |
14 | }, {\r | |
15 | name: 'forumtitle',\r | |
16 | mapping: 'forum_title'\r | |
17 | }, {\r | |
18 | name: 'forumid',\r | |
19 | type: 'int'\r | |
20 | }, {\r | |
21 | name: 'username',\r | |
22 | mapping: 'author'\r | |
23 | }, {\r | |
24 | name: 'replycount', \r | |
25 | mapping: 'reply_count',\r | |
26 | type: 'int'\r | |
27 | }, {\r | |
28 | name: 'lastpost', \r | |
29 | mapping: 'post_time', \r | |
30 | type: 'date', \r | |
31 | dateFormat: 'timestamp'\r | |
32 | },\r | |
33 | 'lastposter', 'excerpt', 'topic_id'\r | |
34 | ],\r | |
35 | idProperty: 'post_id'\r | |
36 | });\r | |
37 | \r | |
38 | // create the Data Store\r | |
39 | var store = Ext.create('Ext.data.BufferedStore', {\r | |
40 | id: 'store',\r | |
41 | model: 'ForumThread',\r | |
42 | \r | |
43 | // The topics-remote.php script appears to be hardcoded to use 50, and ignores this parameter, so we\r | |
44 | // are forced to use 50 here instead of a possibly more efficient value.\r | |
45 | pageSize: 50,\r | |
46 | \r | |
47 | // This web service seems slow, so keep lots of data in the pipeline ahead!\r | |
48 | leadingBufferZone: 1000,\r | |
49 | proxy: {\r | |
50 | // load using script tags for cross domain, if the data in on the same domain as\r | |
51 | // this page, an HttpProxy would be better\r | |
52 | type: 'jsonp',\r | |
53 | url: 'http://www.sencha.com/forum/topics-remote.php',\r | |
54 | reader: {\r | |
55 | rootProperty: 'topics',\r | |
56 | totalProperty: 'totalCount'\r | |
57 | },\r | |
58 | // sends single sort as multi parameter\r | |
59 | simpleSortMode: true,\r | |
60 | \r | |
61 | // Parameter name to send filtering information in\r | |
62 | filterParam: 'query'\r | |
63 | },\r | |
64 | listeners: {\r | |
65 | totalcountchange: onStoreSizeChange\r | |
66 | },\r | |
67 | remoteFilter: true,\r | |
68 | autoLoad: true\r | |
69 | });\r | |
70 | \r | |
71 | function onStoreSizeChange() {\r | |
72 | grid.down('#status').update({count: store.getTotalCount()});\r | |
73 | }\r | |
74 | \r | |
75 | function renderTopic(value, p, record) {\r | |
76 | return Ext.String.format(\r | |
77 | '<a href="http://sencha.com/forum/showthread.php?p={1}" target="_blank">{0}</a>',\r | |
78 | value,\r | |
79 | record.getId()\r | |
80 | );\r | |
81 | }\r | |
82 | \r | |
83 | var grid = Ext.create('Ext.grid.Panel', {\r | |
84 | width: 700,\r | |
85 | height: 470,\r | |
86 | collapsible: true,\r | |
87 | title: 'ExtJS.com - Browse Forums',\r | |
88 | store: store,\r | |
89 | loadMask: true,\r | |
90 | dockedItems: [{\r | |
91 | dock: 'top',\r | |
92 | xtype: 'toolbar',\r | |
93 | items: [{\r | |
94 | width: 400,\r | |
95 | fieldLabel: 'Search',\r | |
96 | labelWidth: 50,\r | |
97 | xtype: 'searchfield',\r | |
98 | store: store\r | |
99 | }, '->', {\r | |
100 | xtype: 'component',\r | |
101 | itemId: 'status',\r | |
102 | tpl: 'Matching threads: {count}',\r | |
103 | style: 'margin-right:5px'\r | |
104 | }]\r | |
105 | }],\r | |
106 | selModel: {\r | |
107 | pruneRemoved: false\r | |
108 | },\r | |
109 | multiSelect: true,\r | |
110 | viewConfig: {\r | |
111 | trackOver: false,\r | |
112 | emptyText: '<h1 style="margin:20px">No matching results</h1>'\r | |
113 | },\r | |
114 | // grid columns\r | |
115 | columns:[{\r | |
116 | xtype: 'rownumberer',\r | |
117 | width: 50,\r | |
118 | sortable: false\r | |
119 | },{\r | |
120 | tdCls: 'x-grid-cell-topic',\r | |
121 | text: "Topic",\r | |
122 | dataIndex: 'title',\r | |
123 | flex: 1,\r | |
124 | renderer: renderTopic,\r | |
125 | sortable: false\r | |
126 | },{\r | |
127 | text: "Author",\r | |
128 | dataIndex: 'username',\r | |
129 | width: 100,\r | |
130 | hidden: true,\r | |
131 | sortable: false\r | |
132 | },{\r | |
133 | text: "Replies",\r | |
134 | dataIndex: 'replycount',\r | |
135 | align: 'center',\r | |
136 | width: 70,\r | |
137 | sortable: false\r | |
138 | },{\r | |
139 | id: 'last',\r | |
140 | text: "Last Post",\r | |
141 | dataIndex: 'lastpost',\r | |
142 | width: 130,\r | |
143 | renderer: Ext.util.Format.dateRenderer('n/j/Y g:i A'),\r | |
144 | sortable: false\r | |
145 | }],\r | |
146 | renderTo: Ext.getBody()\r | |
147 | });\r | |
148 | });\r |