public function createComponentRedirectEditForm() { $form = new AppForm(); $form->getElementPrototype()->class('ajax'); $form->addHidden('id'); $form->addText('oldurl', 'stará adresa'); $form->addText('newurl', 'nová adresa'); $form->addSubmit('submit1', 'OK'); $form->onSuccess[] = callback($this, 'redirectEditFormSubmitted'); return $form; }
protected function createComponentHomeForm($name) { $form = new AppForm(); $form->addTextArea('text', 'Text')->addRule(Form::FILLED, "Bez textu zůstane úvodní strana prázdná")->getControlPrototype()->style = 'width: 685px; height: 370px'; $form->addHidden('id'); $dataSource = dibi::query('SELECT id, text FROM [options] WHERE [name]=%s', 'home')->fetch(); if ($dataSource != null) { $form->setDefaults($dataSource); } $form->addSubmit('ok', 'Uložit')->onClick[] = array($this, 'saveClicked'); return $form; }
public function createComponentTranslationsAddForm() { $form = new AppForm(); $form->getElementPrototype()->class('ajax'); $form->addHidden('id'); $form->addText('key', 'Klíč'); foreach ($this->context->params["langs"] as $l => $txt) { $form->addText($l, $txt); } $form->addSubmit('submit1', 'OK'); $form->onSuccess[] = callback($this, 'editFormSubmitted'); return $form; }
protected function createComponentForm() { $form = new AppForm(); $form->addHidden('id'); $form->addText('jmeno', 'Jméno:')->setOption('description', 'Prázdné jméno smaže záznam.'); $form->addText('prezdivka', 'Přezdívka:'); $form->addText('adresa', 'Adresa:'); $form->addText('pevny_telefon', 'Pevná linka:'); $form->addText('mobilni_telefon', 'Mobil:')->setOption('description', 'STS přidejte nakonec do závorky'); $form->addText('email', 'E-mail:'); $form->addSelect('oddil', 'Oddíl:', self::$oddily); $form->addText('poznamka', 'Poznámka:'); $form->addSubmit('save', 'Uložit'); $form->onSuccess[] = callback($this, 'editFormSubmitted'); 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); } }
public function createComponent($name) { switch ($name) { case 'manageStatusesForm': $form = new AppForm($this, $name); $statuses = array(0 => __('–––')); foreach (mapper::order_statuses()->findAll() as $_) { $statuses[$_->getId()] = $_->getName() . ($_->getInitial() ? ' ✱' : ''); } $form->addSelect('id', __('Status:'), $statuses)->skipFirst(); $form['id']->addRule(Form::FILLED); $form->addSubmit('edit', '✎ ' . __('Edit'))->onClick[] = array($this, 'onManageStatusesFormEdit'); break; case 'statusAddForm': case 'statusEditForm': $prefix_len = strlen('status'); $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:'))->addRule(Form::FILLED, __('You have to entry status name.')); $form->addCheckbox('initial', __('initial for orders')); $form->addSubmit('ok', '✔ ' . __($action)); $form->onSubmit[] = array($this, 'on' . substr($name, 0, strlen($name) - 4) . 'Submit'); break; case 'managePaymentTypesForm': $form = new AppForm($this, $name); $types = array(0 => __('–––')); foreach (mapper::order_payment_types()->findAll() as $_) { $types[$_->getId()] = $_->getName(); } $form->addSelect('id', __('Payment type:'), $types)->skipFirst(); $form['id']->addRule(Form::FILLED); $form->addSubmit('edit', '✎ ' . __('Edit'))->onClick[] = array($this, 'onManagePaymentTypesFormEdit'); break; case 'manageDeliveryTypesForm': $form = new AppForm($this, $name); $types = array(0 => __('–––')); foreach (mapper::order_delivery_types()->findAll() as $_) { $types[$_->getId()] = $_->getName(); } $form->addSelect('id', __('Delivery type:'), $types)->skipFirst(); $form['id']->addRule(Form::FILLED); $form->addSubmit('edit', '✎ ' . __('Edit'))->onClick[] = array($this, 'onManageDeliveryTypesFormEdit'); break; case 'paymentTypeAddForm': case 'paymentTypeEditForm': $prefix_len = strlen('paymentType'); case 'deliveryTypeAddForm': case 'deliveryTypeEditForm': if (!isset($prefix_len)) { $prefix_len = strlen('deliveryType'); } $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:'))->addRule(Form::FILLED, __('You have to entry name.')); $form->addText('price', __('Price:'))->addRule(Form::FILLED, __('You have to entry price.'))->addRule(Form::NUMERIC, __('Price has to be a number.')); $form->addSubmit('ok', '✔ ' . __($action)); $form->onSubmit[] = array($this, 'on' . substr($name, 0, strlen($name) - 4) . 'Submit'); break; case 'changeOrderStatusForm': $form = new AppForm($this, $name); $statuses = array(0 => __('–––')); foreach (mapper::order_statuses()->findAll() as $_) { $statuses[$_->getId()] = $_->getName(); } $form->addSelect('status_id', __('Status:'), $statuses)->skipFirst()->addRule(Form::FILLED, __('You have to entry status.')); $form->addHidden('id'); $form->addSubmit('ok', '✔ ' . __('Change')); $form->onSubmit[] = array($this, 'onChangeOrderStatusFormSubmit'); break; case 'sendMailForm': $form = new AppForm($this, $name); $form->addText('to', __('To:'))->addRule(Form::EMAIL, __('E-mail has to be an e-mail.')); $form->addText('subject', __('Subject:'))->addRule(Form::FILLED, __('You have to entry subject.')); $form->addTextArea('body', __('Body:'))->addRule(Form::FILLED, __('You have to entry text.')); $form->addSubmit('ok', '✔ ' . __('Send')); $form->onSubmit[] = array($this, 'onSendMailFormSubmit'); $form->addHidden('order_id'); break; default: parent::createComponent($name); } }
/** * Component factory. * @see Nette/ComponentContainer#createComponent() */ protected function createComponentForm($name) { $form = new AppForm(); $form->addGroup('general'); //$form->getElementPrototype()->id('editform'); $form->addText('name', 'Křestí a příp. prostřední jméno')->addRule(Form::FILLED, "Jméno je potřeba vyplnit"); $form->addText('surname', 'Příjmení')->addRule(Form::FILLED, "Příjmení je potřeba vyplnit"); $form->addCheckbox('r', 'Osmileté gymnázium (R)'); $form->addSelect('mark', 'Písmeno třídy', array("A" => "A", "B" => "B", "C" => "C", "D" => "D")); $form->addGroup('left'); $form->addText('class', 'Maturitní ročník', 4); $form->addGroup('right'); $form->addSelect('number', 'Číslo třídy', array("?", "1", "2", "3", "4", "5", "6", "7", "8")); $form['class']->addConditionOn($form['number'], Form::EQUAL, 0)->addRule(Form::FILLED, 'Pokud nevyberete číslo třídy, musíte zadat maturitní ročník')->addRule(Form::NUMERIC, 'Ročník musí být číslo')->addRule(Form::RANGE, 'Rok maturity musí být od %d do %d', array(1960, 2999)); $form->addGroup('submit'); $form->addSubmit('ok', 'Přidat autora')->onClick[] = array($this, 'addClicked'); if ($this->setId != '') { $dataSource = dibi::query('SELECT * FROM [authors] WHERE authorId=%i', $this->setId)->fetch(); $form->setDefaults($dataSource); $form['ok']->onClick = array(array($this, 'SaveClicked')); $form['ok']->caption = "Uložit autora"; $form->addHidden("authorId")->setValue($this->setId); } $this->addComponent($form, $name); return; }
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; }
public function createComponentEditForm($table, $id = null) { $form = new AppForm($this, $table . 'EditForm'); $form->addProtection(); if ($id != null) { $form->addHidden('id')->setValue($id); } switch ($table) { case 'students': $years = $this->model('courses')->getYears(); $form->addText('name', 'Name'); $form->addText('surname', 'Surname'); $form->addSelect('year', 'year' . ':', $years); if ($id != null) { $values = $this->model('students')->getStudent($id); } break; case 'teachers': $departments = $this->model('school')->getDepartments(); $form->addText('name', 'Name'); $form->addText('surname', 'Surname'); $form->addSelect('department', 'department' . ':')->setItems($departments, false); if ($id != null) { $values = $this->model('teachers')->getTeacher($id); } break; case 'rooms': $form->addText('name', 'Name'); if ($id != null) { $values = $this->model('school')->getRoom($id); } break; case 'departments': $form->addText('name', 'Name'); if ($id != null) { $values = $this->model('school')->getDepartment($id); } break; case 'learning_times': $form->addText('time', 'time'); if ($id != null) { $values = $this->model('school')->getLearningTime($id); } break; case 'courses': $years = $this->model('courses')->getYears(); $departments = $this->model('school')->getDepartments(); $form->addText('name', 'name'); $form->addSelect('year', 'year:', $years); $form->addSelect('semester', 'semester:', array('L' => 'L', 'Z' => 'Z')); $form->addSelect('department', 'department:', $departments); if ($id != null) { $values = $this->model('courses')->getCourse($id); } break; } $form->addSubmit('btnSubmit', 'Save'); $form->onSubmit[] = array($this, 'editFormSubmitted'); if (isset($values)) { $form->setDefaults($values); } return $form; }
public function createComponentPreviewUploadForm() { $form = new AppForm(); $form->getElementPrototype()->class('ajax_upload'); $form->addHidden("id"); $form->addUpload("file", "soubor"); $form->addSubmit("submit1", "Nahrát"); $form->onSuccess[] = callback($this, 'previewUploadFormSubmitted'); return $form; }
public function createComponentPageEditForm() { $form = new AppForm(); $form->getElementPrototype()->class('ajax'); $form->addHidden("id_page"); $form->addText("heading", "nadpis"); $form->addText("name", "v menu"); $form->addText("seoname", "adresa")->setAttribute('placeholder', '(automatická)'); $form->addCheckbox("published", "publikováno"); $form->addTextArea("text", "obsah stránky"); $form['text']->getControlPrototype()->class('textarea'); $form->addSubmit("submit1", "Uložit"); $form->onSuccess[] = callback($this, 'pageEditFormSubmitted'); //add additional inputs $this->triggerEvent_filter('filterPageEditForm_create', $form); return $form; }
protected function createComponentFileLoader($name) { if ($this->setId != '') { $form = new AppForm(); $form->addFile('file', "Přidat soubor:"); $form->addHidden("workId")->setValue($this->setId); $form->addSubmit('fileSubmit', 'Přidat soubor')->onClick[] = array($this, 'fileSent'); $this->addComponent($form, $name); } return; }
public function createComponentFormPermissionEditor($name) { $model = new UsersModuleModel(); $all_actions = $model->getActions(); $allowed_actions = $model->getAllowedActions(Environment::getSession('group_id')->value); $form = new AppForm($this, $name); $form->addHidden('group_id')->setValue(Environment::getSession('group_id')->value); $form = $this->addPermissionCheckboxes($form, $all_actions, $allowed_actions); foreach ($allowed_actions as $row) { $form['allowed_' . $row->resource_id]->setValue(1); } $form->addGroup(' ')->setOption('container', Html::el('fieldset')->id('buttons')); $form->addButton('btnClose', 'Close'); $form->addSubmit('btnSave', 'Save'); $form->onSubmit[] = array($this, 'SavePermissions'); return $form; }