improve frontend

This commit is contained in:
afkbrb 2020-06-19 10:56:07 +08:00 committed by Tom Morris
parent 335e81a26c
commit cdb02004fd
6 changed files with 68 additions and 68 deletions

View File

@ -82,8 +82,8 @@
"wikidata-account/access-secret-label": "Access secret:", "wikidata-account/access-secret-label": "Access secret:",
"wikidata-account/access-secret-placeholder": "access secret", "wikidata-account/access-secret-placeholder": "access secret",
"wikidata-account/remember-me": "Remember me", "wikidata-account/remember-me": "Remember me",
"wikidata-account/password-remember-me-title": "Your password won't be stored.", "wikidata-account/password-remember-me-title": "Your password won't be stored. Don't check this if your computer is public.",
"wikidata-account/owner-only-consumer-remember-me-title": "Consumer credentials are stored encrypted in cookies.", "wikidata-account/owner-only-consumer-remember-me-title": "Consumer credentials are stored unencrypted in cookies. Don't check this if your computer is public.",
"wikidata-account/close": "Close", "wikidata-account/close": "Close",
"wikidata-account/log-in": "Log in", "wikidata-account/log-in": "Log in",
"wikidata-account/logged-in-as": "You are logged in as:", "wikidata-account/logged-in-as": "You are logged in as:",

View File

@ -114,8 +114,8 @@
"wikidata-account/access-secret-label": "Access secret:", "wikidata-account/access-secret-label": "Access secret:",
"wikidata-account/access-secret-placeholder": "access secret", "wikidata-account/access-secret-placeholder": "access secret",
"wikidata-account/remember-me": "Remember me", "wikidata-account/remember-me": "Remember me",
"wikidata-account/password-remember-me-title": "Your password won't be stored.", "wikidata-account/password-remember-me-title": "Your password won't be stored. Don't check this if your computer is public.",
"wikidata-account/owner-only-consumer-remember-me-title": "Consumer credentials are stored encrypted in cookies.", "wikidata-account/owner-only-consumer-remember-me-title": "Consumer credentials are stored unencrypted in cookies. Don't check this if your computer is public.",
"wikidata-account/close": "Close", "wikidata-account/close": "Close",
"wikidata-account/log-in": "Log in", "wikidata-account/log-in": "Log in",
"wikidata-account/logged-in-as": "You are logged in as:", "wikidata-account/logged-in-as": "You are logged in as:",

View File

@ -7,6 +7,7 @@
</a> </a>
</div> </div>
<div class="right-of-logo"> <div class="right-of-logo">
<p class="body-text" bind="explainLogIn"></p>
<div class="wikibase-user-management-area"> <div class="wikibase-user-management-area">
<div class="wikibase-user-logout" bind="logoutArea"> <div class="wikibase-user-logout" bind="logoutArea">
<p><span bind="loggedInAs"></span> <p><span bind="loggedInAs"></span>
@ -19,7 +20,4 @@
</div> </div>
</div> </div>
</div> </div>
<div class="dialog-footer" style="text-align: center">
<span bind="explainLogIn"></span>
</div>
</div> </div>

View File

