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

198 lines
4.4 KiB
Plaintext
Raw Normal View History

2019-12-06 21:07:39 +01:00
h = require 'maquette' .h
2019-12-06 21:07:39 +01:00
Modal = require './modal.ls'
UUID = require "uuid/v4"
bulma = require "./bulma.ls"
2019-12-06 21:07:39 +01:00
2019-12-08 02:17:55 +01:00
col-to-lines = (column, self) ->
h \div.field.has-addons {
key: "field" + column.id
} [
2019-12-08 04:08:21 +01:00
h \p.control.is-expanded [
2019-12-08 02:17:55 +01:00
h \input.input {
key: "input" + column.id
value: column.title
oninput: (e) ->
self.extra_properties.columns.find((.id == column.id)).title := e.target.value
} [ ]
]
2019-12-08 04:08:21 +01:00
h \div.control.button.is-danger.is-outlined {
2019-12-08 02:17:55 +01:00
key: "button" + column.id
onclick: ->
self.extra_properties.columns := self.extra_properties.columns.filter((.id != column.id))
} [ "DELETE" ]
]
user-form-selection = (self, user) ->
h \option {
2019-12-10 05:59:52 +01:00
value: user.uid
} [ user.login ]
2019-12-10 05:59:52 +01:00
permission-groups =
"Read"
2019-12-10 05:59:52 +01:00
"Write"
"Admin"
permission-to-form-selection = (self, permission) ->
h \option {
value: permission
} [ permission ]
2019-12-08 02:17:55 +01:00
2019-12-10 05:59:52 +01:00
ProjectCreationModal = (project, todod-ws, users) ->
# work on a copy of the columns
# in case of cancelled modifications, only the copies are changed
columns-copy = []
for col in project.extra_properties.columns
new-col = {}
for k,v of col
new-col[k] = v
columns-copy ++= [ new-col ]
2019-12-06 21:07:39 +01:00
self = {
title: project.title || ""
2019-12-07 18:15:57 +01:00
permissions: project.permissions || [[]]
# new-user: "New user"
2019-12-10 05:59:52 +01:00
tmp:
new-user-permission:
id: void
permission: permission-groups[0]
new-column-input:
title: "New column !"
users: users || []
2019-12-06 21:07:39 +01:00
extra_properties:
columns: columns-copy
2019-12-06 21:07:39 +01:00
}
modal = Modal {
+visible
content-render: (self) ->
h \div.form [
2019-12-08 02:17:55 +01:00
bulma.field [
bulma.label "Project title"
h \input.input {
value: self.title
oninput: (e) ->
self.title := e.target.value
}
]
# h \hr []
# bulma.field [
# bulma.label "Adding a user"
# bulma.input {
# value: self.new-user
# oninput: (e) ->
# self.new-user := e.target.value
# name: \new-user
# id: \user-add
# }
# ]
2019-12-06 21:07:39 +01:00
2019-12-08 02:17:55 +01:00
h \hr []
2019-12-07 18:15:57 +01:00
h \aside.menu [
h \p.menu-label [ "Permissions" ]
h \ul.menu-list self.permissions.map (permission) ->
h \li [
h \p permission.map (e, index) ->
if index == 0
"Permissions '" + e + "': "
else
"" + e + ", "
]
]
2019-12-08 02:17:55 +01:00
h \hr []
h \p [ "Adding new user" ]
h \div.field.has-addons {
key: "adding-user"
} [
h \div.select.control [
h \select {
onchange: (e) ->
2019-12-10 05:59:52 +01:00
self.tmp.new-user-permission.permission := e.target.value
} permission-groups.map (permission) -> permission-to-form-selection self, permission
]
h \div.select.control.is-expanded [
h \select {
onchange: (e) ->
2019-12-10 05:59:52 +01:00
self.tmp.new-user-permission.uid := e.target.value
} [
user-form-selection self, { login: "Choose a user", uid: "-" }
for user-id, user of self.tmp.users
user-form-selection self, user
]
]
h \div.control.button.is-success.is-outlined {
onclick: ->
2019-12-10 05:59:52 +01:00
if self.tmp.new-user-permission.uid == void || self.tmp.new-user-permission.uid == "-"
console.log "adding an user permission on the kanban: failed, no user selected"
else
# TODO:
# adding the permissions in self.permissions
# then editing the project in the db via todod-ws
# self.permissions
console.log "right: #{self.tmp.new-user-permission.permission}, user #{self.tmp.new-user-permission.uid}"
} [ "+" ]
]
h \hr []
2019-12-08 02:17:55 +01:00
h \p [ "Choose the columns" ]
for dom in (self.extra_properties.columns.map (column) -> col-to-lines column, self)
dom
h \hr []
2019-12-08 04:08:21 +01:00
h \div.field.has-addons {
key: "adding-field"
} [
h \p.control.is-expanded [
h \input.input {
2019-12-10 05:59:52 +01:00
value: self.tmp.new-column-input.title
2019-12-08 04:08:21 +01:00
oninput: (e) ->
2019-12-10 05:59:52 +01:00
self.tmp.new-column-input.title := e.target.value
2019-12-08 04:08:21 +01:00
} [ ]
]
h \div.control.button.is-success.is-outlined {
onclick: ->
new-col = {
id: UUID!
2019-12-10 05:59:52 +01:00
title: self.tmp.new-column-input.title
2019-12-08 04:08:21 +01:00
}
self.extra_properties.columns ++= [ new-col ]
2019-12-10 05:59:52 +01:00
self.tmp.new-column-input.title := "New column !"
2019-12-08 04:08:21 +01:00
} [ "+" ]
]
2019-12-06 21:07:39 +01:00
]
2019-12-06 21:07:39 +01:00
on-validation: ->
2019-12-10 05:59:52 +01:00
tmp = delete self.tmp
2019-12-06 21:07:39 +01:00
if project.id
todod-ws.edit-list project.id, self
else
todod-ws.add-list self.title, self
2019-12-10 05:59:52 +01:00
self.tmp := tmp
}, self
2019-12-06 21:07:39 +01:00
self.render = ->
modal.render!
self
module.exports = ProjectCreationModal