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

add functions for context menu(filter options)

parent ec0b939d
......@@ -552,6 +552,11 @@ var editor;
var ws = this.wb.getWorksheet();
ws.applyAutoFilter(autoFilterObject);
};
spreadsheet_api.prototype.asc_applyAutoFilterByType = function(autoFilterObject) {
var ws = this.wb.getWorksheet();
ws.applyAutoFilterByType(autoFilterObject);
};
spreadsheet_api.prototype.asc_sortColFilter = function(type, cellId, displayName, color) {
var ws = this.wb.getWorksheet();
......@@ -3331,6 +3336,7 @@ var editor;
prot["asc_addAutoFilter"] = prot.asc_addAutoFilter;
prot["asc_changeAutoFilter"] = prot.asc_changeAutoFilter;
prot["asc_applyAutoFilter"] = prot.asc_applyAutoFilter;
prot["asc_applyAutoFilterByType"] = prot.asc_applyAutoFilterByType;
prot["asc_sortColFilter"] = prot.asc_sortColFilter;
prot["asc_getAddFormatTableOptions"] = prot.asc_getAddFormatTableOptions;
prot["asc_clearFilter"] = prot.asc_clearFilter;
......
......@@ -452,8 +452,8 @@ var UndoRedoDataTypes = new function() {
case this.SheetPositions: return new UndoRedoData_SheetPositions();break;
case this.ClrScheme: return new UndoRedoData_ClrScheme();break;
case this.AutoFilter: return new UndoRedoData_AutoFilter(); break;
case this.AutoFiltersOptions: return new AscCommonExcel.AutoFiltersOptions(); break;
case this.AutoFilterObj: return new AscCommonExcel.AutoFilterObj(); break;
case this.AutoFiltersOptions: return new Asc.AutoFiltersOptions(); break;
case this.AutoFilterObj: return new Asc.AutoFilterObj(); break;
case this.CustomFilters: return new Asc.CustomFilters(); break;
case this.CustomFilter: return new Asc.CustomFilter(); break;
case this.ColorFilter: return new Asc.ColorFilter(); break;
......
......@@ -1793,6 +1793,33 @@
return false;
},
isStartRangeContainIntoTableOrFilter: function(range)
{
var res = null;
var worksheet = this.worksheet;
var tableParts = worksheet.TableParts;
var startRange = new Asc.Range(range.startCol, range.startRow, range.startCol, range.startRow);
for(var i = 0; i < tableParts.length; i++ )
{
if(startRange.intersection(tableParts[i].Ref))
{
res = i;
break;
}
}
//пересекается, но не равен фильтрованному диапазону. если равен - то фильтр превращается в таблицу
if(worksheet.AutoFilter && worksheet.AutoFilter.Ref && startRange.intersection(worksheet.AutoFilter.Ref))
{
res = -1;
}
return res;
},
unmergeTablesAfterMove: function(arnTo)
{
var worksheet = this.worksheet;
......@@ -4786,7 +4813,7 @@
window['AscCommonExcel'] = window['AscCommonExcel'] || {};
window["AscCommonExcel"].AutoFilters = AutoFilters;
window["AscCommonExcel"].AutoFiltersOptions = AutoFiltersOptions;
window["Asc"].AutoFiltersOptions = AutoFiltersOptions;
prot = AutoFiltersOptions.prototype;
prot["asc_setSortState"] = prot.asc_setSortState;
prot["asc_getSortState"] = prot.asc_getSortState;
......@@ -4799,7 +4826,7 @@
prot["asc_getColorsFont"] = prot.asc_getColorsFont;
prot["asc_getSortColor"] = prot.asc_getSortColor;
window["AscCommonExcel"].AutoFilterObj = AutoFilterObj;
window["Asc"].AutoFilterObj = AutoFilterObj;
prot = AutoFilterObj.prototype;
prot["asc_getType"] = prot.asc_getType;
prot["asc_setFilter"] = prot.asc_setFilter;
......
......@@ -12007,6 +12007,95 @@
}
};
this._isLockedAll( onChangeAutoFilterCallback );
};
WorksheetView.prototype.applyAutoFilterByType = function ( autoFilterObject ) {
var t = this;
var ar = t.activeRange.clone( true );
var isStartRangeIntoFilterOrTable = t.model.autoFilters.isStartRangeContainIntoTableOrFilter(ar);
var isApplyAutoFilter = null, iaAddAutoFilter = null, cellId, filterProps;
if(null !== isStartRangeIntoFilterOrTable)//into autofilter or format table
{
if(-1 === isStartRangeIntoFilterOrTable)//autofilter
{
var autoFilter = t.model.AutoFilter;
var colId = ar.c1 - autoFilter.Ref.c1;
filterProps = {id: null, colId: colId};
isApplyAutoFilter = true;
}
else if(t.model.TableParts[isStartRangeIntoFilterOrTable])//format table
{
var formatTable = t.model.TableParts[isStartRangeIntoFilterOrTable];
if(formatTable.AutoFilter)
{
var autoFilter = t.model.AutoFilter;
var colId = ar.c1 - autoFilter.Ref.c1;
filterProps = {id: null, colId: colId};
isApplyAutoFilter = true;
}
else
{
}
}
}
else//without filter
{
}
var onChangeAutoFilterCallback = function ( isSuccess ) {
if ( false === isSuccess ) {
return;
}
History.Create_NewPoint();
History.StartTransaction();
if(null !== isAddAutoFilter)
{
t.model.autoFilters.addAutoFilter(null, ar, addFormatTableOptionsObj);
}
if(null !== isApplyAutoFilter)
{
var autoFilterObject = t.af_setDialogProp(filterProps, true);
var applyFilterProps = t.model.autoFilters.applyAutoFilter( autoFilterObject, ar );
var rowChange = applyFilterProps.rowChange;
var rangeOldFilter = applyFilterProps.rangeOldFilter;
if(null !== rangeOldFilter && !t.model.workbook.bUndoChanges && !t.model.workbook.bRedoChanges)
{
t._onUpdateFormatTable(rangeOldFilter, false, true);
}
if ( null !== rowChange ) {
t.objectRender.updateSizeDrawingObjects( {target: c_oTargetType.RowResize, row: rowChange} );
}
}
History.EndTransaction();
};
if(null !== isAddAutoFilter)//do not add autoFilter
{
this._isLockedAll( onChangeAutoFilterCallback );
}
else//add autofilter + apply
{
if ( t._checkAddAutoFilter( ar, styleName, addFormatTableOptionsObj ) === true ) {
this._isLockedAll( onChangeAutoFilterCallback );
this._isLockedDefNames( null, null );
}
}
};
WorksheetView.prototype.sortColFilter = function ( type, cellId, displayName, color ) {
......@@ -12622,7 +12711,7 @@
return result;
};
WorksheetView.prototype.af_setDialogProp = function(filterProp)
WorksheetView.prototype.af_setDialogProp = function(filterProp, isReturnProps)
{
var ws = this.model;
......@@ -12651,7 +12740,7 @@
var cellId = ws.autoFilters._rangeToId(rangeButton);
//get filter object
var filterObj = new AscCommonExcel.AutoFilterObj();
var filterObj = new Asc.AutoFilterObj();
if(filters && filters.ColorFilter)
{
filterObj.type = c_oAscAutoFilterTypes.ColorFilter;
......@@ -12730,7 +12819,7 @@
//set menu object
var autoFilterObject = new AscCommonExcel.AutoFiltersOptions();
var autoFilterObject = new Asc.AutoFiltersOptions();
autoFilterObject.asc_setSortState(sortVal);
autoFilterObject.asc_setCellId(cellId);
......@@ -12747,8 +12836,14 @@
autoFilterObject.asc_setColorsFill(filterTypes.colors);
autoFilterObject.asc_setColorsFont(filterTypes.fontColors);
this.handlers.trigger("setAutoFiltersDialog", autoFilterObject);
if(isReturnProps)
{
return autoFilterObject;
}
else
{
this.handlers.trigger("setAutoFiltersDialog", autoFilterObject);
}
};
WorksheetView.prototype.af_getFilterTypes = function(columnRange)
......
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