2021-09-08 07:23:10 +00:00
|
|
|
!window.common && (window.common = {});
|
|
|
|
!common.controller && (common.controller = {});
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-10 06:26:28 +00:00
|
|
|
common.ui = _.extend(common.ui || {}, {
|
2021-09-08 07:23:10 +00:00
|
|
|
Keys : {
|
|
|
|
BACKSPACE: 8,
|
|
|
|
TAB: 9,
|
|
|
|
RETURN: 13,
|
|
|
|
SHIFT: 16,
|
|
|
|
CTRL: 17,
|
|
|
|
ALT: 18,
|
|
|
|
ESC: 27,
|
|
|
|
LEFT: 37,
|
|
|
|
UP: 38,
|
|
|
|
RIGHT: 39,
|
|
|
|
DOWN: 40,
|
|
|
|
DELETE: 46,
|
|
|
|
HOME: 36,
|
|
|
|
END: 35,
|
|
|
|
SPACE: 32,
|
|
|
|
PAGEUP: 33,
|
|
|
|
PAGEDOWN: 34,
|
|
|
|
INSERT: 45,
|
|
|
|
EQUALITY_FF:61,
|
|
|
|
NUM_PLUS: 107,
|
|
|
|
NUM_MINUS: 109,
|
|
|
|
F1: 112,
|
|
|
|
F2: 113,
|
|
|
|
F3: 114,
|
|
|
|
F4: 115,
|
|
|
|
F5: 116,
|
|
|
|
F6: 117,
|
|
|
|
F7: 118,
|
|
|
|
F8: 119,
|
|
|
|
F9: 120,
|
|
|
|
F10: 121,
|
|
|
|
F11: 122,
|
|
|
|
F12: 123,
|
|
|
|
MINUS_FF: 173,
|
|
|
|
EQUALITY: 187,
|
|
|
|
MINUS: 189
|
|
|
|
}});
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
common.controller.CellEditor = new(function(){
|
|
|
|
var me,
|
|
|
|
api,
|
|
|
|
editor,
|
|
|
|
mode,
|
|
|
|
created=false;
|
|
|
|
|
|
|
|
function onCellName(e){
|
2021-09-10 06:26:28 +00:00
|
|
|
if (e.keyCode == common.ui.Keys.RETURN){
|
2021-09-08 07:23:10 +00:00
|
|
|
var name = editor.$cellname.val();
|
|
|
|
if (name && name.length) {
|
|
|
|
api.asc_findCell(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function onKeyupCellEditor(e) {
|
2021-09-10 06:26:28 +00:00
|
|
|
if(e.keyCode == common.ui.Keys.RETURN && !e.altKey){
|
2021-09-08 07:23:10 +00:00
|
|
|
api.isCEditorFocused = 'clear';
|
|
|
|
}
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function onBlurCellEditor() {
|
|
|
|
if (api.isCEditorFocused == 'clear')
|
|
|
|
api.isCEditorFocused = undefined;
|
|
|
|
else if (api.isCellEdited)
|
|
|
|
api.isCEditorFocused = true;
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-13 01:38:49 +00:00
|
|
|
function onLayoutResize(o, r) {
|
|
|
|
if (r == 'cell:edit') {
|
|
|
|
o && common.localStorage.setBool('sse-celleditor-expand', false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function events() {
|
|
|
|
editor.$el.find('#ce-cell-name').on( 'keyup', onCellName);
|
|
|
|
editor.$el.find('textarea#ce-cell-content').on( 'keyup', onKeyupCellEditor);
|
|
|
|
editor.$el.find('textarea#ce-cell-content').on('blur', onBlurCellEditor);
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function onLaunch(){
|
|
|
|
common.view.CellEditor.create();
|
|
|
|
editor = common.view.CellEditor;
|
|
|
|
events();
|
|
|
|
|
|
|
|
editor.$el.parent().find('.after').css({zIndex: '4'}); // for spreadsheets - bug 23127
|
|
|
|
|
|
|
|
var val = common.localStorage.getItem('sse-celleditor-height');
|
2021-09-10 06:26:28 +00:00
|
|
|
editor.keep_height = (val!==null && parseInt(val)>0) ? parseInt(val) : 19;
|
2021-09-08 07:23:10 +00:00
|
|
|
if (common.localStorage.getBool('sse-celleditor-expand')) {
|
|
|
|
editor.$el.height(editor.keep_height);
|
|
|
|
onLayoutResize(undefined, 'cell:edit');
|
|
|
|
}
|
|
|
|
this.namedrange_locked = false;
|
|
|
|
}
|
|
|
|
|
2021-09-13 01:38:49 +00:00
|
|
|
function createController() {
|
|
|
|
me = this;
|
|
|
|
if (created) return me;
|
|
|
|
|
|
|
|
created = true;
|
|
|
|
onLaunch();
|
|
|
|
return me;
|
|
|
|
}
|
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function onApiCellSelection(info){
|
|
|
|
editor.cell.updateInfo(info);
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function onApiEditCell(state) {
|
|
|
|
if (this.viewmode) return; // signed file
|
|
|
|
|
|
|
|
if (state == Asc.c_oAscCellEditorState.editStart){
|
|
|
|
api.isCellEdited = true;
|
|
|
|
editor.cell.nameDisabled(true);
|
|
|
|
} else if (state == Asc.c_oAscCellEditorState.editInCell) {
|
|
|
|
api.isCEditorFocused = 'clear';
|
|
|
|
} else if (state == Asc.c_oAscCellEditorState.editEnd) {
|
|
|
|
api.isCellEdited = false;
|
|
|
|
api.isCEditorFocused = false;
|
|
|
|
editor.cell.nameDisabled(false);
|
|
|
|
}
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function onLockDefNameManager(state) {
|
|
|
|
this.namedrange_locked = (state == Asc.c_oAscDefinedNameReason.LockDefNameManager);
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function onApiDisconnect() {
|
|
|
|
mode.isEdit = false;
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function setApi(apiF){
|
|
|
|
api=apiF;
|
|
|
|
|
|
|
|
api.isCEditorFocused = false;
|
|
|
|
api.asc_registerCallback('asc_onSelectionNameChanged', onApiCellSelection);
|
|
|
|
api.asc_registerCallback('asc_onEditCell', onApiEditCell);
|
|
|
|
api.asc_registerCallback('asc_onCoAuthoringDisconnect', onApiDisconnect);
|
|
|
|
api.asc_registerCallback('asc_onLockDefNameManager', onLockDefNameManager);
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function onApiSelectionChanged(info) {
|
|
|
|
if (this.viewmode) return; // signed file
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function setMode(modeF) {
|
|
|
|
mode = modeF;
|
|
|
|
|
|
|
|
if ( mode.isEdit ) {
|
|
|
|
api.asc_registerCallback('asc_onSelectionChanged', onApiSelectionChanged);
|
|
|
|
}
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
function setPreviewMode(mode) {
|
|
|
|
if (this.viewmode === mode) return;
|
|
|
|
this.viewmode = mode;
|
|
|
|
editor.cell.nameDisabled(mode && !(mode.isEdit && !mode.isEditDiagram && !mode.isEditMailMerge));
|
|
|
|
}
|
2021-09-09 02:55:43 +00:00
|
|
|
|
2021-09-08 07:23:10 +00:00
|
|
|
return {
|
|
|
|
create: createController,
|
|
|
|
setApi: setApi,
|
2021-09-09 02:55:43 +00:00
|
|
|
setMode: setMode,
|
|
|
|
setPreviewMode: setPreviewMode
|
2021-09-08 07:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|