|
@@ -80,8 +80,17 @@ watch(() => props.open, (next) => {
|
|
|
primeAdvancedJson();
|
|
primeAdvancedJson();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-watch(activeKey, (key) => {
|
|
|
|
|
- if (key === '2') primeAdvancedJson();
|
|
|
|
|
|
|
+let isRevertingTab = false;
|
|
|
|
|
+watch(activeKey, (key, prev) => {
|
|
|
|
|
+ if (isRevertingTab) { isRevertingTab = false; return; }
|
|
|
|
|
+ if (key === '2') {
|
|
|
|
|
+ primeAdvancedJson();
|
|
|
|
|
+ } else if (key === '1' && prev === '2') {
|
|
|
|
|
+ if (!applyAdvancedJsonToForm()) {
|
|
|
|
|
+ isRevertingTab = true;
|
|
|
|
|
+ activeKey.value = '2';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
function primeAdvancedJson() {
|
|
function primeAdvancedJson() {
|
|
@@ -93,6 +102,33 @@ function primeAdvancedJson() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function applyAdvancedJsonToForm() {
|
|
|
|
|
+ const raw = advancedJson.value.trim();
|
|
|
|
|
+ if (!raw) return true;
|
|
|
|
|
+ let currentJson = '';
|
|
|
|
|
+ try {
|
|
|
|
|
+ currentJson = JSON.stringify(outbound.value?.toJson() ?? {}, null, 2);
|
|
|
|
|
+ } catch (_e) { /* fall through */ }
|
|
|
|
|
+ if (raw === currentJson.trim()) return true;
|
|
|
|
|
+ let parsed;
|
|
|
|
|
+ try {
|
|
|
|
|
+ parsed = JSON.parse(raw);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ message.error(`JSON: ${e.message}`);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ const fallbackTag = outbound.value?.tag;
|
|
|
|
|
+ const next = Outbound.fromJson(parsed);
|
|
|
|
|
+ if (!next.tag && fallbackTag) next.tag = fallbackTag;
|
|
|
|
|
+ outbound.value = next;
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ message.error(`JSON: ${e.message}`);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function close() { emit('update:open', false); }
|
|
function close() { emit('update:open', false); }
|
|
|
|
|
|
|
|
function onProtocolChange(next) {
|
|
function onProtocolChange(next) {
|
|
@@ -131,27 +167,15 @@ const tagHelp = computed(() => {
|
|
|
// ============== Submit ==============
|
|
// ============== Submit ==============
|
|
|
function onOk() {
|
|
function onOk() {
|
|
|
if (!outbound.value) return;
|
|
if (!outbound.value) return;
|
|
|
|
|
+ if (activeKey.value === '2' && !applyAdvancedJsonToForm()) return;
|
|
|
if (!outbound.value.tag?.trim()) {
|
|
if (!outbound.value.tag?.trim()) {
|
|
|
- message.error(t('somethingWentWrong'));
|
|
|
|
|
|
|
+ message.error('Tag is required');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
if (duplicateTag.value) {
|
|
if (duplicateTag.value) {
|
|
|
- message.error(t('somethingWentWrong'));
|
|
|
|
|
|
|
+ message.error('Tag already used by another outbound');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- // If user spent time in the JSON tab, prefer that body — round-trip
|
|
|
|
|
- // it through Outbound.fromJson so the wire shape stays consistent.
|
|
|
|
|
- if (activeKey.value === '2' && advancedJson.value.trim()) {
|
|
|
|
|
- try {
|
|
|
|
|
- const parsed = JSON.parse(advancedJson.value);
|
|
|
|
|
- const built = Outbound.fromJson(parsed);
|
|
|
|
|
- emit('confirm', built.toJson());
|
|
|
|
|
- return;
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- message.error(`JSON: ${e.message}`);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
emit('confirm', outbound.value.toJson());
|
|
emit('confirm', outbound.value.toJson());
|
|
|
}
|
|
}
|
|
|
|
|
|