-
Notifications
You must be signed in to change notification settings - Fork 7
/
interface.js
67 lines (58 loc) · 1.71 KB
/
interface.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
$(document).ready(function(){
$("#bt-validate-js").click(validateJs);
$("#bt-validate-php").click(validatePhp);
$("#bt-validate-php-type-cast-mode").click(validatePhpTypeCastMode);
});
function validatePhpTypeCastMode() {
validatePhp(true);
}
function validatePhp(typeCastMode) {
if(typeCastMode == true) {
typeCastMode = true;
}
else {
typeCastMode = false;
}
$('#resultados').html('. . . w o r k i n g . . . ');
schema = $('#schema').val();
json = $('#json').val();
$.getJSON(
"validate.php",
{"schema":schema,"json":json,"typeCastMode":typeCastMode},
phpCallback
);
}
function phpCallback(json) {
showResponse(json);
}
function validateJs() {
$('#resultados').html('. . . w o r k i n g . . . ');
jsons = getJsons();
//alert(print_r(jsons,true));
if(jsons.schema) {
validateResponse = JSONSchema.validate(jsons.json,jsons.schema);
}
else {
validateResponse = JSONSchema.validate(jsons.json);
}
showResponse(validateResponse);
}
function getJsons() {
schema = $('#schema').val();
json = $('#json').val();
json = eval( '(' + json + ')' );
if(schema) {
schema = eval( '(' + schema + ')' );
}
return {"json":json,"schema":schema};
}
function showResponse(validateResponse) {
//alert(print_r(validateResponse,true));
res = '<b>'+'JSON: '+(validateResponse.valid?' VALID':'INVALID')+'</B><BR/>';
$.each(validateResponse.errors,function(i,item) {
//alert(print_r(item,true));
res += '<b>' + item.property + '</b> :: ' + item.message + '<br/><br/>';
res += '<span class=comment>'+(i+":"+print_r(item,true))+"</span><BR/><br/>";
});
$('#resultados').html(res);
}