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 +4 -4
- data/lib/approval2/controller_additions.rb +22 -0
- data/lib/approval2/model_additions.rb +8 -1
- data/lib/approval2/version.rb +1 -1
- data/lib/generators/approval2/install/templates/_approve.html.haml +14 -3
- data/lib/generators/approval2/install/templates/unapproved_records_controller.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c160ff94c007a93967fa9e3437e0662ee679913
|
4
|
+
data.tar.gz: d64aeaab593e7498f67002a6eb862115d11d3f4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
77
|
+
def on_create_create_unapproved_record_entry
|
71
78
|
if approval_status == 'U'
|
72
79
|
UnapprovedRecord.create!(:approvable => self)
|
73
80
|
end
|
data/lib/approval2/version.rb
CHANGED
@@ -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
|
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"
|
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.
|
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:
|
11
|
+
date: 2018-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|