Lidarr/UI/ProgressMessaging/ProgressMessageCollection.js

43 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
define(
[
'backbone',
'ProgressMessaging/ProgressMessageModel',
'Shared/Messenger',
'Mixins/backbone.signalr.mixin'
], function (Backbone, ProgressMessageModel, Messenger) {
var ProgressMessageCollection = Backbone.Collection.extend({
url : window.ApiRoot + '/progressmessage',
model: ProgressMessageModel
});
var collection = new ProgressMessageCollection().bindSignalR();
collection.signalRconnection.received(function (message) {
var type = getMessengerType(message.status);
var hideAfter = type === 'info' ? 60 : 5;
Messenger.show({
id : message.commandId,
message : message.message,
type : type,
hideAfter: hideAfter
});
});
var getMessengerType = function (status) {
switch (status) {
case 'completed':
return 'success';
case 'failed':
return 'error';
default:
return 'info';
}
};
return collection;
});