@ -2,35 +2,42 @@ var ManageAccountDialog = {};
ManageAccountDialog.firstLogin = true; ManageAccountDialog.firstLogin = true;
ManageAccountDialog.display = function (logged_in_username, callback) { /**
* Displays the logged in page if the user is logged in,
* displays the login page otherwise.
*/
ManageAccountDialog.display = function (logged_in_username, onSuccess) {
if (logged_in_username == null) { if (logged_in_username == null) {
logged_in_username = ManageAccountDialog.tryLoginWithCookies(callback); if (ManageAccountDialog.firstLogin) {
} ManageAccountDialog.firstLogin = false;
ManageAccountDialog.tryLoginWithCookies(onSuccess);
if (logged_in_username != null) { } else {
ManageAccountDialog.displayLoggedIn(logged_in_username, callback); ManageAccountDialog.displayPasswordLogin(onSuccess);
}
} else { } else {
ManageAccountDialog.displayPasswordLogin(callback); ManageAccountDialog.displayLoggedIn(logged_in_username);
} }
}; };
ManageAccountDialog.tryLoginWithCookies = function (callback) {
var logged_user_name = null; ManageAccountDialog.tryLoginWithCookies = function (onSuccess) {
$.ajaxSetup({async: false}); // In the first login, we try logging in with cookies,
// the backend may take a while to tell if the cookies are valid or not.
// So we need to call DialogSystem.showBusy to inform the user that
// OpenRefine is trying connecting to Wikidata.
const discardWaiter = DialogSystem.showBusy($.i18n('wikidata-account/connecting-to-wikidata'));
Refine.postCSRF( Refine.postCSRF(
"command/wikidata/login", "command/wikidata/login",
{}, {},
function (data) { function (data) {
discardWaiter();
if (data.logged_in) { if (data.logged_in) {
callback(data.username); onSuccess(data.username);
logged_user_name = data.username; ManageAccountDialog.displayLoggedIn(data.username);
} else { } else {
logged_user_name = null; ManageAccountDialog.displayPasswordLogin(onSuccess);
} }
}); });
$.ajaxSetup({async: true});
return logged_user_name;
}; };
ManageAccountDialog.initCommon = function (elmts) { ManageAccountDialog.initCommon = function (elmts) {
@ -39,7 +46,7 @@ ManageAccountDialog.initCommon = function (elmts) {
elmts.cancelButton.text($.i18n('wikidata-account/close')); elmts.cancelButton.text($.i18n('wikidata-account/close'));
}; };
ManageAccountDialog.displayLoggedIn = function (logged_in_username, callback) { ManageAccountDialog.displayLoggedIn = function (logged_in_username) {
var frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/logged-in-dialog.html")); var frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/logged-in-dialog.html"));
var elmts = DOM.bind(frame); var elmts = DOM.bind(frame);
ManageAccountDialog.initCommon(elmts); ManageAccountDialog.initCommon(elmts);
@ -57,7 +64,6 @@ ManageAccountDialog.displayLoggedIn = function (logged_in_username, callback) {
elmts.cancelButton.click(function (e) { elmts.cancelButton.click(function (e) {
dismiss(); dismiss();
callback(null);
}); });
elmts.logoutButton.click(function () { elmts.logoutButton.click(function () {
@ -69,13 +75,12 @@ ManageAccountDialog.displayLoggedIn = function (logged_in_username, callback) {
frame.show(); frame.show();
if (!data.logged_in) { if (!data.logged_in) {
dismiss(); dismiss();
callback(null);
} }
}); });
}); });
}; };
ManageAccountDialog.displayPasswordLogin = function (callback) { ManageAccountDialog.displayPasswordLogin = function (onSuccess) {
const frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/password-login-dialog.html")); const frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/password-login-dialog.html"));
const elmts = DOM.bind(frame); const elmts = DOM.bind(frame);
ManageAccountDialog.initCommon(elmts); ManageAccountDialog.initCommon(elmts);
@ -98,12 +103,11 @@ ManageAccountDialog.displayPasswordLogin = function (callback) {
elmts.cancelButton.click(function (e) { elmts.cancelButton.click(function (e) {
dismiss(); dismiss();
callback(null);
}); });
elmts.explainOwnerOnlyConsumerLogin.click(function (e) { elmts.explainOwnerOnlyConsumerLogin.click(function (e) {
dismiss(); dismiss();
ManageAccountDialog.displayOwnerOnlyConsumerLogin(callback); ManageAccountDialog.displayOwnerOnlyConsumerLogin(onSuccess);
}); });
elmts.loginForm.submit(function (e) { elmts.loginForm.submit(function (e) {
@ -114,7 +118,7 @@ ManageAccountDialog.displayPasswordLogin = function (callback) {
function (data) { function (data) {
if (data.logged_in) { if (data.logged_in) {
dismiss(); dismiss();
callback(data.username); onSuccess(data.username);
} else { } else {
frame.show(); frame.show();
elmts.invalidCredentials.show(); elmts.invalidCredentials.show();
@ -124,7 +128,7 @@ ManageAccountDialog.displayPasswordLogin = function (callback) {
}); });
}; };
ManageAccountDialog.displayOwnerOnlyConsumerLogin = function (callback) { ManageAccountDialog.displayOwnerOnlyConsumerLogin = function (onSuccess) {
var frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/owner-only-consumer-login-dialog.html")); var frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/owner-only-consumer-login-dialog.html"));
var elmts = DOM.bind(frame); var elmts = DOM.bind(frame);
ManageAccountDialog.initCommon(elmts); ManageAccountDialog.initCommon(elmts);
@ -152,12 +156,11 @@ ManageAccountDialog.displayOwnerOnlyConsumerLogin = function (callback) {
elmts.cancelButton.click(function (e) { elmts.cancelButton.click(function (e) {
dismiss(); dismiss();
callback(null);
}); });
elmts.explainPasswordLogin.click(function (e) { elmts.explainPasswordLogin.click(function (e) {
dismiss(); dismiss();
ManageAccountDialog.displayPasswordLogin(callback); ManageAccountDialog.displayPasswordLogin(onSuccess);
}); });
elmts.loginForm.submit(function (e) { elmts.loginForm.submit(function (e) {
@ -168,7 +171,7 @@ ManageAccountDialog.displayOwnerOnlyConsumerLogin = function (callback) {
function (data) { function (data) {
if (data.logged_in) { if (data.logged_in) {
dismiss(); dismiss();
callback(data.username); onSuccess(data.username);
} else { } else {
frame.show(); frame.show();
elmts.invalidCredentials.show(); elmts.invalidCredentials.show();
@ -178,27 +181,28 @@ ManageAccountDialog.displayOwnerOnlyConsumerLogin = function (callback) {
}); });
}; };
/**
* Checks if the user is logged in or not.
*
* The callback needs to react to both cases.
*/
ManageAccountDialog.isLoggedIn = function (callback) { ManageAccountDialog.isLoggedIn = function (callback) {
var discardWaiter = function () {
};
if (ManageAccountDialog.firstLogin) {
discardWaiter = DialogSystem.showBusy($.i18n('wikidata-account/connecting-to-wikidata'));
}
$.get( $.get(
"command/wikidata/login", "command/wikidata/login",
function (data) { function (data) {
discardWaiter();
ManageAccountDialog.firstLogin = false;
callback(data.username); callback(data.username);
}); });
}; };
ManageAccountDialog.ensureLoggedIn = function (callback) { /**
* The onSuccess callback is called if and only if the user is logged in.
*/
ManageAccountDialog.ensureLoggedIn = function (onSuccess) {
ManageAccountDialog.isLoggedIn(function (logged_in_username) { ManageAccountDialog.isLoggedIn(function (logged_in_username) {
if (logged_in_username == null) { if (logged_in_username == null) {
ManageAccountDialog.display(null, callback); ManageAccountDialog.display(null, onSuccess);
} else { } else {
callback(logged_in_username); onSuccess(logged_in_username);
} }
}); });
}; };

View File

@ -42,7 +42,7 @@ PerformEditsDialog.launch = function(logged_in_username, max_severity) {
{ onDone: function() { dismiss(); } } { onDone: function() { dismiss(); } }
); );
} }
} };
elmts.loggedInUsername elmts.loggedInUsername
.text(logged_in_username) .text(logged_in_username)
@ -72,7 +72,7 @@ PerformEditsDialog.updateEditCount = function(edit_count) {
this._elmts.reviewYourEdits.html( this._elmts.reviewYourEdits.html(
$.i18n('perform-wikidata-edits/review-your-edits') $.i18n('perform-wikidata-edits/review-your-edits')
.replace('{nb_edits}', edit_count)); .replace('{nb_edits}', edit_count));
} };
PerformEditsDialog._updateWarnings = function(data) { PerformEditsDialog._updateWarnings = function(data) {
var warnings = data.warnings; var warnings = data.warnings;
@ -87,7 +87,7 @@ PerformEditsDialog._updateWarnings = function(data) {
var rendered = WarningsRenderer._renderWarning(warnings[i]); var rendered = WarningsRenderer._renderWarning(warnings[i]);
rendered.appendTo(table); rendered.appendTo(table);
} }
} };
PerformEditsDialog.checkAndLaunch = function () { PerformEditsDialog.checkAndLaunch = function () {
var self = this; var self = this;
@ -95,26 +95,24 @@ PerformEditsDialog.checkAndLaunch = function () {
this._elmts = DOM.bind(this.frame); this._elmts = DOM.bind(this.frame);
this.missingSchema = false; this.missingSchema = false;
var onSaved = function() { var onSaved = function () {
ManageAccountDialog.ensureLoggedIn(function(logged_in_username) { ManageAccountDialog.ensureLoggedIn(function (logged_in_username) {
if (logged_in_username) { var discardWaiter = DialogSystem.showBusy($.i18n('perform-wikidata-edits/analyzing-edits'));
var discardWaiter = DialogSystem.showBusy($.i18n('perform-wikidata-edits/analyzing-edits')); Refine.postCSRF(
Refine.postCSRF( "command/wikidata/preview-wikibase-schema?" + $.param({project: theProject.id}),
"command/wikidata/preview-wikibase-schema?" + $.param({ project: theProject.id }), {engine: JSON.stringify(ui.browsingEngine.getJSON())},
{ engine: JSON.stringify(ui.browsingEngine.getJSON()) }, function (data) {
function(data) { discardWaiter();
discardWaiter(); if (data['code'] != 'error') {
if(data['code'] != 'error') { PerformEditsDialog._updateWarnings(data);
PerformEditsDialog._updateWarnings(data); PerformEditsDialog.launch(logged_in_username, data['max_severity']);
PerformEditsDialog.launch(logged_in_username, data['max_severity']); } else {
} else { SchemaAlignmentDialog.launch(
SchemaAlignmentDialog.launch( PerformEditsDialog.checkAndLaunch);
PerformEditsDialog.checkAndLaunch); }
} },
}, "json"
"json" );
);
}
}); });
}; };

View File

@ -91,4 +91,4 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.wikibase-login-dialog-footer span { .wikibase-login-dialog-footer span {
cursor: pointer; cursor: pointer;
} }