public function insertBrick(HTML_QuickForm2_Container $form) { $paysystems = $this->getPaysystems(); if (count($paysystems) == 1 && $this->getConfig('hide_if_one')) { reset($paysystems); $form->addHidden('paysys_id')->setValue(current($paysystems)->getId())->toggleFrozen(true); return; } $psOptions = $psHide = array(); foreach ($paysystems as $ps) { $psOptions[$ps->getId()] = $this->renderPaysys($ps); $psHide[$ps->getId()] = Am_Di::getInstance()->plugins_payment->loadGet($ps->getId())->hideBricks(); } $psHide = Am_Controller::getJson($psHide); if (count($paysystems) != 1) { $attrs = array('id' => 'paysys_id'); $el0 = $el = $form->addAdvRadio('paysys_id', array('id' => 'paysys_id'), array('intrinsic_validation' => false)); $first = 0; foreach ($psOptions as $k => $v) { $attrs = array(); if (!$first++ && Am_Di::getInstance()->request->isGet()) { $attrs['checked'] = 'checked'; } $el->addOption($v, $k, $attrs); } } else { /** @todo display html here */ reset($psOptions); $el = $form->addStatic('_paysys_id', array('id' => 'paysys_id'))->setContent(current($psOptions)); $el->toggleFrozen(true); $el0 = $form->addHidden('paysys_id')->setValue(key($psOptions)); } $el0->addRule('required', $this->___('Please choose a payment system'), null, HTML_QuickForm2_Rule::SERVER); $el0->addFilter('filterId'); $el->setLabel($this->___('Payment System')); $form->addScript()->setScript(<<<CUT jQuery(document).ready(function(\$) { /// hide payment system selection if: // - there are only free products in the form // - there are selected products, and all of them are free \$(":checkbox[name^='product_id'], select[name^='product_id'], :radio[name^='product_id'], input[type=hidden][name^='product_id']").change(function(){ var count_free = 0, count_paid = 0, total_count_free = 0, total_count_paid = 0; \$(":checkbox[name^='product_id']:checked, select[name^='product_id'] option:selected, :radio[name^='product_id']:checked, input[type=hidden][name^='product_id']").each(function(){ if ((\$(this).data('first_price')>0) || (\$(this).data('second_price')>0)) count_paid++; else count_free++; }); \$(":checkbox[name^='product_id'], select[name^='product_id'] option, :radio[name^='product_id'], input[type=hidden][name^='product_id']").each(function(){ if ((\$(this).data('first_price')>0) || (\$(this).data('second_price')>0)) total_count_paid++; else total_count_free++; }); if ( ((count_free && !count_paid) || (!total_count_paid && total_count_free)) && (total_count_paid + total_count_free)>0) { // hide select \$("#row-paysys_id").hide().after("<input type='hidden' name='paysys_id' value='free' class='hidden-paysys_id' />"); } else { // show select \$("#row-paysys_id").show(); \$(".hidden-paysys_id").remove(); } }).change(); window.psHiddenBricks = []; \$("input[name='paysys_id']").change(function(){ if (!this.checked) return; var val = \$(this).val(); var hideBricks = {$psHide}; \$.each(window.psHiddenBricks, function(k,v){ \$('#row-'+v+'-0').show(); }); window.psHiddenBricks = hideBricks[val]; if (window.psHiddenBricks) { \$.each(window.psHiddenBricks, function(k,v){ \$('#row-'+v+'-0').hide(); }); } }).change(); }); CUT ); }