trestle 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/trestle/_confirmation.js +23 -0
  3. data/app/assets/javascripts/trestle/_datepicker.js +22 -0
  4. data/app/assets/javascripts/trestle/_errors.js +11 -0
  5. data/app/assets/javascripts/trestle/_form.js +6 -0
  6. data/app/assets/javascripts/trestle/_gallery.js +27 -0
  7. data/app/assets/javascripts/trestle/_select.js +11 -0
  8. data/app/assets/javascripts/trestle/_sidebar.js +52 -0
  9. data/app/assets/javascripts/trestle/_table.js +21 -0
  10. data/app/assets/javascripts/trestle/_tabs.js +13 -0
  11. data/app/assets/javascripts/trestle/_tooltips.js +3 -0
  12. data/app/assets/javascripts/trestle/admin.js +23 -0
  13. data/app/assets/javascripts/trestle/custom.js +4 -0
  14. data/app/assets/stylesheets/trestle/components/_table.scss +6 -0
  15. data/app/helpers/trestle/form_helper.rb +1 -1
  16. data/app/helpers/trestle/format_helper.rb +48 -0
  17. data/app/helpers/trestle/url_helper.rb +2 -8
  18. data/app/views/layouts/trestle/admin.html.erb +3 -3
  19. data/app/views/trestle/admin/index.html.erb +1 -1
  20. data/app/views/trestle/dashboard/index.html.erb +2 -2
  21. data/app/views/trestle/resource/_form.html.erb +1 -1
  22. data/app/views/trestle/resource/edit.html.erb +2 -2
  23. data/app/views/trestle/resource/index.html.erb +1 -1
  24. data/app/views/trestle/resource/new.html.erb +1 -1
  25. data/app/views/trestle/resource/show.html.erb +2 -2
  26. data/app/views/trestle/shared/_sidebar.html.erb +4 -2
  27. data/bower.json +1 -1
  28. data/config/locales/en.yml +16 -2
  29. data/lib/generators/trestle/install/install_generator.rb +3 -3
  30. data/lib/generators/trestle/install/templates/custom.js +7 -0
  31. data/lib/generators/trestle/install/templates/trestle.rb.erb +3 -2
  32. data/lib/trestle/adapters.rb +7 -64
  33. data/lib/trestle/adapters/active_record_adapter.rb +46 -20
  34. data/lib/trestle/adapters/adapter.rb +176 -0
  35. data/lib/trestle/adapters/sequel_adapter.rb +85 -0
  36. data/lib/trestle/admin.rb +1 -1
  37. data/lib/trestle/attribute.rb +14 -37
  38. data/lib/trestle/breadcrumb.rb +6 -0
  39. data/lib/trestle/configuration.rb +1 -1
  40. data/lib/trestle/form/automatic.rb +29 -21
  41. data/lib/trestle/form/builder.rb +4 -0
  42. data/lib/trestle/form/field.rb +2 -2
  43. data/lib/trestle/form/fields/check_box.rb +1 -1
  44. data/lib/trestle/form/fields/collection_select.rb +1 -1
  45. data/lib/trestle/form/fields/date_select.rb +1 -1
  46. data/lib/trestle/form/fields/datetime_select.rb +1 -1
  47. data/lib/trestle/form/fields/grouped_collection_select.rb +1 -1
  48. data/lib/trestle/form/fields/select.rb +2 -2
  49. data/lib/trestle/form/fields/tag_select.rb +1 -2
  50. data/lib/trestle/form/fields/time_select.rb +1 -1
  51. data/lib/trestle/form/fields/time_zone_select.rb +1 -1
  52. data/lib/trestle/resource.rb +11 -7
  53. data/lib/trestle/resource/builder.rb +2 -1
  54. data/lib/trestle/resource/controller.rb +61 -17
  55. data/lib/trestle/scope.rb +1 -1
  56. data/lib/trestle/table/automatic.rb +5 -11
  57. data/lib/trestle/table/builder.rb +1 -0
  58. data/lib/trestle/table/column.rb +24 -43
  59. data/lib/trestle/version.rb +1 -1
  60. data/trestle.gemspec +3 -4
  61. data/vendor/assets/bower_components/trestle/flatpickr/dist/flatpickr.css +51 -26
  62. data/vendor/assets/bower_components/trestle/flatpickr/dist/flatpickr.js +349 -299
  63. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ar.js +5 -5
  64. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/bg.js +5 -5
  65. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/bn.js +5 -5
  66. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/cat.js +7 -7
  67. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/cs.js +7 -7
  68. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/cy.js +7 -7
  69. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/da.js +6 -6
  70. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/de.js +10 -10
  71. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/eo.js +11 -11
  72. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/es.js +7 -7
  73. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/et.js +11 -11
  74. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/fa.js +6 -6
  75. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/fi.js +7 -7
  76. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/fr.js +11 -11
  77. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/gr.js +13 -13
  78. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/he.js +5 -5
  79. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/hi.js +5 -5
  80. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/hr.js +6 -6
  81. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/hu.js +10 -10
  82. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/id.js +7 -7
  83. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/index.js +97 -0
  84. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/it.js +10 -10
  85. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ja.js +5 -5
  86. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ko.js +6 -6
  87. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/lt.js +10 -10
  88. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/lv.js +6 -6
  89. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/mk.js +8 -8
  90. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ms.js +7 -7
  91. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/my.js +7 -7
  92. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/nl.js +11 -11
  93. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/no.js +11 -11
  94. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/pa.js +5 -5
  95. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/pl.js +6 -6
  96. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/pt.js +6 -8
  97. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ro.js +7 -9
  98. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/ru.js +6 -8
  99. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/si.js +5 -7
  100. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/sk.js +8 -8
  101. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/sl.js +8 -10
  102. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/sq.js +5 -7
  103. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/sr.js +9 -10
  104. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/sv.js +8 -10
  105. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/th.js +10 -11
  106. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/tr.js +6 -8
  107. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/uk.js +6 -7
  108. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/vn.js +6 -8
  109. data/vendor/assets/bower_components/trestle/flatpickr/dist/l10n/zh.js +9 -11
  110. metadata +24 -34
  111. data/app/assets/javascripts/trestle/_confirmation.js.coffee +0 -18
  112. data/app/assets/javascripts/trestle/_datepicker.js.coffee +0 -18
  113. data/app/assets/javascripts/trestle/_errors.js.coffee +0 -8
  114. data/app/assets/javascripts/trestle/_form.js.coffee +0 -4
  115. data/app/assets/javascripts/trestle/_gallery.js.coffee +0 -21
  116. data/app/assets/javascripts/trestle/_select.js.coffee +0 -7
  117. data/app/assets/javascripts/trestle/_sidebar.js.coffee +0 -45
  118. data/app/assets/javascripts/trestle/_table.js.coffee +0 -16
  119. data/app/assets/javascripts/trestle/_tabs.js.coffee +0 -9
  120. data/app/assets/javascripts/trestle/_tooltips.js.coffee +0 -2
  121. data/app/assets/javascripts/trestle/admin.js.coffee +0 -22
  122. data/app/assets/javascripts/trestle/custom.js.coffee +0 -4
  123. data/lib/generators/trestle/install/templates/custom.js.coffee +0 -7
