2018-03-24 15:49:00 +00:00
|
|
|
export default class PopupController{
|
2018-03-22 18:13:52 +00:00
|
|
|
|
|
|
|
/* (1) Construct default attributes
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
constructor(){
|
|
|
|
|
2018-03-22 19:03:29 +00:00
|
|
|
/* (1) Global
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Background Visibility */
|
|
|
|
this.filter = false;
|
2018-03-22 18:13:52 +00:00
|
|
|
|
2018-03-22 19:03:29 +00:00
|
|
|
/* (2) Popup set */
|
|
|
|
this.list = {};
|
|
|
|
|
|
|
|
/* (3) Active popup */
|
|
|
|
this.active = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Popups
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Create a new Room */
|
|
|
|
this.register('room.create', {
|
|
|
|
data: {
|
|
|
|
type: 'text',
|
|
|
|
name: ''
|
|
|
|
},
|
|
|
|
reset(){ this.data.type = 'text'; this.data.name = ''; },
|
|
|
|
submit(){ gs.get.room.create(this.data.type, this.data.name) && this.parent.hide(); }
|
|
|
|
});
|
2018-03-27 14:41:36 +00:00
|
|
|
/* (2) Create a new Channel */
|
|
|
|
this.register('channel.create', {
|
|
|
|
data: {
|
2018-03-27 16:21:02 +00:00
|
|
|
name: '',
|
|
|
|
link: ''
|
2018-03-27 14:41:36 +00:00
|
|
|
},
|
2018-03-27 16:21:02 +00:00
|
|
|
reset(){ this.data.link = '', this.data.name = ''; },
|
|
|
|
submit(){ gs.get.channel.create(this.data.name, this.data.link) && this.parent.hide(); }
|
2018-03-27 14:41:36 +00:00
|
|
|
});
|
2018-03-28 17:54:16 +00:00
|
|
|
/* (3) Change nickname */
|
|
|
|
this.register('nickname.change', {
|
|
|
|
data: {
|
|
|
|
value: ''
|
|
|
|
},
|
|
|
|
reset(){ this.data.value = ''; },
|
|
|
|
submit(){ gs.get.content.change_username(this.data.value) && this.parent.hide(); }
|
|
|
|
});
|
2018-03-28 18:06:26 +00:00
|
|
|
/* (4) Invite to channel */
|
|
|
|
this.register('channel.invite', {
|
|
|
|
data: {
|
|
|
|
username: ''
|
|
|
|
},
|
|
|
|
reset(){ this.data.username = ''; },
|
|
|
|
submit(){ gs.get.channel.invite(this.data.username) && this.parent.hide(); }
|
|
|
|
});
|
2018-03-22 19:03:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Regiters a new popup
|
|
|
|
*
|
|
|
|
* @name<String> Popup name
|
|
|
|
* @data<Object> Popup structure
|
|
|
|
*
|
|
|
|
* [data.structure]
|
|
|
|
* {
|
|
|
|
* reset: <Function>,
|
|
|
|
* submit: <Function>,
|
|
|
|
* active: <bool>, // will be generated automatically
|
|
|
|
* data: <Object>
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
register(name, popup){
|
|
|
|
|
|
|
|
/* (1) Error: invalid @name */
|
|
|
|
if( typeof name !== 'string' )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (2) Error: invalid @data */
|
|
|
|
if( typeof popup !== 'object' )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (3) Error: @name already used */
|
|
|
|
if( this.list[name] != null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (3) Store popup */
|
|
|
|
this.list[name] = popup;
|
|
|
|
|
|
|
|
/* (4) Add @parent ref */
|
|
|
|
this.list[name].parent = this;
|
|
|
|
|
|
|
|
/* (5) Hide by default */
|
|
|
|
this.list[name].active = false;
|
|
|
|
|
|
|
|
return true;
|
2018-03-22 18:13:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-22 19:03:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* (3) Unregiters an existing popup
|
|
|
|
*
|
|
|
|
* @name<String> Popup name
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
unregister(name){
|
|
|
|
|
|
|
|
/* (1) Error: invalid @name */
|
|
|
|
if( typeof name !== 'string' )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (2) Error: @name not used */
|
|
|
|
if( this.list[name] == null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (3) If popup is @active -> hide */
|
|
|
|
if( this.active === name )
|
|
|
|
this.hide();
|
|
|
|
|
|
|
|
/* (3) Unregister popup */
|
|
|
|
delete this.list[name];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (4) Show a popup
|
|
|
|
*
|
|
|
|
* @name<String> Popup name
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
show(name){
|
|
|
|
|
|
|
|
/* (1) Error: invalid @name */
|
|
|
|
if( typeof name !== 'string' )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (2) Error: @name not used */
|
|
|
|
if( this.list[name] == null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (3) Hide @active popup */
|
|
|
|
this.hide();
|
|
|
|
|
|
|
|
/* (4) Active popup */
|
|
|
|
this.active = name;
|
|
|
|
|
|
|
|
/* (5) Show background */
|
|
|
|
this.filter = true;
|
|
|
|
|
|
|
|
/* (6) Reset popup */
|
|
|
|
this.list[name].reset();
|
|
|
|
|
|
|
|
/* (7) Show popup */
|
|
|
|
this.list[name].active = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (5) Hide currently @active popup
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
hide(){
|
|
|
|
|
|
|
|
/* (1) Error: if no active popup */
|
|
|
|
if( this.active == null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (2) Error: @active not exists */
|
|
|
|
if( this.list[this.active] == null )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (3) Hide background */
|
|
|
|
this.filter = false;
|
|
|
|
|
|
|
|
/* (4) Hide popup */
|
|
|
|
this.list[this.active].active = false;
|
|
|
|
|
|
|
|
/* (5) Reset popup */
|
|
|
|
this.list[this.active].reset();
|
|
|
|
|
|
|
|
/* (6) Reset @active */
|
|
|
|
this.active = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (6) Data getter
|
|
|
|
*
|
|
|
|
* @name<String> Popup name
|
|
|
|
*
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
get(name){
|
|
|
|
|
|
|
|
/* (1) Error: invalid @name */
|
|
|
|
if( typeof name !== 'string' )
|
|
|
|
return { data: {} };
|
|
|
|
|
|
|
|
/* (2) Error: @name not used */
|
|
|
|
if( this.list[name] == null )
|
|
|
|
return { data: {} };
|
|
|
|
|
|
|
|
/* (3) Return data */
|
|
|
|
return this.list[name];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-22 18:13:52 +00:00
|
|
|
}
|