From f142891e9d09d1001a2de0356f30466654273d3a Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Sat, 15 Sep 2007 17:38:17 +0000 Subject: [PATCH] ActionItem5: interface to manage roles functional --- app/controllers/role_controller.rb | 2 +- app/models/role.rb | 5 ++--- app/views/role/_form.rhtml | 6 ++++-- app/views/role/edit.rhtml | 3 +++ app/views/role/index.rhtml | 2 +- app/views/role/show.rhtml | 8 ++++++++ 6 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 app/views/role/edit.rhtml create mode 100644 app/views/role/show.rhtml diff --git a/app/controllers/role_controller.rb b/app/controllers/role_controller.rb index a50b423..7063e8f 100644 --- a/app/controllers/role_controller.rb +++ b/app/controllers/role_controller.rb @@ -8,7 +8,7 @@ class RoleController < ApplicationController end def new - @role = Role.new(:name => 'bla', :permissions => []) + @role = Role.new(:name => '', :permissions => []) end def create diff --git a/app/models/role.rb b/app/models/role.rb index 84d2fb3..370e4b5 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -11,9 +11,8 @@ class Role < ActiveRecord::Base } def self.permission_name(p) -# msgid = ... -# gettext(msgid) - raise "Moises need to write me" + msgid = PERMISSIONS.values.inject({}){|s,v| s.merge(v)}[p] + gettext(msgid) end has_many :role_assignments diff --git a/app/views/role/_form.rhtml b/app/views/role/_form.rhtml index 1ed5c67..b801cfd 100644 --- a/app/views/role/_form.rhtml +++ b/app/views/role/_form.rhtml @@ -1,11 +1,13 @@ <%= error_messages_for :role %> -<% labelled_form_for :role, @role do |f| %> +<% labelled_form_for :role, @role, :url => (mode == :edit) ? {:action => 'update', :id => role} : {:action => 'create'} do |f| %> <%= f.text_field :name %> <%= _('Permissions: ') %>
<% Role::PERMISSIONS[:profile].keys.each do |p| %> - <%= labelled_form_field("bla", (check_box_tag "role[permissions][#{p}]", @role.has_permission?(p))) %> + <%= labelled_form_field(Role.permission_name(p), (check_box_tag "role[permissions][]", p, @role.has_permission?(p))) %> <% end %> + + <%= submit_tag (mode == :edit) ? _('Save changes') : _('Create role')%> <% end %> diff --git a/app/views/role/edit.rhtml b/app/views/role/edit.rhtml new file mode 100644 index 0000000..3714a42 --- /dev/null +++ b/app/views/role/edit.rhtml @@ -0,0 +1,3 @@ +

<%= _("Editing #{@role.name}") %>

+ +<%= render :partial => 'form', :locals => { :mode => :edit, :role => @role } %> diff --git a/app/views/role/index.rhtml b/app/views/role/index.rhtml index d358fe2..fe54a6f 100644 --- a/app/views/role/index.rhtml +++ b/app/views/role/index.rhtml @@ -4,7 +4,7 @@
  • <%= link_to role.name, :action => 'show', :id => role %> <%= link_to _('Edit'), :action => 'edit', :id => role %> - <%= link_to _('Destroy'), :action => 'destoy', :id => role %> + <%= link_to _('Destroy'), :action => 'destroy', :id => role %>
  • <% end %> diff --git a/app/views/role/show.rhtml b/app/views/role/show.rhtml new file mode 100644 index 0000000..e86632a --- /dev/null +++ b/app/views/role/show.rhtml @@ -0,0 +1,8 @@ +

    <%= _(@role.name) %>

    + + + -- libgit2 0.21.2