[open-ils-commits] r9431 - in trunk/Open-ILS/web: conify/global/actor conify/global/config conify/global/permission js/dojo/openils/widget

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Apr 22 22:20:46 EDT 2008


Author: miker
Date: 2008-04-22 21:41:36 -0400 (Tue, 22 Apr 2008)
New Revision: 9431

Added:
   trunk/Open-ILS/web/js/dojo/openils/widget/TranlatorPopup.js
Modified:
   trunk/Open-ILS/web/conify/global/actor/org_unit.html
   trunk/Open-ILS/web/conify/global/actor/org_unit.js
   trunk/Open-ILS/web/conify/global/actor/org_unit_type.html
   trunk/Open-ILS/web/conify/global/actor/org_unit_type.js
   trunk/Open-ILS/web/conify/global/config/copy_status.html
   trunk/Open-ILS/web/conify/global/config/copy_status.js
   trunk/Open-ILS/web/conify/global/permission/grp_tree.html
   trunk/Open-ILS/web/conify/global/permission/grp_tree.js
Log:
move the translation widget out to openils.widget

Modified: trunk/Open-ILS/web/conify/global/actor/org_unit.html
===================================================================
--- trunk/Open-ILS/web/conify/global/actor/org_unit.html	2008-04-22 18:32:12 UTC (rev 9430)
+++ trunk/Open-ILS/web/conify/global/actor/org_unit.html	2008-04-23 01:41:36 UTC (rev 9431)
@@ -222,7 +222,7 @@
 											if (current_ou) ou_list_store.setValue( current_ou, "name", this.getValue() );
 										</script>
 									</span>
-									<span dojoType="openils.I18N.translationWidget" targetObject="current_fm_ou" field="name"></span>
+									<span dojoType="openils.widget.TranslatorPopup" targetObject="current_fm_ou" field="name"></span>
 								</td>
 							</tr>
 							<tr>

Modified: trunk/Open-ILS/web/conify/global/actor/org_unit.js
===================================================================
--- trunk/Open-ILS/web/conify/global/actor/org_unit.js	2008-04-22 18:32:12 UTC (rev 9430)
+++ trunk/Open-ILS/web/conify/global/actor/org_unit.js	2008-04-23 01:41:36 UTC (rev 9431)
@@ -16,7 +16,7 @@
 */
 
 dojo.require('fieldmapper.dojoData');
-dojo.require('openils.I18N');
+dojo.require('openils.widget.TranslatorPopup');
 dojo.require('dojo.parser');
 dojo.require('dojo.data.ItemFileWriteStore');
 dojo.require('dojo.date.stamp');

Modified: trunk/Open-ILS/web/conify/global/actor/org_unit_type.html
===================================================================
--- trunk/Open-ILS/web/conify/global/actor/org_unit_type.html	2008-04-22 18:32:12 UTC (rev 9430)
+++ trunk/Open-ILS/web/conify/global/actor/org_unit_type.html	2008-04-23 01:41:36 UTC (rev 9431)
@@ -190,7 +190,7 @@
 											}
 										</script>
 									</span>
-									<span dojoType="openils.I18N.translationWidget" targetObject="current_fm_type" field="name"></span>
+									<span dojoType="openils.widget.TranslatorPopup" targetObject="current_fm_type" field="name"></span>
 								</td>
 							</tr>
 							<tr>
@@ -203,7 +203,7 @@
 											}
 										</script>
 									</span>
-									<span dojoType="openils.I18N.translationWidget" targetObject="current_fm_type" field="opac_label"></span>
+									<span dojoType="openils.widget.TranslatorPopup" targetObject="current_fm_type" field="opac_label"></span>
 								</td>
 							</tr>
 							<tr>

Modified: trunk/Open-ILS/web/conify/global/actor/org_unit_type.js
===================================================================
--- trunk/Open-ILS/web/conify/global/actor/org_unit_type.js	2008-04-22 18:32:12 UTC (rev 9430)
+++ trunk/Open-ILS/web/conify/global/actor/org_unit_type.js	2008-04-23 01:41:36 UTC (rev 9431)
@@ -16,7 +16,7 @@
 */
 
 dojo.require('fieldmapper.dojoData');
-dojo.require('openils.I18N');
+dojo.require('openils.widget.TranslatorPopup');
 dojo.require('dojo.parser');
 dojo.require('dojo.data.ItemFileWriteStore');
 dojo.require('dojo.date.stamp');

