Commit 8f61be1d authored by Boris Kocherov's avatar Boris Kocherov

support rfc6901 in json paths (json pointer)

parent a452f1dc
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* **done** remove slapos specific code * **done** remove slapos specific code
* **partly done** remove jquery dependence * **partly done** remove jquery dependence
* **partly done** full support of json schema * **partly done** full support of json schema
* support in path [rfc6901](https://tools.ietf.org/html/rfc6901) * **done** support in path [rfc6901](https://tools.ietf.org/html/rfc6901)
* using changeState and mutex * using changeState and mutex
* separate form design from code for form generation * separate form design from code for form generation
* add general using documentation * add general using documentation
......
...@@ -4,6 +4,16 @@ ...@@ -4,6 +4,16 @@
(function (window, document, rJS, $, loopEventListener) { (function (window, document, rJS, $, loopEventListener) {
"use strict"; "use strict";
function decodeJsonPointer(_str) {
// https://tools.ietf.org/html/rfc6901#section-5
return _str.replace(/~1/g,'/').replace(/~0/g,'~');
}
function encodeJsonPointer(_str) {
// https://tools.ietf.org/html/rfc6901#section-5
return _str.replace(/~/g,'~0').replace(/\//g,'~1');
}
function render_selection(json_field, default_value) { function render_selection(json_field, default_value) {
var input = document.createElement("select"), var input = document.createElement("select"),
option = document.createElement("option"), option = document.createElement("option"),
...@@ -103,7 +113,7 @@ ...@@ -103,7 +113,7 @@
queue = RSVP.Queue(); queue = RSVP.Queue();
if (path && key) { if (path && key) {
first_path = path + key; first_path = path + encodeJsonPointer(key);
} else { } else {
first_path = ""; first_path = "";
} }
...@@ -308,7 +318,7 @@ ...@@ -308,7 +318,7 @@
kk, kk,
key_list = key.split("/"); key_list = key.split("/");
for (i = 0; i < key_list.length; i += 1) { for (i = 0; i < key_list.length; i += 1) {
kk = key_list[i]; kk = decodeJsonPointer(key_list[i]);
if (i === key_list.length - 1) { if (i === key_list.length - 1) {
if (value === undefined) { if (value === undefined) {
return d[kk]; return d[kk];
...@@ -417,7 +427,7 @@ ...@@ -417,7 +427,7 @@
key = options.key || key = options.key ||
element.parentNode.querySelector("input[type='text']").value; element.parentNode.querySelector("input[type='text']").value;
} }
scope = parent_path + key; scope = parent_path + encodeJsonPointer(key);
if (!key || g.props.subforms.hasOwnProperty(scope)) { if (!key || g.props.subforms.hasOwnProperty(scope)) {
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment