Skip to content

Commit 76ecac6

Browse files
kauffjJeremy Kauffman
authored and
Jeremy Kauffman
committed
tweaks
1 parent c3ce4f0 commit 76ecac6

File tree

5 files changed

+123
-69
lines changed

5 files changed

+123
-69
lines changed

controller/action/MailActions.class.php

+39-1
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,48 @@ public static function executeUnsubscribe(string $email)
6363
public static function editEmailSettings(string $token)
6464
{
6565
$response = LBRY::emailStatus($token);
66+
$responseData = $response['data'] ?? [];
6667
return ['mail/settings', [
67-
'status' => $response['data'] ?? '/',
68+
'emails' => $responseData['emails'] ?? [],
69+
'tags' => $responseData['tags'] ?? [],
6870
'token' => $token,
6971
'error' => $response['error'] ?? false
7072
]];
7173
}
74+
75+
public static function prepareSettingsFormPartial(array $vars)
76+
{
77+
return $vars + [
78+
'tagMetadata' => [
79+
'3d-printing' => [
80+
'label' => '3D Printing',
81+
'description' => 'Receive updates, tips, and new content suggestions related to 3D Printing.'
82+
],
83+
'android' => [
84+
'label' => 'Android',
85+
'description' => 'Be an Android beta tester, earn LBC, and receive notification when the app goes live!'
86+
],
87+
'college' => [
88+
'label' => 'University',
89+
'description' => 'LBRY has special programs and opportunities for people in school.'
90+
],
91+
'creator' => [
92+
'label' => 'Creator',
93+
'description' => 'Get the most out of the stuff you create with tips and feedback from LBRY.'
94+
],
95+
'consumer' => [
96+
'label' => 'Content Lover',
97+
'description' => 'Learn how to get the most out of LBRY as someone who just wants to find cool stuff.'
98+
],
99+
'developer' => [
100+
'label' => 'Developer',
101+
'description' => 'Receive technical updates and other news intended for those who are familiar with software engineering.'
102+
],
103+
'ios' => [
104+
'label' => 'iPhone',
105+
'description' => 'Be an iOS alpha tester, earn LBC, and receive notification when the app goes live!'
106+
],
107+
]
108+
];
109+
}
72110
}

data/i18n/en.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ page:
115115
header: Frequently Asked Questions
116116
funnier: One day this will be funnier but today is not that day.
117117
join: Join Email List
118-
email_settings: Email Settings
118+
email_settings: Email Preferences
119119
unsubscribe: Unsubscribe
120120
refer:
121121
count0: Don't fret, we still like you.

view/template/mail/_settingsForm.php

