ds.admin.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * @file
  3. * Javascript functionality for Display Suite's administration UI.
  4. */
  5. (function($) {
  6. Drupal.DisplaySuite = Drupal.DisplaySuite || {};
  7. Drupal.DisplaySuite.fieldopened = '';
  8. Drupal.DisplaySuite.layout_original = '';
  9. /**
  10. * Ctools selection content.
  11. */
  12. Drupal.behaviors.CToolsSelection = {
  13. attach: function (context) {
  14. if ($('#ctools-content-selection').length > 0) {
  15. $('#ctools-content-selection .section-link').click(function() {
  16. $('#ctools-content-selection .content').hide();
  17. container = $(this).attr('id') + '-container';
  18. $('#' + container).show();
  19. return false;
  20. });
  21. }
  22. }
  23. };
  24. /**
  25. * Save the Dynamic field content configuration.
  26. */
  27. $.fn.dsCtoolsContentConfiguration = function (configuration) {
  28. $(this[0]).val(configuration);
  29. }
  30. /**
  31. * Update the select content text.
  32. */
  33. $.fn.dsCtoolsContentUpdate = function () {
  34. $(this[0]).html(Drupal.t('Click update to save the configuration'));
  35. }
  36. /**
  37. * Save the page after saving a new field.
  38. */
  39. $.fn.dsRefreshDisplayTable = function () {
  40. $('#edit-submit').click();
  41. }
  42. /**
  43. * Row handlers for the 'Manage display' screen.
  44. */
  45. Drupal.fieldUIDisplayOverview = Drupal.fieldUIDisplayOverview || {};
  46. Drupal.fieldUIDisplayOverview.ds = function (row, data) {
  47. this.row = row;
  48. this.name = data.name;
  49. this.region = data.region;
  50. this.tableDrag = data.tableDrag;
  51. // Attach change listener to the 'region' select.
  52. this.$regionSelect = $('select.ds-field-region', row);
  53. this.$regionSelect.change(Drupal.fieldUIOverview.onChange);
  54. // Attach change listener to the 'formatter type' select.
  55. this.$formatSelect = $('select.field-formatter-type', row);
  56. this.$formatSelect.change(Drupal.fieldUIOverview.onChange);
  57. return this;
  58. };
  59. Drupal.fieldUIDisplayOverview.ds.prototype = {
  60. /**
  61. * Returns the region corresponding to the current form values of the row.
  62. */
  63. getRegion: function () {
  64. return this.$regionSelect.val();
  65. },
  66. /**
  67. * Reacts to a row being changed regions.
  68. *
  69. * This function is called when the row is moved to a different region, as a
  70. * result of either :
  71. * - a drag-and-drop action
  72. * - user input in one of the form elements watched by the
  73. * Drupal.fieldUIOverview.onChange change listener.
  74. *
  75. * @param region
  76. * The name of the new region for the row.
  77. * @return
  78. * A hash object indicating which rows should be AJAX-updated as a result
  79. * of the change, in the format expected by
  80. * Drupal.displayOverview.AJAXRefreshRows().
  81. */
  82. regionChange: function (region) {
  83. // Replace dashes with underscores.
  84. region = region.replace(/-/g, '_');
  85. // Set the region of the select list.
  86. this.$regionSelect.val(region);
  87. // Prepare rows to be refreshed in the form.
  88. var refreshRows = {};
  89. refreshRows[this.name] = this.$regionSelect.get(0);
  90. // If a row is handled by field_group module, loop through the children.
  91. if ($(this.row).hasClass('field-group') && $.isFunction(Drupal.fieldUIDisplayOverview.group.prototype.regionChangeFields)) {
  92. Drupal.fieldUIDisplayOverview.group.prototype.regionChangeFields(region, this, refreshRows);
  93. }
  94. return refreshRows;
  95. }
  96. };
  97. })(jQuery);