multi form refactor

This commit is contained in:
Jeremy Kauffman 2017-02-26 15:20:52 -05:00
parent ab45fce4ff
commit 18599846a7
8 changed files with 67 additions and 41 deletions

View file

@ -6,6 +6,7 @@ class Session
KEY_DOWNLOAD_ALLOWED = 'beta_download_allowed2', KEY_DOWNLOAD_ALLOWED = 'beta_download_allowed2',
KEY_PREFINERY_USER_ID = 'prefinery_user_id', KEY_PREFINERY_USER_ID = 'prefinery_user_id',
KEY_PREFINER_USED_CUSTOM_CODE = 'prefinery_used_custom_code', 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_ERROR = 'developer_credits_error',
KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'developer_credits_wallet_address', KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'developer_credits_wallet_address',
KEY_DEVELOPER_RETURN_URL_SUCCESS = 'developer_return_url_success', KEY_DEVELOPER_RETURN_URL_SUCCESS = 'developer_return_url_success',

View file

@ -49,11 +49,9 @@ class DeveloperActions extends Actions
public static function prepareFormNewDeveloperRewardPartial(array $vars) public static function prepareFormNewDeveloperRewardPartial(array $vars)
{ {
$sendToGithub = !Session::get(Session::KEY_GITHUB_ACCESS_TOKEN);
return $vars + [ return $vars + [
'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), '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_developer" ? Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR) : '',
'sendToGithub' => $sendToGithub,
'apiUrl' => LBRY::getApiUrl('/user/new_github') 'apiUrl' => LBRY::getApiUrl('/user/new_github')
]; ];
} }
@ -62,13 +60,15 @@ class DeveloperActions extends Actions
{ {
return $vars + [ return $vars + [
'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), '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() public static function executeQuickstartAuth()
{ {
Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, trim(Request::getPostParam('wallet_address'))); 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')) if (Request::getPostParam('returnUrl'))
{ {

View file

@ -1,25 +1,28 @@
<form method="POST" action="/quickstart/auth" class="form-inset"> <?php js_start() ?>
<h4 style="margin-top: 0">Receive Credits</h4> lbry.quickstartForm('#form-new-publish-reward', "<?php echo $apiUrl ?>");
<?php if ($error): ?> <?php js_end() ?>
<div class="notice notice-error spacer1"><?php echo $error ?></div> <form method="POST" action="/quickstart/auth" class="form-inset" id="form-new-publish-reward">
<?php elseif ($success): ?> <h4 style="margin-top: 0">Receive Credits for Publish</h4>
<div class="notice notice-success spacer1"><?php echo $success ?></div> <div class="notice notice-error spacer1 <?php echo isset($error) && $error ? '' : 'hide' ?>"><?php echo $error ?? null ?></div>
<?php endif ?> <div class="notice notice-success spacer1 hide"></div>
<div class="form-row"> <div class="form-row">
<label for="wallet">Wallet Address</label> <label for="wallet">Wallet Address</label>
<div class="form-input"> <div class="form-input">
<input type="text" name="wallet" value="<?php echo $defaultWalletAddress ?>" <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> </div>
<div class="form-row"> <div class="form-row">
<label for="wallet">Publishing Transaction ID</label> <label for="wallet">Publishing Transaction ID</label>
<div class="form-input"> <div class="form-input">
<input type="text" name="wallet" value="<?php echo '' ?>" <input type="text" name="transaction_hash" value="<?php echo '' ?>"
class="required standard input-wallet" placeholder="IamATransactionID"> class="required standard " placeholder="e99240e60499b372371a4e461ca25506745686b4c8fa3dd646a83f44ad358255">
</div> </div>
</div> </div>
<div class="spacer-half"> <div class="submit-row">
<input type="submit" value="Continue" class="btn-primary"> <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> </div>
</form> </form>

View file

@ -9,11 +9,12 @@
<label for="wallet">Wallet Address</label> <label for="wallet">Wallet Address</label>
<div class="form-input"> <div class="form-input">
<input type="text" name="wallet_address" value="<?php echo $defaultWalletAddress ?>" <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> </div>
<div class="submit-row spacer-half"> <div class="submit-row spacer-half">
<input type="hidden" name="returnUrl" value="<?php echo $returnUrl ?? '/quickstart/credits#no-return' ?>" /> <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="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..." /> <input type="submit" value="Send" class="btn-primary" data-submit-label="Send" data-submitting-label="Sending credits..." />
</div> </div>

View file

@ -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" "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> [whatever this response looks like]</code>
<div class="quickstart__claim-form content-light content"> <div class="quickstart__claim-form content-light content" id="new-publish">
<?php echo View::render('developer/_formCreditsPublish') ?> <?php echo View::render('developer/_formCreditsPublish', [
'returnUrl' => Request::getRelativeUri() . '#new-developer'
]) ?>
</div> </div>
<h3>Try the UI</h3> <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> <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>

View file

@ -2,17 +2,21 @@ lbry.quickstartForm = function (selector, apiUrl) {
var form = $(selector), var form = $(selector),
accessToken = form.find(':input[name="access_token"]').val(), accessToken = form.find(':input[name="access_token"]').val(),
walletAddressInput = form.find(':input[name="wallet_address"]'), 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"]'), submitButton = form.find(':input[type="submit"]'),
isAutomaticSubmit = false,
isSubmitting = false; isSubmitting = false;
function resetFormState() { function resetFormState() {
isSubmitting = false; isSubmitting = false;
walletAddressInput.attr('readonly', null); walletAddressInput.attr('readonly', null);
transactionHashInput.attr('readonly', null);
submitButton.val(submitButton.data('submitLabel')).attr('disabled', null); submitButton.val(submitButton.data('submitLabel')).attr('disabled', null);
} }
if (window.localStorage.getItem("quickstartFormSuccessHtml")) { if (window.localStorage.getItem(storageKey)) {
form.find('.notice-success').html(window.localStorage.getItem("quickstartFormSuccessHtml")).show(); form.find('.notice-success').html(window.localStorage.getItem(storageKey)).show();
form.find('.form-row, .submit-row').hide(); form.find('.form-row, .submit-row').hide();
} else if (accessToken) { } else if (accessToken) {
form.submit(function (event) { form.submit(function (event) {
@ -20,23 +24,39 @@ lbry.quickstartForm = function (selector, apiUrl) {
return false; return false;
} }
var postData = {
access_token: accessToken,
wallet_address: walletAddressInput.val()
};
form.find('.notice-success, .notice-error').hide(); form.find('.notice-success, .notice-error').hide();
if (!walletAddressInput.val()) { if (!walletAddressInput.val()) {
resetFormState(); resetFormState();
if (!isAutomaticSubmit) {
form.find('.notice-error').html("Please supply a wallet address.").show(); form.find('.notice-error').html("Please supply a wallet address.").show();
}
return false; 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(); event.preventDefault();
walletAddressInput.attr('readonly', 'readonly'); walletAddressInput.attr('readonly', 'readonly');
transactionHashInput.attr('readonly', 'readonly');
submitButton.val(submitButton.data('submittingLabel')).attr('disabled', 'disabled'); submitButton.val(submitButton.data('submittingLabel')).attr('disabled', 'disabled');
$.post(apiUrl, { $.post(apiUrl)
access_token: accessToken,
wallet_address: walletAddressInput.val()
})
.done(function (responseData) { .done(function (responseData) {
var data = responseData.data; var data = responseData.data;
var anchor = $('<a class="link-primary"></a>'); var anchor = $('<a class="link-primary"></a>');
@ -46,7 +66,7 @@ lbry.quickstartForm = function (selector, apiUrl) {
.html(data.RewardAmount + " credits sent in transaction ") .html(data.RewardAmount + " credits sent in transaction ")
.append(anchor) .append(anchor)
.show(); .show();
window.localStorage.setItem("quickstartFormSuccessHtml", form.find('.notice-success').html()); window.localStorage.setItem(storageKey, form.find('.notice-success').html());
}) })
.fail(function (xhr) { .fail(function (xhr) {
var responseData = $.parseJSON(xhr.responseText); var responseData = $.parseJSON(xhr.responseText);
@ -54,6 +74,9 @@ lbry.quickstartForm = function (selector, apiUrl) {
}) })
.always(resetFormState); .always(resetFormState);
}) })
isAutomaticSubmit = true;
form.submit(); form.submit();
isAutomaticSubmit = false;
} }
} }

View file

@ -81,11 +81,6 @@ input[type="date"] {
vertical-align: middle; vertical-align: middle;
} }
input.input-wallet
{
width: 400px;
}
textarea { textarea {
height: auto; height: auto;
min-height: 60px; min-height: 60px;

View file

@ -27,6 +27,7 @@
.quickstart__claim-form .quickstart__claim-form
{ {
margin: $spacing-vertical * 2 0; margin: $spacing-vertical * 2 0;
input[type="text"] { width: 100%; }
} }
.quickstart__progress-bar .quickstart__progress-bar