diff --git a/admin/tool/langimport/index.php b/admin/tool/langimport/index.php index 27fd584001f..c1ee2fb5406 100644 --- a/admin/tool/langimport/index.php +++ b/admin/tool/langimport/index.php @@ -79,7 +79,7 @@ if ($mode == DELETION_OF_SELECTED_LANG and (!empty($uninstalllang) or !empty($co if (in_array('en', $uninstalllang)) { // TODO. - $controller->errors[] = 'English language pack can not be uninstalled'; + $controller->errors[] = get_string('noenglishuninstall', 'tool_langimport'); } else if (empty($confirmtounistall) and confirm_sesskey()) { // User chose langs to be deleted, show confirmation. echo $OUTPUT->header(); @@ -170,7 +170,10 @@ echo html_writer::empty_tag('br'); echo html_writer::select($installedlangs, 'uninstalllang[]', '', false, array('size' => 15, 'multiple' => 'multiple')); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); echo html_writer::empty_tag('br'); -echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('uninstall', 'tool_langimport'))); +echo html_writer::empty_tag('input', array('id' => 'languninstallbutton', + 'type' => 'submit', + 'value' => get_string('uninstall', 'tool_langimport')) + ); echo html_writer::end_tag('fieldset'); echo html_writer::end_tag('form'); if ($remote) { @@ -207,5 +210,13 @@ if (!empty($options)) { echo html_writer::end_tag('tr'); echo html_writer::end_tag('table'); echo $OUTPUT->box_end(); + +$uninstallurl = new moodle_url('/admin/tool/langimport/index.php'); +$PAGE->requires->strings_for_js(array('uninstallconfirm', 'uninstall', 'selectlangs', 'noenglishuninstall'), + 'tool_langimport'); +$PAGE->requires->yui_module('moodle-core-languninstallconfirm', + 'Y.M.core.languninstallconfirm.init', + array(array('uninstallUrl' => $uninstallurl->out())) + ); echo $OUTPUT->footer(); die(); diff --git a/admin/tool/langimport/lang/en/tool_langimport.php b/admin/tool/langimport/lang/en/tool_langimport.php index a8c97fca6bf..676b3e095fe 100644 --- a/admin/tool/langimport/lang/en/tool_langimport.php +++ b/admin/tool/langimport/lang/en/tool_langimport.php @@ -44,6 +44,10 @@ $string['pluginname'] = 'Language packs'; $string['purgestringcaches'] = 'Purge string caches'; $string['remotelangnotavailable'] = 'Because Moodle cannot connect to download.moodle.org, it is not possible for language packs to be installed automatically. Please download the appropriate ZIP file(s) from download.moodle.org/langpack, copy them to your {$a} directory and unzip them manually.'; $string['uninstall'] = 'Uninstall selected language packs'; -$string['uninstallconfirm'] = 'You are about to completely uninstall these language packs: {$a}. Are you sure?'; +$string['uninstallconfirm'] = 'You are about to completely uninstall these language packs: {$a}. Are you sure?'; $string['updatelangs'] = 'Update all installed language packs'; +$string['selectlangs'] = 'Select languages to unistall!'; +$string['noenglishuninstall'] = 'English language pack can not be uninstalled'; + + diff --git a/lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm-debug.js b/lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm-debug.js new file mode 100644 index 00000000000..93c4c97d181 --- /dev/null +++ b/lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm-debug.js @@ -0,0 +1,109 @@ +YUI.add('moodle-core-languninstallconfirm', function (Y, NAME) { + +/** + * Home for a Confirmation class. +* +* @module moodle-core-languninstallconfirm +*/ + +/** +* A class for a language uninstall confirmation. +* +* @class M.core.languninstallconfirm +* @constructor +* @extends Base +*/ +function Confirmation() { + Confirmation.superclass.constructor.apply(this, arguments); +} + +var SELECTORS = { + UNINSTALLBUTTON: '#languninstallbutton', + UNINSTALLSELECT: '#menuuninstalllang option', + ENGLISHOPTION: '#menuuninstalllang option[value=\'en\']' +}; + +Confirmation.NAME = NAME; +Confirmation.ATTRS = { + /** + * Uninstall url + * + * @property uninstallUrl + * @type string + */ + uninstallUrl: { + validator: Y.Lang.isString + } +}; +Y.extend(Confirmation, Y.Base, { + /** + * Initializer. + * Registers onclicks. + * + * @method initializer + */ + initializer: function() { + Y.one(SELECTORS.UNINSTALLBUTTON).on('click', this._confirm, this); + }, + /** + * Confirmation. + * Displays the confirmation dialogue. + * + * @method _confirm + * @protected + * @param {EventFacade} e + */ + _confirm: function(e) { + e.preventDefault(); + var selectedLangCodes = []; + var selectedLangNames = []; + + Y.all(SELECTORS.UNINSTALLSELECT).each(function(option){ + if (option.get('selected')){ + selectedLangCodes.push(option.getAttribute('value')); + selectedLangNames.push(option.get('text')); + } + }); + // Nothing was selected, show warning. + if (selectedLangCodes.length === 0){ + new M.core.alert({ message: M.util.get_string('selectlangs', 'tool_langimport') }).show(); + return; + } else if (selectedLangCodes.indexOf('en')> -1) { // Don't uninstall english. + Y.one(SELECTORS.ENGLISHOPTION).set('selected',false); + new M.core.alert({ message: M.util.get_string('noenglishuninstall', 'tool_langimport') }).show(); + return; + } + var confirmationConfig = { + modal: true, + visible : false, + centered : true, + title : M.util.get_string('uninstall','tool_langimport'), + question : M.util.get_string('uninstallconfirm','tool_langimport', selectedLangNames.join(", ")) + }; + new M.core.confirm(confirmationConfig) + .show() + .on('complete-yes', this._uninstall, this, selectedLangCodes); + }, + /** + * Uninstall. + * Redirects to an uninstall process. + * + * @method _uninstall + * @protected + * @param {EventFacade} e + * @param {Array} langCodes array of lang codes to be uninstalled + */ + _uninstall : function(e, langCodes) { + Y.config.win.location.href = this.get('uninstallUrl') + '?mode=4' + + '&sesskey=' + M.cfg.sesskey + + '&confirmtouninstall=' + langCodes.join('-'); + } + +}); + +Y.namespace('M.core.languninstallconfirm').Confirmation = Confirmation; +Y.namespace('M.core.languninstallconfirm').init = function(config) { + return new Confirmation(config); +}; + +}, '@VERSION@', {"requires": ["base", "node", "moodle-core-notification-confirm", "moodle-core-notification-alert"]}); diff --git a/lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm-min.js b/lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm-min.js new file mode 100644 index 00000000000..fd52350bcd1 --- /dev/null +++ b/lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm-min.js @@ -0,0 +1 @@ +YUI.add("moodle-core-languninstallconfirm",function(e,t){function n(){n.superclass.constructor.apply(this,arguments)}var r={UNINSTALLBUTTON:"#languninstallbutton",UNINSTALLSELECT:"#menuuninstalllang option",ENGLISHOPTION:"#menuuninstalllang option[value='en']"};n.NAME=t,n.ATTRS={uninstallUrl:{validator:e.Lang.isString}},e.extend(n,e.Base,{initializer:function(){e.one(r.UNINSTALLBUTTON).on("click",this._confirm,this)},_confirm:function(t){t.preventDefault();var n=[],i=[];e.all(r.UNINSTALLSELECT).each(function(e){e.get("selected")&&(n.push(e.getAttribute("value")),i.push(e.get("text")))});if(n.length===0){(new M.core.alert({message:M.util.get_string("selectlangs","tool_langimport")})).show();return}if(n.indexOf("en")>-1){e.one(r.ENGLISHOPTION).set("selected",!1),(new M.core.alert({message:M.util.get_string("noenglishuninstall","tool_langimport")})).show();return}var s={modal:!0,visible:!1,centered:!0,title:M.util.get_string("uninstall","tool_langimport"),question:M.util.get_string("uninstallconfirm","tool_langimport",i.join(", "))};(new M.core.confirm(s)).show().on("complete-yes",this._uninstall,this,n)},_uninstall:function(t,n){e.config.win.location.href=this.get("uninstallUrl")+"?mode=4"+"&sesskey="+M.cfg.sesskey+"&confirmtouninstall="+n.join("-")}}),e.namespace("M.core.languninstallconfirm").Confirmation=n,e.namespace("M.core.languninstallconfirm").init=function(e){return new n(e)}},"@VERSION@",{requires:["base","node","moodle-core-notification-confirm","moodle-core-notification-alert"]}); diff --git a/lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm.js b/lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm.js new file mode 100644 index 00000000000..93c4c97d181 --- /dev/null +++ b/lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm.js @@ -0,0 +1,109 @@ +YUI.add('moodle-core-languninstallconfirm', function (Y, NAME) { + +/** + * Home for a Confirmation class. +* +* @module moodle-core-languninstallconfirm +*/ + +/** +* A class for a language uninstall confirmation. +* +* @class M.core.languninstallconfirm +* @constructor +* @extends Base +*/ +function Confirmation() { + Confirmation.superclass.constructor.apply(this, arguments); +} + +var SELECTORS = { + UNINSTALLBUTTON: '#languninstallbutton', + UNINSTALLSELECT: '#menuuninstalllang option', + ENGLISHOPTION: '#menuuninstalllang option[value=\'en\']' +}; + +Confirmation.NAME = NAME; +Confirmation.ATTRS = { + /** + * Uninstall url + * + * @property uninstallUrl + * @type string + */ + uninstallUrl: { + validator: Y.Lang.isString + } +}; +Y.extend(Confirmation, Y.Base, { + /** + * Initializer. + * Registers onclicks. + * + * @method initializer + */ + initializer: function() { + Y.one(SELECTORS.UNINSTALLBUTTON).on('click', this._confirm, this); + }, + /** + * Confirmation. + * Displays the confirmation dialogue. + * + * @method _confirm + * @protected + * @param {EventFacade} e + */ + _confirm: function(e) { + e.preventDefault(); + var selectedLangCodes = []; + var selectedLangNames = []; + + Y.all(SELECTORS.UNINSTALLSELECT).each(function(option){ + if (option.get('selected')){ + selectedLangCodes.push(option.getAttribute('value')); + selectedLangNames.push(option.get('text')); + } + }); + // Nothing was selected, show warning. + if (selectedLangCodes.length === 0){ + new M.core.alert({ message: M.util.get_string('selectlangs', 'tool_langimport') }).show(); + return; + } else if (selectedLangCodes.indexOf('en')> -1) { // Don't uninstall english. + Y.one(SELECTORS.ENGLISHOPTION).set('selected',false); + new M.core.alert({ message: M.util.get_string('noenglishuninstall', 'tool_langimport') }).show(); + return; + } + var confirmationConfig = { + modal: true, + visible : false, + centered : true, + title : M.util.get_string('uninstall','tool_langimport'), + question : M.util.get_string('uninstallconfirm','tool_langimport', selectedLangNames.join(", ")) + }; + new M.core.confirm(confirmationConfig) + .show() + .on('complete-yes', this._uninstall, this, selectedLangCodes); + }, + /** + * Uninstall. + * Redirects to an uninstall process. + * + * @method _uninstall + * @protected + * @param {EventFacade} e + * @param {Array} langCodes array of lang codes to be uninstalled + */ + _uninstall : function(e, langCodes) { + Y.config.win.location.href = this.get('uninstallUrl') + '?mode=4' + + '&sesskey=' + M.cfg.sesskey + + '&confirmtouninstall=' + langCodes.join('-'); + } + +}); + +Y.namespace('M.core.languninstallconfirm').Confirmation = Confirmation; +Y.namespace('M.core.languninstallconfirm').init = function(config) { + return new Confirmation(config); +}; + +}, '@VERSION@', {"requires": ["base", "node", "moodle-core-notification-confirm", "moodle-core-notification-alert"]}); diff --git a/lib/yui/src/languninstallconfirm/build.json b/lib/yui/src/languninstallconfirm/build.json new file mode 100644 index 00000000000..c1c9687846c --- /dev/null +++ b/lib/yui/src/languninstallconfirm/build.json @@ -0,0 +1,10 @@ +{ + "name": "moodle-core-languninstallconfirm", + "builds": { + "moodle-core-languninstallconfirm": { + "jsfiles": [ + "languninstallconfirm.js" + ] + } + } +} diff --git a/lib/yui/src/languninstallconfirm/js/languninstallconfirm.js b/lib/yui/src/languninstallconfirm/js/languninstallconfirm.js new file mode 100644 index 00000000000..8503998f7b8 --- /dev/null +++ b/lib/yui/src/languninstallconfirm/js/languninstallconfirm.js @@ -0,0 +1,105 @@ +/** + * Home for a Confirmation class. +* +* @module moodle-core-languninstallconfirm +*/ + +/** +* A class for a language uninstall confirmation. +* +* @class M.core.languninstallconfirm +* @constructor +* @extends Base +*/ +function Confirmation() { + Confirmation.superclass.constructor.apply(this, arguments); +} + +var SELECTORS = { + UNINSTALLBUTTON: '#languninstallbutton', + UNINSTALLSELECT: '#menuuninstalllang option', + ENGLISHOPTION: '#menuuninstalllang option[value=\'en\']' +}; + +Confirmation.NAME = NAME; +Confirmation.ATTRS = { + /** + * Uninstall url + * + * @property uninstallUrl + * @type string + */ + uninstallUrl: { + validator: Y.Lang.isString + } +}; +Y.extend(Confirmation, Y.Base, { + /** + * Initializer. + * Registers onclicks. + * + * @method initializer + */ + initializer: function() { + Y.one(SELECTORS.UNINSTALLBUTTON).on('click', this._confirm, this); + }, + /** + * Confirmation. + * Displays the confirmation dialogue. + * + * @method _confirm + * @protected + * @param {EventFacade} e + */ + _confirm: function(e) { + e.preventDefault(); + var selectedLangCodes = []; + var selectedLangNames = []; + + Y.all(SELECTORS.UNINSTALLSELECT).each(function(option){ + if (option.get('selected')){ + selectedLangCodes.push(option.getAttribute('value')); + selectedLangNames.push(option.get('text')); + } + }); + // Nothing was selected, show warning. + if (selectedLangCodes.length === 0){ + new M.core.alert({ message: M.util.get_string('selectlangs', 'tool_langimport') }).show(); + return; + } else if (selectedLangCodes.indexOf('en')> -1) { // Don't uninstall english. + Y.one(SELECTORS.ENGLISHOPTION).set('selected',false); + new M.core.alert({ message: M.util.get_string('noenglishuninstall', 'tool_langimport') }).show(); + return; + } + var confirmationConfig = { + modal: true, + visible : false, + centered : true, + title : M.util.get_string('uninstall','tool_langimport'), + question : M.util.get_string('uninstallconfirm','tool_langimport', selectedLangNames.join(", ")) + }; + new M.core.confirm(confirmationConfig) + .show() + .on('complete-yes', this._uninstall, this, selectedLangCodes); + }, + /** + * Uninstall. + * Redirects to an uninstall process. + * + * @method _uninstall + * @protected + * @param {EventFacade} e + * @param {Array} langCodes array of lang codes to be uninstalled + */ + _uninstall : function(e, langCodes) { + Y.config.win.location.href = this.get('uninstallUrl') + '?mode=4' + + '&sesskey=' + M.cfg.sesskey + + '&confirmtouninstall=' + langCodes.join('-'); + } + +}); + +Y.namespace('M.core.languninstallconfirm').Confirmation = Confirmation; +Y.namespace('M.core.languninstallconfirm').init = function(config) { + return new Confirmation(config); +}; \ No newline at end of file diff --git a/lib/yui/src/languninstallconfirm/meta/languninstallconfirm.json b/lib/yui/src/languninstallconfirm/meta/languninstallconfirm.json new file mode 100644 index 00000000000..86350174dc4 --- /dev/null +++ b/lib/yui/src/languninstallconfirm/meta/languninstallconfirm.json @@ -0,0 +1,10 @@ +{ + "moodle-core-languninstallconfirm": { + "requires": [ + "base", + "node", + "moodle-core-notification-confirm", + "moodle-core-notification-alert" + ] + } +} \ No newline at end of file