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

54 lines
2.0 KiB
JavaScript
Raw Normal View History

2015-10-17 23:49:24 +02:00
'use strict';
var Format = require('../util/format');
var EntryPresenter = function(descField) {
this.entry = null;
this.descField = descField;
};
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;
},
get id() { return this.entry ? this.entry.id : this.group.get('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-11-08 22:25:00 +01:00
get color() { return this.entry ? this.entry.color : 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.url : undefined; },
get user() { return this.entry ? this.entry.user : undefined; },
get active() { return this.entry ? this.entry.active : 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; },
2015-11-21 15:55:42 +01:00
get tags() { return this.entry ? this.entry.tags : false; },
2015-10-17 23:49:24 +02:00
get description() {
2015-11-08 22:25:00 +01:00
if (!this.entry) {
return '[Group]';
}
2015-10-17 23:49:24 +02:00
switch (this.descField) {
case 'website':
return this.url || '(no website)';
case 'user':
return this.user || '(no user)';
case 'created':
return this.created;
case 'updated':
return this.updated;
case 'attachments':
return this.entry.attachments.map(function(a) { return a.title; }).join(', ') || '(no attachments)';
default:
return this.notes || this.url || this.user;
}
}
};
module.exports = EntryPresenter;