closes #99, add options for export
This commit is contained in:
parent
af080fe384
commit
6efd6d2cc4
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) {
|
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
|
||||||
translation.setLocation(fp.file);
|
translation.setLocation(fp.file);
|
||||||
translation.setTranslator(translators[fp.filterIndex]);
|
translation.setTranslator(translators[fp.filterIndex]);
|
||||||
//translation.setHandler("itemCount", _exportItemCount);
|
translation.setHandler("options", _exportOptions);
|
||||||
//translation.setHandler("itemDone", _exportItemDone);
|
|
||||||
translation.setHandler("done", _exportDone);
|
translation.setHandler("done", _exportDone);
|
||||||
_disableUnresponsive();
|
_disableUnresponsive();
|
||||||
Scholar_File_Interface.Progress.show(
|
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) {
|
function _exportOptions(obj, options) {
|
||||||
Scholar.debug("count called with "+number);
|
var io = {options:options}
|
||||||
Scholar_File_Interface.Progress.setNumber(number);
|
window.openDialog("chrome://scholar/content/exportOptions.xul",
|
||||||
}
|
"_blank","chrome,modal,centerscreen", io);
|
||||||
|
if(io.options) {
|
||||||
/*
|
// refocus dialog
|
||||||
* Increment progress for each item exported
|
Scholar_File_Interface.Progress.show();
|
||||||
*/
|
return options;
|
||||||
function _exportItemDone(obj, item) {
|
} else {
|
||||||
Scholar_File_Interface.Progress.increment();
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -58,7 +58,6 @@ Scholar_File_Interface = new function() {
|
||||||
_restoreUnresponsive();
|
_restoreUnresponsive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates Scholar.Translate instance and shows file picker for file import
|
* Creates Scholar.Translate instance and shows file picker for file import
|
||||||
*/
|
*/
|
||||||
|
@ -105,7 +104,6 @@ Scholar_File_Interface = new function() {
|
||||||
* "items imported" indicator, too.
|
* "items imported" indicator, too.
|
||||||
*/
|
*/
|
||||||
function _importItemDone(obj, item) {
|
function _importItemDone(obj, item) {
|
||||||
//Scholar_File_Interface.Progress.increment();
|
|
||||||
_importCollection.addItem(item.getID());
|
_importCollection.addItem(item.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,12 +254,11 @@ Scholar_File_Interface.Progress = new function() {
|
||||||
var _loadHeadline, _loadNumber, _outOf, _callback;
|
var _loadHeadline, _loadNumber, _outOf, _callback;
|
||||||
|
|
||||||
this.show = show;
|
this.show = show;
|
||||||
//this.setNumber = setNumber;
|
|
||||||
//this.increment = increment;
|
|
||||||
this.close = close;
|
this.close = close;
|
||||||
|
|
||||||
function show(headline, callback) {
|
function show(headline, callback) {
|
||||||
if(_windowLoading || _windowLoaded) { // already loading or loaded
|
if(_windowLoading || _windowLoaded) { // already loading or loaded
|
||||||
|
_progressWindow.focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_windowLoading = true;
|
_windowLoading = true;
|
||||||
|
@ -275,26 +272,6 @@ Scholar_File_Interface.Progress = new function() {
|
||||||
_progressWindow.addEventListener("pageshow", _onWindowLoaded, false);
|
_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() {
|
function close() {
|
||||||
_windowLoaded = false;
|
_windowLoaded = false;
|
||||||
try {
|
try {
|
||||||
|
@ -307,12 +284,6 @@ Scholar_File_Interface.Progress = new function() {
|
||||||
_windowLoaded = true;
|
_windowLoaded = true;
|
||||||
|
|
||||||
// do things we delayed because the winodw was loading
|
// 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;
|
_progressWindow.document.getElementById("progress-label").value = _loadHeadline;
|
||||||
|
|
||||||
if(_callback) {
|
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
|
* 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
|
||||||
* called: when the user needs to select from a list of available items
|
* 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
|
* finds applicable translators from a list. if the second argument is given,
|
||||||
*
|
* extension-based exclusion is inverted, so that only detectCode is used to
|
||||||
* NOT IMPLEMENTED
|
* determine if a translator can be run.
|
||||||
*/
|
*/
|
||||||
Scholar.Translate.prototype.displayOptions = function() {
|
|
||||||
}
|
|
||||||
|
|
||||||
Scholar.Translate.prototype._findTranslators = function(translators, ignoreExtensions) {
|
Scholar.Translate.prototype._findTranslators = function(translators, ignoreExtensions) {
|
||||||
var possibleTranslators = new Array();
|
var possibleTranslators = new Array();
|
||||||
for(var i in translators) {
|
for(var i in translators) {
|
||||||
|
@ -323,6 +326,9 @@ Scholar.Translate.prototype._findTranslators = function(translators, ignoreExten
|
||||||
return possibleTranslators;
|
return possibleTranslators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* loads a translator into a sandbox
|
||||||
|
*/
|
||||||
Scholar.Translate.prototype._loadTranslator = function() {
|
Scholar.Translate.prototype._loadTranslator = function() {
|
||||||
if(!this._sandbox || this.type == "search") {
|
if(!this._sandbox || this.type == "search") {
|
||||||
// create a new sandbox if none exists, or for searching (so that it's
|
// create a new sandbox if none exists, or for searching (so that it's
|
||||||
|
@ -367,7 +373,16 @@ Scholar.Translate.prototype.translate = function() {
|
||||||
return;
|
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;
|
var returnValue;
|
||||||
if(this.type == "web") {
|
if(this.type == "web") {
|
||||||
|
@ -461,6 +476,8 @@ Scholar.Translate.prototype._generateSandbox = function() {
|
||||||
this._sandbox.Scholar.configure = function(option, value) {me._configure(option, value) };
|
this._sandbox.Scholar.configure = function(option, value) {me._configure(option, value) };
|
||||||
// for adding displayed options
|
// for adding displayed options
|
||||||
this._sandbox.Scholar.addOption = function(option, value) {me._addOption(option, value) };
|
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
|
// for loading other translators and accessing their methods
|
||||||
this._sandbox.Scholar.loadTranslator = function(type, translatorID) {
|
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.setItem = function(arg) { return translation.setItem(arg) };
|
||||||
safeTranslator.setBrowser = function(arg) { return translation.setBrowser(arg) };
|
safeTranslator.setBrowser = function(arg) { return translation.setBrowser(arg) };
|
||||||
safeTranslator.setHandler = function(arg1, arg2) { translation.setHandler(arg1, arg2) };
|
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.setTranslator = function(arg) { return translation.setTranslator(arg) };
|
||||||
safeTranslator.getTranslators = function() { return translation.getTranslators() };
|
safeTranslator.getTranslators = function() { return translation.getTranslators() };
|
||||||
safeTranslator.translate = function() { return translation.translate() };
|
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
|
// if we're ignoring extensions, that means we already tried
|
||||||
// everything without ignoring extensions and it didn't work
|
// everything without ignoring extensions and it didn't work
|
||||||
canTranslate = !canTranslate;
|
canTranslate = !canTranslate;
|
||||||
|
|
||||||
|
// if a translator has no detectCode, don't offer it as an option
|
||||||
|
if(!translator.detectCode) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var canTranslate = true;
|
var canTranslate = true;
|
||||||
|
@ -630,6 +653,16 @@ Scholar.Translate.prototype._addOption = function(option, value) {
|
||||||
Scholar.debug("setting display option "+option+" to "+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
|
* makes translation API wait until done() has been called from the translator
|
||||||
* before executing _translationComplete
|
* before executing _translationComplete
|
||||||
|
|
|
@ -52,3 +52,5 @@
|
||||||
<!ENTITY bibliography.print.label "Print">
|
<!ENTITY bibliography.print.label "Print">
|
||||||
|
|
||||||
<!ENTITY progress.title "Progress">
|
<!ENTITY progress.title "Progress">
|
||||||
|
|
||||||
|
<!ENTITY exportOptions.title "Export...">
|
|
@ -100,3 +100,6 @@ searchOperator.lessThan = is less than
|
||||||
searchOperator.greaterThan = is greater than
|
searchOperator.greaterThan = is greater than
|
||||||
searchOperator.isBefore = is before
|
searchOperator.isBefore = is before
|
||||||
searchOperator.isAfter = is after
|
searchOperator.isAfter = is after
|
||||||
|
|
||||||
|
exportOptions.exportNotes = Export Notes
|
||||||
|
exportOptions.exportFileData = Export Files
|
50
scrapers.sql
50
scrapers.sql
|
@ -1,4 +1,4 @@
|
||||||
-- 40
|
-- 41
|
||||||
|
|
||||||
-- Set the following timestamp to the most recent scraper update date
|
-- Set the following timestamp to the most recent scraper update date
|
||||||
REPLACE INTO "version" VALUES ('repository', STRFTIME('%s', '2006-08-08 17:12:00'));
|
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',
|
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("exportNotes", true);
|
||||||
Scholar.addOption("exportFileData", true);
|
|
||||||
|
|
||||||
function detectImport() {
|
function detectImport() {
|
||||||
var read = Scholar.read(512);
|
var read = Scholar.read(512);
|
||||||
|
@ -3003,10 +3002,12 @@ function doExport() {
|
||||||
|
|
||||||
/** NOTES **/
|
/** NOTES **/
|
||||||
|
|
||||||
for(var j in item.notes) {
|
if(Scholar.getOption("exportNotes")) {
|
||||||
// Add note tag
|
for(var j in item.notes) {
|
||||||
var note = <note type="content">{item.notes[j].note}</note>;
|
// Add note tag
|
||||||
mods.note += note;
|
var note = <note type="content">{item.notes[j].note}</note>;
|
||||||
|
mods.note += note;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** TAGS **/
|
/** TAGS **/
|
||||||
|
@ -3335,6 +3336,9 @@ function doExport() {
|
||||||
type = "Document";
|
type = "Document";
|
||||||
} else if(item.itemType == "note") {
|
} else if(item.itemType == "note") {
|
||||||
type = "Memo";
|
type = "Memo";
|
||||||
|
if(!Scholar.getOption("exportNotes")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(type) {
|
if(type) {
|
||||||
Scholar.RDF.addStatement(resource, rdf+"type", n.bib+type, false);
|
Scholar.RDF.addStatement(resource, rdf+"type", n.bib+type, false);
|
||||||
|
@ -3530,22 +3534,24 @@ function doExport() {
|
||||||
|
|
||||||
/** NOTES **/
|
/** NOTES **/
|
||||||
|
|
||||||
for(var j in item.notes) {
|
if(Scholar.getOption("exportNotes")) {
|
||||||
var noteResource = itemResources[item.notes[j].itemID];
|
for(var j in item.notes) {
|
||||||
|
var noteResource = itemResources[item.notes[j].itemID];
|
||||||
|
|
||||||
// add note tag
|
// add note tag
|
||||||
Scholar.RDF.addStatement(noteResource, rdf+"type", n.bib+"Memo", false);
|
Scholar.RDF.addStatement(noteResource, rdf+"type", n.bib+"Memo", false);
|
||||||
// add note value
|
// add note value
|
||||||
Scholar.RDF.addStatement(noteResource, rdf+"value", item.notes[j].note, true);
|
Scholar.RDF.addStatement(noteResource, rdf+"value", item.notes[j].note, true);
|
||||||
// add relationship between resource and note
|
// add relationship between resource and note
|
||||||
Scholar.RDF.addStatement(resource, n.dcterms+"isReferencedBy", noteResource, false);
|
Scholar.RDF.addStatement(resource, n.dcterms+"isReferencedBy", noteResource, false);
|
||||||
|
|
||||||
// Add see also info to RDF
|
// Add see also info to RDF
|
||||||
generateSeeAlso(resource, item.notes[j].seeAlso);
|
generateSeeAlso(resource, item.notes[j].seeAlso);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(item.note) {
|
if(item.note) {
|
||||||
Scholar.RDF.addStatement(resource, rdf+"value", item.note, true);
|
Scholar.RDF.addStatement(resource, rdf+"value", item.note, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** TAGS **/
|
/** TAGS **/
|
||||||
|
@ -4326,8 +4332,10 @@ function doExport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// notes
|
// notes
|
||||||
for(var j in item.notes) {
|
if(Scholar.getOption("exportNotes")) {
|
||||||
addTag("N1", item.notes[j].note);
|
for(var j in item.notes) {
|
||||||
|
addTag("N1", item.notes[j].note.replace(/[\r\n]/g, " "));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tags
|
// tags
|
||||||
|
|
Loading…
Reference in New Issue
Block a user