You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

420 lines
13 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. var Forum = {};
  16. //////////////////////////////////////////////////////////////////////////////////////////////
  17. // The data store for topics
  18. Forum.TopicStore = function(){
  19. Forum.TopicStore.superclass.constructor.call(this, {
  20. remoteSort: true,
  21. proxy: new Ext.data.ScriptTagProxy({
  22. url: 'http://extjs.com/forum/topics-browse-remote.php'
  23. }),
  24. reader: new Ext.data.JsonReader({
  25. root: 'topics',
  26. totalProperty: 'totalCount',
  27. id: 'threadid'
  28. }, [
  29. 'title', 'forumtitle', 'forumid', 'author',
  30. {name: 'replycount', type: 'int'},
  31. {name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
  32. 'lastposter', 'excerpt'
  33. ])
  34. });
  35. this.setDefaultSort('lastpost', 'desc');
  36. };
  37. Ext.extend(Forum.TopicStore, Ext.data.Store, {
  38. loadForum : function(forumId){
  39. this.baseParams = {
  40. forumId: forumId
  41. };
  42. this.load({
  43. params: {
  44. start:0,
  45. limit:25
  46. }
  47. });
  48. }
  49. });
  50. //////////////////////////////////////////////////////////////////////////////////////////////
  51. // some renderers
  52. Forum.Renderers = {
  53. topic : function(value, p, record){
  54. return String.format(
  55. '<div class="topic"><b>{0}</b><span class="author">{1}</span></div>',
  56. value, record.data.author, record.id, record.data.forumid);
  57. },
  58. lastPost : function(value, p, r){
  59. return String.format('<span class="post-date">{0}</span><br/>by {1}', value.dateFormat('M j, Y, g:i a'), r.data['lastposter']);
  60. }
  61. };
  62. //////////////////////////////////////////////////////////////////////////////////////////////
  63. Forum.SearchView = function(search){
  64. this.preview = new Ext.Panel({
  65. region:'south',
  66. height:250,
  67. title:'View Message',
  68. split:true
  69. });
  70. this.store = new Ext.data.Store({
  71. remoteSort: true,
  72. proxy: new Ext.data.ScriptTagProxy({
  73. url: 'http://extjs.com/forum/topics-browse-remote.php'
  74. }),
  75. reader: new Ext.data.JsonReader({
  76. root: 'topics',
  77. totalProperty: 'totalCount',
  78. id: 'post_id'
  79. }, [
  80. {name: 'postId', mapping: 'post_id'},
  81. {name: 'title', mapping: 'topic_title'},
  82. {name: 'topicId', mapping: 'topic_id'},
  83. {name: 'author', mapping: 'author'},
  84. {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
  85. {name: 'excerpt', mapping: 'post_text'}
  86. ])
  87. });
  88. this.store.setDefaultSort('lastpost', 'desc');
  89. this.grid = new Ext.grid.GridPanel({
  90. region:'center',
  91. store: this.store,
  92. cm: new Ext.grid.ColumnModel([{
  93. id: 'topic',
  94. header: "Post Title",
  95. dataIndex: 'title',
  96. width: 420,
  97. renderer: Forum.Renderers.topic
  98. },{
  99. id: 'last',
  100. header: "Date Posted",
  101. dataIndex: 'lastpost',
  102. width: 150,
  103. renderer: Ext.util.Format.dateRenderer('M j, Y, g:i a')
  104. }]),
  105. sm: new Ext.grid.RowSelectionModel({
  106. singleSelect:true
  107. }),
  108. trackMouseOver:false,
  109. loadMask: {msg:'Searching...'},
  110. viewConfig: {
  111. forceFit:true,
  112. enableRowBody:true,
  113. showPreview:true,
  114. getRowClass : function(record, rowIndex, p, ds){
  115. if(this.showPreview){
  116. p.body = '<p>'+record.data.excerpt+'</p>';
  117. return 'x-grid3-row-expanded';
  118. }
  119. return 'x-grid3-row-collapsed';
  120. }
  121. },
  122. bbar: new Ext.PagingToolbar({
  123. pageSize: 25,
  124. store: ds,
  125. displayInfo: true,
  126. displayMsg: 'Displaying results {0} - {1} of {2}',
  127. emptyMsg: "No results to display"
  128. })
  129. });
  130. Forum.SearchView.superclass.constructor.call(this, {
  131. layout:'border',
  132. title:'Search: '+Ext.util.Format.htmlEncode('"'+search+'"'),
  133. items:[ this.grid, this.preview ]
  134. });
  135. this.store.baseParams = {
  136. query: search
  137. };
  138. this.store.load({params:{start:0, limit: 25}});
  139. };
  140. Ext.extend(Forum.SearchView, Ext.Panel);
  141. Ext.onReady(function(){
  142. Ext.QuickTips.init();
  143. var ds = new Forum.TopicStore();
  144. var cm = new Ext.grid.ColumnModel([{
  145. id: 'topic',
  146. header: "Topic",
  147. dataIndex: 'title',
  148. width: 420,
  149. renderer: Forum.Renderers.topic
  150. },{
  151. header: "Author",
  152. dataIndex: 'author',
  153. width: 100,
  154. hidden: true
  155. },{
  156. header: "Replies",
  157. dataIndex: 'replycount',
  158. width: 70,
  159. align: 'right'
  160. },{
  161. id: 'last',
  162. header: "Last Post",
  163. dataIndex: 'lastpost',
  164. width: 150,
  165. renderer: Forum.Renderers.lastPost
  166. }]);
  167. cm.defaultSortable = true;
  168. var viewport = new Ext.Viewport({
  169. layout:'border',
  170. items:[
  171. new Ext.BoxComponent({ // raw
  172. region:'north',
  173. el: 'header',
  174. height:32
  175. }),
  176. new Ext.tree.TreePanel({
  177. id:'forum-tree',
  178. region:'west',
  179. title:'Forums',
  180. split:true,
  181. width: 325,
  182. minSize: 175,
  183. maxSize: 400,
  184. collapsible: true,
  185. margins:'0 0 5 5',
  186. loader: new Forum.TreeLoader(),
  187. rootVisible:false,
  188. lines:false,
  189. autoScroll:true,
  190. root: new Ext.tree.AsyncTreeNode({
  191. text: 'Forums',
  192. expanded:true
  193. })
  194. }),
  195. new Ext.TabPanel({
  196. id:'main-tabs',
  197. activeTab:0,
  198. region:'center',
  199. margins:'0 5 5 0',
  200. resizeTabs:true,
  201. tabWidth:150,
  202. items: {
  203. id:'main-view',
  204. layout:'border',
  205. title:'Loading...',
  206. items:[
  207. new Ext.grid.GridPanel({
  208. region:'center',
  209. id:'topic-grid',
  210. store: ds,
  211. cm: cm,
  212. sm:new Ext.grid.RowSelectionModel({
  213. singleSelect:true,
  214. listeners: {
  215. selectionchange: function(sel){
  216. var rec = sel.getSelected();
  217. if(rec){
  218. Ext.getCmp('preview').body.update('<b><u>' + rec.get('title') + '</u></b><br /><br />Post details here.');
  219. }
  220. }
  221. }
  222. }),
  223. trackMouseOver:false,
  224. loadMask: {msg:'Loading Topics...'},
  225. viewConfig: {
  226. forceFit:true,
  227. enableRowBody:true,
  228. showPreview:true,
  229. getRowClass : function(record, rowIndex, p, ds){
  230. if(this.showPreview){
  231. p.body = '<p>'+record.data.excerpt+'</p>';
  232. return 'x-grid3-row-expanded';
  233. }
  234. return 'x-grid3-row-collapsed';
  235. }
  236. },
  237. tbar:[
  238. {
  239. text:'New Topic',
  240. iconCls: 'new-topic',
  241. handler:function(){alert('Not implemented.');}
  242. },
  243. '-',
  244. {
  245. pressed: true,
  246. enableToggle:true,
  247. text:'Preview Pane',
  248. tooltip: {title:'Preview Pane',text:'Show or hide the Preview Pane'},
  249. iconCls: 'preview',
  250. toggleHandler: togglePreview
  251. },
  252. ' ',
  253. {
  254. pressed: true,
  255. enableToggle:true,
  256. text:'Summary',
  257. tooltip: {title:'Post Summary',text:'View a short summary of each post in the list'},
  258. iconCls: 'summary',
  259. toggleHandler: toggleDetails
  260. }
  261. ],
  262. bbar: new Ext.PagingToolbar({
  263. pageSize: 25,
  264. store: ds,
  265. displayInfo: true,
  266. displayMsg: 'Displaying topics {0} - {1} of {2}',
  267. emptyMsg: "No topics to display"
  268. })
  269. }), {
  270. id:'preview',
  271. region:'south',
  272. height:250,
  273. title:'View Topic',
  274. split:true,
  275. bodyStyle: 'padding: 10px; font-family: Arial; font-size: 12px;'
  276. }
  277. ]
  278. }
  279. })
  280. ]
  281. });
  282. var tree = Ext.getCmp('forum-tree');
  283. tree.on('append', function(tree, p, node){
  284. if(node.id == 40){
  285. node.select.defer(100, node);
  286. }
  287. });
  288. var sm = tree.getSelectionModel();
  289. sm.on('beforeselect', function(sm, node){
  290. return node.isLeaf();
  291. });
  292. sm.on('selectionchange', function(sm, node){
  293. ds.loadForum(node.id);
  294. Ext.getCmp('main-view').setTitle(node.text);
  295. });
  296. var searchStore = new Ext.data.Store({
  297. proxy: new Ext.data.ScriptTagProxy({
  298. url: 'http://extjs.com/forum/topics-browse-remote.php'
  299. }),
  300. reader: new Ext.data.JsonReader({
  301. root: 'topics',
  302. totalProperty: 'totalCount',
  303. id: 'threadid'
  304. }, [
  305. 'title', 'author',
  306. {name: 'lastpost', type: 'date', dateFormat: 'timestamp'}
  307. ])
  308. });
  309. // Custom rendering Template
  310. var resultTpl = new Ext.XTemplate(
  311. '<tpl for=".">',
  312. '<div class="x-combo-list-item search-item">{title} by <b>{author}</b></div>',
  313. '</tpl>'
  314. );
  315. var search = new Ext.form.ComboBox({
  316. store: searchStore,
  317. applyTo: 'search',
  318. displayField:'title',
  319. typeAhead: false,
  320. loadingText: 'Searching...',
  321. width: 200,
  322. pageSize:10,
  323. listWidth:550,
  324. hideTrigger:true,
  325. tpl: resultTpl,
  326. minChars:3,
  327. emptyText:'Quick Search',
  328. onSelect: function(record){ // override default onSelect to do redirect
  329. window.location =
  330. String.format('http://extjs.com/forum/showthread.php?t={0}&p={1}', record.data.topicId, record.id);
  331. }
  332. });
  333. // apply it to the exsting input element
  334. //search.applyTo('search');
  335. function toggleDetails(btn, pressed){
  336. var view = Ext.getCmp('topic-grid').getView();
  337. view.showPreview = pressed;
  338. view.refresh();
  339. }
  340. function togglePreview(btn, pressed){
  341. var preview = Ext.getCmp('preview');
  342. preview[pressed ? 'show' : 'hide']();
  343. preview.ownerCt.doLayout();
  344. }
  345. });
  346. Forum.TreeLoader = function(){
  347. Forum.TreeLoader.superclass.constructor.call(this);
  348. this.proxy = new Ext.data.ScriptTagProxy({
  349. url : this.dataUrl
  350. });
  351. };
  352. Ext.extend(Forum.TreeLoader, Ext.tree.TreeLoader, {
  353. dataUrl: 'http://extjs.com/forum/forums-remote.php',
  354. requestData : function(node, cb){
  355. this.proxy.request('read', null, {}, {
  356. readRecords : function(o){
  357. return o;
  358. }
  359. }, this.addNodes, this, {node:node, cb:cb});
  360. },
  361. addNodes : function(o, arg){
  362. var node = arg.node;
  363. for(var i = 0, len = o.length; i < len; i++){
  364. var n = this.createNode(o[i]);
  365. if(n){
  366. node.appendChild(n);
  367. }
  368. }
  369. arg.cb(this, node);
  370. }
  371. });