diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml index c2f1bdb98a..1e4184f068 100644 --- a/chrome/content/zotero/bindings/itembox.xml +++ b/chrome/content/zotero/bindings/itembox.xml @@ -341,7 +341,9 @@ fieldNames.push(Zotero.ItemFields.getName(fields[i])); } - fieldNames.push("dateAdded", "dateModified"); + if (!(this.item instanceof Zotero.FeedItem)) { + fieldNames.push("dateAdded", "dateModified"); + } } for (var i=0; i' - + Zotero.getString('ingester.scrapeErrorDescription.linkText') + ''; - Zotero_Browser.progress.addDescription(Zotero.getString("ingester.scrapeErrorDescription", linkText)); - Zotero_Browser.progress.startCloseTimer(8000); - } else { - Zotero_Browser.progress.startCloseTimer(); - } + translate.setHandler("done", function() { + Zotero_Browser.progress.Translation.doneHandler.apply(Zotero_Browser.progress.Translation, arguments); Zotero_Browser.isScraping = false; - deferred.resolve(); }); - translate.setHandler("itemDone", function(obj, dbItem, item) { - Zotero_Browser.progress.show(); - var itemProgress = new Zotero_Browser.progress.ItemProgress(Zotero.ItemTypes.getImageSrc(item.itemType), - item.title); - itemProgress.setProgress(100); - for(var i=0; i. + + ***** END LICENSE BLOCK ***** +*/ + +////////////////////////////////////////////////////////////////////////////// +// +// Zotero_Feed_Settings +// +////////////////////////////////////////////////////////////////////////////// + +var Zotero_Feed_Settings = new function() { + let urlIsValid = true, + data = null, + feedReader = null, + urlTainted = false; + + let cleanURL = function(url) { + let cleanURL = Zotero.Utilities.cleanURL(url, true); + + if (cleanURL) { + if (/^https?:\/\/[^\/\s]+\/\S/.test(cleanURL)) { + return cleanURL; + } else { + Zotero.debug(uri.scheme + " is not a supported protocol for feeds"); + } + } + }; + + this.init = Zotero.Promise.coroutine(function* () { + this.toggleAdvancedOptions(false); + + data = window.arguments[0]; + + if (data.url) { + document.getElementById('feed-url').value = data.url; + // Do not allow to change URL for existing feed + document.getElementById('feed-url').readOnly = true; + } else { + this.invalidateURL(); + } + + if (data.title) { + document.getElementById('feed-title').value = data.title; + } + + let ttl; + if (data.ttl !== undefined) { + ttl = Math.floor(data.ttl / 60); + } else { + ttl = Zotero.Prefs.get('feeds.defaultTTL'); + } + document.getElementById('feed-ttl').value = ttl; + + let cleanupAfter = data.cleanupAfter; + if (cleanupAfter === undefined) cleanupAfter = Zotero.Prefs.get('feeds.defaultCleanupAfter'); + document.getElementById('feed-cleanupAfter').value = cleanupAfter; + + if (data.url && !data.urlIsValid) { + yield this.validateURL(); + } + }); + + this.invalidateURL = function() { + urlTainted = true; + if (feedReader) { + feedReader.terminate(); + feedReader = null; + } + + if (!urlIsValid) return; + + urlIsValid = false; + document.getElementById('feed-title').disabled = true; + document.getElementById('feed-ttl').disabled = true; + document.getElementById('feed-cleanupAfter').disabled = true; + document.documentElement.getButton('accept').disabled = true; + }; + + this.validateURL = Zotero.Promise.coroutine(function* () { + if (feedReader) { + feedReader.terminate(); + feedReader = null; + } + + let url = cleanURL(document.getElementById('feed-url').value); + urlTainted = false; + if (!url) return; + + try { + var fr = feedReader = new Zotero.FeedReader(url); + yield fr.process(); + let feed = fr.feedProperties; + // Prevent progress if textbox changes triggered another call to + // validateURL / invalidateURL (old session) + if (feedReader !== fr || urlTainted) return; + + let title = document.getElementById('feed-title'); + if (!data.url && feed.title) { + title.value = feed.title; + } + + let ttl = document.getElementById('feed-ttl'); + if (!data.url && feed.ttl) { + ttl.value = Math.floor(feed.ttl / 60) || 1; + } + + document.getElementById('feed-url').value = url; + + urlIsValid = true; + title.disabled = false; + ttl.disabled = false; + document.getElementById('feed-cleanupAfter').disabled = false; + document.documentElement.getButton('accept').disabled = false; + } + catch (e) { + Zotero.debug(e); + } + finally { + if (feedReader === fr) feedReader = null; + } + }); + + this.accept = function() { + data.url = document.getElementById('feed-url').value; + data.title = document.getElementById('feed-title').value; + data.ttl = document.getElementById('feed-ttl').value * 60; + data.cleanupAfter = document.getElementById('feed-cleanupAfter').value * 1; + return true; + }; + + this.cancel = function() { + data.cancelled = true; + return true; + }; + + /* + * Show/hide advanced options + * @param {Boolean} [show] If set, indicates whether the advanced + * options should be shown or not. If omitted, the options toggle + */ + this.toggleAdvancedOptions = function(show) { + var opts = document.getElementById("advanced-options-togglable"); + opts.hidden = show !== undefined ? !show : !opts.hidden; + document.getElementById("advanced-options") + .setAttribute("state", opts.hidden ? "closed" : "open"); + window.sizeToContent(); + }; +} \ No newline at end of file diff --git a/chrome/content/zotero/feedSettings.xul b/chrome/content/zotero/feedSettings.xul new file mode 100644 index 0000000000..2cc6e22140 --- /dev/null +++ b/chrome/content/zotero/feedSettings.xul @@ -0,0 +1,62 @@ + + + + %zoteroDTD; +]> + + +