Browse Source

Render Layers always via Model

dynamic-layer-root
Artur Arseniev 8 years ago
parent
commit
9feb91e3f7
  1. 18
      src/navigator/index.js
  2. 34
      src/navigator/view/ItemView.js

18
src/navigator/index.js

@ -1,13 +1,11 @@
import defaults from './config/config'; import defaults from './config/config';
import ItemView from './view/ItemView'; import ItemView from './view/ItemView';
import ItemsView from './view/ItemsView';
import { isElement } from 'underscore'; import { isElement } from 'underscore';
module.exports = () => { module.exports = () => {
let em; let em;
let layers; let layers;
let config = {}; let config = {};
let View = ItemsView;
return { return {
name: 'LayerManager', name: 'LayerManager',
@ -20,7 +18,12 @@ module.exports = () => {
return this; return this;
}, },
getConfig() {
return config;
},
onLoad() { onLoad() {
/*
const collection = em.get('DomComponents').getComponents(); const collection = em.get('DomComponents').getComponents();
const parent = collection.parent; const parent = collection.parent;
const options = { const options = {
@ -36,8 +39,14 @@ module.exports = () => {
} else { } else {
options.collection = collection; options.collection = collection;
} }
*/
layers = new View(options); layers = new ItemView({
level: 0,
config,
opened: config.opened || {},
model: em.get('DomComponents').getWrapper()
});
em && em.on('component:selected', this.componentChanged); em && em.on('component:selected', this.componentChanged);
this.componentChanged(); this.componentChanged();
}, },
@ -45,6 +54,9 @@ module.exports = () => {
postRender() { postRender() {
const elTo = config.appendTo; const elTo = config.appendTo;
if (config.root) {
}
if (elTo) { if (elTo) {
const el = isElement(elTo) ? elTo : document.querySelector(elTo); const el = isElement(elTo) ? elTo : document.querySelector(elTo);
el.appendChild(this.render()); el.appendChild(this.render());

34
src/navigator/view/ItemView.js

@ -25,6 +25,7 @@ module.exports = require('backbone').View.extend({
const clsCaret = `${this.clsCaret} fa fa-chevron-right`; const clsCaret = `${this.clsCaret} fa fa-chevron-right`;
const clsInput = `${this.inputNameCls} ${ppfx}no-app`; const clsInput = `${this.inputNameCls} ${ppfx}no-app`;
const level = this.level + 1; const level = this.level + 1;
const hideWrapper = !this.config.showWrapper && level === 1;
const gut = `${30 + level * 10}px`; const gut = `${30 + level * 10}px`;
const name = model.getName(); const name = model.getName();
return ` return `
@ -35,20 +36,25 @@ module.exports = require('backbone').View.extend({
}" data-toggle-visible></i>` }" data-toggle-visible></i>`
: '' : ''
} }
${
<div class="${clsTitleC}"> !hideWrapper
<div class="${clsTitle}" style="padding-left: ${gut}" data-toggle-select> ? `
<div class="${pfx}layer-title-inn"> <div class="${clsTitleC}">
<i class="${clsCaret}" data-toggle-open></i> <div class="${clsTitle}" style="padding-left: ${gut}" data-toggle-select>
${model.getIcon()} <div class="${pfx}layer-title-inn">
<span class="${clsInput}" data-name>${name}</span> <i class="${clsCaret}" data-toggle-open></i>
${model.getIcon()}
<span class="${clsInput}" data-name>${name}</span>
</div>
</div>
</div>
<div class="${this.clsCount}">${count || ''}</div>
<div class="${this.clsMove}" data-toggle-move>
<i class="fa fa-arrows"></i>
</div> </div>
</div> `
</div> : ''
<div class="${this.clsCount}">${count || ''}</div> }
<div class="${this.clsMove}" data-toggle-move>
<i class="fa fa-arrows"></i>
</div>
<div class="${this.clsChildren}"></div> <div class="${this.clsChildren}"></div>
`; `;
}, },
@ -314,7 +320,7 @@ module.exports = require('backbone').View.extend({
}, },
getCaret() { getCaret() {
if (!this.caret) { if (!this.caret || !this.caret.length) {
const pfx = this.pfx; const pfx = this.pfx;
this.caret = this.$el this.caret = this.$el
.children(`.${this.clsTitleC}`) .children(`.${this.clsTitleC}`)

Loading…
Cancel
Save