Browse Source

Move LayersView to TS

pull/4849/head
Artur Arseniev 4 years ago
parent
commit
023dc05e0c
  1. 37
      src/style_manager/view/LayersView.ts

37
src/style_manager/view/LayersView.js → src/style_manager/view/LayersView.ts

@ -1,8 +1,18 @@
import { View } from '../../common'; import { View } from '../../common';
import Layer from '../model/Layer';
import LayerView from './LayerView'; import LayerView from './LayerView';
import PropertyStackView from './PropertyStackView';
export default class LayersView extends View { export default class LayersView extends View<Layer> {
initialize(o) { pfx: string;
ppfx: string;
config: any;
propertyView: PropertyStackView;
items: LayerView[];
sorter: any;
constructor(o: any) {
super(o);
const coll = this.collection; const coll = this.collection;
const config = o.config || {}; const config = o.config || {};
const em = config.em; const em = config.em;
@ -28,20 +38,27 @@ export default class LayersView extends View {
pfx: config.pStylePrefix, pfx: config.pStylePrefix,
}) })
: ''; : '';
// @ts-ignore
coll.view = this; coll.view = this;
this.$el.data('model', coll); this.$el.data('model', coll);
this.$el.data('collection', coll); this.$el.data('collection', coll);
} }
addTo(model) { addTo(model: Layer) {
const i = this.collection.indexOf(model); const i = this.collection.indexOf(model);
this.addToCollection(model, null, i); this.addToCollection(model, null, i);
} }
addToCollection(model, fragmentEl, index) { addToCollection(model: Layer, fragmentEl: DocumentFragment | null, index?: number) {
const fragment = fragmentEl || null; const fragment = fragmentEl || null;
const { propertyView, config, sorter, $el } = this; const { propertyView, config, sorter, $el } = this;
const view = new LayerView({ model, config, sorter, propertyView }); const view = new LayerView({
model,
// @ts-ignore
config,
sorter,
propertyView,
});
const rendered = view.render().el; const rendered = view.render().el;
this.items.push(view); this.items.push(view);
@ -59,6 +76,7 @@ export default class LayersView extends View {
if (index < 0) { if (index < 0) {
$el.append(rendered); $el.append(rendered);
} else { } else {
// @ts-ignore
$el.children().eq(index)[method](rendered); $el.children().eq(index)[method](rendered);
} }
} else { } else {
@ -69,14 +87,15 @@ export default class LayersView extends View {
return rendered; return rendered;
} }
reset(coll, opts) { reset(coll: any, opts: any) {
this.clearItems(opts); this.clearItems();
this.render(); this.render();
} }
remove() { remove() {
this.clearItems(); this.clearItems();
View.prototype.remove.apply(this, arguments); View.prototype.remove.apply(this, arguments as any);
return this;
} }
clearItems() { clearItems() {
@ -90,7 +109,7 @@ export default class LayersView extends View {
$el.empty(); $el.empty();
this.collection.forEach(m => this.addToCollection(m, frag)); this.collection.forEach(m => this.addToCollection(m, frag));
$el.append(frag); $el.append(frag);
$el.attr('class', this.className); $el.attr('class', this.className!);
if (sorter) sorter.plh = null; if (sorter) sorter.plh = null;
return this; return this;
Loading…
Cancel
Save