Admin can new/edit user_attributes

This commit is contained in:
Wen-Tien Chang 2010-03-15 17:35:01 +08:00
parent 263da6aa9f
commit bebc51e8bb
9 changed files with 145 additions and 1 deletions

View File

@ -0,0 +1,43 @@
class Admin::UserAttributesController < ApplicationController
layout "admin"
before_filter :authenticate_user!
def index
@user_attributes = UserAttribute.all
end
def show
@user_attribute = UserAttribute.find(params[:id])
end
def new
@user_attribute = UserAttribute.new
end
def edit
@user_attribute = UserAttribute.find(params[:id])
end
def create
@user_attribute = UserAttribute.new(params[:user_attribute])
@user_attribute.save
redirect_to :action => :index
end
def update
@user_attribute = UserAttribute.find(params[:id])
@user_attribute.update_attributes(params[:user_attribute])
redirect_to :action => :index
end
def destroy
@user_attribute = UserAttribute.find(params[:id])
@user_attribute.destroy
redirect_to :action => :index
end
end

View File

@ -0,0 +1,2 @@
module Admin::UserAttributesHelper
end

View File

@ -0,0 +1,43 @@
<p>
<%= f.label :name %>
<%= f.text_field :name %>
</p>
<fieldset>
<% @user_attribute.attrs.each_with_index do |attr, i| %>
<p>
<label><%= attr["key"] %></label>
<%= hidden_field_tag "user_attribute[attrs][][key]", attr["key"] %>
<%= text_field_tag "user_attribute[attrs][][name]", attr["name"] %>
<%= select_tag "user_attribute[attrs][][type]", options_for_select(["text_field"], attr["type"]) %>
<a href="#" class="remove">(remove)</a>
</p>
<% end -%>
<p id="newone">
<label>Key</label>
<%= text_field_tag "user_attribute[attrs][][key]", "" %>
<label>Name</label>
<%= text_field_tag "user_attribute[attrs][][name]", "" %>
<%= select_tag "user_attribute[attrs][][type]", options_for_select(["text_field"], "") %>
<a href="#" class="remove">(remove)</a>
</p>
<a href="#" class="add">(add)</a>
</fieldset>
<% content_for :page_specific_javascript do %>
<script type="text/javascript" charset="utf-8">
var newone = $('fieldset #newone').clone();
$('fieldset #newone').remove();
$('fieldset a.remove').live( "click", function(){
$(this).parent().remove();
});
$('fieldset a.add').click(function(){
newone.clone().appendTo( $('fieldset') );
})
</script>
<% end -%>

View File

@ -0,0 +1,12 @@
<h1>Editing user attribute: <%= @user_attribute.key %></h1>
<% form_for @user_attribute, :url => admin_user_attribute_path(@user_attribute) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit %>
</p>
<% end -%>

View File

@ -0,0 +1,23 @@
<h1>Listing user attributes</h1>
<table>
<tr>
<th>名稱</th>
<th>Key</th>
<th></th>
<th></th>
</tr>
<% @user_attributes.each do |user_attribute| %>
<tr>
<td><%= user_attribute.name %></td>
<td><%= user_attribute.key %></td>
<td><%= link_to t(:edit), edit_admin_user_attribute_path(user_attribute) %></td>
<td><%= link_to t(:delete), admin_user_attribute_path(user_attribute), :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to t(:new_user_attribute, :scope => :admin), new_admin_user_attribute_path, :class => 'button positive' %>

View File

@ -0,0 +1,17 @@
<h1>New user attribute: <%= @user_attribute.key %></h1>
<% form_for @user_attribute, :url => admin_user_attributes_path do |f| %>
<p>
<%= f.label :key, "Key" %>
<%= f.text_field :key %>
</p>
<%= render :partial => "form", :locals => { :f => f } %>
<p>
<%= f.submit %>
</p>
<% end -%>

View File

@ -24,6 +24,7 @@
<li><%= link_to t(:item, :scope => :admin), admin_items_path %></li>
<li><%= link_to t(:layout, :scope => :admin), admin_layouts_path %></li>
<li><%= link_to t(:asset, :scope => :admin), admin_assets_path %></li>
<li><%= link_to t(:user_attribute, :scope => :admin), admin_user_attributes_path %></li>
</ul>
</div>

View File

@ -18,7 +18,9 @@ zh_tw:
new_asset: 新增資產
move_up: 往上移
move_down: 往下移
user_attribute: 人物屬性
new_user_attribute: 新增人物屬性
panel:
home: 首頁
users: 使用者管理

View File

@ -17,6 +17,7 @@ R4::Application.routes.draw do |map|
resources :layouts
resources :snippets
resources :assets
resources :user_attributes
end
namespace :panel do