www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

syncUtilities.js (2795B)


      1 /*
      2     ***** BEGIN LICENSE BLOCK *****
      3     
      4     Copyright © 2014 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 if (!Zotero.Sync.Data) {
     27 	Zotero.Sync.Data = {};
     28 }
     29 
     30 Zotero.Sync.Data.Utilities = {
     31 	_syncObjectTypeIDs: {},
     32 	
     33 	init: Zotero.Promise.coroutine(function* () {
     34 		// If not found, cache all
     35 		var sql = "SELECT name, syncObjectTypeID AS id FROM syncObjectTypes";
     36 		var rows = yield Zotero.DB.queryAsync(sql);
     37 		for (let i = 0; i < rows.length; i++) {
     38 			row = rows[i];
     39 			this._syncObjectTypeIDs[row.name] = row.id;
     40 		}
     41 	}),
     42 	
     43 	getSyncObjectTypeID: function (objectType) {
     44 		if (!this._syncObjectTypeIDs[objectType]) {
     45 			return false;
     46 		}
     47 		return this._syncObjectTypeIDs[objectType];
     48 	},
     49 	
     50 	
     51 	/**
     52 	 * Prompt whether to reset unsynced local data in a library
     53 	 *
     54 	 * Keep in sync with Sync.Storage.Utilities.showFileWriteAccessLostPrompt()
     55 	 * @param {Window|null} win
     56 	 * @param {Zotero.Library} library
     57 	 * @return {Integer} - 0 to reset, 1 to skip
     58 	 */
     59 	showWriteAccessLostPrompt: function (win, library) {
     60 		var libraryType = library.libraryType;
     61 		switch (libraryType) {
     62 		case 'group':
     63 			var msg = Zotero.getString('sync.error.groupWriteAccessLost',
     64 					[library.name, ZOTERO_CONFIG.DOMAIN_NAME])
     65 				+ "\n\n"
     66 				+ Zotero.getString('sync.error.groupCopyChangedItems')
     67 			var button1Text = Zotero.getString('sync.resetGroupAndSync');
     68 			var button2Text = Zotero.getString('sync.skipGroup');
     69 			break;
     70 		
     71 		default:
     72 			throw new Error("Unsupported library type " + libraryType);
     73 		}
     74 		
     75 		var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
     76 			.getService(Components.interfaces.nsIPromptService);
     77 		var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
     78 			+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
     79 			+ ps.BUTTON_DELAY_ENABLE;
     80 		
     81 		return ps.confirmEx(
     82 			win,
     83 			Zotero.getString('general.permissionDenied'),
     84 			msg,
     85 			buttonFlags,
     86 			button1Text,
     87 			button2Text,
     88 			null,
     89 			null, {}
     90 		);
     91 	}
     92 };