[home] for bug 75067

This commit is contained in:
maxkadushkin
2025-06-16 19:22:07 +03:00
parent 8934d3dd30
commit ee8c97cca3
2 changed files with 114 additions and 25 deletions

View File

@ -96,28 +96,61 @@ function Collection(attributes) {
this.events.changed = new ModelEvent(this);
this.events.erased = new ModelEvent(this);
this.events.inserted = new ModelEvent(this);
this.events.reset = new ModelEvent(this);
this.events.click = new ModelEvent(this);
this.events.contextmenu = new ModelEvent(this);
};
Collection.prototype.add = function(item) {
item.events.changed.attach(this.on_item_changed);
Collection.prototype.add = function(item, suppressevent) {
const _add_model = (m, se) => {
m.events.changed.attach(this.on_item_changed);
this.items.push(item);
this.events.inserted.notify(item);
this.items.push(m);
$('#' + item.uid).off('click contextmenu');
$('#' + item.uid).on('click', item, this.on_item_click);
$('#' + item.uid).on('contextmenu', item, this.on_item_ctxmenu);
// if ( !(suppressevent === true) )
// this.events.inserted.notify(m);
$('#' + m.uid).off('click contextmenu')
.on('click', m, this.on_item_click)
.on('contextmenu', m, this.on_item_ctxmenu);
}
if ( item instanceof Array ) {
const items = item;
items.forEach(i => {
_add_model(i, true);
});
if ( !(suppressevent === true) )
this.events.inserted.notify(items);
} else {
_add_model(item)
if ( !(suppressevent === true) )
this.events.inserted.notify(item);
}
};
Collection.prototype.set = function(items) {
if ( items instanceof Array ) {
this.empty(true);
items.forEach(i => {
this.add(i, true);
});
// this.items = items;
this.events.reset.notify(items);
}
}
Collection.prototype.find = function(key, val) {
return this.items.find(function(elem, i, arr){
return elem[key] == val;
});
};
Collection.prototype.empty = function() {
Collection.prototype.empty = function(suppressevent) {
this.items.forEach(function(model, i, a) {
$('#'+model.uid).off();
});
@ -126,7 +159,8 @@ Collection.prototype.empty = function() {
if (!!this.list) this.view.find(this.list).empty();
this.events.erased.notify();
if ( !(suppressevent === true) )
this.events.erased.notify();
};
Collection.prototype.size = function() {

View File

@ -173,8 +173,18 @@
});
collection.events.inserted.attach((col, model) => {
const $item = $(this.view.listitemtemplate(model));
if (!model.isCloud) {
let $item, isprepend = false;
if ( model instanceof Array ) {
const items = model;
$item = [], isprepend = true;
items.forEach(m => {
$item.push($(this.view.listitemtemplate(m)));
});
} else {
$item = $(this.view.listitemtemplate(model));
}
if ( isprepend === true ) {
col.list.prepend($item);
} else {
col.list.append($item);
@ -183,6 +193,21 @@
applyFilter(this.view.$panel);
});
collection.events.reset.attach((col, models) => {
let elms = [];
models.forEach(m => {
const $item = $(this.view.listitemtemplate(m));
elms.push($item);
});
if ( elms.length ) {
col.list.prepend(elms);
col.list.parent().removeClass('empty');
applyFilter(this.view.$panel);
}
});
collection.events.click.attach((col, model) => {
if (model.isCloud) {
window.sdk.openTemplate(model.path, model.name);
@ -201,24 +226,54 @@
}
Collection.prototype.emptyLocal = function() {
const cloudItems = this.items.filter(item => item.isCloud);
this.empty();
cloudItems.forEach(item => {
this.add(item);
});
// const cloudItems = this.items.filter(item => item.isCloud);
// this.empty();
// cloudItems.forEach(item => {
// this.add(item);
// });
this.items.forEach(m => {
if ( !m.isCloud ) {
const el = document.getElementById(m.uid);
if ( el ) el.remove();
}
});
const cloud_items = this.items.filter(item => item.isCloud);
this.items = cloud_items;
};
const _on_add_local_templates = function(tmpls) {
this.templates.emptyLocal();
const _func_ = () => {
this.templates.emptyLocal();
[...tmpls]
.reverse()
.forEach(item => {
const type = utils.formatToEditor(item.type);
if (['word', 'cell', 'slide', 'pdf'].includes(type)) {
this.templates.add(new FileTemplateModel(item));
}
});
let items = [];
// [...tmpls]
// .reverse()
(this.tmpls || tmpls)
.forEach(item => {
const type = utils.formatToEditor(item.type);
if (['word', 'cell', 'slide', 'pdf'].includes(type)) {
// this.templates.add(new FileTemplateModel(item));
items.push(new FileTemplateModel(item));
}
});
this.templates.add(items);
};
// if ( this.timer_id )
// this.tmpls = tmpls;
// else {
// this.timer_id = setTimeout(e => {
// this.timer_id = undefined;
// _func_();
// delete this.tmpls;
// }, 2000);
_func_();
// }
};
const _on_add_cloud_templates = function(data) {