Modified: trunk/Open-ILS/web/conify/global/config/copy_status.html
===================================================================
--- trunk/Open-ILS/web/conify/global/config/copy_status.html	2008-04-22 18:32:12 UTC (rev 9430)
+++ trunk/Open-ILS/web/conify/global/config/copy_status.html	2008-04-23 01:41:36 UTC (rev 9431)
@@ -188,7 +188,7 @@
 												window.status_rows[row] = new ccs().fromHash(window.status_data_model.getRow(row));
 												setTimeout(
 													'dojo.query(".status_grid_trans_cell_' + row + '").'+
-														'instantiate(openils.I18N.translationWidget,{field:"name",'+
+														'instantiate(openils.widget.TranslatorPopup,{field:"name",'+
 														'targetObject:"window.status_rows['+row+']",unique:"' + row + '"});'+
 														'status_grid.rowHeightChanged('+row+')',
 													0

Modified: trunk/Open-ILS/web/conify/global/config/copy_status.js
===================================================================
--- trunk/Open-ILS/web/conify/global/config/copy_status.js	2008-04-22 18:32:12 UTC (rev 9430)
+++ trunk/Open-ILS/web/conify/global/config/copy_status.js	2008-04-23 01:41:36 UTC (rev 9431)
@@ -16,7 +16,7 @@
 */
 
 dojo.require('fieldmapper.dojoData');
-dojo.require('openils.I18N');
+dojo.require('openils.widget.TranslatorPopup');
 dojo.require('dojo.parser');
 dojo.require('dojo.string');
 dojo.require('dojo.data.ItemFileWriteStore');

Modified: trunk/Open-ILS/web/conify/global/permission/grp_tree.html
===================================================================
--- trunk/Open-ILS/web/conify/global/permission/grp_tree.html	2008-04-22 18:32:12 UTC (rev 9430)
+++ trunk/Open-ILS/web/conify/global/permission/grp_tree.html	2008-04-23 01:41:36 UTC (rev 9431)
@@ -266,7 +266,7 @@
 											}
 										</script>
 									</span>
-									<span dojoType="openils.I18N.translationWidget" targetObject="current_fm_group" field="name"></span>
+									<span dojoType="openils.widget.TranslatorPopup" targetObject="current_fm_group" field="name"></span>
 								</td>
 							</tr>
 							<tr>
@@ -280,7 +280,7 @@
 										  onChange="if (current_group) group_store.setValue( current_group, "description", this.getValue() );"
 										></textarea>
 									</span>
-									<span dojoType="openils.I18N.translationWidget" targetObject="current_fm_group" field="description"></span>
+									<span dojoType="openils.widget.TranslatorPopup" targetObject="current_fm_group" field="description"></span>
 								</td>
 							</tr>
 							<tr>

Modified: trunk/Open-ILS/web/conify/global/permission/grp_tree.js
===================================================================
--- trunk/Open-ILS/web/conify/global/permission/grp_tree.js	2008-04-22 18:32:12 UTC (rev 9430)
+++ trunk/Open-ILS/web/conify/global/permission/grp_tree.js	2008-04-23 01:41:36 UTC (rev 9431)
@@ -16,7 +16,7 @@
 */
 
 dojo.require('fieldmapper.dojoData');
-dojo.require('openils.I18N');
+dojo.require('openils.widget.TranslatorPopup');
 dojo.require('dojo.parser');
 dojo.require('dojo.data.ItemFileWriteStore');
 dojo.require('dojo.date.stamp');

