Pregunta

I've create a dnd solution, with a source and target location. Right now the drag is bi-directional, I would like to have it be one-direction target to source. Then from the source add a image to each item (a delete icon), so that the users can then click the icon and send the record back to the correct target.

Part 1, I am trying to understand how to make the dnd one-directional and Part 2, how do I add an image to each item.

Thanks

¿Fue útil?

Solución

There are events which handles this in the dnd module.

as for 'part1', see this http://dojotoolkit.org/reference-guide/1.8/dojo/dnd.html#id6 and set is'Source : false on the target which should only be a target.

and with 'part2' go to http://dojotoolkit.org/reference-guide/1.8/dojo/dnd.html#id8 and read about 'onDrop'. If overloading that function in your 'target-only' source, you will gain access to the nodes which is being dropped.

 onDrop: function(source, nodes, copy) {
    dojo.forEach(nodes, function(node) {
       node.innerHTML += "<button title=Delete> X </button>";
    });
 }

Otros consejos

This is what I got working.

dojo.connect(selectedInstructions, "onDndDrop", instructions.addDeleteButton);

addDeleteButton: function (source, nodes, copy, target) {
    if (source != target) {
        dojo.forEach(nodes, function(node) {
            var instructionId = node.getAttribute("id");
            var oImg = document.createElement("img");
            oImg.setAttribute('src', 'images/delete.png');
            oImg.setAttribute('alt', 'Remove');
            oImg.setAttribute('class', 'remove_instruction');
            oImg.setAttribute('onClick', "javascript:instructions.removeInstruction('" + instructionId + "')");
            document.getElementById(instructionId).appendChild(oImg); 
        });
    }
},

I then tried to get on to work, since connect is being depreciated, but I didn't appear to have much luck. I will have to come back to it at a later date, as I am on a time crunch right now to get this code out.

on(selectedInstructions, "onDrop", instructions.addDeleteButton);
aspect.after(selectedInstructions, "onDrop", instructions.addDeleteButton);

Wish the Dojo documentation was better. Thanks goodness for the community and it's support though.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top