window._tree_dnd_controllers = [];
window._tree_dnd_controllers.push(this);
+
+ dojo.connect(
+ this.tree.model.store, "onNew", this,
+ function() { this.redraw_expression_preview(); }
+ );
+ dojo.connect(
+ this.tree.model.store, "onDelete", this,
+ function() { this.redraw_expression_preview(); }
+ );
+ },
+ "redraw_expression_preview": function() {
+ if (typeof(window.redraw_expression_preview) == "function") {
+ window.redraw_expression_preview();
+ } else {
+ console.log("no redraw_expression_preview function registered");
+ }
},
"checkItemAcceptance": function(target, source, position) {
if (!source._ready || source == this) return;
);
}
+ this.redraw_expression_preview();
+
/* just because this is at the end of the default implementation: */
this.onDndCancel();
}
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": {}
- };
+ var mp = model.store.getValue(item, "match_point");
+ mp.children([]);
+ return mp;
}
dojo.declare(
"openils.vandelay.TreeStoreModel", dijit.tree.TreeStoreModel, {
"replace_mode": 0,
- "getSimpleTree": function(item, oncomplete, result) {
+ "get_simple_tree": function(item, oncomplete, result) {
var self = this;
- if (!result) result = {};
-
- var mykey = this.getIdentity(item);
- result[mykey] = _simple_item(this, item);
- var child_collector = result[mykey].children;
+ var me;
+ if (!result) {
+ me = result = _simple_item(this, item);
+ } else {
+ me = _simple_item(this, item);
+ result.push(me);
+ }
if (this.mayHaveChildren(item)) {
this.getChildren(
item, function(children) {
+ var kids_here = [];
for (var i = 0; i < children.length; i++) {
- self.getSimpleTree(
- children[i], null, child_collector
- );
+ self.get_simple_tree(children[i], null, kids_here);
}
+ me.children(kids_here);
if (oncomplete) oncomplete(result);
}
);
else
return true;
}
-// "newItem": function(args, parent) {
-// if (!this.mayHaveChildren(parent)) return;
-// return this.inherited(arguments);
-// }
}
);
"NO_CAN_DO": "An error has occurred. Close this interface and try again.",
"OK": "Ok",
"POINT_NEEDS_ONE": "A match point must be exactly one of the following: boolean operator, MARC tag/subfield pair, single-value-field.",
- "FAULTY_MARC": "A MARC tag must be identified by three digits, and the subfield must be one non-whitespace, non-control character."
+ "FAULTY_MARC": "A MARC tag must be identified by three digits, and the subfield must be one non-whitespace, non-control character.",
+ "WORKING_MP_HERE": "Choose from among the three buttons above to add a new match point."
}
dojo.require("openils.PermaCrud");
dojo.require("openils.widget.ProgressDialog");
-var localeStrings, node_editor, _crads, CGI, tree;
+var localeStrings, node_editor, _crads, CGI, tree, match_set;
function _find_crad_by_name(name) {
for (var i = 0; i < _crads.length; i++) {
this.clear = function() {
this.dnd_source.selectAll().deleteSelectedNodes();
- dojo.empty(this.node_editor_container);
+ dojo.create(
+ "em", {"innerHTML": localeStrings.WORKING_MP_HERE},
+ this.node_editor_container, "only"
+ );
this.dnd_source._ready = false;
};
);
dojo.place(table, this.node_editor_container, "only");
- /* XXX around here attach other data structures to the node */
+
this.dnd_source.insertNodes(false, [draggable]);
+
+ /* nice */
+ try { dojo.query("select, input", table)[0].focus(); }
+ catch(E) { console.log(String(E)); }
+
};
this._init.apply(this, arguments);
}
-function render_vmsp_label(point) {
+function render_vmsp_label(point, minimal) {
/* quick and dirty */
if (point.bool_op()) {
return (openils.Util.isTrue(point.negate()) ? "N" : "") +
point.bool_op();
} else if (point.svf()) {
- return (openils.Util.isTrue(point.negate()) ? "NOT " : "") +
- point.svf() + " / " + _find_crad_by_name(point.svf()).label();
+ return (openils.Util.isTrue(point.negate()) ? "NOT " : "") + (
+ minimal ? point.svf() :
+ (point.svf() + " / " + _find_crad_by_name(point.svf()).label())
+ );
} else {
return (openils.Util.isTrue(point.negate()) ? "NOT " : "") +
point.tag() + " \u2021" + point.subfield();
dojo.byId("vms-mtype").innerHTML = match_set.mtype();
}
+function redraw_expression_preview() {
+ tree.model.getRoot(
+ function(root) {
+ tree.model.get_simple_tree(
+ root, function(r) {
+ dojo.attr(
+ "expr-preview",
+ "innerHTML",
+ render_expression_preview(r)
+ );
+ }
+ );
+ }
+ );
+}
+
+function render_expression_preview(r) {
+ if (r.children().length) {
+ return "(" + r.children().map(render_expression_preview).join(
+ " " + render_vmsp_label(r) + " "
+ ) + ")";
+ } else if (!r.bool_op()) {
+ return render_vmsp_label(r, true /* minimal */);
+ } else {
+ return "()";
+ }
+}
+
+function save_tree() {
+ progress_dialog.show(true);
+
+ tree.model.getRoot(
+ function(root) {
+ tree.model.get_simple_tree(
+ root, function(r) {
+ fieldmapper.standardRequest(
+ ["open-ils.vandelay",
+ "open-ils.vandelay.match_set.update"],/* XXX TODO */{
+ "params": [
+ openils.User.authtoken, match_set.id(), r
+ ],
+ "async": true,
+ "oncomplete": function(r) {
+ progress_dialog.hide();
+ /* catch exceptions */
+ r = openils.Util.readResponse(r);
+
+ location.href = location.href;
+ }
+ }
+ );
+ }
+ );
+ }
+ );
+}
function my_init() {
progress_dialog.show(true);
return;
}
- render_vms_metadata(pcrud.retrieve("vms", CGI.param("match_set")));
+ render_vms_metadata(
+ match_set = pcrud.retrieve("vms", CGI.param("match_set"))
+ );
/* No-one should have hundreds of these or anything, but theoretically
* this could be problematic with a big enough list of crad objects. */
"move." */
}
);
+
+ redraw_expression_preview();
+ node_editor.clear();
progress_dialog.hide();
}
#src-pane { float: left; width: 49%; }
#tree-pane { float: right; width: 50%; }
#submit-row { clear: both; text-align: center; padding-top: 1.5ex; }
- #submit-row hr { margin: 1ex 0; }
+ #submit-row hr { margin: 1.5ex 0; }
+ #expr-preview-row { margin: 2ex 0; }
+ #expr-preview {
+ font-family: monospace;
+ font-size: 125%;
+ font-weight: bold;
+ background-color: #000066;
+ color: white;
+ }
.node-editor { margin-bottom: 1.5ex; }
.node-editor td { padding: 0.5ex; }
li { background-color: #ddd; }
</tr>
</table>
<div class="outer">
- <div><!-- XXX TODO: consider a read-only display here of the query as built
- so far from the treet --></div>
+ <div id="expr-preview-row">
+ <em>Your Expression:</em>
+ <span id="expr-preview"></span>
+ </div>
<div id="vmsp-buttons">
Add new
<button onclick="node_editor.add('svf');">Single-Value-Field</button>