github.io/it1/js/converters/kommentar.js

34 lines
797 B
JavaScript
Raw Normal View History

2020-03-27 22:29:16 +00:00
class Comment {
2020-03-27 23:22:28 +00:00
constructor(name, message, id=0) {
2020-03-27 22:29:16 +00:00
this.name = name,
2020-03-27 23:22:28 +00:00
this.message = message,
this.cfid = id
2020-03-27 22:29:16 +00:00
}
toString() {
return this.name+': '+this.message
}
2020-03-27 23:22:28 +00:00
toHtml(user) {
return '<p id="kommentar">'+this.name+': '+this.message
+(user?' &nbsp; <a class="btn btn-primary" href="javascript: remove(\''+this.cfid+'\')">Slett</a>':'')+'</p>'
2020-03-27 22:29:16 +00:00
}
}
commentConverter = {
toFirestore: function(comment) {
return {
navn: comment.name,
melding: comment.message
}
},
fromFirestore: function(snapshot, options) {
const data = snapshot.data(options)
return new Comment(
data.navn,
2020-03-27 23:22:28 +00:00
data.melding,
snapshot.id
2020-03-27 22:29:16 +00:00
)
}
}