discord-client/webpack/lib/popup-controller.js

198 lines
3.5 KiB
JavaScript
Raw Normal View History

export class PopupController{
/* (1) Construct default attributes
*
---------------------------------------------------------*/
constructor(){
2018-03-22 19:03:29 +00:00
/* (1) Global
---------------------------------------------------------*/
/* (1) Background Visibility */
this.filter = false;
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(); }
});
// this.croom = {
// active: false,
// type: 'text',
// name: '',
// }; this.reset.push(this.croom.reset);
}
/* (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 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];
}
}