+57-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php $formId = 'email_form' ?>
22
<?php js_start() ?>
3-
lbry.emailSettingsForm("#<?php echo $formId ?>", '<?php echo json_encode($status) ?>', <?php echo json_encode($token) ?>);
3+
lbry.emailSettingsForm("#<?php echo $formId ?>", <?php echo json_encode($tags) ?>, <?php echo json_encode($token) ?>);
44
<?php js_end() ?>
5+
56
<noscript>
67
Javascript is required to securely send your unsubscribe information. Email <a href="mailto:help@lbry.io" class="link-primary">help@lbry.io</a> for manual unsubscription.
78
</noscript>
@@ -10,19 +11,63 @@
1011
<div class="notice notice-error spacer1"><?php echo $error ?></div>
1112
<?php endif ?>
1213
<div class="notice notice-success hide">Your email preferences have been updated.</div>
13-
<div class="email-section">
14+
<section class="email-section">
15+
<h4>Where do you want to receive email?</h4>
1416
<div class="notice notice-error hide spacer1"></div>
15-
<h2>Emails</h2>
16-
<h4>Choose which emails you want to receive LBRY news</h4>
17-
<table></table>
18-
</div>
19-
<div class="tag-section">
20-
<h2>Tags</h2>
21-
<h4>Any particular interests?</h4>
17+
<?php $emailIndex = 0 ?>
18+
<table>
19+
<?php foreach($emails as $email => $enabled): ?>
20+
<?php $emailId = 'email_' . (++$emailIndex) ?>
21+
<tr>
22+
<td>
23+
<div class="spacer-half">
24+
<label for="<?php echo $emailId ?>"><?php echo $email ?></label>
25+
</div>
26+
</td>
27+
<td>
28+
<div class="spacer-half" style="padding-left: 5px">
29+
<span class="slider-checkbox">
30+
<input id="<?php echo $emailId ?>" type="checkbox" <?php echo $enabled ? 'checked' : '' ?> value="<?php echo urlencode($email) ?>" />
31+
<label class="label"></label>
32+
</span>
33+
</div>
34+
</td>
35+
</tr>
36+
<?php endforeach ?>
37+
</table>
38+
</section>
39+
<section class="tag-section spacer1">
40+
<h4>What do you want to receive email about?</h4>
2241
<div class="notice notice-error hide"></div>
23-
<table id="tag_table"></table>
24-
<div>
25-
<input type="submit" value="Save" class="btn-primary">
42+
<div class="row-fluid spacer1">
43+
<?php $tagIndex = 0 ?>
44+
<?php foreach($tags as $tag => $enabled): ?>
45+
<?php $tagId = 'tag_' . (++$tagIndex) ?>
46+
<div class="span6">
47+
<div class="row-fluid">
48+
<div class="span10">
49+
<label for="<?php echo $tagId ?>"><?php echo isset($tagMetadata[$tag]['label']) ? $tagMetadata[$tag]['label'] : $tag ?></label>
50+
</div>
51+
<div class="span2">
52+
<span class="slider-checkbox">
53+
<input id="<?php echo $tagId ?>" type="checkbox" <?php echo $enabled ? 'checked' : '' ?> value="<?php echo urlencode($tag) ?>" />
54+
<label class="label"></label>
55+
</span>
56+
</div>
57+
</div>
58+
<?php if (isset($tagMetadata[$tag]['description'])): ?>
59+
<div class="meta">
60+
<?php echo $tagMetadata[$tag]['description'] ?>
61+
</div>
62+
<?php endif ?>
63+
</div>
64+
<?php if ($tagIndex % 2 == 0): ?>
65+
</div><div class="row-fluid spacer1">
66+
<?php endif ?>
67+
<?php endforeach ?>
2668
</div>
69+
</section>
70+
<div>
71+
<input type="submit" value="Save" class="btn-primary">
2772
</div>
2873
</form>

view/template/mail/settings.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
<div class="row-fluid">
88
<div class="span9">
99
<h1>{{page.email_settings}}</h1>
10-
<?php echo View::render('mail/_settingsForm', ['status' => $status, 'error' => $error, 'token' => $token]) ?>
10+
<?php echo View::render('mail/_settingsForm', [
11+
'tags' => $tags,
12+
'emails' => $emails,
13+
'error' => $error,
14+
'token' => $token
15+
]) ?>
1116
</div>
1217
<div class="span3">
1318
<h3>{{social.also}}</h3>

web/js/emailSettings.js

