|
@@ -1,172 +0,0 @@
|
|
|
-/**
|
|
|
- * Created by Syusuke on 2017/3/17.
|
|
|
- *
|
|
|
- */
|
|
|
-(function($){
|
|
|
- var _spSetting = {
|
|
|
- spType:"",
|
|
|
- header:[],
|
|
|
- view:{
|
|
|
- comboBox:[],
|
|
|
- lockedCells:[]
|
|
|
- },
|
|
|
- private:{
|
|
|
- spType:"",
|
|
|
- colCount:0,
|
|
|
- sectionSelected:null,
|
|
|
- cellPrimValue:null,
|
|
|
- cellCurrValue:null
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- _tools = {
|
|
|
- isArray:function(arr){
|
|
|
- return Object.prototype.toString.apply(arr) === "[object Array]"
|
|
|
- },
|
|
|
- clone:function(obj){
|
|
|
- if(obj===null) return null;
|
|
|
- var o = _tools.isArray(obj)?[]:{};
|
|
|
- for(var i in obj){
|
|
|
- o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()): (typeof obj[i] === "object"? _tools.clone(obj[i]): obj[i]);
|
|
|
- }
|
|
|
- return o;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- var _initSpread = function(spID,spSetting){
|
|
|
- spSetting.private.colCount = spSetting.header.length;
|
|
|
- spSetting.private.spType = spSetting.spType;
|
|
|
- var spread = new GC.Spread.Sheets.Workbook(spID[0],{sheetCount:1});
|
|
|
- var ActiveSheet = spread.getActiveSheet();
|
|
|
- ActiveSheet.setColumnCount(spSetting.header.length, GC.Spread.Sheets.SheetArea.viewport);
|
|
|
- ActiveSheet.options.isProtected = true;
|
|
|
- ActiveSheet.getRange(-1, 0, -1 ,100, GC.Spread.Sheets.SheetArea.viewport).locked(false);
|
|
|
- spread.options.tabStripVisible = false;
|
|
|
- spread.options.scrollbarMaxAlign = false;
|
|
|
- for(var i=0;i<spSetting.header.length;i++){
|
|
|
- ActiveSheet.setValue(0, i, spSetting.header[i].headerName, GC.Spread.Sheets.SheetArea.colHeader);
|
|
|
- ActiveSheet.setColumnWidth(i,spSetting.header[i].headerWidth, GC.Spread.Sheets.SheetArea.colHeader);
|
|
|
- }
|
|
|
- for(var i=0;i<spSetting.view.comboBox.length;i++){
|
|
|
- var c = spSetting.view.comboBox[i]
|
|
|
- var cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
|
|
|
- cellType.items(c.items);
|
|
|
- ActiveSheet.getRange(c.row,c.col,c.rowCount,c.colCount, GC.Spread.Sheets.SheetArea.viewport).cellType(cellType);
|
|
|
- }
|
|
|
- ActiveSheet.getRange(-1, 1, -1 , 100, GC.Spread.Sheets.SheetArea.viewport).locked(true);
|
|
|
-
|
|
|
- ActiveSheet.bind(GC.Spread.Sheets.Events.EditStarting,function(sender,args){
|
|
|
- spSetting.private.cellCurrValue = null;
|
|
|
- spSetting.private.cellPrimValue = ActiveSheet.getValue(args.row,args.col);
|
|
|
- })
|
|
|
-
|
|
|
- ActiveSheet.bind(GC.Spread.Sheets.Events.EditEnding,function(sender,args){
|
|
|
- spSetting.private.cellCurrValue = args.editingText;
|
|
|
- if(args.col == 0){
|
|
|
- var a = spSetting.view.lockedCells;
|
|
|
- var b = [];
|
|
|
- ActiveSheet.getRange(args.row, 1, 1 , 100, GC.Spread.Sheets.SheetArea.viewport).locked(args.editingText == null);
|
|
|
- a.forEach(function(x){
|
|
|
- b.push(x.col);
|
|
|
- })
|
|
|
- b.forEach(function(x){
|
|
|
- ActiveSheet.getCell(args.row,x).locked(true);
|
|
|
- });
|
|
|
- if(args.editingText == null){
|
|
|
- removeAction(spSetting)
|
|
|
- for(var i=0;i<spSetting.private.colCount;i++){
|
|
|
- ActiveSheet.setValue(args.row,i,null);
|
|
|
- }
|
|
|
- }else{
|
|
|
- insertAction(spSetting,function(status){
|
|
|
- if(status == 204)
|
|
|
- ActiveSheet.setValue(args.row,0,null)
|
|
|
- spSetting.private.cellCurrValue = null;
|
|
|
- spSetting.private.cellPrimValue = null;
|
|
|
- });
|
|
|
- }
|
|
|
- }else
|
|
|
- // var code = ActiveSheet.getValue(args.row,0);
|
|
|
- {
|
|
|
- var data = [];
|
|
|
- for(var i=0;i<spSetting.header.length;i++){
|
|
|
- data.push(ActiveSheet.getValue(args.row,i))
|
|
|
- }
|
|
|
- data[args.col] = args.editingText
|
|
|
- updateAction(spSetting,data);
|
|
|
- }
|
|
|
- })
|
|
|
- return spread;
|
|
|
- }
|
|
|
- function insertAction(spSetting,callback){
|
|
|
- var value =JSON.stringify(spSetting.private);
|
|
|
- $.ajax({
|
|
|
- type:"POST",
|
|
|
- url:"http://localhost:6060/rationLibEditor/insert" + spSetting.private.spType,
|
|
|
- data:{"rationLibName":params.realLibName,"value":value},
|
|
|
- dataType:"json",
|
|
|
- cache:false,
|
|
|
- timeout:50000,
|
|
|
- success:function(result,textStatus,status){
|
|
|
- if(status.status == 204){
|
|
|
- alert("编号为"+spSetting.private.cellCurrValue+"已存在,不可重复添加!")
|
|
|
- callback(status.status)
|
|
|
- }
|
|
|
-
|
|
|
- spSetting.private.cellCurrValue = null;
|
|
|
- spSetting.private.cellPrimValue = null;
|
|
|
- },
|
|
|
- error:function(err){
|
|
|
- alert(err.statusText);
|
|
|
- spSetting.private.cellCurrValue = null;
|
|
|
- spSetting.private.cellPrimValue = null;
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- function updateAction(spSetting,data){
|
|
|
- var value = JSON.stringify(spSetting.private);
|
|
|
- var datas = JSON.stringify(data);
|
|
|
- $.ajax({
|
|
|
- type:"POST",
|
|
|
- url:"http://localhost:6060/rationLibEditor/update" + spSetting.private.spType,
|
|
|
- data:{"rationLibName":params.realLibName,"value":value,"data":datas},
|
|
|
- dataType:"json",
|
|
|
- cache:false,
|
|
|
- timeout:50000,
|
|
|
- success:function(result,textStatus,status){
|
|
|
- spSetting.private.cellCurrValue = null;
|
|
|
- spSetting.private.cellPrimValue = null;
|
|
|
- },
|
|
|
- error:function(err){
|
|
|
- alert(err.responseText.error)
|
|
|
- spSetting.private.cellCurrValue = null;
|
|
|
- spSetting.private.cellPrimValue = null;
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- function removeAction(spSetting){
|
|
|
- var value = JSON.stringify(spSetting.private);
|
|
|
- $.ajax({
|
|
|
- type:"POST",
|
|
|
- url:"http://localhost:6060/rationLibEditor/remove" + spSetting.private.spType,
|
|
|
- data:{"rationLibName":params.realLibName,"value":value},
|
|
|
- dataType:"json",
|
|
|
- cache:false,
|
|
|
- timeout:50000,
|
|
|
- success:function(result){
|
|
|
- spSetting.private.cellCurrValue = null;
|
|
|
- spSetting.private.cellPrimValue = null;
|
|
|
- },
|
|
|
- error:function(){
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- $.fn.Spread = {
|
|
|
- init:function(spID,zSetting){
|
|
|
- var spSetting = _tools.clone(_spSetting);
|
|
|
- $.extend(true,spSetting,zSetting);
|
|
|
- return _initSpread(spID,spSetting);
|
|
|
- }
|
|
|
- }
|
|
|
-}(jQuery))
|