commit 8cfca53b48a5cf36a22e05fcf67647f77536337d
parent ac12d5891a0eff67c1bb8da68814c60c94ca1421
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 19 May 2015 17:05:58 -0400
Register itembox and noteeditor with notifier and refresh on update
Since selected items are no longer reselected, the boxes now need to
refresh themselves.
Diffstat:
3 files changed, 118 insertions(+), 0 deletions(-)
diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml
@@ -265,6 +265,36 @@
onget="return '(' + Zotero.getString('pane.item.defaultLastName') + ')'"/>
<property name="_defaultFullName"
onget="return '(' + Zotero.getString('pane.item.defaultFullName') + ')'"/>
+
+ <constructor>
+ <![CDATA[
+ this._notifierID = Zotero.Notifier.registerObserver(this, ['item'], 'itembox');
+ ]]>
+ </constructor>
+
+ <destructor>
+ <![CDATA[
+ Zotero.Notifier.unregisterObserver(this._notifierID);
+ ]]>
+ </destructor>
+
+ <method name="notify">
+ <parameter name="event"/>
+ <parameter name="type"/>
+ <parameter name="ids"/>
+ <body><![CDATA[
+ if (event != 'modify' || !this.item || !this.item.id) return;
+ for (let i = 0; i < ids.length; i++) {
+ let id = ids[i];
+ if (id != this.item.id) {
+ continue;
+ }
+ this.refresh();
+ break;
+ }
+ ]]></body>
+ </method>
+
<method name="refresh">
<body>
<![CDATA[
diff --git a/chrome/content/zotero/bindings/noteeditor.xml b/chrome/content/zotero/bindings/noteeditor.xml
@@ -156,6 +156,35 @@
<property name="noteField" onget="return this._id('noteField')" readonly="true"/>
<property name="value" onget="return this._id('noteField').value;" onset="this._id('noteField').value = val;"/>
+ <constructor>
+ <![CDATA[
+ this._notifierID = Zotero.Notifier.registerObserver(this, ['item'], 'noteeditor');
+ ]]>
+ </constructor>
+
+ <destructor>
+ <![CDATA[
+ Zotero.Notifier.unregisterObserver(this._notifierID);
+ ]]>
+ </destructor>
+
+ <method name="notify">
+ <parameter name="event"/>
+ <parameter name="type"/>
+ <parameter name="ids"/>
+ <body><![CDATA[
+ if (event != 'modify' || !this.item || !this.item.id) return;
+ for (let i = 0; i < ids.length; i++) {
+ let id = ids[i];
+ if (id != this.item.id) {
+ continue;
+ }
+ this.refresh();
+ break;
+ }
+ ]]></body>
+ </method>
+
<method name="refresh">
<body><![CDATA[
return Zotero.spawn(function* () {
diff --git a/test/tests/itemPaneTest.js b/test/tests/itemPaneTest.js
@@ -0,0 +1,59 @@
+describe("Item pane", function () {
+ var win, doc, itemsView;
+
+ before(function* () {
+ win = yield loadZoteroPane();
+ doc = win.document;
+ itemsView = win.ZoteroPane.itemsView;
+ });
+ after(function () {
+ win.close();
+ });
+
+ describe("Info pane", function () {
+ it("should refresh on item update", function* () {
+ var item = new Zotero.Item('book');
+ var id = yield item.saveTx();
+ item = yield Zotero.Items.getAsync(id);
+
+ var itemBox = doc.getElementById('zotero-editpane-item-box');
+ var label = doc.getAnonymousNodes(itemBox)[0].getElementsByAttribute('fieldname', 'title')[1];
+ assert.equal(label.textContent, '');
+
+ item.setField('title', 'Test');
+ yield item.saveTx();
+
+ var label = doc.getAnonymousNodes(itemBox)[0].getElementsByAttribute('fieldname', 'title')[1];
+ assert.equal(label.textContent, 'Test');
+
+ yield Zotero.Items.erase(id);
+ })
+ })
+
+ describe("Note pane", function () {
+ it("should refresh on note update", function* () {
+ var item = new Zotero.Item('note');
+ var id = yield item.saveTx();
+ item = yield Zotero.Items.getAsync(id);
+
+
+ // Wait for the editor
+ var noteBox = doc.getElementById('zotero-note-editor');
+ var val = false;
+ do {
+ try {
+ val = noteBox.noteField.value;
+ }
+ catch (e) {}
+ yield Zotero.Promise.delay(1);
+ }
+ while (val === false)
+ assert.equal(noteBox.noteField.value, '');
+
+ item.setNote('<p>Test</p>');
+ yield item.saveTx();
+
+ assert.equal(noteBox.noteField.value, '<p>Test</p>');
+ })
+ })
+})