2015-10-17 23:49:24 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-17 19:25:25 +01:00
|
|
|
var Format = require('../util/format'),
|
|
|
|
Locale = require('../util/locale');
|
2015-10-17 23:49:24 +02:00
|
|
|
|
2015-12-12 12:04:02 +01:00
|
|
|
var EntryPresenter = function(descField, noColor, activeEntryId) {
|
2015-10-17 23:49:24 +02:00
|
|
|
this.entry = null;
|
|
|
|
this.descField = descField;
|
2015-12-02 22:12:14 +01:00
|
|
|
this.noColor = noColor || '';
|
2015-12-12 12:04:02 +01:00
|
|
|
this.activeEntryId = activeEntryId;
|
2015-10-17 23:49:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
EntryPresenter.prototype = {
|
2015-11-08 22:25:00 +01:00
|
|
|
present: function(item) {
|
|
|
|
if (item.entry) {
|
|
|
|
this.entry = item;
|
|
|
|
} else {
|
|
|
|
this.group = item;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
2016-06-05 12:25:50 +02:00
|
|
|
get id() { return this.entry ? this.entry.id : this.group.id; },
|
2015-11-12 21:48:44 +01:00
|
|
|
get icon() { return this.entry ? this.entry.icon : (this.group.get('icon') || 'folder'); },
|
2015-11-12 22:52:28 +01:00
|
|
|
get customIcon() { return this.entry ? this.entry.customIcon : undefined; },
|
2015-12-02 22:12:14 +01:00
|
|
|
get color() { return this.entry ? (this.entry.color || (this.entry.customIcon ? this.noColor : undefined)) : undefined; },
|
2015-11-08 22:25:00 +01:00
|
|
|
get title() { return this.entry ? this.entry.title : this.group.get('title'); },
|
|
|
|
get notes() { return this.entry ? this.entry.notes : undefined; },
|
2016-01-13 19:00:22 +01:00
|
|
|
get url() { return this.entry ? this.entry.displayUrl : undefined; },
|
2015-11-08 22:25:00 +01:00
|
|
|
get user() { return this.entry ? this.entry.user : undefined; },
|
2015-12-12 12:04:02 +01:00
|
|
|
get active() { return this.entry ? this.entry.id === this.activeEntryId : this.group.active; },
|
2015-11-08 22:25:00 +01:00
|
|
|
get created() { return this.entry ? Format.dtStr(this.entry.created) : undefined; },
|
|
|
|
get updated() { return this.entry ? Format.dtStr(this.entry.updated) : undefined; },
|
|
|
|
get expired() { return this.entry ? this.entry.expired : false; },
|
2016-06-11 16:18:11 +02:00
|
|
|
get tags() { return this.entry ? this.entry.tags : undefined; },
|
|
|
|
get groupName() { return this.entry ? this.entry.groupName : undefined; },
|
|
|
|
get fileName() { return this.entry ? this.entry.fileName : undefined; },
|
2015-10-17 23:49:24 +02:00
|
|
|
get description() {
|
2015-11-08 22:25:00 +01:00
|
|
|
if (!this.entry) {
|
2015-12-17 19:25:25 +01:00
|
|
|
return '[' + Locale.listGroup + ']';
|
2015-11-08 22:25:00 +01:00
|
|
|
}
|
2015-10-17 23:49:24 +02:00
|
|
|
switch (this.descField) {
|
|
|
|
case 'website':
|
2015-12-17 19:25:25 +01:00
|
|
|
return this.url || '(' + Locale.listNoWebsite + ')';
|
2015-10-17 23:49:24 +02:00
|
|
|
case 'user':
|
2015-12-17 19:25:25 +01:00
|
|
|
return this.user || '(' + Locale.listNoUser + ')';
|
2015-10-17 23:49:24 +02:00
|
|
|
case 'created':
|
|
|
|
return this.created;
|
|
|
|
case 'updated':
|
|
|
|
return this.updated;
|
|
|
|
case 'attachments':
|
2016-07-17 13:30:38 +02:00
|
|
|
return this.entry.attachments.map(a => a.title).join(', ') || '(' + Locale.listNoAttachments + ')';
|
2015-10-17 23:49:24 +02:00
|
|
|
default:
|
|
|
|
return this.notes || this.url || this.user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = EntryPresenter;
|