From fbef911cb76cdc71427be645505bcd6b9675f3d8 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 26 Apr 2015 02:22:46 -0400 Subject: [PATCH] Add wizard for My Publications Show a wizard after items are dragged to My Publications choosing whether to include files and notes and choosing sharing settings for the items. Sharing options are Creative Commons licenses, CC0, "All rights reserved", or keeping the existing Rights field if available. Also blocks collections, searches, linked file attachments, and top-level attachments/notes from My Publications at the data layer, but not yet from the UI in all places (so it can crash if you try). Todo: - Block certain UI actions with nice messages - Show a nice scrollable list of items in the wizard to allow selecting specific files/notes, instead of just having checkboxes for files and notes that apply to all dragged items - Show an explanation of My Publications in the right-hand pane when no items are selected - Maybe adjust handling when no attached files/notes, since it might be a bit alarming at the moment to see sharing options for metadata entries --- chrome/content/zotero/publicationsDialog.js | 420 ++++++++++++++++++ chrome/content/zotero/publicationsDialog.xul | 107 +++++ .../zotero/xpcom/collectionTreeView.js | 58 ++- .../content/zotero/xpcom/data/collection.js | 1 + .../content/zotero/xpcom/data/dataObject.js | 5 + chrome/content/zotero/xpcom/data/item.js | 17 + chrome/content/zotero/xpcom/itemTreeView.js | 9 +- chrome/content/zotero/xpcom/search.js | 1 + .../zotero/xpcom/utilities_internal.js | 34 ++ chrome/content/zotero/zoteroPane.js | 54 ++- chrome/locale/en-US/zotero/publications.dtd | 19 + chrome/locale/en-US/zotero/zotero.dtd | 4 +- chrome/locale/en-US/zotero/zotero.properties | 20 + .../default/zotero/licenses/cc-by-nc-nd.svg | 243 ++++++++++ .../default/zotero/licenses/cc-by-nc-sa.svg | 202 +++++++++ .../skin/default/zotero/licenses/cc-by-nc.svg | 190 ++++++++ .../skin/default/zotero/licenses/cc-by-nd.svg | 203 +++++++++ .../skin/default/zotero/licenses/cc-by-sa.svg | 199 +++++++++ chrome/skin/default/zotero/licenses/cc-by.svg | 155 +++++++ .../skin/default/zotero/licenses/cc-srr.png | Bin 0 -> 24909 bytes chrome/skin/default/zotero/licenses/cc0.svg | 98 ++++ .../skin/default/zotero/licenses/reserved.png | Bin 0 -> 18349 bytes .../default/zotero/publicationsDialog.css | 16 + chrome/skin/default/zotero/zotero.css | 1 + 24 files changed, 2028 insertions(+), 28 deletions(-) create mode 100644 chrome/content/zotero/publicationsDialog.js create mode 100644 chrome/content/zotero/publicationsDialog.xul create mode 100644 chrome/locale/en-US/zotero/publications.dtd create mode 100644 chrome/skin/default/zotero/licenses/cc-by-nc-nd.svg create mode 100644 chrome/skin/default/zotero/licenses/cc-by-nc-sa.svg create mode 100644 chrome/skin/default/zotero/licenses/cc-by-nc.svg create mode 100644 chrome/skin/default/zotero/licenses/cc-by-nd.svg create mode 100644 chrome/skin/default/zotero/licenses/cc-by-sa.svg create mode 100644 chrome/skin/default/zotero/licenses/cc-by.svg create mode 100644 chrome/skin/default/zotero/licenses/cc-srr.png create mode 100644 chrome/skin/default/zotero/licenses/cc0.svg create mode 100644 chrome/skin/default/zotero/licenses/reserved.png create mode 100644 chrome/skin/default/zotero/publicationsDialog.css diff --git a/chrome/content/zotero/publicationsDialog.js b/chrome/content/zotero/publicationsDialog.js new file mode 100644 index 0000000000..8e3f02cda2 --- /dev/null +++ b/chrome/content/zotero/publicationsDialog.js @@ -0,0 +1,420 @@ +/* + ***** BEGIN LICENSE BLOCK ***** + + Copyright © 2015 Center for History and New Media + George Mason University, Fairfax, Virginia, USA + https://www.zotero.org + + This file is part of Zotero. + + Zotero is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Zotero is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with Zotero. If not, see . + + ***** END LICENSE BLOCK ***** +*/ + +var Zotero_Publications_Dialog = new function () { + var _initialized = false; + var _io; + var _hasFiles = false; + var _hasNotes = false; + var _hasRights = null; + var _includeFiles = true; + var _includeNotes = true; + var _useRights = true; + var _shareSettings = { + sharing: 'cc', + adaptations: 'no', + commercial: 'yes' + }; + var _license = null; + + function _init() { + try { + var wizard = document.getElementById('zotero-publications-wizard'); + wizard.getButton('finish').label = + Zotero.getString('publications.buttons.addToMyPublications'); + + if (window.arguments && window.arguments.length) { + _io = window.arguments[0]; + _hasFiles = _io.hasFiles; + _hasNotes = _io.hasNotes; + _hasRights = _io.hasRights; + if (_hasRights == 'none') _useRights = false; + delete _io.hasFiles; + delete _io.hasNotes; + delete _io.hasRights; + } + _initialized = true; + } + catch (e) { + window.close(); + throw e; + } + } + + + this.updatePage = function () { + if (!_initialized) { + _init(); + } + + var wizard = document.getElementById('zotero-publications-wizard'); + var currentPage = wizard.currentPage; + var pageid = currentPage.pageid; + + if (pageid == 'intro') { + let str = 'publications.authorship.checkbox'; + let filesCheckbox = document.getElementById('include-files'); + let notesCheckbox = document.getElementById('include-notes') + + // Enable the checkboxes only when relevant + filesCheckbox.disabled = !_hasFiles; + filesCheckbox.checked = _hasFiles && _includeFiles; + notesCheckbox.disabled = !_hasNotes; + notesCheckbox.checked = _hasNotes && _includeNotes; + + // Adjust the checkbox text based on whether there are files or notes + if (filesCheckbox.checked || notesCheckbox.checked) { + if (filesCheckbox.checked && notesCheckbox.checked) { + str += '.filesNotes'; + } + else if (filesCheckbox.checked) { + str += '.files'; + } + else { + str += '.notes'; + } + } + } + else if (pageid == 'choose-sharing') { + let useRightsBox = document.getElementById('use-rights'); + let useRightsCheckbox = document.getElementById('use-rights-checkbox'); + if (_hasRights == 'none') { + useRightsBox.hidden = true; + document.getElementById('sharing-radiogroup').focus(); + } + else { + let str = 'publications.sharing.useRightsField'; + if (_hasRights == 'some') { + str += 'WhereAvailable'; + } + useRightsCheckbox.label = Zotero.getString(str); + useRightsCheckbox.checked = _useRights; + this.updateUseRights(useRightsCheckbox.checked); + } + } + // Select appropriate radio button from current license + else if (pageid == 'choose-license') { + document.getElementById('adaptations-' + _shareSettings.adaptations).selected = true; + document.getElementById('commercial-' + _shareSettings.commercial).selected = true; + } + + _updateLicense(); + this.updateNextButton(); + }; + + + this.updateNextButton = function () { + var wizard = document.getElementById('zotero-publications-wizard'); + var currentPage = wizard.currentPage; + var nextPage = wizard.wizardPages[wizard.pageIndex + 1]; + var pageid = wizard.currentPage.pageid; + var nextButton = wizard.getButton('next'); + var finishButton = wizard.getButton('finish'); + + // Require authorship checkbox on first page to be checked to advance + wizard.canAdvance = document.getElementById('confirm-authorship-checkbox').checked; + + if (!nextPage) { + return; + } + + if (currentPage.pageid == 'intro' || + // If CC selected on sharing page and we're not using existing rights for all + // items, go to license chooser next + (currentPage.pageid == 'choose-sharing' + && _shareSettings.sharing == 'cc' + && !(_hasRights == 'all' && _useRights))) { + this.lastPage = false; + finishButton.hidden = true; + nextButton.hidden = false; + nextButton.label = Zotero.getString( + 'publications.buttons.next', + Zotero.getString('publications.buttons.' + nextPage.pageid) + ); + } + // Otherwise this is the last page + else { + this.lastPage = true; + nextButton.hidden = true; + finishButton.hidden = false; + } + } + + + /** + * Update files/notes settings from checkboxes + */ + this.updateInclude = function () { + var filesCheckbox = document.getElementById('include-files'); + var notesCheckbox = document.getElementById('include-notes') + _includeFiles = filesCheckbox.checked; + _includeNotes = notesCheckbox.checked; + } + + + /** + * Update rights setting from checkbox and hide sharing setting if necessary + */ + this.updateUseRights = function (useRights) { + _useRights = useRights; + + // If all items have rights and we're using them, the sharing page is the last page + document.getElementById('choose-sharing-options').hidden = _hasRights == 'all' && useRights; + this.updateNextButton(); + } + + + /** + * Update sharing and license settings + */ + this.updateSharing = function (id) { + var matches = id.match(/^(sharing|adaptations|commercial)-(.+)$/); + var setting = matches[1]; + var value = matches[2]; + _shareSettings[setting] = value; + _updateLicense(); + this.updateNextButton(); + } + + + this.onAdvance = function () { + if (this.lastPage) { + this.finish(); + return false; + } + return true; + } + + + this.onFinish = function () { + _io.includeFiles = document.getElementById('include-files').checked; + _io.includeNotes = document.getElementById('include-notes').checked; + _io.useRights = _useRights; + _io.license = _license; + _io.licenseName = _getLicenseName(_license); + } + + this.finish = function () { + this.onFinish(); + window.close(); + } + + + /** + * Update the calculated license and image + * + * Possible licenses: + * + * 'cc-by' + * 'cc-by-sa' + * 'cc-by-nd' + * 'cc-by-nc' + * 'cc-by-nc-sa' + * 'cc-by-nc-nd' + * 'cc0' + * 'reserved' + */ + function _updateLicense() { + var s = _shareSettings.sharing; + var a = _shareSettings.adaptations; + var c = _shareSettings.commercial; + + if (s == 'cc0' || s == 'reserved') { + _license = s; + } + else { + _license = 'cc-by'; + if (c == 'no') { + _license += '-nc'; + } + if (a == 'no') { + _license += '-nd'; + } + else if (a == 'sharealike') { + _license += '-sa'; + } + } + _updateLicenseSummary(); + } + + + /** + * + */ + function _updateLicenseSummary() { + var wizard = document.getElementById('zotero-publications-wizard'); + var currentPage = wizard.currentPage; + var groupbox = currentPage.getElementsByAttribute('class', 'license-info')[0]; + if (!groupbox) return; + if (groupbox.hasChildNodes()) { + let hbox = groupbox.lastChild; + var icon = currentPage.getElementsByAttribute('class', 'license-icon')[0]; + var div = currentPage.getElementsByAttribute('class', 'license-description')[0]; + } + else { + let hbox = document.createElement('hbox'); + hbox.align = "center"; + groupbox.appendChild(hbox); + + var icon = document.createElement('image'); + icon.className = 'license-icon'; + icon.setAttribute('style', 'width: 88px'); + hbox.appendChild(icon); + + let sep = document.createElement('separator'); + sep.orient = 'vertical'; + sep.setAttribute('style', 'width: 10px'); + hbox.appendChild(sep); + + var div = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); + div.className = 'license-description'; + div.setAttribute('style', 'width: 400px'); + hbox.appendChild(div); + } + + // Show generic CC icon on sharing page + if (currentPage.pageid == 'choose-sharing' && _shareSettings.sharing == 'cc') { + var license = 'cc'; + } + else { + var license = _license; + } + + icon.src = _getLicenseImage(license); + var url = _getLicenseURL(license); + if (url) { + icon.setAttribute('tooltiptext', url); + icon.style.cursor = 'pointer'; + icon.onclick = function () { + try { + let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + let win = wm.getMostRecentWindow("navigator:browser"); + win.ZoteroPane_Local.loadURI(url, { shiftKey: true }) + } + catch (e) { + Zotero.logError(e); + } + return false; + }; + } + else { + icon.removeAttribute('tooltiptext'); + icon.style.cursor = 'auto'; + } + + div.innerHTML = _getLicenseHTML(license); + Zotero.Utilities.Internal.updateHTMLInXUL(div, { linkEvent: { shiftKey: true } }); + + _updateLicenseMoreInfo(); + } + + + function _getLicenseImage(license) { + // Use generic "Some Rights Reserved" image + if (license == 'cc') { + return "chrome://zotero/skin/licenses/cc-srr.png"; + } + else if (license == 'reserved') { + return "chrome://zotero/skin/licenses/reserved.png"; + } + return "chrome://zotero/skin/licenses/" + license + ".svg"; + } + + + function _getLicenseHTML(license) { + switch (license) { + case 'cc': + return 'Creative Commons'; + + case 'reserved': + return "All rights reserved"; + + case 'cc0': + return 'CC0 1.0 Universal Public Domain Dedication'; + + default: + return '' + + Zotero.getString('licenses.' + license) + ""; + } + } + + + function _getLicenseName(license) { + switch (license) { + case 'reserved': + return "All rights reserved"; + + case 'cc0': + return 'CC0 1.0 Universal Public Domain Dedication'; + + default: + return Zotero.getString('licenses.' + license) + " (" + license.toUpperCase() + ")"; + } + } + + + function _getLicenseURL(license) { + switch (license) { + case 'reserved': + return ""; + + case 'cc': + return 'https://creativecommons.org/'; + + case 'cc0': + return "https://creativecommons.org/publicdomain/zero/1.0/"; + + default: + return "https://creativecommons.org/licenses/" + license.replace(/^cc-/, '') + "/4.0/" + } + } + + + function _updateLicenseMoreInfo() { + var wizard = document.getElementById('zotero-publications-wizard'); + var currentPage = wizard.currentPage; + var s = _shareSettings.sharing; + + var div = currentPage.getElementsByAttribute('class', 'license-more-info')[0]; + if (s == 'cc0' || currentPage.pageid == 'choose-license') { + let links = { + cc: 'https://wiki.creativecommons.org/Considerations_for_licensors_and_licensees', + cc0: 'https://wiki.creativecommons.org/CC0_FAQ' + }; + div.innerHTML = Zotero.getString( + 'publications.' + s + '.moreInfo.text', + // Add link to localized string + '' + + Zotero.getString('publications.' + s + '.moreInfo.linkText') + + '' + ); + Zotero.Utilities.Internal.updateHTMLInXUL(div, { linkEvent: { shiftKey: true } }); + } + else { + div.innerHTML = ""; + } + } +} diff --git a/chrome/content/zotero/publicationsDialog.xul b/chrome/content/zotero/publicationsDialog.xul new file mode 100644 index 0000000000..b4f229e1af --- /dev/null +++ b/chrome/content/zotero/publicationsDialog.xul @@ -0,0 +1,107 @@ + + + %zoteroDTD; + %publicationsDTD; +]> + + + + + + + +