commit 93b56944205222e8fc5a7aad0b2295dfcd7f9107
parent 6c536fc784dbf0aedc4b491276d8605dd945bf50
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 19 Jul 2015 17:13:13 -0400
Make editable/filesEditable required in Zotero.Libraries.add()
Diffstat:
2 files changed, 14 insertions(+), 24 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/group.js b/chrome/content/zotero/xpcom/data/group.js
@@ -221,11 +221,7 @@ Zotero.Group.prototype.save = Zotero.Promise.coroutine(function* () {
if (isNew) {
let { id: libraryID } = yield Zotero.Libraries.add(
- 'group',
- {
- editable: this.editable,
- filesEditable: this.filesEditable
- }
+ 'group', this.editable, this.filesEditable
);
sqlColumns.push('libraryID');
sqlValues.push(libraryID);
diff --git a/chrome/content/zotero/xpcom/data/libraries.js b/chrome/content/zotero/xpcom/data/libraries.js
@@ -80,15 +80,12 @@ Zotero.Libraries = new function () {
/**
* @param {String} type - Library type
- * @param {Object} [options] - Library properties to set
- * @param {Boolean} [options.editable]
- * @param {Boolean} [options.filesEditable]
+ * @param {Boolean} editable
+ * @param {Boolean} filesEditable
*/
- this.add = Zotero.Promise.coroutine(function* (type, options) {
+ this.add = Zotero.Promise.coroutine(function* (type, editable, filesEditable) {
Zotero.DB.requireTransaction();
- options = options || {};
-
switch (type) {
case 'group':
break;
@@ -99,17 +96,14 @@ Zotero.Libraries = new function () {
var libraryID = yield Zotero.ID.get('libraries');
- var sql = "INSERT INTO libraries (libraryID, libraryType";
- var params = [libraryID, type];
- if (options.editable) {
- sql += ", editable";
- params.push(options.editable ? 1 : 0);
- if (options.filesEditable) {
- sql += ", filesEditable";
- params.push(options.filesEditable ? 1 : 0);
- }
- }
- sql += ") VALUES (" + params.map(p => "?").join(", ") + ")";
+ var sql = "INSERT INTO libraries (libraryID, libraryType, editable, filesEditable) "
+ + "VALUES (?, ?, ?, ?)";
+ var params = [
+ libraryID,
+ type,
+ editable ? 1 : 0,
+ filesEditable ? 1 : 0
+ ];
yield Zotero.DB.queryAsync(sql, params);
// Re-fetch from DB to get auto-filled defaults
@@ -236,8 +230,8 @@ Zotero.Libraries = new function () {
return {
id: row.libraryID,
type: row.libraryType,
- editable: row.editable,
- filesEditable: row.filesEditable,
+ editable: !!row.editable,
+ filesEditable: !!row.filesEditable,
version: row.version,
lastSyncTime: row.lastsync != 0 ? new Date(row.lastsync * 1000) : false
};