gov_user_plugin.rb
3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class GovUserPlugin < Noosfero::Plugin
include ActionView::Helpers::TagHelper
include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::FormOptionsHelper
include ActionView::Helpers::JavaScriptHelper
include ActionView::Helpers::AssetTagHelper
include FormsHelper
include ActionView::Helpers
include ActionDispatch::Routing
include Rails.application.routes.url_helpers
def self.plugin_name
# FIXME
"GovUserPlugin"
end
def self.plugin_description
# FIXME
_("A plugin that does this and that.")
end
# Hotspot to insert html without an especific hotspot on view.
def body_beginning
return if context.session[:user].nil? or context.session[:hide_incomplete_percentage] == true
person = context.environment.people.where(:user_id=>context.session[:user]).first
if context.profile && context.profile.person? and !person.nil?
@person = person
@percentege = calc_percentage_registration(person)
if @percentege >= 0 and @percentege < 100
expanded_template('incomplete_registration.html.erb')
end
end
end
def profile_editor_transaction_extras
single_hash_transactions = { :user => 'user',
:instituton => 'instituton'
}
single_hash_transactions.each do |model, transaction|
call_model_transaction(model, transaction)
end
end
def profile_editor_extras
profile = context.profile
if profile.person?
expanded_template('person_editor_extras.html.erb')
end
end
def calc_percentage_registration(person)
required_list = profile_required_list
empty_fields = profile_required_empty_list person
count = required_list[:person_fields].count +
required_list[:user_fields].count
percentege = 100 - ((empty_fields.count * 100) / count)
person.percentage_incomplete = percentege
person.save(validate: false)
percentege
end
def js_files
%w(
vendor/modulejs-1.5.0.min.js
vendor/jquery.js
lib/noosfero-root.js
views/complete-registration.js
initializer.js
app.js
)
end
protected
def profile_required_list
fields = {}
fields[:person_fields] = %w(cell_phone
contact_phone
comercial_phone
country
city
state
organization_website
image
identifier
name)
fields[:user_fields] = %w(secondary_email email)
fields
end
def profile_required_empty_list(person)
empty_fields = []
required_list = profile_required_list
required_list[:person_fields].each do |field|
empty_fields << field.sub('_',' ') if person.send(field).blank?
end
required_list[:user_fields].each do |field|
empty_fields << field.sub('_',' ') if person.user.send(field).blank?
end
empty_fields
end
def user_transaction
user_editor_institution_actions
User.transaction do
context.profile.user.update_attributes!(context.params[:user])
end
end
private
def call_model_transaction(model,name)
send(name + '_transaction') if context.params.key?(model.to_sym)
end
end