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

38 lines
967 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
}
toHtml(elm) {
let user = firebase.auth().currentUser
elm.append('<p class="kommentar"></p>')
$($('.kommentar')[$('.kommentar').length-1]).text(this.toString())
if (user) {
$($('.kommentar')[$('.kommentar').length-1]).append(' &nbsp; <a class="btn btn-primary" href="javascript: remove(\''+this.cfid+'\')">Slett</a>')
}
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
)
}
}