Commit cd454371 authored by GoshaZotov's avatar GoshaZotov Committed by Alexander.Trofimov

add function af_checkInsDelCells(check range before ins/del cells)

parent 29065301
...@@ -1904,6 +1904,31 @@ ...@@ -1904,6 +1904,31 @@
return result; return result;
}, },
getTableIntersectionRange: function(range)
{
var worksheet = this.worksheet;
var res = null;
var tableParts = worksheet.TableParts;
if(tableParts)
{
for(var i = 0; i < tableParts.length; i++)
{
if(tableParts[i].Ref.intersection(range))
{
if(res === null)
{
res = [];
}
res.push(worksheet.TableParts[i]);
}
}
}
return res;
},
changeFormatTableInfo: function(tablePart, optionType) changeFormatTableInfo: function(tablePart, optionType)
{ {
switch(optionType) switch(optionType)
...@@ -3807,21 +3832,6 @@ ...@@ -3807,21 +3832,6 @@
return res; return res;
}, },
_isIntersectionTableParts: function(range)
{
var worksheet = this.worksheet;
var tableParts = worksheet.TableParts;
var tablePart;
for(var i = 0; i < tableParts.length; i++)
{
tablePart = tableParts[i];
if(tablePart.Ref.intersection(range))
return true;
}
return false;
},
_cleanFilterColumnsAndSortState: function(autoFilterElement, activeCells) _cleanFilterColumnsAndSortState: function(autoFilterElement, activeCells)
{ {
var worksheet = this.worksheet; var worksheet = this.worksheet;
...@@ -3983,17 +3993,17 @@ ...@@ -3983,17 +3993,17 @@
var tableRef = worksheet.TableParts[i].Ref; var tableRef = worksheet.TableParts[i].Ref;
if(tableRef.r1 >= range.r2) if(tableRef.r1 >= range.r2)
{ {
if(range.c1 < tableRef.c1 && range.c2 < tableRef.c2 && range.c2 >= tableRef.c1) if(tableRef.c1 < range.c1 && tableRef.c2 > range.c1 && tableRef.c2 <= range.c2)
{ {
result = true; result = true;
break; break;
} }
else if(range.c1 > tableRef.c1 && range.c2 > tableRef.c2 && range.c1 >= tableRef.c1) else if(tableRef.c1 >= range.c1 && tableRef.c1 < range.c2 && tableRef.c2 > range.c2)
{ {
result = true; result = true;
break; break;
} }
else if((range.c1 > tableRef.c1 && range.c2 <= tableRef.c2) || (range.c1 >= tableRef.c1 && range.c2 < tableRef.c2)) else if((tableRef.c1 <= range.c1 && tableRef.c2 > range.c2) || (tableRef.c1 < range.c1 && tableRef.c2 >= range.c2))
{ {
result = true; result = true;
break; break;
...@@ -4005,6 +4015,41 @@ ...@@ -4005,6 +4015,41 @@
return result; return result;
}, },
isPartTablePartsRightRange: function(range)
{
var worksheet = this.worksheet;
var res = false;
if(worksheet.TableParts && worksheet.TableParts.length)
{
for(var i = 0; i < worksheet.TableParts.length; i++)
{
var tableRef = worksheet.TableParts[i].Ref;
if(tableRef.c1 >= range.c2)
{
if(tableRef.r1 < range.r1 && tableRef.r2 > range.r1 && tableRef.r2 <= range.r2)
{
result = true;
break;
}
else if(tableRef.r1 >= range.r1 && tableRef.r1 < range.r2 && tableRef.r2 > range.r2)
{
result = true;
break;
}
else if((tableRef.r1 <= range.r1 && tableRef.r2 > range.r2) || (tableRef.r1 < range.r1 && tableRef.r2 >= range.r2))
{
result = true;
break;
}
}
}
}
return res;
},
_isPartAutoFilterUnderRange: function(range) _isPartAutoFilterUnderRange: function(range)
{ {
var worksheet = this.worksheet; var worksheet = this.worksheet;
......
...@@ -10323,7 +10323,7 @@ ...@@ -10323,7 +10323,7 @@
range = t.model.getRange3( arn.r1, arn.c1, arn.r2, arn.c2 ); range = t.model.getRange3( arn.r1, arn.c1, arn.r2, arn.c2 );
switch ( val ) { switch ( val ) {
case c_oAscInsertOptions.InsertCellsAndShiftRight: case c_oAscInsertOptions.InsertCellsAndShiftRight:
isCheckChangeAutoFilter = t.model.autoFilters.isActiveCellsCrossHalfFTable( arn, c_oAscInsertOptions.InsertCellsAndShiftRight, prop ); isCheckChangeAutoFilter = t.af_checkInsDelCells( arn, c_oAscInsertOptions.InsertCellsAndShiftRight, prop );
if ( isCheckChangeAutoFilter === false ) { if ( isCheckChangeAutoFilter === false ) {
return; return;
} }
...@@ -10344,7 +10344,7 @@ ...@@ -10344,7 +10344,7 @@
this._isLockedCells( oChangeData.changedRange, null, onChangeWorksheetCallback ); this._isLockedCells( oChangeData.changedRange, null, onChangeWorksheetCallback );
break; break;
case c_oAscInsertOptions.InsertCellsAndShiftDown: case c_oAscInsertOptions.InsertCellsAndShiftDown:
isCheckChangeAutoFilter = t.model.autoFilters.isActiveCellsCrossHalfFTable( arn, c_oAscInsertOptions.InsertCellsAndShiftDown, prop ); isCheckChangeAutoFilter = t.af_checkInsDelCells( arn, c_oAscInsertOptions.InsertCellsAndShiftDown, prop );
if ( isCheckChangeAutoFilter === false ) { if ( isCheckChangeAutoFilter === false ) {
return; return;
} }
...@@ -10403,7 +10403,7 @@ ...@@ -10403,7 +10403,7 @@
range = t.model.getRange3( checkRange.r1, checkRange.c1, checkRange.r2, checkRange.c2 ); range = t.model.getRange3( checkRange.r1, checkRange.c1, checkRange.r2, checkRange.c2 );
switch ( val ) { switch ( val ) {
case c_oAscDeleteOptions.DeleteCellsAndShiftLeft: case c_oAscDeleteOptions.DeleteCellsAndShiftLeft:
isCheckChangeAutoFilter = t.model.autoFilters.isActiveCellsCrossHalfFTable( arn, c_oAscDeleteOptions.DeleteCellsAndShiftLeft, prop ); isCheckChangeAutoFilter = t.af_checkInsDelCells( arn, c_oAscDeleteOptions.DeleteCellsAndShiftLeft, prop );
if ( isCheckChangeAutoFilter === false ) { if ( isCheckChangeAutoFilter === false ) {
return; return;
} }
...@@ -10428,7 +10428,7 @@ ...@@ -10428,7 +10428,7 @@
this._isLockedCells( oChangeData.changedRange, null, onChangeWorksheetCallback ); this._isLockedCells( oChangeData.changedRange, null, onChangeWorksheetCallback );
break; break;
case c_oAscDeleteOptions.DeleteCellsAndShiftTop: case c_oAscDeleteOptions.DeleteCellsAndShiftTop:
isCheckChangeAutoFilter = t.model.autoFilters.isActiveCellsCrossHalfFTable( arn, c_oAscDeleteOptions.DeleteCellsAndShiftTop, prop ); isCheckChangeAutoFilter = t.af_checkInsDelCells( arn, c_oAscDeleteOptions.DeleteCellsAndShiftTop, prop );
if ( isCheckChangeAutoFilter === false ) { if ( isCheckChangeAutoFilter === false ) {
return; return;
} }
...@@ -12829,7 +12829,7 @@ ...@@ -12829,7 +12829,7 @@
{ {
var t = this; var t = this;
var ws = this.model; var ws = this.model;
var acitveRange = this.activeRange.clone(); var acitveRange = this.activeRange;
var tablePart = ws.autoFilters._getFilterByDisplayName(tableName); var tablePart = ws.autoFilters._getFilterByDisplayName(tableName);
...@@ -12843,37 +12843,51 @@ ...@@ -12843,37 +12843,51 @@
var startRow = this.activeRange.r1; var startRow = this.activeRange.r1;
var endRow = this.activeRange.r2; var endRow = this.activeRange.r2;
var newActiveRange = null; var newActiveRange = this.activeRange.clone();
var val; var val = null;
switch(optionType) switch(optionType)
{ {
case c_oAscInsertOptions.InsertTableRowAbove: case c_oAscInsertOptions.InsertTableRowAbove:
{ {
newActiveRange = new Asc.Range(tablePart.Ref.c1, startRow, tablePart.Ref.c2, endRow); newActiveRange.c1 = tablePart.Ref.c1;
newActiveRange.c2 = tablePart.Ref.c2;
val = c_oAscInsertOptions.InsertCellsAndShiftDown; val = c_oAscInsertOptions.InsertCellsAndShiftDown;
break; break;
} }
case c_oAscInsertOptions.InsertTableRowBelow: case c_oAscInsertOptions.InsertTableRowBelow:
{ {
newActiveRange = new Asc.Range(tablePart.Ref.c1, startRow - 1, tablePart.Ref.c2, endRow - 1); newActiveRange.c1 = tablePart.Ref.c1;
newActiveRange.c2 = tablePart.Ref.c2;
newActiveRange.r1 = startRow + (endRow - startRow) + 1;
newActiveRange.r2 = endRow + (endRow - startRow) + 1;
val = c_oAscInsertOptions.InsertCellsAndShiftDown; val = c_oAscInsertOptions.InsertCellsAndShiftDown;
break; break;
} }
case c_oAscInsertOptions.InsertTableColLeft: case c_oAscInsertOptions.InsertTableColLeft:
{ {
newActiveRange = new Asc.Range(startCol - 1, tablePart.Ref.r1, endCol - 1, tablePart.Ref.r2); newActiveRange.c1 = startCol - 1;
newActiveRange.c2 = endCol - 1;
newActiveRange.r1 = tablePart.Ref.r1;
newActiveRange.r2 = tablePart.Ref.r2;
val = c_oAscInsertOptions.InsertCellsAndShiftRight; val = c_oAscInsertOptions.InsertCellsAndShiftRight;
break; break;
} }
case c_oAscInsertOptions.InsertTableColRight: case c_oAscInsertOptions.InsertTableColRight:
{ {
newActiveRange = new Asc.Range(startCol, tablePart.Ref.r1, endCol, tablePart.Ref.r2); newActiveRange = new Asc.Range(startCol, tablePart.Ref.r1, endCol, tablePart.Ref.r2);
newActiveRange.r1 = tablePart.Ref.r1;
newActiveRange.r2 = tablePart.Ref.r2;
val = c_oAscInsertOptions.InsertCellsAndShiftRight; val = c_oAscInsertOptions.InsertCellsAndShiftRight;
break; break;
} }
} }
if(newActiveRange !== null) if(val !== null)
{ {
t.activeRange = newActiveRange; t.activeRange = newActiveRange;
t.changeWorksheet("insCell", val); t.changeWorksheet("insCell", val);
...@@ -12903,16 +12917,16 @@ ...@@ -12903,16 +12917,16 @@
var val; var val;
switch(optionType) switch(optionType)
{ {
case c_oAscInsertOptions.DeleteColumns: case c_oAscDeleteOptions.DeleteColumns:
{ {
newActiveRange = new Asc.Range(startCol, tablePart.Ref.r1, endCol, tablePart.Ref.r2); newActiveRange = new Asc.Range(startCol, tablePart.Ref.r1, endCol, tablePart.Ref.r2);
val = c_oAscInsertOptions.DeleteCellsAndShiftLeft; val = c_oAscDeleteOptions.DeleteCellsAndShiftLeft;
break; break;
} }
case c_oAscInsertOptions.DeleteRows: case c_oAscDeleteOptions.DeleteRows:
{ {
newActiveRange = new Asc.Range(tablePart.Ref.c1, startRow, tablePart.Ref.c2, endRow); newActiveRange = new Asc.Range(tablePart.Ref.c1, startRow, tablePart.Ref.c2, endRow);
val = c_oAscInsertOptions.DeleteCellsAndShiftTop; val = c_oAscDeleteOptions.DeleteCellsAndShiftTop;
break; break;
} }
case c_oAscInsertOptions.DeleteTable: case c_oAscInsertOptions.DeleteTable:
...@@ -12946,6 +12960,103 @@ ...@@ -12946,6 +12960,103 @@
//TODO тестовый вариант. нужно сделать методы и добавлять в историю //TODO тестовый вариант. нужно сделать методы и добавлять в историю
tablePart.DisplayName = newName; tablePart.DisplayName = newName;
}; };
WorksheetView.prototype.af_checkInsDelCells = function(activeRange, val, prop)
{
var t = this;
var ws = this.model;
var res = true;
var intersectionTableParts = ws.autoFilters.getTableIntersectionRange(activeRange);
var isPartTablePartsUnderRange = ws.autoFilters._isPartTablePartsUnderRange(activeRange);
var isPartTablePartsRightRange = ws.autoFilters.isPartTablePartsRightRange(activeRange);
var isOneTableIntersection = intersectionTableParts && intersectionTableParts.length === 1 ? intersectionTableParts[0] : null;
var checkInsCells = function()
{
switch(val)
{
case c_oAscInsertOptions.InsertCellsAndShiftDown:
{
//если внизу находится часть форматированной таблицы или это часть форматированной таблицы
if(isPartTablePartsUnderRange)
{
res = false;
}
else if(isOneTableIntersection !== null && !(isOneTableIntersection.Ref.c1 === activeRange.c1 && isOneTableIntersection.Ref.c2 === activeRange.c2))
{
res = false;
}
break;
}
case c_oAscInsertOptions.InsertCellsAndShiftRight:
{
//если справа находится часть форматированной таблицы или это часть форматированной таблицы
if(isPartTablePartsRightRange)
{
res = false;
}
break;
}
case c_oAscInsertOptions.InsertColumns:
{
break;
}
case c_oAscInsertOptions.InsertRows:
{
break;
}
}
};
var checkDelCells = function()
{
switch(val)
{
case c_oAscDeleteOptions.DeleteCellsAndShiftTop:
{
if(isPartTablePartsUnderRange)
{
res = false;
}
break;
}
case c_oAscDeleteOptions.DeleteCellsAndShiftLeft:
{
if(isPartTablePartsUnderRange)
{
res = false;
}
break;
}
case c_oAscDeleteOptions.DeleteColumns:
{
break;
}
case c_oAscDeleteOptions.DeleteRows:
{
break;
}
}
};
prop === "insCell" ? checkInsCells() : checkDelCells();
if(res === false)
{
ws.workbook.handlers.trigger("asc_onError", c_oAscError.ID.AutoFilterChangeFormatTableError, c_oAscError.Level.NoCritical);
}
return res;
};
/* /*
* Export * Export
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment