帖子的编辑与删除

guange_homework
lizanle 10 years ago
parent c8d07dedf6
commit b9ff46f8d0

@ -143,7 +143,12 @@ class MemosController < ApplicationController
end end
def edit def edit
@my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count
@my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count
@replying = false @replying = false
respond_to do |format|
format.html {render :layout=>'base_forums'}
end
end end
def update def update

@ -61,7 +61,7 @@
n += 1;//英文,不多说了 n += 1;//英文,不多说了
} }
} }
if(n >= 160) if(n >= 160 && event.keyCode != 8)
event.returnValue = false; event.returnValue = false;
} }
}); });

@ -35,13 +35,13 @@
<div class="cl"></div> <div class="cl"></div>
<% end %> <% end %>
<% if attachment.is_text? %> <%# if attachment.is_text? %>
<%= link_to image_tag('magnifier.png'), <%#= link_to image_tag('magnifier.png'),
:controller => 'attachments', :controller => 'attachments',
:action => 'show', :action => 'show',
:id => attachment, :id => attachment,
:filename => attachment.filename%> :filename => attachment.filename%>
<% end %> <%# end %>
<!--<span title="<%#= attachment.description%>">--> <!--<span title="<%#= attachment.description%>">-->
<!--<%#= h(truncate(" - #{attachment.description}", length: options[:length] ? options[:length]:15, omission: '...')) unless attachment.description.blank? %>--> <!--<%#= h(truncate(" - #{attachment.description}", length: options[:length] ? options[:length]:15, omission: '...')) unless attachment.description.blank? %>-->
<!--</span>--> <!--</span>-->

@ -1,55 +1,47 @@
<!-- <h1>New memo</h1> --> <%= javascript_include_tag 'new_user'%>
<% @replying = !@memo.parent.nil? %> <script>
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %> $(function(){
<h3><%=l(:label_memo_edit)%></h3> limitStrsize('memo_subject',50);
<%= labelled_form_for(@memo, :url => forum_memo_path(@memo.forum_id, @memo)) do |f| %> limitStrsize('memo_content',5000);
<% if @memo.errors.any? %> });
<div id="error_explanation"> function check_and_submit(){
<h2> if($("textarea[name='memo[subject]']").val().trim() != "" && $("textarea[name='memo[content]']").val().trim() != "" ){
<%= pluralize(@memo.errors.count, "error") %> $("#edit_memo").submit();
prohibited this memo from being saved: }else if($("textarea[name='memo[subject]']").val().trim() == "" && $("textarea[name='memo[content]']").val().trim() != "" ){
</h2> $("#error").html("主题不能为空").show();
<ul> }else if($("textarea[name='memo[subject]']").val().trim() != "" && $("textarea[name='memo[content]']").val().trim() == ""){
<% @memo.errors.full_messages.each do |msg| %> $("#error").html("内容不能为空").show();
<li> }
<%= msg %> }
</li> </script>
<% end %> <div class="homepageRightBanner mt15">
</ul> <div class="NewsBannerName">编辑帖子</div>
</div> </div>
<% end %> <div class="postRightContainer" style="margin-top: 15px">
<div class="actions"> <%= labelled_form_for(@memo, :url => forum_memo_path(@memo.forum_id, @memo),:html=>{:id=>'edit_memo'}) do |f| %>
<p> <div id="error" style="display: none">
<% if @memo.parent.nil? && @memo.children.first.nil? %>
<%#= f.text_field :subject, :required => true, :size => 96 ,:readonly => false, :maxlength => 50%> </div>
<% else %> <div>
<%#= f.text_field :subject, :required => true, :size => 96 ,:readonly => true, :style => "border: 1px solid gray", :maxlength => 50%> <textarea type="text" id="memo_subject" name="memo[subject]" class="postDetailInput" placeholder="对应帖子标题" ><%= @memo.subject%></textarea>
<% end %> <script>
</p> var ta = document.getElementById('memo_subject')
<% if User.current.admin?%> autoTextarea(ta)
<p> </script>
<% unless @replying %> </div>
<% if @memo.safe_attribute? 'sticky' %> <div class="mt15">
<%= f.check_box :sticky %> <textarea type="text" id="memo_content" name="memo[content]" class="postDetailInput" placeholder="对应帖子内容" ><%= @memo.content.html_safe%></textarea>
<%= label_tag 'memo_sticky', l(:label_board_sticky) %> <script>
<% end %> var ta1 = document.getElementById('memo_content')
<% if @memo.safe_attribute? 'lock' %> autoTextarea(ta1)
<%= f.check_box :lock %> <%= label_tag 'memo_locked', l(:label_board_locked) %> </script>
<% end %> </div>
<% end %> <div class="mt10">
</p> <!--<a href="javascript:void(0);" class="AnnexBtn fl mt3">对应附件名称</a>-->
<% end %> <%= render :partial => 'forums/file_form', :locals => {:container => @memo} %>
<p> <div class="fr"><a href="javascript:void(0);" class="submit_btn" onclick="check_and_submit();">确定</a></div>
<%= f.kindeditor :content, :required => true, :size => 80,:owner_id => @memo.id,:owner_type => 1 %> <div class="fr"><a href="<%= forum_memo_path(@memo.forum,@memo)%>" class="linkGrey2 mr10">取消</a><span class="mr10 fontGrey">或</span></div>
</p>
<!-- <script type="text/javascript">var ckeditor=CKEDITOR.replace('editor01');</script> -->
<p style="float: left;margin-top: 5px;">
<%= l(:label_attachment_plural) %>
<br />
<%= render :partial => 'attachments/form', :locals => {:container => @memo} %>
</p>
<br/>
<div class="cl"></div> <div class="cl"></div>
<%= f.submit :value => l(:button_change) %>&nbsp;&nbsp;<%= link_to l(:button_back), back_url ,:class => "button-canel",:style => "color: #ffffff;"%>
</div> </div>
<% end %> <% end %>
</div>

