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
d13dae53
Commit
d13dae53
authored
Feb 28, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use job for listenEvents
parent
47f0cb25
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
25 deletions
+39
-25
gadget_json_generated_form.html
gadget_json_generated_form.html
+1
-2
gadget_json_generated_form.js
gadget_json_generated_form.js
+38
-23
No files found.
gadget_json_generated_form.html
View file @
d13dae53
...
...
@@ -5,6 +5,7 @@
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<title>
ERP5
</title>
<link
rel=
"shortcut icon"
href=
"favicon.ico"
>
<link
href=
"gadget_erp5_page_slap_parameter_form.css"
rel=
"stylesheet"
type=
"text/css"
/>
<script
src=
"rsvp.js"
type=
"text/javascript"
></script>
<script
src=
"renderjs.js"
type=
"text/javascript"
></script>
<script
src=
"jquery.js"
type=
"text/javascript"
></script>
...
...
@@ -12,8 +13,6 @@
<script
src=
"gadget_json_generated_form.js"
type=
"text/javascript"
></script>
</head>
<body>
<div>
</div>
<div
class=
"loadschema"
data-gadget-url=
"gadget_erp5_page_slap_load_schema.html"
data-gadget-scope=
"loadschema"
>
...
...
gadget_json_generated_form.js
View file @
d13dae53
...
...
@@ -82,7 +82,7 @@
return
input
;
}
function
render_subform
(
json_field
,
default_dict
,
root
,
path
)
{
function
render_subform
(
gadget
,
json_field
,
default_dict
,
root
,
path
)
{
var
div_input
,
key
,
div
,
...
...
@@ -137,6 +137,7 @@
label
.
setAttribute
(
"
class
"
,
"
slapos-parameter-dict-key
"
);
default_div
.
appendChild
(
label
);
default_div
=
render_subform
(
gadget
,
json_field
.
patternProperties
[
'
.*
'
],
default_dict
[
default_value
],
default_div
,
...
...
@@ -162,7 +163,9 @@
div_input
=
document
.
createElement
(
"
div
"
);
div_input
.
setAttribute
(
"
class
"
,
"
input
"
);
if
(
json_field
.
properties
[
key
].
type
===
'
object
'
)
{
div_input
=
render_subform
(
json_field
.
properties
[
key
],
div_input
=
render_subform
(
gadget
,
json_field
.
properties
[
key
],
default_dict
[
key
],
div_input
,
path
+
"
/
"
+
key
);
...
...
@@ -170,6 +173,7 @@
input
=
render_field
(
json_field
.
properties
[
key
],
default_dict
[
key
]);
input
.
name
=
path
+
"
/
"
+
key
;
input
.
setAttribute
(
"
class
"
,
"
slapos-parameter
"
);
gadget
.
props
.
inputs
.
push
(
input
);
div_input
.
appendChild
(
input
);
}
default_used_list
.
push
(
key
);
...
...
@@ -216,11 +220,11 @@
return
root
;
}
function
getFormValuesAsJSONDict
(
element
)
{
function
getFormValuesAsJSONDict
(
g
)
{
var
json_dict
=
{},
entry
,
multi_level_dict
=
{};
$
(
element
.
querySelectorAll
(
"
.slapos-parameter
"
)).
each
(
function
(
key
,
input
)
{
g
.
props
.
inputs
.
forEach
(
function
(
input
)
{
if
(
input
.
value
!==
""
)
{
if
(
input
.
type
===
'
number
'
)
{
json_dict
[
input
.
name
]
=
parseInt
(
input
.
value
,
10
);
...
...
@@ -270,7 +274,7 @@
return
gadget
.
processValidation
(
json_url
);
}
function
addSubForm
(
element
)
{
function
addSubForm
(
g
,
element
)
{
var
subform_json
=
JSON
.
parse
(
atob
(
element
.
value
)),
input_text
=
element
.
parentNode
.
querySelector
(
"
input[type='text']
"
),
div
=
document
.
createElement
(
"
div
"
),
...
...
@@ -286,7 +290,7 @@
label
.
setAttribute
(
"
class
"
,
"
slapos-parameter-dict-key
"
);
div
.
appendChild
(
label
);
div
=
render_subform
(
subform_json
,
{},
div
,
element
.
name
+
"
/
"
+
input_text
.
value
);
div
=
render_subform
(
g
,
subform_json
,
{},
div
,
element
.
name
+
"
/
"
+
input_text
.
value
);
element
.
parentNode
.
parentNode
.
insertBefore
(
div
,
element
.
parentNode
.
parentNode
.
children
[
1
]);
// element.parentNode.parentNode.appendChild(div);
...
...
@@ -296,7 +300,7 @@
function
loadEventList
(
gadget
)
{
var
g
=
gadget
,
field_list
=
g
.
element
.
querySelectorAll
(
"
.slapos-parameter
"
)
,
field_list
=
g
.
props
.
inputs
,
button_list
=
g
.
element
.
querySelectorAll
(
'
button.add-sub-form
'
),
label_list
=
g
.
element
.
querySelectorAll
(
'
label.slapos-parameter-dict-key
'
),
i
,
...
...
@@ -307,7 +311,7 @@
field_list
[
i
],
'
change
'
,
false
,
validateForm
.
bind
(
g
,
g
,
g
.
options
.
value
.
parameter
.
json
_url
)
validateForm
.
bind
(
g
,
g
,
g
.
options
.
schema
_url
)
));
}
...
...
@@ -316,23 +320,29 @@
button_list
[
i
],
'
click
'
,
false
,
addSubForm
.
bind
(
g
,
button_list
[
i
])
addSubForm
.
bind
(
g
,
g
,
button_list
[
i
])
));
}
for
(
i
=
0
;
i
<
label_list
.
length
;
i
=
i
+
1
)
{
promise_list
.
push
(
loopEventListener
(
label_list
[
i
],
'
click
'
,
false
,
collapseParameter
.
bind
(
g
,
label_list
[
i
])
));
}
//
for (i = 0; i < label_list.length; i = i + 1) {
//
promise_list.push(loopEventListener(
//
label_list[i],
//
'click',
//
false,
//
collapseParameter.bind(g, label_list[i])
//
));
//
}
return
RSVP
.
all
(
promise_list
);
}
rJS
(
window
)
.
ready
(
function
()
{
var
g
=
this
;
g
.
props
=
{};
})
.
declareAcquiredMethod
(
"
notifyValid
"
,
"
notifyValid
"
)
.
declareAcquiredMethod
(
"
notifyInvalid
"
,
"
notifyInvalid
"
)
.
declareMethod
(
"
loadJSONSchema
"
,
function
(
url
)
{
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
.
push
(
function
(
gadget
)
{
...
...
@@ -342,6 +352,9 @@
.
declareMethod
(
'
processValidation
'
,
function
(
schema_url
,
json_dict
)
{
var
g
=
this
;
if
(
!
json_dict
)
{
json_dict
=
getFormValuesAsJSONDict
(
g
);
}
return
this
.
getDeclaredGadget
(
'
loadschema
'
)
.
push
(
function
(
gadget
)
{
return
gadget
.
validateJSON
(
schema_url
,
json_dict
);
...
...
@@ -386,13 +399,15 @@
})
.
declareMethod
(
'
renderParameterForm
'
,
function
(
schema
,
default_dict
)
{
var
g
=
this
;
var
parent_element
=
document
.
createDocumentFragment
();
render_subform
(
schema
,
default_dict
,
parent_element
);
var
g
=
this
,
parent_element
=
document
.
createDocumentFragment
();
g
.
params
.
inputs
=
[];
render_subform
(
g
,
schema
,
default_dict
,
parent_element
);
while
(
g
.
element
.
firstChild
)
{
g
.
element
.
removeChild
(
g
.
element
.
firstChild
);
}
g
.
element
.
appendChild
(
parent_element
);
g
.
listenEvents
();
return
g
.
element
;
})
...
...
@@ -494,13 +509,13 @@
});
})
.
declare
Service
(
function
()
{
.
declare
Job
(
'
listenEvents
'
,
function
()
{
return
loadEventList
(
this
);
})
.
declareMethod
(
'
getContent
'
,
function
()
{
var
g
=
this
,
json_dict
=
getFormValuesAsJSONDict
(
g
.
element
);
json_dict
=
getFormValuesAsJSONDict
(
g
);
return
g
.
processValidation
(
g
.
options
.
schema_url
,
json_dict
)
.
push
(
function
(
status
)
{
return
{
...
...
@@ -527,4 +542,4 @@
// });
//});
}(
window
,
document
,
rJS
,
$
));
\ No newline at end of file
}(
window
,
document
,
rJS
,
$
,
loopEventListener
));
\ No newline at end of file
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