From dbfa7d63ef218b31e0f553195ea0905056928d80 Mon Sep 17 00:00:00 2001 From: Vincent Augagneur Date: Tue, 9 Jul 2013 14:26:34 +0200 Subject: [PATCH] //carrier wizard field validation --- .../carrier_wizard/helpers/form/form.tpl | 85 ++++ .../carrier_wizard/helpers/form/index.php | 35 ++ .../carrier_wizard/helpers/view/view.tpl | 25 +- classes/controller/AdminController.php | 16 +- .../admin/AdminCarrierWizardController.php | 476 ++++++++++++++---- css/admin.css | 5 + js/admin_carrier_wizard.js | 148 ++++++ 7 files changed, 670 insertions(+), 120 deletions(-) create mode 100644 admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl create mode 100644 admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/index.php create mode 100644 js/admin_carrier_wizard.js diff --git a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl new file mode 100644 index 000000000..3222e0548 --- /dev/null +++ b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form.tpl @@ -0,0 +1,85 @@ +{* +* 2007-2013 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +{extends file="helpers/form/form.tpl"} + +{block name="field"} + {if $input.name == 'zones'} + + + + + +
+ + + + + + + + + + + {l s="Add new range"} + + +
+ + + + + + {foreach from=$zones item=zone} + + + + {/foreach} + + + +
+ + {$zone.name} +
 
