/**
  * Example form factory
  * @return AppForm
  */
 protected function createComponentExampleForm()
 {
     $form = new AppForm();
     $form->addTextarea("text", "Text", 110, 20)->getControlPrototype()->class("texyla");
     $form->addSubmit("s", "Submit");
     return $form;
 }
Esempio n. 2
0
 function filterPageEditForm_create(AppForm $form)
 {
     foreach ($this->fields as $k => $v) {
         $label = is_array($v) && isset($v['label']) ? $v['label'] : $k;
         if (isset($v['type']) and $v['type'] == "textarea") {
             $form->addTextarea("fields_{$k}", $label);
         } elseif (isset($v['type']) and $v['type'] == "checkbox") {
             $form->addCheckbox("fields_{$k}", $label);
         } else {
             $form->addText("fields_{$k}", $label);
         }
     }
     return $form;
 }
 public function createComponent($name)
 {
     switch ($name) {
         case 'pageAddForm':
         case 'pageEditForm':
             if (!isset($prefix_len)) {
                 $prefix_len = strlen('page');
             }
         case 'actualityAddFrom':
         case 'actualityEditForm':
             if (!isset($prefix_len)) {
                 $prefix_len = strlen('actuality');
             }
         case 'manufacturerAddForm':
         case 'manufacturerEditForm':
             if (!isset($prefix_len)) {
                 $prefix_len = strlen('manufacturer');
             }
         case 'categoryAddForm':
         case 'categoryEditForm':
             if (!isset($prefix_len)) {
                 $prefix_len = strlen('category');
             }
         case 'productAddForm':
         case 'productEditForm':
             if (!isset($prefix_len)) {
                 $prefix_len = strlen('product');
             }
             // form itself
             $action = substr($name, $prefix_len);
             $action = substr($action, 0, strlen($action) - 4);
             // instantiate
             $form = new AppForm($this, $name);
             // name
             $form->addText('name', __('Name:'))->addRule(Form::FILLED, __('You have to entry name.'));
             // edit or add?
             if (substr($name, strlen($name) - 8) !== 'EditForm') {
                 // add
                 $form->addText('nice_name', __('Name in URL:'))->addRule(Form::FILLED, __('You have to entry URL name.'));
             } else {
                 // edit
                 $form->addHidden('nice_name');
                 if (strncmp($name, 'manufacturer', 12) === 0 || strncmp($name, 'product', 7) === 0) {
                     $form->addHidden('id');
                 }
             }
             // is category?
             if (strncmp($name, 'category', 8) === 0) {
                 $form->addHidden('id');
             }
             // metas
             $form->addText('meta_keywords', __('META keywords:'));
             $form->addText('meta_description', __('META description:'));
             // description or content?
             if (strncmp($name, 'manufacturer', 12) === 0 || strncmp($name, 'category', 8) === 0) {
                 $form->addTextarea('content', __('Description:'));
             } else {
                 $form->addTextarea('content', __('Content:'));
             }
             // is product?
             if (strncmp($name, 'product', 7) === 0) {
                 // category
                 $categories = array(0 => __('–––'));
                 foreach (mapper::categories()->findAll() as $_) {
                     list($depth, $category) = $_;
                     $categories[$category->getId()] = str_repeat('–', $depth) . ' ' . $category->getName();
                 }
                 $form->addSelect('category_id', __('Category:'), $categories)->skipFirst();
                 // manufacturer
                 $manufacturers = array(0 => __('–––'));
                 foreach (mapper::manufacturers()->findAll() as $manufacturer) {
                     $manufacturers[$manufacturer->getId()] = $manufacturer->getName();
                 }
                 $form->addSelect('manufacturer_id', __('Manufacturer:'), $manufacturers)->skipFirst();
                 // availability
                 $availabilities = array(0 => __('–––'));
                 foreach (mapper::product_availabilities()->findAll() as $_) {
                     $availabilities[$_->getId()] = $_->getName();
                 }
                 $form->addSelect('availability_id', __('Availability:'), $availabilities)->skipFirst();
                 // code
                 $form->addText('code', __('Code:'));
                 // price
                 $form->addText('price', __('Price:'))->addRule(Form::NUMERIC, __('Price has to be a number.'));
             }
             // picture
             $pictures = array(0 => __('–––'));
             foreach (mapper::pictures()->findAll() as $_) {
                 $pictures[$_->getId()] = self::remove_ext($_->getFile());
             }
             $form->addSelect('picture_id', __('Picture:'), $pictures);
             // submit
             $form->addSubmit('ok', '✔ ' . __($action));
             $form->onSubmit[] = array($this, 'on' . ucfirst(substr($name, 0, strlen($name) - 4)) . 'Submit');
             break;
         case 'categoriesForm':
             $form = new AppForm($this, $name);
             $items = array(0 => __('–––'));
             foreach (mapper::categories()->findAll() as $_) {
                 list($depth, $category) = $_;
                 $items[$category->getId()] = str_repeat('–', $depth) . ' ' . $category->getName();
             }
             $form->addSelect('id', __('Category:'), $items)->skipFirst();
             $form->addSubmit('edit', '✎ ' . __('Edit'))->onClick[] = array($this, 'onCategoriesFormEdit');
             $form->addSubmit('add', '⊕ ' . __('Add subcategory'))->onClick[] = array($this, 'onCategoriesFormAdd');
             $form->addSubmit('delete', '⊗ ' . __('Delete'))->onClick[] = array($this, 'onCategoriesFormDelete');
             break;
         case 'newPictureForm':
             $form = new AppForm($this, $name);
             $form->addFile('file', __('File:'));
             $form->addText('rename', __('Rename to:'));
             $form->addText('description', __('Description:'));
             $form->addSubmit('ok', '➦ ' . __('Upload'));
             $form->onSubmit[] = array($this, 'onNewPictureSubmit');
             break;
         case 'availabilitiesForm':
             $form = new AppForm($this, $name);
             $availabilities = array(0 => __('–––'));
             foreach (mapper::product_availabilities()->findAll() as $_) {
                 $availabilities[$_->getId()] = $_->getName();
             }
             $form->addSelect('id', __('Availability:'), $availabilities)->skipFirst();
             $form['id']->addRule(Form::FILLED, __('You have to choose availability.'));
             $form->addSubmit('edit', '✎ ' . __('Edit'))->onClick[] = array($this, 'onAvailabilitiesFormEdit');
             $form->addSubmit('delete', '⊗ ' . __('Delete'))->onClick[] = array($this, 'onAvailabilitiesFormDelete');
             break;
         case 'availabilityAddForm':
         case 'availabilityEditForm':
             if (!isset($prefix_len)) {
                 $prefix_len = strlen('availability');
             }
             $action = substr($name, $prefix_len);
             $action = substr($action, 0, strlen($action) - 4);
             $form = new AppForm($this, $name);
             if (substr($name, strlen($name) - 8) === 'EditForm') {
                 $form->addHidden('id');
             }
             $form->addText('name', __('Name:'));
             $form->addSubmit('ok', '✔ ' . __($action));
             $form->onSubmit[] = array($this, 'on' . ucfirst(substr($name, 0, strlen($name) - 4)) . 'Submit');
             break;
         case 'titlePageForm':
             $form = new AppForm($this, $name);
             $form->addTextarea('content', __('Content:'))->addRule(Form::FILLED, __('You have to entry content.'));
             $form->addSubmit('save', '✔ ' . __('Save'));
             $form->onSubmit[] = array($this, 'onTitlePageFormSubmit');
             $form->setDefaults(array('content' => require_once Environment::expand('%titlePageFile%')));
             break;
         default:
             parent::createComponent($name);
     }
 }
