Browse Source

Move the drop block logic inside BlockView and add `activate`, `select` options

pull/1229/head
Artur Arseniev 8 years ago
parent
commit
d780c80bb7
  1. 4
      src/block_manager/model/Block.js
  2. 22
      src/block_manager/view/BlockView.js
  3. 7
      src/utils/Droppable.js

4
src/block_manager/model/Block.js

@ -3,6 +3,10 @@ var Category = require('./Category');
module.exports = Backbone.Model.extend({
defaults: {
// If true, triggers an 'active' event on dropped component
activate: 0,
// If true, the dropped component will be selected
select: 0,
label: '',
content: '',
category: '',

22
src/block_manager/view/BlockView.js

@ -47,7 +47,27 @@ module.exports = Backbone.View.extend({
},
handleDragEnd() {
this.em.set('dragContent', '');
const { em, model } = this;
const result = em.get('dragResult');
if (result) {
const oldKey = 'activeOnRender';
const oldActive = result.get && result.get(oldKey);
if (model.get('activate') || oldActive) {
result.trigger('active');
result.set(oldKey, 0);
}
if (model.get('select')) {
em.setSelected(result);
}
}
em.set({
dragResult: null,
dragContent: null
});
},
/**

7
src/utils/Droppable.js

@ -72,12 +72,7 @@ export default class Droppable {
onStart: () => em.stopDefault(),
onEndMove: model => {
em.runDefault();
if (model && model.get && model.get('activeOnRender')) {
model.trigger('active');
model.set('activeOnRender', 0);
}
em.set('dragResult', model);
model && em.trigger('canvas:drop', dt, model);
},
document: canvas.getFrameEl().contentDocument

Loading…
Cancel
Save