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
b920a106
Commit
b920a106
authored
May 17, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
render all fields unrequired too. simple mark schema as circular.
parent
033e144f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
27 deletions
+60
-27
gadget_json_generated_form.js
gadget_json_generated_form.js
+19
-9
gadget_json_generated_form_child.js
gadget_json_generated_form_child.js
+41
-18
No files found.
gadget_json_generated_form.js
View file @
b920a106
...
@@ -149,8 +149,9 @@
...
@@ -149,8 +149,9 @@
}
}
}
}
function
loadJSONSchema
(
g
,
url
,
path
)
{
function
loadJSONSchema
(
g
,
$ref
,
path
)
{
var
protocol
,
var
protocol
,
url
,
download_url
,
download_url
,
hash
,
hash
,
schema_url_map
;
schema_url_map
;
...
@@ -158,7 +159,7 @@
...
@@ -158,7 +159,7 @@
if
(
!
path
)
{
if
(
!
path
)
{
path
=
"
/
"
;
path
=
"
/
"
;
}
}
url
=
convertUrlToAbsolute
(
g
,
path
,
url
,
window
.
location
);
url
=
convertUrlToAbsolute
(
g
,
path
,
$ref
,
window
.
location
);
download_url
=
url
.
origin
+
url
.
pathname
;
download_url
=
url
.
origin
+
url
.
pathname
;
schema_url_map
=
{
schema_url_map
=
{
"
http://json-schema.org/draft-04/schema
"
:
"
json-schema/schema4.json
"
,
"
http://json-schema.org/draft-04/schema
"
:
"
json-schema/schema4.json
"
,
...
@@ -219,7 +220,16 @@
...
@@ -219,7 +220,16 @@
}
}
schemaPushSchemaPart
(
g
.
props
.
schema
,
path
,
JSON
.
parse
(
JSON
.
stringify
(
schema_part
)));
schemaPushSchemaPart
(
g
.
props
.
schema
,
path
,
JSON
.
parse
(
JSON
.
stringify
(
schema_part
)));
// console.log(g.props.schema[""]);
// console.log(g.props.schema[""]);
return
schema_part
;
return
expandSchema
(
g
,
schema_part
,
path
,
$ref
);
})
.
push
(
function
(
schema_arr
)
{
// if length array > 1 form rendered on demand already
// so not needed circular detection
if
(
schema_arr
.
length
===
1
)
{
// XXX need smart circular detection in this place
schema_arr
[
0
].
circular
=
true
;
}
return
schema_arr
;
});
});
}
}
...
@@ -308,7 +318,7 @@
...
@@ -308,7 +318,7 @@
for
(
i
=
0
;
i
<
arr
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
arr
.
length
;
i
+=
1
)
{
for
(
z
=
0
;
z
<
arr
[
i
].
length
;
z
+=
1
)
{
for
(
z
=
0
;
z
<
arr
[
i
].
length
;
z
+=
1
)
{
if
(
arr
[
i
][
z
].
schema
===
true
)
{
if
(
arr
[
i
][
z
].
schema
===
true
)
{
// or(any, restricted, restricted) simplify to any
// or(any, restricted, restricted
, ..
) simplify to any
return
[
arr
[
i
][
z
]];
return
[
arr
[
i
][
z
]];
}
}
schema_arr
.
push
(
arr
[
i
][
z
]);
schema_arr
.
push
(
arr
[
i
][
z
]);
...
@@ -332,10 +342,7 @@
...
@@ -332,10 +342,7 @@
return
allOf
(
g
,
schema
.
allOf
,
schema_path
);
return
allOf
(
g
,
schema
.
allOf
,
schema_path
);
}
}
if
(
schema
.
$ref
)
{
if
(
schema
.
$ref
)
{
return
loadJSONSchema
(
g
,
schema
.
$ref
,
schema_path
)
return
loadJSONSchema
(
g
,
schema
.
$ref
,
schema_path
);
.
push
(
function
(
schema_part
)
{
return
expandSchema
(
g
,
schema_part
,
schema_path
,
schema
.
$ref
);
});
}
}
return
RSVP
.
Queue
()
return
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
...
@@ -527,7 +534,10 @@
...
@@ -527,7 +534,10 @@
var
schema_url
=
options
.
schema_url
||
var
schema_url
=
options
.
schema_url
||
(
options
.
value
&&
options
.
value
.
$schema
);
(
options
.
value
&&
options
.
value
.
$schema
);
if
(
schema_url
)
{
if
(
schema_url
)
{
return
loadJSONSchema
(
g
,
schema_url
);
return
loadJSONSchema
(
g
,
schema_url
)
.
push
(
function
(
schema_arr
)
{
return
schema_arr
[
0
].
schema
;
});
}
}
return
{};
return
{};
})
})
...
...
gadget_json_generated_form_child.js
View file @
b920a106
...
@@ -144,6 +144,7 @@
...
@@ -144,6 +144,7 @@
return
form_gadget
.
renderForm
({
return
form_gadget
.
renderForm
({
type
:
options
.
type
,
type
:
options
.
type
,
required
:
options
.
required
,
required
:
options
.
required
,
delete_button
:
options
.
delete_button
,
schema
:
options
.
schema_part
,
schema
:
options
.
schema_part
,
schema_path
:
options
.
schema_path
,
schema_path
:
options
.
schema_path
,
document
:
options
.
default_dict
,
document
:
options
.
default_dict
,
...
@@ -615,7 +616,7 @@
...
@@ -615,7 +616,7 @@
div
.
setAttribute
(
"
class
"
,
"
jsonformfield ui-field-contain
"
);
div
.
setAttribute
(
"
class
"
,
"
jsonformfield ui-field-contain
"
);
div
.
title
=
json_field
.
description
;
div
.
title
=
json_field
.
description
;
// if (key && !first_path) {
// if (key && !first_path) {
if
(
options
.
required
!
==
true
)
{
if
(
options
.
delete_button
=
==
true
)
{
delete_button
=
document
.
createElement
(
"
span
"
);
delete_button
=
document
.
createElement
(
"
span
"
);
delete_button
.
setAttribute
(
"
class
"
,
delete_button
.
setAttribute
(
"
class
"
,
"
ui-shadow-inset ui-btn ui-btn-inline ui-corner-all
"
+
"
ui-shadow-inset ui-btn ui-btn-inline ui-corner-all
"
+
...
@@ -623,11 +624,18 @@
...
@@ -623,11 +624,18 @@
gadget
.
props
.
delete_button
=
delete_button
;
gadget
.
props
.
delete_button
=
delete_button
;
div
.
appendChild
(
delete_button
);
div
.
appendChild
(
delete_button
);
}
else
if
(
options
.
top
!==
true
)
{
}
else
if
(
options
.
top
!==
true
)
{
delete_button
=
document
.
createElement
(
"
span
"
);
if
(
options
.
required
)
{
delete_button
.
setAttribute
(
"
class
"
,
delete_button
=
document
.
createElement
(
"
span
"
);
"
ui-shadow-inset ui-btn ui-btn-inline ui-corner-all
"
+
delete_button
.
setAttribute
(
"
class
"
,
"
ui-btn-icon-top ui-icon-btn ui-icon-circle
"
);
"
ui-shadow-inset ui-btn ui-btn-inline ui-corner-all
"
+
div
.
appendChild
(
delete_button
);
"
ui-btn-icon-top ui-icon-btn ui-icon-circle
"
);
div
.
appendChild
(
delete_button
);
}
else
{
delete_button
=
document
.
createElement
(
"
span
"
);
delete_button
.
innerHTML
=
"
 
"
;
div
.
appendChild
(
delete_button
);
}
}
}
if
(
false
)
{
if
(
false
)
{
// XXX;
// XXX;
...
@@ -856,20 +864,27 @@
...
@@ -856,20 +864,27 @@
if
(
properties
.
hasOwnProperty
(
key
))
{
if
(
properties
.
hasOwnProperty
(
key
))
{
schema_arr
=
properties
[
key
];
schema_arr
=
properties
[
key
];
s_o
=
schemaArrFilteredByDocument
(
schema_arr
,
default_dict
[
key
]);
s_o
=
schemaArrFilteredByDocument
(
schema_arr
,
default_dict
[
key
]);
if
(
required
.
indexOf
(
key
)
>=
0
&&
checkSchemaArrOneChoise
(
schema_arr
))
{
if
(
checkSchemaArrOneChoise
(
schema_arr
))
{
used_properties
[
key
]
=
false
;
if
(
required
.
indexOf
(
key
)
>=
0
)
{
q
.
push
(
render_field
.
bind
(
g
,
g
,
key
,
path
,
used_properties
[
key
]
=
false
;
s_o
.
schema
,
default_dict
[
key
],
root
,
s_o
.
schema_path
,
{
required
:
true
})
q
.
push
(
render_field
.
bind
(
g
,
g
,
key
,
path
,
);
s_o
.
schema
,
default_dict
[
key
],
root
,
s_o
.
schema_path
,
{
required
:
true
})
);
}
if
(
!
used_properties
.
hasOwnProperty
(
key
)
&&
!
schema_editor
&&
(
checkSchemaSimpleType
(
s_o
.
schema
)
||
!
s_o
.
circular
)
)
{
used_properties
[
key
]
=
false
;
q
.
push
(
render_field
.
bind
(
g
,
g
,
key
,
path
,
s_o
.
schema
,
default_dict
[
key
],
root
,
s_o
.
schema_path
,
{
required
:
false
,
delete_button
:
false
}));
}
}
}
if
(
!
used_properties
.
hasOwnProperty
(
key
)
&&
if
(
!
used_properties
.
hasOwnProperty
(
key
)
&&
(
default_dict
.
hasOwnProperty
(
key
)
||
default_dict
.
hasOwnProperty
(
key
))
{
(
!
schema_editor
&&
checkSchemaArrOneChoise
(
schema_arr
)
&&
s_o
.
schema
&&
checkSchemaSimpleType
(
s_o
.
schema
)
)
))
{
used_properties
[
key
]
=
""
;
used_properties
[
key
]
=
""
;
q
.
push
(
q
.
push
(
addSubForm
.
bind
(
g
,
{
addSubForm
.
bind
(
g
,
{
...
@@ -1338,6 +1353,13 @@
...
@@ -1338,6 +1353,13 @@
if
(
!
root
)
{
if
(
!
root
)
{
root
=
g
.
element
;
root
=
g
.
element
;
}
}
if
(
options
.
delete_button
===
undefined
)
{
if
(
options
.
top
)
{
options
.
delete_button
=
false
;
}
else
{
options
.
delete_button
=
!
options
.
required
;
}
}
while
(
root
.
firstChild
)
{
while
(
root
.
firstChild
)
{
root
.
removeChild
(
root
.
firstChild
);
root
.
removeChild
(
root
.
firstChild
);
}
}
...
@@ -1346,6 +1368,7 @@
...
@@ -1346,6 +1368,7 @@
{
{
type
:
options
.
type
,
type
:
options
.
type
,
required
:
options
.
required
,
required
:
options
.
required
,
delete_button
:
options
.
delete_button
,
top
:
options
.
top
top
:
options
.
top
})
})
.
push
(
function
()
{
.
push
(
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