forum-search.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Ext.require([
  2. 'Ext.data.*',
  3. 'Ext.form.*'
  4. ]);
  5. Ext.onReady(function(){
  6. Ext.define("Post", {
  7. extend: 'Ext.data.Model',
  8. proxy: {
  9. type: 'jsonp',
  10. url : 'http://www.sencha.com/forum/topics-remote.php',
  11. reader: {
  12. type: 'json',
  13. root: 'topics',
  14. totalProperty: 'totalCount'
  15. }
  16. },
  17. fields: [
  18. {name: 'id', mapping: 'post_id'},
  19. {name: 'title', mapping: 'topic_title'},
  20. {name: 'topicId', mapping: 'topic_id'},
  21. {name: 'author', mapping: 'author'},
  22. {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
  23. {name: 'excerpt', mapping: 'post_text'}
  24. ]
  25. });
  26. ds = Ext.create('Ext.data.Store', {
  27. pageSize: 10,
  28. model: 'Post'
  29. });
  30. panel = Ext.create('Ext.panel.Panel', {
  31. renderTo: Ext.getBody(),
  32. title: 'Search the Ext Forums',
  33. width: 600,
  34. bodyPadding: 10,
  35. layout: 'anchor',
  36. items: [{
  37. xtype: 'combo',
  38. store: ds,
  39. displayField: 'title',
  40. typeAhead: false,
  41. hideLabel: true,
  42. hideTrigger:true,
  43. anchor: '100%',
  44. listConfig: {
  45. loadingText: 'Searching...',
  46. emptyText: 'No matching posts found.',
  47. // Custom rendering template for each item
  48. getInnerTpl: function() {
  49. return '<a class="search-item" href="http://www.sencha.com/forum/showthread.php?t={topicId}&p={id}">' +
  50. '<h3><span>{[Ext.Date.format(values.lastPost, "M j, Y")]}<br />by {author}</span>{title}</h3>' +
  51. '{excerpt}' +
  52. '</a>';
  53. }
  54. },
  55. pageSize: 10
  56. }, {
  57. xtype: 'component',
  58. style: 'margin-top:10px',
  59. html: 'Live search requires a minimum of 4 characters.'
  60. }]
  61. });
  62. });