forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-39319 langimport: Javascript confirmation when uninstalling
- Loading branch information
Martin Mastny
committed
May 29, 2015
1 parent
6ddf92c
commit 96a2e00
Showing
8 changed files
with
362 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm-debug.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]}); |
1 change: 1 addition & 0 deletions
1
lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm-min.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
lib/yui/build/moodle-core-languninstallconfirm/moodle-core-languninstallconfirm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "moodle-core-languninstallconfirm", | ||
"builds": { | ||
"moodle-core-languninstallconfirm": { | ||
"jsfiles": [ | ||
"languninstallconfirm.js" | ||
] | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
lib/yui/src/languninstallconfirm/js/languninstallconfirm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
10 changes: 10 additions & 0 deletions
10
lib/yui/src/languninstallconfirm/meta/languninstallconfirm.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"moodle-core-languninstallconfirm": { | ||
"requires": [ | ||
"base", | ||
"node", | ||
"moodle-core-notification-confirm", | ||
"moodle-core-notification-alert" | ||
] | ||
} | ||
} |