fix some bugs

This commit is contained in:
zmagod 2017-01-19 11:37:59 +01:00
parent 2ccafdd670
commit f2d5066dc7
11 changed files with 28 additions and 11 deletions

View file

@ -230,6 +230,7 @@ var HelperModule = (function(){
return helpers;
})();
// initialize code markup in step descriptions and text results
(function() {
$(document).ready(function() {
$('pre code [class^=language]').each(function(i, block) {

View file

@ -183,8 +183,8 @@ function processResult(ev, resultTypeEnum, editMode, forS3) {
var $nameInput = $form.find("#result_name");
var nameValid = textValidator(ev, $nameInput, 0,
<%= Constants::NAME_MAX_LENGTH %>);
var $textInput = $form.find("#result_result_text_attributes_text");
textValidator(ev, $textInput, 1, <%= Constants::TEXT_MAX_LENGTH %>);
var $textInput = TinyMCE.getContent();// $form.find("#result_result_text_attributes_text");
textValidator(ev, $textInput, 1, <%= Constants::TEXT_MAX_LENGTH %>, false, true);
break;
case ResultTypeEnum.COMMENT:
var $commentInput = $form.find("#comment_message");

View file

@ -489,6 +489,7 @@ $("[data-action='new-step']").on("ajax:success", function(e, data) {
applyCancelOnNew();
toggleButtons(false);
initializeCheckboxSorting();
TinyMCE.init();
$("#step_name").focus();
$("#new-step-main-tab a").on("shown.bs.tab", function() {

View file

@ -22,13 +22,17 @@ $.fn.onSubmitValidator = function(validatorCb) {
* @param {boolean} clearErr Set clearErr to true if this is the only
* error that can happen/show.
*/
function textValidator(ev, textInput, textLimitMin, textLimitMax, clearErr) {
function textValidator(ev, textInput, textLimitMin, textLimitMax, clearErr, tinyMCE) {
clearErr = _.isUndefined(clearErr) ? false : clearErr;
var text = $(textInput).val().trim();
$(textInput).val(text);
var text_from_html = $("<div/>").html(text).text();
if (text_from_html.length < text.length) text = text_from_html;
if(tinyMCE){
var text = textInput.length;
} else {
var text = $(textInput).val().trim();
$(textInput).val(text);
var text_from_html = $("<div/>").html(text).text();
if (text_from_html.length < text.length) text = text_from_html;
}
var nameTooShort = text.length < textLimitMin;
var nameTooLong = text.length > textLimitMax;

View file

@ -39,6 +39,9 @@ var TinyMCE = (function() {
this.destroyAll();
this.init();
},
getContent: function() {
return tinymce.editors[0].getContent();
},
highlight: initHighlightjs
});

View file

@ -1,5 +1,5 @@
/*
*= require github
*= require highlightjs-github-theme
*= require_self
*= require_tree .
*= require jquery-ui/draggable

View file

@ -260,5 +260,11 @@ module BootstrapFormHelper
end
text_area(name, opts)
end
# Returns <textarea> helper tag for tinyMCE editor
def tiny_mce_editor(name, options = {})
options.merge!(class: 'tinymce', cols: 120, rows: 40)
text_area(name, options)
end
end
end

View file

@ -3,7 +3,8 @@
<%= f.text_field :name, style: "margin-top: 10px;" %><br />
<%= f.fields_for :result_text do |ff| %>
<div class="form-group">
<%= ff.text_area(:text, class: 'tinymce', cols: 120, rows: 40, value: @result.result_text.text ) %>
<%= ff.tiny_mce_editor(:text, value: @result.result_text.text) %>
<%#= ff.text_area(:text, class: 'tinymce', cols: 120, rows: 40, value: @result.result_text.text ) %>
</div>
<% end %><br />
<%= f.submit t("result_texts.edit.update"), class: 'btn btn-primary save-result', onclick: "processResult(event, ResultTypeEnum.TEXT, true);" %>

View file

@ -3,7 +3,8 @@
<%= f.text_field :name, style: "margin-top: 10px;" %><br />
<%= f.fields_for :result_text do |ff| %>
<div class="form-group">
<%= ff.text_area(:text, class: 'tinymce', cols: 120, rows: 40) %>
<%= ff.tiny_mce_editor(:text) %>
<%#= ff.text_area(:text, class: 'tinymce', cols: 120, rows: 40) %>
</div>
<% end %><br />
<%= f.submit t("result_texts.new.create"), class: 'btn btn-primary save-result', onclick: "processResult(event, ResultTypeEnum.TEXT, false);" %>

View file

@ -27,7 +27,7 @@
<div class="tab-pane active" role="tabpanel" id="new-step-main">
<%= f.text_field :name, label: t("protocols.steps.new.name"), placeholder: t("protocols.steps.new.name_placeholder") %>
<div class="form-group">
<%= f.text_area(:description, class: 'tinymce', cols: 120, rows: 40) %>
<%= f.tiny_mce_editor(:description) %>
</div>
</div>
<div class="tab-pane" role="tabpanel" id="new-step-checklists">