+20-54
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,31 @@
1-
lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) {
1+
lbry.emailSettingsForm = function (formSelector, tags, userAuthToken) {
22
var
33
form = $(formSelector),
4-
state = JSON.parse(emailState),
5-
emails = state.emails,
6-
tags = state.tags,
74
emailSection = form.find('.email-section'),
85
tagSection = form.find('.tag-section'),
9-
emailTable = emailSection.find('table'),
10-
tagTable = tagSection.find('table'),
116
hasError = false,
127
isEmailSubmitPending = false,
138
tagMap = new Map(),
149
isTagSubmitPending = false;
1510

16-
17-
$.each(emails, function(email, enabled = false){
18-
//console.log('email: ',email, ' enabled: ',enabled);
19-
$labelCell = $('<td style="padding: 5px 10px 5px 5px;" ><label>'+email+'</label></td>');
20-
var checked = enabled ? 'checked':''
21-
$checkbox = $(
22-
'<section class="slider-checkbox">' +
23-
'<input id="'+email+'" type="checkbox" '+checked+'>' +
24-
'<label class="label"></label>'+
25-
'</section>'
26-
);
27-
$checkBoxCell = $('<td style="padding: 5px 10px 5px 5px;">'+$checkbox[0].outerHTML+'</td>');
28-
$rowEmail = $('<tr>'+$labelCell[0].outerHTML+$checkBoxCell[0].outerHTML+'</tr>');
29-
emailTable.append($rowEmail)
30-
});
3111
$.each(tags, function(tag, enabled){
3212
tagMap[tag] = enabled;
33-
//console.log('tagName: ',tag,' enabled: ',enabled)
34-
$labelCell = $('<td style="padding: 5px 10px 5px 5px;"><label>'+tag+'</label></td>');
35-
var checked = enabled ? 'checked':''
36-
$checkbox = $(
37-
'<section class="slider-checkbox">' +
38-
'<input id="'+tag+'" type="checkbox" '+checked+'>' +
39-
'<label class="label"></label>'+
40-
'</section>'
41-
);
42-
$checkBoxCell = $('<td style="padding: 5px 10px 5px 5px;">'+$checkbox[0].outerHTML+'</td>');
43-
$rowTag = $('<tr>'+$labelCell[0].outerHTML+$checkBoxCell[0].outerHTML+'</tr>');
44-
tagTable.append($rowTag)
4513
});
4614

47-
//cleverness could eliminate some mild DRY violations below
4815
form.submit(function(e) {
49-
//remove below obv
50-
// return false;
5116

5217
e.preventDefault();
5318

5419
form.find('.notice').hide();
5520
hasError = false;
5621
isEmailSubmitPending = true;
5722
isTagSubmitPending = true;
23+
5824
console.log("Run Email Edit");
59-
//do email edit
6025
var url = 'https://api.lbry.io/user/email/edit?auth_token=' + userAuthToken
6126
$.param($.map(emailSection.find("input"), function(element) {
62-
console.log("email: ",element.id," is_enabled: ",element.checked);
63-
url = url + "&email="+element.id+"&enabled="+element.checked.toString();
27+
console.log("email: ",element.value," is_enabled: ",element.checked);
28+
url = url + "&email="+element.value+"&enabled="+element.checked.toString();
6429
fetch(url).then(function(value) { return value.json()}).then(jsonResponse => {
6530
isEmailSubmitPending = false;
6631
if (!jsonResponse.success){
@@ -75,22 +40,23 @@ lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) {
7540
emailSection.find('.notice-error').html(error).show();
7641
});
7742
}));
78-
console.log("Run Tag Edit");
43+
7944
//do tag edit
45+
console.log("Run Tag Edit");
8046
var url = 'https://api.lbry.io/user/tag/edit?auth_token=' + userAuthToken
81-
var addTags = new Array(),removeTags = new Array();
82-
$('#tag_table tr').each(function() {
83-
$trow = $(this);
84-
$trow.find('input').each(function () {
85-
var tagName = $(this)[0].id
86-
var enabled = $(this)[0].checked
87-
if (enabled && !tagMap[$(this)[0].id] ){
88-
addTags.push($(this)[0].id)
89-
}else if (!enabled && tagMap[$(this)[0].id]){
90-
removeTags.push($(this)[0].id)
91-
}
92-
})
47+
var addTags = new Array(),
48+
removeTags = new Array();
49+
50+
tagSection.find('input').each(function () {
51+
var tagName = this.value
52+
var enabled = this.checked
53+
if (enabled && !tagMap[tagName] ){
54+
addTags.push(tagName)
55+
} else if (!enabled && tagMap[tagName]){
56+
removeTags.push(tagName)
57+
}
9358
});
59+
9460
var hasChanges = addTags[0] || removeTags[0]
9561
console.log("AddTags: ",addTags,"RemoveTags: ",removeTags)
9662
var addTagsParam = addTags[0]
@@ -109,6 +75,7 @@ lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) {
10975
if ( removeTagsParam && removeTagsParam.length > 0){
11076
url = url + "&remove="+removeTagsParam
11177
}
78+
11279
if (hasChanges){
11380
fetch(url).then(response => { return response.json() }).then(jsonResponse =>{
11481
isTagSubmitPending = false;
@@ -127,15 +94,14 @@ lbry.emailSettingsForm = function (formSelector, emailState, userAuthToken) {
12794
} else{
12895
isTagSubmitPending = false;
12996
}
130-
13197
});
13298

13399
form.show();
134100

135101
function showSuccess() {
136102
if (!isEmailSubmitPending && !isTagSubmitPending && !hasError)
137103
{
138-
form.find('.notice-success').show();
104+
form.find('.notice-success').show().get(0).scrollIntoView();
139105
}
140106
}
141107
}

0 commit comments

Comments
 (0)