5
5
import div Panel and variable Presentation
6
6
7
7
div Editor
8
+ div Title
9
+ div Table
8
10
div Row
9
11
div Cell
10
- div Title
11
- table Table
12
- tr TR
13
- td TD
14
- span ItemNameSpan
15
12
input ItemNameInput
16
13
textarea TextArea
17
14
button EditButton
24
21
variable ItemNames
25
22
variable ItemName
26
23
variable SelectedItem
27
- variable Action
24
+ variable SavedIndex
28
25
variable Message
29
26
variable N
30
- variable B
27
+ variable NumItems
28
+ variable Content
31
29
32
30
put -1 into SelectedItem
33
31
@@ -44,7 +42,14 @@ Start:
44
42
45
43
Restart:
46
44
put property `content` of Presentation into Items
47
- put the json keys of Items into ItemNames
45
+ set ItemNames to array
46
+ put 0 into N
47
+ while N is less than the json count of Items
48
+ begin
49
+ put element N of Items into Item
50
+ json add property `name` of Item to ItemNames
51
+ add 1 to N
52
+ end
48
53
49
54
clear Panel
50
55
create Row in Panel
@@ -68,99 +73,89 @@ Restart:
68
73
go to Restart
69
74
end
70
75
71
- put the json keys of Items into ItemNames
72
- put the json count of ItemNames into N
73
- set the elements of ItemNameSpan to N
74
- set the elements of ItemNameInput to N
75
- set the elements of EditButton to N
76
- set the elements of Editor to N
77
- set the elements of SaveButton to N
78
- set the elements of DeleteItem to N
79
- set the elements of TextArea to N
76
+ put the json count of Items into NumItems
77
+ set the elements of EditButton to NumItems
78
+ set the elements of Editor to NumItems
79
+ set the elements of SaveButton to NumItems
80
+ set the elements of DeleteItem to NumItems
81
+ set the elements of ItemNameInput to NumItems
82
+ set the elements of TextArea to NumItems
80
83
create Table in Panel
81
84
set the style of Table to `width:100%`
82
- put 0 into B
83
- while B is less than the elements of EditButton
85
+ put 0 into N
86
+ while N is less than the elements of EditButton
84
87
begin
85
- index EditButton to B
86
- index DeleteItem to B
87
- index ItemNameSpan to B
88
- index ItemNameInput to B
89
- put element B of ItemNames into ItemName
90
- create TR in Table
91
- create TD in TR
92
- set the style of TD to `width:8em;border:1px solid black`
93
- index ItemNameSpan to B
94
- create ItemNameSpan in TD
95
- set the content of ItemNameSpan to ItemName
96
- index ItemNameInput to B
97
- create ItemNameInput in TD
98
- set the style of ItemNameInput to `width:100%;display:none`
99
- set the content of ItemNameInput to ItemName
100
- create TD in TR
101
- set the style of TD to `border:1px solid black`
102
- index Editor to B
103
- create Row in TD
104
- set the style of Row to `display:flex`
105
- create EditButton in Row
106
- set the style of EditButton to `flex:1`
107
- set the text of EditButton to `Edit`
88
+ index EditButton to N
89
+ index DeleteItem to N
90
+ index Editor to N
91
+ index ItemNameInput to N
92
+ put element N of Items into Item
93
+ put property `name` of Item into ItemName
94
+ create Row in Table
108
95
create Cell in Row
109
- set the style of Cell to `width:1.4em;text-align:center`
96
+ set the style of Cell to `width:100%;display:flex`
97
+ create EditButton in Cell
98
+ set the style of EditButton to `flex:1`
99
+ set the text of EditButton to ItemName
110
100
create Link in Cell
111
101
create DeleteItem in Link
112
- set the style of DeleteItem to `width:1em;margin-top :0.1em `
102
+ set the style of DeleteItem to `width:1em;margin:0.2em 0 0 0.2em `
113
103
set attribute `src` of DeleteItem to `/resources/icon/stop.png`
114
- create Editor in TD
115
- set the style of Editor to `display:none`
116
- add 1 to B
104
+ create Editor in Row
105
+ set the style of Editor to `margin:0.5em;border:1px solid black;padding:0.2em; display:none`
106
+ add 1 to N
117
107
end
118
108
on click EditButton
119
109
begin
120
- gosub to SaveSelectedItem
121
- put the index of EditButton into SelectedItem
122
- put the text of EditButton into Action
110
+ put the index of EditButton into SavedIndex
111
+ gosub to SaveSelectedItem
112
+ put SavedIndex into SelectedItem
123
113
put 0 into N
124
- while N is less than the json count of ItemNames
114
+ while N is less than NumItems
125
115
begin
126
- index EditButton to N
127
- set style `background` of EditButton to ``
128
- set the text of EditButton to `Edit`
129
- index ItemNameSpan to N
130
- index ItemNameInput to N
131
- set the content of ItemNameSpan to the text of ItemNameInput
132
- set style `display` of ItemNameSpan to `inline`
133
- set style `display` of ItemNameInput to `none`
134
- index Editor to N
135
- set style `display` of Editor to `none`
116
+ if N is not SelectedItem
117
+ begin
118
+ index EditButton to N
119
+ set style `background` of EditButton to ``
120
+ index Editor to N
121
+ set style `display` of Editor to `none`
122
+ clear Editor
123
+ end
136
124
add 1 to N
137
125
end
138
126
index EditButton to SelectedItem
139
- if Action is `Edit`
127
+ index ItemNameInput to SelectedItem
128
+ index TextArea to SelectedItem
129
+ index SaveButton to SelectedItem
130
+ index Editor to SelectedItem
131
+ if style `display` of Editor is `none`
140
132
begin
133
+ put element SelectedItem of Items into Item
141
134
set style `background` of EditButton to `lightgray`
142
- set the text of EditButton to `Close`
143
- index ItemNameSpan to SelectedItem
144
- index ItemNameInput to SelectedItem
145
- index TextArea to SelectedItem
146
- index SaveButton to SelectedItem
147
- set style `display` of ItemNameSpan to `none`
148
- set style `display` of ItemNameInput to `inline `
149
- index Editor to SelectedItem
135
+ create Row in Editor
136
+ set the style of Row to `display:flex`
137
+ create Cell in Row
138
+ set the style of Cell to `width:5em`
139
+ set the content of Cell to `Name`
140
+ create ItemNameInput in Row
141
+ set the style of ItemNameInput to `flex:1 `
142
+ set the text of ItemNameInput to property `name` of Item
150
143
set style `display` of Editor to `block`
151
- clear Editor
152
144
create TextArea in Editor
153
145
set the style of TextArea to `width:100%;max-width:100%;height:8em`
154
- put element SelectedItem of ItemNames into ItemName
155
- put property ItemName of Items into Item
156
- replace `%0a` with newline in Item
157
- set the content of TextArea to Item
146
+ put property `content` of Item into Content
147
+ replace `%0a` with newline in Content
148
+ set the content of TextArea to Content
158
149
create SaveButton in Editor
159
150
set the style of SaveButton to `width:100%`
160
151
set the text of SaveButton to `Save`
161
152
on click SaveButton gosub to SaveSelectedItem
162
153
end
163
- else gosub to SaveSelectedItem
154
+ else
155
+ begin
156
+ clear Editor
157
+ set style `display` of Editor to `none`
158
+ end
164
159
end
165
160
on click DeleteItem
166
161
begin
@@ -177,14 +172,15 @@ Restart:
177
172
SaveSelectedItem:
178
173
if SelectedItem is -1 return
179
174
index ItemNameInput to SelectedItem
175
+ index EditButton to SelectedItem
176
+ put element SelectedItem of Items into Item
177
+ set property `name` of Item to the text of ItemNameInput
178
+ set the text of EditButton to the text of ItemNameInput
180
179
index TextArea to SelectedItem
181
- put the content of TextArea into Item
182
- replace newline with `%0a` in Item
183
- set property ItemName of Items to Item
184
- if ItemNameInput is not ItemName json delete property ItemName of Items
185
- put ItemNameInput into ItemName
186
- set element SelectedItem of ItemNames to ItemName
187
- set property ItemName of Items to Item
180
+ put the content of TextArea into Content
181
+ replace newline with `%0a` in Content
182
+ set property `content` of Item to Content
183
+ set element SelectedItem of Items to Item
188
184
set property `content` of Presentation to Items
189
185
190
186
! Tell the parent to refresh the script
0 commit comments