Commit dec78404 authored by GoshaZotov's avatar GoshaZotov

add function asc_convertTableToRange

parent 8c3bb72f
......@@ -600,7 +600,12 @@ var editor;
var ws = this.wb.getWorksheet();
return ws.af_changeTableRange(tableName, range);
};
spreadsheet_api.prototype.asc_convertTableToRange = function(tableName) {
var ws = this.wb.getWorksheet();
return ws.af_convertTableToRange(tableName);
};
spreadsheet_api.prototype.asc_getTablePictures = function (props)
{
return this.wb.getTablePictures(props);
......@@ -3481,6 +3486,7 @@ var editor;
prot["asc_deleteCellsInTable"] = prot.asc_deleteCellsInTable;
prot["asc_changeDisplayNameTable"] = prot.asc_changeDisplayNameTable;
prot["asc_changeTableRange"] = prot.asc_changeTableRange;
prot["asc_convertTableToRange"] = prot.asc_convertTableToRange;
prot["asc_getTablePictures"] = prot.asc_getTablePictures;
// Drawing objects interface
......
......@@ -3875,7 +3875,7 @@ function parserFormula( formula, parent, _ws ) {
parserFormula.prototype.setIsTable = function(isTable){
this.isTable = isTable;
};
parserFormula.prototype.notify = function(data) {
parserFormula.prototype.notify = function(data, bConvertTableFormulaToRef) {
var eventData = {notifyData: data, assemble: null, isRebuild: false, formula: this};
if (this.parent && this.parent.onFormulaEvent) {
var checkCanDo = this.parent.onFormulaEvent(AscCommon.c_oNotifyParentType.CanDo, eventData);
......@@ -3903,7 +3903,7 @@ function parserFormula( formula, parent, _ws ) {
eventData.isRebuild = false;
} else if (AscCommon.c_oNotifyType.ChangeDefName === data.type) {
if (!data.to) {
this.removeTableName(data.from);
this.removeTableName(data.from, bConvertTableFormulaToRef);
eventData.isRebuild = true;
} else if (data.from.name != data.to.name) {
this.changeDefName(data.from, data.to);
......@@ -4889,12 +4889,19 @@ parserFormula.prototype.calculate = function(opt_defName, opt_range) {
}
}
};
parserFormula.prototype.removeTableName = function(defName) {
parserFormula.prototype.removeTableName = function(defName, bConvertTableFormulaToRef) {
var i, elem;
for (i = 0; i < this.outStack.length; i++) {
elem = this.outStack[i];
if (elem.type == cElementType.table && elem.tableName == defName.name) {
this.outStack[i] = new cError(cErrorType.bad_reference);
if(bConvertTableFormulaToRef)
{
this.outStack[i] = this.outStack[i].toRef();
}
else
{
this.outStack[i] = new cError(cErrorType.bad_reference);
}
}
}
};
......
......@@ -763,6 +763,19 @@
var notifyData = {type: AscCommon.c_oNotifyType.ChangeDefName, from: defName.getUndoDefName(), to: null};
this._broadcastDefName(tableName, notifyData);
},
delTableName2: function(tableName) {
this.buildDependency();
var defName = this.getDefNameByName(tableName);
this.addToChangedDefName(defName);
var notifyData = {type: AscCommon.c_oNotifyType.ChangeDefName, from: defName.getUndoDefName(), to: null};
this._broadcastDefName(tableName, notifyData, true);
this._delDefName(tableName, null);
if (defName) {
defName.removeDependencies();
}
},
delColumnTable: function(tableName, deleted) {
this.buildDependency();
var notifyData = {type: AscCommon.c_oNotifyType.DelColumnTable, tableName: tableName, deleted: deleted};
......@@ -1026,12 +1039,12 @@
this.volatileListeners[i].notify(notifyData);
}
},
_broadcastDefName: function(name, notifyData) {
_broadcastDefName: function(name, notifyData, bConvertTableFormulaToRef) {
var nameIndex = getDefNameIndex(name);
var container = this.defNameListeners[nameIndex];
if (container) {
for (var listenerId in container.listeners) {
container.listeners[listenerId].notify(notifyData);
container.listeners[listenerId].notify(notifyData, bConvertTableFormulaToRef);
}
}
},
......@@ -4552,13 +4565,27 @@ Woorksheet.prototype.isApplyFilterBySheet = function(){
this.workbook.dependencyFormulas.changeTableName(oldTablePart.DisplayName, tablePart.DisplayName);
}
};
Woorksheet.prototype.deleteTablePart = function (index) {
var deleted = this.TableParts.splice(index, 1);
for (var delIndex = 0; delIndex < deleted.length; ++delIndex) {
var tablePart = deleted[delIndex];
this.workbook.dependencyFormulas.delTableName(tablePart.DisplayName);
Woorksheet.prototype.deleteTablePart = function (index, bConvertTableFormulaToRef) {
if(bConvertTableFormulaToRef)
{
//TODO скорее всего стоит убрать else
var tablePart = this.TableParts[index];
this.workbook.dependencyFormulas.delTableName2(tablePart.DisplayName);
tablePart.removeDependencies();
//delete table
this.TableParts.splice(index, 1);
}
else
{
var deleted = this.TableParts.splice(index, 1);
for (var delIndex = 0; delIndex < deleted.length; ++delIndex) {
var tablePart = deleted[delIndex];
this.workbook.dependencyFormulas.delTableName(tablePart.DisplayName);
tablePart.removeDependencies();
}
}
};
//-------------------------------------------------------------------------------------------------
/**
......
......@@ -902,7 +902,7 @@
this.sortColFilter(data.type, data.cellId, data.activeCells, null, data.displayName, data.color);
break;
case AscCH.historyitem_AutoFilter_Empty:
this.isEmptyAutoFilters(data.activeCells);
this.isEmptyAutoFilters(data.activeCells, null, null, data.val);
break;
case AscCH.historyitem_AutoFilter_ApplyMF:
this.applyAutoFilter(data.autoFiltersObject, data.activeCells);
......@@ -1160,7 +1160,7 @@
}
},
isEmptyAutoFilters: function(ar, insertType, exceptionArray)
isEmptyAutoFilters: function(ar, insertType, exceptionArray, bConvertTableFormulaToRef)
{
var worksheet = this.worksheet;
var activeCells = ar.clone();
......@@ -1195,7 +1195,7 @@
if(isTablePart) {
oRange.setTableStyle(null);
//write formulas history before filter history
worksheet.deleteTablePart(index);
worksheet.deleteTablePart(index, bConvertTableFormulaToRef);
} else
worksheet.AutoFilter = null;
......@@ -1205,7 +1205,7 @@
//заносим в историю
if(isTablePart){
t._addHistoryObj(oldFilter, AscCH.historyitem_AutoFilter_Empty, {activeCells: activeCells}, null, bbox);
t._addHistoryObj(oldFilter, AscCH.historyitem_AutoFilter_Empty, {activeCells: activeCells, val: bConvertTableFormulaToRef}, null, bbox);
}
else
t._addHistoryObj(oldFilter, AscCH.historyitem_AutoFilter_Empty, {activeCells: activeCells}, null, oldFilter.Ref);
......@@ -2689,6 +2689,37 @@
return range;
},
convertTableToRange: function(tableName)
{
History.Create_NewPoint();
History.StartTransaction();
var table = this._getFilterByDisplayName(tableName);
this._convertTableStyleToStyle(table);
this.isEmptyAutoFilters(table.Ref, null, null, true);
History.EndTransaction();
},
_convertTableStyleToStyle: function(table)
{
if(!table)
{
return;
}
for(var i = table.Ref.r1; i <= table.Ref.r2; i++)
{
for(var j = table.Ref.c1; j <= table.Ref.c2; j++)
{
var cell = this.worksheet._getCell(i, j);
var xfsFrom = cell.getCompiledStyle();
cell.setStyle(xfsFrom);
}
}
},
_clearRange: function(range, isClearText)
{
range.setTableStyle(null);
......
......@@ -13092,7 +13092,47 @@
formatTableInfo.isDeleteColumn = true;
formatTableInfo.isDeleteTable = true;
};
WorksheetView.prototype.af_convertTableToRange = function (tableName) {
var t = this;
var callback = function (isSuccess) {
if (false === isSuccess) {
return;
}
History.Create_NewPoint();
History.StartTransaction();
t.model.workbook.dependencyFormulas.lockRecal();
t.model.autoFilters.convertTableToRange(tableName);
t._onUpdateFormatTable(tableRange, false, true);
t.model.workbook.dependencyFormulas.unlockRecal();
History.EndTransaction();
};
var table = t.model.autoFilters._getFilterByDisplayName(tableName);
var tableRange = null !== table ? table.Ref : null;
var lockRange = tableRange;
var callBackLockedDefNames = function (isSuccess) {
if (false === isSuccess) {
return;
}
t._isLockedCells(lockRange, null, callback);
};
//лочим данный именованный диапазон
var defNameId = t.model.workbook.dependencyFormulas.getDefNameByName(tableName, t.model.getId());
defNameId = defNameId ? defNameId.getNodeId() : null;
t._isLockedDefNames(callBackLockedDefNames, defNameId);
};
WorksheetView.prototype.af_changeTableRange = function (tableName, range) {
var t = this;
range = AscCommonExcel.g_oRangeCache.getAscRange(range);
......
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