MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / saveCurrentAsTemplate

Function saveCurrentAsTemplate

static/js/payment.js:808–852  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

806}
807
808function saveCurrentAsTemplate() {
809 const name = getInputValue("billing-template-name");
810 if (!name) {
811 toast.warning("请先填写模板名称");
812 return;
813 }
814
815 const form = normalizeTemplateData(collectBillingFormData());
816 const hasValue = Boolean(
817 form.card_number ||
818 (form.exp_month && form.exp_year) ||
819 form.cvc ||
820 form.billing_name ||
821 form.address_line1
822 );
823 if (!hasValue) {
824 toast.warning("当前表单为空,无法保存模板");
825 return;
826 }
827
828 const templates = getBillingTemplates();
829 const normalizedName = name.toLowerCase();
830 const existing = templates.find((tpl) => String(tpl.name || "").toLowerCase() === normalizedName);
831 const nowIso = new Date().toISOString();
832 if (existing) {
833 existing.data = form;
834 existing.updated_at = nowIso;
835 saveBillingTemplates(templates);
836 refreshBillingTemplateSelect(existing.id);
837 toast.success(`模板已更新: ${name}`);
838 return;
839 }
840
841 const newTemplate = {
842 id: `tpl_${Date.now()}_${Math.random().toString(16).slice(2, 8)}`,
843 name,
844 data: form,
845 created_at: nowIso,
846 updated_at: nowIso,
847 };
848 templates.unshift(newTemplate);
849 saveBillingTemplates(templates);
850 refreshBillingTemplateSelect(newTemplate.id);
851 toast.success(`模板已保存: ${name}`);
852}
853
854function applySelectedTemplate() {
855 const selectEl = document.getElementById("billing-template-select");

Callers

nothing calls this directly

Calls 8

getInputValueFunction · 0.85
normalizeTemplateDataFunction · 0.85
collectBillingFormDataFunction · 0.85
getBillingTemplatesFunction · 0.85
saveBillingTemplatesFunction · 0.85
warningMethod · 0.80
successMethod · 0.80

Tested by

no test coverage detected