zotero/chrome/chromeFiles/content/scholar/bindings/scholarsearch.xml
Dan Stillman f7aafec402 Addresses #63, Add ECL license info to source code
Stripped GPL text and removed ECL license for now -- leaving in copyright notice where it exists
2006-08-30 06:00:44 +00:00

390 lines
No EOL
11 KiB
XML

<?xml version="1.0"?>
<!--
Zotero
Copyright (C) 2006 Center for History and New Media, George Mason University, Fairfax, VA
http://chnm.gmu.edu/
-->
<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="search-box">
<implementation>
<field name="searchRef"/>
<property name="search" onget="return this.searchRef;">
<setter>
<![CDATA[
this.searchRef = val;
var conditionsBox = this.id('conditions');
while(conditionsBox.hasChildNodes())
conditionsBox.removeChild(conditionsBox.firstChild);
var conditions = this.search.getSearchConditions();
for(var id in conditions)
{
if(conditions[id]['condition'] == 'joinMode')
{
this.id('joinModeMenu').setAttribute('condition',id);
this.id('joinModeMenu').value = conditions[id]['operator'];
}
else
{
this.addCondition(conditions[id]);
}
}
]]>
</setter>
</property>
<method name="onAddClicked">
<body>
<![CDATA[
this.addCondition(this.search.getSearchCondition(this.search.addCondition("title","contains","")));
]]>
</body>
</method>
<method name="addCondition">
<parameter name="ref"/>
<body>
<![CDATA[
var conditionsBox = this.id('conditions');
var condition = document.createElement('searchcondition');
condition.setAttribute('flex','1');
conditionsBox.appendChild(condition);
condition.initWithParentAndCondition(this, ref);
conditionsBox.childNodes[0].id('remove').hidden = (conditionsBox.childNodes.length == 1);
]]>
</body>
</method>
<method name="removeCondition">
<parameter name="id"/>
<body>
<![CDATA[
var conditionsBox = this.id('conditions');
this.search.removeCondition(id);
for(var i = 0, len=conditionsBox.childNodes.length; i < len; i++)
if(conditionsBox.childNodes[i].conditionID == id)
{
conditionsBox.removeChild(conditionsBox.childNodes[i]);
i = len;
}
conditionsBox.childNodes[0].id('remove').hidden = (conditionsBox.childNodes.length == 1);
]]>
</body>
</method>
<method name="updateJoinMode">
<body>
<![CDATA[
var menu = this.id('joinModeMenu');
if(menu.hasAttribute('condition'))
this.search.updateCondition(menu.getAttribute('condition'),'joinMode',menu.value,null);
else
menu.setAttribute('condition', this.search.addCondition('joinMode',menu.value,null));
]]>
</body>
</method>
<method name="save">
<body>
<![CDATA[
var conditionsBox = this.id('conditions');
if(conditionsBox.hasChildNodes())
for(var i = 0, len=conditionsBox.childNodes.length; i < len; i++)
{
conditionsBox.childNodes[i].updateSearch();
}
return this.search.save();
]]>
</body>
</method>
<method name="id">
<parameter name="id"/>
<body>
<![CDATA[
return document.getAnonymousNodes(this)[0].getElementsByAttribute('id',id)[0];
]]>
</body>
</method>
</implementation>
<handlers>
</handlers>
<content>
<xul:groupbox xbl:inherits="flex">
<xul:caption align="center">
<xul:label value="Match"/>
<xul:menulist id="joinModeMenu" oncommand="this.parentNode.parentNode.parentNode.updateJoinMode();">
<xul:menupopup>
<xul:menuitem label="any" value="any"/>
<xul:menuitem label="all" value="all" selected="true"/>
</xul:menupopup>
</xul:menulist>
<xul:label value="of the following:"/>
</xul:caption>
<xul:vbox id="conditions"/>
</xul:groupbox>
</content>
</binding>
<binding id="search-condition">
<implementation>
<constructor>
<![CDATA[
var operators = new Array('is', 'isNot', 'contains', 'doesNotContain', 'isLessThan', 'isGreaterThan', 'isBefore', 'isAfter');
var operatorsList = this.id('operatorsmenu');
for(var i in operators)
{
operatorsList.appendItem(Scholar.getString('searchOperator.'+operators[i]),operators[i]);
}
var conditionsList = this.id('conditionsmenu');
var conditions = Scholar.SearchConditions.getStandardConditions();
for(var i=0, len=conditions.length; i<len; i++)
{
conditionsList.appendItem(conditions[i]['localized'], conditions[i]['name']);
}
conditionsList.selectedIndex = 0;
]]>
</constructor>
<field name="selectedCondition"/>
<field name="selectedOperator"/>
<method name="onConditionSelected">
<body>
<![CDATA[
// Skip if already selected
if (this.id('conditionsmenu').value==this.selectedCondition){
return;
}
var conditionsMenu = this.id('conditionsmenu');
var operatorsList = this.id('operatorsmenu');
this.selectedCondition = conditionsMenu.value;
this.selectedOperator = operatorsList.value;
var condition = Scholar.SearchConditions.get(conditionsMenu.value);
var operators = condition['operators'];
// Display appropriate operators for condition
var selectThis;
for(var i = 0, len = operatorsList.firstChild.childNodes.length; i < len; i++)
{
var val = operatorsList.firstChild.childNodes[i].getAttribute('value');
var hidden = !operators[val];
operatorsList.firstChild.childNodes[i].setAttribute('hidden', hidden);
if (!hidden && (selectThis == null || this.selectedOperator == val))
{
selectThis = i;
}
}
operatorsList.selectedIndex = selectThis;
// Generate drop-down menus for certain conditions
switch (conditionsMenu.value){
case 'collectionID':
var merged = [];
var cols = Scholar.getCollections(false, true);
for (var i in cols)
{
merged.push([cols[i].getName(), 'C' + cols[i].getID()]);
}
var searches = Scholar.Searches.getAll();
for (var i in searches)
{
if (searches[i]['id'] != this.parent.search.getID())
{
merged.push([searches[i]['name'], 'S' + searches[i]['id']]);
}
}
this.createValueMenu(merged);
break;
case 'itemTypeID':
var types = Scholar.ItemTypes.getTypes();
for (var i in types)
{
types[i][0] = Scholar.getString('itemTypes.' + types[i]['name']);
types[i][1] = types[i]['id'];
delete types[i]['name'];
delete types[i]['id'];
}
this.createValueMenu(types);
break;
default:
// If switching between menu and textbox, clear value
if (this.id('valuefield').hidden){
this.value = '';
this.id('valuefield').value = '';
}
else {
this.id('valuefield').value = this.value;
}
this.id('valuefield').hidden = false;
this.id('valuemenu').hidden = true;
break;
}
]]>
</body>
</method>
<method name="createValueMenu">
<parameter name="values"/>
<body>
<![CDATA[
while (this.id('valuemenu').hasChildNodes()){
this.id('valuemenu').removeChild(this.id('valuemenu').firstChild);
}
if (values.length){
for (var i in values){
this.id('valuemenu').appendItem(values[i][0], values[i][1]);
}
this.id('valuemenu').selectedIndex = 0;
}
if (this.value)
{
this.id('valuemenu').value = this.value;
}
this.id('valuefield').hidden = true;
this.id('valuemenu').hidden = false;
]]>
</body>
</method>
<field name="dontupdate"/>
<field name="parent"/>
<field name="conditionID"/>
<field name="value"/>
<method name="initWithParentAndCondition">
<parameter name="parent"/>
<parameter name="condition"/>
<body>
<![CDATA[
this.parent = parent;
this.conditionID = condition['id'];
if(this.parent.search)
{
this.dontupdate = true; //so that the search doesn't get updated while we are creating controls.
var prefix = '';
// Handle collectionID/savedSearchID
switch (condition['condition'])
{
case 'savedSearchID':
this.id('conditionsmenu').value = 'collectionID';
prefix = 'S';
break;
case 'collectionID':
prefix = 'C';
// fall through
default:
this.id('conditionsmenu').value = condition['condition'];
}
this.id('operatorsmenu').value = condition['operator'];
this.value = prefix + condition['value'];
this.dontupdate = false;
}
this.onConditionSelected();
]]>
</body>
</method>
<method name="updateSearch">
<body>
<![CDATA[
if(this.parent && this.parent.search && !this.dontupdate)
{
var condition = this.id('conditionsmenu').value;
var operator = this.id('operatorsmenu').value;
// Regular text field
if (!this.id('valuefield').hidden)
{
var value = this.id('valuefield').value;
}
// Handle special C1234 and S5678 form for
// collections and searches
else if (this.id('conditionsmenu').value=='collectionID')
{
var letter = this.id('valuemenu').value.substr(0,1);
if (letter=='C')
{
condition = 'collectionID';
}
else if (letter=='S')
{
condition = 'savedSearchID';
}
var value = this.id('valuemenu').value.substr(1);
}
// Regular drop-down menu
else
{
var value = this.id('valuemenu').value;
}
this.parent.search.updateCondition(this.conditionID, condition, operator, value);
}
]]>
</body>
</method>
<method name="onRemoveClicked">
<body>
<![CDATA[
if(this.parent)
this.parent.removeCondition(this.conditionID);
]]>
</body>
</method>
<method name="onAddClicked">
<body>
<![CDATA[
if(this.parent)
this.parent.onAddClicked();
]]>
</body>
</method>
<method name="id">
<parameter name="id"/>
<body>
<![CDATA[
return document.getAnonymousNodes(this)[0].getElementsByAttribute('id',id)[0];
]]>
</body>
</method>
</implementation>
<content>
<xul:hbox xbl:inherits="flex">
<xul:menulist id="conditionsmenu" oncommand="this.parentNode.parentNode.onConditionSelected();">
<xul:menupopup/>
</xul:menulist>
<xul:menulist id="operatorsmenu">
<xul:menupopup/>
</xul:menulist>
<xul:textbox id="valuefield" flex="1"/>
<xul:menulist id="valuemenu" flex="1" hidden="true">
<xul:menupopup/>
</xul:menulist>
<xul:toolbarbutton id="remove" class="clicky" label="-" oncommand="this.parentNode.parentNode.onRemoveClicked();"/>
<xul:toolbarbutton id="add" class="clicky" label="+" oncommand="this.parentNode.parentNode.onAddClicked();"/>
</xul:hbox>
</content>
</binding>
</bindings>