effective_resources 0.8.12 → 0.8.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d9f3c476a1b25d899e3ef80460fd11bf5738949
4
- data.tar.gz: bff4db8bfebd28a8b194e390837a2509aff6f9fd
3
+ metadata.gz: d4e0b794db680cc5d1128cec78d437057338870c
4
+ data.tar.gz: b5ce5e70f5abb3c49dd771ab6745fc859610e82a
5
5
  SHA512:
6
- metadata.gz: 036821b4210acece00173e2c1afd0aa406a11359b50b91f1d6eae3b1be4da035cdfacd104b5e8a8a2608a6aed8df1a3257b0991a16f01fd086fcf6df3f6921a6
7
- data.tar.gz: 5b208d0903fc51e37e3236c40a22a06d4938e4679d3131dede7b7df358754072e54fc3b9abb429677ee2ff56c8de36688b94e99477dd8d23167310414cbca8b1
6
+ metadata.gz: 0e25d29b786c84a6337c1a655d90719dfecdeb4a824db2d37d2815cb9a6c485df6a5c7fe7e53da9cfc509c0f3d0d5e9e959bff939ee38f5f197dfe7c468f33bd
7
+ data.tar.gz: 41a58b98945b99b7725f45b7c7b7f4ff5de90f2c3cb1e659f1f031cf2e6d0ea05a4648fdf418360da6105a5b29fb43afff8ae40286ae95f3f8ffcb103244b418
@@ -199,11 +199,10 @@ module Effective
199
199
  EffectiveResources.authorize!(self, action, resource) unless action == :save
200
200
  EffectiveResources.authorize!(self, :create, resource) if action == :save
201
201
 
202
- resource.assign_attributes(send(resource_params_method_name))
203
202
  resource.created_by ||= current_user if resource.respond_to?(:created_by=)
204
203
 
205
204
  respond_to do |format|
206
- if save_resource(resource, action)
205
+ if save_resource(resource, action, send(resource_params_method_name))
207
206
  format.html do
208
207
  flash[:success] ||= resource_flash(:success, resource, action)
209
208
  redirect_to(resource_redirect_path)
@@ -256,10 +255,8 @@ module Effective
256
255
  EffectiveResources.authorize!(self, action, resource) unless action == :save
257
256
  EffectiveResources.authorize!(self, :update, resource) if action == :save
258
257
 
259
- resource.assign_attributes(send(resource_params_method_name))
260
-
261
258
  respond_to do |format|
262
- if save_resource(resource, action)
259
+ if save_resource(resource, action, send(resource_params_method_name))
263
260
  format.html do
264
261
  flash[:success] ||= resource_flash(:success, resource, action)
265
262
  redirect_to(resource_redirect_path)
@@ -305,7 +302,7 @@ module Effective
305
302
  redirect_to(resource_redirect_path)
306
303
  else
307
304
  flash.now[:success] ||= resource_flash(:success, resource, action)
308
- # delete.js.erb
305
+ # destroy.js.erb
309
306
  end
310
307
  end
311
308
  else
@@ -327,12 +324,8 @@ module Effective
327
324
  def member_post_action(action)
328
325
  raise 'expected post, patch or put http action' unless (request.post? || request.patch? || request.put?)
329
326
 
330
- # TODO: This is a recent change. Used to not assign attributes. Is this breaking?
331
- valid_params = (send(resource_params_method_name) rescue {})
332
- resource.assign_attributes(valid_params)
333
-
334
327
  respond_to do |format|
335
- if save_resource(resource, action)
328
+ if save_resource(resource, action, (send(resource_params_method_name) rescue {}))
336
329
  format.html do
337
330
  flash[:success] ||= resource_flash(:success, resource, action)
338
331
  redirect_to(resource_redirect_path)
@@ -345,7 +338,7 @@ module Effective
345
338
  else
346
339
  flash.now[:success] ||= resource_flash(:success, resource, action)
347
340
  reload_resource
348
- # action.js.erb
341
+ render_member_action(action)
349
342
  end
350
343
  end
351
344
  else
@@ -369,11 +362,17 @@ module Effective
369
362
  end
370
363
  end
371
364
 
372
- format.js {} # action.js.erb
365
+ format.js { render_member_action(action) }
373
366
  end
374
367
  end
375
368
  end
376
369
 
370
+ # Which member javascript view to render: #{action}.js or effective_resources member_action.js
371
+ def render_member_action(action)
372
+ view = lookup_context.template_exists?(action, _prefixes) ? action : :member_action
373
+ render(view, locals: { action: action })
374
+ end
375
+
377
376
  # No attributes are assigned or saved. We purely call action! on the resource
378
377
  def collection_post_action(action)
379
378
  action = action.to_s.gsub('bulk_', '').to_sym
@@ -399,13 +398,15 @@ module Effective
399
398
  protected
400
399
 
401
400
  # This calls the appropriate member action, probably save!, on the resource.
