2019-12-06 04:10:00 +01:00
|
|
|
|
2019-12-10 03:34:08 +01:00
|
|
|
# TODO: on modification, the description isn't updated on the client
|
|
|
|
|
2019-12-06 04:10:00 +01:00
|
|
|
h = require 'maquette' .h
|
|
|
|
Modal = require './modal.ls'
|
|
|
|
|
2019-12-12 01:49:34 +01:00
|
|
|
{field, input, textarea, label, control, select} = require './bulma.ls'
|
|
|
|
|
2019-12-20 22:15:12 +01:00
|
|
|
# FIXME: This be a copy-pasta. Somebody gotta touch this spaghetti.
|
|
|
|
const PERMISSION_LEVELS = ["admin", "edit", "read"]
|
|
|
|
|
2019-12-09 03:09:06 +01:00
|
|
|
colors = [
|
|
|
|
"white"
|
|
|
|
"black"
|
|
|
|
"light"
|
|
|
|
"dark"
|
|
|
|
"primary"
|
|
|
|
"info"
|
|
|
|
"link"
|
|
|
|
"success"
|
|
|
|
"warning"
|
|
|
|
"danger"
|
|
|
|
"black-bis"
|
|
|
|
"black-ter"
|
|
|
|
"grey-darker"
|
|
|
|
"grey-dark"
|
|
|
|
"grey"
|
|
|
|
"grey-light"
|
|
|
|
"grey-lighter"
|
|
|
|
"white-ter"
|
|
|
|
"white-bis"
|
|
|
|
]
|
2019-12-08 04:08:21 +01:00
|
|
|
|
|
|
|
column-form-selection = (self, column) ->
|
2019-12-08 15:23:46 +01:00
|
|
|
h \option {
|
|
|
|
value: column.id
|
|
|
|
selected: self.extra_properties && self.extra_properties.column == column.id
|
|
|
|
} [ column.title ]
|
2019-12-08 04:08:21 +01:00
|
|
|
|
2019-12-09 03:31:11 +01:00
|
|
|
color-to-form-selection = (self, color, current-color) ->
|
2019-12-09 03:09:06 +01:00
|
|
|
h \option {
|
|
|
|
value: color
|
2019-12-09 03:31:11 +01:00
|
|
|
selected: current-color && current-color == color
|
2019-12-09 03:09:06 +01:00
|
|
|
} [ color ]
|
2019-12-08 04:08:21 +01:00
|
|
|
|
2019-12-22 19:48:21 +01:00
|
|
|
user-form-selection = (users-cache, uid, is-selected) ->
|
2019-12-12 01:25:36 +01:00
|
|
|
h \option {
|
2019-12-20 22:15:12 +01:00
|
|
|
selected: is-selected
|
|
|
|
value: uid.to-string!
|
2019-12-22 19:48:21 +01:00
|
|
|
} [
|
|
|
|
if user = users-cache.get-user uid
|
|
|
|
(user.profile?.full_name) || user.login
|
|
|
|
else
|
|
|
|
uid.to-string!
|
|
|
|
]
|
|
|
|
|
|
|
|
TaskCreationModal = (project, todod-ws, task, users-cache) ->
|
2019-12-06 04:10:00 +01:00
|
|
|
task ||= {}
|
|
|
|
|
2019-12-08 02:54:07 +01:00
|
|
|
# copy not to override anything on cancel
|
2019-12-06 04:10:00 +01:00
|
|
|
self = {
|
|
|
|
title: task.title || ""
|
|
|
|
description: task.description || ""
|
2019-12-20 22:15:12 +01:00
|
|
|
assigned_to: task.assigned_to
|
2019-12-12 01:25:36 +01:00
|
|
|
extra_properties:
|
2019-12-08 02:56:29 +01:00
|
|
|
column: ""
|
2019-12-09 03:31:11 +01:00
|
|
|
background-color: ""
|
2019-12-06 04:10:00 +01:00
|
|
|
}
|
|
|
|
|
2019-12-09 03:09:06 +01:00
|
|
|
# copy extra properties
|
2019-12-09 03:31:11 +01:00
|
|
|
# currently: column + background-color + assignee + expected duration time
|
2019-12-09 03:09:06 +01:00
|
|
|
for k,v of task.extra_properties
|
|
|
|
self.extra_properties[k] = v
|
|
|
|
|
2019-12-23 23:58:47 +01:00
|
|
|
if self.extra_properties.column == ""
|
|
|
|
self.extra_properties.column = project.extra_properties.columns?[0]?.id || ""
|
|
|
|
|
2019-12-06 04:10:00 +01:00
|
|
|
modal = Modal {
|
|
|
|
+visible
|
2019-12-07 05:11:47 +01:00
|
|
|
content-render: (self) ->
|
|
|
|
h \div.form [
|
2019-12-12 01:25:36 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# TITLE
|
|
|
|
#
|
|
|
|
|
2019-12-12 01:49:34 +01:00
|
|
|
field [
|
|
|
|
label "Task title"
|
2019-12-06 05:04:55 +01:00
|
|
|
|
2019-12-12 01:49:34 +01:00
|
|
|
input {
|
|
|
|
value: self.title
|
|
|
|
oninput: (e) ->
|
|
|
|
self.title := e.target.value
|
|
|
|
}
|
|
|
|
]
|
2019-12-12 01:25:36 +01:00
|
|
|
|
|
|
|
|
2019-12-12 01:49:34 +01:00
|
|
|
field [
|
|
|
|
label "Task description"
|
|
|
|
|
|
|
|
#
|
|
|
|
# DESCRIPTION
|
|
|
|
#
|
2019-12-06 21:07:39 +01:00
|
|
|
|
2019-12-12 01:49:34 +01:00
|
|
|
textarea {
|
|
|
|
value: self.description
|
|
|
|
oninput: (e) ->
|
|
|
|
self.description := e.target.value
|
|
|
|
}
|
|
|
|
]
|
2019-12-08 04:08:21 +01:00
|
|
|
|
2019-12-08 15:23:46 +01:00
|
|
|
|
2019-12-12 01:49:34 +01:00
|
|
|
field [
|
2019-12-12 21:49:15 +01:00
|
|
|
label "Column"
|
2019-12-12 01:49:34 +01:00
|
|
|
|
|
|
|
control [
|
|
|
|
select \.is-fullwidth {
|
|
|
|
onchange: (e) ->
|
|
|
|
self.extra_properties.column := e.target.value
|
|
|
|
} project.extra_properties.columns.map (column) -> column-form-selection self, column
|
|
|
|
]
|
2019-12-08 15:23:46 +01:00
|
|
|
]
|
2019-12-08 04:08:21 +01:00
|
|
|
|
2019-12-12 01:25:36 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# USER MANAGEMENT
|
|
|
|
#
|
|
|
|
|
|
|
|
h \hr []
|
|
|
|
|
2019-12-12 01:49:34 +01:00
|
|
|
field [
|
|
|
|
label "Assigned user"
|
2019-12-12 01:25:36 +01:00
|
|
|
|
2019-12-12 01:49:34 +01:00
|
|
|
control {
|
|
|
|
key: "assign-someone-to-task"
|
|
|
|
} [
|
|
|
|
select \.is-fullwidth {
|
2019-12-12 01:25:36 +01:00
|
|
|
onchange: (e) ->
|
2019-12-20 22:15:12 +01:00
|
|
|
if uid = parse-int e.target.value
|
|
|
|
self.assigned_to := uid
|
|
|
|
else
|
|
|
|
self.assigned_to := void
|
2019-12-12 01:25:36 +01:00
|
|
|
} [
|
2019-12-20 22:15:12 +01:00
|
|
|
h \option {
|
|
|
|
default: true
|
|
|
|
value: ""
|
|
|
|
} [ "(unassigned)" ]
|
|
|
|
|
|
|
|
for permission in PERMISSION_LEVELS
|
|
|
|
[
|
|
|
|
for uid in project.permissions[permission]
|
2019-12-22 19:48:21 +01:00
|
|
|
user-form-selection users-cache, uid,
|
2019-12-20 22:15:12 +01:00
|
|
|
(self.assigned_to == uid)
|
|
|
|
]
|
2019-12-12 01:25:36 +01:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# BACKGROUND COLOR
|
|
|
|
#
|
|
|
|
|
2019-12-12 01:49:34 +01:00
|
|
|
field [
|
|
|
|
label "Card background color"
|
2019-12-09 03:09:06 +01:00
|
|
|
|
2019-12-12 01:49:34 +01:00
|
|
|
control [
|
|
|
|
select \.is-fullwidth {
|
|
|
|
onchange: (e) ->
|
|
|
|
self.extra_properties.background-color := e.target.value
|
|
|
|
} colors.map (color) -> color-to-form-selection self, color, self.extra_properties.background-color
|
|
|
|
]
|
2019-12-09 03:09:06 +01:00
|
|
|
]
|
2019-12-06 05:04:55 +01:00
|
|
|
]
|
2019-12-08 02:17:55 +01:00
|
|
|
|
2019-12-06 04:10:00 +01:00
|
|
|
on-validation: ->
|
2019-12-12 01:25:36 +01:00
|
|
|
tmp = delete self.tmp
|
2019-12-06 04:10:00 +01:00
|
|
|
if task.id
|
2019-12-08 02:17:55 +01:00
|
|
|
todod-ws.edit-task task.id, self
|
2019-12-06 04:10:00 +01:00
|
|
|
else
|
2019-12-08 02:17:55 +01:00
|
|
|
todod-ws.add-task project.id, self.title, self
|
2019-12-12 01:25:36 +01:00
|
|
|
self.tmp = tmp
|
2019-12-07 05:11:47 +01:00
|
|
|
}, self
|
2019-12-06 04:10:00 +01:00
|
|
|
|
|
|
|
self.render = ->
|
|
|
|
modal.render!
|
|
|
|
|
|
|
|
self
|
|
|
|
|
|
|
|
module.exports = TaskCreationModal
|