approval2 0.1.7 → 0.1.9

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: 63eb8f62ec9ef31d1b8e8ae748720d6f3625e4e5
4
- data.tar.gz: d94a300234cc6afc0b0eb2e2d7fa996a5ec842b9
3
+ metadata.gz: 5c160ff94c007a93967fa9e3437e0662ee679913
4
+ data.tar.gz: d64aeaab593e7498f67002a6eb862115d11d3f4e
5
5
  SHA512:
6
- metadata.gz: 26c6e7d9d25aa4499db102f5a4009c636172f15cb0da272d460349cc3cd8ca81bddf1dcb2de143aa221c33f583dcf912f6a673517272004e288e4eecca61a38c
7
- data.tar.gz: 8d41f124ba55c670e496532e358037e5aef16ee974248d2bf1b2433b6d7c7040ca0735554e78b2879461817360d259e2fe40f4257a914405600ab5d4cc0d86b7
6
+ metadata.gz: 4cf79b315085c0793603a689d19e0a2a45220680827c9472f462d82f61cae03f0e71dc6539045f544f9423dcbe1e8e738f22fd624926cf2f1a30516c973c62ea
7
+ data.tar.gz: c7a83ba157b57dc8323e390f3d90077df4dc738254c37cc84c54d7a72e80b8d7030a6229cbe4186e91a9b91292b7796dee47872f359f54833ad0269ff5f188d8
@@ -6,10 +6,29 @@ module Approval2
6
6
  before_filter :before_edit, only: :edit
7
7
  before_filter :before_approve, only: :approve
8
8
  before_filter :before_index, only: :index
9
+
10
+ def reject
11
+ modelName = self.class.name.sub("Controller", "").underscore.split('/').last.singularize
12
+ modelKlass = modelName.classify.constantize
13
+ x = modelKlass.unscoped.find(params[:id])
14
+ x.destroy if x.can_destroy?
15
+ flash[:alert] = "The unapproved record has been deleted"
16
+ redirect_with_params
17
+ end
18
+
9
19
  end
10
20
 
11
21
 
12
22
  private
23
+
24
+ # apps can provide redirect params via a known session variable
25
+ def redirect_with_params
26
+ if session[:approval2_redirect_params].present?
27
+ redirect_to unapproved_records_path(session[:approval2_redirect_params])
28
+ else
29
+ redirect_to unapproved_records_path
30
+ end
31
+ end
13
32
 
14
33
  def before_index
15
34
  if (params[:approval_status].present? and params[:approval_status] == 'U')
@@ -50,6 +69,9 @@ module Approval2
50
69
  end
51
70
  end
52
71
  end
72
+
73
+
74
+
53
75
  end
54
76
  end
55
77
 
@@ -62,12 +62,19 @@ module Approval2
62
62
  return approved_record
63
63
  end
64
64
  end
65
+
66
+ def can_destroy?
67
+ # only unaproved records are allowed to be destroyed
68
+ self.approval_status == 'U'
69
+ end
70
+
71
+ alias_method :enable_reject_button?, :can_destroy?
65
72
 
66
73
  def enable_approve_button?
67
74
  self.approval_status == 'U' ? true : false
68
75
  end
69
76
 
70
- def on_create_create_unapproved_record_entry
77
+ def on_create_create_unapproved_record_entry
71
78
  if approval_status == 'U'
72
79
  UnapprovedRecord.create!(:approvable => self)
73
80
  end
@@ -1,3 +1,3 @@
1
1
  module Approval2
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -1,15 +1,26 @@
1
+ - reject_url = polymorphic_path(@record, :action => 'reject') rescue nil
1
2
  - can = can? :approve, @record
2
3
  - approve_flag = @record.enable_approve_button?
4
+ - reject_flag = @record.enable_reject_button?
3
5
  %a.btn{"data-toggle" => "modal", :href => "#{!(can && approve_flag) ? '#' : '#myModalApprove'}", :role => "button", :class => "btn btn-primary #{(can && approve_flag) ? '' : 'disabled'}"} Approve
6
+ - if reject_url.present?
7
+ %a.btn{"data-toggle" => "modal", :href => "#{!(can && approve_flag) ? '#' : '#myModalReject'}", :role => "button", :class => "btn btn-primary #{(can && reject_flag) ? '' : 'disabled'}"} Reject
4
8
  .modal.hide.fade{"id" => "myModalApprove", "aria-hidden" => "true", "aria-labelledby" => " myModalLabel", :role => "dialog", :tabindex => "-1"}
5
9
  .modal-header
6
10
  %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
7
- %h3#myModalLabel Acknowledge
11
+ %h3#myModalLabel Acknowledge Approval
8
12
  #error_message{:style => 'color:red'}
9
13
  .modal-body
10
- = simple_form_for @record, :url => {:action => 'approve'}, :method => :put, :html=>{:id=>"transition"} do |ef|
14
+ = simple_form_for @record, :url => {:action => 'approve'}, :method => :put do |ef|
11
15
  = ef.input :updated_by, :as => :hidden, :input_html => {:value => current_user.id}
12
- = submit_tag "Confirm", :class=>"btn btn-primary transition_button", :id => "transition_button"
16
+ = submit_tag "Confirm", :class=>"btn btn-primary transition_button"
17
+ .modal.hide.fade{"id" => "myModalReject", "aria-hidden" => "true", "aria-labelledby" => " myModalLabel", :role => "dialog", :tabindex => "-1"}
18
+ .modal-header
19
+ %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
20
+ %h3#myModalLabel Acknowledge Rejection
21
+ #error_message{:style => 'color:red'}
22
+ .modal-body
23
+ = link_to 'Confirm', reject_url, method: :put, :class=>"btn btn-primary transition_button"
13
24
  %p{:style => 'color:green;'}
14
25
  = created_or_edited_by(@record)
15
26
  %br
@@ -11,5 +11,10 @@ class UnapprovedRecordsController < ApplicationController
11
11
  end
12
12
 
13
13
  @records = result.paginate(:per_page => 10, :page => params[:page]) rescue []
14
+
15
+ # the approval2 gem requires a known session variable to include any redirect params to be sent to the unapproved_records_path
16
+ # for the reject action
17
+ session[:approval2_redirect_params] = {param1: 'some_param', param2: 'some_other_param'}
18
+
14
19
  end
15
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: approval2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - akil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-12 00:00:00.000000000 Z
11
+ date: 2018-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler