From: pines Date: Wed, 21 Feb 2007 21:23:09 +0000 (+0000) Subject: import/export for receipt templates X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f5fcb81a26d1864df861906702b95b4bb11d4e28;p=Evergreen.git import/export for receipt templates git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_0@6977 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/xul/staff_client/server/circ/print_list_template_editor.js b/Open-ILS/xul/staff_client/server/circ/print_list_template_editor.js index 062aa0bd0d..3ca8ce11b9 100644 --- a/Open-ILS/xul/staff_client/server/circ/print_list_template_editor.js +++ b/Open-ILS/xul/staff_client/server/circ/print_list_template_editor.js @@ -103,6 +103,18 @@ circ.print_list_template_editor.prototype = { obj.save_template( obj.controller.view.template_name_menu.value ); } ], + 'export' : [ + ['command'], + function() { + obj.export_templates(); + } + ], + 'import' : [ + ['command'], + function() { + obj.import_templates(); + } + ], 'default' : [ ['command'], function() { @@ -280,6 +292,90 @@ circ.print_list_template_editor.prototype = { alert('Template Saved\n' + js2JSON(obj.data.print_list_templates[name])); }, + 'export_templates' : function() { + try { + var obj = this; + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + JSAN.use('util.file'); + var f = obj.pick_file('save'); + if (f) { + if (f.exists()) { + var r = obj.error.yns_alert( + 'Would you like to overwrite the existing file ' + f.leafName + '?', + 'Templates Export Warning', + 'Yes', + 'No', + null, + 'Check here to confirm this message' + ); + if (r != 0) { file.close(); alert('Not overwriting file.'); return; } + } + var e_file = new util.file(''); e_file._file = f; + e_file.write_content( 'truncate', js2JSON( obj.data.print_list_templates ) ); + e_file.close(); + alert('Templates exported as file ' + f.leafName); + } else { + alert('File not chosen for export.'); + } + + } catch(E) { + this.error.standard_unexpected_error_alert('Error exporting templates',E); + } + }, + + 'import_templates' : function() { + try { + var obj = this; + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + JSAN.use('util.file'); + var f = obj.pick_file('open'); + if (f && f.exists()) { + var i_file = new util.file(''); i_file._file = f; + var temp = JSON2js( i_file.get_content() ); + i_file.close(); + var s = ''; + function set_t(k,v) { + obj.data.print_list_templates[k] = v; + if (s) s+= ', '; s += k; + } + for (var i in temp) { set_t(i,temp[i]); } + obj.data.stash('print_list_templates'); + alert('Imported these templates: ' + s); + if (xulG) { + xulG.set_tab(xulG.url_prefix(urls.XUL_PRINT_LIST_TEMPLATE_EDITOR), {}, {}); + } else { + alert('Please reload this interface.'); + } + + } else { + alert('File not chosen for import.'); + } + } catch(E) { + this.error.standard_unexpected_error_alert('Error importing templates',E); + } + }, + + 'pick_file' : function(mode) { + try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var nsIFilePicker = Components.interfaces.nsIFilePicker; + var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance( nsIFilePicker ); + fp.init( + window, + mode == 'open' ? "Import Templates File" : "Save Templates File As", + mode == 'open' ? nsIFilePicker.modeOpen : nsIFilePicker.modeSave + ); + fp.appendFilters( nsIFilePicker.filterAll ); + if ( fp.show( ) == nsIFilePicker.returnOK && fp.file ) { + return fp.file; + } else { + return null; + } + } catch(E) { + this.error.standard_unexpected_error_alert('error picking file',E); + } + }, + } dump('exiting print_list_template_editor.js\n'); diff --git a/Open-ILS/xul/staff_client/server/circ/print_list_template_editor.xul b/Open-ILS/xul/staff_client/server/circ/print_list_template_editor.xul index 50935e8d33..a2b4eb95a6 100644 --- a/Open-ILS/xul/staff_client/server/circ/print_list_template_editor.xul +++ b/Open-ILS/xul/staff_client/server/circ/print_list_template_editor.xul @@ -84,12 +84,21 @@ - + -