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
Jérome Perrin
rjs_json_form
Commits
fe719311
Commit
fe719311
authored
Feb 28, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
recursive gadget declaration for complex json document generation
parent
9ba0bebd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
32 deletions
+87
-32
gadget_json_generated_form.js
gadget_json_generated_form.js
+87
-32
No files found.
gadget_json_generated_form.js
View file @
fe719311
...
...
@@ -226,7 +226,10 @@
function
getFormValuesAsJSONDict
(
g
)
{
var
json_dict
=
{},
entry
,
multi_level_dict
=
{};
multi_level_dict
=
{},
scope
,
subforms
=
g
.
props
.
subforms
,
queue
=
RSVP
.
Queue
();
g
.
props
.
inputs
.
forEach
(
function
(
input
)
{
if
(
input
.
value
!==
""
)
{
if
(
input
.
type
===
'
number
'
)
{
...
...
@@ -264,13 +267,35 @@
}
}
function
recursiveGetContent
(
gadget
,
scope
)
{
queue
.
push
(
function
()
{
return
gadget
.
getContent
();
})
.
push
(
function
(
jdict
)
{
for
(
entry
in
jdict
)
{
if
(
jdict
.
hasOwnProperty
(
entry
))
{
convertOnMultiLevel
(
scope
+
'
/
'
+
entry
,
jdict
[
entry
],
multi_level_dict
);
}
}
});
}
for
(
scope
in
subforms
)
{
if
(
subforms
.
hasOwnProperty
(
scope
))
{
recursiveGetContent
(
subforms
[
scope
],
scope
);
}
}
return
queue
.
push
(
function
()
{
for
(
entry
in
json_dict
)
{
if
(
json_dict
.
hasOwnProperty
(
entry
))
{
convertOnMultiLevel
(
entry
,
json_dict
[
entry
],
multi_level_dict
);
}
}
return
multi_level_dict
;
});
}
function
validateForm
(
gadget
,
json_url
)
{
...
...
@@ -279,27 +304,30 @@
function
addSubForm
(
g
,
options
)
{
var
element
=
options
.
element
,
subform_json
=
options
.
schema_part
,
input_text
=
element
.
parentNode
.
querySelector
(
"
input[type='text']
"
),
div
=
document
.
createElement
(
"
div
"
),
label
;
key
=
element
.
parentNode
.
querySelector
(
"
input[type='text']
"
).
value
,
scope
=
element
.
name
+
"
/
"
+
key
;
if
(
input_text
.
value
===
""
)
{
if
(
!
key
||
g
.
props
.
subforms
.
hasOwnProperty
(
scope
)
)
{
return
false
;
}
return
g
.
declareGadget
(
'
gadget_json_generated_form.html
'
,
{
scope
:
scope
})
.
push
(
function
(
form_gadget
)
{
var
div
=
document
.
createElement
(
"
div
"
),
label
;
g
.
props
.
subforms
[
scope
]
=
form_gadget
;
div
.
setAttribute
(
"
class
"
,
"
slapos-parameter-dict-key
"
);
label
=
document
.
createElement
(
"
label
"
);
label
.
textContent
=
input_text
.
value
;
label
.
textContent
=
key
;
label
.
setAttribute
(
"
class
"
,
"
slapos-parameter-dict-key
"
);
div
.
appendChild
(
label
);
div
=
render_subform
(
g
,
subform_json
,
{},
div
,
element
.
name
+
"
/
"
+
input_text
.
value
);
div
.
appendChild
(
form_gadget
.
element
);
element
.
parentNode
.
parentNode
.
insertBefore
(
div
,
element
.
parentNode
.
parentNode
.
children
[
1
]);
// element.parentNode.parentNode.appendChild(div);
return
div
;
return
form_gadget
.
renderParameterForm
(
options
.
schema_part
,
{},
scope
);
});
}
function
loadEventList
(
gadget
)
{
...
...
@@ -344,6 +372,7 @@
.
ready
(
function
()
{
var
g
=
this
;
g
.
props
=
{};
g
.
options
=
{};
})
.
declareAcquiredMethod
(
"
notifyValid
"
,
"
notifyValid
"
)
.
declareAcquiredMethod
(
"
notifyInvalid
"
,
"
notifyInvalid
"
)
...
...
@@ -354,14 +383,38 @@
});
})
.
declareAcquiredMethod
(
"
processValidationParent
"
,
"
processValidation
"
)
.
allowPublicAcquisition
(
"
processValidation
"
,
function
(
json_dict
)
{
return
this
.
processValidation
(
undefined
,
json_dict
);
})
.
declareMethod
(
'
processValidation
'
,
function
(
schema_url
,
json_dict
)
{
var
g
=
this
;
if
(
!
schema_url
)
{
if
(
!
g
.
options
.
schema_url
)
{
return
g
.
processValidationParent
(
json_dict
);
}
else
{
schema_url
=
g
.
options
.
schema_url
;
}
}
if
(
!
json_dict
)
{
json_dict
=
getFormValuesAsJSONDict
(
g
);
}
else
{
json_dict
=
RSVP
.
Queue
()
.
push
(
function
()
{
return
json_dict
;
});
}
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
.
push
(
function
(
gadget
)
{
return
gadget
.
validateJSON
(
schema_url
,
json_dict
);
return
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
([
g
.
getDeclaredGadget
(
'
loadschema
'
),
json_dict
])
})
.
push
(
function
(
ret
)
{
var
loadschema_gadget
=
ret
[
0
],
json_dict
=
ret
[
1
];
return
loadschema_gadget
.
validateJSON
(
schema_url
,
json_dict
);
})
.
push
(
function
(
validation
)
{
var
error_index
,
...
...
@@ -402,11 +455,13 @@
});
})
.
declareMethod
(
'
renderParameterForm
'
,
function
(
schema
,
default_dict
)
{
.
declareMethod
(
'
renderParameterForm
'
,
function
(
schema
,
default_dict
,
path
)
{
var
g
=
this
,
parent_element
=
document
.
createDocumentFragment
();
g
.
props
.
inputs
=
[];
g
.
props
.
add_buttons
=
[];
g
.
props
.
subforms
=
{};
g
.
props
.
path
=
path
;
render_subform
(
g
,
schema
,
default_dict
,
parent_element
);
while
(
g
.
element
.
firstChild
)
{
g
.
element
.
removeChild
(
g
.
element
.
firstChild
);
...
...
@@ -519,15 +574,15 @@
})
.
declareMethod
(
'
getContent
'
,
function
()
{
var
g
=
this
,
json_dict
=
getFormValuesAsJSONDict
(
g
);
return
g
.
processValidation
(
g
.
options
.
schema_url
,
json_dict
)
.
push
(
function
(
status
)
{
return
{
value
:
json_dict
,
status
:
status
};
});
var
g
=
this
;
return
getFormValuesAsJSONDict
(
g
);
//
return g.processValidation(g.options.schema_url, json_dict)
//
.push(function (status) {
//
return {
//
value: json_dict,
//
status: status
//
};
//
});
});
//.declareService(function () {
...
...
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