PluginProbe
Tiered Pricing Table for WooCommerce / 6.1.0
Tiered Pricing Table for WooCommerce v6.1.0
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / assets / admin / settings.js

settings.js in Tiered Pricing Table for WooCommerce 6.1.0, at assets/admin/settings.js

251 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function ($) {
2
3 const TieredPricingSettingsPage = function () {
4 this.rows = [];
5
6 this.init = function (rows) {
7 this.rows = rows;
8 this.renderSettings();
9 }
10
11 this.getRowById = function (id) {
12 return this.rows.find((row) => row.id = id);
13 }
14
15 this.renderSettings = function () {
16 this.rows.forEach(row => row.showBeShown() ? row.show() : row.hide());
17 }
18 }
19
20 const TieredPricingSettingsRow = function (id, dependencies = {}) {
21 this.prefix = 'tier_pricing_table_';
22 this.id = id;
23 this.settingsPage = null;
24 this.dependencies = dependencies;
25
26 this.init = function (settingsPage) {
27 this.settingsPage = settingsPage;
28 this.$getRow(false).on('change', () => this.settingsPage.renderSettings());
29 }
30
31 this.show = function () {
32 this.$getRow().closest('tr').show();
33 }
34
35 this.hide = function () {
36 this.$getRow().closest('tr').hide();
37 }
38
39 this.isChecked = function () {
40 return this.$getRow().is(':checked');
41 }
42
43 this.isValueEqual = function (value) {
44
45 return this.$getRow().val() === value;
46 }
47
48 this.showBeShown = function () {
49
50 let pass = true;
51
52 for (const [rowID, value] of Object.entries(this.dependencies)) {
53 const row = this.settingsPage.getRowById(rowID);
54
55 if (!row) {
56 continue;
57 }
58
59 if (value === ':checked') {
60 pass = pass && row.isChecked();
61 continue;
62 }
63
64
65 if (value === ':unchecked') {
66 pass = pass && !row.isChecked();
67 continue;
68 }
69
70 // there is multiple values to pass
71 if (typeof value === 'string') {
72 pass = pass && row.isValueEqual(value);
73 continue;
74 }
75
76 // there is multiple values to pass
77 if (value.constructor === Array) {
78
79 let _pass = false;
80
81 value.forEach((_value) => {
82 _pass = _pass || row.isValueEqual(_value);
83 });
84 pass = pass && _pass;
85 }
86 }
87 return pass;
88 }
89
90 this.$getRow = function (any = true) {
91 let input = $('[name=' + this.prefix + this.id + ']');
92
93 if (any && input.is(':radio')) {
94 input = input.filter(':checked');
95 }
96
97 return input;
98 }
99 }
100
101 // Product Page Option
102 const display = new TieredPricingSettingsRow('display');
103 const displayTypeRow = new TieredPricingSettingsRow('display_type', {
104 'display': ':checked'
105 });
106 const quantityType = new TieredPricingSettingsRow('quantity_type', {
107 'display': ':checked'
108 });
109 const tooltipColor = new TieredPricingSettingsRow('tooltip_color', {
110 'display': ':checked',
111 'display_type': 'tooltip'
112 });
113 const tooltipSize = new TieredPricingSettingsRow('tooltip_size', {
114 'display': ':checked',
115 'display_type': 'tooltip'
116 });
117 const tooltipBorder = new TieredPricingSettingsRow('tooltip_border', {
118 'display': ':checked',
119 'display_type': 'tooltip'
120 });
121 const pricingTitle = new TieredPricingSettingsRow('table_title', {
122 'display': ':checked',
123 'display_type': ['blocks', 'table', 'options']
124 });
125 const pricingPlace = new TieredPricingSettingsRow('position_hook', {
126 'display': ':checked',
127 'display_type': ['blocks', 'table', 'options']
128 });
129 const activeTierColor = new TieredPricingSettingsRow('selected_quantity_color', {
130 'display': ':checked',
131 });
132 const quantityColumnTitle = new TieredPricingSettingsRow('head_quantity_text', {
133 'display': ':checked',
134 'display_type': ['tooltip', 'table']
135 });
136 const priceColumnTitle = new TieredPricingSettingsRow('head_price_text', {
137 'display': ':checked',
138 'display_type': ['tooltip', 'table']
139 });
140 const showDiscountColumn = new TieredPricingSettingsRow('show_discount_column', {
141 'display': ':checked',
142 'display_type': ['blocks', 'table', 'tooltip']
143 });
144 const discountColumnTitle = new TieredPricingSettingsRow('head_discount_text', {
145 'display': ':checked',
146 'show_discount_column': ':checked',
147 'display_type': ['tooltip', 'table']
148 });
149 const showTotalPrice = new TieredPricingSettingsRow('show_total_price', {
150 'tiered_price_at_product_page': ':unchecked',
151 });
152
153 const OPTIONS_optionText = new TieredPricingSettingsRow('options_option_text', {
154 'display': ':checked',
155 'display_type': 'options'
156 });
157
158 const OPTIONS_showDefaultOption = new TieredPricingSettingsRow('options_show_default_option', {
159 'display': ':checked',
160 'display_type': 'options'
161 });
162
163 const OPTIONS_defaultOptionText = new TieredPricingSettingsRow('options_default_option_text', {
164 'display': ':checked',
165 'options_show_default_option': ':checked',
166 'display_type': 'options',
167 });
168
169 const OPTIONS_showOriginalProductPrice = new TieredPricingSettingsRow('options_show_original_product_price', {
170 'display': ':checked',
171 'display_type': 'options'
172 });
173
174 const OPTIONS_showTotal = new TieredPricingSettingsRow('options_show_total', {
175 'display': ':checked',
176 'display_type': 'options'
177 });
178
179 // Catalog prices
180 const catalogPrices = new TieredPricingSettingsRow('tiered_price_at_catalog');
181 const catalogPricesForVariableProducts = new TieredPricingSettingsRow('tiered_price_at_catalog_for_variable', {
182 'tiered_price_at_catalog': ':checked'
183 });
184 const catalogPricesForVariableProductsCache = new TieredPricingSettingsRow('tiered_price_at_catalog_cache_for_variable', {
185 'tiered_price_at_catalog': ':checked',
186 'tiered_price_at_catalog_for_variable': ':checked'
187 });
188 const catalogPricesForProductPage = new TieredPricingSettingsRow('tiered_price_at_product_page', {
189 'tiered_price_at_catalog': ':checked',
190 'show_total_price': ':unchecked',
191 });
192 const catalogPricesType = new TieredPricingSettingsRow('tiered_price_at_catalog_type', {
193 'tiered_price_at_catalog': ':checked'
194 });
195 const lowestPricePrefix = new TieredPricingSettingsRow('lowest_prefix', {
196 'tiered_price_at_catalog': ':checked',
197 'tiered_price_at_catalog_type': 'lowest'
198 });
199
200 // Cart
201 const cartUpsellEnabled = new TieredPricingSettingsRow('cart_upsell_enabled');
202 const cartUpsellTemplate = new TieredPricingSettingsRow('cart_upsell_template', {
203 'cart_upsell_enabled': ':checked'
204 });
205 const cartUpsellColor = new TieredPricingSettingsRow('cart_upsell_color', {
206 'cart_upsell_enabled': ':checked'
207 });
208
209 // Summary block
210 const displaySummary = new TieredPricingSettingsRow('display_summary');
211 const summaryTitle = new TieredPricingSettingsRow('summary_title', {
212 'display_summary': ':checked'
213 });
214 const summaryType = new TieredPricingSettingsRow('summary_type', {
215 'display_summary': ':checked'
216 });
217 const summaryTotalLabel = new TieredPricingSettingsRow('summary_total_label', {
218 'display_summary': ':checked',
219 'summary_type': 'inline',
220 });
221 const summaryEachLabel = new TieredPricingSettingsRow('summary_each_label', {
222 'display_summary': ':checked',
223 'summary_type': 'inline',
224 });
225 const summaryPosition = new TieredPricingSettingsRow('summary_position_hook', {
226 'display_summary': ':checked',
227 });
228
229 let rows = [
230 // product page
231 display, displayTypeRow, quantityType, tooltipColor, tooltipSize, tooltipBorder, pricingTitle, pricingPlace,
232 activeTierColor, quantityColumnTitle, priceColumnTitle, showDiscountColumn, discountColumnTitle, showTotalPrice,
233 OPTIONS_optionText, OPTIONS_showDefaultOption, OPTIONS_defaultOptionText, OPTIONS_showOriginalProductPrice, OPTIONS_showTotal,
234 // Catalog prices
235 catalogPrices, catalogPricesForVariableProducts, catalogPricesForVariableProductsCache, catalogPricesForProductPage,
236 catalogPricesType, lowestPricePrefix,
237
238 //Cart
239 cartUpsellEnabled, cartUpsellTemplate, cartUpsellColor,
240
241 // Summary block
242 displaySummary, summaryTitle, summaryType, summaryTotalLabel, summaryEachLabel, summaryPosition
243 ];
244
245 const productPageSettingPage = new TieredPricingSettingsPage();
246
247 rows.forEach(row => row.init(productPageSettingPage));
248
249 productPageSettingPage.init(rows);
250 });
251