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
5f555486
Commit
5f555486
authored
Feb 24, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove multiple JSON.parse
parent
6f31e5a6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
30 deletions
+17
-30
gadget_erp5_page_slap_load_schema.js
gadget_erp5_page_slap_load_schema.js
+17
-30
No files found.
gadget_erp5_page_slap_load_schema.js
View file @
5f555486
...
...
@@ -22,11 +22,12 @@
return
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
ajax
({
url
:
url
url
:
url
,
dataType
:
"
json
"
})
.
then
(
function
(
evt
)
{
return
evt
.
target
.
responseText
;
})
;
})
.
push
(
function
(
evt
)
{
return
evt
.
target
.
response
;
});
}
...
...
@@ -46,7 +47,6 @@
function
resolveReference
(
partial_schema
,
schema
,
base_url
)
{
var
parts
,
external_schema
,
ref
=
partial_schema
.
$ref
;
if
(
ref
===
undefined
)
{
...
...
@@ -69,8 +69,7 @@
}
return
getJSON
(
ref
);
})
.
push
(
function
(
json
)
{
external_schema
=
JSON
.
parse
(
json
);
.
push
(
function
(
external_schema
)
{
parts
=
ref
.
split
(
"
#
"
);
ref
=
"
#
"
+
parts
[
1
];
return
resolveLocalReference
(
ref
,
external_schema
);
...
...
@@ -190,15 +189,12 @@
return
getJSON
(
"
slapos_load_meta_schema.json
"
);
}
function
validateJSONSchema
(
json
,
base_url
)
{
function
validateJSONSchema
(
schema
,
base_url
)
{
return
getMetaJSONSchema
()
.
push
(
function
(
meta_schema
)
{
if
(
!
tv4
.
validate
(
json
,
meta_schema
))
{
throw
new
Error
(
"
Non valid JSON schema
"
+
json
);
if
(
!
tv4
.
validate
(
schema
,
meta_schema
))
{
throw
new
Error
(
"
Non valid JSON schema
"
+
schema
);
}
return
JSON
.
parse
(
json
);
})
.
push
(
function
(
schema
)
{
return
expandSchema
(
schema
,
schema
,
base_url
);
});
}
...
...
@@ -219,23 +215,17 @@
})
.
declareMethod
(
"
loadSoftwareJSON
"
,
function
(
url
)
{
return
getJSON
(
url
)
.
push
(
function
(
json
)
{
return
JSON
.
parse
(
json
);
});
return
getJSON
(
url
);
})
.
declareMethod
(
"
validateJSONForSoftwareType
"
,
function
(
schema_url
,
software_type
,
generated_json
)
{
return
getJSON
(
schema_url
)
.
push
(
function
(
json
)
{
return
JSON
.
parse
(
json
);
})
.
push
(
function
(
json_object
)
{
var
parameter_schema_url
,
st
,
base_url
,
url_uri
=
URI
(
schema_url
);
for
(
st
in
json_object
[
"
software-type
"
])
{
if
(
json_object
[
"
software-type
"
].
hasOwnProperty
(
st
))
{
if
(
st
===
software_type
)
{
...
...
@@ -243,7 +233,7 @@
}
}
}
if
(
URI
(
parameter_schema_url
).
protocol
()
===
""
)
{
base_url
=
url_uri
.
path
().
split
(
"
/
"
);
base_url
.
pop
();
...
...
@@ -252,25 +242,22 @@
parameter_schema_url
=
base_url
+
"
/
"
+
parameter_schema_url
;
}
}
return
getJSON
(
parameter_schema_url
)
.
push
(
function
(
json
)
{
var
schema
=
JSON
.
parse
(
json
);
return
getJSON
(
parameter_schema_url
)
.
push
(
function
(
schema
)
{
return
expandSchema
(
schema
,
schema
,
base_url
)
.
push
(
function
(
loaded_json
)
{
return
tv4
.
validateMultiple
(
generated_json
,
loaded_json
);
});
});
});
});
})
.
declareMethod
(
"
validateJSON
"
,
function
(
schema_url
,
generated_json
)
{
return
getJSON
(
schema_url
)
.
push
(
function
(
json
)
{
.
push
(
function
(
schema
)
{
var
base_url
,
url_uri
=
URI
(
schema_url
),
schema
=
JSON
.
parse
(
json
);
url_uri
=
URI
(
schema_url
);
base_url
=
url_uri
.
path
().
split
(
"
/
"
);
base_url
.
pop
();
...
...
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