SF.net SVN: postfixadmin:[1252] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2011-10-30 20:27:15
|
Revision: 1252 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1252&view=rev Author: christian_boltz Date: 2011-10-30 20:27:08 +0000 (Sun, 30 Oct 2011) Log Message: ----------- templates/editform.tpl: - new file - generic edit form template that uses $struct to render the form templates/admin_edit-domain.tpl: - deleted, obsoleted by editform.tpl create-domain.php - use new editform.tpl - use $errormsg array instead of join't $errortext - store/move errors related to a display_in_form field in $fielderror (they will be displayed next to the field) - display remaining error messages (not related to a field) with flash_error() - use "value_$key" instead of "t$Key" as smarty variable name for field values model/DomainHandler.php - store error messages in $this->errormsg[$field] (instead of $this->errormsg[]) - fix label for default_aliases model/PFAHandler.php: - store error messages in $this->errormsg[$field] (instead of $this->errormsg[]) Modified Paths: -------------- trunk/create-domain.php trunk/model/DomainHandler.php trunk/model/PFAHandler.php Added Paths: ----------- trunk/templates/editform.tpl Removed Paths: ------------- trunk/templates/admin_edit-domain.tpl Modified: trunk/create-domain.php =================================================================== --- trunk/create-domain.php 2011-10-30 18:56:11 UTC (rev 1251) +++ trunk/create-domain.php 2011-10-30 20:27:08 UTC (rev 1252) @@ -14,7 +14,6 @@ * * File: create-domain.php * Allows administrators to create or edit domains. - * Template File: admin_edit-domain.tpl */ require_once('common.php'); @@ -22,7 +21,6 @@ authentication_require_role('global-admin'); $error = 0; -$errortext = ""; $mode = 'create'; $edit = safepost('edit', safeget('edit')); @@ -75,17 +73,17 @@ if (!$handler->init($values[$id_field])) { $error = 1; - $errortext = join("<br />", $handler->errormsg); + $errormsg = $handler->errormsg; } if (!$handler->set($values)) { $error = 1; - $errortext = join("<br />", $handler->errormsg); + $errormsg = $handler->errormsg; } if ($error != 1) { if (!$handler->store()) { - $errortext = join("\n", $handler->errormsg); + $errormsg = $handler->errormsg; } else { flash_info($PALANG['pAdminCreate_domain_result_success'] . " (" . $values[$id_field] . ")"); # TODO: - use a sprintf string @@ -111,22 +109,36 @@ } } +$errormsg = $handler->errormsg; +$fielderror = array(); + foreach($form_fields as $key => $field) { if($form_fields[$key]['display_in_form']) { - $smartykey = "t" . ucfirst($key); # TODO: ugly workaround until I decide on the template variable names + + if (isset($errormsg[$key])) { + $fielderror[$key] = $errormsg[$key]; + unset ($errormsg[$key]); + } else { + $fielderror[$key] = ''; + } + switch ($field['type']) { case 'bool': - $smarty->assign ($smartykey, ($values[$key] == '1') ? ' checked="checked"' : ''); + $smarty->assign ("value_$key", ($values[$key] == '1') ? ' checked="checked"' : ''); break; case 'enum': - $smarty->assign ($smartykey, select_options ($form_fields[$key]['options'], array ($values[$key])),false); + $smarty->assign ("value_$key", select_options ($form_fields[$key]['options'], array ($values[$key])),false); # non-escaped break; default: - $smarty->assign ($smartykey, $values[$key]); + $smarty->assign ("value_$key", $values[$key]); } } } +foreach($errormsg as $msg) { # output the remaining error messages (not related to a field) with flash_error + flash_error($msg); +} + if ($mode == 'edit') { $smarty->assign('formtitle', Lang::read('pAdminEdit_domain_welcome')); $smarty->assign('submitbutton', Lang::read('save')); @@ -135,9 +147,11 @@ $smarty->assign('submitbutton', Lang::read('pAdminCreate_domain_button')); } +$smarty->assign ('struct', $form_fields); +$smarty->assign ('fielderror', $fielderror); $smarty->assign ('mode', $mode); -$smarty->assign ('errortext', $errortext, false); # non-escaped -$smarty->assign ('smarty_template', 'admin_edit-domain'); +$smarty->assign ('table', 'domain'); +$smarty->assign ('smarty_template', 'editform'); $smarty->display ('index.tpl'); /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ Modified: trunk/model/DomainHandler.php =================================================================== --- trunk/model/DomainHandler.php 2011-10-30 18:56:11 UTC (rev 1251) +++ trunk/model/DomainHandler.php 2011-10-30 20:27:08 UTC (rev 1252) @@ -41,7 +41,7 @@ if ($this->new) { if ($exists) { - $this->errormsg[] = Lang::read($this->msg['error_already_exists']); + $this->errormsg[$this->id_field] = Lang::read($this->msg['error_already_exists']); return false; } elseif (!$this->validate_id() ) { # errormsg filled by validate_id() @@ -51,7 +51,7 @@ } } else { # edit mode if (!$exists) { - $this->errormsg[] = Lang::read($this->msg['error_does_not_exist']); + $this->errormsg[$this->id_field] = Lang::read($this->msg['error_does_not_exist']); return false; } else { return true; @@ -65,7 +65,7 @@ if ($valid) { return true; } else { - $this->errormsg[] = Lang::read('pAdminCreate_domain_domain_text_error2'); # TODO: half of the errormsg is currently delivered via flash_error() in check_domain + $this->errormsg[$this->id_field] = Lang::read('pAdminCreate_domain_domain_text_error2'); # TODO: half of the errormsg is currently delivered via flash_error() in check_domain return false; } } @@ -123,11 +123,12 @@ /*options*/ $this->getTransports() ), 'backupmx' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_backupmx' , '' ), 'active' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_active' , '' , 1 ), - 'default_aliases' => pacol( $this->new, $this->new, 0, 'bool', 'pAdminCreate_domain_defaultaliases ', '' , 1,'', /*not in db*/ 1 ), + 'default_aliases' => pacol( $this->new, $this->new, 0, 'bool', 'pAdminCreate_domain_defaultaliases', '' , 1,'', /*not in db*/ 1 ), 'created' => pacol( 0, 0, 1, 'ts', '' /* TODO: "created" label */ , '' ), 'modified' => pacol( 0, 0, 1, 'ts', 'pAdminList_domain_modified' , '' ), ); + # TODO: hook to modify $this->struct } # messages used in various functions. Modified: trunk/model/PFAHandler.php =================================================================== --- trunk/model/PFAHandler.php 2011-10-30 18:56:11 UTC (rev 1251) +++ trunk/model/PFAHandler.php 2011-10-30 20:27:08 UTC (rev 1252) @@ -15,27 +15,27 @@ function _inp_num($field, $val) { $valid = is_numeric($val); if ($val < -1) $valid = false; - if (!$valid) $this->errormsg[] = "$field must be numeric"; + if (!$valid) $this->errormsg[$field] = "$field must be numeric"; return $valid; # return (int)($val); } function _inp_bool($field, $val) { if ($val == "0" || $val == "1") return true; - $this->errormsg[] = "$field must be boolean"; + $this->errormsg[$field] = "$field must be boolean"; return false; # return $val ? db_get_boolean(true): db_get_boolean(false); } function _inp_enum($field, $val) { if(in_array($val, $this->struct[$field]['options'])) return true; - $this->errormsg[] = "Invalid parameter given for $field"; + $this->errormsg[$field] = "Invalid parameter given for $field"; return false; } function _inp_password($field, $val){ # TODO: fetchmail specific. Not suited for mailbox/admin passwords. - $this->errormsg[] = "_inp_password not implemented yet"; + $this->errormsg[$field] = "_inp_password not implemented yet"; return false; # return base64_encode($val); } Deleted: trunk/templates/admin_edit-domain.tpl =================================================================== --- trunk/templates/admin_edit-domain.tpl 2011-10-30 18:56:11 UTC (rev 1251) +++ trunk/templates/admin_edit-domain.tpl 2011-10-30 20:27:08 UTC (rev 1252) @@ -1,86 +0,0 @@ -<div id="edit_form"> -<form name="edit_domain" method="post" action=""> -<table> - <tr> - <th colspan="4">{$formtitle}</th> - </tr> - <tr> - <td class="label"><label>{$PALANG.pAdminEdit_domain_domain}:</label></td> - <td> -{if $mode == 'edit'} - <em>{$tDomain}</em> - <input type="hidden" name="edit" value="{$tDomain}" /> -{else} - <input class="flat" type="text" name="domain" value="{$tDomain}" /> -{/if} - </td> - <td> </td> - <td><span class="error_msg">{$errortext}</span></td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pAdminEdit_domain_description}:</label></td> - <td><input class="flat" type="text" name="description" value="{$tDescription}" /></td> - <td colspan="2"> </td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pAdminEdit_domain_aliases}:</label></td> - <td><input class="flat" type="text" name="aliases" value="{$tAliases}" /></td> - <td>{$PALANG.pAdminEdit_domain_aliases_text}</td> - <td> </td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pAdminEdit_domain_mailboxes}:</label></td> - <td><input class="flat" type="text" name="mailboxes" value="{$tMailboxes}" /></td> - <td>{$PALANG.pAdminEdit_domain_mailboxes_text}</td> - <td> </td> - </tr> -{if $CONF.domain_quota===YES} - <tr> - <td class="label"><label>{$PALANG.pAdminEdit_domain_quota}:</label></td> - <td><input class="flat" type="text" name="quota" value="{$tQuota}" /></td> - <td>{$PALANG.pAdminEdit_domain_maxquota_text}</td> - <td> </td> - </tr> -{/if} -{if $CONF.quota===YES} - <tr> - <td class="label"><label>{$PALANG.pAdminEdit_domain_maxquota}:</label></td> - <td><input class="flat" type="text" name="maxquota" value="{$tMaxquota}" /></td> - <td>{$PALANG.pAdminEdit_domain_maxquota_text}</td> - <td> </td> - </tr> -{/if} -{if $CONF.transport===YES} - <tr> - <td class="label"><label>{$PALANG.pAdminEdit_domain_transport}:</label></td> - <td><select class="flat" name="transport">{$tTransport}</select></td> - <td>{$PALANG.pAdminEdit_domain_transport_text}</td> - <td> </td> - </tr> -{/if} -{if $mode == 'create'} - <tr> - <td class="label"><label>{$PALANG.pAdminCreate_domain_defaultaliases}:</label></td> - <td><input class="flat" type="checkbox" value='1' name="default_aliases"{$tDefault_aliases}/></td> - <td>{$PALANG.pAdminCreate_domain_defaultaliases_text}</td> - <td> </td> - </tr> -{/if} - <tr> - <td class="label"><label>{$PALANG.pAdminEdit_domain_backupmx}:</label></td> - <td><input class="flat" type="checkbox" value='1' name="backupmx"{$tBackupmx}/></td> - <td> </td> - <td> </td> - </tr> - <tr> - <td class="label"><label>{$PALANG.pAdminEdit_domain_active}:</label></td> - <td><input class="flat" type="checkbox" value='1' name="active"{$tActive}/></td> - <td colspan="2"> </td> - </tr> - <tr> - <td> </td> - <td colspan="3"><input class="button" type="submit" name="submit" value="{$submitbutton}" /></td> - </tr> -</table> -</form> -</div> Added: trunk/templates/editform.tpl =================================================================== --- trunk/templates/editform.tpl (rev 0) +++ trunk/templates/editform.tpl 2011-10-30 20:27:08 UTC (rev 1252) @@ -0,0 +1,47 @@ +<div id="edit_form"> +<form name="edit_{$table}" method="post" action=""> + +<table> + <tr> + <th colspan="4">{$formtitle}</th> + </tr> + +{foreach key=key item=field from=$struct} + {if $field.display_in_form == 1} + + {if $table == 'foo' && $key == 'bar'} + <tr><td>Special handling (complete table row) for {$table} / {$key}</td></tr> + {else} + <tr> + <td class="label">{$field.label}</td> + <td> + {if $field.editable == 0} + {$value_{$key}} + {else} + {if $table == 'foo' && $key == 'bar'} + Special handling (td content) for {$table} / {$key} + {elseif $field.type == 'bool'} + <input class="flat" type="checkbox" value='1' name="{$key}"{$value_{$key}}/> + {elseif $field.type == 'enum'} + <select class="flat" name="{$key}">{$value_{$key}}</select> + {else} + <input class="flat" type="text" name="{$key}" value="{$value_{$key}}" /> + {/if} + {/if} + </td> + <td>{$field.desc}</td> + <td class="error_msg">{$fielderror.{$key}}</td> + </tr> + {/if} + + {/if} +{/foreach} + + <tr> + <td> </td> + <td colspan="3"><input class="button" type="submit" name="submit" value="{$submitbutton}" /></td> + </tr> +</table> + +</form> +</div> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |