|
@@ -48,22 +48,40 @@ var dbController = {
|
|
|
|
|
|
upLevel: function(controller){
|
|
|
var node = controller.tree.selected;
|
|
|
+ var ids = [];
|
|
|
+ var getNextSibling = function(node){
|
|
|
+ if(node.nextSibling){
|
|
|
+ ids.push(node.getNextSiblingID());
|
|
|
+ getNextSibling(node.nextSibling);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //node
|
|
|
+ //todo:整合代码:updataPNId;
|
|
|
+ //------------------------todo
|
|
|
+ /* var updateData = [
|
|
|
+ {
|
|
|
+ billsLibId: null,
|
|
|
+ updateIds: [],
|
|
|
+ updatePid: null,
|
|
|
+ updateNid: null
|
|
|
+ }
|
|
|
+ ];*/
|
|
|
+ //--------------------------todo
|
|
|
if(node){
|
|
|
if(node.parent){
|
|
|
- //node
|
|
|
billsAjax.updatePNId(billsLibId, node.getID(), node.parent.getParentID(), node.parent.getNextSiblingID());
|
|
|
//parent
|
|
|
billsAjax.updatePNId(billsLibId, node.getParentID(), null, node.getID());
|
|
|
if(node.nextSibling){
|
|
|
- billsAjax.updatePNId(billsLibId, node.getNextSiblingID(), node.getID(), null);
|
|
|
+ getNextSibling(node);
|
|
|
+ billsAjax.updatePNId(billsLibId, ids, node.getID(), null);
|
|
|
}
|
|
|
if(node.preSibling){
|
|
|
billsAjax.updatePNId(billsLibId, node.preSibling.getID(), null, -1);
|
|
|
}
|
|
|
+ controller.upLevel();
|
|
|
}
|
|
|
- controller.upLevel();
|
|
|
}
|
|
|
-
|
|
|
},
|
|
|
|
|
|
downLevel: function(controller){
|
|
@@ -127,4 +145,574 @@ var dbController = {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+};
|
|
|
+//todo: 总表不存在则自动生成code并对应到分表
|
|
|
+var createObj = {
|
|
|
+ newJob: function(data){
|
|
|
+ var Job = function(data){
|
|
|
+ this.data = data;
|
|
|
+ };
|
|
|
+ return new Job(data);
|
|
|
+ },
|
|
|
+ newJobs: function(){
|
|
|
+ var TotalJobs = function(){
|
|
|
+ this.jobs = {};
|
|
|
+ this.jobsArr = [];
|
|
|
+ this.prefix = '_id';
|
|
|
+ };
|
|
|
+
|
|
|
+ TotalJobs.prototype.loadJobs = function (nodes){
|
|
|
+ var me = this;
|
|
|
+ jobsAjax.getJobContent(billsLibId, function(reslut){
|
|
|
+ reslut.forEach(function(jobData){
|
|
|
+ var job = createObj.newJob(jobData);
|
|
|
+ me.jobs[me.prefix + jobData.id] = job;
|
|
|
+ me.jobsArr.push(job);
|
|
|
+ });
|
|
|
+ nodes.forEach(function(node){
|
|
|
+ node.data.jobs.forEach(function(data){
|
|
|
+ node.jobs.push(me.jobs[me.prefix + data.id]);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ TotalJobs.prototype.getUpdateIds = function(nodes, repeatId){
|
|
|
+ var ids = [];
|
|
|
+ nodes.forEach(function(node){
|
|
|
+ node.jobs.forEach(function(job){
|
|
|
+ if(job.data.id === repeatId){
|
|
|
+ ids.push(node.getID());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return ids;
|
|
|
+ };
|
|
|
+
|
|
|
+ return new TotalJobs();
|
|
|
+ },
|
|
|
+
|
|
|
+ newItem: function(data){
|
|
|
+ var Item = function(data){
|
|
|
+ this.data = data;
|
|
|
+ };
|
|
|
+ return new Item(data);
|
|
|
+ },
|
|
|
+
|
|
|
+ newItems: function(){
|
|
|
+ var TotalItems = function(){
|
|
|
+ this.items = {};
|
|
|
+ this.itemsArr = [];
|
|
|
+ this.prefix = '_id';
|
|
|
+ };
|
|
|
+
|
|
|
+ TotalItems.prototype.loadItems = function (nodes){
|
|
|
+ var me = this;
|
|
|
+ itemsAjax.getItemCharacter(billsLibId, function(reslut){
|
|
|
+ reslut.forEach(function(itemData){
|
|
|
+ var item = createObj.newItem(itemData);
|
|
|
+ me.items[me.prefix + itemData.id] = item;
|
|
|
+ me.itemsArr.push(item);
|
|
|
+ });
|
|
|
+ nodes.forEach(function(node){
|
|
|
+ node.data.items.forEach(function(data){
|
|
|
+ node.items.push(me.items[me.prefix + data.id]);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ TotalItems.prototype.getUpdateIds = function(nodes, repeatId){
|
|
|
+ var ids = [];
|
|
|
+ nodes.forEach(function(node){
|
|
|
+ node.items.forEach(function(item){
|
|
|
+ if(item.data.id === repeatId){
|
|
|
+ ids.push(node.getID());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return ids;
|
|
|
+ };
|
|
|
+ return new TotalItems();
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+var jobsController = {
|
|
|
+ editData: function(controller, sheet, totalJobs, maxNumber, setting){
|
|
|
+ var orgData;
|
|
|
+ sheet.bind(GC.Spread.Sheets.Events.EnterCell, function(sender, args){
|
|
|
+ orgData = sheet.getCell(args.row, args.col).value();
|
|
|
+ });
|
|
|
+ sheet.bind(GC.Spread.Sheets.Events.EditEnded, function(sender, args) {
|
|
|
+ var field, newData = args.editingText, id = sheet.getTag(args.row, args.col);
|
|
|
+ setting.cols.forEach(function (col, idx) {
|
|
|
+ if (args.col === idx) {
|
|
|
+ field = col.data.field;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (controller.tree.selected) {
|
|
|
+ var isExist = false;
|
|
|
+ var isRepeat = false;
|
|
|
+ //isExist?
|
|
|
+ if(totalJobs.jobsArr.length > 0){
|
|
|
+ totalJobs.jobsArr.forEach(function(job){
|
|
|
+ if(job.data[field] === newData && newData !== orgData){
|
|
|
+ isExist = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //isRepeat?
|
|
|
+ if (controller.tree.selected.jobs) {
|
|
|
+ controller.tree.selected.jobs.forEach(function (job) {
|
|
|
+ if (job.data[field] === newData && id !== job.data.id) {
|
|
|
+ isRepeat = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //create
|
|
|
+ if(!id && newData && !isRepeat){
|
|
|
+ if(totalJobs.jobsArr.length > 0){
|
|
|
+ if(isExist){
|
|
|
+ jobsController.createExist(sheet, controller, totalJobs, field, newData, isExist, args);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ jobsController.createNew(maxNumber, sheet, controller, totalJobs, field, newData, args);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ jobsController.createInit(sheet, controller, totalJobs, field, newData, args);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //update
|
|
|
+ else if(id && newData !== orgData && !isRepeat){
|
|
|
+ jobsController.update(maxNumber, sheet, controller, totalJobs, field, newData, id);
|
|
|
+ }
|
|
|
+ //处理重复
|
|
|
+ if(isRepeat){
|
|
|
+ //todo:redirect focus
|
|
|
+ if(id && newData){
|
|
|
+ console.log('isRepeat1 orgData:'+orgData);
|
|
|
+ sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value(orgData);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log('isRepeat2');
|
|
|
+ sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ createExist: function(sheet, controller, totalJobs, field, newData, args){
|
|
|
+ totalJobs.jobsArr.forEach(function(job){
|
|
|
+ //todo:整合代码
|
|
|
+ if(field === 'content'&& newData === job.data.content){
|
|
|
+ console.log('ECreate1');
|
|
|
+ //isExist = true;
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data);
|
|
|
+ if(!controller.tree.selected.jobs){
|
|
|
+ controller.tree.selected.jobs = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.jobs.push(job);
|
|
|
+ sheet.getCell(args.row, 0).value(job.data.code);
|
|
|
+ sheet.setTag(args.row, 0, job.data.id);
|
|
|
+ sheet.setTag(args.row, 1, job.data.id);
|
|
|
+ }
|
|
|
+ else if(field === 'code' && newData === job.data.code){
|
|
|
+ console.log('ECreate2');
|
|
|
+ //isExist = true;
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data);
|
|
|
+ if(!controller.tree.selected.jobs){
|
|
|
+ controller.tree.selected.jobs = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.jobs.push(job);
|
|
|
+ sheet.getCell(args.row, 1).value(job.data.content);
|
|
|
+ sheet.setTag(args.row, 0, job.data.id);
|
|
|
+ sheet.setTag(args.row, 1, job.data.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ createNew: function(maxNumber, sheet, controller, totalJobs, field, newData, args){
|
|
|
+ console.log('notEcreate');
|
|
|
+ if(field === 'content'){
|
|
|
+ maxNumber++;
|
|
|
+ jobsAjax.createJobContent(billsLibId, field, newData, maxNumber, function(id){
|
|
|
+ var newJobData, newJob;
|
|
|
+ newJobData = {id: id, content: newData, code: maxNumber};
|
|
|
+ newJob = createObj.newJob(newJobData);
|
|
|
+ totalJobs.jobs[totalJobs.prefix + id] = newJob;
|
|
|
+ totalJobs.jobsArr.push(newJob);
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
|
|
|
+ if(!controller.tree.selected.jobs){
|
|
|
+ controller.tree.selected.jobs = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.jobs.push(newJob);
|
|
|
+ sheet.setTag(args.row, 0, id);
|
|
|
+ sheet.setTag(args.row, 1, id);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sheet.getCell(args.row, args.col).value('');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ createInit: function(sheet, controller, totalJobs, field, newData, args){
|
|
|
+ console.log('0create '+totalJobs.jobsArr.length);
|
|
|
+ //new----------------
|
|
|
+ if(field === 'content'){
|
|
|
+ jobsAjax.createJobContent(billsLibId, field, newData, 1, function(id){
|
|
|
+ var newJobData, newJob;
|
|
|
+ newJobData = {id: id, content: newData, code: 1};
|
|
|
+ newJob = createObj.newJob(newJobData);
|
|
|
+ totalJobs.jobs[totalJobs.prefix + id] = newJob;
|
|
|
+ totalJobs.jobsArr.push(newJob);
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
|
|
|
+ if(!controller.tree.selected.jobs){
|
|
|
+ controller.tree.selected.jobs = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.jobs.push(newJob);
|
|
|
+ sheet.setTag(args.row, 0, id);
|
|
|
+ sheet.setTag(args.row, 1, id);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sheet.getCell(args.row, args.col).value('');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ update: function(maxNumber, sheet, controller, totalJobs, field, newData, id, isExist){
|
|
|
+ //1.更新后的数据存在总表则引用总表,不存在则新增 2.原数据有多个引用,
|
|
|
+ var index;
|
|
|
+ controller.tree.selected.jobs.forEach(function(job){
|
|
|
+ if(job.data.id === id){
|
|
|
+ index = controller.tree.selected.jobs.indexOf(job);
|
|
|
+ controller.tree.selected.jobs.splice(index ,1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(isExist){
|
|
|
+ totalJobs.forEach(function(job){
|
|
|
+ if(field === 'code' && job.data[field] === newData){
|
|
|
+ controller.tree.selected.jobs.splice(index, 0, job);
|
|
|
+ var newJobData = {id: job.data.id, code: newData, content: job.data.content}
|
|
|
+ billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), id, newJobData, 'jobs');
|
|
|
+ sheet.getCell(args.row, 1).value(job.data.content);
|
|
|
+ sheet.setTag(args.row, 0, job.data.id);
|
|
|
+ sheet.setTag(args.row, 1, job.data.id);
|
|
|
+ }
|
|
|
+ if(field === 'content' && job.data[field] === newData){
|
|
|
+ controller.tree.selected.jobs.splice(index, 0, job);
|
|
|
+ var newJobData = {id: job.data.id, code: job.data.code, content: newData}
|
|
|
+ billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), id, newJobData, 'jobs');
|
|
|
+ sheet.getCell(args.row, 0).value(job.data.code);
|
|
|
+ sheet.setTag(args.row, 0, job.data.id);
|
|
|
+ sheet.setTag(args.row, 1, job.data.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ //jobsController.createNew(maxNumber, sheet, controller, totalJobs, field, newData, args);
|
|
|
+ if(field === 'content'){
|
|
|
+ maxNumber++;
|
|
|
+ jobsAjax.createJobContent(billsLibId, field, newData, maxNumber, function(newId){
|
|
|
+ var newJobData, newJob;
|
|
|
+ newJobData = {id: newId, content: newData, code: maxNumber};
|
|
|
+ newJob = createObj.newJob(newJobData);
|
|
|
+ totalJobs.jobs[totalJobs.prefix + newId] = newJob;
|
|
|
+ totalJobs.jobsArr.push(newJob);
|
|
|
+ billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), id, newJobData, 'jobs');
|
|
|
+ if(!controller.tree.selected.jobs){
|
|
|
+ controller.tree.selected.jobs = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.jobs.splice(index, 0, newJob);
|
|
|
+ sheet.setTag(args.row, 0, newId);
|
|
|
+ sheet.setTag(args.row, 1, newId);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sheet.getCell(args.row, args.col).value(orgData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ delete: function(id){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+var itemsController = {
|
|
|
+ editData: function(controller, sheet, totalItems, setting){
|
|
|
+ var orgData;
|
|
|
+ sheet.bind(GC.Spread.Sheets.Events.EnterCell, function(sender, args){
|
|
|
+ orgData = sheet.getCell(args.row, args.col).value();
|
|
|
+ });
|
|
|
+ sheet.bind(GC.Spread.Sheets.Events.EditEnded, function(sender, args) {
|
|
|
+ var field, newData = args.editingText, id = sheet.getTag(args.row, args.col);
|
|
|
+ setting.cols.forEach(function (col, idx) {
|
|
|
+ if (args.col === idx) {
|
|
|
+ field = col.data.field;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (controller.tree.selected) {
|
|
|
+ var isExist = false;
|
|
|
+ var isRepeat = false;
|
|
|
+ //isRepeat?
|
|
|
+ if (controller.tree.selected.items) {
|
|
|
+ controller.tree.selected.items.forEach(function (item) {
|
|
|
+ if (item.data[field] === newData && id !== item.data.id) {
|
|
|
+ isRepeat = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //create
|
|
|
+ if(!id && newData && !isRepeat){
|
|
|
+ if(totalItems.itemsArr.length > 0){
|
|
|
+ itemsController.createExist(sheet, controller, totalItems, field, newData, isExist, args);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ itemsController.createInit(sheet, controller, totalItems, field, newData, args);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //update
|
|
|
+ else if(id && newData !== orgData && !isRepeat){
|
|
|
+ itemsController.update(controller, totalItems, field, newData, id);
|
|
|
+ }
|
|
|
+ //处理重复
|
|
|
+ if(isRepeat){
|
|
|
+ //todo:redirect focus
|
|
|
+ if(id && newData){
|
|
|
+ console.log('isRepeat1 orgData:'+orgData);
|
|
|
+ sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value(orgData);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log('isRepeat2');
|
|
|
+ sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ createExist: function(sheet, controller, totalItems, field, newData, isExist, args){
|
|
|
+ totalItems.itemsArr.forEach(function(item){
|
|
|
+ //todo:整合代码
|
|
|
+ if(field === 'content'&& newData === item.data.content){
|
|
|
+ console.log('ECreate1');
|
|
|
+ isExist = true;
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'items', item.data);
|
|
|
+ if(!controller.tree.selected.items){
|
|
|
+ controller.tree.selected.items = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.items.push(item);
|
|
|
+ sheet.getCell(args.row, 0).value(item.data.code);
|
|
|
+ sheet.setTag(args.row, 0, item.data.id);
|
|
|
+ sheet.setTag(args.row, 1, item.data.id);
|
|
|
+ }
|
|
|
+ else if(field === 'code' && newData === item.data.code){
|
|
|
+ console.log('ECreate2');
|
|
|
+ isExist = true;
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'items', item.data);
|
|
|
+ if(!controller.tree.selected.items){
|
|
|
+ controller.tree.selected.items = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.items.push(item);
|
|
|
+ sheet.getCell(args.row, 1).value(item.data.content);
|
|
|
+ sheet.setTag(args.row, 0, item.data.id);
|
|
|
+ sheet.setTag(args.row, 1, item.data.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(!isExist){
|
|
|
+ console.log('notEcreate');
|
|
|
+ itemsAjax.createItemCharacter(billsLibId, field, newData, function(id){
|
|
|
+ var newItemData, newItem;
|
|
|
+ if(field === 'code'){
|
|
|
+ newItemData = {id: id, code: newData, content: ''};
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ newItemData = {id: id, content: newData, code: ''};
|
|
|
+ }
|
|
|
+ newItem = createObj.newItem(newItemData);
|
|
|
+ totalItems.items[totalItems.prefix + id] = newItem;
|
|
|
+ totalItems.itemsArr.push(newItem);
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'items', newItemData);
|
|
|
+ if(!controller.tree.selected.items){
|
|
|
+ controller.tree.selected.items = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.items.push(newItem);
|
|
|
+ sheet.setTag(args.row, 0, id);
|
|
|
+ sheet.setTag(args.row, 1, id);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ createNew: function(sheet, controller, totalItems, field, newData, args){
|
|
|
+ console.log('0create '+totalItems.itemsArr.length);
|
|
|
+ itemsAjax.createItemCharacter(billsLibId, field, newData, function(id){
|
|
|
+ var newItemData, newItem;
|
|
|
+ if(field === 'code'){
|
|
|
+ newItemData = {id: id, code: newData, content: ''};
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ newItemData = {id: id, content: newData, code: ''};
|
|
|
+ }
|
|
|
+ newItem = createObj.newItem(newItemData);
|
|
|
+ totalItems.items[totalItems.prefix + id] = newItem;
|
|
|
+ totalItems.itemsArr.push(newItem);
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'items', newItemData);
|
|
|
+ if(!controller.tree.selected.items){
|
|
|
+ controller.tree.selected.items = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.items.push(newItem);
|
|
|
+ sheet.setTag(args.row, 0, id);
|
|
|
+ sheet.setTag(args.row, 1, id);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ update: function(controller, totalItems, field, newData, id){
|
|
|
+ console.log('update');
|
|
|
+ var ids = totalItems.getUpdateIds(controller.tree.items, id);
|
|
|
+ totalItems.items[totalItems.prefix + id].data[field] = newData;
|
|
|
+ itemsAjax.updateItemCharacter(id, field, newData);
|
|
|
+ billsAjax.updateBillsArr(billsLibId, ids, field, id, newData, 'items');
|
|
|
+ },
|
|
|
+
|
|
|
+ delete: function(id){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+/*function jobsController(controller, sheet, totalJobs, setting){
|
|
|
+ var orgData;
|
|
|
+ sheet.bind(GC.Spread.Sheets.Events.EnterCell, function(sender, args){
|
|
|
+ orgData = sheet.getCell(args.row, args.col).value();
|
|
|
+ });
|
|
|
+ sheet.bind(GC.Spread.Sheets.Events.EditEnded, function(sender, args){
|
|
|
+ var field, newData = args.editingText, id = sheet.getTag(args.row, args.col) ;
|
|
|
+ setting.cols.forEach(function(col, idx){
|
|
|
+ if(args.col === idx){
|
|
|
+ field = col.data.field;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(controller.tree.selected){
|
|
|
+ var isExist = false;
|
|
|
+ var isRepeat = false;
|
|
|
+ //isRepeat?
|
|
|
+ if(controller.tree.selected.jobs){
|
|
|
+ controller.tree.selected.jobs.forEach(function(job){
|
|
|
+ if(job.data[field] === newData && id !== job.data.id){
|
|
|
+ isRepeat = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //create
|
|
|
+ if(!id && newData && !isRepeat){
|
|
|
+ if(totalJobs.jobsArr.length > 0){
|
|
|
+ //spl==========================================================
|
|
|
+ totalJobs.jobsArr.forEach(function(job){
|
|
|
+ //todo:整合代码
|
|
|
+ if(field === 'content'&& newData === job.data.content){
|
|
|
+ console.log('ECreate1');
|
|
|
+ isExist = true;
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data);
|
|
|
+ if(!controller.tree.selected.jobs){
|
|
|
+ controller.tree.selected.jobs = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.jobs.push(job);
|
|
|
+ sheet.getCell(args.row, 0).value(job.data.code);
|
|
|
+ sheet.setTag(args.row, 0, job.data.id);
|
|
|
+ sheet.setTag(args.row, 1, job.data.id);
|
|
|
+ }
|
|
|
+ else if(field === 'code' && newData === job.data.code){
|
|
|
+ console.log('ECreate2');
|
|
|
+ isExist = true;
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data);
|
|
|
+ if(!controller.tree.selected.jobs){
|
|
|
+ controller.tree.selected.jobs = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.jobs.push(job);
|
|
|
+ sheet.getCell(args.row, 1).value(job.data.content);
|
|
|
+ sheet.setTag(args.row, 0, job.data.id);
|
|
|
+ sheet.setTag(args.row, 1, job.data.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(!isExist){
|
|
|
+ console.log('notEcreate');
|
|
|
+ jobsAjax.createJobContent(billsLibId, field, newData, function(id){
|
|
|
+ var newJobData, newJob;
|
|
|
+ if(field === 'code'){
|
|
|
+ newJobData = {id: id, code: newData, content: ''};
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ newJobData = {id: id, content: newData, code: ''};
|
|
|
+ }
|
|
|
+ newJob = new Job(newJobData);
|
|
|
+ totalJobs.jobs[totalJobs.prefix + id] = newJob;
|
|
|
+ totalJobs.jobsArr.push(newJob);
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
|
|
|
+ if(!controller.tree.selected.jobs){
|
|
|
+ controller.tree.selected.jobs = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.jobs.push(newJob);
|
|
|
+ sheet.setTag(args.row, 0, id);
|
|
|
+ sheet.setTag(args.row, 1, id);
|
|
|
+ });
|
|
|
+ //spl==========================================================
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //spl==========================================================
|
|
|
+ console.log('0create '+totalJobs.jobsArr.length);
|
|
|
+ jobsAjax.createJobContent(billsLibId, field, newData, function(id){
|
|
|
+ var newJobData, newJob;
|
|
|
+ if(field === 'code'){
|
|
|
+ newJobData = {id: id, code: newData, content: ''};
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ newJobData = {id: id, content: newData, code: ''};
|
|
|
+ }
|
|
|
+ newJob = new Job(newJobData);
|
|
|
+ totalJobs.jobs[totalJobs.prefix + id] = newJob;
|
|
|
+ totalJobs.jobsArr.push(newJob);
|
|
|
+ billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', newJobData);
|
|
|
+ if(!controller.tree.selected.jobs){
|
|
|
+ controller.tree.selected.jobs = new Array();
|
|
|
+ }
|
|
|
+ controller.tree.selected.jobs.push(newJob);
|
|
|
+ sheet.setTag(args.row, 0, id);
|
|
|
+ sheet.setTag(args.row, 1, id);
|
|
|
+ });
|
|
|
+ //spl==========================================================
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //update
|
|
|
+ else if(id && newData !== orgData && !isRepeat){
|
|
|
+ //spl==========================================================
|
|
|
+ console.log('update');
|
|
|
+ var ids = totalJobs.getUpdateIds(controller.tree.items, id);
|
|
|
+ totalJobs.jobs[totalJobs.prefix + id].data[field] = newData;
|
|
|
+ jobsAjax.updateJobContent(id, field, newData);
|
|
|
+ billsAjax.updateBillsArr(billsLibId, ids, field, id, newData);
|
|
|
+ //spl==========================================================
|
|
|
+ }
|
|
|
+ if(isRepeat){
|
|
|
+ //todo:redirect focus
|
|
|
+ if(id && newData){
|
|
|
+ console.log('isRepeat1 orgData:'+orgData);
|
|
|
+ sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value(orgData);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log('isRepeat2');
|
|
|
+ sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //delete
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+}*/
|
|
|
+
|
|
|
+
|