[lib.client.xhr] fix when no token do not send anything [popup] added 'room.remove' popup [lib.room-controller] method 'remove' to remove a room

This commit is contained in:
xdrm-brackets 2018-03-29 12:31:23 +02:00
parent dbe360f695
commit 3e3a9197b2
5 changed files with 71 additions and 4 deletions

View File

@ -155,7 +155,8 @@ export default class XHRClientDriver extends ClientDriver{
/* (2) Open connection */
console.log(`API >>> ${this.proto}${request_uri}`);
this.xhr.open(http_method, `${this.proto}${request_uri}`, true);
this.xhr.setRequestHeader('Authorization', `Basic ${btoa(http_token)}`);
if( http_token != null )
this.xhr.setRequestHeader('Authorization', `Basic ${btoa(http_token)}`);
/* (3) Send request */
this.xhr.send(form_data);

View File

@ -103,13 +103,25 @@ export default class PopupController{
submit(){ gs.get.channel.remove() && this.parent.hide(); }
});
/* (6) Leave channel */
/* (6) Remove channel */
this.register('room.remove', {
data: {
id: '',
type: '',
name: '',
messages: []
},
reset(){ this.data = { id: '', type: '', name: '', messages: [] }; },
submit(){ gs.get.room.remove(this.data.type, this.data.id) && this.parent.hide(); }
});
/* (7) Leave channel */
this.register('channel.leave', {
reset(){ },
submit(){ gs.get.channel.remove() && this.parent.hide(); }
});
/* (6) Change password */
/* (8) Change password */
this.register('password.change', {
password: new FieldValidator('password', ''),
confirm: new FieldValidator('password', ''),

View File

@ -246,5 +246,43 @@ export default class RoomController{
}
/* (7) Remove an existing room
*
* @type<int> room type
* @rid<String> room id
*
* @return removed<bool> Whether the room has been removed
*
---------------------------------------------------------*/
remove(type=null, rid=null){
/* (1) Manage invalid @type */
if( typeof type !== 'string' || this[type] == null )
return false;
/* (2) Manage invalid @rid */
if( rid === null || isNaN(rid) )
return false;
/* (3) Try to create room in API */
api.call(`DELETE /channel/room/${gs.get.content.cid}/${rid}`, {}, function(rs){
/* (1) Manage error */
if( rs.error !== 0 )
return false;
/* (2) Reload room list */
this.fetch();
/* (3) Hide popup */
gs.get.popup.hide();
}.bind(this), auth.token);
return true;
}
}

View File

@ -121,7 +121,9 @@
<li v-for='r in rooms.list'
:class='rooms.current==r.id?`active`:``'
:data-type='r.type'
@click='gs.room.nav(r.type, r.id)'>{{ r.name }}<span class='rem' @click='gs.popup.show(`room.remove`)'></span></li>
@click='gs.room.nav(r.type, r.id)'>{{ r.name }}
<span class='rem' @click="gs.popup.show('room.remove'); gs.popup.get('room.remove').data=r"></span>
</li>
</ul>
</div>

View File

@ -99,6 +99,20 @@
</span>
</div>
<!-- Pop-up ROOM REMOVE -->
<div class='popup' v-show='gs.popup.get(`room.remove`).active'>
<span class='header'>Remove <strong>{{ gs.popup.get(`room.remove`).data.type }}</strong> room</span>
<span class='body form'>
<p>You are about to remove the room #<strong>{{ gs.popup.get(`room.remove`).data.name }}</strong>, this operation cannot be undone. All {{ gs.popup.get(`room.remove`).data.messages.length }} messages will be gone.</p>
</span>
<span class='footer form'>
<button @click='gs.popup.hide()'>Cancel</button>
<button class='submit invalid' @click='gs.popup.get(`room.remove`).submit()'>Remove</button>
</span>
</div>
<!-- Pop-up CHANNEL LEAVE -->
<div class='popup' v-show='gs.popup.get(`channel.leave`).active'>
<span class='header'>Leave channel</span>