preferences_search.js (4018B)
1 /* 2 ***** BEGIN LICENSE BLOCK ***** 3 4 Copyright © 2006–2013 Center for History and New Media 5 George Mason University, Fairfax, Virginia, USA 6 http://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 "use strict"; 27 28 Zotero_Preferences.Search = { 29 init: function () { 30 document.getElementById('fulltext-rebuildIndex').setAttribute('label', 31 Zotero.getString('zotero.preferences.search.rebuildIndex') 32 + Zotero.getString('punctuation.ellipsis')); 33 document.getElementById('fulltext-clearIndex').setAttribute('label', 34 Zotero.getString('zotero.preferences.search.clearIndex') 35 + Zotero.getString('punctuation.ellipsis')); 36 37 this.updateIndexStats(); 38 }, 39 40 updateIndexStats: Zotero.Promise.coroutine(function* () { 41 var stats = yield Zotero.Fulltext.getIndexStats(); 42 document.getElementById('fulltext-stats-indexed'). 43 lastChild.setAttribute('value', stats.indexed); 44 document.getElementById('fulltext-stats-partial'). 45 lastChild.setAttribute('value', stats.partial); 46 document.getElementById('fulltext-stats-unindexed'). 47 lastChild.setAttribute('value', stats.unindexed); 48 document.getElementById('fulltext-stats-words'). 49 lastChild.setAttribute('value', stats.words); 50 }), 51 52 53 rebuildIndexPrompt: Zotero.Promise.coroutine(function* () { 54 var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]. 55 createInstance(Components.interfaces.nsIPromptService); 56 var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING) 57 + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL) 58 + (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_IS_STRING); 59 60 var index = ps.confirmEx(null, 61 Zotero.getString('zotero.preferences.search.rebuildIndex'), 62 Zotero.getString('zotero.preferences.search.rebuildWarning', 63 Zotero.getString('zotero.preferences.search.indexUnindexed')), 64 buttonFlags, 65 Zotero.getString('zotero.preferences.search.rebuildIndex'), 66 null, 67 // Position 2 because of https://bugzilla.mozilla.org/show_bug.cgi?id=345067 68 Zotero.getString('zotero.preferences.search.indexUnindexed'), 69 null, {}); 70 71 if (index == 0) { 72 yield Zotero.Fulltext.rebuildIndex(); 73 } 74 else if (index == 2) { 75 yield Zotero.Fulltext.rebuildIndex(true) 76 } 77 78 yield this.updateIndexStats(); 79 }), 80 81 82 clearIndexPrompt: Zotero.Promise.coroutine(function* () { 83 var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]. 84 createInstance(Components.interfaces.nsIPromptService); 85 var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING) 86 + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL) 87 + (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_IS_STRING); 88 89 var index = ps.confirmEx(null, 90 Zotero.getString('zotero.preferences.search.clearIndex'), 91 Zotero.getString('zotero.preferences.search.clearWarning', 92 Zotero.getString('zotero.preferences.search.clearNonLinkedURLs')), 93 buttonFlags, 94 Zotero.getString('zotero.preferences.search.clearIndex'), 95 null, 96 // Position 2 because of https://bugzilla.mozilla.org/show_bug.cgi?id=345067 97 Zotero.getString('zotero.preferences.search.clearNonLinkedURLs'), null, {}); 98 99 if (index == 0) { 100 yield Zotero.Fulltext.clearIndex(); 101 } 102 else if (index == 2) { 103 yield Zotero.Fulltext.clearIndex(true); 104 } 105 106 yield this.updateIndexStats(); 107 }) 108 };