Browse Source

Update the sorter with the possibility to check which el to drop

pull/36/head
Artur Arseniev 9 years ago
parent
commit
281694ef36
  1. 3
      src/commands/view/MoveComponent.js
  2. 3
      src/dom_components/model/ComponentTableRow.js
  3. 25
      src/utils/Sorter.js

3
src/commands/view/MoveComponent.js

@ -42,6 +42,7 @@ define(['backbone', './SelectComponent','./SelectPosition'],
// Avoid badge showing on move
this.cacheEl = null;
this.startSelectPosition(e.target, this.frameEl.contentDocument);
console.log(el.get('draggable'));
this.sorter.onEndMove = this.onEndMove.bind(this);
this.stopSelectComponent();
this.$wrapper.off('mousedown', this.initSorter);
@ -110,4 +111,4 @@ define(['backbone', './SelectComponent','./SelectPosition'],
wp.css('cursor', '').unbind().removeClass(this.noSelClass);
}
});
});
});

3
src/dom_components/model/ComponentTableRow.js

@ -5,7 +5,8 @@ define(['./Component'],
defaults: _.extend({}, Component.prototype.defaults, {
tagName: 'tr',
draggable: false
draggable: ['table', 'tbody', 'thead'],
droppable: ['th', 'td']
}),
},{

25
src/utils/Sorter.js

@ -509,7 +509,13 @@ define(['backbone'],
var targetModel = $dst.data('model');
var droppable = targetModel ? targetModel.get('droppable') : 1;
if(targetCollection && droppable){ // TODO && targetModel.get('droppable')
// Check if the target could accept the element
var accepted = 1;
if(droppable instanceof Array){
accepted = this.matches(src, droppable.join(', '));
}
if(targetCollection && droppable && accepted){ // TODO && targetModel.get('droppable')
index = pos.method === 'after' ? index + 1 : index;
var modelToDrop, modelTemp;
var opts = {at: index, noIncrement: 1};
@ -531,8 +537,19 @@ define(['backbone'],
// This will cause to recalculate children dimensions
this.prevTarget = null;
return created;
}else
console.warn("Invalid target position");
}else{
var warns = [];
if(!targetCollection){
warns.push('target collection not found');
}
if(!droppable){
warns.push('target is not droppable');
}
if(!accepted){
warns.push('target accepts only [' + droppable.join(', ') + ']');
}
console.warn('Invalid target position: ' + warns.join(', '));
}
},
/**
@ -551,4 +568,4 @@ define(['backbone'],
},
});
});
});

Loading…
Cancel
Save