Changed signup form - RoleStatus work in progress

This commit is contained in:
Saurabh Bhatia 2014-05-26 15:18:59 +08:00
parent 1f9ab39a09
commit ab8b52e66f
24 changed files with 214 additions and 8 deletions

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the admin/role_statuses controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,54 @@
class Admin::RoleStatusesController < OrbitMemberController
before_action :set_role_status, only: [:show, :edit , :update, :destroy]
def index
@role = Role.find(params[:role_id])
@role_statuses = RoleStatus.where(role_id: @role.id)
respond_to do |format|
format.html # index.html.erb
format.js
end
end
def show
end
def new
@role_status = RoleStatus.new
render layout: false
end
def create
@role_status = RoleStatus.new(role_status_params)
if @role_status.save
redirect_to action: :index
else
redirect_to action: :new
end
end
def edit
render layout: false
end
def update
end
def toggle
end
def destroy
end
private
# Use callbacks to share common setup or constraints between actions.
def set_role_status
@role_status = RoleStatus.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def role_status_params
params.require(:role_status).permit!
end
end

View File

@ -6,7 +6,7 @@ class UsersController < ApplicationController
def create def create
@user = User.new(user_params) @user = User.new(user_params)
@member = MemberProfile.new(email: params[:email]) @member = MemberProfile.new(email: params[:email], first_name: params[:first_name], last_name: params[:last_name])
if @user.save if @user.save
@member.save @member.save
@user.update_attributes(member_profile_id: @member.id) @user.update_attributes(member_profile_id: @member.id)
@ -35,6 +35,6 @@ class UsersController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def user_params def user_params
params.require(:user).permit(:password, :password_confirmation, :user_name, :member_profile_id, :email) params.require(:user).permit(:password, :password_confirmation, :user_name, :member_profile_id, :email, :first_name, :last_name)
end end
end end

View File

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

View File

@ -8,6 +8,7 @@ class Role
has_and_belongs_to_many :member_profiles has_and_belongs_to_many :member_profiles
has_many :authorizations has_many :authorizations
embeds_many :role_fields embeds_many :role_fields
has_many :role_statuses
def is_built_in? def is_built_in?
self.built_in self.built_in

16
app/models/role_status.rb Normal file
View File

@ -0,0 +1,16 @@
class RoleStatus
include Mongoid::Document
field :key, type: String
field :title, type: String, localize: true
field :disable, type: Boolean, default: false
scope :can_display, ->{ where(disable: false) }
has_and_belongs_to_many :member_profile
belongs_to :role
def self.get_role_data(role_key)
@role = Role.find_by(key: role_key)
return @role.id
end
end

View File

@ -23,7 +23,7 @@ class User
validates :password, presence: true, :on => :create, length: {:in => 8..20} validates :password, presence: true, :on => :create, length: {:in => 8..20}
#Add getter and setter for email virtual field #Add getter and setter for email virtual field
attr_accessor :email attr_accessor :email, :first_name, :last_name
def generate_confirmation_token def generate_confirmation_token
self.confirmation_token = SecureRandom.hex(5) self.confirmation_token = SecureRandom.hex(5)

View File

@ -0,0 +1,10 @@
<%= label_tag "key","key", :class=>"muted" %>
<%= f.text_field :key, :class=>"input-large" %>
<%= f.fields_for :title_translations do |f| %>
<% @site_in_use_locales.each do |locale| %>
<%= label_tag "name-#{locale}", "#{t(:name)} (#{I18nVariable.from_locale(locale)})" %>
<%= f.text_field locale, :class => 'input-large', :value => (@role_filter.title_translations[locale] rescue ''), placeholder: t(:name) %>
<% end %>
<% end %>
<%= f.hidden_field :role_id, :value => params[:role_id] if !params[:role_id].blank? %>

View File

@ -0,0 +1,16 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<th class="span3 active"><a href="#">Key<b class="icons-arrow-down-4"></b></a></th>
<% @site_in_use_locales.each do |locale| %>
<th><%= I18nVariable.from_locale(locale) %></th>
<% end %>
<th class="span1"></th>
</tr>
</thead>
<tbody>
<%= render :partial => 'role_status', :collection => @role_status %>
</tbody>
</table>

View File

@ -0,0 +1,10 @@
<%= form_for @role_status, url: admin_role_status_path(id: @role_status.id), remote: true, :html => { :id => 'form_role_filter' } do |f| %>
<fieldset>
<legend>Add</legend>
<%= render :partial => 'form', :locals => {:f => f} %>
</fieldset>
<div class="form-actions">
<a href="javascript:$.pageslide.close()" class="btn btn-small"><%= t(:cancel) %></a>
<%= f.submit t(:create_), class: 'btn btn-primary btn-small' %>
</div>
<% end %>

View File

