Просмотр исходного кода

set selection of sheet before context menu show, refresh context menu disabled

MaiXinRong 8 лет назад
Родитель
Сommit
9a63925d6d
2 измененных файлов с 147 добавлено и 103 удалено
  1. 54 13
      web/main/html/main.html
  2. 93 90
      web/main/js/views/std_ration_lib.js

+ 54 - 13
web/main/html/main.html

@@ -589,19 +589,6 @@
         billsSpread.options.tabStripVisible = false;
         billsSpread.options.scrollbarMaxAlign = true;
 
-        $.contextMenu({
-            selector: '#billsSpread',
-            items: {
-                "edit": {name: "Edit"},
-                "cut": {name: "Cut"},
-                copy: {name: "Copy"},
-                "paste": {name: "Paste"},
-                "delete": {name: "Delete"},
-                "sep1": "---------",
-                "quit": {name: "Quit"}
-            }
-        });
-
         // For Test
         /*datas.forEach(function (data) {
             data.fees = [];
@@ -644,6 +631,60 @@
 
             }
         });
+
+        $.contextMenu({
+            selector: '#billsSpread',
+            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);
+                controller.setTreeSelected(controller.tree.items[target.row]);
+            },
+            items: {
+                "insertBills": {
+                    name: "插入清单",
+                    icon: 'fa-sign-in',
+                    disabled: function () {
+                        return project.mainTree.selected ? project.mainTree.selected.sourceType !== project.Bills.getSourceType() : false;
+                    }
+                },
+                "insertRation": {
+                    name: "插入定额",
+                    icon: 'fa-sign-in',
+                    disabled: function () {
+                        var selected = project.mainTree.selected;
+                        if (selected) {
+                            if (selected.sourceType === project.Ration.getSourceType()) {
+                                return false;
+                            } else if (selected.sourceType === project.Bills.getSourceType()) {
+                                return selected.source.children.length !== 0;
+                            };
+                        } else {
+                            return true;
+                        }
+                    }
+                },
+                "insertLJ": {
+                    name: "插入量价",
+                    icon: 'fa-sign-in',
+                    disabled: function () {
+                        var selected = project.mainTree.selected;
+                        if (selected) {
+                            if (selected.sourceType === project.Ration.getSourceType()) {
+                                return false;
+                            } else if (selected.sourceType === project.Bills.getSourceType()) {
+                                return selected.source.children.length !== 0;
+                            };
+                        } else {
+                            return true;
+                        }
+                    }
+                }
+            }
+        });
+
         /*CommonAjax.post('/bills/getBills', {}, function (bills) {
             project.Bills.loadDatas(bills);
             project.Ration.loadDatas([]);

+ 93 - 90
web/main/js/views/std_ration_lib.js

@@ -1,78 +1,87 @@
 /**
  * Created by Mai on 2017/5/16.
  */
+/*var rationChapterSpread, sectionRationsSpread;*/
 