@@ -24,7 +24,7 @@ module Trestle
24
24
  end
25
25
 
26
26
  def breadcrumb
27
- Breadcrumb.new(admin_name.titleize.pluralize, path)
27
+ Breadcrumb.new(admin_name.titleize, path)
28
28
  end
29
29
 
30
30
  def admin_name
@@ -1,53 +1,30 @@
1
1
  module Trestle
2
2
  class Attribute
3
- attr_reader :admin, :name, :type
3
+ attr_reader :name, :type, :options
4
4
 
5
- def initialize(admin, name, type)
6
- @admin, @name, @type = admin, name.to_sym, type
5
+ def initialize(name, type, options={})
6
+ @name, @type, @options = name.to_sym, type, options
7
7
  end
8
8
 
9
- def association?
10
- type == :association
11
- end
12
-
13
- def boolean?
14
- type == :boolean
15
- end
16
-
17
- def text?
18
- type == :text
19
- end
20
-
21
- def datetime?
22
- [:datetime, :time, :date].include?(type)
23
- end
24
-
25
- def primary_key?
26
- name.to_s == admin.model.primary_key
27
- end
28
-
29
- def inheritance_column?
30
- name.to_s == admin.model.inheritance_column
31
- end
32
-
33
- def counter_cache?
34
- name.to_s.end_with?("_count")
9
+ def array?
10
+ options[:array] == true
35
11
  end
