Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
a7644ef6
Commit
a7644ef6
authored
Mar 04, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement jQuery form handling functions into base template
parent
531e9be8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
3 deletions
+82
-3
default.volt
src/opnsense/mvc/app/views/layouts/default.volt
+3
-1
opnsense.js
src/opnsense/www/js/opnsense.js
+79
-2
No files found.
src/opnsense/mvc/app/views/layouts/default.volt
View file @
a7644ef6
...
@@ -30,8 +30,10 @@
...
@@ -30,8 +30,10 @@
xhr
.
setRequestHeader
(
"
X-CSRFTokenKey
"
,
"
{{ csrf_tokenKey }}
"
);
xhr
.
setRequestHeader
(
"
X-CSRFTokenKey
"
,
"
{{ csrf_tokenKey }}
"
);
}
}
});
});
</script>
</script>
<!-- OPNsense standard toolkit -->
<script
type=
"text/javascript"
src=
"/ui/js/opnsense.js"
></script>
</head>
</head>
<body>
<body>
<header
class=
"page-head"
>
<header
class=
"page-head"
>
...
...
src/opnsense/www/js/opnsense.js
View file @
a7644ef6
...
@@ -18,7 +18,11 @@ function getFormData(parent) {
...
@@ -18,7 +18,11 @@ function getFormData(parent) {
node
=
node
[
keyparts
[
i
]];
node
=
node
[
keyparts
[
i
]];
}
else
{
}
else
{
if
(
$
(
this
).
prop
(
"
type
"
)
==
"
checkbox
"
)
{
if
(
$
(
this
).
prop
(
"
type
"
)
==
"
checkbox
"
)
{
node
[
keyparts
[
i
]]
=
$
(
this
).
prop
(
"
checked
"
);
if
(
$
(
this
).
prop
(
"
checked
"
))
{
node
[
keyparts
[
i
]]
=
1
;
}
else
{
node
[
keyparts
[
i
]]
=
0
;
}
}
else
{
}
else
{
node
[
keyparts
[
i
]]
=
$
(
this
).
val
();
node
[
keyparts
[
i
]]
=
$
(
this
).
val
();
}
}
...
@@ -53,7 +57,12 @@ function setFormData(parent,data) {
...
@@ -53,7 +57,12 @@ function setFormData(parent,data) {
node
=
node
[
keyparts
[
i
]];
node
=
node
[
keyparts
[
i
]];
}
else
{
}
else
{
if
(
$
(
this
).
prop
(
"
type
"
)
==
"
checkbox
"
)
{
if
(
$
(
this
).
prop
(
"
type
"
)
==
"
checkbox
"
)
{
$
(
this
).
prop
(
"
checked
"
,
node
[
keyparts
[
i
]])
;
if
(
node
[
keyparts
[
i
]]
!=
0
)
{
$
(
this
).
prop
(
"
checked
"
,
true
)
;
}
else
{
$
(
this
).
prop
(
"
checked
"
,
false
)
;
}
}
else
{
}
else
{
$
(
this
).
val
(
node
[
keyparts
[
i
]]);
$
(
this
).
val
(
node
[
keyparts
[
i
]]);
}
}
...
@@ -61,3 +70,71 @@ function setFormData(parent,data) {
...
@@ -61,3 +70,71 @@ function setFormData(parent,data) {
}
}
});
});
}
}
/**
* handle form validations
* @param parent
* @param validationErrors
*/
function
handleFormValidation
(
parent
,
validationErrors
)
{
$
(
"
#
"
+
parent
+
"
input
"
).
each
(
function
(
index
)
{
if
(
validationErrors
!=
undefined
&&
$
(
this
).
attr
(
'
id
'
)
in
validationErrors
)
{
$
(
this
).
parent
().
addClass
(
"
has-error
"
);
$
(
"
span[for='
"
+
$
(
this
).
attr
(
'
id
'
)
+
"
']
"
).
text
(
validationErrors
[
$
(
this
).
attr
(
'
id
'
)]);
}
else
{
$
(
this
).
parent
().
removeClass
(
"
has-error
"
);
$
(
"
span[for='
"
+
$
(
this
).
attr
(
'
id
'
)
+
"
']
"
).
text
(
""
);
}
});
}
/**
* call remote function (post request), wrapper around standard jQuery lib.
* @param url endpoint url
* @param sendData input structure
* @param callback callback function
*/
function
ajaxCall
(
url
,
sendData
,
callback
)
{
$
.
ajax
({
type
:
"
POST
"
,
url
:
url
,
dataType
:
"
json
"
,
complete
:
function
(
data
,
status
)
{
if
(
callback
==
null
)
{
null
;
}
else
if
(
"
responseJSON
"
in
data
)
{
callback
(
data
[
'
responseJSON
'
],
status
);
}
else
{
callback
({},
status
);
}
},
data
:
sendData
});
}
/**
* retrieve json type data (GET request) from remote url
* @param url endpoint url
* @param sendData input structure
* @param callback callback function
*/
function
ajaxGet
(
url
,
sendData
,
callback
)
{
$
.
ajax
({
type
:
"
GET
"
,
url
:
url
,
dataType
:
"
json
"
,
complete
:
function
(
data
,
status
)
{
if
(
callback
==
null
)
{
null
;
}
else
if
(
"
responseJSON
"
in
data
)
{
callback
(
data
[
'
responseJSON
'
],
status
);
}
else
{
callback
({},
status
);
}
},
data
:
sendData
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment