closes #99, add options for export
This commit is contained in:
parent
af080fe384
commit
6efd6d2cc4
7 changed files with 178 additions and 75 deletions
72
chrome/chromeFiles/content/scholar/exportOptions.js
Normal file
72
chrome/chromeFiles/content/scholar/exportOptions.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Scholar_File_Interface_Export
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Class to provide options for export
|
||||
|
||||
Scholar_File_Interface_Export = new function() {
|
||||
var _options;
|
||||
|
||||
this.init = init;
|
||||
this.accept = accept;
|
||||
this.cancel = cancel;
|
||||
|
||||
/*
|
||||
* add options to export
|
||||
*/
|
||||
function init() {
|
||||
_options = window.arguments[0].options;
|
||||
|
||||
// add options to dialog
|
||||
var dialog = document.getElementById("scholar-export-options");
|
||||
for(var option in _options) {
|
||||
var defValue = _options[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
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* make option array reflect status
|
||||
*/
|
||||
function accept() {
|
||||
for(var option in _options) {
|
||||
var defValue = _options[option];
|
||||
var element = document.getElementById(option);
|
||||
|
||||
if(typeof(defValue) == "bool") {
|
||||
if(element.checked == "true") {
|
||||
_options[option] = true;
|
||||
} else {
|
||||
_options[option] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Scholar.debug(_options);
|
||||
}
|
||||
|
||||
/*
|
||||
* make option array reflect status
|
||||
*/
|
||||
function cancel() {
|
||||
window.arguments[0].options = false;
|
||||
}
|
||||
}
|
14
chrome/chromeFiles/content/scholar/exportOptions.xul
Normal file
14
chrome/chromeFiles/content/scholar/exportOptions.xul
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
<!DOCTYPE window SYSTEM "chrome://scholar/locale/scholar.dtd">
|
||||
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="&exportOptions.title;" buttons="cancel,accept"
|
||||
ondialogaccept="Scholar_File_Interface_Export.accept()"
|
||||
ondialogcancel="Scholar_File_Interface_Export.cancel()"
|
||||
id="scholar-export-options"
|
||||
onload="Scholar_File_Interface_Export.init()">
|
||||
|
||||
<script src="include.js"/>
|
||||
<script src="exportOptions.js"/>
|
||||
|
||||
</dialog>
|
|
@ -23,8 +23,7 @@ Scholar_File_Interface = new function() {
|
|||
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
|
||||
translation.setLocation(fp.file);
|
||||
translation.setTranslator(translators[fp.filterIndex]);
|
||||
//translation.setHandler("itemCount", _exportItemCount);
|
||||
//translation.setHandler("itemDone", _exportItemDone);
|
||||
translation.setHandler("options", _exportOptions);
|
||||
translation.setHandler("done", _exportDone);
|
||||
_disableUnresponsive();
|
||||
Scholar_File_Interface.Progress.show(
|
||||
|
@ -36,18 +35,19 @@ Scholar_File_Interface = new function() {
|
|||
}
|
||||
|
||||
/*
|
||||
* set progress indicator length
|
||||
* closes items exported indicator
|
||||
*/
|
||||
function _exportItemCount(obj, number) {
|
||||
Scholar.debug("count called with "+number);
|
||||
Scholar_File_Interface.Progress.setNumber(number);
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* Increment progress for each item exported
|
||||
*/
|
||||
function _exportItemDone(obj, item) {
|
||||
Scholar_File_Interface.Progress.increment();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -58,7 +58,6 @@ Scholar_File_Interface = new function() {
|
|||
_restoreUnresponsive();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Creates Scholar.Translate instance and shows file picker for file import
|
||||
*/
|
||||
|
@ -105,7 +104,6 @@ Scholar_File_Interface = new function() {
|
|||
* "items imported" indicator, too.
|
||||
*/
|
||||
function _importItemDone(obj, item) {
|
||||
//Scholar_File_Interface.Progress.increment();
|
||||
_importCollection.addItem(item.getID());
|
||||
}
|
||||
|
||||
|
@ -256,12 +254,11 @@ Scholar_File_Interface.Progress = new function() {
|
|||
var _loadHeadline, _loadNumber, _outOf, _callback;
|
||||
|
||||
this.show = show;
|
||||
//this.setNumber = setNumber;
|
||||
//this.increment = increment;
|
||||
this.close = close;
|
||||
|
||||
function show(headline, callback) {
|
||||
if(_windowLoading || _windowLoaded) { // already loading or loaded
|
||||
_progressWindow.focus();
|
||||
return false;
|
||||
}
|
||||
_windowLoading = true;
|
||||
|
@ -275,26 +272,6 @@ Scholar_File_Interface.Progress = new function() {
|
|||
_progressWindow.addEventListener("pageshow", _onWindowLoaded, false);
|
||||
}
|
||||
|
||||
/*function setNumber(number) {
|
||||
_outOf = number;
|
||||
if(_windowLoaded) {
|
||||
var progressMeter = _progressWindow.document.getElementById("progress-indicator");
|
||||
progressMeter.mode = "normal";
|
||||
progressMeter.value = "0%";
|
||||
}
|
||||
}
|
||||
|
||||
function increment() {
|
||||
_loadNumber++;
|
||||
if(_windowLoaded) {
|
||||
_progressWindow.document.getElementById("progress-items").value = _loadNumber;
|
||||
if(_outOf) {
|
||||
_progressWindow.document.getElementById("progress-indicator").value = ((_loadNumber/_outOf)*100).toString()+"%";
|
||||
}
|
||||
_progressWindow.getSelection();
|
||||
}
|
||||
}*/
|
||||
|
||||
function close() {
|
||||
_windowLoaded = false;
|
||||
try {
|
||||
|
@ -307,12 +284,6 @@ Scholar_File_Interface.Progress = new function() {
|
|||
_windowLoaded = true;
|
||||
|
||||
// do things we delayed because the winodw was loading
|
||||
/*if(_outOf) {
|
||||
var progressMeter = _progressWindow.document.getElementById("progress-indicator");
|
||||
progressMeter.mode = "normal";
|
||||
progressMeter.value = ((_loadNumber/_outOf)*100).toString()+"%";
|
||||
}
|
||||
_progressWindow.document.getElementById("progress-items").value = _loadNumber;*/
|
||||
_progressWindow.document.getElementById("progress-label").value = _loadHeadline;
|
||||
|
||||
if(_callback) {
|
||||
|
|
|
@ -216,6 +216,12 @@ 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
|
||||
* called: when the user needs to select from a list of available items
|
||||
|
@ -291,13 +297,10 @@ Scholar.Translate.prototype.getTranslators = function() {
|
|||
}
|
||||
|
||||
/*
|
||||
* gets translator options to be displayed in a dialog
|
||||
*
|
||||
* NOT IMPLEMENTED
|
||||
* finds applicable translators from a list. if the second argument is given,
|
||||
* extension-based exclusion is inverted, so that only detectCode is used to
|
||||
* determine if a translator can be run.
|
||||
*/
|
||||
Scholar.Translate.prototype.displayOptions = function() {
|
||||
}
|
||||
|
||||
Scholar.Translate.prototype._findTranslators = function(translators, ignoreExtensions) {
|
||||
var possibleTranslators = new Array();
|
||||
for(var i in translators) {
|
||||
|
@ -323,6 +326,9 @@ Scholar.Translate.prototype._findTranslators = function(translators, ignoreExten
|
|||
return possibleTranslators;
|
||||
}
|
||||
|
||||
/*
|
||||
* loads a translator into a sandbox
|
||||
*/
|
||||
Scholar.Translate.prototype._loadTranslator = function() {
|
||||
if(!this._sandbox || this.type == "search") {
|
||||
// create a new sandbox if none exists, or for searching (so that it's
|
||||
|
@ -367,7 +373,16 @@ Scholar.Translate.prototype.translate = function() {
|
|||
return;
|
||||
}
|
||||
|
||||
this._sandbox.Scholar.scraperName = this.translator[0].label;
|
||||
|
||||
// hack to see if there are any options, bc length does not work on objects
|
||||
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") {
|
||||
|
@ -461,6 +476,8 @@ Scholar.Translate.prototype._generateSandbox = function() {
|
|||
this._sandbox.Scholar.configure = function(option, value) {me._configure(option, value) };
|
||||
// for adding displayed options
|
||||
this._sandbox.Scholar.addOption = function(option, value) {me._addOption(option, value) };
|
||||
// for getting the value of displayed options
|
||||
this._sandbox.Scholar.getOption = function(option) { return me._getOption(option) };
|
||||
|
||||
// for loading other translators and accessing their methods
|
||||
this._sandbox.Scholar.loadTranslator = function(type, translatorID) {
|
||||
|
@ -488,6 +505,7 @@ Scholar.Translate.prototype._generateSandbox = function() {
|
|||
safeTranslator.setItem = function(arg) { return translation.setItem(arg) };
|
||||
safeTranslator.setBrowser = function(arg) { return translation.setBrowser(arg) };
|
||||
safeTranslator.setHandler = function(arg1, arg2) { translation.setHandler(arg1, arg2) };
|
||||
safeTranslator.setString = function(arg) { translation.setString(arg) };
|
||||
safeTranslator.setTranslator = function(arg) { return translation.setTranslator(arg) };
|
||||
safeTranslator.getTranslators = function() { return translation.getTranslators() };
|
||||
safeTranslator.translate = function() { return translation.translate() };
|
||||
|
@ -521,6 +539,11 @@ Scholar.Translate.prototype._canTranslate = function(translator, ignoreExtension
|
|||
// if we're ignoring extensions, that means we already tried
|
||||
// everything without ignoring extensions and it didn't work
|
||||
canTranslate = !canTranslate;
|
||||
|
||||
// if a translator has no detectCode, don't offer it as an option
|
||||
if(!translator.detectCode) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var canTranslate = true;
|
||||
|
@ -630,6 +653,16 @@ Scholar.Translate.prototype._addOption = function(option, value) {
|
|||
Scholar.debug("setting display option "+option+" to "+value);
|
||||
}
|
||||
|
||||
/*
|
||||
* gets translator options that were displayed in a dialog
|
||||
*
|
||||
* called as getOption() in detect code
|
||||
*
|
||||
*/
|
||||
Scholar.Translate.prototype._getOption = function(option) {
|
||||
return this._displayOptions[option];
|
||||
}
|
||||
|
||||
/*
|
||||
* makes translation API wait until done() has been called from the translator
|
||||
* before executing _translationComplete
|
||||
|
|
|
@ -52,3 +52,5 @@
|
|||
<!ENTITY bibliography.print.label "Print">
|
||||
|
||||
<!ENTITY progress.title "Progress">
|
||||
|
||||
<!ENTITY exportOptions.title "Export...">
|
|
@ -100,3 +100,6 @@ searchOperator.lessThan = is less than
|
|||
searchOperator.greaterThan = is greater than
|
||||
searchOperator.isBefore = is before
|
||||
searchOperator.isAfter = is after
|
||||
|
||||
exportOptions.exportNotes = Export Notes
|
||||
exportOptions.exportFileData = Export Files
|
14
scrapers.sql
14
scrapers.sql
|
@ -1,4 +1,4 @@
|
|||
-- 40
|
||||
-- 41
|
||||
|
||||
-- Set the following timestamp to the most recent scraper update date
|
||||
REPLACE INTO "version" VALUES ('repository', STRFTIME('%s', '2006-08-08 17:12:00'));
|
||||
|
@ -2738,7 +2738,6 @@ function doSearch(item) {
|
|||
|
||||
REPLACE INTO "translators" VALUES ('0e2235e7-babf-413c-9acf-f27cce5f059c', '2006-07-05 23:40:00', 3, 'MODS (XML)', 'Simon Kornblith', 'xml',
|
||||
'Scholar.addOption("exportNotes", true);
|
||||
Scholar.addOption("exportFileData", true);
|
||||
|
||||
function detectImport() {
|
||||
var read = Scholar.read(512);
|
||||
|
@ -3003,11 +3002,13 @@ function doExport() {
|
|||
|
||||
/** NOTES **/
|
||||
|
||||
if(Scholar.getOption("exportNotes")) {
|
||||
for(var j in item.notes) {
|
||||
// Add note tag
|
||||
var note = <note type="content">{item.notes[j].note}</note>;
|
||||
mods.note += note;
|
||||
}
|
||||
}
|
||||
|
||||
/** TAGS **/
|
||||
|
||||
|
@ -3335,6 +3336,9 @@ function doExport() {
|
|||
type = "Document";
|
||||
} else if(item.itemType == "note") {
|
||||
type = "Memo";
|
||||
if(!Scholar.getOption("exportNotes")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(type) {
|
||||
Scholar.RDF.addStatement(resource, rdf+"type", n.bib+type, false);
|
||||
|
@ -3530,6 +3534,7 @@ function doExport() {
|
|||
|
||||
/** NOTES **/
|
||||
|
||||
if(Scholar.getOption("exportNotes")) {
|
||||
for(var j in item.notes) {
|
||||
var noteResource = itemResources[item.notes[j].itemID];
|
||||
|
||||
|
@ -3547,6 +3552,7 @@ function doExport() {
|
|||
if(item.note) {
|
||||
Scholar.RDF.addStatement(resource, rdf+"value", item.note, true);
|
||||
}
|
||||
}
|
||||
|
||||
/** TAGS **/
|
||||
|
||||
|
@ -4326,8 +4332,10 @@ function doExport() {
|
|||
}
|
||||
|
||||
// notes
|
||||
if(Scholar.getOption("exportNotes")) {
|
||||
for(var j in item.notes) {
|
||||
addTag("N1", item.notes[j].note);
|
||||
addTag("N1", item.notes[j].note.replace(/[\r\n]/g, " "));
|
||||
}
|
||||
}
|
||||
|
||||
// tags
|
||||
|
|
Loading…
Reference in a new issue