Browse Source

1. common method for sheet's context menu
2. usage for jquery-contextmenu & sheet
3. adjust structure of std_bills_lib

MaiXinRong 8 years ago
parent
commit
d6fa94c84e

+ 3 - 3
public/web/sheet_contextmenu.js

@@ -58,11 +58,11 @@ SHEET_CONTEXTMENU = {
                 // reSet Selections when no selections
                 // reSet Selections when no selections
                 if (info.hitTestType === GC.Spread.Sheets.SheetArea.colHeader) {
                 if (info.hitTestType === GC.Spread.Sheets.SheetArea.colHeader) {
                     if (tools.getCellInSelections(selections, row, col) === null) {
                     if (tools.getCellInSelections(selections, row, col) === null) {
-                        info.sheet.setSelection(-1, row, col);
+                        info.sheet.setSelection(-1, col, info.sheet.getRowCount(), 1);
                     }
                     }
                 } else if (info.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader) {
                 } else if (info.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader) {
                     if (tools.getCellInSelections(selections, row, col) === null) {
                     if (tools.getCellInSelections(selections, row, col) === null) {
-                        info.sheet.setSelection(row, -1, 1, sheet.getColumnCount());
+                        info.sheet.setSelection(row, -1, 1, info.sheet.getColumnCount());
                     }
                     }
                 } else if (info.hitTestType === GC.Spread.Sheets.SheetArea.viewport) {
                 } else if (info.hitTestType === GC.Spread.Sheets.SheetArea.viewport) {
                     if (tools.getCellInSelections(selections, row, col) === null) {
                     if (tools.getCellInSelections(selections, row, col) === null) {
@@ -71,7 +71,7 @@ SHEET_CONTEXTMENU = {
                         info.sheet.setActiveCell(row, col);
                         info.sheet.setActiveCell(row, col);
                     }
                     }
                 } else if (info.hitTestType === GC.Spread.Sheets.SheetArea.corner) {
                 } else if (info.hitTestType === GC.Spread.Sheets.SheetArea.corner) {
-                    info.sheet.setSelection(-1, -1, sheet.getRowCount(), sheet.getColumnCount());
+                    info.sheet.setSelection(-1, -1, info.sheet.getRowCount(), info.sheet.getColumnCount());
                 };
                 };
 
 
                 menuObj.data("sheetArea", info.hitTestType);
                 menuObj.data("sheetArea", info.hitTestType);

+ 6 - 8
web/main/html/main.html

@@ -588,6 +588,7 @@
         billsSpread = new GC.Spread.Sheets.Workbook($('#billsSpread')[0], { sheetCount: 1 });
         billsSpread = new GC.Spread.Sheets.Workbook($('#billsSpread')[0], { sheetCount: 1 });
         billsSpread.options.tabStripVisible = false;
         billsSpread.options.tabStripVisible = false;
         billsSpread.options.scrollbarMaxAlign = true;
         billsSpread.options.scrollbarMaxAlign = true;
+        billsSpread.getActiveSheet().selectionPolicy(GC.Spread.Sheets.SelectionPolicy.single);
 
 
         // For Test
         // For Test
         /*datas.forEach(function (data) {
         /*datas.forEach(function (data) {
@@ -635,12 +636,9 @@
         $.contextMenu({
         $.contextMenu({
             selector: '#billsSpread',
             selector: '#billsSpread',
             build: function ($trigger, e) {
             build: function ($trigger, e) {
-                var offset = $trigger.offset();
-                var x = e.pageX - offset.left;
-                var y = e.pageY - offset.top;
-                var target = billsSpread.getActiveSheet().hitTest(x, y);
-                billsSpread.getActiveSheet().setSelection(target.row, target.col, 1, 1);
+                var target = SheetDataHelper.safeRightClickSelection($trigger, e, billsSpread);
                 controller.setTreeSelected(controller.tree.items[target.row]);
                 controller.setTreeSelected(controller.tree.items[target.row]);
+                return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
             },
             },
             items: {
             items: {
                 "insertBills": {
                 "insertBills": {
@@ -718,9 +716,9 @@
             if (!selected || selected.sourceType === project.Bills.getSourceType()) {
             if (!selected || selected.sourceType === project.Bills.getSourceType()) {
                 newSource = project.Bills.tree.insert(selected ? selected.source.getParentID() : -1, selected ? selected.source.getNextSiblingID() : -1);
                 newSource = project.Bills.tree.insert(selected ? selected.source.getParentID() : -1, selected ? selected.source.getNextSiblingID() : -1);
                 newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
                 newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
-            } else if (selected.sourceType === project.Rations.getSourceType()) {
+            } else if (selected.sourceType === project.Ration.getSourceType()) {
 
 
-            } else if (selected.sourceType === project.GLJs.getSourceType()) {
+            } else if (selected.sourceType === project.GLJ.getSourceType()) {
 
 
             }
             }
 
 
@@ -749,7 +747,7 @@
                     project.Bills.delete(selected.source.getID());
                     project.Bills.delete(selected.source.getID());
                     controller.delete();
                     controller.delete();
                 } else if (selected.sourceType === project.Rations.getSourceType()) {
                 } else if (selected.sourceType === project.Rations.getSourceType()) {
-                    project.Rations.delete(selected.source);
+                    project.Ration.delete(selected.source);
                     controller.delete();
                     controller.delete();
                 };
                 };
             }
             }

+ 2 - 1
web/main/js/models/bills.js

@@ -8,7 +8,8 @@ var Bills = {
             id: 'ID',
             id: 'ID',
             pid: 'ParentID',
             pid: 'ParentID',
             nid: 'NextSiblingID',
             nid: 'NextSiblingID',
-            rootId: -1
+            rootId: -1,
+            autoUpdate: false
         };
         };
 
 
         // 用户定义private方法
         // 用户定义private方法

+ 268 - 201
web/main/js/views/std_bills_lib.js

@@ -2,8 +2,164 @@
  * Created by Mai on 2017/5/16.
  * Created by Mai on 2017/5/16.
  */
  */
 
 
-/*var stdBillsLibController = {
+/**
+ * showObj = {bills, jobAndFeatureTab, job, feature, remarkTab, remark}
+ */
+/*var stdBillsLibObj = {
+    createNew: function (sessionID, showObj) {
+        var tools = {
+            sessionID: sessionID,
+            billsSpread: null,
+            billsJobSpread: null,
+            billsFeatureSpread: null,
+            checkSpread: function (spread, spreadObj) {
+                if (!spread) {
+                    spread = SheetDataHelper.createNewSpread(spreadObj);
+                }
+            }
+        };
+        var libObj = function () {
+            this.billsTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
+            this.spread = tools.billsSpread;
+        };
+
+        libObj.prototype.LoadStdBills = function () {
+            tools.checkSpread(tools.billsSpread, showObj.bills);
+
+        };
 
 
+        return new libObj(sessionID);
+    },
+    settings: {
+        stdBillsTreeSetting: {
+            "treeCol": 0,
+            "emptyRows":0,
+            "headRows":1,
+            "headRowHeight":[
+                35
+            ],
+            "cols":[{
+                "width":100,
+                "readOnly":null,
+                "head":{
+                    "titleNames":["项目编码"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["12px Arial"]
+                },
+                "data":{
+                    "field":"code",
+                    "vAlign":0,
+                    "hAlign":3,
+                    "font":"12px Arial"
+                }
+            }, {
+                "width":120,
+                "readOnly":null,
+                "head":{
+                    "titleNames":["项目名称"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["12px Arial"]
+                },
+                "data":{
+                    "field":"name",
+                    "vAlign":0,
+                    "hAlign":3,
+                    "font":"12px Arial"
+                }
+            }, {
+                "width":40,
+                "readOnly":null,
+                "head":{
+                    "titleNames":["计量单位"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["12px Arial"],
+                    "wordWrap": true
+                },
+                "data":{
+                    "field":"unti",
+                    "vAlign":0,
+                    "hAlign":3,
+                    "font":"12px Arial"
+                }
+            }, {
+                "width":100,
+                "readOnly": true,
+                "head":{
+                    "titleNames":["工程量计算规则"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["12px Arial"]
+                },
+                "data":{
+                    "field":"ruleText",
+                    "vAlign":0,
+                    "hAlign":3,
+                    "font":"12px Arial"
+                }
+            }]
+        },
+        stdBillsJobSetting: {
+            "emptyRows":0,
+            "headRows":1,
+            "headRowHeight":[
+                20
+            ],
+            "cols":[{
+                "width":200,
+                "readOnly":true,
+                "head":{
+                    "titleNames":["工程内容"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["12px Arial"]
+                },
+                "data":{
+                    "field":"content",
+                    "vAlign":0,
+                    "hAlign":3,
+                    "font":"12px Arial"
+                }
+            }]
+        },
+        stdBillsFeatureSetting: {
+            "emptyRows":0,
+            "headRows":1,
+            "headRowHeight":[
+                20
+            ],
+            "cols":[{
+                "width":200,
+                "readOnly":null,
+                "head":{
+                    "titleNames":["项目特征"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["12px Arial"]
+                },
+                "data":{
+                    "field":"content",
+                    "vAlign":0,
+                    "hAlign":3,
+                    "font":"12px Arial"
+                }
+            }]
+        }
+    }
 };*/
 };*/
 
 
 CommonAjax.post('/stdBillsEditor/getStdBillsLib', {userId: userID}, function (datas) {
 CommonAjax.post('/stdBillsEditor/getStdBillsLib', {userId: userID}, function (datas) {
@@ -22,136 +178,83 @@ var LoadStdBills = (function () {
     var stdBillsSpread = SheetDataHelper.createNewSpread($('#stdBillsSpread')[0]);
     var stdBillsSpread = SheetDataHelper.createNewSpread($('#stdBillsSpread')[0]);
     var stdBillsJobSpread = null, stdBillsFeatureSpread = null;
     var stdBillsJobSpread = null, stdBillsFeatureSpread = null;
     var stdBillsTreeSetting = {
     var stdBillsTreeSetting = {
-            "treeCol": 0,
-            "emptyRows":0,
-            "headRows":1,
-            "headRowHeight":[
-                35
-            ],
-            "cols":[
-                {
-                    "width":100,
-                    "readOnly":null,
-                    "head":{
-                        "titleNames":[
-                            "项目编码"
-                        ],
-                        "spanCols":[
-                            1
-                        ],
-                        "spanRows":[
-                            1
-                        ],
-                        "vAlign":[
-                            1
-                        ],
-                        "hAlign":[
-                            1
-                        ],
-                        "font":[
-                            "12px Arial"
-                        ]
-                    },
-                    "data":{
-                        "field":"code",
-                        "vAlign":0,
-                        "hAlign":3,
-                        "font":"12px Arial"
-                    }
-                },
-                {
-                    "width":120,
-                    "readOnly":null,
-                    "head":{
-                        "titleNames":[
-                            "项目名称"
-                        ],
-                        "spanCols":[
-                            1
-                        ],
-                        "spanRows":[
-                            1
-                        ],
-                        "vAlign":[
-                            1
-                        ],
-                        "hAlign":[
-                            1
-                        ],
-                        "font":[
-                            "12px Arial"
-                        ]
-                    },
-                    "data":{
-                        "field":"name",
-                        "vAlign":0,
-                        "hAlign":3,
-                        "font":"12px Arial"
-                    }
-                },
-                {
-                    "width":40,
-                    "readOnly":null,
-                    "head":{
-                        "titleNames":[
-                            "计量单位"
-                        ],
-                        "spanCols":[
-                            1
-                        ],
-                        "spanRows":[
-                            1
-                        ],
-                        "vAlign":[
-                            1
-                        ],
-                        "hAlign":[
-                            1
-                        ],
-                        "font":[
-                            "12px Arial"
-                        ],
-                        "wordWrap": true
-                    },
-                    "data":{
-                        "field":"unti",
-                        "vAlign":0,
-                        "hAlign":3,
-                        "font":"12px Arial"
-                    }
-                },
-                {
-                    "width":100,
-                    "readOnly":null,
-                    "head":{
-                        "titleNames":[
-                            "工程量计算规则"
-                        ],
-                        "spanCols":[
-                            1
-                        ],
-                        "spanRows":[
-                            1
-                        ],
-                        "vAlign":[
-                            1
-                        ],
-                        "hAlign":[
-                            1
-                        ],
-                        "font":[
-                            "12px Arial"
-                        ]
-                    },
-                    "data":{
-                        "field":"ruleText",
-                        "vAlign":0,
-                        "hAlign":3,
-                        "font":"12px Arial"
-                    }
-                }
-            ]
-        };
+        "treeCol": 0,
+        "emptyRows":0,
+        "headRows":1,
+        "headRowHeight":[
+            35
+        ],
+        "cols":[{
+            "width":100,
+            "readOnly":null,
+            "head":{
+                "titleNames":["项目编码"],
+                "spanCols":[1],
+                "spanRows":[1],
+                "vAlign":[1],
+                "hAlign":[1],
+                "font":["12px Arial"]
+            },
+            "data":{
+                "field":"code",
+                "vAlign":0,
+                "hAlign":3,
+                "font":"12px Arial"
+            }
+        }, {
+            "width":120,
+            "readOnly":null,
+            "head":{
+                "titleNames":["项目名称"],
+                "spanCols":[1],
+                "spanRows":[1],
+                "vAlign":[1],
+                "hAlign":[1],
+                "font":["12px Arial"]
+            },
+            "data":{
+                "field":"name",
+                "vAlign":0,
+                "hAlign":3,
+                "font":"12px Arial"
+            }
+        }, {
+            "width":40,
+            "readOnly":null,
+            "head":{
+                "titleNames":["计量单位"],
+                "spanCols":[1],
+                "spanRows":[1],
+                "vAlign":[1],
+                "hAlign":[1],
+                "font":["12px Arial"],
+                "wordWrap": true
+            },
+            "data":{
+                "field":"unti",
+                "vAlign":0,
+                "hAlign":3,
+                "font":"12px Arial"
+            }
+        }, {
+            "width":100,
+            "readOnly": true,
+            "head":{
+                "titleNames":["工程量计算规则"],
+                "spanCols":[1],
+                "spanRows":[1],
+                "vAlign":[1],
+                "hAlign":[1],
+                "font":["12px Arial"]
+            },
+            "data":{
+                "field":"ruleText",
+                "vAlign":0,
+                "hAlign":3,
+                "font":"12px Arial"
+            }
+        }]
+    };
     var stdBillsData, stdBillsJobData, stdBillsFeatureData;
     var stdBillsData, stdBillsJobData, stdBillsFeatureData;
     var stdBillsTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
     var stdBillsTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
     var stdBillsTreeController = TREE_SHEET_CONTROLLER.createNew(stdBillsTree, stdBillsSpread.getActiveSheet(), stdBillsTreeSetting);
     var stdBillsTreeController = TREE_SHEET_CONTROLLER.createNew(stdBillsTree, stdBillsSpread.getActiveSheet(), stdBillsTreeSetting);
@@ -189,7 +292,6 @@ var LoadStdBills = (function () {
         }
         }
         return features;
         return features;
     };
     };
-
     var showJobs = function (jobs) {
     var showJobs = function (jobs) {
         var jobsSetting = {
         var jobsSetting = {
             "emptyRows":0,
             "emptyRows":0,
@@ -197,38 +299,24 @@ var LoadStdBills = (function () {
             "headRowHeight":[
             "headRowHeight":[
                 20
                 20
             ],
             ],
-            "cols":[
-                {
-                    "width":200,
-                    "readOnly":null,
-                    "head":{
-                        "titleNames":[
-                            "工程内容"
-                        ],
-                        "spanCols":[
-                            1
-                        ],
-                        "spanRows":[
-                            1
-                        ],
-                        "vAlign":[
-                            1
-                        ],
-                        "hAlign":[
-                            1
-                        ],
-                        "font":[
-                            "12px Arial"
-                        ]
-                    },
-                    "data":{
-                        "field":"content",
-                        "vAlign":0,
-                        "hAlign":3,
-                        "font":"12px Arial"
-                    }
+            "cols":[{
+                "width":200,
+                "readOnly":true,
+                "head":{
+                    "titleNames":["工程内容"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["12px Arial"]
+                },
+                "data":{
+                    "field":"content",
+                    "vAlign":0,
+                    "hAlign":3,
+                    "font":"12px Arial"
                 }
                 }
-            ]
+            }]
         };
         };
         SheetDataHelper.loadSheetHeader(jobsSetting, stdBillsJobSpread.getActiveSheet());
         SheetDataHelper.loadSheetHeader(jobsSetting, stdBillsJobSpread.getActiveSheet());
         SheetDataHelper.loadSheetData(jobsSetting, stdBillsJobSpread.getActiveSheet(), jobs);
         SheetDataHelper.loadSheetData(jobsSetting, stdBillsJobSpread.getActiveSheet(), jobs);
@@ -240,43 +328,28 @@ var LoadStdBills = (function () {
             "headRowHeight":[
             "headRowHeight":[
                 20
                 20
             ],
             ],
-            "cols":[
-                {
-                    "width":200,
-                    "readOnly":null,
-                    "head":{
-                        "titleNames":[
-                            "项目特征"
-                        ],
-                        "spanCols":[
-                            1
-                        ],
-                        "spanRows":[
-                            1
-                        ],
-                        "vAlign":[
-                            1
-                        ],
-                        "hAlign":[
-                            1
-                        ],
-                        "font":[
-                            "12px Arial"
-                        ]
-                    },
-                    "data":{
-                        "field":"content",
-                        "vAlign":0,
-                        "hAlign":3,
-                        "font":"12px Arial"
-                    }
+            "cols":[{
+                "width":200,
+                "readOnly":true,
+                "head":{
+                    "titleNames":["项目特征"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["12px Arial"]
+                },
+                "data":{
+                    "field":"content",
+                    "vAlign":0,
+                    "hAlign":3,
+                    "font":"12px Arial"
                 }
                 }
-            ]
+            }]
         };
         };
         SheetDataHelper.loadSheetHeader(featuresSetting, stdBillsFeatureSpread.getActiveSheet());
         SheetDataHelper.loadSheetHeader(featuresSetting, stdBillsFeatureSpread.getActiveSheet());
         SheetDataHelper.loadSheetData(featuresSetting, stdBillsFeatureSpread.getActiveSheet(), features);
         SheetDataHelper.loadSheetData(featuresSetting, stdBillsFeatureSpread.getActiveSheet(), features);
     }
     }
-
     var showJobsAndFeatures = function (node) {
     var showJobsAndFeatures = function (node) {
         $('#stdBillsJobTab').show();
         $('#stdBillsJobTab').show();
         $('#stdBillsRemarkTab').hide();
         $('#stdBillsRemarkTab').hide();
@@ -289,7 +362,6 @@ var LoadStdBills = (function () {
         }
         }
         showFeatures(getBillsFeatures(node));
         showFeatures(getBillsFeatures(node));
     };
     };
-
     var showBillsRemark = function (node) {
     var showBillsRemark = function (node) {
         $('#stdBillsJobTab').hide();
         $('#stdBillsJobTab').hide();
         $('#stdBillsRemarkTab').show();
         $('#stdBillsRemarkTab').show();
@@ -324,11 +396,6 @@ var LoadStdBills = (function () {
         });
         });
     };
     };
 
 
-    stdBillsSpread.options.tabStripVisible = false;
-    stdBillsSpread.options.scrollbarMaxAlign = true;
-    stdBillsSpread.options.cutCopyIndicatorVisible = false;
-    stdBillsSpread.options.allowCopyPasteExcelStyle = false;
-
     return LoadData;
     return LoadData;
 })();
 })();
 
 

+ 0 - 1
web/main/js/views/std_ration_lib.js

@@ -168,7 +168,6 @@ $('#stdRationTab').on('shown.bs.tab', function (e) {
         rationLibObj.loadStdRationLibs();
         rationLibObj.loadStdRationLibs();
     };
     };
 });
 });
