2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
11 //////////////////////////////////////////////////////////////////////////////////////////////
\r
12 // The data store for topics
\r
13 Forum.TopicStore = function(){
\r
14 Forum.TopicStore.superclass.constructor.call(this, {
\r
17 proxy: new Ext.data.ScriptTagProxy({
\r
18 url: 'http://extjs.com/forum/topics-browse-remote.php'
\r
21 reader: new Ext.data.JsonReader({
\r
23 totalProperty: 'totalCount',
\r
26 'title', 'forumtitle', 'forumid', 'author',
\r
27 {name: 'replycount', type: 'int'},
\r
28 {name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
\r
29 'lastposter', 'excerpt'
\r
33 this.setDefaultSort('lastpost', 'desc');
\r
35 Ext.extend(Forum.TopicStore, Ext.data.Store, {
\r
36 loadForum : function(forumId){
\r
49 //////////////////////////////////////////////////////////////////////////////////////////////
\r
53 topic : function(value, p, record){
\r
54 return String.format(
\r
55 '<div class="topic"><b>{0}</b><span class="author">{1}</span></div>',
\r
56 value, record.data.author, record.id, record.data.forumid);
\r
59 lastPost : function(value, p, r){
\r
60 return String.format('<span class="post-date">{0}</span><br/>by {1}', value.dateFormat('M j, Y, g:i a'), r.data['lastposter']);
\r
64 //////////////////////////////////////////////////////////////////////////////////////////////
\r
66 Forum.SearchView = function(search){
\r
68 this.preview = new Ext.Panel({
\r
71 title:'View Message',
\r
75 this.store = new Ext.data.Store({
\r
77 proxy: new Ext.data.ScriptTagProxy({
\r
78 url: 'http://extjs.com/forum/topics-remote.php'
\r
80 reader: new Ext.data.JsonReader({
\r
82 totalProperty: 'totalCount',
\r
85 {name: 'postId', mapping: 'post_id'},
\r
86 {name: 'title', mapping: 'topic_title'},
\r
87 {name: 'topicId', mapping: 'topic_id'},
\r
88 {name: 'author', mapping: 'author'},
\r
89 {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
\r
90 {name: 'excerpt', mapping: 'post_text'}
\r
93 this.store.setDefaultSort('lastpost', 'desc');
\r
96 this.grid = new Ext.grid.GridPanel({
\r
101 cm: new Ext.grid.ColumnModel([{
\r
103 header: "Post Title",
\r
104 dataIndex: 'title',
\r
106 renderer: Forum.Renderers.topic
\r
109 header: "Date Posted",
\r
110 dataIndex: 'lastpost',
\r
112 renderer: Ext.util.Format.dateRenderer('M j, Y, g:i a')
\r
115 sm: new Ext.grid.RowSelectionModel({
\r
119 trackMouseOver:false,
\r
121 loadMask: {msg:'Searching...'},
\r
125 enableRowBody:true,
\r
127 getRowClass : function(record, rowIndex, p, ds){
\r
128 if(this.showPreview){
\r
129 p.body = '<p>'+record.data.excerpt+'</p>';
\r
130 return 'x-grid3-row-expanded';
\r
132 return 'x-grid3-row-collapsed';
\r
136 bbar: new Ext.PagingToolbar({
\r
140 displayMsg: 'Displaying results {0} - {1} of {2}',
\r
141 emptyMsg: "No results to display"
\r
145 Forum.SearchView.superclass.constructor.call(this, {
\r
147 title:'Search: '+Ext.util.Format.htmlEncode('"'+search+'"'),
\r
148 items:[ this.grid, this.preview ]
\r
151 this.store.baseParams = {
\r
155 this.store.load({params:{start:0, limit: 25}});
\r
158 Ext.extend(Forum.SearchView, Ext.Panel);
\r
162 Ext.onReady(function(){
\r
164 Ext.QuickTips.init();
\r
166 var ds = new Forum.TopicStore();
\r
168 var cm = new Ext.grid.ColumnModel([{
\r
171 dataIndex: 'title',
\r
173 renderer: Forum.Renderers.topic
\r
176 dataIndex: 'author',
\r
181 dataIndex: 'replycount',
\r
186 header: "Last Post",
\r
187 dataIndex: 'lastpost',
\r
189 renderer: Forum.Renderers.lastPost
\r
192 cm.defaultSortable = true;
\r
194 var viewport = new Ext.Viewport({
\r
197 new Ext.BoxComponent({ // raw
\r
202 new Ext.tree.TreePanel({
\r
212 loader: new Forum.TreeLoader(),
\r
216 root: new Ext.tree.AsyncTreeNode({
\r
231 title:'Loading...',
\r
233 new Ext.grid.GridPanel({
\r
238 sm:new Ext.grid.RowSelectionModel({singleSelect:true}),
\r
239 trackMouseOver:false,
\r
240 loadMask: {msg:'Loading Topics...'},
\r
243 enableRowBody:true,
\r
245 getRowClass : function(record, rowIndex, p, ds){
\r
246 if(this.showPreview){
\r
247 p.body = '<p>'+record.data.excerpt+'</p>';
\r
248 return 'x-grid3-row-expanded';
\r
250 return 'x-grid3-row-collapsed';
\r
256 iconCls: 'new-topic',
\r
257 handler:function(){alert('Not implemented.');}
\r
263 text:'Preview Pane',
\r
264 tooltip: {title:'Preview Pane',text:'Show or hide the Preview Pane'},
\r
265 iconCls: 'preview',
\r
266 toggleHandler: togglePreview
\r
273 tooltip: {title:'Post Summary',text:'View a short summary of each post in the list'},
\r
274 iconCls: 'summary',
\r
275 toggleHandler: toggleDetails
\r
278 bbar: new Ext.PagingToolbar({
\r
282 displayMsg: 'Displaying topics {0} - {1} of {2}',
\r
283 emptyMsg: "No topics to display"
\r
289 title:'View Topic',
\r
298 var tree = Ext.getCmp('forum-tree');
\r
299 tree.on('append', function(tree, p, node){
\r
301 node.select.defer(100, node);
\r
304 var sm = tree.getSelectionModel();
\r
305 sm.on('beforeselect', function(sm, node){
\r
306 return node.isLeaf();
\r
308 sm.on('selectionchange', function(sm, node){
\r
309 ds.loadForum(node.id);
\r
310 Ext.getCmp('main-view').setTitle(node.text);
\r
314 var searchStore = new Ext.data.Store({
\r
315 proxy: new Ext.data.ScriptTagProxy({
\r
316 url: 'http://extjs.com/forum/topics-remote.php'
\r
318 reader: new Ext.data.JsonReader({
\r
320 totalProperty: 'totalCount',
\r
323 {name: 'title', mapping: 'topic_title'},
\r
324 {name: 'topicId', mapping: 'topic_id'},
\r
325 {name: 'author', mapping: 'author'},
\r
326 {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
\r
327 {name: 'excerpt', mapping: 'post_text'}
\r
331 // Custom rendering Template
\r
332 var resultTpl = new Ext.Template(
\r
333 '<div class="search-item">',
\r
334 '<h3><span>{lastPost:date("M j, Y")}<br />by {author}</span>{title}</h3>',
\r
339 var search = new Ext.form.ComboBox({
\r
340 store: searchStore,
\r
341 displayField:'title',
\r
343 loadingText: 'Searching...',
\r
350 emptyText:'Quick Search',
\r
351 onSelect: function(record){ // override default onSelect to do redirect
\r
353 String.format('http://extjs.com/forum/showthread.php?t={0}&p={1}', record.data.topicId, record.id);
\r
356 // apply it to the exsting input element
\r
357 search.applyTo('search');
\r
361 function toggleDetails(btn, pressed){
\r
362 var view = Ext.getCmp('topic-grid').getView();
\r
363 view.showPreview = pressed;
\r
367 function togglePreview(btn, pressed){
\r
368 var preview = Ext.getCmp('preview');
\r
369 preview[pressed ? 'show' : 'hide']();
\r
370 preview.ownerCt.doLayout();
\r
374 Forum.TreeLoader = function(){
\r
375 Forum.TreeLoader.superclass.constructor.call(this);
\r
376 this.proxy = new Ext.data.ScriptTagProxy({
\r
380 Ext.extend(Forum.TreeLoader, Ext.tree.TreeLoader, {
\r
381 dataUrl: 'http://extjs.com/forum/forums-remote.php',
\r
382 requestData : function(node, cb){
\r
383 this.proxy.load({}, {
\r
384 readRecords : function(o){
\r
387 }, this.addNodes, this, {node:node, cb:cb});
\r
390 addNodes : function(o, arg){
\r
391 var node = arg.node;
\r
392 for(var i = 0, len = o.length; i < len; i++){
\r
393 var n = this.createNode(o[i]);
\r
395 node.appendChild(n);
\r
398 arg.cb(this, node);
\r