コード例 #1
0
ファイル: Brick.php プロジェクト: alexanderTsig/arabic
    public function initConfigForm(Am_Form $form)
    {
        $radio = $form->addSelect('type')->setLabel(___('What to Display'));
        $radio->loadOptions(array(self::DISPLAY_ALL => ___('Display All Products'), self::DISPLAY_CATEGORY => ___('Products from selected Categories'), self::DISPLAY_PRODUCT => ___('Only Products selected below'), self::DISPLAY_BP => ___('Only Billing Plans selected below')));
        $groups = $form->addMagicSelect('groups', array('data-type' => self::DISPLAY_CATEGORY))->setLabel(___('Product Gategories'));
        $groups->loadOptions(Am_Di::getInstance()->productCategoryTable->getAdminSelectOptions(array(ProductCategoryTable::COUNT => 1)));
        $products = $form->addSortableMagicSelect('products', array('data-type' => self::DISPLAY_PRODUCT))->setLabel(___('Product(s) to display'));
        $products->loadOptions(Am_Di::getInstance()->productTable->getOptions(true));
        $bpOptions = array();
        foreach (Am_Di::getInstance()->productTable->getVisible() as $product) {
            /* @var $product Product */
            foreach ($product->getBillingOptions() as $bp_id => $title) {
                $bpOptions[$product->pk() . '-' . $bp_id] = sprintf('%s (%s)', $product->title, $title);
            }
        }
        $bps = $form->addSortableMagicSelect('bps', array('data-type' => self::DISPLAY_BP))->setLabel(___('Billing Plan(s) to display'));
        $bps->loadOptions($bpOptions);
        $inputType = $form->addSelect('input-type')->setLabel(___('Input Type'));
        $inputType->loadOptions(array('advradio' => ___('Radio-buttons (one product can be selected)'), 'select' => ___('Select-box (one product can be selected)'), 'checkbox' => ___('Checkboxes (multiple products can be selected)')));
        $form->addAdvCheckbox('display-popup')->setlabel('Display Products in Popup');
        $form->addSelect('display-type')->setLabel(___('If product is not available because of require/disallow settings'))->loadOptions(array('hide' => ___('Remove It From Signup Form'), 'display' => ___('Display It Anyway')));
        $form->addCheckboxedGroup('empty-option')->setLabel(___("Add an 'empty' option to select box\nto do not choose any products"))->addText('empty-option-text');
        $form->addAdvCheckbox('hide_if_one')->setLabel(___("Hide Select\n" . 'if there is only one choice'));
        $form->addAdvRadio('require')->setLabel(___('Require Behaviour'))->loadOptions(array(self::REQUIRE_DEFAULT => sprintf('<strong>%s</strong>: %s', ___('Default'), ___('Make this Brick Required Only in Case There is not any Required Brick on Page Above It')), self::REQUIRE_ALWAYS => sprintf('<strong>%s</strong>: %s', ___('Always'), ___('Force User to Choose Some Product from this Brick')), self::REQUIRE_NEVER => sprintf('<strong>%s</strong>: %s', ___('Never'), ___('Products in this Brick is Optional (Not Required)')), self::REQUIRE_ALTERNATE => sprintf('<strong>%s</strong>: %s', ___('Alternate'), ___('User can Choose Product in any Brick of Such Type on Page but he Should Choose at least One Product still'))))->setValue(self::REQUIRE_DEFAULT);
        $formId = $form->getId();
        $script = <<<EOF
        jQuery(document).ready(function(\$) {
            // there can be multiple bricks like that :)
            if (!window.product_brick_hook_set)
            {
                window.product_brick_hook_set = true;
                \$(document).on('change',"select[name='type']", function (event){
                    var val = \$(event.target).val();
                    var frm = \$(event.target).closest("form");
                    \$("[data-type]", frm).closest(".row").hide();
                    \$("[data-type='"+val+"']", frm).closest(".row").show();
                })
                \$("select[name='type']").change();
                \$(document).on('change',"select[name='input-type']", function (event){
                    var val = \$(event.target).val();
                    var frm = \$(event.target).closest("form");
                    \$("input[name='display-popup']", frm).closest(".row").toggle(val == 'checkbox');
                    \$("input[name='empty-option']", frm).closest(".row").toggle(val == 'advradio' || val == 'select');
                })
                \$("select[name='input-type']").change();
            }
        });
EOF;
        $form->addScript()->setScript($script);
        $form->addAdvCheckbox('no_label')->setLabel(___('Remove Label'));
    }