¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -3,7 +3,7 @@ export default class {
for (let key in errors) {
let inputField = this.getInputFieldForErrorKey(key);
inputField.closest('.option').addClass('option-has-errors');
inputField.closest(".option").addClass("option-has-errors");
let parent = inputField.parent();
@@ -12,7 +12,7 @@ export default class {
}
getRowTemplate(data) {
let template = _.template($('#option-select-values-template').html());
let template = _.template($("#option-select-values-template").html());
return $(template(data));
}
@@ -20,13 +20,16 @@ export default class {
changeOptionType({ optionId, type, values = [] }) {
let optionValuesElement = this.getOptionValuesElement(optionId);
let templateType = this.getTemplateType(type, optionValuesElement);
let optionValuesData = { optionId, value: { id: '', label: '', price: '', price_type: 'fixed' } };
let optionValuesData = {
optionId,
value: { id: "", label: "", price: "", price_type: "fixed" },
};
if (this.shouldNotChangeTemplate(templateType, optionValuesElement)) {
return;
}
if (values.length !== 0 && templateType === 'text') {
if (values.length !== 0 && templateType === "text") {
optionValuesData.value = values[0];
}
@@ -34,13 +37,13 @@ export default class {
optionValuesElement.html(template(optionValuesData));
if (templateType === 'select') {
if (templateType === "select") {
this.addOptionRowEventListener(optionId);
this.addOptionRows({ optionId, values });
if (values.length === 0) {
this.getAddNewRowButton(optionId).trigger('click');
this.getAddNewRowButton(optionId).trigger("click");
}
}
}
@@ -57,41 +60,53 @@ export default class {
getTemplateType(type) {
if (this.templateTypeIsText(type)) {
return 'text';
return "text";
}
if (this.templateTypeIsSelect(type)) {
return 'select';
return "select";
}
}
templateTypeIsText(type) {
return ['field', 'textarea', 'date', 'date_time', 'time'].includes(type);
return ["field", "textarea", "date", "date_time", "time"].includes(
type
);
}
templateTypeIsSelect(type) {
return ['dropdown', 'checkbox', 'checkbox_custom', 'radio', 'radio_custom', 'multiple_select'].includes(type);
return [
"dropdown",
"checkbox",
"checkbox_custom",
"radio",
"radio_custom",
"multiple_select",
].includes(type);
}
shouldNotChangeTemplate(templateType, optionValuesElement) {
return templateType === undefined || this.alreadyHasCurrentTemplate(templateType, optionValuesElement);
return (
templateType === undefined ||
this.alreadyHasCurrentTemplate(templateType, optionValuesElement)
);
}
alreadyHasCurrentTemplate(templateType, optionValuesElement) {
if (templateType === 'text') {
return optionValuesElement.children().hasClass('option-text');
if (templateType === "text") {
return optionValuesElement.children().hasClass("option-text");
}
if (templateType === 'select') {
return optionValuesElement.children().hasClass('option-select');
if (templateType === "select") {
return optionValuesElement.children().hasClass("option-select");
}
}
initOptionRow(template, selectValues) {
if (selectValues.length !== 0 && ! selectValues.is('.sortable')) {
if (selectValues.length !== 0 && !selectValues.is(".sortable")) {
this.makeSortable(selectValues[0]);
selectValues.addClass('sortable');
selectValues.addClass("sortable");
}
this.deleteOptionRowEventListener(template);
@@ -100,14 +115,14 @@ export default class {
}
deleteOptionRowEventListener(row) {
row.find('.delete-row').on('click', (e) => {
$(e.currentTarget).closest('.option-row').remove();
row.find(".delete-row").on("click", (e) => {
$(e.currentTarget).closest(".option-row").remove();
});
}
makeSortable(el) {
Sortable.create(el, {
handle: '.drag-icon',
handle: ".drag-handle",
animation: 150,
});
}

View File

@@ -1,10 +1,5 @@
import Option from './Option';
import ProductOption from './ProductOption';
import Option from "./Option";
if ($('#option-create-form, #option-edit-form').length !== 0) {
if ($("#option-create-form, #option-edit-form").length !== 0) {
new Option();
}
if ($('#product-create-form, #product-edit-form').length !== 0) {
new ProductOption();
}