146 lines
6.6 KiB
Twig
146 lines
6.6 KiB
Twig
{% extends 'base.html.twig' %}
|
|
|
|
{% block body %}
|
|
<!-- BEGIN: Subheader -->
|
|
<div class="m-subheader">
|
|
<div class="d-flex align-items-center">
|
|
<div class="mr-auto">
|
|
<h3 class="m-subheader__title">Trade-In Pricing</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- END: Subheader -->
|
|
<div class="m-content">
|
|
<div class="row">
|
|
<div class="col-xl-12">
|
|
<div class="m-portlet m-portlet--mobile">
|
|
<div class="m-portlet__body">
|
|
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
|
<div class="row align-items-center">
|
|
<div class="col-xl-12">
|
|
<div class="form-group m-form__group row align-items-center">
|
|
<div class="col-md-2">
|
|
<label>Trade-In Prices for </label>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<div class="m-input-icon m-input-icon--left">
|
|
<div class="input-group">
|
|
<select class="form-control m-input" id="price-tier-select" name="price_tier_list">
|
|
<option value="0">Default Price Tier</option>
|
|
{% for price_tier in sets.price_tiers %}
|
|
<option value="{{ price_tier.getID }}">{{ price_tier.getName }} </option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ url('trade_in_pricing_update') }}">
|
|
<input id="price-tier-id" type="hidden" name="price_tier_id" value="0">
|
|
<div style="padding-left: 25px; padding-right: 25px;">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th style="width: 100px">ID</th>
|
|
<th>Name</th>
|
|
<th style="width: 180px">Motolite</th>
|
|
<th style="width: 180px">Premium</th>
|
|
<th style="width: 180px">Other</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="table-body">
|
|
{% for id, item in items.items %}
|
|
<tr>
|
|
<td>{{ id }}</td>
|
|
<td>{{ item.name }} </td>
|
|
<td class="py-1">
|
|
<input name="motolite_tip[{{ id }}]" class="form-control ca-filter" type="number" value="{{ item.motolite_tip }}" step="0.01">
|
|
</td>
|
|
<td class="py-1">
|
|
<input name="premium_tip[{{ id }}]" class="form-control ca-filter" type="number" value="{{ item.premium_tip }}" step="0.01">
|
|
</td>
|
|
<td class="py-1">
|
|
<input name="other_tip[{{ id }}]" class="form-control ca-filter" type="number" value="{{ item.other_tip }}" step="0.01">
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
<div class="">
|
|
<input type="submit" class="btn btn-primary" value="Update Price">
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block scripts %}
|
|
<script>
|
|
|
|
initialize();
|
|
|
|
function initialize() {
|
|
init_price_tier_dropdown();
|
|
}
|
|
|
|
function init_price_tier_dropdown() {
|
|
var pt_dropdown = document.getElementById('price-tier-select');
|
|
pt_dropdown.addEventListener('change', function(e) {
|
|
load_prices(e.target.value);
|
|
});
|
|
}
|
|
|
|
function load_prices(price_tier_id) {
|
|
var req = new XMLHttpRequest();
|
|
req.onreadystatechange = function() {
|
|
// process response
|
|
if (this.readyState == 4 && this.status == 200) {
|
|
// update form
|
|
update_table(JSON.parse(req.responseText));
|
|
var pt_field = document.getElementById('price-tier-id');
|
|
pt_field.value = price_tier_id;
|
|
} else {
|
|
// console.log('could not load tier prices');
|
|
}
|
|
}
|
|
var url_pattern = '{{ url('trade_in_pricing_prices', {'pt_id': '--id--'}) }}';
|
|
var url = url_pattern.replace('--id--', price_tier_id);
|
|
console.log(url);
|
|
req.open('GET', url, true);
|
|
req.send();
|
|
}
|
|
|
|
function update_table(data) {
|
|
console.log(data);
|
|
var item_html = '';
|
|
for (var i in data.items) {
|
|
var item = data.items[i];
|
|
// console.log(item);
|
|
item_html += '<tr>';
|
|
item_html += '<td>' + item.id + '</td>';
|
|
item_html += '<td>' + item.name + '</td>';
|
|
item_html += '<td class="py-1">';
|
|
item_html += '<input name="motolite_tip[' + item.id + ']" class="form-control ca-filter" type="number" value="' + item.motolite_tip + '" step="0.01">';
|
|
item_html += '</td>';
|
|
item_html += '<td class="py-1">';
|
|
item_html += '<input name="premium_tip[' + item.id + ']" class="form-control ca-filter" type="number" value="' + item.premium_tip + '" step="0.01">';
|
|
item_html += '</td>';
|
|
item_html += '<td class="py-1">';
|
|
item_html += '<input name="other_tip[' + item.id + ']" class="form-control ca-filter" type="number" value="' + item.other_tip + '" step="0.01">';
|
|
item_html += '</td>';
|
|
item_html += '</tr>';
|
|
}
|
|
|
|
var table_body = document.getElementById('table-body');
|
|
table_body.innerHTML = item_html;
|
|
}
|
|
|
|
</script>
|
|
{% endblock %}
|