Commit 13bc0db1 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Добавил PopUpSelector для подстановки формул и для выбора списка для ячейки.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55363 954022d7-b5bf-4e40-9824-e11837661b57
parent 41b8bec7
...@@ -93,6 +93,7 @@ ...@@ -93,6 +93,7 @@
<script type="text/javascript" src="../Common/scroll.js"></script> <script type="text/javascript" src="../Common/scroll.js"></script>
<script type="text/javascript" src="view/PopUpSelector.js"></script>
<script type="text/javascript" src="view/StringRender.js"></script> <script type="text/javascript" src="view/StringRender.js"></script>
<script type="text/javascript" src="view/CellTextRender.js"></script> <script type="text/javascript" src="view/CellTextRender.js"></script>
<script type="text/javascript" src="view/CellEditorView.js"></script> <script type="text/javascript" src="view/CellEditorView.js"></script>
......
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
<script type="text/javascript" src="../Common/scroll.js"></script> <script type="text/javascript" src="../Common/scroll.js"></script>
<script type="text/javascript" src="view/mobileTouch.js"></script> <script type="text/javascript" src="view/mobileTouch.js"></script>
<script type="text/javascript" src="view/iscroll.js"></script> <script type="text/javascript" src="view/iscroll.js"></script>
<script type="text/javascript" src="view/PopUpSelector.js"></script>
<script type="text/javascript" src="view/StringRender.js"></script> <script type="text/javascript" src="view/StringRender.js"></script>
<script type="text/javascript" src="view/CellTextRender.js"></script> <script type="text/javascript" src="view/CellTextRender.js"></script>
<script type="text/javascript" src="view/CellEditorView.js"></script> <script type="text/javascript" src="view/CellEditorView.js"></script>
......
...@@ -134,3 +134,26 @@ ...@@ -134,3 +134,26 @@
width: 1px; width: 1px;
height: 11pt; height: 11pt;
} }
#apiPopUpSelector {
z-index: 3000;
height: auto;
background-color: #FFF;
border: 1px solid Grey;
position: absolute;
cursor: default;
font-size: 12px;
padding: 4px;
display: none;
}
#apiPopUpList {
margin: 0 10px 0 0;
padding: 0;
list-style: none;
}
#apiPopUpList li {
max-width: 500px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
\ No newline at end of file
...@@ -173,6 +173,7 @@ ...@@ -173,6 +173,7 @@
<script type="text/javascript" src="../../../../OfficeWeb/Excel/model/UndoRedo.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Excel/model/UndoRedo.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Common/scroll.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Common/scroll.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/PopUpSelector.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/StringRender.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Excel/view/StringRender.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/CellTextRender.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Excel/view/CellTextRender.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/CellEditorView.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Excel/view/CellEditorView.js"></script>
......
...@@ -133,6 +133,7 @@ ...@@ -133,6 +133,7 @@
<script type="text/javascript" src="../../../../OfficeWeb/Common/scroll.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Common/scroll.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/mobileTouch.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Excel/view/mobileTouch.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/iscroll.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Excel/view/iscroll.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/PopUpSelector.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/StringRender.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Excel/view/StringRender.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/CellTextRender.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Excel/view/CellTextRender.js"></script>
<script type="text/javascript" src="../../../../OfficeWeb/Excel/view/CellEditorView.js"></script> <script type="text/javascript" src="../../../../OfficeWeb/Excel/view/CellEditorView.js"></script>
......
...@@ -1617,151 +1617,6 @@ ...@@ -1617,151 +1617,6 @@
} }
return this.objAutoComplete[str] = arrResult; return this.objAutoComplete[str] = arrResult;
}, },
_getFormulaList: function(str) {
var _this = this;
var text = _this.input.value + str;
if ( text.indexOf("=") == 0 ) {
var pattern = text.substring(1);
var api = asc["editor"];
if ( api.wb && pattern.length ) {
var ws = api.wb.getWorksheet();
if ( ws ) {
var oFormulaList = {};
var editedCol = ws.getSelectedColumnIndex();
var editedRow = ws.getSelectedRowIndex() + 1;
var fvr = ws.getFirstVisibleRow();
var fvc = ws.getFirstVisibleCol();
oFormulaList.col = editedCol;
oFormulaList.row = editedRow;
oFormulaList.y = ws.getCellTop(editedRow, 0) - (fvr ? ws.getCellTop(fvr, 0) - ws.getCellTop(0, 0) : 0);
oFormulaList.x = ws.getCellLeft(editedCol, 0) - (fvc ? ws.getCellLeft(fvc, 0) - ws.getCellLeft(0, 0) : 0);
oFormulaList.list = [];
var fullFormulaList = api.asc_getFormulasInfo();
for ( var i = 0; i < fullFormulaList.length; i++ ) {
var group = fullFormulaList[i];
for ( var j = 0; j < group.formulasArray.length; j++ ) {
if ( group.formulasArray[j].name.indexOf(pattern/*.toUpperCase()*/) == 0 ) {
oFormulaList.list.push(group.formulasArray[j]);
}
}
}
return oFormulaList.list.length ? oFormulaList : null;
}
}
}
return null;
},
_showFormulaSelector: function(formulaList) {
if ( formulaList ) {
var _this = this;
var api = asc["editor"];
var ws = api.wb.getWorksheet();
var canvasWidget = $("#" + api.HtmlElementName);
var selector = document.createElement("div");
selector.id = "formulaSelector";
selector.style["zIndex"] = "3000";
selector.style["width"] = "100px";
selector.style["height"] = "auto";
selector.style["backgroundColor"] = "#FFFFFF";
selector.style["border"] = "1px solid Grey";
selector.style["top"] = (formulaList.y + canvasWidget.offset().top) + "px";
selector.style["left"] = (formulaList.x + canvasWidget.offset().left) + "px";
selector.style["position"] = "absolute";
selector.style["cursor"] = "default";
selector.style["font-size"] = "12px";
selector.style["padding"] = "4px";
selector.style["fontSize"] = "12px";
document.body.appendChild(selector);
// Selection hack
var clearSelection = function() {
if (document.selection && document.selection.empty) {
document.selection.empty();
}
else if (window.getSelection) {
var sel = window.getSelection();
sel.removeAllRanges();
}
}
// TODO: В Mozilla избавиться от селекта текста при dblclick
var combo = document.createElement("ul");
combo.id = "formulaList";
combo.style["margin"] = 0;
combo.style["padding"] = 0;
combo.style["listStyle"] = "none";
combo.style["listImage"] = "none";
selector.appendChild(combo);
for ( var i = 0; i < formulaList.list.length; i++ ) {
var item = document.createElement("li");
if ( item.textContent != undefined )
item.textContent = formulaList.list[i].name;
else
item.innerText = formulaList.list[i].name;
item.setAttribute("title", formulaList.list[i].arg);
item.onmouseover = function(e) {
var nodes = combo.childNodes;
for ( var i = 0; i < nodes.length; i++ ) {
if ( nodes[i].style["backgroundColor"] != "" ) {
nodes[i].style["backgroundColor"] = "";
}
}
this.style["backgroundColor"] = _this.formulaSelectorColor;
}
item.onmouseout = function(e) {
this.style["backgroundColor"] = "";
}
item.ondblclick = function(e) {
if ( e && (e.button === 0) ) {
var formulaName = this.innerText || this.textContent;
var insertText = formulaName.substring(_this.input.value.length - 1) + "(";
_this._addChars(insertText);
_this._removeFormulaSelector();
}
}
combo.appendChild(item);
}
// Calculate scroll
var lvr = ws.getLastVisibleRow();
var lvc = ws.getLastVisibleCol();
var getBottomPoint = function() {
var pointPx = formulaList.y + selector.offsetHeight;
return pointPx * asc.getCvtRatio( 0, 1, ws.drawingCtx.getPPIY() );
}
var getRightPoint = function() {
var pointPx = formulaList.x + selector.offsetWidth;
return pointPx * asc.getCvtRatio( 0, 1, ws.drawingCtx.getPPIX() );
}
// Height
var row = ws._findRowUnderCursor(getBottomPoint(), true);
while ( !row ) {
ws.expandRowsOnScroll(true);
row = ws._findRowUnderCursor(getBottomPoint(), true);
}
if ( row.row - lvr > 0 ) {
ws.scrollVertical(row.row - lvr + 1, _this);
//ws.handlers.trigger("reinitializeScrollY");
}
// Width
var col = ws._findColUnderCursor(getRightPoint(), true);
while ( !col ) {
ws.expandColsOnScroll(true);
col = ws._findColUnderCursor(getRightPoint(), true);
}
if ( col.col - lvc > 0 ) {
ws.scrollHorizontal(col.col - lvc + 1, _this);
//ws.handlers.trigger("reinitializeScrollX");
}
}
},
_removeFormulaSelector: function() { _removeFormulaSelector: function() {
var selector = document.getElementById("formulaSelector"); var selector = document.getElementById("formulaSelector");
...@@ -2139,21 +1994,6 @@ ...@@ -2139,21 +1994,6 @@
} }
} }
} }
//t._removeFormulaSelector();
//var oFormulaList = t._getFormulaList(oNewChar);
//if (oFormulaList) {
// t._showFormulaSelector(oFormulaList);
//}
/*if ( oAutoString ) {
t._addChars(oAutoString.text);
t.selectionBegin = oAutoString.selectionBegin;
t.selectionEnd = oAutoString.selectionEnd;
t._drawSelection();
}
else
t._addChars(String.fromCharCode(event.which));*/
return t.isTopLineActive ? true : false; // prevent event bubbling return t.isTopLineActive ? true : false; // prevent event bubbling
}, },
......
...@@ -1297,10 +1297,8 @@ ...@@ -1297,10 +1297,8 @@
this.isMoveResizeRange = true; this.isMoveResizeRange = true;
t._moveResizeRangeHandle(event, t.targetInfo); t._moveResizeRangeHandle(event, t.targetInfo);
return; return;
} } else if (false === t.handlers.trigger("canEnterCellRange")) {
// для определения рэнджа под курсором и активизации его для WorksheetView // для определения рэнджа под курсором и активизации его для WorksheetView
else if (false === t.handlers.trigger("canEnterCellRange")) {
t.handlers.trigger("removeFormulaSelector");
if (!t.handlers.trigger("stopCellEditing")) {return;} if (!t.handlers.trigger("stopCellEditing")) {return;}
} }
} }
......
"use strict";
/* PopUpSelector.js
*
* Author: Alexander.Trofimov@avsmedia.net
* Date: April 7, 2014
*/
( /**
* @param {jQuery} $
* @param {Window} window
* @param {undefined} undefined
*/
function($, window, undefined) {
function PopUpSelector(element) {
this.element = element;
this.selector = null;
this.selectorStyle = null;
this.selectorList = null;
this._init();
return this;
}
PopUpSelector.prototype._init = function () {
if (null != this.element) {
this.selector = document.createElement("div");
this.selectorStyle = this.selector.style;
this.selector.id = "apiPopUpSelector";
this.selector.innerHTML = '<div style="max-height:210px;overflow-y:auto"><ul id="apiPopUpList"></ul></div>';
this.element.appendChild(this.selector);
this.selectorList = document.getElementById("apiPopUpList");
}
};
PopUpSelector.prototype.show = function (isFormula, arrItems, cellRect) {
this._clearList();
this.setPosition(cellRect);
this.selectorStyle.display = "block";
var item;
for (var i = 0; i < arrItems.length; ++i) {
item = document.createElement("li");
if (isFormula) {
item.innerHTML = arrItems[i].name;
item.setAttribute("title", arrItems[i].arg);
} else
item.innerHTML = arrItems[i];
/*item.onmouseover = function(e) {
var nodes = combo.childNodes;
for ( var i = 0; i < nodes.length; i++ ) {
if ( nodes[i].style["backgroundColor"] != "" ) {
nodes[i].style["backgroundColor"] = "";
}
}
this.style["backgroundColor"] = _this.formulaSelectorColor;
}
item.onmouseout = function(e) {
this.style["backgroundColor"] = "";
}
item.ondblclick = function(e) {
if ( e && (e.button === 0) ) {
var formulaName = this.innerText || this.textContent;
var insertText = formulaName.substring(_this.input.value.length - 1) + "(";
_this._addChars(insertText);
_this._removeFormulaSelector();
}
}*/
this.selectorList.appendChild(item);
}
// Selection hack
/*var clearSelection = function() {
if (document.selection && document.selection.empty) {
document.selection.empty();
}
else if (window.getSelection) {
var sel = window.getSelection();
sel.removeAllRanges();
}
}*/
// TODO: В Mozilla избавиться от селекта текста при dblclick
};
PopUpSelector.prototype.hide = function () {
this.selectorStyle.display = "none";
this._clearList();
};
PopUpSelector.prototype.setPosition = function (cellRect) {
this.selectorStyle["left"] = (cellRect.asc_getX() + 10) + "px";
this.selectorStyle["top"] = (cellRect.asc_getY() + cellRect.asc_getHeight()) + "px";
};
PopUpSelector.prototype._clearList = function () {
this.selectorList.innerHTML = "";
};
/*
* Export
* -----------------------------------------------------------------------------
*/
window["Asc"].PopUpSelector = PopUpSelector;
}
)(jQuery, window);
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
var asc_typeof = asc.typeOf; var asc_typeof = asc.typeOf;
var asc_FP = asc.FontProperties; var asc_FP = asc.FontProperties;
var asc_CE = asc.CellEditor; var asc_CE = asc.CellEditor;
var asc_PS = asc.PopUpSelector;
var asc_WSV = asc.WorksheetView; var asc_WSV = asc.WorksheetView;
var asc_CB = asc.Clipboard; var asc_CB = asc.Clipboard;
var asc_CMM = asc.asc_CMouseMoveData; var asc_CMM = asc.asc_CMouseMoveData;
...@@ -84,6 +85,7 @@ ...@@ -84,6 +85,7 @@
this.cellEditor = undefined; this.cellEditor = undefined;
this.fontRenderingMode = null; this.fontRenderingMode = null;
this.popUpSelector = null;
this.formulasList = null; // Список всех формул this.formulasList = null; // Список всех формул
this._lockDraw = false; this._lockDraw = false;
...@@ -211,7 +213,6 @@ ...@@ -211,7 +213,6 @@
"moveResizeRangeHandleDone":function () {self._onMoveResizeRangeHandleDone.apply(self, arguments);}, "moveResizeRangeHandleDone":function () {self._onMoveResizeRangeHandleDone.apply(self, arguments);},
"editCell": function () {self._onEditCell.apply(self, arguments);}, "editCell": function () {self._onEditCell.apply(self, arguments);},
"stopCellEditing": function () {return self._onStopCellEditing.apply(self, arguments);}, "stopCellEditing": function () {return self._onStopCellEditing.apply(self, arguments);},
"removeFormulaSelector": function () {return self._onRemoveFormulaSelector.apply(self, arguments);},
"empty": function () {self._onEmpty.apply(self, arguments);}, "empty": function () {self._onEmpty.apply(self, arguments);},
"canEnterCellRange": function () { "canEnterCellRange": function () {
self.cellEditor.setFocus(false); self.cellEditor.setFocus(false);
...@@ -420,6 +421,8 @@ ...@@ -420,6 +421,8 @@
/*settings*/{ /*settings*/{
font: this.defaultFont font: this.defaultFont
}); });
this.popUpSelector = new asc_PS(this.element);
} }
this.clipboard.Api = this.Api; this.clipboard.Api = this.Api;
...@@ -790,7 +793,8 @@ ...@@ -790,7 +793,8 @@
WorkbookView.prototype._onShowAutoComplete = function () { WorkbookView.prototype._onShowAutoComplete = function () {
var ws = this.getWorksheet(); var ws = this.getWorksheet();
var arrValues = ws.getCellAutoCompleteValues(ws.activeRange.startCol, ws.activeRange.startRow); var arrValues = ws.getCellAutoCompleteValues(ws.activeRange.startCol, ws.activeRange.startRow);
console.log(arrValues); this.popUpSelector.show(false, arrValues, this.getWorksheet().getActiveCellCoord());
// ToDo нужно не забыть скрывать этот список
}; };
WorkbookView.prototype._onAutoFiltersClick = function (idFilter) { WorkbookView.prototype._onAutoFiltersClick = function (idFilter) {
...@@ -966,10 +970,6 @@ ...@@ -966,10 +970,6 @@
WorkbookView.prototype._onStopCellEditing = function () { WorkbookView.prototype._onStopCellEditing = function () {
return this.cellEditor.close(true); return this.cellEditor.close(true);
}; };
WorkbookView.prototype._onRemoveFormulaSelector = function () {
return this.cellEditor._removeFormulaSelector();
};
WorkbookView.prototype._onCloseCellEditor = function () { WorkbookView.prototype._onCloseCellEditor = function () {
this.controller.setCellEditMode(false); this.controller.setCellEditMode(false);
...@@ -1335,6 +1335,22 @@ ...@@ -1335,6 +1335,22 @@
WorkbookView.prototype._onUpdateCellEditor = function (text, cursorPosition, isFormula, formulaPos, formulaName) { WorkbookView.prototype._onUpdateCellEditor = function (text, cursorPosition, isFormula, formulaPos, formulaName) {
// ToDo добавить вывод окна для формулы (список формул должен всегда лежать в переменной, сделанной на инициализации) // ToDo добавить вывод окна для формулы (список формул должен всегда лежать в переменной, сделанной на инициализации)
// Еще для ускорения можно завести объект, куда класть результаты поиска по формулам и второй раз не искать. // Еще для ускорения можно завести объект, куда класть результаты поиска по формулам и второй раз не искать.
var arrResult = [];
if (isFormula && formulaName) {
formulaName = formulaName.toUpperCase();
for (var i = 0; i < this.formulasList.length; ++i) {
var group = this.formulasList[i].formulasArray;
for (var j = 0; j < group.length; ++j) {
if (0 === group[j].name.indexOf(formulaName)) {
arrResult.push(group[j]);
}
}
}
}
if (0 < arrResult.length)
this.popUpSelector.show(true, arrResult, this.getWorksheet().getActiveCellCoord());
else
this.popUpSelector.hide();
}; };
// Вставка формулы в редактор // Вставка формулы в редактор
......
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