field_group.field_ui.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.$regionSelect = $(row).find('select.field-region');
  58. this.$regionSelect.on('change', Drupal.fieldUIOverview.onChange);
  59. return this;
  60. };
  61. Drupal.fieldUIDisplayOverview.group.prototype = {
  62. getRegion: function getRegion() {
  63. return this.$regionSelect.val();
  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 'region' select needs to be adjusted to
  69. // the new region.
  70. region = region.replace(/-/g, '_');
  71. this.$regionSelect.val(region);
  72. var refreshRows = {};
  73. refreshRows[this.name] = this.$regionSelect.get(0);
  74. if (recurse) {
  75. this.regionChangeFields(region, this, refreshRows);
  76. }
  77. return refreshRows;
  78. },
  79. regionChangeFields: function (region, element, refreshRows) {
  80. // Create a new tabledrag rowObject, that will compute the group's child
  81. // rows for us.
  82. var tableDrag = element.tableDrag;
  83. var rowObject = new tableDrag.row(element.row, 'mouse', true);
  84. // Skip the main row, we handled it above.
  85. rowObject.group.shift();
  86. // Let child rows handlers deal with the region change - without recursing
  87. // on nested group rows, we are handling them all here.
  88. $.each(rowObject.group, function () {
  89. var childRow = this;
  90. var childRowHandler = $(childRow).data('fieldUIRowHandler');
  91. $.extend(refreshRows, childRowHandler.regionChange(region, false));
  92. });
  93. }
  94. };
  95. })(jQuery);