modx.panel.dashboards.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. MODx.panel.Dashboards = function(config) {
  2. config = config || {};
  3. Ext.applyIf(config,{
  4. id: 'modx-panel-dashboards'
  5. ,cls: 'container'
  6. ,defaults: { collapsible: false ,autoHeight: true }
  7. ,items: [{
  8. html: _('dashboards')
  9. ,id: 'modx-dashboards-header'
  10. ,xtype: 'modx-header'
  11. },MODx.getPageStructure([{
  12. layout: 'form'
  13. ,title: _('dashboards')
  14. ,items: [{
  15. html: '<p>'+_('dashboards.intro_msg')+'</p>'
  16. ,xtype: 'modx-description'
  17. },{
  18. xtype: 'modx-grid-dashboards'
  19. ,cls: 'main-wrapper'
  20. ,preventRender: true
  21. }]
  22. },{
  23. layout: 'form'
  24. ,title: _('widgets')
  25. ,items: [{
  26. html: '<p>'+_('widgets.intro_msg')+'</p>'
  27. ,xtype: 'modx-description'
  28. },{
  29. xtype: 'modx-grid-dashboard-widgets'
  30. ,cls: 'main-wrapper'
  31. ,preventRender: true
  32. }]
  33. }],{
  34. stateful: true
  35. ,stateId: 'modx-dashboards-tabpanel'
  36. ,stateEvents: ['tabchange']
  37. ,getState:function() {
  38. return {activeTab:this.items.indexOf(this.getActiveTab())};
  39. }
  40. })]
  41. });
  42. MODx.panel.Dashboards.superclass.constructor.call(this,config);
  43. };
  44. Ext.extend(MODx.panel.Dashboards,MODx.FormPanel);
  45. Ext.reg('modx-panel-dashboards',MODx.panel.Dashboards);
  46. MODx.grid.Dashboards = function(config) {
  47. config = config || {};
  48. this.sm = new Ext.grid.CheckboxSelectionModel();
  49. Ext.applyIf(config,{
  50. url: MODx.config.connector_url
  51. ,baseParams: {
  52. action: 'system/dashboard/getlist'
  53. }
  54. ,fields: ['id','name','description','cls']
  55. ,paging: true
  56. ,autosave: true
  57. ,save_action: 'system/dashboard/updatefromgrid'
  58. ,remoteSort: true
  59. ,sm: this.sm
  60. ,columns: [this.sm,{
  61. header: _('id')
  62. ,dataIndex: 'id'
  63. ,width: 50
  64. ,sortable: true
  65. },{
  66. header: _('name')
  67. ,dataIndex: 'name'
  68. ,width: 150
  69. ,sortable: true
  70. ,editor: { xtype: 'textfield' ,allowBlank: false }
  71. },{
  72. header: _('description')
  73. ,dataIndex: 'description'
  74. ,width: 300
  75. ,sortable: false
  76. ,editor: { xtype: 'textarea' }
  77. }]
  78. ,tbar: [{
  79. text: _('dashboard_create')
  80. ,cls:'primary-button'
  81. ,handler: this.createDashboard
  82. ,scope: this
  83. },{
  84. text: _('bulk_actions')
  85. ,menu: [{
  86. text: _('selected_remove')
  87. ,handler: this.removeSelected
  88. ,scope: this
  89. }]
  90. },'->',{
  91. xtype: 'modx-combo-usergroup'
  92. ,name: 'usergroup'
  93. ,id: 'modx-user-filter-usergroup'
  94. ,itemId: 'usergroup'
  95. ,emptyText: _('user_group_filter')+'...'
  96. ,baseParams: {
  97. action: 'security/group/getlist'
  98. ,addAll: true
  99. }
  100. ,value: ''
  101. ,width: 200
  102. ,listeners: {
  103. 'select': {fn:this.filterUsergroup,scope:this}
  104. }
  105. },{
  106. xtype: 'textfield'
  107. ,name: 'search'
  108. ,id: 'modx-dashboard-search'
  109. ,cls: 'x-form-filter'
  110. ,emptyText: _('search_ellipsis')
  111. ,listeners: {
  112. 'change': {fn: this.search, scope: this}
  113. ,'render': {fn: function(cmp) {
  114. new Ext.KeyMap(cmp.getEl(), {
  115. key: Ext.EventObject.ENTER
  116. ,fn: function() {
  117. this.fireEvent('change',this.getValue());
  118. this.blur();
  119. return true;}
  120. ,scope: cmp
  121. });
  122. },scope:this}
  123. }
  124. },{
  125. xtype: 'button'
  126. ,text: _('filter_clear')
  127. ,id: 'modx-filter-clear'
  128. ,cls: 'x-form-filter-clear'
  129. ,listeners: {
  130. 'click': {fn: this.clearFilter, scope: this},
  131. 'mouseout': { fn: function(evt){
  132. this.removeClass('x-btn-focus');
  133. }
  134. }
  135. }
  136. }]
  137. });
  138. MODx.grid.Dashboards.superclass.constructor.call(this,config);
  139. };
  140. Ext.extend(MODx.grid.Dashboards,MODx.grid.Grid,{
  141. getMenu: function() {
  142. var r = this.getSelectionModel().getSelected();
  143. var p = r.data.cls;
  144. var m = [];
  145. if (this.getSelectionModel().getCount() > 1) {
  146. m.push({
  147. text: _('selected_remove')
  148. ,handler: this.removeSelected
  149. ,scope: this
  150. });
  151. } else {
  152. if (p.indexOf('pupdate') != -1) {
  153. m.push({
  154. text: _('dashboard_update')
  155. ,handler: this.updateDashboard
  156. });
  157. }
  158. if (p.indexOf('pduplicate') != -1) {
  159. m.push({
  160. text: _('dashboard_duplicate')
  161. ,handler: this.duplicateDashboard
  162. });
  163. }
  164. if (p.indexOf('premove') != -1 && r.data.id != 1 && r.data.name != 'Default') {
  165. if (m.length > 0) m.push('-');
  166. m.push({
  167. text: _('dashboard_remove')
  168. ,handler: this.removeDashboard
  169. });
  170. }
  171. }
  172. if (m.length > 0) {
  173. this.addContextMenuItem(m);
  174. }
  175. }
  176. ,createDashboard: function() {
  177. MODx.loadPage('system/dashboards/create');
  178. }
  179. ,removeSelected: function() {
  180. var cs = this.getSelectedAsList();
  181. if (cs === false) return false;
  182. MODx.msg.confirm({
  183. title: _('dashboard_remove_multiple')
  184. ,text: _('dashboard_remove_multiple_confirm')
  185. ,url: this.config.url
  186. ,params: {
  187. action: 'system/dashboard/removeMultiple'
  188. ,dashboards: cs
  189. }
  190. ,listeners: {
  191. 'success': {fn:function(r) {
  192. this.getSelectionModel().clearSelections(true);
  193. this.refresh();
  194. },scope:this}
  195. }
  196. });
  197. return true;
  198. }
  199. ,removeDashboard: function() {
  200. MODx.msg.confirm({
  201. title: _('dashboard_remove')
  202. ,text: _('dashboard_remove_confirm')
  203. ,url: this.config.url
  204. ,params: {
  205. action: 'system/dashboard/remove'
  206. ,id: this.menu.record.id
  207. }
  208. ,listeners: {
  209. 'success': {fn:this.refresh,scope:this}
  210. }
  211. });
  212. }
  213. ,duplicateDashboard: function(btn,e) {
  214. MODx.Ajax.request({
  215. url: this.config.url
  216. ,params: {
  217. action: 'system/dashboard/duplicate'
  218. ,id: this.menu.record.id
  219. }
  220. ,listeners: {
  221. 'success': {fn:this.refresh,scope:this}
  222. }
  223. });
  224. }
  225. ,updateDashboard: function() {
  226. MODx.loadPage('system/dashboards/update', 'id='+this.menu.record.id);
  227. }
  228. ,filterUsergroup: function(cb,nv,ov) {
  229. this.getStore().baseParams.usergroup = Ext.isEmpty(nv) || Ext.isObject(nv) ? cb.getValue() : nv;
  230. this.getBottomToolbar().changePage(1);
  231. //this.refresh();
  232. return true;
  233. }
  234. ,search: function(tf,newValue,oldValue) {
  235. var nv = newValue || tf;
  236. this.getStore().baseParams.query = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  237. this.getBottomToolbar().changePage(1);
  238. //this.refresh();
  239. return true;
  240. }
  241. ,clearFilter: function() {
  242. this.getStore().baseParams = {
  243. action: 'system/dashboard/getList'
  244. };
  245. Ext.getCmp('modx-dashboard-search').reset();
  246. Ext.getCmp('modx-user-filter-usergroup').reset();
  247. this.getBottomToolbar().changePage(1);
  248. //this.refresh();
  249. }
  250. });
  251. Ext.reg('modx-grid-dashboards',MODx.grid.Dashboards);