From 15a3ae6db14fd021d3c9ca672a8afc98b86cf174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Wed, 22 May 2013 18:01:18 +0200 Subject: [PATCH] improved error messages --- apps/files_encryption/ajax/adminrecovery.php | 8 +++++++- apps/files_encryption/js/settings-admin.js | 10 +++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/files_encryption/ajax/adminrecovery.php b/apps/files_encryption/ajax/adminrecovery.php index a32225d036..306f0088be 100644 --- a/apps/files_encryption/ajax/adminrecovery.php +++ b/apps/files_encryption/ajax/adminrecovery.php @@ -22,6 +22,7 @@ $recoveryKeyId = OC_Appconfig::getValue('files_encryption', 'recoveryKeyId'); if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] == 1){ $return = \OCA\Encryption\Helper::adminEnableRecovery($recoveryKeyId, $_POST['recoveryPassword']); + $action = "enable"; // Disable recoveryAdmin } elseif ( @@ -29,7 +30,12 @@ if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] == 1){ && 0 == $_POST['adminEnableRecovery'] ) { $return = \OCA\Encryption\Helper::adminDisableRecovery($_POST['recoveryPassword']); + $action = "disable"; } // Return success or failure -( $return ) ? \OCP\JSON::success() : \OCP\JSON::error(); \ No newline at end of file +if ($return) { + \OCP\JSON::success(array("data" => array( "message" => 'Recovery key successfully ' . $action.'d'))); +} else { + \OCP\JSON::error(array("data" => array( "message" => 'Could not '.$action.' recovery key. Please check your recovery key password!'))); +} diff --git a/apps/files_encryption/js/settings-admin.js b/apps/files_encryption/js/settings-admin.js index dbae42b011..c58d75341d 100644 --- a/apps/files_encryption/js/settings-admin.js +++ b/apps/files_encryption/js/settings-admin.js @@ -44,19 +44,19 @@ $(document).ready(function(){ $( 'input:radio[name="adminEnableRecovery"]' ).change( function() { - var recoveryStatus = $( this ).val(); var oldStatus = (1+parseInt(recoveryStatus)) % 2; var recoveryPassword = $( '#recoveryPassword' ).val(); $.post( OC.filePath( 'files_encryption', 'ajax', 'adminrecovery.php' ) , { adminEnableRecovery: recoveryStatus, recoveryPassword: recoveryPassword } - , function( data ) { - if (data.status == "error") { - alert("Couldn't switch recovery key mode, please check your recovery key password!"); + , function( result ) { + if (result.status === "error") { + OC.Notification.show(t('admin', result.data.message)); $('input:radio[name="adminEnableRecovery"][value="'+oldStatus.toString()+'"]').attr("checked", "true"); } else { - if (recoveryStatus == "0") { + OC.Notification.hide(); + if (recoveryStatus === "0") { $('button:button[name="submitChangeRecoveryKey"]').attr("disabled", "true"); $('input:password[name="changeRecoveryPassword"]').attr("disabled", "true"); $('input:password[name="changeRecoveryPassword"]').val("");