1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| dojo.require("dojo.dnd.common");
dojo.require("dojo.dnd.Source");
dojo.require("dojox.rpc.JsonRest");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dijit.Tree");
dojo.require("dijit.tree.dndSource");
var shopping_list_store=null;
var shopping_list_items_list=null;
var shopping_list_store=null;
var shopping_list_tree_model=null;
var shopping_list_tree=null;
var shopping_list_tree_dnd =null;
dojo.addOnLoad(function(){
shopping_list_store = new dojo.data.ItemFileReadStore({
data: jsonData
});
shopping_list_tree_model = new dijit.tree.ForestStoreModel({
store: shopping_list_store,
query: {
"type": "category"
},
rootId: "root",
childrenAttrs: ["children"]
});
shopping_list_tree=new dijit.Tree({
model: shopping_list_tree_model,
showRoot: false,
dragThreshold: 8 //Nombre de pixel avant de considerer que c'est un drag and drop
}, "shopping_list_tree");
shopping_list_tree_dnd = new dijit.tree.dndSource(shopping_list_tree,
{id: "shopping_list_tree",
copyOnly: "true",
checkItemAcceptance: function(target, source) {
return false;
},
checkAcceptance: function(target, source) {
return false;
}
});
shopping_list_items_list = new dojo.dnd.Source("shopping_list_items_list",{
selfAccept: "false",
checkItemAcceptance: function(target, source) {
console.log("Check acceptance ",source);
return true;
},
checkAcceptance: function(target, source) {
return true;
}
});
dojo.connect(shopping_list_items_list, "onDndDrop", function(source, nodes, copy, target){
if (target==shopping_list_items_list) {
var obj=target.current;
console.log("current ",obj);
//delItem(mettre la clé de l'item)
nodes.forEach(function(node){
shopping_list_items_list.delItem(node.id);
});
}
});
}); |
Partager