@ -0,0 +1,19 @@
<tr id="<%= dom_id role_status %>" class="<%= role_status.disable ? 'disable' : '' %>">
<td><span class="label label-info"><%= role_status.key %></span></td>
<% @site_in_use_locales.each_with_index do |locale, i| %>
<td>
<%= role_status.title_translations[locale] rescue nil %>
<% if i == 0 %>
<div class="quick-edit">
<ul class="nav nav-pills">
<li><%= link_to t(:edit), polymorphic_path([:admin, role_status], {:action => :edit}), :class=>"open-slide" %></li>
</ul>
</div>
<% end %>
</td>
<% end %>
<td class="action dsrgsdgsdg">
<%= check_box_tag 'accept', role_status.disable ? 'fasle' : 'true', false ,{ :class => 'toggle-check role_status_checked', :data=>{:deploy=>"right"}, :data=>{:path=> eval("admin_role_status_toggle_path(role_status)")}, :checked=> role_status.disable} %>
</td>
</tr>

View File

@ -0,0 +1,20 @@
<% content_for :side_bar do %>
<%= render :partial => 'admin/members/side_bar' %>
<% end %>
<% content_for :page_specific_css do -%>
<%= stylesheet_link_tag "lib/wrap-nav.css" %>
<%= stylesheet_link_tag "lib/pageslide.css" %>
<%= stylesheet_link_tag "lib/main-list.css" %>
<%= stylesheet_link_tag "lib/togglebox.css" %>
<% end -%>
<div class="bottomnav clearfix">
<div class="action pull-right">
<%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), eval("new_admin_role_status_path(role_id: params[:role_id])"), class: "btn btn-primary open-slide" %>
</div>
</div>
<div id="role_filters_index">
<%= render 'index' %>
</div>

View File

@ -0,0 +1 @@
<%= render 'new' %>

View File

@ -0,0 +1 @@
$("#form > form").replaceWith("<%= j render "form" %>");

View File

@ -6,6 +6,7 @@
<ul class="nav nav-pills"> <ul class="nav nav-pills">
<li><%= link_to t(:edit), edit_admin_role_path(role), :class=>"open-slide" %></li> <li><%= link_to t(:edit), edit_admin_role_path(role), :class=>"open-slide" %></li>
<li><%= link_to t(:role_field) %></li> <li><%= link_to t(:role_field) %></li>
<li><%= link_to t(:status), admin_role_statuses_path(role_id: role.id) %></li>
<li></li> <li></li>
</ul> </ul>
</div> </div>

View File

@ -1,2 +0,0 @@
<h1>Member#new</h1>
<p>Find me in app/views/member/new.html.erb</p>

View File

@ -22,6 +22,26 @@
</div> </div>
</div> </div>
<div class="control-group clear">
<label class="control-label" for="user_email"><%= t("user.first_name")%></label>
<div class="controls">
<%= text_field_tag :first_name, "", class: "availibility", id: "user_first_name", placeholder: t("users.first_name") %>
<span class="loader hide"><img src="/assets/availability-check-loader.gif" /></span>
<span class="notify not-ok hide alert alert-danger"><i class="icon-remove"></i>Not Available</span>
<span class="notify ok hide alert alert-success"><i class="icon-ok"></i>Available</span>
</div>
</div>
<div class="control-group clear">
<label class="control-label" for="user_email"><%= t("user.last_name")%></label>
<div class="controls">
<%= text_field_tag :last_name, "", class: "availibility", id: "user_last_name", placeholder: t("users.last_name") %>
<span class="loader hide"><img src="/assets/availability-check-loader.gif" /></span>
<span class="notify not-ok hide alert alert-danger"><i class="icon-remove"></i>Not Available</span>
<span class="notify ok hide alert alert-success"><i class="icon-ok"></i>Available</span>
</div>
</div>
<div class="control-group clear"> <div class="control-group clear">
<label class="control-label" for="user_email"><%= t("user.email")%></label> <label class="control-label" for="user_email"><%= t("user.email")%></label>
<div class="controls"> <div class="controls">

View File

@ -49,8 +49,6 @@ Orbit::Application.routes.draw do
resources :passwords resources :passwords
namespace :admin do namespace :admin do
resources :dashboards do resources :dashboards do
collection do collection do
@ -71,6 +69,10 @@ Orbit::Application.routes.draw do
resources :member_infos resources :member_infos
resources :role_statuses do
post 'toggle'
end
resources :module_apps do resources :module_apps do
resources :categories do resources :categories do
collection do collection do

View File

@ -0,0 +1,9 @@
require 'test_helper'
class Admin::RoleStatusesControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
end
end

9
test/fixtures/role_statuses.yml vendored Normal file
View File

@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
key: MyString
title: MyString
two:
key: MyString
title: MyString

View File

@ -0,0 +1,4 @@
require 'test_helper'
class Admin::RoleStatusesHelperTest < ActionView::TestCase
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class RoleStatusTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end