form.tpl 3.82 KB
Newer Older
1
{**
Pierre RAMBAUD's avatar
Pierre RAMBAUD committed
2
3
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
4
5
6
7
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
Pierre RAMBAUD's avatar
Pierre RAMBAUD committed
8
 * that is bundled with this package in the file LICENSE.md.
9
 * It is also available through the world-wide-web at this URL:
10
 * https://opensource.org/licenses/OSL-3.0
11
12
13
14
15
16
17
18
 * 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
Pierre RAMBAUD's avatar
Pierre RAMBAUD committed
19
 * needs please refer to https://devdocs.prestashop.com/ for more information.
20
 *
Pierre RAMBAUD's avatar
Pierre RAMBAUD committed
21
22
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
23
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
24
 *}
25
{extends file="helpers/form/form.tpl"}
26

27
{block name="label"}
tDidierjean's avatar
tDidierjean committed
28
	{if $input.name == 'zipcode' && isset($input.label)}
29
		<label id="zipcode-label" class="control-label col-lg-4">{$input.label}</label>
tDidierjean's avatar
tDidierjean committed
30
	{elseif $input.name == 'states[]'}
31
		<label id="states-label" class="control-label col-lg-4">{$input.label}</label>
tDidierjean's avatar
tDidierjean committed
32
33
	{else}
		{$smarty.block.parent}
34
35
36
37
	{/if}
{/block}

{block name="script"}
tDidierjean's avatar
tDidierjean committed
38
	$(document).ready(function() {
39
		$('#country').change(function() {
tDidierjean's avatar
tDidierjean committed
40
41
			populateStates($(this).val(), '');
		});
42

Jerome Nadaud's avatar
Jerome Nadaud committed
43
44
45
		$('#id_tax_rules_group').clone().attr('id', '').insertAfter('#id_tax_rule');


46
47
		if ($('#id_tax_rules_group').val() != '' && $('table.tax_rule tbody tr').length == 0)
		{
Jerome Nadaud's avatar
Jerome Nadaud committed
48
			initForm();
49
50
51
52
			$('#tax_rule_form').show();
			$('#country').focus();
		}
		else
Jerome Nadaud's avatar
Jerome Nadaud committed
53
		{
54
			$('#tax_rule_form').hide();
Jerome Nadaud's avatar
Jerome Nadaud committed
55
56
57
58
59
60
			$('#page-header-desc-tax_rule-new').click(function() {
				initForm();
				$('#tax_rule_form').slideToggle();
				return false;
			});
		}
tDidierjean's avatar
tDidierjean committed
61
	});
62

tDidierjean's avatar
tDidierjean committed
63
64
65
	function populateStates(id_country, id_state)
	{
		if ($("#country option:selected").size() > 1)
66
		{
tDidierjean's avatar
tDidierjean committed
67
68
69
70
71
72
			$("#zipcode-label").hide();
			$("#zipcode").hide();

			$("#states").parent().hide();
			$("#states-label").hide();
		} else {
73
			$.ajax({
Rémi Gaillard's avatar
Rémi Gaillard committed
74
				url: "index.php",
tDidierjean's avatar
tDidierjean committed
75
				cache: false,
76
				data: "ajax=1&tab=AdminStates&token={getAdminToken tab='AdminStates'}&action=states&id_country="+id_country+"&id_state="+id_state+"&empty_value={l s='All' d='Admin.Global'}",
tDidierjean's avatar
tDidierjean committed
77
78
79
80
81
82
83
84
				success: function(html){
					if (html == "false")
					{
						$("#states").parent().hide();
						$("#states-label").hide();
						$("#states").html('');
					}
					else
85
					{
tDidierjean's avatar
tDidierjean committed
86
87
88
						$("#states").parent().show();
						$("#states-label").show();
						$("#states").html(html);
89
90
91
					}
				}
			});
tDidierjean's avatar
tDidierjean committed
92
93
94

			$("#zipcode-label").show();
			$("#zipcode").show();
95
		}
tDidierjean's avatar
tDidierjean committed
96
97
98
99
100
101
	}

	function loadTaxRule(id_tax_rule)
	{
		$.ajax({
			type: 'POST',
Rémi Gaillard's avatar
Rémi Gaillard committed
102
			url: 'index.php',
tDidierjean's avatar
tDidierjean committed
103
104
			async: true,
			dataType: 'json',
Rémi Gaillard's avatar
Rémi Gaillard committed
105
			data: 'ajax=1&tab=AdminTaxRulesGroup&token={getAdminToken tab='AdminTaxRulesGroup'}&ajaxStates=1&action=updateTaxRule&id_tax_rule='+id_tax_rule,
tDidierjean's avatar
tDidierjean committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
			success: function(data){
				$('#tax_rule_form').show();
				$('#id_tax_rule').val(data.id);
				$('#country').val(data.id_country);
				$('#state').val(data.id_state);

				zipcode = 0;
				if (data.zipcode_from != 0)
				{
					zipcode = data.zipcode_from;

					if (data.zipcode_to != 0)
						zipcode = zipcode +"-"+data.zipcode_to
				}

				$('#zipcode').val(zipcode);
				$('#behavior').val(data.behavior);
				$('#id_tax').val(data.id_tax);
				$('#description').val(data.description);

				populateStates(data.id_country, data.id_state);
			}
		});
	}

	function initForm()
	{
		$('#id_tax_rule').val('');
		$('#country').val(0);
		$('#state').val(0);
		$('#zipcode').val(0);
		$('#behavior').val(0);
		$('#tax').val(0);
		$('#description').val('');

		populateStates(0,0);
	}
143
{/block}