2019-09-15 14:16:32 +02:00
|
|
|
import { DateFormat } from 'util/formatting/date-format';
|
|
|
|
import { Locale } from 'util/locale';
|
2015-10-17 23:49:24 +02:00
|
|
|
|
2017-01-31 07:50:28 +01:00
|
|
|
const 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 = {
|
2019-08-18 10:17:09 +02:00
|
|
|
present(item) {
|
2015-11-08 22:25:00 +01:00
|
|
|
if (item.entry) {
|
|
|
|
this.entry = item;
|
|
|
|
} else {
|
|
|
|
this.group = item;
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
2019-08-16 23:05:39 +02:00
|
|
|
get id() {
|
|
|
|
return this.entry ? this.entry.id : this.group.id;
|
|
|
|
},
|
|
|
|
get icon() {
|
2019-09-18 23:37:57 +02:00
|
|
|
return this.entry ? this.entry.icon : this.group.icon || 'folder';
|
2019-08-16 23:05:39 +02:00
|
|
|
},
|
|
|
|
get customIcon() {
|
|
|
|
return this.entry ? this.entry.customIcon : undefined;
|
|
|
|
},
|
|
|
|
get color() {
|
2019-08-18 08:05:38 +02:00
|
|
|
return this.entry
|
|
|
|
? this.entry.color || (this.entry.customIcon ? this.noColor : undefined)
|
|
|
|
: undefined;
|
2019-08-16 23:05:39 +02:00
|
|
|
},
|
|
|
|
get title() {
|
2019-09-18 23:37:57 +02:00
|
|
|
return this.entry ? this.entry.title : this.group.title;
|
2019-08-16 23:05:39 +02:00
|
|
|
},
|
|
|
|
get notes() {
|
|
|
|
return this.entry ? this.entry.notes : undefined;
|
|
|
|
},
|
|
|
|
get url() {
|
|
|
|
return this.entry ? this.entry.displayUrl : undefined;
|
|
|
|
},
|
|
|
|
get user() {
|
|
|
|
return this.entry ? this.entry.user : undefined;
|
|
|
|
},
|
|
|
|
get active() {
|
|
|
|
return this.entry ? this.entry.id === this.activeEntryId : this.group.active;
|
|
|
|
},
|
|
|
|
get created() {
|
2019-09-15 08:11:11 +02:00
|
|
|
return this.entry ? DateFormat.dtStr(this.entry.created) : undefined;
|
2019-08-16 23:05:39 +02:00
|
|
|
},
|
|
|
|
get updated() {
|
2019-09-15 08:11:11 +02:00
|
|
|
return this.entry ? DateFormat.dtStr(this.entry.updated) : undefined;
|
2019-08-16 23:05:39 +02:00
|
|
|
},
|
|
|
|
get expired() {
|
|
|
|
return this.entry ? this.entry.expired : false;
|
|
|
|
},
|
|
|
|
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':
|
2019-08-18 08:05:38 +02:00
|
|
|
return (
|
|
|
|
this.entry.attachments.map(a => a.title).join(', ') ||
|
|
|
|
'(' + Locale.listNoAttachments + ')'
|
|
|
|
);
|
2015-10-17 23:49:24 +02:00
|
|
|
default:
|
2017-11-04 09:38:56 +01:00
|
|
|
return this.user || this.notes || this.url;
|
2015-10-17 23:49:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-15 14:16:32 +02:00
|
|
|
export { EntryPresenter };
|