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
|
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 lists list
shopping_list_items_list = new dojo.dnd.Source("shopping_list_items_list",{
selfAccept: "false",
checkAcceptance: function(source, nodes) { //checks, if the target can accept nodes from this source
if (source==shopping_list_tree_dnd) {
for each(node in nodes) {
var item=source.getItem(node.id).data.item;
if (item.type=="category") {
return false;
}
}
}
return true;
},
creator: function(item, hint) {
if (dojo.byId(item) && dojo.attr(item,'thing_uuid')) {
//Code pour creer l'avatar lorsque je fais l'initialisation par defaut de la liste
return {node: item, data: item.innerHTML, type: ["Text"]};
}else if(hint=="avatar") {
var dndNode;
dndNode= dojo.create("div",{innerHTML: item});
dojo.addClass(dndNode, "dojoDndItem");
return {node: dndNode, data: item, type: ["Text"]};
}else {
var dndNode;
var text;
text=shopping_list_store.getValue(item.item, 'name')
dndNode= dojo.create("div",{thing_uuid: shopping_list_store.getValue(item.item, 'id'),
innerHTML: text});
dojo.addClass(dndNode, "dojoDndItem");
return {node: dndNode, data: text, type: ["Text"]};
}
}
});
dojo.connect(shopping_list_items_list, "onDndDrop", function(source, nodes, copy, target){
if (target==shopping_list_items_list) {
if (source==shopping_list_tree_dnd) {
for each(node in nodes) {
var item=source.getItem(node.id).data.item;
dojo.xhrPost({
url: "/manag/ShoppingList/add_item",
postData: dojo.toJson({thing_uuid:item.id[0]}),
handleAs: "text",
load: function(json) {
},
error: function(error) {
console.log("Error during add item ",error);
}
});
}
}
}
});//end dojo.connect |
Partager