8000 Add JS,CSS,Input · udacity/activeadmin_json_editor@b668a71 · GitHub
[go: up one dir, main page]

Skip to content

Commit b668a71

Browse files
committed
Add JS,CSS,Input
1 parent 5e043c9 commit b668a71

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

app/assets/javascripts/active_admin/json_editor.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@
44
;(function(window, $) {
55
$(function() {
66
$('div.jsoneditor-wrap').each(function(i,wrap){
7+
var fieldset = $(wrap).parents('li:eq(0)');
78
var container = $(wrap)[0];
89
var textarea = $($(wrap).find('textarea'));
910
var editor;
1011
var options = {
12+
modes: ['tree', 'text'],
1113
mode: 'tree',
1214
change: function(ev){
13-
textarea.text(JSON.stringify(editor.get()));
15+
try {
16+
var text = JSON.stringify(editor.get());
17+
textarea.text(text);
18+
$(fieldset).toggleClass('error',false);
19+
textarea.text(JSON.stringify(editor.get()));
20+
} catch (e) {
21+
editor.options.error(e);
22+
}
23+
},
24+
error: function(e){
25+
$(fieldset).toggleClass('error',true);
1426
}
1527
};
1628
editor = new JSONEditor(container, options,JSON.parse(textarea.val()));

app/assets/stylesheets/active_admin/json_editor.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,21 @@
4444
.jsoneditor .search .frame {
4545
border-color: rgb(201, 208, 214);
4646
}
47+
48+
49+
/*
50+
* Use text mode
51+
*/
52+
.jsoneditor-wrap textarea.text {
53+
display: block;
54+
}
55+
.jsoneditor .menu button.separator {
56+
color: black;
57+
text-shadow: none;
58+
}
59+
.jsoneditor-contextmenu ul li button {
60+
text-shadow: none;
61+
}
62+
form fieldset > ol > li.error .jsoneditor {
63+
border: 1px solid #932419;
64+
}

app/inputs/jsonb_input.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class JsonbInput < JsonInput
2+
3+
end

0 commit comments

Comments
 (0)
0