Esempio n. 4
0
 /**
  * A little componen factory
  * @param string
  */
 public function createComponent($name)
 {
     switch ($name) {
         case 'dataForm':
             $data = isset(Environment::getSession(SESSION_ORDER_NS)->data) ? Environment::getSession(SESSION_ORDER_NS)->data : array();
             $form = new AppForm($this, $name);
             // contacts
             $form->addGroup(__('Contacts'));
             $form->addText('email', __('E-mail:'))->setEmptyValue('@')->addRule(Form::FILLED, __('You have to enter your e-mail.'))->addRule(Form::EMAIL, __('This is not an e-mail address.'));
             $form->addText('phone', __('Phone number:'))->addRule(Form::FILLED, __('You have to enter your phone number.'))->addRule(Form::NUMERIC, __('Phone number has to be number.'));
             // payer
             $form->addGroup(__('Payer'));
             $form->addText('payer_name', __('Name:'))->addRule(Form::FILLED, __('You have to enter your name.'));
             $form->addText('payer_lastname', __('Last name:'))->addRule(Form::FILLED, __('You have to enter your last name.'));
             $form->addText('payer_company', __('Company:'));
             $form->addText('payer_street', __('Street:'))->addRule(Form::FILLED, __('You have to enter your street.'));
             $form->addText('payer_city', __('City:'))->addRule(Form::FILLED, __('You have to enter your city.'));
             $form->addText('payer_postcode', __('Post code:'))->addRule(Form::FILLED, __('You have to enter your post code.'))->addRule(Form::NUMERIC, __('Post code has to be number.'));
             $form->addCheckbox('same_delivery', __('deliver at same address (you do not need to fill Delivery address below)'))->setValue(TRUE);
             // delivery address
             $form->addGroup(__('Delivery address'));
             $form->addText('delivery_name', __('Name:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your name.'));
             $form->addText('delivery_lastname', __('Last name:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your last name.'));
             $form->addText('delivery_street', __('Street:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your street.'));
             $form->addText('delivery_city', __('City:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your city.'));
             $form->addText('delivery_postcode', __('Post code:'))->addConditionOn($form['same_delivery'], Form::EQUAL, FALSE)->addRule(Form::FILLED, __('You have to enter your post code.'))->addRule(Form::NUMERIC, __('Post code has to be number.'));
             // delivery type
             $form->addGroup(__('Delivery type'));
             $delivery_types = array();
             foreach (mapper::order_delivery_types()->findAll() as $delivery_type) {
                 $delivery_types[$delivery_type->getId()] = $delivery_type->getName() . Environment::expand(' (' . $delivery_type->getPrice() . ' %currency%)');
             }
             $form->addSelect('delivery_type', __('Type:'), $delivery_types);
             // payment type
             $form->addGroup(__('Payment type'));
             $payment_types = array();
             foreach (mapper::order_payment_types()->findAll() as $payment_type) {
                 $payment_types[$payment_type->getId()] = $payment_type->getName() . Environment::expand(' (' . $payment_type->getPrice() . ' %currency%)');
             }
             $form->addSelect('payment_type', __('Type:'), $payment_types);
             // comment
             $form->addGroup(__('Comment'));
             $form->addTextarea('comment', __('Comment:'));
             // submit
             $form->setCurrentGroup(NULL);
             $form->addSubmit('ok', '(3/3) ' . __('Complete order »'));
             $form['ok']->setRendered(TRUE);
             $form->onSubmit[] = array($this, 'onDataFormSubmit');
             // defaults
             if (isset(Environment::getSession(SESSION_ORDER_NS)->data)) {
                 $form->setDefaults(Environment::getSession(SESSION_ORDER_NS)->data);
             }
             break;
         default:
             parent::createComponent($name);
     }
 }
