service.grid.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. HybridAuth.grid.Services = function (config) {
  2. config = config || {};
  3. var baseParams = {
  4. action: 'mgr/service/getlist'
  5. };
  6. if (config.userId) {
  7. baseParams.user_id = config.userId;
  8. }
  9. Ext.applyIf(config, {
  10. url: HybridAuth.config.connectorUrl,
  11. id: 'ha-row',
  12. baseParams: baseParams,
  13. remoteSort: true,
  14. paging: true,
  15. preventRender: true,
  16. sm: new Ext.grid.CheckboxSelectionModel(),
  17. fields: this.getFields(config),
  18. columns: this.getColumns(config)
  19. });
  20. HybridAuth.grid.Services.superclass.constructor.call(this, config);
  21. };
  22. Ext.extend(HybridAuth.grid.Services, MODx.grid.Grid, {
  23. getMenu: function (grid, rowIndex) {
  24. var ids = this._getSelectedIds();
  25. var row = grid.getStore().getAt(rowIndex);
  26. var menu = HybridAuth.utils.getMenu(row.data['actions'], this, ids);
  27. this.addContextMenuItem(menu);
  28. },
  29. getFields: function () {
  30. return [
  31. 'id',
  32. 'hash',
  33. 'createdon',
  34. 'provider',
  35. 'identifier',
  36. 'profileurl',
  37. 'photourl',
  38. 'displayname',
  39. 'email',
  40. 'actions'
  41. ]
  42. },
  43. getColumns: function () {
  44. return [{
  45. header: '',
  46. dataIndex: 'hash',
  47. sortable: false,
  48. width: 45,
  49. renderer: this._renderAvatar,
  50. id: 'avatar'
  51. }, {
  52. header: _('ha.service_createdon'),
  53. dataIndex: 'createdon',
  54. sortable: true
  55. }, {
  56. header: _('ha.service_provider'),
  57. dataIndex: 'provider',
  58. sortable: true
  59. }, {
  60. header: _('ha.service_identifier'),
  61. dataIndex: 'identifier',
  62. sortable: true,
  63. renderer: this._renderProfileUrl
  64. }, {
  65. header: _('ha.service_displayname'),
  66. dataIndex: 'displayname',
  67. sortable: true
  68. }, {
  69. header: _('ha.service_email'),
  70. dataIndex: 'email',
  71. sortable: true,
  72. renderer: this._renderEmail
  73. }, {
  74. header: '',
  75. dataIndex: 'actions',
  76. renderer: HybridAuth.utils.renderActions,
  77. sortable: false,
  78. width: 35,
  79. id: 'actions'
  80. }];
  81. },
  82. removeItem: function () {
  83. var ids = this._getSelectedIds();
  84. if (!ids.length) {
  85. return false;
  86. }
  87. MODx.msg.confirm({
  88. title: ids.length > 1
  89. ? _('ha.services_remove')
  90. : _('ha.service_remove'),
  91. text: ids.length > 1
  92. ? _('ha.services_remove_confirm')
  93. : _('ha.service_remove_confirm'),
  94. url: this.config.url,
  95. params: {
  96. action: 'mgr/service/remove',
  97. ids: Ext.util.JSON.encode(ids),
  98. },
  99. listeners: {
  100. success: {
  101. fn: function () {
  102. this.refresh();
  103. }, scope: this
  104. }
  105. }
  106. });
  107. return true;
  108. },
  109. onClick: function (e) {
  110. var elem = e.getTarget();
  111. if (elem.nodeName == 'BUTTON') {
  112. var row = this.getSelectionModel().getSelected();
  113. if (typeof(row) != 'undefined') {
  114. var action = elem.getAttribute('action');
  115. if (action == 'showMenu') {
  116. var ri = this.getStore().find('id', row.id);
  117. return this._showMenu(this, ri, e);
  118. }
  119. else if (typeof this[action] === 'function') {
  120. this.menu.record = row.data;
  121. return this[action](this, e);
  122. }
  123. }
  124. }
  125. return this.processEvent('click', e);
  126. },
  127. _getSelectedIds: function () {
  128. var ids = [];
  129. var selected = this.getSelectionModel().getSelections();
  130. for (var i in selected) {
  131. if (!selected.hasOwnProperty(i)) {
  132. continue;
  133. }
  134. ids.push(selected[i]['id']);
  135. }
  136. return ids;
  137. },
  138. _renderAvatar: function (v, md, record) {
  139. return '<img src="//gravatar.com/avatar/' + v + '?d=' +
  140. encodeURIComponent(record.get('photourl')) + '&s=80&d=mm"/>';
  141. },
  142. _renderProfileUrl: function (v, md, record) {
  143. var url = record.get('profileurl');
  144. if (typeof(url) == 'string') {
  145. url = url.trim();
  146. if (url != '') {
  147. return '<a href="' + url + '" target="_blank" style="color:#428bca;">' + v + '</a>';
  148. }
  149. }
  150. return v;
  151. },
  152. _renderEmail: function (v) {
  153. return '<a href="mailto:' + v + '" style="color:#428bca;">' + v + '</a>';
  154. }
  155. });
  156. Ext.reg('hybridauth-grid-services', HybridAuth.grid.Services);