modx.grid.dashboard.widgets.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. MODx.grid.DashboardWidgets = function(config) {
  2. config = config || {};
  3. this.exp = new Ext.grid.RowExpander({
  4. tpl : new Ext.Template(
  5. '<p class="desc">{description_trans}</p>'
  6. )
  7. });
  8. this.sm = new Ext.grid.CheckboxSelectionModel();
  9. Ext.applyIf(config,{
  10. url: MODx.config.connector_url
  11. ,baseParams: {
  12. action: 'system/dashboard/widget/getlist'
  13. }
  14. ,fields: ['id','name','name_trans','description','description_trans','type','content','namespace','lexicon','size','cls']
  15. ,paging: true
  16. ,remoteSort: true
  17. ,sm: this.sm
  18. ,plugins: [this.exp]
  19. ,columns: [this.exp,this.sm,{
  20. header: _('id')
  21. ,dataIndex: 'id'
  22. ,width: 50
  23. ,sortable: true
  24. },{
  25. header: _('name')
  26. ,dataIndex: 'name_trans'
  27. ,width: 150
  28. ,sortable: true
  29. ,editable: false
  30. },{
  31. header: _('widget_type')
  32. ,dataIndex: 'type'
  33. ,width: 80
  34. ,sortable: true
  35. },{
  36. header: _('widget_namespace')
  37. ,dataIndex: 'namespace'
  38. ,width: 120
  39. ,sortable: true
  40. }]
  41. ,tbar: [{
  42. text: _('widget_create')
  43. ,cls:'primary-button'
  44. ,handler: this.createDashboard
  45. ,scope: this
  46. },{
  47. text: _('bulk_actions')
  48. ,menu: [{
  49. text: _('selected_remove')
  50. ,handler: this.removeSelected
  51. ,scope: this
  52. }]
  53. },'->',{
  54. xtype: 'textfield'
  55. ,name: 'search'
  56. ,id: 'modx-dashboard-widget-search'
  57. ,cls: 'x-form-filter'
  58. ,emptyText: _('search_ellipsis')
  59. ,listeners: {
  60. 'change': {fn: this.search, scope: this}
  61. ,'render': {fn: function(cmp) {
  62. new Ext.KeyMap(cmp.getEl(), {
  63. key: Ext.EventObject.ENTER
  64. ,fn: this.blur
  65. ,scope: cmp
  66. });
  67. },scope:this}
  68. }
  69. },{
  70. xtype: 'button'
  71. ,text: _('filter_clear')
  72. ,id: 'modx-dashboard-widgets-filter-clear'
  73. ,cls: 'x-form-filter-clear'
  74. ,listeners: {
  75. 'click': {fn: this.clearFilter, scope: this},
  76. 'mouseout': { fn: function(evt){
  77. this.removeClass('x-btn-focus');
  78. }
  79. }
  80. }
  81. }]
  82. });
  83. MODx.grid.DashboardWidgets.superclass.constructor.call(this,config);
  84. };
  85. Ext.extend(MODx.grid.DashboardWidgets,MODx.grid.Grid,{
  86. getMenu: function() {
  87. var r = this.getSelectionModel().getSelected();
  88. var p = r.data.cls;
  89. var m = [];
  90. if (this.getSelectionModel().getCount() > 1) {
  91. m.push({
  92. text: _('selected_remove')
  93. ,handler: this.removeSelected
  94. ,scope: this
  95. });
  96. } else {
  97. if (p.indexOf('pupdate') != -1) {
  98. m.push({
  99. text: _('widget_update')
  100. ,handler: this.updateWidget
  101. });
  102. }
  103. if (p.indexOf('premove') != -1) {
  104. if (m.length > 0) m.push('-');
  105. m.push({
  106. text: _('widget_unplace')
  107. ,handler: this.removeWidget
  108. });
  109. }
  110. }
  111. if (m.length > 0) {
  112. this.addContextMenuItem(m);
  113. }
  114. }
  115. ,createDashboard: function() {
  116. MODx.loadPage('system/dashboards/widget/create');
  117. }
  118. ,removeSelected: function() {
  119. var cs = this.getSelectedAsList();
  120. if (cs === false) return false;
  121. MODx.msg.confirm({
  122. title: _('widget_remove_multiple')
  123. ,text: _('widget_remove_multiple_confirm')
  124. ,url: this.config.url
  125. ,params: {
  126. action: 'system/dashboard/widget/removeMultiple'
  127. ,widgets: cs
  128. }
  129. ,listeners: {
  130. 'success': {fn:function(r) {
  131. this.getSelectionModel().clearSelections(true);
  132. this.refresh();
  133. },scope:this}
  134. }
  135. });
  136. return true;
  137. }
  138. ,removeWidget: function() {
  139. MODx.msg.confirm({
  140. title: _('widget_remove')
  141. ,text: _('widget_remove_confirm')
  142. ,url: this.config.url
  143. ,params: {
  144. action: 'system/dashboard/widget/remove'
  145. ,id: this.menu.record.id
  146. }
  147. ,listeners: {
  148. 'success': {fn:this.refresh,scope:this}
  149. }
  150. });
  151. }
  152. ,updateWidget: function() {
  153. MODx.loadPage('system/dashboards/widget/update', 'id='+this.menu.record.id);
  154. }
  155. ,search: function(tf,newValue,oldValue) {
  156. var nv = newValue || tf;
  157. this.getStore().baseParams.query = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  158. this.getBottomToolbar().changePage(1);
  159. //this.refresh();
  160. return true;
  161. }
  162. ,clearFilter: function() {
  163. this.getStore().baseParams = {
  164. action: 'system/dashboard/widget/getlist'
  165. };
  166. Ext.getCmp('modx-dashboard-widget-search').reset();
  167. this.getBottomToolbar().changePage(1);
  168. //this.refresh();
  169. }
  170. });
  171. Ext.reg('modx-grid-dashboard-widgets',MODx.grid.DashboardWidgets);