mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
multi form refactor
This commit is contained in:
parent
ab45fce4ff
commit
18599846a7
8 changed files with 67 additions and 41 deletions
|
@ -6,6 +6,7 @@ class Session
|
|||
KEY_DOWNLOAD_ALLOWED = 'beta_download_allowed2',
|
||||
KEY_PREFINERY_USER_ID = 'prefinery_user_id',
|
||||
KEY_PREFINER_USED_CUSTOM_CODE = 'prefinery_used_custom_code',
|
||||
KEY_DEVELOPER_LAST_FORM = 'developer_last_form',
|
||||
KEY_DEVELOPER_CREDITS_ERROR = 'developer_credits_error',
|
||||
KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'developer_credits_wallet_address',
|
||||
KEY_DEVELOPER_RETURN_URL_SUCCESS = 'developer_return_url_success',
|
||||
|
|
|
@ -3,22 +3,22 @@
|
|||
class DeveloperActions extends Actions
|
||||
{
|
||||
const DEVELOPER_REWARD = 250,
|
||||
API_DOC_URL = 'https://lbryio.github.io/lbry/api/';
|
||||
API_DOC_URL = 'https://lbryio.github.io/lbry/api/';
|
||||
|
||||
public static function executeQuickstart(string $step = null)
|
||||
{
|
||||
$stepLabels = [
|
||||
'' => 'Home',
|
||||
$stepLabels = [
|
||||
'' => 'Home',
|
||||
'install' => 'Installation',
|
||||
'api' => 'The API',
|
||||
'api' => 'The API',
|
||||
'credits' => 'Credits'
|
||||
];
|
||||
$allSteps = array_keys($stepLabels);
|
||||
$allSteps = array_keys($stepLabels);
|
||||
$currentStep = $step ?: $allSteps[0];
|
||||
|
||||
$viewParams = [
|
||||
'currentStep' => $currentStep,
|
||||
'stepLabels' => $stepLabels
|
||||
'stepLabels' => $stepLabels
|
||||
];
|
||||
|
||||
if ($currentStep !== 'all')
|
||||
|
@ -49,12 +49,10 @@ class DeveloperActions extends Actions
|
|||
|
||||
public static function prepareFormNewDeveloperRewardPartial(array $vars)
|
||||
{
|
||||
$sendToGithub = !Session::get(Session::KEY_GITHUB_ACCESS_TOKEN);
|
||||
return $vars + [
|
||||
'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS),
|
||||
'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR),
|
||||
'sendToGithub' => $sendToGithub,
|
||||
'apiUrl' => LBRY::getApiUrl('/user/new_github')
|
||||
'error' => Session::get(Session::KEY_DEVELOPER_LAST_FORM) == "new_developer" ? Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR) : '',
|
||||
'apiUrl' => LBRY::getApiUrl('/user/new_github')
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -62,13 +60,15 @@ class DeveloperActions extends Actions
|
|||
{
|
||||
return $vars + [
|
||||
'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS),
|
||||
'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR),
|
||||
'error' => Session::get(Session::KEY_DEVELOPER_LAST_FORM) == "new_publish" ? Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR) : '',
|
||||
'apiUrl' => LBRY::getApiUrl('/reward/new')
|
||||
];
|
||||
}
|
||||
|
||||
public static function executeQuickstartAuth()
|
||||
{
|
||||
Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, trim(Request::getPostParam('wallet_address')));
|
||||
Session::set(Session::KEY_DEVELOPER_LAST_FORM, Request::getPostParam('formName'));
|
||||
|
||||
if (Request::getPostParam('returnUrl'))
|
||||
{
|
||||
|
@ -92,7 +92,7 @@ class DeveloperActions extends Actions
|
|||
|
||||
public static function executeQuickstartGithubCallback()
|
||||
{
|
||||
$code = Request::getParam('code');
|
||||
$code = Request::getParam('code');
|
||||
|
||||
if (!$code)
|
||||
{
|
||||
|
|
|
@ -1,25 +1,28 @@
|
|||
<form method="POST" action="/quickstart/auth" class="form-inset">
|
||||
<h4 style="margin-top: 0">Receive Credits</h4>
|
||||
<?php if ($error): ?>
|
||||
<div class="notice notice-error spacer1"><?php echo $error ?></div>
|
||||
<?php elseif ($success): ?>
|
||||
<div class="notice notice-success spacer1"><?php echo $success ?></div>
|
||||
<?php endif ?>
|
||||
<?php js_start() ?>
|
||||
lbry.quickstartForm('#form-new-publish-reward', "<?php echo $apiUrl ?>");
|
||||
<?php js_end() ?>
|
||||
<form method="POST" action="/quickstart/auth" class="form-inset" id="form-new-publish-reward">
|
||||
<h4 style="margin-top: 0">Receive Credits for Publish</h4>
|
||||
<div class="notice notice-error spacer1 <?php echo isset($error) && $error ? '' : 'hide' ?>"><?php echo $error ?? null ?></div>
|
||||
<div class="notice notice-success spacer1 hide"></div>
|
||||
<div class="form-row">
|
||||
<label for="wallet">Wallet Address</label>
|
||||
<div class="form-input">
|
||||
<input type="text" name="wallet" value="<?php echo $defaultWalletAddress ?>"
|
||||
class="required standard input-wallet" placeholder="bYnFQUPTTDM1BYNCxgxKEav4FFQsrgDBoE">
|
||||
<input type="text" name="wallet_address" value="<?php echo $defaultWalletAddress ?>"
|
||||
class="required standard " placeholder="bYnFQUPTTDM1BYNCxgxKEav4FFQsrgDBoE">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="wallet">Publishing Transaction ID</label>
|
||||
<div class="form-input">
|
||||
<input type="text" name="wallet" value="<?php echo '' ?>"
|
||||
class="required standard input-wallet" placeholder="IamATransactionID">
|
||||
<input type="text" name="transaction_hash" value="<?php echo '' ?>"
|
||||
class="required standard " placeholder="e99240e60499b372371a4e461ca25506745686b4c8fa3dd646a83f44ad358255">
|
||||
</div>
|
||||
</div>
|
||||
<div class="spacer-half">
|
||||
<input type="submit" value="Continue" class="btn-primary">
|
||||
<div class="submit-row">
|
||||
<input type="hidden" name="returnUrl" value="<?php echo $returnUrl ?? '/quickstart/credits#no-return' ?>" />
|
||||
<input type="hidden" name="formName" value="new_publish" />
|
||||
<input type="hidden" name="access_token" value="<?php echo Session::get(Session::KEY_GITHUB_ACCESS_TOKEN) ?>" />
|
||||
<input type="submit" value="Send" class="btn-primary" data-submit-label="Send" data-submitting-label="Sending credits..." />
|
||||
</div>
|
||||
</form>
|
|
@ -9,11 +9,12 @@
|
|||
<label for="wallet">Wallet Address</label>
|
||||
<div class="form-input">
|
||||
<input type="text" name="wallet_address" value="<?php echo $defaultWalletAddress ?>"
|
||||
class="required standard input-wallet" placeholder="bYnFQUPTTDM1BYNCxgxKEav4FFQsrgDBoE">
|
||||
class="required standard " placeholder="bYnFQUPTTDM1BYNCxgxKEav4FFQsrgDBoE">
|
||||
</div>
|
||||
</div>
|
||||
<div class="submit-row spacer-half">
|
||||
<input type="hidden" name="returnUrl" value="<?php echo $returnUrl ?? '/quickstart/credits#no-return' ?>" />
|
||||
<input type="hidden" name="formName" value="new_developer" />
|
||||
<input type="hidden" name="access_token" value="<?php echo Session::get(Session::KEY_GITHUB_ACCESS_TOKEN) ?>" />
|
||||
<input type="submit" value="Send" class="btn-primary" data-submit-label="Send" data-submitting-label="Sending credits..." />
|
||||
</div>
|
||||
|
|
|
@ -22,8 +22,10 @@
|
|||
"metadata": {"what goes here": "who knows if you do not work for LBRY, certainly you will not be able to figure it out from response messages or API docs"
|
||||
}]}'
|
||||
[whatever this response looks like]</code>
|
||||
<div class="quickstart__claim-form content-light content">
|
||||
<?php echo View::render('developer/_formCreditsPublish') ?>
|
||||
<div class="quickstart__claim-form content-light content" id="new-publish">
|
||||
<?php echo View::render('developer/_formCreditsPublish', [
|
||||
'returnUrl' => Request::getRelativeUri() . '#new-developer'
|
||||
]) ?>
|
||||
</div>
|
||||
<h3>Try the UI</h3>
|
||||
<p>LBRY comes with a UI so that normal people can use it to. You can download it <a href="https://lbry.io/get" class="link-primary">here</a>.</p>
|
||||
|
|
|
@ -2,17 +2,21 @@ lbry.quickstartForm = function (selector, apiUrl) {
|
|||
var form = $(selector),
|
||||
accessToken = form.find(':input[name="access_token"]').val(),
|
||||
walletAddressInput = form.find(':input[name="wallet_address"]'),
|
||||
transactionHashInput = form.find(':input[name="transaction_hash"]'),
|
||||
storageKey = form.attr('id') + "SuccessHTML",
|
||||
submitButton = form.find(':input[type="submit"]'),
|
||||
isAutomaticSubmit = false,
|
||||
isSubmitting = false;
|
||||
|
||||
function resetFormState() {
|
||||
isSubmitting = false;
|
||||
walletAddressInput.attr('readonly', null);
|
||||
transactionHashInput.attr('readonly', null);
|
||||
submitButton.val(submitButton.data('submitLabel')).attr('disabled', null);
|
||||
}
|
||||
|
||||
if (window.localStorage.getItem("quickstartFormSuccessHtml")) {
|
||||
form.find('.notice-success').html(window.localStorage.getItem("quickstartFormSuccessHtml")).show();
|
||||
if (window.localStorage.getItem(storageKey)) {
|
||||
form.find('.notice-success').html(window.localStorage.getItem(storageKey)).show();
|
||||
form.find('.form-row, .submit-row').hide();
|
||||
} else if (accessToken) {
|
||||
form.submit(function (event) {
|
||||
|
@ -20,23 +24,39 @@ lbry.quickstartForm = function (selector, apiUrl) {
|
|||
return false;
|
||||
}
|
||||
|
||||
var postData = {
|
||||
access_token: accessToken,
|
||||
wallet_address: walletAddressInput.val()
|
||||
};
|
||||
|
||||
form.find('.notice-success, .notice-error').hide();
|
||||
|
||||
if (!walletAddressInput.val()) {
|
||||
resetFormState();
|
||||
form.find('.notice-error').html("Please supply a wallet address.").show();
|
||||
if (!isAutomaticSubmit) {
|
||||
form.find('.notice-error').html("Please supply a wallet address.").show();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (transactionHashInput.length) {
|
||||
if (!transactionHashInput.val()) {
|
||||
resetFormState();
|
||||
if (!isAutomaticSubmit) {
|
||||
form.find('.notice-error').html("Please supply a transaction ID.").show();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
postData.transaction_hash = transactionHashInput.val();
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
walletAddressInput.attr('readonly', 'readonly');
|
||||
transactionHashInput.attr('readonly', 'readonly');
|
||||
submitButton.val(submitButton.data('submittingLabel')).attr('disabled', 'disabled');
|
||||
|
||||
$.post(apiUrl, {
|
||||
access_token: accessToken,
|
||||
wallet_address: walletAddressInput.val()
|
||||
})
|
||||
$.post(apiUrl)
|
||||
.done(function (responseData) {
|
||||
var data = responseData.data;
|
||||
var anchor = $('<a class="link-primary"></a>');
|
||||
|
@ -46,7 +66,7 @@ lbry.quickstartForm = function (selector, apiUrl) {
|
|||
.html(data.RewardAmount + " credits sent in transaction ")
|
||||
.append(anchor)
|
||||
.show();
|
||||
window.localStorage.setItem("quickstartFormSuccessHtml", form.find('.notice-success').html());
|
||||
window.localStorage.setItem(storageKey, form.find('.notice-success').html());
|
||||
})
|
||||
.fail(function (xhr) {
|
||||
var responseData = $.parseJSON(xhr.responseText);
|
||||
|
@ -54,6 +74,9 @@ lbry.quickstartForm = function (selector, apiUrl) {
|
|||
})
|
||||
.always(resetFormState);
|
||||
})
|
||||
|
||||
isAutomaticSubmit = true;
|
||||
form.submit();
|
||||
isAutomaticSubmit = false;
|
||||
}
|
||||
}
|
|
@ -81,11 +81,6 @@ input[type="date"] {
|
|||
vertical-align: middle;
|
||||
}
|
||||
|
||||
input.input-wallet
|
||||
{
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
textarea {
|
||||
height: auto;
|
||||
min-height: 60px;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
.quickstart__claim-form
|
||||
{
|
||||
margin: $spacing-vertical * 2 0;
|
||||
input[type="text"] { width: 100%; }
|
||||
}
|
||||
|
||||
.quickstart__progress-bar
|
||||
|
|
Loading…
Add table
Reference in a new issue