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
Rafael Monnerat
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
Hide 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 @@
...
@@ -226,7 +226,10 @@
function
getFormValuesAsJSONDict
(
g
)
{
function
getFormValuesAsJSONDict
(
g
)
{
var
json_dict
=
{},
var
json_dict
=
{},
entry
,
entry
,
multi_level_dict
=
{};
multi_level_dict
=
{},
scope
,
subforms
=
g
.
props
.
subforms
,
queue
=
RSVP
.
Queue
();
g
.
props
.
inputs
.
forEach
(
function
(
input
)
{
g
.
props
.
inputs
.
forEach
(
function
(
input
)
{
if
(
input
.
value
!==
""
)
{
if
(
input
.
value
!==
""
)
{
if
(
input
.
type
===
'
number
'
)
{
if
(
input
.
type
===
'
number
'
)
{
...
@@ -264,13 +267,35 @@
...
@@ -264,13 +267,35 @@
}
}
}
}
for
(
entry
in
json_dict
)
{
function
recursiveGetContent
(
gadget
,
scope
)
{
if
(
json_dict
.
hasOwnProperty
(
entry
))
{
queue
convertOnMultiLevel
(
entry
,
json_dict
[
entry
],
multi_level_dict
);
.
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
multi_level_dict
;
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
)
{
function
validateForm
(
gadget
,
json_url
)
{
...
@@ -279,27 +304,30 @@
...
@@ -279,27 +304,30 @@
function
addSubForm
(
g
,
options
)
{
function
addSubForm
(
g
,
options
)
{
var
element
=
options
.
element
,
var
element
=
options
.
element
,
subform_json
=
options
.
schema_part
,
key
=
element
.
parentNode
.
querySelector
(
"
input[type='text']
"
).
value
,
input_text
=
element
.
parentNode
.
querySelector
(
"
input[type='text']
"
),
scope
=
element
.
name
+
"
/
"
+
key
;
div
=
document
.
createElement
(
"
div
"
),
label
;
if
(
input_text
.
value
===
""
)
{
if
(
!
key
||
g
.
props
.
subforms
.
hasOwnProperty
(
scope
)
)
{
return
false
;
return
false
;
}
}
div
.
setAttribute
(
"
class
"
,
"
slapos-parameter-dict-key
"
);
return
g
.
declareGadget
(
'
gadget_json_generated_form.html
'
,
{
scope
:
scope
})
label
=
document
.
createElement
(
"
label
"
);
.
push
(
function
(
form_gadget
)
{
label
.
textContent
=
input_text
.
value
;
var
div
=
document
.
createElement
(
"
div
"
),
label
.
setAttribute
(
"
class
"
,
"
slapos-parameter-dict-key
"
);
label
;
div
.
appendChild
(
label
);
div
=
render_subform
(
g
,
subform_json
,
{},
div
,
element
.
name
+
"
/
"
+
input_text
.
value
)
;
g
.
props
.
subforms
[
scope
]
=
form_gadget
;
element
.
parentNode
.
parentNode
.
insertBefore
(
div
,
element
.
parentNode
.
parentNode
.
children
[
1
]);
div
.
setAttribute
(
"
class
"
,
"
slapos-parameter-dict-key
"
);
// element.parentNode.parentNode.appendChild(div);
label
=
document
.
createElement
(
"
label
"
);
label
.
textContent
=
key
;
label
.
setAttribute
(
"
class
"
,
"
slapos-parameter-dict-key
"
);
div
.
appendChild
(
label
);
return
div
;
div
.
appendChild
(
form_gadget
.
element
);
element
.
parentNode
.
parentNode
.
insertBefore
(
div
,
element
.
parentNode
.
parentNode
.
children
[
1
]);
return
form_gadget
.
renderParameterForm
(
options
.
schema_part
,
{},
scope
);
});
}
}
function
loadEventList
(
gadget
)
{
function
loadEventList
(
gadget
)
{
...
@@ -344,6 +372,7 @@
...
@@ -344,6 +372,7 @@
.
ready
(
function
()
{
.
ready
(
function
()
{
var
g
=
this
;
var
g
=
this
;
g
.
props
=
{};
g
.
props
=
{};
g
.
options
=
{};
})
})
.
declareAcquiredMethod
(
"
notifyValid
"
,
"
notifyValid
"
)
.
declareAcquiredMethod
(
"
notifyValid
"
,
"
notifyValid
"
)
.
declareAcquiredMethod
(
"
notifyInvalid
"
,
"
notifyInvalid
"
)
.
declareAcquiredMethod
(
"
notifyInvalid
"
,
"
notifyInvalid
"
)
...
@@ -354,14 +383,38 @@
...
@@ -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
)
{
.
declareMethod
(
'
processValidation
'
,
function
(
schema_url
,
json_dict
)
{
var
g
=
this
;
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
)
{
if
(
!
json_dict
)
{
json_dict
=
getFormValuesAsJSONDict
(
g
);
json_dict
=
getFormValuesAsJSONDict
(
g
);
}
else
{
json_dict
=
RSVP
.
Queue
()
.
push
(
function
()
{
return
json_dict
;
});
}
}
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
return
RSVP
.
Queue
()
.
push
(
function
(
gadget
)
{
.
push
(
function
()
{
return
gadget
.
validateJSON
(
schema_url
,
json_dict
);
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
)
{
.
push
(
function
(
validation
)
{
var
error_index
,
var
error_index
,
...
@@ -402,11 +455,13 @@
...
@@ -402,11 +455,13 @@
});
});
})
})
.
declareMethod
(
'
renderParameterForm
'
,
function
(
schema
,
default_dict
)
{
.
declareMethod
(
'
renderParameterForm
'
,
function
(
schema
,
default_dict
,
path
)
{
var
g
=
this
,
var
g
=
this
,
parent_element
=
document
.
createDocumentFragment
();
parent_element
=
document
.
createDocumentFragment
();
g
.
props
.
inputs
=
[];
g
.
props
.
inputs
=
[];
g
.
props
.
add_buttons
=
[];
g
.
props
.
add_buttons
=
[];
g
.
props
.
subforms
=
{};
g
.
props
.
path
=
path
;
render_subform
(
g
,
schema
,
default_dict
,
parent_element
);
render_subform
(
g
,
schema
,
default_dict
,
parent_element
);
while
(
g
.
element
.
firstChild
)
{
while
(
g
.
element
.
firstChild
)
{
g
.
element
.
removeChild
(
g
.
element
.
firstChild
);
g
.
element
.
removeChild
(
g
.
element
.
firstChild
);
...
@@ -519,15 +574,15 @@
...
@@ -519,15 +574,15 @@
})
})
.
declareMethod
(
'
getContent
'
,
function
()
{
.
declareMethod
(
'
getContent
'
,
function
()
{
var
g
=
this
,
var
g
=
this
;
json_dict
=
getFormValuesAsJSONDict
(
g
);
return
getFormValuesAsJSONDict
(
g
);
return
g
.
processValidation
(
g
.
options
.
schema_url
,
json_dict
)
//
return g.processValidation(g.options.schema_url, json_dict)
.
push
(
function
(
status
)
{
//
.push(function (status) {
return
{
//
return {
value
:
json_dict
,
//
value: json_dict,
status
:
status
//
status: status
};
//
};
});
//
});
});
});
//.declareService(function () {
//.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