diff --git a/app/controllers/admin/user_attributes_controller.rb b/app/controllers/admin/user_attributes_controller.rb new file mode 100644 index 00000000..c7021c74 --- /dev/null +++ b/app/controllers/admin/user_attributes_controller.rb @@ -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 diff --git a/app/helpers/admin/user_attributes_helper.rb b/app/helpers/admin/user_attributes_helper.rb new file mode 100644 index 00000000..c60beabb --- /dev/null +++ b/app/helpers/admin/user_attributes_helper.rb @@ -0,0 +1,2 @@ +module Admin::UserAttributesHelper +end diff --git a/app/views/admin/user_attributes/_form.html.erb b/app/views/admin/user_attributes/_form.html.erb new file mode 100644 index 00000000..05a03817 --- /dev/null +++ b/app/views/admin/user_attributes/_form.html.erb @@ -0,0 +1,43 @@ +

+ <%= f.label :name %> + <%= f.text_field :name %> +

+ +
+ <% @user_attribute.attrs.each_with_index do |attr, i| %> +

+ + <%= 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"]) %> + (remove) +

+ <% end -%> + +

+ + <%= text_field_tag "user_attribute[attrs][][key]", "" %> + + <%= text_field_tag "user_attribute[attrs][][name]", "" %> + <%= select_tag "user_attribute[attrs][][type]", options_for_select(["text_field"], "") %> + (remove) +

+ + (add) + +
+ +<% content_for :page_specific_javascript do %> + +<% end -%> \ No newline at end of file diff --git a/app/views/admin/user_attributes/edit.html.erb b/app/views/admin/user_attributes/edit.html.erb new file mode 100644 index 00000000..1bc86bc4 --- /dev/null +++ b/app/views/admin/user_attributes/edit.html.erb @@ -0,0 +1,12 @@ + +

Editing user attribute: <%= @user_attribute.key %>

+ +<% form_for @user_attribute, :url => admin_user_attribute_path(@user_attribute) do |f| %> + + <%= render :partial => "form", :locals => { :f => f } %> + +

+ <%= f.submit %> +

+ +<% end -%> diff --git a/app/views/admin/user_attributes/index.html.erb b/app/views/admin/user_attributes/index.html.erb new file mode 100644 index 00000000..c9fe93b4 --- /dev/null +++ b/app/views/admin/user_attributes/index.html.erb @@ -0,0 +1,23 @@ +

Listing user attributes

+ + + + + + + + + +<% @user_attributes.each do |user_attribute| %> + + + + + + +<% end %> +
名稱Key
<%= user_attribute.name %><%= user_attribute.key %><%= link_to t(:edit), edit_admin_user_attribute_path(user_attribute) %><%= link_to t(:delete), admin_user_attribute_path(user_attribute), :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to t(:new_user_attribute, :scope => :admin), new_admin_user_attribute_path, :class => 'button positive' %> \ No newline at end of file diff --git a/app/views/admin/user_attributes/new.html.erb b/app/views/admin/user_attributes/new.html.erb new file mode 100644 index 00000000..c2ada3c1 --- /dev/null +++ b/app/views/admin/user_attributes/new.html.erb @@ -0,0 +1,17 @@ + +

New user attribute: <%= @user_attribute.key %>

+ +<% form_for @user_attribute, :url => admin_user_attributes_path do |f| %> + +

+ <%= f.label :key, "Key" %> + <%= f.text_field :key %> +

+ + <%= render :partial => "form", :locals => { :f => f } %> + +

+ <%= f.submit %> +

+ +<% end -%> diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 54c76a1c..7770b6d4 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -24,6 +24,7 @@
  • <%= link_to t(:item, :scope => :admin), admin_items_path %>
  • <%= link_to t(:layout, :scope => :admin), admin_layouts_path %>
  • <%= link_to t(:asset, :scope => :admin), admin_assets_path %>
  • +
  • <%= link_to t(:user_attribute, :scope => :admin), admin_user_attributes_path %>
  • diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 68c9a198..d6791aa4 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -18,7 +18,9 @@ zh_tw: new_asset: 新增資產 move_up: 往上移 move_down: 往下移 - + user_attribute: 人物屬性 + new_user_attribute: 新增人物屬性 + panel: home: 首頁 users: 使用者管理 diff --git a/config/routes.rb b/config/routes.rb index ddc701f6..11a686b8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,7 @@ R4::Application.routes.draw do |map| resources :layouts resources :snippets resources :assets + resources :user_attributes end namespace :panel do