Made the loan length preset buttons configurable in config.php
Supported length keywords are day, week, month and year. The plural forms are also valid. There may be minor differences in the semantics of the time string between the preset list and the default length setting, due to the default length being computed by php's Date object, while the preset list is computed in javascript on the client side.
This commit is contained in:
parent
16f48cd28d
commit
e953f6c7a5
@ -445,9 +445,7 @@
|
||||
</button>
|
||||
<br/>
|
||||
<label>Loan length:</label>
|
||||
<button onClick="JavaScript:loanLength(event, 7, 'day')">1 week</button>
|
||||
<button onClick="JavaScript:loanLength(event, 1, 'year')">1 year</button>
|
||||
<button onClick="JavaScript:loanLength(event, 3, 'year')">3 years</button>
|
||||
¤loan_presets¤
|
||||
<br/>
|
||||
<label for="end">End date:</label>
|
||||
<input type="text"
|
||||
@ -794,7 +792,6 @@
|
||||
</button>
|
||||
</form>
|
||||
|
||||
|
||||
¤¤ checkout_page ¤¤
|
||||
<div id="user-select">
|
||||
<h2>Choose borrower</h2>
|
||||
@ -874,9 +871,7 @@
|
||||
</button>
|
||||
<br/>
|
||||
<label>Loan length:</label>
|
||||
<button onClick="JavaScript:loanLength(event, 7, 'day')">1 week</button>
|
||||
<button onClick="JavaScript:loanLength(event, 1, 'year')">1 year</button>
|
||||
<button onClick="JavaScript:loanLength(event, 3, 'year')">3 years</button>
|
||||
¤loan_presets¤
|
||||
<br/>
|
||||
<label for="end">End date:</label>
|
||||
<input type="text"
|
||||
@ -890,6 +885,11 @@
|
||||
¤loan_table¤
|
||||
</div>
|
||||
|
||||
¤¤ loan_preset_button ¤¤
|
||||
<button onClick="JavaScript:loanLength(event, ¤count¤, '¤type¤')">
|
||||
¤description¤
|
||||
</button>
|
||||
|
||||
¤¤ inventory_start ¤¤
|
||||
<form class="dark"
|
||||
onSubmit="JavaScript:startInventory(event)">
|
||||
@ -899,7 +899,6 @@
|
||||
</form>
|
||||
|
||||
¤¤ inventory_do ¤¤
|
||||
|
||||
<div id="inventory-overview"
|
||||
class="dark">
|
||||
<span class="label">
|
||||
|
@ -445,9 +445,7 @@
|
||||
</button>
|
||||
<br/>
|
||||
<label>Löptid:</label>
|
||||
<button onClick="JavaScript:loanLength(event, 7, 'day')">1 vecka</button>
|
||||
<button onClick="JavaScript:loanLength(event, 1, 'year')">1 år</button>
|
||||
<button onClick="JavaScript:loanLength(event, 3, 'year')">3 år</button>
|
||||
¤loan_presets¤
|
||||
<br/>
|
||||
<label for="end">Slutdatum:</label>
|
||||
<input type="text"
|
||||
@ -874,9 +872,7 @@
|
||||
</button>
|
||||
<br/>
|
||||
<label>Löptid:</label>
|
||||
<button onClick="JavaScript:loanLength(event, 7, 'day')">1 vecka</button>
|
||||
<button onClick="JavaScript:loanLength(event, 1, 'year')">1 år</button>
|
||||
<button onClick="JavaScript:loanLength(event, 3, 'year')">3 år</button>
|
||||
¤loan_presets¤
|
||||
<br/>
|
||||
<label for="end">Slutdatum:</label>
|
||||
<input type="text"
|
||||
@ -890,6 +886,11 @@
|
||||
¤loan_table¤
|
||||
</div>
|
||||
|
||||
¤¤ loan_preset_button ¤¤
|
||||
<button onClick="JavaScript:loanLength(event, ¤count¤, '¤type¤')">
|
||||
¤description¤
|
||||
</button>
|
||||
|
||||
¤¤ inventory_start ¤¤
|
||||
<form class="dark"
|
||||
onSubmit="JavaScript:startInventory(event)">
|
||||
|
@ -95,6 +95,7 @@ class CheckoutPage extends Page {
|
||||
$subhead = replace(array('title' => i18n('Borrowed products')),
|
||||
$this->fragments['subtitle']);
|
||||
}
|
||||
$loan_presets = $this->build_loan_preset_buttons();
|
||||
print(replace(array('user' => $username,
|
||||
'email' => $email,
|
||||
'displayname' => $displayname,
|
||||
@ -102,7 +103,8 @@ class CheckoutPage extends Page {
|
||||
'end' => $enddate,
|
||||
'subtitle' => $subhead,
|
||||
'disabled' => $disabled,
|
||||
'loan_table' => $loan_table),
|
||||
'loan_table' => $loan_table,
|
||||
'loan_presets' => $loan_presets),
|
||||
$this->fragments['checkout_page']));
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,19 @@ abstract class Page extends Responder {
|
||||
$this->fragments['user_table']);
|
||||
}
|
||||
|
||||
final protected function build_loan_preset_buttons() {
|
||||
global $loan_length_presets;
|
||||
$buttons = '';
|
||||
foreach($loan_length_presets as $preset) {
|
||||
[$count, $type] = explode(' ', $preset);
|
||||
$buttons .= replace(array('count' => $count,
|
||||
'type' => $type,
|
||||
'description' => $count." ".i18n($type)),
|
||||
$this->fragments['loan_preset_button']);
|
||||
}
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
final protected function build_product_table($products) {
|
||||
usort($products, ['Product', 'compare']);
|
||||
|
||||
|
@ -70,6 +70,7 @@ class ProductPage extends Page {
|
||||
$history = $this->build_history_table($this->product->get_history());
|
||||
$attachments = $this->build_attachment_list(
|
||||
$this->product->get_attachments());
|
||||
$presets = $this->build_loan_preset_buttons();
|
||||
$fields = array('id' => $this->product->get_id(),
|
||||
'brand' => $this->product->get_brand(),
|
||||
'name' => $this->product->get_name(),
|
||||
@ -84,6 +85,7 @@ class ProductPage extends Page {
|
||||
'service' => i18n('Start service'),
|
||||
'history' => $history,
|
||||
'attachments' => $attachments,
|
||||
'loan_presets' => $presets,
|
||||
'end' => format_date(default_loan_end()));
|
||||
if(class_exists('QRcode')) {
|
||||
$fields['label'] = replace($fields,
|
||||
|
@ -295,6 +295,15 @@ function default_loan_end() {
|
||||
return $end->getTimestamp();
|
||||
}
|
||||
|
||||
function str_ends_with($haystack, $needle) {
|
||||
if(strlen($needle) === 0) {
|
||||
return true;
|
||||
}
|
||||
if(strlen($haystack) === 0) {
|
||||
return false;
|
||||
}
|
||||
return substr($haystack, -strlen($needle)) === $needle;
|
||||
}
|
||||
|
||||
### Database interaction functions ###
|
||||
|
||||
|
@ -41,6 +41,38 @@ $i18n = array(
|
||||
"en" => function() { return "Search"; },
|
||||
"sv" => function() { return "Sök"; },
|
||||
),
|
||||
"day" => array(
|
||||
"en" => function() { return "day"; },
|
||||
"sv" => function() { return "dag"; },
|
||||
),
|
||||
"days" => array(
|
||||
"en" => function() { return "days"; },
|
||||
"sv" => function() { return "dagar"; },
|
||||
),
|
||||
"week" => array(
|
||||
"en" => function() { return "week"; },
|
||||
"sv" => function() { return "vecka"; },
|
||||
),
|
||||
"weeks" => array(
|
||||
"en" => function() { return "weeks"; },
|
||||
"sv" => function() { return "veckor"; },
|
||||
),
|
||||
"month" => array(
|
||||
"en" => function() { return "month"; },
|
||||
"sv" => function() { return "månad"; },
|
||||
),
|
||||
"months" => array(
|
||||
"en" => function() { return "months"; },
|
||||
"sv" => function() { return "månader"; },
|
||||
),
|
||||
"year" => array(
|
||||
"en" => function() { return "year"; },
|
||||
"sv" => function() { return "år"; },
|
||||
),
|
||||
"years" => array(
|
||||
"en" => function() { return "years"; },
|
||||
"sv" => function() { return "år"; },
|
||||
),
|
||||
"{count} products" => array(
|
||||
"en" => function($count) { return "$count products"; },
|
||||
"sv" => function($count) { return "$count artiklar"; },
|
||||
|
10
script.js
10
script.js
@ -581,9 +581,19 @@ function loanLength(event, length, unit) {
|
||||
var enddate = new Date()
|
||||
switch(unit) {
|
||||
case 'day':
|
||||
case 'days':
|
||||
enddate.setDate(enddate.getDate() + length)
|
||||
break
|
||||
case 'week':
|
||||
case 'weeks':
|
||||
enddate.setDate(enddate.getDate() + length*7)
|
||||
break;
|
||||
case 'month':
|
||||
case 'months':
|
||||
enddate.setMonth(enddate.getMonth() + length)
|
||||
break;
|
||||
case 'year':
|
||||
case 'years':
|
||||
enddate.setFullYear(enddate.getFullYear() + length)
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user