admin_it 1.3.3 → 1.3.4
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 +4 -4
- data/app/assets/javascript/admin_it/admin_it.js +6 -0
- data/app/assets/javascript/admin_it/index.js +1 -0
- data/app/assets/javascript/admin_it/switch.js +75 -0
- data/app/views/admin_it/editors/_boolean.html.slim +10 -0
- data/lib/admin_it/field/field.rb +3 -2
- data/lib/admin_it/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed2838252adc99ebf5fcd8643dbbd57dedd61212
|
4
|
+
data.tar.gz: dbb42a7dbdfbf7117344cc5c178eb160caef1235
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e093e9ff5ff82e03c4ebb3281d47cebaa969733b2b9e341ca755726a98c259e396bca5aaf7f4b43005dafca9fee09bafa7f4d0052952c649846a10d0f1a09e03
|
7
|
+
data.tar.gz: 2ede8e32d02eec21654f6e729f23985ede364ac694918e35650198f8dc86ddf84857bec63abeef6fb974adbb8ce00f4c81f7ef3f60ee31e859736d08ac714cf7
|
@@ -127,13 +127,19 @@ var initGeoPickers = function() {
|
|
127
127
|
});
|
128
128
|
}
|
129
129
|
|
130
|
+
var initSwitches = function() {
|
131
|
+
$('[data-toggle="switch"]').switch()
|
132
|
+
}
|
133
|
+
|
130
134
|
var initControls = function() {
|
131
135
|
initImageUploads();
|
132
136
|
initSelects();
|
133
137
|
initGeoPickers();
|
134
138
|
initTiles();
|
139
|
+
initSwitches();
|
135
140
|
}
|
136
141
|
|
142
|
+
|
137
143
|
$(document).on('ready page:load', function() {
|
138
144
|
initPartials();
|
139
145
|
// initDialogs();
|
@@ -0,0 +1,75 @@
|
|
1
|
+
// bootstrap 3 switch support:
|
2
|
+
// http://www.bootply.com/92189
|
3
|
+
|
4
|
+
(function($) {
|
5
|
+
function parseOptions(element, options) {
|
6
|
+
if (!$.isPlainObject(options)) options = {};
|
7
|
+
var opts = $.extend({}, $.fn.switch.defaults, element.data(), options);
|
8
|
+
if (opts.onValue == undefined) opts.onValue = true
|
9
|
+
if (opts.offValue == undefined) opts.offValue = false
|
10
|
+
return opts;
|
11
|
+
};
|
12
|
+
|
13
|
+
function toggle(element, options) {
|
14
|
+
var buttons = element.find('.btn');
|
15
|
+
|
16
|
+
if (element.find('.btn-primary').length > 0) buttons.toggleClass('btn-primary');
|
17
|
+
if (element.find('.btn-danger').length > 0) buttons.toggleClass('btn-danger');
|
18
|
+
if (element.find('.btn-success').length > 0) buttons.toggleClass('btn-success');
|
19
|
+
if (element.find('.btn-info').length > 0) buttons.toggleClass('btn-info');
|
20
|
+
|
21
|
+
buttons.toggleClass('btn-default').toggleClass('active');
|
22
|
+
|
23
|
+
var value = element.data('value') == options.onValue ? options.offValue : options.onValue
|
24
|
+
if (element.data('value') != undefined) element.data('value', value);
|
25
|
+
var input = element.find('input')
|
26
|
+
if (input.length > 0 && input.attr('value') != undefined) input.attr('value', value)
|
27
|
+
if ($.isFunction(options.change)) options.change(value);
|
28
|
+
element.trigger('change', [value]);
|
29
|
+
};
|
30
|
+
|
31
|
+
function set(element, options) {
|
32
|
+
if (element.data('value') == undefined) element.data('value', options.offValue);
|
33
|
+
if (options.value == undefined) options.value = options.offValue;
|
34
|
+
if (element.data('value') == options.value) return;
|
35
|
+
toggle(element, options);
|
36
|
+
};
|
37
|
+
|
38
|
+
$.fn.switch = function(action, options) {
|
39
|
+
if ($.isPlainObject(action)) options = action;
|
40
|
+
if (typeof action !== 'string') action = 'init';
|
41
|
+
return this.each(function() {
|
42
|
+
var $this = $(this);
|
43
|
+
if (!$.isPlainObject(options)) options = { value: options }
|
44
|
+
var opts = parseOptions($this, options);
|
45
|
+
if (action === 'init') {
|
46
|
+
if ($this.hasClass('switch-initialized')) return;
|
47
|
+
$this.addClass('switch-initialized');
|
48
|
+
if ($this.data('value') == undefined) $this.data('value', opts.offValue);
|
49
|
+
if ($this.find('.btn-primary,.btn-danger,.btn-success,.btn-info').length == 0) {
|
50
|
+
var btn = $this.find('.btn').removeClass('active btn-default');
|
51
|
+
var off = $this.data('value') == opts.onValue ? btn.last() : btn.first();
|
52
|
+
btn = $this.data('value') == opts.onValue ? btn.first() : btn.last();
|
53
|
+
btn.addClass('btn-primary active');
|
54
|
+
off.addClass('btn-default');
|
55
|
+
}
|
56
|
+
$this.on('click', function(evt) {
|
57
|
+
evt.preventDefault()
|
58
|
+
toggle($this, opts);
|
59
|
+
});
|
60
|
+
} else if (action === 'toggle') {
|
61
|
+
toggle($this, opts);
|
62
|
+
} else if (action === 'set' || action === 'val') {
|
63
|
+
set($this, opts);
|
64
|
+
} else if (action === 'on') {
|
65
|
+
opts.value = opts.onValue;
|
66
|
+
set($this, opts);
|
67
|
+
} else if (action === 'off') {
|
68
|
+
opts.value = opts.offValue;
|
69
|
+
set($this, opts);
|
70
|
+
}
|
71
|
+
});
|
72
|
+
};
|
73
|
+
|
74
|
+
$.fn.switch.defaults = {};
|
75
|
+
})(jQuery);
|
@@ -0,0 +1,10 @@
|
|
1
|
+
- for_context ||= context
|
2
|
+
- name ||= "#{for_context.resource.name}[#{field.name}]"
|
3
|
+
- id ||= "#{for_context.resource.name}_#{field.name}"
|
4
|
+
- value ||= field.read(for_context.entity)
|
5
|
+
- opts = { name: name, id: id, value: value }
|
6
|
+
|
7
|
+
.btn-group.btn-group-sm< data-toggle="switch" data-value=value.to_s
|
8
|
+
button.btn Да
|
9
|
+
input.form-control type="hidden" *opts
|
10
|
+
button.btn Нет
|
data/lib/admin_it/field/field.rb
CHANGED
@@ -19,8 +19,8 @@ module AdminIt
|
|
19
19
|
include ExtendIt::Callbacks
|
20
20
|
|
21
21
|
TYPES = %i(unknown integer float string date datetime time relation enum
|
22
|
-
array hash range regexp symbol binary image geo_point)
|
23
|
-
EDITORS = %i(text combo radio image hidden geo_picker)
|
22
|
+
array hash range regexp symbol binary image geo_point boolean)
|
23
|
+
EDITORS = %i(text combo radio image hidden geo_picker boolean)
|
24
24
|
|
25
25
|
define_callbacks :initialize
|
26
26
|
|
@@ -127,6 +127,7 @@ module AdminIt
|
|
127
127
|
return @editor = :image if type == :image
|
128
128
|
return @editor = :combo if type == :enum
|
129
129
|
return @editor = :geo_picker if type == :geo_point
|
130
|
+
return @editor = :boolean if type == :boolean
|
130
131
|
@editor = EDITORS[0]
|
131
132
|
end
|
132
133
|
|
data/lib/admin_it/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: admin_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Ovchinnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -255,6 +255,7 @@ files:
|
|
255
255
|
- app/assets/javascript/admin_it/jquery.fileupload.js
|
256
256
|
- app/assets/javascript/admin_it/jquery.geolocationpicker.js
|
257
257
|
- app/assets/javascript/admin_it/jquery.ui.widget.js
|
258
|
+
- app/assets/javascript/admin_it/switch.js
|
258
259
|
- app/assets/stylesheets/admin_it/admin_it.css
|
259
260
|
- app/assets/stylesheets/admin_it/bootstrap-theme.min.css
|
260
261
|
- app/assets/stylesheets/admin_it/bootstrap.min.css
|
@@ -268,6 +269,7 @@ files:
|
|
268
269
|
- app/views/admin_it/context/_table.html.slim
|
269
270
|
- app/views/admin_it/context/_tiles.html.slim
|
270
271
|
- app/views/admin_it/edit.html.slim
|
272
|
+
- app/views/admin_it/editors/_boolean.html.slim
|
271
273
|
- app/views/admin_it/editors/_combo.html.slim
|
272
274
|
- app/views/admin_it/editors/_geo_picker.html.slim
|
273
275
|
- app/views/admin_it/editors/_hidden.html.slim
|