forked from mrvautin/adminMongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor.js
36 lines (34 loc) · 1.47 KB
/
editor.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
$(document).ready(function(){
var editor = ace.edit('json');
editor.setTheme('ace/theme/github');
editor.session.setMode('ace/mode/json');
editor.setFontSize(14);
editor.getSession().setUseWorker(false);
editor.$blockScrolling = Infinity;
$(document).on('click', '#submit_json', function(){
try{
// convert BSON string to EJSON
var ejson = toEJSON.serializeString(editor.getValue());
$.ajax({
method: 'POST',
contentType: 'application/json',
url: $('#app_context').val() + '/document/' + $('#conn_name').val() + '/' + $('#db_name').val() + '/' + $('#coll_name').val() + '/' + $('#edit_request_type').val(),
data: JSON.stringify({'objectData': ejson})
})
.done(function(data){
show_notification(data.msg, 'success');
if(data.doc_id){
setInterval(function(){
// remove "new" and replace with "edit" and redirect to edit the doc
window.location = window.location.href.substring(0, window.location.href.length - 3) + 'edit/' + data.doc_id;
}, 2500);
}
})
.fail(function(data){
show_notification(data.responseJSON.msg, 'danger');
});
}catch(err){
show_notification(err, 'danger');
}
});
});