@ -24,8 +24,8 @@
<ul> <ul>
<li class="homepagePostSettingIcon"> <li class="homepagePostSettingIcon">
<ul class="homepagePostSettiongText"> <ul class="homepagePostSettiongText">
<li><a href="javascript:void(0);" class="postOptionLink">编辑</a></li> <li><a href="<%= edit_forum_memo_path(@memo.forum,@memo)%>" class="postOptionLink">编辑</a></li>
<li><a href="javascript:void(0);" class="postOptionLink">删除</a></li> <li><a href="<%= forum_memo_path(@memo.forum,@memo) %>" data-method="delete" class="postOptionLink">删除</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>

@ -250,3 +250,22 @@ var autoTextarea = function (elem, extra, maxHeight) {
addEvent('focus', change); addEvent('focus', change);
change(); change();
}; };
function limitStrsize(id,length){
document.getElementById(id).onkeydown = function()
{
var n = 0;
var str = this.value;
for (i = 0; i < str.length; i++) {
var leg = str.charCodeAt(i);//ASCII码
if (leg > 255) {//大于255的都是中文
n += 2;//如果是中文就是2个字节
} else {
n += 1;//英文,不多说了
}
}
if(n >= length && event.keyCode !== 8)
event.returnValue = false;
}
}

@ -55,7 +55,7 @@ a.homepageMenuText {color:#484848; font-size:16px; margin-left:20px;}
.homepageLeftLabelContainer {width:238px; border:1px solid #dddddd; background-color:#ffffff; margin-top:10px;} .homepageLeftLabelContainer {width:238px; border:1px solid #dddddd; background-color:#ffffff; margin-top:10px;}
.homepageLabelText {color:#484848; font-size:16px; margin-left:10px; margin-bottom:12px; display:block;} .homepageLabelText {color:#484848; font-size:16px; margin-left:10px; margin-bottom:12px; display:block;}
.homepageRightBanner {width:720px; height:34px; margin:0px auto; border-bottom:1px solid #e9e9e9;} .homepageRightBanner {width:720px; height:34px; margin:0px auto; border-bottom:1px solid #e9e9e9;}
.NewsBannerName {font-size:16px; color:#4b4b4b; display:block; background:url(../images/homepage_icon.png) -18px -230px no-repeat; width:150px; float:left; padding-left:15px; margin-top:4px;} .NewsBannerName {font-size:16px; color:#4b4b4b; display:block; width:150px; float:left; margin-top:4px;}
.newsType {width:60px; background-color:#ffffff; float:left; list-style:none; position:absolute; border:1px solid #eaeaea; border-radius:5px; top:15px; padding:5px 10px; left:-40px; font-size:12px; color:#888888; display:none; line-height:2; z-index:9999;} .newsType {width:60px; background-color:#ffffff; float:left; list-style:none; position:absolute; border:1px solid #eaeaea; border-radius:5px; top:15px; padding:5px 10px; left:-40px; font-size:12px; color:#888888; display:none; line-height:2; z-index:9999;}
.newsReadSetting {width:700px; background-color:#f6f6f6; border-bottom:1px solid #eeeeee; margin:10px auto; height:39px; line-height:39px; vertical-align:middle; font-size:14px; color:#7a7a7a; padding-left:10px;} .newsReadSetting {width:700px; background-color:#f6f6f6; border-bottom:1px solid #eeeeee; margin:10px auto; height:39px; line-height:39px; vertical-align:middle; font-size:14px; color:#7a7a7a; padding-left:10px;}
.homepageNewsList {width:710px; height:49px; line-height:49px; vertical-align:middle; border-bottom:1px dashed #eaeaea; margin-left:10px;} .homepageNewsList {width:710px; height:49px; line-height:49px; vertical-align:middle; border-bottom:1px dashed #eaeaea; margin-left:10px;}

@ -534,7 +534,7 @@ a.sendButtonBlue:hover {color:#ffffff;}
outline:none; outline:none;
} }
.homepageRightBanner {width:720px; height:34px; margin:0px auto; border-bottom:1px solid #e9e9e9;} .homepageRightBanner {width:720px; height:34px; margin:0px auto; border-bottom:1px solid #e9e9e9;}
.NewsBannerName {font-size:16px; color:#4b4b4b; display:block; background:url(images/homepage_icon.png) -18px -230px no-repeat; width:150px; float:left; padding-left:15px; margin-top:4px;} .NewsBannerName {font-size:16px; color:#4b4b4b; display:block; width:150px; float:left; margin-top:4px;}
a.resourcesTypeAll {background:url(images/homepage_icon.png) -180px -89px no-repeat; padding-left:23px;} a.resourcesTypeAll {background:url(images/homepage_icon.png) -180px -89px no-repeat; padding-left:23px;}
a.resourcesTypeAtt {background:url(images/homepage_icon.png) -180px -49px no-repeat; padding-left:23px;} a.resourcesTypeAtt {background:url(images/homepage_icon.png) -180px -49px no-repeat; padding-left:23px;}
.resourcesType {width:75px; background-color:#ffffff; float:left; list-style:none; position:absolute; border:1px solid #eaeaea; border-radius:5px; top:15px; padding:10px 20px; left:-90px; font-size:12px; color:#888888; display:none; line-height:2;} .resourcesType {width:75px; background-color:#ffffff; float:left; list-style:none; position:absolute; border:1px solid #eaeaea; border-radius:5px; top:15px; padding:10px 20px; left:-90px; font-size:12px; color:#888888; display:none; line-height:2;}

Loading…
Cancel
Save