field_group.field_ui.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. (function($) {
  2. Drupal.behaviors.fieldUIFieldsOverview = {
  3. attach: function (context, settings) {
  4. $('table#field-overview', context).once('field-field-overview', function() {
  5. Drupal.fieldUIOverview.attach(this, settings.fieldUIRowsData, Drupal.fieldUIFieldOverview);
  6. });
  7. }
  8. };
  9. /**
  10. * Row handlers for the 'Manage fields' screen.
  11. */
  12. Drupal.fieldUIFieldOverview = Drupal.fieldUIFieldOverview || {};
  13. Drupal.fieldUIFieldOverview.group = function(row, data) {
  14. this.row = row;
  15. this.name = data.name;
  16. this.region = data.region;
  17. this.tableDrag = data.tableDrag;
  18. // Attach change listener to the 'group format' select.
  19. this.$formatSelect = $('select.field-group-type', row);
  20. this.$formatSelect.change(Drupal.fieldUIOverview.onChange);
  21. return this;
  22. };
  23. Drupal.fieldUIFieldOverview.group.prototype = {
  24. getRegion: function () {
  25. return 'main';
  26. },
  27. regionChange: function (region, recurse) {
  28. return {};
  29. },
  30. regionChangeFields: function (region, element, refreshRows) {
  31. // Create a new tabledrag rowObject, that will compute the group's child
  32. // rows for us.
  33. var tableDrag = element.tableDrag;
  34. rowObject = new tableDrag.row(element.row, 'mouse', true);
  35. // Skip the main row, we handled it above.
  36. rowObject.group.shift();
  37. // Let child rows handlers deal with the region change - without recursing
  38. // on nested group rows, we are handling them all here.
  39. $.each(rowObject.group, function() {
  40. var childRow = this;
  41. var childRowHandler = $(childRow).data('fieldUIRowHandler');
  42. $.extend(refreshRows, childRowHandler.regionChange(region, false));
  43. });
  44. }
  45. };
  46. /**
  47. * Row handlers for the 'Manage display' screen.
  48. */
  49. Drupal.fieldUIDisplayOverview = Drupal.fieldUIDisplayOverview || {};
  50. Drupal.fieldUIDisplayOverview.group = function(row, data) {
  51. this.row = row;
  52. this.name = data.name;
  53. this.region = data.region;
  54. this.tableDrag = data.tableDrag;
  55. // Attach change listener to the 'group format' select.
  56. this.$formatSelect = $('select.field-group-type', row);
  57. this.$formatSelect.change(Drupal.fieldUIOverview.onChange);
  58. return this;
  59. };
  60. Drupal.fieldUIDisplayOverview.group.prototype = {
  61. getRegion: function () {
  62. return (this.$formatSelect.val() == 'hidden') ? 'hidden' : 'visible';
  63. },
  64. regionChange: function (region, recurse) {
  65. // Default recurse to true.
  66. recurse = (recurse == undefined) || recurse;
  67. // When triggered by a row drag, the 'format' select needs to be adjusted to
  68. // the new region.
  69. var currentValue = this.$formatSelect.val();
  70. switch (region) {
  71. case 'visible':
  72. if (currentValue == 'hidden') {
  73. // Restore the group format back to 'fieldset'.
  74. var value = 'fieldset';
  75. }
  76. break;
  77. default:
  78. var value = 'hidden';
  79. break;
  80. }
  81. if (value != undefined) {
  82. this.$formatSelect.val(value);
  83. }
  84. var refreshRows = {};
  85. refreshRows[this.name] = this.$formatSelect.get(0);
  86. if (recurse) {
  87. this.regionChangeFields(region, this, refreshRows);
  88. }
  89. return refreshRows;
  90. },
  91. regionChangeFields: function (region, element, refreshRows) {
  92. // Create a new tabledrag rowObject, that will compute the group's child
  93. // rows for us.
  94. var tableDrag = element.tableDrag;
  95. rowObject = new tableDrag.row(element.row, 'mouse', true);
  96. // Skip the main row, we handled it above.
  97. rowObject.group.shift();
  98. // Let child rows handlers deal with the region change - without recursing
  99. // on nested group rows, we are handling them all here.
  100. $.each(rowObject.group, function() {
  101. var childRow = this;
  102. var childRowHandler = $(childRow).data('fieldUIRowHandler');
  103. $.extend(refreshRows, childRowHandler.regionChange(region, false));
  104. });
  105. }
  106. };
  107. })(jQuery);