zotero/chrome/content/zotero/bindings/relatedbox.xml
Dan Stillman 33de40ad95 Adds sync support for related items
Might fix (or break) other stuff, but who remembers?
2008-06-25 00:26:55 +00:00

253 lines
No EOL
6.8 KiB
XML

<?xml version="1.0"?>
<!--
***** BEGIN LICENSE BLOCK *****
Copyright (c) 2006 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://chnm.gmu.edu
Licensed under the Educational Community License, Version 1.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.opensource.org/licenses/ecl1.php
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
***** END LICENSE BLOCK *****
-->
<!DOCTYPE bindings SYSTEM "chrome://zotero/locale/zotero.dtd">
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="seealso-box">
<implementation>
<field name="itemRef"/>
<property name="item" onget="return this.itemRef;">
<setter>
<![CDATA[
this.itemRef = val;
this.reload();
]]>
</setter>
</property>
<property name="summary">
<getter>
<![CDATA[
var r = "";
if (this.item) {
var related = this.item.relatedItemsBidirectional;
if (related) {
related = Zotero.Items.get(related);
for(var i = 0; i < related.length; i++) {
r = r + related[i].getField('title') + ", ";
}
r = r.substr(0,r.length-2);
}
}
return r;
]]>
</getter>
</property>
<method name="reload">
<body>
<![CDATA[
var rows = this.id('seeAlsoRows');
while(rows.hasChildNodes())
rows.removeChild(rows.firstChild);
if (this.item) {
var related = this.item.relatedItemsBidirectional;
if (related) {
related = Zotero.Items.get(related);
for (var i = 0; i < related.length; i++) {
var icon= document.createElement("image");
var type = Zotero.ItemTypes.getName(related[i].itemTypeID);
if (type=='attachment')
{
switch (related[i].getAttachmentLinkMode())
{
case Zotero.Attachments.LINK_MODE_LINKED_URL:
type += '-web-link';
break;
case Zotero.Attachments.LINK_MODE_IMPORTED_URL:
type += '-snapshot';
break;
case Zotero.Attachments.LINK_MODE_LINKED_FILE:
type += '-link';
break;
case Zotero.Attachments.LINK_MODE_IMPORTED_FILE:
type += '-file';
break;
}
}
icon.setAttribute('src','chrome://zotero/skin/treeitem-' + type + '.png');
var label = document.createElement("label");
label.setAttribute('value', related[i].getField('title'));
label.setAttribute('crop','end');
label.setAttribute('flex','1');
var box = document.createElement('box');
box.setAttribute('onclick',
"document.getBindingParent(this).showItem('" + related[i].id + "')");
box.setAttribute('class','zotero-clicky');
box.setAttribute('flex','1');
box.appendChild(icon);
box.appendChild(label);
var remove = document.createElement("label");
remove.setAttribute('value','-');
remove.setAttribute('onclick',
"document.getBindingParent(this).remove('" + related[i].id + "');");
remove.setAttribute('class','zotero-clicky');
var row = document.createElement("row");
row.appendChild(box);
row.appendChild(remove);
row.setAttribute('id', 'seealso-' + related[i].id);
rows.appendChild(row);
}
this.updateCount(related.length);
}
else
{
this.updateCount();
}
}
]]>
</body>
</method>
<method name="add">
<body>
<![CDATA[
var io = {dataIn: null, dataOut: null};
window.openDialog('chrome://zotero/content/selectItemsDialog.xul', '',
'chrome,dialog=no,modal,centerscreen,resizable=yes', io);
if(io.dataOut && this.item)
{
for(var i = 0; i < io.dataOut.length; i++)
{
this.item.addRelatedItem(io.dataOut[i]);
}
this.item.save();
}
]]>
</body>
</method>
<method name="remove">
<parameter name="id"/>
<body>
<![CDATA[
if(id) {
// TODO: set attribute on reload to determine
// which of these is necessary
this.item.removeRelatedItem(id);
this.item.save();
var item = Zotero.Items.get(id);
item.removeRelatedItem(this.item.id);
item.save();
}
]]>
</body>
</method>
<method name="showItem">
<parameter name="id"/>
<body>
<![CDATA[
if(id)
{
var p;
if(window.ZoteroPane)
{
p = window.ZoteroPane;
}
else
{
var win;
if(window.opener && window.opener.ZoteroPane)
{
win = window.opener;
}
else
{
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
win = wm.getMostRecentWindow('navigator:browser');
if(!win)
return;
}
p = win.ZoteroPane;
}
p.selectItem(id);
}
]]>
</body>
</method>
<method name="updateCount">
<parameter name="count"/>
<body>
<![CDATA[
if (count == null) {
var count = this.item.relatedItemsBidirectional.length;
}
var str = 'pane.item.related.count.';
switch (count){
case 0:
str += 'zero';
break;
case 1:
str += 'singular';
break;
default:
str += 'plural';
break;
}
this.id('seeAlsoNum').value = Zotero.getString(str, [count]);
]]>
</body>
</method>
<method name="id">
<parameter name="id"/>
<body>
<![CDATA[
return document.getAnonymousNodes(this)[0].getElementsByAttribute('id',id)[0];
]]>
</body>
</method>
</implementation>
<content>
<xul:vbox xbl:inherits="flex">
<xul:hbox align="center">
<xul:label id="seeAlsoNum"/>
<xul:button label="&zotero.item.add;" oncommand="this.parentNode.parentNode.parentNode.add();"/>
</xul:hbox>
<xul:grid flex="1">
<xul:columns>
<xul:column flex="1"/>
<xul:column/>
</xul:columns>
<xul:rows id="seeAlsoRows"/>
</xul:grid>
</xul:vbox>
</content>
</binding>
</bindings>