402
- def save_resource(resource, action = :save, &block)
401
+ def save_resource(resource, action = :save, to_assign = {}, &block)
403
402
  raise "expected @#{resource_name} to respond to #{action}!" unless resource.respond_to?("#{action}!")
404
403
 
405
404
  resource.current_user ||= current_user if resource.respond_to?(:current_user=)
406
405
 
407
406
  ActiveRecord::Base.transaction do
408
407
  begin
408
+ resource.assign_attributes(to_assign) if to_assign.present?
409
+
409
410
  if resource.public_send("#{action}!") == false
410
411
  raise("failed to #{action} #{resource}")
411
412
  end
@@ -40,9 +40,14 @@ module EffectiveResourcesHelper
40
40
 
41
41
  # When called from /admin/things/new.html.haml this will render 'admin/things/form', or 'things/form', or 'thing/form'
42
42
  def render_resource_form(resource, atts = {})
43
+ raise 'expected attributes to be a Hash. Try passing action: action if rendering custom action' unless atts.kind_of?(Hash)
44
+
45
+ action = atts.delete(:action)
43
46
  atts = {:namespace => (resource.namespace.to_sym if resource.namespace.present?), resource.name.to_sym => instance_variable_get('@' + resource.name)}.compact.merge(atts)
44
47
 
45
- if lookup_context.template_exists?('form', controller._prefixes, :partial)
48
+ if lookup_context.template_exists?("form_#{action}", controller._prefixes, :partial)
49
+ render "form_#{action}", atts
50
+ elsif lookup_context.template_exists?('form', controller._prefixes, :partial)
46
51
  render 'form', atts
47
52
  elsif lookup_context.template_exists?('form', resource.plural_name, :partial)
48
53
  render "#{resource.plural_name}/form", atts
@@ -15,7 +15,7 @@ module ActsAsTokened
15
15
  end
16
16
 
17
17
  included do
18
- has_secure_token
18
+ has_secure_token # Will always be 24-digits long
19
19
 
20
20
  extend FinderMethods
21
21
  end
@@ -28,7 +28,7 @@ module Effective
28
28
 
29
29
  # Here we look at all available (class level) member actions, see which ones apply to the current resource
30
30
  # This feeds into the helper simple_form_submit(f)
31
- # Returns a Hash of {'Save': {data-disable-with: 'Saving...'}, 'Approve': {data-disable-with: 'Approve'}}
31
+ # Returns a Hash of {'Save': {class: 'btn btn-primary'}, 'Approve': {class: 'btn btn-secondary'}}
32
32
  def submits_for(obj, controller:)
33
33
  submits.select do |commit, args|
34
34
  args[:class] = args[:class].to_s
@@ -1,5 +1,5 @@
1
1
  <% resource = (@_effective_resource || Effective::Resource.new(controller_path)) %>
2
2
  <% @resource = instance_variable_get('@' + resource.name) if resource.name %>
3
3
 
4
- EffectiveForm.remote_form_payload = $("<div><%= j render_resource_form(resource) %></div>");
4
+ EffectiveForm.remote_form_payload = "<%= j render_resource_form(resource) %>";
5
5
  EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
@@ -1,5 +1,5 @@
1
1
  <% resource = (@_effective_resource || Effective::Resource.new(controller_path)) %>
2
2
  <% @resource = instance_variable_get('@' + resource.name) if resource.name %>
3
3
 
4
- EffectiveForm.remote_form_payload = $("<div><%= j render_resource_form(resource) %></div>");
4
+ EffectiveForm.remote_form_payload = "<%= j render_resource_form(resource) %>";
5
5
  EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
@@ -0,0 +1,5 @@
1
+ <% resource = (@_effective_resource || Effective::Resource.new(controller_path)) %>
2
+ <% @resource = instance_variable_get('@' + resource.name) if resource.name %>
3
+
4
+ EffectiveForm.remote_form_payload = "<%= j render_resource_form(resource, action: action) %>";
5
+ EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
@@ -1,5 +1,5 @@
1
1
  <% resource = (@_effective_resource || Effective::Resource.new(controller_path)) %>
2
2
  <% @resource = instance_variable_get('@' + resource.name) if resource.name %>
3
3
 
4
- EffectiveForm.remote_form_payload = $("<div><%= j render_resource_form(resource) %></div>");
4
+ EffectiveForm.remote_form_payload = "<%= j render_resource_form(resource) %>";
5
5
  EffectiveForm.remote_form_flash = <%= raw flash.to_json %>;
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.8.12'.freeze
2
+ VERSION = '0.8.13'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.12
4
+ version: 0.8.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-16 00:00:00.000000000 Z
11
+ date: 2018-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -59,6 +59,7 @@ files:
59
59
  - app/views/application/destroy.js.erb
60
60
  - app/views/application/edit.html.haml
61
61
  - app/views/application/index.html.haml
62
+ - app/views/application/member_action.js.erb
62
63
  - app/views/application/new.html.haml
63
64
  - app/views/application/show.html.haml
64
65
  - app/views/application/update.js.erb