-
 $('#stdRationLibSelect').change(function () {
 $('#stdRationLibSelect').change(function () {
     var select = $(this);
     var select = $(this);
     if (this.children.length !== 0) {
     if (this.children.length !== 0) {

+ 45 - 0
web/scripts/sheetDataHelper.js

@@ -115,5 +115,50 @@ var SheetDataHelper = {
             sheet.setStyle(-1, iCol, SheetDataHelper.getSheetCellStyle(colSetting));
             sheet.setStyle(-1, iCol, SheetDataHelper.getSheetCellStyle(colSetting));
             sheet.bindColumn(iCol, getBindColInfo(colSetting));
             sheet.bindColumn(iCol, getBindColInfo(colSetting));
         });
         });
+    },
+    getHitTest: function (obj, e, sheet) {
+        var offset = obj.offset(),
+            x = e.pageX - offset.left,
+            y = e.pageY - offset.top;
+        return sheet.hitTest(x, y);
+    },
+    getTargetSelection: function (sheet, target) {
+        if (target.hitTestType === GC.Spread.Sheets.SheetArea.colHeader) {
+            return sheet.getRange(-1, target.col, sheet.getRowCount(), 1);
+        } else if (target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader) {
+            return sheet.getRange(target.row, -1, 1, sheet.getColumnCount());
+        } else if (target.hitTestType === GC.Spread.Sheets.SheetArea.viewport) {
+            return sheet.getRange(target.row, target.col, 1, 1);
+        } else if (target.hitTestType === GC.Spread.Sheets.SheetArea.corner) {
+            return sheet.getRange(-1, -1, sheet.getRowCount(), sheet.getColumnCount());
+        };
+    },
+    getCellInSelections: function (selections, row, col) {
+        var count = selections.length, range;
+        for (var i = 0; i < count; i++) {
+            range = selections[i];
+            if (range.contains(row, col)) {
+                return range;
+            }
+        }
+        return null;
+    },
+    checkTargetInSelection: function (selections, range) {
+        var count = selections.length, sel;
+        for (var i = 0; i < count; i++) {
+            sel = selections[i];
+            if (sel.containsRange(range)) {
+                return true;
+            }
+        }
+        return false;
+    },
+    safeRightClickSelection: function (obj, e, spread) {
+        var sheet = spread.getActiveSheet();
+        var selections = sheet.getSelections(), target = this.getHitTest(obj, e, sheet), range = this.getTargetSelection(sheet, target);
+        if (!this.checkTargetInSelection(selections, range)) {
+            sheet.setSelection(range.row, range.col, range.rowCount, range.colCount);
+        }
+        return target;
     }
     }
 };
 };