36
12
 
37
13
  class Association < Attribute
38
- attr_reader :association_class
39
-
40
- def initialize(admin, name, association_class)
41
- super(admin, name, :association)
42
- @association_class = association_class
14
+ def initialize(name, options={})
15
+ super(name, :association, options)
43
16
  end
44
17
 
45
18
  def association_name
46
- name.to_s.sub(/_id$/, "")
19
+ options[:name] || name.to_s.sub(/_id$/, "")
20
+ end
21
+
22
+ def association_class
23
+ options[:class].respond_to?(:call) ? options[:class].call : options[:class]
47
24
  end
48
25
 
49
- def association_admin
50
- Trestle.admins[association_class.name.underscore.pluralize]
26
+ def polymorphic?
27
+ options[:polymorphic] == true
51
28
  end
52
29
  end
53
30
  end
@@ -11,10 +11,16 @@ module Trestle
11
11
  end
12
12
 
13
13
  class Trail
14
+ include Enumerable
15
+
14
16
  def initialize(breadcrumbs=[])
15
17
  @breadcrumbs = Array(breadcrumbs)
16
18
  end
17
19
 
20
+ def ==(other)
21
+ to_a == other.to_a
22
+ end
23
+
18
24
  def dup
19
25
  self.class.new(@breadcrumbs.dup)
20
26
  end
@@ -67,7 +67,7 @@ module Trestle
67
67
  option :display_methods, [:display_name, :full_name, :name, :title, :username, :login, :email, :to_s]
68
68
 
69
69
  # Default adapter class used by all admin resources
70
- option :default_adapter, Adapters::Adapter.compose(Adapters::ActiveRecordAdapter, Adapters::DraperAdapter)
70
+ option :default_adapter, Adapters.compose(Adapters::ActiveRecordAdapter, Adapters::DraperAdapter)
71
71
 
72
72
  # Register a custom form field class
73
73
  def form_field(name, klass)
@@ -2,28 +2,36 @@ module Trestle
2
2
  class Form
3
3
  class Automatic < Form
4
4
  def initialize(admin)
5
- @block = Proc.new do
6
- admin.default_attributes.each do |attribute|
7
- next if attribute.primary_key?
8
- next if attribute.inheritance_column?
9
- next if attribute.counter_cache?
10
-
11
- case attribute.type
12
- when :association
13
- options = attribute.association_class.all.map { |instance| [display(instance), instance.id] }
14
- prompt = "- Select #{admin.model.human_attribute_name(attribute.association_name)} -"
15
-
16
- select attribute.name, options, include_blank: prompt
17
- when :text
18
- text_area attribute.name
19
- when :date
20
- date_field attribute.name
21
- when :datetime
22
- datetime_field attribute.name
23
- when :boolean
24
- check_box attribute.name
5
+ @block = Proc.new do |instance|
6
+ admin.default_form_attributes.each do |attribute|
7
+ if attribute.array?
8
+ if [:string, :text].include?(attribute.type)
9
+ select attribute.name, nil, {}, { multiple: true, data: { tags: true, select_on_close: true }}
10
+ end
25
11
  else
26
- text_field attribute.name
12
+ case attribute.type
13
+ when :association
14
+ if attribute.polymorphic?
15
+ static_field attribute.name do
16
+ associated_instance = instance.public_send(attribute.association_name)
17
+ admin_link_to format_value(associated_instance), associated_instance
18
+ end
19
+ else
20
+ prompt = I18n.t("admin.form.select.prompt", default: "- Select %{attribute_name} -", attribute_name: admin.human_attribute_name(attribute.association_name))
21
+
22
+ select attribute.name, attribute.association_class.all, include_blank: prompt
23
+ end
24
+ when :text
25
+ text_area attribute.name
26
+ when :date
27
+ date_field attribute.name
28
+ when :datetime
29
+ datetime_field attribute.name
30
+ when :boolean
31
+ check_box attribute.name
32
+ else
33
+ text_field attribute.name
34
+ end
27
35
  end
28
36
  end
29
37
  end
@@ -9,6 +9,10 @@ module Trestle
9
9
  cattr_accessor :fields
10
10
  self.fields = {}
11
11
 
12
+ def errors(name)
13
+ object.errors[name].to_a
14
+ end
15
+
12
16
  def self.register(name, klass)
13
17
  rename_existing_helper_method(name)
14
18
  self.fields[name] = klass
@@ -13,8 +13,8 @@ module Trestle
13
13
  end
14
14
 
15
15
  def errors
16
- errors = builder.object.errors[name]
17
- errors += builder.object.errors[name.to_s.sub(/_id$/, '')] if name.to_s =~ /_id$/
16
+ errors = builder.errors(name)
17
+ errors += builder.errors(name.to_s.sub(/_id$/, '')) if name.to_s =~ /_id$/
18
18
  errors
19
19
  end
20
20
 
@@ -20,7 +20,7 @@ module Trestle
20
20
  content_tag(:label) do
21
21
  safe_join([
22
22
  builder.raw_check_box(name, options, checked_value, unchecked_value),
23
- options[:label] || admin.model.human_attribute_name(name)
23
+ options[:label] || admin.human_attribute_name(name)
24
24
  ], " ")
25
25
  end
26
26
  end
@@ -16,7 +16,7 @@ module Trestle
16
16
  end
17
17
 
18
18
  def default_html_options
19
- Trestle::Options.new(class: ["form-control"])
19
+ Trestle::Options.new(class: ["form-control"], data: { enable_select2: true })
20
20
  end
21
21
  end
22
22
  end
@@ -17,7 +17,7 @@ module Trestle
17
17
  end
18
18
 
19
19
  def default_html_options
20
- Trestle::Options.new(class: ["form-control"])
20
+ Trestle::Options.new(class: ["form-control"], data: { enable_select2: true })
21
21
  end
22
22
  end
23
23
  end
@@ -17,7 +17,7 @@ module Trestle
17
17
  end
18
18
 
19
19
  def default_html_options
20
- Trestle::Options.new(class: ["form-control"])
20
+ Trestle::Options.new(class: ["form-control"], data: { enable_select2: true })
21
21
  end
22
22
  end
23
23
  end
@@ -16,7 +16,7 @@ module Trestle
16
16
  end
17
17
 
18
18
  def default_html_options
19
- Trestle::Options.new(class: ["form-control"])
19
+ Trestle::Options.new(class: ["form-control"], data: { enable_select2: true })
20
20
  end
21
21
  end
22
22
  end
@@ -7,7 +7,7 @@ module Trestle
7
7
  def initialize(builder, template, name, choices=nil, options={}, html_options={}, &block)
8
8
  super(builder, template, name, options, &block)
9
9
 
