CXM_jquery_button.anubis
9.63 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* Created by PyramIDE.
* User: Jeremy
* Date: 07/09/2012
* Time: 15:10
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
read calexium_lib/web/CXM_making_a_web_site.anubis
read calexium_lib/web/CXM_jquery.anubis
read calexium_lib/web/CXM_jquery_icons.anubis
read tools/basis.anubis
read system/string.anubis
public type JQuery_button:
jQuery_button(
String button_id, String button_name, String button_label, JQuery_Actioner actioner, JQuery_icon primary, JQuery_icon secondary // primary icon is for left icon, secondary icon is for right icon and button_id must set with an unique ID in order to have icons working
)
.
define String
jquery_button_get_onclick_action_window_options
(
List(Other_Window_Option) options,
String formated_options
)
=
if options is
{
[ ] then formated_options,
[ h . t ] then
if h is
{
resizable then
if formated_options="" then // si c'est vide on ne prefixe pas avec une virgule
jquery_button_get_onclick_action_window_options(
t,
formated_options+"resizable='yes'"
)
else
jquery_button_get_onclick_action_window_options(
t,
formated_options+", resizable='yes'"
),
scrollbars then
if formated_options="" then // si c'est vide on ne prefixe pas avec une virgule
jquery_button_get_onclick_action_window_options(
t,
formated_options+"scrollbars='yes'"
)
else
jquery_button_get_onclick_action_window_options(
t,
formated_options+", scrollbars='yes'"
),
width(w) then
if formated_options="" then // si c'est vide on ne prefixe pas avec une virgule
jquery_button_get_onclick_action_window_options(
t,
formated_options+"width="+w
)
else
jquery_button_get_onclick_action_window_options(
t,
formated_options+", width="+w
),
height(h) then
if formated_options="" then // si c'est vide on ne prefixe pas avec une virgule
jquery_button_get_onclick_action_window_options(
t,
formated_options+"height="+h
)
else
jquery_button_get_onclick_action_window_options(
t,
formated_options+", height="+h
)
}
}
.
define HTML_Head_Tag
jquery_button_get_onclick_action
(
String button_id,
JQuery_Actioner actioner
)
=
if actioner is jQuery_actioner(target, act_type, str) then
if target is
{
same then
if act_type is
{
jqform then js_inline(script("", "$(document).ready(function(){$('#"+button_id+"').click(function(){$('#"+str+"').submit();});});")),
jqlink then js_inline(script("", "$(document).ready(function(){$('#"+button_id+"').click(function(){document.location='"+str+"';});});")),
},
same(label) then
if act_type is
{
jqform then js_inline(script("", "$(document).ready(function(){$('#"+button_id+"').click(function(){$('#"+str+"').submit();});});")),
jqlink then js_inline(script("", "$(document).ready(function(){$('#"+button_id+"').click(function(){document.location='"+str+"';});});")),
},
other(window_name, window_options) then
if act_type is
{
jqform then js_inline(script("", "$(document).ready(function(){$('#"+button_id+"').click(function(){$('#"+str+"').submit();});});")), //il s'agit d'une soumision d'un formulaire => cela se fait uniquement dans la même fenêtre !
jqlink then js_inline(script("", "$(document).ready(function(){$('#"+button_id+"').click(function(){window.open('"+str+"', '"+window_name+"', '"+jquery_button_get_onclick_action_window_options(window_options, "")+"');});});")),
}
}
.
define HTML_Partial_Content
_jquery_buttons
(
List(JQuery_button) buttons,
List(HTML_Head_Tag) html_tags,
List(HTML_Off_Form) html_buttons
)
=
if buttons is
{
[ ] then
partial_content(
reverse(html_tags),
sequence(reverse(html_buttons))
),
[ h . t ] then
if h is jQuery_button(id, name, label, actioner, primary, secondary) then
with onclick_action=jquery_button_get_onclick_action(id, actioner),
if id = "" then // if the ID is not set => we can't use icons in the buttonset.
_jquery_buttons(
t,
[ onclick_action . html_tags ],
[
literal("<input type=\"submit\" name=\""+name+"\" value=\""+label+"\">")
.
html_buttons
]
)
else
if jquery_icon_to_string(primary) = "" then
if jquery_icon_to_string(secondary) = "" then
_jquery_buttons(
t,
[
js_inline(script("", "$(document).ready(function(){$('#"+id+"').button();});")),
onclick_action
]
+html_tags,
[
literal("<input type=\"submit\" id=\""+id+"\" name=\""+name+"\" value=\""+label+"\">")
.
html_buttons
]
)
else
_jquery_buttons(
t,
[
js_inline(script("", "$(document).ready(function(){$('#"+id+"').button({icons:{secondary:'"+jquery_icon_to_string(secondary)+"'}});});")),
onclick_action
]
+html_tags,
[
literal("<button id=\""+id+"\">"+label+"</button>")
.
html_buttons
]
)
else
if jquery_icon_to_string(secondary) = "" then
_jquery_buttons(
t,
[
js_inline(script("", "$(document).ready(function(){$('#"+id+"').button({icons:{primary:'"+jquery_icon_to_string(primary)+"'}});});")),
onclick_action
]
+html_tags,
[
literal("<button id=\""+id+"\">"+label+"</button>")
.
html_buttons
]
)
else
_jquery_buttons(
t,
[
js_inline(script("", "$(document).ready(function(){$('#"+id+"').button({icons:{primary:'"+jquery_icon_to_string(primary)+"',secondary:'"+jquery_icon_to_string(secondary)+"'}});});")),
onclick_action
]
+html_tags,
[
literal("<button id=\""+id+"\">"+label+"</button>")
.
html_buttons
]
)
}
.
public define HTML_Partial_Content
jquery_buttons
(
String buttons_container_id,
List(JQuery_button) buttons
)
=
if _jquery_buttons(buttons, [], []) is partial_content(tags, html) then
partial_content(
[ js_inline(script("", "$(document).ready(function(){$('#"+buttons_container_id+"').buttonset();});")) ] + tags,
sequence([
literal("<div id=\""+buttons_container_id+"\">"),
html,
literal("</div>")
])
)
.
public define HTML_Partial_Content
jquery_button
(
JQuery_button button
)
=
if button is jQuery_button(id, name, label, actioner, primary, secondary) then
with onclick_action=jquery_button_get_onclick_action(id, actioner),
if jquery_icon_to_string(primary) = "" then
if jquery_icon_to_string(secondary) = "" then
partial_content(
[
js_inline(script("", "$(document).ready(function(){$('#"+id+"').button();});")),
onclick_action
],
literal("<input type=\"submit\" id=\""+id+"\" name=\""+name+"\" value=\""+label+"\">")
)
else
partial_content(
[
js_inline(script("", "$(document).ready(function(){$('#"+id+"').button({icons:{secondary:'"+jquery_icon_to_string(secondary)+"'}});});")),
onclick_action
],
literal("<button id=\""+id+"\">"+label+"</button>")
)
else
if jquery_icon_to_string(secondary) = "" then
partial_content(
[
js_inline(script("", "$(document).ready(function(){$('#"+id+"').button({icons:{primary:'"+jquery_icon_to_string(primary)+"'}});});")),
onclick_action
],
literal("<button id=\""+id+"\">"+label+"</button>")
)
else
partial_content(
[
js_inline(script("", "$(document).ready(function(){$('#"+id+"').button({icons:{primary:'"+jquery_icon_to_string(primary)+"',secondary:'"+jquery_icon_to_string(secondary)+"'}});});")),
onclick_action
],
literal("<button id=\""+id+"\">"+label+"</button>")
)
.