38af960fa063fca664cf95ab238948f1c8b3d071.svn-base 10 KB

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