Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
ced823cd
Commit
ced823cd
authored
8 years ago
by
Deomid Ryabkov
Committed by
Cesanta Bot
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add a radio button to teh settins_panel example
PUBLISHED_FROM=2daba7380508df24d909f922c5009286b4d8e7cf
parent
79325bd2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/settings_panel_for_a_device/settings_panel.c
+10
-1
10 additions, 1 deletion
examples/settings_panel_for_a_device/settings_panel.c
examples/settings_panel_for_a_device/web_root/index.shtml
+6
-2
6 additions, 2 deletions
examples/settings_panel_for_a_device/web_root/index.shtml
with
16 additions
and
3 deletions
examples/settings_panel_for_a_device/settings_panel.c
+
10
−
1
View file @
ced823cd
...
@@ -8,11 +8,12 @@
...
@@ -8,11 +8,12 @@
struct
device_settings
{
struct
device_settings
{
char
setting1
[
100
];
char
setting1
[
100
];
char
setting2
[
100
];
char
setting2
[
100
];
char
setting3
[
4
];
};
};
static
const
char
*
s_http_port
=
"8000"
;
static
const
char
*
s_http_port
=
"8000"
;
static
struct
mg_serve_http_opts
s_http_server_opts
;
static
struct
mg_serve_http_opts
s_http_server_opts
;
static
struct
device_settings
s_settings
=
{
"value1"
,
"value2"
};
static
struct
device_settings
s_settings
=
{
"value1"
,
"value2"
,
""
};
static
void
handle_save
(
struct
mg_connection
*
nc
,
struct
http_message
*
hm
)
{
static
void
handle_save
(
struct
mg_connection
*
nc
,
struct
http_message
*
hm
)
{
/* Get form variables and store settings values */
/* Get form variables and store settings values */
...
@@ -20,7 +21,11 @@ static void handle_save(struct mg_connection *nc, struct http_message *hm) {
...
@@ -20,7 +21,11 @@ static void handle_save(struct mg_connection *nc, struct http_message *hm) {
sizeof
(
s_settings
.
setting1
));
sizeof
(
s_settings
.
setting1
));
mg_get_http_var
(
&
hm
->
body
,
"setting2"
,
s_settings
.
setting2
,
mg_get_http_var
(
&
hm
->
body
,
"setting2"
,
s_settings
.
setting2
,
sizeof
(
s_settings
.
setting2
));
sizeof
(
s_settings
.
setting2
));
mg_get_http_var
(
&
hm
->
body
,
"setting3"
,
s_settings
.
setting3
,
sizeof
(
s_settings
.
setting3
));
printf
(
"Settings updated to '%s' '%s' '%s'
\n
"
,
s_settings
.
setting1
,
s_settings
.
setting2
,
s_settings
.
setting3
);
/* Send response */
/* Send response */
mg_printf
(
nc
,
"HTTP/1.1 200 OK
\r\n
Content-Length: %lu
\r\n\r\n
%.*s"
,
mg_printf
(
nc
,
"HTTP/1.1 200 OK
\r\n
Content-Length: %lu
\r\n\r\n
%.*s"
,
(
unsigned
long
)
hm
->
body
.
len
,
(
int
)
hm
->
body
.
len
,
hm
->
body
.
p
);
(
unsigned
long
)
hm
->
body
.
len
,
(
int
)
hm
->
body
.
len
,
hm
->
body
.
p
);
...
@@ -31,6 +36,10 @@ static void handle_ssi_call(struct mg_connection *nc, const char *param) {
...
@@ -31,6 +36,10 @@ static void handle_ssi_call(struct mg_connection *nc, const char *param) {
mg_printf_html_escape
(
nc
,
"%s"
,
s_settings
.
setting1
);
mg_printf_html_escape
(
nc
,
"%s"
,
s_settings
.
setting1
);
}
else
if
(
strcmp
(
param
,
"setting2"
)
==
0
)
{
}
else
if
(
strcmp
(
param
,
"setting2"
)
==
0
)
{
mg_printf_html_escape
(
nc
,
"%s"
,
s_settings
.
setting2
);
mg_printf_html_escape
(
nc
,
"%s"
,
s_settings
.
setting2
);
}
else
if
(
strcmp
(
param
,
"setting3_is_one"
)
==
0
)
{
if
(
strcmp
(
s_settings
.
setting3
,
"one"
)
==
0
)
mg_printf
(
nc
,
"checked"
);
}
else
if
(
strcmp
(
param
,
"setting3_is_two"
)
==
0
)
{
if
(
strcmp
(
s_settings
.
setting3
,
"two"
)
==
0
)
mg_printf
(
nc
,
"checked"
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
examples/settings_panel_for_a_device/web_root/index.shtml
+
6
−
2
View file @
ced823cd
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<html
lang=
"en"
>
<html
lang=
"en"
>
<head>
<head>
<meta
charset=
"utf-8"
/>
<meta
charset=
"utf-8"
/>
<title>
RESTful API demo
</title>
<title>
ACMEtron 9000 - Settings
</title>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
/>
<style
type=
"text/css"
>
<style
type=
"text/css"
>
*
{
outline
:
none
;
}
*
{
outline
:
none
;
}
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
}
}
code
{
background
:
#eee
;
padding
:
0
0.3em
;
border-radius
:
0.2em
;
}
code
{
background
:
#eee
;
padding
:
0
0.3em
;
border-radius
:
0.2em
;
}
label
{
display
:
inline-block
;
min-width
:
5em
;
}
label
{
display
:
inline-block
;
min-width
:
5em
;
}
input
{
border
:
1px
solid
#ccc
;
padding
:
0.2em
;
margin-right
:
2em
;
}
input
[
type
=
"text"
]
{
border
:
1px
solid
#ccc
;
padding
:
0.2em
;
margin-right
:
2em
;
}
a
:link
,
a
:visited
{
color
:
#69c
;
text-decoration
:
none
;
}
a
:link
,
a
:visited
{
color
:
#69c
;
text-decoration
:
none
;
}
@media
(
max-width
:
900px
)
{
@media
(
max-width
:
900px
)
{
div
.content
{
width
:
auto
;
margin
:
2em
;
padding
:
1em
;
}
div
.content
{
width
:
auto
;
margin
:
2em
;
padding
:
1em
;
}
...
@@ -36,6 +36,7 @@
...
@@ -36,6 +36,7 @@
$
(
document
).
on
(
'
submit
'
,
'
#settings_form
'
,
function
()
{
$
(
document
).
on
(
'
submit
'
,
'
#settings_form
'
,
function
()
{
var
data
=
{};
var
data
=
{};
$
(
'
#settings_form [name]
'
).
each
(
function
(
index
,
el
)
{
$
(
'
#settings_form [name]
'
).
each
(
function
(
index
,
el
)
{
if
(
$
(
el
).
attr
(
'
type
'
)
==
'
radio
'
&&
!
$
(
el
).
is
(
'
:checked
'
))
return
;
data
[
$
(
el
).
attr
(
'
name
'
)]
=
$
(
el
).
val
();
data
[
$
(
el
).
attr
(
'
name
'
)]
=
$
(
el
).
val
();
});
});
$
(
'
#result
'
).
text
(
''
);
$
(
'
#result
'
).
text
(
''
);
...
@@ -91,6 +92,9 @@
...
@@ -91,6 +92,9 @@
name=
"setting1"
value=
"<!--#call setting1 -->"
>
name=
"setting1"
value=
"<!--#call setting1 -->"
>
<label>
Setting 2:
</label>
<input
type=
"text"
<label>
Setting 2:
</label>
<input
type=
"text"
name=
"setting2"
value=
"<!--#call setting2 -->"
>
name=
"setting2"
value=
"<!--#call setting2 -->"
>
<label>
Setting 3:
</label>
<input
type=
"radio"
name=
"setting3"
value=
"one"
<!
--#call
setting3_is_one
--
>
> One
<input
type=
"radio"
name=
"setting3"
value=
"two"
<!
--#call
setting3_is_two
--
>
> Two
</fieldset>
</fieldset>
<div
style=
"margin: 1em 0;"
>
<div
style=
"margin: 1em 0;"
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment