From 46e550f4a718584c054a36e8fa4ff6206b522b2f Mon Sep 17 00:00:00 2001 From: capynet Date: Sun, 26 Jan 2014 11:35:22 +0100 Subject: [PATCH] Re-roll --- .../lib/Drupal/system/Form/ModulesListForm.php | 6 ++ core/modules/system/system.modules.js | 78 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/core/modules/system/lib/Drupal/system/Form/ModulesListForm.php b/core/modules/system/lib/Drupal/system/Form/ModulesListForm.php index a090c67..2705f90 100644 --- a/core/modules/system/lib/Drupal/system/Form/ModulesListForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ModulesListForm.php @@ -136,6 +136,8 @@ public function buildForm(array $form, array &$form_state) { uasort($form['modules'], 'element_sort_by_title'); $form['#attached']['library'][] = array('system', 'drupal.system.modules'); + $form['#attached']['library'][] = array('system', 'drupal.dialog.ajax'); + $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array( '#type' => 'submit', @@ -220,6 +222,10 @@ protected function buildRow(array $modules, $module, $distribution) { '#title' => $this->t('Install'), '#default_value' => (bool) $module->status, '#disabled' => (bool) $module->status, + '#attributes' => array( + 'data-module' => $module->name, + 'data-requires' => implode(',', array_keys($module->requires)), + ), ); // Disable the checkbox for required modules. diff --git a/core/modules/system/system.modules.js b/core/modules/system/system.modules.js index 4d97652..30380c9 100644 --- a/core/modules/system/system.modules.js +++ b/core/modules/system/system.modules.js @@ -57,4 +57,82 @@ Drupal.behaviors.tableFilterByText = { } }; + /** + * Display an alert for dependant modules. + */ + Drupal.behaviors.moduleDependencies = { + attach: function (context, settings) { + + var moduleDependencies = this; + + $('input[data-requires!=""]').once('module-dependency').on('click', function () { + + var $that = $(this); + + if ($that.is(':checked') && !moduleDependencies.gettingDependencies) { + var dependenciesList = $that.attr('data-requires').split(','); + var $dependencies = Drupal.system.getDependencies(dependenciesList); + if ($dependencies.length) { + + var messageTitle = Drupal.t('Some required modules must be enabled'); + var message = Drupal.formatPlural( + $dependencies.length, + 'You must enable the !required module to install !module.', + 'You must enable the !required modules to install !module.', + {'!required': dependenciesList.join(', '), '!module': $that.attr('data-module')} + ); + var messageFooter = Drupal.t('Would you like to continue with the above?'); + + $('
' + + '

' + message + '

' + + '

' + messageFooter + '

' + + '
').dialog({ + resizable: false, + modal: true, + buttons: { + Confirm: function () { + $(this).dialog("close"); + moduleDependencies.gettingDependencies = true; + $dependencies.click(); + moduleDependencies.gettingDependencies = false; + }, + Cancel: function () { + $(this).dialog("close"); + $that.attr('checked', false); + } + }, + beforeClose: function (event) { + if (event.keyCode === $.ui.keyCode.ESCAPE) { + $that.attr('checked', false); + } + } + }); + } + } + }); + }, + + gettingDependencies: false + }; + + Drupal.system = { + /** + * Returns a jQuery collection of unchecked inputs from the dependency list + * + * @param {Array} list + * Array of ids + */ + getDependencies: function (list) { + return $('input[data-module]').filter(function () { + var $that = $(this); + var required = $.inArray($that.attr('data-module'), list) !== -1; + var notEnabled = true; + if (required) { + notEnabled = !$that.is(':checked'); + } + return required && notEnabled; + }); + } + }; + }(jQuery, Drupal)); -- 1.8.5.2.msysgit.0