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
3773f8e2
Commit
3773f8e2
authored
Aug 15, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rendering const field
parent
bb373146
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
5 deletions
+64
-5
jsonform/gadget_json_generated_form_child.js
jsonform/gadget_json_generated_form_child.js
+64
-5
No files found.
jsonform/gadget_json_generated_form_child.js
View file @
3773f8e2
...
@@ -5,6 +5,31 @@
...
@@ -5,6 +5,31 @@
"
use strict
"
;
"
use strict
"
;
var
render_object
;
var
render_object
;
function
deepEqual
(
x
,
y
)
{
if
(
x
===
y
)
{
return
true
;
}
if
((
typeof
x
===
"
object
"
&&
x
!==
null
)
&&
(
typeof
y
===
"
object
"
&&
y
!==
null
))
{
if
(
Object
.
keys
(
x
).
length
!==
Object
.
keys
(
y
).
length
)
{
return
false
;
}
var
prop
;
for
(
prop
in
x
)
{
if
(
x
.
hasOwnProperty
(
prop
))
{
if
(
y
.
hasOwnProperty
(
prop
))
{
if
(
!
deepEqual
(
x
[
prop
],
y
[
prop
]))
{
return
false
;
}
}
else
{
return
false
;
}
}
}
return
true
;
}
return
false
;
}
function
decodeJsonPointer
(
_str
)
{
function
decodeJsonPointer
(
_str
)
{
// https://tools.ietf.org/html/rfc6901#section-5
// https://tools.ietf.org/html/rfc6901#section-5
return
_str
.
replace
(
/~1/g
,
'
/
'
).
replace
(
/~0/g
,
'
~
'
);
return
_str
.
replace
(
/~1/g
,
'
/
'
).
replace
(
/~0/g
,
'
~
'
);
...
@@ -124,7 +149,7 @@
...
@@ -124,7 +149,7 @@
}
else
{
}
else
{
option
.
textContent
=
ser_value
;
option
.
textContent
=
ser_value
;
}
}
if
(
enum_arr
[
i
]
===
json_document
)
{
if
(
deepEqual
(
enum_arr
[
i
],
json_document
)
)
{
option
.
selected
=
true
;
option
.
selected
=
true
;
selected
=
true
;
selected
=
true
;
}
}
...
@@ -170,6 +195,19 @@
...
@@ -170,6 +195,19 @@
return
input
;
return
input
;
}
}
function
render_const
(
schema
,
json_document
)
{
var
input
=
document
.
createElement
(
"
input
"
),
ser_const
=
JSON
.
stringify
(
schema
.
const
);
input
.
setAttribute
(
'
readonly
'
,
true
);
if
(
deepEqual
(
json_document
,
schema
.
const
))
{
input
.
value
=
ser_const
;
}
else
{
input
.
value
=
JSON
.
stringify
(
json_document
)
+
'
≠
'
+
ser_const
;
input
.
setAttribute
(
'
data-const-value
'
,
ser_const
);
}
return
input
;
}
function
render_textarea
(
json_document
,
data_format
)
{
function
render_textarea
(
json_document
,
data_format
)
{
var
input
=
document
.
createElement
(
"
textarea
"
);
var
input
=
document
.
createElement
(
"
textarea
"
);
if
(
json_document
!==
undefined
)
{
if
(
json_document
!==
undefined
)
{
...
@@ -730,13 +768,16 @@
...
@@ -730,13 +768,16 @@
div_input
.
setAttribute
(
"
id
"
,
gadget
.
element
.
getAttribute
(
"
data-gadget-scope
"
)
+
first_path
+
'
/
'
);
div_input
.
setAttribute
(
"
id
"
,
gadget
.
element
.
getAttribute
(
"
data-gadget-scope
"
)
+
first_path
+
'
/
'
);
div_input
.
setAttribute
(
"
class
"
,
"
input
"
);
div_input
.
setAttribute
(
"
class
"
,
"
input
"
);
if
(
json_field
.
enum
!==
undefined
)
{
if
(
json_field
.
const
!==
undefined
)
{
input
=
render_const
(
json_field
,
default_value
);
type_changed
=
true
;
}
else
if
(
json_field
.
enum
!==
undefined
)
{
input
=
render_enum
(
json_field
,
default_value
);
input
=
render_enum
(
json_field
,
default_value
);
// XXX take in account existing type with enum
// XXX take in account existing type with enum
type_changed
=
false
;
type_changed
=
false
;
}
}
if
(
type
===
"
boolean
"
)
{
if
(
!
input
&&
type
===
"
boolean
"
)
{
input
=
render_boolean
(
json_field
,
default_value
);
input
=
render_boolean
(
json_field
,
default_value
);
}
}
...
@@ -789,7 +830,7 @@
...
@@ -789,7 +830,7 @@
}
}
}
}
if
(
type
===
"
array
"
)
{
if
(
!
input
&&
type
===
"
array
"
)
{
queue
=
render_array
(
queue
=
render_array
(
gadget
,
gadget
,
json_field
,
json_field
,
...
@@ -801,7 +842,7 @@
...
@@ -801,7 +842,7 @@
gadget
.
props
.
arrays
[
first_path
+
'
/
'
]
=
div
;
gadget
.
props
.
arrays
[
first_path
+
'
/
'
]
=
div
;
}
}
if
(
type
===
"
object
"
)
{
if
(
!
input
&&
type
===
"
object
"
)
{
queue
queue
.
push
(
function
()
{
.
push
(
function
()
{
return
render_object
(
return
render_object
(
...
@@ -1608,6 +1649,9 @@
...
@@ -1608,6 +1649,9 @@
var
link
=
evt
.
target
.
getAttribute
(
"
data-error-link
"
),
var
link
=
evt
.
target
.
getAttribute
(
"
data-error-link
"
),
button_list
=
this
.
props
.
add_buttons
,
button_list
=
this
.
props
.
add_buttons
,
field_list
=
this
.
props
.
inputs
,
input
,
changed
=
false
,
i
;
i
;
if
(
link
)
{
if
(
link
)
{
location
.
href
=
link
;
location
.
href
=
link
;
...
@@ -1619,6 +1663,21 @@
...
@@ -1619,6 +1663,21 @@
return
button_list
[
i
].
event
(
evt
);
return
button_list
[
i
].
event
(
evt
);
}
}
}
}
for
(
i
=
0
;
i
<
field_list
.
length
;
i
=
i
+
1
)
{
if
(
evt
.
target
===
field_list
[
i
])
{
input
=
evt
.
target
;
if
(
input
.
hasAttribute
(
'
data-const-value
'
))
{
input
.
value
=
input
.
getAttribute
(
'
data-const-value
'
);
input
.
setAttribute
(
'
data-origin-value
'
,
input
.
value
);
input
.
removeAttribute
(
'
data-const-value
'
);
changed
=
true
;
}
}
}
if
(
changed
)
{
return
this
.
rootNotifyChange
();
}
})
})
.
onEvent
(
'
input
'
,
function
(
evt
)
{
.
onEvent
(
'
input
'
,
function
(
evt
)
{
...
...
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