项目留言换编辑器

This commit is contained in:
yutao 2015-06-11 17:31:47 +08:00
parent 9c0454d4fa
commit e99206ff4a
4 changed files with 181 additions and 9 deletions

View File

@ -21,7 +21,7 @@
<% end %> <% end %>
<% if reply_allow %> <% if reply_allow %>
<%= link_to l(:label_bid_respond_quote),'', <%= link_to l(:label_bid_respond_quote),'',
{:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea')); $('##{ids} textarea') ;return false;"} %> {:focus => 'project_respond',:nhname=>"reply_btn", :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea')); $('##{ids} textarea') ;return false;"} %>
<% end %> <% end %>
</span> </span>

View File

@ -1,4 +1,18 @@
<div class="msg_box" id='leave-message'> <style type="text/css">
div.ke-toolbar{display:none;width:400px;border:none;background:none;padding:0px 0px;}
span.ke-toolbar-icon{line-height:26px;font-size:14px;padding-left:26px;}
span.ke-toolbar-icon-url{background-image:url( /images/public_icon.png )}
div.ke-toolbar .ke-outline{padding:0px 0px;line-height:26px;font-size:14px;}
span.ke-icon-emoticons{background-position:0px -671px;width:50px;height:26px;}
span.ke-icon-emoticons:hover{background-position:-79px -671px;width:50px;height:26px;}
div.ke-toolbar .ke-outline{border:none;}
div.respond-form .reply_btn{margin-left:565px;margin-top:5px;}
div.recall_con{width:600px;}
div.recall_con .reply_btn{margin-left:555px;margin-top:5px;}
</style>
<%= javascript_include_tag "/assets/kindeditor/kindeditor" %>
<div class="msg_box" id='leave-message' nhname='new_message' style="height:auto;">
<% reply_allow = JournalsForMessage.create_by_user? User.current %> <% reply_allow = JournalsForMessage.create_by_user? User.current %>
<h4><%= l(:label_user_response) %></h4> <h4><%= l(:label_user_response) %></h4>
<% if !User.current.logged?%> <% if !User.current.logged?%>
@ -12,8 +26,10 @@
<%= form_for('new_form', :method => :post, <%= form_for('new_form', :method => :post,
:url => {:controller => 'words', :action => 'leave_project_message'}) do |f|%> :url => {:controller => 'words', :action => 'leave_project_message'}) do |f|%>
<%= f.text_area 'project_message', :rows => 3, :cols => 65, <%= f.text_area 'project_message', :rows => 3, :cols => 65,
:placeholder => "#{l(:label_welcome_my_respond)}" %> :placeholder => "#{l(:label_welcome_my_respond)}",:nhname=>'new_message_textarea' %>
<%= submit_tag l(:button_leave_meassge), :name => nil , :class => "blue_btn fr" %> <p nhname="contentmsg"></p>
<div class="fl mt10" style="padding-top:5px;" nhname="toolbar_container"></div>
<%= submit_tag l(:button_leave_meassge), :name => nil , :class => "blue_btn fr mt10 mb10" %>
<% end %> <% end %>
<% end %> <% end %>
@ -24,3 +40,155 @@
</div> </div>
<ul class="wlist"><%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%></ul> <ul class="wlist"><%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%></ul>
<div style="display:none;"><a href="#" id="nhjump"></a></div>
<script type="text/javascript">
$(function(){
function init_editor(params){
var editor = params.kindutil.create(params.textarea, {
resizeType : 1,minWidth:"1px",width:"100%",height:"150px",
items:['emoticons'],
afterChange:function(){//按键事件
nh_check_field({content:this,contentmsg:params.contentmsg,textarea:params.textarea});
},
afterCreate:function(){
var toolbar = $("div[class='ke-toolbar']",params.div_form);
$(".ke-outline>.ke-toolbar-icon",toolbar).append('表情');
params.toolbar_container.append(toolbar);
}
}).loadPlugin('paste');
return editor;
}
function nh_check_field(params){
var result=true;
if(params.content!=undefined){
if(params.content.isEmpty()){
result=false;
}
if(params.content.html()!=params.textarea.html() || params.issubmit==true){
params.textarea.html(params.content.html());
params.content.sync();
if(params.content.isEmpty()){
params.contentmsg.html('内容不能为空');
params.contentmsg.css({color:'#ff0000'});
}else{
params.contentmsg.html('填写正确');
params.contentmsg.css({color:'#008000'});
}
params.contentmsg.show();
}
}
return result;
}
function init_form(params){
// var flag = false;
// if(params.form.attr('data-remote') != undefined ){
// flag = true
// }
// params.form[0].onsubmit = function(){
// if(flag){
// $(this).removeAttr('data-remote');//不这么搞return false没用 花擦花擦
// }
// var is_checked = nh_check_field({
// issubmit:true,
// content:params.editor,
// contentmsg:params.contentmsg,
// textarea:params.textarea
// });
// if(is_checked){
// if(flag){
// alert('add')
// $(this).attr('data-remote','true');
// }
// alert('ok')
// return true;
// }
// return false;
// }
params.form.submit(function(){
var flag = false;
if(params.form.attr('data-remote') != undefined ){
flag = true
}
var is_checked = nh_check_field({
issubmit:true,
content:params.editor,
contentmsg:params.contentmsg,
textarea:params.textarea
});
if(is_checked){
if(flag){
return true;
}else{
$(this)[0].submit();
return false;
}
// return true; //这个涛哥的firefox不能提交
//$(this).trigger('submit'); //这个虽然能提交 但是他是个死循环
//$(this)[0].submit(); //用这个form的data-remote='true'没效果了
//肿么破阿 我滴个神 实在不行就用$.ajax()算了
}
return false;
});
}
function nh_reset_form(params){
params.form[0].reset();
params.textarea.empty();
if(params.editor != undefined){
params.editor.html(params.textarea.html());
}
params.contentmsg.hide();
}
KindEditor.ready(function(K){
$("a[nhname='reply_btn']").live('click',function(){
var params = {};
params.kindutil = K;
params.container = $(this).parent('div').parent('div');
params.div_form = $(">.respond-form",params.container);
params.form = $("form",params.div_form);
params.textarea = $("textarea[name='user_notes']",params.div_form);
params.contentmsg = $("p[nhname='contentmsg']",params.div_form),
params.toolbar_container = $("div[nhname='toolbar_container']",params.div_form);
params.cancel_btn = $("input[nhname='cancel_btn']",params.div_form);
if(params.textarea.data('init') == undefined){
params.editor = init_editor(params);
init_form(params);
params.cancel_btn.click(function(){
nh_reset_form(params);
});
}
params.cancel_btn.click();
setTimeout(function(){
if(!params.div_form.is(':hidden')){
$("#nhjump").attr('href','#'+params.div_form.attr('id'));
$("#nhjump")[0].click();
}
},300);
params.textarea.data('init',1);
});
$("div[nhname='new_message']").each(function(){
var params = {};
params.kindutil = K;
params.div_form = $(this);
params.form = $("form",params.div_form);
if(params.form==undefined || params.form.length==0){
return;
}
params.textarea = $("textarea[nhname='new_message_textarea']",params.div_form);
params.contentmsg = $("p[nhname='contentmsg']",params.div_form),
params.toolbar_container = $("div[nhname='toolbar_container']",params.div_form);
if(params.textarea.data('init') == undefined){
params.editor = init_editor(params);
init_form(params);
// $("a[nhname='cancel_btn']",params.div_form).click(function(){
// nh_reset_form(params);
// });
params.textarea.data('init',1);
}
});
});
});
</script>

View File

@ -1,9 +1,10 @@
<%= form_tag(words_create_reply_path, :remote => true) do %> <%= form_tag(words_create_reply_path, :remote => true) do %>
<%= text_area_tag 'user_notes', "", :class => 'w520 h50 mb5', <%= text_area_tag 'user_notes', "", :class => 'w520 h50 mb5',
:style => "resize: none;overflow: hidden;",:rows => 4, :style => "resize: none;overflow: hidden;",:rows => 4,
:placeholder => l(:label_feedback_respond_content), :placeholder => l(:label_feedback_respond_content)#,
:maxlength => 250 %> #:maxlength => 250
%>
<p nhname="contentmsg"></p> <p nhname="contentmsg"></p>
<%= hidden_field_tag 'reference_id', params[:reference_id], :value => journal.id %> <%= hidden_field_tag 'reference_id', params[:reference_id], :value => journal.id %>
<%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => m_reply_id.user.id %> <%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => m_reply_id.user.id %>

View File

@ -1,15 +1,18 @@
<%= form_tag(words_create_reply_path, :remote => true) do %> <%= form_tag(words_create_reply_path, :remote => true) do %>
<%= text_area_tag 'user_notes', "", :class => 'w520 h50 mb5', <%= text_area_tag 'user_notes', "", :class => 'w520 h50 mb5',
:style => "resize: none;overflow: hidden;",:rows => 4, :style => "resize: none;overflow: hidden;",:rows => 4,
:placeholder => l(:label_feedback_respond_content), :placeholder => l(:label_feedback_respond_content)
#,:maxlength => 250
:maxlength => 250 %> %>
<p nhname="contentmsg"></p>
<%= hidden_field_tag 'reference_id', params[:reference_id], :value => journal.id %> <%= hidden_field_tag 'reference_id', params[:reference_id], :value => journal.id %>
<%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => m_reply_id.user.id %> <%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => m_reply_id.user.id %>
<%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => m_reply_id.id %> <%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => m_reply_id.id %>
<%= hidden_field_tag 'show_name',params[:show_name],:value => show_name.nil? ? true : show_name %> <%= hidden_field_tag 'show_name',params[:show_name],:value => show_name.nil? ? true : show_name %>
<div class="fl" style="padding-top:5px;" nhname="toolbar_container"></div>
<%= submit_tag l(:button_feedback_respond), :name => nil , <%= submit_tag l(:button_feedback_respond), :name => nil ,
:class => "reply_btn"%> :class => "reply_btn"%>
<input nhname="cancel_btn" type="button" style="display:none;"/>
<% end %> <% end %>