10
- @choices = Choices.new(choices)
10
+ @choices = Choices.new(choices || builder.object.send(name))
11
11
  @html_options = default_html_options.merge(html_options)
12
12
  end
13
13
 
@@ -16,7 +16,7 @@ module Trestle
16
16
  end
17
17
 
18
18
  def default_html_options
19
- Trestle::Options.new(class: ["form-control"])
19
+ Trestle::Options.new(class: ["form-control"], data: { enable_select2: true })
20
20
  end
21
21
 
22
22
  # Allows an array of model instances (or a scope) to be
@@ -3,8 +3,7 @@ module Trestle
3
3
  module Fields
4
4
  class TagSelect < Select
5
5
  def initialize(builder, template, name, options={}, html_options={})
6
- choices = builder.object.send(name)
7
- super(builder, template, name, choices, options, html_options)
6
+ super(builder, template, name, nil, options, html_options)
8
7
  end
9
8
 
10
9
  def default_html_options
@@ -17,7 +17,7 @@ module Trestle
17
17
  end
18
18
 
19
19
  def default_html_options
20
- Trestle::Options.new(class: ["form-control"])
20
+ Trestle::Options.new(class: ["form-control"], data: { enable_select2: true })
21
21
  end
22
22
  end
23
23
  end
@@ -16,7 +16,7 @@ module Trestle
16
16
  end
17
17
 
18
18
  def default_html_options
19
- Trestle::Options.new(class: ["form-control"])
19
+ Trestle::Options.new(class: ["form-control"], data: { enable_select2: true })
20
20
  end
21
21
  end
22
22
  end
@@ -39,10 +39,12 @@ module Trestle
39
39
  adapter_method :decorate_collection
40
40
  adapter_method :unscope
41
41
  adapter_method :merge_scopes
42
+ adapter_method :count
42
43
  adapter_method :sort
43
44
  adapter_method :paginate
44
- adapter_method :count
45
- adapter_method :default_attributes
45
+ adapter_method :human_attribute_name
46
+ adapter_method :default_table_attributes
47
+ adapter_method :default_form_attributes
46
48
 
47
49
  attr_accessor :decorator
48
50
 
@@ -95,9 +97,7 @@ module Trestle
95
97
  return collection unless params[:sort]
96
98
 
97
99
  field = params[:sort].to_sym
98
-
99
- order = params[:order].downcase
100
- order = "asc" unless %w(asc desc).include?(order)
100
+ order = params[:order].to_s.downcase == "desc" ? :desc : :asc
101
101
 
102
102
  if column_sorts.has_key?(field)
103
103
  instance_exec(collection, order, &column_sorts[field])
@@ -152,8 +152,12 @@ module Trestle
152
152
  end
153
153
 
154
154
  def default_model_name
155
- model_name = model.model_name
156
- model_name.respond_to?(:human) ? model_name.human : model_name.to_s.titleize
155
+ if model.respond_to?(:model_name)
156
+ model_name = model.model_name
157
+ model_name.respond_to?(:human) ? model_name.human : model_name.to_s.titleize
158
+ else
159
+ model.name.titleize
160
+ end
157
161
  end
158
162
  end
159
163
  end
@@ -18,9 +18,10 @@ module Trestle
18
18
  admin.collection = block
19
19
  end
20
20
 
21
- def instance(&block)
21
+ def find_instance(&block)
22
22
  admin.find_instance = block
23
23
  end
24
+ alias instance find_instance
24
25
 
25
26
  def build_instance(&block)
26
27
  admin.build_instance = block
@@ -3,26 +3,52 @@ module Trestle
3
3
  class Controller < Admin::Controller
4
4
  def index
5
5
  self.collection = admin.prepare_collection(params)
6
+
7
+ respond_to do |format|
8
+ format.html
9
+ format.json { render json: collection }
10
+ end
6
11
  end
7
12
 
8
13
  def new
