rails_admin_json_editor 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc981b62642d2d92d10afd887cc9d2a1d174270
|
4
|
+
data.tar.gz: 738e60bf27875bc7169171887cf54c5e7ad5994f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ea4556d7bc4f0213270dd9b052524642dbc01e58b0ab8e8f6f8e8447bb84611dde769cb2afc8d7a7c00e151cd2d5aec9af8715bd083a6bc111d336989e70485
|
7
|
+
data.tar.gz: 0569c9fac21f10d1aa99f1bad5966cd487f9e045a25e3b5a3a5d034a91ecacb4662e8be093d26301bb5cfc07305ba839fc8ef8426ca348545c65a53c237ab5fe
|
@@ -16,9 +16,6 @@ $(document).on('rails_admin.dom_ready', function() {
|
|
16
16
|
jsonResult = { components: [] };
|
17
17
|
}
|
18
18
|
|
19
|
-
// Make sure we let Vue update the json-field, but do it here to prevent data-loss when js is disabled
|
20
|
-
$('[ref=json-textarea]').val('');
|
21
|
-
|
22
19
|
// Setup dynamic component-type components
|
23
20
|
var components = {};
|
24
21
|
_.each(jsonComponentTypes, function(c) {
|
@@ -26,8 +23,6 @@ $(document).on('rails_admin.dom_ready', function() {
|
|
26
23
|
template: '#template-component-type-' + c.type,
|
27
24
|
data: function() {
|
28
25
|
return {
|
29
|
-
type: null,
|
30
|
-
props: {},
|
31
26
|
expanded: true
|
32
27
|
};
|
33
28
|
},
|
@@ -57,18 +52,18 @@ $(document).on('rails_admin.dom_ready', function() {
|
|
57
52
|
},
|
58
53
|
|
59
54
|
remove: function() {
|
60
|
-
if(confirm("Are you sure?")) {
|
55
|
+
if(_.values(this.component.props).length === 0 || confirm("Are you sure?")) {
|
61
56
|
this.parentComponents.$remove(this.parentIndex);
|
62
57
|
}
|
63
58
|
},
|
64
59
|
|
65
60
|
// TODO: DRY up with $root.addComponent
|
66
|
-
addComponent: function(event,
|
61
|
+
addComponent: function(event, target, type) {
|
67
62
|
event.preventDefault();
|
68
63
|
|
69
|
-
var clonedProps = _.clone(component.props);
|
70
|
-
if(!clonedProps
|
71
|
-
clonedProps
|
64
|
+
var clonedProps = _.clone(this.component.props);
|
65
|
+
if(!clonedProps[target]) {
|
66
|
+
clonedProps[target] = [];
|
72
67
|
}
|
73
68
|
|
74
69
|
var obj = {
|
@@ -76,25 +71,29 @@ $(document).on('rails_admin.dom_ready', function() {
|
|
76
71
|
props: {}
|
77
72
|
};
|
78
73
|
|
79
|
-
clonedProps.
|
74
|
+
clonedProps[target].push(obj);
|
80
75
|
this.parentComponents[this.parentIndex].props = clonedProps;
|
81
76
|
},
|
82
77
|
|
83
|
-
onChangePicker: function(event,
|
78
|
+
onChangePicker: function(event, fieldName) {
|
84
79
|
var el = event.target;
|
85
80
|
var value = el.options[el.selectedIndex].getAttribute('data-json');
|
86
81
|
var json = JSON.parse(value);
|
87
82
|
|
88
|
-
var clonedProps = _.clone(component.props);
|
83
|
+
var clonedProps = _.clone(this.component.props);
|
89
84
|
clonedProps[fieldName] = json;
|
90
85
|
this.parentComponents[this.parentIndex].props = clonedProps;
|
91
86
|
},
|
92
87
|
|
93
|
-
pickerOptionIsSelected: function(
|
94
|
-
return component.props &&
|
95
|
-
component.props[fieldName] &&
|
96
|
-
component.props[fieldName][recordLabel] &&
|
97
|
-
component.props[fieldName][recordLabel] === recordName;
|
88
|
+
pickerOptionIsSelected: function(fieldName, recordLabel, recordName) {
|
89
|
+
return this.component.props &&
|
90
|
+
this.component.props[fieldName] &&
|
91
|
+
this.component.props[fieldName][recordLabel] &&
|
92
|
+
this.component.props[fieldName][recordLabel] === recordName;
|
93
|
+
},
|
94
|
+
|
95
|
+
nestedComponentTypeIsAllowed: function(componentType, allowedComponentTypes) {
|
96
|
+
return _.contains(allowedComponentTypes, componentType)
|
98
97
|
}
|
99
98
|
}
|
100
99
|
};
|
@@ -15,12 +15,15 @@
|
|
15
15
|
<button v-on="click: moveUp" type="button" class="btn btn-default {{ moveUpEnabled ? '' : 'disabled' }}">
|
16
16
|
<i class="icon-circle-arrow-up"></i>
|
17
17
|
</button>
|
18
|
+
|
18
19
|
<button v-on="click: moveDown" type="button" class="btn btn-default {{ moveDownEnabled ? '' : 'disabled' }}">
|
19
20
|
<i class="icon-circle-arrow-down"></i>
|
20
21
|
</button>
|
22
|
+
|
21
23
|
<button v-on="click: expanded = !expanded" type="button" class="btn btn-default">
|
22
24
|
<i class="{{ expanded ? 'icon-resize-small' : 'icon-resize-full' }}"></i>
|
23
25
|
</button>
|
26
|
+
|
24
27
|
<button v-on="click:remove" type="button" class="btn btn-default">
|
25
28
|
<i class="icon-remove"></i>
|
26
29
|
</button>
|
@@ -44,11 +47,11 @@
|
|
44
47
|
<% end %>
|
45
48
|
|
46
49
|
<% if f.type == :picker %>
|
47
|
-
<select v-on="change: onChangePicker($event,
|
50
|
+
<select v-on="change: onChangePicker($event, '<%= f.name %>')" class="form-control record-picker">
|
48
51
|
<option value=""></option>
|
49
52
|
<% f.picker_records.each do |record| %>
|
50
53
|
<option
|
51
|
-
v-attr="selected: pickerOptionIsSelected(
|
54
|
+
v-attr="selected: pickerOptionIsSelected('<%= f.name %>', '<%= f.picker_label %>', '<%= record.send(f.picker_label) %>')"
|
52
55
|
value="<%= record.send(f.picker_label) %>"
|
53
56
|
data-json="<%= record.to_json %>">
|
54
57
|
<%= record.send(f.picker_label) %>
|
@@ -58,22 +61,39 @@
|
|
58
61
|
<% end %>
|
59
62
|
|
60
63
|
<% if f.type == :list %>
|
61
|
-
|
62
|
-
<div v-repeat="nested_component: component.props.components">
|
64
|
+
<div v-repeat="nestedComponent: component.props.<%= f.name %>">
|
63
65
|
<div
|
64
|
-
v-component="component-type-{{
|
65
|
-
v-with="component:
|
66
|
+
v-component="component-type-{{ nestedComponent.type }}"
|
67
|
+
v-with="component: nestedComponent, parentComponents: component.props.<%= f.name %>, parentIndex: $index">
|
66
68
|
</div>
|
67
69
|
</div>
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
<
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
71
|
+
<!-- Add nested component -- one type allowed -->
|
72
|
+
<% if f.allowed_nested_component_types.count == 1 %>
|
73
|
+
<a href="#"
|
74
|
+
class="btn btn-info"
|
75
|
+
v-repeat="componentType: $root.componentTypes"
|
76
|
+
v-show="nestedComponentTypeIsAllowed(componentType.type, <%= f.allowed_nested_component_types.map { |nct| nct.to_s } %>)"
|
77
|
+
v-on="click: addComponent($event, '<%= f.name %>', componentType.type)">
|
78
|
+
Add {{ componentType.label | lowercase }}
|
79
|
+
</a>
|
80
|
+
<% end %>
|
81
|
+
|
82
|
+
<!-- Add nested component -- multiple types allowed -->
|
83
|
+
<% if f.allowed_nested_component_types.count > 1 %>
|
84
|
+
<div class="dropdown">
|
85
|
+
<a class="dropdown-toggle btn btn-info" data-toggle="dropdown" href="#">Add component <b class="caret"></b></a>
|
86
|
+
<ul class="dropdown-menu">
|
87
|
+
<li v-repeat="componentType: $root.componentTypes">
|
88
|
+
<a href="#"
|
89
|
+
v-if="nestedComponentTypeIsAllowed(componentType.type, <%= f.allowed_nested_component_types.map { |nct| nct.to_s } %>)"
|
90
|
+
v-on="click: addComponent($event, '<%= f.name %>', componentType.type)">
|
91
|
+
{{ componentType.label }}
|
92
|
+
</a>
|
93
|
+
</li>
|
94
|
+
</ul>
|
95
|
+
</div>
|
96
|
+
<% end %>
|
77
97
|
<% end %>
|
78
98
|
|
79
99
|
<%= content_tag :p, f.help, class: "help-block" unless f.help.nil? %>
|
@@ -92,7 +112,7 @@
|
|
92
112
|
|
93
113
|
<!-- Dropdown to add new content -->
|
94
114
|
<div class="dropdown pull-left">
|
95
|
-
<a class="dropdown-toggle btn btn-info" data-toggle="dropdown" href="#">
|
115
|
+
<a class="dropdown-toggle btn btn-info" data-toggle="dropdown" href="#">Add component <b class="caret"></b></a>
|
96
116
|
|
97
117
|
<ul class="dropdown-menu">
|
98
118
|
<li v-repeat="componentType: componentTypes">
|
@@ -46,8 +46,8 @@ module RailsAdmin
|
|
46
46
|
@label = type.to_s.humanize
|
47
47
|
end
|
48
48
|
|
49
|
-
def field(name, type)
|
50
|
-
field = Field.new(name, type)
|
49
|
+
def field(name, type, options = {})
|
50
|
+
field = Field.new(name, type, options)
|
51
51
|
|
52
52
|
yield(field) if block_given?
|
53
53
|
|
@@ -68,13 +68,17 @@ module RailsAdmin
|
|
68
68
|
attr_accessor :label, :help
|
69
69
|
attr_accessor :picker_label
|
70
70
|
attr_accessor :picker_records
|
71
|
-
attr_accessor :
|
71
|
+
attr_accessor :allowed_nested_component_types
|
72
72
|
|
73
|
-
def initialize(name, type)
|
73
|
+
def initialize(name, type, options = {})
|
74
74
|
@name = name
|
75
75
|
@type = type
|
76
76
|
@label = name.to_s.humanize
|
77
|
-
|
77
|
+
|
78
|
+
if type == :list
|
79
|
+
@allowed_nested_component_types = options[:components] unless options[:components].nil?
|
80
|
+
@allowed_nested_component_types = [options[:component]] unless options[:component].nil?
|
81
|
+
end
|
78
82
|
end
|
79
83
|
|
80
84
|
def label(s = nil)
|
@@ -89,14 +93,6 @@ module RailsAdmin
|
|
89
93
|
@picker_label = label
|
90
94
|
@picker_records = records
|
91
95
|
end
|
92
|
-
|
93
|
-
def component(type)
|
94
|
-
component = Component.new(type)
|
95
|
-
|
96
|
-
yield(component) if block_given?
|
97
|
-
|
98
|
-
@components << component
|
99
|
-
end
|
100
96
|
end
|
101
97
|
end
|
102
98
|
end
|