126 lines
2.6 KiB
JavaScript
126 lines
2.6 KiB
JavaScript
var bricks = window.bricks || {};
|
|
bricks.BPopup = class extends bricks.VBox {
|
|
/*
|
|
{
|
|
holder:
|
|
title:
|
|
auto_open:
|
|
auto_dismiss:
|
|
archor:cc
|
|
timeout:
|
|
}
|
|
*/
|
|
constructor(opts){
|
|
super(opts);
|
|
this.task = null;
|
|
this.title = opts.title|| 'Title';
|
|
this.archor = opts.archor || 'cc';
|
|
this.timeout = opts.timeout || 0;
|
|
this.panel.set_css('message');
|
|
this.build();
|
|
archorize(this.dom_element, this.archor);
|
|
}
|
|
|
|
build(){
|
|
var tb = new bricks.HBox({height:'40px'});
|
|
tb.set_css('title');
|
|
bricks.VBox.prototype.add_widget.bind(this)(tb);
|
|
var tit = new bricks.Text({otext:this.title, i18n:true});
|
|
this.content = new bricks.Filler({});
|
|
bricks.VBox.prototype.add_widget.bind(this)(this.content);
|
|
tb.add_widget(tit);
|
|
this.holder = bricks.Body;
|
|
if (this.opts.holder){
|
|
if (type(this.opts.holder) == 'string'){
|
|
this.holder = getWidgetById(this.opts.holder, bricks.Body);
|
|
} else {
|
|
this.holder = this.opts.holder;
|
|
}
|
|
}
|
|
}
|
|
open(){
|
|
this.holder.add_widget(this);
|
|
if (this.timeout > 0){
|
|
this.task = schedule_once(this.dismiss.bind(this), this.timeout);
|
|
}
|
|
}
|
|
add_widget(w, idx){
|
|
this.content.add_widget(w, idx);
|
|
if (this.opts.auto_open){
|
|
this.open();
|
|
}
|
|
}
|
|
dismiss(){
|
|
if (this.task){
|
|
this.task.cancel();
|
|
this.task = null
|
|
}
|
|
this.target_w.remove_widget(this);
|
|
}
|
|
}
|
|
|
|
bricks.Message = class extends bricks.Modal {
|
|
/*
|
|
{
|
|
title:
|
|
message:
|
|
}
|
|
*/
|
|
constructor(opts){
|
|
opts.auto_open = true;
|
|
super(opts);
|
|
this.create_message_widget();
|
|
this.panel.set_css('message');
|
|
}
|
|
create_message_widget(){
|
|
this.message_w = new bricks.VBox({width:'100%',height:'100%'});
|
|
var w = new bricks.Filler();
|
|
this.message_w.add_widget(w);
|
|
var t = new bricks.Text({otext:this.opts.message,
|
|
wrap:true,
|
|
halign:'middle',
|
|
i18n:true});
|
|
w.add_widget(t);
|
|
this.add_widget(this.message_w);
|
|
}
|
|
}
|
|
|
|
bricks.Error = class extends bricks.Message {
|
|
constructor(opts){
|
|
super(opts);
|
|
this.panel.set_css('error');
|
|
}
|
|
}
|
|
|
|
bricks.show_error = function(opts){
|
|
var w = new bricks.Error(opts);
|
|
w.open();
|
|
}
|
|
|
|
bricks.show_message = function(opts){
|
|
var w = new bricks.Message(opts);
|
|
w.open();
|
|
}
|
|
|
|
bricks.PopupForm = class extends bricks.BPopup {
|
|
/*
|
|
{
|
|
form:{
|
|
}
|
|
}
|
|
*/
|
|
constructor(options){
|
|
super(options);
|
|
this.form = new bricks.Form(this.opts.form);
|
|
this.add_widget(this.form);
|
|
this.form.bind('submit', this.close_popup.bind(this));
|
|
this.form.bind('discard', this.close_popup.bind(this));
|
|
}
|
|
close_popup(e){
|
|
this.dismiss();
|
|
}
|
|
}
|
|
bricks.Factory.register('Message', bricks.Message);
|
|
bricks.Factory.register('Error', bricks.Error);
|
|
bricks.Factory.register('PopupForm', bricks.PopupForm);
|