[open-ils-commits] r1237 - conifer/branches/rel_1_6_1/xul/server/cat (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Feb 23 13:59:43 EST 2011
Author: dbs
Date: 2011-02-23 13:59:39 -0500 (Wed, 23 Feb 2011)
New Revision: 1237
Modified:
conifer/branches/rel_1_6_1/xul/server/cat/spine_labels.js
Log:
Naive attempt to backport spine label editing goodness from rel_1_6
Modified: conifer/branches/rel_1_6_1/xul/server/cat/spine_labels.js
===================================================================
--- conifer/branches/rel_1_6_1/xul/server/cat/spine_labels.js 2011-02-23 16:31:06 UTC (rev 1236)
+++ conifer/branches/rel_1_6_1/xul/server/cat/spine_labels.js 2011-02-23 18:59:39 UTC (rev 1237)
@@ -102,6 +102,9 @@
tb.setAttribute('class','plain'); tb.setAttribute('style','font-family: Arial, Helvetica, sans-serif'); tb.setAttribute('font-weight','bold');
tb.setAttribute('size',lw+1); tb.setAttribute('maxlength',lw);
tb.setAttribute('name','spine');
+ var spine_row_id = 'acn_' + volume.id() + '_spine_' + j;
+ tb.setAttribute('id',spine_row_id);
+
var name = names.shift(); if (name) {
name = String( name );
/* if the name is greater than the label width... */
@@ -133,6 +136,7 @@
tb.value = name;
}
}
+ dojo.connect($(spine_row_id), 'onkeypress', 'spine_label_key_events');
}
/* pocket */
@@ -206,6 +210,161 @@
}
}
+ function spine_label_key_events (event) {
+
+ /* Current value of the inpux box */
+ var line_value = event.target.value;
+
+ /* Cursor positions */
+ var sel_start = event.target.selectionStart;
+ var sel_end = event.target.selectionEnd;
+
+ /* Identifiers for this row: "acn_ID_spine_ROW" */
+ var atts = event.target.id.split('_');
+ var row_id = {
+ "acn": atts[1],
+ "spine": atts[3],
+ "prefix": 'acn_' + atts[1] + '_spine_'
+ };
+
+ switch (event.charOrCode) {
+ case dojo.keys.ENTER : {
+ /* Create a new row by inserting a space at the
+ * current cursor point, then regenerating the
+ * label
+ */
+ if (sel_start == sel_end) {
+ if (sel_start == 0) {
+ /* If the cursor is at the start of the line:
+ * insert new line
+ */
+ line_value = ' ' + line_value;
+ } else if (sel_start == line_value.length) {
+ /* Special case if the cursor is at the end of the line:
+ * move to next line
+ */
+ var next_row = $(row_id.prefix + (parseInt(row_id.spine) + 1));
+ if (next_row) {
+ next_row.focus();
+ }
+ break;
+ } else {
+ line_value = line_value.substr(0, sel_start) + ' ' + line_value.substr(sel_end);
+ }
+ } else {
+ line_value = line_value.substr(0, sel_start) + ' ' + line_value.substr(sel_end);
+ }
+ event.target.value = line_value;
+
+ /* Recreate the label */
+ var new_label = '';
+ var chunk;
+ var x = 0;
+ while (chunk = $(row_id.prefix + x)) {
+ if (x > 0) {
+ new_label += ' ' + chunk.value;
+ } else {
+ new_label = chunk.value;
+ }
+ x++;
+ }
+ generate({"acn": row_id.acn, "label": new_label});
+ $(row_id.prefix + row_id.spine).focus();
+ break;
+ }
+
+ case dojo.keys.BACKSPACE : {
+ /* Delete line if at the start of an input box */
+ if (sel_start == 0 && sel_end == sel_start) {
+ var new_label = '';
+ var chunk;
+ var x = 0;
+ while (x <= (row_id.spine - 1) && (chunk = $(row_id.prefix + x))) {
+ if (x > 0) {
+ new_label += ' ' + chunk.value;
+ } else {
+ new_label = chunk.value;
+ }
+ x++;
+ }
+
+ if (chunk = $(row_id.prefix + x)) {
+ new_label += chunk.value;
+ x++;
+ }
+
+ while (chunk = $(row_id.prefix + x)) {
+ new_label += ' ' + chunk.value;
+ x++;
+ }
+ generate({"acn": row_id.acn, "label": new_label});
+ $(row_id.prefix + row_id.spine).focus();
+ }
+ if (sel_start == 0) {
+ /* Move to the previous row */
+ var prev_row = $(row_id.prefix + (parseInt(row_id.spine) - 1));
+ if (prev_row) {
+ prev_row.focus();
+ }
+ }
+ break;
+ }
+
+ case dojo.keys.DELETE : {
+ /* Delete line if at the end of an input box */
+ if (sel_start == event.target.textLength) {
+ var new_label = '';
+ var chunk;
+ var x = 0;
+ while (x <= row_id.spine && (chunk = $(row_id.prefix + x))) {
+ if (x > 0) {
+ new_label += ' ' + chunk.value;
+ } else {
+ new_label = chunk.value;
+ }
+ x++;
+ }
+
+ if (chunk = $(row_id.prefix + x)) {
+ new_label += chunk.value;
+ x++;
+ }
+
+ while (chunk = $(row_id.prefix + x)) {
+ new_label += ' ' + chunk.value;
+ x++;
+ }
+ generate({"acn": row_id.acn, "label": new_label});
+ $(row_id.prefix + row_id.spine).focus();
+ }
+ break;
+ }
+
+ case dojo.keys.UP_ARROW : {
+ /* Move to the previous row */
+ var prev_row = $(row_id.prefix + (parseInt(row_id.spine) - 1));
+ if (prev_row) {
+ prev_row.focus();
+ }
+ break;
+ }
+
+ case dojo.keys.DOWN_ARROW : {
+ /* Move to the next row */
+ var next_row = $(row_id.prefix + (parseInt(row_id.spine) + 1));
+ if (next_row) {
+ next_row.focus();
+ }
+ break;
+ }
+
+ default : {
+ break;
+ }
+ }
+ }
+
+
function expand_macros(text,copy,volume,record) {
var my = { 'acp' : copy, 'acn' : volume, 'mvr' : record };
var obj = { 'data' : g.data };
More information about the open-ils-commits
mailing list