-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRUD.red
73 lines (70 loc) · 1.55 KB
/
CRUD.red
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Red [
Title: "CRUD"
Number: 5
Author: @9214
Date: 29/10/2019
Needs: View
]
model: deep-reactor [
data: [
[name "Hans" surname "Emil"]
[name "Max" surname "Mustermann"]
[name "Roman" surname "Tisch"]
]
format: func [entry][rejoin [entry/name comma space entry/surname]]
construct: func [name surname][reduce ['name name 'surname surname]]
view: is [collect [foreach entry data [keep format entry]]]
]
system/view/VID/GUI-rules/active?: no
view [
title "CRUD"
text "Filter prefix:"
prefix: field
return
list: text-list 170x200
on-alt-down [face/selected: none]
on-change [
unless zero? face/selected [
face/extra: at model/data index? find/same
model/view
pick face/data face/selected
]
]
react [
database: model/data
face/data: sort collect [
forall database [
if any [
empty? prefix/text
find/match database/1/surname prefix/text
][
keep pick model/view index? database
]
]
]
if empty? face/data [face/selected: none]
]
panel [
text "Name:" name: field return
text "Surname:" surname: field return
]
return
button "Create" [
unless any [empty? name/text empty? surname/text][
append/only model/data model/construct
copy name/text
copy surname/text
]
]
update: button "Update" [
list/selected: none
foreach field [name surname][
unless empty? entry: select get field 'text [
list/extra/1/:field: copy entry
]
]
]
delete: button "Delete" [remove list/extra] react [
update/enabled?: delete/enabled?: make logic! list/selected
]
]