Commit 6c12b72e authored by GoshaZotov's avatar GoshaZotov Committed by Alexander.Trofimov

different changes for format tables

parent efac5340
......@@ -661,9 +661,9 @@ var editor;
return ws.af_changeSelectionFormatTable(tableName, optionType);
};
spreadsheet_api.prototype.asc_changeFormatTableInfo = function(tableName, optionType) {
spreadsheet_api.prototype.asc_changeFormatTableInfo = function(tableName, optionType, val) {
var ws = this.wb.getWorksheet();
return ws.af_changeFormatTableInfo(tableName, optionType);
return ws.af_changeFormatTableInfo(tableName, optionType, val);
};
spreadsheet_api.prototype.asc_insertCellsInTable = function(tableName, optionType) {
......
......@@ -205,7 +205,7 @@
asc_getIsInsertRowAbove: function () { return this.isInsertRowAbove; },
asc_getIsInsertRowBelow: function () { return this.isInsertRowBelow; },
asc_getIsInsertColumnLeft: function () { return this.isInsertRowLeft; },
asc_getIsInsertColumnLeft: function () { return this.isInsertColumnLeft; },
asc_getIsInsertColumnRight: function () { return this.isInsertColumnRight; },
asc_getIsDeleteRow: function () { return this.isDeleteRow; },
asc_getIsDeleteColumn: function () { return this.isDeleteColumn; },
......
......@@ -103,6 +103,7 @@ var historyitem_AutoFilter_Delete = 8;
var historyitem_AutoFilter_ChangeTableStyle = 9;
var historyitem_AutoFilter_Change = 10;
var historyitem_AutoFilter_CleanFormat = 11;
var historyitem_AutoFilter_ChangeTableInfo = 12;
function CHistory(workbook)
......
......@@ -1706,7 +1706,8 @@ var g_oUndoRedoData_AutoFilterProperties = {
moveFrom : 6,
moveTo : 7,
bWithoutFilter : 8,
displayName : 9
displayName : 9,
val : 10
};
function UndoRedoData_AutoFilter() {
this.Properties = g_oUndoRedoData_AutoFilterProperties;
......@@ -1723,6 +1724,7 @@ function UndoRedoData_AutoFilter() {
this.moveTo = null;
this.bWithoutFilter = null;
this.displayName = null;
this.val = null;
}
UndoRedoData_AutoFilter.prototype = {
getType : function ()
......@@ -1747,6 +1749,7 @@ UndoRedoData_AutoFilter.prototype = {
case this.Properties.moveTo: return new UndoRedoData_BBox(this.moveTo); break;
case this.Properties.bWithoutFilter: return this.bWithoutFilter; break;
case this.Properties.displayName: return this.displayName; break;
case this.Properties.val: return this.val; break;
}
return null;
......@@ -1765,6 +1768,7 @@ UndoRedoData_AutoFilter.prototype = {
case this.Properties.moveTo: this.moveTo = value;break;
case this.Properties.bWithoutFilter: this.bWithoutFilter = value;break;
case this.Properties.displayName: this.displayName = value;break;
case this.Properties.val: this.val = value;break;
}
return null;
},
......
......@@ -4749,6 +4749,39 @@ TablePart.prototype.getTableNameColumnByIndex = function(index)
return res;
};
TablePart.prototype.showButton = function(val)
{
if(val === false)
{
if(!this.AutoFilter)
{
this.AutoFilter = new AutoFilter();
this.AutoFilter.Ref = this.Ref;
}
this.AutoFilter.showButton(val);
}
else
{
if(this.AutoFilter && this.AutoFilter.FilterColumns && this.AutoFilter.FilterColumns.length)
{
this.AutoFilter.showButton(val);
}
}
};
TablePart.prototype.isShowButton = function()
{
var res = true;
if(this.AutoFilter)
{
res = this.AutoFilter.isShowButton();
}
return res;
};
/** @constructor */
function AutoFilter() {
this.Ref = null;
......@@ -4851,6 +4884,55 @@ AutoFilter.prototype.cleanFilters = function() {
}
};
AutoFilter.prototype.showButton = function(val) {
if(val === false)
{
if(this.FilterColumns === null)
{
this.FilterColumns = [];
}
var columnsLength = this.Ref.c2 - this.Ref.c1 + 1;
for(var i = 0; i < columnsLength; i++)
{
this.FilterColumns[i] = new FilterColumn();
this.FilterColumns[i].ColId = i;
this.FilterColumns[i].ShowButton = false;
}
}
else
{
if(this.FilterColumns && this.FilterColumns.length)
{
for(var i = 0; i < this.FilterColumns.length; i++)
{
this.FilterColumns[i].ShowButton = true;
}
}
}
};
AutoFilter.prototype.isShowButton = function()
{
var res = true;
if(this.FilterColumns && this.FilterColumns.length)
{
for(var i = 0; i < this.FilterColumns.length; i++)
{
if(this.FilterColumns[i].ShowButton === false)
{
res = false;
break;
}
}
}
return res;
};
function FilterColumns() {
this.ColId = null;
this.CustomFiltersObj = null;
......
......@@ -724,6 +724,9 @@
}
}
break;
case historyitem_AutoFilter_ChangeTableInfo:
this.changeFormatTableInfo(data.displayName, data.type, data.val);
break;
}
History.TurnOn();
},
......@@ -765,7 +768,7 @@
else
worksheet.AutoFilter = cloneData;
}
else if(type === historyitem_AutoFilter_Change)//добавление/удаление строк/столбцов
else if(type === historyitem_AutoFilter_Change || type === historyitem_AutoFilter_ChangeTableInfo)//добавление/удаление строк/столбцов
{
if(worksheet.AutoFilter && cloneData.newFilterRef.isEqual(worksheet.AutoFilter.Ref))
worksheet.AutoFilter = cloneData.oldFilter.clone(null);
......@@ -2078,8 +2081,24 @@
return res;
},
changeFormatTableInfo: function(tablePart, optionType)
changeFormatTableInfo: function(tableName, optionType, val)
{
var worksheet = this.worksheet;
var isSetValue = false;
var tablePart = this._getFilterByDisplayName(tableName);
if(!tablePart)
{
return false;
}
History.Create_NewPoint();
History.StartTransaction();
//History.TurnOff();
var oldFilter = tablePart.clone(null);
switch(optionType)
{
case c_oAscChangeTableStyleInfo.columnBanded:
......@@ -2103,26 +2122,118 @@
break;
}
case c_oAscChangeTableStyleInfo.rowTotal:
{
tablePart.TotalsRowCount = tablePart.TotalsRowCount === null ? 1 : null;
{
if(val === false)//снимаем галку - удаляем строку итогов
{
var clearRange = new Range(worksheet, tablePart.Ref.r2, tablePart.Ref.c1, tablePart.Ref.r2, tablePart.Ref.c2);
this._clearRange(clearRange, true);
tablePart.changeRef(null, -1);
tablePart.TotalsRowCount = tablePart.TotalsRowCount === null ? 1 : null;
}
else
{
//если сверху пустая строка, то просто увеличиваем диапазон и меняем флаг
var rangeUpTable = new Asc.Range(tablePart.Ref.c1, tablePart.Ref.r2 + 1, tablePart.Ref.c2, tablePart.Ref.r2 + 1);
if(this._isEmptyCurrentRange(rangeUpTable) && this.searchRangeInTableParts(rangeUpTable) === -1)
{
tablePart.changeRef(null, 1);
isSetValue = true;
tablePart.TotalsRowCount = tablePart.TotalsRowCount === null ? 1 : null;
}
else
{
worksheet.getRange3(tablePart.Ref.r2 + 1, tablePart.Ref.c1, tablePart.Ref.r2 + 1, tablePart.Ref.c2).addCellsShiftBottom();
tablePart.changeRef(null, 1);
isSetValue = true;
tablePart.TotalsRowCount = tablePart.TotalsRowCount === null ? 1 : null;
}
}
break;
}
case c_oAscChangeTableStyleInfo.rowHeader:
{
tablePart.HeaderRowCount = tablePart.HeaderRowCount === null ? 0 : null;
if(val === false)//снимаем галку
{
var clearRange = new Range(worksheet, tablePart.Ref.r1, tablePart.Ref.c1, tablePart.Ref.r1, tablePart.Ref.c2);
this._clearRange(clearRange, true);
tablePart.changeRef(null, 1, true);
tablePart.HeaderRowCount = tablePart.HeaderRowCount === null ? 0 : null;
}
else
{
//если сверху пустая строка, то просто увеличиваем диапазон и меняем флаг
var rangeUpTable = new Asc.Range(tablePart.Ref.c1, tablePart.Ref.r1 - 1, tablePart.Ref.c2, tablePart.Ref.r1 - 1);
if(this._isEmptyCurrentRange(rangeUpTable) && this.searchRangeInTableParts(rangeUpTable) === -1)
{
tablePart.changeRef(null, -1, true);
isSetValue = true;
tablePart.HeaderRowCount = tablePart.HeaderRowCount === null ? 0 : null;
}
else
{
worksheet.getRange3(tablePart.Ref.r2, tablePart.Ref.c1, tablePart.Ref.r2, tablePart.Ref.c2).addCellsShiftBottom();
worksheet._moveRange(tablePart.Ref, new Asc.Range(tablePart.Ref.c1, tablePart.Ref.r1 + 1, tablePart.Ref.c2, tablePart.Ref.r2 + 1));
tablePart.changeRef(null, -1, true);
isSetValue = true;
tablePart.HeaderRowCount = tablePart.HeaderRowCount === null ? 0 : null;
}
}
break;
}
case c_oAscChangeTableStyleInfo.filterButton:
{
tablePart.TableStyleInfo.ShowRowStripes = !tablePart.TableStyleInfo.ShowRowStripes;
tablePart.showButton(val);
break;
}
}
this._cleanStyleTable(tablePart.Ref);
this._setColorStyleTable(tablePart.Ref, tablePart);
//History.TurnOn();
//TODO add to history
this._addHistoryObj({oldFilter: oldFilter, newFilterRef: tablePart.Ref.clone()}, historyitem_AutoFilter_ChangeTableInfo,
{activeCells: null, type: optionType, val: val, displayName: tableName});
this._cleanStyleTable(tablePart.Ref);
this._setColorStyleTable(tablePart.Ref, tablePart, null, isSetValue);
History.EndTransaction();
},
_clearRange: function(range, isClearText)
{
range.setTableStyle(null);
if(isClearText)
{
History.TurnOff();
range.cleanText();
History.TurnOn();
}
},
_isEmptyCurrentRange: function(range)
{
var worksheet = this.worksheet;
for(var n = range.r1; n <= range.r2; n++)
{
for(var k = range.c1; k <= range.c2; k++)
{
var cell = worksheet.getCell3(n, k, n, k);
if(cell.getValueWithoutFormat() != '')
return false;
}
}
return true;
},
//TODO избавиться от split, передавать cellId и tableName
......@@ -2237,7 +2348,7 @@
if(redoObject)
{
oHistoryObject.activeCells = redoObject.activeCells.clone(); // ToDo Слишком много клонирования, это долгая операция
oHistoryObject.activeCells = redoObject.activeCells ? redoObject.activeCells.clone() : null; // ToDo Слишком много клонирования, это долгая операция
oHistoryObject.styleName = redoObject.styleName;
oHistoryObject.type = redoObject.type;
oHistoryObject.cellId = redoObject.cellId;
......@@ -2247,6 +2358,7 @@
oHistoryObject.moveTo = redoObject.arnTo;
oHistoryObject.bWithoutFilter = bWithoutFilter ? bWithoutFilter : false;
oHistoryObject.displayName = redoObject.displayName;
oHistoryObject.val = redoObject.val;
}
else
{
......
......@@ -7313,7 +7313,7 @@
cell_info.formatTableInfo.lastRow = curTablePart.TotalsRowCount !== null ? true : false;
cell_info.formatTableInfo.firstRow = curTablePart.HeaderRowCount === null ? true : false;
cell_info.formatTableInfo.tableRange = curTablePart.Ref.getAbsName();
//cell_info.formatTableInfo.filterButton = curTablePart.HeaderRowCount !== null ? true : false;
cell_info.formatTableInfo.filterButton = curTablePart.isShowButton();
var checkDisableProps = this.af_checkDisableProps(curTablePart)
......@@ -12363,7 +12363,7 @@
{
for(var i = 0; i < aWs.TableParts.length; i++)
{
if(aWs.TableParts[i].AutoFilter)
if(aWs.TableParts[i].AutoFilter && aWs.TableParts[i].HeaderRowCount !== 0)
drawCurrentFilterButton(aWs.TableParts[i].AutoFilter, true);
}
}
......@@ -12800,7 +12800,7 @@
t.setSelection(new Asc.Range(startCol, startRow, endCol, endRow));
};
WorksheetView.prototype.af_changeFormatTableInfo = function(tableName, optionType)
WorksheetView.prototype.af_changeFormatTableInfo = function(tableName, optionType, val)
{
var tablePart = this.model.autoFilters._getFilterByDisplayName(tableName);
......@@ -12812,7 +12812,7 @@
var isChangeTableInfo = this.af_checkChangeTableInfo(tablePart, optionType);
if(isChangeTableInfo !== false)
{
this.model.autoFilters.changeFormatTableInfo(tablePart, optionType);
this.model.autoFilters.changeFormatTableInfo(tableName, optionType, val);
this._onUpdateFormatTable(isChangeTableInfo, false, true);
//TODO добавить перерисовку таблицы и перерисовку шаблонов
......@@ -12821,17 +12821,31 @@
WorksheetView.prototype.af_checkChangeTableInfo = function(tablePart, optionType)
{
var updateRange = tablePart.Ref;
var res = tablePart.Ref;
var ws = this.model;
if(optionType === c_oAscChangeTableStyleInfo.rowHeader && tablePart.HeaderRowCount !== null)//add header row
{
var rangeUpTable = new Asc.Range(tablePart.Ref.c1, tablePart.Ref.r1 - 1, tablePart.Ref.c2, tablePart.Ref.r1 - 1);
if(this.model.autoFilters._isEmptyCurrentRange(rangeUpTable) === false && this.model.autoFilters._isPartTablePartsUnderRange(tablePart.Ref) === true)
{
ws.workbook.handlers.trigger("asc_onError", c_oAscError.ID.AutoFilterMoveToHiddenRangeError, c_oAscError.Level.NoCritical);
res = false;
}
}
else if(optionType === c_oAscChangeTableStyleInfo.rowTotal && tablePart.TotalsRowCount !== null)//add total row
else if(optionType === c_oAscChangeTableStyleInfo.rowTotal && tablePart.TotalsRowCount === null)//add total row
{
var rangeUpTable = new Asc.Range(tablePart.Ref.c1, tablePart.Ref.r2 + 1, tablePart.Ref.c2, tablePart.Ref.r2 + 1);
if(this.model.autoFilters._isEmptyCurrentRange(rangeUpTable) === false && this.model.autoFilters._isPartTablePartsUnderRange(tablePart.Ref) === true)
{
ws.workbook.handlers.trigger("asc_onError", c_oAscError.ID.AutoFilterMoveToHiddenRangeError, c_oAscError.Level.NoCritical);
res = false;
}
}
return updateRange;
return res;
};
WorksheetView.prototype.af_insertCellsInTable = function(tableName, optionType)
......@@ -13103,8 +13117,7 @@
insertColumnLeft = !!(refTableContainsActiveRange || (acitveRange.c2 > refTable.c2 && acitveRange.r1 >= refTable.r1 && acitveRange.r2 <= refTable.r2 && acitveRange.c1 >= refTable.c1));
//если внутри находится вся активная область(кроме строки заголовков) или если выходит активная область за границу снизу
insertRowAbove = !!(((acitveRange.r1 > refTable.c1 && tablePart.HeaderRowCount === null) || (acitveRange.r1 >= refTable.c1 && tablePart.HeaderRowCount !== null)) && (refTableContainsActiveRange || (acitveRange.r2 > refTable.r2 && acitveRange.c1 >= refTable.c1 && acitveRange.c2 <= refTable.c2 && acitveRange.r1 >= refTable.r1)));
insertRowAbove = !!(((acitveRange.r1 > refTable.r1 && tablePart.HeaderRowCount === null) || (acitveRange.r1 >= refTable.r1 && tablePart.HeaderRowCount !== null)) && (refTableContainsActiveRange || (acitveRange.r2 > refTable.r2 && acitveRange.c1 >= refTable.c1 && acitveRange.c2 <= refTable.c2 && acitveRange.r1 >= refTable.r1)));
return {insertRowAbove: insertRowAbove, insertRowBelow: insertRowBelow, insertColumnLeft: insertColumnLeft, insertColumnRight: insertColumnRight, deleteRow: deleteRow, deleteColumn: deleteColumn, deleteTable: deleteTable};
......
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