stoa_plugin.rb
2.12 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
require_dependency 'person'
class StoaPlugin < Noosfero::Plugin
Person.human_names[:usp_id] = _('USP number')
def self.plugin_name
"Stoa"
end
def self.plugin_description
_("Add Stoa features")
end
def stylesheet?
true
end
def signup_extra_contents
lambda {
required(labelled_form_field(_('USP number'), text_field_tag('profile_data[usp_id]', '', :id => 'usp_id_field'))) +
labelled_form_field(_('Select a confirmation data'), select_tag('confirmation_field',
options_for_select([['CPF','cpf'], [_('Mother\'s name'), 'mother'], [_('Birth date (yyyy-mm-dd)'), 'birth']])
)) +
required(labelled_form_field(_('Confirmation value'), text_field_tag('confirmation_value', '', :placeholder=>_('Confirmation value')))) +
javascript_tag(<<-EOF
jQuery("#usp_id_field").change(function(){
var me=this;
jQuery(this).addClass('checking').removeClass('validated');
jQuery.getJSON('#{url_for(:controller => 'stoa_plugin', :action => 'check_usp_id')}?usp_id='+this.value,
function(data){
if(data.exists) jQuery(me).removeClass('checking').addClass('validated');
else jQuery(me).removeClass('checking').addClass('invalid');
if(data.error) displayValidationUspIdError(data.error);
}
);
});
function displayValidationUspIdError(error){
jQuery.colorbox({html: '<h2>'+error.message+'</h2>'+error.backtrace.join("<br />"),
height: "80%",
width: "70%" });
}
EOF
)
}
end
def account_controller_filters
block = lambda do
if request.post?
if !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[:confirmation_value])
@person = Person.new
@person.errors.add(:usp_id, _(' validation failed'))
render :action => :signup
end
end
end
[{ :type => 'before_filter',
:method_name => 'validate_usp_id',
:options => {:only => 'signup'},
:block => block }]
end
end