Commit cdf521f1 authored by Nigel McNie's avatar Nigel McNie
Browse files

Build the form controls separately from the artefact chooser template itself,...

Build the form controls separately from the artefact chooser template itself, cleaning up all the artefactchooser templates quite a bit. Make sure that the message for the resumefield blocktype isn't stored as configdata also.
parent 89e82e29
<tr>
<td style="width: 20px;" rowspan="2">
{if $selectone}<input type="radio" class="radio"id="{$elementname}_{$artefact->id}" name="{$elementname}" value="{$artefact->id|escape}"{if $value == $artefact->id} checked="checked"{/if}>
{else}<input type="checkbox" id="{$elementname}_{$artefact->id}" name="{$elementname}[{$artefact->id}]"{if $value && in_array($artefact->id, $value)} checked="checked"{/if}>
<input type="hidden" name="{$elementname}_onpage[]" value="{$artefact->id}">
{/if}</td>
{$formcontrols}
</td>
<th><label for="{$elementname}_{$artefact->id}">{if $artefact->blog}{$artefact->blog|escape}: {/if}{$artefact->title|escape}</label></th>
</tr>
<tr>
......
<tr title="{$artefact->hovertitle|escape}">
<td style="width: 20px;">
{if $selectone}<input type="radio" class="radio"id="{$elementname}_{$artefact->id}" name="{$elementname}" value="{$artefact->id|escape}"{if $value == $artefact->id} checked="checked"{/if}>
{else}<input type="checkbox" id="{$elementname}_{$artefact->id}" name="{$elementname}[{$artefact->id}]"{if $value && in_array($artefact->id, $value)} checked="checked"{/if}>
<input type="hidden" name="{$elementname}_onpage[]" value="{$artefact->id}">
{/if}</td>
{$formcontrols}
</td>
<td style="width: 22px;"><label for="{$elementname}_{$artefact->id}"><img src="{$artefact->icon|escape}" alt="*"></label></td>
<th><label for="{$elementname}_{$artefact->id}">{if $artefact->description}{$artefact->description|escape}{else}{$artefact->title|escape}{/if}{if $artefact->artefacttype == 'profileicon'} ({str tag=profileicon section=artefact.internal}){/if}</label></th>
</tr>
<tr>
<td style="width: 20px;" rowspan="2">
{if $selectone}<input type="radio" class="radio"id="{$elementname}_{$artefact->id}" name="{$elementname}" value="{$artefact->id|escape}"{if $value == $artefact->id} checked="checked"{/if}>
{else}<input type="checkbox" id="{$elementname}_{$artefact->id}" name="{$elementname}[{$artefact->id}]"{if $value && in_array($artefact->id, $value)} checked="checked"{/if}>
<input type="hidden" name="{$elementname}_onpage[]" value="{$artefact->id}">
{/if}</td>
{$formcontrols}
</td>
<th><label for="{$elementname}_{$artefact->id}" title="{$artefact->title|strip_tags|substr:0:60|escape}">{str tag=$artefact->artefacttype section=artefact.internal}</label></th>
</tr>
<tr>
......
......@@ -44,11 +44,12 @@ class PluginBlocktypeResumefield extends PluginBlocktype {
require_once(get_config('docroot') . 'lib/artefact.php');
$smarty = smarty_core();
$configdata = $instance->get('configdata');
$configdata['viewid'] = $instance->get('view');
// Get data about the resume field in this blockinstance
if (!empty($configdata['artefactid'])) {
$resumefield = artefact_instance_from_id($configdata['artefactid']);
$rendered = $resumefield->render_self(false);
$rendered = $resumefield->render_self($configdata);
$result = $rendered['html'];
if (!empty($rendered['javascript'])) {
$result .= '<script type="text/javascript">' . $rendered['javascript'] . '</script>';
......@@ -69,7 +70,7 @@ class PluginBlocktypeResumefield extends PluginBlocktype {
// Which resume field does the user want
$form[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null);
$form[] = array(
$form['message'] = array(
'type' => 'html',
'value' => '<a href="' . get_config('wwwroot') . 'artefact/resume/">Fill out your resume</a> in order to add more fields!'
);
......@@ -77,6 +78,11 @@ class PluginBlocktypeResumefield extends PluginBlocktype {
return $form;
}
public static function instance_config_save($values) {
unset($values['message']);
return $values;
}
// TODO: make decision on whether this should be abstract or not
public static function artefactchooser_element($default=null) {
safe_require('artefact', 'resume');
......
<tr>
<td style="width: 20px;" rowspan="2">
{if $selectone}<input type="radio" class="radio"id="{$elementname}_{$artefact->id}" name="{$elementname}" value="{$artefact->id|escape}"{if $value == $artefact->id} checked="checked"{/if}>
{else}<input type="checkbox" id="{$elementname}_{$artefact->id}" name="{$elementname}[{$artefact->id}]"{if $value && in_array($artefact->id, $value)} checked="checked"{/if}>
<input type="hidden" name="{$elementname}_onpage[]" value="{$artefact->id}">
{/if}</td>
{$formcontrols}
</td>
<th><label for="{$elementname}_{$artefact->id}" title="{$artefact->title|strip_tags|substr:0:60|escape}">{str tag=$artefact->artefacttype section=artefact.resume}</label></th>
</tr>
<tr>
......
......@@ -1194,11 +1194,29 @@ class View {
$artefact = call_static_method($blocktypeclass, 'artefactchooser_get_element_data', $artefact);
}
// Build the radio button or checkbox for the artefact
$formcontrols = '';
if ($selectone) {
$formcontrols .= '<input type="radio" class="radio" id="' . hsc($elementname . '_' . $artefact->id)
. '" name="' . hsc($elementname) . '" value="' . hsc($artefact->id) . '"';
if ($value == $artefact->id) {
$formcontrols .= ' checked="checked"';
}
$formcontrols .= '>';
}
else {
$formcontrols .= '<input type="checkbox" id="' . hsc($elementname . '_' . $artefact->id) . '" name="' . hsc($elementname) . '[' . hsc($artefact->id) . ']"';
if ($value && in_array($artefact->id, $value)) {
$formcontrols .= ' checked="checked"';
}
$formcontrols .= '>';
$formcontrols .= '<input type="hidden" name="' . hsc($elementname) . '_onpage[]" value="' . hsc($artefact->id) . '">';
}
$smarty = smarty_core();
$smarty->assign('artefact', $artefact);
$smarty->assign('selectone', $selectone);
$smarty->assign('elementname', $elementname);
$smarty->assign('value', $value);
$smarty->assign('formcontrols', $formcontrols);
$result .= $smarty->fetch($template) . "\n";
}
......
<tr title="{$artefact->hovertitle|escape}">
<td style="width: 20px;">
{if $selectone}<input type="radio" class="radio"id="{$elementname}_{$artefact->id}" name="{$elementname}" value="{$artefact->id|escape}"{if $value == $artefact->id} checked="checked"{/if}>
{else}<input type="checkbox" id="{$elementname}_{$artefact->id}" name="{$elementname}[{$artefact->id}]"{if $value && in_array($artefact->id, $value)} checked="checked"{/if}>
<input type="hidden" name="{$elementname}_onpage[]" value="{$artefact->id}">
{/if}</td>
{$formcontrols}
<td>
<th><label for="{$elementname}_{$artefact->id}">{$artefact->title|escape}</label></th>
</tr>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment