|
|
@@ -7,14 +7,17 @@ $(document).ready(function() {
|
|
|
this.spread.options.showHorizontalScrollbar = false;
|
|
|
this.sheet = this.spread.getActiveSheet();
|
|
|
this.treeIcons = {
|
|
|
- folder: new Image(),
|
|
|
+ closed: new Image(),
|
|
|
+ open: new Image(),
|
|
|
leaf: new Image(),
|
|
|
};
|
|
|
const refreshTreeIcon = () => { this.spread.refresh(); };
|
|
|
- this.treeIcons.folder.onload = refreshTreeIcon;
|
|
|
+ this.treeIcons.closed.onload = refreshTreeIcon;
|
|
|
+ this.treeIcons.open.onload = refreshTreeIcon;
|
|
|
this.treeIcons.leaf.onload = refreshTreeIcon;
|
|
|
- this.treeIcons.folder.src = '/public/images/filesjs-folder.png';
|
|
|
- this.treeIcons.leaf.src = '/public/images/filesjs-leaf.png';
|
|
|
+ this.treeIcons.closed.src = '/public/images/filesjs-tree-closed.png';
|
|
|
+ this.treeIcons.open.src = '/public/images/filesjs-tree-open.png';
|
|
|
+ this.treeIcons.leaf.src = '/public/images/filesjs-tree-leaf.png';
|
|
|
const treeIcons = this.treeIcons;
|
|
|
|
|
|
this.filingTree = createNewPathTree('base', {
|
|
|
@@ -32,7 +35,7 @@ $(document).ready(function() {
|
|
|
getIcon: function(data) {
|
|
|
const fallback = data.is_leaf ? 'file' : 'folder';
|
|
|
return {
|
|
|
- image: data.is_leaf ? treeIcons.leaf : treeIcons.folder,
|
|
|
+ image: data.is_leaf ? treeIcons.leaf : (data.expanded ? treeIcons.open : treeIcons.closed),
|
|
|
fallback,
|
|
|
size: 18,
|
|
|
};
|
|
|
@@ -43,7 +46,8 @@ $(document).ready(function() {
|
|
|
title: '固定目录', colSpan: '1', rowSpan: '1', field: 'is_fixed', hAlign: 1, width: 75, formatter: '@',
|
|
|
getValue: function(data) { return data.is_fixed ? '\u{1F512}' : ''; },
|
|
|
},
|
|
|
- { title: '上传说明', colSpan: '1', rowSpan: '1', field: 'upload_tips', hAlign: 0, width: 200, formatter: '@', cellType: 'autoTip' },
|
|
|
+ { title: '归档单位', colSpan: '1', rowSpan: '1', field: 'file_company', hAlign: 0, width: 160, formatter: '@', cellType: 'autoTip', wordWrap: true },
|
|
|
+ { title: '上传说明', colSpan: '1', rowSpan: '1', field: 'upload_tips', hAlign: 0, width: 200, formatter: '@', cellType: 'autoTip', wordWrap: true },
|
|
|
{ title: '授权用户', colSpan: '1', rowSpan: '1', field: 'auth_users', hAlign: 0, width: 320, formatter: '@', cellType: 'autoTip' },
|
|
|
{ title: '添加人', colSpan: '1', rowSpan: '1', field: 'add_user', hAlign: 0, width: 90, formatter: '@', cellType: 'autoTip' },
|
|
|
],
|
|
|
@@ -54,6 +58,14 @@ $(document).ready(function() {
|
|
|
|
|
|
SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
|
|
|
this.curNode = null;
|
|
|
+ this.editableTextFields = [ 'upload_tips', 'file_company' ];
|
|
|
+ var editableTextFields = this.editableTextFields;
|
|
|
+ this.editableTextColumnIndexes = this.spreadSetting.cols.reduce(function(indexes, col, index) {
|
|
|
+ if (editableTextFields.indexOf(col.field) >= 0) indexes.push(index);
|
|
|
+ return indexes;
|
|
|
+ }, []);
|
|
|
+ this._textCellEditing = null;
|
|
|
+ this._editableTextCellType = null;
|
|
|
this._authUserSaving = false;
|
|
|
this._authTargetSaving = false;
|
|
|
this._buildAuthAccountList();
|
|
|
@@ -138,6 +150,7 @@ $(document).ready(function() {
|
|
|
file_count: Number(node.file_count) || 0,
|
|
|
is_fixed: node.is_fixed,
|
|
|
upload_tips: node.upload_tips || '',
|
|
|
+ file_company: node.file_company || '',
|
|
|
auth_users: authUsers.map(function(x) { return x.name; }).join('、'),
|
|
|
auth_user_ids: authUsers.map(function(x) { return Number(x.id); }),
|
|
|
add_user: node.add_user || '',
|
|
|
@@ -151,6 +164,7 @@ $(document).ready(function() {
|
|
|
var convertedData = this._convertData(filingData);
|
|
|
this.filingTree.loadDatas(convertedData);
|
|
|
SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree);
|
|
|
+ this._applyEditableTextCellType();
|
|
|
this._applyLastColumnRightBorder();
|
|
|
}
|
|
|
|
|
|
@@ -158,9 +172,37 @@ $(document).ready(function() {
|
|
|
var convertedData = this._convertData(filingData);
|
|
|
this.filingTree.loadDatas(convertedData);
|
|
|
SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.filingTree, true);
|
|
|
+ this._applyEditableTextCellType();
|
|
|
this._resizeSpreadColumns();
|
|
|
}
|
|
|
|
|
|
+ _isEditableTextColumn(columnIndex) {
|
|
|
+ return this.editableTextColumnIndexes.indexOf(columnIndex) >= 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ _applyEditableTextCellType() {
|
|
|
+ if (!this._editableTextCellType) {
|
|
|
+ this._editableTextCellType = SpreadJsObj.CellType.getAutoTipCellType();
|
|
|
+ var defaultIsReservedKey = this._editableTextCellType.isReservedKey;
|
|
|
+ this._editableTextCellType.isReservedKey = function(event, context) {
|
|
|
+ var target = event && (event.target || event.srcElement);
|
|
|
+ var isEditingInput = target && target.getAttribute &&
|
|
|
+ target.getAttribute('gcUIElement') === 'gcEditingInput';
|
|
|
+ if (event && event.keyCode === 13 && context && context.isEditing && isEditingInput &&
|
|
|
+ !event.ctrlKey && !event.altKey && !event.metaKey) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return defaultIsReservedKey ? defaultIsReservedKey.call(this, event, context) : false;
|
|
|
+ };
|
|
|
+ }
|
|
|
+ var self = this;
|
|
|
+ this.editableTextColumnIndexes.forEach(function(columnIndex) {
|
|
|
+ self.sheet.getRange(-1, columnIndex, -1, 1)
|
|
|
+ .cellType(self._editableTextCellType)
|
|
|
+ .wordWrap(true);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
_applyLastColumnRightBorder() {
|
|
|
var lastColumnIndex = this.spreadSetting.cols.length - 1;
|
|
|
var borderLine = this.sheet.borderLine || new spreadNS.LineBorder('#cccccc', spreadNS.LineStyle.thin);
|
|
|
@@ -182,14 +224,15 @@ $(document).ready(function() {
|
|
|
var containerWidth = Math.floor($('#config-dir-spread').innerWidth() || 0);
|
|
|
if (containerWidth <= 0) return;
|
|
|
var rowHeaderWidth = 25;
|
|
|
- var fixedWidth = 75 + 75 + 113;
|
|
|
+ var fileCompanyWidth = 160;
|
|
|
+ var fixedWidth = 75 + 75 + fileCompanyWidth + 113;
|
|
|
var minimumFlexWidth = 600;
|
|
|
var usableWidth = Math.max(containerWidth - rowHeaderWidth, fixedWidth + minimumFlexWidth);
|
|
|
var flexWidth = usableWidth - fixedWidth;
|
|
|
var nameWidth = Math.floor(flexWidth * 0.34);
|
|
|
var tipsWidth = Math.floor(flexWidth * 0.24);
|
|
|
var authUserWidth = flexWidth - nameWidth - tipsWidth;
|
|
|
- var widths = [ nameWidth, 75, 75, tipsWidth, authUserWidth, 90 ];
|
|
|
+ var widths = [ nameWidth, 75, 75, fileCompanyWidth, tipsWidth, authUserWidth, 90 ];
|
|
|
for (var index = 0; index < widths.length; index++) {
|
|
|
this.sheet.setColumnWidth(index, widths[index]);
|
|
|
}
|
|
|
@@ -201,28 +244,10 @@ $(document).ready(function() {
|
|
|
|
|
|
_getSelectedNode() { return SpreadJsObj.getSelectObject(this.sheet); }
|
|
|
|
|
|
- _hasDirectAuthorization(node) {
|
|
|
- if (!node) return false;
|
|
|
- return filingPermissionData.some(function(permission) {
|
|
|
- return permission.filing_id && Number(permission.is_legacy) !== 1 &&
|
|
|
- String(permission.filing_id) === String(node.id);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- _hasAuthorizedAncestor(node) {
|
|
|
- if (!node) return false;
|
|
|
- var parent = this.filingTree.getParent(node);
|
|
|
- while (parent) {
|
|
|
- if (this._hasDirectAuthorization(parent)) return true;
|
|
|
- parent = this.filingTree.getParent(parent);
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
_refreshAuthUserButton(node) {
|
|
|
var button = $('#cd-auth-user');
|
|
|
if (button.length === 0) return;
|
|
|
- var disabled = !node || this._hasAuthorizedAncestor(node);
|
|
|
+ var disabled = !node;
|
|
|
button
|
|
|
.toggleClass('disabled btn-outline-secondary', disabled)
|
|
|
.toggleClass('btn-outline-primary', !disabled)
|
|
|
@@ -247,6 +272,16 @@ $(document).ready(function() {
|
|
|
if (node) self.curNode = node;
|
|
|
self._refreshAuthUserButton(node);
|
|
|
});
|
|
|
+ this.spread.bind(spreadNS.Events.EditStarting, function(e, info) {
|
|
|
+ var editing = self._textCellEditing;
|
|
|
+ if (!editing || info.row !== editing.row || info.col !== editing.col ||
|
|
|
+ !configDirLocked || !canManageConfigDir) {
|
|
|
+ info.cancel = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.spread.bind(spreadNS.Events.EditEnded, function(e, info) {
|
|
|
+ self._saveTextCellEdit(info);
|
|
|
+ });
|
|
|
|
|
|
$('#cd-add-sibling').click(function() {
|
|
|
var node = self._getSelectedNode();
|
|
|
@@ -344,8 +379,7 @@ $(document).ready(function() {
|
|
|
$('#cd-move').click(function() {
|
|
|
var node = self._getSelectedNode();
|
|
|
if (!node) { toastr.warning('请先选择一个分类'); return; }
|
|
|
- if (node.is_fixed) { toastr.error('固定分类不可移动'); return; }
|
|
|
- if (self._hasSubtreeFiles(node)) { toastr.error('该目录或子目录下已有文件,不可移动'); return; }
|
|
|
+ if (!self._hasSubtreeFiles(node)) { toastr.warning('当前目录及子目录暂无可移动文件'); return; }
|
|
|
self._showMoveModal(node);
|
|
|
});
|
|
|
|
|
|
@@ -391,6 +425,14 @@ $(document).ready(function() {
|
|
|
self._showAuthUserModal(node);
|
|
|
});
|
|
|
|
|
|
+ $('#cd-auth-batch-add').click(function() {
|
|
|
+ self._showAuthTargetModal('add');
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#cd-auth-batch-cover').click(function() {
|
|
|
+ self._showAuthTargetModal('cover');
|
|
|
+ });
|
|
|
+
|
|
|
$('[name=cd-show-level]').click(function() {
|
|
|
self._showLevel($(this).attr('tag'));
|
|
|
});
|
|
|
@@ -399,10 +441,60 @@ $(document).ready(function() {
|
|
|
if (!configDirLocked || !canManageConfigDir) return;
|
|
|
var node = self._getSelectedNode();
|
|
|
if (!node) return;
|
|
|
+ var selection = self.sheet.getSelections()[0];
|
|
|
+ if (selection && self._isEditableTextColumn(selection.col)) {
|
|
|
+ self._startTextCellEdit(selection.row, selection.col, node);
|
|
|
+ return;
|
|
|
+ }
|
|
|
self._showEditModal(node);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ _startTextCellEdit(row, col, node) {
|
|
|
+ if (row < 0 || !node || !this._isEditableTextColumn(col)) return;
|
|
|
+ var field = this.spreadSetting.cols[col].field;
|
|
|
+ this._textCellEditing = {
|
|
|
+ row: row,
|
|
|
+ col: col,
|
|
|
+ field: field,
|
|
|
+ filingId: String(node.id),
|
|
|
+ originalValue: String(node[field] || ''),
|
|
|
+ };
|
|
|
+ this.sheet.getCell(row, col).locked(false);
|
|
|
+ this.sheet.startEdit(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ _saveTextCellEdit(info) {
|
|
|
+ if (!info || !this._isEditableTextColumn(info.col)) return;
|
|
|
+ info.sheet.getCell(info.row, info.col).locked(true);
|
|
|
+ var editing = this._textCellEditing;
|
|
|
+ this._textCellEditing = null;
|
|
|
+ var node = this.filingTree.nodes[info.row];
|
|
|
+ if (!editing || !node || editing.row !== info.row || editing.col !== info.col ||
|
|
|
+ String(node.id) !== editing.filingId) {
|
|
|
+ if (node) SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var textValue = String(info.editingText || '').trim();
|
|
|
+ if (textValue === editing.originalValue) {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var saveData = { updateType: 'save', id: node.id };
|
|
|
+ saveData[editing.field] = textValue;
|
|
|
+ postData('config-dir/update', saveData, function() {
|
|
|
+ var srcNode = filingData.find(function(item) { return String(item.id) === String(node.id); });
|
|
|
+ if (srcNode) srcNode[editing.field] = textValue;
|
|
|
+ node[editing.field] = textValue;
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ }, function() {
|
|
|
+ node[editing.field] = editing.originalValue;
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
_getSubtreeTreeIds(node) {
|
|
|
var result = new Set([node.tree_id]);
|
|
|
var pending = [node.tree_id];
|
|
|
@@ -496,50 +588,102 @@ $(document).ready(function() {
|
|
|
var self = this;
|
|
|
var subtreeTreeIds = this._getSubtreeTreeIds(node);
|
|
|
$('#cd-move-source-name').text(node.name);
|
|
|
+ this._moveTargetExpanded = {};
|
|
|
+ this.filingTree.nodes.forEach(function(item) {
|
|
|
+ if (!item.is_leaf) self._moveTargetExpanded[item.tree_id] = true;
|
|
|
+ });
|
|
|
var html = [];
|
|
|
+ var hasSelectableTarget = false;
|
|
|
for (var i = 0; i < this.filingTree.nodes.length; i++) {
|
|
|
var n = this.filingTree.nodes[i];
|
|
|
- if (subtreeTreeIds.has(n.tree_id)) continue;
|
|
|
- if (Number(n.file_count) > 0) continue;
|
|
|
- if (n.is_fixed && n.level >= node.level) continue;
|
|
|
- var indent = '';
|
|
|
- for (var k = 1; k < n.level; k++) indent += ' ';
|
|
|
- var icon = n.is_leaf ? '\u{1F4C4}' : '\u{1F4C1}';
|
|
|
- html.push('<tr><td class="text-center"><input type="radio" name="cd-move-target" value="' + n.id + '" tree-id="' + n.tree_id + '"></td>');
|
|
|
- html.push('<td>' + indent + icon + ' ' + n.name + '</td></tr>');
|
|
|
+ var hasChildren = this.filingTree.nodes.some(function(child) { return child.tree_pid === n.tree_id; });
|
|
|
+ var inSourceSubtree = subtreeTreeIds.has(n.tree_id);
|
|
|
+ var selectable = n.is_leaf && !inSourceSubtree;
|
|
|
+ var indent = Math.max(Number(n.level) - 1, 0) * 20;
|
|
|
+ if (selectable) hasSelectableTarget = true;
|
|
|
+ html.push('<tr data-move-tree-id="' + n.tree_id + '" data-move-tree-pid="' + n.tree_pid + '">');
|
|
|
+ html.push('<td class="text-center"><input type="radio" name="cd-move-target" value="' +
|
|
|
+ self._escapeAuthUserHtml(n.id) + '" tree-id="' + n.tree_id + '"' + (selectable ? '' : ' disabled') + '></td>');
|
|
|
+ html.push('<td><span style="display:inline-block;width:' + indent + 'px;"></span>');
|
|
|
+ if (hasChildren) {
|
|
|
+ html.push('<a href="javascript:void(0);" class="cd-move-target-toggle mr-1" data-tree-id="' + n.tree_id + '">');
|
|
|
+ html.push('<i class="fa fa-minus-square-o"></i></a>');
|
|
|
+ html.push('<i class="fa fa-folder-open text-warning mr-1 cd-move-target-folder" data-tree-id="' + n.tree_id + '"></i>');
|
|
|
+ } else {
|
|
|
+ html.push('<span class="d-inline-block mr-1" style="width:12px;"></span>');
|
|
|
+ html.push('<i class="fa fa-file-o text-primary mr-1"></i>');
|
|
|
+ }
|
|
|
+ html.push(self._escapeAuthUserHtml(n.name));
|
|
|
+ if (String(n.id) === String(node.id)) html.push('<span class="text-muted ml-1">(当前目录)</span>');
|
|
|
+ html.push('</td></tr>');
|
|
|
+ }
|
|
|
+ if (!hasSelectableTarget) {
|
|
|
+ html.push('<tr><td colspan="2" class="text-muted text-center py-3">暂无可选择的目标底层目录</td></tr>');
|
|
|
}
|
|
|
$('#cd-move-target-list').html(html.join(''));
|
|
|
+ this._refreshMoveTargetTreeVisibility();
|
|
|
+ $('#cd-move-target-list').off('click', '.cd-move-target-toggle')
|
|
|
+ .on('click', '.cd-move-target-toggle', function(event) {
|
|
|
+ event.preventDefault();
|
|
|
+ var treeId = Number($(this).attr('data-tree-id'));
|
|
|
+ self._moveTargetExpanded[treeId] = !self._moveTargetExpanded[treeId];
|
|
|
+ self._refreshMoveTargetTreeVisibility();
|
|
|
+ });
|
|
|
$('#cd-move-modal').modal('show');
|
|
|
$('#cd-move-ok').off('click').on('click', function() {
|
|
|
var target = $('input[name=cd-move-target]:checked');
|
|
|
- if (target.length === 0) { toastr.warning('请选择目标分类'); return; }
|
|
|
+ if (target.length === 0) { toastr.warning('请选择目标底层目录'); return; }
|
|
|
var targetOrigId = target.attr('value');
|
|
|
- var targetTreeId = parseInt(target.attr('tree-id'));
|
|
|
- var targetNode = self.filingTree.nodes.find(function(x) { return x.tree_id === targetTreeId; });
|
|
|
- var siblings = self.filingTree.nodes.filter(function(x) { return x.tree_pid === targetTreeId; });
|
|
|
- var newOrder = siblings.length;
|
|
|
var srcOrigId = self._findOriginalId(node.tree_id);
|
|
|
- var parentOrigId = targetTreeId === -1 ? '-1' : targetOrigId;
|
|
|
- postData('config-dir/update', { updateType: 'move', id: srcOrigId, tree_pid: parentOrigId, tree_order: newOrder }, function(result) {
|
|
|
- // 使用后端返回的更新数据同步 filingData
|
|
|
- if (result && result.update) {
|
|
|
- for (var i = 0; i < result.update.length; i++) {
|
|
|
- var updateItem = result.update[i];
|
|
|
- var srcNode = filingData.find(function(x) { return x.id === updateItem.id; });
|
|
|
- if (srcNode) {
|
|
|
- // 更新所有可能变化的字段
|
|
|
- if (updateItem.tree_pid !== undefined) srcNode.tree_pid = updateItem.tree_pid;
|
|
|
- if (updateItem.tree_order !== undefined) srcNode.tree_order = updateItem.tree_order;
|
|
|
- if (updateItem.tree_level !== undefined) srcNode.tree_level = updateItem.tree_level;
|
|
|
- }
|
|
|
+ postData('config-dir/file/move', {
|
|
|
+ source_filing_id: srcOrigId,
|
|
|
+ target_filing_id: targetOrigId,
|
|
|
+ }, function(result) {
|
|
|
+ if (result && result.filings) {
|
|
|
+ for (var i = 0; i < result.filings.length; i++) {
|
|
|
+ var updateItem = result.filings[i];
|
|
|
+ var srcNode = filingData.find(function(x) { return String(x.id) === String(updateItem.id); });
|
|
|
+ if (srcNode) srcNode.file_count = Number(updateItem.file_count) || 0;
|
|
|
}
|
|
|
}
|
|
|
self._reloadTree();
|
|
|
+ var selectedRow = self.filingTree.nodes.findIndex(function(item) {
|
|
|
+ return String(item.id) === String(srcOrigId);
|
|
|
+ });
|
|
|
+ if (selectedRow >= 0) self.sheet.setSelection(selectedRow, 0, 1, 1);
|
|
|
$('#cd-move-modal').modal('hide');
|
|
|
+ toastr.success('已移动' + Number(result.moved_count || 0) + '个文件');
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ _refreshMoveTargetTreeVisibility() {
|
|
|
+ var self = this;
|
|
|
+ var nodeMap = {};
|
|
|
+ this.filingTree.nodes.forEach(function(node) { nodeMap[node.tree_id] = node; });
|
|
|
+ this.filingTree.nodes.forEach(function(node) {
|
|
|
+ var visible = true;
|
|
|
+ var parentTreeId = node.tree_pid;
|
|
|
+ while (parentTreeId !== -1) {
|
|
|
+ if (!self._moveTargetExpanded[parentTreeId]) {
|
|
|
+ visible = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ var parent = nodeMap[parentTreeId];
|
|
|
+ if (!parent) break;
|
|
|
+ parentTreeId = parent.tree_pid;
|
|
|
+ }
|
|
|
+ $('#cd-move-target-list tr[data-move-tree-id="' + node.tree_id + '"]').toggle(visible);
|
|
|
+ var expanded = Boolean(self._moveTargetExpanded[node.tree_id]);
|
|
|
+ $('#cd-move-target-list .cd-move-target-toggle[data-tree-id="' + node.tree_id + '"] i')
|
|
|
+ .toggleClass('fa-minus-square-o', expanded)
|
|
|
+ .toggleClass('fa-plus-square-o', !expanded);
|
|
|
+ $('#cd-move-target-list .cd-move-target-folder[data-tree-id="' + node.tree_id + '"]')
|
|
|
+ .toggleClass('fa-folder-open', expanded)
|
|
|
+ .toggleClass('fa-folder', !expanded);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
_showTipsModal(node) {
|
|
|
var self = this;
|
|
|
$('#cd-tips-filing-name').text(node.name);
|
|
|
@@ -559,7 +703,6 @@ $(document).ready(function() {
|
|
|
}
|
|
|
|
|
|
_showAuthUserModal(node) {
|
|
|
- if (this._hasAuthorizedAncestor(node)) return;
|
|
|
var self = this;
|
|
|
this._authUserFiling = node;
|
|
|
this._authUserIds = (node.auth_user_ids || []).map(function(id) { return Number(id); });
|
|
|
@@ -678,28 +821,6 @@ $(document).ready(function() {
|
|
|
self._syncAuthUserDropdownMarks();
|
|
|
});
|
|
|
|
|
|
- $('#cd-auth-add-other').off('click').on('click', function(event) {
|
|
|
- event.preventDefault();
|
|
|
- if ($(this).attr('aria-disabled') === 'true') return;
|
|
|
- var selectedPermissions = self._getCheckedAuthUserPermissions();
|
|
|
- if (selectedPermissions.length === 0) {
|
|
|
- toastr.warning('请选择需要添加的授权用户');
|
|
|
- return;
|
|
|
- }
|
|
|
- self._showAuthTargetModal(node, selectedPermissions, 'add');
|
|
|
- });
|
|
|
-
|
|
|
- $('#cd-auth-cover-other').off('click').on('click', function(event) {
|
|
|
- event.preventDefault();
|
|
|
- if ($(this).attr('aria-disabled') === 'true') return;
|
|
|
- var selectedPermissions = self._getCheckedAuthUserPermissions();
|
|
|
- if (selectedPermissions.length === 0) {
|
|
|
- toastr.warning('请选择需要覆盖的授权用户');
|
|
|
- return;
|
|
|
- }
|
|
|
- self._showAuthTargetModal(node, selectedPermissions, 'cover');
|
|
|
- });
|
|
|
-
|
|
|
$('#auth-user-save').off('click').on('click', function() {
|
|
|
if (self._authUserSaving) return;
|
|
|
var userIds = self._authUserIds.slice();
|
|
|
@@ -741,7 +862,7 @@ $(document).ready(function() {
|
|
|
can_edit_file: Number(permission.can_edit_file) ? 1 : 0,
|
|
|
can_edit_dir: Number(permission.can_edit_dir) ? 1 : 0,
|
|
|
can_lock_file: Number(permission.can_lock_file) ? 1 : 0,
|
|
|
- is_legacy: 0,
|
|
|
+ is_legacy: Number(permission.is_legacy) === 1 ? 1 : 0,
|
|
|
});
|
|
|
});
|
|
|
self._buildAuthUserMap();
|
|
|
@@ -775,36 +896,24 @@ $(document).ready(function() {
|
|
|
.text(this._authUserSaving ? '保存中...' : '确定');
|
|
|
}
|
|
|
|
|
|
- _getCheckedAuthUserPermissions() {
|
|
|
+ _showAuthTargetModal(mode) {
|
|
|
var self = this;
|
|
|
- var result = [];
|
|
|
- $('#auth-user-list input[name=cd-auth-user-check]:checked').each(function() {
|
|
|
- var userId = Number($(this).attr('data-user-id'));
|
|
|
- var state = self._ensureAuthUserPermissionState(userId);
|
|
|
- result.push({
|
|
|
- uid: userId,
|
|
|
- can_upload: state.upload_reference ? 1 : 0,
|
|
|
- can_edit_file: state.edit_file ? 1 : 0,
|
|
|
- can_edit_dir: state.edit_dir ? 1 : 0,
|
|
|
- can_lock_file: state.lock_file ? 1 : 0,
|
|
|
- });
|
|
|
- });
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- _showAuthTargetModal(sourceNode, userPermissions, mode) {
|
|
|
- var self = this;
|
|
|
- this._authTargetSource = sourceNode;
|
|
|
- this._authTargetPermissions = userPermissions;
|
|
|
+ var selectedNode = this._getSelectedNode();
|
|
|
+ this._authTargetReturnId = selectedNode ? String(selectedNode.id) : '';
|
|
|
this._authTargetMode = mode === 'cover' ? 'cover' : 'add';
|
|
|
this._authTargetIds = [];
|
|
|
this._authTargetExpanded = {};
|
|
|
+ this._authTargetUserIds = [];
|
|
|
+ this._authTargetPermissionState = {};
|
|
|
this.filingTree.nodes.forEach(function(node) {
|
|
|
- if (node.tree_pid === -1) self._authTargetExpanded[node.tree_id] = true;
|
|
|
+ if (!node.is_leaf) self._authTargetExpanded[node.tree_id] = true;
|
|
|
});
|
|
|
- $('#cd-auth-target-modal-title').text(this._authTargetMode === 'cover' ? '覆盖至其他目录' : '添加至其他目录');
|
|
|
- $('#cd-auth-cover-warning').hide();
|
|
|
+ $('#cd-auth-target-modal-title').text(
|
|
|
+ this._authTargetMode === 'cover' ? '批量覆盖授权' : '批量新增授权'
|
|
|
+ );
|
|
|
this._renderAuthTargetTree();
|
|
|
+ this._renderAuthTargetUserDropdown();
|
|
|
+ this._renderAuthTargetUserList();
|
|
|
this._setAuthTargetSaveState(false);
|
|
|
|
|
|
$('#cd-auth-target-list').off('click', '.cd-auth-target-toggle')
|
|
|
@@ -817,24 +926,95 @@ $(document).ready(function() {
|
|
|
|
|
|
$('#cd-auth-target-list').off('change', '.cd-auth-target-check')
|
|
|
.on('change', '.cd-auth-target-check', function() {
|
|
|
- var filingId = String($(this).attr('data-filing-id'));
|
|
|
- if (this.checked && self._authTargetIds.indexOf(filingId) < 0) {
|
|
|
- self._authTargetIds.push(filingId);
|
|
|
- }
|
|
|
- if (!this.checked) {
|
|
|
- self._authTargetIds = self._authTargetIds.filter(function(id) { return id !== filingId; });
|
|
|
- }
|
|
|
+ self._setAuthTargetBranchChecked(Number($(this).attr('data-tree-id')), this.checked);
|
|
|
self._syncAuthTargetSelectionState();
|
|
|
});
|
|
|
|
|
|
- $('#cd-auth-target-select-all').off('change').on('change', function() {
|
|
|
+ $('#cd-auth-target-user-options').off('click', '.cd-auth-target-unit-row')
|
|
|
+ .on('click', '.cd-auth-target-unit-row', function(event) {
|
|
|
+ event.preventDefault();
|
|
|
+ event.stopPropagation();
|
|
|
+ var groupId = $(this).attr('data-group-id');
|
|
|
+ var children = $('#cd-auth-target-user-options').find('[data-group-content="' + groupId + '"]');
|
|
|
+ children.toggle();
|
|
|
+ $('i', this).toggleClass('fa-plus-square fa-minus-square-o');
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#cd-auth-target-user-options').off('click', '.cd-auth-target-add-unit')
|
|
|
+ .on('click', '.cd-auth-target-add-unit', function(event) {
|
|
|
+ event.preventDefault();
|
|
|
+ event.stopPropagation();
|
|
|
+ var company = $(this).attr('data-company');
|
|
|
+ self._addAuthTargetUsers(accountList.filter(function(account) {
|
|
|
+ return (account.company || '未设置单位') === company;
|
|
|
+ }).map(function(account) { return Number(account.id); }));
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#cd-auth-target-user-options').off('click', '.cd-auth-target-add-user')
|
|
|
+ .on('click', '.cd-auth-target-add-user', function(event) {
|
|
|
+ event.preventDefault();
|
|
|
+ event.stopPropagation();
|
|
|
+ self._addAuthTargetUsers([Number($(this).attr('data-user-id'))]);
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#cd-auth-target-user-list').off('click', '.cd-auth-target-user-remove')
|
|
|
+ .on('click', '.cd-auth-target-user-remove', function(event) {
|
|
|
+ event.preventDefault();
|
|
|
+ self._removeAuthTargetUsers([Number($(this).attr('data-user-id'))]);
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#cd-auth-target-user-select-all').off('change').on('change', function() {
|
|
|
+ var checked = this.checked;
|
|
|
+ var userIds = [];
|
|
|
+ $('#cd-auth-target-user-list input[name=cd-auth-target-user-check]')
|
|
|
+ .prop('checked', checked).each(function() {
|
|
|
+ userIds.push(Number($(this).attr('data-user-id')));
|
|
|
+ });
|
|
|
+ if (!checked) self._setAuthTargetUserPermissions(userIds, false);
|
|
|
+ self._syncAuthTargetUserControls();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#cd-auth-target-user-list').off('change', 'input[name=cd-auth-target-user-check]')
|
|
|
+ .on('change', 'input[name=cd-auth-target-user-check]', function() {
|
|
|
+ var userId = Number($(this).attr('data-user-id'));
|
|
|
+ if (!this.checked) self._setAuthTargetUserPermissions([userId], false);
|
|
|
+ self._syncAuthTargetUserControls();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('.cd-auth-target-permission-all').off('change').on('change', function() {
|
|
|
+ var permissionKey = $(this).attr('data-permission');
|
|
|
var checked = this.checked;
|
|
|
- var targetChecks = $('#cd-auth-target-list .cd-auth-target-check:not(:disabled)');
|
|
|
- targetChecks.prop('checked', checked);
|
|
|
- self._authTargetIds = checked ? targetChecks.map(function() {
|
|
|
- return String($(this).attr('data-filing-id'));
|
|
|
- }).get() : [];
|
|
|
- self._syncAuthTargetSelectionState();
|
|
|
+ $('#cd-auth-target-user-list .cd-auth-target-permission-check[data-permission="' + permissionKey + '"]')
|
|
|
+ .each(function() {
|
|
|
+ var userId = Number($(this).attr('data-user-id'));
|
|
|
+ $(this).prop('checked', checked);
|
|
|
+ self._ensureAuthTargetUserPermissionState(userId)[permissionKey] = checked;
|
|
|
+ if (checked) {
|
|
|
+ $('#cd-auth-target-user-list input[name=cd-auth-target-user-check][data-user-id="' + userId + '"]')
|
|
|
+ .prop('checked', true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ self._syncAuthTargetUserControls();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#cd-auth-target-user-list').off('change', '.cd-auth-target-permission-check')
|
|
|
+ .on('change', '.cd-auth-target-permission-check', function() {
|
|
|
+ var userId = Number($(this).attr('data-user-id'));
|
|
|
+ var permissionKey = $(this).attr('data-permission');
|
|
|
+ self._ensureAuthTargetUserPermissionState(userId)[permissionKey] = this.checked;
|
|
|
+ if (this.checked) {
|
|
|
+ $('#cd-auth-target-user-list input[name=cd-auth-target-user-check][data-user-id="' + userId + '"]')
|
|
|
+ .prop('checked', true);
|
|
|
+ }
|
|
|
+ self._syncAuthTargetUserControls();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#cd-auth-target-user-delete').off('click').on('click', function(event) {
|
|
|
+ event.preventDefault();
|
|
|
+ if ($(this).attr('aria-disabled') === 'true') return;
|
|
|
+ var removeIds = $('#cd-auth-target-user-list input[name=cd-auth-target-user-check]:checked')
|
|
|
+ .map(function() { return Number($(this).attr('data-user-id')); }).get();
|
|
|
+ self._removeAuthTargetUsers(removeIds);
|
|
|
});
|
|
|
|
|
|
$('#cd-auth-target-save').off('click').on('click', function() {
|
|
|
@@ -843,56 +1023,51 @@ $(document).ready(function() {
|
|
|
toastr.warning('请选择目标资料目录');
|
|
|
return;
|
|
|
}
|
|
|
+ if (self._authTargetUserIds.length === 0) {
|
|
|
+ toastr.warning('请选择需要授权的用户');
|
|
|
+ return;
|
|
|
+ }
|
|
|
var isCover = self._authTargetMode === 'cover';
|
|
|
self._setAuthTargetSaveState(true);
|
|
|
postData(isCover ? 'config-dir/permission/cover-other' : 'config-dir/permission/add-other', {
|
|
|
- source_filing_id: sourceNode.id,
|
|
|
target_filing_ids: self._authTargetIds.slice(),
|
|
|
- user_permissions: self._authTargetPermissions,
|
|
|
+ user_permissions: self._getAuthTargetUserPermissions(),
|
|
|
}, function(result) {
|
|
|
self._setAuthTargetSaveState(false);
|
|
|
self._applyAuthTargetResult(result || {});
|
|
|
$('#cd-auth-target-modal').modal('hide');
|
|
|
- toastr.success(isCover ? '覆盖成功' : '添加成功');
|
|
|
+ toastr.success(isCover ? '批量覆盖授权成功' : '批量新增授权成功');
|
|
|
}, function() {
|
|
|
self._setAuthTargetSaveState(false);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- $('#cd-auth-target-modal').off('.configDirAuthTarget')
|
|
|
- .on('shown.bs.modal.configDirAuthTarget', function() {
|
|
|
- $('.modal-backdrop').last().css('z-index', 1055);
|
|
|
- })
|
|
|
- .on('hidden.bs.modal.configDirAuthTarget', function() {
|
|
|
- if ($('#auth-user-modal').hasClass('show')) $('body').addClass('modal-open');
|
|
|
- })
|
|
|
- .modal('show');
|
|
|
+ $('#cd-auth-target-modal').modal('show');
|
|
|
}
|
|
|
|
|
|
_renderAuthTargetTree() {
|
|
|
var self = this;
|
|
|
var nodes = this.filingTree.nodes;
|
|
|
- var sourceId = String(this._authTargetSource.id);
|
|
|
var html = [];
|
|
|
nodes.forEach(function(node) {
|
|
|
var hasChildren = nodes.some(function(child) { return child.tree_pid === node.tree_id; });
|
|
|
- var indent = Math.max(Number(node.level) - 1, 0) * 20;
|
|
|
- var isSource = String(node.id) === sourceId;
|
|
|
+ var indent = Math.max(Number(node.level) - 1, 0) * 18;
|
|
|
html.push('<tr data-target-tree-id="' + node.tree_id + '" data-target-tree-pid="' + node.tree_pid + '">');
|
|
|
+ html.push('<td class="text-center"><input type="checkbox" class="cd-auth-target-check" data-tree-id="' +
|
|
|
+ node.tree_id + '" data-filing-id="' + self._escapeAuthUserHtml(node.id) + '"></td>');
|
|
|
html.push('<td><span style="display:inline-block;width:' + indent + 'px;"></span>');
|
|
|
if (hasChildren) {
|
|
|
html.push('<a href="javascript:void(0);" class="cd-auth-target-toggle mr-1" data-tree-id="' + node.tree_id + '">');
|
|
|
html.push('<i class="fa ' + (self._authTargetExpanded[node.tree_id] ? 'fa-minus-square-o' : 'fa-plus-square-o') + '"></i></a>');
|
|
|
+ html.push('<i class="fa fa-folder-open text-warning mr-1 cd-auth-target-folder" data-tree-id="' + node.tree_id + '"></i>');
|
|
|
} else {
|
|
|
html.push('<span class="d-inline-block mr-1" style="width:12px;"></span>');
|
|
|
+ html.push('<i class="fa fa-file-o text-primary mr-1"></i>');
|
|
|
}
|
|
|
- html.push('<i class="fa fa-folder text-warning mr-1"></i>' + self._escapeAuthUserHtml(node.name));
|
|
|
- if (isSource) html.push('<span class="text-muted ml-1">(当前目录)</span>');
|
|
|
- html.push('</td><td class="text-center"><input type="checkbox" class="cd-auth-target-check" data-filing-id="' +
|
|
|
- self._escapeAuthUserHtml(node.id) + '"' + (isSource ? ' disabled' : '') + '></td></tr>');
|
|
|
+ html.push(self._escapeAuthUserHtml(node.name) + '</td></tr>');
|
|
|
});
|
|
|
- if (nodes.length <= 1) {
|
|
|
- html.push('<tr><td colspan="2" class="text-muted text-center py-4">暂无可选择的其他目录</td></tr>');
|
|
|
+ if (nodes.length === 0) {
|
|
|
+ html.push('<tr><td colspan="2" class="text-muted text-center py-4">暂无可选择的目录</td></tr>');
|
|
|
}
|
|
|
$('#cd-auth-target-list').html(html.join(''));
|
|
|
this._refreshAuthTargetTreeVisibility();
|
|
|
@@ -916,30 +1091,200 @@ $(document).ready(function() {
|
|
|
parentTreeId = parent.tree_pid;
|
|
|
}
|
|
|
$('#cd-auth-target-list tr[data-target-tree-id="' + node.tree_id + '"]').toggle(visible);
|
|
|
+ var expanded = Boolean(self._authTargetExpanded[node.tree_id]);
|
|
|
$('#cd-auth-target-list .cd-auth-target-toggle[data-tree-id="' + node.tree_id + '"] i')
|
|
|
- .toggleClass('fa-minus-square-o', Boolean(self._authTargetExpanded[node.tree_id]))
|
|
|
- .toggleClass('fa-plus-square-o', !self._authTargetExpanded[node.tree_id]);
|
|
|
+ .toggleClass('fa-minus-square-o', expanded)
|
|
|
+ .toggleClass('fa-plus-square-o', !expanded);
|
|
|
+ $('#cd-auth-target-list .cd-auth-target-folder[data-tree-id="' + node.tree_id + '"]')
|
|
|
+ .toggleClass('fa-folder-open', expanded)
|
|
|
+ .toggleClass('fa-folder', !expanded);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ _setAuthTargetBranchChecked(treeId, checked) {
|
|
|
+ var pending = [treeId];
|
|
|
+ while (pending.length > 0) {
|
|
|
+ var currentId = pending.shift();
|
|
|
+ $('#cd-auth-target-list .cd-auth-target-check[data-tree-id="' + currentId + '"]')
|
|
|
+ .prop('checked', checked).prop('indeterminate', false);
|
|
|
+ this.filingTree.nodes.filter(function(node) { return node.tree_pid === currentId; })
|
|
|
+ .forEach(function(child) { pending.push(child.tree_id); });
|
|
|
+ }
|
|
|
+ this._syncAuthTargetParentChecks();
|
|
|
+ }
|
|
|
+
|
|
|
+ _syncAuthTargetParentChecks() {
|
|
|
+ var nodes = this.filingTree.nodes.slice().sort(function(a, b) { return Number(b.level) - Number(a.level); });
|
|
|
+ nodes.forEach(function(node) {
|
|
|
+ var children = nodes.filter(function(child) { return child.tree_pid === node.tree_id; });
|
|
|
+ if (children.length === 0) return;
|
|
|
+ var childChecks = children.map(function(child) {
|
|
|
+ return $('#cd-auth-target-list .cd-auth-target-check[data-tree-id="' + child.tree_id + '"]')[0];
|
|
|
+ }).filter(Boolean);
|
|
|
+ var allChecked = childChecks.length > 0 && childChecks.every(function(check) { return check.checked; });
|
|
|
+ var hasChecked = childChecks.some(function(check) { return check.checked || check.indeterminate; });
|
|
|
+ $('#cd-auth-target-list .cd-auth-target-check[data-tree-id="' + node.tree_id + '"]')
|
|
|
+ .prop('checked', allChecked)
|
|
|
+ .prop('indeterminate', !allChecked && hasChecked);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_syncAuthTargetSelectionState() {
|
|
|
- var targetChecks = $('#cd-auth-target-list .cd-auth-target-check:not(:disabled)');
|
|
|
- var checkedCount = targetChecks.filter(':checked').length;
|
|
|
- $('#cd-auth-target-select-all')
|
|
|
- .prop('checked', targetChecks.length > 0 && checkedCount === targetChecks.length)
|
|
|
- .prop('indeterminate', checkedCount > 0 && checkedCount < targetChecks.length)
|
|
|
- .prop('disabled', targetChecks.length === 0);
|
|
|
- $('#cd-auth-target-save').prop('disabled', this._authTargetSaving || checkedCount === 0);
|
|
|
- $('#cd-auth-cover-warning').toggle(this._authTargetMode === 'cover' && checkedCount > 0);
|
|
|
+ this._authTargetIds = $('#cd-auth-target-list .cd-auth-target-check:checked').map(function() {
|
|
|
+ return String($(this).attr('data-filing-id'));
|
|
|
+ }).get();
|
|
|
+ var hasTargets = this._authTargetIds.length > 0;
|
|
|
+ var hasUsers = (this._authTargetUserIds || []).length > 0;
|
|
|
+ $('#cd-auth-target-save').prop('disabled', this._authTargetSaving || !hasTargets || !hasUsers);
|
|
|
+ $('#cd-auth-cover-warning').toggle(this._authTargetMode === 'cover' && hasTargets);
|
|
|
}
|
|
|
|
|
|
_setAuthTargetSaveState(saving) {
|
|
|
this._authTargetSaving = Boolean(saving);
|
|
|
- $('#cd-auth-target-save')
|
|
|
- .text(this._authTargetSaving ? '保存中...' : '确定');
|
|
|
+ $('#cd-auth-target-save').text(this._authTargetSaving ? '保存中...' : '确定');
|
|
|
+ this._syncAuthTargetSelectionState();
|
|
|
+ }
|
|
|
+
|
|
|
+ _renderAuthTargetUserDropdown() {
|
|
|
+ var self = this;
|
|
|
+ var html = [];
|
|
|
+ this._getAuthUserGroups().forEach(function(group, groupIndex) {
|
|
|
+ html.push('<dt class="px-2 py-1 mb-0 cd-auth-target-unit-row" data-group-id="' + groupIndex + '" style="cursor:pointer;">');
|
|
|
+ html.push('<a href="javascript:void(0);"><i class="fa fa-plus-square mr-1"></i></a>');
|
|
|
+ html.push('<span>' + self._escapeAuthUserHtml(group.company) + '</span></dt>');
|
|
|
+ html.push('<div class="dd-content" data-group-content="' + groupIndex + '" style="display:none;">');
|
|
|
+ html.push('<dd class="border-bottom p-2 mb-0 cd-auth-target-add-unit" data-company="' +
|
|
|
+ self._escapeAuthUserHtml(group.company) + '"><span class="text-primary">添加单位下全部用户</span></dd>');
|
|
|
+ group.users.forEach(function(user) {
|
|
|
+ html.push('<dd class="border-bottom p-2 mb-0 cd-auth-target-add-user" data-user-id="' + Number(user.id) + '">');
|
|
|
+ html.push('<p class="mb-0 d-flex"><span class="text-primary">' + self._escapeAuthUserHtml(user.name) + '</span>');
|
|
|
+ html.push('<span class="ml-auto">' + self._escapeAuthUserHtml(user.mobile || '') + '</span>');
|
|
|
+ html.push('<span class="text-success ml-2" data-target-user-mark="' + Number(user.id) + '"><i class="fa fa-check"></i></span></p>');
|
|
|
+ html.push('<span class="text-muted">' + self._escapeAuthUserHtml(user.role || '') + '</span></dd>');
|
|
|
+ });
|
|
|
+ html.push('</div>');
|
|
|
+ });
|
|
|
+ if (html.length === 0) html.push('<div class="text-muted text-center py-3">数据范围内暂无可选用户</div>');
|
|
|
+ $('#cd-auth-target-user-options').html(html.join(''));
|
|
|
+ this._syncAuthTargetUserDropdownMarks();
|
|
|
+ }
|
|
|
+
|
|
|
+ _syncAuthTargetUserDropdownMarks() {
|
|
|
+ var selectedIds = this._authTargetUserIds || [];
|
|
|
+ $('#cd-auth-target-user-options [data-target-user-mark]').each(function() {
|
|
|
+ var userId = Number($(this).attr('data-target-user-mark'));
|
|
|
+ $(this).toggle(selectedIds.indexOf(userId) >= 0);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ _addAuthTargetUsers(userIds) {
|
|
|
+ var selectableIds = accountList.map(function(account) { return Number(account.id); });
|
|
|
+ for (var index = 0; index < userIds.length; index++) {
|
|
|
+ var userId = Number(userIds[index]);
|
|
|
+ if (selectableIds.indexOf(userId) < 0 || this._authTargetUserIds.indexOf(userId) >= 0) continue;
|
|
|
+ this._authTargetUserIds.push(userId);
|
|
|
+ this._ensureAuthTargetUserPermissionState(userId);
|
|
|
+ }
|
|
|
+ this._renderAuthTargetUserList();
|
|
|
+ this._syncAuthTargetUserDropdownMarks();
|
|
|
+ }
|
|
|
+
|
|
|
+ _removeAuthTargetUsers(userIds) {
|
|
|
+ var self = this;
|
|
|
+ this._authTargetUserIds = this._authTargetUserIds.filter(function(userId) {
|
|
|
+ return userIds.indexOf(userId) < 0;
|
|
|
+ });
|
|
|
+ userIds.forEach(function(userId) { delete self._authTargetPermissionState[userId]; });
|
|
|
+ this._renderAuthTargetUserList();
|
|
|
+ this._syncAuthTargetUserDropdownMarks();
|
|
|
+ }
|
|
|
+
|
|
|
+ _ensureAuthTargetUserPermissionState(userId) {
|
|
|
+ if (!this._authTargetPermissionState[userId]) {
|
|
|
+ this._authTargetPermissionState[userId] = {
|
|
|
+ upload_reference: false,
|
|
|
+ edit_file: false,
|
|
|
+ edit_dir: false,
|
|
|
+ lock_file: false,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return this._authTargetPermissionState[userId];
|
|
|
+ }
|
|
|
+
|
|
|
+ _renderAuthTargetUserList() {
|
|
|
+ var self = this;
|
|
|
+ var html = [];
|
|
|
+ this.authAccountList.filter(function(account) {
|
|
|
+ return self._authTargetUserIds.indexOf(Number(account.id)) >= 0;
|
|
|
+ }).forEach(function(user) {
|
|
|
+ var userId = Number(user.id);
|
|
|
+ var state = self._ensureAuthTargetUserPermissionState(userId);
|
|
|
+ var selected = state.upload_reference || state.edit_file || state.edit_dir || state.lock_file;
|
|
|
+ html.push('<tr class="text-center" data-user-id="' + userId + '">');
|
|
|
+ html.push('<td><input type="checkbox" name="cd-auth-target-user-check" data-user-id="' + userId + '"' + (selected ? ' checked' : '') + '></td>');
|
|
|
+ html.push('<td>' + self._escapeAuthUserHtml(user.name) + '</td>');
|
|
|
+ html.push('<td><i class="fa fa-check text-primary"></i></td>');
|
|
|
+ [ 'upload_reference', 'edit_file', 'edit_dir', 'lock_file' ].forEach(function(key) {
|
|
|
+ html.push('<td><input type="checkbox" class="cd-auth-target-permission-check" data-user-id="' + userId +
|
|
|
+ '" data-permission="' + key + '"' + (state[key] ? ' checked' : '') + '></td>');
|
|
|
+ });
|
|
|
+ html.push('<td><a href="javascript:void(0);" class="text-danger cd-auth-target-user-remove" data-user-id="' + userId + '">移除</a></td></tr>');
|
|
|
+ });
|
|
|
+ if (html.length === 0) {
|
|
|
+ html.push('<tr><td colspan="8" class="text-muted text-center py-4">请添加需要授权的用户</td></tr>');
|
|
|
+ }
|
|
|
+ $('#cd-auth-target-user-list').html(html.join(''));
|
|
|
+ this._syncAuthTargetUserControls();
|
|
|
+ }
|
|
|
+
|
|
|
+ _setAuthTargetUserPermissions(userIds, checked) {
|
|
|
+ var self = this;
|
|
|
+ userIds.forEach(function(userId) {
|
|
|
+ $('#cd-auth-target-user-list .cd-auth-target-permission-check[data-user-id="' + userId + '"]')
|
|
|
+ .each(function() {
|
|
|
+ var key = $(this).attr('data-permission');
|
|
|
+ $(this).prop('checked', checked);
|
|
|
+ self._ensureAuthTargetUserPermissionState(userId)[key] = checked;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ _syncAuthTargetUserControls() {
|
|
|
+ var userChecks = $('#cd-auth-target-user-list input[name=cd-auth-target-user-check]');
|
|
|
+ var checkedCount = userChecks.filter(':checked').length;
|
|
|
+ $('#cd-auth-target-user-select-all')
|
|
|
+ .prop('checked', userChecks.length > 0 && checkedCount === userChecks.length)
|
|
|
+ .prop('indeterminate', checkedCount > 0 && checkedCount < userChecks.length);
|
|
|
+ $('.cd-auth-target-permission-all').each(function() {
|
|
|
+ var key = $(this).attr('data-permission');
|
|
|
+ var permissionChecks = $('#cd-auth-target-user-list .cd-auth-target-permission-check[data-permission="' + key + '"]');
|
|
|
+ var permissionCheckedCount = permissionChecks.filter(':checked').length;
|
|
|
+ $(this)
|
|
|
+ .prop('checked', permissionChecks.length > 0 && permissionCheckedCount === permissionChecks.length)
|
|
|
+ .prop('indeterminate', permissionCheckedCount > 0 && permissionCheckedCount < permissionChecks.length);
|
|
|
+ });
|
|
|
+ $('#cd-auth-target-user-delete')
|
|
|
+ .attr('aria-disabled', checkedCount > 0 ? 'false' : 'true')
|
|
|
+ .attr('tabindex', checkedCount > 0 ? '0' : '-1')
|
|
|
+ .toggleClass('text-muted', checkedCount === 0)
|
|
|
+ .toggleClass('text-danger', checkedCount > 0);
|
|
|
this._syncAuthTargetSelectionState();
|
|
|
}
|
|
|
|
|
|
+ _getAuthTargetUserPermissions() {
|
|
|
+ var self = this;
|
|
|
+ return this._authTargetUserIds.map(function(userId) {
|
|
|
+ var state = self._ensureAuthTargetUserPermissionState(userId);
|
|
|
+ return {
|
|
|
+ uid: userId,
|
|
|
+ can_upload: state.upload_reference ? 1 : 0,
|
|
|
+ can_edit_file: state.edit_file ? 1 : 0,
|
|
|
+ can_edit_dir: state.edit_dir ? 1 : 0,
|
|
|
+ can_lock_file: state.lock_file ? 1 : 0,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
_applyAuthTargetResult(result) {
|
|
|
var targetIds = this._authTargetIds || [];
|
|
|
var permissions = result.permissions instanceof Array ? result.permissions : [];
|
|
|
@@ -963,10 +1308,11 @@ $(document).ready(function() {
|
|
|
var filingInfo = filingInfos.find(function(item) { return String(item.id) === filingId; });
|
|
|
if (filingInfo) filing.add_user = filingInfo.add_user || '';
|
|
|
});
|
|
|
- var sourceId = String(this._authTargetSource.id);
|
|
|
+ var returnId = this._authTargetReturnId;
|
|
|
this._reloadTree();
|
|
|
- var sourceIndex = this.filingTree.nodes.findIndex(function(node) { return String(node.id) === sourceId; });
|
|
|
- if (sourceIndex >= 0) this.sheet.setSelection(sourceIndex, 0, 1, 1);
|
|
|
+ var returnIndex = this.filingTree.nodes.findIndex(function(node) { return String(node.id) === returnId; });
|
|
|
+ if (returnIndex >= 0) this.sheet.setSelection(returnIndex, 0, 1, 1);
|
|
|
+ this._refreshAuthUserButton(returnIndex >= 0 ? this.filingTree.nodes[returnIndex] : this._getSelectedNode());
|
|
|
}
|
|
|
|
|
|
_escapeAuthUserHtml(value) {
|
|
|
@@ -1172,9 +1518,6 @@ $(document).ready(function() {
|
|
|
$('#cd-auth-batch-delete')
|
|
|
.toggleClass('text-muted', !hasUsers)
|
|
|
.toggleClass('text-danger', hasUsers);
|
|
|
- $('#cd-auth-add-other, #cd-auth-cover-other')
|
|
|
- .toggleClass('text-muted', !hasUsers)
|
|
|
- .toggleClass('text-primary', hasUsers);
|
|
|
}
|
|
|
}
|
|
|
|