ADD edit and delete dynamic_news
This commit is contained in:
parent
418975c21e
commit
b4cc5883bd
|
@ -1,14 +1,14 @@
|
|||
class DynamicNewsController < ApplicationController
|
||||
layout 'admin', only: [:new, :index, :destroy]
|
||||
layout 'admin', only: [:new, :destroy, :edit]
|
||||
|
||||
before_filter :require_admin, :only => [:new, :create, :destroy]
|
||||
before_filter :find_dynamic_new, :only => [:show, :destroy]
|
||||
before_filter :require_admin, :except => [:index, :show]
|
||||
before_filter :find_dynamic_new, :only => [:destroy, :edit, :update]
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def new
|
||||
@category_id = params[:category_id] || 0
|
||||
@dynamic_new = DynamicNew.new
|
||||
end
|
||||
|
||||
|
@ -16,20 +16,22 @@ class DynamicNewsController < ApplicationController
|
|||
tmp_file = params[:cover]
|
||||
@dynamic_new = DynamicNew.new(params[:dynamic_new])
|
||||
begin
|
||||
ActiveRecord::Base.transaction do
|
||||
identity = SecureRandom.uuid
|
||||
unless tmp_file.nil?
|
||||
File.open(Rails.root.join('public', 'images', 'dynamic_new', identity.to_s+'.png'), 'wb') do |file|
|
||||
file.write(tmp_file.read)
|
||||
end
|
||||
@dynamic_new.cover_remote_url = "/images/dynamic_new/#{identity}.png"
|
||||
identity = SecureRandom.uuid
|
||||
unless tmp_file.nil?
|
||||
File.open(Rails.root.join('public', 'images', 'dynamic_new', identity.to_s+'.png'), 'wb') do |file|
|
||||
file.write(tmp_file.read)
|
||||
end
|
||||
# TODO: 如下警告信息导致值写不进库
|
||||
# WARNING: Can't mass-assign protected attributes: simple_intruduce,
|
||||
@dynamic_new.simple_intruduce = params[:dynamic_new][:simple_intruduce]
|
||||
@dynamic_new.save
|
||||
@dynamic_new.cover_remote_url = "/images/dynamic_new/#{identity}.png"
|
||||
end
|
||||
redirect_to admin_dynamic_news_path
|
||||
# TODO: 如下警告信息导致值写不进库
|
||||
# WARNING: Can't mass-assign protected attributes: simple_intruduce,
|
||||
@dynamic_new.simple_intruduce = params[:dynamic_new][:simple_intruduce]
|
||||
if @dynamic_new.save!
|
||||
redirect_to admin_dynamic_news_path
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
|
||||
rescue => e
|
||||
logger.info e
|
||||
render 'new'
|
||||
|
@ -41,6 +43,14 @@ class DynamicNewsController < ApplicationController
|
|||
redirect_to admin_dynamic_news_path
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@dynamic_new.update_attributes!(params[:dynamic_new])
|
||||
redirect_to admin_dynamic_news_path
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
|
|
|
@ -54,8 +54,8 @@
|
|||
<%= format_time(dynamic_new.created_at) %>
|
||||
</td>
|
||||
<td class="buttons" style="vertical-align: middle;text-align:center">
|
||||
<%= link_to("修改", upload_logo_school_path(dynamic_new.id,:school_name => @school_name), :class => 'icon icon-copy') %>
|
||||
<%= link_to(l(:button_delete), dynamic_news_path(dynamic_new), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
|
||||
<%= link_to("修改", edit_dynamic_news_path(dynamic_new), :class => 'icon icon-copy') %>
|
||||
<%= link_to(l(:button_delete), dynamic_news_path(dynamic_new), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
@ -64,12 +64,3 @@
|
|||
<div class="pagination">
|
||||
<%= pagination_links_full @obj_pages, @obj_count ,:per_page_links => true, :remote => true, :flag => true, :is_new => true %>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
function delcfm() {
|
||||
if (!confirm("删除项目会一并删除项目的关联信息,确认要删除吗?")) {
|
||||
window.event.returnValue = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<%= form_for(@dynamic_new, :url=> { :action => params[:action] == 'new'? :create : :update }, :html => {:id =>'system_messages-form',:multipart => true }) do |f| %>
|
||||
<li>
|
||||
<%= image_tag(params[:action] == 'new' ? '' : @dynamic_new.cover_url, id: "avatar_image", :class=>"school_avatar dynamic_new_image" )%>
|
||||
<a type="button" onclick="$('#file').click();" style="margin: 86px 0 0 15px;float: left;padding: 2px 5px;border: 1px solid #eaeaea;cursor: pointer;text-decoration: none;width: 55px;">上传封面</a>
|
||||
<%= file_field_tag 'cover',:style => "display:none;", :id => "file", :onchange => "showPreview(this)"%>
|
||||
<div style="clear: both;"></div>
|
||||
</li>
|
||||
<li>
|
||||
<label><span class="">*</span> <%= l(:field_category) %> :</label>
|
||||
<%= f.select :category_id, options_for_select(Category.all.collect{|item| [item.name, item.id]}, @category_id), :class => "small" %>
|
||||
<p id="title_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label><span class="">*</span> <%= l(:field_title) %> :</label>
|
||||
<input type="text" name="dynamic_new[title]" class="hwork_input_news" id="dynamic_new_title" width="576px" onblur="regexTitle($(this));" maxlength="255" placeholder="255个字符以内" value="<%= @dynamic_new.title %>">
|
||||
<p id="title_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<li>
|
||||
<label><span class="">*</span> <%= l(:field_summary) %> :</label>
|
||||
<input type="textarea" name="dynamic_new[simple_intruduce]" class="hwork_input_news" id="dynamic_new_simple_introduce" width="576px" onblur="regexTitle($(this));" maxlength="255" placeholder="255个字符以内" value="<%= @dynamic_new.simple_intruduce %>">
|
||||
<p id="title_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<li>
|
||||
<label class="fl" > <span class="c_red"></span> <%= l(:field_content) %> :</label>
|
||||
<%= f.kindeditor :content,:width=>'87.5%',:editor_id=>'dynamic_new_editor' %>
|
||||
<p id="content_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<div>
|
||||
<p id="content_notice_span" class="ml55"></p>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="actions">
|
||||
<%= link_to l(:label_submit), "javascript:void(0)", :class => "btn_message_free", :onclick => "dynamic_new_editor.sync();submit_message($(this));" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<script>
|
||||
function system_message_length() {
|
||||
var obj = dynamic_new_editor.html();
|
||||
if (obj.length > 10000) {
|
||||
$("#content_notice_span").text("内容过长,超过10000个字符");
|
||||
$("#content_notice_span").css('color', '#ff0000');
|
||||
$("#content_notice_span").focus();
|
||||
return false;
|
||||
} else {
|
||||
$("#content_notice_span").text("填写正确");
|
||||
$("#content_notice_span").css('color', '#008000');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function regexTitle(obj) {
|
||||
var title = obj.val();
|
||||
if (title.length == 0) {
|
||||
$("#title_notice_span").text("标题不能为空").css("color", "#ff0000").focus();
|
||||
return false;
|
||||
} else if (title.length > 255) {
|
||||
$("#title_notice_span").text("标题长度过长,不能超过255个字符").css("color", "#ff0000").focus();
|
||||
return false;
|
||||
} else {
|
||||
$("#title_notice_span").text("填写正确").css("color", "#008000");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function submit_message(dom) {
|
||||
if (system_message_length() && regexTitle($("#dynamic_new_title")) && regexTitle($("#dynamic_new_simple_introduce"))) {
|
||||
$("#system_messages-form").submit();
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,23 @@
|
|||
<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>
|
||||
|
||||
<%= content_for(:header_tags) do %>
|
||||
<%= import_ke(enable_at: false) %>
|
||||
<% end %>
|
||||
<h3 style="float: left">
|
||||
<%=l(:label_new_dynamic_new)%>
|
||||
</h3><br/>
|
||||
<div style="padding-top: 20px; padding-left: 5px;">
|
||||
<%= error_messages_for 'dynamic_new' %>
|
||||
<%= render 'form' %>
|
||||
</div>
|
|
@ -18,70 +18,5 @@
|
|||
<%=l(:label_new_dynamic_new)%>
|
||||
</h3><br/>
|
||||
<div style="padding-top: 20px; padding-left: 5px;">
|
||||
<%= form_for(@dynamic_new, :url=> { :action => :create }, :html => {:id =>'system_messages-form',:multipart => true }) do |f| %>
|
||||
<li>
|
||||
<input type="hidden" value="<%= @school_name%>" name="school_name">
|
||||
<%= image_tag('', id: "avatar_image", :class=>"school_avatar dynamic_new_image" )%>
|
||||
<a type="button" onclick="$('#file').click();" style="margin: 86px 0 0 15px;float: left;padding: 2px 5px;border: 1px solid #eaeaea;cursor: pointer;text-decoration: none;width: 55px;">上传图片</a>
|
||||
<%= file_field_tag 'cover',:style => "display:none;", :id => "file", :onchange => "showPreview(this)"%>
|
||||
<div style="clear: both;"></div>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
<label><span class="">*</span> <%= l(:field_title) %> :</label>
|
||||
<input type="text" name="dynamic_new[title]" class="hwork_input_news" id="system_message_subject" width="576px" onblur="regexTitle($(this));" maxlength="255" placeholder="255个字符以内" value="">
|
||||
<p id="title_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<li>
|
||||
<label><span class="">*</span> <%= l(:field_summary) %> :</label>
|
||||
<input type="textarea" name="dynamic_new[simple_intruduce]" class="hwork_input_news" id="system_message_subject" width="576px" onblur="regexTitle($(this));" maxlength="255" placeholder="255个字符以内" value="">
|
||||
<p id="title_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<li>
|
||||
<label class="fl" > <span class="c_red"></span> <%= l(:field_content) %> :</label>
|
||||
<%= f.kindeditor :content,:width=>'87.5%',:editor_id=>'system_message_editor' %>
|
||||
<p id="content_notice_span" class="ml55"></p>
|
||||
</li>
|
||||
<div>
|
||||
<p id="content_notice_span" class="ml55"></p>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="actions">
|
||||
<%= link_to l(:label_submit), "javascript:void(0)", :class => "btn_message_free", :onclick => "system_message_editor.sync();submit_message($(this));" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= render 'form' %>
|
||||
</div>
|
||||
<script>
|
||||
function system_message_length() {
|
||||
var obj = system_message_editor.html();
|
||||
if (obj.length > 10000) {
|
||||
$("#content_notice_span").text("内容过长,超过10000个字符");
|
||||
$("#content_notice_span").css('color', '#ff0000');
|
||||
$("#content_notice_span").focus();
|
||||
return false;
|
||||
} else {
|
||||
$("#content_notice_span").text("填写正确");
|
||||
$("#content_notice_span").css('color', '#008000');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function regexTitle(obj) {
|
||||
var title = obj.val();
|
||||
if (title.length == 0) {
|
||||
$("#title_notice_span").text("标题不能为空").css("color", "#ff0000").focus();
|
||||
return false;
|
||||
} else if (title.length > 255) {
|
||||
$("#title_notice_span").text("标题长度过长,不能超过255个字符").css("color", "#ff0000").focus();
|
||||
return false;
|
||||
} else {
|
||||
$("#title_notice_span").text("填写正确").css("color", "#008000");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function submit_message(dom) {
|
||||
|
||||
if (system_message_length() && regexTitle($("#system_message_subject"))) {
|
||||
$("#system_messages-form").submit();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue