mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 22:28:51 +01:00
Also update new message count if space entry is moved
This commit is contained in:
parent
fec5770366
commit
c39815bf01
@ -41,8 +41,8 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
railpadding: {top: 0, right: 3, left: 0, bottom: 0}
|
railpadding: {top: 0, right: 3, left: 0, bottom: 0}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$chooser.on('touchmove', function(evt) {
|
this.$chooser.on('touchmove', function (evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.initEvents();
|
this.initEvents();
|
||||||
@ -51,10 +51,10 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
|
|
||||||
SpaceChooser.prototype.initEvents = function () {
|
SpaceChooser.prototype.initEvents = function () {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
$('[data-space-guid]').find('[data-message-count]').each(function() {
|
$('[data-space-guid]').find('[data-message-count]').each(function () {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
if($this.data('message-count') > 0) {
|
if ($this.data('message-count') > 0) {
|
||||||
$this.show();
|
$this.show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -68,7 +68,7 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
|
|
||||||
// Focus on search on open and clear item selection when closed
|
// Focus on search on open and clear item selection when closed
|
||||||
this.$menu.parent().on('shown.bs.dropdown', function () {
|
this.$menu.parent().on('shown.bs.dropdown', function () {
|
||||||
if(!view.isSmall()) {
|
if (!view.isSmall()) {
|
||||||
that.$search.focus();
|
that.$search.focus();
|
||||||
}
|
}
|
||||||
}).on('hidden.bs.dropdown', function () {
|
}).on('hidden.bs.dropdown', function () {
|
||||||
@ -90,7 +90,7 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
that.removeItem(space);
|
that.removeItem(space);
|
||||||
}).on('humhub:space:unarchived', function (evt, space) {
|
}).on('humhub:space:unarchived', function (evt, space) {
|
||||||
that.prependItem(space);
|
that.prependItem(space);
|
||||||
}).on('humhub:modules:content:live:NewContent', function(evt, liveEvents) {
|
}).on('humhub:modules:content:live:NewContent', function (evt, liveEvents) {
|
||||||
that.handleNewContent(liveEvents);
|
that.handleNewContent(liveEvents);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -98,28 +98,30 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
SpaceChooser.prototype.handleNewContent = function (liveEvents) {
|
SpaceChooser.prototype.handleNewContent = function (liveEvents) {
|
||||||
var that = this;
|
var that = this;
|
||||||
var increments = {};
|
var increments = {};
|
||||||
|
|
||||||
liveEvents.forEach(function(event) {
|
liveEvents.forEach(function (event) {
|
||||||
if(event.data.uguid || event.data.originator === user.guid()) {
|
if (event.data.uguid || event.data.originator === user.guid()) {
|
||||||
return;
|
return;
|
||||||
} else if(increments[event.data.sguid]) {
|
} else if (increments[event.data.sguid]) {
|
||||||
increments[event.data.sguid]++;
|
increments[event.data.sguid]++;
|
||||||
} else {
|
} else {
|
||||||
increments[event.data.sguid] = 1;
|
increments[event.data.sguid] = 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.each(increments, function(guid, count) {
|
$.each(increments, function (guid, count) {
|
||||||
that.incrementMessageCount(guid, count);
|
that.incrementMessageCount(guid, count);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
SpaceChooser.prototype.incrementMessageCount = function (guid, count) {
|
SpaceChooser.prototype.incrementMessageCount = function (guid, count) {
|
||||||
var $messageCount = $('[data-space-guid="'+guid+'"]').find('[data-message-count]');
|
var $messageCount = $('[data-space-guid="' + guid + '"]').find('[data-message-count]');
|
||||||
var newCount = $messageCount.data('message-count') + count;
|
var newCount = $messageCount.data('message-count') + count;
|
||||||
|
|
||||||
$messageCount.hide().text(newCount).data('message-count', newCount);
|
$messageCount.hide().text(newCount).data('message-count', newCount);
|
||||||
setTimeout(function() {$messageCount.show();}, 100);
|
setTimeout(function () {
|
||||||
|
$messageCount.show();
|
||||||
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
SpaceChooser.prototype.prependItem = function (space) {
|
SpaceChooser.prototype.prependItem = function (space) {
|
||||||
@ -248,9 +250,9 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
|
|
||||||
SpaceChooser.prototype.triggerRemoteSearch = function (input) {
|
SpaceChooser.prototype.triggerRemoteSearch = function (input) {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
this.remoteSearch(input).then(function (data) {
|
this.remoteSearch(input).then(function (data) {
|
||||||
if(data === true) { //Outdated result, just ignore this...
|
if (data === true) { //Outdated result, just ignore this...
|
||||||
return;
|
return;
|
||||||
} else if (!data) {
|
} else if (!data) {
|
||||||
that.onChange(input);
|
that.onChange(input);
|
||||||
@ -264,7 +266,7 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
that.highlight(input, SELECTOR_ITEM_REMOTE);
|
that.highlight(input, SELECTOR_ITEM_REMOTE);
|
||||||
that.onChange(input);
|
that.onChange(input);
|
||||||
}).catch(function (e) {
|
}).catch(function (e) {
|
||||||
if(!e.textStatus === "abort") {
|
if (!e.textStatus === "abort") {
|
||||||
module.log.error(e, true);
|
module.log.error(e, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -273,10 +275,10 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
SpaceChooser.prototype.remoteSearch = function (input) {
|
SpaceChooser.prototype.remoteSearch = function (input) {
|
||||||
var that = this;
|
var that = this;
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
if(that.currentXhr) {
|
if (that.currentXhr) {
|
||||||
that.currentXhr.abort();
|
that.currentXhr.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear all current remote results not matching the current search
|
// Clear all current remote results not matching the current search
|
||||||
that.clearRemoteSearch(input);
|
that.clearRemoteSearch(input);
|
||||||
var url = module.config.remoteSearchUrl;
|
var url = module.config.remoteSearchUrl;
|
||||||
@ -290,20 +292,20 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var searchTs = Date.now();
|
var searchTs = Date.now();
|
||||||
var options = {data: {keyword: input, target: 'chooser'},
|
var options = {data: {keyword: input, target: 'chooser'},
|
||||||
beforeSend: function(xhr) {
|
beforeSend: function (xhr) {
|
||||||
that.currentXhr = xhr;
|
that.currentXhr = xhr;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
ui.loader.set(that.$remoteSearch, {'wrapper': '<li>', 'css': {padding: '5px'}});
|
ui.loader.set(that.$remoteSearch, {'wrapper': '<li>', 'css': {padding: '5px'}});
|
||||||
|
|
||||||
client.get(url, options).then(function (response) {
|
client.get(url, options).then(function (response) {
|
||||||
that.currentXhr = undefined;
|
that.currentXhr = undefined;
|
||||||
var lastSearchTs = that.$remoteSearch.data('last-search-ts');
|
var lastSearchTs = that.$remoteSearch.data('last-search-ts');
|
||||||
var isOutDated = lastSearchTs && lastSearchTs > searchTs;
|
var isOutDated = lastSearchTs && lastSearchTs > searchTs;
|
||||||
var hastData = response.data && response.data.length;
|
var hastData = response.data && response.data.length;
|
||||||
|
|
||||||
if(!isOutDated) {
|
if (!isOutDated) {
|
||||||
that.$remoteSearch.empty();
|
that.$remoteSearch.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +341,7 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
$('#space-search-reset').fadeOut('fast');
|
$('#space-search-reset').fadeOut('fast');
|
||||||
this.clearRemoteSearch();
|
this.clearRemoteSearch();
|
||||||
|
|
||||||
if(!view.isSmall()) {
|
if (!view.isSmall()) {
|
||||||
this.$search.val('').focus();
|
this.$search.val('').focus();
|
||||||
}
|
}
|
||||||
this.$search.removeData('last-search');
|
this.$search.removeData('last-search');
|
||||||
@ -402,12 +404,13 @@ humhub.module('space.chooser', function (module, require, $) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SpaceChooser.prototype.setSpaceMessageCount = function (space, count) {
|
SpaceChooser.prototype.setSpaceMessageCount = function (space, count) {
|
||||||
var $item = this.findItem(space);
|
var guid = object.isString(space) ? space : space.guid;
|
||||||
if ($item.length) {
|
var $messageCount = $('[data-space-guid="' + guid + '"]').find('[data-message-count]');
|
||||||
if(count) {
|
if ($messageCount.length) {
|
||||||
$item.find('.messageCount').text(count);
|
if (count) {
|
||||||
|
$messageCount.text(count);
|
||||||
} else {
|
} else {
|
||||||
$item.find('.messageCount').fadeOut('fast');
|
$messageCount.fadeOut('fast');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user