Version Description
- Improvement: woocommerce checkout manager
- Improvement: woocommerce checkout number field type
Download this release
Release Info
Developer | quadlayers |
Plugin | WooCommerce Checkout Manager |
Version | 5.0.7 |
Comparing to | |
See all releases |
Code changes from version 5.0.6 to 5.0.7
- assets/backend/jquery-serializejson/jquery-serializejson.js +393 -0
- assets/backend/jquery-serializejson/jquery-serializejson.min.js +10 -0
- assets/backend/js/wooccm-admin-field.js +180 -178
- assets/backend/js/wooccm-admin-field.min.js +1 -1
- assets/frontend/css/wooccm.min.css +1 -2
- assets/frontend/js/wooccm-checkout.min.js +1 -1
- assets/frontend/js/wooccm-order-upload.min.js +1 -1
- includes/{class-wooccm-admin.php → class-wooccm-backend.php} +25 -21
- includes/class-wooccm-compatibility.php +184 -177
- includes/class-wooccm-notices.php +26 -25
- includes/class-wooccm-upload.php +35 -33
- includes/class-wooccm.php +81 -67
- includes/controller/class-wooccm-advanced.php +75 -72
- includes/controller/class-wooccm-checkout.php +184 -169
- includes/controller/class-wooccm-controller.php +25 -0
- includes/controller/class-wooccm-email.php +91 -89
- includes/controller/class-wooccm-field-additional.php +8 -16
- includes/controller/class-wooccm-field-billing.php +7 -16
- includes/controller/class-wooccm-field-shipping.php +23 -25
- includes/controller/class-wooccm-field.php +105 -104
- includes/controller/class-wooccm-order.php +143 -130
- includes/controller/class-wooccm-premium.php +24 -25
- includes/controller/class-wooccm-suggestions.php +19 -18
- includes/model/class-wooccm-field-additional.php +1 -1
- includes/model/class-wooccm-field-billing.php +1 -1
- includes/model/class-wooccm-field-shipping.php +1 -1
- includes/model/class-wooccm-field.php +217 -314
- includes/model/class-wooccm-model.php +163 -0
- includes/view/backend/pages/modals/parts/panel-general.php +13 -0
- includes/view/backend/pages/suggestions.php +14 -0
- includes/view/frontend/class-wooccm-fields-additional.php +64 -62
- includes/view/frontend/class-wooccm-fields-conditional.php +15 -15
- includes/view/frontend/class-wooccm-fields-disable.php +20 -20
- includes/view/frontend/class-wooccm-fields-handler.php +62 -47
- includes/view/frontend/class-wooccm-fields-i18n.php +15 -13
- includes/view/frontend/class-wooccm-fields-register.php +31 -30
- readme.txt +8 -4
- woocommerce-checkout-manager.php +10 -4
assets/backend/jquery-serializejson/jquery-serializejson.js
ADDED
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*!
|
2 |
+
SerializeJSON jQuery plugin.
|
3 |
+
https://github.com/marioizquierdo/jquery.serializeJSON
|
4 |
+
version 2.9.0 (Jan, 2018)
|
5 |
+
Copyright (c) 2012-2018 Mario Izquierdo
|
6 |
+
Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
|
7 |
+
and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
|
8 |
+
*/
|
9 |
+
(function (factory) {
|
10 |
+
if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module.
|
11 |
+
define(['jquery'], factory);
|
12 |
+
} else if (typeof exports === 'object') { // Node/CommonJS
|
13 |
+
var jQuery = require('jquery');
|
14 |
+
module.exports = factory(jQuery);
|
15 |
+
} else { // Browser globals (zepto supported)
|
16 |
+
factory(window.jQuery || window.Zepto || window.$); // Zepto supported on browsers as well
|
17 |
+
}
|
18 |
+
|
19 |
+
}(function ($) {
|
20 |
+
"use strict";
|
21 |
+
|
22 |
+
// jQuery('form').serializeJSON()
|
23 |
+
$.fn.serializeJSON = function (options) {
|
24 |
+
var f, $form, opts, formAsArray, serializedObject, name, value, parsedValue, _obj, nameWithNoType, type, keys, skipFalsy;
|
25 |
+
f = $.serializeJSON;
|
26 |
+
$form = this; // NOTE: the set of matched elements is most likely a form, but it could also be a group of inputs
|
27 |
+
opts = f.setupOpts(options); // calculate values for options {parseNumbers, parseBoolens, parseNulls, ...} with defaults
|
28 |
+
|
29 |
+
// Use native `serializeArray` function to get an array of {name, value} objects.
|
30 |
+
formAsArray = $form.serializeArray();
|
31 |
+
f.readCheckboxUncheckedValues(formAsArray, opts, $form); // add objects to the array from unchecked checkboxes if needed
|
32 |
+
|
33 |
+
// Convert the formAsArray into a serializedObject with nested keys
|
34 |
+
serializedObject = {};
|
35 |
+
$.each(formAsArray, function (i, obj) {
|
36 |
+
name = obj.name; // original input name
|
37 |
+
value = obj.value; // input value
|
38 |
+
_obj = f.extractTypeAndNameWithNoType(name);
|
39 |
+
nameWithNoType = _obj.nameWithNoType; // input name with no type (i.e. "foo:string" => "foo")
|
40 |
+
type = _obj.type; // type defined from the input name in :type colon notation
|
41 |
+
if (!type)
|
42 |
+
type = f.attrFromInputWithName($form, name, 'data-value-type');
|
43 |
+
f.validateType(name, type, opts); // make sure that the type is one of the valid types if defined
|
44 |
+
|
45 |
+
if (type !== 'skip') { // ignore inputs with type 'skip'
|
46 |
+
keys = f.splitInputNameIntoKeysArray(nameWithNoType);
|
47 |
+
parsedValue = f.parseValue(value, name, type, opts); // convert to string, number, boolean, null or customType
|
48 |
+
|
49 |
+
skipFalsy = !parsedValue && f.shouldSkipFalsy($form, name, nameWithNoType, type, opts); // ignore falsy inputs if specified
|
50 |
+
if (!skipFalsy) {
|
51 |
+
f.deepSet(serializedObject, keys, parsedValue, opts);
|
52 |
+
}
|
53 |
+
}
|
54 |
+
});
|
55 |
+
return serializedObject;
|
56 |
+
};
|
57 |
+
|
58 |
+
// Use $.serializeJSON as namespace for the auxiliar functions
|
59 |
+
// and to define defaults
|
60 |
+
$.serializeJSON = {
|
61 |
+
|
62 |
+
defaultOptions: {
|
63 |
+
checkboxUncheckedValue: undefined, // to include that value for unchecked checkboxes (instead of ignoring them)
|
64 |
+
|
65 |
+
parseNumbers: false, // convert values like "1", "-2.33" to 1, -2.33
|
66 |
+
parseBooleans: false, // convert "true", "false" to true, false
|
67 |
+
parseNulls: false, // convert "null" to null
|
68 |
+
parseAll: false, // all of the above
|
69 |
+
parseWithFunction: null, // to use custom parser, a function like: function(val){ return parsed_val; }
|
70 |
+
|
71 |
+
skipFalsyValuesForTypes: [], // skip serialization of falsy values for listed value types
|
72 |
+
skipFalsyValuesForFields: [], // skip serialization of falsy values for listed field names
|
73 |
+
|
74 |
+
customTypes: {}, // override defaultTypes
|
75 |
+
defaultTypes: {
|
76 |
+
"string": function (str) {
|
77 |
+
return String(str);
|
78 |
+
},
|
79 |
+
"number": function (str) {
|
80 |
+
return Number(str);
|
81 |
+
},
|
82 |
+
"boolean": function (str) {
|
83 |
+
var falses = ["false", "null", "undefined", "", "0"];
|
84 |
+
return falses.indexOf(str) === -1;
|
85 |
+
},
|
86 |
+
"null": function (str) {
|
87 |
+
var falses = ["false", "null", "undefined", "", "0"];
|
88 |
+
return falses.indexOf(str) === -1 ? str : null;
|
89 |
+
},
|
90 |
+
"array": function (str) {
|
91 |
+
return JSON.parse(str);
|
92 |
+
},
|
93 |
+
"object": function (str) {
|
94 |
+
return JSON.parse(str);
|
95 |
+
},
|
96 |
+
"auto": function (str) {
|
97 |
+
return $.serializeJSON.parseValue(str, null, null, {parseNumbers: true, parseBooleans: true, parseNulls: true});
|
98 |
+
}, // try again with something like "parseAll"
|
99 |
+
"skip": null // skip is a special type that makes it easy to ignore elements
|
100 |
+
},
|
101 |
+
|
102 |
+
useIntKeysAsArrayIndex: false // name="foo[2]" value="v" => {foo: [null, null, "v"]}, instead of {foo: ["2": "v"]}
|
103 |
+
},
|
104 |
+
|
105 |
+
// Merge option defaults into the options
|
106 |
+
setupOpts: function (options) {
|
107 |
+
var opt, validOpts, defaultOptions, optWithDefault, parseAll, f;
|
108 |
+
f = $.serializeJSON;
|
109 |
+
|
110 |
+
if (options == null) {
|
111 |
+
options = {};
|
112 |
+
} // options ||= {}
|
113 |
+
defaultOptions = f.defaultOptions || {}; // defaultOptions
|
114 |
+
|
115 |
+
// Make sure that the user didn't misspell an option
|
116 |
+
validOpts = ['checkboxUncheckedValue', 'parseNumbers', 'parseBooleans', 'parseNulls', 'parseAll', 'parseWithFunction', 'skipFalsyValuesForTypes', 'skipFalsyValuesForFields', 'customTypes', 'defaultTypes', 'useIntKeysAsArrayIndex']; // re-define because the user may override the defaultOptions
|
117 |
+
for (opt in options) {
|
118 |
+
if (validOpts.indexOf(opt) === -1) {
|
119 |
+
throw new Error("serializeJSON ERROR: invalid option '" + opt + "'. Please use one of " + validOpts.join(', '));
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
// Helper to get the default value for this option if none is specified by the user
|
124 |
+
optWithDefault = function (key) {
|
125 |
+
return (options[key] !== false) && (options[key] !== '') && (options[key] || defaultOptions[key]);
|
126 |
+
};
|
127 |
+
|
128 |
+
// Return computed options (opts to be used in the rest of the script)
|
129 |
+
parseAll = optWithDefault('parseAll');
|
130 |
+
return {
|
131 |
+
checkboxUncheckedValue: optWithDefault('checkboxUncheckedValue'),
|
132 |
+
|
133 |
+
parseNumbers: parseAll || optWithDefault('parseNumbers'),
|
134 |
+
parseBooleans: parseAll || optWithDefault('parseBooleans'),
|
135 |
+
parseNulls: parseAll || optWithDefault('parseNulls'),
|
136 |
+
parseWithFunction: optWithDefault('parseWithFunction'),
|
137 |
+
|
138 |
+
skipFalsyValuesForTypes: optWithDefault('skipFalsyValuesForTypes'),
|
139 |
+
skipFalsyValuesForFields: optWithDefault('skipFalsyValuesForFields'),
|
140 |
+
typeFunctions: $.extend({}, optWithDefault('defaultTypes'), optWithDefault('customTypes')),
|
141 |
+
|
142 |
+
useIntKeysAsArrayIndex: optWithDefault('useIntKeysAsArrayIndex')
|
143 |
+
};
|
144 |
+
},
|
145 |
+
|
146 |
+
// Given a string, apply the type or the relevant "parse" options, to return the parsed value
|
147 |
+
parseValue: function (valStr, inputName, type, opts) {
|
148 |
+
var f, parsedVal;
|
149 |
+
f = $.serializeJSON;
|
150 |
+
parsedVal = valStr; // if no parsing is needed, the returned value will be the same
|
151 |
+
|
152 |
+
if (opts.typeFunctions && type && opts.typeFunctions[type]) { // use a type if available
|
153 |
+
parsedVal = opts.typeFunctions[type](valStr);
|
154 |
+
} else if (opts.parseNumbers && f.isNumeric(valStr)) { // auto: number
|
155 |
+
parsedVal = Number(valStr);
|
156 |
+
} else if (opts.parseBooleans && (valStr === "true" || valStr === "false")) { // auto: boolean
|
157 |
+
parsedVal = (valStr === "true");
|
158 |
+
} else if (opts.parseNulls && valStr == "null") { // auto: null
|
159 |
+
parsedVal = null;
|
160 |
+
} else if (opts.typeFunctions && opts.typeFunctions["string"]) { // make sure to apply :string type if it was re-defined
|
161 |
+
parsedVal = opts.typeFunctions["string"](valStr);
|
162 |
+
}
|
163 |
+
|
164 |
+
// Custom parse function: apply after parsing options, unless there's an explicit type.
|
165 |
+
if (opts.parseWithFunction && !type) {
|
166 |
+
parsedVal = opts.parseWithFunction(parsedVal, inputName);
|
167 |
+
}
|
168 |
+
|
169 |
+
return parsedVal;
|
170 |
+
},
|
171 |
+
|
172 |
+
isObject: function (obj) {
|
173 |
+
return obj === Object(obj);
|
174 |
+
}, // is it an Object?
|
175 |
+
isUndefined: function (obj) {
|
176 |
+
return obj === void 0;
|
177 |
+
}, // safe check for undefined values
|
178 |
+
isValidArrayIndex: function (val) {
|
179 |
+
return /^[0-9]+$/.test(String(val));
|
180 |
+
}, // 1,2,3,4 ... are valid array indexes
|
181 |
+
isNumeric: function (obj) {
|
182 |
+
return obj - parseFloat(obj) >= 0;
|
183 |
+
}, // taken from jQuery.isNumeric implementation. Not using jQuery.isNumeric to support old jQuery and Zepto versions
|
184 |
+
|
185 |
+
optionKeys: function (obj) {
|
186 |
+
if (Object.keys) {
|
187 |
+
return Object.keys(obj);
|
188 |
+
} else {
|
189 |
+
var key, keys = [];
|
190 |
+
for (key in obj) {
|
191 |
+
keys.push(key);
|
192 |
+
}
|
193 |
+
return keys;
|
194 |
+
}
|
195 |
+
}, // polyfill Object.keys to get option keys in IE<9
|
196 |
+
|
197 |
+
|
198 |
+
// Fill the formAsArray object with values for the unchecked checkbox inputs,
|
199 |
+
// using the same format as the jquery.serializeArray function.
|
200 |
+
// The value of the unchecked values is determined from the opts.checkboxUncheckedValue
|
201 |
+
// and/or the data-unchecked-value attribute of the inputs.
|
202 |
+
readCheckboxUncheckedValues: function (formAsArray, opts, $form) {
|
203 |
+
var selector, $uncheckedCheckboxes, $el, uncheckedValue, f, name;
|
204 |
+
if (opts == null) {
|
205 |
+
opts = {};
|
206 |
+
}
|
207 |
+
f = $.serializeJSON;
|
208 |
+
|
209 |
+
selector = 'input[type=checkbox][name]:not(:checked):not([disabled])';
|
210 |
+
$uncheckedCheckboxes = $form.find(selector).add($form.filter(selector));
|
211 |
+
$uncheckedCheckboxes.each(function (i, el) {
|
212 |
+
// Check data attr first, then the option
|
213 |
+
$el = $(el);
|
214 |
+
uncheckedValue = $el.attr('data-unchecked-value');
|
215 |
+
if (uncheckedValue == null) {
|
216 |
+
uncheckedValue = opts.checkboxUncheckedValue;
|
217 |
+
}
|
218 |
+
|
219 |
+
// If there's an uncheckedValue, push it into the serialized formAsArray
|
220 |
+
if (uncheckedValue != null) {
|
221 |
+
if (el.name && el.name.indexOf("[][") !== -1) { // identify a non-supported
|
222 |
+
throw new Error("serializeJSON ERROR: checkbox unchecked values are not supported on nested arrays of objects like '" + el.name + "'. See https://github.com/marioizquierdo/jquery.serializeJSON/issues/67");
|
223 |
+
}
|
224 |
+
formAsArray.push({name: el.name, value: uncheckedValue});
|
225 |
+
}
|
226 |
+
});
|
227 |
+
},
|
228 |
+
|
229 |
+
// Returns and object with properties {name_without_type, type} from a given name.
|
230 |
+
// The type is null if none specified. Example:
|
231 |
+
// "foo" => {nameWithNoType: "foo", type: null}
|
232 |
+
// "foo:boolean" => {nameWithNoType: "foo", type: "boolean"}
|
233 |
+
// "foo[bar]:null" => {nameWithNoType: "foo[bar]", type: "null"}
|
234 |
+
extractTypeAndNameWithNoType: function (name) {
|
235 |
+
var match;
|
236 |
+
if (match = name.match(/(.*):([^:]+)$/)) {
|
237 |
+
return {nameWithNoType: match[1], type: match[2]};
|
238 |
+
} else {
|
239 |
+
return {nameWithNoType: name, type: null};
|
240 |
+
}
|
241 |
+
},
|
242 |
+
|
243 |
+
// Check if this input should be skipped when it has a falsy value,
|
244 |
+
// depending on the options to skip values by name or type, and the data-skip-falsy attribute.
|
245 |
+
shouldSkipFalsy: function ($form, name, nameWithNoType, type, opts) {
|
246 |
+
var f = $.serializeJSON;
|
247 |
+
|
248 |
+
var skipFromDataAttr = f.attrFromInputWithName($form, name, 'data-skip-falsy');
|
249 |
+
if (skipFromDataAttr != null) {
|
250 |
+
return skipFromDataAttr !== 'false'; // any value is true, except if explicitly using 'false'
|
251 |
+
}
|
252 |
+
|
253 |
+
var optForFields = opts.skipFalsyValuesForFields;
|
254 |
+
if (optForFields && (optForFields.indexOf(nameWithNoType) !== -1 || optForFields.indexOf(name) !== -1)) {
|
255 |
+
return true;
|
256 |
+
}
|
257 |
+
|
258 |
+
var optForTypes = opts.skipFalsyValuesForTypes;
|
259 |
+
if (type == null)
|
260 |
+
type = 'string'; // assume fields with no type are targeted as string
|
261 |
+
if (optForTypes && optForTypes.indexOf(type) !== -1) {
|
262 |
+
return true
|
263 |
+
}
|
264 |
+
|
265 |
+
return false;
|
266 |
+
},
|
267 |
+
|
268 |
+
// Finds the first input in $form with this name, and get the given attr from it.
|
269 |
+
// Returns undefined if no input or no attribute was found.
|
270 |
+
attrFromInputWithName: function ($form, name, attrName) {
|
271 |
+
var escapedName, selector, $input, attrValue;
|
272 |
+
escapedName = name.replace(/(:|\.|\[|\]|\s)/g, '\\$1'); // every non-standard character need to be escaped by \\
|
273 |
+
selector = '[name="' + escapedName + '"]';
|
274 |
+
$input = $form.find(selector).add($form.filter(selector)); // NOTE: this returns only the first $input element if multiple are matched with the same name (i.e. an "array[]"). So, arrays with different element types specified through the data-value-type attr is not supported.
|
275 |
+
return $input.attr(attrName);
|
276 |
+
},
|
277 |
+
|
278 |
+
// Raise an error if the type is not recognized.
|
279 |
+
validateType: function (name, type, opts) {
|
280 |
+
var validTypes, f;
|
281 |
+
f = $.serializeJSON;
|
282 |
+
validTypes = f.optionKeys(opts ? opts.typeFunctions : f.defaultOptions.defaultTypes);
|
283 |
+
if (!type || validTypes.indexOf(type) !== -1) {
|
284 |
+
return true;
|
285 |
+
} else {
|
286 |
+
throw new Error("serializeJSON ERROR: Invalid type " + type + " found in input name '" + name + "', please use one of " + validTypes.join(', '));
|
287 |
+
}
|
288 |
+
},
|
289 |
+
|
290 |
+
// Split the input name in programatically readable keys.
|
291 |
+
// Examples:
|
292 |
+
// "foo" => ['foo']
|
293 |
+
// "[foo]" => ['foo']
|
294 |
+
// "foo[inn][bar]" => ['foo', 'inn', 'bar']
|
295 |
+
// "foo[inn[bar]]" => ['foo', 'inn', 'bar']
|
296 |
+
// "foo[inn][arr][0]" => ['foo', 'inn', 'arr', '0']
|
297 |
+
// "arr[][val]" => ['arr', '', 'val']
|
298 |
+
splitInputNameIntoKeysArray: function (nameWithNoType) {
|
299 |
+
var keys, f;
|
300 |
+
f = $.serializeJSON;
|
301 |
+
keys = nameWithNoType.split('['); // split string into array
|
302 |
+
keys = $.map(keys, function (key) {
|
303 |
+
return key.replace(/\]/g, '');
|
304 |
+
}); // remove closing brackets
|
305 |
+
if (keys[0] === '') {
|
306 |
+
keys.shift();
|
307 |
+
} // ensure no opening bracket ("[foo][inn]" should be same as "foo[inn]")
|
308 |
+
return keys;
|
309 |
+
},
|
310 |
+
|
311 |
+
// Set a value in an object or array, using multiple keys to set in a nested object or array:
|
312 |
+
//
|
313 |
+
// deepSet(obj, ['foo'], v) // obj['foo'] = v
|
314 |
+
// deepSet(obj, ['foo', 'inn'], v) // obj['foo']['inn'] = v // Create the inner obj['foo'] object, if needed
|
315 |
+
// deepSet(obj, ['foo', 'inn', '123'], v) // obj['foo']['arr']['123'] = v //
|
316 |
+
//
|
317 |
+
// deepSet(obj, ['0'], v) // obj['0'] = v
|
318 |
+
// deepSet(arr, ['0'], v, {useIntKeysAsArrayIndex: true}) // arr[0] = v
|
319 |
+
// deepSet(arr, [''], v) // arr.push(v)
|
320 |
+
// deepSet(obj, ['arr', ''], v) // obj['arr'].push(v)
|
321 |
+
//
|
322 |
+
// arr = [];
|
323 |
+
// deepSet(arr, ['', v] // arr => [v]
|
324 |
+
// deepSet(arr, ['', 'foo'], v) // arr => [v, {foo: v}]
|
325 |
+
// deepSet(arr, ['', 'bar'], v) // arr => [v, {foo: v, bar: v}]
|
326 |
+
// deepSet(arr, ['', 'bar'], v) // arr => [v, {foo: v, bar: v}, {bar: v}]
|
327 |
+
//
|
328 |
+
deepSet: function (o, keys, value, opts) {
|
329 |
+
var key, nextKey, tail, lastIdx, lastVal, f;
|
330 |
+
if (opts == null) {
|
331 |
+
opts = {};
|
332 |
+
}
|
333 |
+
f = $.serializeJSON;
|
334 |
+
if (f.isUndefined(o)) {
|
335 |
+
throw new Error("ArgumentError: param 'o' expected to be an object or array, found undefined");
|
336 |
+
}
|
337 |
+
if (!keys || keys.length === 0) {
|
338 |
+
throw new Error("ArgumentError: param 'keys' expected to be an array with least one element");
|
339 |
+
}
|
340 |
+
|
341 |
+
key = keys[0];
|
342 |
+
|
343 |
+
// Only one key, then it's not a deepSet, just assign the value.
|
344 |
+
if (keys.length === 1) {
|
345 |
+
if (key === '') {
|
346 |
+
o.push(value); // '' is used to push values into the array (assume o is an array)
|
347 |
+
} else {
|
348 |
+
o[key] = value; // other keys can be used as object keys or array indexes
|
349 |
+
}
|
350 |
+
|
351 |
+
// With more keys is a deepSet. Apply recursively.
|
352 |
+
} else {
|
353 |
+
nextKey = keys[1];
|
354 |
+
|
355 |
+
// '' is used to push values into the array,
|
356 |
+
// with nextKey, set the value into the same object, in object[nextKey].
|
357 |
+
// Covers the case of ['', 'foo'] and ['', 'var'] to push the object {foo, var}, and the case of nested arrays.
|
358 |
+
if (key === '') {
|
359 |
+
lastIdx = o.length - 1; // asume o is array
|
360 |
+
lastVal = o[lastIdx];
|
361 |
+
if (f.isObject(lastVal) && (f.isUndefined(lastVal[nextKey]) || keys.length > 2)) { // if nextKey is not present in the last object element, or there are more keys to deep set
|
362 |
+
key = lastIdx; // then set the new value in the same object element
|
363 |
+
} else {
|
364 |
+
key = lastIdx + 1; // otherwise, point to set the next index in the array
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
// '' is used to push values into the array "array[]"
|
369 |
+
if (nextKey === '') {
|
370 |
+
if (f.isUndefined(o[key]) || !$.isArray(o[key])) {
|
371 |
+
o[key] = []; // define (or override) as array to push values
|
372 |
+
}
|
373 |
+
} else {
|
374 |
+
if (opts.useIntKeysAsArrayIndex && f.isValidArrayIndex(nextKey)) { // if 1, 2, 3 ... then use an array, where nextKey is the index
|
375 |
+
if (f.isUndefined(o[key]) || !$.isArray(o[key])) {
|
376 |
+
o[key] = []; // define (or override) as array, to insert values using int keys as array indexes
|
377 |
+
}
|
378 |
+
} else { // for anything else, use an object, where nextKey is going to be the attribute name
|
379 |
+
if (f.isUndefined(o[key]) || !f.isObject(o[key])) {
|
380 |
+
o[key] = {}; // define (or override) as object, to set nested properties
|
381 |
+
}
|
382 |
+
}
|
383 |
+
}
|
384 |
+
|
385 |
+
// Recursively set the inner object
|
386 |
+
tail = keys.slice(1);
|
387 |
+
f.deepSet(o[key], tail, value, opts);
|
388 |
+
}
|
389 |
+
}
|
390 |
+
|
391 |
+
};
|
392 |
+
|
393 |
+
}));
|
assets/backend/jquery-serializejson/jquery-serializejson.min.js
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
/*!
|
3 |
+
SerializeJSON jQuery plugin.
|
4 |
+
https://github.com/marioizquierdo/jquery.serializeJSON
|
5 |
+
version 2.9.0 (Jan, 2018)
|
6 |
+
Copyright (c) 2012-2018 Mario Izquierdo
|
7 |
+
Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
|
8 |
+
and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
|
9 |
+
*/
|
10 |
+
(function(a){if(typeof define==="function"&&define.amd){define(["jquery"],a)}else{if(typeof exports==="object"){var b=require("jquery");module.exports=a(b)}else{a(window.jQuery||window.Zepto||window.$)}}}(function(a){a.fn.serializeJSON=function(o){var h,p,b,i,k,c,m,d,j,e,l,n,g;h=a.serializeJSON;p=this;b=h.setupOpts(o);i=p.serializeArray();h.readCheckboxUncheckedValues(i,b,p);k={};a.each(i,function(f,q){c=q.name;m=q.value;j=h.extractTypeAndNameWithNoType(c);e=j.nameWithNoType;l=j.type;if(!l){l=h.attrFromInputWithName(p,c,"data-value-type")}h.validateType(c,l,b);if(l!=="skip"){n=h.splitInputNameIntoKeysArray(e);d=h.parseValue(m,c,l,b);g=!d&&h.shouldSkipFalsy(p,c,e,l,b);if(!g){h.deepSet(k,n,d,b)}}});return k};a.serializeJSON={defaultOptions:{checkboxUncheckedValue:undefined,parseNumbers:false,parseBooleans:false,parseNulls:false,parseAll:false,parseWithFunction:null,skipFalsyValuesForTypes:[],skipFalsyValuesForFields:[],customTypes:{},defaultTypes:{string:function(b){return String(b)},number:function(b){return Number(b)},"boolean":function(c){var b=["false","null","undefined","","0"];return b.indexOf(c)===-1},"null":function(c){var b=["false","null","undefined","","0"];return b.indexOf(c)===-1?c:null},array:function(b){return JSON.parse(b)},object:function(b){return JSON.parse(b)},auto:function(b){return a.serializeJSON.parseValue(b,null,null,{parseNumbers:true,parseBooleans:true,parseNulls:true})},skip:null},useIntKeysAsArrayIndex:false},setupOpts:function(d){var e,g,b,i,c,h;h=a.serializeJSON;if(d==null){d={}}b=h.defaultOptions||{};g=["checkboxUncheckedValue","parseNumbers","parseBooleans","parseNulls","parseAll","parseWithFunction","skipFalsyValuesForTypes","skipFalsyValuesForFields","customTypes","defaultTypes","useIntKeysAsArrayIndex"];for(e in d){if(g.indexOf(e)===-1){throw new Error("serializeJSON ERROR: invalid option '"+e+"'. Please use one of "+g.join(", "))}}i=function(f){return(d[f]!==false)&&(d[f]!=="")&&(d[f]||b[f])};c=i("parseAll");return{checkboxUncheckedValue:i("checkboxUncheckedValue"),parseNumbers:c||i("parseNumbers"),parseBooleans:c||i("parseBooleans"),parseNulls:c||i("parseNulls"),parseWithFunction:i("parseWithFunction"),skipFalsyValuesForTypes:i("skipFalsyValuesForTypes"),skipFalsyValuesForFields:i("skipFalsyValuesForFields"),typeFunctions:a.extend({},i("defaultTypes"),i("customTypes")),useIntKeysAsArrayIndex:i("useIntKeysAsArrayIndex")}},parseValue:function(d,c,e,g){var h,b;h=a.serializeJSON;b=d;if(g.typeFunctions&&e&&g.typeFunctions[e]){b=g.typeFunctions[e](d)}else{if(g.parseNumbers&&h.isNumeric(d)){b=Number(d)}else{if(g.parseBooleans&&(d==="true"||d==="false")){b=(d==="true")}else{if(g.parseNulls&&d=="null"){b=null}else{if(g.typeFunctions&&g.typeFunctions.string){b=g.typeFunctions.string(d)}}}}}if(g.parseWithFunction&&!e){b=g.parseWithFunction(b,c)}return b},isObject:function(b){return b===Object(b)},isUndefined:function(b){return b===void 0},isValidArrayIndex:function(b){return/^[0-9]+$/.test(String(b))},isNumeric:function(b){return b-parseFloat(b)>=0},optionKeys:function(d){if(Object.keys){return Object.keys(d)}else{var b,c=[];for(b in d){c.push(b)}return c}},readCheckboxUncheckedValues:function(i,b,k){var d,g,j,h,e,c;if(b==null){b={}}e=a.serializeJSON;d="input[type=checkbox][name]:not(:checked):not([disabled])";g=k.find(d).add(k.filter(d));g.each(function(f,l){j=a(l);h=j.attr("data-unchecked-value");if(h==null){h=b.checkboxUncheckedValue}if(h!=null){if(l.name&&l.name.indexOf("[][")!==-1){throw new Error("serializeJSON ERROR: checkbox unchecked values are not supported on nested arrays of objects like '"+l.name+"'. See https://github.com/marioizquierdo/jquery.serializeJSON/issues/67")}i.push({name:l.name,value:h})}})},extractTypeAndNameWithNoType:function(c){var b;if(b=c.match(/(.*):([^:]+)$/)){return{nameWithNoType:b[1],type:b[2]}}else{return{nameWithNoType:c,type:null}}},shouldSkipFalsy:function(k,c,e,i,b){var h=a.serializeJSON;var j=h.attrFromInputWithName(k,c,"data-skip-falsy");if(j!=null){return j!=="false"}var g=b.skipFalsyValuesForFields;if(g&&(g.indexOf(e)!==-1||g.indexOf(c)!==-1)){return true}var d=b.skipFalsyValuesForTypes;if(i==null){i="string"}if(d&&d.indexOf(i)!==-1){return true}return false},attrFromInputWithName:function(d,e,f){var c,b,h,g;c=e.replace(/(:|\.|\[|\]|\s)/g,"\\$1");b='[name="'+c+'"]';h=d.find(b).add(d.filter(b));return h.attr(f)},validateType:function(b,c,d){var g,e;e=a.serializeJSON;g=e.optionKeys(d?d.typeFunctions:e.defaultOptions.defaultTypes);if(!c||g.indexOf(c)!==-1){return true}else{throw new Error("serializeJSON ERROR: Invalid type "+c+" found in input name '"+b+"', please use one of "+g.join(", "))}},splitInputNameIntoKeysArray:function(b){var c,d;d=a.serializeJSON;c=b.split("[");c=a.map(c,function(e){return e.replace(/\]/g,"")});if(c[0]===""){c.shift()}return c},deepSet:function(c,l,j,b){var k,h,g,i,d,e;if(b==null){b={}}e=a.serializeJSON;if(e.isUndefined(c)){throw new Error("ArgumentError: param 'o' expected to be an object or array, found undefined")}if(!l||l.length===0){throw new Error("ArgumentError: param 'keys' expected to be an array with least one element")}k=l[0];if(l.length===1){if(k===""){c.push(j)}else{c[k]=j}}else{h=l[1];if(k===""){i=c.length-1;d=c[i];if(e.isObject(d)&&(e.isUndefined(d[h])||l.length>2)){k=i}else{k=i+1}}if(h===""){if(e.isUndefined(c[k])||!a.isArray(c[k])){c[k]=[]}}else{if(b.useIntKeysAsArrayIndex&&e.isValidArrayIndex(h)){if(e.isUndefined(c[k])||!a.isArray(c[k])){c[k]=[]}}else{if(e.isUndefined(c[k])||!e.isObject(c[k])){c[k]={}}}}g=l.slice(1);e.deepSet(c[k],g,j,b)}}}}));
|
assets/backend/js/wooccm-admin-field.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
(function ($) {
|
2 |
|
3 |
var count = 0,
|
4 |
-
|
5 |
|
6 |
var is_blocked = function ($node) {
|
7 |
return $node.is('.processing') || $node.parents('.processing').length;
|
@@ -18,42 +18,39 @@
|
|
18 |
return _.sortBy(object, function (o) {
|
19 |
return o.order;
|
20 |
});
|
21 |
-
}
|
22 |
-
});
|
23 |
-
var FieldViewTabs = Backbone.View.extend({
|
24 |
-
templates: {},
|
25 |
-
initialize: function () {
|
26 |
-
this.templates.window = wp.template('wooccm-modal-tabs');
|
27 |
},
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
var FieldViewPanels = Backbone.View.extend({
|
35 |
-
templates: {},
|
36 |
-
initialize: function () {
|
37 |
-
this.templates.window = wp.template('wooccm-modal-panels');
|
38 |
},
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
this.$el.trigger('init_tooltips');
|
44 |
}
|
45 |
});
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
},
|
51 |
-
render: function () {
|
52 |
-
this.$el.html(this.templates.window(this.model.attributes));
|
53 |
-
this.$el.trigger('wooccm-enhanced-select');
|
54 |
-
this.$el.trigger('init_tooltips');
|
55 |
-
}
|
56 |
});
|
|
|
57 |
var FieldView = Backbone.View.extend({
|
58 |
events: {
|
59 |
'change input': 'enableSave',
|
@@ -72,7 +69,7 @@
|
|
72 |
},
|
73 |
templates: {},
|
74 |
initialize: function () {
|
75 |
-
_.bindAll(this, '
|
76 |
this.init();
|
77 |
this.open();
|
78 |
},
|
@@ -82,22 +79,85 @@
|
|
82 |
assign: function (view, selector) {
|
83 |
view.setElement(this.$(selector)).render();
|
84 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
render: function () {
|
86 |
var modal = this;
|
87 |
modal.$el.html(modal.templates.window(modal.model.attributes));
|
88 |
-
this.tabs = new FieldViewTabs({model: modal.model});
|
89 |
-
this.panels = new FieldViewPanels({model: modal.model});
|
90 |
-
this.info = new FieldViewInfo({model: modal.model});
|
91 |
this.assign(this.tabs, '#wooccm-modal-tabs');
|
92 |
this.assign(this.panels, '#wooccm-modal-panels');
|
93 |
this.assign(this.info, '#wooccm-modal-info');
|
94 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
load: function () {
|
96 |
-
|
97 |
var modal = this;
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
101 |
$.ajax({
|
102 |
url: wooccm_field.ajax_url,
|
103 |
data: {
|
@@ -107,8 +167,8 @@
|
|
107 |
},
|
108 |
dataType: 'json',
|
109 |
type: 'POST',
|
110 |
-
beforeSend: function () {
|
111 |
-
},
|
112 |
complete: function () {
|
113 |
unblock();
|
114 |
},
|
@@ -128,9 +188,9 @@
|
|
128 |
edit: function (e) {
|
129 |
e.preventDefault();
|
130 |
var modal = this,
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
count++;
|
135 |
if (timer) {
|
136 |
clearTimeout(timer);
|
@@ -151,97 +211,45 @@
|
|
151 |
modal.load();
|
152 |
}, 300);
|
153 |
},
|
154 |
-
|
155 |
-
$('body').addClass('modal-open').append(this.$el);
|
156 |
-
if (this.model.attributes.id == undefined) {
|
157 |
-
_.delay(function () {
|
158 |
-
unblock();
|
159 |
-
}, 100);
|
160 |
-
return;
|
161 |
-
}
|
162 |
-
this.load();
|
163 |
-
},
|
164 |
-
updateModel: function (e) {
|
165 |
-
e.preventDefault();
|
166 |
-
|
167 |
-
var $field = $(e.target),
|
168 |
-
name = $field.attr('name'),
|
169 |
-
value = $field.val();
|
170 |
-
|
171 |
-
if (e.target.type === 'checkbox') {
|
172 |
-
value = $field.prop('checked') === true ? 1 : 0;
|
173 |
-
}
|
174 |
-
|
175 |
-
this.model.attributes[name] = value;
|
176 |
-
this.model.changed[name] = value;
|
177 |
-
},
|
178 |
-
tab: function (e) {
|
179 |
-
e.preventDefault();
|
180 |
-
|
181 |
-
var modal = this,
|
182 |
-
$modal = modal.$el.find('#wooccm_modal'),
|
183 |
-
$tab = $(e.currentTarget),
|
184 |
-
$tabs = $modal.find('ul.wc-tabs'),
|
185 |
-
panel = $tab.find('a').attr('href').replace('#', '');
|
186 |
-
|
187 |
-
$tabs.find('.active').removeClass('active');
|
188 |
-
$tab.addClass('active');
|
189 |
-
|
190 |
-
this.model.attributes['panel'] = panel;
|
191 |
-
this.model.changed['panel'] = panel;
|
192 |
-
|
193 |
-
this.renderPanels(e);
|
194 |
-
},
|
195 |
-
renderTabs: function (e) {
|
196 |
-
this.renderPanels(e);
|
197 |
-
this.tabs.render();
|
198 |
-
},
|
199 |
-
renderPanels: function (e) {
|
200 |
-
this.updateModel(e);
|
201 |
-
this.panels.render();
|
202 |
-
},
|
203 |
-
renderInfo: function () {
|
204 |
-
this.info.render();
|
205 |
-
},
|
206 |
-
close: function (e) {
|
207 |
-
e.preventDefault();
|
208 |
-
this.undelegateEvents();
|
209 |
-
$(document).off('focusin');
|
210 |
-
$('body').removeClass('modal-open');
|
211 |
-
this.remove();
|
212 |
-
},
|
213 |
-
parent: function (e) {
|
214 |
e.preventDefault();
|
215 |
var modal = this,
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
$.ajax({
|
220 |
url: wooccm_field.ajax_url,
|
221 |
data: {
|
222 |
-
action: '
|
223 |
nonce: wooccm_field.nonce,
|
224 |
-
|
225 |
},
|
226 |
dataType: 'json',
|
227 |
type: 'POST',
|
228 |
beforeSend: function () {
|
229 |
-
modal.
|
230 |
-
$
|
231 |
},
|
232 |
complete: function () {
|
233 |
-
$
|
234 |
-
$
|
235 |
-
|
|
|
|
|
236 |
},
|
237 |
-
error: function () {
|
238 |
alert('Error!');
|
239 |
},
|
240 |
success: function (response) {
|
|
|
241 |
if (response.success) {
|
242 |
-
|
243 |
-
modal.model.
|
244 |
-
|
|
|
|
|
|
|
|
|
245 |
} else {
|
246 |
alert(response.data);
|
247 |
}
|
@@ -249,94 +257,88 @@
|
|
249 |
});
|
250 |
return false;
|
251 |
},
|
252 |
-
|
253 |
-
|
254 |
-
location.reload();
|
255 |
-
return;
|
256 |
-
}
|
257 |
-
this.remove();
|
258 |
-
return;
|
259 |
-
},
|
260 |
-
close: function (e) {
|
261 |
-
e.preventDefault();
|
262 |
-
this.undelegateEvents();
|
263 |
-
$(document).off('focusin');
|
264 |
-
$('body').removeClass('modal-open');
|
265 |
-
this.reload(e);
|
266 |
-
return;
|
267 |
-
},
|
268 |
-
enableSave: function (e) {
|
269 |
-
$('.media-modal-submit').removeProp('disabled');
|
270 |
-
},
|
271 |
-
disableSave: function (e) {
|
272 |
-
$('.media-modal-submit').prop('disabled', true);
|
273 |
},
|
274 |
-
|
275 |
e.preventDefault();
|
276 |
var modal = this,
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
$.ajax({
|
281 |
url: wooccm_field.ajax_url,
|
282 |
data: {
|
283 |
-
action: '
|
284 |
nonce: wooccm_field.nonce,
|
285 |
-
|
286 |
-
field_data: $('form', this.$el).serialize()
|
287 |
},
|
288 |
dataType: 'json',
|
289 |
type: 'POST',
|
290 |
beforeSend: function () {
|
291 |
-
|
292 |
$details.addClass('save-waiting');
|
293 |
-
block();
|
294 |
},
|
295 |
complete: function () {
|
296 |
$details.addClass('save-complete');
|
297 |
$details.removeClass('save-waiting');
|
298 |
-
|
299 |
},
|
300 |
error: function () {
|
301 |
alert('Error!');
|
302 |
},
|
303 |
success: function (response) {
|
304 |
if (response.success) {
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
modal.close(e);
|
309 |
-
}
|
310 |
-
|
311 |
-
//re-render dont load select2 saved options
|
312 |
-
modal.model.set(response.data);
|
313 |
-
//$modal.addClass('reload');
|
314 |
-
|
315 |
} else {
|
316 |
alert(response.data);
|
317 |
}
|
318 |
}
|
319 |
});
|
320 |
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
}
|
322 |
});
|
323 |
-
var
|
324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
});
|
326 |
-
var
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
field_id = $button.closest('[data-field_id]').data('field_id');
|
331 |
-
var model = new FieldModel();
|
332 |
-
model.set({
|
333 |
-
id: field_id
|
334 |
-
});
|
335 |
-
new FieldView({
|
336 |
-
model: model
|
337 |
-
}).render();
|
338 |
},
|
|
|
|
|
|
|
|
|
|
|
339 |
});
|
|
|
340 |
$('#wooccm_billing_settings_add, #wooccm_shipping_settings_add, #wooccm_additional_settings_add').on('click', function (e) {
|
341 |
e.preventDefault();
|
342 |
new FieldModal(e);
|
@@ -382,8 +384,8 @@
|
|
382 |
$('.wooccm_billing_settings_delete, .wooccm_shipping_settings_delete, .wooccm_additional_settings_delete').on('click', function (e) {
|
383 |
e.preventDefault();
|
384 |
var $button = $(e.target),
|
385 |
-
|
386 |
-
|
387 |
var c = confirm(wooccm_field.message.remove);
|
388 |
if (!c) {
|
389 |
return false;
|
@@ -419,8 +421,8 @@
|
|
419 |
$(document).on('click', '.wooccm-field-toggle-attribute', function (e) {
|
420 |
e.preventDefault();
|
421 |
var $link = $(this),
|
422 |
-
|
423 |
-
|
424 |
$.ajax({
|
425 |
url: wooccm_field.ajax_url,
|
426 |
data: {
|
@@ -455,7 +457,7 @@
|
|
455 |
$(document).on('change', '.wooccm-field-change-attribute', function (e) {
|
456 |
e.preventDefault();
|
457 |
var $change = $(this),
|
458 |
-
|
459 |
$.ajax({
|
460 |
url: wooccm_field.ajax_url,
|
461 |
data: {
|
1 |
(function ($) {
|
2 |
|
3 |
var count = 0,
|
4 |
+
timer;
|
5 |
|
6 |
var is_blocked = function ($node) {
|
7 |
return $node.is('.processing') || $node.parents('.processing').length;
|
18 |
return _.sortBy(object, function (o) {
|
19 |
return o.order;
|
20 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
},
|
22 |
+
escapeHtml: function (attribute) {
|
23 |
+
return attribute.replace('&', /&/g)
|
24 |
+
.replace(/>/g, ">")
|
25 |
+
.replace(/</g, "<")
|
26 |
+
.replace(/"/g, '"')
|
27 |
+
.replace(/'/g, "'");
|
|
|
|
|
|
|
|
|
28 |
},
|
29 |
+
getFormData: function ($form) {
|
30 |
+
return $form.serializeJSON({ checkboxUncheckedValue: 'false', parseBooleans: true, parseNulls: true });
|
31 |
+
//breakes image highlight id
|
32 |
+
// return $form.serializeJSON({checkboxUncheckedValue: 'false', parseBooleans: true, parseNumbers: true, parseNulls: true});
|
|
|
33 |
}
|
34 |
});
|
35 |
+
|
36 |
+
var FieldModel = Backbone.Model.extend({
|
37 |
+
defaults: wooccm_field.args
|
38 |
+
});
|
39 |
+
|
40 |
+
var FieldModal = Backbone.View.extend({
|
41 |
+
initialize: function (e) {
|
42 |
+
var $button = $(e.target),
|
43 |
+
field_id = $button.closest('[data-field_id]').data('field_id');
|
44 |
+
var model = new FieldModel();
|
45 |
+
model.set({
|
46 |
+
id: field_id
|
47 |
+
});
|
48 |
+
new FieldView({
|
49 |
+
model: model
|
50 |
+
}).render();
|
51 |
},
|
|
|
|
|
|
|
|
|
|
|
52 |
});
|
53 |
+
|
54 |
var FieldView = Backbone.View.extend({
|
55 |
events: {
|
56 |
'change input': 'enableSave',
|
69 |
},
|
70 |
templates: {},
|
71 |
initialize: function () {
|
72 |
+
_.bindAll(this, 'open', 'tab', 'edit', 'load', 'render', 'close', 'submit', 'parent');
|
73 |
this.init();
|
74 |
this.open();
|
75 |
},
|
79 |
assign: function (view, selector) {
|
80 |
view.setElement(this.$(selector)).render();
|
81 |
},
|
82 |
+
updateModel: function (e) {
|
83 |
+
e.preventDefault();
|
84 |
+
var modal = this,
|
85 |
+
$form = modal.$el.find('#wooccm_modal').find('form');
|
86 |
+
var model = _.getFormData($form);
|
87 |
+
this.model.set(model);
|
88 |
+
},
|
89 |
+
reload: function (e) {
|
90 |
+
if (this.$el.find('#wooccm_modal').hasClass('reload')) {
|
91 |
+
location.reload();
|
92 |
+
return;
|
93 |
+
}
|
94 |
+
this.remove();
|
95 |
+
return;
|
96 |
+
},
|
97 |
+
close: function (e) {
|
98 |
+
e.preventDefault();
|
99 |
+
this.undelegateEvents();
|
100 |
+
$(document).off('focusin');
|
101 |
+
$('body').removeClass('modal-open');
|
102 |
+
// if necesary reload...
|
103 |
+
this.$el.find('#wooccm_modal').addClass('reload');
|
104 |
+
this.reload(e);
|
105 |
+
return;
|
106 |
+
},
|
107 |
+
enableSave: function (e) {
|
108 |
+
$('.media-modal-submit').removeProp('disabled');
|
109 |
+
this.updateModel(e);
|
110 |
+
},
|
111 |
+
disableSave: function (e) {
|
112 |
+
$('.media-modal-submit').prop('disabled', true);
|
113 |
+
},
|
114 |
+
tab: function (e) {
|
115 |
+
e.preventDefault();
|
116 |
+
var modal = this,
|
117 |
+
$modal = modal.$el.find('#wooccm_modal'),
|
118 |
+
$tab = $(e.currentTarget),
|
119 |
+
$tabs = $modal.find('ul.wc-tabs'),
|
120 |
+
panel = $tab.find('a').attr('href').replace('#', '');
|
121 |
+
$tabs.find('.active').removeClass('active');
|
122 |
+
$tab.addClass('active');
|
123 |
+
this.model.attributes['panel'] = panel;
|
124 |
+
this.model.changed['panel'] = panel;
|
125 |
+
this.renderPanels(e);
|
126 |
+
},
|
127 |
+
renderTabs: function (e) {
|
128 |
+
this.renderPanels(e);
|
129 |
+
this.tabs.render();
|
130 |
+
},
|
131 |
+
renderPanels: function (e) {
|
132 |
+
this.updateModel(e);
|
133 |
+
this.panels.render();
|
134 |
+
},
|
135 |
render: function () {
|
136 |
var modal = this;
|
137 |
modal.$el.html(modal.templates.window(modal.model.attributes));
|
138 |
+
this.tabs = new FieldViewTabs({ model: modal.model });
|
139 |
+
this.panels = new FieldViewPanels({ model: modal.model });
|
140 |
+
this.info = new FieldViewInfo({ model: modal.model });
|
141 |
this.assign(this.tabs, '#wooccm-modal-tabs');
|
142 |
this.assign(this.panels, '#wooccm-modal-panels');
|
143 |
this.assign(this.info, '#wooccm-modal-info');
|
144 |
},
|
145 |
+
open: function (e) {
|
146 |
+
$('body').addClass('modal-open').append(this.$el);
|
147 |
+
if (this.model.attributes.id == undefined) {
|
148 |
+
_.delay(function () {
|
149 |
+
unblock();
|
150 |
+
}, 100);
|
151 |
+
return;
|
152 |
+
}
|
153 |
+
this.load();
|
154 |
+
},
|
155 |
load: function () {
|
|
|
156 |
var modal = this;
|
157 |
+
if (modal.model.attributes.id == undefined) {
|
158 |
+
modal.render();
|
159 |
+
return;
|
160 |
+
}
|
161 |
$.ajax({
|
162 |
url: wooccm_field.ajax_url,
|
163 |
data: {
|
167 |
},
|
168 |
dataType: 'json',
|
169 |
type: 'POST',
|
170 |
+
// beforeSend: function () {
|
171 |
+
// },
|
172 |
complete: function () {
|
173 |
unblock();
|
174 |
},
|
188 |
edit: function (e) {
|
189 |
e.preventDefault();
|
190 |
var modal = this,
|
191 |
+
$button = $(e.target),
|
192 |
+
field_count = parseInt($('.wc_gateways tr[data-field_id]').length),
|
193 |
+
order = parseInt(modal.model.get('order'));
|
194 |
count++;
|
195 |
if (timer) {
|
196 |
clearTimeout(timer);
|
211 |
modal.load();
|
212 |
}, 300);
|
213 |
},
|
214 |
+
submit: function (e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
e.preventDefault();
|
216 |
var modal = this,
|
217 |
+
$modal = modal.$el.find('#wooccm_modal'),
|
218 |
+
$spinner = $modal.find('.settings-save-status .spinner'),
|
219 |
+
$saved = $modal.find('.settings-save-status .saved');
|
220 |
$.ajax({
|
221 |
url: wooccm_field.ajax_url,
|
222 |
data: {
|
223 |
+
action: 'wooccm_save_field',
|
224 |
nonce: wooccm_field.nonce,
|
225 |
+
field_data: JSON.stringify(modal.model.attributes)
|
226 |
},
|
227 |
dataType: 'json',
|
228 |
type: 'POST',
|
229 |
beforeSend: function () {
|
230 |
+
$('.media-modal-submit').prop('disabled', true);
|
231 |
+
$spinner.addClass('is-active');
|
232 |
},
|
233 |
complete: function () {
|
234 |
+
$saved.addClass('is-active');
|
235 |
+
$spinner.removeClass('is-active');
|
236 |
+
_.delay(function () {
|
237 |
+
$saved.removeClass('is-active');
|
238 |
+
}, 1000);
|
239 |
},
|
240 |
+
error: function (response) {
|
241 |
alert('Error!');
|
242 |
},
|
243 |
success: function (response) {
|
244 |
+
console.log(response);
|
245 |
if (response.success) {
|
246 |
+
|
247 |
+
if (modal.model.attributes.id == undefined) {
|
248 |
+
$modal.addClass('reload');
|
249 |
+
modal.reload(e);
|
250 |
+
modal.close(e);
|
251 |
+
}
|
252 |
+
|
253 |
} else {
|
254 |
alert(response.data);
|
255 |
}
|
257 |
});
|
258 |
return false;
|
259 |
},
|
260 |
+
renderInfo: function () {
|
261 |
+
this.info.render();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
},
|
263 |
+
parent: function (e) {
|
264 |
e.preventDefault();
|
265 |
var modal = this,
|
266 |
+
$modal = modal.$el.find('#wooccm_modal'),
|
267 |
+
$details = $modal.find('.attachment-details');
|
268 |
+
this.updateModel(e);
|
269 |
$.ajax({
|
270 |
url: wooccm_field.ajax_url,
|
271 |
data: {
|
272 |
+
action: 'wooccm_load_parent',
|
273 |
nonce: wooccm_field.nonce,
|
274 |
+
conditional_parent_key: modal.model.attributes.conditional_parent_key
|
|
|
275 |
},
|
276 |
dataType: 'json',
|
277 |
type: 'POST',
|
278 |
beforeSend: function () {
|
279 |
+
modal.disableSave();
|
280 |
$details.addClass('save-waiting');
|
|
|
281 |
},
|
282 |
complete: function () {
|
283 |
$details.addClass('save-complete');
|
284 |
$details.removeClass('save-waiting');
|
285 |
+
modal.enableSave();
|
286 |
},
|
287 |
error: function () {
|
288 |
alert('Error!');
|
289 |
},
|
290 |
success: function (response) {
|
291 |
if (response.success) {
|
292 |
+
modal.model.attributes['parent'] = response.data;
|
293 |
+
modal.model.changed['parent'] = response.data;
|
294 |
+
modal.renderInfo();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
} else {
|
296 |
alert(response.data);
|
297 |
}
|
298 |
}
|
299 |
});
|
300 |
return false;
|
301 |
+
},
|
302 |
+
});
|
303 |
+
|
304 |
+
// Parts
|
305 |
+
// -------------------------------------------------------------
|
306 |
+
|
307 |
+
var FieldViewTabs = Backbone.View.extend({
|
308 |
+
templates: {},
|
309 |
+
initialize: function () {
|
310 |
+
this.templates.window = wp.template('wooccm-modal-tabs');
|
311 |
+
},
|
312 |
+
render: function () {
|
313 |
+
this.model.attributes.panel = 'general';
|
314 |
+
this.$el.html(this.templates.window(this.model.attributes));
|
315 |
+
//this.$el.trigger('wooccm-tab-panels');
|
316 |
}
|
317 |
});
|
318 |
+
var FieldViewPanels = Backbone.View.extend({
|
319 |
+
templates: {},
|
320 |
+
initialize: function () {
|
321 |
+
this.templates.window = wp.template('wooccm-modal-panels');
|
322 |
+
},
|
323 |
+
render: function () {
|
324 |
+
this.$el.html(this.templates.window(this.model.attributes));
|
325 |
+
this.$el.trigger('wooccm-enhanced-options');
|
326 |
+
this.$el.trigger('wooccm-enhanced-select');
|
327 |
+
this.$el.trigger('init_tooltips');
|
328 |
+
}
|
329 |
});
|
330 |
+
var FieldViewInfo = Backbone.View.extend({
|
331 |
+
templates: {},
|
332 |
+
initialize: function () {
|
333 |
+
this.templates.window = wp.template('wooccm-modal-info');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
},
|
335 |
+
render: function () {
|
336 |
+
this.$el.html(this.templates.window(this.model.attributes));
|
337 |
+
this.$el.trigger('wooccm-enhanced-select');
|
338 |
+
this.$el.trigger('init_tooltips');
|
339 |
+
}
|
340 |
});
|
341 |
+
|
342 |
$('#wooccm_billing_settings_add, #wooccm_shipping_settings_add, #wooccm_additional_settings_add').on('click', function (e) {
|
343 |
e.preventDefault();
|
344 |
new FieldModal(e);
|
384 |
$('.wooccm_billing_settings_delete, .wooccm_shipping_settings_delete, .wooccm_additional_settings_delete').on('click', function (e) {
|
385 |
e.preventDefault();
|
386 |
var $button = $(e.target),
|
387 |
+
$field = $button.closest('[data-field_id]'),
|
388 |
+
field_id = $field.data('field_id');
|
389 |
var c = confirm(wooccm_field.message.remove);
|
390 |
if (!c) {
|
391 |
return false;
|
421 |
$(document).on('click', '.wooccm-field-toggle-attribute', function (e) {
|
422 |
e.preventDefault();
|
423 |
var $link = $(this),
|
424 |
+
$tr = $link.closest('tr'),
|
425 |
+
$toggle = $link.find('.woocommerce-input-toggle');
|
426 |
$.ajax({
|
427 |
url: wooccm_field.ajax_url,
|
428 |
data: {
|
457 |
$(document).on('change', '.wooccm-field-change-attribute', function (e) {
|
458 |
e.preventDefault();
|
459 |
var $change = $(this),
|
460 |
+
$tr = $change.closest('tr');
|
461 |
$.ajax({
|
462 |
url: wooccm_field.ajax_url,
|
463 |
data: {
|
assets/backend/js/wooccm-admin-field.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
1 |
+
!function($){var count=0,timer,is_blocked=function($node){return $node.is(".processing")||$node.parents(".processing").length},block=function(){$("#wooccm_modal").addClass("processing")},unblock=function(){$("#wooccm_modal").removeClass("processing")};_.mixin({sortOptions:function(object){return _.sortBy(object,(function(o){return o.order}))},escapeHtml:function(attribute){return attribute.replace("&",/&/g).replace(/>/g,">").replace(/</g,"<").replace(/"/g,'"').replace(/'/g,"'")},getFormData:function($form){return $form.serializeJSON({checkboxUncheckedValue:"false",parseBooleans:!0,parseNulls:!0})}});var FieldModel=Backbone.Model.extend({defaults:wooccm_field.args}),FieldModal=Backbone.View.extend({initialize:function(e){var $button,field_id=$(e.target).closest("[data-field_id]").data("field_id"),model=new FieldModel;model.set({id:field_id}),new FieldView({model:model}).render()}}),FieldView=Backbone.View.extend({events:{"change input":"enableSave","change textarea":"enableSave","change select":"enableSave","click .media-modal-backdrop":"close","click .media-modal-close":"close","click .media-modal-prev":"edit","click .media-modal-next":"edit","click .media-modal-tab":"tab","change .media-modal-parent":"parent","change .media-modal-render-tabs":"renderTabs","change .media-modal-render-panels":"renderPanels","change .media-modal-render-info":"renderInfo","submit .media-modal-form":"submit"},templates:{},initialize:function(){_.bindAll(this,"open","tab","edit","load","render","close","submit","parent"),this.init(),this.open()},init:function(){this.templates.window=wp.template("wooccm-modal-main")},assign:function(view,selector){view.setElement(this.$(selector)).render()},updateModel:function(e){e.preventDefault();var modal=this,$form=this.$el.find("#wooccm_modal").find("form"),model=_.getFormData($form);this.model.set(model)},reload:function(e){this.$el.find("#wooccm_modal").hasClass("reload")?location.reload():this.remove()},close:function(e){e.preventDefault(),this.undelegateEvents(),$(document).off("focusin"),$("body").removeClass("modal-open"),this.$el.find("#wooccm_modal").addClass("reload"),this.reload(e)},enableSave:function(e){$(".media-modal-submit").removeProp("disabled"),this.updateModel(e)},disableSave:function(e){$(".media-modal-submit").prop("disabled",!0)},tab:function(e){e.preventDefault();var modal=this,$modal=this.$el.find("#wooccm_modal"),$tab=$(e.currentTarget),$tabs=$modal.find("ul.wc-tabs"),panel=$tab.find("a").attr("href").replace("#","");$tabs.find(".active").removeClass("active"),$tab.addClass("active"),this.model.attributes.panel=panel,this.model.changed.panel=panel,this.renderPanels(e)},renderTabs:function(e){this.renderPanels(e),this.tabs.render()},renderPanels:function(e){this.updateModel(e),this.panels.render()},render:function(){var modal=this;this.$el.html(this.templates.window(this.model.attributes)),this.tabs=new FieldViewTabs({model:this.model}),this.panels=new FieldViewPanels({model:this.model}),this.info=new FieldViewInfo({model:this.model}),this.assign(this.tabs,"#wooccm-modal-tabs"),this.assign(this.panels,"#wooccm-modal-panels"),this.assign(this.info,"#wooccm-modal-info")},open:function(e){$("body").addClass("modal-open").append(this.$el),null!=this.model.attributes.id?this.load():_.delay((function(){unblock()}),100)},load:function(){var modal=this;null!=modal.model.attributes.id?$.ajax({url:wooccm_field.ajax_url,data:{action:"wooccm_load_field",nonce:wooccm_field.nonce,field_id:this.model.attributes.id},dataType:"json",type:"POST",complete:function(){unblock()},error:function(){alert("Error!")},success:function(response){response.success?(modal.model.set(response.data),modal.render()):alert(response.data)}}):modal.render()},edit:function(e){e.preventDefault();var modal=this,$button=$(e.target),field_count=parseInt($(".wc_gateways tr[data-field_id]").length),order=parseInt(modal.model.get("order"));count++,timer&&clearTimeout(timer),timer=setTimeout((function(){order=$button.hasClass("media-modal-next")?Math.min(order+count,field_count):Math.max(order-count,1),modal.model.set({id:parseInt($(".wc_gateways tr[data-field_order="+order+"]").data("field_id"))}),count=0,modal.load()}),300)},submit:function(e){e.preventDefault();var modal=this,$modal=modal.$el.find("#wooccm_modal"),$spinner=$modal.find(".settings-save-status .spinner"),$saved=$modal.find(".settings-save-status .saved");return $.ajax({url:wooccm_field.ajax_url,data:{action:"wooccm_save_field",nonce:wooccm_field.nonce,field_data:JSON.stringify(modal.model.attributes)},dataType:"json",type:"POST",beforeSend:function(){$(".media-modal-submit").prop("disabled",!0),$spinner.addClass("is-active")},complete:function(){$saved.addClass("is-active"),$spinner.removeClass("is-active"),_.delay((function(){$saved.removeClass("is-active")}),1e3)},error:function(response){alert("Error!")},success:function(response){console.log(response),response.success?null==modal.model.attributes.id&&($modal.addClass("reload"),modal.reload(e),modal.close(e)):alert(response.data)}}),!1},renderInfo:function(){this.info.render()},parent:function(e){e.preventDefault();var modal=this,$modal,$details=modal.$el.find("#wooccm_modal").find(".attachment-details");return this.updateModel(e),$.ajax({url:wooccm_field.ajax_url,data:{action:"wooccm_load_parent",nonce:wooccm_field.nonce,conditional_parent_key:modal.model.attributes.conditional_parent_key},dataType:"json",type:"POST",beforeSend:function(){modal.disableSave(),$details.addClass("save-waiting")},complete:function(){$details.addClass("save-complete"),$details.removeClass("save-waiting"),modal.enableSave()},error:function(){alert("Error!")},success:function(response){response.success?(modal.model.attributes.parent=response.data,modal.model.changed.parent=response.data,modal.renderInfo()):alert(response.data)}}),!1}}),FieldViewTabs=Backbone.View.extend({templates:{},initialize:function(){this.templates.window=wp.template("wooccm-modal-tabs")},render:function(){this.model.attributes.panel="general",this.$el.html(this.templates.window(this.model.attributes))}}),FieldViewPanels=Backbone.View.extend({templates:{},initialize:function(){this.templates.window=wp.template("wooccm-modal-panels")},render:function(){this.$el.html(this.templates.window(this.model.attributes)),this.$el.trigger("wooccm-enhanced-options"),this.$el.trigger("wooccm-enhanced-select"),this.$el.trigger("init_tooltips")}}),FieldViewInfo=Backbone.View.extend({templates:{},initialize:function(){this.templates.window=wp.template("wooccm-modal-info")},render:function(){this.$el.html(this.templates.window(this.model.attributes)),this.$el.trigger("wooccm-enhanced-select"),this.$el.trigger("init_tooltips")}});$("#wooccm_billing_settings_add, #wooccm_shipping_settings_add, #wooccm_additional_settings_add").on("click",(function(e){e.preventDefault(),new FieldModal(e)})),$("#wooccm_billing_settings_reset, #wooccm_shipping_settings_reset, #wooccm_additional_settings_reset").on("click",(function(e){e.preventDefault();var $button=$(e.target),c;return!!confirm(wooccm_field.message.reset)&&($.ajax({url:wooccm_field.ajax_url,data:{action:"wooccm_reset_fields",nonce:wooccm_field.nonce},dataType:"json",type:"POST",beforeSend:function(){},complete:function(){},error:function(){alert("Error!")},success:function(response){response.success?location.reload():alert(response.data)}}),!1)})),$(".wooccm_billing_settings_edit, .wooccm_shipping_settings_edit, .wooccm_additional_settings_edit").on("click",(function(e){e.preventDefault(),new FieldModal(e)})),$(".wooccm_billing_settings_delete, .wooccm_shipping_settings_delete, .wooccm_additional_settings_delete").on("click",(function(e){e.preventDefault();var $button,$field=$(e.target).closest("[data-field_id]"),field_id=$field.data("field_id"),c;return!!confirm(wooccm_field.message.remove)&&($.ajax({url:wooccm_field.ajax_url,data:{action:"wooccm_delete_field",nonce:wooccm_field.nonce,field_id:field_id},dataType:"json",type:"POST",beforeSend:function(){},complete:function(){},error:function(){alert("Error!")},success:function(response){response.success?$field.remove():alert(response.data)}}),!1)})),$(document).on("click",".wooccm-field-toggle-attribute",(function(e){e.preventDefault();var $link=$(this),$tr=$link.closest("tr"),$toggle=$link.find(".woocommerce-input-toggle");return $.ajax({url:wooccm_field.ajax_url,data:{action:"wooccm_toggle_field_attribute",nonce:wooccm_field.nonce,field_attr:$(this).data("field_attr"),field_id:$tr.data("field_id")},dataType:"json",type:"POST",beforeSend:function(response){$toggle.addClass("woocommerce-input-toggle--loading")},success:function(response){!0===response.data?($toggle.removeClass("woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled"),$toggle.addClass("woocommerce-input-toggle--enabled"),$toggle.removeClass("woocommerce-input-toggle--loading")):!0!==response.data&&($toggle.removeClass("woocommerce-input-toggle--enabled, woocommerce-input-toggle--disabled"),$toggle.addClass("woocommerce-input-toggle--disabled"),$toggle.removeClass("woocommerce-input-toggle--loading"))}}),!1})),$(document).on("change",".wooccm-field-change-attribute",(function(e){e.preventDefault();var $change=$(this),$tr=$change.closest("tr");return $.ajax({url:wooccm_field.ajax_url,data:{action:"wooccm_change_field_attribute",nonce:wooccm_field.nonce,field_attr:$change.data("field_attr"),field_value:$change.val(),field_id:$tr.data("field_id")},dataType:"json",type:"POST",beforeSend:function(response){$change.prop("disabled",!0)},success:function(response){console.log(response.data)},complete:function(response){$change.prop("disabled",!1)}}),!1}))}(jQuery);
|
assets/frontend/css/wooccm.min.css
CHANGED
@@ -1,2 +1 @@
|
|
1 |
-
|
2 |
-
.woocommerce form .wooccm-clearfix:before,.woocommerce form .wooccm-clearfix:after{content:'';display:table}.woocommerce form .wooccm-clearfix:after{clear:both}.woocommerce form .wooccm-conditional-child{display:none}.woocommerce form .wooccm-type-radio .woocommerce-radio-wrapper label{display:inline-block}.woocommerce form .wooccm-colorpicker-iris .iris-picker{display:none}.woocommerce form .wooccm-colorpicker-iris.active .iris-picker{display:block}@media(min-width:768px){.woocommerce form .wooccm-field.form-row-first{width:47.0588235294%;float:left;margin-right:5.8823529412%;clear:both}.woocommerce form .wooccm-field.form-row-last{width:45.4545454545%;float:right;margin-right:0}}.button.fileinput-button{position:relative;overflow:hidden!important}.button.fileinput-button input{position:absolute;top:0;right:0;margin:0;opacity:0;-ms-filter:'alpha(opacity=0)';font-size:200px;direction:ltr;cursor:pointer}.wooccm-file-list{margin:0 -5px;padding:0;display:flex;flex-wrap:wrap;align-items:center;justify-content:start}.wooccm-file-list .wooccm-file-file{display:flex;justify-content:center;align-items:stretch;box-sizing:border-box;padding:10px 5px 0 5px;width:25%;position:relative}.wooccm-file-list .wooccm-file-file .wooccm-file-list-delete{z-index:1;position:absolute;top:2px;right:-3px;width:16px;height:16px;background-color:#222;display:block;line-height:16px;text-align:center;color:#fefefe;font-weight:900;border-radius:50%;font-size:12px;cursor:pointer;font-family:code;text-decoration:none!important}.wooccm-file-list .wooccm-file-file .wooccm-file-list-container{width:100%;overflow:hidden}.wooccm-file-list .wooccm-file-file .wooccm-file-list-image-container{display:flex;justify-content:center;align-items:center;overflow:hidden;width:100%;padding-top:100%;position:relative;background:#eee}.wooccm-file-list .wooccm-file-file .wooccm-file-list-image-container>img{overflow:hidden;object-fit:cover;position:absolute;top:30%;bottom:auto;height:40%;opacity:.8}.wooccm-file-list .wooccm-file-file .wooccm-file-list-image-container>img.image{top:0;bottom:0;left:0;right:0;max-height:100%;height:100%;width:100%}
|
1 |
+
.woocommerce form .wooccm-clearfix:after,.woocommerce form .wooccm-clearfix:before{content:'';display:table}.woocommerce form .wooccm-clearfix:after{clear:both}.woocommerce form .wooccm-conditional-child{display:none}.woocommerce form .wooccm-type-radio .woocommerce-radio-wrapper label{display:inline-block}.woocommerce form .wooccm-colorpicker-iris .iris-picker{display:none}.woocommerce form .wooccm-colorpicker-iris.active .iris-picker{display:block}.button.fileinput-button{position:relative;overflow:hidden!important}.button.fileinput-button input{position:absolute;top:0;right:0;margin:0;opacity:0;-ms-filter:'alpha(opacity=0)';font-size:200px;direction:ltr;cursor:pointer}.wooccm-file-list{margin:0 -5px;padding:0;display:flex;flex-wrap:wrap;align-items:center;justify-content:start}.wooccm-file-list .wooccm-file-file{display:flex;justify-content:center;align-items:stretch;box-sizing:border-box;padding:10px 5px 0 5px;width:25%;position:relative}.wooccm-file-list .wooccm-file-file .wooccm-file-list-delete{z-index:1;position:absolute;top:2px;right:-3px;width:16px;height:16px;background-color:#222;display:block;line-height:16px;text-align:center;color:#fefefe;font-weight:900;border-radius:50%;font-size:12px;cursor:pointer;font-family:code;text-decoration:none!important}.wooccm-file-list .wooccm-file-file .wooccm-file-list-container{width:100%;overflow:hidden}.wooccm-file-list .wooccm-file-file .wooccm-file-list-image-container{display:flex;justify-content:center;align-items:center;overflow:hidden;width:100%;padding-top:100%;position:relative;background:#eee}.wooccm-file-list .wooccm-file-file .wooccm-file-list-image-container>img{overflow:hidden;object-fit:cover;position:absolute;top:30%;bottom:auto;height:40%;opacity:.8}.wooccm-file-list .wooccm-file-file .wooccm-file-list-image-container>img.image{top:0;bottom:0;left:0;right:0;max-height:100%;height:100%;width:100%}
|
|
assets/frontend/js/wooccm-checkout.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
!function(e){var t=function(e){return e.is(".processing")||e.parents(".processing").length};e(document).on("country_to_state_changing",function(t,o,c){var i=c,n=e.parseJSON(wc_address_i18n_params.locale_fields);e.each(n,function(e,t){var o=i.find(t),c=o.find("[data-required]").data("required")||o.find(".wooccm-required-field").length;!function(e,t){t?(e.find("label .optional").remove(),e.addClass("validate-required"),0===e.find("label .required").length&&e.find("label").append('<abbr class="required" title="'+wc_address_i18n_params.i18n_required_text+'">*</abbr>'),e.show(),e.find("input[type=hidden]").prop("type","text")):(e.find("label .required").remove(),e.removeClass("validate-required woocommerce-invalid woocommerce-invalid-required-field"),0===e.find("label .optional").length&&e.find("label").append('<span class="optional">('+wc_address_i18n_params.i18n_optional_text+")</span>"))}(o,c)})});var o={};if(e(".wooccm-type-file").each(function(t,c){var i=e(c),n=i.find("[type=file]"),a=i.find(".wooccm-file-button"),r=i.find(".wooccm-file-list");o[i.attr("id")]=[],a.on("click",function(e){e.preventDefault(),n.trigger("click")}),r.on("click",".wooccm-file-list-delete",function(t){var c=e(this).closest(".wooccm-file-file"),n=e(this).closest("[data-file_id]").data("file_id");o[i.attr("id")]=e.grep(o[i.attr("id")],function(e,t){return t!=n}),c.remove(),e("#order_review").trigger("wooccm_upload")}),n.on("change",function(t){var c=e(this)[0].files;c.length&&window.FileReader&&e.each(c,function(t,c){var n;return r.find("span[data-file_id]").length+t>=wooccm_upload.limit.max_files?(alert("Exeeds max files limit of "+wooccm_upload.limit.max_files),!1):c.size>wooccm_upload.limit.max_file_size?(alert("Exeeds max file size of "+wooccm_upload.limit.max_file_size),!0):(reader=new FileReader,reader.onload=(n=c,function(t){setTimeout(function(){!function(t,o,c,i,n){var a,r=e(t);n.match("image.*")?a="image":n.match("application/ms.*")?(c=wooccm_upload.icons.spreadsheet,a="spreadsheet"):n.match("application/x.*")?(c=wooccm_upload.icons.archive,a="application"):n.match("audio.*")?(c=wooccm_upload.icons.audio,a="audio"):n.match("text.*")?(c=wooccm_upload.icons.text,a="text"):n.match("video.*")?(c=wooccm_upload.icons.video,a="video"):(c=wooccm_upload.icons.interactive,a="interactive");var s='<span data-file_id="'+o+'" title="'+i+'" class="wooccm-file-file">\n <span class="wooccm-file-list-container">\n <a title="'+i+'" class="wooccm-file-list-delete">×</a>\n <span class="wooccm-file-list-image-container">\n <img class="'+a+'" alt="'+i+'" src="'+c+'"/>\n </span>\n </span>\n </span>';r.append(s).fadeIn()}(r,o[i.attr("id")].push(c)-1,t.target.result,n.name,n.type),e("#order_review").trigger("wooccm_upload")},200)}),console.log(c.name),void reader.readAsDataURL(c))})})}),e("#order_review").on("ajaxSuccess wooccm_upload",function(t){var o=e(t.target).find("#place_order");e(".wooccm-type-file").length?o.addClass("wooccm-upload-process"):o.removeClass("wooccm-upload-process")}),e(document).on("click","#place_order.wooccm-upload-process",function(c){c.preventDefault();var i,n=e("form.checkout"),a=e(this);e(".wooccm-type-file").length&&(window.FormData&&Object.keys(o).length&&(t(n)||(a.html(wooccm_upload.message.uploading),t(i=n)||i.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})),e.each(o,function(t,o){var c=e("#"+t).find(".wooccm-file-field"),i=new FormData;e.each(o,function(e,t){return e>wooccm_upload.limit.max_files?(console.log("Exeeds max files limit of "+wooccm_upload.limit.max_files),!1):t.size>wooccm_upload.limit.max_file_size?(console.log("Exeeds max file size of "+wooccm_upload.limit.max_files),!0):(console.log("We're ready to upload "+t.name),void i.append("wooccm_checkout_attachment_upload[]",t))}),i.append("action","wooccm_checkout_attachment_upload"),i.append("nonce",wooccm_upload.nonce),e.ajax({async:!1,url:wooccm_upload.ajax_url,type:"POST",cache:!1,data:i,processData:!1,contentType:!1,beforeSend:function(e){},success:function(t){t.success?c.val(t.data):e("body").trigger("update_checkout")},complete:function(e){}})}),function(e){e.removeClass("processing").unblock()}(n),a.removeClass("wooccm-upload-process").trigger("click")))}),e(document).on("change",".wooccm-add-price",function(t){e("body").trigger("update_checkout")}),e(".wooccm-conditional-child").each(function(t,o){var c=e(o),i=e("#"+c.find("[data-conditional-parent]").data("conditional-parent")+"_field"),n=c.find("[data-conditional-parent-value]").data("conditional-parent-value").toString();i.length?(i.on("wooccm_change change keyup",function(t){var o=e(t.target),a=o.val();o.hasClass("select2-selection")||("checkbox"==o.prop("type")&&(a=-1!==o.attr("name").indexOf("[]")?i.find("input:checked").map(function(e,t){return t.value}).toArray():o.is(":checked")),n==a||e.isArray(a)&&a.indexOf(n)>-1?c.fadeIn():c.fadeOut(),o.off("wooccm_change"),o.off("change"),o.off("keyup"),c.trigger("change"))}),i.find("select:first").trigger("wooccm_change"),i.find("textarea:first").trigger("wooccm_change"),i.find("input[type=button]:first").trigger("wooccm_change"),i.find("input[type=radio]:checked:first").trigger("wooccm_change"),i.find("input[type=checkbox]:checked:first").trigger("wooccm_change"),i.find("input[type=color]:first").trigger("wooccm_change"),i.find("input[type=date]:first").trigger("wooccm_change"),i.find("input[type=datetime-local]:first").trigger("wooccm_change"),i.find("input[type=email]:first").trigger("wooccm_change"),i.find("input[type=file]:first").trigger("wooccm_change"),i.find("input[type=hidden]:first").trigger("wooccm_change"),i.find("input[type=image]:first").trigger("wooccm_change"),i.find("input[type=month]:first").trigger("wooccm_change"),i.find("input[type=number]:first").trigger("wooccm_change"),i.find("input[type=password]:first").trigger("wooccm_change"),i.find("input[type=range]:first").trigger("wooccm_change"),i.find("input[type=reset]:first").trigger("wooccm_change"),i.find("input[type=search]:first").trigger("wooccm_change"),i.find("input[type=submit]:first").trigger("wooccm_change"),i.find("input[type=tel]:first").trigger("wooccm_change"),i.find("input[type=text]:first").trigger("wooccm_change"),i.find("input[type=time]:first").trigger("wooccm_change"),i.find("input[type=url]:first").trigger("wooccm_change"),i.find("input[type=week]:first").trigger("wooccm_change")):c.show()}),e(".wooccm-enhanced-datepicker").each(function(t,o){var c=e(this),i=c.data("disable")||!1;e.isFunction(e.fn.datepicker)&&c.datepicker({dateFormat:c.data("formatdate")||"dd-mm-yy",minDate:c.data("mindate")||void 0,maxDate:c.data("maxdate")||void 0,beforeShowDay:function(t){var o=t.getDay().toString();return i?[-1===e.inArray(o,i)]:[!0]}})}),e(".wooccm-enhanced-timepicker").each(function(t,o){var c=e(this);e.isFunction(e.fn.timepicker)&&c.timepicker({showPeriod:!0,showLeadingZero:!0,hours:c.data("hours")||void 0,minutes:c.data("minutes")||void 0})}),e(".wooccm-colorpicker-farbtastic").each(function(t,o){var c=e(o),i=c.find("input[type=text]"),n=c.find(".wooccmcolorpicker_container");i.hide(),e.isFunction(e.fn.farbtastic)&&(n.farbtastic("#"+i.attr("id")),n.on("click",function(e){i.fadeIn()}))}),e(".wooccm-colorpicker-iris").each(function(t,o){var c=e(o),i=c.find("input[type=text]");i.css("background",i.val()),i.on("click",function(e){c.toggleClass("active")}),i.iris({class:i.attr("id"),palettes:!0,color:"",hide:!1,change:function(e,t){i.css("background",t.color.toString()).fadeIn()}})}),e(document).on("click",function(t){0===e(t.target).closest(".iris-picker").length&&e(".wooccm-colorpicker-iris").removeClass("active")}),"undefined"==typeof wc_country_select_params)return!1;if(e().selectWoo){e("select.wooccm-enhanced-select").each(function(){var t=e.extend({width:"100%",placeholder:e(this).data("placeholder")||"",allowClear:e(this).data("allowclear")||!1,selectOnClose:e(this).data("selectonclose")||!1,closeOnSelect:e(this).data("closeonselect")||!1,minimumResultsForSearch:e(this).data("search")||-1},{language:{errorLoading:function(){return wc_country_select_params.i18n_searching},inputTooLong:function(e){var t=e.input.length-e.maximum;return 1===t?wc_country_select_params.i18n_input_too_long_1:wc_country_select_params.i18n_input_too_long_n.replace("%qty%",t)},inputTooShort:function(e){var t=e.minimum-e.input.length;return 1===t?wc_country_select_params.i18n_input_too_short_1:wc_country_select_params.i18n_input_too_short_n.replace("%qty%",t)},loadingMore:function(){return wc_country_select_params.i18n_load_more},maximumSelected:function(e){return 1===e.maximum?wc_country_select_params.i18n_selection_too_long_1:wc_country_select_params.i18n_selection_too_long_n.replace("%qty%",e.maximum)},noResults:function(){return wc_country_select_params.i18n_no_matches},searching:function(){return wc_country_select_params.i18n_searching}}});e(this).on("select2:select",function(){e(this).focus()}).selectWoo(t)})}}(jQuery);
|
1 |
+
!function($){var is_blocked=function($node){return $node.is(".processing")||$node.parents(".processing").length},block=function($node){is_blocked($node)||$node.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock=function($node){$node.removeClass("processing").unblock()},append_image=function(list,i,source,name,filetype){var $field_list=$(list),source_class;filetype.match("image.*")?source_class="image":filetype.match("application/ms.*")?(source=wooccm_upload.icons.spreadsheet,source_class="spreadsheet"):filetype.match("application/x.*")?(source=wooccm_upload.icons.archive,source_class="application"):filetype.match("audio.*")?(source=wooccm_upload.icons.audio,source_class="audio"):filetype.match("text.*")?(source=wooccm_upload.icons.text,source_class="text"):filetype.match("video.*")?(source=wooccm_upload.icons.video,source_class="video"):(source=wooccm_upload.icons.interactive,source_class="interactive");var html='<span data-file_id="'+i+'" title="'+name+'" class="wooccm-file-file">\n <span class="wooccm-file-list-container">\n <a title="'+name+'" class="wooccm-file-list-delete">×</a>\n <span class="wooccm-file-list-image-container">\n <img class="'+source_class+'" alt="'+name+'" src="'+source+'"/>\n </span>\n </span>\n </span>';$field_list.append(html).fadeIn()};function field_is_required(field,is_required){is_required?(field.find("label .optional").remove(),field.addClass("validate-required"),0===field.find("label .required").length&&field.find("label").append('<abbr class="required" title="'+wc_address_i18n_params.i18n_required_text+'">*</abbr>'),field.show(),field.find("input[type=hidden]").prop("type","text")):(field.find("label .required").remove(),field.removeClass("validate-required woocommerce-invalid woocommerce-invalid-required-field"),0===field.find("label .optional").length&&field.find("label").append('<span class="optional">('+wc_address_i18n_params.i18n_optional_text+")</span>"))}$(document).on("country_to_state_changing",(function(event,country,wrapper){var thisform=wrapper,thislocale,locale_fields=$.parseJSON(wc_address_i18n_params.locale_fields);$.each(locale_fields,(function(key,value){var field=thisform.find(value),required=field.find("[data-required]").data("required")||field.find(".wooccm-required-field").length;field_is_required(field,required)}))}));var fileList={};if($(".wooccm-type-file").each((function(i,field){var $field=$(field),$button_file=$field.find("[type=file]"),$button_click=$field.find(".wooccm-file-button"),$field_list=$field.find(".wooccm-file-list");fileList[$field.attr("id")]=[],$button_click.on("click",(function(e){e.preventDefault(),$button_file.trigger("click")})),$field_list.on("click",".wooccm-file-list-delete",(function(e){var $file=$(this).closest(".wooccm-file-file"),file_id=$(this).closest("[data-file_id]").data("file_id");fileList[$field.attr("id")]=$.grep(fileList[$field.attr("id")],(function(value,index){return index!=file_id})),$file.remove(),$("#order_review").trigger("wooccm_upload")})),$button_file.on("change",(function(e){var files=$(this)[0].files;files.length&&window.FileReader&&$.each(files,(function(i,file){var count,theFile;return $field_list.find("span[data-file_id]").length+i>=wooccm_upload.limit.max_files?(alert("Exeeds max files limit of "+wooccm_upload.limit.max_files),!1):file.size>wooccm_upload.limit.max_file_size?(alert("Exeeds max file size of "+wooccm_upload.limit.max_file_size),!0):(reader=new FileReader,reader.onload=(theFile=file,function(e){setTimeout((function(){append_image($field_list,fileList[$field.attr("id")].push(file)-1,e.target.result,theFile.name,theFile.type),$("#order_review").trigger("wooccm_upload")}),200)}),console.log(file.name),void reader.readAsDataURL(file))}))}))})),$("#order_review").on("ajaxSuccess wooccm_upload",(function(e,xhr,settings){var $order_review,$place_order=$(e.target).find("#place_order"),$fields,fields;$(".wooccm-type-file").length?$place_order.addClass("wooccm-upload-process"):$place_order.removeClass("wooccm-upload-process")})),$(document).on("click","#place_order.wooccm-upload-process",(function(e){e.preventDefault();var $form=$("form.checkout"),$place_order=$(this),$fields;$(".wooccm-type-file").length&&window.FormData&&Object.keys(fileList).length&&(is_blocked($form)||($place_order.html(wooccm_upload.message.uploading),block($form)),$.each(fileList,(function(field_id,files){var $field,$attachment_ids=$("#"+field_id).find(".wooccm-file-field"),data=new FormData;$.each(files,(function(file_id,file){return file_id>wooccm_upload.limit.max_files?(console.log("Exeeds max files limit of "+wooccm_upload.limit.max_files),!1):file.size>wooccm_upload.limit.max_file_size?(console.log("Exeeds max file size of "+wooccm_upload.limit.max_files),!0):(console.log("We're ready to upload "+file.name),void data.append("wooccm_checkout_attachment_upload[]",file))})),data.append("action","wooccm_checkout_attachment_upload"),data.append("nonce",wooccm_upload.nonce),$.ajax({async:!1,url:wooccm_upload.ajax_url,type:"POST",cache:!1,data:data,processData:!1,contentType:!1,beforeSend:function(response){},success:function(response){response.success?$attachment_ids.val(response.data):$("body").trigger("update_checkout")},complete:function(response){}})})),unblock($form),$place_order.removeClass("wooccm-upload-process").trigger("click"))})),$(document).on("change",".wooccm-add-price",(function(e){$("body").trigger("update_checkout")})),$(".wooccm-conditional-child").each((function(i,field){var $field=$(field),$parent=$("#"+$field.find("[data-conditional-parent]").data("conditional-parent")+"_field"),show_if_value=$field.find("[data-conditional-parent-value]").data("conditional-parent-value").toString();$parent.length?($parent.on("wooccm_change change keyup",(function(e){var $this=$(e.target),value=$this.val();$this.hasClass("select2-selection")||("checkbox"==$this.prop("type")&&(value=-1!==$this.attr("name").indexOf("[]")?$parent.find("input:checked").map((function(i,e){return e.value})).toArray():$this.is(":checked")),show_if_value==value||$.isArray(value)&&value.indexOf(show_if_value)>-1?$field.fadeIn():$field.fadeOut(),$this.off("wooccm_change"),$this.off("change"),$this.off("keyup"),$field.trigger("change"))})),$parent.find("select:first").trigger("wooccm_change"),$parent.find("textarea:first").trigger("wooccm_change"),$parent.find("input[type=button]:first").trigger("wooccm_change"),$parent.find("input[type=radio]:checked:first").trigger("wooccm_change"),$parent.find("input[type=checkbox]:checked:first").trigger("wooccm_change"),$parent.find("input[type=color]:first").trigger("wooccm_change"),$parent.find("input[type=date]:first").trigger("wooccm_change"),$parent.find("input[type=datetime-local]:first").trigger("wooccm_change"),$parent.find("input[type=email]:first").trigger("wooccm_change"),$parent.find("input[type=file]:first").trigger("wooccm_change"),$parent.find("input[type=hidden]:first").trigger("wooccm_change"),$parent.find("input[type=image]:first").trigger("wooccm_change"),$parent.find("input[type=month]:first").trigger("wooccm_change"),$parent.find("input[type=number]:first").trigger("wooccm_change"),$parent.find("input[type=password]:first").trigger("wooccm_change"),$parent.find("input[type=range]:first").trigger("wooccm_change"),$parent.find("input[type=reset]:first").trigger("wooccm_change"),$parent.find("input[type=search]:first").trigger("wooccm_change"),$parent.find("input[type=submit]:first").trigger("wooccm_change"),$parent.find("input[type=tel]:first").trigger("wooccm_change"),$parent.find("input[type=text]:first").trigger("wooccm_change"),$parent.find("input[type=time]:first").trigger("wooccm_change"),$parent.find("input[type=url]:first").trigger("wooccm_change"),$parent.find("input[type=week]:first").trigger("wooccm_change")):$field.show()})),$(".wooccm-enhanced-datepicker").each((function(i,field){var $input=$(this),disable=$input.data("disable")||!1;console.log("mindate",$input.data("mindate")),$.isFunction($.fn.datepicker)&&$input.datepicker({dateFormat:$input.data("formatdate")||"dd-mm-yy",minDate:$input.data("mindate"),maxDate:$input.data("maxdate"),beforeShowDay:function(date){var day=date.getDay().toString();return disable?[-1===$.inArray(day,disable)]:[!0]}})})),$(".wooccm-enhanced-timepicker").each((function(i,field){var $input=$(this);$.isFunction($.fn.timepicker)&&$input.timepicker({showPeriod:!0,showLeadingZero:!0,hours:$input.data("hours")||void 0,minutes:$input.data("minutes")||void 0})})),$(".wooccm-colorpicker-farbtastic").each((function(i,field){var $field=$(field),$input=$field.find("input[type=text]"),$container=$field.find(".wooccmcolorpicker_container");$input.hide(),$.isFunction($.fn.farbtastic)&&($container.farbtastic("#"+$input.attr("id")),$container.on("click",(function(e){$input.fadeIn()})))})),$(".wooccm-colorpicker-iris").each((function(i,field){var $field=$(field),$input=$field.find("input[type=text]");$input.css("background",$input.val()),$input.on("click",(function(e){$field.toggleClass("active")})),$input.iris({class:$input.attr("id"),palettes:!0,color:"",hide:!1,change:function(event,ui){$input.css("background",ui.color.toString()).fadeIn()}})})),$(document).on("click",(function(e){0===$(e.target).closest(".iris-picker").length&&$(".wooccm-colorpicker-iris").removeClass("active")})),"undefined"==typeof wc_country_select_params)return!1;if($().selectWoo){var getEnhancedSelectFormatString=function(){return{language:{errorLoading:function(){return wc_country_select_params.i18n_searching},inputTooLong:function(args){var overChars=args.input.length-args.maximum;return 1===overChars?wc_country_select_params.i18n_input_too_long_1:wc_country_select_params.i18n_input_too_long_n.replace("%qty%",overChars)},inputTooShort:function(args){var remainingChars=args.minimum-args.input.length;return 1===remainingChars?wc_country_select_params.i18n_input_too_short_1:wc_country_select_params.i18n_input_too_short_n.replace("%qty%",remainingChars)},loadingMore:function(){return wc_country_select_params.i18n_load_more},maximumSelected:function(args){return 1===args.maximum?wc_country_select_params.i18n_selection_too_long_1:wc_country_select_params.i18n_selection_too_long_n.replace("%qty%",args.maximum)},noResults:function(){return wc_country_select_params.i18n_no_matches},searching:function(){return wc_country_select_params.i18n_searching}}}},wooccm_enhanced_select;(function(){$("select.wooccm-enhanced-select").each((function(){var select2_args=$.extend({width:"100%",placeholder:$(this).data("placeholder")||"",allowClear:$(this).data("allowclear")||!1,selectOnClose:$(this).data("selectonclose")||!1,closeOnSelect:$(this).data("closeonselect")||!1,minimumResultsForSearch:$(this).data("search")||-1},getEnhancedSelectFormatString());$(this).on("select2:select",(function(){$(this).focus()})).selectWoo(select2_args)}))})()}}(jQuery);
|
assets/frontend/js/wooccm-order-upload.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
1 |
+
!function($){var is_blocked=function($node){return $node.is(".processing")||$node.parents(".processing").length},block=function($node){is_blocked($node)||$node.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock=function($node){$node.removeClass("processing").unblock()};$(document).ready((function($){$(document).on("click",".wooccm_delete_attachment",(function(e){var $tr=$(this).closest("tr"),attachment_id=$(this).data("attachment_id");$tr.hide(),$("#wooccm_order_attachment_update").prop("disabled",!1),$("#delete_attachments_ids").val($("#delete_attachments_ids").val().replace(attachment_id,""))})),$(document).on("click","#wooccm_order_attachment_update",(function(e){$.ajax({url:wooccm_upload.ajax_url,type:"POST",cache:!1,data:{action:"wooccm_order_attachment_update",nonce:wooccm_upload.nonce,delete_attachments_ids:$("#delete_attachments_ids").val(),all_attachments_ids:$("#all_attachments_ids").val()},beforeSend:function(response){$(".wooccm_upload_results").html(wooccm_upload.message.saving)},success:function(response){response.success?($(".wooccm_upload_results").html(wooccm_upload.message.deleted),$("#wooccm_order_attachment_update").prop("disabled",!0)):$(".wooccm_upload_results").html(response.data)}})})),$(document).on("change","#wooccm_order_attachment_upload",(function(e){var data=!1,order_id=$(this).data("order_id");window.FormData&&(data=new FormData);for(var i=0,len=this.files.length,img,reader,file;i<len;i++)file=this.files[i],data&&data.append("wooccm_order_attachment_upload[]",file);data&&(data.append("action","wooccm_order_attachment_upload"),data.append("nonce",wooccm_upload.nonce),data.append("order_id",order_id),$.ajax({url:wooccm_upload.ajax_url,type:"POST",cache:!1,data:data,processData:!1,contentType:!1,beforeSend:function(response){$(".wooccm_upload_results").html(wooccm_upload.message.uploading),block($(".wooccm_order_attachments_wrapper"))},success:function(response){response.success?($(".wooccm_order_attachments_wrapper").fadeOut(),$(".wooccm_order_attachments_wrapper").replaceWith($(response.data).fadeIn()),$(".wooccm_upload_results").html(wooccm_upload.message.success)):$(".wooccm_upload_results").html(response.data),unblock($(".wooccm_order_attachments_wrapper"))}}))}))}))}(jQuery);
|
includes/{class-wooccm-admin.php → class-wooccm-backend.php}
RENAMED
@@ -1,21 +1,29 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class WOOCCM_Field_Admin
|
|
|
4 |
|
5 |
protected static $_instance;
|
6 |
|
7 |
-
public function __construct()
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
9 |
}
|
10 |
|
11 |
-
public static function instance()
|
|
|
12 |
if (is_null(self::$_instance)) {
|
13 |
self::$_instance = new self();
|
14 |
}
|
15 |
return self::$_instance;
|
16 |
}
|
17 |
|
18 |
-
public function ajax_select_search_products()
|
|
|
19 |
|
20 |
if (current_user_can('manage_woocommerce') && check_ajax_referer('search-products', 'security') && isset($_REQUEST['term'])) {
|
21 |
|
@@ -62,41 +70,37 @@ class WOOCCM_Field_Admin {
|
|
62 |
}
|
63 |
}
|
64 |
|
65 |
-
public function enqueue_scripts()
|
|
|
66 |
|
67 |
$screen = get_current_screen();
|
68 |
|
69 |
-
wp_register_style('wooccm-admin', plugins_url('assets/backend/css/wooccm-admin.css', WOOCCM_PLUGIN_FILE), array(), WOOCCM_PLUGIN_VERSION, 'all');
|
|
|
|
|
70 |
|
71 |
-
wp_register_script('wooccm-admin', plugins_url('assets/backend/js/wooccm-admin.js', WOOCCM_PLUGIN_FILE), array('jquery'), WOOCCM_PLUGIN_VERSION, true);
|
72 |
|
73 |
if ((isset($_GET['tab']) && $_GET['tab'] === WOOCCM_PREFIX) || in_array($screen->id, array(/* 'product', 'edit-product', */'shop_order', 'edit-shop_order'))) {
|
74 |
wp_enqueue_style('wooccm-admin');
|
75 |
wp_enqueue_script('wooccm-admin');
|
76 |
wp_localize_script('wooccm-admin', 'wooccm_admin', array(
|
77 |
-
|
78 |
-
|
79 |
));
|
80 |
}
|
81 |
}
|
82 |
|
83 |
-
public function add_tab($settings_tabs)
|
|
|
84 |
$settings_tabs[WOOCCM_PREFIX] = esc_html__('Checkout', 'woocommerce-checkout-manager');
|
85 |
return $settings_tabs;
|
86 |
}
|
87 |
|
88 |
-
public function add_menu_page()
|
|
|
89 |
add_submenu_page('woocommerce', esc_html__('Checkout', 'woocommerce-checkout-manager'), esc_html__('Checkout', 'woocommerce-checkout-manager'), 'manage_woocommerce', admin_url('admin.php?page=wc-settings&tab=' . sanitize_title(WOOCCM_PREFIX)));
|
90 |
}
|
91 |
-
|
92 |
-
public function init() {
|
93 |
-
add_action('wp_ajax_wooccm_select_search_products', array($this, 'ajax_select_search_products'));
|
94 |
-
add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
|
95 |
-
add_action('admin_menu', array($this, 'add_menu_page'));
|
96 |
-
add_filter('woocommerce_settings_tabs_array', array($this, 'add_tab'), 50);
|
97 |
-
}
|
98 |
-
|
99 |
}
|
100 |
|
101 |
WOOCCM_Field_Admin::instance();
|
102 |
-
|
1 |
<?php
|
2 |
|
3 |
+
class WOOCCM_Field_Admin
|
4 |
+
{
|
5 |
|
6 |
protected static $_instance;
|
7 |
|
8 |
+
public function __construct()
|
9 |
+
{
|
10 |
+
|
11 |
+
add_action('wp_ajax_wooccm_select_search_products', array($this, 'ajax_select_search_products'));
|
12 |
+
add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
|
13 |
+
add_action('admin_menu', array($this, 'add_menu_page'));
|
14 |
+
add_filter('woocommerce_settings_tabs_array', array($this, 'add_tab'), 50);
|
15 |
}
|
16 |
|
17 |
+
public static function instance()
|
18 |
+
{
|
19 |
if (is_null(self::$_instance)) {
|
20 |
self::$_instance = new self();
|
21 |
}
|
22 |
return self::$_instance;
|
23 |
}
|
24 |
|
25 |
+
public function ajax_select_search_products()
|
26 |
+
{
|
27 |
|
28 |
if (current_user_can('manage_woocommerce') && check_ajax_referer('search-products', 'security') && isset($_REQUEST['term'])) {
|
29 |
|
70 |
}
|
71 |
}
|
72 |
|
73 |
+
public function enqueue_scripts()
|
74 |
+
{
|
75 |
|
76 |
$screen = get_current_screen();
|
77 |
|
78 |
+
wp_register_style('wooccm-admin', plugins_url('assets/backend/css/wooccm-admin' . WOOCCM::is_min() . '.css', WOOCCM_PLUGIN_FILE), array(), WOOCCM_PLUGIN_VERSION, 'all');
|
79 |
+
|
80 |
+
wp_register_script('jquery-serializejson', plugins_url('/assets/backend/jquery-serializejson/jquery-serializejson' . WOOCCM::is_min() . '.js', WOOCCM_PLUGIN_FILE), array('jquery'), WOOCCM_PLUGIN_VERSION, true);
|
81 |
|
82 |
+
wp_register_script('wooccm-admin', plugins_url('assets/backend/js/wooccm-admin' . WOOCCM::is_min() . '.js', WOOCCM_PLUGIN_FILE), array('jquery', 'jquery-serializejson'), WOOCCM_PLUGIN_VERSION, true);
|
83 |
|
84 |
if ((isset($_GET['tab']) && $_GET['tab'] === WOOCCM_PREFIX) || in_array($screen->id, array(/* 'product', 'edit-product', */'shop_order', 'edit-shop_order'))) {
|
85 |
wp_enqueue_style('wooccm-admin');
|
86 |
wp_enqueue_script('wooccm-admin');
|
87 |
wp_localize_script('wooccm-admin', 'wooccm_admin', array(
|
88 |
+
'ajax_url' => admin_url('admin-ajax.php'),
|
89 |
+
'nonce' => wp_create_nonce('wooccm_search_field'),
|
90 |
));
|
91 |
}
|
92 |
}
|
93 |
|
94 |
+
public function add_tab($settings_tabs)
|
95 |
+
{
|
96 |
$settings_tabs[WOOCCM_PREFIX] = esc_html__('Checkout', 'woocommerce-checkout-manager');
|
97 |
return $settings_tabs;
|
98 |
}
|
99 |
|
100 |
+
public function add_menu_page()
|
101 |
+
{
|
102 |
add_submenu_page('woocommerce', esc_html__('Checkout', 'woocommerce-checkout-manager'), esc_html__('Checkout', 'woocommerce-checkout-manager'), 'manage_woocommerce', admin_url('admin.php?page=wc-settings&tab=' . sanitize_title(WOOCCM_PREFIX)));
|
103 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
|
106 |
WOOCCM_Field_Admin::instance();
|
|
includes/class-wooccm-compatibility.php
CHANGED
@@ -1,176 +1,166 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class WOOCCM_Field_Compatibility
|
|
|
4 |
|
5 |
protected $fields = null;
|
6 |
protected $prefix = '';
|
7 |
-
protected $
|
8 |
protected $defaults = array();
|
9 |
private $old_to_old_types = array(
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
);
|
27 |
private $old_to_old_args = array(
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
);
|
96 |
private $old_args = array(
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
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 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
);
|
159 |
protected static $_instance;
|
160 |
|
161 |
-
public function __construct()
|
162 |
-
|
163 |
-
}
|
164 |
-
|
165 |
-
public static function instance() {
|
166 |
-
|
167 |
-
if (is_null(self::$_instance)) {
|
168 |
-
self::$_instance = new self();
|
169 |
-
}
|
170 |
-
return self::$_instance;
|
171 |
-
}
|
172 |
-
|
173 |
-
public function init() {
|
174 |
|
175 |
if (false === get_option('wooccm_billing', false) && $fields = $this->get_fields_new('wccs_settings3', 'billing')) {
|
176 |
update_option('wooccm_billing', $fields);
|
@@ -185,7 +175,17 @@ class WOOCCM_Field_Compatibility {
|
|
185 |
}
|
186 |
}
|
187 |
|
188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
foreach ($array as $key => $value) {
|
191 |
|
@@ -200,7 +200,8 @@ class WOOCCM_Field_Compatibility {
|
|
200 |
return $array;
|
201 |
}
|
202 |
|
203 |
-
function replace_value($value = '', $replace = array())
|
|
|
204 |
if (array_key_exists($value, $replace)) {
|
205 |
return $replace[$value];
|
206 |
}
|
@@ -208,7 +209,8 @@ class WOOCCM_Field_Compatibility {
|
|
208 |
return $value;
|
209 |
}
|
210 |
|
211 |
-
function string_to_array($value)
|
|
|
212 |
|
213 |
if (!empty($value) && !is_array($value)) {
|
214 |
if (strpos($value, '||') !== false) {
|
@@ -223,7 +225,8 @@ class WOOCCM_Field_Compatibility {
|
|
223 |
return $value;
|
224 |
}
|
225 |
|
226 |
-
function array_to_string($value)
|
|
|
227 |
|
228 |
if (is_array($value)) {
|
229 |
if (count($value)) {
|
@@ -236,7 +239,8 @@ class WOOCCM_Field_Compatibility {
|
|
236 |
return $value;
|
237 |
}
|
238 |
|
239 |
-
function get_new_args($field = array(), $prefix = '')
|
|
|
240 |
|
241 |
$replace = array_flip(array_filter($this->old_to_old_args));
|
242 |
|
@@ -247,7 +251,8 @@ class WOOCCM_Field_Compatibility {
|
|
247 |
return $field;
|
248 |
}
|
249 |
|
250 |
-
function get_new_type($type = '')
|
|
|
251 |
|
252 |
$replace = array_flip(array_filter($this->old_to_old_types));
|
253 |
|
@@ -256,7 +261,8 @@ class WOOCCM_Field_Compatibility {
|
|
256 |
return $type;
|
257 |
}
|
258 |
|
259 |
-
function new_panel_compatibility($field_id, $field = array(), $fields = array(), $prefix = '')
|
|
|
260 |
|
261 |
$field = $this->get_new_args($field, $prefix);
|
262 |
|
@@ -272,21 +278,21 @@ class WOOCCM_Field_Compatibility {
|
|
272 |
if (is_array($options)) {
|
273 |
|
274 |
$field['options'] = array();
|
275 |
-
// $i = 0;
|
276 |
foreach ($options as $key => $label) {
|
277 |
$field['options'][] = array(
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
);
|
284 |
|
285 |
if (!empty($field['conditional_parent_value']) && $field['conditional_parent_value'] == $label) {
|
286 |
$field['conditional_parent_value'] = $label;
|
287 |
}
|
288 |
|
289 |
-
// $i++;
|
290 |
}
|
291 |
}
|
292 |
}
|
@@ -355,7 +361,8 @@ class WOOCCM_Field_Compatibility {
|
|
355 |
return WOOCCM()->$prefix->sanitize_field_data(array_intersect_key($field, array_flip(array_keys(WOOCCM()->$prefix->get_args()))));
|
356 |
}
|
357 |
|
358 |
-
protected function get_fields_new($name, $prefix = '')
|
|
|
359 |
|
360 |
if ($fields = $this->get_option_old($name, $prefix)) {
|
361 |
|
@@ -365,7 +372,7 @@ class WOOCCM_Field_Compatibility {
|
|
365 |
|
366 |
$field = $this->new_panel_compatibility($field_id, $field, $fields, $prefix);
|
367 |
|
368 |
-
// if (count($defaults) && $default_id = @max(array_keys(array_column($defaults, 'key'), $field['key']))) {
|
369 |
if (count($defaults) && $default_id = WOOCCM()->$prefix->get_field_id($defaults, 'key', $field['key'])) {
|
370 |
|
371 |
if (isset($defaults[$default_id])) {
|
@@ -390,7 +397,8 @@ class WOOCCM_Field_Compatibility {
|
|
390 |
// Core
|
391 |
// -------------------------------------------------------------------------
|
392 |
|
393 |
-
protected function get_option_old($name, $prefix)
|
|
|
394 |
|
395 |
if ($fields = get_option($name)) {
|
396 |
|
@@ -409,7 +417,6 @@ class WOOCCM_Field_Compatibility {
|
|
409 |
|
410 |
return $fields;
|
411 |
}
|
412 |
-
|
413 |
}
|
414 |
|
415 |
WOOCCM_Field_Compatibility::instance();
|
1 |
<?php
|
2 |
|
3 |
+
class WOOCCM_Field_Compatibility
|
4 |
+
{
|
5 |
|
6 |
protected $fields = null;
|
7 |
protected $prefix = '';
|
8 |
+
protected $table = '';
|
9 |
protected $defaults = array();
|
10 |
private $old_to_old_types = array(
|
11 |
+
'heading' => 'heading',
|
12 |
+
'text' => 'wooccmtext',
|
13 |
+
'textarea' => 'wooccmtextarea',
|
14 |
+
'password' => 'wooccmpassword',
|
15 |
+
'select' => 'wooccmselect',
|
16 |
+
'radio' => 'wooccmradio',
|
17 |
+
'checkbox' => 'checkbox_wccm',
|
18 |
+
//'button' => __('Button', 'woocommerce-checkout-manager'),
|
19 |
+
'country' => 'wooccmcountry',
|
20 |
+
'state' => 'wooccmstate',
|
21 |
+
'multiselect' => 'multiselect',
|
22 |
+
'multicheckbox' => 'multicheckbox',
|
23 |
+
'datepicker' => 'datepicker',
|
24 |
+
'timepicker' => 'time',
|
25 |
+
'colorpicker' => 'colorpicker',
|
26 |
+
'file' => 'wooccmupload',
|
27 |
);
|
28 |
private $old_to_old_args = array(
|
29 |
+
'disabled' => null,
|
30 |
+
'order' => null,
|
31 |
+
'priority' => null,
|
32 |
+
'name' => 'cow',
|
33 |
+
'type' => null,
|
34 |
+
'label' => null,
|
35 |
+
'placeholder' => null,
|
36 |
+
'default' => 'force_title2',
|
37 |
+
'position' => null,
|
38 |
+
'clear' => 'clear_row',
|
39 |
+
'options' => 'option_array',
|
40 |
+
'required' => 'checkbox',
|
41 |
+
// Display
|
42 |
+
// -------------------------------------------------------------------
|
43 |
+
'show_role' => 'role_option',
|
44 |
+
'hide_role' => 'role_option2',
|
45 |
+
'more_product' => 'more_content',
|
46 |
+
'show_product' => 'single_px',
|
47 |
+
'hide_product' => 'single_p',
|
48 |
+
'show_product_cat' => 'single_px_cat',
|
49 |
+
'hide_product_cat' => 'single_p_cat',
|
50 |
+
// Timing
|
51 |
+
// -------------------------------------------------------------------
|
52 |
+
'time_limit_start' => 'start_hour',
|
53 |
+
'time_limit_end' => 'end_hour',
|
54 |
+
'time_limit_interval' => 'interval_min',
|
55 |
+
'manual_min' => null,
|
56 |
+
'date_limit' => 'date_limit',
|
57 |
+
'date_limit_variable_min' => 'min_before',
|
58 |
+
'date_limit_variable_max' => 'max_after',
|
59 |
+
'date_limit_fixed_min' => null,
|
60 |
+
'date_limit_fixed_max' => null,
|
61 |
+
'date_limit_days' => null,
|
62 |
+
'single_dd' => null,
|
63 |
+
'single_mm' => null,
|
64 |
+
'single_yy' => null,
|
65 |
+
'single_max_dd' => null,
|
66 |
+
'single_max_mm' => null,
|
67 |
+
'single_max_yy' => null,
|
68 |
+
// Amount
|
69 |
+
// -------------------------------------------------------------------
|
70 |
+
'add_price' => null,
|
71 |
+
'add_price_name' => 'fee_name',
|
72 |
+
'add_price_total' => 'add_price_field',
|
73 |
+
'add_price_type' => null,
|
74 |
+
'add_price_tax' => 'tax_remove',
|
75 |
+
'extra_class' => null,
|
76 |
+
// Conditional
|
77 |
+
// -------------------------------------------------------------------
|
78 |
+
'conditional' => 'conditional_parent_use',
|
79 |
+
'conditional_parent_key' => 'conditional_tie',
|
80 |
+
'conditional_parent_value' => 'chosen_valt',
|
81 |
+
// Color
|
82 |
+
// -------------------------------------------------------------------
|
83 |
+
'pickertype' => 'colorpickertype',
|
84 |
+
// State
|
85 |
+
// -------------------------------------------------------------------
|
86 |
+
'country' => null,
|
87 |
+
// Upload
|
88 |
+
// -------------------------------------------------------------------
|
89 |
+
'file_limit' => null,
|
90 |
+
'file_types' => null,
|
91 |
+
// Listing
|
92 |
+
// -------------------------------------------------------------------
|
93 |
+
'listable' => null,
|
94 |
+
'sortable' => null,
|
95 |
+
'filterable' => null,
|
96 |
);
|
97 |
private $old_args = array(
|
98 |
+
'disabled',
|
99 |
+
'order',
|
100 |
+
'priority',
|
101 |
+
'cow',
|
102 |
+
'type',
|
103 |
+
'label',
|
104 |
+
'placeholder',
|
105 |
+
'force_title2',
|
106 |
+
'position',
|
107 |
+
'clear_row',
|
108 |
+
'option_array',
|
109 |
+
'checkbox',
|
110 |
+
'role_option',
|
111 |
+
'role_option2',
|
112 |
+
'more_content',
|
113 |
+
'single_p',
|
114 |
+
'single_px',
|
115 |
+
'single_p_cat',
|
116 |
+
'single_px_cat',
|
117 |
+
'start_hour',
|
118 |
+
'end_hour',
|
119 |
+
'interval_min',
|
120 |
+
'manual_min',
|
121 |
+
'min_before',
|
122 |
+
'max_after',
|
123 |
+
'single_dd',
|
124 |
+
'single_mm',
|
125 |
+
'single_yy',
|
126 |
+
'single_max_dd',
|
127 |
+
'single_max_mm',
|
128 |
+
'single_max_yy',
|
129 |
+
'days_disabler',
|
130 |
+
'days_disabler0',
|
131 |
+
'days_disabler1',
|
132 |
+
'days_disabler2',
|
133 |
+
'days_disabler3',
|
134 |
+
'days_disabler4',
|
135 |
+
'days_disabler5',
|
136 |
+
'days_disabler6',
|
137 |
+
'add_amount',
|
138 |
+
'fee_name',
|
139 |
+
'add_amount_field',
|
140 |
+
'tax_remove',
|
141 |
+
'conditional_parent_use',
|
142 |
+
'conditional_tie',
|
143 |
+
'chosen_valt',
|
144 |
+
'extra_class',
|
145 |
+
'colorpickertype',
|
146 |
+
'colorpickerd',
|
147 |
+
'role_options',
|
148 |
+
'role_options2',
|
149 |
+
'changenamep',
|
150 |
+
'changename',
|
151 |
+
// New
|
152 |
+
// -----------------------------------------------------------------------
|
153 |
+
'country',
|
154 |
+
'file_limit',
|
155 |
+
'file_types',
|
156 |
+
'listable',
|
157 |
+
'sortable',
|
158 |
+
'filterable',
|
159 |
);
|
160 |
protected static $_instance;
|
161 |
|
162 |
+
public function __construct()
|
163 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
if (false === get_option('wooccm_billing', false) && $fields = $this->get_fields_new('wccs_settings3', 'billing')) {
|
166 |
update_option('wooccm_billing', $fields);
|
175 |
}
|
176 |
}
|
177 |
|
178 |
+
public static function instance()
|
179 |
+
{
|
180 |
+
|
181 |
+
if (is_null(self::$_instance)) {
|
182 |
+
self::$_instance = new self();
|
183 |
+
}
|
184 |
+
return self::$_instance;
|
185 |
+
}
|
186 |
+
|
187 |
+
function replace_keys($array = array(), $replace = array())
|
188 |
+
{
|
189 |
|
190 |
foreach ($array as $key => $value) {
|
191 |
|
200 |
return $array;
|
201 |
}
|
202 |
|
203 |
+
function replace_value($value = '', $replace = array())
|
204 |
+
{
|
205 |
if (array_key_exists($value, $replace)) {
|
206 |
return $replace[$value];
|
207 |
}
|
209 |
return $value;
|
210 |
}
|
211 |
|
212 |
+
function string_to_array($value)
|
213 |
+
{
|
214 |
|
215 |
if (!empty($value) && !is_array($value)) {
|
216 |
if (strpos($value, '||') !== false) {
|
225 |
return $value;
|
226 |
}
|
227 |
|
228 |
+
function array_to_string($value)
|
229 |
+
{
|
230 |
|
231 |
if (is_array($value)) {
|
232 |
if (count($value)) {
|
239 |
return $value;
|
240 |
}
|
241 |
|
242 |
+
function get_new_args($field = array(), $prefix = '')
|
243 |
+
{
|
244 |
|
245 |
$replace = array_flip(array_filter($this->old_to_old_args));
|
246 |
|
251 |
return $field;
|
252 |
}
|
253 |
|
254 |
+
function get_new_type($type = '')
|
255 |
+
{
|
256 |
|
257 |
$replace = array_flip(array_filter($this->old_to_old_types));
|
258 |
|
261 |
return $type;
|
262 |
}
|
263 |
|
264 |
+
function new_panel_compatibility($field_id, $field = array(), $fields = array(), $prefix = '')
|
265 |
+
{
|
266 |
|
267 |
$field = $this->get_new_args($field, $prefix);
|
268 |
|
278 |
if (is_array($options)) {
|
279 |
|
280 |
$field['options'] = array();
|
281 |
+
// $i = 0;
|
282 |
foreach ($options as $key => $label) {
|
283 |
$field['options'][] = array(
|
284 |
+
'label' => $label,
|
285 |
+
'add_price_total' => 0,
|
286 |
+
'add_price_type' => 'fixed',
|
287 |
+
'add_price_tax' => 0,
|
288 |
+
'default' => ''
|
289 |
);
|
290 |
|
291 |
if (!empty($field['conditional_parent_value']) && $field['conditional_parent_value'] == $label) {
|
292 |
$field['conditional_parent_value'] = $label;
|
293 |
}
|
294 |
|
295 |
+
// $i++;
|
296 |
}
|
297 |
}
|
298 |
}
|
361 |
return WOOCCM()->$prefix->sanitize_field_data(array_intersect_key($field, array_flip(array_keys(WOOCCM()->$prefix->get_args()))));
|
362 |
}
|
363 |
|
364 |
+
protected function get_fields_new($name, $prefix = '')
|
365 |
+
{
|
366 |
|
367 |
if ($fields = $this->get_option_old($name, $prefix)) {
|
368 |
|
372 |
|
373 |
$field = $this->new_panel_compatibility($field_id, $field, $fields, $prefix);
|
374 |
|
375 |
+
// if (count($defaults) && $default_id = @max(array_keys(array_column($defaults, 'key'), $field['key']))) {
|
376 |
if (count($defaults) && $default_id = WOOCCM()->$prefix->get_field_id($defaults, 'key', $field['key'])) {
|
377 |
|
378 |
if (isset($defaults[$default_id])) {
|
397 |
// Core
|
398 |
// -------------------------------------------------------------------------
|
399 |
|
400 |
+
protected function get_option_old($name, $prefix)
|
401 |
+
{
|
402 |
|
403 |
if ($fields = get_option($name)) {
|
404 |
|
417 |
|
418 |
return $fields;
|
419 |
}
|
|
|
420 |
}
|
421 |
|
422 |
WOOCCM_Field_Compatibility::instance();
|
includes/class-wooccm-notices.php
CHANGED
@@ -1,27 +1,27 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
class WOOCCM_Notices
|
|
|
4 |
|
5 |
protected static $_instance;
|
6 |
|
7 |
-
public function __construct()
|
8 |
-
|
|
|
|
|
|
|
9 |
}
|
10 |
|
11 |
-
public static function instance()
|
|
|
12 |
if (is_null(self::$_instance)) {
|
13 |
self::$_instance = new self();
|
14 |
}
|
15 |
return self::$_instance;
|
16 |
}
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
add_action('admin_notices', array($this, 'add_notices'));
|
21 |
-
add_filter('plugin_action_links_' . plugin_basename(WOOCCM_PLUGIN_FILE), array($this, 'add_action_links'));
|
22 |
-
}
|
23 |
-
|
24 |
-
public function ajax_dismiss_notice() {
|
25 |
|
26 |
if (check_admin_referer('wooccm_dismiss_notice', 'nonce') && isset($_REQUEST['notice_id'])) {
|
27 |
|
@@ -35,10 +35,11 @@ class WOOCCM_Notices {
|
|
35 |
wp_die();
|
36 |
}
|
37 |
|
38 |
-
public function add_notices()
|
|
|
39 |
|
40 |
if (!get_user_meta(get_current_user_id(), 'wooccm-beta-notice', true) && get_option('wccs_settings')) {
|
41 |
-
|
42 |
<div class="wooccm-notice notice is-dismissible" data-notice_id="wooccm-beta-notice">
|
43 |
<div class="notice-container" style="padding-top: 10px; padding-bottom: 10px; display: flex; justify-content: left; align-items: center;">
|
44 |
<div class="notice-image">
|
@@ -46,7 +47,7 @@ class WOOCCM_Notices {
|
|
46 |
</div>
|
47 |
<div class="notice-content" style="margin-left: 15px;">
|
48 |
<p>
|
49 |
-
|
50 |
</p>
|
51 |
<p>
|
52 |
As you know, we've recently acquired this plugin and we've been working very hard to bring you a quality product.
|
@@ -80,9 +81,9 @@ class WOOCCM_Notices {
|
|
80 |
</div>
|
81 |
</div>
|
82 |
</div>
|
83 |
-
|
84 |
} elseif (!get_user_meta(get_current_user_id(), 'wooccm-user-rating', true) && !get_transient('wooccm-first-rating') && !get_option('wccs_settings')) {
|
85 |
-
|
86 |
<div class="wooccm-notice notice is-dismissible" data-notice_id="wooccm-user-rating">
|
87 |
<div class="notice-container" style="padding-top: 10px; padding-bottom: 10px; display: flex; justify-content: left; align-items: center;">
|
88 |
<div class="notice-image">
|
@@ -91,7 +92,7 @@ class WOOCCM_Notices {
|
|
91 |
<div class="notice-content" style="margin-left: 15px;">
|
92 |
<p>
|
93 |
<?php printf(esc_html__('Hello! We\'ve recently acquired this plugin!', 'woocommerce-checkout-manager'), WOOCCM_PLUGIN_NAME); ?>
|
94 |
-
<br/>
|
95 |
<?php esc_html_e('We will do our best to improve it and include new features gradually. Please be patient and let us know about the issues and improvements that you want to see in this plugin.', 'woocommerce-checkout-manager'); ?>
|
96 |
</p>
|
97 |
<a href="<?php echo esc_url(WOOCCM_GROUP_URL); ?>" class="button-primary" target="_blank">
|
@@ -115,7 +116,7 @@ class WOOCCM_Notices {
|
|
115 |
<div class="notice-content" style="margin-left: 15px;">
|
116 |
<p>
|
117 |
<b><?php printf(esc_html__('Important! Manual update is required.', 'woocommerce-checkout-manager'), WOOCCM_PLUGIN_NAME); ?></b>
|
118 |
-
<br/>
|
119 |
<?php esc_html_e('Due to the recent WooCommerce 4.0 changes it is necessary to reconfigure conditional fields. If you have conditional fields, please go to the billing, shipping and advanced sections and set conditionals relationships again.', 'woocommerce-checkout-manager'); ?>
|
120 |
</p>
|
121 |
<a href="<?php echo admin_url('admin.php?page=wc-settings&tab=wooccm'); ?>" class="button-primary" target="_blank">
|
@@ -127,12 +128,12 @@ class WOOCCM_Notices {
|
|
127 |
</div>
|
128 |
</div>
|
129 |
</div>
|
130 |
-
|
131 |
}
|
132 |
?>
|
133 |
<script>
|
134 |
-
(function
|
135 |
-
$('.wooccm-notice').on('click', '.notice-dismiss', function
|
136 |
e.preventDefault();
|
137 |
var notice_id = $(e.delegateTarget).data('notice_id');
|
138 |
$.ajax({
|
@@ -143,24 +144,24 @@ class WOOCCM_Notices {
|
|
143 |
action: 'wooccm_dismiss_notice',
|
144 |
nonce: '<?php echo wp_create_nonce('wooccm_dismiss_notice'); ?>'
|
145 |
},
|
146 |
-
success: function
|
147 |
console.log(response);
|
148 |
},
|
149 |
});
|
150 |
});
|
151 |
})(jQuery);
|
152 |
</script>
|
153 |
-
|
154 |
}
|
155 |
|
156 |
-
public function add_action_links($links)
|
|
|
157 |
|
158 |
$links[] = '<a target="_blank" href="' . WOOCCM_PURCHASE_URL . '">' . esc_html__('Premium', 'woocommerce-checkout-manager') . '</a>';
|
159 |
$links[] = '<a href="' . admin_url('admin.php?page=wc-settings&tab=' . sanitize_title(WOOCCM_PREFIX)) . '">' . esc_html__('Settings', 'woocommerce-checkout-manager') . '</a>';
|
160 |
|
161 |
return $links;
|
162 |
}
|
163 |
-
|
164 |
}
|
165 |
|
166 |
WOOCCM_Notices::instance();
|
1 |
<?php
|
2 |
|