diff --git a/core/misc/dialog.ajax.js b/core/misc/dialog.ajax.js index c56515b..3ed9b2a 100644 --- a/core/misc/dialog.ajax.js +++ b/core/misc/dialog.ajax.js @@ -24,9 +24,10 @@ if ($dialog.length) { // Remove and replace the dialog buttons with those from the new form. if ($dialog.dialog('option', 'drupalAutoButtons')) { - var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); - $dialog.dialog('option', 'buttons', buttons); + // Trigger an event to detect/sync changes to buttons. + $dialog.trigger('dialogButtonsChange'); } + // Refocus the first input element after validation errors. if ($context.find('form').length) { $context.find('input:first').focus(); @@ -61,7 +62,7 @@ 'text': $originalButton.html() || $originalButton.attr('value'), 'class': $originalButton.attr('class'), 'click': function (e) { - $originalButton.trigger('click'); + $originalButton.trigger('mousedown').trigger('click').trigger('mouseup'); e.preventDefault(); } }); @@ -98,6 +99,12 @@ response.dialogOptions.buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); } + // Bind dialogButtonsChange + $dialog.on('dialogButtonsChange', function() { + var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); + $dialog.dialog('option', 'buttons', buttons); + }); + // Open the dialog itself. response.dialogOptions = response.dialogOptions || {}; var dialog = Drupal.dialog($dialog, response.dialogOptions); @@ -107,6 +114,9 @@ else { dialog.show(); } + + // Add the standard Drupal class for buttons for style consistency. + $dialog.parent().find('.ui-dialog-buttonset').addClass('form-actions'); }; /** @@ -119,6 +129,9 @@ if ($dialog.length) { Drupal.dialog($dialog).close(); } + + // Unbind dialogButtonsChange + $dialog.off('dialogButtonsChange'); }; /** diff --git a/core/misc/dialog.js b/core/misc/dialog.js index 94f2101..d7108e9 100644 --- a/core/misc/dialog.js +++ b/core/misc/dialog.js @@ -76,6 +76,7 @@ Drupal.dialog = function (element, options) { } } $element.dialog('option', adjustedOptions); + $element.trigger('dialogContentResize'); } var undef; diff --git a/core/misc/dialog.theme.css b/core/misc/dialog.theme.css index 360e6ae..581c03b 100644 --- a/core/misc/dialog.theme.css +++ b/core/misc/dialog.theme.css @@ -38,43 +38,6 @@ padding: 0; } -.ui-dialog .ui-dialog-buttonpane button { - background: #fefefe; - background-image: -webkit-linear-gradient(top, #fefefe, #e0e0e0); - background-image: -moz-linear-gradient(top, #fefefe, #e0e0e0); - background-image: -o-linear-gradient(top, #fefefe, #e0e0e0); - background-image: linear-gradient(to bottom, #fefefe, #e0e0e0); - border: 1px solid #c8c8c8; - border-radius: 3px; - text-decoration: none; - padding: 6px 17px 6px 17px; -} -.ui-dialog .ui-dialog-buttonpane button:hover, -.ui-dialog .ui-dialog-buttonpane button:focus { - background: #fefefe; - background-image: -webkit-linear-gradient(top, #fefefe, #eaeaea); - background-image: -moz-linear-gradient(top, #fefefe, #eaeaea); - background-image: -o-linear-gradient(top, #fefefe, #eaeaea); - background-image: linear-gradient(to bottom, #fefefe, #eaeaea); - -webkit-box-shadow: 1px 1px 3px rgba(50, 50, 50, 0.1); - box-shadow: 1px 1px 3px rgba(50, 50, 50, 0.1); - color: #2e2e2e; - text-decoration: none; -} -.ui-dialog .ui-dialog-buttonpane button:active { - border: 1px solid #c8c8c8; - background: #fefefe; - background-image: -webkit-linear-gradient(top, #eaeaea, #fefefe); - background-image: -moz-linear-gradient(top, #eaeaea, #fefefe); - background-image: -o-linear-gradient(top, #eaeaea, #fefefe); - background-image: linear-gradient(to bottom, #eaeaea, #fefefe); - -webkit-box-shadow: 1px 1px 3px rgba(50, 50, 50, 0.1); - box-shadow: 1px 1px 3px rgba(50, 50, 50, 0.1); - color: #2e2e2e; - text-decoration: none; - text-shadow: none; -} - /* Form action buttons are moved in dialogs. Remove empty space. */ .ui-dialog .ui-dialog-content .form-actions { padding: 0; diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 5b91aaa..0a394c2 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -418,7 +418,7 @@ public function buildOptionsForm(&$form, &$form_state) { '#options' => $formatters, '#default_value' => $this->options['type'], '#ajax' => array( - 'path' => views_ui_build_form_url($form_state), + 'path' => views_ui_build_form_path($form_state), ), '#submit' => array(array($this, 'submitTemporaryForm')), '#executes_submit_callback' => TRUE, diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 03f9042..089d268 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1088,7 +1088,7 @@ function system_library_info() { array('system', 'drupal'), array('system', 'drupal.debounce'), array('system', 'drupalSettings'), - array('system', 'jquery.ui.dialog') + array('system', 'jquery.ui.dialog'), ), ); diff --git a/core/modules/views/includes/ajax.inc b/core/modules/views/includes/ajax.inc index 788d1c1..a2832a7 100644 --- a/core/modules/views/includes/ajax.inc +++ b/core/modules/views/includes/ajax.inc @@ -6,7 +6,7 @@ */ use Drupal\views\Ajax\HighlightCommand; -use Drupal\views\Ajax\SetFormCommand; +use Drupal\Core\Ajax\OpenModalDialogCommand; use Drupal\Core\Ajax\AjaxResponse; /** @@ -52,10 +52,12 @@ function views_ajax_form_wrapper($form_id, &$form_state) { $display .= $output; $title = empty($form_state['title']) ? '' : $form_state['title']; + $options = array( + 'dialogClass' => 'views-ui-dialog', + 'width' => '50%', + ); - $url = empty($form_state['url']) ? url(current_path(), array('absolute' => TRUE)) : $form_state['url']; - - $response->addCommand(new SetFormCommand($display, $title, $url)); + $response->addCommand(new OpenModalDialogCommand($title, $display, $options)); if (!empty($form_state['#section'])) { $response->addCommand(new HighlightCommand('.' . drupal_clean_css_identifier($form_state['#section']))); diff --git a/core/modules/views/js/jquery.ui.dialog.patch.js b/core/modules/views/js/jquery.ui.dialog.patch.js deleted file mode 100644 index 1fb9b0b..0000000 --- a/core/modules/views/js/jquery.ui.dialog.patch.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * This is part of a patch to address a jQueryUI bug. The bug is responsible - * for the inability to scroll a page when a modal dialog is active. If the content - * of the dialog extends beyond the bottom of the viewport, the user is only able - * to scroll with a mousewheel or up/down keyboard keys. - * - * @see http://bugs.jqueryui.com/ticket/4671 - * @see https://bugs.webkit.org/show_bug.cgi?id=19033 - * @see views_ui.module - * @see js/jquery.ui.dialog.min.js - * - * This javascript patch overwrites the $.ui.dialog.overlay.events object to remove - * the mousedown, mouseup and click events from the list of events that are bound - * in $.ui.dialog.overlay.create - * - * The original code for this object: - * $.ui.dialog.overlay.events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','), - * function(event) { return event + '.dialog-overlay'; }).join(' '), - * - */ - -(function ($, undefined) { - - "use strict"; - - if ($.ui && $.ui.dialog) { - $.ui.dialog.overlay.events = $.map('focus,keydown,keypress'.split(','), - function(event) { return event + '.dialog-overlay'; }).join(' '); - } -}(jQuery)); diff --git a/core/modules/views/lib/Drupal/views/Ajax/DismissFormCommand.php b/core/modules/views/lib/Drupal/views/Ajax/DismissFormCommand.php deleted file mode 100644 index a32b7fe..0000000 --- a/core/modules/views/lib/Drupal/views/Ajax/DismissFormCommand.php +++ /dev/null @@ -1,28 +0,0 @@ - 'viewsDismissForm', - ); - } - -} diff --git a/core/modules/views/lib/Drupal/views/Ajax/SetFormCommand.php b/core/modules/views/lib/Drupal/views/Ajax/SetFormCommand.php deleted file mode 100644 index e3c4ffa..0000000 --- a/core/modules/views/lib/Drupal/views/Ajax/SetFormCommand.php +++ /dev/null @@ -1,71 +0,0 @@ -output = $output; - $this->title = $title; - $this->url = $url; - } - - /** - * Implements \Drupal\Core\Ajax\CommandInterface::render(). - */ - public function render() { - $command = array( - 'command' => 'viewsSetForm', - 'output' => $this->output, - 'title' => $this->title, - ); - if (isset($this->url)) { - $command['url'] = $this->url; - } - return $command; - } - -} diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index aeea6b2..cd8262a 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -351,7 +351,7 @@ function views_ui_standard_display_dropdown(&$form, &$form_state, $section) { // @todo Move this to a separate function if it's needed on any forms that // don't have the display dropdown. $form['override'] = array( - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', '#weight' => -1000, '#tree' => TRUE, @@ -401,20 +401,20 @@ function views_ui_standard_display_dropdown(&$form, &$form_state, $section) { } /** - * Create the URL for one of our standard AJAX forms based upon known + * Create the menu path for one of our standard AJAX forms based upon known * information about the form. */ -function views_ui_build_form_url($form_state) { +function views_ui_build_form_path($form_state) { $ajax = empty($form_state['ajax']) ? 'nojs' : 'ajax'; $name = $form_state['view']->id(); - $url = "admin/structure/views/$ajax/$form_state[form_key]/$name/$form_state[display_id]"; + $path = "admin/structure/views/$ajax/$form_state[form_key]/$name/$form_state[display_id]"; if (isset($form_state['type'])) { - $url .= '/' . $form_state['type']; + $path .= '/' . $form_state['type']; } if (isset($form_state['id'])) { - $url .= '/' . $form_state['id']; + $path .= '/' . $form_state['id']; } - return $url; + return $path; } /** diff --git a/core/modules/views_ui/css/views_ui.admin.css b/core/modules/views_ui/css/views_ui.admin.css index 893a34d..b4a53b7 100644 --- a/core/modules/views_ui/css/views_ui.admin.css +++ b/core/modules/views_ui/css/views_ui.admin.css @@ -209,35 +209,6 @@ /* @end */ -/* @group Modal dialog box */ - -.views-ui-dialog { - /* We need this so the button is visible. */ - overflow: visible; - position: fixed; -} - -.views-ui-dialog .ui-dialog-titlebar-close { - border: 1px solid transparent; - display: block; - margin: 0; - padding: 0; - position: absolute; - right: 0; - top: 2px; - /* Make sure this is in front of the modal backdrop. */ - z-index: 1002; -} - -.views-ui-dialog .ui-dialog-titlebar { - padding: 0; - margin: 0; -} - -.views-ui-dialog .ui-dialog-title { - display: none; -} - .views-ui-dialog #views-ajax-popup { padding: 0; overflow: hidden; @@ -253,7 +224,6 @@ } .views-ui-dialog .scroll { - max-height: 400px; overflow: auto; } diff --git a/core/modules/views_ui/css/views_ui.admin.theme.css b/core/modules/views_ui/css/views_ui.admin.theme.css index bbc7d16..87a645b 100644 --- a/core/modules/views_ui/css/views_ui.admin.theme.css +++ b/core/modules/views_ui/css/views_ui.admin.theme.css @@ -783,25 +783,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{ * The contents of the popup dialog on the views edit form. */ -.views-ui-dialog { - font-size: small; - padding: 0; -} - .views-ui-dialog .ui-dialog-titlebar-close { - background: url("../images/close.png") no-repeat scroll 6px 3px #f3f4ee; - border-color: #aaa; - border-radius: 0 10px 12px 0; - border-style: solid; - border-width: 1px 1px 1px 0; - box-shadow: 0 -2px 0 rgba(0, 0, 0, 0.1); - height: 22px; - right: -28px; - top: 0; - width: 26px; -} - -.views-ui-dialog .ui-dialog-titlebar-close span { display: none; } @@ -847,6 +829,10 @@ ul#views-display-menu-tabs li.add ul.action-list li{ width: 200px; } +.views-ui-dialog .ui-dialog-content { + padding: 0; +} + .views-ui-dialog .views-filterable-options { margin-bottom: 10px; } @@ -902,16 +888,10 @@ ul#views-display-menu-tabs li.add ul.action-list li{ content: "\00A0\003E"; } -.views-ui-dialog .scroll { - border: 1px solid #ccc; - border-width: 1px 0; - padding: 8px 13px; -} - .views-ui-dialog details .item-list { padding-left: 2em; } - +/* .views-ui-dialog .form-buttons { background-color: #f3f4ee; padding: 8px 13px; @@ -920,7 +900,7 @@ ul#views-display-menu-tabs li.add ul.action-list li{ margin-bottom: 0; margin-right: 0; } - +*/ /* @end */ /* @group Configure filter criteria */ diff --git a/core/modules/views_ui/js/ajax.js b/core/modules/views_ui/js/ajax.js index dc327ee..487cf6b 100644 --- a/core/modules/views_ui/js/ajax.js +++ b/core/modules/views_ui/js/ajax.js @@ -6,42 +6,6 @@ "use strict"; - Drupal.AjaxCommands.prototype.viewsSetForm = function (ajax, response, status) { - var ajax_title = drupalSettings.views.ajax.title; - var ajax_body = drupalSettings.views.ajax.id; - var ajax_popup = drupalSettings.views.ajax.popup; - $(ajax_title).html('

' + response.title + '

'); - $(ajax_body).html(response.output); - $(ajax_popup).dialog('open'); - Drupal.attachBehaviors($(ajax_popup), ajax.settings); - if (response.url) { - // Identify the button that was clicked so that .ajaxSubmit() can use it. - // We need to do this for both .click() and .mousedown() since JavaScript - // code might trigger either behavior. - var $submit_buttons = $('input[type=submit], button', ajax_body); - $submit_buttons.click(function(event) { - this.form.clk = this; - }); - $submit_buttons.mousedown(function(event) { - this.form.clk = this; - }); - - $('form', ajax_body).once('views-ajax-submit-processed').each(function() { - var element_settings = { 'url': response.url, 'event': 'submit', 'progress': { 'type': 'throbber' } }; - var $form = $(this); - var id = $form.attr('id'); - Drupal.ajax[id] = new Drupal.ajax(id, this, element_settings); - Drupal.ajax[id].form = $form; - }); - } - Drupal.viewsUi.resizeModal(); - }; - - Drupal.AjaxCommands.prototype.viewsDismissForm = function (ajax, response, status) { - Drupal.AjaxCommands.prototype.viewsSetForm({}, {'title': '', 'output': drupalSettings.views.ajax.defaultForm}); - $(drupalSettings.views.ajax.popup).dialog('close'); - }; - Drupal.AjaxCommands.prototype.viewsHighlight = function (ajax, response, status) { $('.hilited').removeClass('hilited'); $(response.selector).addClass('hilited'); @@ -113,20 +77,9 @@ Drupal.behaviors.viewsAjax = { collapseReplaced: false, attach: function (context, settings) { - if (!settings.views) { + /*if (!settings.views) { return; - } - // Create a jQuery UI dialog, but leave it closed. - var dialog_area = $(settings.views.ajax.popup, context); - dialog_area.dialog({ - 'autoOpen': false, - 'dialogClass': 'views-ui-dialog', - 'modal': true, - 'position': 'center', - 'resizable': false, - 'width': 750 - }); - + }*/ var base_element_settings = { 'event': 'click', 'progress': { 'type': 'throbber' } @@ -187,36 +140,6 @@ Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings); }); - if (!this.collapseReplaced && Drupal.collapseScrollIntoView) { - this.collapseReplaced = true; - Drupal.collapseScrollIntoView = function (node) { - for (var $parent = $(node); $parent.get(0) !== document && $parent.size() !== 0; $parent = $parent.parent()) { - if ($parent.css('overflow') === 'scroll' || $parent.css('overflow') === 'auto') { - if (Drupal.viewsUi.resizeModal) { - // If the modal is already at the max height, don't bother with - // this since the only reason to do it is to grow the modal. - if ($('.views-ui-dialog').height() < parseInt($(window).height() * 0.8, 10)) { - Drupal.viewsUi.resizeModal('', true); - } - } - return; - } - } - - var h = document.documentElement.clientHeight || document.body.clientHeight || 0; - var offset = document.documentElement.scrollTop || document.body.scrollTop || 0; - var posY = $(node).offset().top; - var fudge = 55; - if (posY + node.offsetHeight + fudge > h + offset) { - if (node.offsetHeight > h) { - window.scrollTo(0, posY); - } - else { - window.scrollTo(0, posY + node.offsetHeight - h + fudge); - } - } - }; - } } }; diff --git a/core/modules/views_ui/js/dialog.views.js b/core/modules/views_ui/js/dialog.views.js new file mode 100644 index 0000000..3217597 --- /dev/null +++ b/core/modules/views_ui/js/dialog.views.js @@ -0,0 +1,30 @@ +(function ($, Drupal, drupalSettings) { + + "use strict"; + Drupal.behaviors.viewsModalContent = { + attach: function () { + $('body').once('viewsDialog').on('dialogContentResize.viewsDialog', '.ui-dialog-content', function (e) { + var $modal = $(e.currentTarget); + var $viewsOverride = $modal.find('[data-drupal-views-offset]'); + var $scroll = $modal.find('[data-drupal-views-scroll]'); + var offset = 0; + var modalHeight = 0; + if ($viewsOverride.length && $scroll.length) { + modalHeight = $modal.height(); + $viewsOverride.each(function () { + offset += $(this).outerHeight(); + }); + + $scroll.height(modalHeight - offset); + $modal.css('overflow', 'hidden'); + } + }); + }, + detach: function (context, settings, trigger) { + if (trigger === 'unload') { + $('body').removeOnce('viewsDialog').off('.viewsDialog'); + } + } + }; + +})(jQuery, Drupal, drupalSettings); diff --git a/core/modules/views_ui/js/views-admin.js b/core/modules/views_ui/js/views-admin.js index bc5c6f0..add95fa 100644 --- a/core/modules/views_ui/js/views-admin.js +++ b/core/modules/views_ui/js/views-admin.js @@ -2,7 +2,7 @@ * @file * Some basic behaviors and utility functions for Views UI. */ -(function ($, Drupal, drupalSettings, debounce) { +(function ($, Drupal, drupalSettings) { "use strict"; @@ -162,11 +162,14 @@ $.extend(Drupal.viewsUi.FormFieldFiller.prototype, { Drupal.behaviors.addItemForm = { attach: function (context) { + var $context = $(context); + var $form = $context; // The add item form may have an id of views-ui-add-item-form--n. - var $form = $(context).find('form[id^="views-ui-add-item-form"]').first(); - // Make sure we don't add more than one event handler to the same form. - $form = $form.once('views-ui-add-item-form'); - if ($form.length) { + if (!$context.is('form[id^="views-ui-add-item-form"]')) { + $form = $context.find('form[id^="views-ui-add-item-form"]'); + } + if ($form.once('views-ui-add-item-form').length) { + // If we we have an unprocessed views-ui-add-item-form, let's instantiate. new Drupal.viewsUi.AddItemForm($form); } } @@ -212,8 +215,9 @@ Drupal.viewsUi.AddItemForm.prototype.handleCheck = function (event) { */ Drupal.viewsUi.AddItemForm.prototype.refreshCheckedItems = function () { // Perhaps we should precache the text div, too. - this.$selected_div.find('.views-selected-options').html(this.checkedItems.join(', ')); - Drupal.viewsUi.resizeModal('', true); + this.$selected_div.find('.views-selected-options') + .html(this.checkedItems.join(', ')) + .trigger('dialogContentResize'); }; /** @@ -868,7 +872,8 @@ Drupal.behaviors.viewsUiOverrideSelect = { attach: function (context) { $(context).find('#edit-override-dropdown').once('views-ui-override-button-text', function () { // Closures! :( - var $submit = $('#edit-submit'); + var $context = $(context); + var $submit = $context.find('[id^=edit-submit]'); var old_value = $submit.val(); $submit.once('views-ui-override-button-text') @@ -888,6 +893,8 @@ Drupal.behaviors.viewsUiOverrideSelect = { else { $submit.val(Drupal.t('Apply (this display)')); } + var $dialog = $context.closest('.ui-dialog-content'); + $dialog.trigger('dialogButtonsChange'); }) .trigger('change'); }); @@ -895,98 +902,6 @@ Drupal.behaviors.viewsUiOverrideSelect = { } }; -Drupal.viewsUi.resizeModal = function (e, no_shrink) { - var $modal = $('.views-ui-dialog'); - var $window = $(window); - var windowWidth = $window.width(); - var $scroll = $modal.find('.scroll'); - if ($modal.size() === 0 || $modal.css('display') === 'none') { - return; - } - - var maxWidth = parseInt(windowWidth * 0.85, 10); // 85% of window - var minWidth = parseInt(windowWidth * 0.6, 10); // 60% of window - - // Set the modal to the minwidth so that our width calculation of - // children works. - $modal.css('width', minWidth); - var width = minWidth; - - // Don't let the window get more than 80% of the display high. - var maxHeight = parseInt($window.height() * 0.8, 10); - var minHeight = 200; - if (no_shrink) { - minHeight = $modal.height(); - } - - if (minHeight > maxHeight) { - minHeight = maxHeight; - } - - var height = 0; - - // Calculate the height of the 'scroll' region. - var scrollHeight = 0; - - scrollHeight += parseInt($scroll.css('padding-top'), 10); - scrollHeight += parseInt($scroll.css('padding-bottom'), 10); - - $scroll.children().each(function () { - var w = $(this).innerWidth(); - if (w > width) { - width = w; - } - scrollHeight += $(this).outerHeight(true); - }); - - // Now, calculate what the difference between the scroll and the modal - // will be. - - var difference = 0; - difference += parseInt($scroll.css('padding-top'), 10); - difference += parseInt($scroll.css('padding-bottom'), 10); - difference += $('.views-override').outerHeight(true); - difference += $('.views-messages').outerHeight(true); - difference += $('#views-ajax-title').outerHeight(true); - difference += $('.views-add-form-selected').outerHeight(true); - difference += $('.form-buttons', $modal).outerHeight(true); - - height = scrollHeight + difference; - - if (height > maxHeight) { - height = maxHeight; - scrollHeight = maxHeight - difference; - } - else if (height < minHeight) { - height = minHeight; - scrollHeight = minHeight - difference; - } - - if (width > maxWidth) { - width = maxWidth; - } - - // Get where we should move content to - var top = ($(window).height() / 2) - (height / 2); - var left = ($(window).width() / 2) - (width / 2); - - $modal.css({ - 'top': top + 'px', - 'left': left + 'px', - 'width': width + 'px', - 'height': height + 'px' - }); - - // Ensure inner popup height matches. - $(drupalSettings.views.ajax.popup).css('height', height + 'px'); - - $scroll.css({ - 'height': scrollHeight + 'px', - 'max-height': scrollHeight + 'px' - }); - -}; - Drupal.behaviors.viewsUiHandlerRemoveLink = { attach: function (context) { var $context = $(context); @@ -1010,6 +925,4 @@ Drupal.behaviors.viewsUiHandlerRemoveLink = { } }; -$(window).on('resize scroll', debounce(Drupal.viewsUi.resizeModal, 100)); - -})(jQuery, Drupal, drupalSettings, Drupal.debounce); +})(jQuery, Drupal, drupalSettings); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/AddItem.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/AddItem.php index 6e03f73..33a1fdf 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/AddItem.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/AddItem.php @@ -56,7 +56,7 @@ public function buildForm(array $form, array &$form_state) { $form = array( 'options' => array( '#theme_wrappers' => array('container'), - '#attributes' => array('class' => array('scroll')), + '#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE), ), ); @@ -169,15 +169,18 @@ public function buildForm(array $form, array &$form_state) { '#type' => 'item', '#markup' => '' . $this->t('Selected:') . ' ' . '
', '#theme_wrappers' => array('form_element', 'views_ui_container'), - '#attributes' => array('class' => array('container-inline', 'views-add-form-selected')), + '#attributes' => array( + 'class' => array('container-inline', 'views-add-form-selected'), + 'data-drupal-views-offset' => 'bottom', + ), ); $view->getStandardButtons($form, $form_state, 'views_ui_add_item_form', $this->t('Add and configure @types', array('@types' => $ltitle))); // Remove the default submit function. - $form['buttons']['submit']['#submit'] = array_filter($form['buttons']['submit']['#submit'], function($var) { + $form['actions']['submit']['#submit'] = array_filter($form['actions']['submit']['#submit'], function($var) { return !(is_array($var) && isset($var[1]) && $var[1] == 'standardSubmit'); }); - $form['buttons']['submit']['#submit'][] = array($view, 'submitItemAdd'); + $form['actions']['submit']['#submit'][] = array($view, 'submitItemAdd'); return $form; } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItem.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItem.php index 26ad723..f393f9d 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItem.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItem.php @@ -60,7 +60,7 @@ public function buildForm(array $form, array &$form_state) { 'options' => array( '#tree' => TRUE, '#theme_wrappers' => array('container'), - '#attributes' => array('class' => array('scroll')), + '#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE), ), ); $executable = $view->getExecutable(); @@ -168,11 +168,14 @@ public function buildForm(array $form, array &$form_state) { $view->getStandardButtons($form, $form_state, 'views_ui_config_item_form', $name); // Add a 'remove' button. - $form['buttons']['remove'] = array( + $form['actions']['remove'] = array( '#type' => 'submit', '#value' => $this->t('Remove'), '#submit' => array(array($this, 'remove')), '#limit_validation_errors' => array(array('override')), + '#ajax' => array( + 'path' => current_path(), + ), ); } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItemExtra.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItemExtra.php index 56e282c..5fe4681 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItemExtra.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItemExtra.php @@ -59,7 +59,7 @@ public function buildForm(array $form, array &$form_state) { 'options' => array( '#tree' => true, '#theme_wrappers' => array('container'), - '#attributes' => array('class' => array('scroll')), + '#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE), ), ); $executable = $view->getExecutable(); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItemGroup.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItemGroup.php index 79e2b15..3b73800 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItemGroup.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ConfigItemGroup.php @@ -60,7 +60,7 @@ public function buildForm(array $form, array &$form_state) { 'options' => array( '#tree' => TRUE, '#theme_wrappers' => array('container'), - '#attributes' => array('class' => array('scroll')), + '#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE), ), ); $executable = $view->getExecutable(); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Display.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Display.php index c1729ef..b364459 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Display.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Display.php @@ -70,7 +70,7 @@ public function buildForm(array $form, array &$form_state) { // Get form from the handler. $form['options'] = array( '#theme_wrappers' => array('container'), - '#attributes' => array('class' => array('scroll')), + '#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE), ); $executable->display_handler->buildOptionsForm($form['options'], $form_state); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/EditDetails.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/EditDetails.php index 3c011f3..cf55abf 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/EditDetails.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/EditDetails.php @@ -40,7 +40,7 @@ public function buildForm(array $form, array &$form_state) { $form['details'] = array( '#theme_wrappers' => array('container'), - '#attributes' => array('class' => array('scroll')), + '#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE), ); $form['details']['label'] = array( '#type' => 'textfield', diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Rearrange.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Rearrange.php index b5364d0..62038ae 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Rearrange.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Rearrange.php @@ -80,7 +80,7 @@ public function buildForm(array $form, array &$form_state) { array('order', 'sibling', 'weight'), ), '#tree' => TRUE, - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', ); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/RearrangeFilter.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/RearrangeFilter.php index ebfbd48..3991f56 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/RearrangeFilter.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/RearrangeFilter.php @@ -204,7 +204,7 @@ public function buildForm(array $form, array &$form_state) { } $view->getStandardButtons($form, $form_state, 'views_ui_rearrange_filter_form'); - $form['buttons']['add_group'] = array( + $form['actions']['add_group'] = array( '#type' => 'submit', '#value' => $this->t('Create new filter group'), '#id' => 'views-add-group', diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php index 512ab2a..7c573a1 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ReorderDisplays.php @@ -63,7 +63,7 @@ public function buildForm(array $form, array &$form_state) { array('order', 'sibling', 'weight'), ), '#tree' => TRUE, - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', ); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ViewsFormBase.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ViewsFormBase.php index f4c83a5..9bc5802 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ViewsFormBase.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/ViewsFormBase.php @@ -11,6 +11,7 @@ use Drupal\views\ViewStorageInterface; use Drupal\views\Ajax; use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\CloseModalDialogCommand; use Symfony\Component\HttpFoundation\RedirectResponse; /** @@ -144,11 +145,11 @@ public function getForm(ViewStorageInterface $view, $display_id, $js) { $form_state = $reflection->newInstanceArgs(array_slice($top, 3, 2))->getFormState($view, $top[2], $form_state['ajax']); $form_state['input'] = array(); - $form_url = views_ui_build_form_url($form_state); + $form_path = views_ui_build_form_path($form_state); if (!$form_state['ajax']) { - return new RedirectResponse(url($form_url, array('absolute' => TRUE))); + return new RedirectResponse(url($form_path, array('absolute' => TRUE))); } - $form_state['url'] = url($form_url); + $form_state['path'] = $form_path; $response = views_ajax_form_wrapper($form_state['form_id'], $form_state); } elseif (!$form_state['ajax']) { @@ -157,7 +158,7 @@ public function getForm(ViewStorageInterface $view, $display_id, $js) { } else { $response = new AjaxResponse(); - $response->addCommand(new Ajax\DismissFormCommand()); + $response->addCommand(new CloseModalDialogCommand()); $response->addCommand(new Ajax\ShowButtonsCommand()); $response->addCommand(new Ajax\TriggerPreviewCommand()); if (!empty($form_state['#page_title'])) { diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php index 3de8091..6ce07c6 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -267,9 +267,8 @@ public function standardCancel($form, &$form_state) { * docblock outdated? */ public function getStandardButtons(&$form, &$form_state, $form_id, $name = NULL) { - $form['buttons'] = array( - '#prefix' => '
', - '#suffix' => '
', + $form['actions'] = array( + '#type' => 'actions', ); if (empty($name)) { @@ -280,12 +279,18 @@ public function getStandardButtons(&$form, &$form_state, $form_id, $name = NULL) $names = array(t('Apply'), t('Apply and continue')); } + // Views provides its own custom handling of AJAX form submissions. Usually + // this happens at the same path, but custom paths may be specified in + // $form_state. + $form_path = empty($form_state['path']) ? current_path() : $form_state['path']; + // Forms that are purely informational set an ok_button flag, so we know not // to create an "Apply" button for them. if (empty($form_state['ok_button'])) { - $form['buttons']['submit'] = array( + $form['actions']['submit'] = array( '#type' => 'submit', '#value' => $name, + '#id' => 'edit-submit-' . drupal_html_id($form_id), // The regular submit handler ($form_id . '_submit') does not apply if // we're updating the default display. It does apply if we're updating // the current display. Since we have no way of knowing at this point @@ -293,6 +298,9 @@ public function getStandardButtons(&$form, &$form_state, $form_id, $name = NULL) // take care of running the regular submit handler as appropriate. '#submit' => array(array($this, 'standardSubmit')), '#button_type' => 'primary', + '#ajax' => array( + 'path' => $form_path, + ), ); // Form API button click detection requires the button's #value to be the // same between the form build of the initial page request, and the @@ -304,25 +312,28 @@ public function getStandardButtons(&$form, &$form_state, $form_id, $name = NULL) // extending button click detection code to support any of the possible // button labels. if (isset($names)) { - $form['buttons']['submit']['#values'] = $names; - $form['buttons']['submit']['#process'] = array_merge(array('views_ui_form_button_was_clicked'), element_info_property($form['buttons']['submit']['#type'], '#process', array())); + $form['actions']['submit']['#values'] = $names; + $form['actions']['submit']['#process'] = array_merge(array('views_ui_form_button_was_clicked'), element_info_property($form['actions']['submit']['#type'], '#process', array())); } // If a validation handler exists for the form, assign it to this button. if (isset($form_state['build_info']['callback_object'])) { - $form['buttons']['submit']['#validate'][] = array($form_state['build_info']['callback_object'], 'validateForm'); + $form['actions']['submit']['#validate'][] = array($form_state['build_info']['callback_object'], 'validateForm'); } if (function_exists($form_id . '_validate')) { - $form['buttons']['submit']['#validate'][] = $form_id . '_validate'; + $form['actions']['submit']['#validate'][] = $form_id . '_validate'; } } // Create a "Cancel" button. For purely informational forms, label it "OK". $cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : array($this, 'standardCancel'); - $form['buttons']['cancel'] = array( + $form['actions']['cancel'] = array( '#type' => 'submit', '#value' => empty($form_state['ok_button']) ? t('Cancel') : t('Ok'), '#submit' => array($cancel_submit), '#validate' => array(), + '#ajax' => array( + 'path' => $form_path, + ), '#limit_validation_errors' => array(), ); @@ -331,9 +342,6 @@ public function getStandardButtons(&$form, &$form_state, $form_id, $name = NULL) if (isset($form['#title'])) { $form_state['title'] = $form['#title']; } - if (isset($form['#url'])) { - $form_state['url'] = $form['#url']; - } if (isset($form['#section'])) { $form_state['#section'] = $form['#section']; } diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module index 6da5339..0f76cbd 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -191,13 +191,13 @@ function views_ui_library_info() { 'version' => \Drupal::VERSION, 'js' => array( $path . 'ajax.js' => array('group' => JS_DEFAULT), + $path . 'dialog.views.js' => array('group' => JS_DEFAULT), $path . 'views-admin.js' => array('group' => JS_DEFAULT), ), 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), array('system', 'drupalSettings'), - array('system', 'drupal.debounce'), array('system', 'jquery.once'), array('system', 'jquery.form'), array('system', 'drupal.ajax'), diff --git a/core/modules/views_ui/views_ui.theme.inc b/core/modules/views_ui/views_ui.theme.inc index 38a8fe4..a13467e 100644 --- a/core/modules/views_ui/views_ui.theme.inc +++ b/core/modules/views_ui/views_ui.theme.inc @@ -276,7 +276,7 @@ function theme_views_ui_rearrange_filter_form(&$variables) { } $output = drupal_render($form['override']); - $output .= '
'; + $output .= '
'; if ($grouping) { $output .= drupal_render($form['filter_groups']['operator']); } @@ -315,7 +315,7 @@ function theme_views_ui_rearrange_filter_form(&$variables) { // When JavaScript is enabled, the button for adding a new group should be // hidden, since it will be replaced by a link on the client side. - $form['buttons']['add_group']['#attributes']['class'][] = 'js-hide'; + $form['actions']['add_group']['#attributes']['class'][] = 'js-hide'; // Render the rest of the form and return. $output .= drupal_render_children($form); diff --git a/core/themes/bartik/css/style.css b/core/themes/bartik/css/style.css index f74c184..eaa3061 100644 --- a/core/themes/bartik/css/style.css +++ b/core/themes/bartik/css/style.css @@ -1992,22 +1992,6 @@ div.admin-panel .description { background-color: #F9F9F9; } -.views-ui-dialog .ui-dialog-titlebar-close, -.views-ui-dialog #views-ajax-title, -.views-ui-dialog .views-override, -.views-ui-dialog .form-buttons { - background-color: #f6f6f6; -} - -.views-ui-dialog a { - color: #0071b3; -} - -.views-ui-dialog a:hover, -.views-ui-dialog a:focus { - color: #018fe2; -} - /* @end */ .views-display-column .details-wrapper {