9
- self.instance = admin.build_instance
14
+ self.instance = admin.build_instance({}, params)
15
+
16
+ respond_to do |format|
17
+ format.html
18
+ format.json { render json: instance }
19
+ end
10
20
  end
11
21
 
12
22
  def create
13
- self.instance = admin.build_instance(admin.permitted_params(params))
23
+ self.instance = admin.build_instance(admin.permitted_params(params), params)
14
24
 
15
25
  if admin.save_instance(instance)
16
- flash[:message] = flash_message("success.create", default: "The %{model_name} was successfully created.")
17
- redirect_to action: :show, id: admin.to_param(instance)
26
+ respond_to do |format|
27
+ format.html do
28
+ flash[:message] = flash_message("success.create", default: "The %{model_name} was successfully created.")
29
+ redirect_to action: :show, id: admin.to_param(instance)
30
+ end
31
+ format.json { render json: instance, status: :created, location: { action: :show, id: admin.to_param(instance) } }
32
+ format.js
33
+ end
18
34
  else
19
- flash.now[:error] = flash_message("failure.create", default: "Please correct the errors below.")
20
- render "new"
35
+ respond_to do |format|
36
+ format.html do
37
+ flash.now[:error] = flash_message("failure.create", default: "Please correct the errors below.")
38
+ render "new"
39
+ end
40
+ format.json { render json: instance.errors, status: :unprocessable_entity }
41
+ end
21
42
  end
22
43
  end
23
44
 
24
45
  def show
25
46
  self.instance = admin.find_instance(params)
47
+
48
+ respond_to do |format|
49
+ format.html
50
+ format.json { render json: instance }
51
+ end
26
52
  end
27
53
 
28
54
  def edit
@@ -31,27 +57,45 @@ module Trestle
31
57
 
32
58
  def update
33
59
  self.instance = admin.find_instance(params)
34
- admin.update_instance(instance, admin.permitted_params(params))
60
+ admin.update_instance(instance, admin.permitted_params(params), params)
35
61
 
36
62
  if admin.save_instance(instance)
37
- flash[:message] = flash_message("success.update", default: "The %{model_name} was successfully updated.")
38
- redirect_to action: :show, id: admin.to_param(instance)
63
+ respond_to do |format|
64
+ format.html do
65
+ flash[:message] = flash_message("success.update", default: "The %{model_name} was successfully updated.")
66
+ redirect_to action: :show, id: admin.to_param(instance)
67
+ end
68
+ format.json { render json: instance, status: :ok }
69
+ format.js
70
+ end
39
71
  else
40
- flash.now[:error] = flash_message("failure.update", default: "Please correct the errors below.")
41
- render "show"
72
+ respond_to do |format|
73
+ format.html do
74
+ flash.now[:error] = flash_message("failure.update", default: "Please correct the errors below.")
75
+ render "show"
76
+ end
77
+ format.json { render json: instance.errors, status: :unprocessable_entity }
78
+ end
42
79
  end
43
80
  end
44
81
 
45
82
  def destroy
46
83
  self.instance = admin.find_instance(params)
84
+ success = admin.delete_instance(instance)
47
85
 
48
- if admin.delete_instance(instance)
49
- flash[:message] = flash_message("success.destroy", default: "The %{model_name} was successfully deleted.")
50
- else
51
- flash[:error] = flash_message("failure.destroy", default: "Could not delete %{model_name}.")
52
- end
86
+ respond_to do |format|
87
+ format.html do
88
+ if success
89
+ flash[:message] = flash_message("success.destroy", default: "The %{model_name} was successfully deleted.")
90
+ else
91
+ flash[:message] = flash_message("failure.destroy", default: "Could not delete %{model_name}.")
92
+ end
53
93
 
54
- redirect_to action: :index
94
+ redirect_to action: :index
95
+ end
96
+ format.json { head :no_content }
97
+ format.js
98
+ end
55
99
  end
56
100
 
57
101
  protected