Add new Notifier event types, 'collection-item' and 'item-tag', which send id pairs, e.g. adding tagID 2 to item id 1 would trigger ('add', 'item-tag', '1-2')
Similarly, removing items from collections now uses collection-item remove instead of item remove This was done to prevent some problems that resulted from the tag selector using item modify events to update itself (which caused the items pane to refresh itself before itemTreeView.notify() got a chance to do the things it likes to do). This should also help out utility writers.
This commit is contained in:
parent
7aa5662bae
commit
0ec1ed58ef
|
@ -265,20 +265,14 @@
|
||||||
<parameter name="ids"/>
|
<parameter name="ids"/>
|
||||||
<body>
|
<body>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
if (type == 'item') {
|
// This could be more optimized to insert new/changed tags at the appropriate
|
||||||
|
// spot if we cared, but we probably don't
|
||||||
|
if (type == 'collection-item' || type == 'item-tag' || type == 'tag') {
|
||||||
var t = this.id('tags-search').inputField;
|
var t = this.id('tags-search').inputField;
|
||||||
this.setFilterTags(Zotero.Tags.search(t.value), true);
|
this.setFilterTags(Zotero.Tags.search(t.value), true);
|
||||||
this._dirty = true;
|
this._dirty = true;
|
||||||
this.doCommand();
|
this.doCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: optimize for tag notifications?
|
|
||||||
// Would need separate additional Notifier events
|
|
||||||
// to distinguish between item adds and item collection adds
|
|
||||||
// and for tag changes on items separate from item-modify,
|
|
||||||
// plus code to insert new/changed tags at the appropriate spot
|
|
||||||
|
|
||||||
return;
|
|
||||||
]]>
|
]]>
|
||||||
</body>
|
</body>
|
||||||
</method>
|
</method>
|
||||||
|
|
|
@ -1636,6 +1636,7 @@ Zotero.Item.prototype.addTagByID = function(tagID) {
|
||||||
|
|
||||||
Zotero.DB.commitTransaction();
|
Zotero.DB.commitTransaction();
|
||||||
Zotero.Notifier.trigger('modify', 'item', this.getID());
|
Zotero.Notifier.trigger('modify', 'item', this.getID());
|
||||||
|
Zotero.Notifier.trigger('add', 'item-tag', this.getID() + '-' + tagID);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1679,6 +1680,8 @@ Zotero.Item.prototype.replaceTag = function(oldTagID, newTag){
|
||||||
var id = this.addTag(newTag);
|
var id = this.addTag(newTag);
|
||||||
Zotero.DB.commitTransaction();
|
Zotero.DB.commitTransaction();
|
||||||
Zotero.Notifier.trigger('modify', 'item', this.getID());
|
Zotero.Notifier.trigger('modify', 'item', this.getID());
|
||||||
|
Zotero.Notifier.trigger('remove', 'item-tag', this.getID() + '-' + oldTagID);
|
||||||
|
Zotero.Notifier.trigger('add', 'item-tag', this.getID() + '-' + id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1693,6 +1696,7 @@ Zotero.Item.prototype.removeTag = function(tagID){
|
||||||
Zotero.Tags.purge();
|
Zotero.Tags.purge();
|
||||||
Zotero.DB.commitTransaction();
|
Zotero.DB.commitTransaction();
|
||||||
Zotero.Notifier.trigger('modify', 'item', this.getID());
|
Zotero.Notifier.trigger('modify', 'item', this.getID());
|
||||||
|
Zotero.Notifier.trigger('remove', 'item-tag', this.getID() + '-' + tagID);
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Item.prototype.removeAllTags = function(){
|
Zotero.Item.prototype.removeAllTags = function(){
|
||||||
|
@ -1701,10 +1705,18 @@ Zotero.Item.prototype.removeAllTags = function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.DB.beginTransaction();
|
Zotero.DB.beginTransaction();
|
||||||
|
var tagIDs = this.getTagIDs();
|
||||||
Zotero.DB.query("DELETE FROM itemTags WHERE itemID=?", this.getID());
|
Zotero.DB.query("DELETE FROM itemTags WHERE itemID=?", this.getID());
|
||||||
Zotero.Tags.purge();
|
Zotero.Tags.purge();
|
||||||
Zotero.DB.commitTransaction();
|
Zotero.DB.commitTransaction();
|
||||||
Zotero.Notifier.trigger('modify', 'item', this.getID());
|
Zotero.Notifier.trigger('modify', 'item', this.getID());
|
||||||
|
|
||||||
|
if (tagIDs) {
|
||||||
|
for (var i in tagIDs) {
|
||||||
|
tagIDs[i] = this.getID() + '-' + tagIDs[i];
|
||||||
|
}
|
||||||
|
Zotero.Notifier.trigger('remove', 'item-tag', tagIDs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2643,7 +2655,7 @@ Zotero.Collection.prototype.addItem = function(itemID){
|
||||||
Zotero.Notifier.trigger('modify', 'collection', this.getID());
|
Zotero.Notifier.trigger('modify', 'collection', this.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Notifier.trigger('add', 'item', itemID);
|
Zotero.Notifier.trigger('add', 'collection-item', this.getID() + '-' + itemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2684,7 +2696,7 @@ Zotero.Collection.prototype.removeItem = function(itemID){
|
||||||
Zotero.Notifier.trigger('modify', 'collection', this.getID());
|
Zotero.Notifier.trigger('modify', 'collection', this.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Notifier.trigger('remove', 'item', itemID);
|
Zotero.Notifier.trigger('remove', 'collection-item', this.getID() + '-' + itemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3258,6 +3270,11 @@ Zotero.Tags = new function(){
|
||||||
Zotero.DB.commitTransaction();
|
Zotero.DB.commitTransaction();
|
||||||
|
|
||||||
Zotero.Notifier.trigger('modify', 'item', itemIDs);
|
Zotero.Notifier.trigger('modify', 'item', itemIDs);
|
||||||
|
var itemTags = [];
|
||||||
|
for (var i in itemIDs) {
|
||||||
|
itemTags.push(itemIDs[i] + '-' + tagID);
|
||||||
|
}
|
||||||
|
Zotero.Notifier.trigger('modify', 'item-tag', itemTags);
|
||||||
Zotero.Notifier.trigger('modify', 'tag', tagID);
|
Zotero.Notifier.trigger('modify', 'tag', tagID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3266,15 +3283,21 @@ Zotero.Tags = new function(){
|
||||||
Zotero.DB.beginTransaction();
|
Zotero.DB.beginTransaction();
|
||||||
|
|
||||||
var sql = "SELECT itemID FROM itemTags WHERE tagID=?";
|
var sql = "SELECT itemID FROM itemTags WHERE tagID=?";
|
||||||
var items = Zotero.DB.columnQuery(sql, tagID);
|
var itemIDs = Zotero.DB.columnQuery(sql, tagID);
|
||||||
|
|
||||||
if (!items) {
|
if (!itemIDs) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sql = "DELETE FROM itemTags WHERE tagID=?";
|
var sql = "DELETE FROM itemTags WHERE tagID=?";
|
||||||
Zotero.DB.query(sql, tagID);
|
Zotero.DB.query(sql, tagID);
|
||||||
Zotero.Notifier.trigger('modify', 'item', items)
|
|
||||||
|
Zotero.Notifier.trigger('modify', 'item', itemIDs)
|
||||||
|
var itemTags = [];
|
||||||
|
for (var i in itemIDs) {
|
||||||
|
itemTags.push(itemIDs[i] + '-' + tagID);
|
||||||
|
}
|
||||||
|
Zotero.Notifier.trigger('remove', 'item-tag', itemTags);
|
||||||
|
|
||||||
this.purge();
|
this.purge();
|
||||||
Zotero.DB.commitTransaction();
|
Zotero.DB.commitTransaction();
|
||||||
|
|
|
@ -110,7 +110,7 @@ Zotero.ItemTreeView.prototype.refresh = function()
|
||||||
*/
|
*/
|
||||||
Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
|
Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
{
|
{
|
||||||
if (type != 'item'){
|
if (type != 'item' && type != 'collection-item'){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,12 +136,13 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
var rows = new Array();
|
var rows = new Array();
|
||||||
for(var i=0, len=ids.length; i<len; i++)
|
for(var i=0, len=ids.length; i<len; i++)
|
||||||
{
|
{
|
||||||
if(action == 'delete' || !this._itemGroup.ref.hasItem(ids[i]))
|
var removeID = (action == 'remove') ? ids[i].split('-')[1] : ids[i];
|
||||||
{
|
|
||||||
|
if (action == 'delete' || !this._itemGroup.ref.hasItem(removeID)) {
|
||||||
// Row might already be gone (e.g. if this is a child and
|
// Row might already be gone (e.g. if this is a child and
|
||||||
// 'modify' was sent to parent)
|
// 'modify' was sent to parent)
|
||||||
if (this._itemRowMap[ids[i]] != undefined) {
|
if (this._itemRowMap[removeID] != undefined) {
|
||||||
rows.push(this._itemRowMap[ids[i]]);
|
rows.push(this._itemRowMap[removeID]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +240,6 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
else if (quicksearch.value == '')
|
else if (quicksearch.value == '')
|
||||||
{
|
{
|
||||||
var items = Zotero.Items.get(ids);
|
var items = Zotero.Items.get(ids);
|
||||||
|
|
||||||
for (var i in items)
|
for (var i in items)
|
||||||
{
|
{
|
||||||
// if the item belongs in this collection
|
// if the item belongs in this collection
|
||||||
|
@ -284,9 +284,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids)
|
||||||
if(action == 'add' && ids.length===1 && activeWindow)
|
if(action == 'add' && ids.length===1 && activeWindow)
|
||||||
{
|
{
|
||||||
// Reset to Info tab
|
// Reset to Info tab
|
||||||
this._treebox.treeBody.ownerDocument.
|
this._treebox.treeBody.ownerDocument.getElementById('zotero-view-tabs').selectedIndex = 0;
|
||||||
getElementById('zotero-view-tabs').selectedIndex = 0;
|
|
||||||
|
|
||||||
this.selectItem(ids[0]);
|
this.selectItem(ids[0]);
|
||||||
}
|
}
|
||||||
// If single item is selected and was modified
|
// If single item is selected and was modified
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
Zotero.Notifier = new function(){
|
Zotero.Notifier = new function(){
|
||||||
var _observers = new Zotero.Hash();
|
var _observers = new Zotero.Hash();
|
||||||
var _disabled = false;
|
var _disabled = false;
|
||||||
var _types = ['collection', 'search', 'item', 'tag'];
|
var _types = ['collection', 'search', 'item', 'collection-item', 'item-tag', 'tag'];
|
||||||
var _inTransaction;
|
var _inTransaction;
|
||||||
var _locked = false;
|
var _locked = false;
|
||||||
var _queue = [];
|
var _queue = [];
|
||||||
|
@ -114,7 +114,7 @@ Zotero.Notifier = new function(){
|
||||||
* type - 'collection', 'search', 'item'
|
* type - 'collection', 'search', 'item'
|
||||||
* ids - single id or array of ids
|
* ids - single id or array of ids
|
||||||
*
|
*
|
||||||
* c = collection, s = search, i = item, t = tag
|
* c = collection, s = search, i = item, t = tag, it = item-tag
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Notes:
|
* Notes:
|
||||||
|
@ -215,7 +215,7 @@ Zotero.Notifier = new function(){
|
||||||
function sorter(a, b) {
|
function sorter(a, b) {
|
||||||
return order.indexOf(a) - order.indexOf(b);
|
return order.indexOf(a) - order.indexOf(b);
|
||||||
}
|
}
|
||||||
var order = ['collection', 'search', 'items', 'tags'];
|
var order = ['collection', 'search', 'item', 'collection-item', 'item-tag', 'tag'];
|
||||||
_queue.sort();
|
_queue.sort();
|
||||||
|
|
||||||
var order = ['add', 'modify', 'remove', 'move', 'delete'];
|
var order = ['add', 'modify', 'remove', 'move', 'delete'];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user