From 5ed91bc20ccdd7667b8d30bfb7b5b76a5c5bdc0c Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 1 Jul 2017 18:10:04 +0200 Subject: [PATCH] Make freezed a status of the component --- src/dom_components/view/ComponentView.js | 27 +++++++++++++--------- src/utils/Sorter.js | 29 ++++++++++++------------ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/dom_components/view/ComponentView.js b/src/dom_components/view/ComponentView.js index e2246ced8..219ee5817 100644 --- a/src/dom_components/view/ComponentView.js +++ b/src/dom_components/view/ComponentView.js @@ -100,22 +100,27 @@ module.exports = Backbone.View.extend({ * @private * */ updateStatus(e) { - var s = this.model.get('status'); + var el = this.el; + var status = this.model.get('status'); var pfx = this.pfx; - var selectedClass = pfx + 'selected'; - var selectedParentClass = selectedClass + '-parent'; + var ppfx = this.ppfx; + var selectedCls = pfx + 'selected'; + var selectedParentCls = selectedCls + '-parent'; + var freezedCls = `${ppfx}freezed`; + var actualCls = el.getAttribute('class'); - switch(s) { + switch (status) { case 'selected': - this.$el.addClass(selectedClass); - break; + el.setAttribute('class', `${actualCls} ${selectedCls}`); + break; case 'selected-parent': - this.$el.addClass(selectedParentClass); - break; - case 'moving': - break; + el.setAttribute('class', `${actualCls} ${selectedParentCls}`); + break; + case 'freezed': + el.setAttribute('class', `${actualCls} ${freezedCls}`); + break; default: - this.$el.removeClass(`${selectedClass} ${selectedParentClass}`); + this.$el.removeClass(`${selectedCls} ${selectedParentCls} ${freezedCls}`); } }, diff --git a/src/utils/Sorter.js b/src/utils/Sorter.js index 3cd088854..da26a7060 100644 --- a/src/utils/Sorter.js +++ b/src/utils/Sorter.js @@ -220,26 +220,27 @@ module.exports = Backbone.View.extend({ /** * Picking component to move - * @param {HTMLElement} trg + * @param {HTMLElement} src * */ - startSort(trg) { + startSort(src) { this.dropModel = null; this.moved = 0; + //this.$document = $([document, trg.ownerDocument]); - if(trg && !this.matches(trg, this.itemSel + ',' + this.containerSel)) - trg = this.closest(trg, this.itemSel); + if(src && !this.matches(src, this.itemSel + ',' + this.containerSel)) + src = this.closest(src, this.itemSel); - this.eV = trg; + this.eV = src; // Create placeholder if not exists - if(!this.plh) { + if (!this.plh) { this.plh = this.createPlaceholder(); this.getContainerEl().appendChild(this.plh); } - if(trg) { - var className = trg.getAttribute('class'); - trg.setAttribute('class', `${className} ${this.freezeClass}`); + if (src) { + var srcModel = this.getSourceModel(); + srcModel.set('status', 'freezed'); this.$document.on('mouseup', this.endMove); } @@ -728,15 +729,15 @@ module.exports = Backbone.View.extend({ this.$document.off('keydown', this.rollback); this.plh.style.display = 'none'; var clsReg = new RegExp('(?:^|\\s)'+this.freezeClass+'(?!\\S)', 'gi'); - let trg = this.eV; + let src = this.eV; - if (trg) { - var className = (trg.getAttribute('class')+'').replace(clsReg, ''); - trg.setAttribute('class', className); + if (src) { + var srcModel = this.getSourceModel(); + srcModel.set('status', 'selected'); } if(this.moved) - created = this.move(this.target, trg, this.lastPos); + created = this.move(this.target, src, this.lastPos); if(this.plh) this.plh.style.display = 'none';