+ + +
+ + + + + + + + + +
>=
<
+
+ + {/if} + {$smarty.block.parent} +{/block} diff --git a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/index.php b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/index.php new file mode 100644 index 000000000..30839633c --- /dev/null +++ b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../../../../../../'); +exit; \ No newline at end of file diff --git a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/view/view.tpl b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/view/view.tpl index a070fee92..17090a2e1 100644 --- a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/view/view.tpl +++ b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/view/view.tpl @@ -26,26 +26,11 @@ {extends file="helpers/view/view.tpl"} {block name="override_tpl"}
    diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index a8a33ca7a..a36b3b6a0 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -2377,7 +2377,7 @@ class AdminControllerCore extends Controller foreach ($rules['required'] as $field) if (($value = Tools::getValue($field)) == false && (string)$value != '0') if (!Tools::getValue($this->identifier) || ($field != 'passwd' && $field != 'no-picture')) - $this->errors[] = sprintf( + $this->errors[$field] = sprintf( Tools::displayError('The %s field is required.'), call_user_func(array($class_name, 'displayFieldName'), $field, $class_name) ); @@ -2386,7 +2386,7 @@ class AdminControllerCore extends Controller if (isset($rules['requiredLang']) && is_array($rules['requiredLang'])) foreach ($rules['requiredLang'] as $field_lang) if (($empty = Tools::getValue($field_lang.'_'.$default_language->id)) === false || $empty !== '0' && empty($empty)) - $this->errors[] = sprintf( + $this->errors[$field_lang.'_'.$default_language->id] = sprintf( Tools::displayError('The field %1$s is required at least in %2$s.'), call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name), $default_language->name @@ -2396,7 +2396,7 @@ class AdminControllerCore extends Controller if (isset($rules['size']) && is_array($rules['size'])) foreach ($rules['size'] as $field => $max_length) if (Tools::getValue($field) !== false && Tools::strlen(Tools::getValue($field)) > $max_length) - $this->errors[] = sprintf( + $this->errors[$field] = sprintf( Tools::displayError('The %1$s field is too long (%2$d chars max).'), call_user_func(array($class_name, 'displayFieldName'), $field, $class_name), $max_length @@ -2409,7 +2409,7 @@ class AdminControllerCore extends Controller { $field_lang_value = Tools::getValue($field_lang.'_'.$language['id_lang']); if ($field_lang_value !== false && Tools::strlen($field_lang_value) > $max_length) - $this->errors[] = sprintf( + $this->errors[$field_lang.'_'.$language['id_lang']] = sprintf( Tools::displayError('The field %1$s (%2$s) is too long (%3$d chars max, html chars including).'), call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name), $language['name'], @@ -2424,7 +2424,7 @@ class AdminControllerCore extends Controller foreach ($rules['validate'] as $field => $function) if (($value = Tools::getValue($field)) !== false && ($field != 'passwd')) if (!Validate::$function($value) && !empty($value)) - $this->errors[] = sprintf( + $this->errors[$field] = sprintf( Tools::displayError('The %s field is invalid.'), call_user_func(array($class_name, 'displayFieldName'), $field, $class_name) ); @@ -2433,12 +2433,12 @@ class AdminControllerCore extends Controller if (($value = Tools::getValue('passwd')) != false) { if ($class_name == 'Employee' && !Validate::isPasswdAdmin($value)) - $this->errors[] = sprintf( + $this->errors['passwd'] = sprintf( Tools::displayError('The %s field is invalid.'), call_user_func(array($class_name, 'displayFieldName'), 'passwd', $class_name) ); elseif ($class_name == 'Customer' && !Validate::isPasswd($value)) - $this->errors[] = sprintf( + $this->errors[$field] = sprintf( Tools::displayError('The %s field is invalid.'), call_user_func(array($class_name, 'displayFieldName'), 'passwd', $class_name) ); @@ -2450,7 +2450,7 @@ class AdminControllerCore extends Controller foreach ($languages as $language) if (($value = Tools::getValue($field_lang.'_'.$language['id_lang'])) !== false && !empty($value)) if (!Validate::$function($value)) - $this->errors[] = sprintf( + $this->errors[$field_lang.'_'.$language['id_lang']] = sprintf( Tools::displayError('The %1$s field (%2$s) is invalid.'), call_user_func(array($class_name, 'displayFieldName'), $field_lang, $class_name), $language['name'] diff --git a/controllers/admin/AdminCarrierWizardController.php b/controllers/admin/AdminCarrierWizardController.php index 7e975b5a3..f8a1b7994 100644 --- a/controllers/admin/AdminCarrierWizardController.php +++ b/controllers/admin/AdminCarrierWizardController.php @@ -27,17 +27,26 @@ class AdminCarrierWizardControllerCore extends AdminController { public function __construct() - { + { $this->display = 'view'; + $this->table = 'carrier'; + $this->className = 'Carrier'; + $this->lang = false; + $this->deleted = true; + $this->step_number = 0; + + + parent::__construct(); } - + public function setMedia() { parent::setMedia(); $this->addJqueryPlugin('smartWizard'); + $this->addJs(_PS_JS_DIR_.'admin_carrier_wizard.js'); } - + public function initWizard() { $this->wizard_steps = array( @@ -46,26 +55,22 @@ class AdminCarrierWizardControllerCore extends AdminController array( 'title' => $this->l('General'), 'desc' => $this->l('General'), - ), + ), array( 'title' => $this->l('Where and how much ?'), 'desc' => $this->l('Where and how much ?'), - ), + ), array( 'title' => $this->l('What and to who ?'), 'desc' => $this->l('What and to who ?'), - ), + ), array( 'title' => $this->l('Resume'), 'desc' => $this->l('Resume'), - ), - - )); - - /* $this->wizard_steps */ - - - + ), + + )); + if (Shop::isFeatureActive()) { $multistore_step = array( @@ -77,115 +82,402 @@ class AdminCarrierWizardControllerCore extends AdminController array_splice($this->wizard_steps['steps'], 1, 0, $multistore_step); } } - + public function renderView() { $this->initWizard(); - - + + if (Tools::getValue('id_carrier')) + $carrier = $this->loadObject(); + else + $carrier = new Carrier(); + $this->tpl_view_vars = array( 'wizard_steps' => $this->wizard_steps, + 'validate_url' => $this->context->link->getAdminLink('AdminCarrierWizard'), 'wizard_contents' => array( 'contents' => array( - 0 => $this->renderStepOne(), + 0 => $this->renderStepOne($carrier), + 1 => $this->renderStepTow($carrier), + 2 => $this->renderStepThree($carrier), + 3 => $this->renderStepFour($carrier) )), 'labels' => array('next' => $this->l('Next'), 'previous' => $this->l('Previous'), 'finish' => $this->l('Finish')) - ); - + ); + return parent::renderView(); } - - public function renderStepOne() + + public function initToolbarTitle() + { + $bread_extended = array_unique($this->breadcrumbs); + + if (Tools::getValue('id_carrier')) + $bread_extended[1] = $this->l('Edit'); + else + $bread_extended[1] = $this->l('Add new'); + + $this->toolbar_title = $bread_extended; + } + + public function renderStepOne($carrier) { $this->fields_form = array( 'form' => array( - 'legend' => array( - 'title' => $this->l('Carriers:'), - 'image' => '../img/admin/delivery.gif' - ), - 'input' => array( - array( - 'type' => 'text', - 'label' => $this->l('Company:'), - 'name' => 'name', - 'size' => 25, - 'required' => true, - 'hint' => sprintf($this->l('Allowed characters: letters, spaces and %s'), '().-'), - 'desc' => array( - $this->l('Carrier name displayed during checkout'), - $this->l('For in-store pickup, enter 0 to replace the carrier name with your shop name.') - ) + 'legend' => array( + 'title' => $this->l('Carriers:'), + 'image' => '../img/admin/delivery.gif' ), - array( - 'type' => 'text', - 'label' => $this->l('Transit time:'), - 'name' => 'delay', - 'lang' => true, - 'required' => true, - 'size' => 41, - 'maxlength' => 128, - 'desc' => $this->l('Estimated delivery time will be displayed during checkout.') - ), - array( - 'type' => 'text', - 'label' => $this->l('Speed Grade:'), - 'name' => 'grade', - 'required' => false, - 'size' => 1, - 'desc' => $this->l('Enter "0" for a longest shipping delay, or "9" for the shortest shipping delay.') - ), - array( - 'type' => 'file', - 'label' => $this->l('Logo:'), - 'name' => 'logo', - 'desc' => $this->l('Upload a logo from your computer.').' (.gif, .jpg, .jpeg '.$this->l('or').' .png)' - ), - array( - 'type' => 'text', - 'label' => $this->l('URL:'), - 'name' => 'url', - 'size' => 40, - 'desc' => $this->l('Delivery tracking URL: Type \'@\' where the tracking number should appear. It will then be automatically replaced by the tracking number.') - ), - )), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Company:'), + 'name' => 'name', + 'size' => 25, + 'required' => true, + 'hint' => sprintf($this->l('Allowed characters: letters, spaces and %s'), '().-'), + 'desc' => array( + $this->l('Carrier name displayed during checkout'), + $this->l('For in-store pickup, enter 0 to replace the carrier name with your shop name.') + ) + ), + array( + 'type' => 'text', + 'label' => $this->l('Transit time:'), + 'name' => 'delay', + 'lang' => true, + 'required' => true, + 'size' => 41, + 'maxlength' => 128, + 'desc' => $this->l('Estimated delivery time will be displayed during checkout.') + ), + array( + 'type' => 'text', + 'label' => $this->l('Speed Grade:'), + 'name' => 'grade', + 'required' => false, + 'size' => 1, + 'desc' => $this->l('Enter "0" for a longest shipping delay, or "9" for the shortest shipping delay.') + ), + array( + 'type' => 'file', + 'label' => $this->l('Logo:'), + 'name' => 'logo', + 'desc' => $this->l('Upload a logo from your computer.').' (.gif, .jpg, .jpeg '.$this->l('or').' .png)' + ), + array( + 'type' => 'text', + 'label' => $this->l('URL:'), + 'name' => 'url', + 'size' => 40, + 'desc' => $this->l('Delivery tracking URL: Type \'@\' where the tracking number should appear. It will then be automatically replaced by the tracking number.') + ), + )), ); - - $carrier = new Carrier(1); - $fields_value = $this->getStep1FieldsValues($carrier); - return $this->renderGenericForm($this->fields_form, $fields_value); + + $fields_value = $this->getStepOneFieldsValues($carrier); + return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value); } - - public function renderStepTow($fields_form) + + public function renderStepTow($carrier) { - - - + $this->fields_form = array( + 'form' => array( + 'legend' => array( + 'title' => $this->l('Carriers:'), + 'image' => '../img/admin/delivery.gif' + ), + 'input' => array( + array( + 'type' => 'shop', + 'label' => $this->l('Shop association:'), + 'name' => 'checkBoxShopAsso', + ), + )) + ); + $fields_value = $this->getStepTowFieldsValues($carrier); + return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value); } - - public function renderGenericForm($fields_form, $fields_value) + + public function renderStepThree($carrier) + { + $this->fields_form = array( + 'form' => array( + 'legend' => array( + 'title' => $this->l('Carriers:'), + 'image' => '../img/admin/delivery.gif' + ), + 'input' => array( + array( + 'type' => 'radio', + 'label' => $this->l('Apply shipping cost:'), + 'name' => 'is_free', + 'required' => false, + 'class' => 't', + 'values' => array( + array( + 'id' => 'is_free_on', + 'value' => 0, + 'label' => ''.$this->l('Yes').'' + ), + array( + 'id' => 'is_free_off', + 'value' => 1, + 'label' => ''.$this->l('No').'' + ) + ), + 'desc' => $this->l('Apply both regular shipping cost and product-specific shipping costs.') + ), + array( + 'type' => 'radio', + 'label' => $this->l('Shipping and handling:'), + 'name' => 'shipping_handling', + 'required' => false, + 'class' => 't', + 'is_bool' => true, + 'values' => array( + array( + 'id' => 'shipping_handling_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'shipping_handling_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + 'desc' => $this->l('Include the shipping and handling costs in the carrier price.') + ), + array( + 'type' => 'radio', + 'label' => $this->l('Billing:'), + 'name' => 'shipping_method', + 'required' => false, + 'class' => 't', + 'br' => true, + 'values' => array( + array( + 'id' => 'billing_default', + 'value' => Carrier::SHIPPING_METHOD_DEFAULT, + 'label' => $this->l('Default behavior') + ), + array( + 'id' => 'billing_price', + 'value' => Carrier::SHIPPING_METHOD_PRICE, + 'label' => $this->l('According to total price') + ), + array( + 'id' => 'billing_weight', + 'value' => Carrier::SHIPPING_METHOD_WEIGHT, + 'label' => $this->l('According to total weight') + ) + ) + ), + array( + 'type' => 'select', + 'label' => $this->l('Tax:'), + 'name' => 'id_tax_rules_group', + 'options' => array( + 'query' => TaxRulesGroup::getTaxRulesGroups(true), + 'id' => 'id_tax_rules_group', + 'name' => 'name', + 'default' => array( + 'label' => $this->l('No Tax'), + 'value' => 0 + ) + ) + ), + array( + 'type' => 'zone', + 'name' => 'zones', + 'value' => array() + ) + ) + )); + + $tpl_vars = array(); + $tpl_vars['zones'] = Zone::getZones(false); + + $fields_value = $this->getStepThreeFieldsValues($carrier); + return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value, $tpl_vars); + } + + public function renderStepFour($carrier) + { + $this->fields_form = array( + 'form' => array( + 'legend' => array( + 'title' => $this->l('Carriers:'), + 'image' => '../img/admin/delivery.gif' + ), + 'input' => array( + array( + 'type' => 'select', + 'label' => $this->l('Out-of-range behavior:'), + 'name' => 'range_behavior', + 'options' => array( + 'query' => array( + array( + 'id' => 0, + 'name' => $this->l('Apply the cost of the highest defined range') + ), + array( + 'id' => 1, + 'name' => $this->l('Disable carrier') + ) + ), + 'id' => 'id', + 'name' => 'name' + ), + 'desc' => $this->l('Out-of-range behavior occurs when none is defined (e.g. when a customer\'s cart weight is greater than the highest range limit)') + ), + array( + 'type' => 'text', + 'label' => $this->l('Maximium package height:'), + 'name' => 'max_height', + 'required' => false, + 'size' => 10, + 'desc' => $this->l('Maximum height managed by this carrier. Set the value to "0," or leave this field blank to ignore.') + ), + array( + 'type' => 'text', + 'label' => $this->l('Maximium package width:'), + 'name' => 'max_width', + 'required' => false, + 'size' => 10, + 'desc' => $this->l('Maximum width managed by this carrier. Set the value to "0," or leave this field blank to ignore.') + ), + array( + 'type' => 'text', + 'label' => $this->l('Maximium package depth:'), + 'name' => 'max_depth', + 'required' => false, + 'size' => 10, + 'desc' => $this->l('Maximum depth managed by this carrier. Set the value to "0," or leave this field blank to ignore.') + ), + array( + 'type' => 'text', + 'label' => $this->l('Maximium package weight:'), + 'name' => 'max_weight', + 'required' => false, + 'size' => 10, + 'desc' => $this->l('Maximum weight managed by this carrier. Set the value to "0," or leave this field blank to ignore.') + ), + ) + )); + $fields_value = $this->getStepFourFieldsValues($carrier); + return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value); + } + + public function renderGenericForm($fields_form, $fields_value, $tpl_vars = array()) { $helper = new HelperForm(); + $helper->show_toolbar = false; $helper->default_form_language = $this->context->language->id; $helper->allow_employee_form_lang = 1; $this->fields_form = array(); - $helper->tpl_vars = array( + $helper->tpl_vars = array_merge(array( 'fields_value' => $fields_value, 'languages' => $this->getLanguages(), - 'id_language' => 1 - ); - return $helper->generateForm(array('form' => $fields_form)); - } - - public function getStep1FieldsValues($carrier) + 'id_language' => $this->context->language->id + ), $tpl_vars); + $helper->override_folder = 'carrier_wizard/'; + + return $helper->generateForm($fields_form); + } + + public function getStepOneFieldsValues($carrier) { return array( - 'name' => $this->getFieldsValue($carrier, 'name'), - 'delay' => $this->getFieldsValue($carrier, 'delay'), - 'grade' => $this->getFieldsValue($carrier, 'grade'), + 'name' => $this->getFieldValue($carrier, 'name'), + 'delay' => $this->getFieldValue($carrier, 'delay'), + 'grade' => $this->getFieldValue($carrier, 'grade'), 'logo' => '', - 'url' => $this->getFieldsValue($carrier, 'url'), + 'url' => $this->getFieldValue($carrier, 'url'), + ); + } + + public function getStepTowFieldsValues($carrier) + { + return array('shop' => $this->getFieldValue($carrier, 'shop')); + + } + + public function getStepThreeFieldsValues($carrier) + { + return array( + 'is_free' => $this->getFieldValue($carrier, 'is_free'), + 'id_tax_rules_group' => $this->getFieldValue($carrier, 'id_tax_rules_group'), + 'shipping_handling' => $this->getFieldValue($carrier, 'shipping_handling'), + 'shipping_method' => $this->getFieldValue($carrier, 'shipping_method'), + 'range_behavior' => $this->getFieldValue($carrier, 'range_behavior'), + ); + + } + + public function getStepFourFieldsValues($carrier) + { + return array( + 'range_behavior' => $this->getFieldValue($carrier, 'shop'), + 'max_height' => $this->getFieldValue($carrier, 'max_height'), + 'max_width' => $this->getFieldValue($carrier, 'max_width'), + 'max_depth' => $this->getFieldValue($carrier, 'max_depth'), + 'max_weight' => $this->getFieldValue($carrier, 'max_weight'), ); + } + + public function ajaxProcessValidateStep() + { + $step_number = (int)Tools::getValue('step_number'); + $this->validateRules('AdminCarrierWizardControllerCore'); + + $return = array('has_error' => false); + + if (count($this->errors)) + { + $return['has_error'] = true; + $return['errors'] = $this->errors; + } + die(Tools::jsonEncode($return)); + } + + public static function getValidationRules() + { + $step_number = Tools::getValue('step_number'); + $step_fields = array( + 1 => array('name', 'delay', 'grade', 'url'), + 2 => array('is_free', 'id_tax_rules_group', 'shipping_handling', 'shipping_method', 'range_behavior'), + 3 => array('range_behavior', 'max_height', 'max_width', 'max_depth', 'max_weight'), + ); + + switch ($step_number) + { + case 1: + $rules = Carrier::getValidationRules('Carrier'); + break; + case 2: + $rules = Carrier::getValidationRules('Carrier'); + break; + } + + foreach ($rules as $key_r => $rule) + foreach ($rule as $key_f => $field) + if (!in_array($field, $step_fields[$step_number])) + unset($rules[$key_r][$key_f]); + return $rules; +/* + 'carrier' => Carrier::getValidationRules('Carrier'), + 'range_price' => RangePrice::getValidationRules('RangePrice'), + 'range_weight' => RangeWeight::getValidationRules('RangeWeight'), + +*/ + } + + public static function displayFieldName($field) + { + return $field; } } \ No newline at end of file diff --git a/css/admin.css b/css/admin.css index 8011b9362..10566f104 100644 --- a/css/admin.css +++ b/css/admin.css @@ -2493,3 +2493,8 @@ margin-bottom:7px; #carrier_wizard.swMain .stepContainer div.content{width:99%} #carrier_wizard.swMain div.actionBar{width:99.5%} + +.border_top {border-top:solid 1px #C0C0C0;} +.border_bottom {border-bottom:solid 1px #C0C0C0;} +.border_left {border-left:solid 1px #C0C0C0;} +.border_right {border-right:solid 1px #C0C0C0;} diff --git a/js/admin_carrier_wizard.js b/js/admin_carrier_wizard.js new file mode 100644 index 000000000..e4c3f50fa --- /dev/null +++ b/js/admin_carrier_wizard.js @@ -0,0 +1,148 @@ +/* +* 2007-2013 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + + +$(document).ready(function() { + + bind_inputs(); + initCarrierWizard(); + +}); + +function initCarrierWizard() +{ + $("#carrier_wizard").smartWizard({ + 'labelNext' : labelNext, + 'labelPrevious' : labelPrevious, + 'labelFinish' : labelFinish, + 'fixHeight' : 1, + 'onShowStep' : onShowStepCallback, + 'onLeaveStep' : leaveStepCallback, + }); +} + +function onShowStepCallback() +{ + $('.anchor li a').each( function () { + $(this).parent('li').addClass($(this).attr('class')); + }); + resizeWizard(); +} + +function leaveStepCallback(obj, context) +{ + return validateSteps(context.fromStep); // return false to stay on step and true to continue navigation +} + +function validateSteps(step_number){ + var step_valid = true; + + form = $('#carrier_wizard #step-'+step_number+' form'); + +/* + switch(step_number) + { + case 1: + + break; + case 2: + + break; + default: + return false; + } +*/ + + $.ajax({ + type:"POST", + url : validate_url, + async: true, + dataType: 'json', + data : form.serialize()+'&step_number='+step_number+'&action=validate_step&ajax=1', + success : function(datas) + { + if (datas.has_error) + { + for (var error in datas.errors) + { + $('#carrier_wizard').smartWizard('setError',{stepnum:step_number,iserror:true}); + $('input[name="'+error+'"]').css({'border' : 'solid 1px red', 'background-color' : '#FFCCCC'}); + $("#carrier_wizard") + + } + return false; + } + + } + }); + return true; +} + +function resizeWizard() +{ + resizeInterval = setInterval(function (){$("#carrier_wizard").smartWizard('fixHeight'); clearInterval(resizeInterval)}, 100); +} + +function bind_inputs() +{ + $('a#add_new_range').bind('click', function () { + add_new_range(); + }); + + $('tr.zones_delete td button').each( function () { + $(this).bind('click', function () { + + return false; + }); + }); +} + + +function add_new_range() +{ + $('.zones td input:checkbox').removeAttr('disabled'); + $('td#range_limit').children('table').show(); + $('tr#new_range_form_placeholder').children('td:last').after(''+$('#new_range_form').html()+'
    '); + $('tr.zones').each( function () { + $(this).children('td:eq(1)').removeClass('border_right'); + $(this).children('td:last').after(''); + }); + $('tr.zones_delete:last').children('td:last').after(''); + resizeWizard(); + bind_inputs(); + return false; +} + +function delete_new_range() +{ + if ($('#new_range_form_placeholder').children('td').length = 1) + return false; +} + +function setInputRangeId() +{ + + +} \ No newline at end of file