modx.panel.search.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**
  2. * Loads the search filter panel
  3. *
  4. * @class MODx.panel.Search
  5. * @extends MODx.FormPanel
  6. * @param {Object} config An object of options.
  7. * @xtype modx-panel-search
  8. */
  9. MODx.panel.Search = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. id: 'modx-panel-search'
  13. ,cls: 'container form-with-labels'
  14. ,labelAlign: 'top'
  15. ,autoHeight: true
  16. ,items: [{
  17. html: _('search')
  18. ,xtype: 'modx-header'
  19. },MODx.getPageStructure([{
  20. layout: 'form'
  21. ,title: _('search_criteria')
  22. ,defaults: {
  23. collapsible: false
  24. ,autoHeight: true
  25. }
  26. ,items: [{
  27. layout: 'form'
  28. ,cls: 'main-wrapper'
  29. ,border: false
  30. ,items: this.getFields(config)
  31. },{
  32. html: '<hr />'
  33. ,border: false
  34. },{
  35. xtype: 'modx-grid-search'
  36. ,cls: 'main-wrapper'
  37. ,preventRender: true
  38. }]
  39. }])]
  40. });
  41. MODx.panel.Search.superclass.constructor.call(this,config);
  42. };
  43. Ext.extend(MODx.panel.Search,MODx.FormPanel,{
  44. filters: {}
  45. ,getFields: function(config) {
  46. return [{
  47. layout: 'column'
  48. ,border: false
  49. ,defaults: {
  50. layout: 'form'
  51. ,labelAlign: 'top'
  52. ,anchor: '100%'
  53. ,border: false
  54. }
  55. ,items: [{
  56. columnWidth: .6
  57. ,items: [{
  58. xtype: 'textfield'
  59. ,name: 'pagetitle'
  60. ,id: 'modx-search-pagetitle'
  61. ,fieldLabel: _('pagetitle')
  62. ,anchor: '100%'
  63. ,listeners: {
  64. 'change': {fn:this.filter,scope: this}
  65. ,'render': {fn:this._addEnterKeyHandler}
  66. }
  67. ,value: config.record.q || ''
  68. },{
  69. xtype: 'textfield'
  70. ,name: 'longtitle'
  71. ,id: 'modx-search-longtitle'
  72. ,fieldLabel: _('long_title')
  73. ,anchor: '100%'
  74. ,listeners: {
  75. 'change': {fn:this.filter,scope: this}
  76. ,'render': {fn:this._addEnterKeyHandler}
  77. }
  78. ,value: config.record.q || ''
  79. },{
  80. xtype: 'textfield'
  81. ,fieldLabel: _('resource_summary')
  82. ,name: 'introtext'
  83. ,id: 'modx-search-introtext'
  84. ,anchor: '100%'
  85. ,listeners: {
  86. 'change': {fn:this.filter,scope: this}
  87. ,'render': {fn:this._addEnterKeyHandler}
  88. }
  89. ,value: config.record.q || ''
  90. },{
  91. xtype: 'textfield'
  92. ,fieldLabel: _('resource_description')
  93. ,name: 'description'
  94. ,id: 'modx-search-description'
  95. ,anchor: '100%'
  96. ,listeners: {
  97. 'change': {fn:this.filter,scope: this}
  98. ,'render': {fn:this._addEnterKeyHandler}
  99. }
  100. ,value: config.record.q || ''
  101. }]
  102. },{
  103. columnWidth: .4
  104. ,items: [{
  105. xtype: 'textfield'
  106. ,name: 'alias'
  107. ,id: 'modx-search-alias'
  108. ,fieldLabel: _('alias')
  109. ,anchor: '100%'
  110. ,listeners: {
  111. 'change': {fn:this.filter,scope: this}
  112. ,'render': {fn:this._addEnterKeyHandler}
  113. }
  114. ,value: config.record.q || ''
  115. },{
  116. xtype: 'textfield'
  117. ,name: 'menutitle'
  118. ,id: 'modx-search-menutitle'
  119. ,fieldLabel: _('resource_menutitle')
  120. ,anchor: '100%'
  121. ,listeners: {
  122. 'change': {fn:this.filter,scope: this}
  123. ,'render': {fn:this._addEnterKeyHandler}
  124. }
  125. ,value: config.record.q || ''
  126. },{
  127. layout: 'column'
  128. ,border: false
  129. ,defaults: {
  130. layout: 'form'
  131. ,labelAlign: 'top'
  132. ,anchor: '100%'
  133. ,border: false
  134. }
  135. ,items: [{
  136. columnWidth: .5
  137. ,items: [{
  138. xtype: 'textfield'
  139. ,name: 'id'
  140. ,id: 'modx-search-id'
  141. ,fieldLabel: _('id')
  142. ,width: 100
  143. ,listeners: {
  144. 'change': {fn:this.filter,scope: this}
  145. ,'render': {fn:this._addEnterKeyHandler}
  146. }
  147. },{
  148. xtype: 'xcheckbox'
  149. ,name: 'published'
  150. ,id: 'modx-search-published'
  151. ,boxLabel: _('published')
  152. ,hideLabel: true
  153. ,inputValue: 1
  154. ,checked: false
  155. ,handler: this.filter
  156. ,scope: this
  157. },{
  158. xtype: 'xcheckbox'
  159. ,name: 'unpublished'
  160. ,id: 'modx-search-unpublished'
  161. ,boxLabel: _('unpublished')
  162. ,hideLabel: true
  163. ,inputValue: 1
  164. ,checked: false
  165. ,handler: this.filter
  166. ,scope: this
  167. }]
  168. },{
  169. columnWidth: .5
  170. ,items: [{
  171. xtype: 'textfield'
  172. ,name: 'parent'
  173. ,id: 'modx-search-parent'
  174. ,fieldLabel: _('parent')
  175. ,width: 100
  176. ,listeners: {
  177. 'change': {fn:this.filter,scope: this}
  178. ,'render': {fn:this._addEnterKeyHandler}
  179. }
  180. },{
  181. xtype: 'xcheckbox'
  182. ,name: 'deleted'
  183. ,id: 'modx-search-deleted'
  184. ,boxLabel: _('deleted')
  185. ,hideLabel: true
  186. ,inputValue: 1
  187. ,checked: false
  188. ,handler: this.filter
  189. ,scope: this
  190. },{
  191. xtype: 'xcheckbox'
  192. ,name: 'undeleted'
  193. ,id: 'modx-search-undeleted'
  194. ,boxLabel: _('undeleted')
  195. ,hideLabel: true
  196. ,inputValue: 1
  197. ,checked: false
  198. ,handler: this.filter
  199. ,scope: this
  200. }]
  201. }]
  202. }]
  203. }]
  204. },{
  205. xtype: 'textarea'
  206. ,name: 'content'
  207. ,fieldLabel: _('content')
  208. ,anchor: '100%'
  209. ,grow: true
  210. ,listeners: {
  211. 'change': {fn:this.filter,scope: this}
  212. ,'render': {fn:this._addEnterKeyHandler}
  213. }
  214. ,value: config.record.q || ''
  215. }];
  216. }
  217. ,filter: function(tf,newValue,oldValue) {
  218. var p = this.getForm().getValues();
  219. p.action = 'resource/search';
  220. var g = Ext.getCmp('modx-grid-search');
  221. if (g) {
  222. g.getStore().baseParams = p;
  223. g.getBottomToolbar().changePage(1);
  224. g.refresh();
  225. }
  226. }
  227. ,_addEnterKeyHandler: function() {
  228. this.getEl().addKeyListener(Ext.EventObject.ENTER,function() {
  229. this.fireEvent('change');
  230. },this);
  231. }
  232. });
  233. Ext.reg('modx-panel-search',MODx.panel.Search);
  234. /**
  235. * Loads the search result grid
  236. *
  237. * @class MODx.grid.Search
  238. * @extends MODx.grid.Grid
  239. * @param {Object} config An object of options.
  240. * @xtype grid-search
  241. */
  242. MODx.grid.Search = function(config) {
  243. config = config || {};
  244. Ext.applyIf(config,{
  245. title: _('search_results')
  246. ,id: 'modx-grid-search'
  247. ,url: MODx.config.connector_url
  248. ,baseParams: {
  249. action: 'resource/search'
  250. }
  251. ,fields: ['id','pagetitle','description','published','deleted','menu']
  252. ,paging: true
  253. ,remoteSort: true
  254. ,columns: [{
  255. header: _('id')
  256. ,dataIndex: 'id'
  257. ,width: 20
  258. ,sortable: true
  259. },{
  260. header: _('pagetitle')
  261. ,dataIndex: 'pagetitle'
  262. ,sortable: true
  263. },{
  264. header: _('description')
  265. ,dataIndex: 'description'
  266. ,sortable: true
  267. },{
  268. header: _('published')
  269. ,dataIndex: 'published'
  270. ,width: 30
  271. ,editor: { xtype: 'combo-boolean' ,renderer: 'boolean' }
  272. ,editable: false
  273. ,sortable: true
  274. },{
  275. header: _('deleted')
  276. ,dataIndex: 'deleted'
  277. ,width: 30
  278. ,editor: { xtype: 'combo-boolean' ,renderer: 'boolean' }
  279. ,editable: false
  280. ,sortable: true
  281. }]
  282. });
  283. MODx.grid.Search.superclass.constructor.call(this,config);
  284. };
  285. Ext.extend(MODx.grid.Search,MODx.grid.Grid);
  286. Ext.reg('modx-grid-search',MODx.grid.Search);