2017-12-04 22:29:02 +00:00
|
|
|
<template>
|
|
|
|
|
2017-12-07 18:12:32 +00:00
|
|
|
<div id='CONTAINER' class='message'>
|
2017-12-04 22:29:02 +00:00
|
|
|
|
2017-12-07 19:51:06 +00:00
|
|
|
<div v-for='(msg, id) in gstore.notif.emergency.data' :class="msg.user == gstore.server.session.name ? 'me' : ''" :data-noauthor='id == 0 || gstore.notif.emergency.data[id-1].user != msg.user ? "1" : "0"'>
|
2017-12-07 18:49:57 +00:00
|
|
|
<span class='author' v-text='msg.user' v-if='id == 0 || gstore.notif.emergency.data[id-1].user != msg.user'></span>
|
|
|
|
<span class='content' v-html='bbcode(msg.message)'></span>
|
|
|
|
<span class='date' v-text='local_date(id)'></span>
|
2017-12-08 03:46:44 +00:00
|
|
|
<span @click='del_message(msg.id)' class='del' v-if='msg.user == gstore.server.session.name'></span>
|
2017-12-08 04:04:49 +00:00
|
|
|
<span @click='upd_message(msg.id, msg.message)' class='upd' v-if='msg.user == gstore.server.session.name'></span>
|
2017-12-08 04:24:18 +00:00
|
|
|
<span @click='maps(msg.location)' class='maps' v-if='msg.user != gstore.server.session.name && msg.location[0] != 0 && msg.location[1] != 0'></span>
|
2017-12-07 18:12:32 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class='end-pad'></div> <!-- End Spacing -->
|
|
|
|
|
2017-12-07 19:09:08 +00:00
|
|
|
<form class='msg-input' @submit.prevent='new_message(gstore.new_msg.emergency)'>
|
2017-12-07 18:12:32 +00:00
|
|
|
<input type='text' placeholder='Nouveau message..' id='msg-new-content' v-model='gstore.new_msg.emergency' :class='gstore.msg_pending.emergency ? "loading" : ""'>
|
|
|
|
<button></button>
|
|
|
|
</form>
|
2017-12-04 22:29:02 +00:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2017-12-07 18:12:32 +00:00
|
|
|
|
2017-12-04 22:29:02 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2017-12-07 17:17:32 +00:00
|
|
|
name: 'CONTAINER_EMERGENCY',
|
2017-12-07 21:25:39 +00:00
|
|
|
data(){ return {
|
|
|
|
gstore: gstore.data,
|
|
|
|
dep: "31"
|
|
|
|
}; },
|
2017-12-07 18:12:32 +00:00
|
|
|
methods: {
|
2017-12-08 04:24:18 +00:00
|
|
|
maps(coord){
|
|
|
|
window.open('https://www.google.com/maps/?q=-'+coord[0]+','+coord[1]);
|
|
|
|
},
|
2017-12-07 18:49:57 +00:00
|
|
|
local_date: function(id){
|
2017-12-08 01:45:23 +00:00
|
|
|
/* (1) Get current date (convert unix timestamp to javascript timestamp */
|
|
|
|
var cur = new Date( gstore.data.notif.emergency.data[id].timestamp * 1000);
|
2017-12-07 18:49:57 +00:00
|
|
|
|
|
|
|
/* (2) First line -> show whole date */
|
|
|
|
if( id < 1 )
|
|
|
|
return cur.toLocaleString();
|
|
|
|
|
|
|
|
/* (3) Get previous date */
|
|
|
|
var pre = new Date( gstore.data.notif.emergency.data[id-1].timestamp );
|
|
|
|
|
|
|
|
/* (2) If same day -> show time only */
|
|
|
|
if( cur.toLocaleDateString() == pre.toLocaleDateString() )
|
|
|
|
return cur.toLocaleTimeString();
|
|
|
|
|
|
|
|
return cur.toLocaleString();
|
|
|
|
},
|
2017-12-07 18:12:32 +00:00
|
|
|
new_message(msg){
|
|
|
|
|
2017-12-07 19:02:27 +00:00
|
|
|
/* (1) If empty message -> abort */
|
|
|
|
if( msg.trim().length == 0 )
|
|
|
|
return;
|
2017-12-07 18:12:32 +00:00
|
|
|
|
2017-12-07 19:02:27 +00:00
|
|
|
|
|
|
|
|
2017-12-08 04:04:49 +00:00
|
|
|
/* (1) If in EDIT_MODE
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
if( gstore.data.upd_msg.emergency != null ){
|
2017-12-07 21:25:39 +00:00
|
|
|
|
2017-12-08 04:04:49 +00:00
|
|
|
/* (2) Prepare request */
|
|
|
|
var rq = {
|
|
|
|
id: this.gstore.upd_msg.emergency,
|
|
|
|
message: msg
|
|
|
|
};
|
2017-12-07 21:25:39 +00:00
|
|
|
|
2017-12-08 04:04:49 +00:00
|
|
|
/* (3) Add loader */
|
|
|
|
gstore.data.msg_pending.emergency = true;
|
|
|
|
|
|
|
|
/* (4) Send request */
|
|
|
|
api.call("PUT message/emergency/"+this.dep, rq, function(rs){
|
|
|
|
|
|
|
|
// {1} If error -> exit //
|
|
|
|
if( rs.error != 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// {2} Update message content //
|
|
|
|
for( var id in gstore.data.notif.emergency.data )
|
|
|
|
if( gstore.data.notif.emergency.data[id].id == gstore.data.upd_msg.emergency )
|
|
|
|
gstore.data.notif.emergency.data[id].message = msg;
|
|
|
|
|
|
|
|
|
|
|
|
// {3} exit EDIT_MODE //
|
|
|
|
gstore.data.upd_msg.emergency = null;
|
|
|
|
|
|
|
|
// {4} Empty input //
|
|
|
|
gstore.data.new_msg.emergency = '';
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) If IN NEW_MSG_MODE
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
}else{
|
|
|
|
|
|
|
|
/* (2) Prepare request */
|
|
|
|
var rq = {
|
|
|
|
message: this.gstore.new_msg.emergency,
|
|
|
|
location: this.gstore.loc,
|
|
|
|
username: this.gstore.server.session.name
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (3) Add loader */
|
|
|
|
gstore.data.msg_pending.emergency = true;
|
|
|
|
|
|
|
|
/* (4) Send request */
|
|
|
|
api.call("POST message/emergency/"+this.dep, rq, function(rs){
|
|
|
|
|
|
|
|
// {1} If error -> exit //
|
|
|
|
if( rs.error != 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// {2} Empty input //
|
|
|
|
gstore.data.new_msg.emergency = '';
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2017-12-07 21:25:39 +00:00
|
|
|
|
2017-12-07 19:02:27 +00:00
|
|
|
|
2017-12-07 18:12:32 +00:00
|
|
|
},
|
2017-12-08 03:46:44 +00:00
|
|
|
del_message(id_msg){
|
|
|
|
api.call("DELETE message/emergency/"+this.dep, { id: id_msg }, function(rs){});
|
2017-12-08 04:04:49 +00:00
|
|
|
},
|
|
|
|
upd_message(id_msg, msg_content){
|
|
|
|
|
|
|
|
/* (1) Move to 'edit_mode' */
|
|
|
|
this.gstore.upd_msg.emergency = id_msg;
|
|
|
|
|
|
|
|
/* (2) Copy message content to INPUT */
|
|
|
|
this.gstore.new_msg.emergency = msg_content;
|
|
|
|
|
|
|
|
|
2017-12-08 03:46:44 +00:00
|
|
|
},
|
2017-12-07 18:12:32 +00:00
|
|
|
bbcode: function(msg){
|
2017-12-07 19:47:03 +00:00
|
|
|
return this.gstore.func.bbcode(msg);
|
2017-12-07 18:12:32 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-04 22:29:02 +00:00
|
|
|
}
|
|
|
|
</script>
|