Snippet se vykresluje ve špatné části stránky
- Azim
- Člen | 41
Zdravim. Potykam se s nasledujicim problemem – v sablone se mi snippet
vykresli jinde, nez by mel, viz obrazek – ciselne hodnoty by se mely objevit ve
vodorovnych inputech formulare, takhle mi je to pridava rovnou pod selectbox.
prikladam kod presenteru a sablony.
diky vsem za rady a pomoc
CostCenterPresenter
<?php
class CostCenterPresenter extends SecuredPresenter
{
public function __construct()
{
$this->model = Environment::getService('CentersModel');
}
public function renderDefault()
{
$costCenters = $this->model->getCostCenters();
if ($this->isAjax())
{
$this['costCentersForm']->setDefaults(array('CostCenter' => $this->payload->CostCenter_ID));
$center = new CostCenter($this->payload->CostCenter_ID);
$this['yearsForm']['CostCenter_ID']->setValue($center->id);
$this['rateForm']['CostCenter_ID']->setValue($center->id);
$years = array();
$minYear = NULL;
foreach ($center->rates as $year => $values)
{
if ($minYear == NULL)
$minYear = $year;
$years[$year] = $year;
}
$this['yearsForm']['years']->setItems($years);
if (isset ($this->payload->year))
$year = $this->payload->year;
else
$year = $minYear;
$this['yearsForm']['years']->setValue($year);
$this['rateForm']['Year']->setValue($year);
$this['rateForm']->setDefaults($center->rates[$year]);
$this->invalidateControl('centerYear');
}
}
public function createComponentCostCentersForm($name)
{
$form = new AppForm($this, $name);
$centers = $this->model->getCostCenters();
$costCenters = array(NULL => '---');
foreach ($centers as $center)
{
$costCenters[$center->id] = $center->Name;
}
$form->addSelect('CostCenter', 'CostCenter:', $costCenters);
$form->addSubmit('newSearch', 'New search');
$form->getElementPrototype()->class('ajax costCentersForm');
$form->onSubmit[] = array($this, 'CostCentersFormSubmitted');
return $form;
}
public function CostCentersFormSubmitted($form)
{
$values = $form->getValues();
if (!$this->isAjax())
{
if ($form['newSearch']->isSubmittedBy())
{
$this->redirect('default');
}
}
else {
if ($values['CostCenter'] != NULL)
{
$center = new CostCenter($values['CostCenter']);
$this->payload->year = $minYear;
$this->payload->CostCenter_ID = $center->id;
}
}
}
public function YearsFormSubmitted($form)
{
if ($this->isAjax())
{
$values = $form->getValues();
///////////////////////////////////
// osklivy hack, nicmene bez nej to nejde, je to tak reseny i na nette foru
$values['years'] = $_POST['years'];
///////////////////////////////////
$center = new CostCenter($values['CostCenter_ID']);
$rate = $center->rates[$values['years']];
$this->payload->CostCenter_ID = $center->id;
$this->payload->year = $values['years'];
}
}
public function createComponentYearsForm($name)
{
$form = new AppForm($this, $name);
$form->addSelect('years', 'Year');
$form->addHidden('CostCenter_ID');
$form->getElementPrototype()->class('ajax');
$form->onSubmit[] = array($this, 'YearsFormSubmitted');
return $form;
}
public function createComponentRateForm($name)
{
$form = new AppForm($this, $name);
$form->addHidden('CostCenter_ID');
$form->addHidden('Year');
foreach (BasePresenter::$months as $month)
{
$form->addText($month, $month);
}
$form->addSubmit('save', 'Save');
$form['save']->disabled = 'disabled';
$form->getElementPrototype()->class('rateForm');
$form->onSubmit[] = array($this, 'RateFormSubmitted');
return $form;
}
public function RateFormSubmitted($form)
{
$values = $form->getValues();
$center = new CostCenter($values['CostCenter_ID']);
foreach (BasePresenter::$months as $month)
{
$center->rates[$values['Year']][$month] = $values[$month];
}
$this->model->saveCostCenter($center);
$this->flashMessage('Rates updated successfully.');
$this->redirect('default');
}
}
?>
default.latte
<?php
@{block content}
<script type="text/javascript">
$(document).ready(function()
{
$("#details").css('display', 'none');
$(".costCentersForm select").change(function()
{
if ($(this).val() == '')
{
$("#details").css('display', 'none');
}
else
{
$("#details").css('display', 'block');
}
});
$(".rateForm input").live('change', function()
{
$(".rateForm input[type=\"submit\"]").removeAttr("disabled");
});
});
</script>
{snippet costCenters}
{control costCentersForm}
{/snippet}
<div id="details">
<table>
<thead>
<tr>
<th>Year</th>
{foreach BasePresenter::$months as $month}
<th>{$month}</th>
{/foreach}
</tr>
</thead>
<tbody>
<tr>
<td>
{snippet centerYear}
{control yearsForm begin}
{$control['yearsForm']['years']->control}
{control yearsForm end}
</td>
{* {control rateForm} *}
{foreach BasePresenter::$months as $month}
<td>{$control['rateForm'][$month]->control}</td>
{/foreach}
{/snippet}
</tr>
</tbody>
</table>
</div>
?>
- bojovyletoun
- Člen | 667
nějak tam nechápu ty operace s payload na začátku. Payload je přece
prázdný a do něj se zapisuje.
Ohledně dotazu: snippety se vykreslují do elementu div (blokový element), tak
jestli to nemůže být tím… jinak přepsat ten element jde
takto: {snippet jmeno, td}
- Azim
- Člen | 41
do payloadu se zapisuje v jednotlivych xxxFormSubmitted() funkcich, renderDefault si z nej potom taha data pro nastaveni spravnych hodnot formularu
jinak přepsat ten element jde takto: {snippet jmeno, td}
tohle jsem nepochopil, muzes to prosim trochu rozvest? nepotrebuju nic prespat, potrebuju ho vykreslit na spravnem miste
- Azim
- Člen | 41
abych jeste vysvetlil pointu toho celeho – uzivatel vybere z prvniho selectu costcentrum, onchange se CostCenterForm ajaxove odesle a do payloadu ulozi CostCenter_ID, ze ktereho potom renderDefault z db vytahne roky, ktere jsou pro dane costcentrum definovane a nastavi je jako hodnoty YearsForm selectboxu. uzivatel vybere z YearsFormu rok, ten se onchange ajaxove odesle a do payloadu da vybrany rok. renderDefault pro vybrany rok vytahne z db hodnoty pro jednotlive mesice a nastavi je jako hodnoty inputu.
doufam ze jsem to popsal srozumitelne. pokud mate porad pocit, ze pouzivam payload spatne, ocenim dalsi rady.
- bojovyletoun
- Člen | 667
původní <td>{snippet centerYear}
se přeloží na
<td><div id="snippet--centerYear">
. Možná tam právě
ten div může dělat problémy…
takže zkus toto {snippet centerYear, td}
a umazat td tag.
PS: novějším zápisem to nejde:<td n:snippet="center">
nebo <td n:snippet="center, tag">
, úmyslem bylo, aby se
snippetem byl rovnou tag td.
- Azim
- Člen | 41
tak tenhle problem se vyresil, nicmene se naskytl novy – tagy <form>
a </form> se vykresluji spatne, tj. takto
<form id=„frm-rateForm“ class=„rateForm“ method=„post“
action=„/ate/?do=rateForm-submit&presenter=CostCenter“></form>)
takze tam mam prazdny form a jeho inputy se vykresluji az za nim, tudiz nejde
odeslat.
prislusna cast sablony nasleduje
<tbody>
{snippet centerYear, tr}
<td>
{control yearsForm begin}
{$control['yearsForm']['years']->control}
{control yearsForm end}
</td>
{control rateForm}
{*
{foreach BasePresenter::$months as $month}
<td>{$control['rateForm'][$month]->control}</td>
{/foreach}
<td>{$control['rateForm']['save']->control}</td>
{control rateForm end}
*}
{/snippet}
</tbody>
nekdo nejaky napad proc tomu tak je a jak na to? diky
- voda
- Člen | 561
chybí ti tam begin
{control rateForm begin}
// inputy
{control rateForm end}
Stejně bych ale doporučil použít Form macros