Module: PermissionsHelper

Included in:
ProductsHelper, RolesHelper
Defined in:
lib/generators/permissify/views/template/permissions_helper.rb

Instance Method Summary collapse

Instance Method Details

#additional_column_id(i) ⇒ Object



66
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 66

def additional_column_id(i); "ac#{i}_#{@permissions_object.id}"; end

#category_allows_one_or_noneObject



30
31
32
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 30

def category_allows_one_or_none
  @permission[:category_allows] == :one_or_none
end

#category_nameObject



22
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 22

def category_name; 'category_' + @category.downcase.gsub(' ', '_'); end

#category_permissionsObject



16
17
18
19
20
21
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 16

def category_permissions
  return @category_permissions if @category == @last_category
  @last_category = @category
  @category_permissions = @permissions.select{|pa| pa[:category] == @category}
  @category_permissions.sort!{|pa1,pa2| pa1[:position] <=> pa2[:position]}
end

#clear_all_in_categoryObject



33
34
35
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 33

def clear_all_in_category
  "clear_all_in_category(this, '#{@permissions_prefix}');"
end

#click_associated_checkboxObject



36
37
38
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 36

def click_associated_checkbox
  "toggle_color_coded_permission('#{@permission[:key]}', document.getElementById('#{@permissions_prefix}permissions_#{@permission[:key]}_0'));"
end

#colorized_permissionObject



15
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 15

def colorized_permission; @permissions_object.allows?(@permission[:key]) ? 'green' : 'red' ; end

#data_tagObject



3
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 3

def data_tag ; tag_for 'data'; end

#delete_tagObject



5
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 5

def delete_tag ; tag_for 'delete'; end

#edit_tagObject



14
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 14

def edit_tag ; tag_for 'edit' ; end

#edit_urlObject



64
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 64

def edit_url; send("edit_#{@permissions_name}_url", :id => @permissions_object); end

#expand_categoryObject



39
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 39

def expand_category ; "$('##{category_name}').show();" ; end

#focus_and_select_first_additional_inputObject



40
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 40

def focus_and_select_first_additional_input ; "$('##{@permissions_prefix}permissions_#{@permission[:key]}_1').focus().select()" ; end

#form_pathObject



65
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 65

def form_path; send("#{@permissions_name}_path", :id => @permissions_object.id); end

#models_that_have_permissionObject



83
84
85
86
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 83

def models_that_have_permission
  mthp = @permissions_group_list.select{|p| p.permissions[@permission[:key]] }.collect(&:name).sort.reverse.join(', ')
  mthp.blank? ? 'none' : mthp
end

#permission_click_actionsObject



24
25
26
27
28
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 24

def permission_click_actions
  actions = category_allows_one_or_none ? clear_all_in_category : click_associated_checkbox
  actions += expand_category + focus_and_select_first_additional_input if @permission[:number_of_values] > 1
  actions
end

#permission_input(specification) ⇒ Object



50
51
52
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 50

def permission_input(specification)
  permission_text_input(specification) if specification[1] == 'text'
end

#permission_text_input(specification) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 54

def permission_text_input(specification)
  size  = specification[2].to_i
  size  = 4 if size == 0
  value = (@permissions_object.permissions[@permission[:key]][specification[0]] rescue nil)
  value = @permission[:default_values][specification[0].to_i] if value.blank?
  name  = "#{@permissions_name}[permissions][#{@permission[:key]}][#{specification[0]}]"
  id    = "#{@permissions_prefix}permissions_#{@permission[:key]}_#{specification[0]}"
  "<input type='text' id='#{id}' name='#{name}' value='#{value}' size='#{size}' maxlength='#{size}'/>"
end

#permission_tokenObject



46
47
48
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 46

def permission_token
  @token.starts_with?('*') ? permission_input(@token.delete('*').split(':')) : @token
end

#permission_valuesObject



42
43
44
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 42

def permission_values
  @permission[:administration_expression].split('**').collect{|token| @token = token; permission_token }.join('')
end

#permissions_groupObject



11
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 11

def permissions_group; @permissions_group_list ||= @permissions_class.find(:all, :order => "#{@permissions_class.table_name}.#{@sort_field} ASC"); end

#permissions_group_nameObject



12
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 12

def permissions_group_name ; truncate(@permissions_object.name, :length => 40) ; end

#permissions_sectionsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 68

def permissions_sections
  { 'role'     => [ 'Tabs',
                    'Admin',
                    'Dealer Admin',
                    'Corporation Admin',
                    'Brand Admin',
                    'Merchant Admin',
                    'Social Media',
                  ],
    'product' =>  [ 'Social Media',
                    'Solutions',
                  ]
  }[@permissions_name]
end

#product_permissionsObject



6
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 6

def product_permissions; @permissions ||= Ability.all_for(@applicability); end

#section_categoriesObject



7
8
9
10
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 7

def section_categories
  section_permissions = product_permissions.select{|permission| permission[:section] == @section }
  section_permissions.collect{|sp| sp[:category]}.uniq.sort
end

#set_tag(model) ⇒ Object



2
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 2

def set_tag(model); @tag = "_#{model.class.name.titleize.downcase.gsub(' ','_')}_#{model.id}"; end

#status_tagObject



13
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 13

def status_tag ; tag_for 'status' ; end

#tag_for(t) ⇒ Object



4
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 4

def tag_for(t); "#{t}#{@tag}"; end