Show intro text for My Publications in middle pane when no items

ZoteroPane.setItemsPaneMessage() and setItemPaneMessage() can now
optionally take a DOM node instead of a string.

Closes #705
This commit is contained in:
Dan Stillman 2016-03-24 08:55:32 -04:00
parent db33163a99
commit fc6c113f25
8 changed files with 83 additions and 20 deletions

View file

@ -246,7 +246,7 @@
background-color: #ffffff;
}
#zotero-item-pane-message {
#zotero-item-pane-message-box description {
color: #7f7f7f;
}

View file

@ -47,7 +47,7 @@
<deck id="zotero-item-pane-content" selectedIndex="0" flex="1">
<!-- Center label (for zero or multiple item selection) -->
<groupbox id="zotero-item-pane-groupbox" pack="center" align="center">
<label id="zotero-item-pane-message"/>
<vbox id="zotero-item-pane-message-box"/>
</groupbox>
<!-- Regular item -->

View file

@ -234,10 +234,38 @@ Zotero.ItemTreeView.prototype.setTree = Zotero.Promise.coroutine(function* (tree
this.expandMatchParents();
if (this._ownerDocument.defaultView.ZoteroPane_Local) {
this._ownerDocument.defaultView.ZoteroPane_Local.clearItemsPaneMessage();
// For My Publications, show intro text in middle pane if no items
if (this.collectionTreeRow && this.collectionTreeRow.isPublications() && !this.rowCount) {
let doc = this._ownerDocument;
let ns = 'http://www.w3.org/1999/xhtml'
let div = doc.createElementNS(ns, 'div');
let p = doc.createElementNS(ns, 'p');
p.textContent = Zotero.getString('publications.intro.text1', ZOTERO_CONFIG.DOMAIN_NAME);
div.appendChild(p);
p = doc.createElementNS(ns, 'p');
p.textContent = Zotero.getString('publications.intro.text2');
div.appendChild(p);
p = doc.createElementNS(ns, 'p');
let html = Zotero.getString('publications.intro.text3');
// Convert <b> tags to placeholders
html = html.replace('<b>', ':b:').replace('</b>', ':/b:');
// Encode any other special chars, which shouldn't exist
html = Zotero.Utilities.htmlSpecialChars(html);
// Restore bold text
html = html.replace(':b:', '<strong>').replace(':/b:', '</strong>');
p.innerHTML = html; // AMO note: markup from hard-coded strings and filtered above
div.appendChild(p);
content = div;
doc.defaultView.ZoteroPane_Local.setItemsPaneMessage(content);
}
else {
this._ownerDocument.defaultView.ZoteroPane_Local.clearItemsPaneMessage();
}
}
// Select a queued item from selectItem()
if (this.collectionTreeRow && this.collectionTreeRow.itemToSelect) {
var item = this.collectionTreeRow.itemToSelect;
yield this.selectItem(item['id'], item['expand']);

View file

@ -3047,21 +3047,24 @@ var ZoteroPane = new function()
}
function setItemsPaneMessage(msg, lock) {
function setItemsPaneMessage(content, lock) {
var elem = document.getElementById('zotero-items-pane-message-box');
if (elem.getAttribute('locked') == 'true') {
return;
}
while (elem.hasChildNodes()) {
elem.removeChild(elem.firstChild);
elem.textContent = '';
if (typeof content == 'string') {
let contentParts = content.split("\n\n");
for (let part of contentParts) {
var desc = document.createElement('description');
desc.appendChild(document.createTextNode(part));
elem.appendChild(desc);
}
}
var msgParts = msg.split("\n\n");
for (var i=0; i<msgParts.length; i++) {
var desc = document.createElement('description');
desc.appendChild(document.createTextNode(msgParts[i]));
elem.appendChild(desc);
else {
elem.appendChild(content);
}
// Make message permanent
@ -3084,11 +3087,22 @@ var ZoteroPane = new function()
}
this.setItemPaneMessage = function (msg) {
this.setItemPaneMessage = function (content) {
document.getElementById('zotero-item-pane-content').selectedIndex = 0;
var label = document.getElementById('zotero-item-pane-message');
label.value = msg;
var elem = document.getElementById('zotero-item-pane-message-box');
elem.textContent = '';
if (typeof content == 'string') {
let contentParts = content.split("\n\n");
for (let part of contentParts) {
let desc = document.createElement('description');
desc.appendChild(document.createTextNode(part));
elem.appendChild(desc);
}
}
else {
elem.appendChild(content);
}
}