diff --git a/controller/action/MailActions.class.php b/controller/action/MailActions.class.php index 5d3d99ef..b97fe21e 100644 --- a/controller/action/MailActions.class.php +++ b/controller/action/MailActions.class.php @@ -63,10 +63,48 @@ class MailActions extends Actions public static function editEmailSettings(string $token) { $response = LBRY::emailStatus($token); + $responseData = $response['data'] ?? []; return ['mail/settings', [ - 'status' => $response['data'] ?? '/', + 'emails' => $responseData['emails'] ?? [], + 'tags' => $responseData['tags'] ?? [], 'token' => $token, 'error' => $response['error'] ?? false ]]; } + + public static function prepareSettingsFormPartial(array $vars) + { + return $vars + [ + 'tagMetadata' => [ + '3d-printing' => [ + 'label' => '3D Printing', + 'description' => 'Receive updates, tips, and new content suggestions related to 3D Printing.' + ], + 'android' => [ + 'label' => 'Android', + 'description' => 'Be an Android beta tester, earn LBC, and receive notification when the app goes live!' + ], + 'college' => [ + 'label' => 'University', + 'description' => 'LBRY has special programs and opportunities for people in school.' + ], + 'creator' => [ + 'label' => 'Creator', + 'description' => 'Get the most out of the stuff you create with tips and feedback from LBRY.' + ], + 'consumer' => [ + 'label' => 'Content Lover', + 'description' => 'Learn how to get the most out of LBRY as someone who just wants to find cool stuff.' + ], + 'developer' => [ + 'label' => 'Developer', + 'description' => 'Receive technical updates and other news intended for those who are familiar with software engineering.' + ], + 'ios' => [ + 'label' => 'iPhone', + 'description' => 'Be an iOS alpha tester, earn LBC, and receive notification when the app goes live!' + ], + ] + ]; + } } diff --git a/data/i18n/en.yaml b/data/i18n/en.yaml index a36b2523..c1d33453 100644 --- a/data/i18n/en.yaml +++ b/data/i18n/en.yaml @@ -115,7 +115,7 @@ page: header: Frequently Asked Questions funnier: One day this will be funnier but today is not that day. join: Join Email List - email_settings: Email Settings + email_settings: Email Preferences unsubscribe: Unsubscribe refer: count0: Don't fret, we still like you. diff --git a/view/template/mail/_settingsForm.php b/view/template/mail/_settingsForm.php index b62ae580..945cb309 100644 --- a/view/template/mail/_settingsForm.php +++ b/view/template/mail/_settingsForm.php @@ -1,7 +1,8 @@ - lbry.emailSettingsForm("#", '', ); + lbry.emailSettingsForm("#", , ); + @@ -10,19 +11,63 @@
Your email preferences have been updated.
-
+
+

Where do you want to receive email?

-

Emails

-

Choose which emails you want to receive LBRY news

-
-
-
-

Tags

-

Any particular interests?

+ + + $enabled): ?> + + + + + + +
+
+ +
+
+
+ + value="" /> + + +
+
+ +
+

What do you want to receive email about?

-
-
- +
+ + $enabled): ?> + +
+
+
+ +
+
+ + value="" /> + + +
+
+ +
+ +
+ +
+ +
+ +
+
+
+
\ No newline at end of file diff --git a/view/template/mail/settings.php b/view/template/mail/settings.php index 4f5b3c53..edd8ce7c 100644 --- a/view/template/mail/settings.php +++ b/view/template/mail/settings.php @@ -7,7 +7,12 @@

{{page.email_settings}}

- $status, 'error' => $error, 'token' => $token]) ?> + $tags, + 'emails' => $emails, + 'error' => $error, + 'token' => $token + ]) ?>

{{social.also}}

