mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
instant save of email settings, slight refactor
This commit is contained in:
parent
5b8ca112d0
commit
ab2091096e
5 changed files with 74 additions and 69 deletions
2
lib/thirdparty/LBRY.class.php
vendored
2
lib/thirdparty/LBRY.class.php
vendored
|
@ -6,7 +6,7 @@ class LBRY
|
||||||
public static function getApiUrl($endpoint)
|
public static function getApiUrl($endpoint)
|
||||||
{
|
{
|
||||||
if (!strlen(Config::get(Config::LBRY_API_SERVER)) > 0) {
|
if (!strlen(Config::get(Config::LBRY_API_SERVER)) > 0) {
|
||||||
throw new Exception("API server URL is missing from `/data/config.php`");
|
throw new Exception("API server URL is missing from configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Config::get(Config::LBRY_API_SERVER) . $endpoint;
|
return Config::get(Config::LBRY_API_SERVER) . $endpoint;
|
||||||
|
|
|
@ -7,13 +7,45 @@
|
||||||
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.
|
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.
|
||||||
</noscript>
|
</noscript>
|
||||||
<form id="<?php echo $formId ?>" novalidate style="display: none">
|
<form id="<?php echo $formId ?>" novalidate style="display: none">
|
||||||
|
<div style="min-height: 48px">
|
||||||
<?php if ($error): ?>
|
<?php if ($error): ?>
|
||||||
<div class="notice notice-error spacer1"><?php echo $error ?></div>
|
<div class="notice notice-error spacer1"><?php echo $error ?></div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<div class="notice notice-success hide">Your email preferences have been updated.</div>
|
<div class="notice notice-success hide">Your email preferences have been updated.</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<section class="email-section">
|
||||||
|
<h4><?php echo count($emails ) > 1 ? 'Receiving Addresses' : 'Do You Want To Receive Mail?' ?></h4>
|
||||||
|
<?php if (count($emails) > 1): ?>
|
||||||
|
<div class="meta spacer1">Uncheck all boxes if you want to receive no future messages.</div>
|
||||||
|
<?php endif ?>
|
||||||
|
<div class="notice notice-error hide spacer1"></div>
|
||||||
|
<?php $emailIndex = 0 ?>
|
||||||
|
<table>
|
||||||
|
<?php foreach($emails as $email => $enabled): ?>
|
||||||
|
<?php $emailId = 'email_' . (++$emailIndex) ?>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="spacer-half">
|
||||||
|
<label for="<?php echo $emailId ?>"><?php echo $email ?></label>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="spacer-half" style="padding-left: 5px">
|
||||||
|
<span class="slider-checkbox">
|
||||||
|
<input id="<?php echo $emailId ?>" type="checkbox" <?php echo $enabled ? 'checked' : '' ?> value="<?php echo urlencode($email) ?>" />
|
||||||
|
<label class="label"></label>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</table>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section class="tag-section spacer1">
|
<section class="tag-section spacer1">
|
||||||
<h4>Fine-tune your newsletter</h4>
|
<h4>Fine-tune your Mail</h4>
|
||||||
<div class="notice notice-error hide"></div>
|
<div class="notice notice-error hide"></div>
|
||||||
|
|
||||||
<div class="row-fluid spacer1">
|
<div class="row-fluid spacer1">
|
||||||
|
@ -46,36 +78,4 @@
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="email-section">
|
|
||||||
<h4>Quick Unsubscribe</h4>
|
|
||||||
<div class="notice notice-error hide spacer1"></div>
|
|
||||||
<?php $emailIndex = 0 ?>
|
|
||||||
<table>
|
|
||||||
<?php foreach($emails as $email => $enabled): ?>
|
|
||||||
<?php $emailId = 'email_' . (++$emailIndex) ?>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<div class="spacer-half">
|
|
||||||
<label for="<?php echo $emailId ?>"><?php echo $email ?></label>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<div class="spacer-half" style="padding-left: 5px">
|
|
||||||
<span class="slider-checkbox">
|
|
||||||
<input id="<?php echo $emailId ?>" type="checkbox" <?php echo $enabled ? 'checked' : '' ?> value="<?php echo urlencode($email) ?>" />
|
|
||||||
<label class="label"></label>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<div class="meta">If you toggle "off" and hit "Save", you will be removed from all of our mailing lists.</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<input type="submit" value="Save" class="btn-primary">
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -12,9 +12,9 @@ lbry.emailSettingsForm = function (formSelector, tags, userAuthToken) {
|
||||||
tagMap[tag] = enabled;
|
tagMap[tag] = enabled;
|
||||||
});
|
});
|
||||||
|
|
||||||
form.submit(function(e) {
|
form.find(':input').change(submitForm);
|
||||||
|
|
||||||
e.preventDefault();
|
function submitForm() {
|
||||||
|
|
||||||
form.find('.notice').hide();
|
form.find('.notice').hide();
|
||||||
hasError = false;
|
hasError = false;
|
||||||
|
@ -23,7 +23,9 @@ lbry.emailSettingsForm = function (formSelector, tags, userAuthToken) {
|
||||||
var promiseMap = $.map(emailSection.find("input"), function (element) {
|
var promiseMap = $.map(emailSection.find("input"), function (element) {
|
||||||
var url = 'https://api.lbry.io/user/email/edit?auth_token=' + userAuthToken
|
var url = 'https://api.lbry.io/user/email/edit?auth_token=' + userAuthToken
|
||||||
url = url + "&email=" + element.value + "&enabled=" + element.checked.toString();
|
url = url + "&email=" + element.value + "&enabled=" + element.checked.toString();
|
||||||
return fetch(url).then(function(value) { return value.json()})
|
return fetch(url).then(function (value) {
|
||||||
|
return value.json()
|
||||||
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
//Call api for each email a user will have linked - polyfill needed for IE for Promise.all
|
//Call api for each email a user will have linked - polyfill needed for IE for Promise.all
|
||||||
|
@ -73,7 +75,9 @@ lbry.emailSettingsForm = function (formSelector, tags, userAuthToken) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasChanges) {
|
if (hasChanges) {
|
||||||
fetch(url).then(response => { return response.json() }).then(jsonResponse =>{
|
fetch(url).then(response => {return response.json()}
|
||||||
|
).
|
||||||
|
then(jsonResponse => {
|
||||||
isTagSubmitPending = false;
|
isTagSubmitPending = false;
|
||||||
if (jsonResponse.success) {
|
if (jsonResponse.success) {
|
||||||
showSuccess();
|
showSuccess();
|
||||||
|
@ -81,7 +85,8 @@ lbry.emailSettingsForm = function (formSelector, tags, userAuthToken) {
|
||||||
hasError = true;
|
hasError = true;
|
||||||
tagSection.find('.notice-error').html(jsonResponse.error).show();
|
tagSection.find('.notice-error').html(jsonResponse.error).show();
|
||||||
}
|
}
|
||||||
}).catch(function(value) {
|
}).
|
||||||
|
catch(function (value) {
|
||||||
isTagSubmitPending = false;
|
isTagSubmitPending = false;
|
||||||
hasError = true;
|
hasError = true;
|
||||||
tagSection.find('.notice-error').html(value.error).show();
|
tagSection.find('.notice-error').html(value.error).show();
|
||||||
|
@ -89,15 +94,16 @@ lbry.emailSettingsForm = function (formSelector, tags, userAuthToken) {
|
||||||
} else {
|
} else {
|
||||||
isTagSubmitPending = false;
|
isTagSubmitPending = false;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
form.show();
|
|
||||||
|
|
||||||
function showSuccess() {
|
function showSuccess() {
|
||||||
if (!isEmailSubmitPending && !isTagSubmitPending && !hasError)
|
if (!isEmailSubmitPending && !isTagSubmitPending && !hasError)
|
||||||
{
|
{
|
||||||
form.find('.notice-success').show().get(0).scrollIntoView();
|
form.find('.notice-success').show()
|
||||||
}
|
// .get(0).scrollIntoView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
form.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,5 +18,4 @@
|
||||||
@import "quickstart";
|
@import "quickstart";
|
||||||
@import "social";
|
@import "social";
|
||||||
@import "home";
|
@import "home";
|
||||||
@import "mail_settings";
|
|
||||||
@import "slider";
|
@import "slider";
|
Loading…
Add table
Reference in a new issue