增加学校logo的上传功能,以及实时预览效果
This commit is contained in:
parent
19c515e11e
commit
6091369e02
|
@ -340,9 +340,9 @@ class AdminController < ApplicationController
|
|||
|
||||
#学校列表
|
||||
def schools
|
||||
@q = params[:school_name]
|
||||
if @q
|
||||
@schools = School.where("name like '%#{@q}%'")
|
||||
@school_name = params[:school_name]
|
||||
if @school_name
|
||||
@schools = School.where("name like '%#{@school_name}%'")
|
||||
else
|
||||
@schools = School.all
|
||||
end
|
||||
|
|
|
@ -4,28 +4,21 @@ class SchoolController < ApplicationController
|
|||
|
||||
def upload
|
||||
uploaded_io = params[:logo]
|
||||
school_id = 0
|
||||
schools = School.where("name = ?", params[:school])
|
||||
|
||||
schools.each do |s|
|
||||
school_id = s.id
|
||||
end
|
||||
|
||||
school_id ||= params[:id]
|
||||
unless uploaded_io.nil?
|
||||
File.open(Rails.root.join('public', 'images', 'school', school_id.to_s+'.png'), 'wb') do |file|
|
||||
file.write(uploaded_io.read)
|
||||
end
|
||||
|
||||
s1 = School.find(school_id)
|
||||
s1.logo_link = '/images/school/'+school_id.to_s+'.png'
|
||||
s1.save
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
redirect_to admin_schools_url(:school_name => params[:school_name])
|
||||
end
|
||||
|
||||
def upload_logo
|
||||
|
||||
@school = School.find params[:id]
|
||||
@school_name = params[:school_name]
|
||||
end
|
||||
|
||||
#获取制定学校开设的课程数
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
</h3>
|
||||
<%= form_tag({:controller => 'admin', :action => 'schools' }, :method => :get,:id=>"search_course_form") do %>
|
||||
<%= submit_tag "搜索",:style => "float: right;margin-right: 15px;"%>
|
||||
<input style="float: right;margin-right: 10px;" id="v_subject" placeholder="学校名称" type="text" name="school_name" value="<%= @q%>">
|
||||
<input style="float: right;margin-right: 10px;" id="v_subject" placeholder="学校名称" type="text" name="school_name" value="<%= @school_name%>">
|
||||
<% end %>
|
||||
<div class="cl"></div>
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
|||
</span>
|
||||
</td>
|
||||
<td class="buttons" style="vertical-align: middle;">
|
||||
<%= link_to("上传logo", edit_organization_path(school.id), :class => 'icon icon-copy') %>
|
||||
<%= link_to("修改", upload_logo_school_path(school.id,:school_name => @school_name), :class => 'icon icon-copy') %>
|
||||
<%#= link_to(l(:button_delete), organization_path(school.id), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -1,5 +1,28 @@
|
|||
<%= form_tag({action: :upload},method: "post", multipart: true) do %>
|
||||
<%= text_field_tag 'school'%>
|
||||
<%= file_field_tag 'logo' %>
|
||||
<%= submit_tag('Upload') %>
|
||||
<script>
|
||||
function showPreview(source) {
|
||||
var file = source.files[0];
|
||||
if(window.FileReader) {
|
||||
var fr = new FileReader();
|
||||
fr.onloadend = function(e) {
|
||||
document.getElementById("avatar_image").src = e.target.result;
|
||||
};
|
||||
fr.readAsDataURL(file);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<%= form_tag(upload_school_path(@school.id),method: "post", multipart: true) do %>
|
||||
<%#= text_field_tag 'school'%>
|
||||
<div style="margin: 20px;">
|
||||
<input type="hidden" value="<%= @school_name%>" name="school_name">
|
||||
<%= image_tag(@school.logo_link, id: "avatar_image", :class=>"school_avatar")%>
|
||||
<a type="button" onclick="$('#file').click();" style="margin: 90px 0 0 10px;float: left;padding: 2px 5px;border: 1px solid #eaeaea;cursor: pointer;text-decoration: none;width: 55px;">上传图片</a>
|
||||
<%= file_field_tag 'logo',:style => "display:none;", :id => "file", :onchange => "showPreview(this)"%>
|
||||
<div style="clear: both;"></div>
|
||||
<div style="margin-top: 10px;">
|
||||
<%= submit_tag('上传') %>
|
||||
<%= submit_tag('取消') %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -39,6 +39,17 @@ RedmineApp::Application.routes.draw do
|
|||
|
||||
end
|
||||
|
||||
resources :school do
|
||||
collection do
|
||||
|
||||
end
|
||||
|
||||
member do
|
||||
get 'upload_logo'
|
||||
post 'upload'
|
||||
end
|
||||
end
|
||||
|
||||
resources :homework_attach do
|
||||
collection do
|
||||
get 'get_homework_member_list'
|
||||
|
@ -809,9 +820,6 @@ RedmineApp::Application.routes.draw do
|
|||
post 'school/search_school/', :to => 'school#search_school'
|
||||
get 'school/search_school/', :to => 'school#search_school'
|
||||
|
||||
post 'school/upload', :to => 'school#upload'
|
||||
get 'school/upload_logo', :to => 'school#upload_logo'
|
||||
|
||||
######added by nie
|
||||
match 'tags/show_projects_tags'
|
||||
########### added by liuping
|
||||
|
|
|
@ -2796,4 +2796,15 @@ div.repos_explain{
|
|||
.upload_img img{max-width: 100%;}
|
||||
#activity .upload_img img{max-width: 580px;}
|
||||
|
||||
img,embed{max-width: 100%;}
|
||||
img,embed{max-width: 100%;}
|
||||
|
||||
img.school_avatar {
|
||||
background: rgb(245, 245, 245);
|
||||
padding: 4px;
|
||||
border: 1px solid #e5dfc7;
|
||||
float: left;
|
||||
display: block;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
max-width: none;
|
||||
}
|
Loading…
Reference in New Issue