3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
9 //////////////////////////////////////////////////////////////////////////////////////////////
10 // The data store for topics
11 Forum.TopicStore = function(){
12 Forum.TopicStore.superclass.constructor.call(this, {
15 proxy: new Ext.data.ScriptTagProxy({
16 url: 'http://extjs.com/forum/topics-browse-remote.php'
19 reader: new Ext.data.JsonReader({
21 totalProperty: 'totalCount',
24 'title', 'forumtitle', 'forumid', 'author',
25 {name: 'replycount', type: 'int'},
26 {name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
27 'lastposter', 'excerpt'
31 this.setDefaultSort('lastpost', 'desc');
33 Ext.extend(Forum.TopicStore, Ext.data.Store, {
34 loadForum : function(forumId){
47 //////////////////////////////////////////////////////////////////////////////////////////////
51 topic : function(value, p, record){
53 '<div class="topic"><b>{0}</b><span class="author">{1}</span></div>',
54 value, record.data.author, record.id, record.data.forumid);
57 lastPost : function(value, p, r){
58 return String.format('<span class="post-date">{0}</span><br/>by {1}', value.dateFormat('M j, Y, g:i a'), r.data['lastposter']);
62 //////////////////////////////////////////////////////////////////////////////////////////////
64 Forum.SearchView = function(search){
66 this.preview = new Ext.Panel({
73 this.store = new Ext.data.Store({
75 proxy: new Ext.data.ScriptTagProxy({
76 url: 'http://extjs.com/forum/topics-browse-remote.php'
78 reader: new Ext.data.JsonReader({
80 totalProperty: 'totalCount',
83 {name: 'postId', mapping: 'post_id'},
84 {name: 'title', mapping: 'topic_title'},
85 {name: 'topicId', mapping: 'topic_id'},
86 {name: 'author', mapping: 'author'},
87 {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
88 {name: 'excerpt', mapping: 'post_text'}
91 this.store.setDefaultSort('lastpost', 'desc');
94 this.grid = new Ext.grid.GridPanel({
99 cm: new Ext.grid.ColumnModel([{
101 header: "Post Title",
104 renderer: Forum.Renderers.topic
107 header: "Date Posted",
108 dataIndex: 'lastpost',
110 renderer: Ext.util.Format.dateRenderer('M j, Y, g:i a')
113 sm: new Ext.grid.RowSelectionModel({
117 trackMouseOver:false,
119 loadMask: {msg:'Searching...'},
125 getRowClass : function(record, rowIndex, p, ds){
126 if(this.showPreview){
127 p.body = '<p>'+record.data.excerpt+'</p>';
128 return 'x-grid3-row-expanded';
130 return 'x-grid3-row-collapsed';
134 bbar: new Ext.PagingToolbar({
138 displayMsg: 'Displaying results {0} - {1} of {2}',
139 emptyMsg: "No results to display"
143 Forum.SearchView.superclass.constructor.call(this, {
145 title:'Search: '+Ext.util.Format.htmlEncode('"'+search+'"'),
146 items:[ this.grid, this.preview ]
149 this.store.baseParams = {
153 this.store.load({params:{start:0, limit: 25}});
156 Ext.extend(Forum.SearchView, Ext.Panel);
160 Ext.onReady(function(){
162 Ext.QuickTips.init();
164 var ds = new Forum.TopicStore();
166 var cm = new Ext.grid.ColumnModel([{
171 renderer: Forum.Renderers.topic
179 dataIndex: 'replycount',
185 dataIndex: 'lastpost',
187 renderer: Forum.Renderers.lastPost
190 cm.defaultSortable = true;
192 var viewport = new Ext.Viewport({
195 new Ext.BoxComponent({ // raw
200 new Ext.tree.TreePanel({
210 loader: new Forum.TreeLoader(),
214 root: new Ext.tree.AsyncTreeNode({
231 new Ext.grid.GridPanel({
236 sm:new Ext.grid.RowSelectionModel({
239 selectionchange: function(sel){
240 var rec = sel.getSelected();
242 Ext.getCmp('preview').body.update('<b><u>' + rec.get('title') + '</u></b><br /><br />Post details here.');
247 trackMouseOver:false,
248 loadMask: {msg:'Loading Topics...'},
253 getRowClass : function(record, rowIndex, p, ds){
254 if(this.showPreview){
255 p.body = '<p>'+record.data.excerpt+'</p>';
256 return 'x-grid3-row-expanded';
258 return 'x-grid3-row-collapsed';
264 iconCls: 'new-topic',
265 handler:function(){alert('Not implemented.');}
272 tooltip: {title:'Preview Pane',text:'Show or hide the Preview Pane'},
274 toggleHandler: togglePreview
281 tooltip: {title:'Post Summary',text:'View a short summary of each post in the list'},
283 toggleHandler: toggleDetails
286 bbar: new Ext.PagingToolbar({
290 displayMsg: 'Displaying topics {0} - {1} of {2}',
291 emptyMsg: "No topics to display"
299 bodyStyle: 'padding: 10px; font-family: Arial; font-size: 12px;'
307 var tree = Ext.getCmp('forum-tree');
308 tree.on('append', function(tree, p, node){
310 node.select.defer(100, node);
313 var sm = tree.getSelectionModel();
314 sm.on('beforeselect', function(sm, node){
315 return node.isLeaf();
317 sm.on('selectionchange', function(sm, node){
318 ds.loadForum(node.id);
319 Ext.getCmp('main-view').setTitle(node.text);
323 var searchStore = new Ext.data.Store({
324 proxy: new Ext.data.ScriptTagProxy({
325 url: 'http://extjs.com/forum/topics-browse-remote.php'
327 reader: new Ext.data.JsonReader({
329 totalProperty: 'totalCount',
333 {name: 'lastpost', type: 'date', dateFormat: 'timestamp'}
337 // Custom rendering Template
338 var resultTpl = new Ext.XTemplate(
340 '<div class="x-combo-list-item search-item">{title} by <b>{author}</b></div>',
344 var search = new Ext.form.ComboBox({
347 displayField:'title',
349 loadingText: 'Searching...',
356 emptyText:'Quick Search',
357 onSelect: function(record){ // override default onSelect to do redirect
359 String.format('http://extjs.com/forum/showthread.php?t={0}&p={1}', record.data.topicId, record.id);
362 // apply it to the exsting input element
363 //search.applyTo('search');
367 function toggleDetails(btn, pressed){
368 var view = Ext.getCmp('topic-grid').getView();
369 view.showPreview = pressed;
373 function togglePreview(btn, pressed){
374 var preview = Ext.getCmp('preview');
375 preview[pressed ? 'show' : 'hide']();
376 preview.ownerCt.doLayout();
380 Forum.TreeLoader = function(){
381 Forum.TreeLoader.superclass.constructor.call(this);
382 this.proxy = new Ext.data.ScriptTagProxy({
386 Ext.extend(Forum.TreeLoader, Ext.tree.TreeLoader, {
387 dataUrl: 'http://extjs.com/forum/forums-remote.php',
388 requestData : function(node, cb){
389 this.proxy.request('read', null, {}, {
390 readRecords : function(o){
393 }, this.addNodes, this, {node:node, cb:cb});
396 addNodes : function(o, arg){
398 for(var i = 0, len = o.length; i < len; i++){
399 var n = this.createNode(o[i]);