Browse Source

Refactor ItemsView

pull/856/head
Artur Arseniev 9 years ago
parent
commit
253d0011ab
  1. 2
      src/navigator/index.js
  2. 11
      src/navigator/view/ItemView.js
  3. 42
      src/navigator/view/ItemsView.js

2
src/navigator/index.js

@ -37,7 +37,6 @@ module.exports = () => {
options.collection = collection;
}
console.log('options', options);
layers = new View(options);
em && em.on('component:selected', this.componentChanged);
this.componentChanged();
@ -79,7 +78,6 @@ module.exports = () => {
},
render() {
console.log('render layers');
return layers.render().el;
}
};

11
src/navigator/view/ItemView.js

@ -204,13 +204,10 @@ module.exports = require('backbone').View.extend({
* */
startSort(e) {
e.stopPropagation();
//Right or middel click
if (e.button !== 0) {
return;
}
this.sorter && this.sorter.startSort(e.target);
const sorter = this.sorter;
// Right or middel click
if (e.button !== 0) return;
sorter && sorter.startSort(e.target);
},
/**

42
src/navigator/view/ItemsView.js

@ -1,7 +1,6 @@
var Backbone = require('backbone');
var ItemView = require('./ItemView');
const ItemView = require('./ItemView');
module.exports = Backbone.View.extend({
module.exports = require('backbone').View.extend({
initialize(o = {}) {
this.opt = o;
const config = o.config || {};
@ -11,33 +10,33 @@ module.exports = Backbone.View.extend({
this.ppfx = config.pStylePrefix || '';
this.pfx = config.stylePrefix || '';
this.parent = o.parent;
this.listenTo(this.collection, 'add', this.addTo);
this.listenTo(this.collection, 'reset resetNavigator', this.render);
this.className = this.pfx + 'items';
const pfx = this.pfx;
const ppfx = this.ppfx;
const parent = this.parent;
const coll = this.collection;
this.listenTo(coll, 'add', this.addTo);
this.listenTo(coll, 'reset resetNavigator', this.render);
this.className = `${pfx}layers`;
if (config.sortable && !this.opt.sorter) {
var pfx = this.pfx;
var utils = config.em.get('Utils');
const utils = config.em.get('Utils');
this.opt.sorter = new utils.Sorter({
container: config.sortContainer || this.el,
containerSel: '.' + pfx + 'items',
itemSel: '.' + pfx + 'item',
ppfx: this.ppfx,
containerSel: `.${this.className}`,
itemSel: `.${pfx}layer`,
ignoreViewChildren: 1,
avoidSelectOnEnd: 1,
pfx,
nested: 1
nested: 1,
ppfx,
pfx
});
}
this.sorter = this.opt.sorter || '';
// For the sorter
this.$el.data('collection', this.collection);
if (this.parent) {
this.$el.data('model', this.parent);
}
this.$el.data('collection', coll);
parent && this.$el.data('model', parent);
},
/**
@ -123,10 +122,11 @@ module.exports = Backbone.View.extend({
render() {
const frag = document.createDocumentFragment();
this.el.innerHTML = '';
const el = this.el;
el.innerHTML = '';
this.collection.each(model => this.addToCollection(model, frag));
this.el.appendChild(frag);
this.$el.attr('class', this.className);
el.appendChild(frag);
el.className = this.className;
return this;
}
});

Loading…
Cancel
Save