1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Coupons_Form
35: extends Mage_Adminhtml_Block_Widget_Form
36: {
37: 38: 39: 40: 41:
42: protected function _prepareForm()
43: {
44: $form = new Varien_Data_Form();
45:
46: 47: 48:
49: $couponHelper = Mage::helper('salesrule/coupon');
50:
51: $model = Mage::registry('current_promo_quote_rule');
52: $ruleId = $model->getId();
53:
54: $form->setHtmlIdPrefix('coupons_');
55:
56: $gridBlock = $this->getLayout()->getBlock('promo_quote_edit_tab_coupons_grid');
57: $gridBlockJsObject = '';
58: if ($gridBlock) {
59: $gridBlockJsObject = $gridBlock->getJsObjectName();
60: }
61:
62: $fieldset = $form->addFieldset('information_fieldset', array('legend'=>Mage::helper('salesrule')->__('Coupons Information')));
63: $fieldset->addClass('ignore-validate');
64:
65: $fieldset->addField('rule_id', 'hidden', array(
66: 'name' => 'rule_id',
67: 'value' => $ruleId
68: ));
69:
70: $fieldset->addField('qty', 'text', array(
71: 'name' => 'qty',
72: 'label' => Mage::helper('salesrule')->__('Coupon Qty'),
73: 'title' => Mage::helper('salesrule')->__('Coupon Qty'),
74: 'required' => true,
75: 'class' => 'validate-digits validate-greater-than-zero'
76: ));
77:
78: $fieldset->addField('length', 'text', array(
79: 'name' => 'length',
80: 'label' => Mage::helper('salesrule')->__('Code Length'),
81: 'title' => Mage::helper('salesrule')->__('Code Length'),
82: 'required' => true,
83: 'note' => Mage::helper('salesrule')->__('Excluding prefix, suffix and separators.'),
84: 'value' => $couponHelper->getDefaultLength(),
85: 'class' => 'validate-digits validate-greater-than-zero'
86: ));
87:
88: $fieldset->addField('format', 'select', array(
89: 'label' => Mage::helper('salesrule')->__('Code Format'),
90: 'name' => 'format',
91: 'options' => $couponHelper->getFormatsList(),
92: 'required' => true,
93: 'value' => $couponHelper->getDefaultFormat()
94: ));
95:
96: $fieldset->addField('prefix', 'text', array(
97: 'name' => 'prefix',
98: 'label' => Mage::helper('salesrule')->__('Code Prefix'),
99: 'title' => Mage::helper('salesrule')->__('Code Prefix'),
100: 'value' => $couponHelper->getDefaultPrefix()
101: ));
102:
103: $fieldset->addField('suffix', 'text', array(
104: 'name' => 'suffix',
105: 'label' => Mage::helper('salesrule')->__('Code Suffix'),
106: 'title' => Mage::helper('salesrule')->__('Code Suffix'),
107: 'value' => $couponHelper->getDefaultSuffix()
108: ));
109:
110: $fieldset->addField('dash', 'text', array(
111: 'name' => 'dash',
112: 'label' => Mage::helper('salesrule')->__('Dash Every X Characters'),
113: 'title' => Mage::helper('salesrule')->__('Dash Every X Characters'),
114: 'note' => Mage::helper('salesrule')->__('If empty no separation.'),
115: 'value' => $couponHelper->getDefaultDashInterval(),
116: 'class' => 'validate-digits'
117: ));
118:
119: $idPrefix = $form->getHtmlIdPrefix();
120: $generateUrl = $this->getGenerateUrl();
121:
122: $fieldset->addField('generate_button', 'note', array(
123: 'text' => $this->getButtonHtml(
124: Mage::helper('salesrule')->__('Generate'),
125: "generateCouponCodes('{$idPrefix}' ,'{$generateUrl}', '{$gridBlockJsObject}')",
126: 'generate'
127: )
128: ));
129:
130: $this->setForm($form);
131:
132: Mage::dispatchEvent('adminhtml_promo_quote_edit_tab_coupons_form_prepare_form', array('form' => $form));
133:
134: return parent::_prepareForm();
135: }
136:
137: 138: 139: 140: 141:
142: public function getGenerateUrl()
143: {
144: return $this->getUrl('*/*/generate');
145: }
146: }
147: