rails_admin 0.7.0 → 0.8.1

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.

Potentially problematic release.


This version of rails_admin might be problematic. Click here for more details.

Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +13 -2
  3. data/README.md +2 -2
  4. data/app/assets/javascripts/rails_admin/ra.filter-box.js +53 -39
  5. data/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +50 -32
  6. data/app/assets/javascripts/rails_admin/ra.i18n.coffee +5 -3
  7. data/app/assets/javascripts/rails_admin/ra.widgets.coffee +21 -6
  8. data/app/assets/javascripts/rails_admin/rails_admin.js +2 -3
  9. data/app/assets/stylesheets/rails_admin/base/theming.scss +6 -7
  10. data/app/assets/stylesheets/rails_admin/custom/mixins.scss +3 -4
  11. data/app/assets/stylesheets/rails_admin/custom/theming.scss +4 -4
  12. data/app/assets/stylesheets/rails_admin/custom/variables.scss +4 -4
  13. data/app/assets/stylesheets/rails_admin/rails_admin.scss.erb +3 -3
  14. data/app/assets/stylesheets/rails_admin/themes/default/mixins.scss +2 -2
  15. data/app/assets/stylesheets/rails_admin/themes/default/theming.scss +3 -3
  16. data/app/assets/stylesheets/rails_admin/themes/default/variables.scss +3 -3
  17. data/app/controllers/rails_admin/application_controller.rb +0 -2
  18. data/app/controllers/rails_admin/main_controller.rb +6 -5
  19. data/app/helpers/rails_admin/application_helper.rb +3 -3
  20. data/app/helpers/rails_admin/main_helper.rb +45 -0
  21. data/app/views/layouts/rails_admin/application.html.haml +2 -2
  22. data/app/views/layouts/rails_admin/pjax.html.haml +2 -2
  23. data/app/views/rails_admin/main/_form_datetime.html.haml +4 -1
  24. data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +1 -0
  25. data/app/views/rails_admin/main/_submit_buttons.html.haml +1 -1
  26. data/app/views/rails_admin/main/export.html.haml +13 -13
  27. data/app/views/rails_admin/main/index.html.haml +20 -64
  28. data/config/locales/rails_admin.en.yml +0 -1
  29. data/lib/generators/rails_admin/templates/initializer.erb +3 -0
  30. data/lib/rails_admin.rb +2 -1
  31. data/lib/rails_admin/abstract_model.rb +14 -16
  32. data/lib/rails_admin/adapters/active_record.rb +17 -8
  33. data/lib/rails_admin/adapters/active_record/association.rb +5 -0
  34. data/lib/rails_admin/adapters/mongoid.rb +7 -12
  35. data/lib/rails_admin/adapters/mongoid/association.rb +5 -0
  36. data/lib/rails_admin/config/actions/export.rb +1 -1
  37. data/lib/rails_admin/config/fields.rb +1 -0
  38. data/lib/rails_admin/config/fields/association.rb +5 -0
  39. data/lib/rails_admin/config/fields/base.rb +4 -0
  40. data/lib/rails_admin/config/fields/factories/paperclip.rb +1 -1
  41. data/lib/rails_admin/config/fields/factories/refile.rb +25 -0
  42. data/lib/rails_admin/config/fields/types/active_record_enum.rb +5 -5
  43. data/lib/rails_admin/config/fields/types/all.rb +1 -0
  44. data/lib/rails_admin/config/fields/types/bson_object_id.rb +16 -2
  45. data/lib/rails_admin/config/fields/types/date.rb +19 -8
  46. data/lib/rails_admin/config/fields/types/datetime.rb +33 -117
  47. data/lib/rails_admin/config/fields/types/json.rb +5 -2
  48. data/lib/rails_admin/config/fields/types/refile.rb +27 -0
  49. data/lib/rails_admin/config/fields/types/serialized.rb +5 -2
  50. data/lib/rails_admin/config/fields/types/time.rb +6 -18
  51. data/lib/rails_admin/config/has_fields.rb +2 -2
  52. data/lib/rails_admin/config/lazy_model.rb +2 -2
  53. data/lib/rails_admin/config/proxyable/proxy.rb +2 -4
  54. data/lib/rails_admin/extensions/pundit.rb +3 -0
  55. data/lib/rails_admin/extensions/pundit/authorization_adapter.rb +63 -0
  56. data/lib/rails_admin/support/datetime.rb +99 -0
  57. data/lib/rails_admin/support/hash_helper.rb +28 -0
  58. data/lib/rails_admin/support/i18n.rb +41 -0
  59. data/lib/rails_admin/version.rb +2 -2
  60. data/vendor/assets/javascripts/rails_admin/bootstrap-datetimepicker.js +2444 -0
  61. data/vendor/assets/javascripts/rails_admin/moment-with-locales.js +9977 -0
  62. data/vendor/assets/stylesheets/rails_admin/_bootstrap-datetimepicker.scss +343 -0
  63. data/vendor/assets/stylesheets/rails_admin/bootstrap-datetimepicker-build.scss +16 -0
  64. metadata +14 -9
  65. data/app/assets/javascripts/rails_admin/jquery.ui.timepicker.js +0 -1437
  66. data/app/assets/javascripts/rails_admin/ra.datetimepicker.js +0 -83
  67. data/app/assets/stylesheets/rails_admin/jquery.ui.timepicker.scss +0 -68
  68. data/app/assets/stylesheets/rails_admin/ra.calendar-additions.scss +0 -45
  69. data/lib/rails_admin/i18n_support.rb +0 -39
  70. data/lib/rails_admin/support/core_extensions.rb +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 531cf0017e10c6ec70071cc36bf6f26bb022eb0a
4
- data.tar.gz: 1660b6774fadf54a24b9d67a534305630727ccb1
3
+ metadata.gz: 7e491a0735ca200d0e74ad5dcb6bd299919da52b
4
+ data.tar.gz: 5a96d44742b0029c1d7554c532e7fa6ae6ed6853
5
5
  SHA512:
6
- metadata.gz: f2ca04cae79c6bfcdaab54dfadcbaa72b36bdc715ac37d15bbaa52d9ff383b27f7d514fd76537e466ebb6dd76ef1b5805c53dc73ade5abb6af717e1164e6a3a7
7
- data.tar.gz: 39da0448e0b86dde4a980fa8444ec09007d9e095285d89a2329eb8c79bc03a2ec56dbed0c9c8da2503e50ba3391f36c4687f7995ce3a3c02b67f985f5d080674
6
+ metadata.gz: 51af7b94bb6eb226489fdd111ba81bd17a16f32910c44c97876b427396d48c8b972c7b3ea288f3d850157c12bb1fa628351b878e6e2d1bcb1683ec6d402d7349
7
+ data.tar.gz: 99bedb21db9884f4f58c0ed3069e15961aad70209d75e1cd8dcbff99b6e5fa39a3ca02f90eb82593f0b8d44e9cccf2b2cd15ccefec1bcd4402b999acba041916
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ group :mongoid do
7
7
  gem 'mongoid', '~> 4.0.0'
8
8
  gem 'mongoid-paperclip', '>= 0.0.8', require: 'mongoid_paperclip'
9
9
  gem 'carrierwave-mongoid', '>= 0.6.3', require: 'carrierwave/mongoid'
10
+ gem 'refile-mongoid', '>= 0.0.1', platforms: [:ruby_21, :ruby_22]
10
11
  end
11
12
 
12
13
  group :active_record do
@@ -34,11 +35,11 @@ end
34
35
 
35
36
  group :test do
36
37
  gem 'cancan', '>= 1.6'
37
- gem 'cancancan', '~> 1.9'
38
+ gem 'cancancan', '~> 1.12.0'
38
39
  gem 'capybara', '>= 2.1'
39
40
  gem 'carrierwave', '>= 0.8'
40
41
  gem 'coveralls'
41
- gem 'database_cleaner', ['>= 1.2', '!= 1.4.0']
42
+ gem 'database_cleaner', ['>= 1.2', '!= 1.4.0', '!= 1.5.0']
42
43
  gem 'dragonfly', '~> 1.0'
43
44
  gem 'factory_girl', '>= 4.2'
44
45
  gem 'generator_spec', '>= 0.8'
