2017-05-18 21:31:38 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sgMessageListItem - A directive that watches some attributes of a message. Any component inside the
|
|
|
|
* list item should depends on this directive and extend the 'onUpdate' method instead of creating new
|
|
|
|
* independent watchers.
|
|
|
|
* @memberof SOGo.MailerUI
|
|
|
|
*/
|
|
|
|
function sgMessageListItem() {
|
|
|
|
return {
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {},
|
|
|
|
bindToController: {
|
|
|
|
message: '=sgMessage'
|
|
|
|
},
|
|
|
|
controller: 'sgMessageListItemController'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
sgMessageListItemController.$inject = ['$scope', '$element', 'Mailbox'];
|
|
|
|
function sgMessageListItemController($scope, $element, Mailbox) {
|
|
|
|
var $ctrl = this;
|
|
|
|
|
|
|
|
|
|
|
|
this.$onInit = function () {
|
2021-06-17 23:39:49 +02:00
|
|
|
var watchedAttrs = ['uid', 'isread', 'isflagged', 'flags', 'loading'];
|
2018-01-17 17:04:22 +01:00
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
// this.service = Message;
|
|
|
|
this.MailboxService = Mailbox;
|
|
|
|
|
2018-01-17 17:04:22 +01:00
|
|
|
if (Mailbox.selectedFolder.type == 'draft')
|
|
|
|
watchedAttrs.push('subject');
|
|
|
|
|
2017-05-18 21:31:38 +02:00
|
|
|
$scope.$watch(
|
|
|
|
function() {
|
2018-01-17 17:04:22 +01:00
|
|
|
return $ctrl.message? [ _.pick($ctrl.message, watchedAttrs) ] : null;
|
2017-05-18 21:31:38 +02:00
|
|
|
},
|
|
|
|
function(newId, oldId) {
|
|
|
|
if ($ctrl.message) {
|
|
|
|
// Message has changed
|
|
|
|
$ctrl.onUpdate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true // compare for object equality
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.onUpdate = function () {
|
2021-06-15 23:13:32 +02:00
|
|
|
if (this.message.loading) {
|
|
|
|
$element.addClass('sg-skeleton');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$element.removeClass('sg-skeleton');
|
2017-05-18 21:31:38 +02:00
|
|
|
// Is the message unread?
|
|
|
|
if (this.message.isread)
|
|
|
|
$element.removeClass('unread');
|
|
|
|
else
|
|
|
|
$element.addClass('unread');
|
|
|
|
// Is the message selected?
|
|
|
|
if (Mailbox.selectedFolder.isSelectedMessage(this.message.uid, this.message.$mailbox.path))
|
|
|
|
$element.addClass('md-default-theme md-accent md-bg md-hue-2');
|
|
|
|
else
|
|
|
|
$element.removeClass('md-default-theme md-accent md-bg md-hue-2');
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.setVisibility = function (element, visible) {
|
|
|
|
if (visible)
|
|
|
|
element.classList.remove('ng-hide');
|
|
|
|
else
|
|
|
|
element.classList.add('ng-hide');
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.MailerUI')
|
|
|
|
.controller('sgMessageListItemController', sgMessageListItemController)
|
|
|
|
.directive('sgMessageListItem', sgMessageListItem);
|
|
|
|
})();
|