main/view/vue/container/emergency.vue

83 lines
2.1 KiB
Vue
Raw Normal View History

2017-12-04 22:29:02 +00:00
<template>
<div id='CONTAINER' class='message'>
2017-12-04 22:29:02 +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"'>
<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>
</div>
<div class='end-pad'></div> <!-- End Spacing -->
<form class='msg-input' @submit.prevent='new_message(gstore.new_msg.emergency)'>
<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-04 22:29:02 +00:00
</template>
<script>
export default {
name: 'CONTAINER_EMERGENCY',
2017-12-07 21:25:39 +00:00
data(){ return {
gstore: gstore.data,
dep: "31"
}; },
methods: {
local_date: function(id){
/* (1) Get current date */
var cur = new Date( gstore.data.notif.emergency.data[id].timestamp );
/* (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();
},
new_message(msg){
/* (1) If empty message -> abort */
if( msg.trim().length == 0 )
return;
2017-12-07 21:25:39 +00:00
/* (2) Prepare request */
var rq = {
message: this.gstore.new_msg.emergency,
location: this.gstore.loc,
2017-12-07 21:25:39 +00:00
username: this.gstore.server.session.name
};
/* (3) Add loader */
2017-12-07 19:03:51 +00:00
gstore.data.msg_pending.emergency = true;
2017-12-07 21:25:39 +00:00
/* (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 = '';
});
},
bbcode: function(msg){
return this.gstore.func.bbcode(msg);
}
}
2017-12-04 22:29:02 +00:00
}
</script>