@@ -46,11 +47,21 @@ group :test do
46
47
  gem 'mini_magick', '>= 3.4'
47
48
  gem 'paperclip', ['>= 3.4', '!= 4.3.0']
48
49
  gem 'poltergeist', '~> 1.5'
50
+ gem 'pundit'
49
51
  gem 'rack-cache', require: 'rack/cache'
50
52
  gem 'rspec-rails', '>= 2.14'
51
53
  gem 'rubocop', '~> 0.31.0'
52
54
  gem 'simplecov', '>= 0.9', require: false
53
55
  gem 'timecop', '>= 0.5'
56
+
57
+ platforms :ruby_19 do
58
+ gem 'tins', '~> 1.6.0'
59
+ end
60
+
61
+ platforms :ruby_21, :ruby_22 do
62
+ gem 'refile', '~> 0.5', require: 'refile/rails'
63
+ gem 'refile-mini_magick', '>= 0.1.0'
64
+ end
54
65
  end
55
66
 
56
67
  gemspec
data/README.md CHANGED
@@ -23,7 +23,7 @@ RailsAdmin is a Rails engine that provides an easy-to-use interface for managing
23
23
  * Search and filtering
24
24
  * Export data to CSV/JSON/XML
25
25
  * Authentication (via [Devise](https://github.com/plataformatec/devise) or other)
26
- * Authorization (via [Cancan](https://github.com/ryanb/cancan))
26
+ * Authorization (via [CanCanCan](https://github.com/CanCanCommunity/cancancan) or [Pundit](https://github.com/elabs/pundit))
27
27
  * User action history (via [PaperTrail](https://github.com/airblade/paper_trail))
28
28
  * Supported ORMs
29
29
  * ActiveRecord
@@ -44,7 +44,7 @@ In `config/initializers/rails_admin`:
44
44
 
45
45
  [Details](https://github.com/sferik/rails_admin/wiki/Base-configuration)
46
46
 
47
- To begin with, you may be interested in setting up [Devise](https://github.com/sferik/rails_admin/wiki/Devise), [Cancan](https://github.com/sferik/rails_admin/wiki/Cancan) or [Papertrail](https://github.com/sferik/rails_admin/wiki/Papertrail)!
47
+ To begin with, you may be interested in setting up [Devise](https://github.com/sferik/rails_admin/wiki/Devise), [CanCanCan](https://github.com/sferik/rails_admin/wiki/Cancancan) or [Papertrail](https://github.com/sferik/rails_admin/wiki/Papertrail)!
48
48
 
49
49
  ### Per model
50
50
  ```ruby
@@ -3,17 +3,20 @@
3
3
  var filters;
4
4
 
5
5
  $.filters = filters = {
6
- options: {
7
- regional: {
8
- datePicker: {
9
- dateFormat: 'mm/dd/yy'
10
- }
11
- }
12
- },
13
-
14
- append: function(field_label, field_name, field_type, field_value, field_operator, field_options, index) {
15
- var value_name = 'f[' + field_name + '][' + index + '][v]';
6
+ append: function(options) {
7
+ options = options || {};
8
+ var field_label = options['label'];
9
+ var field_name = options['name'];
10
+ var field_type = options['type'];
11
+ var field_value = options['value'];
12
+ var field_operator = options['operator'];
13
+ var select_options = options['select_options'];
14
+ var index = options['index'];
15
+ var value_name = 'f[' + field_name + '][' + index + '][v]';
16
16
  var operator_name = 'f[' + field_name + '][' + index + '][o]';
17
+ var control = null;
18
+ var additional_control = null;
19
+
17
20
  switch(field_type) {
18
21
  case 'boolean':
19
22
  var control = '<select class="input-sm form-control" name="' + value_name + '">' +
@@ -26,9 +29,13 @@
26
29
  '</select>';
27
30
  break;
28
31
  case 'date':
32
+ additional_control =
33
+ '<input size="20" class="date additional-fieldset default input-sm form-control" style="display:' + ((!field_operator || field_operator == "default") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[0] || '') + '" /> ' +
34
+ '<input size="20" placeholder="-∞" class="date additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[1] || '') + '" /> ' +
35
+ '<input size="20" placeholder="∞" class="date additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[2] || '') + '" />';
29
36
  case 'datetime':
30
37
  case 'timestamp':
31
- var control = '<select class="switch-additionnal-fieldsets input-sm form-control" name="' + operator_name + '">' +
38
+ control = control || '<select class="switch-additionnal-fieldsets input-sm form-control" name="' + operator_name + '">' +
32
39
  '<option ' + (field_operator == "default" ? 'selected="selected"' : '') + ' data-additional-fieldset="default" value="default">' + RailsAdmin.I18n.t("date") + '</option>' +
33
40
  '<option ' + (field_operator == "between" ? 'selected="selected"' : '') + ' data-additional-fieldset="between" value="between">' + RailsAdmin.I18n.t("between_and_") + '</option>' +
34
41
  '<option ' + (field_operator == "today" ? 'selected="selected"' : '') + ' value="today">' + RailsAdmin.I18n.t("today") + '</option>' +
@@ -39,29 +46,29 @@
39
46
  '<option ' + (field_operator == "_not_null" ? 'selected="selected"' : '') + ' value="_not_null">' + RailsAdmin.I18n.t("is_present") + '</option>' +
40
47
  '<option ' + (field_operator == "_null" ? 'selected="selected"' : '') + ' value="_null" >' + RailsAdmin.I18n.t("is_blank") + '</option>' +
41
48
  '</select>'
42
- var additional_control =
43
- '<input class="date additional-fieldset default input-sm form-control" style="display:' + ((!field_operator || field_operator == "default") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[0] || '') + '" /> ' +
44
- '<input placeholder="-∞" class="date additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[1] || '') + '" /> ' +
45
- '<input placeholder="∞" class="date additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[2] || '') + '" />';
49
+ additional_control = additional_control ||
50
+ '<input size="25" class="datetime additional-fieldset default input-sm form-control" style="display:' + ((!field_operator || field_operator == "default") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[0] || '') + '" /> ' +
51
+ '<input size="25" placeholder="-∞" class="datetime additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[1] || '') + '" /> ' +
52
+ '<input size="25" placeholder="∞" class="datetime additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="text" name="' + value_name + '[]" value="' + (field_value[2] || '') + '" />';
46
53
  break;
47
54
  case 'enum':
48
55
  var multiple_values = ((field_value instanceof Array) ? true : false)
49
- var control = '<select style="display:' + (multiple_values ? 'none' : 'inline-block') + '" ' + (multiple_values ? '' : 'name="' + value_name + '"') + ' data-name="' + value_name + '" class="select-single input-sm form-control">' +
56
+ control = '<select style="display:' + (multiple_values ? 'none' : 'inline-block') + '" ' + (multiple_values ? '' : 'name="' + value_name + '"') + ' data-name="' + value_name + '" class="select-single input-sm form-control">' +
50
57
  '<option value="_discard">...</option>' +
51
58
  '<option ' + (field_value == "_present" ? 'selected="selected"' : '') + ' value="_present">' + RailsAdmin.I18n.t("is_present") + '</option>' +
52
59
  '<option ' + (field_value == "_blank" ? 'selected="selected"' : '') + ' value="_blank">' + RailsAdmin.I18n.t("is_blank") + '</option>' +
53
60
  '<option disabled="disabled">---------</option>' +
54
- field_options +
61
+ select_options +
55
62
  '</select>' +
56
63
  '<select multiple="multiple" style="display:' + (multiple_values ? 'inline-block' : 'none') + '" ' + (multiple_values ? 'name="' + value_name + '[]"' : '') + ' data-name="' + value_name + '[]" class="select-multiple input-sm form-control">' +
57
- field_options +
64
+ select_options +
58
65
  '</select> ' +
59
66
  '<a href="#" class="switch-select"><i class="icon-' + (multiple_values ? 'minus' : 'plus') + '"></i></a>';
60
67
  break;
61
68
  case 'string':
62
69
  case 'text':
63
70
  case 'belongs_to_association':
64
- var control = '<select class="switch-additionnal-fieldsets input-sm form-control" value="' + field_operator + '" name="' + operator_name + '">' +
71
+ control = '<select class="switch-additionnal-fieldsets input-sm form-control" value="' + field_operator + '" name="' + operator_name + '">' +
65
72
  '<option data-additional-fieldset="additional-fieldset"' + (field_operator == "like" ? 'selected="selected"' : '') + ' value="like">' + RailsAdmin.I18n.t("contains") + '</option>' +
66
73
  '<option data-additional-fieldset="additional-fieldset"' + (field_operator == "is" ? 'selected="selected"' : '') + ' value="is">' + RailsAdmin.I18n.t("is_exactly") + '</option>' +
67
74
  '<option data-additional-fieldset="additional-fieldset"' + (field_operator == "starts_with" ? 'selected="selected"' : '') + ' value="starts_with">' + RailsAdmin.I18n.t("starts_with") + '</option>' +
@@ -70,50 +77,57 @@
70
77
  '<option ' + (field_operator == "_not_null" ? 'selected="selected"' : '') + ' value="_not_null">' + RailsAdmin.I18n.t("is_present") + '</option>' +
71
78
  '<option ' + (field_operator == "_null" ? 'selected="selected"' : '') + ' value="_null">' + RailsAdmin.I18n.t("is_blank") + '</option>' +
72
79
  '</select>'
73
- var additional_control = '<input class="additional-fieldset input-sm form-control" style="display:' + (field_operator == "_blank" || field_operator == "_present" ? 'none' : 'inline-block') + ';" type="text" name="' + value_name + '" value="' + field_value + '" /> ';
80
+ additional_control = '<input class="additional-fieldset input-sm form-control" style="display:' + (field_operator == "_blank" || field_operator == "_present" ? 'none' : 'inline-block') + ';" type="text" name="' + value_name + '" value="' + field_value + '" /> ';
74
81
  break;
75
82
  case 'integer':
76
83
  case 'decimal':
77
84
  case 'float':
78
- var control = '<select class="switch-additionnal-fieldsets input-sm form-control" name="' + operator_name + '">' +
85
+ control = '<select class="switch-additionnal-fieldsets input-sm form-control" name="' + operator_name + '">' +
79
86
  '<option ' + (field_operator == "default" ? 'selected="selected"' : '') + ' data-additional-fieldset="default" value="default">' + RailsAdmin.I18n.t("number") + '</option>' +
80
87
  '<option ' + (field_operator == "between" ? 'selected="selected"' : '') + ' data-additional-fieldset="between" value="between">' + RailsAdmin.I18n.t("between_and_") + '</option>' +
81
88
  '<option disabled="disabled">---------</option>' +
82
89
  '<option ' + (field_operator == "_not_null" ? 'selected="selected"' : '') + ' value="_not_null">' + RailsAdmin.I18n.t("is_present") +'</option>' +
83
90
  '<option ' + (field_operator == "_null" ? 'selected="selected"' : '') + ' value="_null" >' + RailsAdmin.I18n.t("is_blank") + '</option>' +
84
91
  '</select>'
85
- var additional_control =
92
+ additional_control =
86
93
  '<input class="additional-fieldset default input-sm form-control" style="display:' + ((!field_operator || field_operator == "default") ? 'inline-block' : 'none') + ';" type="' + field_type + '" name="' + value_name + '[]" value="' + (field_value[0] || '') + '" /> ' +
87
94
  '<input placeholder="-∞" class="additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="' + field_type + '" name="' + value_name + '[]" value="' + (field_value[1] || '') + '" /> ' +
88
95
  '<input placeholder="∞" class="additional-fieldset between input-sm form-control" style="display:' + ((field_operator == "between") ? 'inline-block' : 'none') + ';" type="' + field_type + '" name="' + value_name + '[]" value="' + (field_value[2] || '') + '" />';
89
96
  break;
90
97
  default:
91
- var control = '<input type="text" class="input-sm form-control" name="' + value_name + '" value="' + field_value + '"/> ';
98
+ control = '<input type="text" class="input-sm form-control" name="' + value_name + '" value="' + field_value + '"/> ';
92
99
  break;
93
100
  }
94
101
 
95
- var content = '<p class="filter form-search">' +
96
- '<span class="label label-info form-label"><a href="#" class="delete"><i class="icon-trash icon-white"></i></a> ' + field_label + '</span> ' +
97
- control + " " +
98
- (additional_control || '') +
99
- '</p> ';
100
- $('#filters_box').append(content);
101
- $('#filters_box .date').datepicker(this.options.regional.datePicker);
102
+ var $content = $('<p>')
103
+ .addClass('filter form-search')
104
+ .append('<span class="label label-info form-label"><a href="#delete" class="delete"><i class="fa fa-trash-o fa-fw icon-white"></i></a> ' + field_label + '</span>')
105
+ .append('&nbsp;' + control + '&nbsp;' + (additional_control || ''));
106
+
107
+ $('#filters_box').append($content);
108
+
109
+ $content.find('.date, .datetime').datetimepicker({
110
+ locale: RailsAdmin.I18n.locale,
111
+ showTodayButton: true,
112
+ format: options['datetimepicker_format']
113
+ });
114
+
102
115
  $("hr.filters_box:hidden").show('slow');
103
116
  }
104
117
  }
105
118
 
106
119
  $(document).on('click', "#filters a", function(e) {
107
120
  e.preventDefault();
108
- $.filters.append(
109
- $(this).data('field-label'),
110
- $(this).data('field-name'),
111
- $(this).data('field-type'),
112
- $(this).data('field-value'),
113
- $(this).data('field-operator'),
114
- $(this).data('field-options'),
115
- $.now().toString().slice(6,11)
116
- );
121
+ $.filters.append({
122
+ label: $(this).data('field-label'),
123
+ name: $(this).data('field-name'),
124
+ type: $(this).data('field-type'),
125
+ value: $(this).data('field-value'),
126
+ operator: $(this).data('field-operator'),
127
+ select_options: $(this).data('field-options'),
128
+ index: $.now().toString().slice(6,11),
129
+ datetimepicker_format: $(this).data('field-datetimepicker-format')
130
+ });
117
131
  });
118
132
 
119
133
  $(document).on('click', "#filters_box .delete", function(e) {
@@ -17,6 +17,7 @@
17
17
  return { query: query };
18
18
  },
19
19
  sortable: false,
20
+ removable: true,
20
21
  regional: {
21
22
  up: "Up",
22
23
  down: "Down",
@@ -68,20 +69,23 @@
68
69
  this.collection = $('<select multiple="multiple"></select>');
69
70
 
70
71
  this.collection.addClass("form-control ra-multiselect-collection");
71
-
72
+
72
73
  this.addAll = $('<a href="#" class="ra-multiselect-item-add-all"><span class="ui-icon ui-icon-circle-triangle-e"></span>' + this.options.regional.chooseAll + '</a>');
73
-
74
+
74
75
  this.columns.left.html(this.collection)
75
76
  .append(this.addAll);
76
-
77
+
77
78
  this.collection.wrap('<div class="wrapper"/>');
78
-
79
-
79
+
80
+
80
81
  this.add = $('<a href="#" class="ui-icon ui-icon-circle-triangle-e ra-multiselect-item-add">' + this.options.regional.add + '</a>');
82
+ this.columns.center.append(this.add);
81
83
 
82
- this.remove = $('<a href="#" class="ui-icon ui-icon-circle-triangle-w ra-multiselect-item-remove">' + this.options.regional.remove + '</a>');
84
+ if (this.options.removable) {
85
+ this.remove = $('<a href="#" class="ui-icon ui-icon-circle-triangle-w ra-multiselect-item-remove">' + this.options.regional.remove + '</a>');
86
+ this.columns.center.append(this.remove);
87
+ }
83
88
 
84
- this.columns.center.append(this.add).append(this.remove)
85
89
  if (this.options.sortable) {
86
90
  this.up = $('<a href="#" class="ui-icon ui-icon-circle-triangle-n ra-multiselect-item-up">' + this.options.regional.up + '</a>');
87
91
  this.down = $('<a href="#" class="ui-icon ui-icon-circle-triangle-s ra-multiselect-item-down">' + this.options.regional.down + '</a>');
@@ -89,14 +93,14 @@
89
93
  }
90
94
 
91
95
  this.selection = $('<select class="form-control ra-multiselect-selection" multiple="multiple"></select>');
92
-
93
-
96
+ this.columns.right.append(this.selection);
97
+
94
98
 
95
- this.removeAll = $('<a href="#" class="ra-multiselect-item-remove-all"><span class="ui-icon ui-icon-circle-triangle-w"></span>' + this.options.regional.clearAll + '</a>');
99
+ if (this.options.removable) {
100
+ this.removeAll = $('<a href="#" class="ra-multiselect-item-remove-all"><span class="ui-icon ui-icon-circle-triangle-w"></span>' + this.options.regional.clearAll + '</a>');
101
+ this.columns.right.append(this.removeAll);
102
+ }
96
103
 
97
- this.columns.right.append(this.selection)
98
- .append(this.removeAll);
99
-
100
104
  this.selection.wrap('<div class="wrapper"/>');
101
105
 
102
106
  this.element.css({display: "none"});
@@ -122,24 +126,26 @@
122
126
  /* Add to selection */
123
127
  this.add.click(function(e){
124
128
  widget._select($(':selected', widget.collection));
125
-
126
- e.preventDefault();
127
- widget.selection.trigger('change');
128
- });
129
129
 
130
- /* Remove all from selection */
131
- this.removeAll.click(function(e){
132
- widget._deSelect($('option', widget.selection));
133
130
  e.preventDefault();
134
131
  widget.selection.trigger('change');
135
132
  });
136
133
 
137
- /* Remove from selection */
138
- this.remove.click(function(e){
139
- widget._deSelect($(':selected', widget.selection));
140
- e.preventDefault();
141
- widget.selection.trigger('change');
142
- });
134
+ if (this.options.removable) {
135
+ /* Remove all from selection */
136
+ this.removeAll.click(function(e){
137
+ widget._deSelect($('option', widget.selection));
138
+ e.preventDefault();
139
+ widget.selection.trigger('change');
140
+ });
141
+
142
+ /* Remove from selection */
143
+ this.remove.click(function(e){
144
+ widget._deSelect($(':selected', widget.selection));
145
+ e.preventDefault();
146
+ widget.selection.trigger('change');
147
+ });
148
+ }
143
149
 
144
150
  var timeout = null;
145
151
  if(this.options.sortable) {
@@ -180,7 +186,7 @@
180
186
  widget.collection.html('');
181
187
  for (i in filtered) {
182
188
  widget.collection.append(
183
- $('<option></option>').attr('value', matches[i].id).attr('title', matches[i].label).text(matches[i].label)
189
+ $('<option></option>').attr('value', matches[filtered[i]].id).attr('title', matches[filtered[i]].label).text(matches[filtered[i]].label)
184
190
  );
185
191
  }
186
192
  } else {
@@ -189,15 +195,25 @@
189
195
  });
190
196
  },
191
197
 
198
+ /*
199
+ * Cache key is stored in the format `o_<option value>` to avoid JS
200
+ * engine coercing string keys to int keys, and thereby preserving
201
+ * the insertion order. The value for each key is in turn an object
202
+ * that stores the option tag's HTML text and the value. Example:
203
+ * cache = {
204
+ * 'o_271': { id: 271, value: 'CartItem #271'},
205
+ * 'o_270': { id: 270, value: 'CartItem #270'}
206
+ * }
207
+ */
192
208
  _buildCache: function(options) {
193
209
  var widget = this;
194
210
 
195
211
  this.element.find("option").each(function(i, option) {
196
212
  if (option.selected) {
197
- widget._cache[option.value] = option.innerHTML;
213
+ widget._cache['o_' + option.value] = {id: option.value, value: option.innerHTML};
198
214
  $(option).clone().appendTo(widget.selection).attr("selected", false).attr("title", $(option).text());
199
215
  } else {
200
- widget._cache[option.value] = option.innerHTML;
216
+ widget._cache['o_' + option.value] = {id: option.value, value: option.innerHTML};
201
217
  $(option).clone().appendTo(widget.collection).attr("selected", false).attr("title", $(option).text());
202
218
  }
203
219
  });
@@ -220,7 +236,8 @@
220
236
  if (!this.options.xhr) {
221
237
  for (i in this._cache) {
222
238
  if (this._cache.hasOwnProperty(i)) {
223
- matches.push({id: i, label: this._cache[i]});
239
+ option = this._cache[i];
240
+ matches.push({id: option.id, label: option.value});
224
241
  }
225
242
  }
226
243
  success.apply(this, [matches]);
@@ -246,8 +263,9 @@
246
263
  query = new RegExp(query + '.*', 'i');
247
264
 
248
265
  for (i in this._cache) {
249
- if (this._cache.hasOwnProperty(i) && query.test(this._cache[i])) {
250
- matches.push({id: i, label: this._cache[i]});
266
+ if (this._cache.hasOwnProperty(i) && query.test(this._cache[i]['value'])) {
267
+ option = this._cache[i];
268
+ matches.push({id: option.id, label: option.value});
251
269
  }
252
270
  }
253
271
 
@@ -1,6 +1,8 @@
1
- class @RailsAdmin
1
+ @RailsAdmin ||= {}
2
2
  @RailsAdmin.I18n = class Locale
3
- @init: (@locale)->
3
+ @init: (@locale, @translations)->
4
+ moment.locale(@locale)
5
+
4
6
  @t:(key) ->
5
7
  humanize = key.charAt(0).toUpperCase() + key.replace(/_/g, " ").slice(1)
6
- @locale[key] || humanize
8
+ @translations[key] || humanize
@@ -20,10 +20,22 @@ $(document).on 'rails_admin.dom_ready', (e, content) ->
20
20
  $(that).val(hex)
21
21
  $(that).css('backgroundColor', '#' + hex)
22
22
 
23
- # datetime
23
+ # datetime picker
24
+ $.fn.datetimepicker.defaults.icons =
25
+ time: 'fa fa-clock-o'
26
+ date: 'fa fa-calendar'
27
+ up: 'fa fa-chevron-up'
28
+ down: 'fa fa-chevron-down'
29
+ previous: 'fa fa-angle-double-left'
30
+ next: 'fa fa-angle-double-right'
31
+ today: 'fa fa-dot-circle-o'
32
+ clear: 'fa fa-trash'
33
+ close: 'fa fa-times'
24
34
 
25
35
  content.find('[data-datetimepicker]').each ->
26
- $(this).datetimepicker $(this).data('options')
36
+ options = $(this).data('options')
37
+ $.extend(options, {locale: RailsAdmin.I18n.locale})
38
+ $(this).datetimepicker options
27
39
 
28
40
  # enumeration
29
41
 
@@ -63,7 +75,7 @@ $(document).on 'rails_admin.dom_ready', (e, content) ->
63
75
  content.find('[data-filteringmultiselect]').each ->
64
76
  $(this).filteringMultiselect $(this).data('options')
65
77
  if $(this).parents("#modal").length # hide link if we already are inside a dialog (endless issues on nested dialogs with JS)
66
- $(this).parents('.control-group').find('.btn').remove()
78
+ $(this).siblings('.btn').remove()
67
79
  else
68
80
  $(this).parents('.control-group').first().remoteForm()
69
81
 
@@ -72,7 +84,7 @@ $(document).on 'rails_admin.dom_ready', (e, content) ->
72
84
  content.find('[data-filteringselect]').each ->
73
85
  $(this).filteringSelect $(this).data('options')
74
86
  if $(this).parents("#modal").length # hide link if we already are inside a dialog (endless issues on nested dialogs with JS)
75
- $(this).parents('.control-group').find('.btn').remove()
87
+ $(this).siblings('.btn').remove()
76
88
  else
77
89
  $(this).parents('.control-group').first().remoteForm()
78
90
 
@@ -151,9 +163,12 @@ $(document).on 'rails_admin.dom_ready', (e, content) ->
151
163
  beforeSend: (xhr) ->
152
164
  xhr.setRequestHeader("Accept", "application/json")
153
165
  success: (data, status, xhr) ->
154
- html = '<option></option>'
166
+ html = $('<option></option>')
155
167
  $(data).each (i, el) ->
156
- html += '<option value="' + el.id + '">' + el.label + '</option>'
168
+ option = $('<option></option>')
169
+ option.attr('value', el.id)
170
+ option.text(el.label)
171
+ html = html.add(option)
157
172
  object_select.html(html)
158
173
 
159
174
  # ckeditor