rails_admin_json_editor 0.0.24 → 0.0.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/rails_admin_json_editor/{lodash.2.4.1.js → lib/lodash.2.4.1.js} +0 -0
- data/app/assets/javascripts/rails_admin_json_editor/{markdown.js → lib/markdown.js} +0 -0
- data/app/assets/javascripts/rails_admin_json_editor/{vue.0.11.4.js → lib/vue.0.11.4.js} +0 -0
- data/app/assets/javascripts/rails_admin_json_editor/ra.filtering-select.custom.js +199 -0
- data/app/assets/javascripts/rails_admin_json_editor/ra.remoteForm.custom.js +91 -0
- data/app/assets/javascripts/rails_admin_json_editor/rails_admin_json_editor.js +62 -15
- data/app/assets/stylesheets/rails_admin_json_editor/rails_admin_json_editor.css.scss +28 -0
- data/app/views/rails_admin_json_editor/main/_component.html.erb +68 -0
- data/app/views/rails_admin_json_editor/main/_form_json_editor.html.erb +6 -129
- data/app/views/rails_admin_json_editor/main/component_fields/_boolean.html.erb +1 -0
- data/app/views/rails_admin_json_editor/main/component_fields/_enum.html.erb +1 -0
- data/app/views/rails_admin_json_editor/main/component_fields/_list.html.erb +37 -0
- data/app/views/rails_admin_json_editor/main/component_fields/_markdown.html.erb +11 -0
- data/app/views/rails_admin_json_editor/main/component_fields/_picker.html.erb +35 -0
- data/app/views/rails_admin_json_editor/main/component_fields/_string.html.erb +1 -0
- data/app/views/rails_admin_json_editor/main/component_fields/_text.html.erb +1 -0
- data/config/locales/rails_admin_json_editor.en.yml +5 -0
- data/lib/rails_admin_json_editor.rb +5 -3
- data/lib/rails_admin_json_editor/version.rb +1 -1
- metadata +16 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f8dae8b1ebeaffd54086badfea8ba5c6ee0ab43
|
4
|
+
data.tar.gz: c974baf5abeb93f121981558bd28641a070d5dc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 236d6d1364ee1514f3436d8e3f4cdc33c08c6bf77f4e465defe149d3f339903f2356af8dc00b9be01ccc3ff62745ce388bb8055adf1845aa1c2e66fb9e053288
|
7
|
+
data.tar.gz: 39dea58187e439508c4b958a83fdba7efb225375015852df6eaccdb61e0783f86272ef0145f2910ae30f5e38eecf2b4ee37356ce4165478914ab8fda677d9c03
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,199 @@
|
|
1
|
+
/*
|
2
|
+
* RailsAdmin filtering select @VERSION
|
3
|
+
*
|
4
|
+
* Based on the combobox example from jQuery UI documentation
|
5
|
+
* http://jqueryui.com/demos/autocomplete/#combobox
|
6
|
+
*
|
7
|
+
* License
|
8
|
+
*
|
9
|
+
* http://www.railsadmin.org
|
10
|
+
*
|
11
|
+
* Depends:
|
12
|
+
* jquery.ui.core.js
|
13
|
+
* jquery.ui.widget.js
|
14
|
+
* jquery.ui.autocomplete.js
|
15
|
+
*/
|
16
|
+
(function($) {
|
17
|
+
$.widget("ra.jsonEditorFilteringSelect", {
|
18
|
+
options: {
|
19
|
+
createQuery: function(query) {
|
20
|
+
return { query: query };
|
21
|
+
},
|
22
|
+
minLength: 0,
|
23
|
+
searchDelay: 200,
|
24
|
+
remote_source: null,
|
25
|
+
source: null,
|
26
|
+
xhr: false
|
27
|
+
},
|
28
|
+
|
29
|
+
_create: function() {
|
30
|
+
var self = this,
|
31
|
+
select = this.element.hide(),
|
32
|
+
selected = select.children(":selected"),
|
33
|
+
value = selected.val() ? selected.text() : "";
|
34
|
+
|
35
|
+
if (this.options.xhr) {
|
36
|
+
this.options.source = this.options.remote_source;
|
37
|
+
} else {
|
38
|
+
this.options.source = select.children("option").map(function() {
|
39
|
+
return { label: $(this).text(), value: this.value };
|
40
|
+
}).toArray();
|
41
|
+
}
|
42
|
+
|
43
|
+
var remoteSource = this.element.data('remote-source');
|
44
|
+
if(remoteSource) {
|
45
|
+
this.options.xhr = true;
|
46
|
+
this.options.source = remoteSource;
|
47
|
+
}
|
48
|
+
this.element.removeClass('not-initialized-filtering-select');
|
49
|
+
|
50
|
+
var filtering_select = $('<div class="input-append filtering-select" style="float:left"></div>')
|
51
|
+
var input = this.input = $('<input type="text">')
|
52
|
+
.val(value)
|
53
|
+
.addClass("form-control ra-filtering-select-input")
|
54
|
+
.attr('style', select.attr('style'))
|
55
|
+
.show()
|
56
|
+
.autocomplete({
|
57
|
+
delay: this.options.searchDelay,
|
58
|
+
minLength: this.options.minLength,
|
59
|
+
source: this._getSourceFunction(this.options.source),
|
60
|
+
select: function(event, ui) {
|
61
|
+
var option = $('<option></option>').attr('value', ui.item.id).attr('selected', 'selected').text(ui.item.value);
|
62
|
+
select.html(option);
|
63
|
+
select.trigger("change", ui.item.id);
|
64
|
+
select[0].dispatchEvent(new Event('change')); // Dispatch native event
|
65
|
+
self._trigger("selected", event, {
|
66
|
+
item: option
|
67
|
+
});
|
68
|
+
$(self.element.parents('.controls')[0]).find('.update').removeClass('disabled');
|
69
|
+
},
|
70
|
+
change: function(event, ui) {
|
71
|
+
if (!ui.item) {
|
72
|
+
var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$", "i"),
|
73
|
+
valid = false;
|
74
|
+
select.children("option").each(function() {
|
75
|
+
if ($(this).text().match(matcher)) {
|
76
|
+
this.selected = valid = true;
|
77
|
+
return false;
|
78
|
+
}
|
79
|
+
});
|
80
|
+
if (!valid || $(this).val() == '') {
|
81
|
+
// remove invalid value, as it didn't match anything
|
82
|
+
$(this).val(null);
|
83
|
+
select.html($('<option value="" selected="selected"></option>'));
|
84
|
+
input.data("ui-autocomplete").term = "";
|
85
|
+
$(self.element.parents('.controls')[0]).find('.update').addClass('disabled');
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
|
89
|
+
}
|
90
|
+
}
|
91
|
+
})
|
92
|
+
.keyup(function() {
|
93
|
+
/* Clear select options and trigger change if selected item is deleted */
|
94
|
+
if ($(this).val().length == 0) {
|
95
|
+
select.html($('<option value="" selected="selected"></option>'));
|
96
|
+
select.trigger("change");
|
97
|
+
}
|
98
|
+
})
|
99
|
+
|
100
|
+
if(select.attr('placeholder'))
|
101
|
+
input.attr('placeholder', select.attr('placeholder'))
|
102
|
+
|
103
|
+
input.data("ui-autocomplete")._renderItem = function(ul, item) {
|
104
|
+
return $("<li></li>")
|
105
|
+
.data("ui-autocomplete-item", item)
|
106
|
+
.append( $( "<a></a>" ).html( item.label || item.id ) )
|
107
|
+
.appendTo(ul);
|
108
|
+
};
|
109
|
+
|
110
|
+
// replace with dropdown button once ready in twitter-bootstrap
|
111
|
+
var button = this.button = $('<label class="add-on ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" title="Show All Items" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text"> </span></label>')
|
112
|
+
.click(function() {
|
113
|
+
// close if already visible
|
114
|
+
if (input.autocomplete("widget").is(":visible")) {
|
115
|
+
input.autocomplete("close");
|
116
|
+
return;
|
117
|
+
}
|
118
|
+
|
119
|
+
// pass empty string as value to search for, displaying all results
|
120
|
+
input.autocomplete("search", "");
|
121
|
+
input.focus();
|
122
|
+
});
|
123
|
+
|
124
|
+
filtering_select.append(input).append(button).insertAfter(select);
|
125
|
+
|
126
|
+
|
127
|
+
},
|
128
|
+
|
129
|
+
_getResultSet: function(request, data, xhr) {
|
130
|
+
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
|
131
|
+
|
132
|
+
return $.map(data, function(el, i) {
|
133
|
+
// match regexp only for local requests, remote ones are already filtered, and label may not contain filtered term.
|
134
|
+
if ((el.id || el.value) && (xhr || matcher.test(el.label))) {
|
135
|
+
return {
|
136
|
+
label: el.label ? el.label.replace(
|
137
|
+
new RegExp(
|
138
|
+
"(?![^&;]+;)(?!<[^<>]*)(" +
|
139
|
+
$.ui.autocomplete.escapeRegex(request.term) +
|
140
|
+
")(?![^<>]*>)(?![^&;]+;)", "gi"
|
141
|
+
), "<strong>$1</strong>") : el.id,
|
142
|
+
value: el.label || el.id,
|
143
|
+
id: el.id || el.value
|
144
|
+
};
|
145
|
+
}
|
146
|
+
});
|
147
|
+
},
|
148
|
+
|
149
|
+
_getSourceFunction: function(source) {
|
150
|
+
|
151
|
+
var self = this,
|
152
|
+
requestIndex = 0;
|
153
|
+
|
154
|
+
if ($.isArray(source)) {
|
155
|
+
|
156
|
+
return function(request, response) {
|
157
|
+
response(self._getResultSet(request, source, false));
|
158
|
+
};
|
159
|
+
|
160
|
+
} else if (typeof source === "string") {
|
161
|
+
|
162
|
+
return function(request, response) {
|
163
|
+
|
164
|
+
if (this.xhr) {
|
165
|
+
this.xhr.abort();
|
166
|
+
}
|
167
|
+
|
168
|
+
this.xhr = $.ajax({
|
169
|
+
url: source,
|
170
|
+
data: self.options.createQuery(request.term),
|
171
|
+
dataType: "json",
|
172
|
+
autocompleteRequest: ++requestIndex,
|
173
|
+
success: function(data, status) {
|
174
|
+
if (this.autocompleteRequest === requestIndex) {
|
175
|
+
response(self._getResultSet(request, data, true));
|
176
|
+
}
|
177
|
+
},
|
178
|
+
error: function() {
|
179
|
+
if (this.autocompleteRequest === requestIndex) {
|
180
|
+
response([]);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
});
|
184
|
+
};
|
185
|
+
|
186
|
+
} else {
|
187
|
+
|
188
|
+
return source;
|
189
|
+
}
|
190
|
+
},
|
191
|
+
|
192
|
+
destroy: function() {
|
193
|
+
this.input.remove();
|
194
|
+
this.button.remove();
|
195
|
+
this.element.show();
|
196
|
+
$.Widget.prototype.destroy.call(this);
|
197
|
+
}
|
198
|
+
});
|
199
|
+
})(jQuery);
|
@@ -0,0 +1,91 @@
|
|
1
|
+
(function($) {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
window.jsonEditorRemoteForm = {
|
5
|
+
init: function(url) {
|
6
|
+
var deferred = $.Deferred();
|
7
|
+
|
8
|
+
setTimeout(function() {
|
9
|
+
$.ajax({
|
10
|
+
url: url,
|
11
|
+
beforeSend: function(xhr) {
|
12
|
+
xhr.setRequestHeader("Accept", "text/javascript");
|
13
|
+
},
|
14
|
+
success: function(data, status, xhr) {
|
15
|
+
deferred.resolve(data);
|
16
|
+
},
|
17
|
+
error: function(xhr, status, error) {
|
18
|
+
deferred.reject(xhr.responseText);
|
19
|
+
},
|
20
|
+
dataType: 'text'
|
21
|
+
});
|
22
|
+
}, 200);
|
23
|
+
|
24
|
+
return deferred.promise();
|
25
|
+
},
|
26
|
+
|
27
|
+
setupForm: function($modal) {
|
28
|
+
var deferred = $.Deferred();
|
29
|
+
|
30
|
+
var $form = $modal.find("form");
|
31
|
+
var saveButtonText = $modal.find(":submit[name=_save]").html();
|
32
|
+
var cancelButtonText = $modal.find(":submit[name=_continue]").html();
|
33
|
+
$modal.find('.form-actions').remove();
|
34
|
+
|
35
|
+
$form.attr("data-remote", true);
|
36
|
+
$modal.find('.modal-header-title').text($form.data('title'));
|
37
|
+
$modal.find('.cancel-action').unbind().click(function(){
|
38
|
+
$modal.modal('hide');
|
39
|
+
deferred.reject();
|
40
|
+
return false;
|
41
|
+
}).html(cancelButtonText);
|
42
|
+
|
43
|
+
$modal.find('.save-action').unbind().click(function(){
|
44
|
+
$form.submit();
|
45
|
+
return false;
|
46
|
+
}).html(saveButtonText);
|
47
|
+
|
48
|
+
$(document).trigger('rails_admin.dom_ready', [$form]);
|
49
|
+
|
50
|
+
$form.bind("ajax:complete", function(xhr, data, status) {
|
51
|
+
if (status === 'error') {
|
52
|
+
// TODO
|
53
|
+
// $modal.find('.modal-body').html(data.responseText);
|
54
|
+
// widget._bindFormEvents();
|
55
|
+
deferred.reject(data.responseText);
|
56
|
+
} else {
|
57
|
+
var json = $.parseJSON(data.responseText);
|
58
|
+
$modal.modal('hide');
|
59
|
+
deferred.resolve(json);
|
60
|
+
}
|
61
|
+
});
|
62
|
+
|
63
|
+
return deferred.promise();
|
64
|
+
},
|
65
|
+
|
66
|
+
getModal: function() {
|
67
|
+
return $('<div id="modal" class="modal fade">\
|
68
|
+
<div class="modal-dialog">\
|
69
|
+
<div class="modal-content">\
|
70
|
+
<div class="modal-header">\
|
71
|
+
<a href="#" class="close" data-dismiss="modal">×</a>\
|
72
|
+
<h3 class="modal-header-title">...</h3>\
|
73
|
+
</div>\
|
74
|
+
<div class="modal-body">\
|
75
|
+
...\
|
76
|
+
</div>\
|
77
|
+
<div class="modal-footer">\
|
78
|
+
<a href="#" class="btn cancel-action">...</a>\
|
79
|
+
<a href="#" class="btn btn-primary save-action">...</a>\
|
80
|
+
</div>\
|
81
|
+
</div>\
|
82
|
+
</div>\
|
83
|
+
</div>')
|
84
|
+
.modal({
|
85
|
+
keyboard: true,
|
86
|
+
backdrop: true,
|
87
|
+
show: true
|
88
|
+
});
|
89
|
+
}
|
90
|
+
};
|
91
|
+
})(jQuery);
|
@@ -1,8 +1,11 @@
|
|
1
1
|
/*globals $, Vue, markdown, _*/
|
2
2
|
|
3
|
-
//= require rails_admin_json_editor/vue.0.11.4
|
4
|
-
//= require rails_admin_json_editor/lodash.2.4.1
|
5
|
-
//= require rails_admin_json_editor/markdown
|
3
|
+
//= require rails_admin_json_editor/lib/vue.0.11.4
|
4
|
+
//= require rails_admin_json_editor/lib/lodash.2.4.1
|
5
|
+
//= require rails_admin_json_editor/lib/markdown
|
6
|
+
|
7
|
+
//= require rails_admin_json_editor/ra.remoteForm.custom
|
8
|
+
//= require rails_admin_json_editor/ra.filtering-select.custom
|
6
9
|
|
7
10
|
var vm;
|
8
11
|
|
@@ -84,21 +87,61 @@ $(document).on('rails_admin.dom_ready', function() {
|
|
84
87
|
this.parentComponents[this.parentIndex].properties = clonedproperties;
|
85
88
|
},
|
86
89
|
|
87
|
-
|
88
|
-
var
|
89
|
-
var
|
90
|
-
var
|
90
|
+
showPickerModal: function(e, fieldName, baseUrl) {
|
91
|
+
var remoteForm = window.jsonEditorRemoteForm;
|
92
|
+
var $modal = remoteForm.getModal();
|
93
|
+
var self = this;
|
94
|
+
|
95
|
+
remoteForm.init(baseUrl + '/new?modal=true')
|
96
|
+
// Inject form-DOM into modal
|
97
|
+
.then(function(form) {
|
98
|
+
$modal.find('.modal-body').html(form);
|
99
|
+
})
|
100
|
+
|
101
|
+
// Wait for results from modal
|
102
|
+
.then(function() {
|
103
|
+
return remoteForm.setupForm($modal);
|
104
|
+
})
|
105
|
+
|
106
|
+
// Fetch full JSON
|
107
|
+
.then(function(minimalJson) {
|
108
|
+
var url = baseUrl + '/' + minimalJson.id + '.json';
|
109
|
+
return $.get(url);
|
110
|
+
})
|
111
|
+
|
112
|
+
// Full result received
|
113
|
+
.then(function(json) {
|
114
|
+
var clonedproperties = _.clone(self.component.properties);
|
115
|
+
clonedproperties[fieldName] = json;
|
116
|
+
self.parentComponents[self.parentIndex].properties = clonedproperties;
|
117
|
+
})
|
118
|
+
|
119
|
+
// Cleanup
|
120
|
+
.always(function() {
|
121
|
+
setTimeout(function() {
|
122
|
+
$('.modal-backdrop, #modal').remove();
|
123
|
+
}, 500);
|
124
|
+
});
|
125
|
+
},
|
91
126
|
|
92
|
-
|
93
|
-
|
94
|
-
|
127
|
+
onChangePickerSelect: function(e, fieldName, baseUrl) {
|
128
|
+
var self = this;
|
129
|
+
var id = $(e.currentTarget).val();
|
130
|
+
var url = baseUrl + '/' + id + '.json';
|
131
|
+
|
132
|
+
$.get(url).then(function(json) {
|
133
|
+
var clonedproperties = _.clone(self.component.properties);
|
134
|
+
clonedproperties[fieldName] = json;
|
135
|
+
self.parentComponents[self.parentIndex].properties = clonedproperties;
|
136
|
+
});
|
137
|
+
},
|
138
|
+
|
139
|
+
pickerResult: function(fieldName) {
|
140
|
+
return this.component.properties[fieldName];
|
95
141
|
},
|
96
142
|
|
97
|
-
|
98
|
-
|
99
|
-
this.component.properties[fieldName] &&
|
100
|
-
this.component.properties[fieldName][recordLabel] &&
|
101
|
-
this.component.properties[fieldName][recordLabel].replace(/["']/g, "") === recordName.replace(/["']/g, "");
|
143
|
+
removePickerResult: function(fieldName) {
|
144
|
+
this.component.properties[fieldName] = null;
|
102
145
|
},
|
103
146
|
|
104
147
|
nestedModelIsAllowed: function(model, allowedModels) {
|
@@ -134,6 +177,10 @@ $(document).on('rails_admin.dom_ready', function() {
|
|
134
177
|
},
|
135
178
|
computed: {
|
136
179
|
result: function() {
|
180
|
+
// Hack in jquery filtering select
|
181
|
+
$('.not-initialized-filtering-select').jsonEditorFilteringSelect();
|
182
|
+
|
183
|
+
// Format result
|
137
184
|
var result = { components: this.components };
|
138
185
|
$(this.$el).trigger('json-editor:changed', result);
|
139
186
|
return JSON.stringify(result);
|
@@ -6,6 +6,10 @@ body.rails_admin .form-horizontal.denser .json-editor {
|
|
6
6
|
|
7
7
|
.form-control:not([type="checkbox"]) {
|
8
8
|
width: 90%;
|
9
|
+
|
10
|
+
&.ra-filtering-select-input {
|
11
|
+
width: auto;
|
12
|
+
}
|
9
13
|
}
|
10
14
|
|
11
15
|
.btn-toggle-json {
|
@@ -35,4 +39,28 @@ body.rails_admin .form-horizontal.denser .json-editor {
|
|
35
39
|
padding: 0.1em 0.5em;
|
36
40
|
margin: 0 0 -2px 5px;
|
37
41
|
}
|
42
|
+
|
43
|
+
.picker {
|
44
|
+
.btn.remove {
|
45
|
+
display: inline-block;
|
46
|
+
vertical-align: top;
|
47
|
+
}
|
48
|
+
|
49
|
+
.btn.create {
|
50
|
+
margin-left: 10px;
|
51
|
+
}
|
52
|
+
|
53
|
+
.picker-preview {
|
54
|
+
img {
|
55
|
+
margin-bottom: 5px;
|
56
|
+
}
|
57
|
+
|
58
|
+
p {
|
59
|
+
margin-top: 8px;
|
60
|
+
margin-right: 12px;
|
61
|
+
display: inline-block;
|
62
|
+
font-size: 14px;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
38
66
|
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<div class="component">
|
2
|
+
<legend>
|
3
|
+
<span class="model-label"><%= model.label %></span>
|
4
|
+
<pre class="guid" v-text="component.guid"></pre>
|
5
|
+
|
6
|
+
<div class="btn-group btn-group-sm pull-right">
|
7
|
+
<% if field.orderable %>
|
8
|
+
<button v-on="click: moveUp" type="button" class="btn btn-default {{ moveUpEnabled ? '' : 'disabled' }}">
|
9
|
+
<i class="icon-circle-arrow-up"></i>
|
10
|
+
</button>
|
11
|
+
|
12
|
+
<button v-on="click: moveDown" type="button" class="btn btn-default {{ moveDownEnabled ? '' : 'disabled' }}">
|
13
|
+
<i class="icon-circle-arrow-down"></i>
|
14
|
+
</button>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<button v-on="click: expanded = !expanded" type="button" class="btn btn-default">
|
18
|
+
<i class="{{ expanded ? 'icon-resize-small' : 'icon-resize-full' }}"></i>
|
19
|
+
</button>
|
20
|
+
|
21
|
+
<button v-on="click:remove" type="button" class="btn btn-default">
|
22
|
+
<i class="icon-remove"></i>
|
23
|
+
</button>
|
24
|
+
</div>
|
25
|
+
</legend>
|
26
|
+
|
27
|
+
<div v-show="expanded">
|
28
|
+
<%= content_tag :p, model.help, class: "help-block" unless model.help.nil? %>
|
29
|
+
|
30
|
+
<% model.fields.each do |f| %>
|
31
|
+
<div class="control-group row <%= f.css_class %>">
|
32
|
+
<label class="col-sm-2 control-label"><%= f.label %></label>
|
33
|
+
|
34
|
+
<div class="controls col-sm-10">
|
35
|
+
<% if f.type == :string %>
|
36
|
+
<%= render 'rails_admin_json_editor/main/component_fields/string', f: f %>
|
37
|
+
<% end %>
|
38
|
+
|
39
|
+
<% if f.type == :text %>
|
40
|
+
<%= render 'rails_admin_json_editor/main/component_fields/text', f: f %>
|
41
|
+
<% end %>
|
42
|
+
|
43
|
+
<% if f.type == :markdown %>
|
44
|
+
<%= render 'rails_admin_json_editor/main/component_fields/markdown', f: f %>
|
45
|
+
<% end %>
|
46
|
+
|
47
|
+
<% if f.type == :boolean %>
|
48
|
+
<%= render 'rails_admin_json_editor/main/component_fields/boolean', f: f %>
|
49
|
+
<% end %>
|
50
|
+
|
51
|
+
<% if f.type == :enum %>
|
52
|
+
<%= render 'rails_admin_json_editor/main/component_fields/enum', f: f %>
|
53
|
+
<% end %>
|
54
|
+
|
55
|
+
<% if f.type == :picker %>
|
56
|
+
<%= render 'rails_admin_json_editor/main/component_fields/picker', f: f %>
|
57
|
+
<% end %>
|
58
|
+
|
59
|
+
<% if f.type == :list %>
|
60
|
+
<%= render 'rails_admin_json_editor/main/component_fields/list', f: f %>
|
61
|
+
<% end %>
|
62
|
+
|
63
|
+
<%= content_tag :p, f.help, class: "help-block" unless f.help.nil? %>
|
64
|
+
</div>
|
65
|
+
</div>
|
66
|
+
<% end %>
|
67
|
+
</div>
|
68
|
+
</div>
|
@@ -9,144 +9,21 @@
|
|
9
9
|
|
10
10
|
<% field.models.each do |model| %>
|
11
11
|
<script type="text/x-template" id="template-fields-for-<%= model.name %>">
|
12
|
-
|
13
|
-
<legend>
|
14
|
-
<span class="model-label"><%= model.label %></span>
|
15
|
-
<pre class="guid" v-text="component.guid"></pre>
|
16
|
-
|
17
|
-
<div class="btn-group btn-group-sm pull-right">
|
18
|
-
<% if field.orderable %>
|
19
|
-
<button v-on="click: moveUp" type="button" class="btn btn-default {{ moveUpEnabled ? '' : 'disabled' }}">
|
20
|
-
<i class="icon-circle-arrow-up"></i>
|
21
|
-
</button>
|
22
|
-
|
23
|
-
<button v-on="click: moveDown" type="button" class="btn btn-default {{ moveDownEnabled ? '' : 'disabled' }}">
|
24
|
-
<i class="icon-circle-arrow-down"></i>
|
25
|
-
</button>
|
26
|
-
<% end %>
|
27
|
-
|
28
|
-
<button v-on="click: expanded = !expanded" type="button" class="btn btn-default">
|
29
|
-
<i class="{{ expanded ? 'icon-resize-small' : 'icon-resize-full' }}"></i>
|
30
|
-
</button>
|
31
|
-
|
32
|
-
<button v-on="click:remove" type="button" class="btn btn-default">
|
33
|
-
<i class="icon-remove"></i>
|
34
|
-
</button>
|
35
|
-
</div>
|
36
|
-
</legend>
|
37
|
-
|
38
|
-
<div v-show="expanded">
|
39
|
-
<%= content_tag :p, model.help, class: "help-block" unless model.help.nil? %>
|
40
|
-
|
41
|
-
<% model.fields.each do |f| %>
|
42
|
-
<div class="control-group row <%= f.css_class %>">
|
43
|
-
<label class="col-sm-2 control-label"><%= f.label %></label>
|
44
|
-
|
45
|
-
<div class="controls col-sm-10">
|
46
|
-
<% if f.type == :string %>
|
47
|
-
<input v-model="component.properties.<%= f.name %>" type="text" class="form-control" />
|
48
|
-
<% end %>
|
49
|
-
|
50
|
-
<% if f.type == :text %>
|
51
|
-
<textarea v-model="component.properties.<%= f.name %>" class="form-control"></textarea>
|
52
|
-
<% end %>
|
53
|
-
|
54
|
-
<% if f.type == :markdown %>
|
55
|
-
<div class="markdown-field">
|
56
|
-
<textarea v-model="component.properties.<%= f.name %>" class="form-control" rows="10"></textarea>
|
57
|
-
|
58
|
-
<button v-on="click: showPreview = !showPreview" type="button" class="btn btn-default">
|
59
|
-
<i class="icon-eye-open"></i>
|
60
|
-
</button>
|
61
|
-
</div>
|
62
|
-
|
63
|
-
<div class="markdown-preview" v-show="showPreview">
|
64
|
-
<div v-html="component.properties.<%= f.name %> | markdown"></div>
|
65
|
-
</div>
|
66
|
-
<% end %>
|
67
|
-
|
68
|
-
<% if f.type == :boolean %>
|
69
|
-
<input type="checkbox" v-model="component.properties.<%= f.name %>" class="form-control">
|
70
|
-
<% end %>
|
71
|
-
|
72
|
-
<% if f.type == :enum %>
|
73
|
-
<%= select_tag(nil, options_for_select(f.enum_options), include_blank: true, class: "form-control", "v-model" => "component.properties.#{f.name}") %>
|
74
|
-
<% end %>
|
75
|
-
|
76
|
-
<% if f.type == :picker %>
|
77
|
-
<select v-on="change: onChangePicker($event, '<%= f.name %>')" class="form-control record-picker">
|
78
|
-
<option value=""></option>
|
79
|
-
<%
|
80
|
-
records = Rails.cache.fetch("record-picker-#{f.picker_model_name}") do
|
81
|
-
f.picker_model_name.constantize.send(:all).order(f.picker_label)
|
82
|
-
end
|
83
|
-
%>
|
84
|
-
<% records.each do |record| %>
|
85
|
-
<option
|
86
|
-
v-attr="selected: pickerOptionIsSelected('<%= f.name %>', '<%= f.picker_label %>', '<%= record.send(f.picker_label).gsub(/['"]/, '') %>')"
|
87
|
-
value="<%= record.send(f.picker_label) %>"
|
88
|
-
data-json="<%= record.to_json %>">
|
89
|
-
<%= record.send(f.picker_label) %>
|
90
|
-
</option>
|
91
|
-
<% end %>
|
92
|
-
</select>
|
93
|
-
<% end %>
|
94
|
-
|
95
|
-
<% if f.type == :list %>
|
96
|
-
<div v-repeat="nestedComponent: component.properties.<%= f.name %>">
|
97
|
-
<div
|
98
|
-
v-component="fields-for-{{ nestedComponent.model_name }}"
|
99
|
-
v-with="component: nestedComponent, parentComponents: component.properties.<%= f.name %>, parentIndex: $index">
|
100
|
-
</div>
|
101
|
-
</div>
|
102
|
-
|
103
|
-
<div v-show="!component.properties.<%= f.name %> || component.properties.<%= f.name %>.length < <%= f.list_max_length.nil? ? 999999 : f.list_max_length %>">
|
104
|
-
<!-- Add nested component -- one model allowed -->
|
105
|
-
<% if f.list_model_names.count == 1 %>
|
106
|
-
<a href="#"
|
107
|
-
class="btn btn-info"
|
108
|
-
v-repeat="model: $root.scheme.models"
|
109
|
-
v-show="nestedModelIsAllowed(model, <%= f.list_model_names %>)"
|
110
|
-
v-on="click: addComponent($event, '<%= f.name %>', model)">
|
111
|
-
Add {{ model.label | lowercase }}
|
112
|
-
</a>
|
113
|
-
<% end %>
|
114
|
-
|
115
|
-
<!-- Add nested component -- multiple models allowed -->
|
116
|
-
<% if f.list_model_names.count > 1 %>
|
117
|
-
<div class="dropdown">
|
118
|
-
<a class="dropdown-toggle btn btn-info" data-toggle="dropdown" href="#">Add component <b class="caret"></b></a>
|
119
|
-
<ul class="dropdown-menu">
|
120
|
-
<li v-repeat="model: $root.scheme.models">
|
121
|
-
<a href="#"
|
122
|
-
v-if="nestedModelIsAllowed(model, <%= f.list_model_names %>)"
|
123
|
-
v-on="click: addComponent($event, '<%= f.name %>', model)">
|
124
|
-
{{ model.label }}
|
125
|
-
</a>
|
126
|
-
</li>
|
127
|
-
</ul>
|
128
|
-
</div>
|
129
|
-
<% end %>
|
130
|
-
</div>
|
131
|
-
<% end %>
|
132
|
-
|
133
|
-
<%= content_tag :p, f.help, class: "help-block" unless f.help.nil? %>
|
134
|
-
</div>
|
135
|
-
</div>
|
136
|
-
<% end %>
|
137
|
-
</div>
|
138
|
-
</div>
|
12
|
+
<%= render 'rails_admin_json_editor/main/component', field: field, model: model %>
|
139
13
|
</script>
|
140
14
|
<% end %>
|
141
15
|
|
142
|
-
<!-- List all
|
16
|
+
<!-- List all content -->
|
143
17
|
<div v-repeat="component: components">
|
144
18
|
<div v-component="fields-for-{{ component.model_name }}" v-with="component: component, parentComponents: components, parentIndex: $index"></div>
|
145
19
|
</div>
|
146
20
|
|
147
21
|
<!-- Dropdown to add new content -->
|
148
22
|
<div class="dropdown pull-left">
|
149
|
-
<a class="dropdown-toggle btn btn-info" data-toggle="dropdown" href="#">
|
23
|
+
<a class="dropdown-toggle btn btn-info" data-toggle="dropdown" href="#">
|
24
|
+
<%= I18n.t 'admin.json_editor.add', field_name: 'Component' %>
|
25
|
+
<b class="caret"></b>
|
26
|
+
</a>
|
150
27
|
|
151
28
|
<ul class="dropdown-menu">
|
152
29
|
<li v-repeat="model: scheme.models">
|
@@ -0,0 +1 @@
|
|
1
|
+
<input type="checkbox" v-model="component.properties.<%= f.name %>" class="form-control">
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= select_tag(nil, options_for_select(f.enum_options), include_blank: true, class: "form-control", "v-model" => "component.properties.#{f.name}") %>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<div v-repeat="nestedComponent: component.properties.<%= f.name %>">
|
2
|
+
<div
|
3
|
+
v-component="fields-for-{{ nestedComponent.model_name }}"
|
4
|
+
v-with="component: nestedComponent, parentComponents: component.properties.<%= f.name %>, parentIndex: $index">
|
5
|
+
</div>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<div v-show="!component.properties.<%= f.name %> || component.properties.<%= f.name %>.length < <%= f.list_max_length.nil? ? 999999 : f.list_max_length %>">
|
9
|
+
<!-- Add nested component, one model allowed -->
|
10
|
+
<% if f.list_model_names.count == 1 %>
|
11
|
+
<a href="#"
|
12
|
+
class="btn btn-info"
|
13
|
+
v-repeat="model: $root.scheme.models"
|
14
|
+
v-show="nestedModelIsAllowed(model, <%= f.list_model_names %>)"
|
15
|
+
v-on="click: addComponent($event, '<%= f.name %>', model)">
|
16
|
+
<i class="icon-plus icon-white"></i>
|
17
|
+
Add {{ model.label | lowercase }}
|
18
|
+
</a>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<!-- Add nested component, multiple models allowed -->
|
22
|
+
<% if f.list_model_names.count > 1 %>
|
23
|
+
<div class="dropdown">
|
24
|
+
<a class="dropdown-toggle btn btn-info" data-toggle="dropdown" href="#">Add component <b class="caret"></b></a>
|
25
|
+
<ul class="dropdown-menu">
|
26
|
+
<li v-repeat="model: $root.scheme.models">
|
27
|
+
<a href="#"
|
28
|
+
v-if="nestedModelIsAllowed(model, <%= f.list_model_names %>)"
|
29
|
+
v-on="click: addComponent($event, '<%= f.name %>', model)">
|
30
|
+
<i class="icon-plus icon-white"></i>
|
31
|
+
{{ model.label }}
|
32
|
+
</a>
|
33
|
+
</li>
|
34
|
+
</ul>
|
35
|
+
</div>
|
36
|
+
<% end %>
|
37
|
+
</div>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<div class="markdown-field">
|
2
|
+
<textarea v-model="component.properties.<%= f.name %>" class="form-control" rows="10"></textarea>
|
3
|
+
|
4
|
+
<button v-on="click: showPreview = !showPreview" type="button" class="btn btn-default">
|
5
|
+
<i class="icon-eye-open"></i>
|
6
|
+
</button>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div class="markdown-preview" v-show="showPreview">
|
10
|
+
<div v-html="component.properties.<%= f.name %> | markdown"></div>
|
11
|
+
</div>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<div class="picker">
|
2
|
+
<div v-if="pickerResult('<%= f.name %>')" class="picker-preview">
|
3
|
+
<% if !f.picker_preview_image_field.nil? %>
|
4
|
+
<img v-attr="src: pickerResult('<%= f.name %>').<%= f.picker_preview_image_field %>" />
|
5
|
+
<% elsif !f.picker_preview_field.nil? %>
|
6
|
+
<p v-text="pickerResult('<%= f.name %>').<%= f.picker_preview_field %>"></p>
|
7
|
+
<% else %>
|
8
|
+
<pre v-text="pickerResult('<%= f.name %>') | json"></pre>
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
<a v-on="click: removePickerResult('<%= f.name %>')" class="btn btn-info remove">
|
12
|
+
<i class="icon-remove icon-white"></i>
|
13
|
+
<%= I18n.t('admin.json_editor.remove', field_name: f.picker_model_name.constantize.send(:model_name).human) %>
|
14
|
+
</a>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div v-if="!pickerResult('<%= f.name %>')">
|
18
|
+
<%
|
19
|
+
base_url = rails_admin.index_path(f.picker_model_name)
|
20
|
+
%>
|
21
|
+
|
22
|
+
<select v-on="change: onChangePickerSelect($event, '<%= f.name %>', '<%= base_url %>')"
|
23
|
+
data-filteringselect="true"
|
24
|
+
data-remote-source="<%= base_url %>?compact=true"
|
25
|
+
placeholder="Search"
|
26
|
+
class="not-initialized-filtering-select" >
|
27
|
+
<option value=""></option>
|
28
|
+
</select>
|
29
|
+
|
30
|
+
<a v-on="click: showPickerModal($event, '<%= f.name %>', '<%= base_url %>')" class="btn btn-info create">
|
31
|
+
<i class="icon-plus icon-white"></i>
|
32
|
+
<%= I18n.t('admin.json_editor.add', field_name: f.picker_model_name.constantize.send(:model_name).human) %>
|
33
|
+
</a>
|
34
|
+
</div>
|
35
|
+
</div>
|
@@ -0,0 +1 @@
|
|
1
|
+
<input v-model="component.properties.<%= f.name %>" type="text" class="form-control" />
|
@@ -0,0 +1 @@
|
|
1
|
+
<textarea v-model="component.properties.<%= f.name %>" class="form-control"></textarea>
|
@@ -88,8 +88,9 @@ module RailsAdmin
|
|
88
88
|
:help,
|
89
89
|
:css_class
|
90
90
|
|
91
|
-
attr_accessor :
|
92
|
-
:
|
91
|
+
attr_accessor :picker_model_name,
|
92
|
+
:picker_preview_field,
|
93
|
+
:picker_preview_image_field
|
93
94
|
|
94
95
|
attr_accessor :list_model_names,
|
95
96
|
:list_max_length
|
@@ -115,8 +116,9 @@ module RailsAdmin
|
|
115
116
|
end
|
116
117
|
|
117
118
|
def picker(options)
|
118
|
-
@picker_label = options[:label]
|
119
119
|
@picker_model_name = options[:model].name
|
120
|
+
@picker_preview_field = options[:preview_field]
|
121
|
+
@picker_preview_image_field = options[:preview_image_field]
|
120
122
|
end
|
121
123
|
|
122
124
|
def list(models, options = {})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_json_editor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jasper Haggenburg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -65,13 +65,24 @@ files:
|
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
67
67
|
- Rakefile
|
68
|
-
- app/assets/javascripts/rails_admin_json_editor/lodash.2.4.1.js
|
69
|
-
- app/assets/javascripts/rails_admin_json_editor/markdown.js
|
68
|
+
- app/assets/javascripts/rails_admin_json_editor/lib/lodash.2.4.1.js
|
69
|
+
- app/assets/javascripts/rails_admin_json_editor/lib/markdown.js
|
70
|
+
- app/assets/javascripts/rails_admin_json_editor/lib/vue.0.11.4.js
|
71
|
+
- app/assets/javascripts/rails_admin_json_editor/ra.filtering-select.custom.js
|
72
|
+
- app/assets/javascripts/rails_admin_json_editor/ra.remoteForm.custom.js
|
70
73
|
- app/assets/javascripts/rails_admin_json_editor/rails_admin_json_editor.js
|
71
|
-
- app/assets/javascripts/rails_admin_json_editor/vue.0.11.4.js
|
72
74
|
- app/assets/stylesheets/rails_admin_json_editor/rails_admin_json_editor.css.scss
|
75
|
+
- app/views/rails_admin_json_editor/main/_component.html.erb
|
73
76
|
- app/views/rails_admin_json_editor/main/_form_json_editor.html.erb
|
77
|
+
- app/views/rails_admin_json_editor/main/component_fields/_boolean.html.erb
|
78
|
+
- app/views/rails_admin_json_editor/main/component_fields/_enum.html.erb
|
79
|
+
- app/views/rails_admin_json_editor/main/component_fields/_list.html.erb
|
80
|
+
- app/views/rails_admin_json_editor/main/component_fields/_markdown.html.erb
|
81
|
+
- app/views/rails_admin_json_editor/main/component_fields/_picker.html.erb
|
82
|
+
- app/views/rails_admin_json_editor/main/component_fields/_string.html.erb
|
83
|
+
- app/views/rails_admin_json_editor/main/component_fields/_text.html.erb
|
74
84
|
- config/initializers/assets.rb
|
85
|
+
- config/locales/rails_admin_json_editor.en.yml
|
75
86
|
- lib/rails_admin_json_editor.rb
|
76
87
|
- lib/rails_admin_json_editor/version.rb
|
77
88
|
- rails_admin_json_editor.gemspec
|