encryption.grid.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. FormIt.grid.Encryptions = function(config) {
  2. config = config || {};
  3. config.tbar = ['->', {
  4. xtype : 'textfield',
  5. name : 'formit-filter-encryptions-search',
  6. id : 'formit-filter-encryptions-search',
  7. emptyText : _('search') + '...',
  8. listeners : {
  9. 'change' : {
  10. fn : this.filterSearch,
  11. scope : this
  12. },
  13. 'render' : {
  14. fn : function(cmp) {
  15. new Ext.KeyMap(cmp.getEl(), {
  16. key : Ext.EventObject.ENTER,
  17. fn : this.blur,
  18. scope : cmp
  19. });
  20. },
  21. scope : this
  22. }
  23. }
  24. }, {
  25. xtype : 'button',
  26. cls : 'x-form-filter-clear',
  27. id : 'formit-filter-encryptions-clear',
  28. text : _('filter_clear'),
  29. listeners : {
  30. 'click' : {
  31. fn : this.clearFilter,
  32. scope : this
  33. }
  34. }
  35. }];
  36. var columns = [{
  37. header : _('formit.label_form_name'),
  38. dataIndex : 'form',
  39. sortable : true,
  40. editable : false,
  41. width : 250
  42. }, {
  43. header : _('formit.label_form_encrypted'),
  44. dataIndex : 'encrypted',
  45. sortable : true,
  46. editable : false,
  47. width : 150,
  48. fixed : true
  49. }, {
  50. header : _('formit.label_form_decrypted'),
  51. dataIndex : 'decrypted',
  52. sortable : true,
  53. editable : false,
  54. width : 150,
  55. fixed : true
  56. }, {
  57. header : _('formit.label_form_total'),
  58. dataIndex : 'total',
  59. sortable : true,
  60. editable : false,
  61. width : 150,
  62. fixed : true,
  63. renderer : this.renderTotal
  64. }];
  65. Ext.applyIf(config,{
  66. columns : columns,
  67. url : FormIt.config.connector_url,
  68. baseParams : {
  69. action : 'mgr/encryption/getlist'
  70. },
  71. fields : ['form', 'encrypted', 'decrypted'],
  72. paging : true,
  73. pageSize : MODx.config.default_per_page > 30 ? MODx.config.default_per_page : 30,
  74. remoteSort : true,
  75. refreshGrid : [],
  76. });
  77. FormIt.grid.Encryptions.superclass.constructor.call(this, config);
  78. };
  79. Ext.extend(FormIt.grid.Encryptions, MODx.grid.Grid, {
  80. filterSearch: function(tf, nv, ov) {
  81. this.getStore().baseParams.query = tf.getValue();
  82. this.getBottomToolbar().changePage(1);
  83. },
  84. clearFilter: function() {
  85. this.getStore().baseParams.query = '';
  86. Ext.getCmp('formit-filter-encryptions-search').reset();
  87. this.getBottomToolbar().changePage(1);
  88. },
  89. getMenu: function() {
  90. var menu = [];
  91. if (FormIt.config.openssl) {
  92. if (this.menu.record.decrypted > 0) {
  93. menu.push({
  94. text : '<i class="x-menu-item-icon icon icon-lock"></i>' + _('formit.form_encrypt'),
  95. handler : this.encryptAll
  96. });
  97. }
  98. if (this.menu.record.encrypted > 0) {
  99. menu.push({
  100. text : '<i class="x-menu-item-icon icon icon-unlock"></i>' + _('formit.form_decrypt'),
  101. handler : this.decryptAll
  102. });
  103. }
  104. }
  105. return menu;
  106. },
  107. refreshGrids: function() {
  108. var grids = this.config.refreshGrid;
  109. if (typeof this.config.refreshGrid === 'string') {
  110. if (Ext.getCmp(this.config.refreshGrid)) {
  111. Ext.getCmp(this.config.refreshGrid).refresh();
  112. }
  113. } else {
  114. this.config.refreshGrid.forEach(function(grid) {
  115. if (Ext.getCmp(grid)) {
  116. Ext.getCmp(grid).refresh();
  117. }
  118. });
  119. }
  120. this.refresh();
  121. },
  122. encryptAll: function(btn, e) {
  123. MODx.msg.confirm({
  124. title : _('formit.form_encrypt'),
  125. text : _('formit.form_encrypt_confirm'),
  126. url : FormIt.config.connector_url,
  127. params : {
  128. action : 'mgr/encryption/encrypt',
  129. form : this.menu.record.form
  130. },
  131. listeners : {
  132. 'success' : {
  133. fn : this.refreshGrids,
  134. scope : this
  135. }
  136. }
  137. });
  138. },
  139. decryptAll: function(btn, e) {
  140. MODx.msg.confirm({
  141. title : _('formit.form_decrypt'),
  142. text : _('formit.form_decrypt_confirm'),
  143. url : FormIt.config.connector_url,
  144. params : {
  145. action : 'mgr/encryption/decrypt',
  146. form : this.menu.record.form
  147. },
  148. listeners : {
  149. 'success' : {
  150. fn : this.refreshGrids,
  151. scope : this
  152. }
  153. }
  154. });
  155. },
  156. renderTotal: function(d, c, e) {
  157. return e.json.encrypted + e.json.decrypted;
  158. }
  159. });
  160. Ext.reg('formit-grid-encryptions', FormIt.grid.Encryptions);