field_group.field_ui.js 4.0 KB

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