/**
* 目录操作「从其他处复制到此处」对话框:支持多条源路径/目标路径。
* 若打开时已选中子目录树节点,则目标路径固定为选中路径;否则可在当前目录框内选择目标。
*/
window.IARDirCopyFromDialog = (function () {
'use strict';
var MODAL_ID = 'iarDirCopyFromModal';
var ROWS_ID = 'iarDirCopyFromRows';
var _pendingResolve = null;
var _rowSeq = 0;
var _ctx = {
boxLabel: '',
targetColLabel: '',
lockedTarget: null,
initialLockedTarget: null,
localTargets: [],
pageSourceTargets: [],
otherSourceTargets: [],
fetchTree: null,
refreshOtherTargets: null,
sourceOpsId: '',
defaultTargetColKey: '',
getLockedTarget: null,
};
var _rows = [];
function esc(s) {
if (s == null) return '';
var d = document.createElement('div');
d.textContent = String(s);
return d.innerHTML;
}
function basename(relPath) {
var p = String(relPath || '').replace(/\\/g, '/');
var parts = p.split('/');
return parts.length ? parts[parts.length - 1] : p;
}
function _formatTargetLabel(colLabel, parentPath, toRoot) {
if (toRoot || !parentPath) return colLabel + '(根目录)';
return colLabel + ' / ' + String(parentPath).replace(/\\/g, '/');
}
function _effectiveLockedTarget() {
if (_ctx.lockedTarget) return _ctx.lockedTarget;
if (_ctx.initialLockedTarget) return _ctx.initialLockedTarget;
return null;
}
function _buildOtherPages(targets) {
var pages = [];
var seen = {};
(targets || []).forEach(function (t) {
var key = t.pageKey || t.opsId;
if (seen[key]) {
if (!t.disabled) {
seen[key].disabled = false;
seen[key].disabledReason = '';
}
return;
}
var page = {
opsId: key,
pageLabel: t.pageLabel || t.boxLabel || key,
entityId: t.entityId,
disabled: !!t.disabled,
disabledReason: t.disabledReason || '',
};
seen[key] = page;
pages.push(page);
});
pages.sort(function (a, b) {
return String(a.pageLabel).localeCompare(String(b.pageLabel), 'zh-CN');
});
return pages;
}
function _otherTargetsForPage(targets, opsId) {
return (targets || []).filter(function (t) {
return t.pageKey === opsId || t.opsId === opsId;
});
}
function renderDirTree(items, indent, selectedPath) {
indent = indent || 0;
var html = '';
(items || []).forEach(function (it) {
if (it.type !== 'directory') return;
var path = String(it.path || '').replace(/\\/g, '/');
var pad = indent + 12;
html += '
' +
'📁 ' + esc(it.name || path) + ' ';
if (it.children && it.children.length) {
html += renderDirTree(it.children, indent + 16, selectedPath);
}
});
return html;
}
function renderSourceTree(items, indent, selectedPath) {
indent = indent || 0;
var html = '';
(items || []).forEach(function (it) {
var path = String(it.path || '').replace(/\\/g, '/');
var pad = indent + 12;
var icon = it.type === 'directory' ? '📁' : '📄';
html += '' +
icon + ' ' + esc(it.name || path) + ' ';
if (it.type === 'directory' && it.children && it.children.length) {
html += renderSourceTree(it.children, indent + 16, selectedPath);
}
});
return html;
}
function _findTargetByIndex(list, idx) {
if (isNaN(idx) || idx < 0 || idx >= list.length) return null;
return list[idx];
}
function _updateRowPathDisplays(row) {
var el = row.el;
if (!el) return;
var srcInput = el.querySelector('[data-role="source-path"]');
var tgtInput = el.querySelector('[data-role="target-path"]');
if (row.sourceTab === 'local') {
var localInput = el.querySelector('[data-role="source-local-path"]');
row.sourcePath = localInput ? String(localInput.value || '').trim() : row.sourcePath;
}
if (srcInput) {
srcInput.value = row.sourcePath
? String(row.sourcePath).replace(/\\/g, '/')
: '';
}
if (tgtInput) {
var locked = _effectiveLockedTarget();
if (locked) {
tgtInput.value = locked.display || '';
} else {
var tgt = row.targetMeta;
var label = tgt ? (tgt.colLabel || tgt.colKey) : '';
tgtInput.value = tgt
? _formatTargetLabel(label, row.targetParentPath, row.targetToRoot)
: '';
}
}
}
function _renderSourceTree(row) {
var treeEl = row.el.querySelector('[data-role="source-tree"]');
if (!treeEl) return;
var meta = row.sourceMeta;
if (!meta || meta.disabled || !row.sourceFilesData) {
treeEl.innerHTML = '' +
esc(meta && meta.disabled ? (meta.disabledReason || '源不可用') : '请选择源位置') + ' ';
return;
}
var items = row.sourceFilesData[meta.colKey] || [];
var html = renderSourceTree(items, 0, row.sourcePath);
treeEl.innerHTML = html || '(该位置下暂无文件或目录) ';
}
function _renderTargetTree(row) {
if (_ctx.lockedTarget) return;
var treeEl = row.el.querySelector('[data-role="target-tree"]');
if (!treeEl) return;
var meta = row.targetMeta;
if (!meta || meta.disabled || !row.targetFilesData) {
treeEl.innerHTML = '' +
esc(meta && meta.disabled ? (meta.disabledReason || '目标不可用') : '请选择目标子目录') + ' ';
return;
}
var items = row.targetFilesData[meta.colKey] || [];
var html = renderDirTree(items, 0, row.targetToRoot ? '' : row.targetParentPath);
treeEl.innerHTML = html || '(该子目录下暂无文件夹,将复制到根目录) ';
}
function _loadSourceTree(row) {
var treeEl = row.el.querySelector('[data-role="source-tree"]');
var meta = row.sourceMeta;
if (typeof _ctx.fetchTree !== 'function' || !meta || meta.disabled) {
row.sourceFilesData = null;
_renderSourceTree(row);
return Promise.resolve();
}
if (treeEl) treeEl.innerHTML = '加载中... ';
return _ctx.fetchTree(meta.opsId, meta.entityId).then(function (data) {
row.sourceFilesData = data || {};
row.sourcePath = '';
_renderSourceTree(row);
_updateRowPathDisplays(row);
}).catch(function (err) {
row.sourceFilesData = null;
if (treeEl) {
treeEl.innerHTML = '加载失败:' +
esc(err.message || String(err)) + ' ';
}
});
}
function _loadTargetTree(row) {
if (_ctx.lockedTarget) return Promise.resolve();
var treeEl = row.el.querySelector('[data-role="target-tree"]');
var meta = row.targetMeta;
if (typeof _ctx.fetchTree !== 'function' || !meta || meta.disabled) {
row.targetFilesData = null;
_renderTargetTree(row);
return Promise.resolve();
}
if (treeEl) treeEl.innerHTML = '加载中... ';
return _ctx.fetchTree(meta.opsId, meta.entityId).then(function (data) {
row.targetFilesData = data || {};
_renderTargetTree(row);
_updateRowPathDisplays(row);
}).catch(function (err) {
row.targetFilesData = null;
if (treeEl) {
treeEl.innerHTML = '加载失败:' +
esc(err.message || String(err)) + ' ';
}
});
}
function _fillSourceLocalSelect(row) {
var selectEl = row.el.querySelector('[data-role="source-local-select"]');
if (!selectEl) return;
var targets = _ctx.pageSourceTargets || [];
var html = '';
targets.forEach(function (t, idx) {
html += '' +
esc(t.colLabel) + (t.disabled ? '(' + esc(t.disabledReason || '不可用') + ')' : '') + ' ';
});
selectEl.innerHTML = html || '(无可用源) ';
var first = targets.find(function (t) { return !t.disabled; }) || targets[0] || null;
row.sourceMeta = first;
selectEl.value = first ? String(targets.indexOf(first)) : '';
}
function _fillSourcePageSelect(row) {
var selectEl = row.el.querySelector('[data-role="source-page-select"]');
var hintEl = row.el.querySelector('[data-role="source-page-hint"]');
if (!selectEl) return;
if (typeof _ctx.refreshOtherTargets === 'function') {
_ctx.otherSourceTargets = _ctx.refreshOtherTargets() || _ctx.otherSourceTargets;
}
var pages = _buildOtherPages(_ctx.otherSourceTargets);
var html = '';
pages.forEach(function (p) {
html += '' +
esc(p.pageLabel) + (p.disabled ? '(' + esc(p.disabledReason || '不可用') + ')' : '') + ' ';
});
selectEl.innerHTML = html || '(无其它页面) ';
var first = pages.find(function (p) { return !p.disabled; }) || pages[0] || null;
row.sourcePageOpsId = first ? String(first.opsId) : '';
selectEl.value = row.sourcePageOpsId;
if (hintEl) {
hintEl.textContent = pages.length
? '共 ' + pages.length + ' 个其它页面;不可用项请先在对应页面打开目录操作对话框。'
: '当前页面暂无其它已注册目录框页面。';
}
_fillSourceOtherSelect(row);
}
function _fillSourceOtherSelect(row) {
var selectEl = row.el.querySelector('[data-role="source-other-select"]');
if (!selectEl) return;
var targets = _otherTargetsForPage(_ctx.otherSourceTargets, row.sourcePageOpsId);
var html = '';
targets.forEach(function (t, idx) {
html += '' +
esc(t.colLabel) + (t.disabled ? '(' + esc(t.disabledReason || '不可用') + ')' : '') + ' ';
});
selectEl.innerHTML = html || '(该页面下无可用源) ';
var firstIdx = -1;
var i;
for (i = 0; i < targets.length; i++) {
if (!targets[i].disabled) { firstIdx = i; break; }
}
var pickIdx = firstIdx >= 0 ? firstIdx : (targets.length ? 0 : -1);
selectEl.selectedIndex = pickIdx;
row.sourceMeta = pickIdx >= 0 ? targets[pickIdx] : null;
}
function _fillTargetLocalSelect(row) {
if (_ctx.lockedTarget) return;
var selectEl = row.el.querySelector('[data-role="target-local-select"]');
if (!selectEl) return;
var targets = _ctx.localTargets || [];
var html = '';
targets.forEach(function (t, idx) {
html += '' +
esc(t.colLabel) + (t.disabled ? '(' + esc(t.disabledReason || '不可用') + ')' : '') + ' ';
});
selectEl.innerHTML = html || '(无可用目标) ';
var preferred = targets.find(function (t) {
return t.colKey === _ctx.defaultTargetColKey && !t.disabled;
});
var first = preferred || targets.find(function (t) { return !t.disabled; }) || targets[0] || null;
row.targetMeta = first;
selectEl.value = first ? String(targets.indexOf(first)) : '';
}
function _syncSourceTabButtons(row) {
if (!row.el) return;
row.el.querySelectorAll('[data-role="source-tab"]').forEach(function (btn) {
btn.classList.toggle('active', btn.getAttribute('data-tab') === row.sourceTab);
});
}
async function _pickLocalPath(row, kind) {
var input = row.el.querySelector('[data-role="source-local-path"]');
var initial = input ? input.value.trim() : '';
var url = '/api/system/select-path?kind=' + encodeURIComponent(kind);
if (kind === 'file') url += '&filter=all';
if (initial) url += '&initial=' + encodeURIComponent(initial);
try {
var resp = await fetch(url);
var data = await resp.json();
if (data && data.success && data.path) {
row.sourcePath = data.path;
if (input) input.value = data.path;
_updateRowPathDisplays(row);
} else if (data && data.message && data.message !== '已取消选择') {
alert(data.message);
}
} catch (err) {
alert('选择路径失败:' + (err.message || String(err)));
}
}
function _renderLocalBrowser(row, data) {
var browserEl = row.el.querySelector('[data-role="source-local-browser"]');
if (!browserEl) return;
if (!data || !data.success) {
browserEl.innerHTML = '加载失败 ';
return;
}
var html = '';
if (data.parent) {
html += '⬆ ' +
esc(data.parent) + ' ';
} else if (data.roots) {
html += '选择盘符或目录 ';
} else if (data.path) {
html += '当前:' + esc(data.path) + ' ';
}
(data.entries || []).forEach(function (entry) {
var icon = entry.type === 'directory' ? '📁' : '📄';
html += '' +
icon + ' ' + esc(entry.name || entry.path) + ' ';
});
browserEl.innerHTML = html || '(空目录) ';
row.localBrowsePath = data.path || '';
row.localBrowseParent = data.parent || '';
}
function _loadLocalBrowser(row, path) {
var browserEl = row.el.querySelector('[data-role="source-local-browser"]');
if (browserEl) browserEl.innerHTML = '加载中... ';
var url = '/api/system/browse-path?kind=file';
if (path) url += '&path=' + encodeURIComponent(path);
return fetch(url).then(function (resp) { return resp.json(); }).then(function (data) {
_renderLocalBrowser(row, data);
}).catch(function (err) {
if (browserEl) {
browserEl.innerHTML = '加载失败:' +
esc(err.message || String(err)) + ' ';
}
});
}
function _switchSourceTab(row, tab) {
row.sourceTab = tab === 'other' ? 'other' : (tab === 'local' ? 'local' : 'page');
var pagePane = row.el.querySelector('[data-role="source-pane-page"]');
var otherPane = row.el.querySelector('[data-role="source-pane-other"]');
var localPane = row.el.querySelector('[data-role="source-pane-local"]');
var treeWrap = row.el.querySelector('[data-role="source-tree-wrap"]');
if (pagePane) pagePane.classList.toggle('d-none', row.sourceTab !== 'page');
if (otherPane) otherPane.classList.toggle('d-none', row.sourceTab !== 'other');
if (localPane) localPane.classList.toggle('d-none', row.sourceTab !== 'local');
if (treeWrap) treeWrap.classList.toggle('d-none', row.sourceTab === 'local');
_syncSourceTabButtons(row);
row.sourcePath = '';
if (row.sourceTab === 'local') {
row.sourceMeta = null;
row.sourceFilesData = null;
var localInput = row.el.querySelector('[data-role="source-local-path"]');
if (localInput) localInput.value = '';
_updateRowPathDisplays(row);
return;
}
if (row.sourceTab === 'other') {
_fillSourcePageSelect(row);
} else {
_fillSourceLocalSelect(row);
}
_loadSourceTree(row);
}
function _bindRowEvents(row) {
var el = row.el;
el.querySelectorAll('[data-role="source-tab"]').forEach(function (btn) {
btn.addEventListener('click', function () {
_switchSourceTab(row, btn.getAttribute('data-tab'));
});
});
var localSelect = el.querySelector('[data-role="source-local-select"]');
if (localSelect) {
localSelect.addEventListener('change', function () {
var idx = parseInt(localSelect.value, 10);
row.sourceMeta = _findTargetByIndex(_ctx.pageSourceTargets, idx);
row.sourcePath = '';
_loadSourceTree(row);
});
}
var pageSelect = el.querySelector('[data-role="source-page-select"]');
if (pageSelect) {
pageSelect.addEventListener('change', function () {
row.sourcePageOpsId = pageSelect.value || '';
row.sourcePath = '';
_fillSourceOtherSelect(row);
_loadSourceTree(row);
});
}
var otherSelect = el.querySelector('[data-role="source-other-select"]');
if (otherSelect) {
otherSelect.addEventListener('change', function () {
var idx = parseInt(otherSelect.value, 10);
var targets = _otherTargetsForPage(_ctx.otherSourceTargets, row.sourcePageOpsId);
row.sourceMeta = _findTargetByIndex(targets, idx);
row.sourcePath = '';
_loadSourceTree(row);
});
}
var srcTree = el.querySelector('[data-role="source-tree"]');
if (srcTree) {
srcTree.addEventListener('click', function (e) {
var li = e.target.closest('.iar-copy-from-src-item');
if (!li) return;
row.sourcePath = li.getAttribute('data-path') || '';
_renderSourceTree(row);
_updateRowPathDisplays(row);
});
}
var localInput = el.querySelector('[data-role="source-local-path"]');
if (localInput) {
localInput.addEventListener('input', function () {
row.sourcePath = localInput.value.trim();
_updateRowPathDisplays(row);
});
}
var pickFileBtn = el.querySelector('[data-role="source-pick-file"]');
if (pickFileBtn) {
pickFileBtn.addEventListener('click', function () { _pickLocalPath(row, 'file'); });
}
var pickDirBtn = el.querySelector('[data-role="source-pick-dir"]');
if (pickDirBtn) {
pickDirBtn.addEventListener('click', function () { _pickLocalPath(row, 'directory'); });
}
var browseBtn = el.querySelector('[data-role="source-browse-local"]');
if (browseBtn) {
browseBtn.addEventListener('click', function () {
var wrap = el.querySelector('[data-role="source-local-browser-wrap"]');
if (wrap) wrap.classList.remove('d-none');
var initial = localInput ? localInput.value.trim() : '';
_loadLocalBrowser(row, initial);
});
}
var browserEl = el.querySelector('[data-role="source-local-browser"]');
if (browserEl) {
browserEl.addEventListener('click', function (e) {
var up = e.target.closest('.iar-copy-from-local-up');
if (up && row.localBrowseParent) {
_loadLocalBrowser(row, row.localBrowseParent);
return;
}
var li = e.target.closest('.iar-copy-from-local-item');
if (!li) return;
var p = li.getAttribute('data-path') || '';
var typ = li.getAttribute('data-type') || 'file';
if (typ === 'directory') {
_loadLocalBrowser(row, p);
return;
}
row.sourcePath = p;
if (localInput) localInput.value = p;
_loadLocalBrowser(row, row.localBrowsePath || '');
_updateRowPathDisplays(row);
});
}
if (!_ctx.lockedTarget) {
var tgtSelect = el.querySelector('[data-role="target-local-select"]');
if (tgtSelect) {
tgtSelect.addEventListener('change', function () {
var idx = parseInt(tgtSelect.value, 10);
row.targetMeta = _findTargetByIndex(_ctx.localTargets, idx);
row.targetParentPath = '';
row.targetToRoot = false;
var rootCheck = el.querySelector('[data-role="target-root-check"]');
if (rootCheck) rootCheck.checked = false;
_loadTargetTree(row);
});
}
var rootCheck = el.querySelector('[data-role="target-root-check"]');
if (rootCheck) {
rootCheck.addEventListener('change', function () {
row.targetToRoot = !!rootCheck.checked;
if (row.targetToRoot) row.targetParentPath = '';
_renderTargetTree(row);
_updateRowPathDisplays(row);
});
}
var tgtTree = el.querySelector('[data-role="target-tree"]');
if (tgtTree) {
tgtTree.addEventListener('click', function (e) {
var li = e.target.closest('.iar-copy-from-dir-item');
if (!li) return;
row.targetParentPath = li.getAttribute('data-path') || '';
row.targetToRoot = false;
if (rootCheck) rootCheck.checked = false;
_renderTargetTree(row);
_updateRowPathDisplays(row);
});
}
}
var removeBtn = el.querySelector('[data-role="remove-row"]');
if (removeBtn) {
removeBtn.addEventListener('click', function () {
if (_rows.length <= 1) {
alert('至少保留一条源/目标路径');
return;
}
_removeRow(row.id);
});
}
}
function _rowHtml(rowIndex, canRemove) {
var locked = !!_ctx.lockedTarget;
var targetBlock = locked
? '目标路径(来自当前选中)
' +
' '
: '' +
'目标子目录 ' +
' ' +
'
' +
'' +
' ' +
'复制到该子目录根目录 ' +
'
' +
'' +
' ';
return '' +
'
' +
'第 ' + (rowIndex + 1) + ' 条 ' +
(canRemove
? '删除 '
: '') +
'
' +
'
' +
'
' +
'
源路径
' +
'
' +
'当前页面 ' +
'其它页面 ' +
'本机路径 ' +
'
' +
'
' +
' ' +
'
' +
'
' +
'
' +
'
' +
' ' +
'选文件 ' +
'选文件夹 ' +
'浏览 ' +
'
' +
'
可手动输入路径;「选文件/选文件夹」在本机弹出系统对话框(需 Flask 与浏览器同机且有图形界面);「浏览」适用于远程访问。
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
目标路径
' +
targetBlock +
'
' +
'
' +
'
';
}
function _createRow() {
var id = _rowSeq++;
var row = {
id: id,
el: null,
sourceTab: 'page',
sourcePageOpsId: '',
sourceMeta: null,
sourceFilesData: null,
sourcePath: '',
targetMeta: null,
targetFilesData: null,
targetParentPath: '',
targetToRoot: false,
};
var host = document.getElementById(ROWS_ID);
if (!host) return row;
var wrap = document.createElement('div');
wrap.innerHTML = _rowHtml(_rows.length, _rows.length > 0);
row.el = wrap.firstElementChild;
host.appendChild(row.el);
_rows.push(row);
_bindRowEvents(row);
_switchSourceTab(row, 'page');
if (!_ctx.lockedTarget) {
_fillTargetLocalSelect(row);
_loadTargetTree(row);
} else {
_updateRowPathDisplays(row);
}
_renumberRows();
return row;
}
function _removeRow(id) {
var idx = _rows.findIndex(function (r) { return r.id === id; });
if (idx < 0) return;
var row = _rows[idx];
if (row.el && row.el.parentNode) row.el.parentNode.removeChild(row.el);
_rows.splice(idx, 1);
_renumberRows();
}
function _renumberRows() {
_rows.forEach(function (row, idx) {
var title = row.el.querySelector('strong');
if (title) title.textContent = '第 ' + (idx + 1) + ' 条';
var removeBtn = row.el.querySelector('[data-role="remove-row"]');
if (removeBtn) removeBtn.style.display = _rows.length > 1 ? '' : 'none';
});
}
function _validateRow(row) {
if (row.sourceTab === 'local') {
var localInput = row.el.querySelector('[data-role="source-local-path"]');
var p = (localInput ? localInput.value : row.sourcePath || '').trim();
if (!p) return '请输入或选择本机源路径';
return '';
}
if (!row.sourcePath) return '请为每条记录选择源路径';
if (!row.sourceMeta || row.sourceMeta.disabled) return '源位置不可用';
var locked = _effectiveLockedTarget();
if (locked) return '';
if (!row.targetMeta || row.targetMeta.disabled) return '目标子目录不可用';
if (!row.targetToRoot && !(row.targetParentPath || '').trim()) {
return '请选择目标文件夹,或勾选「复制到该子目录根目录」';
}
return '';
}
function _rowResult(row) {
var locked = _effectiveLockedTarget();
var targetColKey = locked ? locked.colKey : (row.targetMeta ? row.targetMeta.colKey : '');
var toParent = locked
? locked.toParentPath
: (row.targetToRoot ? '' : (row.targetParentPath || ''));
var toRoot = locked
? !!locked.toRoot
: !!row.targetToRoot;
if (row.sourceTab === 'local') {
var localInput = row.el.querySelector('[data-role="source-local-path"]');
var localPath = (localInput ? localInput.value : row.sourcePath || '').trim();
return {
source: {
isLocal: true,
fromPath: localPath,
},
target: {
colKey: targetColKey,
toParentPath: toParent,
toRoot: toRoot,
colLabel: locked
? locked.colLabel
: (row.targetMeta ? row.targetMeta.colLabel : ''),
},
};
}
return {
source: {
opsId: row.sourceMeta.opsId,
colKey: row.sourceMeta.colKey,
entityId: row.sourceMeta.entityId,
fromPath: row.sourcePath,
colLabel: row.sourceMeta.colLabel,
boxLabel: row.sourceMeta.boxLabel,
},
target: {
colKey: targetColKey,
toParentPath: toParent,
toRoot: toRoot,
colLabel: locked
? locked.colLabel
: (row.targetMeta ? row.targetMeta.colLabel : ''),
},
};
}
function _bindModalEvents(el) {
if (!el || el.dataset.copyFromInit) return;
el.dataset.copyFromInit = '1';
el.addEventListener('hidden.bs.modal', function () {
if (_pendingResolve) {
var r = _pendingResolve;
_pendingResolve = null;
r(null);
}
_rows = [];
_ctx.initialLockedTarget = null;
_ctx.lockedTarget = null;
var host = document.getElementById(ROWS_ID);
if (host) host.innerHTML = '';
});
var addBtn = document.getElementById('iarDirCopyFromAddRowBtn');
if (addBtn) {
addBtn.addEventListener('click', function () {
_createRow();
});
}
var confirmBtn = document.getElementById('iarDirCopyFromConfirmBtn');
if (confirmBtn) {
confirmBtn.addEventListener('click', function () {
if (!_rows.length) {
alert('请至少添加一条源/目标路径');
return;
}
if (typeof _ctx.getLockedTarget === 'function') {
var freshLocked = _ctx.getLockedTarget();
_ctx.lockedTarget = freshLocked || _ctx.initialLockedTarget || null;
}
var results = [];
var i;
for (i = 0; i < _rows.length; i++) {
var err = _validateRow(_rows[i]);
if (err) {
alert('第 ' + (i + 1) + ' 条:' + err);
return;
}
results.push(_rowResult(_rows[i]));
}
var r = _pendingResolve;
_pendingResolve = null;
if (typeof bootstrap !== 'undefined' && bootstrap.Modal) {
var inst = bootstrap.Modal.getInstance(el);
if (inst) inst.hide();
}
if (r) r(results);
});
}
}
function ensureModal() {
var el = document.getElementById(MODAL_ID);
if (!el) {
console.error('IARDirCopyFromDialog: modal #' + MODAL_ID + ' not found');
return null;
}
_bindModalEvents(el);
return el;
}
function open(opts) {
opts = opts || {};
return new Promise(function (resolve) {
if (typeof bootstrap === 'undefined' || !bootstrap.Modal) {
alert('无法打开「从其他处复制到此处」对话框');
resolve(null);
return;
}
var modalEl = ensureModal();
if (!modalEl) {
alert('「从其他处复制到此处」对话框未加载');
resolve(null);
return;
}
_ctx.boxLabel = opts.boxLabel || '';
_ctx.targetColLabel = opts.targetColLabel || '';
_ctx.getLockedTarget = opts.getLockedTarget || null;
if (typeof _ctx.getLockedTarget === 'function') {
_ctx.lockedTarget = _ctx.getLockedTarget();
} else {
_ctx.lockedTarget = opts.lockedTarget || null;
}
_ctx.initialLockedTarget = _ctx.lockedTarget
? Object.assign({}, _ctx.lockedTarget)
: (opts.lockedTarget ? Object.assign({}, opts.lockedTarget) : null);
_ctx.localTargets = opts.localTargets || [];
_ctx.pageSourceTargets = opts.pageSourceTargets || [];
_ctx.otherSourceTargets = opts.otherSourceTargets || [];
_ctx.fetchTree = opts.fetchTree || null;
_ctx.refreshOtherTargets = opts.refreshOtherTargets || null;
_ctx.sourceOpsId = opts.sourceOpsId || '';
_ctx.defaultTargetColKey = opts.defaultTargetColKey || '';
if (typeof opts.refreshOtherTargets === 'function') {
_ctx.otherSourceTargets = opts.refreshOtherTargets() || _ctx.otherSourceTargets;
}
var hintEl = document.getElementById('iarDirCopyFromHint');
if (hintEl) {
hintEl.textContent = '将其它位置的文件或目录复制到「' +
(_ctx.boxLabel || '当前目录框') + ' / ' + (_ctx.targetColLabel || '') + '」。' +
'源路径可选当前/其它页面目录,也可输入或选择本机任意绝对路径。可添加多条源/目标路径。';
}
var lockedEl = document.getElementById('iarDirCopyFromLockedTarget');
if (lockedEl) {
if (_ctx.lockedTarget) {
lockedEl.classList.remove('d-none');
lockedEl.textContent = '当前子目录框已选中路径,所有条目的目标路径均为:' +
(_ctx.lockedTarget.display || '-');
} else {
lockedEl.classList.add('d-none');
lockedEl.textContent = '';
}
}
_rows = [];
_rowSeq = 0;
var host = document.getElementById(ROWS_ID);
if (host) host.innerHTML = '';
_createRow();
_pendingResolve = resolve;
var inst = bootstrap.Modal.getOrCreateInstance(modalEl);
inst.show();
});
}
return {
open: open,
basename: basename,
};
})();