From ee8c97cca3a9d882f88f3301ca96aaf95fb27cbc Mon Sep 17 00:00:00 2001 From: maxkadushkin Date: Mon, 16 Jun 2025 19:22:07 +0300 Subject: [PATCH] [home] for bug 75067 --- common/loginpage/src/model.js | 52 ++++++++++++--- common/loginpage/src/paneltemplates.js | 87 +++++++++++++++++++++----- 2 files changed, 114 insertions(+), 25 deletions(-) diff --git a/common/loginpage/src/model.js b/common/loginpage/src/model.js index 3ccae7a16..7191e9221 100644 --- a/common/loginpage/src/model.js +++ b/common/loginpage/src/model.js @@ -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() { diff --git a/common/loginpage/src/paneltemplates.js b/common/loginpage/src/paneltemplates.js index a3720f1ff..01ec93b16 100644 --- a/common/loginpage/src/paneltemplates.js +++ b/common/loginpage/src/paneltemplates.js @@ -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) {