From 3bc5c1c3cf285baa4d0ceabaa09c49f85c1ae4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 17 Apr 2015 18:04:02 +0200 Subject: [PATCH 1/4] use a simple function - OC.Encryption is already defined - fixes #15707 This reverts commit 0ca6398aa34e0a3698f3aed0305f0e9299578bbc. --- apps/encryption/js/encryption.js | 38 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/apps/encryption/js/encryption.js b/apps/encryption/js/encryption.js index c02b4d74ae..94203d93f7 100644 --- a/apps/encryption/js/encryption.js +++ b/apps/encryption/js/encryption.js @@ -5,37 +5,27 @@ * See the COPYING-README file. */ -/** - * @namespace - * @memberOf OC - */ -OC.Encryption= { - MIGRATION_OPEN: 0, - MIGRATION_COMPLETED: 1, - MIGRATION_IN_PROGRESS: -1, +function displayEncryptionWarning () { - displayEncryptionWarning: function () { - - if (!OC.Notification.isHidden()) { - return; - } - - $.get( - OC.generateUrl('/apps/encryption/ajax/getStatus') - , function( result ) { - if (result.status === "success") { - OC.Notification.show(result.data.message); - } - } - ); + if (!OC.Notification.isHidden()) { + return; } -}; + + $.get( + OC.generateUrl('/apps/encryption/ajax/getStatus'), + function( result ) { + if (result.status === "success") { + OC.Notification.show(result.data.message); + } + } + ); +} $(document).ready(function() { // wait for other apps/extensions to register their event handlers and file actions // in the "ready" clause _.defer(function() { - OC.Encryption.displayEncryptionWarning(); + displayEncryptionWarning(); }); }); From 55962c5f5ad0e03618a0a3c1267d72c8f607e2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 17 Apr 2015 18:04:07 +0200 Subject: [PATCH 2/4] make jshint happy This reverts commit ae681f0061f534b48b45cf9a41f6110c0ff20b1d. --- apps/encryption/js/settings-admin.js | 19 +++++++++++-------- apps/encryption/js/settings-personal.js | 12 ++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/apps/encryption/js/settings-admin.js b/apps/encryption/js/settings-admin.js index 36765adf3e..bb539f6a4e 100644 --- a/apps/encryption/js/settings-admin.js +++ b/apps/encryption/js/settings-admin.js @@ -12,17 +12,20 @@ $(document).ready(function(){ $( 'input:radio[name="adminEnableRecovery"]' ).change( function() { var recoveryStatus = $( this ).val(); - var oldStatus = (1+parseInt(recoveryStatus)) % 2; + var oldStatus = (1+parseInt(recoveryStatus, 10)) % 2; var recoveryPassword = $( '#encryptionRecoveryPassword' ).val(); var confirmPassword = $( '#repeatEncryptionRecoveryPassword' ).val(); OC.msg.startSaving('#encryptionSetRecoveryKey .msg'); $.post( - OC.generateUrl('/apps/encryption/ajax/adminRecovery') - , { adminEnableRecovery: recoveryStatus, recoveryPassword: recoveryPassword, confirmPassword: confirmPassword } - , function( result ) { + OC.generateUrl('/apps/encryption/ajax/adminRecovery'), + { adminEnableRecovery: recoveryStatus, + recoveryPassword: recoveryPassword, + confirmPassword: confirmPassword }, + function( result ) { OC.msg.finishedSaving('#encryptionSetRecoveryKey .msg', result); if (result.status === "error") { - $('input:radio[name="adminEnableRecovery"][value="'+oldStatus.toString()+'"]').attr("checked", "true"); + $('input:radio[name="adminEnableRecovery"][value="'+oldStatus.toString()+'"]') + .attr("checked", "true"); } else { if (recoveryStatus === "0") { $('p[name="changeRecoveryPasswordBlock"]').addClass("hidden"); @@ -44,9 +47,9 @@ $(document).ready(function(){ var confirmNewPassword = $('#repeatedNewEncryptionRecoveryPassword').val(); OC.msg.startSaving('#encryptionChangeRecoveryKey .msg'); $.post( - OC.generateUrl('/apps/encryption/ajax/changeRecoveryPassword') - , { oldPassword: oldRecoveryPassword, newPassword: newRecoveryPassword, confirmPassword: confirmNewPassword } - , function( data ) { + OC.generateUrl('/apps/encryption/ajax/changeRecoveryPassword'), + { oldPassword: oldRecoveryPassword, newPassword: newRecoveryPassword, confirmPassword: confirmNewPassword }, + function( data ) { OC.msg.finishedSaving('#encryptionChangeRecoveryKey .msg', data); } ); diff --git a/apps/encryption/js/settings-personal.js b/apps/encryption/js/settings-personal.js index 68609877c0..601bf22d78 100644 --- a/apps/encryption/js/settings-personal.js +++ b/apps/encryption/js/settings-personal.js @@ -4,7 +4,7 @@ * See the COPYING-README file. */ -function updatePrivateKeyPasswd() { +function updatePrivateKeyPassword() { var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val(); var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val(); OC.msg.startSaving('#encryption .msg'); @@ -26,9 +26,9 @@ $(document).ready(function(){ var recoveryStatus = $( this ).val(); OC.msg.startAction('#userEnableRecovery .msg', 'Updating recovery keys. This can take some time...'); $.post( - OC.generateUrl('/apps/encryption/ajax/userSetRecovery') - , { userEnableRecovery: recoveryStatus } - , function( data ) { + OC.generateUrl('/apps/encryption/ajax/userSetRecovery'), + { userEnableRecovery: recoveryStatus }, + function( data ) { OC.msg.finishedAction('#userEnableRecovery .msg', data); } ); @@ -45,7 +45,7 @@ $(document).ready(function(){ if (newPrivateKeyPassword !== '' && oldPrivateKeyPassword !== '' ) { $('button:button[name="submitChangePrivateKeyPassword"]').removeAttr("disabled"); if(event.which === 13) { - updatePrivateKeyPasswd(); + updatePrivateKeyPassword(); } } else { $('button:button[name="submitChangePrivateKeyPassword"]').attr("disabled", "true"); @@ -53,7 +53,7 @@ $(document).ready(function(){ }); $('button:button[name="submitChangePrivateKeyPassword"]').click(function() { - updatePrivateKeyPasswd(); + updatePrivateKeyPassword(); }); }); From 4a2f8f81ca8dcc91c5b784077620517ec1011724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 21 Apr 2015 12:01:56 +0200 Subject: [PATCH 3/4] Don't pollute the global namespace --- apps/encryption/js/encryption.js | 35 ++++++++++++++----------- apps/encryption/js/settings-personal.js | 34 ++++++++++++++---------- settings/js/personal.js | 10 ++++--- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/apps/encryption/js/encryption.js b/apps/encryption/js/encryption.js index 94203d93f7..32b50553f7 100644 --- a/apps/encryption/js/encryption.js +++ b/apps/encryption/js/encryption.js @@ -5,27 +5,30 @@ * See the COPYING-README file. */ - -function displayEncryptionWarning () { - - if (!OC.Notification.isHidden()) { - return; - } - - $.get( - OC.generateUrl('/apps/encryption/ajax/getStatus'), - function( result ) { - if (result.status === "success") { - OC.Notification.show(result.data.message); - } - } - ); +if (!OC.Encryption) { + OC.Encryption = {}; } +OC.Encryption = { + displayEncryptionWarning: function () { + if (!OC.Notification.isHidden()) { + return; + } + + $.get( + OC.generateUrl('/apps/encryption/ajax/getStatus'), + function (result) { + if (result.status === "success") { + OC.Notification.show(result.data.message); + } + } + ); + } +}; $(document).ready(function() { // wait for other apps/extensions to register their event handlers and file actions // in the "ready" clause _.defer(function() { - displayEncryptionWarning(); + OC.Encryption.displayEncryptionWarning(); }); }); diff --git a/apps/encryption/js/settings-personal.js b/apps/encryption/js/settings-personal.js index 601bf22d78..bf3aeaad91 100644 --- a/apps/encryption/js/settings-personal.js +++ b/apps/encryption/js/settings-personal.js @@ -4,20 +4,26 @@ * See the COPYING-README file. */ -function updatePrivateKeyPassword() { - var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val(); - var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val(); - OC.msg.startSaving('#encryption .msg'); - $.post( - OC.generateUrl('/apps/encryption/ajax/updatePrivateKeyPassword'), - { oldPassword: oldPrivateKeyPassword, newPassword: newPrivateKeyPassword } - ).success(function(response) { - OC.msg.finishedSuccess('#encryption .msg', response.message); - }).fail(function(response) { - OC.msg.finishedError('#encryption .msg', response.responseJSON.message); - }); +if (!OC.Encryption) { + OC.Encryption = {}; } +OC.Encryption = { + updatePrivateKeyPassword: function() { + var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val(); + var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val(); + OC.msg.startSaving('#encryption .msg'); + $.post( + OC.generateUrl('/apps/encryption/ajax/updatePrivateKeyPassword'), + {oldPassword: oldPrivateKeyPassword, newPassword: newPrivateKeyPassword} + ).success(function (response) { + OC.msg.finishedSuccess('#encryption .msg', response.message); + }).fail(function (response) { + OC.msg.finishedError('#encryption .msg', response.responseJSON.message); + }); + } +}; + $(document).ready(function(){ // Trigger ajax on recoveryAdmin status change @@ -45,7 +51,7 @@ $(document).ready(function(){ if (newPrivateKeyPassword !== '' && oldPrivateKeyPassword !== '' ) { $('button:button[name="submitChangePrivateKeyPassword"]').removeAttr("disabled"); if(event.which === 13) { - updatePrivateKeyPassword(); + OC.Encryption.updatePrivateKeyPassword(); } } else { $('button:button[name="submitChangePrivateKeyPassword"]').attr("disabled", "true"); @@ -53,7 +59,7 @@ $(document).ready(function(){ }); $('button:button[name="submitChangePrivateKeyPassword"]').click(function() { - updatePrivateKeyPassword(); + OC.Encryption.updatePrivateKeyPassword(); }); }); diff --git a/settings/js/personal.js b/settings/js/personal.js index 165b55bcda..f3fcf614bf 100644 --- a/settings/js/personal.js +++ b/settings/js/personal.js @@ -330,8 +330,9 @@ $(document).ready(function () { $('#sslCertificate tbody').append(row); }, - fail: function (e, data) { - OC.Notification.showTemporary(t('settings', 'An error occured. Please upload an ASCII-encoded PEM certificate.')); + fail: function () { + OC.Notification.showTemporary( + t('settings', 'An error occurred. Please upload an ASCII-encoded PEM certificate.')); } }); @@ -340,8 +341,9 @@ $(document).ready(function () { }); }); -OC.Encryption = { -}; +if (!OC.Encryption) { + OC.Encryption = {}; +} OC.Encryption.msg = { start: function (selector, msg) { From 490e779424178977c143eba94a139f249eb2416f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 21 Apr 2015 12:19:15 +0200 Subject: [PATCH 4/4] doc and indent --- apps/encryption/js/encryption.js | 4 ++++ apps/encryption/js/settings-personal.js | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/encryption/js/encryption.js b/apps/encryption/js/encryption.js index 32b50553f7..7ed49f7731 100644 --- a/apps/encryption/js/encryption.js +++ b/apps/encryption/js/encryption.js @@ -9,6 +9,10 @@ if (!OC.Encryption) { OC.Encryption = {}; } +/** + * @namespace + * @memberOf OC + */ OC.Encryption = { displayEncryptionWarning: function () { if (!OC.Notification.isHidden()) { diff --git a/apps/encryption/js/settings-personal.js b/apps/encryption/js/settings-personal.js index bf3aeaad91..e36f10a244 100644 --- a/apps/encryption/js/settings-personal.js +++ b/apps/encryption/js/settings-personal.js @@ -17,10 +17,10 @@ OC.Encryption = { OC.generateUrl('/apps/encryption/ajax/updatePrivateKeyPassword'), {oldPassword: oldPrivateKeyPassword, newPassword: newPrivateKeyPassword} ).success(function (response) { - OC.msg.finishedSuccess('#encryption .msg', response.message); - }).fail(function (response) { - OC.msg.finishedError('#encryption .msg', response.responseJSON.message); - }); + OC.msg.finishedSuccess('#encryption .msg', response.message); + }).fail(function (response) { + OC.msg.finishedError('#encryption .msg', response.responseJSON.message); + }); } };