|
@@ -3,6 +3,8 @@
|
|
|
* Created by CSL on 2018-09-19.
|
|
|
*/
|
|
|
var blockLibObj = {
|
|
|
+ libs: [],
|
|
|
+ activeLib: null,
|
|
|
mainSpread: null,
|
|
|
mainSheet: null,
|
|
|
mainTree: null,
|
|
@@ -66,12 +68,11 @@ var blockLibObj = {
|
|
|
}
|
|
|
},
|
|
|
cloneType: null,
|
|
|
- libID: 1,
|
|
|
|
|
|
- buildSheet: function () {
|
|
|
+ buildSheet: async function () {
|
|
|
$.bootstrapLoading.start();
|
|
|
let me = this;
|
|
|
- me.mainDatas = [
|
|
|
+ /* me.mainDatas = [
|
|
|
{ID: 1, ParentID: -1, NextSiblingID: 2, nodeName: '分类1', type: 1},
|
|
|
{ID: 2, ParentID: -1, NextSiblingID: 3, nodeName: '分类2', type: 1},
|
|
|
{ID: 3, ParentID: -1, NextSiblingID: 4, nodeName: '分类3', type: 1},
|
|
@@ -80,9 +81,10 @@ var blockLibObj = {
|
|
|
{ID: 7, ParentID: -1, NextSiblingID: 8, nodeName: '分类7', type: 1},
|
|
|
{ID: 9, ParentID: -1, NextSiblingID: -1, nodeName: '分类9', type: 1}//,
|
|
|
// {ID: 201, ParentID: 52, NextSiblingID: -1, nodeName: '块201', type: 2}
|
|
|
- ];
|
|
|
+ ];*/
|
|
|
|
|
|
- if (me.mainSpread) {
|
|
|
+ if (me.libs.length > 0) me.libs.splice(0, me.libs.length);
|
|
|
+ if (me.mainSpread) {
|
|
|
me.mainSpread.destroy();
|
|
|
me.mainSpread = null;
|
|
|
};
|
|
@@ -95,6 +97,21 @@ var blockLibObj = {
|
|
|
me.rationSpread = null;
|
|
|
};
|
|
|
|
|
|
+ let namesAndLib = await ajaxPost('/blockLib/getLibNamesAndFirstLib', {userID: userID, compilationID: projectInfoObj.projectInfo.compilation});
|
|
|
+ me.mainDatas = namesAndLib.firstLib.datas;
|
|
|
+ me.libs.push(namesAndLib.firstLib);
|
|
|
+ me.activeLib = namesAndLib.firstLib;
|
|
|
+
|
|
|
+ function getLibNamesHtml(libsArr) {
|
|
|
+ let result = '';
|
|
|
+ for (let lib of libsArr) {
|
|
|
+ result += '<option value="' + lib.libID + '">' + lib.libName + '</option>';
|
|
|
+ };
|
|
|
+ return result;
|
|
|
+ };
|
|
|
+ let html = getLibNamesHtml(namesAndLib.libNames);
|
|
|
+ $("#select_block_lib_names").html(html);
|
|
|
+
|
|
|
me.mainSpread = SheetDataHelper.createNewSpread($('#div_block_tree')[0]);
|
|
|
// me.mainSpread = TREE_SHEET_HELPER.createNewSpread($('#div_block_tree')[0]);
|
|
|
me.mainSheet = me.mainSpread.getSheet(0);
|
|
@@ -367,14 +384,14 @@ var blockLibObj = {
|
|
|
}
|
|
|
|
|
|
let newN = tree.insert(pID, nID);
|
|
|
- newN.data.libID = blockLibObj.libID;
|
|
|
+ newN.data.libID = blockLibObj.activeLib.libID;
|
|
|
newN.data.type = nodeType;
|
|
|
newN.data.nodeName = nodeName;
|
|
|
if (nodeType == 2)
|
|
|
blockLibObj.assignData(newN, source);
|
|
|
|
|
|
- let a = await ajaxPost('/blockLib/saveBlock', newN.data);
|
|
|
- alert(a);
|
|
|
+ let save = await ajaxPost('/blockLib/saveBlock', newN.data);
|
|
|
+ alert(save);
|
|
|
tree.selected = newN;
|
|
|
let sheet = blockLibObj.mainSheet;
|
|
|
sheet.suspendPaint();
|
|
@@ -386,25 +403,6 @@ var blockLibObj = {
|
|
|
sheet.setSelection(idx, 0, 1, 1);
|
|
|
sheet.resumeEvent();
|
|
|
sheet.resumePaint();
|
|
|
- /* .then(
|
|
|
- function () {
|
|
|
- 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(
|
|
|
- function () {
|
|
|
- console.log('块文件入库存储失败!');
|
|
|
- }
|
|
|
- );*/
|
|
|
},
|
|
|
assignData: function (block, source){
|
|
|
block.data.compilationID = source.compilationID;
|
|
@@ -599,10 +597,19 @@ var blockLibObj = {
|
|
|
};
|
|
|
vBlock_WC = JSON.parse(JSON.stringify(vBlock_WC));
|
|
|
BlockController.confirmPaste(vBlock_WC, projectNode, 'sub');
|
|
|
+ },
|
|
|
+ checkShow: async function () { // 这里需要处理异步:模板库装载完再弹出位置选择窗。
|
|
|
+ if (!$("#kmbk").is(":visible")){
|
|
|
+ if (!blockLibObj.mainSpread){
|
|
|
+ await blockLibObj.buildSheet();
|
|
|
+ };
|
|
|
+ $('#blockLibTab').click();
|
|
|
+ };
|
|
|
+ $("#div_createBlocks").modal({show: true});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-$(document).ready(function(){
|
|
|
+$(document).ready(function(){ // 这里不需要处理异步:因为不需要弹出位置选择窗。
|
|
|
$('#blockLibTab').on('click', function (){
|
|
|
if ($("#kmbk").is(":visible")){
|
|
|
if (!blockLibObj.mainSpread){
|