todo-webclient/client/project-creation-modal.ls
Luka Vandervelden f4f043f4e1 Columns can be added and removed again.
A .visible-on-hover class has also been added, although it isn’t very
flexible at the moment.
2019-12-22 20:03:11 +01:00

154 lines
3.2 KiB
Plaintext

h = require 'maquette' .h
UUID = require "uuid/v4"
Column = require './column.ls'
Modal = require './modal.ls'
bulma = require "./bulma.ls"
{field, control, label, button, tag, input, select} = bulma
deep-copy = (object) ->
JSON.parse JSON.stringify object
const PERMISSION_LEVELS = ["admin", "edit", "read"]
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) ->
self = {
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
}
}
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
args.on-validation self.project
on-cancellation: ->
self.visible := false
content-render: -> [
field {key: \title} [
label "Title"
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} [
label "Permissions"
h \table.table.is-fullwidth [
h \thead [
h \th [ "User" ]
h \th [ "Permission" ]
]
h \tbody [
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 ]
]
]
]
]
]
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
}
]
control [
select {
onchange: (e) ->
self.input.new-user-permission := e.target.value
} PERMISSION_LEVELS.map (perm) ->
h \option {
selected: perm == \read
} [ perm ]
]
control [
h \div.button.is-success.is-outlined {
onclick: ->
uid = parse-int self.input.new-user
perm = self.input.new-user-permission
self.input.new-user := ""
# FIXME: Really? :thonk:
#self.input.new-user-permission := \read
console.log "Adding new perm? :/", uid, perm
remove-permission self.project, uid
add-permission self.project, uid, perm
console.log self.project.permissions
} [
"+"
]
]
]
]
}
self.render = ->
self.modal.visible = self.visible
self.modal.render!
self
module.exports = ProjectCreationModal