From 33b1e18f82b165c1e64f31ed6a5470608c0d2dc0 Mon Sep 17 00:00:00 2001 From: capynet Date: Sun, 26 Jan 2014 13:43:55 +0100 Subject: [PATCH] lllllllllllll --- core-js-modules-dependencies-1473760-8.patch | 124 +++++++++++++++++++++ .../lib/Drupal/system/Form/ModulesListForm.php | 6 + core/modules/system/system.modules.js | 78 +++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 core-js-modules-dependencies-1473760-8.patch diff --git a/core-js-modules-dependencies-1473760-8.patch b/core-js-modules-dependencies-1473760-8.patch new file mode 100644 index 0000000..67e4a64 --- /dev/null +++ b/core-js-modules-dependencies-1473760-8.patch @@ -0,0 +1,124 @@ +From fda7d883cc5d2e756d4fb8e6cb0e13b3ab63fde9 Mon Sep 17 00:00:00 2001 +From: capynet +Date: Sun, 26 Jan 2014 13:35:55 +0100 +Subject: [PATCH] lala + +--- + .../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..eea63de 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 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?'); ++ var $dialogMsg = $('

' + message + '

' + messageFooter + '

'); ++ ++ Drupal.dialog($dialogMsg, { ++ title: Drupal.t('Some required modules must be enabled'), ++ dialogClass: 'module-mark-dependencies-modal', ++ resizable: false, ++ minWidth: 340, ++ 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); ++ } ++ } ++ }).showModal(); ++ ++ } ++ } ++ }); ++ }, ++ ++ 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 + diff --git a/core/modules/system/lib/Drupal/system/Form/ModulesListForm.php b/core/modules/system/lib/Drupal/system/Form/ModulesListForm.php index a090c67..688faae 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'); + $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..eea63de 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 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?'); + var $dialogMsg = $('

' + message + '

' + messageFooter + '

'); + + Drupal.dialog($dialogMsg, { + title: Drupal.t('Some required modules must be enabled'), + dialogClass: 'module-mark-dependencies-modal', + resizable: false, + minWidth: 340, + 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); + } + } + }).showModal(); + + } + } + }); + }, + + 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