Merge pull request #9582 from nextcloud/feature/2593/password-confirm-texts
Allow custom text for OC.PasswordConfirmation
This commit is contained in:
commit
6689a3e37b
|
@ -76,3 +76,17 @@
|
|||
.oc-dialog-content {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.oc-dialog.password-confirmation {
|
||||
.oc-dialog-content {
|
||||
width: auto;
|
||||
margin: 12px;
|
||||
|
||||
input[type=password] {
|
||||
width: 100%;
|
||||
}
|
||||
label {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1715,38 +1715,54 @@ OC.PasswordConfirmation = {
|
|||
/**
|
||||
* @param {function} callback
|
||||
*/
|
||||
requirePasswordConfirmation: function(callback) {
|
||||
requirePasswordConfirmation: function(callback, options) {
|
||||
options = typeof options !== 'undefined' ? options : {};
|
||||
var defaults = {
|
||||
title: t('core','Authentication required'),
|
||||
text: t(
|
||||
'core',
|
||||
'This action requires you to confirm your password'
|
||||
),
|
||||
confirm: t('core', 'Confirm'),
|
||||
label: t('core','Password'),
|
||||
error: '',
|
||||
};
|
||||
|
||||
var config = _.extend(defaults, options);
|
||||
|
||||
var self = this;
|
||||
|
||||
if (this.requiresPasswordConfirmation()) {
|
||||
OC.dialogs.prompt(
|
||||
t(
|
||||
'core',
|
||||
'This action requires you to confirm your password'
|
||||
),
|
||||
t('core','Authentication required'),
|
||||
config.text,
|
||||
config.title,
|
||||
function (result, password) {
|
||||
if (result && password !== '') {
|
||||
self._confirmPassword(password);
|
||||
self._confirmPassword(password, config);
|
||||
}
|
||||
},
|
||||
true,
|
||||
t('core','Password'),
|
||||
config.label,
|
||||
true
|
||||
).then(function() {
|
||||
var $dialog = $('.oc-dialog:visible');
|
||||
$dialog.find('.ui-icon').remove();
|
||||
$dialog.addClass('password-confirmation');
|
||||
if (config.error !== '') {
|
||||
var $error = $('<p></p>').addClass('msg warning').text(config.error);
|
||||
}
|
||||
$dialog.find('.oc-dialog-content').append($error);
|
||||
|
||||
var $buttons = $dialog.find('button');
|
||||
$buttons.eq(0).text(t('core', 'Cancel'));
|
||||
$buttons.eq(1).text(t('core', 'Confirm'));
|
||||
$buttons.eq(0).hide();
|
||||
$buttons.eq(1).text(config.confirm);
|
||||
});
|
||||
}
|
||||
|
||||
this.callback = callback;
|
||||
},
|
||||
|
||||
_confirmPassword: function(password) {
|
||||
_confirmPassword: function(password, config) {
|
||||
var self = this;
|
||||
|
||||
$.ajax({
|
||||
|
@ -1763,8 +1779,8 @@ OC.PasswordConfirmation = {
|
|||
}
|
||||
},
|
||||
error: function() {
|
||||
OC.PasswordConfirmation.requirePasswordConfirmation(self.callback);
|
||||
OC.Notification.showTemporary(t('core', 'Failed to authenticate, try again'));
|
||||
config.error = t('core', 'Failed to authenticate, try again');
|
||||
OC.PasswordConfirmation.requirePasswordConfirmation(self.callback, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ var OCdialogs = {
|
|||
type : 'notice'
|
||||
});
|
||||
var input = $('<input/>');
|
||||
input.attr('type', password ? 'password' : 'text').attr('id', dialogName + '-input');
|
||||
input.attr('type', password ? 'password' : 'text').attr('id', dialogName + '-input').attr('placeholder', name);
|
||||
var label = $('<label/>').attr('for', dialogName + '-input').text(name + ': ');
|
||||
$dlg.append(label);
|
||||
$dlg.append(input);
|
||||
|
|
|
@ -324,7 +324,10 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
|||
|
||||
enableAppBundle:function(bundleId, active, element, groups) {
|
||||
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
|
||||
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableAppBundle, this, bundleId, active, element, groups));
|
||||
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableAppBundle, this, bundleId, active, element, groups), {
|
||||
text: t('settings', 'Installing apps requires you to confirm your password'),
|
||||
confirm: t('settings', 'Install app bundle'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -348,7 +351,10 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
|||
*/
|
||||
enableApp:function(appId, active, groups) {
|
||||
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
|
||||
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableApp, this, appId, active, groups));
|
||||
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.enableApp, this, appId, active, groups), {
|
||||
text: ( active ? t('settings', 'Disabling apps requires you to confirm your password') : t('settings', 'Enabling apps requires you to confirm your password') ),
|
||||
confirm: ( active ? t('settings', 'Disable app') : t('settings', 'Enable app') ),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -577,7 +583,10 @@ OC.Settings.Apps = OC.Settings.Apps || {
|
|||
|
||||
uninstallApp:function(appId, element) {
|
||||
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
|
||||
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.uninstallApp, this, appId, element));
|
||||
OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this.uninstallApp, this, appId, element), {
|
||||
text: t('settings', 'Uninstalling apps requires you to confirm your password'),
|
||||
confirm: t('settings', 'Uninstall')
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue