www

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

commit 234127e65a2eb5f139835e0b44cce12f1baa90e7
parent a61c99843bd554cd279ae3434ba996a1e3b5d408
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri, 25 Mar 2016 16:48:33 -0400

Update toolbar icons on group editability change

And trigger 'group' 'modify' notifier event for inherited Zotero.Library
properties

Diffstat:
Mchrome/content/zotero/xpcom/data/library.js | 4++++
Mchrome/content/zotero/zoteroPane.js | 80+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Mtest/tests/collectionTreeViewTest.js | 19+++++++++++++++++++
Mtest/tests/groupsTest.js | 15+++++++++++++++
4 files changed, 82 insertions(+), 36 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/library.js b/chrome/content/zotero/xpcom/data/library.js @@ -458,6 +458,10 @@ Zotero.Library.prototype._saveData = Zotero.Promise.coroutine(function* (env) { let sql = "UPDATE libraries SET " + changedCols.map(function(v) v + "=?").join(", ") + " WHERE libraryID=?"; 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 { Zotero.debug("Library data did not change for " + this._objectType + " " + this.id, 5); } diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js @@ -1128,6 +1128,9 @@ var ZoteroPane = new function() if (this.itemsView && this.itemsView.collectionTreeRow.id == collectionTreeRow.id) { Zotero.debug("Collection selection hasn't changed"); + + // Update toolbar, in case editability has changed + this._updateToolbarIconsForRow(collectionTreeRow); return; } @@ -1168,42 +1171,7 @@ var ZoteroPane = new function() collectionTreeRow.setSearch(''); collectionTreeRow.setTags(getTagSelection()); - // Enable or disable toolbar icons and menu options as necessary - 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._updateToolbarIconsForRow(collectionTreeRow); this.itemsView = new Zotero.ItemTreeView(collectionTreeRow); 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 () { if (!this.collectionsView.selection.count) { return false; diff --git a/test/tests/collectionTreeViewTest.js b/test/tests/collectionTreeViewTest.js @@ -177,6 +177,25 @@ describe("Zotero.CollectionTreeView", function() { 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* () { var prefix = Zotero.Utilities.randomString() + " "; var collectionA = yield createDataObject('collection', { name: prefix + "A" }); diff --git a/test/tests/groupsTest.js b/test/tests/groupsTest.js @@ -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]); + }); + }); })