modx.grid.user.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. MODx.panel.Users = function(config) {
  2. config = config || {};
  3. Ext.applyIf(config,{
  4. id: 'modx-panel-users'
  5. ,cls: 'container'
  6. ,bodyStyle: ''
  7. ,defaults: { collapsible: false ,autoHeight: true }
  8. ,items: [{
  9. html: _('users')
  10. ,id: 'modx-users-header'
  11. ,xtype: 'modx-header'
  12. },{
  13. layout: 'form'
  14. ,items: [{
  15. html: '<p>'+_('user_management_msg')+'</p>'
  16. ,xtype: 'modx-description'
  17. },{
  18. xtype: 'modx-grid-user'
  19. ,cls:'main-wrapper'
  20. ,preventRender: true
  21. }]
  22. }]
  23. });
  24. MODx.panel.Users.superclass.constructor.call(this,config);
  25. };
  26. Ext.extend(MODx.panel.Users,MODx.FormPanel);
  27. Ext.reg('modx-panel-users',MODx.panel.Users);
  28. MODx.grid.User = function(config) {
  29. config = config || {};
  30. this.sm = new Ext.grid.CheckboxSelectionModel();
  31. Ext.applyIf(config,{
  32. url: MODx.config.connector_url
  33. ,baseParams: {
  34. action: 'security/user/getList'
  35. ,usergroup: MODx.request['usergroup'] ? MODx.request['usergroup'] : ''
  36. }
  37. ,fields: ['id','username','fullname','email','gender','blocked','role','active','cls']
  38. ,paging: true
  39. ,autosave: true
  40. ,save_action: 'security/user/updatefromgrid'
  41. ,autosaveErrorMsg: _('user_err_save')
  42. ,remoteSort: true
  43. ,viewConfig: {
  44. forceFit:true
  45. ,enableRowBody:true
  46. ,scrollOffset: 0
  47. ,autoFill: true
  48. ,showPreview: true
  49. ,getRowClass : function(rec){
  50. return rec.data.active ? 'grid-row-active' : 'grid-row-inactive';
  51. }
  52. }
  53. ,sm: this.sm
  54. ,columns: [this.sm,{
  55. header: _('id')
  56. ,dataIndex: 'id'
  57. ,width: 50
  58. ,sortable: true
  59. },{
  60. header: _('name')
  61. ,dataIndex: 'username'
  62. ,width: 150
  63. ,sortable: true
  64. ,renderer: function(value, p, record){
  65. return String.format('<a href="?a=security/user/update&id={0}" title="{1}" class="x-grid-link">{2}</a>', record.id, _('user_update'), Ext.util.Format.htmlEncode( value ) );
  66. }
  67. },{
  68. header: _('user_full_name')
  69. ,dataIndex: 'fullname'
  70. ,width: 180
  71. ,sortable: true
  72. ,editor: { xtype: 'textfield' }
  73. ,renderer: Ext.util.Format.htmlEncode
  74. },{
  75. header: _('email')
  76. ,dataIndex: 'email'
  77. ,width: 180
  78. ,sortable: true
  79. ,editor: { xtype: 'textfield' }
  80. },{
  81. header: _('active')
  82. ,dataIndex: 'active'
  83. ,width: 80
  84. ,sortable: true
  85. ,editor: { xtype: 'combo-boolean', renderer: 'boolean' }
  86. },{
  87. header: _('user_block')
  88. ,dataIndex: 'blocked'
  89. ,width: 80
  90. ,sortable: true
  91. ,editor: { xtype: 'combo-boolean', renderer: 'boolean' }
  92. }]
  93. ,tbar: [{
  94. text: _('user_new')
  95. ,handler: this.createUser
  96. ,scope: this
  97. ,cls:'primary-button'
  98. },{
  99. text: _('bulk_actions')
  100. ,menu: [{
  101. text: _('selected_activate')
  102. ,handler: this.activateSelected
  103. ,scope: this
  104. },{
  105. text: _('selected_deactivate')
  106. ,handler: this.deactivateSelected
  107. ,scope: this
  108. },{
  109. text: _('selected_remove')
  110. ,handler: this.removeSelected
  111. ,scope: this
  112. }]
  113. },'->',{
  114. xtype: 'modx-combo-usergroup'
  115. ,name: 'usergroup'
  116. ,id: 'modx-user-filter-usergroup'
  117. ,itemId: 'usergroup'
  118. ,emptyText: _('user_group')+'...'
  119. ,baseParams: {
  120. action: 'security/group/getList'
  121. ,addAll: true
  122. }
  123. ,value: MODx.request['usergroup'] ? MODx.request['usergroup'] : ''
  124. ,width: 200
  125. ,listeners: {
  126. 'select': {fn:this.filterUsergroup,scope:this}
  127. }
  128. },{
  129. xtype: 'textfield'
  130. ,name: 'search'
  131. ,id: 'modx-user-search'
  132. ,cls: 'x-form-filter'
  133. ,emptyText: _('search_ellipsis')
  134. ,listeners: {
  135. 'change': {fn: this.search, scope: this}
  136. ,'render': {fn: function(cmp) {
  137. new Ext.KeyMap(cmp.getEl(), {
  138. key: Ext.EventObject.ENTER
  139. ,fn: this.blur
  140. ,scope: cmp
  141. });
  142. },scope:this}
  143. }
  144. },{
  145. xtype: 'button'
  146. ,id: 'modx-filter-clear'
  147. ,cls: 'x-form-filter-clear'
  148. ,text: _('filter_clear')
  149. ,listeners: {
  150. 'click': {fn: this.clearFilter, scope: this},
  151. 'mouseout': { fn: function(evt){
  152. this.removeClass('x-btn-focus');
  153. }
  154. }
  155. }
  156. }]
  157. });
  158. MODx.grid.User.superclass.constructor.call(this,config);
  159. };
  160. Ext.extend(MODx.grid.User,MODx.grid.Grid,{
  161. getMenu: function() {
  162. var r = this.getSelectionModel().getSelected();
  163. var p = r.data.cls;
  164. var m = [];
  165. if (this.getSelectionModel().getCount() > 1) {
  166. m.push({
  167. text: _('selected_activate')
  168. ,handler: this.activateSelected
  169. ,scope: this
  170. });
  171. m.push({
  172. text: _('selected_deactivate')
  173. ,handler: this.deactivateSelected
  174. ,scope: this
  175. });
  176. m.push('-');
  177. m.push({
  178. text: _('selected_remove')
  179. ,handler: this.removeSelected
  180. ,scope: this
  181. });
  182. } else {
  183. if (p.indexOf('pupdate') != -1) {
  184. m.push({
  185. text: _('user_update')
  186. ,handler: this.updateUser
  187. });
  188. }
  189. if (p.indexOf('pcopy') != -1) {
  190. if (m.length > 0) m.push('-');
  191. m.push({
  192. text: _('user_duplicate')
  193. ,handler: this.duplicateUser
  194. });
  195. }
  196. if (p.indexOf('premove') != -1) {
  197. if (m.length > 0) m.push('-');
  198. m.push({
  199. text: _('user_remove')
  200. ,handler: this.removeUser
  201. });
  202. }
  203. }
  204. if (m.length > 0) {
  205. this.addContextMenuItem(m);
  206. }
  207. }
  208. ,createUser: function() {
  209. MODx.loadPage('security/user/create');
  210. }
  211. ,activateSelected: function() {
  212. var cs = this.getSelectedAsList();
  213. if (cs === false) return false;
  214. MODx.Ajax.request({
  215. url: this.config.url
  216. ,params: {
  217. action: 'security/user/activateMultiple'
  218. ,users: cs
  219. }
  220. ,listeners: {
  221. 'success': {fn:function(r) {
  222. this.getSelectionModel().clearSelections(true);
  223. this.refresh();
  224. },scope:this}
  225. }
  226. });
  227. return true;
  228. }
  229. ,deactivateSelected: function() {
  230. var cs = this.getSelectedAsList();
  231. if (cs === false) return false;
  232. MODx.Ajax.request({
  233. url: this.config.url
  234. ,params: {
  235. action: 'security/user/deactivateMultiple'
  236. ,users: cs
  237. }
  238. ,listeners: {
  239. 'success': {fn:function(r) {
  240. this.getSelectionModel().clearSelections(true);
  241. this.refresh();
  242. },scope:this}
  243. }
  244. });
  245. return true;
  246. }
  247. ,removeSelected: function() {
  248. var cs = this.getSelectedAsList();
  249. if (cs === false) return false;
  250. MODx.msg.confirm({
  251. title: _('user_remove_multiple')
  252. ,text: _('user_remove_multiple_confirm')
  253. ,url: this.config.url
  254. ,params: {
  255. action: 'security/user/removeMultiple'
  256. ,users: cs
  257. }
  258. ,listeners: {
  259. 'success': {fn:function(r) {
  260. this.getSelectionModel().clearSelections(true);
  261. this.refresh();
  262. },scope:this}
  263. }
  264. });
  265. return true;
  266. }
  267. ,removeUser: function() {
  268. MODx.msg.confirm({
  269. title: _('user_remove')
  270. ,text: _('user_confirm_remove')
  271. ,url: this.config.url
  272. ,params: {
  273. action: 'security/user/delete'
  274. ,id: this.menu.record.id
  275. }
  276. ,listeners: {
  277. 'success': {fn:this.refresh,scope:this}
  278. }
  279. });
  280. }
  281. ,duplicateUser: function() {
  282. MODx.Ajax.request({
  283. url: this.config.url
  284. ,params: {
  285. action: 'security/user/duplicate'
  286. ,id: this.menu.record.id
  287. }
  288. ,listeners: {
  289. 'success': {fn:this.refresh,scope:this}
  290. }
  291. });
  292. }
  293. ,updateUser: function() {
  294. MODx.loadPage('security/user/update', 'id='+this.menu.record.id);
  295. }
  296. ,rendGender: function(d,c) {
  297. switch(d.toString()) {
  298. case '0':
  299. return '-';
  300. case '1':
  301. return _('male');
  302. case '2':
  303. return _('female');
  304. }
  305. }
  306. ,filterUsergroup: function(cb,nv,ov) {
  307. this.getStore().baseParams.usergroup = Ext.isEmpty(nv) || Ext.isObject(nv) ? cb.getValue() : nv;
  308. this.getBottomToolbar().changePage(1);
  309. return true;
  310. }
  311. ,search: function(tf,newValue,oldValue) {
  312. var nv = newValue || tf;
  313. this.getStore().baseParams.query = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  314. this.getBottomToolbar().changePage(1);
  315. return true;
  316. }
  317. ,clearFilter: function() {
  318. this.getStore().baseParams = {
  319. action: 'security/user/getList'
  320. };
  321. Ext.getCmp('modx-user-search').reset();
  322. Ext.getCmp('modx-user-filter-usergroup').reset();
  323. this.getBottomToolbar().changePage(1);
  324. }
  325. });
  326. Ext.reg('modx-grid-user',MODx.grid.User);