diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 1b328ad7e..c63cf8c7f 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -238,23 +238,12 @@ class OrganizationsController < ApplicationController if @type.nil? @containers = Course.find_by_sql("SELECT * FROM `courses` where is_delete = 0 and is_public = 1 and name like '%#{q}%' order by updated_at desc;") elsif @type == "famous" - @containers = Course.find_by_sql("SELECT * FROM `courses` where is_delete = 0 and is_public = 1 and hot = 1 and name like '%#{q}%' order by updated_at desc;") + @containers = Course.find_by_sql("SELECT * FROM `courses` where is_delete = 0 and is_public = 1 and is_excellent = 1 and name like '%#{q}%' order by updated_at desc;") end atta_page_public @containers end def acts - q = params[:search].nil? ? "" : "#{params[:search].strip}" - @field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Compstu").first : OrgSubfield.find(params[:org_subfield_id]) - @type = params[:type] - if @type == "courses" || @type.nil? - @org_students = User.find_by_sql("select u.*, ue.student_id, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count - from users u, user_extensions ue where u.id = ue.user_id and ue.identity= 1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") - elsif @type == "famous" - @org_students = User.find_by_sql("select u.*, ue.student_id, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count - from users u, user_extensions ue where u.id = ue.user_id and ue.identity= 1 and u.excellent_student =1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc") - end - atta_page_public container @containers end def searchmember_by_name members, name @@ -543,6 +532,18 @@ class OrganizationsController < ApplicationController end end + def update_field_by_admin + @type = params[:type] + @status = params[:status] + if @type == "project" + @container = Project.find(params[:container]) + @status == "reset" ? @container.update_column(:hot, 0) : @container.update_column(:hot, 1) + else + @container = Course.find(params[:container]) + @status == "reset" ? @container.update_column(:is_excellent, 0) : @container.update_column(:is_excellent, 1) + end + end + # 设置为名师 def set_excellent_teacher @ex_teacher = User.find(params[:user]) diff --git a/app/views/organizations/_org_container.html.erb b/app/views/organizations/_org_container.html.erb index 42c216879..59ac4d95c 100644 --- a/app/views/organizations/_org_container.html.erb +++ b/app/views/organizations/_org_container.html.erb @@ -16,24 +16,9 @@
资源
- - <%= (container.class == Course ? container.is_excellent == 0 : container.hot ==0) ? "设为热门" : "取消设置" %> + <%= container.class == Course ? (container.is_excellent == 0 ? "设为精品" : "取消精品") : (container.hot ==0 ? "设为热门" : "取消热门") %>
<% end %> - \ No newline at end of file diff --git a/app/views/organizations/update_field_by_admin.js.erb b/app/views/organizations/update_field_by_admin.js.erb new file mode 100644 index 000000000..ba218c746 --- /dev/null +++ b/app/views/organizations/update_field_by_admin.js.erb @@ -0,0 +1,5 @@ +<% if @type == "course" %> +$("#hide_<%= @container.id %>").text("<%= (@status == 'reset' ? '设为精品' : '取消精品') %>"); +<% elsif @type == "project" %> +$("#hide_<%= @container.id %>").text("<%= (@status == 'reset' ? '设为热门' : '取消热门') %>"); +<% end %> diff --git a/public/javascripts/org.js b/public/javascripts/org.js index 05ae5e717..a2b2bd361 100644 --- a/public/javascripts/org.js +++ b/public/javascripts/org.js @@ -112,19 +112,28 @@ function chooseTeacherType(org_id){ //修改状态 function admin_hide_org(content, id){ - if (content.text() == '设为热门') + if (content.text() == '设为热门'){ $.ajax({ - url: "/organizations/update_field_by_admin?user=" + id + "&type=project", + url: "/organizations/update_field_by_admin?container=" + id + "&type=project", type: "post" }); - else if (content.text() == '设为精品') + } + else if (content.text() == '设为精品'){ $.ajax({ - url: "/organizations/update_field_by_admin?user=" + id + "&type=course", + url: "/organizations/update_field_by_admin?container=" + id + "&type=course", type: "post" }); - else if (content.text() == '取消设置') + } + else if (content.text() == '取消热门'){ $.ajax({ - url: "/organizations/reset_update_field_by_admin?user=" + id + "&type=student", + url: "/organizations/update_field_by_admin?container=" + id + "&type=project" + "&status=reset", type: "post" }); + } + else if (content.text() == '取消精品'){ + $.ajax({ + url: "/organizations/update_field_by_admin?container=" + id + "&type=course" + "&status=reset", + type: "post" + }); + } } \ No newline at end of file