closes #267, MODS export option uses an rdf extension (should be xml)

thanks to Dan for the idea
This commit is contained in:
Simon Kornblith 2006-09-04 22:57:23 +00:00
parent 7d93903e2d
commit dd0c537ce1
6 changed files with 139 additions and 98 deletions

View File

@ -7,9 +7,8 @@
// Class to provide options for export // Class to provide options for export
var Scholar_File_Interface_Export = new function() { var Scholar_File_Interface_Export = new function() {
var _options;
this.init = init; this.init = init;
this.updateOptions = updateOptions;
this.accept = accept; this.accept = accept;
this.cancel = cancel; this.cancel = cancel;
@ -17,29 +16,80 @@ var Scholar_File_Interface_Export = new function() {
* add options to export * add options to export
*/ */
function init() { function init() {
_options = window.arguments[0].options; var addedOptions = new Object();
// add options to dialog var translators = window.arguments[0].translators;
var dialog = document.getElementById("scholar-export-options");
for(var option in _options) { var listbox = document.getElementById("format-popup");
var defValue = _options[option]; var formatMenu = document.getElementById("format-menu");
var optionsBox = document.getElementById("translator-options");
// add styles to list
for(i in translators) {
var itemNode = document.createElement("menuitem");
itemNode.setAttribute("label", translators[i].label);
listbox.appendChild(itemNode);
// get readable name for option // add options
try { for(var option in translators[i].displayOptions) {
var optionLabel = Scholar.getString("exportOptions."+option); if(!addedOptions[option]) { // if this option is not already
} catch(e) { // presented to the user
var optionLabel = option; // get readable name for option
try {
var optionLabel = Scholar.getString("exportOptions."+option);
} catch(e) {
var optionLabel = option;
}
// right now, option interface supports only boolean values, which
// it interprets as checkboxes
if(typeof(translators[i].displayOptions[option]) == "boolean") {
var checkbox = document.createElement("checkbox");
checkbox.setAttribute("id", "export-option-"+option);
checkbox.setAttribute("label", optionLabel);
optionsBox.appendChild(checkbox);
}
addedOptions[option] = true;
}
} }
}
// select first item by default
if(formatMenu.selectedIndex == -1) {
formatMenu.selectedIndex = 0;
}
updateOptions();
}
/*
* update translator-specific options
*/
function updateOptions() {
// get selected translator
var index = document.getElementById("format-menu").selectedIndex;
var translatorOptions = window.arguments[0].translators[index].displayOptions;
var optionsBox = document.getElementById("translator-options");
for(var i=0; i<optionsBox.childNodes.length; i++) {
// loop through options to see which should be enabled
var node = optionsBox.childNodes[i];
var optionName = node.getAttribute("id").toString().substr(14);
// right now, option interface supports only boolean values, which if(translatorOptions[optionName] != undefined) {
// it interprets as checkboxes // option should be enabled
Scholar.debug(option+" ("+optionLabel+") = "+defValue+" ("+typeof(defValue)+")"); node.disabled = undefined;
if(typeof(defValue) == "boolean") {
var checkbox = document.createElement("checkbox"); var defValue = translatorOptions[optionName];
checkbox.setAttribute("id", option); if(typeof(defValue) == "boolean") {
checkbox.setAttribute("label", optionLabel); // if option exists, enable it and set to default value
checkbox.setAttribute("checked", (defValue ? "true" : "false")); node.setAttribute("checked", (defValue ? "true" : "false"));
dialog.appendChild(checkbox); }
} else {
// option should be disabled and unchecked to prevent confusion
node.disabled = true;
node.setAttribute("checked", "false");
} }
} }
} }
@ -48,15 +98,21 @@ var Scholar_File_Interface_Export = new function() {
* make option array reflect status * make option array reflect status
*/ */
function accept() { function accept() {
for(var option in _options) { // set selected translator
var defValue = _options[option]; var index = document.getElementById("format-menu").selectedIndex;
var element = document.getElementById(option); window.arguments[0].selectedTranslator = window.arguments[0].translators[index];
// set options on selected translator
var optionsAvailable = window.arguments[0].selectedTranslator.displayOptions;
for(var option in optionsAvailable) {
var defValue = optionsAvailable[option];
var element = document.getElementById("export-option-"+option);
if(typeof(defValue) == "boolean") { if(typeof(defValue) == "boolean") {
if(element.checked == true) { if(element.checked == true) {
_options[option] = true; optionsAvailable[option] = true;
} else { } else {
_options[option] = false; optionsAvailable[option] = false;
} }
} }
} }
@ -66,6 +122,6 @@ var Scholar_File_Interface_Export = new function() {
* make option array reflect status * make option array reflect status
*/ */
function cancel() { function cancel() {
window.arguments[0].options = false; window.arguments[0].selectedTranslator = false;
} }
} }

View File

@ -10,5 +10,14 @@
<script src="include.js"/> <script src="include.js"/>
<script src="exportOptions.js"/> <script src="exportOptions.js"/>
<hbox>
<label value="&exportOptions.format.label;" control="format-menu"/>
<menulist id="format-menu" oncommand="Scholar_File_Interface_Export.updateOptions()">
<menupopup id="format-popup">
</menupopup>
</menulist>
</hbox>
<groupbox id="translator-options">
<caption label="&exportOptions.translatorOptions.label;"/>
</groupbox>
</dialog> </dialog>

View File

@ -15,27 +15,24 @@ var Scholar_File_Interface = new function() {
var translation = new Scholar.Translate("export"); var translation = new Scholar.Translate("export");
var translators = translation.getTranslators(); var translators = translation.getTranslators();
// present options dialog
var io = {translators:translators}
window.openDialog("chrome://scholar/content/exportOptions.xul",
"_blank", "chrome,modal,centerscreen", io);
if(!io.selectedTranslator) {
return false;
}
const nsIFilePicker = Components.interfaces.nsIFilePicker; const nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"] var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker); .createInstance(nsIFilePicker);
fp.init(window, Scholar.getString("fileInterface.export"), nsIFilePicker.modeSave); fp.init(window, Scholar.getString("fileInterface.export"), nsIFilePicker.modeSave);
// set file name and extension. // set file name and extension
name = (name ? name : Scholar.getString("pane.collections.library")); name = (name ? name : Scholar.getString("pane.collections.library"));
fp.defaultString = name+"."+translators[0].target; fp.defaultString = name+"."+io.selectedTranslator.target;
fp.appendFilter(io.selectedTranslator.label, "*."+io.selectedTranslator.target);
// add save filters
for(var i in translators) {
var label = translators[i].label;
// put extensions in parentheses if Mac (Windows users already
// get extension)
label += " (."+translators[i].target+")";
fp.appendFilter(label, "*."+translators[i].target);
}
var rv = fp.show(); var rv = fp.show();
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
@ -43,8 +40,7 @@ var Scholar_File_Interface = new function() {
translation.setItems(items); translation.setItems(items);
} }
translation.setLocation(fp.file); translation.setLocation(fp.file);
translation.setTranslator(translators[fp.filterIndex]); translation.setTranslator(io.selectedTranslator);
translation.setHandler("options", _exportOptions);
translation.setHandler("done", _exportDone); translation.setHandler("done", _exportDone);
_disableUnresponsive(); _disableUnresponsive();
Scholar_File_Interface.Progress.show( Scholar_File_Interface.Progress.show(
@ -89,22 +85,6 @@ var Scholar_File_Interface = new function() {
exportFile(Scholar.getString("fileInterface.exportedItems"), items); exportFile(Scholar.getString("fileInterface.exportedItems"), items);
} }
/*
* closes items exported indicator
*/
function _exportOptions(obj, options) {
var io = {options:options}
window.openDialog("chrome://scholar/content/exportOptions.xul",
"_blank","chrome,modal,centerscreen", io);
if(io.options) {
// refocus dialog
Scholar_File_Interface.Progress.show();
return options;
} else {
return false;
}
}
/* /*
* closes items exported indicator * closes items exported indicator
*/ */

View File

@ -180,10 +180,7 @@ Scholar_Ingester_Interface.showPopup = function(collectionID, parentElement) {
return false; // Don't dynamically reload popups that are already showing return false; // Don't dynamically reload popups that are already showing
} }
Scholar_Ingester_Interface._scrapePopupShowing = true; Scholar_Ingester_Interface._scrapePopupShowing = true;
parentElement.removeAllItems();
while(parentElement.hasChildNodes()) {
parentElement.removeChild(parentElement.firstChild);
}
if(collectionID == null) { // show library if(collectionID == null) { // show library
var newItem = document.createElement("menuitem"); var newItem = document.createElement("menuitem");

View File

@ -246,6 +246,14 @@ Scholar.Translate.prototype.setString = function(string) {
this._storagePointer = 0; this._storagePointer = 0;
} }
/*
* sets translator display options. you can also pass a translator (not ID) to
* setTranslator that includes a displayOptions argument
*/
Scholar.Translate.prototype.setDisplayOptions = function(displayOptions) {
this._setDisplayOptions = displayOptions;
}
/* /*
* sets the translator to be used for import/export * sets the translator to be used for import/export
* *
@ -256,8 +264,14 @@ Scholar.Translate.prototype.setTranslator = function(translator) {
throw("cannot set translator: invalid value"); throw("cannot set translator: invalid value");
} }
this._setDisplayOptions = null;
if(typeof(translator) == "object") { // passed an object and not an ID if(typeof(translator) == "object") { // passed an object and not an ID
if(translator.translatorID) { if(translator.translatorID) {
if(translator.displayOptions) {
this._setDisplayOptions = translator.displayOptions;
}
translator = [translator.translatorID]; translator = [translator.translatorID];
} else { } else {
// we have an associative array of translators // we have an associative array of translators
@ -303,12 +317,6 @@ Scholar.Translate.prototype.setTranslator = function(translator) {
* *
* as the first argument, all handlers will be passed the current function. the * as the first argument, all handlers will be passed the current function. the
* second argument is dependent on the handler. * second argument is dependent on the handler.
*
* options
* valid: export
* called: when options requiring user interaction are available
* passed: an associative array of options and default values
* returns: an associative array of options
* *
* select * select
* valid: web * valid: web
@ -372,22 +380,16 @@ Scholar.Translate.prototype.getTranslators = function() {
var translators = Scholar.DB.query(sql); var translators = Scholar.DB.query(sql);
} }
if(!this.location && !this.search) { // create a new sandbox
return translators; // no need to see which can translate, because this._generateSandbox();
// we don't have a location yet (for export or
// import dialog) var possibleTranslators = new Array();
} else { Scholar.debug("searching for translators for "+(this.path ? this.path : "an undisclosed location"));
// create a new sandbox
this._generateSandbox(); // see which translators can translate
var possibleTranslators = this._findTranslators(translators);
var possibleTranslators = new Array();
Scholar.debug("searching for translators for "+this.path); return possibleTranslators;
// see which translators can translate
var possibleTranslators = this._findTranslators(translators);
return possibleTranslators;
}
} }
/* /*
@ -408,6 +410,9 @@ Scholar.Translate.prototype._findTranslators = function(translators, ignoreExten
label:translators[i].label, label:translators[i].label,
target:translators[i].target, target:translators[i].target,
itemType:translators[i].itemType} itemType:translators[i].itemType}
if(this.type == "export") {
translator.displayOptions = this._displayOptions;
}
possibleTranslators.push(translator); possibleTranslators.push(translator);
} }
@ -471,24 +476,16 @@ Scholar.Translate.prototype.translate = function() {
return; return;
} }
if(this._setDisplayOptions) {
this._displayOptions = this._setDisplayOptions;
}
if(this._storage) { if(this._storage) {
// enable reading from storage, which we can't do until the translator // enable reading from storage, which we can't do until the translator
// is loaded // is loaded
this._storageFunctions(true); this._storageFunctions(true);
} }
// hack to see if there are any options, bc length does not work on objects
if(this.type == "export") {
for(var i in this._displayOptions) {
// run handler for options if there are any
if(!(this._displayOptions = this._runHandler("options", this._displayOptions))) {
this._translationComplete(true);
return false;
}
break;
}
}
var returnValue; var returnValue;
if(this.type == "web") { if(this.type == "web") {
returnValue = this._web(); returnValue = this._web();

View File

@ -64,6 +64,8 @@
<!ENTITY progress.title "Progress"> <!ENTITY progress.title "Progress">
<!ENTITY exportOptions.title "Export..."> <!ENTITY exportOptions.title "Export...">
<!ENTITY exportOptions.format.label "Format:">
<!ENTITY exportOptions.translatorOptions.label "Translator Options">
<!ENTITY search.match "Match"> <!ENTITY search.match "Match">
<!ENTITY search.any "any"> <!ENTITY search.any "any">