From 8340fad866ae55df4d845291e9ee249dfab2a7c9 Mon Sep 17 00:00:00 2001 From: dbs Date: Wed, 23 Feb 2011 18:59:39 +0000 Subject: [PATCH] Naive attempt to backport spine label editing goodness from rel_1_6 git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/branches/rel_1_6_1@1237 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- xul/server/cat/spine_labels.js | 159 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) diff --git a/xul/server/cat/spine_labels.js b/xul/server/cat/spine_labels.js index 2d16945bd8..bf983d39c8 100644 --- a/xul/server/cat/spine_labels.js +++ b/xul/server/cat/spine_labels.js @@ -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 }; -- 2.11.0