www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit dd0c537ce15b94c9b24cfa9ee3b8ab623303b826
parent 7d93903e2db0466f9477d9c153900f0eaaace3a1
Author: Simon Kornblith <simon@simonster.com>
Date:   Mon,  4 Sep 2006 22:57:23 +0000

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

thanks to Dan for the idea


Diffstat:
Mchrome/chromeFiles/content/scholar/exportOptions.js | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Mchrome/chromeFiles/content/scholar/exportOptions.xul | 11++++++++++-
Mchrome/chromeFiles/content/scholar/fileInterface.js | 44++++++++++++--------------------------------
Mchrome/chromeFiles/content/scholar/ingester/browser.js | 5+----
Mchrome/chromeFiles/content/scholar/xpcom/translate.js | 65+++++++++++++++++++++++++++++++----------------------------------
Mchrome/chromeFiles/locale/en-US/scholar/scholar.dtd | 2++
6 files changed, 139 insertions(+), 98 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/exportOptions.js b/chrome/chromeFiles/content/scholar/exportOptions.js @@ -7,9 +7,8 @@ // Class to provide options for export var Scholar_File_Interface_Export = new function() { - var _options; - this.init = init; + this.updateOptions = updateOptions; this.accept = accept; this.cancel = cancel; @@ -17,29 +16,80 @@ var Scholar_File_Interface_Export = new function() { * add options to export */ function init() { - _options = window.arguments[0].options; + var addedOptions = new Object(); + + var translators = window.arguments[0].translators; - // add options to dialog - var dialog = document.getElementById("scholar-export-options"); - for(var option in _options) { - var defValue = _options[option]; + var listbox = document.getElementById("format-popup"); + 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 - try { - var optionLabel = Scholar.getString("exportOptions."+option); - } catch(e) { - var optionLabel = option; + // add options + for(var option in translators[i].displayOptions) { + if(!addedOptions[option]) { // if this option is not already + // presented to the user + // 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 - // it interprets as checkboxes - Scholar.debug(option+" ("+optionLabel+") = "+defValue+" ("+typeof(defValue)+")"); - if(typeof(defValue) == "boolean") { - var checkbox = document.createElement("checkbox"); - checkbox.setAttribute("id", option); - checkbox.setAttribute("label", optionLabel); - checkbox.setAttribute("checked", (defValue ? "true" : "false")); - dialog.appendChild(checkbox); + if(translatorOptions[optionName] != undefined) { + // option should be enabled + node.disabled = undefined; + + var defValue = translatorOptions[optionName]; + if(typeof(defValue) == "boolean") { + // if option exists, enable it and set to default value + node.setAttribute("checked", (defValue ? "true" : "false")); + } + } 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 */ function accept() { - for(var option in _options) { - var defValue = _options[option]; - var element = document.getElementById(option); + // set selected translator + var index = document.getElementById("format-menu").selectedIndex; + 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(element.checked == true) { - _options[option] = true; + optionsAvailable[option] = true; } else { - _options[option] = false; + optionsAvailable[option] = false; } } } @@ -66,6 +122,6 @@ var Scholar_File_Interface_Export = new function() { * make option array reflect status */ function cancel() { - window.arguments[0].options = false; + window.arguments[0].selectedTranslator = false; } } \ No newline at end of file diff --git a/chrome/chromeFiles/content/scholar/exportOptions.xul b/chrome/chromeFiles/content/scholar/exportOptions.xul @@ -10,5 +10,14 @@ <script src="include.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> \ No newline at end of file diff --git a/chrome/chromeFiles/content/scholar/fileInterface.js b/chrome/chromeFiles/content/scholar/fileInterface.js @@ -15,27 +15,24 @@ var Scholar_File_Interface = new function() { var translation = new Scholar.Translate("export"); 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; var fp = Components.classes["@mozilla.org/filepicker;1"] .createInstance(nsIFilePicker); 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")); - fp.defaultString = name+"."+translators[0].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); - } - + fp.defaultString = name+"."+io.selectedTranslator.target; + fp.appendFilter(io.selectedTranslator.label, "*."+io.selectedTranslator.target); var rv = fp.show(); if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { @@ -43,8 +40,7 @@ var Scholar_File_Interface = new function() { translation.setItems(items); } translation.setLocation(fp.file); - translation.setTranslator(translators[fp.filterIndex]); - translation.setHandler("options", _exportOptions); + translation.setTranslator(io.selectedTranslator); translation.setHandler("done", _exportDone); _disableUnresponsive(); Scholar_File_Interface.Progress.show( @@ -92,22 +88,6 @@ var Scholar_File_Interface = new function() { /* * 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 - */ function _exportDone(obj, worked) { Scholar_File_Interface.Progress.close(); _restoreUnresponsive(); diff --git a/chrome/chromeFiles/content/scholar/ingester/browser.js b/chrome/chromeFiles/content/scholar/ingester/browser.js @@ -180,10 +180,7 @@ Scholar_Ingester_Interface.showPopup = function(collectionID, parentElement) { return false; // Don't dynamically reload popups that are already showing } Scholar_Ingester_Interface._scrapePopupShowing = true; - - while(parentElement.hasChildNodes()) { - parentElement.removeChild(parentElement.firstChild); - } + parentElement.removeAllItems(); if(collectionID == null) { // show library var newItem = document.createElement("menuitem"); diff --git a/chrome/chromeFiles/content/scholar/xpcom/translate.js b/chrome/chromeFiles/content/scholar/xpcom/translate.js @@ -247,6 +247,14 @@ Scholar.Translate.prototype.setString = function(string) { } /* + * 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 * * accepts either the object from getTranslators() or an ID @@ -256,8 +264,14 @@ Scholar.Translate.prototype.setTranslator = function(translator) { throw("cannot set translator: invalid value"); } + this._setDisplayOptions = null; + if(typeof(translator) == "object") { // passed an object and not an ID if(translator.translatorID) { + if(translator.displayOptions) { + this._setDisplayOptions = translator.displayOptions; + } + translator = [translator.translatorID]; } else { // 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 * 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 * valid: web @@ -372,22 +380,16 @@ Scholar.Translate.prototype.getTranslators = function() { var translators = Scholar.DB.query(sql); } - if(!this.location && !this.search) { - return translators; // no need to see which can translate, because - // we don't have a location yet (for export or - // import dialog) - } else { - // create a new sandbox - this._generateSandbox(); - - var possibleTranslators = new Array(); - Scholar.debug("searching for translators for "+this.path); - - // see which translators can translate - var possibleTranslators = this._findTranslators(translators); - - return possibleTranslators; - } + // create a new sandbox + this._generateSandbox(); + + var possibleTranslators = new Array(); + Scholar.debug("searching for translators for "+(this.path ? this.path : "an undisclosed location")); + + // 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, target:translators[i].target, itemType:translators[i].itemType} + if(this.type == "export") { + translator.displayOptions = this._displayOptions; + } possibleTranslators.push(translator); } @@ -471,24 +476,16 @@ Scholar.Translate.prototype.translate = function() { return; } + if(this._setDisplayOptions) { + this._displayOptions = this._setDisplayOptions; + } + if(this._storage) { // enable reading from storage, which we can't do until the translator // is loaded 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; if(this.type == "web") { returnValue = this._web(); diff --git a/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd b/chrome/chromeFiles/locale/en-US/scholar/scholar.dtd @@ -64,6 +64,8 @@ <!ENTITY progress.title "Progress"> <!ENTITY exportOptions.title "Export..."> +<!ENTITY exportOptions.format.label "Format:"> +<!ENTITY exportOptions.translatorOptions.label "Translator Options"> <!ENTITY search.match "Match"> <!ENTITY search.any "any">