Skip to content

Commit

Permalink
removed editing requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
kalebheitzman committed Mar 4, 2024
1 parent ba7f73c commit 4341734
Showing 1 changed file with 29 additions and 32 deletions.
61 changes: 29 additions & 32 deletions classes/output/manage_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,40 +261,37 @@ class="col-5 filter-autotranslate__source-text"
$mform->addElement('html', '<div
class="col-5 filter-autotranslate__target-text ' . $record->target_lang_dir . '"
>');
if ($PAGE->user_is_editing()) {
// Edit mode is on.
$fieldname = 'translation[' . $record->hash . ']';
$fieldname2 = 'original[' . $record->hash . ']';
$ishtml = $this->contains_html($record->text);
if ($ishtml) {
$mform->addElement(
'editor',
$fieldname,
null,
[
'autosave' => false,
'removeorphaneddrafts' => true,
]
)->setValue(['text' => $record->target_text]);
$mform->setType($fieldname, PARAM_RAW);
} else {
$mform->addElement(
'textarea',
$fieldname,
null,
[
'oninput' => 'this.style.height = "";this.style.height = this.scrollHeight + "px"',
'onfocus' => 'this.style.height = "";this.style.height = this.scrollHeight + "px"',
]
);
$mform->setDefault($fieldname, $record->target_text);
}
$mform->addElement('textarea', $fieldname2, null, ["class" => "d-none"]);
$mform->setDefault($fieldname2, $record->target_text);

// Edit mode is on.
$fieldname = 'translation[' . $record->hash . ']';
$fieldname2 = 'original[' . $record->hash . ']';
$ishtml = $this->contains_html($record->text);
if ($ishtml) {
$mform->addElement(
'editor',
$fieldname,
null,
[
'autosave' => false,
'removeorphaneddrafts' => true,
]
)->setValue(['text' => $record->target_text]);
$mform->setType($fieldname, PARAM_RAW);
} else {
// Edit mode is off.
$mform->addElement('html', $record->target_text);
$mform->addElement(
'textarea',
$fieldname,
null,
[
'oninput' => 'this.style.height = "";this.style.height = this.scrollHeight + "px"',
'onfocus' => 'this.style.height = "";this.style.height = this.scrollHeight + "px"',
]
);
$mform->setDefault($fieldname, $record->target_text);
}
$mform->addElement('textarea', $fieldname2, null, ["class" => "d-none"]);
$mform->setDefault($fieldname2, $record->target_text);

$mform->addElement('html', '</div>');

// Close translation item.
Expand Down

0 comments on commit 4341734

Please sign in to comment.