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