213 lines
5.0 KiB
Plaintext
213 lines
5.0 KiB
Plaintext
|
|
h = require 'maquette' .h
|
|
Modal = require './modal.ls'
|
|
UUID = require "uuid/v4"
|
|
bulma = require "./bulma.ls"
|
|
|
|
col-to-lines = (column, self) ->
|
|
h \div.field.has-addons {
|
|
key: "field" + column.id
|
|
} [
|
|
h \p.control.is-expanded [
|
|
h \input.input {
|
|
key: "input" + column.id
|
|
value: column.title
|
|
oninput: (e) ->
|
|
self.extra_properties.columns.find((.id == column.id)).title := e.target.value
|
|
} [ ]
|
|
]
|
|
|
|
h \div.control.button.is-danger.is-outlined {
|
|
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 {
|
|
value: user.uid
|
|
} [ user.login ]
|
|
|
|
permission-groups =
|
|
"read"
|
|
"post"
|
|
"edit"
|
|
"admin"
|
|
|
|
permissions-add = (self, permission, user-id) ->
|
|
perm-list = self.permissions[permission]
|
|
if perm-list
|
|
is-already-there = perm-list.find (e) -> (""+ e) == ("" + user-id)
|
|
if is-already-there
|
|
console.log "user #{user-id} already in #{perm-list}"
|
|
else
|
|
perm-list ++= [ parseInt(user-id) ]
|
|
self.permissions[permission] := perm-list
|
|
# console.log "adding user #{user-id} to #{perm-list[0]}: #{perm-list}"
|
|
else
|
|
console.log "Cannot find #{permission} permissions, creating it"
|
|
self.permissions[permission] := user-id
|
|
|
|
permission-to-form-selection = (self, permission) ->
|
|
h \option {
|
|
value: permission
|
|
} [ permission ]
|
|
|
|
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 ]
|
|
|
|
self = {
|
|
title: project.title || ""
|
|
permissions: project.permissions || {admin: [], edit: [], post: [], read: []}
|
|
|
|
tmp:
|
|
new-user-permission:
|
|
id: void
|
|
permission: permission-groups[0]
|
|
new-column-input:
|
|
title: "New column !"
|
|
users: users || []
|
|
|
|
extra_properties:
|
|
columns: columns-copy
|
|
}
|
|
|
|
modal = Modal {
|
|
+visible
|
|
content-render: (self) ->
|
|
h \div.form [
|
|
|
|
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
|
|
# }
|
|
# ]
|
|
|
|
h \hr []
|
|
|
|
h \aside.menu [
|
|
h \p.menu-label [ "Permissions" ]
|
|
h \ul.menu-list Object.keys(self.permissions).map (permission) ->
|
|
h \li {
|
|
key: "permission" + permission
|
|
} [
|
|
h \p self.permissions[permission].map (e, index) ->
|
|
if index == 0
|
|
"Permissions '" + permission + "': " + e + ", "
|
|
else
|
|
"" + e + ", "
|
|
]
|
|
]
|
|
|
|
h \hr []
|
|
|
|
h \p [ "Adding new user" ]
|
|
|
|
h \div.field.has-addons {
|
|
key: "adding-user"
|
|
} [
|
|
h \div.select.control [
|
|
h \select {
|
|
onchange: (e) ->
|
|
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) ->
|
|
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: ->
|
|
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
|
|
permissions-add self, self.tmp.new-user-permission.permission, self.tmp.new-user-permission.uid
|
|
} [ "+" ]
|
|
]
|
|
|
|
h \hr []
|
|
|
|
h \p [ "Choose the columns" ]
|
|
|
|
for dom in (self.extra_properties.columns.map (column) -> col-to-lines column, self)
|
|
dom
|
|
|
|
h \hr []
|
|
|
|
h \div.field.has-addons {
|
|
key: "adding-field"
|
|
} [
|
|
h \p.control.is-expanded [
|
|
h \input.input {
|
|
value: self.tmp.new-column-input.title
|
|
oninput: (e) ->
|
|
self.tmp.new-column-input.title := e.target.value
|
|
} [ ]
|
|
]
|
|
|
|
h \div.control.button.is-success.is-outlined {
|
|
onclick: ->
|
|
new-col = {
|
|
id: UUID!
|
|
title: self.tmp.new-column-input.title
|
|
}
|
|
self.extra_properties.columns ++= [ new-col ]
|
|
self.tmp.new-column-input.title := "New column !"
|
|
} [ "+" ]
|
|
]
|
|
]
|
|
|
|
on-validation: ->
|
|
tmp = delete self.tmp
|
|
if project.id
|
|
todod-ws.edit-list project.id, self
|
|
else
|
|
todod-ws.add-list self.title, self
|
|
self.tmp := tmp
|
|
}, self
|
|
|
|
self.render = ->
|
|
modal.render!
|
|
|
|
self
|
|
|
|
module.exports = ProjectCreationModal
|
|
|