44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
leantime.reactionsController = (function () {
|
|
|
|
|
|
//Functions
|
|
|
|
let addReactions = function (module, moduleId, reaction, clb) {
|
|
|
|
leantime.rpc('Reactions.Reactions.react', {
|
|
module: module,
|
|
moduleId: moduleId,
|
|
reaction: reaction
|
|
}).then(function (success) {
|
|
// The service returns false when the reaction was not applied
|
|
// (e.g. the user already reacted) — only update the UI on success.
|
|
if (success) {
|
|
clb();
|
|
}
|
|
}).catch(function (e) { console.error('Could not add reaction', e); });
|
|
|
|
};
|
|
|
|
let removeReaction = function (module, moduleId, reaction, clb) {
|
|
|
|
leantime.rpc('Reactions.Reactions.unreact', {
|
|
module: module,
|
|
moduleId: moduleId,
|
|
reaction: reaction
|
|
}).then(function (success) {
|
|
// Only update the UI when the reaction was actually removed.
|
|
if (success) {
|
|
clb();
|
|
}
|
|
}).catch(function (e) { console.error('Could not remove reaction', e); });
|
|
|
|
};
|
|
|
|
// Make public what you want to have public, everything else is private
|
|
return {
|
|
addReactions:addReactions,
|
|
removeReaction:removeReaction
|
|
|
|
};
|
|
})();
|