todo-webclient/client/task.ls

79 lines
1.7 KiB
Plaintext

h = require 'maquette' .h
bulma = require "./bulma.ls"
nmd = require "nano-markdown"
TaskCreationModal = require './task-creation-modal.ls'
TaskRemovalModal = require './task-removal-modal.ls'
{icon} = require "./font-awesome.ls"
Task = (self, project, todod-ws, users-cache) ->
modal = void
self.render-login = (uid) ->
h \p [
if user = users-cache.get-user uid
'@' + user.login
else
'@' + uid.to-string!
]
self.render = (args) ->
args or= {}
background-color = "grey"
if self.extra_properties && self.extra_properties.background-color
background-color = self.extra_properties.background-color
h "div.card.is-#{background-color}" {
classes: {
"is-selected": args.is-selected
}
key: self.id
onclick: (e) ->
if args.onclick
args.onclick(e)
} [
h \div.card-content [
h \div.title.is-5 [
h \a.has-text-grey.is-pulled-right {
onclick: ->
modal := TaskCreationModal project, todod-ws, self, users-cache
} [
icon \cog.visible-on-hover
]
self.title
]
h \div.media [
h \div.media-left [
# FIXME: assignee card image
]
h \div.media-content [
if uid = self.assigned_to
self.render-login uid
]
]
if args.is-selected
h \div.content {
key: "task-description-#{self.id}"
after-create: (dom) ->
dom.innerHTML = nmd self.description
} [ ]
if args.is-selected
h \div.card-footer [
h \a.card-footer-item.has-text-danger {
onclick: ->
modal := TaskRemovalModal project.id, todod-ws, self
} [ "Destroy" ]
]
]
if modal
modal.render!
]
self
module.exports = Task