Commit f142891e9d09d1001a2de0356f30466654273d3a

Authored by MoisesMachado
1 parent f285ecc3

ActionItem5: interface to manage roles functional


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@483 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/role_controller.rb
... ... @@ -8,7 +8,7 @@ class RoleController < ApplicationController
8 8 end
9 9  
10 10 def new
11   - @role = Role.new(:name => 'bla', :permissions => [])
  11 + @role = Role.new(:name => '', :permissions => [])
12 12 end
13 13  
14 14 def create
... ...
app/models/role.rb
... ... @@ -11,9 +11,8 @@ class Role < ActiveRecord::Base
11 11 }
12 12  
13 13 def self.permission_name(p)
14   -# msgid = ...
15   -# gettext(msgid)
16   - raise "Moises need to write me"
  14 + msgid = PERMISSIONS.values.inject({}){|s,v| s.merge(v)}[p]
  15 + gettext(msgid)
17 16 end
18 17  
19 18 has_many :role_assignments
... ...
app/views/role/_form.rhtml
1 1 <%= error_messages_for :role %>
2 2  
3   -<% labelled_form_for :role, @role do |f| %>
  3 +<% labelled_form_for :role, @role, :url => (mode == :edit) ? {:action => 'update', :id => role} : {:action => 'create'} do |f| %>
4 4  
5 5 <%= f.text_field :name %>
6 6  
7 7 <%= _('Permissions: ') %> <br>
8 8 <% Role::PERMISSIONS[:profile].keys.each do |p| %>
9   - <%= labelled_form_field("bla", (check_box_tag "role[permissions][#{p}]", @role.has_permission?(p))) %>
  9 + <%= labelled_form_field(Role.permission_name(p), (check_box_tag "role[permissions][]", p, @role.has_permission?(p))) %>
10 10 <% end %>
  11 +
  12 + <%= submit_tag (mode == :edit) ? _('Save changes') : _('Create role')%>
11 13 <% end %>
... ...
app/views/role/edit.rhtml 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<h2> <%= _("Editing #{@role.name}") %> </h2>
  2 +
  3 +<%= render :partial => 'form', :locals => { :mode => :edit, :role => @role } %>
... ...
app/views/role/index.rhtml
... ... @@ -4,7 +4,7 @@
4 4 <li>
5 5 <%= link_to role.name, :action => 'show', :id => role %>
6 6 <%= link_to _('Edit'), :action => 'edit', :id => role %>
7   - <%= link_to _('Destroy'), :action => 'destoy', :id => role %>
  7 + <%= link_to _('Destroy'), :action => 'destroy', :id => role %>
8 8 </li>
9 9 <% end %>
10 10 </ul>
... ...
app/views/role/show.rhtml 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<h1> <%= _(@role.name) %></h1>
  2 +
  3 +
  4 +<ul>
  5 + <% @role.permissions.each do |p| %>
  6 + <li> <%= Role.permission_name(p) %> </li>
  7 + <% end %>
  8 +</ul>
... ...