This commit is contained in:
yumoqing 2024-03-19 13:06:19 +08:00
parent 1ee5647c9a
commit da18bb96d8
5 changed files with 108 additions and 51 deletions

BIN
bricks/.DS_Store vendored

Binary file not shown.

View File

@ -28,10 +28,12 @@ bricks.Conform = class extends bricks.BMessage {
this.message_w.add_widget(w);
}
conform_hndl(event){
console.log(' --- conform event handling ...');
this.dismiss();
this.dispatch('conform');
}
discard_hndl(event){
console.log(' --- discard event handling ...');
this.dismiss();
}
}

View File

@ -63,12 +63,7 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
if (this.toolbar){
await this.build_toolbar();
}
if (this.editable && this.fields){
await this.build_new_form();
}
if (! this.noheader){
await this.build_header();
}
await this.build_header();
var filler = new bricks.Filler();
this.container = new bricks.VScrollPanel({ });
filler.add_widget(this.container);
@ -78,7 +73,34 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
await this.render();
}
async build_header(){
await this.build_info(this);
this.header_w = await this.build_item();
this.add_widget(this.header_w);
}
async build_item(record){
var item = new bricks.AccordionItem({});
var info = await this.build_info(item, record);
var content = new bricks.VBox({
height:'auto',
display:'none'
});
var build_content = true;
if (!record){
build_content = false;
} else {
if (this.content_rely_on){
var v = this.content_rely_value || true;
if(record[this.content_rely_on] != v){
build_content = false;
}
}
}
content.set_css('accordion-item-content');
content.hide();
if ( build_content ){
info.bind('click', this.toggle_content.bind(this, info, content, record));
}
item.add_widget(content);
return item;
}
async build_info(item, record){
@ -111,12 +133,34 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
}
return info;
}
add_record(info){
var w = info.parent;
var hided;
var content = w.children[1];
content.clear_widgets();
var hided = content.is_hide();
var fields = this.fields;
var f = new bricks.Form({
"cheight":this.editable.form_cheight||7,
"submit_url":this.editable.new_data_url,
"fields":fields
});
f.bind('cancel', this.add_record_finish.bind(this, info));
content.add_widget(f, 0);
content.show();
f.bind('submited', this.add_record_finish.bind(this, info));
}
add_record_finish(info,record){
var content = info.parent.children[1];
content.hide();
this.render();
}
update_record(info, record){
console.log('update_record():info=', info)
var w = info.parent;
var hided;
var content = w.children[1];
var hided = content.is_hide();
content.clear_widgets();
var fields = [];
for (var i=0; i< this.fields.length; i++){
var f = bricks.extend({}, this.fields[i]);
@ -129,10 +173,13 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
"fields":fields
});
content.add_widget(f, 0);
if (hided){
content.show();
}
f.bind('submited', this.update_record_finish.bind(this, info, content, hided, f));
f.bind('cancel', this.update_cancel.bind(this, info, content));
content.show();
}
update_cancel(info, content){
content.clear_widgets();
content.hide();
}
async update_record_finish(info, content, hided, form){
var d = form.getValue();
@ -155,11 +202,17 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
message:'Are you sure to delete is record?'
});
conform_w.bind('conform', this.delete_record_act.bind(this, info, record));
conform_w.bind('discard', conform_w.dismiss.bind(conform_w));
}
delete_record_act(info, record){
url = this.editable.delete_record_url + '?id=' + record.id;
var hc = new bricks.HttpClient();
var r = hc.get(url);
async delete_record_act(info, record){
var url = this.editable.delete_data_url + '?id=' + record.id;
var hc = new bricks.HttpJson();
var desc = await hc.get(url);
var w = await bricks.widgetBuild(desc);
if (desc.widgettype == 'Message'){
this.container.remove_widget(info.parent);
}
}
async build_new_form(){
var desc = {
@ -223,8 +276,24 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
}
build_record_toolbar(info, record){
var c = new bricks.Layout({cwidth:2.5, height:'auto'})
var desc;
if (! record){
c.set_style('height', '20px');
desc = {
cwidth:2.5,
tools:[
{
name:'add',
tip:'add new record',
icon:this.editable.add_icon || bricks_resource('imgs/add.png')
},
{
name:'blankicon'
}
]
}
var w = new bricks.IconBar(desc);
w.bind('add', this.add_record.bind(this, info, record));
c.add_widget(w);
return c;
}
var desc = {
@ -257,27 +326,7 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
pos = i;
}
var record = data[i];
var item = new bricks.AccordionItem({});
var info = await this.build_info(item, record);
this.content_rely_value = this.content_rely_value || true;
var build_content = true;
if (this.content_rely_on){
var v = this.content_rely_value || true;
if(record[this.content_rely_on] != v){
build_content = false;
}
}
content = null;
var content = new bricks.VBox({
height:'auto',
display:'none'
});
content.set_css('accordion-item-content');
content.hide();
if ( build_content ){
info.bind('click', this.toggle_content.bind(this, info, content, record));
}
item.add_widget(content);
var item = await this.build_item(record);
item.set_attribute('data-page', page);
this.container.add_widget(item, pos);
};

View File

@ -30,27 +30,33 @@ bricks.IconBar = class extends bricks.HBox {
w.widget_id = tools[i].name;
}
w.set_style('cursor', 'pointer');
w.bind('click', this.regen_event.bind(this,tools[i]))
this.add_widget(w);
}
this.set_style('height', this.height_int + 'px');
}
build_item(opts){
var rate = this.opts.rate || 1;
var desc = {
url:opts.icon,
rate:opts.rate || rate,
dynsize:opts.dynsize||true,
tip:opts.tip
};
var rate = opts.rate || this.opts.rate || 1;
var h = bricks.app.charsize * rate;
if (this.height_int < h){
this.height_int = h;
}
var w = new bricks.Icon(desc);
if (opts.name == 'blankicon'){
return new bricks.BlankIcon({
rate:rate,
dynsize:opts.dynsize||true
});
}
var w = new bricks.Icon({
url:opts.icon,
rate:opts.rate || rate,
dynsize:opts.dynsize||true,
tip:opts.tip
});
w.bind('click', this.regen_event.bind(this,opts));
return w;
}
regen_event(desc, event){
console.log('regen_event desc=', desc);
this.dispatch(desc.name, desc);
this.dispatch('command', desc);
event.stopPropagation();
@ -94,6 +100,7 @@ bricks.IconTextBar = class extends bricks.IconBar {
if (this.height_int < h){
this.height_int = h;
}
box.bind('click', this.regen_event.bind(this,opts));
return box;
}
}

View File

@ -12,11 +12,10 @@ bricks.BPopup = class extends bricks.VBox {
*/
constructor(opts){
super(opts);
this.holder = opts.holder;
this.task = null;
this.title = opts.title|| 'Title';
this.archor = opts.archor || 'cc';
this.timeout = opts.timeout;
this.timeout = opts.timeout || 0;
this.panel.set_css('message');
this.build();
archorize(this.dom_element, this.archor);
@ -41,7 +40,7 @@ bricks.BPopup = class extends bricks.VBox {
}
open(){
this.holder.add_widget(this);
if (this.timeout && this.timeout > 0){
if (this.timeout > 0){
this.task = schedule_once(this.dismiss.bind(this), this.timeout);
}
}
@ -56,7 +55,7 @@ bricks.BPopup = class extends bricks.VBox {
this.task.cancel();
this.task = null
}
this.holder.remove_widget(this);
this.target_w.remove_widget(this);
}
}