建立组织、成员表及模型控制器;

编写创建组织页面。
This commit is contained in:
ouyangxuhua 2015-11-03 11:19:38 +08:00
parent 636063c6ca
commit eadab840b6
16 changed files with 156 additions and 9 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://jashkenas.github.com/coffee-script/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the organizations 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,15 @@
class OrganizationsController < ApplicationController
def new
@organization = Organization.new
render :layout => 'new_base'
end
def create
@organization = Organization.new
@organization.name = params[:organization][:name]
@organization.description = params[:organization][:description]
@organization.is_public = params[:organization][:is_public]
@organization.creator_id = User.current.id
member = OrgMember.new(:user_id => User.current.id, :role => 'Manager')
@organization.org_members << member
end
end

View File

@ -1,2 +1,2 @@
module EnterprisesHelper
module OrganizationsHelper
end

4
app/models/org_member.rb Normal file
View File

@ -0,0 +1,4 @@
class OrgMember < ActiveRecord::Base
attr_accessible :organization_id, :role, :user_id
belongs_to :organization
end

View File

@ -1,5 +1,5 @@
class Organization < ActiveRecord::Base
attr_accessible :logo_link, :name
attr_accessible :name, :description, :creator_id, :home_id, :domain, :is_public
has_many :org_members, :dependent => :destroy
has_many :projects
end

View File

@ -13,7 +13,7 @@
<%= javascript_heads %>
<%= heads_for_theme %>
<%= call_hook :view_layouts_base_html_head %>
<%= stylesheet_link_tag 'public', 'leftside', 'courses','header','prettify'%>
<%= stylesheet_link_tag 'public', 'leftside', 'courses','header','prettify', 'org'%>
<%= javascript_include_tag "course","header",'prettify' %>
<!-- page specific tags -->
<%= yield :header_tags -%>

View File

View File

@ -0,0 +1,95 @@
<% @nav_dispaly_organization_label = 1
@nav_dispaly_forum_label = 1 %>
<%= error_messages_for 'organization' %>
<div class="organization_r_h02">
<h2 class="organization_h2"><%= l(:label_organization_new)%></h2>
</div>
<div class="hwork_new">
<ul>
<%= labelled_form_for @organization do |f| %>
<li class="ml45">
<input type="text" style="display: none"/> <!--阻止表单自动填充 -->
<input type="password" style="display: none"/> <!--阻止表单自动填充 -->
<label><span class="c_red">*</span>&nbsp;<%= l(:label_organization_name)%>&nbsp;&nbsp;</label>
<input type="text" name="organization[name]" id="organization_name" class="courses_input" maxlength="100" onkeyup="regex_organization_name();">
<span class="c_red" id="organization_name_notice" style="display: none;">项目名称不能为空</span>
</li>
<div class="cl"></div>
<div class="cl"></div>
<li class="ml45">
<label class="fl" >&nbsp;&nbsp;<%= l(:label_organization_description) %>&nbsp;&nbsp;</label>
<textarea name="organization[description]" placeholder="最多3000个汉字(或6000个英文字符)" class="courses_text fl" ></textarea>
<div class="cl"></div>
</li>
<li>
<p style="display: none" >
<%= f.text_field :identifier, :required => true, :size => 60, :style => "width:488px;", :maxlength => Project::IDENTIFIER_MAX_LENGTH,
value:"#{User.current.id.to_s + '_' +Time.now.to_s.gsub(' ','_').gsub(':','').gsub('+','')}" %>
</p>
</li>
<li class=" mb5 ml80">
<label >公开&nbsp;&nbsp;</label>
<input id="organization_is_public" name="organization[is_public]" type="checkbox" value="1" checked="checked">
<span class="c_grey">(打钩为公开,不打钩则不公开,若不公开,仅项目成员可见该项目。)</span>
<div class="cl"></div>
</li>
<li class=" ml90" >
<a href="javascript:void(0)" class="blue_btn fl c_white" onclick="submit_new_organization();" >提交</a>
<%= link_to "取消",user_activities_path(User.current.id),:class => "blue_btn grey_btn fl c_white"%>
<div class="cl"></div>
</li>
<% end%>
</ul>
</div><!--talknew end-->
<div class="cl"></div>
<% html_title(l(:label_organization_new)) -%>
<script>
//////////////////////////////////////////////////////////////
//新建项目
//验证项目名称
function regex_organization_name()
{
var name = $.trim($("#organization_name").val());
if(name.length == 0)
{
$("#organization_name_notice").show();
return false;
}
else
{
$("#organization_name_notice").hide();
return true;
}
}
//提交新建项目
function submit_new_organization()
{
if(regex_organization_name())
{
$("#new_organization").submit();
}
}
$(function(){
$('#organization_new_type').change(function(){
var type = $('#organization_new_type').val();
if(type == '1'){
$(this).next().html("<%= l(:label_type_des_development)%>");
}
else if(type == '2'){
$(this).next().html("<%= l(:label_type_des_research)%>");
}
else if(type == '3'){
$(this).next().html("<%= l(:label_type_des_friend)%>");
}
// var p1=$(this).children('option:selected').val("研讨模式:面向小组研究,支持任务分工、论坛交流、资源分享等。");//这就是selected的值
// var p2=$('#param2').val();//获取本页面其他标签的值
})
})
</script>

View File

@ -289,6 +289,10 @@ zh:
label_projects_new_name: "项目名称"
label_tags_project_description: "项目描述"
label_organization_name: "组织名称"
label_organization_description: "组织描述"
label_organization_new: "新建组织"
label_tags_user_mail: "用户邮箱:"
label_tags_user_name: "用户名:"

View File

@ -31,6 +31,8 @@ RedmineApp::Application.routes.draw do
# Enable Grack support
# mount Trustie::Grack.new, at: '/', constraints: lambda { |request| /[-\/\w\.]+\.git\//.match(request.path_info) }, via: [:get, :post]
resources :organizations
resources :homework_users
resources :no_uses
delete 'no_uses', :to => 'no_uses#delete'

View File

@ -1,14 +1,11 @@
class CreateOrgMembers < ActiveRecord::Migration
def up
def change
create_table :org_members do |t|
t.integer :user_id
t.integer :organization_id
t.string :role
t.timestamps
end
end
def down
drop_table :org_members
end
end

View File

@ -0,0 +1,6 @@
@charset "utf-8";
/* CSS Document */
.orgName {width:130px; color:#484848;}
.organization_r_h02{ width:970px; height:40px; background:#eaeaea; margin-bottom:10px;}
.organization_h2{ background:#64bdd9; color:#fff; height:33px; width:90px; text-align:center; font-weight:normal; padding-top:7px; font-size:16px;}

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe OrganizationsController, :type => :controller do
end

View File

@ -0,0 +1,8 @@
FactoryGirl.define do
factory :org_member do
user_id 1
organization_id 1
role "MyString"
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe OrgMember, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end