lexicon.topic.grid.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * Loads a grid for managing lexicon topics.
  3. *
  4. * @class MODx.grid.LexiconTopic
  5. * @extends MODx.grid.Grid
  6. * @param {Object} config An object of configuration properties
  7. * @xtype modx-grid-lexicon-topic
  8. */
  9. MODx.grid.LexiconTopic = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. title: _('lexicon_topics')
  13. ,id: 'modx-grid-lexicon-topic'
  14. ,url: MODx.config.connector_url
  15. ,fields: ['id','name','namespace','menu']
  16. ,baseParams: {
  17. action: 'workspace/lexicon/topic/getList'
  18. ,'namespace': 'core'
  19. }
  20. ,saveParams: {
  21. 'namespace': 'core'
  22. }
  23. ,width: '97%'
  24. ,paging: true
  25. ,autosave: true
  26. ,columns: [{
  27. header: _('name')
  28. ,dataIndex: 'name'
  29. ,width: 200
  30. ,sortable: true
  31. },{
  32. header: _('namespace')
  33. ,dataIndex: 'namespace'
  34. ,width: 500
  35. ,sortable: false
  36. ,editor: {
  37. xtype: 'modx-combo-namespace'
  38. ,renderer: true
  39. }
  40. }]
  41. ,tbar: [{
  42. xtype: 'modx-combo-namespace'
  43. ,name: 'namespace'
  44. ,id: 'modx-lexicon-topic-filter-namespace'
  45. ,itemId: 'namespace'
  46. ,value: 'core'
  47. ,listeners: {
  48. 'change': {fn:this.filter.createDelegate(this,['namespace'],true),scope:this}
  49. }
  50. },'->',{
  51. text: _('search_by_key')
  52. },{
  53. xtype: 'textfield'
  54. ,name: 'name'
  55. ,id: 'modx-lexicon-topic-filter-name'
  56. ,itemId: 'name'
  57. ,listeners: {
  58. 'change': {fn:this.filter.createDelegate(this,['name'],true),scope:this}
  59. ,'render': {fn:function(tf) {
  60. tf.getEl().addKeyListener(Ext.EventObject.ENTER,function() {
  61. tf.fireEvent('change');
  62. },this);
  63. }}
  64. }
  65. },{
  66. text: _('create_new')
  67. ,xtype: 'button'
  68. ,cls:'primary-button'
  69. ,menu: [{
  70. text: _('topic')
  71. ,handler: this.loadWindow2.createDelegate(this,[{
  72. xtype: 'modx-window-lexicon-topic-create'
  73. ,listeners: {
  74. 'success':{fn:function(o) {
  75. var r = o.a.result.object;
  76. this.setNamespace(r['namespace']);
  77. var g = Ext.getCmp('modx-grid-lexicon');
  78. if (g) {
  79. g.setFilterParams(r['namespace'],r.id);
  80. }
  81. },scope: this}
  82. }
  83. }],true)
  84. ,scope: this
  85. },{
  86. text: _('namespace')
  87. ,handler: this.loadWindow2.createDelegate(this,[{
  88. xtype: 'modx-window-namespace-create'
  89. ,listeners: {
  90. 'success':{fn:function(o) {
  91. var r = o.a.result.object;
  92. this.setNamespace(r.name);
  93. var g = Ext.getCmp('modx-grid-lexicon');
  94. if (g) {
  95. g.setFilterParams(r.name);
  96. }
  97. },scope: this}
  98. }
  99. }],true)
  100. ,scope: this
  101. }]
  102. }]
  103. });
  104. MODx.grid.LexiconTopic.superclass.constructor.call(this,config);
  105. };
  106. Ext.extend(MODx.grid.LexiconTopic,MODx.grid.Grid,{
  107. filter: function(cb,nv,ov,name) {
  108. if (!name) { return false; }
  109. this.getStore().baseParams[name] = nv;
  110. this.config.saveParams[name] = nv;
  111. this.getBottomToolbar().changePage(1);
  112. //this.refresh();
  113. }
  114. ,loadWindow2: function(btn,e,o) {
  115. this.menu.record = {
  116. 'namespace': this.getTopToolbar().getComponent('namespace').getValue()
  117. };
  118. this.loadWindow(btn,e,o);
  119. }
  120. ,setNamespace: function(ns) {
  121. var ncb = this.getTopToolbar().getComponent('namespace');
  122. if (ncb) { ncb.setValue(ns); }
  123. this.config.saveParams['namespace'] = ns;
  124. this.getBottomToolbar().changePage(1);
  125. this.getStore().baseParams['namespace'] = ns;
  126. //this.refresh();
  127. }
  128. });
  129. Ext.reg('modx-grid-lexicon-topic',MODx.grid.LexiconTopic);
  130. /**
  131. * Generates the create lexicon topic window.
  132. *
  133. * @class MODx.window.CreateLexiconTopic
  134. * @extends MODx.Window
  135. * @param {Object} config An object of options.
  136. * @xtype modx-window-lexicon-topic-create
  137. */
  138. MODx.window.CreateLexiconTopic = function(config) {
  139. config = config || {};
  140. var r = config.record;
  141. Ext.applyIf(config,{
  142. title: _('topic_create')
  143. ,url: MODx.config.connector_url
  144. ,action: 'workspace/lexicon/topic/create'
  145. ,fields: [{
  146. xtype: 'textfield'
  147. ,fieldLabel: _('name')
  148. ,name: 'name'
  149. ,id: 'modx-clt-name'
  150. ,itemId: 'name'
  151. ,anchor: '100%'
  152. ,maxLength: 100
  153. },{
  154. xtype: 'modx-combo-namespace'
  155. ,fieldLabel: _('namespace')
  156. ,name: 'namespace'
  157. ,id: 'modx-clt-namespace'
  158. ,itemId: 'namespace'
  159. ,value: r['namespace']
  160. ,anchor: '100%'
  161. }]
  162. });
  163. MODx.window.CreateLexiconTopic.superclass.constructor.call(this,config);
  164. };
  165. Ext.extend(MODx.window.CreateLexiconTopic,MODx.Window);
  166. Ext.reg('modx-window-lexicon-topic-create',MODx.window.CreateLexiconTopic);