MDL-39319 langimport: Javascript confirmation when uninstalling

This commit is contained in:
Martin Mastny
2015-05-29 13:08:33 +08:00
parent 6ddf92c774
commit 96a2e00d42
8 changed files with 362 additions and 3 deletions
+13 -2
View File
@@ -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();
@@ -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 <a href="https://download.moodle.org/langpack/">download.moodle.org/langpack</a>, 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: <strong>{$a}</strong>. 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';
@@ -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"]});
@@ -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"]});
@@ -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"]});
@@ -0,0 +1,10 @@
{
"name": "moodle-core-languninstallconfirm",
"builds": {
"moodle-core-languninstallconfirm": {
"jsfiles": [
"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);
};
@@ -0,0 +1,10 @@
{
"moodle-core-languninstallconfirm": {
"requires": [
"base",
"node",
"moodle-core-notification-confirm",
"moodle-core-notification-alert"
]
}
}