publicationsDialog.js (11986B)
1 /* 2 ***** BEGIN LICENSE BLOCK ***** 3 4 Copyright © 2015 Center for History and New Media 5 George Mason University, Fairfax, Virginia, USA 6 https://www.zotero.org 7 8 This file is part of Zotero. 9 10 Zotero is free software: you can redistribute it and/or modify 11 it under the terms of the GNU Affero General Public License as published by 12 the Free Software Foundation, either version 3 of the License, or 13 (at your option) any later version. 14 15 Zotero is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU Affero General Public License for more details. 19 20 You should have received a copy of the GNU Affero General Public License 21 along with Zotero. If not, see <http://www.gnu.org/licenses/>. 22 23 ***** END LICENSE BLOCK ***** 24 */ 25 26 var Zotero_Publications_Dialog = new function () { 27 var _initialized = false; 28 var _io; 29 var _hasFiles = false; 30 var _hasNotes = false; 31 var _hasRights = null; 32 var _includeFiles = true; 33 var _includeNotes = true; 34 var _keepRights = true; 35 var _shareSettings = { 36 sharing: 'reserved', // 'reserved', 'cc', 'cc0' 37 adaptations: 'no', 38 commercial: 'no' 39 }; 40 var _license = null; 41 42 function _init() { 43 try { 44 var wizard = document.getElementById('zotero-publications-wizard'); 45 wizard.getButton('finish').label = 46 Zotero.getString('publications.buttons.addToMyPublications'); 47 48 if (window.arguments && window.arguments.length) { 49 _io = window.arguments[0]; 50 _hasFiles = _io.hasFiles; 51 _hasNotes = _io.hasNotes; 52 _hasRights = _io.hasRights; 53 if (_hasRights == 'none') _keepRights = false; 54 delete _io.hasFiles; 55 delete _io.hasNotes; 56 delete _io.hasRights; 57 } 58 _initialized = true; 59 } 60 catch (e) { 61 window.close(); 62 throw e; 63 } 64 } 65 66 67 this.updatePage = function () { 68 if (!_initialized) { 69 _init(); 70 this.updateInclude(); 71 } 72 73 var wizard = document.getElementById('zotero-publications-wizard'); 74 var currentPage = wizard.currentPage; 75 var pageid = currentPage.pageid; 76 77 if (pageid == 'intro') { 78 let str = 'publications.authorship.checkbox'; 79 let filesCheckbox = document.getElementById('include-files'); 80 let notesCheckbox = document.getElementById('include-notes') 81 82 // Enable the checkboxes only when relevant 83 filesCheckbox.disabled = !_hasFiles; 84 filesCheckbox.checked = _hasFiles && _includeFiles; 85 notesCheckbox.disabled = !_hasNotes; 86 notesCheckbox.checked = _hasNotes && _includeNotes; 87 88 // Adjust the checkbox text based on whether there are files or notes 89 if (filesCheckbox.checked || notesCheckbox.checked) { 90 if (filesCheckbox.checked && notesCheckbox.checked) { 91 str += '.filesNotes'; 92 } 93 else if (filesCheckbox.checked) { 94 str += '.files'; 95 } 96 else { 97 str += '.notes'; 98 } 99 } 100 } 101 else if (pageid == 'choose-sharing') { 102 let keepRightsBox = document.getElementById('keep-rights'); 103 let keepRightsCheckbox = document.getElementById('keep-rights-checkbox'); 104 if (_hasRights == 'none') { 105 keepRightsBox.hidden = true; 106 document.getElementById('sharing-radiogroup').focus(); 107 } 108 else { 109 let str = 'publications.sharing.keepRightsField'; 110 if (_hasRights == 'some') { 111 str += 'WhereAvailable'; 112 } 113 keepRightsCheckbox.label = Zotero.getString(str); 114 keepRightsCheckbox.checked = _keepRights; 115 this.updateKeepRights(keepRightsCheckbox.checked); 116 } 117 } 118 // Select appropriate radio button from current license 119 else if (pageid == 'choose-license') { 120 document.getElementById('adaptations-' + _shareSettings.adaptations).selected = true; 121 document.getElementById('commercial-' + _shareSettings.commercial).selected = true; 122 } 123 124 _updateLicense(); 125 this.updateNextButton(); 126 }; 127 128 129 this.updateNextButton = function () { 130 var wizard = document.getElementById('zotero-publications-wizard'); 131 var currentPage = wizard.currentPage; 132 var nextPage = wizard.wizardPages[wizard.pageIndex + 1]; 133 var nextButton = wizard.getButton('next'); 134 135 // Require authorship checkbox on first page to be checked to advance 136 wizard.canAdvance = document.getElementById('confirm-authorship-checkbox').checked; 137 138 if (!nextPage) { 139 return; 140 } 141 142 if (_hasFiles 143 && _includeFiles 144 && (currentPage.pageid == 'intro' || 145 // If CC selected on sharing page and we're not using existing rights for all 146 // items, go to license chooser next 147 (currentPage.pageid == 'choose-sharing' 148 && _shareSettings.sharing == 'cc' 149 && !(_hasRights == 'all' && _keepRights)))) { 150 this.lastPage = false; 151 nextButton.label = Zotero.getString( 152 'publications.buttons.next', 153 Zotero.getString('publications.buttons.' + nextPage.pageid) 154 ); 155 } 156 // Otherwise this is the last page 157 else { 158 this.lastPage = true; 159 // Due to issues with linux not handling finish button hiding correctly 160 // we just set the next button label to be the one for the finish button 161 // and leave visibility handling up to mr wizard 162 nextButton.label = Zotero.getString('publications.buttons.addToMyPublications'); 163 } 164 } 165 166 167 /** 168 * Update files/notes settings from checkboxes 169 */ 170 this.updateInclude = function () { 171 var filesCheckbox = document.getElementById('include-files'); 172 var notesCheckbox = document.getElementById('include-notes') 173 var authorshipCheckbox = document.getElementById('confirm-authorship-checkbox'); 174 _includeFiles = filesCheckbox.checked; 175 _includeNotes = notesCheckbox.checked; 176 authorshipCheckbox.label = Zotero.getString( 177 'publications.intro.authorship' + (_includeFiles ? '.files' : '') 178 ); 179 this.updateNextButton(); 180 } 181 182 183 /** 184 * Update rights setting from checkbox and hide sharing setting if necessary 185 */ 186 this.updateKeepRights = function (keepRights) { 187 _keepRights = keepRights; 188 189 // If all items have rights and we're using them, the sharing page is the last page 190 document.getElementById('choose-sharing-options').hidden = _hasRights == 'all' && keepRights; 191 this.updateNextButton(); 192 } 193 194 195 /** 196 * Update sharing and license settings 197 */ 198 this.updateSharing = function (id) { 199 var matches = id.match(/^(sharing|adaptations|commercial)-(.+)$/); 200 var setting = matches[1]; 201 var value = matches[2]; 202 _shareSettings[setting] = value; 203 _updateLicense(); 204 this.updateNextButton(); 205 } 206 207 208 this.onAdvance = function () { 209 if (this.lastPage) { 210 this.finish(); 211 return false; 212 } 213 return true; 214 } 215 216 217 this.onFinish = function () { 218 _io.includeFiles = document.getElementById('include-files').checked; 219 _io.includeNotes = document.getElementById('include-notes').checked; 220 _io.keepRights = _keepRights; 221 _io.license = _license; 222 _io.licenseName = _getLicenseName(_license); 223 } 224 225 this.finish = function () { 226 this.onFinish(); 227 window.close(); 228 } 229 230 231 /** 232 * Update the calculated license and image 233 * 234 * Possible licenses: 235 * 236 * 'cc-by' 237 * 'cc-by-sa' 238 * 'cc-by-nd' 239 * 'cc-by-nc' 240 * 'cc-by-nc-sa' 241 * 'cc-by-nc-nd' 242 * 'cc0' 243 * 'reserved' 244 */ 245 function _updateLicense() { 246 var s = _shareSettings.sharing; 247 var a = _shareSettings.adaptations; 248 var c = _shareSettings.commercial; 249 250 if (s == 'cc0' || s == 'reserved') { 251 _license = s; 252 } 253 else { 254 _license = 'cc-by'; 255 if (c == 'no') { 256 _license += '-nc'; 257 } 258 if (a == 'no') { 259 _license += '-nd'; 260 } 261 else if (a == 'sharealike') { 262 _license += '-sa'; 263 } 264 } 265 _updateLicenseSummary(); 266 } 267 268 269 /** 270 * 271 */ 272 function _updateLicenseSummary() { 273 var wizard = document.getElementById('zotero-publications-wizard'); 274 var currentPage = wizard.currentPage; 275 var groupbox = currentPage.getElementsByAttribute('class', 'license-info')[0]; 276 if (!groupbox) return; 277 if (groupbox.hasChildNodes()) { 278 let hbox = groupbox.lastChild; 279 var icon = currentPage.getElementsByAttribute('class', 'license-icon')[0]; 280 var div = currentPage.getElementsByAttribute('class', 'license-description')[0]; 281 } 282 else { 283 let hbox = document.createElement('hbox'); 284 hbox.align = "center"; 285 groupbox.appendChild(hbox); 286 287 var icon = document.createElement('image'); 288 icon.className = 'license-icon'; 289 icon.setAttribute('style', 'width: 88px'); 290 hbox.appendChild(icon); 291 292 let sep = document.createElement('separator'); 293 sep.orient = 'vertical'; 294 sep.setAttribute('style', 'width: 10px'); 295 hbox.appendChild(sep); 296 297 var div = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); 298 div.className = 'license-description'; 299 div.setAttribute('style', 'width: 400px'); 300 hbox.appendChild(div); 301 } 302 303 // Show generic CC icon on sharing page 304 if (currentPage.pageid == 'choose-sharing' && _shareSettings.sharing == 'cc') { 305 var license = 'cc'; 306 } 307 else { 308 var license = _license; 309 } 310 311 icon.src = _getLicenseImage(license); 312 var url = _getLicenseURL(license); 313 if (url) { 314 icon.setAttribute('tooltiptext', url); 315 icon.style.cursor = 'pointer'; 316 icon.onclick = function () { 317 try { 318 let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] 319 .getService(Components.interfaces.nsIWindowMediator); 320 let win = wm.getMostRecentWindow("navigator:browser"); 321 win.ZoteroPane_Local.loadURI(url, { shiftKey: true }) 322 } 323 catch (e) { 324 Zotero.logError(e); 325 } 326 return false; 327 }; 328 } 329 else { 330 icon.removeAttribute('tooltiptext'); 331 icon.style.cursor = 'auto'; 332 } 333 334 div.innerHTML = _getLicenseHTML(license); 335 Zotero.Utilities.Internal.updateHTMLInXUL(div, { linkEvent: { shiftKey: true } }); 336 337 _updateLicenseMoreInfo(); 338 } 339 340 341 function _getLicenseImage(license) { 342 // Use generic "Some Rights Reserved" image 343 if (license == 'cc') { 344 return "chrome://zotero/skin/licenses/cc-srr.png"; 345 } 346 else if (license == 'reserved') { 347 return "chrome://zotero/skin/licenses/reserved.png"; 348 } 349 return "chrome://zotero/skin/licenses/" + license + ".svg"; 350 } 351 352 353 function _getLicenseHTML(license) { 354 switch (license) { 355 case 'cc': 356 return '<a href="' + _getLicenseURL(license) + '">Creative Commons</a>'; 357 358 case 'reserved': 359 return "All rights reserved"; 360 361 case 'cc0': 362 return '<a href="' + _getLicenseURL(license) + '">CC0 1.0 Universal Public Domain Dedication</a>'; 363 364 default: 365 return '<a href="' + _getLicenseURL(license) + '">' 366 + Zotero.getString('licenses.' + license) + "</a>"; 367 } 368 } 369 370 371 function _getLicenseName(license) { 372 switch (license) { 373 case 'reserved': 374 return "All rights reserved"; 375 376 case 'cc0': 377 return 'CC0 1.0 Universal Public Domain Dedication'; 378 379 default: 380 return Zotero.getString('licenses.' + license) + " (" + license.toUpperCase() + ")"; 381 } 382 } 383 384 385 function _getLicenseURL(license) { 386 switch (license) { 387 case 'reserved': 388 return ""; 389 390 case 'cc': 391 return 'https://creativecommons.org/'; 392 393 case 'cc0': 394 return "https://creativecommons.org/publicdomain/zero/1.0/"; 395 396 default: 397 return "https://creativecommons.org/licenses/" + license.replace(/^cc-/, '') + "/4.0/" 398 } 399 } 400 401 402 function _updateLicenseMoreInfo() { 403 var wizard = document.getElementById('zotero-publications-wizard'); 404 var currentPage = wizard.currentPage; 405 var s = _shareSettings.sharing; 406 407 var div = currentPage.getElementsByAttribute('class', 'license-more-info')[0]; 408 if (s == 'cc0' || currentPage.pageid == 'choose-license') { 409 let links = { 410 cc: 'https://wiki.creativecommons.org/Considerations_for_licensors_and_licensees', 411 cc0: 'https://wiki.creativecommons.org/CC0_FAQ' 412 }; 413 div.innerHTML = Zotero.getString( 414 'publications.' + s + '.moreInfo.text', 415 // Add link to localized string 416 '<a href="' + links[s] + '">' 417 + Zotero.getString('publications.' + s + '.moreInfo.linkText') 418 + '</a>' 419 ); 420 Zotero.Utilities.Internal.updateHTMLInXUL(div, { linkEvent: { shiftKey: true } }); 421 } 422 else { 423 div.innerHTML = ""; 424 } 425 } 426 }