Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
erp5
Commits
d64711d5
Commit
d64711d5
authored
Jun 18, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_json_form: 'urn:jio:reference?' url schema supported
parent
8d3adfd6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
18 deletions
+66
-18
bt5/erp5_json_form/SkinTemplateItem/portal_skins/erp5_json_form/jsonform.gadget.js.js
...ateItem/portal_skins/erp5_json_form/jsonform.gadget.js.js
+65
-17
bt5/erp5_json_form/SkinTemplateItem/portal_skins/erp5_json_form/jsonform.gadget.js.xml
...teItem/portal_skins/erp5_json_form/jsonform.gadget.js.xml
+1
-1
No files found.
bt5/erp5_json_form/SkinTemplateItem/portal_skins/erp5_json_form/jsonform.gadget.js.js
View file @
d64711d5
...
@@ -5,6 +5,36 @@
...
@@ -5,6 +5,36 @@
"
use strict
"
;
"
use strict
"
;
var
expandSchema
;
var
expandSchema
;
function
URLwithJio
(
url
,
base_url
)
{
var
urn_prefix
,
pathname
,
fake_prefix
=
"
https://jio_urn_prefix/
"
;
// XXX urn: can any case
if
(
url
.
startsWith
(
"
urn:jio:reference?
"
))
{
urn_prefix
=
url
.
indexOf
(
"
?
"
)
+
1
;
urn_prefix
=
url
.
slice
(
0
,
urn_prefix
);
url
=
fake_prefix
+
decodeURIComponent
(
url
.
replace
(
urn_prefix
,
""
));
}
if
(
typeof
base_url
===
"
string
"
&&
base_url
.
startsWith
(
"
urn:jio:reference?
"
))
{
if
(
!
urn_prefix
)
{
urn_prefix
=
base_url
.
indexOf
(
"
?
"
)
+
1
;
urn_prefix
=
base_url
.
slice
(
0
,
urn_prefix
);
}
base_url
=
fake_prefix
+
decodeURIComponent
(
base_url
.
replace
(
urn_prefix
,
""
));
}
url
=
new
URL
(
url
,
base_url
);
if
(
urn_prefix
)
{
pathname
=
url
.
pathname
.
slice
(
1
);
return
{
href
:
urn_prefix
+
encodeURIComponent
(
pathname
+
url
.
search
+
url
.
hash
),
origin
:
urn_prefix
,
pathname
:
encodeURIComponent
(
pathname
),
hash
:
url
.
hash
};
}
return
url
;
}
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
,
'
~
'
);
...
@@ -87,9 +117,9 @@
...
@@ -87,9 +117,9 @@
base_url
=
convertToRealWorldSchemaPath
(
g
,
path
),
base_url
=
convertToRealWorldSchemaPath
(
g
,
path
),
absolute_url
;
absolute_url
;
if
(
base_url
===
""
||
base_url
.
indexOf
(
"
#
"
)
===
0
)
{
if
(
base_url
===
""
||
base_url
.
indexOf
(
"
#
"
)
===
0
)
{
absolute_url
=
new
URL
(
url
,
base_url_failback
);
absolute_url
=
URLwithJio
(
url
,
base_url_failback
);
}
else
{
}
else
{
absolute_url
=
new
URL
(
url
,
base_url
);
absolute_url
=
URLwithJio
(
url
,
base_url
);
}
}
return
absolute_url
;
return
absolute_url
;
}
}
...
@@ -154,7 +184,8 @@
...
@@ -154,7 +184,8 @@
url
,
url
,
download_url
,
download_url
,
hash
,
hash
,
schema_url_map
;
schema_url_map
,
queue
;
// XXX need use `id` property
// XXX need use `id` property
if
(
!
path
)
{
if
(
!
path
)
{
path
=
"
/
"
;
path
=
"
/
"
;
...
@@ -179,7 +210,18 @@
...
@@ -179,7 +210,18 @@
}
}
hash
=
url
.
hash
;
hash
=
url
.
hash
;
url
=
url
.
href
;
url
=
url
.
href
;
return
downloadJSON
(
download_url
)
if
(
download_url
.
startsWith
(
"
urn:jio:
"
))
{
queue
=
RSVP
.
Queue
()
.
push
(
function
()
{
return
g
.
downloadJSON
(
download_url
);
});
}
else
{
queue
=
RSVP
.
Queue
()
.
push
(
function
()
{
return
downloadJSON
(
download_url
);
});
}
return
queue
.
push
(
function
(
json
)
{
.
push
(
function
(
json
)
{
checkCircular
(
g
,
path
,
url
);
checkCircular
(
g
,
path
,
url
);
return
resolveLocalReference
(
json
,
hash
);
return
resolveLocalReference
(
json
,
hash
);
...
@@ -192,9 +234,9 @@
...
@@ -192,9 +234,9 @@
schema_a
=
document
.
createElement
(
"
a
"
),
schema_a
=
document
.
createElement
(
"
a
"
),
pointed_a
=
document
.
createElement
(
"
a
"
);
pointed_a
=
document
.
createElement
(
"
a
"
);
schema_a
.
setAttribute
(
"
href
"
,
download_url
);
schema_a
.
setAttribute
(
"
href
"
,
download_url
);
schema_a
.
text
=
(
new
URL
(
download_url
)).
pathname
;
schema_a
.
text
=
(
URLwithJio
(
download_url
)).
pathname
;
pointed_a
.
setAttribute
(
"
href
"
,
url_from_pointed
);
pointed_a
.
setAttribute
(
"
href
"
,
url_from_pointed
);
pointed_a
.
text
=
(
new
URL
(
url_from_pointed
)).
pathname
;
pointed_a
.
text
=
(
URLwithJio
(
url_from_pointed
)).
pathname
;
g
.
props
.
schema_resolve_errors
[
url_from_pointed
]
=
{
g
.
props
.
schema_resolve_errors
[
url_from_pointed
]
=
{
schemaPath
:
path
,
schemaPath
:
path
,
message
:
[
message
:
[
...
@@ -373,6 +415,7 @@
...
@@ -373,6 +415,7 @@
g
.
props
=
{};
g
.
props
=
{};
g
.
options
=
{};
g
.
options
=
{};
})
})
.
declareAcquiredMethod
(
"
downloadJSON
"
,
"
downloadJSON
"
)
.
declareAcquiredMethod
(
"
notifyChange
"
,
"
notifyChange
"
)
.
declareAcquiredMethod
(
"
notifyChange
"
,
"
notifyChange
"
)
.
allowPublicAcquisition
(
"
notifyChange
"
,
function
()
{
.
allowPublicAcquisition
(
"
notifyChange
"
,
function
()
{
return
this
.
notifyChange
();
return
this
.
notifyChange
();
...
@@ -500,14 +543,19 @@
...
@@ -500,14 +543,19 @@
.
declareMethod
(
'
render
'
,
function
(
options
)
{
.
declareMethod
(
'
render
'
,
function
(
options
)
{
return
this
.
changeState
({
return
this
.
changeState
({
key
:
options
.
key
,
key
:
options
.
key
,
value
:
options
.
value
||
""
,
value
:
JSON
.
stringify
(
options
.
value
)
||
'
""
'
,
schema
:
options
.
schema
,
schema
:
JSON
.
stringify
(
options
.
schema
)
,
schema_url
:
options
.
schema_url
,
schema_url
:
options
.
schema_url
,
editable
:
options
.
editable
===
undefined
?
true
:
options
.
editable
editable
:
options
.
editable
===
undefined
?
true
:
options
.
editable
});
});
})
})
.
onStateChange
(
function
(
options
)
{
.
onStateChange
(
function
()
{
var
g
=
this
;
var
g
=
this
,
json_document
=
JSON
.
parse
(
g
.
state
.
value
),
schema
;
if
(
g
.
state
.
schema
!==
undefined
)
{
schema
=
JSON
.
parse
(
g
.
state
.
schema
);
}
g
.
props
.
toplevel
=
true
;
g
.
props
.
toplevel
=
true
;
// contain map of current normalized schema
// contain map of current normalized schema
// json pointer and corresponding url
// json pointer and corresponding url
...
@@ -537,11 +585,11 @@
...
@@ -537,11 +585,11 @@
}
}
})
})
.
push
(
function
()
{
.
push
(
function
()
{
if
(
options
.
schema
)
{
if
(
schema
)
{
return
options
.
schema
;
return
schema
;
}
}
var
schema_url
=
options
.
schema_url
||
var
schema_url
=
g
.
state
.
schema_url
||
(
options
.
value
&&
options
.
value
.
$schema
);
(
json_document
&&
json_document
.
$schema
);
if
(
schema_url
)
{
if
(
schema_url
)
{
return
loadJSONSchema
(
g
,
schema_url
)
return
loadJSONSchema
(
g
,
schema_url
)
.
push
(
function
(
schema_arr
)
{
.
push
(
function
(
schema_arr
)
{
...
@@ -551,11 +599,10 @@
...
@@ -551,11 +599,10 @@
return
{};
return
{};
})
})
.
push
(
function
(
schema
)
{
.
push
(
function
(
schema
)
{
g
.
options
.
schema
=
schema
;
return
g
.
props
.
form_gadget
.
renderForm
({
return
g
.
props
.
form_gadget
.
renderForm
({
schema
:
schema
,
schema
:
schema
,
schema_path
:
""
,
schema_path
:
""
,
document
:
options
.
value
,
document
:
json_document
,
required
:
true
,
required
:
true
,
top
:
true
top
:
true
});
});
...
@@ -603,7 +650,8 @@
...
@@ -603,7 +650,8 @@
// This will prevent the gadget to be changed if
// This will prevent the gadget to be changed if
// its parent call render with the same value
// its parent call render with the same value
// (as ERP5 does in case of formulator error)
// (as ERP5 does in case of formulator error)
g
.
state
.
value
=
value
;
g
.
state
.
value
=
JSON
.
stringify
(
value
);
console
.
log
(
g
.
state
.
value
);
if
(
g
.
state
.
key
)
{
if
(
g
.
state
.
key
)
{
var
form_data
=
{};
var
form_data
=
{};
value
=
JSON
.
stringify
(
value
);
value
=
JSON
.
stringify
(
value
);
...
...
bt5/erp5_json_form/SkinTemplateItem/portal_skins/erp5_json_form/jsonform.gadget.js.xml
View file @
d64711d5
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
title
</string>
</key>
<key>
<string>
title
</string>
</key>
<value>
<string>
schema
.gadget.js
</string>
</value>
<value>
<string>
jsonform
.gadget.js
</string>
</value>
</item>
</item>
</dictionary>
</dictionary>
</pickle>
</pickle>
...
...
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