keeweb/app/scripts/presenters/entry-presenter.js

87 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-01-31 07:50:28 +01:00
const Format = require('../util/format');
const Locale = require('../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 || '';
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;
},
2019-08-16 23:05:39 +02:00
get id() {
return this.entry ? this.entry.id : this.group.id;
},
get icon() {
return this.entry ? this.entry.icon : this.group.get('icon') || 'folder';
},
get customIcon() {
return this.entry ? this.entry.customIcon : undefined;
},
get color() {
return this.entry ? this.entry.color || (this.entry.customIcon ? this.noColor : undefined) : undefined;
},
get title() {
return this.entry ? this.entry.title : this.group.get('title');
},
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() {
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;
},
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.user || this.notes || this.url;
2015-10-17 23:49:24 +02:00
}
}
};
module.exports = EntryPresenter;