Skip to content
Snippets Groups Projects
Commit 0e21ff48 authored by Jared Hancock's avatar Jared Hancock
Browse files

forms: Instructions can be HTML

parent 07e18dc1
Branches
Tags
No related merge requests found
......@@ -101,8 +101,8 @@ class DynamicForm extends VerySimpleModel {
}
function getTitle() { return $this->get('title'); }
function getInstructions() { return $this->get('instructions'); }
function getTitle() { return $this->getLocal('title'); }
function getInstructions() { return $this->getLocal('instructions'); }
function getForm($source=false) {
if (!$this->_form || $source) {
......@@ -151,7 +151,9 @@ class DynamicForm extends VerySimpleModel {
$this->set('updated', new SqlFunction('NOW'));
if (isset($this->dirty['notes']))
$this->notes = Format::sanitize($this->notes);
return parent::save($refetch);
if ($rv = parent::save($refetch | $this->dirty))
return $this->saveTranslations();
return $rv;
}
function delete() {
......@@ -195,6 +197,53 @@ class DynamicForm extends VerySimpleModel {
return $inst;
}
function saveTranslations($vars=false) {
global $thisstaff;
$vars = $vars ?: $_POST;
$tags = array(
'title' => $this->getTranslateTag('title'),
'instructions' => $this->getTranslateTag('instructions'),
);
$rtags = array_flip($tags);
$translations = CustomDataTranslation::allTranslations($tags, 'phrase');
foreach ($translations as $t) {
$T = $rtags[$t->object_hash];
$content = @$vars['trans'][$t->lang][$T];
if (!isset($content))
continue;
// Content is not new and shouldn't be added below
unset($vars['trans'][$t->lang][$T]);
$t->text = $content;
$t->agent_id = $thisstaff->getId();
$t->updated = SqlFunction::NOW();
if (!$t->save())
return false;
}
// New translations (?)
foreach ($vars['trans'] as $lang=>$parts) {
if (!Internationalization::isLanguageInstalled($lang))
continue;
foreach ($parts as $T => $content) {
$content = trim($content);
if (!$content)
continue;
$t = CustomDataTranslation::create(array(
'type' => 'phrase',
'object_hash' => $tags[$T],
'lang' => $lang,
'text' => $content,
'agent_id' => $thisstaff->getId(),
'updated' => SqlFunction::NOW(),
));
if (!$t->save())
return false;
}
}
return true;
}
static function getCrossTabQuery($object_type, $object_id='object_id', $exclude=array()) {
......@@ -709,10 +758,10 @@ class DynamicFormField extends VerySimpleModel {
$this->save();
}
function save() {
function save($refetch=false) {
if (count($this->dirty))
$this->set('updated', new SqlFunction('NOW'));
return parent::save();
return parent::save($this->dirty || $refetch);
}
static function create($ht=false) {
......
......@@ -7,9 +7,20 @@ if($form && $_REQUEST['a']!='add') {
$url = "?id=".urlencode($_REQUEST['id']);
$submit_text=__('Save Changes');
$info = $form->ht;
$trans['title'] = $form->getTranslateTag('title');
$trans['instructions'] = $form->getTranslateTag('instructions');
$trans = array(
'title' => $form->getTranslateTag('title'),
'instructions' => $form->getTranslateTag('instructions'),
);
$newcount=2;
$translations = CustomDataTranslation::allTranslations($trans, 'phrase');
$_keys = array_flip($trans);
foreach ($translations as $t) {
if (!Internationalization::isLanguageInstalled($t->lang))
continue;
// Create keys of [trans][de_DE][title] for instance
$info['trans'][$t->lang][$_keys[$t->object_hash]]
= Format::viewableImages($t->text);
}
} else {
$title = __('Add new custom form section');
$action = 'add';
......@@ -39,23 +50,65 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
</thead>
<tbody style="vertical-align:top">
<tr>
<td width="180" class="required"><?php echo __('Title'); ?>:</td>
<td><input type="text" name="title" size="40"
data-translate-tag="<?php echo $trans['title']; ?>"
<td colspan="2">
<table class="full-width"><tbody><tr><td style="vertical-align:top">
<?php
$langs = Internationalization::getConfiguredSystemLanguages();
if ($form && count($langs) > 1) { ?>
<ul class="vertical tabs" id="translations">
<li class="empty"><i class="icon-globe" title="This content is translatable"></i></li>
<?php foreach ($langs as $tag=>$nfo) { ?>
<li class="<?php if ($tag == $cfg->getPrimaryLanguage()) echo "active";
?>"><a href="#translation-<?php echo $tag; ?>" title="<?php
echo Internationalization::getLanguageDescription($tag);
?>"><span class="flag flag-<?php echo strtolower($nfo['flag']); ?>"></span>
</a></li>
<?php } ?>
</ul>
<?php
} ?>
</td>
<td id="translations_container">
<div id="translation-<?php echo $cfg->getPrimaryLanguage(); ?>" class="tab_content"
lang="<?php echo $cfg->getPrimaryLanguage(); ?>">
<div class="required"><?php echo __('Title'); ?>:</div>
<div>
<input type="text" name="title" size="60"
value="<?php echo $info['title']; ?>"/>
<i class="help-tip icon-question-sign" href="#form_title"></i>
<font class="error"><?php
if ($errors['title']) echo '<br/>'; echo $errors['title']; ?></font>
</td>
</tr>
<tr>
<td width="180"><?php echo __('Instructions'); ?>:</td>
<td><textarea name="instructions" rows="3" cols="40"
data-translate-tag="<?php echo $trans['instructions']; ?>"><?php
echo $info['instructions']; ?></textarea>
<div class="error"><?php
if ($errors['title']) echo '<br/>'; echo $errors['title']; ?></div>
</div>
<div style="margin-top: 8px"><?php echo __('Instructions'); ?>:
<i class="help-tip icon-question-sign" href="#form_instructions"></i>
</td>
</tr>
</div>
<textarea name="instructions" rows="3" cols="40" class="richtext"><?php
echo $info['instructions']; ?></textarea>
</div>
<?php if ($langs && $form) {
foreach ($langs as $tag=>$nfo) {
if ($tag == $cfg->getPrimaryLanguage())
continue; ?>
<div id="translation-<?php echo $tag; ?>" class="tab_content"
style="display:none;" lang="<?php echo $tag; ?>">
<div>
<div class="required"><?php echo __('Title'); ?>:</div>
<input type="text" name="trans[<?php echo $tag; ?>][title]" size="60"
value="<?php echo $info['trans'][$tag]['title']; ?>"/>
<i class="help-tip icon-question-sign" href="#form_title"></i>
</div>
<div style="margin-top: 8px"><?php echo __('Instructions'); ?>:
<i class="help-tip icon-question-sign" href="#form_instructions"></i>
</div>
<textarea name="trans[<?php echo $tag; ?>][instructions]" cols="21" rows="12"
style="width:100%" class="richtext"><?php
echo $info['trans'][$tag]['instructions']; ?></textarea>
</div>
<?php }
} ?>
</td></tr></tbody></table>
</td></tr>
</tbody>
</table>
<table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2">
......
......@@ -116,10 +116,11 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
<li><a href="#notes"><?php echo __('Internal Notes'); ?></a></li>
</ul>
<div class="tab_content active" id="content">
<table class="full-width"><tbody><tr><td style="vertical-align:top">
<?php
$langs = Internationalization::getConfiguredSystemLanguages();
if ($page && count($langs) > 1) { ?>
<ul class="vertical left tabs">
<ul class="vertical tabs" id="translations">
<li class="empty"><i class="icon-globe" title="This content is translatable"></i></li>
<?php foreach ($langs as $tag=>$nfo) { ?>
<li class="<?php if ($tag == $cfg->getPrimaryLanguage()) echo "active";
......@@ -131,15 +132,18 @@ if ($page && count($langs) > 1) { ?>
</ul>
<?php
} ?>
<div id="msg_info" style="margin:0 55px">
</td>
<td id="translations_container" style="padding-left: 10px">
<div id="msg_info">
<em><i class="icon-info-sign"></i> <?php
echo __(
'Ticket variables are only supported in thank-you pages.'
); ?></em></div>
); ?></em>
</div>
<div id="translation-<?php echo $cfg->getPrimaryLanguage(); ?>" class="tab_content" style="margin:0 45px"
<div id="translation-<?php echo $cfg->getPrimaryLanguage(); ?>" class="tab_content"
lang="<?php echo $cfg->getPrimaryLanguage(); ?>">
<textarea name="body" cols="21" rows="12" style="width:98%;" class="richtext draft"
<textarea name="body" cols="21" rows="12" style="width:100%" class="richtext draft"
<?php
list($draft, $attrs) = Draft::getDraftAndDataAttrs('page', $info['id'], $info['body']);
echo $attrs; ?>><?php echo $draft ?: $info['body']; ?></textarea>
......@@ -150,17 +154,18 @@ if ($page && count($langs) > 1) { ?>
if ($tag == $cfg->getPrimaryLanguage())
continue; ?>
<div id="translation-<?php echo $tag; ?>" class="tab_content"
style="display:none;margin:0 45px" lang="<?php echo $tag; ?>">
style="display:none;" lang="<?php echo $tag; ?>">
<textarea name="trans[<?php echo $tag; ?>][body]" cols="21" rows="12"
style="width:98%;" class="richtext draft"
style="width:100%" class="richtext draft"
<?php
list($draft, $attrs) = Draft::getDraftAndDataAttrs('page', $info['id'].'.'.$tag, $info['trans'][$tag]);
echo $attrs; ?>><?php echo $draft ?: $info['trans'][$tag]; ?></textarea>
</div>
<?php }
} ?>
</td></tr></tbody></table>
<div class="error" style="margin: 5px 55px"><?php echo $errors['body']; ?></div>
<div class="error" style="margin: 5px 0"><?php echo $errors['body']; ?></div>
<div class="clear"></div>
</div>
<div class="tab_content" style="display:none" id="notes">
......
......@@ -632,10 +632,16 @@ table.fixed {
border-collapse: collapse;
width: 100%;
}
table.fixed td {
table.fixed > thead > tr > th,
table.fixed > thead > tr > td,
table.fixed > tbody > tr > td,
table.fixed > tr > td {
width: 180px;
}
table.fixed td + td {
table.fixed > thead > tr > th + th,
table.fixed > thead > tr > td + td,
table.fixed > tbody > tr > td + td,
table.fixed > tr > td + td {
width: auto;
}
......
......@@ -100,13 +100,14 @@ div.translatable {
box-shadow: inset 0 1px 1px rgba(0,0,0,0.05);
display: inline-block;
white-space: nowrap;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
border-right: none;
padding: 0 5px 2px;
padding: 1px 5px 1px;
margin-left: 2px;
width: auto;
background-color: white;
line-height: 16px;
}
div.translatable.textarea {
border: 1px solid #bbb;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment