todo-webclient/client/project-creation-modal.ls

154 lines
3.2 KiB
Plaintext
Raw Normal View History

2019-12-06 21:07:39 +01:00
h = require 'maquette' .h
UUID = require "uuid/v4"
Column = require './column.ls'
Modal = require './modal.ls'
bulma = require "./bulma.ls"
2019-12-06 21:07:39 +01:00
2019-12-12 02:30:46 +01:00
{field, control, label, button, tag, input, select} = bulma
2019-12-20 01:34:41 +01:00
deep-copy = (object) ->
JSON.parse JSON.stringify object
2019-12-08 02:17:55 +01:00
2019-12-20 01:34:41 +01:00
const PERMISSION_LEVELS = ["admin", "edit", "read"]
2019-12-20 01:34:41 +01:00
remove-permission = (project, uid) ->
for key, value of project.permissions
project.permissions[key] := value.filter (!= uid)
add-permission = (project, uid, perm) ->
project.permissions[perm].push uid
ProjectCreationModal = (args) ->
2019-12-06 21:07:39 +01:00
self = {
2019-12-20 01:34:41 +01:00
project: if args.project
deep-copy args.project
else
{}
visible: args.visible || true
on-validation: args.on-validation || (project) ->
input : {
# Used when giving permissions to users not currently in the
# list of permissions.
new-user: ""
new-user-permission: \read
}
2019-12-06 21:07:39 +01:00
}
2019-12-20 01:34:41 +01:00
self.project.tasks := void
unless self.project.extra_properties
self.project.extra_properties = {
columns: [
Column "Unassigned" {color: "red"}
Column "Work in Progress"
Column "To be Checked"
Column "Being Checked"
Column "Done" {color: "green"}
]
}
self.modal = Modal {
on-validation: ->
if true # FIXME: Validate project
self.visible := false
2019-12-08 02:17:55 +01:00
2019-12-20 01:34:41 +01:00
args.on-validation self.project
2019-12-20 01:34:41 +01:00
on-cancellation: ->
self.visible := false
2019-12-06 21:07:39 +01:00
2019-12-20 01:34:41 +01:00
content-render: -> [
field {key: \title} [
label "Title"
2019-12-20 01:34:41 +01:00
input {
value: self.project.title
oninput: (e) ->
console.log "oninput => ", e.target.value
self.project.title := e.target.value
}
]
if self.project.permissions
field {key: \permissions} [
2019-12-12 02:30:46 +01:00
label "Permissions"
2019-12-20 01:34:41 +01:00
h \table.table.is-fullwidth [
h \thead [
h \th [ "User" ]
h \th [ "Permission" ]
]
2019-12-12 02:30:46 +01:00
h \tbody [
2019-12-20 01:34:41 +01:00
for permission in PERMISSION_LEVELS
[
for uid in self.project.permissions[permission]
h \tr {key: uid} [
# FIXME: show full name or login
h \td [ uid.to-string! ]
h \td [ permission ]
2019-12-12 02:30:46 +01:00
]
2019-12-20 01:34:41 +01:00
]
2019-12-12 02:30:46 +01:00
]
]
2019-12-07 18:15:57 +01:00
]
2019-12-20 01:34:41 +01:00
if self.project.permissions
field \.has-addons [
control \.is-expanded [
# FIXME: Replace by a “user search input” as soon
# as one is available.
input {
value: self.input.new-user
oninput: (e) ->
self.input.new-user := e.target.value
}
]
2019-12-12 02:30:46 +01:00
control [
select {
onchange: (e) ->
2019-12-20 01:34:41 +01:00
self.input.new-user-permission := e.target.value
} PERMISSION_LEVELS.map (perm) ->
h \option {
selected: perm == \read
} [ perm ]
]
2019-12-12 02:30:46 +01:00
control [
2019-12-20 01:34:41 +01:00
h \div.button.is-success.is-outlined {
2019-12-12 02:30:46 +01:00
onclick: ->
2019-12-20 01:34:41 +01:00
uid = parse-int self.input.new-user
perm = self.input.new-user-permission
2019-12-20 01:34:41 +01:00
self.input.new-user := ""
# FIXME: Really? :thonk:
#self.input.new-user-permission := \read
2019-12-08 02:17:55 +01:00
2019-12-20 01:34:41 +01:00
console.log "Adding new perm? :/", uid, perm
2019-12-08 02:17:55 +01:00
2019-12-20 01:34:41 +01:00
remove-permission self.project, uid
add-permission self.project, uid, perm
2019-12-08 04:08:21 +01:00
2019-12-20 01:34:41 +01:00
console.log self.project.permissions
} [
"+"
]
2019-12-12 21:49:15 +01:00
]
2019-12-08 04:08:21 +01:00
]
2019-12-20 01:34:41 +01:00
]
}
2019-12-06 21:07:39 +01:00
self.render = ->
2019-12-20 01:34:41 +01:00
self.modal.visible = self.visible
self.modal.render!
2019-12-06 21:07:39 +01:00
self
module.exports = ProjectCreationModal