|
|
|
@@ -149,10 +149,16 @@
|
|
|
|
|
return out + "</select>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 품목 토글 — [켜짐, 꺼짐] 표기
|
|
|
|
|
var FLAG_LABELS = {
|
|
|
|
|
display: ["진열", "미진열"], selling: ["판매", "중지"],
|
|
|
|
|
use_inventory: ["사용", "미사용"], display_soldout: ["표시", "안함"]
|
|
|
|
|
};
|
|
|
|
|
var FLAGS = Object.keys(FLAG_LABELS);
|
|
|
|
|
|
|
|
|
|
function toggleBtn(flag, on) {
|
|
|
|
|
var label = flag === "display" ? (on ? "진열" : "미진열") : (on ? "판매" : "중지");
|
|
|
|
|
return '<button type="button" class="cf24-v-toggle' + (on ? " is-on" : "") + '" data-flag="' + flag +
|
|
|
|
|
'" data-on="' + (on ? 1 : 0) + '" data-initial="' + (on ? 1 : 0) + '">' + label + "</button>";
|
|
|
|
|
'" data-on="' + (on ? 1 : 0) + '" data-initial="' + (on ? 1 : 0) + '">' + FLAG_LABELS[flag][on ? 0 : 1] + "</button>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function paintToggle(btn, on, resetInitial) {
|
|
|
|
@@ -160,7 +166,25 @@
|
|
|
|
|
if (resetInitial) btn.dataset.initial = btn.dataset.on;
|
|
|
|
|
btn.classList.toggle("is-on", on);
|
|
|
|
|
btn.classList.toggle("is-dirty", btn.dataset.on !== btn.dataset.initial);
|
|
|
|
|
btn.textContent = btn.dataset.flag === "display" ? (on ? "진열" : "미진열") : (on ? "판매" : "중지");
|
|
|
|
|
btn.textContent = FLAG_LABELS[btn.dataset.flag][on ? 0 : 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 재고관리 · 재고 수량 · 품절표시 칸 (진열·판매 다음)
|
|
|
|
|
var INVENTORY_TH = '<th class="cf24-v-flag">재고관리</th><th class="cf24-v-qty">재고</th><th class="cf24-v-flag">품절표시</th>';
|
|
|
|
|
function inventoryCells(variant) {
|
|
|
|
|
var qty = variant && variant.quantity != null ? String(variant.quantity) : "0";
|
|
|
|
|
return '<td class="cf24-v-flag">' + toggleBtn("use_inventory", !!(variant && variant.use_inventory)) + "</td>" +
|
|
|
|
|
'<td class="cf24-v-qty"><input type="text" name="quantity" inputmode="numeric" value="' + esc(qty) + '" /></td>' +
|
|
|
|
|
'<td class="cf24-v-flag">' + toggleBtn("display_soldout", !!(variant && variant.display_soldout)) + "</td>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 행의 품목 입력 요소들 — 저장 패치(variantPatch/newRowPatch)용
|
|
|
|
|
function variantFields(tr, into) {
|
|
|
|
|
into.custom = tr.querySelector('[name="custom_variant_code"]');
|
|
|
|
|
into.amount = tr.querySelector('[name="additional_amount"]');
|
|
|
|
|
into.quantity = tr.querySelector('[name="quantity"]');
|
|
|
|
|
FLAGS.forEach(function (flag) { into[flag] = tr.querySelector('.cf24-v-toggle[data-flag="' + flag + '"]'); });
|
|
|
|
|
return into;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function bindToggles(container) {
|
|
|
|
@@ -339,7 +363,7 @@
|
|
|
|
|
});
|
|
|
|
|
tbody.addEventListener("keydown", function (e) {
|
|
|
|
|
// isComposing: 한글 조합 중 Enter 는 글자 확정용이다 — 여기서 옮기면 글자가 깨지거나 두 칸 내려간다.
|
|
|
|
|
if (e.isComposing || !e.target.matches('[name="option_text"], [name="custom_variant_code"], [name="additional_amount"], .cf24-sale-price')) return;
|
|
|
|
|
if (e.isComposing || !e.target.matches('[name="option_text"], [name="custom_variant_code"], [name="additional_amount"], .cf24-sale-price, [name="quantity"]')) return;
|
|
|
|
|
var down = e.key === "Enter" || e.key === "ArrowDown";
|
|
|
|
|
if (!down && e.key !== "ArrowUp") return;
|
|
|
|
|
e.preventDefault();
|
|
|
|
@@ -425,6 +449,7 @@
|
|
|
|
|
salePriceCell(variant ? variant.additional_amount : "0") +
|
|
|
|
|
'<td class="cf24-v-flag">' + toggleBtn("display", variant ? !!variant.display : true) + "</td>" +
|
|
|
|
|
'<td class="cf24-v-flag">' + toggleBtn("selling", variant ? !!variant.selling : true) + "</td>" +
|
|
|
|
|
inventoryCells(variant) +
|
|
|
|
|
'<td class="cf24-u-del">' + (awaiting ? "" : '<button type="button" class="cf24-u-remove" title="' + (isNewRow ? "행 삭제" : "품목 삭제 (카페24에 바로 반영)") + '">✕</button>') + "</td>" +
|
|
|
|
|
"</tr>";
|
|
|
|
|
}
|
|
|
|
@@ -449,7 +474,7 @@
|
|
|
|
|
"</div>" +
|
|
|
|
|
'<div class="cf24-u-tablewrap"><table class="cf24-variants cf24-u-table"><thead><tr>' +
|
|
|
|
|
'<th class="cf24-u-drag"></th><th class="cf24-u-thumb">썸네일</th><th>옵션값 이름</th><th class="cf24-v-syscode">품목코드</th>' +
|
|
|
|
|
'<th class="cf24-v-code">자체 품목코드</th><th class="cf24-v-amount">추가금액</th><th class="cf24-v-amount">판매 가격</th><th class="cf24-v-flag">진열</th><th class="cf24-v-flag">판매</th><th class="cf24-u-del"></th>' +
|
|
|
|
|
'<th class="cf24-v-code">자체 품목코드</th><th class="cf24-v-amount">추가금액</th><th class="cf24-v-amount">판매 가격</th><th class="cf24-v-flag">진열</th><th class="cf24-v-flag">판매</th>' + INVENTORY_TH + '<th class="cf24-u-del"></th>' +
|
|
|
|
|
"</tr></thead><tbody id=\"cf24-u-body\">";
|
|
|
|
|
rows.forEach(function (r, i) { html += rowHtml(r, canDrag, i); });
|
|
|
|
|
if (isNew) html += rowHtml({ index: null, value: null, variant: null }, true, null);
|
|
|
|
@@ -569,8 +594,8 @@
|
|
|
|
|
link: tr.querySelector('[name="option_link_image"]').value,
|
|
|
|
|
custom: tr.querySelector('[name="custom_variant_code"]').value,
|
|
|
|
|
amount: tr.querySelector('[name="additional_amount"]').value,
|
|
|
|
|
display: tr.querySelector('.cf24-v-toggle[data-flag="display"]').dataset.on,
|
|
|
|
|
selling: tr.querySelector('.cf24-v-toggle[data-flag="selling"]').dataset.on
|
|
|
|
|
quantity: tr.querySelector('[name="quantity"]').value,
|
|
|
|
|
flags: FLAGS.map(function (flag) { return tr.querySelector('.cf24-v-toggle[data-flag="' + flag + '"]').dataset.on; })
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@@ -598,11 +623,12 @@
|
|
|
|
|
set('[name="option_text"]', k.text);
|
|
|
|
|
set('[name="custom_variant_code"]', k.custom);
|
|
|
|
|
set('[name="additional_amount"]', k.amount);
|
|
|
|
|
set('[name="quantity"]', k.quantity);
|
|
|
|
|
if (k.image) { tr.querySelector('[name="option_image_file"]').value = k.image; }
|
|
|
|
|
if (k.link) { tr.querySelector('[name="option_link_image"]').value = k.link; }
|
|
|
|
|
["display", "selling"].forEach(function (flag) {
|
|
|
|
|
FLAGS.forEach(function (flag, i) {
|
|
|
|
|
var btn = tr.querySelector('.cf24-v-toggle[data-flag="' + flag + '"]');
|
|
|
|
|
if (btn && btn.dataset.on !== k[flag]) paintToggle(btn, k[flag] === "1", false);
|
|
|
|
|
if (btn && btn.dataset.on !== k.flags[i]) paintToggle(btn, k.flags[i] === "1", false);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@@ -766,7 +792,7 @@
|
|
|
|
|
/* ── 저장 (통합) ── */
|
|
|
|
|
function collectUnified(tbody) {
|
|
|
|
|
return Array.prototype.map.call(tbody.children, function (tr, i) {
|
|
|
|
|
return {
|
|
|
|
|
return variantFields(tr, {
|
|
|
|
|
tr: tr,
|
|
|
|
|
position: i,
|
|
|
|
|
isNew: tr.classList.contains("is-new"),
|
|
|
|
@@ -774,12 +800,8 @@
|
|
|
|
|
code: tr.dataset.code || "",
|
|
|
|
|
text: tr.querySelector('[name="option_text"]').value.trim(),
|
|
|
|
|
image: tr.querySelector('[name="option_image_file"]').value,
|
|
|
|
|
link: tr.querySelector('[name="option_link_image"]').value,
|
|
|
|
|
custom: tr.querySelector('[name="custom_variant_code"]'),
|
|
|
|
|
amount: tr.querySelector('[name="additional_amount"]'),
|
|
|
|
|
display: tr.querySelector('.cf24-v-toggle[data-flag="display"]'),
|
|
|
|
|
selling: tr.querySelector('.cf24-v-toggle[data-flag="selling"]')
|
|
|
|
|
};
|
|
|
|
|
link: tr.querySelector('[name="option_link_image"]').value
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -801,20 +823,25 @@
|
|
|
|
|
var any = false;
|
|
|
|
|
if (r.custom.value !== r.custom.defaultValue) { patch.custom_variant_code = r.custom.value.trim(); any = true; }
|
|
|
|
|
if (r.amount.value !== r.amount.defaultValue) { patch.additional_amount = r.amount.value.trim() || "0"; any = true; }
|
|
|
|
|
if (r.display.dataset.on !== r.display.dataset.initial) { patch.display = r.display.dataset.on === "1" ? "on" : "off"; any = true; }
|
|
|
|
|
if (r.selling.dataset.on !== r.selling.dataset.initial) { patch.selling = r.selling.dataset.on === "1" ? "on" : "off"; any = true; }
|
|
|
|
|
if (r.quantity.value !== r.quantity.defaultValue) { patch.quantity = r.quantity.value.trim() || "0"; any = true; }
|
|
|
|
|
FLAGS.forEach(function (flag) {
|
|
|
|
|
if (r[flag].dataset.on !== r[flag].dataset.initial) { patch[flag] = r[flag].dataset.on === "1" ? "on" : "off"; any = true; }
|
|
|
|
|
});
|
|
|
|
|
if (withOrder) { patch.display_order = r.position + 1; any = true; }
|
|
|
|
|
return any ? patch : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 새 행(아직 품목 없음)의 초기 패치 — 기본값(빈 코드·0원·진열·판매)과 다른 것만
|
|
|
|
|
// 새 행(아직 품목 없음)의 초기 패치 — 기본값(빈 코드·0원·진열·판매·재고관리 미사용·재고 0·품절표시 안함)과 다른 것만
|
|
|
|
|
function newRowPatch(r, code) {
|
|
|
|
|
var p = { variant_code: code };
|
|
|
|
|
var any = false;
|
|
|
|
|
if (r.custom.value.trim()) { p.custom_variant_code = r.custom.value.trim(); any = true; }
|
|
|
|
|
if (amountPlain(r.amount.value) !== "0") { p.additional_amount = r.amount.value.trim(); any = true; }
|
|
|
|
|
if (r.display.dataset.on !== "1") { p.display = "off"; any = true; }
|
|
|
|
|
if (r.selling.dataset.on !== "1") { p.selling = "off"; any = true; }
|
|
|
|
|
if (amountPlain(r.quantity.value) !== "0") { p.quantity = r.quantity.value.trim(); any = true; }
|
|
|
|
|
FLAGS.forEach(function (flag) {
|
|
|
|
|
var defaultOn = flag === "display" || flag === "selling";
|
|
|
|
|
if ((r[flag].dataset.on === "1") !== defaultOn) { p[flag] = defaultOn ? "off" : "on"; any = true; }
|
|
|
|
|
});
|
|
|
|
|
return any ? p : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -866,7 +893,7 @@
|
|
|
|
|
|
|
|
|
|
var lines = [];
|
|
|
|
|
if (optionsChanged) lines.push("옵션명·옵션값 이름/썸네일/표시방식");
|
|
|
|
|
if (patches.length) lines.push("품목 " + patches.length + "건 (자체코드·추가금액·진열/판매" + (orderChanged ? "·순서" : "") + ")");
|
|
|
|
|
if (patches.length) lines.push("품목 " + patches.length + "건 (자체코드·추가금액·진열/판매·재고" + (orderChanged ? "·순서" : "") + ")");
|
|
|
|
|
window.erpConfirm("카페24에 바로 반영합니다. 계속할까요?\n\n- " + lines.join("\n- ")).then(function (ok) {
|
|
|
|
|
if (!ok) return;
|
|
|
|
|
saveBtn.disabled = true;
|
|
|
|
@@ -1013,7 +1040,7 @@
|
|
|
|
|
html += '<p class="cf24-muted">품목이 아직 조회되지 않았습니다. 잠시 뒤 창을 닫았다 다시 여세요.</p>';
|
|
|
|
|
} else {
|
|
|
|
|
html += '<div class="cf24-variants-wrap"><table class="cf24-variants"><thead><tr><th class="cf24-v-imgcol"></th><th>옵션</th><th class="cf24-v-syscode">품목코드</th>' +
|
|
|
|
|
'<th class="cf24-v-code">자체 품목코드</th><th class="cf24-v-amount">추가금액</th><th class="cf24-v-amount">판매 가격</th><th class="cf24-v-flag">진열</th><th class="cf24-v-flag">판매</th><th class="cf24-u-del"></th></tr></thead><tbody>';
|
|
|
|
|
'<th class="cf24-v-code">자체 품목코드</th><th class="cf24-v-amount">추가금액</th><th class="cf24-v-amount">판매 가격</th><th class="cf24-v-flag">진열</th><th class="cf24-v-flag">판매</th>' + INVENTORY_TH + '<th class="cf24-u-del"></th></tr></thead><tbody>';
|
|
|
|
|
variants.forEach(function (v) {
|
|
|
|
|
var label = v.options.map(function (o) { return o.value; }).join(" / ") || v.variant_code;
|
|
|
|
|
html += '<tr class="cf24-v-item" data-code="' + esc(v.variant_code) + '">' +
|
|
|
|
@@ -1024,6 +1051,7 @@
|
|
|
|
|
'<td class="cf24-v-amount"><input type="text" name="additional_amount" inputmode="numeric" value="' + esc(amountPlain(v.additional_amount)) + '" /></td>' +
|
|
|
|
|
salePriceCell(v.additional_amount) +
|
|
|
|
|
'<td class="cf24-v-flag">' + toggleBtn("display", !!v.display) + "</td><td class=\"cf24-v-flag\">" + toggleBtn("selling", !!v.selling) + "</td>" +
|
|
|
|
|
inventoryCells(v) +
|
|
|
|
|
'<td class="cf24-u-del"><button type="button" class="cf24-u-remove" data-code="' + esc(v.variant_code) + '" title="품목 삭제 (카페24에 바로 반영)">✕</button></td></tr>';
|
|
|
|
|
});
|
|
|
|
|
html += "</tbody></table></div><div class=\"cf24-side-actions\" style=\"margin-top:8px;\"><span class=\"cf24-muted\" id=\"cf24-var-msg\"></span>" +
|
|
|
|
@@ -1106,9 +1134,7 @@
|
|
|
|
|
var saveBtn = body.querySelector("#cf24-var-save");
|
|
|
|
|
var rows = [];
|
|
|
|
|
wrap.querySelectorAll("tr[data-code]").forEach(function (tr) {
|
|
|
|
|
var r = { code: tr.dataset.code, custom: tr.querySelector('[name="custom_variant_code"]'), amount: tr.querySelector('[name="additional_amount"]'),
|
|
|
|
|
display: tr.querySelector('.cf24-v-toggle[data-flag="display"]'), selling: tr.querySelector('.cf24-v-toggle[data-flag="selling"]') };
|
|
|
|
|
var p = variantPatch(r, false);
|
|
|
|
|
var p = variantPatch(variantFields(tr, { code: tr.dataset.code }), false);
|
|
|
|
|
if (p) rows.push(p);
|
|
|
|
|
});
|
|
|
|
|
if (!rows.length) { setMsg(msg, "바뀐 품목이 없습니다.", ""); return; }
|
|
|
|
@@ -1125,6 +1151,7 @@
|
|
|
|
|
if (!tr) return;
|
|
|
|
|
if (u.custom_variant_code !== undefined) tr.querySelector('[name="custom_variant_code"]').value = u.custom_variant_code;
|
|
|
|
|
if (u.additional_amount !== undefined) tr.querySelector('[name="additional_amount"]').value = amountPlain(u.additional_amount);
|
|
|
|
|
if (u.quantity != null) tr.querySelector('[name="quantity"]').value = String(u.quantity);
|
|
|
|
|
tr.querySelectorAll(".cf24-v-toggle").forEach(function (btn) {
|
|
|
|
|
if (u[btn.dataset.flag] !== undefined) paintToggle(btn, !!u[btn.dataset.flag], true);
|
|
|
|
|
});
|
|
|
|
@@ -1132,8 +1159,8 @@
|
|
|
|
|
if (v.variant_code !== code) return;
|
|
|
|
|
if (u.custom_variant_code !== undefined) v.custom_variant_code = u.custom_variant_code;
|
|
|
|
|
if (u.additional_amount !== undefined) v.additional_amount = u.additional_amount;
|
|
|
|
|
if (u.display !== undefined) v.display = !!u.display;
|
|
|
|
|
if (u.selling !== undefined) v.selling = !!u.selling;
|
|
|
|
|
if (u.quantity != null) v.quantity = u.quantity;
|
|
|
|
|
FLAGS.forEach(function (flag) { if (u[flag] !== undefined) v[flag] = !!u[flag]; });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
commitValues(wrap);
|
|
|
|
|