Update toolbar icons on group editability change
And trigger 'group' 'modify' notifier event for inherited Zotero.Library properties
This commit is contained in:
parent
a61c99843b
commit
234127e65a
chrome/content/zotero
test/tests
|
@ -458,6 +458,10 @@ Zotero.Library.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
||||||
let sql = "UPDATE libraries SET " + changedCols.map(function(v) v + "=?").join(", ")
|
let sql = "UPDATE libraries SET " + changedCols.map(function(v) v + "=?").join(", ")
|
||||||
+ " WHERE libraryID=?";
|
+ " WHERE libraryID=?";
|
||||||
yield Zotero.DB.queryAsync(sql, params);
|
yield Zotero.DB.queryAsync(sql, params);
|
||||||
|
|
||||||
|
// Since these are Zotero.Library properties, the 'modify' for the inheriting object may not
|
||||||
|
// get triggered, so call it here too
|
||||||
|
Zotero.Notifier.queue('modify', this.libraryType, this.libraryTypeID);
|
||||||
} else {
|
} else {
|
||||||
Zotero.debug("Library data did not change for " + this._objectType + " " + this.id, 5);
|
Zotero.debug("Library data did not change for " + this._objectType + " " + this.id, 5);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1128,6 +1128,9 @@ var ZoteroPane = new function()
|
||||||
|
|
||||||
if (this.itemsView && this.itemsView.collectionTreeRow.id == collectionTreeRow.id) {
|
if (this.itemsView && this.itemsView.collectionTreeRow.id == collectionTreeRow.id) {
|
||||||
Zotero.debug("Collection selection hasn't changed");
|
Zotero.debug("Collection selection hasn't changed");
|
||||||
|
|
||||||
|
// Update toolbar, in case editability has changed
|
||||||
|
this._updateToolbarIconsForRow(collectionTreeRow);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1168,42 +1171,7 @@ var ZoteroPane = new function()
|
||||||
collectionTreeRow.setSearch('');
|
collectionTreeRow.setSearch('');
|
||||||
collectionTreeRow.setTags(getTagSelection());
|
collectionTreeRow.setTags(getTagSelection());
|
||||||
|
|
||||||
// Enable or disable toolbar icons and menu options as necessary
|
this._updateToolbarIconsForRow(collectionTreeRow);
|
||||||
const disableIfNoEdit = [
|
|
||||||
"cmd_zotero_newCollection",
|
|
||||||
"cmd_zotero_newSavedSearch",
|
|
||||||
"zotero-tb-add",
|
|
||||||
"cmd_zotero_newItemFromCurrentPage",
|
|
||||||
"zotero-tb-lookup",
|
|
||||||
"cmd_zotero_newStandaloneNote",
|
|
||||||
"zotero-tb-note-add",
|
|
||||||
"zotero-tb-attachment-add"
|
|
||||||
];
|
|
||||||
for(var i=0; i<disableIfNoEdit.length; i++) {
|
|
||||||
let command = disableIfNoEdit[i];
|
|
||||||
var el = document.getElementById(command);
|
|
||||||
|
|
||||||
// If a trash is selected, new collection depends on the
|
|
||||||
// editability of the library
|
|
||||||
if (collectionTreeRow.isTrash() &&
|
|
||||||
command == 'cmd_zotero_newCollection') {
|
|
||||||
var overrideEditable = Zotero.Libraries.isEditable(collectionTreeRow.ref.libraryID);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var overrideEditable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't allow normal buttons in My Pubications, because things need to
|
|
||||||
// be dragged and go through the wizard
|
|
||||||
let forceDisable = collectionTreeRow.isPublications()
|
|
||||||
&& command != 'zotero-tb-note-add';
|
|
||||||
|
|
||||||
if ((collectionTreeRow.editable || overrideEditable) && !forceDisable) {
|
|
||||||
if(el.hasAttribute("disabled")) el.removeAttribute("disabled");
|
|
||||||
} else {
|
|
||||||
el.setAttribute("disabled", "true");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.itemsView = new Zotero.ItemTreeView(collectionTreeRow);
|
this.itemsView = new Zotero.ItemTreeView(collectionTreeRow);
|
||||||
this.itemsView.onError = function () {
|
this.itemsView.onError = function () {
|
||||||
|
@ -1239,6 +1207,46 @@ var ZoteroPane = new function()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable toolbar icons and menu options as necessary
|
||||||
|
*/
|
||||||
|
this._updateToolbarIconsForRow = function (collectionTreeRow) {
|
||||||
|
const disableIfNoEdit = [
|
||||||
|
"cmd_zotero_newCollection",
|
||||||
|
"cmd_zotero_newSavedSearch",
|
||||||
|
"zotero-tb-add",
|
||||||
|
"cmd_zotero_newItemFromCurrentPage",
|
||||||
|
"zotero-tb-lookup",
|
||||||
|
"cmd_zotero_newStandaloneNote",
|
||||||
|
"zotero-tb-note-add",
|
||||||
|
"zotero-tb-attachment-add"
|
||||||
|
];
|
||||||
|
for (let i = 0; i < disableIfNoEdit.length; i++) {
|
||||||
|
let command = disableIfNoEdit[i];
|
||||||
|
let el = document.getElementById(command);
|
||||||
|
|
||||||
|
// If a trash is selected, new collection depends on the
|
||||||
|
// editability of the library
|
||||||
|
if (collectionTreeRow.isTrash() && command == 'cmd_zotero_newCollection') {
|
||||||
|
var overrideEditable = Zotero.Libraries.isEditable(collectionTreeRow.ref.libraryID);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var overrideEditable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't allow normal buttons in My Publications, because things need to
|
||||||
|
// be dragged and go through the wizard
|
||||||
|
let forceDisable = collectionTreeRow.isPublications() && command != 'zotero-tb-note-add';
|
||||||
|
|
||||||
|
if ((collectionTreeRow.editable || overrideEditable) && !forceDisable) {
|
||||||
|
if(el.hasAttribute("disabled")) el.removeAttribute("disabled");
|
||||||
|
} else {
|
||||||
|
el.setAttribute("disabled", "true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
this.getCollectionTreeRow = function () {
|
this.getCollectionTreeRow = function () {
|
||||||
if (!this.collectionsView.selection.count) {
|
if (!this.collectionsView.selection.count) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -177,6 +177,25 @@ describe("Zotero.CollectionTreeView", function() {
|
||||||
assert.equal(selected, id);
|
assert.equal(selected, id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should update the editability of the current view", function* () {
|
||||||
|
var group = yield createGroup({
|
||||||
|
editable: false,
|
||||||
|
filesEditable: false
|
||||||
|
});
|
||||||
|
yield cv.selectLibrary(group.libraryID);
|
||||||
|
yield waitForItemsLoad(win);
|
||||||
|
|
||||||
|
assert.isFalse(cv.selectedTreeRow.editable);
|
||||||
|
var cmd = win.document.getElementById('cmd_zotero_newStandaloneNote');
|
||||||
|
assert.isTrue(cmd.getAttribute('disabled') == 'true');
|
||||||
|
|
||||||
|
group.editable = true;
|
||||||
|
yield group.saveTx();
|
||||||
|
|
||||||
|
assert.isTrue(cv.selectedTreeRow.editable);
|
||||||
|
assert.isFalse(cmd.getAttribute('disabled') == 'true');
|
||||||
|
});
|
||||||
|
|
||||||
it("should re-sort a modified collection", function* () {
|
it("should re-sort a modified collection", function* () {
|
||||||
var prefix = Zotero.Utilities.randomString() + " ";
|
var prefix = Zotero.Utilities.randomString() + " ";
|
||||||
var collectionA = yield createDataObject('collection', { name: prefix + "A" });
|
var collectionA = yield createDataObject('collection', { name: prefix + "A" });
|
||||||
|
|
|
@ -14,4 +14,19 @@ describe("Zotero.Groups", function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("#save()", function () {
|
||||||
|
it("should trigger notifier event for inherited properties", function* () {
|
||||||
|
var group = yield createGroup({
|
||||||
|
editable: false
|
||||||
|
});
|
||||||
|
group.editable = true;
|
||||||
|
|
||||||
|
var promise = waitForNotifierEvent('modify', 'group');
|
||||||
|
yield group.saveTx();
|
||||||
|
var data = yield promise;
|
||||||
|
assert.lengthOf(data.ids, 1);
|
||||||
|
assert.sameMembers(data.ids, [group.id]);
|
||||||
|
});
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user