完成组织二级域名

beidou_tim
huang 9 years ago
parent 811c3a065e
commit 9fbf713709

@ -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/

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

@ -0,0 +1,28 @@
class SubDomainsController < ApplicationController
layout 'base_org'
def create
if SubDomain.where("org_subfield_id=#{params[:org_subfield_id]} and name=?",params[:name]).count == 0
@res = true
# @organization = Organization.find(params[:organization_id])
@subfield = OrgSubfield.find(params[:org_subfield_id])
# @subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id],:priority => @organization.org_subfields.order("priority").last.priority + 1)
@subdomain = SubDomain.create(:name => params[:name], :org_subfield_id => params[:org_subfield_id],:priority => @subfield.sub_domains.blank? ? 1.1 : @subfield.sub_domains.order("priority").last.priority + 0.1)
# if !params[:sub_dir].blank?
# sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+
# "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'"
# if SubfieldSubdomainDir.find_by_sql(sql).count == 0
# SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir].downcase)
# end
# end
@subdomain.update_column(:field_type, params[:field_type])
else
@res = false
end
end
def show
@subdomain = SubDomain.find(params[:id])
render layout: 'base'
end
end

@ -0,0 +1,2 @@
module SubDomainsHelper
end

@ -7,6 +7,7 @@ class OrgSubfield < ActiveRecord::Base
has_many :messages, :through => :org_subfield_messages
has_many :boards, :dependent => :destroy
has_many :news, :dependent => :destroy
has_many :sub_domains, :dependent => :destroy
acts_as_attachable
after_create :create_board_sync
after_destroy :update_priority

@ -0,0 +1,4 @@
class SubDomain < ActiveRecord::Base
attr_accessible :field_type, :hide, :name, :org_subfield_id, :priority, :status
belongs_to :org_subfield, :foreign_key => :org_subfield_id
end

@ -128,6 +128,29 @@
<div class="cl"></div>
</div>
<div class="undis ml15 mr15" id="orgContent_3">
<!--新增二级栏目-->
<div class="orgMemberList" id="org_subfield_list">
<p>
<%= form_tag url_for(:controller => 'sub_domains', :action => 'create', :org_subfield_id => 458), :id=> 'add_subfield_form_subdomain',:remote => true do %>
<input type="text" id="subfield_name_subdomain" name="name" placeholder="二级栏目名称" class="orgAddSearch mb10" />
<ul class="orgAddRole">
<li class="fontGrey3 fb mb10">栏目类型</li>
<li class="fl mr15">
<input type="radio" id="orgMng" value="Post" name="field_type" checked="checked"/>
<label for="orgMng">帖子</label>
</li>
<li class="fl">
<input type="radio" id="orgMeb" value="Resource" name="field_type" />
<label for="orgMeb">资源</label>
</li>
<li class="cl"></li>
</ul>
<div class="cl"></div>
<a href="javascript:void(0);" class="saveBtn db fl mt10" onclick="add_org_subfield_subdomain();">确定</a>
<% end %>
</p>
</div>
<!--over-->
<div class="orgMemberList" id="org_subfield_list">
<%= render :partial => 'organizations/subfield_list', :locals => {:subfields => @organization.org_subfields.order("priority")} %>
</div>
@ -170,6 +193,12 @@
if ($("#subfield_name").val().trim() != "")
$("#add_subfield_form").submit();
}
function add_org_subfield_subdomain(){
if ($("#subfield_name_subdomain").val().trim() != "")
alert("Test");
$("#add_subfield_form_subdomain").submit();
}
var $is_exist = false;
function apply_subdomain(id, domain){
var reg = new RegExp("^[a-zA-Z0-9_]{1,}$");

@ -117,6 +117,14 @@ RedmineApp::Application.routes.draw do
match "quote_resource_show_org_subfield", :via => [:get]
end
end
resources :sub_domains, :only => [:index, :new, :create, :show] do
collection do
end
member do
end
end
member do
match 'update_sub_dir', :via => [:put]
match 'update_priority', :via => [:put]

@ -0,0 +1,14 @@
class CreateSubDomains < ActiveRecord::Migration
def change
create_table :sub_domains do |t|
t.integer :org_subfield_id
t.integer :priority, :default => false
t.string :name
t.string :field_type
t.integer :hide, :default => false
t.integer :status, :default => false
t.timestamps
end
end
end

File diff suppressed because it is too large Load Diff

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

@ -0,0 +1,11 @@
FactoryGirl.define do
factory :sub_domain do
org_subfield_id 1
priority 1
name "MyString"
field_type "MyString"
hide 1
status 1
end
end

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