2022-06-29 11:28:26 +02:00
|
|
|
{% extends "default.html" %}
|
2021-12-02 17:03:13 +01:00
|
|
|
|
|
|
|
{% set active_page = "phone" %}
|
2022-06-29 11:28:26 +02:00
|
|
|
{% block title %}Phone reservation {{ phone_number.number }}{% endblock %}
|
2021-12-02 17:03:13 +01:00
|
|
|
{% block default_content %}
|
2022-06-29 11:28:26 +02:00
|
|
|
|
2021-12-02 17:03:13 +01:00
|
|
|
<div class="card">
|
|
|
|
<div class="card-body">
|
|
|
|
Your number is
|
|
|
|
<div class="d-flex mt-3">
|
|
|
|
<h2>{{ phone_number.number }}</h2>
|
|
|
|
<div class="ml-3">
|
2022-06-29 11:28:26 +02:00
|
|
|
<button data-clipboard-text="{{ phone_number.number }}"
|
|
|
|
class="clipboard btn btn-outline-primary btn-sm"
|
|
|
|
type="button">
|
2021-12-02 17:03:13 +01:00
|
|
|
<i class="fe fe-clipboard"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{% if now > reservation.end %}
|
2022-06-29 11:28:26 +02:00
|
|
|
|
2021-12-02 17:03:13 +01:00
|
|
|
was ended {{ reservation.end.humanize() }}
|
|
|
|
{% else %}
|
|
|
|
will be released {{ reservation.end.humanize() }}
|
|
|
|
{% endif %}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="card">
|
2022-01-04 16:24:50 +01:00
|
|
|
<div class="card-body" id="message-app">
|
2021-12-02 17:03:13 +01:00
|
|
|
<h2 class="mb-2">Received Messages</h2>
|
2022-06-29 11:28:26 +02:00
|
|
|
<div v-if="loading">Loading ...</div>
|
2022-01-04 16:24:50 +01:00
|
|
|
<div v-else>
|
|
|
|
<table class="table">
|
|
|
|
<thead>
|
2022-06-29 11:28:26 +02:00
|
|
|
<tr>
|
|
|
|
<th scope="col">From</th>
|
|
|
|
<th scope="col">Time</th>
|
|
|
|
<th scope="col">Message</th>
|
|
|
|
</tr>
|
2022-01-04 16:24:50 +01:00
|
|
|
</thead>
|
|
|
|
<tbody>
|
2022-06-29 11:28:26 +02:00
|
|
|
<tr v-for="message in messages">
|
|
|
|
<td>[[ message.from_number ]]</td>
|
|
|
|
<td>[[ message.created_at ]]</td>
|
|
|
|
<td>[[ message.body ]]</td>
|
|
|
|
</tr>
|
2022-01-04 16:24:50 +01:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2021-12-02 17:03:13 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{% if now < reservation.end %}
|
2022-06-29 11:28:26 +02:00
|
|
|
|
2021-12-02 17:03:13 +01:00
|
|
|
<div class="card">
|
|
|
|
<div class="card-body">
|
|
|
|
When the number is released, you can't reclaim it.
|
|
|
|
<form method="post" class="mt-3">
|
|
|
|
<input type="hidden" name="form-name" value="release">
|
|
|
|
<button class="btn btn-outline-danger">Release the number</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{% endif %}
|
2022-01-04 16:24:50 +01:00
|
|
|
{% endblock %}
|
|
|
|
{% block script %}
|
2022-06-29 11:28:26 +02:00
|
|
|
|
2022-01-04 16:24:50 +01:00
|
|
|
<script>
|
|
|
|
var app = new Vue({
|
|
|
|
el: '#message-app',
|
|
|
|
delimiters: ["[[", "]]"], // necessary to avoid conflict with jinja
|
|
|
|
data: {
|
|
|
|
messages: [],
|
|
|
|
loading: true,
|
|
|
|
},
|
|
|
|
async mounted() {
|
|
|
|
await this.loadMessage();
|
|
|
|
|
|
|
|
// refresh every 5 seconds
|
|
|
|
this.intervalId = window.setInterval(this.loadMessage, 5000)
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
loadMessage: async function () {
|
|
|
|
let that = this;
|
|
|
|
console.log("load messages");
|
|
|
|
|
|
|
|
let res = await fetch(`/api/phone/reservations/{{reservation.id}}`, {
|
|
|
|
method: "GET",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (res.ok) {
|
|
|
|
let json = await res.json();
|
|
|
|
that.messages = json.messages;
|
|
|
|
that.loading = false;
|
|
|
|
if (res.ended) {
|
|
|
|
console.log("clear interval")
|
|
|
|
window.clearInterval(that.intervalId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
2021-12-02 17:03:13 +01:00
|
|
|
{% endblock %}
|