Module: Admin::HasCredentialColumnHelper

Included in:
ClientRepresentativesHelper, EmployeesHelper
Defined in:
app/helpers/admin/has_credential_column_helper.rb

Constant Summary collapse

PASSWORD_ON_FOCUS_JS =
"$(%s).observe('focus',function(event){"+
  "el = event.element();"+
  "old_password_values[%d] = el.value;"+
  "el.value = '';"+
"});"
PASSWORD_ON_BLUR_JS =
"$(%s).observe('blur', function(event){"+
  "el = event.element();"+
  "record_id = %d;"+
  "if (el.value == ''){el.value = old_password_values[record_id];} else {password_has_changed[record_id] = true;};"+
"});"

Instance Method Summary collapse

Instance Method Details

#form_remote_tag(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/admin/has_credential_column_helper.rb', line 14

def form_remote_tag(*args)
  if @record and !@record.new_record? and @record.password_hash
    args[0][:before] = "if (password_has_changed[%d] == false) { $('%s').value = ''; }" % [ 
      @record.id, 
      password_input_id 
    ]

    concat(
      ('<script>'+
        'if (typeof(password_has_changed) == "undefined"){password_has_changed = [];old_password_values = [];};'+
        'password_has_changed[%d] = false;'+
      '</script>')  % @record.id
    )
  end

  super(*args)
end

#login_enabled_form_column(record, options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/admin/has_credential_column_helper.rb', line 44

def (record, options)
  select_tag(
    options[:name], 
    options_for_select( 
      [ ["Yes", 'true'], ["No", 'false'] ], 
      (record..nil?) ? 'false' : record..to_s
    ),
    :id => 'record_login_enabled'
  )
end

#password_form_column(record, options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/admin/has_credential_column_helper.rb', line 32

def password_form_column(record, options)

  password_field_tag(
    options[:name], 
    ( record.password_hash ) ? 'secretsecret' : '', 
    :id => password_input_id,
    :size => 20
  )+javascript_tag( 
    [PASSWORD_ON_FOCUS_JS, PASSWORD_ON_BLUR_JS].collect{|js| js % [password_input_id.to_json, @record.id]}
  )
end

#password_input_idObject



55
56
57
58
# File 'app/helpers/admin/has_credential_column_helper.rb', line 55

def password_input_id()
  input_id = 'record_password'
  input_id += ('_%d' % @record.id) unless @record.new_record?
end