*/
dojo.declare(
"openils.vandelay.TreeDndSource", dijit._tree.dndSource, {
- "_is_replaceable": function(src_item, target_item) {
+ "_is_replaceable": function(spoint, dpoint) {
/* An OP can replace anything, but non-OPs can only replace other
* non-OPs
*/
- console.log("src item: " + src_item + " target item: " + target_item);
- return true; /* XXX TODO FINISHME */
+ if (spoint.bool_op())
+ return true;
+ else if (!dpoint.bool_op())
+ return true;
+ return false;
},
"constructor": function() {
/* Given a tree object, there seems to be no way to access its
"checkItemAcceptance": function(target, source, position) {
if (!source._ready || source == this) return;
- if (this.tree.model._replace_mode) {
+ if (this.tree.model.replace_mode) {
return (
position == "over" && this._is_replaceable(
source.getAllNodes()[0].match_point,
- dijit.getEnclosingWidget(target).item.match_point
+ this.tree.model.store.getValue(
+ dijit.getEnclosingWidget(target).item,
+ "match_point"
+ )
)
);
} else {
* only when we want the item to be draggable */
},
"itemCreator": function(nodes, somethingelse) {
- console.log("gew: " + dijit.getEnclosingWidget(somethingelse).item.name);
- console.log("dojo.dnd.manager.copy: " + dojo.dnd.manager.copy);
var default_items = this.inherited(arguments);
for (var i = 0; i < default_items.length; i++)
default_items[i].match_point = nodes[i].match_point;
return default_items;
+ },
+ "onDndDrop": function(source, nodes, copy) {
+ if (
+ !this.tree.model.replace_mode ||
+ this.containerState != "Over" ||
+ this.dropPosition == "Before" ||
+ this.dropPosition == "After" ||
+ source == this
+ ) {
+ return this.inherited(arguments);
+ }
+
+ /* This method only comes into play for our "replace mode" */
+
+ var target_widget = dijit.getEnclosingWidget(this.targetAnchor);
+ var new_params = this.itemCreator(nodes, this.targetAnchor)[0];
+
+ /* Here, we morph target_widget.item into the new item */
+
+ var store = this.tree.model.store;
+ var item = target_widget.item;
+ for (var k in new_params) {
+ if (k == "id") continue; /* can't use this / don't need it */
+ store.setValue(item, k, new_params[k]);
+ }
+ if (typeof(window.render_vmsp_label) == "function") {
+ store.setValue(
+ item,
+ "name",
+ window.render_vmsp_label(new_params.match_point)
+ );
+ }
+
+ /* just because this is at the end of the default implementation: */
+ this.onDndCancel();
}
}
);
}
}
-function replace_mode() {
- tree.model._replace_mode ^= 1;
+function replace_mode(explicit) {
+ if (typeof explicit == "undefined")
+ tree.model.replace_mode ^= 1;
+ else
+ tree.model.replace_mode = explicit;
+
dojo.attr(
"replacer", "innerHTML",
localeStrings[
- (tree.model._replace_mode ? "EXIT" : "ENTER") + "_REPLACE_MODE"
+ (tree.model.replace_mode ? "EXIT" : "ENTER") + "_REPLACE_MODE"
]
);
+ dojo[tree.model.replace_mode ? "addClass" : "removeClass"](
+ "replacer", "replace-mode"
+ );
}
function delete_selected_in_tree() {
);
}
+function new_match_set_tree() {
+ var point = new vmsp();
+ point.bool_op("AND");
+ return [
+ {
+ "id": "root",
+ "children": [],
+ "name": render_vmsp_label(point),
+ "match_point": point
+ }
+ ];
+}
+
/* dojoize_match_set_tree() takes an argument, "point", that is actually a
* vmsp fieldmapper object with descendants fleshed hierarchically. It turns
* that into a syntactically flat array but preserving the hierarchy
/* XXX TODO test with deeper trees! */
var root = false;
if (!refgen) {
+ if (!point) {
+ return new_match_set_tree();
+ }
refgen = 0;
root = true;
}
pcrud = new openils.PermaCrud();
CGI = new openils.CGI();
+ if (!CGI.param("match_set")) {
+ alert(localeStrings.NO_CAN_DO);
+ progress_dialog.hide();
+ return;
+ }
+
var match_set = pcrud.retrieve("vms", CGI.param("match_set"));
render_match_set_description(match_set);
node_editor = new NodeEditor(src, "node-editor-container");
+ replace_mode(0);
+
dojo.connect(
src, "onDndDrop", null,
function(source, nodes, copy, target) {