diff --git a/controller/action/MailActions.class.php b/controller/action/MailActions.class.php
index e6371e6b..5d3d99ef 100644
--- a/controller/action/MailActions.class.php
+++ b/controller/action/MailActions.class.php
@@ -63,6 +63,10 @@ class MailActions extends Actions
public static function editEmailSettings(string $token)
{
$response = LBRY::emailStatus($token);
- return ['mail/settings',['data' => $response['data'],'error' => $response['error']]];
+ return ['mail/settings', [
+ 'status' => $response['data'] ?? '/',
+ 'token' => $token,
+ 'error' => $response['error'] ?? false
+ ]];
}
}
diff --git a/view/template/mail/_settingsForm.php b/view/template/mail/_settingsForm.php
index c892d33e..d389bdf7 100644
--- a/view/template/mail/_settingsForm.php
+++ b/view/template/mail/_settingsForm.php
@@ -1,27 +1,28 @@
+
-lbry.emailSettingsForm( '');
+ lbry.emailSettingsForm("#", '', );
-
-
-
-
\ No newline at end of file
diff --git a/view/template/mail/settings.php b/view/template/mail/settings.php
index 31d1b0be..4f5b3c53 100644
--- a/view/template/mail/settings.php
+++ b/view/template/mail/settings.php
@@ -7,10 +7,7 @@
{{page.email_settings}}
-
-
-
- $data ?? '/']) ?>
+ $status, 'error' => $error, 'token' => $token]) ?>
{{social.also}}
@@ -19,4 +16,4 @@
- $learnFooter ?? false]) ?>
+ false]) ?>
diff --git a/web/js/emailSettings.js b/web/js/emailSettings.js
index af9adcff..8ebdd610 100644
--- a/web/js/emailSettings.js
+++ b/web/js/emailSettings.js
@@ -1,10 +1,16 @@
-lbry.emailSettingsForm = function (emailState) {
+lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) {
var
+ form = $(formSelector),
state = JSON.parse(emailState),
emails = state.emails,
tags = state.tags,
- emailTable = $('#email_table'),
- tagTable = $('#tag_table');
+ emailSection = form.find('.email-section'),
+ tagSection = form.find('.tag-section'),
+ emailTable = emailSection.find('table'),
+ tagTable = tagSection.find('table'),
+ hasError = false,
+ isEmailSubmitPending = false,
+ isTagSubmitPending = false;
$.each(emails, function(email, enabled = false){
console.log('email: ',email, ' enabled: ',enabled)
@@ -23,30 +29,63 @@ lbry.emailSettingsForm = function (emailState) {
tagTable.append($rowTag).append($labelCell).append($checkBoxCell);
});
- $('#email_form').submit(function(e) {
- e.preventDefault();
- });
- $('#tag_form').submit(function(e) {
+ function showSuccess() {
+ if (!isEmailSubmitPending && !isTagSubmitPending && !hasError)
+ {
+ form.find('.notice-success').show();
+ }
+ }
+
+ //cleverness could eliminate some mild DRY violations below
+ form.submit(function(e) {
+ //remove below obv
+ // return false;
+
e.preventDefault();
+
+ form.find('.notice').hide();
+ hasError = false;
+ isEmailSubmitPending = true;
+ isTagSubmitPending = true;
+
+ //do email edit
+ var url = 'http://localhost:8080/user/email/edit?auth_token=' + userAuthToken,
+ //Did not test below but should be close to this, it may need to be scrubbed and/or modified.
+ formData = emailSection.find(':input').serialize();
+
+
+ fetch(url, {
+ method: "POST",
+ body: formData
+ }).then(function(value) {
+ isEmailSubmitPending = false;
+ showSuccess();
+ }).catch(function(value) {
+ isEmailSubmitPending = false;
+ hasError = true;
+ var error = "get actual error message from value";
+ emailSection.find('.notice-error').html(error).show();
+ });
+
+ //do tag edit
+ var url = 'http://localhost:8080/user/fix/me?auth_token=' + userAuthToken,
+ //Did not test below but should be close to this, it may need to be scrubbed and/or modified.
+ formData = tagSection.find(':input').serialize();
+
+
+ fetch(url, {
+ method: "POST",
+ body: formData
+ }).then(function(value) {
+ isTagSubmitPending = false;
+ showSuccess();
+ }).catch(function(value) {
+ isTagSubmitPending = false;
+ hasError = true;
+ var error = "get actual error message from value";
+ tagSection.find('.notice-error').html(error).show();
+ });
});
-
-}
-
-lbry.applyEmailEdit = function () {
- console.log("applied email settings")
-
- //How do I call PHP api with the proper arguments from here?
- //Then how do I go to the page again triggering a refresh or show an error?
- //Need to get the token here as well to call the API
-
- /*let url = 'http://localhost:8080/user/email/edit?auth_token='+token+'&'
- fetch('http://localhost:8080/user/email/edit?').then(value => {
- console.log(value.json())
-
- });*/
-}
-
-lbry.applyTagEdit = function () {
- console.log("applied tag settings")
+ form.show();
}
\ No newline at end of file