diff --git a/web/js/emailSettings.js b/web/js/emailSettings.js index e77105bf..1c5b3b02 100644 --- a/web/js/emailSettings.js +++ b/web/js/emailSettings.js @@ -1,53 +1,18 @@ -lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) { +lbry.emailSettingsForm = function (formSelector, tags, userAuthToken) { var form = $(formSelector), - state = JSON.parse(emailState), - emails = state.emails, - tags = state.tags, emailSection = form.find('.email-section'), tagSection = form.find('.tag-section'), - emailTable = emailSection.find('table'), - tagTable = tagSection.find('table'), hasError = false, isEmailSubmitPending = false, tagMap = new Map(), isTagSubmitPending = false; - - $.each(emails, function(email, enabled = false){ - //console.log('email: ',email, ' enabled: ',enabled); - $labelCell = $(''); - var checked = enabled ? 'checked':'' - $checkbox = $( - '
' + - '' + - ''+ - '
' - ); - $checkBoxCell = $(''+$checkbox[0].outerHTML+''); - $rowEmail = $(''+$labelCell[0].outerHTML+$checkBoxCell[0].outerHTML+''); - emailTable.append($rowEmail) - }); $.each(tags, function(tag, enabled){ tagMap[tag] = enabled; - //console.log('tagName: ',tag,' enabled: ',enabled) - $labelCell = $(''); - var checked = enabled ? 'checked':'' - $checkbox = $( - '
' + - '' + - ''+ - '
' - ); - $checkBoxCell = $(''+$checkbox[0].outerHTML+''); - $rowTag = $(''+$labelCell[0].outerHTML+$checkBoxCell[0].outerHTML+''); - tagTable.append($rowTag) }); - //cleverness could eliminate some mild DRY violations below form.submit(function(e) { - //remove below obv - // return false; e.preventDefault(); @@ -55,12 +20,12 @@ lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) { hasError = false; isEmailSubmitPending = true; isTagSubmitPending = true; + console.log("Run Email Edit"); - //do email edit var url = 'https://api.lbry.io/user/email/edit?auth_token=' + userAuthToken $.param($.map(emailSection.find("input"), function(element) { - console.log("email: ",element.id," is_enabled: ",element.checked); - url = url + "&email="+element.id+"&enabled="+element.checked.toString(); + console.log("email: ",element.value," is_enabled: ",element.checked); + url = url + "&email="+element.value+"&enabled="+element.checked.toString(); fetch(url).then(function(value) { return value.json()}).then(jsonResponse => { isEmailSubmitPending = false; if (!jsonResponse.success){ @@ -75,22 +40,23 @@ lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) { emailSection.find('.notice-error').html(error).show(); }); })); - console.log("Run Tag Edit"); + //do tag edit + console.log("Run Tag Edit"); var url = 'https://api.lbry.io/user/tag/edit?auth_token=' + userAuthToken - var addTags = new Array(),removeTags = new Array(); - $('#tag_table tr').each(function() { - $trow = $(this); - $trow.find('input').each(function () { - var tagName = $(this)[0].id - var enabled = $(this)[0].checked - if (enabled && !tagMap[$(this)[0].id] ){ - addTags.push($(this)[0].id) - }else if (!enabled && tagMap[$(this)[0].id]){ - removeTags.push($(this)[0].id) - } - }) + var addTags = new Array(), + removeTags = new Array(); + + tagSection.find('input').each(function () { + var tagName = this.value + var enabled = this.checked + if (enabled && !tagMap[tagName] ){ + addTags.push(tagName) + } else if (!enabled && tagMap[tagName]){ + removeTags.push(tagName) + } }); + var hasChanges = addTags[0] || removeTags[0] console.log("AddTags: ",addTags,"RemoveTags: ",removeTags) var addTagsParam = addTags[0] @@ -109,6 +75,7 @@ lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) { if ( removeTagsParam && removeTagsParam.length > 0){ url = url + "&remove="+removeTagsParam } + if (hasChanges){ fetch(url).then(response => { return response.json() }).then(jsonResponse =>{ isTagSubmitPending = false; @@ -127,7 +94,6 @@ lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) { } else{ isTagSubmitPending = false; } - }); form.show(); @@ -135,7 +101,7 @@ lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) { function showSuccess() { if (!isEmailSubmitPending && !isTagSubmitPending && !hasError) { - form.find('.notice-success').show(); + form.find('.notice-success').show().get(0).scrollIntoView(); } } }