Added: trunk/Open-ILS/web/js/dojo/openils/widget/TranlatorPopup.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/TranlatorPopup.js	                        (rev 0)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/TranlatorPopup.js	2008-04-23 01:41:36 UTC (rev 9431)
@@ -0,0 +1,224 @@
+/* ---------------------------------------------------------------------------
+ * Copyright (C) 2008  Georgia Public Library Service
+ * Copyright (C) 2008  Equinox Software, Inc
+ * Mike Rylander <miker at esilibrary.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * ---------------------------------------------------------------------------
+ */
+
+if(!dojo._hasResource["openils.widget.TranslatorPopup"]) {
+
+    dojo._hasResource["openils.widget.TranslatorPopup"] = true;
+    dojo.provide("openils.widget.TranslatorPopup");
+    dojo.require("openils.I18N");
+    dojo.require("fieldmapper.dojoData");
+    dojo.require("DojoSRF");
+	dojo.require("dojo.data.ItemFileWriteStore");
+	dojo.require("dijit._Widget");
+	dojo.require("dijit._Templated");
+	dojo.require("dijit.layout.ContentPane");
+	dojo.require("dijit.Dialog");
+	dojo.require("dijit.form.Button");
+	dojo.require("dijit.form.TextBox");
+	dojo.require("dijit.form.ComboBox");
+
+
+    dojo.declare(
+		'openils.widget.TranslatorPopup',
+		[dijit._Widget, dijit._Templated],
+		{
+
+			templateString : "<span dojoAttachPoint='node'><div dojoType='dijit.form.DropDownButton'><span>Translate</span><div id='${field}_translation_${unique}' dojoType='dijit.TooltipDialog' onOpen='openils.widget.TranslatorPopup.renderTranslationPopup(${targetObject}, \"${field}\", \"${unique}\")' ><div dojoType='dijit.layout.ContentPane'><table><tbody class='translation_tbody_template' style='display:none; visiblity:hidden;'><tr><th>Locale</th><td class='locale'><div class='locale_combobox'></div></td><th>Translation</th><td class='translation'><div class='translation_textbox'></div></td><td><button class='create_button' style='display:none; visiblity:hidden;'>Create</button><button class='update_button' style='display:none; visiblity:hidden;'>Update</button><button class='delete_button' style='display:none; visiblity:hidden;'>Remove</button></td></tr></tbody><tbody class='translation_tbody'></tbody></table></div></div></div></span>",
+
+			widgetsInTemplate: true,
+			field : "",
+			targetObject : "",
+			unique : ""
+		}
+	);
+
+	openils.widget.TranslatorPopup.renderTranslationPopup = function (obj, field, num) {
+		var node = dojo.byId(field + '_translation_' + num);
+
+		var trans_list = openils.I18N.getTranslations( obj, field );
+
+		var trans_template = dojo.query('.translation_tbody_template', node)[0];
+		var trans_tbody = dojo.query('.translation_tbody', node)[0];
+
+		// Empty it
+		while (trans_tbody.lastChild) trans_tbody.removeChild( trans_tbody.lastChild );
+
+		for (var i in trans_list) {
+			if (!trans_list[i]) continue;
+
+			var trans_obj = trans_list[i];
+			var trans_id = trans_obj.id();
+
+			var trans_row = dojo.query('tr',trans_template)[0].cloneNode(true);
+			trans_row.id = 'translation_row_' + trans_id;
+
+			var old_dijit = dijit.byId('locale_' + trans_id);
+			if (old_dijit) old_dijit.destroy();
+
+			old_dijit = dijit.byId('translation_' + trans_id);
+			if (old_dijit) old_dijit.destroy();
+
+			dojo.query('.locale_combobox',trans_row).instantiate(
+				dijit.form.ComboBox,
+				{ store:openils.I18N.localeStore,
+				  searchAttr:'locale',
+				  lowercase:true,
+				  required:true,
+				  id:'locale_' + trans_id,
+				  value: trans_obj.translation(),
+				  invalidMessage:'Specify locale as {languageCode}_{countryCode}, like en_us',
+				  regExp:'[a-z_]+'
+				}
+			);
+
+			dojo.query('.translation_textbox',trans_row).instantiate(
+				dijit.form.TextBox,
+				{ required : true,
+				  id:'translation_' + trans_id,
+				  value: trans_obj.string()
+				}
+			);
+
+			dojo.query('.update_button',trans_row).style({ visibility : 'visible', display : 'inline'}).instantiate(
+				dijit.form.Button,
+				{ onClick :
+					(function (trans_id, obj, field) {
+						return function () { openils.widget.TranslatorPopup.updateTranslation(trans_id, obj, field, num) }
+					})(trans_id, obj, field) 
+				}
+			);
+
+			dojo.query('.delete_button',trans_row).style({ visibility : 'visible', display : 'inline'}).instantiate(
+				dijit.form.Button,
+				{ onClick :
+					(function (trans_id, obj, field) {
+						return function () { openils.widget.TranslatorPopup.removeTranslation(trans_id, obj, field, num) }
+					})(trans_id, obj, field) 
+				}
+			);
+
+			trans_tbody.appendChild( trans_row );
+		}
+
+		old_dijit = dijit.byId('i18n_new_locale_' + obj.classname + '.' + field + num);
+		if (old_dijit) old_dijit.destroy();
+
+		old_dijit = dijit.byId('i18n_new_translation_' + obj.classname + '.' + field + num);
+		if (old_dijit) old_dijit.destroy();
+
+		trans_row = dojo.query('tr',trans_template)[0].cloneNode(true);
+
+		dojo.query('.locale_combobox',trans_row).instantiate(
+			dijit.form.ComboBox,
+			{ store:openils.I18N.localeStore,
+			  searchAttr:'locale',
+			  id:'i18n_new_locale_' + obj.classname + '.' + field + num,
+			  lowercase:true,
+			  required:true,
+			  invalidMessage:'Specify locale as {languageCode}_{countryCode}, like en_us',
+			  regExp:'[a-z_]+'
+			}
+		);
+
+		dojo.query('.translation_textbox',trans_row).addClass('new_translation').instantiate(
+			dijit.form.TextBox,
+			{ required : true,
+			  id:'i18n_new_translation_' + obj.classname + '.' + field + num
+			}
+		);
+
+		dojo.query('.create_button',trans_row).style({ visibility : 'visible', display : 'inline'}).instantiate(
+			dijit.form.Button,
+			{ onClick : function () { openils.widget.TranslatorPopup.createTranslation( obj, field, num) } }
+		);
+
+		trans_tbody.appendChild( trans_row );
+	}
+
+	openils.widget.TranslatorPopup.updateTranslation = function (trans_id, obj, field, num) {
+		return openils.widget.TranslatorPopup.changeTranslation('update', trans_id, obj, field, num);
+	}
+	
+	openils.widget.TranslatorPopup.removeTranslation = function (trans_id, obj, field, num) {
+		return openils.widget.TranslatorPopup.changeTranslation('delete', trans_id, obj, field, num);
+	}
+	
+	openils.widget.TranslatorPopup.changeTranslation = function (method, trans_id, obj, field, num) {
+	
+		var trans_obj = new i18n().fromHash({
+			ischanged : method == 'update' ? 1 : 0,
+			isdeleted : method == 'delete' ? 1 : 0,
+			id : trans_id,
+			fq_field : obj.classname + '.' + field,
+			identity_value : obj.id(),
+			translation : dijit.byId('locale_' + trans_id).getValue(),
+			string : dijit.byId('translation_' + trans_id).getValue()
+		});
+	
+		openils.widget.TranslatorPopup.writeTranslation(method, trans_obj, obj, field, num);
+	}
+	
+	openils.widget.TranslatorPopup.createTranslation = function (obj, field, num) {
+		var node = dojo.byId(field + '_translation_' + num);
+	
+		var trans_obj = new i18n().fromHash({
+			isnew : 1,
+			fq_field : obj.classname + '.' + field,
+			identity_value : obj.id(),
+			translation : dijit.byId('i18n_new_locale_' + obj.classname + '.' + field + num).getValue(),
+			string : dijit.byId('i18n_new_translation_' + obj.classname + '.' + field + num).getValue()
+		});
+	
+		openils.widget.TranslatorPopup.writeTranslation('create', trans_obj, obj, field, num);
+	}
+	
+	openils.widget.TranslatorPopup.writeTranslation = function (method, trans_obj, obj, field, num) {
+	
+		OpenSRF.CachedClientSession('open-ils.permacrud').request({
+			method : 'open-ils.permacrud.' + method + '.i18n',
+			timeout: 10,
+			params : [ ses, trans_obj ],
+			onerror: function (r) {
+				//highlighter.editor_pane.red.play();
+				if (status_update) status_update( 'Problem saving translation for ' + obj[field]() );
+			},
+			oncomplete : function (r) {
+				var res = r.recv();
+				if ( res && res.content() ) {
+					//highlighter.editor_pane.green.play();
+					if (status_update) status_update( 'Saved changes to translation for ' + obj[field]() );
+	
+					if (method == 'delete') {
+						dojo.NodeList(dojo.byId('translation_row_' + trans_obj.id())).orphan();
+					} else if (method == 'create') {
+						var node = dojo.byId(field + '_translation_' + num);
+						dijit.byId('i18n_new_locale_' + obj.classname + '.' + field + num).setValue(null);
+						dijit.byId('i18n_new_translation_' + obj.classname + '.' + field + num).setValue(null);
+						openils.widget.TranslatorPopup.renderTranslationPopup(obj, field, num);
+					}
+	
+				} else {
+					//highlighter.editor_pane.red.play();
+					if (status_update) status_update( 'Problem saving translation for ' + obj[field]() );
+				}
+			},
+		}).send();
+	}
+
+}
+
+



More information about the open-ils-commits mailing list