Skip to content

Commit

Permalink
Adding TinyMCE editor on add case update form
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchezfauste committed Jun 29, 2018
1 parent c0006ed commit fa497c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
14 changes: 1 addition & 13 deletions portal/static/portal/cases_detail.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
$( document ).ready(function() {

$('textarea').each(function () {
this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;resize:none;');
}).on('input', function () {
this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px';
if (this.value.length > 0) {
$('#update-case-form-submit-button').prop('disabled', false);
} else {
$('#update-case-form-submit-button').prop('disabled', true);
}
});

$('#update-case-form').submit(function(event) {
// Stop the browser from submitting the form.
Expand All @@ -36,7 +24,7 @@ $( document ).ready(function() {
$('#update_case_modal').each(function () {
$('#update-case-text').val('');
$('#update-case-attachment').val(null);
$('#update-case-form-submit-button').prop('disabled', true);
tinyMCE.get('update-case-text').load();
$('#case-updates').append(response.case_update);
$(this).find('.modal-body').html(
'<div class="alert alert-success" role="alert">'
Expand Down
9 changes: 8 additions & 1 deletion portal/templates/portal/module_detail_cases.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@ <h5 class="card-title">{% trans "Update case" %}</h5>
<label for="update-case-attachment-label">{% trans "Attachments:" %}</label>
<input type="file" class="form-control-file" id="update-case-attachment" name="update-case-attachment" multiple>
</div>
<button type="submit" class="btn btn-primary" id="update-case-form-submit-button" disabled><span class="oi oi-share"></span> {% trans "Add update" %}</button>
<button type="submit" class="btn btn-primary" id="update-case-form-submit-button"><span class="oi oi-share"></span> {% trans "Add update" %}</button>
</form>
</div>
</div>

<script src="{% static 'portal/tinymce/tinymce.min.js' %}"></script>
<script>
tinymce.init({
selector: '#update-case-text'
});
</script>

<!-- Modal -->
<div class="modal fade" id="update_case_modal" tabindex="-1" role="dialog" aria-labelledby="update_case_modal_title" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
Expand Down
2 changes: 1 addition & 1 deletion portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def add_case_update(request):
case_update['contact_id'] = request.user.userattr.contact_id
case_update['case_id'] = request.POST['case-id']
case_update['name'] = update_case_text[:45]
case_update['description'] = update_case_text.replace('\n', '<br>')
case_update['description'] = update_case_text
case_update['internal'] = 0
try:
SuiteCRM().save_bean(case_update)
Expand Down

0 comments on commit fa497c2

Please sign in to comment.