Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rjs_json_form
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
rjs_json_form
Commits
a1c5935c
Commit
a1c5935c
authored
Mar 02, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix getContent in subgadget mode and remove leading '//' in input.name
parent
94269625
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
42 deletions
+47
-42
gadget_json_generated_form.js
gadget_json_generated_form.js
+47
-42
No files found.
gadget_json_generated_form.js
View file @
a1c5935c
/*jslint nomen: true, maxlen: 200, indent: 2*/
/*global rJS,
console, window, document, RSVP, btoa, atob
, $, loopEventListener */
/*global rJS,
window, document, RSVP
, $, loopEventListener */
(
function
(
window
,
document
,
rJS
,
$
,
loopEventListener
)
{
"
use strict
"
;
...
...
@@ -49,9 +49,14 @@
span_info
,
span_error
,
input
,
first_path
,
queue
=
RSVP
.
Queue
();
// var input = document.createElement("input");
if
(
path
&&
key
)
{
first_path
=
path
+
key
;
}
else
{
first_path
=
""
;
}
div
=
document
.
createElement
(
"
div
"
);
div
.
setAttribute
(
"
class
"
,
"
subfield
"
);
...
...
@@ -87,7 +92,6 @@
}
else
{
input
=
document
.
createElement
(
"
input
"
);
if
(
default_value
!==
undefined
)
{
console
.
log
(
default_value
);
input
.
value
=
default_value
;
}
...
...
@@ -107,7 +111,7 @@
json_field
,
default_value
,
div_input
,
path
+
"
/
"
+
key
);
first_path
+
'
/
'
);
});
}
...
...
@@ -115,7 +119,7 @@
// object and array excluded from
// gadget.props.inputs not contain values
gadget
.
props
.
inputs
.
push
(
input
);
input
.
name
=
path
+
"
/
"
+
key
;
input
.
name
=
first_path
;
input
.
setAttribute
(
"
class
"
,
"
slapos-parameter
"
);
div_input
.
appendChild
(
input
);
}
...
...
@@ -226,37 +230,20 @@
}
function
getFormValuesAsJSONDict
(
g
)
{
var
json_dict
=
{},
entry
,
multi_level_dict
=
{},
var
multi_level_dict
=
{},
scope
,
subforms
=
g
.
props
.
subforms
,
queue
=
RSVP
.
Queue
();
g
.
props
.
inputs
.
forEach
(
function
(
input
)
{
if
(
input
.
value
!==
""
)
{
if
(
input
.
type
===
'
number
'
)
{
json_dict
[
input
.
name
]
=
parseInt
(
input
.
value
,
10
);
}
else
if
(
input
.
value
===
"
true
"
)
{
json_dict
[
input
.
name
]
=
true
;
}
else
if
(
input
.
value
===
"
false
"
)
{
json_dict
[
input
.
name
]
=
false
;
}
else
if
(
input
.
tagName
===
"
TEXTAREA
"
)
{
if
(
input
[
"
data-format
"
]
===
"
string
"
)
{
json_dict
[
input
.
name
]
=
input
.
value
;
}
else
{
json_dict
[
input
.
name
]
=
input
.
value
.
split
(
'
\n
'
);
}
}
else
{
json_dict
[
input
.
name
]
=
input
.
value
;
}
}
});
function
convertOnMultiLevel
(
key
,
value
,
d
)
{
var
i
,
function
convertOnMultiLevel
(
d
,
key
,
value
)
{
var
orig_d
=
d
,
i
,
kk
,
key_list
=
key
.
split
(
"
/
"
);
for
(
i
=
2
;
i
<
key_list
.
length
;
i
+=
1
)
{
if
(
key
===
""
)
{
return
value
;
}
for
(
i
=
1
;
i
<
key_list
.
length
;
i
+=
1
)
{
kk
=
key_list
[
i
];
if
(
i
===
key_list
.
length
-
1
)
{
d
[
kk
]
=
value
;
...
...
@@ -267,6 +254,7 @@
d
=
d
[
kk
];
}
}
return
orig_d
;
}
function
recursiveGetContent
(
gadget
,
scope
)
{
...
...
@@ -275,11 +263,7 @@
return
gadget
.
getContent
();
})
.
push
(
function
(
jdict
)
{
for
(
entry
in
jdict
)
{
if
(
jdict
.
hasOwnProperty
(
entry
))
{
convertOnMultiLevel
(
scope
+
'
/
'
+
entry
,
jdict
[
entry
],
multi_level_dict
);
}
}
convertOnMultiLevel
(
multi_level_dict
,
scope
,
jdict
);
});
}
...
...
@@ -291,9 +275,30 @@
return
queue
.
push
(
function
()
{
for
(
entry
in
json_dict
)
{
if
(
json_dict
.
hasOwnProperty
(
entry
))
{
convertOnMultiLevel
(
entry
,
json_dict
[
entry
],
multi_level_dict
);
var
json_dict
=
{},
key
;
g
.
props
.
inputs
.
forEach
(
function
(
input
)
{
if
(
input
.
name
===
""
||
input
.
value
!==
""
)
{
if
(
input
.
type
===
'
number
'
)
{
json_dict
[
input
.
name
]
=
parseInt
(
input
.
value
,
10
);
}
else
if
(
input
.
value
===
"
true
"
)
{
json_dict
[
input
.
name
]
=
true
;
}
else
if
(
input
.
value
===
"
false
"
)
{
json_dict
[
input
.
name
]
=
false
;
}
else
if
(
input
.
tagName
===
"
TEXTAREA
"
)
{
if
(
input
[
"
data-format
"
]
===
"
string
"
)
{
json_dict
[
input
.
name
]
=
input
.
value
;
}
else
{
json_dict
[
input
.
name
]
=
input
.
value
.
split
(
'
\n
'
);
}
}
else
{
json_dict
[
input
.
name
]
=
input
.
value
;
}
}
});
for
(
key
in
json_dict
)
{
if
(
json_dict
.
hasOwnProperty
(
key
))
{
multi_level_dict
=
convertOnMultiLevel
(
multi_level_dict
,
key
,
json_dict
[
key
]);
}
}
return
multi_level_dict
;
...
...
@@ -304,7 +309,7 @@
var
element
=
options
.
element
,
key
=
options
.
key
||
element
.
parentNode
.
querySelector
(
"
input[type='text']
"
).
value
,
scope
=
(
options
.
path
||
element
.
name
)
+
"
/
"
+
key
;
scope
=
(
options
.
path
||
element
.
name
)
+
key
;
if
(
!
key
||
g
.
props
.
subforms
.
hasOwnProperty
(
scope
))
{
return
false
;
...
...
@@ -430,7 +435,7 @@
for
(
error_index
in
validation
.
errors
)
{
if
(
validation
.
errors
.
hasOwnProperty
(
error_index
))
{
field_name
=
validation
.
errors
[
error_index
].
dataPath
;
div
=
$
(
"
.slapos-parameter[name='
/
"
+
field_name
+
"
']
"
)[
0
].
parentNode
;
div
=
$
(
"
.slapos-parameter[name='
"
+
field_name
+
"
']
"
)[
0
].
parentNode
;
div
.
setAttribute
(
"
class
"
,
"
slapos-parameter error-input
"
);
div
.
querySelector
(
"
span.error
"
).
textContent
=
validation
.
errors
[
error_index
].
message
;
}
...
...
@@ -439,7 +444,7 @@
for
(
missing_index
in
validation
.
missing
)
{
if
(
validation
.
missing
.
hasOwnProperty
(
missing_index
))
{
missing_field_name
=
validation
.
missing
[
missing_index
].
dataPath
;
divm
=
$
(
'
.slapos-parameter[name=
/
'
+
missing_field_name
+
"
']
"
)[
0
].
parentNode
;
divm
=
$
(
'
.slapos-parameter[name=
'
+
missing_field_name
+
"
']
"
)[
0
].
parentNode
;
divm
.
setAttribute
(
"
class
"
,
"
error-input
"
);
divm
.
querySelector
(
"
span.error
"
).
textContent
=
validation
.
missing
[
missing_index
].
message
;
}
...
...
@@ -453,7 +458,7 @@
g
.
props
.
inputs
=
[];
g
.
props
.
add_buttons
=
[];
g
.
props
.
subforms
=
{};
g
.
props
.
path
=
path
;
g
.
props
.
path
=
path
;
// self gadget scope
if
(
key
===
undefined
)
{
key
=
""
;
}
...
...
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