-var rationChapterSpread, sectionRationsSpread;
-
-var LoadStdRationLibs = function () {
-    CommonAjax.postRationLib('/rationRepository/api/getRationDisplayNames', {user_id: userID}, function (datas) {
-        var select = $('#stdRationLibSelect');
-        select.empty();
-        datas.forEach(function (data) {
-            select.append($('<option>').val(data.ID).text(data.dispName));
-        });
-        if (select[0].options.length !== 0) {
-            LoadStdRation(select.val());
+var rationLibObj = {
+    rationChapterSpread: null,
+    sectionRationsSpread: null,
+    checkSpread: function () {
+        if (!this.rationChapterSpread) {
+            this.rationChapterSpread = SheetDataHelper.createNewSpread($('#stdRationChapter')[0]);
         }
-    }, function () {
-        $('#stdRationLibSelect').empty();
-    });
-};
-
-var LoadStdRation = (function () {
-    var rationChapterTreeSetting = {
-        "emptyRows":0,
-        "headRows":1,
-        "headRowHeight":[30],
-        "treeCol": 0,
-        "cols":[{
-            "width":300,
-            "readOnly": true,
-            "head":{
-                "titleNames":["名称"],
-                "spanCols":[1],
-                "spanRows":[1],
-                "vAlign":[1],
-                "hAlign":[1],
-                "font":["9px Arial"]
-            },
-            "data":{
-                "field":"name",
-                "vAlign":0,
-                "hAlign":3,
-                "font":"9px Arial"
+        if (!this.sectionRationsSpread) {
+            this.sectionRationsSpread = SheetDataHelper.createNewSpread($('#stdSectionRations')[0]);
+        }
+    },
+    loadStdRationLibs: function () {
+        CommonAjax.postRationLib('/rationRepository/api/getRationDisplayNames', {user_id: userID}, function (datas) {
+            var select = $('#stdRationLibSelect');
+            select.empty();
+            datas.forEach(function (data) {
+                select.append($('<option>').val(data.ID).text(data.dispName));
+            });
+            if (select[0].options.length !== 0) {
+                rationLibObj.loadStdRation(select.val());
             }
-        }]
-    };
-    var showRationChapterTree = function (datas) {
-        var rationChapterTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
-        var rationChapterTreeController = TREE_SHEET_CONTROLLER.createNew(rationChapterTree, rationChapterSpread.getActiveSheet(), rationChapterTreeSetting);
-        rationChapterTree.loadDatas(datas);
-        rationChapterTreeController.showTreeData();
-
-        rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
-            LoadSectionRations(node.getID());
+        }, function () {
+            $('#stdRationLibSelect').empty();
         });
+    },
+    loadStdRation: (function () {
+        var rationChapterTreeSetting = {
+            "emptyRows":0,
+            "headRows":1,
+            "headRowHeight":[30],
+            "treeCol": 0,
+            "cols":[{
+                "width":300,
+                "readOnly": true,
+                "head":{
+                    "titleNames":["名称"],
+                    "spanCols":[1],
+                    "spanRows":[1],
+                    "vAlign":[1],
+                    "hAlign":[1],
+                    "font":["9px Arial"]
+                },
+                "data":{
+                    "field":"name",
+                    "vAlign":0,
+                    "hAlign":3,
+                    "font":"9px Arial"
+                }
+            }]
+        };
+        var showRationChapterTree = function (datas) {
+            var rationChapterTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});
+            var rationChapterTreeController = TREE_SHEET_CONTROLLER.createNew(rationChapterTree, rationLibObj.rationChapterSpread.getActiveSheet(), rationChapterTreeSetting);
+            rationChapterTree.loadDatas(datas);
+            rationChapterTreeController.showTreeData();
+
+            rationChapterTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, function (node) {
+                rationLibObj.loadSectionRations(node.getID());
+            });
 
-        if (rationChapterTree.firstNode()) {
-            LoadSectionRations(rationChapterTree.firstNode().getID());
-        } else {
-            LoadSectionRations();
+            if (rationChapterTree.firstNode()) {
+                rationLibObj.loadSectionRations(rationChapterTree.firstNode().getID());
+            } else {
+                rationLibObj.loadSectionRations();
+            };
         };
-    };
 
-    var LoadData = function (rationLibID) {
-        CommonAjax.postRationLib('/rationRepository/api/getRationTree', {userId: userID, rationRepositoryId: rationLibID}, function (datas) {
-            showRationChapterTree(datas);
-        }, function () {
-            showRationChapterTree([]);
-        });
-    };
+        var LoadData = function (rationLibID) {
+            CommonAjax.postRationLib('/rationRepository/api/getRationTree', {userId: userID, rationRepositoryId: rationLibID}, function (datas) {
+                showRationChapterTree(datas);
+            }, function () {
+                showRationChapterTree([]);
+            });
+        };
 
-    return LoadData;
-})();
-var LoadSectionRations = (function () {
-    var sectionRationsSetting = {
+        return LoadData;
+    })(),
+    loadSectionRations: (function () {
+        var sectionRationsSetting = {
             "emptyRows":3,
             "headRows":1,
             "headRowHeight":[20],
@@ -133,42 +142,36 @@ var LoadSectionRations = (function () {
                 }
             ]
         };
-
-    var LoadData = function (sectionID) {
-        if (sectionID) {
-            CommonAjax.postRationLib('/rationRepository/api/getRationItems', {userId: userID, sectionID: sectionID}, function (datas) {
-                SheetDataHelper.loadSheetHeader(sectionRationsSetting, sectionRationsSpread.getActiveSheet());
-                SheetDataHelper.loadSheetData(sectionRationsSetting, sectionRationsSpread.getActiveSheet(), datas);
-            }, function () {
-                SheetDataHelper.loadSheetHeader(sectionRationsSetting, sectionRationsSpread.getActiveSheet());
-                SheetDataHelper.loadSheetData(sectionRationsSetting, sectionRationsSpread.getActiveSheet(), []);
-            });
-        } else {
-            SheetDataHelper.loadSheetHeader(sectionRationsSetting, sectionRationsSpread.getActiveSheet());
-            SheetDataHelper.loadSheetData(sectionRationsSetting, sectionRationsSpread.getActiveSheet(), []);
+        var showDatas = function (datas) {
+            SheetDataHelper.loadSheetHeader(sectionRationsSetting, rationLibObj.sectionRationsSpread.getActiveSheet());
+            SheetDataHelper.loadSheetData(sectionRationsSetting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
         }
-    };
-
-    return LoadData;
-})();
+        var LoadData = function (sectionID) {
+            if (sectionID) {
+                CommonAjax.postRationLib('/rationRepository/api/getRationItems', {userId: userID, sectionID: sectionID}, function (datas) {
+                    showDatas(datas);
+                }, function () {
+                    showDatas([]);
+                });
+            } else {
+                showDatas([]);
+            }
+        };
+        return LoadData;
+    })()
+};
 
 $('#stdRationTab').on('shown.bs.tab', function (e) {
     var select = $('#stdRationLibSelect');
-    if (!rationChapterSpread) {
-        rationChapterSpread = SheetDataHelper.createNewSpread($('#stdRationChapter')[0]);
-    }
-    if (!sectionRationsSpread) {
-        sectionRationsSpread = SheetDataHelper.createNewSpread($('#stdSectionRations')[0]);
-    }
+    rationLibObj.checkSpread();
     if (select[0].options.length === 0) {
-        LoadStdRationLibs();
+        rationLibObj.loadStdRationLibs();
     };
 });
 
 $('#stdRationLibSelect').change(function () {
     var select = $(this);
     if (this.children.length !== 0) {
-        LoadStdRation(select.val());
+        rationLibObj.loadStdRation(select.val());
     }
-    rationChapterSpread.getActiveSheet().repaint();
 });