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

59 lines
2.4 KiB
JavaScript
Raw Normal View History

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
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 || '';
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;
},
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; },
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':
2015-12-17 19:25:25 +01:00
return this.entry.attachments.map(function(a) { return a.title; }).join(', ') || '(' + Locale.listNoAttachments + ')';
2015-10-17 23:49:24 +02:00
default:
return this.notes || this.url || this.user;
}
}
};
module.exports = EntryPresenter;