PDA

View Full Version : How to change DD status?



Ex_Soft
30 Mar 2012, 11:43 AM
I want to check the existence of a draggable item in the target and change the DD status from dropAllowed to dropNotAllowed if it already exists. I'm trying


var
dropZone = Ext.create("Ext.dd.DropZone", dropTarget, {
...
notifyEnter: function(ddSource, e, data) {
if(alreadyExists(data))
ddSource.proxy.setStatus(Ext.dd.DropZone.prototype.dropNotAllowed);
}
...
});

but status doesn't change.

Ex_Soft
2 Apr 2012, 4:00 AM
Any ideas?

Ex_Soft
2 Apr 2012, 12:01 PM
notifyOver/onNodeOver works fine:


var
alreadyExists = function(target, data) {
var
text = data.records[0].get("text"),
el = Ext.fly(target),
exists = el.select(".appended");

return Ext.Array.some(exists.elements, function(item, index, allItems) {
return item.innerHTML == text;
});

},
dropZone = Ext.create("Ext.dd.DropZone", dropTarget, {
ddGroup: "tree2div",

getTargetFromEvent: function(e) {
return e.getTarget("div.drop-target");
},

notifyEnter: function(ddSource, e, data) {
return !alreadyExists(this.getTargetFromEvent(e), data) ? Ext.dd.DropZone.prototype.dropAllowed : Ext.dd.DropZone.prototype.dropNotAllowed;
},

onNodeEnter: function(target, source, e, data) {
source.proxy.setStatus(!alreadyExists(target, data) ? Ext.dd.DropZone.prototype.dropAllowed : Ext.dd.DropZone.prototype.dropNotAllowed);
},

/*notifyOver: function(ddSource, e, data) {
return !alreadyExists(this.getTargetFromEvent(e), data) ? Ext.dd.DropZone.prototype.dropAllowed : Ext.dd.DropZone.prototype.dropNotAllowed;
},*/

onNodeOver: function(target, source, e, data) {
return !alreadyExists(target, data) ? Ext.dd.DropZone.prototype.dropAllowed : Ext.dd.DropZone.prototype.dropNotAllowed;
},

onNodeDrop: function(target, dd, e, data) {
if(alreadyExists(target, data))
return false;

var
text = data.records[0].get("text"),
el = Ext.fly(target);

Ext.DomHelper.append(el, { tag: "div", html: text, cls: "appended" }) ;

return true;
}
});

But it is called many times. So alreadyExists() is called many times too. May I use notifyEnter/onNodeEnter which is called once?