filesyncstatus.xml (5613B)
1 <?xml version="1.0"?> 2 <!-- 3 ***** BEGIN LICENSE BLOCK ***** 4 5 Copyright © 2012 Center for History and New Media 6 George Mason University, Fairfax, Virginia, USA 7 http://zotero.org 8 9 This file is part of Zotero. 10 11 Zotero is free software: you can redistribute it and/or modify 12 it under the terms of the GNU Affero General Public License as published by 13 the Free Software Foundation, either version 3 of the License, or 14 (at your option) any later version. 15 16 Zotero is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU Affero General Public License for more details. 20 21 You should have received a copy of the GNU Affero General Public License 22 along with Zotero. If not, see <http://www.gnu.org/licenses/>. 23 24 ***** END LICENSE BLOCK ***** 25 --> 26 <?xml-stylesheet href="chrome://zotero/skin/overlay.css" type="text/css"?> 27 <!DOCTYPE bindings SYSTEM "chrome://zotero/locale/zotero.dtd"> 28 29 <bindings xmlns="http://www.mozilla.org/xbl"> 30 <binding id="file-sync-status"> 31 <implementation> 32 <property name="data" 33 onget="return this._data;" 34 onset="this._data = val; this.refresh();"> 35 </property> 36 37 <field name="_libraries">[]</field> 38 39 <method name="refresh"> 40 <body> 41 <![CDATA[ 42 var rows = this._id('rows'); 43 44 // Get libraries with active downloads or uploads 45 var newLibraries = []; 46 for (var libraryID in this._data) { 47 if ((this._data[libraryID].download 48 && !this._data[libraryID].download.finished) 49 || 50 (this._data[libraryID].upload 51 && !this._data[libraryID].upload.finished)) { 52 newLibraries.push(parseInt(libraryID)); 53 } 54 } 55 56 // If set of libraries is different, clear and recreate 57 var toRemove = Zotero.Utilities.arrayDiff(this._libraries, newLibraries); 58 var toAdd = Zotero.Utilities.arrayDiff(newLibraries, this._libraries); 59 if (toRemove.length || toAdd.length) { 60 while (rows.hasChildNodes()) { 61 rows.removeChild(rows.firstChild); 62 } 63 } 64 65 this._libraries = newLibraries; 66 67 // Update 68 if (rows.hasChildNodes()) { 69 for (var libraryID in this._data) { 70 var libraryStatus = this._data[libraryID]; 71 72 // Library is finished 73 if (newLibraries.indexOf(parseInt(libraryID)) == -1) { 74 continue; 75 } 76 77 var libraryNameRow = this._id('library-name-row-' + libraryID); 78 var downloadsRow = this._id('downloads-row-' + libraryID); 79 var uploadsRow = this._id('uploads-row-' + libraryID); 80 81 downloadsRow.lastChild.setAttribute('value', 82 libraryStatus.download 83 ? libraryStatus.download.statusString 84 : Zotero.getString('sync.storage.none')); 85 uploadsRow.lastChild.setAttribute('value', 86 libraryStatus.upload 87 ? libraryStatus.upload.statusString 88 : Zotero.getString('sync.storage.none')); 89 } 90 } 91 // Build from scratch 92 else { 93 // Get ordered list of library names 94 var libraryNames = []; 95 for (let libraryID of newLibraries) { 96 libraryNames.push({ 97 libraryID: libraryID, 98 name: Zotero.Libraries.getName(libraryID) 99 }); 100 } 101 var collation = Zotero.getLocaleCollation(); 102 let userLibraryID = Zotero.Libraries.userLibraryID; 103 libraryNames.sort(function (a, b) { 104 if (a.libraryID == userLibraryID) { 105 return -1; 106 } 107 if (b.libraryID == userLibraryID) { 108 return 1; 109 } 110 return collation.compareString(1, a.name, b.name); 111 }); 112 113 for (var i in libraryNames) { 114 var libraryID = libraryNames[i].libraryID; 115 var libraryStatus = this._data[libraryID]; 116 117 var label = document.createElement('label'); 118 label.id = 'library-name-row-' + libraryID; 119 label.setAttribute('value', libraryNames[i].name); 120 rows.appendChild(label); 121 122 var row = this._createRow('download', 123 libraryStatus.download 124 ? libraryStatus.download.statusString 125 : false); 126 row.id = 'downloads-row-' + libraryID; 127 rows.appendChild(row); 128 129 var row = this._createRow('upload', 130 libraryStatus.upload 131 ? libraryStatus.upload.statusString 132 : false); 133 row.id = 'uploads-row-' + libraryID; 134 rows.appendChild(row); 135 } 136 } 137 ]]> 138 </body> 139 </method> 140 141 <method name="_createRow"> 142 <parameter name="type"/> 143 <parameter name="value"/> 144 <body> 145 <![CDATA[ 146 var row = document.createElement('row'); 147 148 var label = document.createElement('label'); 149 label.setAttribute('value', Zotero.getString('sync.storage.' + type + 's')); 150 row.appendChild(label); 151 152 label = document.createElement('label'); 153 label.setAttribute('value', 154 value ? value : Zotero.getString('sync.storage.none')); 155 row.appendChild(label); 156 157 return row; 158 ]]> 159 </body> 160 </method> 161 162 <method name="_id"> 163 <parameter name="id"/> 164 <body> 165 <![CDATA[ 166 return document.getAnonymousNodes(this)[0].getElementsByAttribute('id', id)[0]; 167 ]]> 168 </body> 169 </method> 170 </implementation> 171 172 <content> 173 <grid xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1"> 174 <columns> 175 <column/> 176 <column/> 177 </columns> 178 <rows id="rows"/> 179 </grid> 180 </content> 181 182 </binding> 183 </bindings>