|
@@ -8,37 +8,35 @@ var dbController = {
|
|
|
btn.attr('doing', 'true');
|
|
|
if(controller.tree.items.length === 0){
|
|
|
controller.tree.maxNodeID(0);
|
|
|
- // let newNodeId = controller.tree.newNodeID();
|
|
|
let newNodeId = uuid.v1();
|
|
|
- console.log(newNodeId);
|
|
|
let sectionInfo = {first: null, second: null, third: null};
|
|
|
billsAjax.createBills(userAccount, billsLibId, newNodeId, -1 , -1, null, sectionInfo, function(){
|
|
|
- controller.insert();
|
|
|
+ controller.insertByID(newNodeId);
|
|
|
controller.tree.selected.jobs = new Array();
|
|
|
controller.tree.selected.items = new Array();
|
|
|
controller.sheet.setTag(controller.tree.selected.serialNo(), 0, newNodeId);
|
|
|
sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
|
|
|
tools.btnAction(btn);
|
|
|
btn.attr('doing', 'false');
|
|
|
+ controller.sheet.getParent().focus(true);
|
|
|
});
|
|
|
}
|
|
|
else {
|
|
|
let node = controller.tree.selected;
|
|
|
if(node){
|
|
|
var updateId = node.getID(), createpid = node.getParentID(), createnid = node.getNextSiblingID();
|
|
|
- //let newNodeId = controller.tree.newNodeID();
|
|
|
let newNodeId = uuid.v1();
|
|
|
- console.log(newNodeId);
|
|
|
let updatePreData = {ID: updateId, NextSiblingID: newNodeId};
|
|
|
let sectionInfo = tools.getSectionInfo(node);
|
|
|
billsAjax.createBills(userAccount, billsLibId, newNodeId, createpid, createnid, updatePreData, sectionInfo, function(){
|
|
|
- controller.insert();
|
|
|
+ controller.insertByID(newNodeId);
|
|
|
controller.tree.selected.jobs = new Array();
|
|
|
controller.tree.selected.items = new Array();
|
|
|
controller.sheet.setTag(controller.tree.selected.serialNo(), 0, newNodeId);
|
|
|
sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
|
|
|
- tools.btnAction(btn);
|
|
|
+ tools.btnAction(btn);
|
|
|
btn.attr('doing', 'false');
|
|
|
+ controller.sheet.getParent().focus(true);
|
|
|
});
|
|
|
}
|
|
|
else {
|
|
@@ -46,17 +44,17 @@ var dbController = {
|
|
|
let updateId = updateNode.getID();
|
|
|
//let newNodeId = controller.tree.newNodeID();
|
|
|
let newNodeId = uuid.v1();
|
|
|
- console.log(newNodeId);
|
|
|
let updatePreData = {ID: updateId, NextSiblingID: newNodeId};
|
|
|
let sectionInfo = tools.getSectionInfo(node);
|
|
|
billsAjax.createBills(userAccount, billsLibId, newNodeId, -1, -1, updatePreData, sectionInfo, function(){
|
|
|
- controller.insert();
|
|
|
+ controller.insertByID(newNodeId);
|
|
|
controller.tree.selected.jobs = new Array();
|
|
|
controller.tree.selected.items = new Array();
|
|
|
controller.sheet.setTag(controller.tree.selected.serialNo(), 0, newNodeId);
|
|
|
sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
|
|
|
tools.btnAction(btn);
|
|
|
btn.attr('doing', 'false');
|
|
|
+ controller.sheet.getParent().focus(true);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -66,136 +64,221 @@ var dbController = {
|
|
|
tools.btnClose(btn);
|
|
|
btn.attr('doing', 'true');
|
|
|
var node = controller.tree.selected;
|
|
|
- var ids = [];
|
|
|
+ var nextSiblingIds = [];
|
|
|
var updateData = [];
|
|
|
- var getNextSibling = function(node){
|
|
|
+ let selNodes = tools.getSameDepthNodes(controller);
|
|
|
+ let nextSiblings = [];
|
|
|
+ let getNextSibling = function(node){
|
|
|
if(node.nextSibling){
|
|
|
- ids.push(node.getNextSiblingID());
|
|
|
+ nextSiblingIds.push(node.getNextSiblingID());
|
|
|
+ nextSiblings.push(node.nextSibling);
|
|
|
getNextSibling(node.nextSibling);
|
|
|
}
|
|
|
- }
|
|
|
- //node
|
|
|
- if(node){
|
|
|
- if(node.parent){
|
|
|
- let oprSectionInfo = tools.getSectionInfo(node.parent);
|
|
|
- let updateA = {
|
|
|
- ID: node.getID(),
|
|
|
- ParentID: node.parent.getParentID(),
|
|
|
- NextSiblingID: node.parent.getNextSiblingID(),
|
|
|
- sectionInfo: oprSectionInfo,
|
|
|
- type: 'oprNode'
|
|
|
- };
|
|
|
- updateData.push(updateA);
|
|
|
- //parent
|
|
|
- let updateB = {
|
|
|
- ID: node.getParentID(),
|
|
|
- NextSiblingID: node.getID(),
|
|
|
+ };
|
|
|
+ if(selNodes.length > 0){
|
|
|
+ let firstParent = selNodes[0].parent;
|
|
|
+ //选中的第一个节点有父节点,则可升级
|
|
|
+ if(firstParent){
|
|
|
+ //更新父节点
|
|
|
+ updateData.push({
|
|
|
+ ID: firstParent.getID(),
|
|
|
+ NextSiblingID: selNodes[0].getID(),
|
|
|
type: 'parentNode'
|
|
|
+ });
|
|
|
+ //更新前节点
|
|
|
+ if(selNodes[0].preSibling){
|
|
|
+ updateData.push({
|
|
|
+ ID: selNodes[0].preSibling.getID(),
|
|
|
+ NextSiblingID: -1,
|
|
|
+ type: 'preSiblingNode'
|
|
|
+ });
|
|
|
}
|
|
|
- updateData.push(updateB);
|
|
|
- if(node.nextSibling){
|
|
|
- let nextSectionInfo = tools.getSectionInfo(node.parent);
|
|
|
- if(!tools.isDef(nextSectionInfo.first)){
|
|
|
- nextSectionInfo.first = node.getID();
|
|
|
- }
|
|
|
- else if(!tools.isDef(nextSectionInfo.second)){
|
|
|
- nextSectionInfo.second = node.getID();
|
|
|
+ //更新选中节点的后兄弟节点
|
|
|
+ let lastSelNode = selNodes[selNodes.length - 1];
|
|
|
+ if(lastSelNode.nextSibling){
|
|
|
+ let nextSectionInfo = tools.getSectionInfo(firstParent);
|
|
|
+ let nullNextSectionInfo = tools.sectionInfoNull(nextSectionInfo);
|
|
|
+ if(nullNextSectionInfo){
|
|
|
+ nextSectionInfo[nullNextSectionInfo] = lastSelNode.getID();
|
|
|
}
|
|
|
- else if(!tools.isDef(nextSectionInfo.third)){
|
|
|
- nextSectionInfo.third = node.getID();
|
|
|
- }
|
|
|
- getNextSibling(node);
|
|
|
+ getNextSibling(lastSelNode);
|
|
|
let updateC = {
|
|
|
- ID: ids,
|
|
|
+ ID: nextSiblingIds,
|
|
|
ParentID: node.getID(),
|
|
|
sectionInfo: nextSectionInfo,
|
|
|
type: 'nextSiblingNode'
|
|
|
+ };
|
|
|
+ updateData.push({
|
|
|
+ ID: nextSiblingIds,
|
|
|
+ ParentID: lastSelNode.getID(),
|
|
|
+ sectionInfo: nextSectionInfo,
|
|
|
+ type: 'nextSiblingNode'
|
|
|
+ });
|
|
|
+ //nextSibling children
|
|
|
+ for(let nextSibling of nextSiblings){
|
|
|
+ let nextChildSectionInfo = {first: nextSectionInfo.first, second: nextSectionInfo.second, third: nextSectionInfo.third};
|
|
|
+ let nextCFlag = false;
|
|
|
+ let nullNextCInfo = tools.sectionInfoNull(nextChildSectionInfo);
|
|
|
+ if(nullNextCInfo){
|
|
|
+ nextChildSectionInfo[nullNextCInfo] = nextSibling.getID();
|
|
|
+ nextCFlag = true;
|
|
|
+ }
|
|
|
+ if(nextCFlag){
|
|
|
+ let nextCIds = [];
|
|
|
+ for(let nextChild of nextSibling.children){
|
|
|
+ nextCIds.push(nextChild.getID());
|
|
|
+ //nextSibling grandChildren
|
|
|
+ let nextGChildSectionInfo = {first: nextChildSectionInfo.first, second: nextChildSectionInfo.second, third: nextChildSectionInfo.third};
|
|
|
+ let nextGCFlag = false;
|
|
|
+ if(!tools.isDef(nextChildSectionInfo.third)){
|
|
|
+ nextGChildSectionInfo.third = nextChild.getID();
|
|
|
+ nextGCFlag = true;
|
|
|
+ }
|
|
|
+ if(nextGCFlag){
|
|
|
+ let nextGCIds = [];
|
|
|
+ for(let nextGChild of nextChild.children){
|
|
|
+ nextGCIds.push(nextGChild.getID());
|
|
|
+ }
|
|
|
+ updateData.push({ID: nextGCIds, ParentID: nextChild.getID(), sectionInfo: nextGChildSectionInfo, type: 'nextSiblingNode'});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updateData.push({ID: nextCIds, ParentID: nextSibling.getID(), sectionInfo: nextChildSectionInfo, type: 'nextSiblingNode'});
|
|
|
+ }
|
|
|
}
|
|
|
- updateData.push(updateC);
|
|
|
}
|
|
|
- if(node.preSibling){
|
|
|
- let updateD = {
|
|
|
- ID: node.preSibling.getID(),
|
|
|
- NextSiblingID: -1,
|
|
|
- type: 'preSiblingNode'
|
|
|
+ //更新选中节点
|
|
|
+ for(let i = 0; i < selNodes.length; i++){
|
|
|
+ let selNode = selNodes[i];
|
|
|
+ let oprSectionInfo = tools.getSectionInfo(firstParent);
|
|
|
+ let updateA = {
|
|
|
+ ID: node.getID(),
|
|
|
+ ParentID: node.parent.getParentID(),
|
|
|
+ NextSiblingID: node.parent.getNextSiblingID(),
|
|
|
+ sectionInfo: oprSectionInfo,
|
|
|
+ type: 'oprNode'
|
|
|
+ };
|
|
|
+ updateData.push({
|
|
|
+ ID: selNode.getID(),
|
|
|
+ ParentID: firstParent.getParentID(),
|
|
|
+ NextSiblingID: firstParent.getNextSiblingID(),
|
|
|
+ sectionInfo: oprSectionInfo,
|
|
|
+ type: 'oprNode'
|
|
|
+ });
|
|
|
+ //update node children and grandchildren sectionInfo
|
|
|
+ let nullOprSectionInfo = tools.sectionInfoNull(oprSectionInfo);
|
|
|
+ if(nullOprSectionInfo){
|
|
|
+ let oprChildSectionInfo = {first: oprSectionInfo.first, second: oprSectionInfo.second, third: oprSectionInfo.third};
|
|
|
+ oprChildSectionInfo[nullOprSectionInfo] = selNode.getID();
|
|
|
+ let oprChildIds = [];
|
|
|
+ for(let oprChild of selNode.children){
|
|
|
+ oprChildIds.push(oprChild.getID());
|
|
|
+ let nullOprCSectionInfo = tools.sectionInfoNull(oprChildSectionInfo);
|
|
|
+ if(nullOprCSectionInfo){
|
|
|
+ let oprGCSectionInfo = {first: oprChildSectionInfo.first, second: oprChildSectionInfo.second, third: oprChildSectionInfo.third};
|
|
|
+ oprGCSectionInfo[nullOprCSectionInfo] = oprChild.getID();
|
|
|
+ let oprGCIds = [];
|
|
|
+ for(let oprGChild of oprChild.children){
|
|
|
+ oprGCIds.push(oprGChild.getID());
|
|
|
+ }
|
|
|
+ if(oprGCIds.length > 0){
|
|
|
+ updateData.push({ID: oprGCIds, ParentID: oprChild.getID(), sectionInfo: oprGCSectionInfo, type: 'nextSiblingNode'});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(oprChildIds.length > 0){
|
|
|
+ updateData.push({ID: oprChildIds, ParentID: node.getID(), sectionInfo: oprChildSectionInfo, type: 'nextSiblingNode'});
|
|
|
+ }
|
|
|
}
|
|
|
- updateData.push(updateD);
|
|
|
}
|
|
|
billsAjax.upLevel(userAccount, billsLibId, updateData, function(){
|
|
|
tools.btnAction(btn);
|
|
|
btn.attr('doing', 'false');
|
|
|
- controller.upLevel();
|
|
|
+ for(let upLevelNode of selNodes){
|
|
|
+ controller.setTreeSelected(upLevelNode);
|
|
|
+ controller.upLevel();
|
|
|
+ }
|
|
|
sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
|
|
|
+ controller.sheet.getParent().focus(true);
|
|
|
});
|
|
|
- //rechargeController.createRecharge(controller.tree.selected);
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
downLevel: function(controller, btn){
|
|
|
tools.btnClose(btn);
|
|
|
btn.attr('doing', 'true');
|
|
|
- var node = controller.tree.selected;
|
|
|
var updateData = [];
|
|
|
- if(node){
|
|
|
- if(node.preSibling){
|
|
|
- let oprSectionInfo = tools.getSectionInfo(node.preSibling);
|
|
|
- if(!tools.isDef(oprSectionInfo.first)){
|
|
|
- oprSectionInfo.first = node.preSibling.getID();
|
|
|
- }
|
|
|
- else if(!tools.isDef(oprSectionInfo.second)){
|
|
|
- oprSectionInfo.second = node.preSibling.getID();
|
|
|
- }
|
|
|
- else if(!tools.isDef(oprSectionInfo.third)){
|
|
|
- oprSectionInfo.third = node.preSibling.getID();
|
|
|
- }
|
|
|
- var updateA = {
|
|
|
- ID: node.preSibling.getID(),
|
|
|
- NextSiblingID: node.getNextSiblingID(),
|
|
|
- type: 'preSiblingNode'
|
|
|
- };
|
|
|
- var updateB = {
|
|
|
- ID: node.getID(),
|
|
|
- ParentID: node.preSibling.getID(),
|
|
|
- NextSiblingID: -1,
|
|
|
- sectionInfo: oprSectionInfo,
|
|
|
- type: 'oprNode'
|
|
|
- };
|
|
|
- updateData.push(updateA);
|
|
|
- updateData.push(updateB);
|
|
|
- if(node.preSibling.children.length > 0){
|
|
|
- var updateC = {
|
|
|
- ID: node.preSibling.children[node.preSibling.children.length -1].getID(),
|
|
|
- NextSiblingID: node.getID(),
|
|
|
+ let selNodes = tools.getSameDepthNodes(controller);
|
|
|
+ if(selNodes.length > 0){
|
|
|
+ //选中的第一个节点有前节点,则可降级
|
|
|
+ let firstPreSibling = selNodes[0].preSibling;
|
|
|
+ if(firstPreSibling){
|
|
|
+ //更新前节点
|
|
|
+ updateData.push({
|
|
|
+ ID: firstPreSibling.getID(),
|
|
|
+ NextSiblingID: selNodes[selNodes.length - 1].getNextSiblingID(),
|
|
|
+ type: 'preSiblingNode'});
|
|
|
+ //更新前节点最末子节点
|
|
|
+ if(firstPreSibling.children.length > 0){
|
|
|
+ updateData.push({
|
|
|
+ ID: firstPreSibling.children[firstPreSibling.children.length - 1].getID(),
|
|
|
+ NextSiblingID: selNodes[0].getID(),
|
|
|
type: 'preChildren'
|
|
|
- }
|
|
|
- updateData.push(updateC);
|
|
|
- }
|
|
|
- //更新子节点sectionInfo
|
|
|
- let childSectionInfo = {first: oprSectionInfo.first, second: oprSectionInfo.second, third: oprSectionInfo.third};
|
|
|
- if(!tools.isDef(childSectionInfo.first)){
|
|
|
- childSectionInfo.first = node.getID();
|
|
|
- }
|
|
|
- else if(!tools.isDef(childSectionInfo.second)){
|
|
|
- childSectionInfo.second = node.getID();
|
|
|
- }
|
|
|
- else if(!tools.isDef(childSectionInfo.third)){
|
|
|
- childSectionInfo.third = node.getID();
|
|
|
+ })
|
|
|
}
|
|
|
- for(let i = 0, len = node.children.length; i < len; i++){
|
|
|
+ for(let i = 0; i < selNodes.length; i++){
|
|
|
+ let selNode = selNodes[i];
|
|
|
+ //更新选中的节点(第一层)
|
|
|
+ let oprSectionInfo = tools.getSectionInfo(firstPreSibling);
|
|
|
+ let nullOprSectionInfo = tools.sectionInfoNull(oprSectionInfo);
|
|
|
+ if(nullOprSectionInfo){
|
|
|
+ oprSectionInfo[nullOprSectionInfo] = firstPreSibling.getID();
|
|
|
+ }
|
|
|
updateData.push({
|
|
|
- ID: node.children[i].getID(),
|
|
|
- sectionInfo: childSectionInfo,
|
|
|
- type: 'oprChildren'
|
|
|
- })
|
|
|
+ ID: selNode.getID(),
|
|
|
+ ParentID: firstPreSibling.getID(),
|
|
|
+ NextSiblingID: i === selNodes.length - 1 ? -1 : selNode.getNextSiblingID(),
|
|
|
+ sectionInfo: oprSectionInfo,
|
|
|
+ type: 'oprNode'});
|
|
|
+ //更新选中节点的子节点(第二层)
|
|
|
+ let childSectionInfo = {first: oprSectionInfo.first, second: oprSectionInfo.second, third: oprSectionInfo.third};
|
|
|
+ let updateChildFlag = false;
|
|
|
+ let nullChildSection = tools.sectionInfoNull(childSectionInfo);
|
|
|
+ if(nullChildSection){
|
|
|
+ childSectionInfo[nullChildSection] = selNode.getID();
|
|
|
+ updateChildFlag = true;
|
|
|
+ }
|
|
|
+ if(updateChildFlag){
|
|
|
+ for(let child of selNode.children){
|
|
|
+ updateData.push({
|
|
|
+ ID: child.getID(),
|
|
|
+ sectionInfo: childSectionInfo,
|
|
|
+ type: 'oprChildren'
|
|
|
+ });
|
|
|
+ //更新选中节点的孙子节点(第三层)
|
|
|
+ let gChildSectionInfo = {first: childSectionInfo.first, second: childSectionInfo.second, third: childSectionInfo.third};
|
|
|
+ let updateGChildFlag = false;
|
|
|
+ if(!tools.isDef(gChildSectionInfo.third)){
|
|
|
+ gChildSectionInfo.third = child.getID();
|
|
|
+ updateGChildFlag = true;
|
|
|
+ }
|
|
|
+ if(updateGChildFlag){
|
|
|
+ for(let grandChild of child.children){
|
|
|
+ updateData.push({ID: grandChild.getID(), sectionInfo: gChildSectionInfo, type: 'oprChildren'});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
billsAjax.downLevel(userAccount, billsLibId, updateData, function(){
|
|
|
tools.btnAction(btn);
|
|
|
btn.attr('doing', 'false');
|
|
|
- controller.downLevel();
|
|
|
+ for(let downNode of selNodes){
|
|
|
+ controller.setTreeSelected(downNode);
|
|
|
+ controller.downLevel();
|
|
|
+ }
|
|
|
sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
|
|
|
+ controller.sheet.getParent().focus(true);
|
|
|
});
|
|
|
- //rechargeController.createRecharge(controller.tree.selected);
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -250,6 +333,7 @@ var dbController = {
|
|
|
sheetDatas = tools.getsheetDatas(jobsSheet, 'jobs');
|
|
|
sheetItemsDatas = tools.getsheetDatas(itemsSheet, 'items');
|
|
|
sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
|
|
|
+ controller.sheet.getParent().focus(true);
|
|
|
//to solve refresh after deleted
|
|
|
});
|
|
|
}
|
|
@@ -284,6 +368,7 @@ var dbController = {
|
|
|
btn.attr('doing', 'false');
|
|
|
controller.upMove();
|
|
|
sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
|
|
|
+ controller.sheet.getParent().focus(true);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -321,6 +406,7 @@ var dbController = {
|
|
|
btn.attr('doing', 'false');
|
|
|
controller.downMove();
|
|
|
sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
|
|
|
+ controller.sheet.getParent().focus(true);
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -1438,6 +1524,15 @@ var tools = {
|
|
|
isDef: function (v) {
|
|
|
return v !== undefined && v !== null;
|
|
|
},
|
|
|
+ //返回
|
|
|
+ sectionInfoNull: function (sectionInfo) {
|
|
|
+ for(let info in sectionInfo){
|
|
|
+ if(!this.isDef(sectionInfo[info])){
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ },
|
|
|
|
|
|
getSectionInfo: function (node) {
|
|
|
let parentIDs = [];
|
|
@@ -1459,6 +1554,19 @@ var tools = {
|
|
|
getParent(node.parent);
|
|
|
}
|
|
|
}
|
|
|
+ },
|
|
|
+ getSameDepthNodes: function(controller){
|
|
|
+ const items = controller.tree.items;
|
|
|
+ let rst = [];
|
|
|
+ let sel = controller.sheet.getSelections()[0];
|
|
|
+ let selectedDepth = controller.tree.selected.depth();
|
|
|
+ for(let i = 0; i < sel.rowCount; i++){
|
|
|
+ let row = sel.row + i;
|
|
|
+ if(items[row].depth() === selectedDepth){
|
|
|
+ rst.push(items[row]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
}
|
|
|
};
|
|
|
|