utils.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. HybridAuth.utils.getMenu = function (actions, grid, selected) {
  2. var menu = [];
  3. var cls, icon, title, action;
  4. var has_delete = false;
  5. for (var i in actions) {
  6. if (!actions.hasOwnProperty(i)) {
  7. continue;
  8. }
  9. var a = actions[i];
  10. if (!a['menu']) {
  11. if (a == '-') {
  12. menu.push('-');
  13. }
  14. continue;
  15. }
  16. else if (menu.length > 0 && !has_delete && (/^remove/i.test(a['action']) || /^delete/i.test(a['action']))) {
  17. menu.push('-');
  18. has_delete = true;
  19. }
  20. if (selected.length > 1) {
  21. if (!a['multiple']) {
  22. continue;
  23. }
  24. else if (typeof(a['multiple']) == 'string') {
  25. a['title'] = a['multiple'];
  26. }
  27. }
  28. icon = a['icon'] ? a['icon'] : '';
  29. if (typeof(a['cls']) == 'object') {
  30. if (typeof(a['cls']['menu']) != 'undefined') {
  31. icon += ' ' + a['cls']['menu'];
  32. }
  33. }
  34. else {
  35. cls = a['cls'] ? a['cls'] : '';
  36. }
  37. title = a['title'] ? a['title'] : a['title'];
  38. action = a['action'] ? grid[a['action']] : '';
  39. menu.push({
  40. handler: action,
  41. text: String.format(
  42. '<span class="{0}"><i class="x-menu-item-icon {1}"></i>{2}</span>',
  43. cls, icon, title
  44. ),
  45. scope: grid
  46. });
  47. }
  48. return menu;
  49. };
  50. HybridAuth.utils.renderActions = function (value, props, row) {
  51. var res = [];
  52. var cls, icon, title, action, item;
  53. for (var i in row.data.actions) {
  54. if (!row.data.actions.hasOwnProperty(i)) {
  55. continue;
  56. }
  57. var a = row.data.actions[i];
  58. if (!a['button']) {
  59. continue;
  60. }
  61. icon = a['icon'] ? a['icon'] : '';
  62. if (typeof(a['cls']) == 'object') {
  63. if (typeof(a['cls']['button']) != 'undefined') {
  64. icon += ' ' + a['cls']['button'];
  65. }
  66. }
  67. else {
  68. cls = a['cls'] ? a['cls'] : '';
  69. }
  70. action = a['action'] ? a['action'] : '';
  71. title = a['title'] ? a['title'] : '';
  72. item = String.format(
  73. '<li class="{0}"><button class="btn btn-default {1}" action="{2}" title="{3}"></button></li>',
  74. cls, icon, action, title
  75. );
  76. res.push(item);
  77. }
  78. return String.format(
  79. '<ul class="ha-row-actions">{0}</ul>',
  80. res.join('')
  81. );
  82. };