|
@@ -365,44 +365,43 @@ var blockLibObj = {
|
|
},
|
|
},
|
|
newNode: async function (nodeType, nodeName, categoryID, source){ // 1 分类(只用前两个参数) 2 块文件
|
|
newNode: async function (nodeType, nodeName, categoryID, source){ // 1 分类(只用前两个参数) 2 块文件
|
|
let tree = blockLibObj.mainTree;
|
|
let tree = blockLibObj.mainTree;
|
|
- let pID = -1, nID = -1;
|
|
|
|
- let select = tree.selected;
|
|
|
|
- if (nodeType == 1){
|
|
|
|
- if (!select) {
|
|
|
|
- nID = -1;
|
|
|
|
- }
|
|
|
|
- else if (select.data.type == 1){
|
|
|
|
- nID = select.getNextSiblingID();
|
|
|
|
- }
|
|
|
|
- else if (select.data.type == 2){
|
|
|
|
- nID = select.parent.getNextSiblingID();
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
- else if (nodeType == 2) {
|
|
|
|
- pID = categoryID;
|
|
|
|
- nID = -1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let newN = tree.insert(pID, nID);
|
|
|
|
- newN.data.libID = blockLibObj.activeLib.libID;
|
|
|
|
- newN.data.type = nodeType;
|
|
|
|
- newN.data.nodeName = nodeName;
|
|
|
|
|
|
+ let ID = uuid.v1();
|
|
|
|
+ let pID = (nodeType == 2) ? categoryID : -1;
|
|
|
|
+ let nID = -1;
|
|
|
|
+
|
|
|
|
+ // 先生成临时结点数据用于提交入库,成功后才生成树结点,并在UI上刷新显示。
|
|
|
|
+ let temp = {};
|
|
|
|
+ temp.data = {
|
|
|
|
+ ID: ID,
|
|
|
|
+ ParentID: pID,
|
|
|
|
+ NextSiblingID: nID,
|
|
|
|
+ libID: blockLibObj.activeLib.libID,
|
|
|
|
+ type: nodeType,
|
|
|
|
+ nodeName: nodeName
|
|
|
|
+ };
|
|
if (nodeType == 2)
|
|
if (nodeType == 2)
|
|
- blockLibObj.assignData(newN, source);
|
|
|
|
-
|
|
|
|
- let save = await ajaxPost('/blockLib/saveBlock', newN.data);
|
|
|
|
- alert(save);
|
|
|
|
- tree.selected = newN;
|
|
|
|
- let sheet = blockLibObj.mainSheet;
|
|
|
|
- sheet.suspendPaint();
|
|
|
|
- sheet.suspendEvent();
|
|
|
|
- let idx = tree.items.indexOf(newN);
|
|
|
|
- sheet.addRows(idx, 1);
|
|
|
|
- sheet.getRange(idx, 0, 1, 1).locked(true);
|
|
|
|
- sheet.setValue(idx, 0, newN.data.nodeName);
|
|
|
|
- sheet.setSelection(idx, 0, 1, 1);
|
|
|
|
- sheet.resumeEvent();
|
|
|
|
- sheet.resumePaint();
|
|
|
|
|
|
+ blockLibObj.assignData(temp, source);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ await ajaxPost('/blockLib/saveBlock', temp.data);
|
|
|
|
+ let newN = tree.insertByID(ID, pID, nID);
|
|
|
|
+ newN.data = temp.data;
|
|
|
|
+ tree.selected = newN;
|
|
|
|
+ let sheet = blockLibObj.mainSheet;
|
|
|
|
+ sheet.suspendPaint();
|
|
|
|
+ sheet.suspendEvent();
|
|
|
|
+ let idx = tree.items.indexOf(newN);
|
|
|
|
+ sheet.addRows(idx, 1);
|
|
|
|
+ sheet.getRange(idx, 0, 1, 1).locked(true);
|
|
|
|
+ sheet.setValue(idx, 0, newN.data.nodeName);
|
|
|
|
+ sheet.setSelection(idx, 0, 1, 1);
|
|
|
|
+ sheet.resumeEvent();
|
|
|
|
+ sheet.resumePaint();
|
|
|
|
+ }
|
|
|
|
+ catch (err) {
|
|
|
|
+ console.log(err.message);
|
|
|
|
+ return;
|
|
|
|
+ };
|
|
},
|
|
},
|
|
assignData: function (block, source){
|
|
assignData: function (block, source){
|
|
block.data.compilationID = source.compilationID;
|
|
block.data.compilationID = source.compilationID;
|
|
@@ -599,11 +598,11 @@ var blockLibObj = {
|
|
BlockController.confirmPaste(vBlock_WC, projectNode, 'sub');
|
|
BlockController.confirmPaste(vBlock_WC, projectNode, 'sub');
|
|
},
|
|
},
|
|
checkShow: async function () { // 这里需要处理异步:模板库装载完再弹出位置选择窗。
|
|
checkShow: async function () { // 这里需要处理异步:模板库装载完再弹出位置选择窗。
|
|
- if (!$("#kmbk").is(":visible")){
|
|
|
|
|
|
+ if (!$("#kmbk").is(":visible")){ // 如果还没显示
|
|
if (!blockLibObj.mainSpread){
|
|
if (!blockLibObj.mainSpread){
|
|
await blockLibObj.buildSheet();
|
|
await blockLibObj.buildSheet();
|
|
};
|
|
};
|
|
- $('#blockLibTab').click();
|
|
|
|
|
|
+ $('#blockLibTab').click(); // 强制显示
|
|
};
|
|
};
|
|
$("#div_createBlocks").modal({show: true});
|
|
$("#div_createBlocks").modal({show: true});
|
|
}
|
|
}
|
|
@@ -611,12 +610,13 @@ var blockLibObj = {
|
|
|
|
|
|
$(document).ready(function(){ // 这里不需要处理异步:因为不需要弹出位置选择窗。
|
|
$(document).ready(function(){ // 这里不需要处理异步:因为不需要弹出位置选择窗。
|
|
$('#blockLibTab').on('click', function (){
|
|
$('#blockLibTab').on('click', function (){
|
|
- if ($("#kmbk").is(":visible")){
|
|
|
|
|
|
+ if ($("#kmbk").is(":visible")){ // 显示状态下
|
|
if (!blockLibObj.mainSpread){
|
|
if (!blockLibObj.mainSpread){
|
|
blockLibObj.buildSheet();
|
|
blockLibObj.buildSheet();
|
|
};
|
|
};
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
$('#btn_block_newFolder').on('click', function (){
|
|
$('#btn_block_newFolder').on('click', function (){
|
|
$('#input_block_newFolder').val('');
|
|
$('#input_block_newFolder').val('');
|
|
});
|
|
});
|