Esempio n. 5
0
 private function formNewEditFields(AppForm $form)
 {
     $form->addGroup('Content')->setOption('container', Html::el('fieldset')->id('contents'));
     $form->addText('title', 'Title')->addRule(Form::FILLED, 'Fill title');
     $form->addTextarea('content', 'Text');
     $templates = $this->model('contentTemplates')->get('page');
     $form->addGroup('Properties')->setOption('container', Html::el('fieldset')->id('properties'));
     $categories = $this->model('categories')->getPairs();
     $categories = array('0' => 'none') + $categories;
     $form->addSelect('category', 'Category', $categories);
     $form->addCheckBox('homepage', 'Set as homepage?');
     $form->addSelect('template', 'Template', $templates);
     $form->addCheckBox('has_widgets', 'Has widgets');
     $form->addText('publish_time', 'Publish time');
     //$form->addText('time', '');
     $form->addText('keywords', 'keywords');
     $form->addTextarea('description', 'description');
     $form->addHidden('content_type')->setValue('page');
     if ($form->name == 'formNewPage') {
         //$form->addGroup('Link')->setOption('container', Html::el('fieldset')->id('link'));
         $menus = $this->model('menu')->getPairs();
         $menus = array(0 => 'none') + $menus;
         $form->addSelect('link', 'Link in menu', $menus);
     }
     $form->addTextArea('css_files', 'Css files')->getControlPrototype()->{'data-ext'} = 'css';
     $form->addTextArea('js_files', 'Js files')->getControlPrototype()->{'data-ext'} = 'js';
     $form->addGroup('')->setOption('container', Html::el('fieldset')->id('buttons'));
     $form->addButton('btnClose', 'Close');
     $form->addSubmit('btnPreview', 'Preview')->onClick[] = array($this, 'formNewPagePreview');
     $form['btnPreview']->getControlPrototype()->class('ajax');
     return $form;
 }
Esempio n. 6
0
 public function createComponentEditFileForm()
 {
     $form = new AppForm();
     $form->getElementPrototype()->class('ajax');
     //todo:zlobí
     $form->addHidden("id");
     $form->addSelect("id_page_change", "Přesun", PagesModel::getPagesFlat()->getPairs());
     $form->addText("filename", "Název");
     $form->addTextarea("description", "Popis")->getControlPrototype()->setRows(3);
     $form->addText("keywords", "Keywords");
     $form->addText("timestamp", "Timestamp");
     $form->addText("gallerynum", "Číslo galerie")->getControlPrototype()->style('width:50px');
     //TODO ->addRule(Form::INTEGER,'%label musí být číslo')  .. nefunguje js(ajax) validace
     $form->addSubmit("submit1", "Uložit");
     $form->onSuccess[] = callback($this, 'editFileFormSubmitted');
     return $form;
 }