From b5d1b5e86dcaee9b6d29b2777798fd29f70a20eb Mon Sep 17 00:00:00 2001
From: miker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Fri, 9 Jul 2010 14:34:47 +0000
Subject: [PATCH] add support for switching between xul and textarea marc
 editors

git-svn-id: svn://svn.open-ils.org/ILS/trunk@16896 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 Open-ILS/web/opac/locale/en-US/lang.dtd           |  1 +
 Open-ILS/xul/staff_client/server/cat/marcedit.js  | 31 +++++++++++++++++++++++
 Open-ILS/xul/staff_client/server/cat/marcedit.xul |  7 ++++-
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd
index a7f22891a2..8551ac3982 100644
--- a/Open-ILS/web/opac/locale/en-US/lang.dtd
+++ b/Open-ILS/web/opac/locale/en-US/lang.dtd
@@ -2454,6 +2454,7 @@
 <!ENTITY staff.cat.marcedit.validate.accesskey "V">
 <!ENTITY staff.cat.marcedit.save-button.accesskey "d">
 <!ENTITY staff.cat.marcedit.help.label "Help">
+<!ENTITY staff.cat.marcedit.swapEditor.label "Swap Editor Type">
 <!ENTITY staff.cat.marcedit.help.accesskey "H">
 <!ENTITY staff.cat.marcedit.caption.label "MARC Record">
 <!ENTITY staff.cat.marcedit.toggleFFE.label "Fixed Fields -- Record type: ">
diff --git a/Open-ILS/xul/staff_client/server/cat/marcedit.js b/Open-ILS/xul/staff_client/server/cat/marcedit.js
index 32e7031e73..c5d417a396 100644
--- a/Open-ILS/xul/staff_client/server/cat/marcedit.js
+++ b/Open-ILS/xul/staff_client/server/cat/marcedit.js
@@ -78,6 +78,36 @@ function xml_escape_unicode ( str ) {
     );
 }
 
+function swap_editors () {
+
+	dojo.require('MARC.Record');
+
+	var xe = $('xul-editor');
+	var te = $('text-editor');
+
+	te.hidden = te.hidden ? false : true;
+	xe.hidden = xe.hidden ? false : true;
+
+	if (te.hidden) {
+		// get the marcxml from the text box
+		var xml_string = new MARC.Record({
+			marcbreaker : $('text-editor-box').value,
+			delimiter : '$'
+		}).toXmlString();
+
+		// reset the xml record and rerender it
+		xml_record = new XML( xml_string );
+		loadRecord(xml_record);
+	} else {
+		var xml_string = xml_record.toXMLString();
+
+		// push the xml record into the textbox
+		var rec = new MARC.Record ({ delimiter : '$', marcxml : xml_string });
+		$('text-editor-box').value = rec.toBreaker();
+	}
+}
+
+
 function my_init() {
     try {
 
@@ -107,6 +137,7 @@ function my_init() {
 
         document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
         document.getElementById('save-button').setAttribute('oncommand',
+			'if ($("xul-editor").hidden) swap_editors(); ' +
             'mangle_005(); ' + 
             'var xml_string = xml_escape_unicode( xml_record.toXMLString() ); ' + 
             'save_attempt( xml_string ); ' +
diff --git a/Open-ILS/xul/staff_client/server/cat/marcedit.xul b/Open-ILS/xul/staff_client/server/cat/marcedit.xul
index e56fa3b24d..4baa212bcf 100644
--- a/Open-ILS/xul/staff_client/server/cat/marcedit.xul
+++ b/Open-ILS/xul/staff_client/server/cat/marcedit.xul
@@ -33,6 +33,7 @@
         </hbox>
         <button label="&staff.cat.marcedit.validate.label;" accesskey="&staff.cat.marcedit.validate.accesskey;" oncommand="validateAuthority(this);"/>
         <button id="save-button" accesskey="&staff.cat.marcedit.save-button.accesskey;"/>
+        <button label="&staff.cat.marcedit.swapEditor.label;" oncommand="swap_editors()"/>
         <button label="&staff.cat.marcedit.help.label;" accesskey="&staff.cat.marcedit.help.accesskey;"
             oncommand="alert(
                 $('catStrings').getString('staff.cat.marcedit.help.add_row') + '\n' +
@@ -50,7 +51,7 @@
     </hbox>
 </groupbox>
 
-<groupbox flex="1">
+<groupbox id="xul-editor" flex="1">
     <caption label="&staff.cat.marcedit.caption.label;"/>
     <vbox flex="1" style="overflow: auto;">
         <hbox>
@@ -196,6 +197,10 @@
     </vbox>
 </groupbox>
 
+<hbox hidden="true" id="text-editor" flex="1">
+    <xhtml:textarea rows="50" cols='100' id="text-editor-box"></xhtml:textarea>
+</hbox>
+
 <grid name="authority-marc-template" hidden="true">
     <columns>
         <column/>
-- 
2.11.0