Ejemplo n.º 1
0
 public function createComponent($name)
 {
     switch ($name) {
         case 'importForm':
             $form = new AppForm($this, $name);
             $form->addFile('file', __('File:'))->addRule(Form::FILLED, __('You have to entry file.'));
             $form->addText('provision', __('Provision (%):'))->addRule(Form::FILLED, __('You have to entry provison.'))->addRule(Form::NUMERIC, __('Provison has to be a number.'))->addRule(Form::RANGE, __('Provision has to be between 0 and 99.'), array(0, 99));
             $form->addCheckbox('update_only', __('only update existing products'));
             // availability_id
             $availabilities = array(0 => __('–––'));
             foreach (mapper::product_availabilities()->findAll() as $_) {
                 $availabilities[$_->getId()] = $_->getName();
             }
             $form->addSelect('availability_id', __('Default availability:'), $availabilities);
             $form->addSubmit('ok', '✔ ' . __('Import'));
             $form->setDefaults(array('provision' => 0, 'update_only' => TRUE));
             $form->onSubmit[] = array($this, 'onImportFormSubmit');
             break;
         case 'importManufacturersForm':
             $form = new AppForm($this, $name);
             $form->addFile('file', __('File:'))->addRule(Form::FILLED, __('You have to entry file.'));
             $form->addSubmit('ok', '✔ ' . __('Import'));
             $form->onSubmit[] = array($this, 'onImportManufacturersFormSubmit');
             break;
         default:
             parent::createComponent($name);
     }
 }
Ejemplo n.º 2
0
 public function createComponent($name)
 {
     switch ($name) {
         case 'settingsForm':
             $form = new AppForm($this, $name);
             // basic
             $form->addGroup(__('Basic'));
             $form->addText('shopName', __('Shop name:'))->addRule(Form::FILLED, __('You have to entry shop name.'));
             $form->addText('shopSlogan', __('Shop slogan:'))->addRule(Form::FILLED, __('You have to entry shop slogan.'));
             $form->addText('shopEmail', __('Contact e-mail:'))->addRule(Form::FILLED, __('You have to entry contact e-mail.'));
             // address
             $form->addGroup(__('Shop address'));
             $form->addText('shopAddressCompany', __('Company:'));
             $form->addText('shopAddressName', __('Name:'))->addRule(Form::FILLED, __('You have to entry name.'));
             $form->addText('shopAddressStreet', __('Street:'))->addRule(Form::FILLED, __('You have to entry street.'));
             $form->addText('shopAddressCity', __('City:'))->addRule(Form::FILLED, __('You have to entry city.'));
             $form->addText('shopAddressPostcode', __('Post code:'))->addRule(Form::FILLED, __('You have to entry post code.'));
             // miscellaneous
             $form->addGroup(__('Miscellaneous'));
             $form->addText('metaKeywords', __('META keywords:'))->addRule(Form::FILLED, __('You have to entry META keywords.'));
             $form->addText('metaDescription', __('META description:'))->addRule(Form::FILLED, __('You have to entry META description.'));
             $form->addText('currency', __('Currency:'))->addRule(Form::FILLED, __('You have to entry currency.'));
             $form->addText('itemsPerPage', __('Items per page:'))->addRule(Form::FILLED, __('You have to entry items per page.'))->addRule(Form::FILLED, __('Items per page has to be a number.'));
             $themes = array(0 => __('–––'));
             foreach (new DirectoryIterator(Environment::expand('%themeDir%')) as $_) {
                 if (!$_->isDot() && $_->isDir()) {
                     $themes[$_->getFilename()] = $_->getFilename();
                 }
             }
             $form->addSelect('theme', __('Theme:'), $themes)->skipFirst();
             $form['theme']->addRule(Form::FILLED, __('You have to select theme.'));
             // submit
             $form->setCurrentGroup(NULL);
             $form->addSubmit('ok', '✔ ' . __('Save'));
             $form->onSubmit[] = array($this, 'onSettingsFormSubmit');
             break;
         case 'changeLoginForm':
             $form = new AppForm($this, $name);
             $form->addText('username', __('Username:'******'You have to entry username.'));
             $form->addPassword('old_password', __('Old password:'******'You have to entry old password.'));
             $form->addPassword('new_password', __('New password:'******'You have to entry new password.'));
             $form->addPassword('new_password_again', __('New password (again):'))->addRule(Form::FILLED, __('You have to entry new password again.'))->addRule(Form::EQUAL, __('New passwords have to match.'), $form['new_password']);
             $form->addSubmit('ok', '✔ ' . __('Change'));
             $form->onSubmit[] = array($this, 'onChangeLoginFormSubmit');
             break;
         default:
             parent::createComponent($name);
     }
 }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
 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);
     }
 }