dojo.provide("openils.vandelay.TreeDndSource");
dojo.require("dijit._tree.dndSource");
+/* This class specifically serves the eg/vandelay/match_set interface
+ * for editing Vandelay Match Set trees. It should probably have a more
+ * specific name that reflects that.
+ */
dojo.declare(
"openils.vandelay.TreeDndSource", dijit._tree.dndSource, {
"checkItemAcceptance": function(target, source, position) {
- /* Here we'll return false if source has no fm object in the right place */
- console.log(
- "target: " + dijit.getEnclosingWidget(target).item.name +
- " source: " + source +
- " position: " + position
+ return (
+ source._ready && (
+ position != "over" ||
+ this.tree.model.mayHaveChildren(
+ dijit.getEnclosingWidget(target).item
+ )
+ )
);
- return true;
+ /* code in match_set.js makes sure that source._ready gets set true
+ * only when we want the item to be draggable */
+ },
+ "itemCreator": function(nodes) {
+ 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;
}
}
);
dojo.provide("openils.vandelay.TreeStoreModel");
dojo.require("dijit.tree.TreeStoreModel");
+dojo.require("openils.Util");
+
+/* This class specifically serves the eg/vandelay/match_set interface
+ * for editing Vandelay Match Set trees. It should probably have a more
+ * specific name that reflects that.
+ */
function _simple_item(model, item) {
/* Instead of model.getLabel(), could do
* model.store.getValue(item, "blah") or something like that ... */
return {
"label": model.getLabel(item),
+ "match_point": String(model.store.getValue(item, "match_point")),
"children": {}
};
}
}
);
}
+ },
+ "mayHaveChildren": function(item) {
+ var match_point = this.store.getValue(item, "match_point");
+ if (match_point)
+ return openils.Util.isTrue(match_point.bool_op());
+ else
+ return true;
}
+// "newItem": function(args, parent) {
+// if (!this.mayHaveChildren(parent)) return;
+// return this.inherited(arguments);
+// }
}
);
-dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dijit.Tree");
dojo.require("dijit.form.Button");
+dojo.require("dojo.data.ItemFileWriteStore");
+//dojo.require("openils.vandelay.DndSource");
dojo.require("dojo.dnd.Source");
-dojo.require("dijit._tree.dndSource");
-//dojo.require("openils.vandelay.TreeDndSource");
+dojo.require("openils.vandelay.TreeDndSource");
dojo.require("openils.vandelay.TreeStoreModel");
dojo.require("openils.CGI");
dojo.require("openils.User");
dojo.require("openils.PermaCrud");
dojo.require("openils.widget.ProgressDialog");
+var localeStrings;
var node_editor;
var _crads;
var CGI;
this.update_draggable = function(draggable) {
var s = "";
- draggable.data = {"match_point": new vmsp()};
+ draggable.match_point = new vmsp();
var had_op = false;
dojo.query("[fmfield]", this.node_editor_container).forEach(
function(control) {
var used_svf = null;
var field = dojo.attr(control, "fmfield");
var value = _simple_value_getter(control);
- draggable.data.match_point[field](value);
+ draggable.match_point[field](value);
if (field == "subfield")
s += " \u2021";
}
);
dojo.attr(draggable, "innerHTML", s);
+ this.dnd_source._ready = true;
};
this._add_consistent_controls = function(tgt) {
/* a representation, not the editing widgets, but will also carry
* the fieldmapper object when dragged to the tree */
var draggable = dojo.create(
- "li", {
- "innerHTML": "Define your match point and drag me<br/>" +
- "to the tree on the right"
- }
+ "li", {"innerHTML": localeStrings.DEFINE_MP}
);
/* these are the editing widgets */
dojo.place(table, this.node_editor_container, "only");
/* XXX around here attach other data structures to the node */
this.dnd_source.insertNodes(false, [draggable]);
+ this.dnd_source._ready = false;
};
this._init.apply(this, arguments);
function init_test() {
progress_dialog.show(true);
+ dojo.requireLocalization("openils.vandelay", "match_set");
+ localeStrings = dojo.i18n.getLocalization("openils.vandelay", "match_set");
+
CGI = new openils.CGI();
/* XXX No-one should have hundreds of these or anything, but theoretically
store: store, "query": {"id": "root"}
});
+ var src = new dojo.dnd.Source("src_here");
var tree = new dijit.Tree(
{
"model": treeModel,
- "dndController": dijit._tree.dndSource,
+ "dndController": openils.vandelay.TreeDndSource,
"dragThreshold": 8,
"betweenThreshold": 5,
"persist": false
- }, "treeOne"
+ }, "tree_here"
);
- node_editor = new NodeEditor(mysrc, "node-editor-container");
+ node_editor = new NodeEditor(src, "node-editor-container");
dojo.connect(
- mysrc, "onDndDrop", null,
+ src, "onDndDrop", null,
function(source, nodes, copy, target) {
if (source == this) {
var model = target.tree.model;
);
node_editor.clear(); /* because otherwise this acts like a copy! */
} else {
- alert("XXX [mysrc] nodes length is " + nodes.length); /* XXX DEBUG */
+ alert("XXX [src] nodes length is " + nodes.length); /* XXX DEBUG */
}
}
);