<?php

/**
 * Offer form.
 *
 * @package    sf
 * @subpackage form
 * @author     Atma
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class OfferForm extends BaseOfferForm
{
    public function configure()
    {
        $this->embedI18n(array('ru', 'en'));
        $this->useFields(array('ru', 'en', 'quantity_type_select', 'price', 'sort', 'discount_available', 'img', 'product_id'));

        $parentId = sfContext::getInstance()->getRequest()->getParameter('parentId');
        if($parentId){
            $parentId = str_replace('product_', '', $parentId);
            if($parentId){
                $this->setDefault('product_id', $parentId);
            }
        }
        $this->widgetSchema['discount_available'] = new sfWidgetFormInputCheckbox(array('label' => 'Доступен со скидкой?'), array("required" => true));
        $this->widgetSchema['product_id'] = new sfWidgetFormInputHidden();
        $this->widgetSchema['ru']['title'] = new sfWidgetFormInputText(array("label" => "Название"), array("size" => 64, "maxlength" => 255, "required" => true));
        $this->widgetSchema['en']['title'] = new sfWidgetFormInputText(array("label" => "Название"), array("size" => 64, "maxlength" => 255, "required" => true));
        $this->widgetSchema['ru']['quantity_type'] = new sfWidgetFormInputText(array("label" => "Единица измерения"), array("size" => 24, "maxlength" => 255, "required" => true, "placeholder" => '10 кг, мешок', 'class' => 'offer_all_lang_quantity_type'));
        $this->widgetSchema['en']['quantity_type'] = new sfWidgetFormInputText(array("label" => "Единица измерения"), array("size" => 24, "maxlength" => 255, "required" => true, "placeholder" => '10 кг, мешок', 'class' => 'offer_all_lang_quantity_type'));
        $this->widgetSchema['price'] = new sfWidgetFormInputText(array("label" => "Цена"), array("size" => 8, "maxlength" => 8, "required" => true));
        $this->validatorSchema['price'] = new sfValidatorInteger(array('min' => '0', 'required' => true), array('min' => 'Число должно быть больше %min%.'));
        $this->widgetSchema['quantity_type_select'] = new sfWidgetFormChoice(array('choices' => array('' => '–', 'm2' => 'кв. метр', 'sheet' => 'лист', 'piece' => 'шт.')), array('onchange' => 'offerQuantityType.change(this)', 'style' => 'margin-right:5px;', 'class' => 'offer_quantity_type_select'));

        $this->widgetSchema['img'] = new sfWidgetFormInputFileUpload(array(
            'label' => 'Изображение',
            'allowedFileTypes' => 'image/png,image/jpeg',
            'script' => '/uploader?key=product'
        ), array('required' => false));
    }
}
