Module: PermissionsHelper
- Included in:
- ProductsHelper, RolesHelper
- Defined in:
- lib/generators/permissify/views/template/permissions_helper.rb
Instance Method Summary collapse
- #additional_column_id(i) ⇒ Object
- #category_allows_one_or_none ⇒ Object
- #category_name ⇒ Object
- #category_permissions ⇒ Object
- #clear_all_in_category ⇒ Object
- #click_associated_checkbox ⇒ Object
- #colorized_permission ⇒ Object
- #data_tag ⇒ Object
- #delete_tag ⇒ Object
- #edit_tag ⇒ Object
- #edit_url ⇒ Object
- #expand_category ⇒ Object
- #focus_and_select_first_additional_input ⇒ Object
- #form_path ⇒ Object
- #models_that_have_permission ⇒ Object
- #permission_click_actions ⇒ Object
- #permission_input(specification) ⇒ Object
- #permission_text_input(specification) ⇒ Object
- #permission_token ⇒ Object
- #permission_values ⇒ Object
- #permissions_group ⇒ Object
- #permissions_group_name ⇒ Object
- #permissions_sections ⇒ Object
- #product_permissions ⇒ Object
- #section_categories ⇒ Object
- #set_tag(model) ⇒ Object
- #status_tag ⇒ Object
- #tag_for(t) ⇒ Object
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_none ⇒ Object
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_name ⇒ Object
22 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 22 def category_name; 'category_' + @category.downcase.gsub(' ', '_'); end |
#category_permissions ⇒ Object
16 17 18 19 20 21 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 16 def 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_category ⇒ Object
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_checkbox ⇒ Object
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_permission ⇒ Object
15 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 15 def ; @permissions_object.allows?(@permission[:key]) ? 'green' : 'red' ; end |
#data_tag ⇒ Object
3 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 3 def data_tag ; tag_for 'data'; end |
#delete_tag ⇒ Object
5 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 5 def delete_tag ; tag_for 'delete'; end |
#edit_tag ⇒ Object
14 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 14 def edit_tag ; tag_for 'edit' ; end |
#edit_url ⇒ Object
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_category ⇒ Object
39 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 39 def ; "$('##{category_name}').show();" ; end |
#focus_and_select_first_additional_input ⇒ Object
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_path ⇒ Object
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_permission ⇒ Object
83 84 85 86 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 83 def mthp = @permissions_group_list.select{|p| p.[@permission[:key]] }.collect(&:name).sort.reverse.join(', ') mthp.blank? ? 'none' : mthp end |
#permission_click_actions ⇒ Object
24 25 26 27 28 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 24 def actions = category_allows_one_or_none ? clear_all_in_category : click_associated_checkbox actions += + 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 (specification) (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 (specification) size = specification[2].to_i size = 4 if size == 0 value = (@permissions_object.[@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_token ⇒ Object
46 47 48 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 46 def @token.starts_with?('*') ? (@token.delete('*').split(':')) : @token end |
#permission_values ⇒ Object
42 43 44 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 42 def @permission[:administration_expression].split('**').collect{|token| @token = token; }.join('') end |
#permissions_group ⇒ Object
11 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 11 def ; @permissions_group_list ||= @permissions_class.find(:all, :order => "#{@permissions_class.table_name}.#{@sort_field} ASC"); end |
#permissions_group_name ⇒ Object
12 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 12 def ; truncate(@permissions_object.name, :length => 40) ; end |
#permissions_sections ⇒ Object
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 { 'role' => [ 'Tabs', 'Admin', 'Dealer Admin', 'Corporation Admin', 'Brand Admin', 'Merchant Admin', 'Social Media', ], 'product' => [ 'Social Media', 'Solutions', ] }[@permissions_name] end |
#product_permissions ⇒ Object
6 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 6 def ; @permissions ||= Ability.all_for(@applicability); end |
#section_categories ⇒ Object
7 8 9 10 |
# File 'lib/generators/permissify/views/template/permissions_helper.rb', line 7 def section_categories = .select{|| [:section] == @section } .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_tag ⇒ Object
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 |