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
393ece50
Commit
393ece50
authored
Aug 28, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support if schema.items is array of schema
parent
8efcc991
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
29 deletions
+108
-29
jsonform/gadget_json_generated_form_child.js
jsonform/gadget_json_generated_form_child.js
+108
-29
No files found.
jsonform/gadget_json_generated_form_child.js
View file @
393ece50
...
...
@@ -286,6 +286,21 @@
});
}
function
expandItems
(
g
,
items
,
schema_path
,
minItems
)
{
if
(
!
(
items
instanceof
Array
))
{
return
g
.
expandSchema
(
items
,
schema_path
,
minItems
!==
0
);
}
var
i
,
tasks
=
[];
for
(
i
=
0
;
i
<
items
.
length
;
i
+=
1
)
{
tasks
.
push
(
g
.
expandSchema
(
items
[
i
],
schema_path
+
'
/
'
+
i
,
i
<
minItems
));
}
return
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
(
tasks
);
});
}
function
expandProperties
(
g
,
properties
,
schema_path
,
required
)
{
var
ret_obj
=
{};
return
RSVP
.
Queue
()
...
...
@@ -600,6 +615,7 @@
function
render_array
(
gadget
,
schema
,
json_document
,
div_input
,
path
,
schema_path
)
{
var
input
,
is_items_arr
=
schema
.
items
instanceof
Array
,
minItems
=
schema
.
minItems
||
0
;
if
(
schema
.
default
===
undefined
&&
json_document
===
undefined
)
{
...
...
@@ -622,20 +638,39 @@
// XXX add failback rendering if json_document not array
// input = render_textarea(schema, default_value, "array");
return
gadget
.
expandSchema
(
schema
.
items
,
schema_path
+
'
/items
'
,
minItems
!==
0
)
.
push
(
function
(
schema_arr
)
{
return
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
([
expandItems
(
gadget
,
schema
.
items
,
schema_path
+
'
/items
'
,
minItems
),
gadget
.
expandSchema
(
schema
.
additionalItems
,
schema_path
+
'
/additionalItems
'
,
false
)
]);
})
.
push
(
function
(
arr
)
{
var
queue
=
RSVP
.
Queue
(),
i
,
schema_path_item
=
schema_path
+
'
/items
'
,
schema_arr_arr
=
arr
[
0
],
additionalItems
=
arr
[
1
],
schema_arr
=
schema_arr_arr
,
len
=
0
;
// XXX rewrite loading document for anyOf schema
if
(
json_document
)
{
for
(
i
=
0
;
i
<
json_document
.
length
;
i
=
i
+
1
)
{
if
(
is_items_arr
)
{
if
(
i
<
schema_arr_arr
.
length
)
{
schema_arr
=
schema_arr_arr
[
i
];
schema_path_item
=
schema_path
+
'
/items/
'
+
i
;
}
else
{
schema_arr
=
additionalItems
;
schema_path_item
=
schema_path
+
'
/additionalItems
'
;
}
}
queue
.
push
(
addSubForm
.
bind
(
gadget
,
{
gadget
:
gadget
,
parent_type
:
'
array
'
,
schema_path
:
schema_path
+
'
/items
'
,
schema_path
:
schema_path
_item
,
schema_part
:
schema_arr
,
default_dict
:
json_document
[
i
],
required
:
i
<
minItems
...
...
@@ -646,34 +681,78 @@
len
=
json_document
.
length
;
}
if
(
checkSchemaArrOneChoise
(
schema_arr
)
&&
minItems
>
len
)
{
for
(
i
=
0
;
i
<
(
minItems
-
len
);
i
+=
1
)
{
queue
.
push
(
addSubForm
.
bind
(
gadget
,
{
gadget
:
gadget
,
parent_type
:
'
array
'
,
schema_path
:
schema_arr
[
0
].
schema_path
,
schema_part
:
schema_arr
[
0
].
schema
,
required
:
true
})
)
.
push
(
div_append
);
if
(
is_items_arr
)
{
if
(
minItems
>
len
)
{
for
(
i
;
i
<
(
minItems
-
len
);
i
+=
1
)
{
if
(
i
<
schema_arr_arr
.
length
)
{
schema_arr
=
schema_arr_arr
[
i
];
}
else
{
schema_arr
=
additionalItems
;
}
if
(
!
checkSchemaArrOneChoise
(
schema_arr
))
{
break
;
}
queue
.
push
(
addSubForm
.
bind
(
gadget
,
{
gadget
:
gadget
,
parent_type
:
'
array
'
,
schema_path
:
schema_arr
[
0
].
schema_path
,
schema_part
:
schema_arr
[
0
].
schema
,
required
:
true
})
)
.
push
(
div_append
);
}
}
if
(
i
<
schema_arr_arr
.
length
)
{
schema_arr
=
schema_arr_arr
[
i
];
}
else
{
schema_arr
=
additionalItems
;
}
// XXX rerender on next item in schema.items
queue
.
push
(
render_schema_selector
.
bind
(
gadget
,
gadget
,
"
add item to array
"
,
schema_arr
,
function
(
value
)
{
return
addSubForm
({
gadget
:
gadget
,
parent_type
:
'
array
'
,
type
:
value
.
type
,
schema_path
:
value
.
schema_path
,
schema_part
:
value
.
schema
})
.
push
(
element_append
);
}));
}
else
{
if
(
minItems
>
len
&&
checkSchemaArrOneChoise
(
schema_arr
))
{
for
(
i
=
0
;
i
<
(
minItems
-
len
);
i
+=
1
)
{
queue
.
push
(
addSubForm
.
bind
(
gadget
,
{
gadget
:
gadget
,
parent_type
:
'
array
'
,
schema_path
:
schema_arr
[
0
].
schema_path
,
schema_part
:
schema_arr
[
0
].
schema
,
required
:
true
})
)
.
push
(
div_append
);
}
}
}
queue
.
push
(
render_schema_selector
.
bind
(
gadget
,
gadget
,
"
add item to array
"
,
schema_arr
,
function
(
value
)
{
return
addSubForm
({
gadget
:
gadget
,
parent_type
:
'
array
'
,
type
:
value
.
type
,
schema_path
:
value
.
schema_path
,
schema_part
:
value
.
schema
})
.
push
(
element_append
);
}));
queue
.
push
(
render_schema_selector
.
bind
(
gadget
,
gadget
,
"
add item to array
"
,
schema_arr
,
function
(
value
)
{
return
addSubForm
({
gadget
:
gadget
,
parent_type
:
'
array
'
,
type
:
value
.
type
,
schema_path
:
value
.
schema_path
,
schema_part
:
value
.
schema
})
.
push
(
element_append
);
}));
}
return
queue
;
})
.
push
(
function
(
element
)
{
...
...
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