diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index bae0232a5..2a4bcf9c8 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -30,7 +30,8 @@ class OrgSubfieldsController < ApplicationController if params[:id] @organization = Organization.find(params[:id]) else - @organization = Organization.where("domain=?",request.subdomain).first + domain = Secdomain.where("subname=?", request.subdomain).first + @organization = Organization.find(domain.pid) end @org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+ "subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+ diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 6e2da311f..f225e7f50 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -139,7 +139,7 @@ class OrganizationsController < ApplicationController end def check_uniq_domain - @is_exist = (Organization.where("domain=?", params[:org_domain]).count > 0) + @is_exist = (Secdomain.where("subname=?",params[:org_domain]).count > 0) end def find_organization @@ -322,7 +322,12 @@ class OrganizationsController < ApplicationController def agree_apply_subdomain @organization = Organization.find(params[:organization_id]) OrgMessage.find(params[:act_id]).update_attribute(:viewed, 1) - @organization.update_attribute(:domain, params[:org_domain]) + if Secdomain.where("pid=? and sub_type=2",@organization.id).count > 0 + domain = Secdomain.where("pid=? and sub_type=2",params[:organization_id]).first + Secdomain.update(domain.id, :subname => params[:org_domain]) + else + Secdomain.create(:sub_type => 2, :pid => params[:organization_id], :subname => params[:org_domain]) + end if OrgMessage.where("message_type='AgreeApplySubdomain' and organization_id=#{@organization.id} and content=?",params[:org_domain]).count == 0 OrgMessage.create(:user_id => params[:user_id], :organization_id => @organization.id, :message_type => 'AgreeApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:org_domain]) end diff --git a/app/views/org_document_comments/_simple_ke_reply_form.html.erb b/app/views/org_document_comments/_simple_ke_reply_form.html.erb index c0166f5ce..44eb71500 100644 --- a/app/views/org_document_comments/_simple_ke_reply_form.html.erb +++ b/app/views/org_document_comments/_simple_ke_reply_form.html.erb @@ -1,16 +1,3 @@ -<style type="text/css"> - /*回复框*/ - .ReplyToMessageInputContainer .ke-toolbar{display:none;width:400px;border:none;background:none;padding:0px 0px;} - .ReplyToMessageInputContainer .ke-toolbar-icon{line-height:26px;font-size:14px;padding-left:26px;} - .ReplyToMessageInputContainer .ke-toolbar-icon-url{background-image:url( /images/public_icon.png )} - .ReplyToMessageInputContainer .ke-outline{padding:0px 0px;line-height:26px;font-size:14px;} - .ReplyToMessageInputContainer .ke-icon-emoticons{background-position:0px -671px;width:50px;height:26px;} - .ReplyToMessageInputContainer .ke-icon-emoticons:hover{background-position:-79px -671px;width:50px;height:26px;} - .ReplyToMessageInputContainer .ke-outline{border:none;} - .ReplyToMessageInputContainer .ke-inline-block{display: none;} - .ReplyToMessageInputContainer .ke-container{float:left;} -</style> - <div class="ReplyToMessageContainer borderBottomNone"id="reply_to_message_<%= reply.id%>"> <div class="homepagePostReplyPortrait mr15 imageFuzzy" id="reply_image_<%= reply.id%>"><%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %></div> <div class="ReplyToMessageInputContainer mb10"> diff --git a/app/views/organizations/_subfield_list.html.erb b/app/views/organizations/_subfield_list.html.erb index b49436d4e..eed0dabf6 100644 --- a/app/views/organizations/_subfield_list.html.erb +++ b/app/views/organizations/_subfield_list.html.erb @@ -28,7 +28,7 @@ <li class="orgListStatus">新增</li> <li class="orgListStatus"><%= field.field_type == "Post" ? "帖子" : "资源" %></li> <li class="orgListUser hidden"> - <% if @organization.domain %> + <% if Secdomain.where("sub_type=2 and pid=?", @organization.id).count > 0 %> <div id="sub_dir_show_<%= field.id %>" ondblclick="edit_dir('#sub_dir_show_<%= field.id %>','#sub_dir_edit_<%= field.id %>');" style="cursor:pointer;background-color:#fffce6;color: #0d90c3;" title="双击可编辑"> <%= field.subfield_subdomain_dir.nil? ? '未设置': field.subfield_subdomain_dir.name %> </div> diff --git a/app/views/organizations/setting.html.erb b/app/views/organizations/setting.html.erb index f2e4d5631..146e643a0 100644 --- a/app/views/organizations/setting.html.erb +++ b/app/views/organizations/setting.html.erb @@ -27,6 +27,7 @@ } </script> +<% domain = Secdomain.where("sub_type=2 and pid=?", @organization.id).first %> <div class="homepageRightBanner"> <div class="NewsBannerName">配置</div> </div> @@ -53,12 +54,12 @@ <div class="orgRow mb10"><span class="ml10">组织描述:</span><textarea type="text" name="organization[description]" class="orgDes" id="org_desc" placeholder="最多3000个汉字(或6000个英文字符)"><%= @organization.description%></textarea> <div class="cl"></div> </div> - <div style="margin-left: 80px " id="check_desc_hint"></div> + <div style="margin-left: 80px " id="check_desc_hint"></div> <div class="orgRow mb10"><span class="ml10">组织URL:</span> <div class="w607 fr">http:// - <input type="text" name="organization[domain]" id="domain" value="<%= @organization.domain%>" class="orgUrlInput" /> + <input type="text" name="organization[domain]" id="domain" value="<%= domain.nil? ? '' : domain.subname %>" class="orgUrlInput" /> .trustie.net<a href="javascript:void(0);" class="linkBlue ml15" style="text-decoration:underline;" onclick="apply_subdomain(<%= @organization.id %>,$('#domain').val());">申请</a> - <% if @organization.domain.present? and OrgMessage.where("organization_id=? and message_type='ApplySubdomain'", @organization.id).order("updated_at desc").first.content == @organization.domain %> + <% if domain.present? and OrgMessage.where("organization_id=? and message_type='ApplySubdomain'", @organization.id).order("updated_at desc").first.content == domain.subname %> <span>(已批准)</span> <% elsif OrgMessage.where("organization_id=? and message_type='ApplySubdomain'", @organization.id).count > 0 %> <span>(您申请了子域名<%= OrgMessage.where("organization_id=? and message_type='ApplySubdomain'", @organization.id).order("updated_at desc").first.content %>,还未批准)</span> @@ -127,8 +128,8 @@ <input type="text" id="subfield_name" name="name" placeholder="栏目名称" class="orgAddSearch mb10" /> <div class="mb5"> <p class="fontGrey3"><span class="fb">域名目录</span>(用户自定义url,可选)</p> - <% if @organization.domain %> - <span class="fl"><%= @organization.domain %>.trustie.net/</span><input class="fl personalUrl ml3" type="text" name="sub_dir"> + <% if domain %> + <span class="fl"><%= domain.subname %>.trustie.net/</span><input class="fl personalUrl ml3" type="text" name="sub_dir"> <% else %> <span class="fl">您还没有子域名,请先在左侧信息栏申请子域名</span> <% end %> diff --git a/app/views/users/user_organizations.html.erb b/app/views/users/user_organizations.html.erb index f3005c456..57b939af8 100644 --- a/app/views/users/user_organizations.html.erb +++ b/app/views/users/user_organizations.html.erb @@ -22,12 +22,7 @@ </div> <div class="orgWrap"> <div class="orgTitle"> - <% if org.domain.nil? %> <%= link_to org.name, organization_path(org), :class => 'f16 linkBlue' %> - <% else %> - <%= link_to org.name, organization_path(org), :class => 'f16 linkBlue' %> - <!--<a href="http://test.<%#= org.domain %>.trustie.net" class = 'f16 linkBlue'><%#= org.name %></a>--> - <% end %> </div> <div class="orgIntro"><%= org.description %></div> <div class="postCreater">创建者:<%= link_to User.find(org.creator_id), user_path(org.creator_id), :class => 'linkGrey2', :target => '_blank' %></div> diff --git a/config/initializers/subdomain.rb b/config/initializers/subdomain.rb index f813a24a0..b66059de5 100644 --- a/config/initializers/subdomain.rb +++ b/config/initializers/subdomain.rb @@ -9,7 +9,7 @@ class Subdomain o = ::Secdomain.where(subname: request.subdomain).first if(@opt[:sub]) - if o && o.sub_type == 2 && request.path_parameters[:sub_dir_name] == 'news' + if o && o.sub_type == 2 request.path_parameters[:id] = o.pid request.path_parameters[:controller] = 'org_subfields' request.path_parameters[:action] = 'show' diff --git a/db/migrate/20160223021012_add_index_to_secdomain.rb b/db/migrate/20160223021012_add_index_to_secdomain.rb new file mode 100644 index 000000000..928dfdbab --- /dev/null +++ b/db/migrate/20160223021012_add_index_to_secdomain.rb @@ -0,0 +1,5 @@ +class AddIndexToSecdomain < ActiveRecord::Migration + def change + add_index(:secdomains, :subname, unique: true) + end +end diff --git a/db/migrate/20160223021227_move_domain_to_secdomain.rb b/db/migrate/20160223021227_move_domain_to_secdomain.rb new file mode 100644 index 000000000..0c78f0ac6 --- /dev/null +++ b/db/migrate/20160223021227_move_domain_to_secdomain.rb @@ -0,0 +1,14 @@ +class MoveDomainToSecdomain < ActiveRecord::Migration + def up + Secdomain.transaction do + #将组织中的子域名迁移至secdomains表 + Organization.where("domain is not null").each do |org| + Secdomain.create(sub_type: 2, subname: org.domain, pid: org.id) + end + #remove_column :organizations, :domain + end + end + + def down + end +end diff --git a/db/migrate/20160223031843_remove_domain_from_organizations.rb b/db/migrate/20160223031843_remove_domain_from_organizations.rb new file mode 100644 index 000000000..d49ab3964 --- /dev/null +++ b/db/migrate/20160223031843_remove_domain_from_organizations.rb @@ -0,0 +1,8 @@ +class RemoveDomainFromOrganizations < ActiveRecord::Migration + def up + remove_column :organizations, :domain + end + + def down + end +end