diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb
index dabf45da8..3c5266f79 100644
--- a/app/controllers/organizations_controller.rb
+++ b/app/controllers/organizations_controller.rb
@@ -28,7 +28,7 @@ class OrganizationsController < ApplicationController
helper :project_score
helper :issues
include UsersHelper
- before_filter :find_organization, :only => [:show, :members]
+ before_filter :find_organization, :only => [:show, :members, :apply_subdomain]
layout 'base_org'
def index
@@ -291,4 +291,20 @@ class OrganizationsController < ApplicationController
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
@org_subfield.update_attribute(:hide, 0)
end
+
+ def apply_subdomain
+ @organization = Organization.find(params[:id])
+ admins = User.where("admin=1")
+ admins.each do |admin|
+ OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain])
+ end
+ end
+
+ def agree_apply_subdomain
+ @organization = Organization.find(params[:organization_id])
+ @organization.update_attribute(:domain, params[:org_domain])
+ 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
+ end
end
diff --git a/app/models/org_message.rb b/app/models/org_message.rb
new file mode 100644
index 000000000..baedc77f4
--- /dev/null
+++ b/app/models/org_message.rb
@@ -0,0 +1,15 @@
+class OrgMessage < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :organization
+ has_many :message_alls, :as => :message, :dependent => :destroy
+ validates :message_type, :presence => true
+ validates :message_id, :presence => true
+ validates :organization_id, :presence => true
+ after_create :add_user_message
+
+ def add_user_message
+ if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
+ self.message_alls << MessageAll.new(:user_id => self.user_id)
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/views/homework_common/_set_evalutation_att.html.erb b/app/views/homework_common/_set_evalutation_att.html.erb
index 59df88680..bc4e8e733 100644
--- a/app/views/homework_common/_set_evalutation_att.html.erb
+++ b/app/views/homework_common/_set_evalutation_att.html.erb
@@ -45,7 +45,7 @@
确定
diff --git a/app/views/homework_common/score_rule_set.js.erb b/app/views/homework_common/score_rule_set.js.erb
index 7fae1ecdc..da685b758 100644
--- a/app/views/homework_common/score_rule_set.js.erb
+++ b/app/views/homework_common/score_rule_set.js.erb
@@ -2,5 +2,5 @@ $('#ajax-modal').html('<%= escape_javascript(render :partial => 'student_work/se
showModal('ajax-modal', '350px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("" +
- " ");
+ " ");
$('#ajax-modal').parent().css("top","25%").css("left","35%").css("position","fixed");
\ No newline at end of file
diff --git a/app/views/homework_common/start_evaluation_set.js.erb b/app/views/homework_common/start_evaluation_set.js.erb
index 2a260dc4d..659441ce8 100644
--- a/app/views/homework_common/start_evaluation_set.js.erb
+++ b/app/views/homework_common/start_evaluation_set.js.erb
@@ -3,7 +3,7 @@ var datepickerOptions={dateFormat: 'yy-mm-dd', firstDay: 0, showOn: 'button', bu
showModal('ajax-modal', '350px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("" +
-" ");
+" ");
$('#ajax-modal').parent().css("top","25%").css("left","35%").css("position","fixed");
$(function() { $('#evaluation_start_time').datepicker(datepickerOptions);
$('#evaluation_end_time').datepicker(datepickerOptions);
diff --git a/app/views/organizations/agree_apply_subdomain.js.erb b/app/views/organizations/agree_apply_subdomain.js.erb
new file mode 100644
index 000000000..df25d018c
--- /dev/null
+++ b/app/views/organizations/agree_apply_subdomain.js.erb
@@ -0,0 +1 @@
+$("#agree_apply_subdomain").text("已同意申请");
\ No newline at end of file
diff --git a/app/views/organizations/apply_subdomain.js.erb b/app/views/organizations/apply_subdomain.js.erb
new file mode 100644
index 000000000..e69de29bb
diff --git a/app/views/organizations/setting.html.erb b/app/views/organizations/setting.html.erb
index 3058d03a8..77cfdc985 100644
--- a/app/views/organizations/setting.html.erb
+++ b/app/views/organizations/setting.html.erb
@@ -54,14 +54,14 @@
-
-
-
-
-
-
-
-
+ 组织URL:
+
https://
+
+ .trustie.net
申请
+
+
+
+
公开 :
class="ml3" />
@@ -139,4 +139,17 @@
if ($("#subfield_name").val().trim() != "")
$("#add_subfield_form").submit();
}
+ function apply_subdomain(id, domain){
+ $.ajax({
+ url:"<%= apply_subdomain_organization_path %>",
+ type:'post',
+ data:{
+ id:id,
+ domain:domain
+ },
+ success:function(){
+ $("#apply_hint").text("您的申请已提交,系统会以消息的形式通知您结果");
+ }
+ });
+ }
\ No newline at end of file
diff --git a/app/views/student_work/_set_score_rule_detail.html.erb b/app/views/student_work/_set_score_rule_detail.html.erb
index 4739fba47..c8451e478 100644
--- a/app/views/student_work/_set_score_rule_detail.html.erb
+++ b/app/views/student_work/_set_score_rule_detail.html.erb
@@ -56,7 +56,7 @@
确定
diff --git a/app/views/users/_user_message_org.html.erb b/app/views/users/_user_message_org.html.erb
new file mode 100644
index 000000000..56d7d7b29
--- /dev/null
+++ b/app/views/users/_user_message_org.html.erb
@@ -0,0 +1,39 @@
+<% if ma.class == OrgMessage %>
+ <% if ma.message_type == 'ApplySubdomain'%>
+
+
+ <%=link_to image_tag(url_to_avatar(ma.organization), :width => "30", :height => "30"), organization_path(ma.organization_id) %>
+
+
+ <%=link_to ma.organization.name, organization_path(ma.organization_id), :class => "newsBlue homepageNewsPublisher" %>
+ '>申请子域名:
+
+
+ <%= ma.content %>
+
+
+ <%=link_to ma.organization.domain.nil? ? "同意申请":"已同意申请", agree_apply_subdomain_organizations_path( :organization_id => ma.organization_id, :org_domain => ma.content, :user_id => ma.sender_id ),
+ :id => 'agree_apply_subdomain',
+ :method => 'post',
+ :remote => true,
+ :class => "green_btn_cir ml10",
+ :style => "color:#fff" %>
+
+ <%= time_tag(ma.created_at).html_safe %>
+
+ <% end %>
+ <% if ma.message_type == 'AgreeApplySubdomain'%>
+
+
+ <%= image_tag("/images/trustie_logo1.png", width: "30px", height: "30px", class: "mt3") %>
+
+
+ '>管理员同意了您的子域名申请:
+
+
+ <%= ma.content %>
+
+ <%= time_tag(ma.created_at).html_safe %>
+
+ <% end %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/users/user_messages.html.erb b/app/views/users/user_messages.html.erb
index d690f7e43..391709b52 100644
--- a/app/views/users/user_messages.html.erb
+++ b/app/views/users/user_messages.html.erb
@@ -31,6 +31,8 @@
<%= render :partial => 'users/user_message_userfeedaback', :locals => {:ma => ma} %>
+ <%= render :partial => 'users/user_message_org', :locals => {:ma => ma} %>
+
<% end %>
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
diff --git a/app/views/users/user_organizations.html.erb b/app/views/users/user_organizations.html.erb
index ed8238169..e9709f766 100644
--- a/app/views/users/user_organizations.html.erb
+++ b/app/views/users/user_organizations.html.erb
@@ -22,7 +22,11 @@
- <%= link_to org.name, organization_path(org), :class => 'f16 linkBlue' %>
+ <% if org.domain.nil? %>
+ <%= link_to org.name, organization_path(org), :class => 'f16 linkBlue' %>
+ <% else %>
+
<%= org.name %>
+ <% end %>
<%= org.description %>
创建者:<%= link_to User.find(org.creator_id), user_path(org.creator_id), :class => 'linkGrey2', :target => '_blank' %>
diff --git a/config/routes.rb b/config/routes.rb
index 2d195f0d2..543cd1645 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -47,12 +47,14 @@ RedmineApp::Application.routes.draw do
post 'join_project_menu'
post 'join_projects'
post 'logout'
+ post 'apply_subdomain'
end
collection do
get 'check_uniq'
get 'autocomplete_search'
post 'hide_org_subfield'
post 'show_org_subfield'
+ post 'agree_apply_subdomain'
end
resources :org_document_comments do
member do
@@ -64,6 +66,9 @@ RedmineApp::Application.routes.draw do
end
end
+ Organization.where("domain is not null").each do |org|
+ get '/', to: 'organizations#show', defaults: { id: org.id }, constraints: {subdomain: org.domain}
+ end
get '/', to: 'organizations#show', defaults: { id: 5 }, constraints: {subdomain: 'micros'}
get '/', to: 'organizations#show', defaults: { id: 23 }, constraints: {subdomain: 'nubot'}
diff --git a/db/migrate/20160105014033_create_org_messages.rb b/db/migrate/20160105014033_create_org_messages.rb
new file mode 100644
index 000000000..9ea18ccb0
--- /dev/null
+++ b/db/migrate/20160105014033_create_org_messages.rb
@@ -0,0 +1,19 @@
+class CreateOrgMessages < ActiveRecord::Migration
+ def up
+ create_table :org_messages do |t|
+ t.integer :user_id
+ t.integer :sender_id
+ t.integer :organization_id
+ t.string :message_type
+ t.integer :message_id
+ t.integer :viewed
+ t.string :content
+
+ t.timestamps
+ end
+ end
+
+ def down
+ drop_table :org_messages
+ end
+end