Browse Source

Fixed Sorter errors and moved them in the warning logs

pull/3281/head
Artur Arseniev 6 years ago
parent
commit
01d5aac740
  1. 54
      src/utils/Sorter.js

54
src/utils/Sorter.js

@ -478,7 +478,8 @@ export default Backbone.View.extend({
// If there is a significant changes with the pointer // If there is a significant changes with the pointer
if ( if (
!this.lastPos || !this.lastPos ||
this.lastPos.index != pos.index || this.lastPos.method != pos.method this.lastPos.index != pos.index ||
this.lastPos.method != pos.method
) { ) {
this.movePlaceholder(this.plh, dims, pos, this.prevTargetDim); this.movePlaceholder(this.plh, dims, pos, this.prevTargetDim);
if (!this.$plh) this.$plh = $(this.plh); if (!this.$plh) this.$plh = $(this.plh);
@ -1084,17 +1085,17 @@ export default Backbone.View.extend({
const { em, activeTextModel, dropContent } = this; const { em, activeTextModel, dropContent } = this;
const srcEl = getElement(src); const srcEl = getElement(src);
em && em.trigger('component:dragEnd:before', dst, srcEl, pos); // @depricated em && em.trigger('component:dragEnd:before', dst, srcEl, pos); // @depricated
var warns = []; let index = pos.indexEl;
var index = pos.indexEl; let modelToDrop, modelTemp, created;
var modelToDrop, modelTemp, created; const warns = [];
var validResult = this.validTarget(dst, srcEl); const validResult = this.validTarget(dst, srcEl);
var targetCollection = $(dst).data('collection'); const targetCollection = $(dst).data('collection');
var model = validResult.srcModel; const model = validResult.srcModel;
var droppable = validResult.droppable; let { droppable } = validResult;
var draggable = validResult.draggable; const { trgModel, draggable } = validResult;
var dropInfo = validResult.dropInfo; const dropInfo =
var dragInfo = validResult.dragInfo; validResult.dropInfo || (trgModel && trgModel.get('droppable'));
const { trgModel } = validResult; const dragInfo = validResult.dragInfo || (model && model.get('draggable'));
droppable = trgModel instanceof Backbone.Collection ? 1 : droppable; droppable = trgModel instanceof Backbone.Collection ? 1 : droppable;
const isTextableActive = this.isTextableActive(model, trgModel); const isTextableActive = this.isTextableActive(model, trgModel);
@ -1138,24 +1139,24 @@ export default Backbone.View.extend({
// This will cause to recalculate children dimensions // This will cause to recalculate children dimensions
this.prevTarget = null; this.prevTarget = null;
} else { } else if (em) {
if (!targetCollection) { !targetCollection && warns.push('Target collection not found');
warns.push('Target collection not found'); !droppable &&
} dropInfo &&
if (!droppable) {
warns.push(`Target is not droppable, accepts [${dropInfo}]`); warns.push(`Target is not droppable, accepts [${dropInfo}]`);
} !draggable &&
dragInfo &&
if (!draggable) {
warns.push(`Component not draggable, acceptable by [${dragInfo}]`); warns.push(`Component not draggable, acceptable by [${dragInfo}]`);
} em.logWarning('Invalid target position', {
errors: warns,
console.warn('Invalid target position: ' + warns.join(', ')); model,
context: 'sorter',
target: trgModel
});
} }
em && em.trigger('component:dragEnd', targetCollection, modelToDrop, warns); // @depricated if (em) {
em && em.trigger('component:dragEnd', targetCollection, modelToDrop, warns); // @depricated
em.trigger('sorter:drag:end', { em.trigger('sorter:drag:end', {
targetCollection, targetCollection,
modelToDrop, modelToDrop,
@ -1164,6 +1165,7 @@ export default Backbone.View.extend({
dst, dst,
srcEl srcEl
}); });
}
return created; return created;
}, },

Loading…
Cancel
Save