diff --git a/src/abstract/Collection.ts b/src/abstract/Collection.ts index e0d25542b..19d721d37 100644 --- a/src/abstract/Collection.ts +++ b/src/abstract/Collection.ts @@ -7,7 +7,7 @@ type ModelConstructor = { new (mod: Module, attr: export default class Collection extends Backbone.Collection { module!: Module; - private newModel!: { new (mod: Module, attr: any): TModel }; + private newModel!: ModelConstructor; //modelConstructor = {new (mod: Module, attr: any): TModel} add(model: Array> | TModel, options?: AddOptions): TModel; diff --git a/src/abstract/View.ts b/src/abstract/View.ts index 9d69aa816..72093d1ef 100644 --- a/src/abstract/View.ts +++ b/src/abstract/View.ts @@ -1,29 +1,44 @@ import Backbone from 'backbone'; +import Collection from './Collection'; import Model from './Model'; -import Module, { IBaseModule } from './Module'; +import { IBaseModule } from './Module'; -export default class View extends Backbone.View< - TModel, - TElement -> { +type ModuleFromModel = TModel extends Model ? M : unknown; +type Module = TItem extends Collection + ? ModuleFromModel + : TItem extends Model + ? M + : unknown; + +export default class View< + TModel extends Model | Collection = Model, + TElement extends Element = HTMLElement +> extends Backbone.View { protected get pfx() { - return this.ppfx + this.config.stylePrefix || ''; + return this.ppfx + (this.config as any).stylePrefix || ''; } protected get ppfx() { - return (this.em.config as any).stylePrefix || ''; + return this.em.config.stylePrefix || ''; } - protected get module(): TModel extends Model ? M : unknown { - //console.log((this.collection.first as any).module) - return this.model?.module ?? (this.collection as any).module; + collection!: TModel extends Collection ? TModel : Collection; + + protected get module(): Module { + return (this.model as any)?.module ?? this.collection.module; } protected get em() { return this.module.em; } - protected get config(): TModel extends Model ? (M extends IBaseModule ? C : unknown) : unknown { + protected get config(): Module extends IBaseModule ? C : unknown { return this.module.config as any; } + + public className!: string; + + preinitialize(options?: any) { + this.className = ''; + } } diff --git a/src/panels/index.ts b/src/panels/index.ts index c3cfb5411..a9b2cb857 100644 --- a/src/panels/index.ts +++ b/src/panels/index.ts @@ -191,15 +191,10 @@ export default class PanelManager extends Module { /** * Render panels and buttons * @return {HTMLElement} - * @private */ render() { this.PanelsViewObj && this.PanelsViewObj.remove(); - this.PanelsViewObj = new PanelsView({ - collection: this.panels, - //@ts-ignore - config: this.config, - }); + this.PanelsViewObj = new PanelsView(this.panels); return this.PanelsViewObj.render().el; } diff --git a/src/panels/model/Button.ts b/src/panels/model/Button.ts index 667f2829a..e7e3e5932 100644 --- a/src/panels/model/Button.ts +++ b/src/panels/model/Button.ts @@ -24,6 +24,35 @@ export default class Button extends Model { }; } + get className(): string { + return this.get('className'); + } + + get command(): string { + return this.get('command'); + } + + get active(): boolean { + return this.get('active'); + } + set active(isActive: boolean) { + this.set('active', isActive); + } + + get togglable(): boolean { + return this.get('togglable'); + } + + get runDefaultCommand(): boolean { + return this.get('runDefaultCommand'); + } + get stopDefaultCommand(): boolean { + return this.get('stopDefaultCommand'); + } + get disable(): boolean { + return this.get('disable'); + } + constructor(module: PanelManager, options: any) { super(module, options); if (this.get('buttons').length) { diff --git a/src/panels/model/Panel.ts b/src/panels/model/Panel.ts index 9054eb676..920a8e6fe 100644 --- a/src/panels/model/Panel.ts +++ b/src/panels/model/Panel.ts @@ -21,6 +21,8 @@ export default class Panel extends Model { this.set('buttons', buttons); } + view?: any; + constructor(module: PanelManager, options: any) { super(module, options); var btn = this.get('buttons') || []; diff --git a/src/panels/view/ButtonView.js b/src/panels/view/ButtonView.ts similarity index 75% rename from src/panels/view/ButtonView.js rename to src/panels/view/ButtonView.ts index 0ba6df7ec..d614427d3 100644 --- a/src/panels/view/ButtonView.js +++ b/src/panels/view/ButtonView.ts @@ -1,7 +1,10 @@ import { isString, isObject, isFunction } from 'underscore'; -import { View } from '../../common'; +import { View } from '../../abstract'; +import Button from '../model/Button'; +import Buttons from '../model/Buttons'; -export default class ButtonView extends View { +export default class ButtonView extends View