-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit.js
executable file
·114 lines (85 loc) · 2.55 KB
/
edit.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
(function() {
var json = {}, treema;
var message = {
"intro":"Welcome to the Mapping Portal Toolbox Editor",
"load":"JSON has been successfully loaded",
"load_error":"Error loading data or schema json file",
"not_valid":"A data entry is not valid",
"submit":"JSON has been successfully updated",
"submit_error":"Error updating JSON",
"bad_pass":"Incorrect password."
}
$('#message').html(message.intro);
$(function() {
$.when( $.getJSON("usr/toolbox.json"), $.getJSON("schema.json") ).done( function(data, schema){
json.data = data[0]
json.schema = schema[0]
if (data[1] == "success" && schema[1] == "success") {
$('#title-link').html( ( json.data.config ? json.data.config.title : "Mapping Portal") );
var options = { schema:json.schema, data:json.data };
var el = $("#data");
// var treema = el.treema(options);
treema = TreemaNode.make(el, options);
treema.build();
// console.log(treema.data);
// console.log("treema built");
$('#message').html(message.load);
} else {
console.log("error loading data or schema json file");
$('#message').html(message.load_error);
}
})
})
$('#submit button').click(function(){
console.log("click");
// check json isValid()
var isValid = treema.isValid();
console.log(isValid)
if ( !isValid ) {
console.log('Not Valid');
$('#message').html(message.not_valid);
alert('A data entry is not valid')
return;
}
var confirm = prompt("Confirm update");
if ( confirm != null && isValid ) {
var pass;
$.ajax ({
url: "process.php",
data: {call: "pass", pass: confirm},
dataType: "json",
type: "post",
async: false,
success: function (result) {
console.log("pass check done");
// console.log(result);
pass = result;
},
error: function (result) {
console.log("pass check error");
}
})
if ( pass ) {
$.ajax ({
url: "process.php",
data: {call: "json", json: JSON.stringify(treema.data)},
dataType: "json",
type: "post",
async: false,
success: function (result) {
console.log("toolbox update done");
$('#message').html(message.submit);
},
error: function (result) {
console.log("toolbox update error");
// console.log(result);
$('#message').html(message.submit_error);
}
})
} else {
console.log(message.bad_pass);
$('#message').html(message.bad_pass);
}
}
})
}).call(this);