var Unibase; (function (Unibase) { let Apps; (function (Apps) { let Collaboration; (function (Collaboration) { let Components; (function (Components) { let Sheets; (function (Sheets) { class FormatPainter { constructor() { this.hederText = {}; this.isDrag = false; this.isScroll = false; this.isLeftScroll = false; this.isTopScroll = false; this.isVertical = false; this.side = -1; this.isEdit = false; this.isCellDrag = false; this.isCellDragged = false; this.isCellEdit = false; } init(base) { this.base = base; this.ssObj = base.ssObj; this.util = Unibase.Apps.Collaboration.Components.Common.Util.Instance(); this.initProp(); } initProp() { this.selectFn = this.selected.bind(this); this.ssObj.addEventListener("select", this.selectFn); this.createdFn = this.created.bind(this); this.ssObj.addEventListener("created", this.createdFn); this.initialLoadFn = this.initialLoad.bind(this); this.ssObj.on("initialLoad", this.initialLoadFn); this.ssObj.on("activeSheetChanged", this.activeSheetChanged, this); this.ssObj.on("mouseDown", this.mouseDown, this); } destroy() { this.ssObj.removeEventListener("select", this.selectFn); this.ssObj.removeEventListener("created", this.createdFn); this.ssObj.off("initialLoad", this.initialLoadFn); this.ssObj.off("activeSheetChanged", this.activeSheetChanged); this.ssObj.off("mouseDown", this.mouseDown); ej.base.EventHandler.remove(this.ssObj.element, 'mousemove', this.mouseMoveHandler); ej.base.EventHandler.remove(this.ssObj.element, 'mouseup', this.mouseUp); } activeSheetChanged() { if (this.isClicked) { this.hideFPBdr(); setTimeout(() => { if (this.activesheet === this.ssObj.biz.getActiveSheet()) { this.updateFPBdr(); } }, 650); setTimeout(() => { this.ssObj.element.querySelector('#' + this.ssObj.element.id + '_formatpainter').classList.add('biz-fp-color'); }, 50); } } createFPBdr() { if (!this.ssObj.element.getElementsByClassName('biz-fp')[0]) { this.element = document.createElement('div'); this.element.classList.add('biz-fp'); this.element.appendChild(ej.base.createElement('div', { className: 'e-top' })); this.element.appendChild(ej.base.createElement('div', { className: 'e-bottom' })); this.element.appendChild(ej.base.createElement('div', { className: 'e-left' })); this.element.appendChild(ej.base.createElement('div', { className: 'e-right' })); let content = this.ssObj.element.getElementsByClassName('e-sheet-content')[0]; content.appendChild(this.element); } this.element.classList.remove('biz-hide'); } updateFPBdr() { if (this.isClicked) { this.createFPBdr(); let sel = this.ssObj.element.getElementsByClassName('e-selection')[0]; let activecell = this.ssObj.element.getElementsByClassName('e-active-cell')[0]; let selection = sel.classList.contains('e-hide') ? activecell : sel; let offset = selection.getBoundingClientRect(); this.element.style.top = selection.style.top; this.element.style.left = selection.style.left; this.element.style.width = offset.width + 'px'; this.element.style.height = offset.height + 'px'; } } hideFPBdr() { let ele = this.ssObj.element.getElementsByClassName('biz-fp')[0]; if (ele) { ele.classList.add('biz-hide'); } } mouseDown(e) { let target = ej.base.closest(e.target, '.biz-icon-painter'); if (target) { this.isClicked = true; this.ssObj.element.querySelector('#' + this.ssObj.element.id + '_formatpainter').classList.add('biz-fp-color'); this.updateFPBdr(); } if (this.splitDlgObj && !this.splitDlgObj.isDestroyed) { let cbox = ej.base.closest(e.target, '.e-checkbox-wrapper'); if (cbox) { let isRefresh = true; let tickicon = cbox.firstElementChild; tickicon.classList.contains('e-check') ? tickicon.classList.remove('e-check') : tickicon.classList.add('e-check'); if (cbox.classList.contains('biz-st-other')) { this.inputObj.enabled = tickicon.classList.contains('e-check'); if (this.inputObj.value && this.inputObj.value.length) { isRefresh = false; } } isRefresh && this.refreshST(); } } this.mdown(e); this.mdown2(e); } initialLoad() { let getRibbonItemsFn = this.ssObj.ribbonModule.getRibbonItems.bind(this.ssObj.ribbonModule); this.ssObj.ribbonModule.getRibbonItems = () => { let items = getRibbonItemsFn(); let home = items[0].content; let item = { id: this.ssObj.element.id + '_formatpainter', prefixIcon: "biz-icon-painter", tooltipText: "Format Painter" }; home.splice(6, 0, item); item = { template: this.getRotationElem(), id: this.ssObj.element.id + '_text_rotation', tooltipText: "Text rotation" }; home.splice(27, 0, item); return items; }; } isSingleCellSel(ranges) { if (ranges[0] === ranges[2] && ranges[1] === ranges[3]) { return true; } return false; } applyFormatPaint(srcRange, destRange, srcSheetIndex) { let srcSheet = this.ssObj.sheets[srcSheetIndex]; this.formatIndexes = this.base.getIndexesFromAddress(destRange); this.rangeIndexes = this.base.getIndexesFromAddress(srcRange); let r = -1; let c = -1; let sheet = this.ssObj.biz.getActiveSheet(); let values = []; for (let i = this.rangeIndexes[0]; i <= this.rangeIndexes[2]; i++) { let row = []; for (let j = this.rangeIndexes[1]; j <= this.rangeIndexes[3]; j++) { let obj = ej.base.extend({}, ej.spreadsheet.getCell(i, j, sheet)); row.push(obj); } values.push(row); } if (this.isSingleCellSel(this.formatIndexes)) { r = this.formatIndexes[0] - 1; c = this.formatIndexes[1] - 1; for (let i = this.rangeIndexes[0]; i <= this.rangeIndexes[2]; i++) { r++; c = this.formatIndexes[1] - 1; let row = values.shift(); for (let j = this.rangeIndexes[1]; j <= this.rangeIndexes[3]; j++) { c++; let srcObj = row.shift(); let destObj = ej.spreadsheet.getCell(r, c, sheet) || {}; this.copyValues(srcObj, destObj, ['style', 'format', 'hyperlink', 'wrap']); this.ssObj.biz.setCell(r, c, sheet, destObj); } } this.ssObj.selectRange(this.base.generateHeaderText(this.formatIndexes[1] + 1) + (this.formatIndexes[0] + 1) + ':' + this.base.generateHeaderText(c + 1) + (r + 1)); } else { let m = 0; let n = 0; for (let i = this.formatIndexes[0]; i <= this.formatIndexes[2]; i++) { if (m === values.length) { m = 0; } n = 0; for (let j = this.formatIndexes[1]; j <= this.formatIndexes[3]; j++) { if (n === values[m].length) { n = 0; } let srcObj = values[m][n]; let destObj = ej.spreadsheet.getCell(i, j, sheet) || {}; this.copyValues(srcObj, destObj, ['style', 'format', 'hyperlink', 'wrap']); this.ssObj.biz.setCell(i, j, sheet, destObj); n++; } m++; } } } selected(e) { this.formatRange = e.range; this.formatIndexes = this.base.getIndexesFromAddress(this.formatRange); if (this.isClicked) { this.formatRange = e.range; let args = { srcRange: this.range, destRange: this.formatRange, destIndexes: this.ssObj.biz.getIndexes(), origin: 'biz', action: 'formatpaint', srcSheetIndex: this.base.getSheetIndex(this.activesheet), sheetIndex: this.base.getSheetIndex() }; this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'formatpaint', options: args, oldCells: this.base.getCellsFromIndexes(args.destIndexes) } }); this.applyFormatPaint(this.range, this.formatRange, args.srcSheetIndex); this.hideFPBdr(); this.base.download.ssAutoSave({ action: "format", eventArgs: {} }, this.base, true); this.ssObj.element.querySelector('#' + this.ssObj.element.id + '_formatpainter').classList.remove('biz-fp-color'); Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args); } this.isClicked = false; this.range = e.range; this.activesheet = this.ssObj.biz.getActiveSheet(); this.selectionSignalr(); } copyValues(srcObj, destObj, props) { for (let i = 0; i < props.length; i++) { if (srcObj[props[i]]) { destObj[props[i]] = srcObj[props[i]]; } else { delete destObj[props[i]]; } } return destObj; } created(e) { ej.base.EventHandler.add(document.body, 'mousemove', this.mouseMoveHandler, this); ej.base.EventHandler.add(document.body, 'mouseup', this.mouseUp, this); } selectionSignalr() { let userName = Unibase.Platform.Membership.Infos.Identity.getCurrentUser().name; let args = { range: this.ssObj.biz.getActiveSheet().activeCell, userName: userName, origin: 'biz', action: 'selection', sheetIndex: this.base.getSheetIndex() }; Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args); } applyUserSelection(range, userName) { let ranges = this.base.getIndexesFromAddress(range); let elem = this.ssObj.element.querySelector('.biz-user-selection'); elem && elem.classList.add('biz-hide'); this.clearTooltip(); if (this.ssObj.biz.sheetIndex !== this.base.getSheetIndex(this.ssObj.getActiveSheet())) { return; } let cell = this.ssObj.getCell(ranges[0], ranges[1]); if (!cell) { return; } !elem && this.drawUserSel(userName); this.positionUserSel(ranges[0], ranges[1], cell, userName); elem.classList.remove('biz-hide'); } drawUserSel(userName) { let color = this.util.colorHash(userName); let elem = document.createElement('div'); elem.classList.add('biz-user-selection'); elem.style.borderColor = color.hex; let content = this.ssObj.element.getElementsByClassName('e-sheet-content')[0]; content.appendChild(elem); } positionUserSel(rowIdx, colIdx, cell, userName) { let sheet = this.ssObj.biz.getActiveSheet(); let freezeRow = this.ssObj.frozenRowCount(sheet); let freezeCol = this.ssObj.frozenColCount(sheet); let elem = this.ssObj.element.querySelector('.biz-user-selection'); let dim = ej.spreadsheet.getCellPosition(sheet, [rowIdx, colIdx], freezeRow, freezeCol); cell.classList.add('biz-user-name'); cell.setAttribute('title', userName); elem.style.width = cell.offsetWidth + 'px'; elem.style.height = cell.offsetHeight + 'px'; elem.style.top = dim.top + 'px'; elem.style.left = dim.left + 'px'; } clearTooltip() { let elem = this.ssObj.element.querySelector('.biz-user-name'); if (elem) { elem.classList.remove('biz-user-name'); elem.removeAttribute('title'); } } deleteValues() { let rngIndexes = this.base.getIndexesFromAddress(this.range); let sheet = this.ssObj.biz.getActiveSheet(); for (let i = rngIndexes[0]; i <= rngIndexes[2]; i++) { if (!sheet.rows[i]) { return; } for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) { let srcObj = ej.spreadsheet.getCell(i, j, sheet); delete srcObj.value; delete srcObj.formula; this.ssObj.biz.setCell(i, j, sheet, srcObj); } } } deleteShiftUp(range) { let args = { range: this.base.ssObj.biz.getRange(), action: 'deleteshiftup', origin: 'biz', sheetIndex: this.base.getSheetIndex() }; this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'deleteshiftup', range: args.range, indexes: this.base.ssObj.biz.getIndexes(), oldCells: this.base.getCellsFromIndexes(this.base.ssObj.biz.getIndexes()) } }); this.applyDeleteShiftUp(range, args); var selectedRange = this.base.ssObj.getActiveSheet().selectedRange; this.base.ssObj.selectRange(selectedRange); Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().autoSave(args); Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args); } applyDeleteShiftUp(range, args) { let rngIndexes = this.base.getIndexesFromAddress(range); let sheet = this.ssObj.biz.getActiveSheet(); let len = rngIndexes[2] - rngIndexes[0] + 1; for (let i = rngIndexes[0]; i <= sheet.rows.length; i++) { if (!this.ssObj.biz.isRowAvailable(i + len, sheet)) { if (this.ssObj.biz.isRowAvailable(i, sheet)) { for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) { this.ssObj.biz.setCell(i, j, sheet, {}); delete sheet.rows[i].cells[j]; } } continue; } else { for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) { let destObj = ej.spreadsheet.getCell(i + len, j, sheet); let srcObj = ej.spreadsheet.getCell(i, j, sheet); if (destObj) { destObj = ej.base.extend({}, destObj); srcObj = destObj; this.ssObj.biz.setCell(i, j, sheet, srcObj); } else { if (srcObj) { this.ssObj.biz.setCell(i, j, sheet, {}); delete sheet.rows[i].cells[j]; } } } } } Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().autoSave(args); } deleteShiftLeft(range) { let args = { range: this.base.ssObj.biz.getRange(), action: 'deleteshiftleft', origin: 'biz', sheetIndex: this.base.getSheetIndex() }; this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'deleteshiftleft', range: args.range, indexes: this.base.ssObj.biz.getIndexes(), oldCells: this.base.getCellsFromIndexes(this.base.ssObj.biz.getIndexes()) } }); this.applyDeleteShiftLeft(range); var selectedRange = this.base.ssObj.getActiveSheet().selectedRange; this.base.ssObj.selectRange(selectedRange); Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().autoSave(args); Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args); } applyDeleteShiftLeft(range) { let rngIndexes = this.base.getIndexesFromAddress(range); let sheet = this.ssObj.biz.getActiveSheet(); let len = rngIndexes[3] - rngIndexes[1] + 1; for (let i = rngIndexes[0]; i <= rngIndexes[2]; i++) { if (this.ssObj.biz.isRowAvailable(i, sheet)) { for (let j = rngIndexes[1]; j <= sheet.rows[i].cells.length; j++) { let destObj = ej.spreadsheet.getCell(i, j + len, sheet); let srcObj = ej.spreadsheet.getCell(i, j, sheet); if (destObj) { destObj = ej.base.extend({}, destObj); srcObj = destObj; this.ssObj.biz.setCell(i, j, sheet, srcObj); } else { if (srcObj) { this.ssObj.biz.setCell(i, j, sheet, {}); delete sheet.rows[i].cells[j]; } } } } } } insertShiftDown(range) { let args = { range: this.base.ssObj.biz.getRange(), action: 'insertshiftdown', origin: 'biz', sheetIndex: this.base.getSheetIndex(), usedRange: this.base.ssObj.getActiveSheet().usedRange }; this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'insertshiftdown', range: args.range, indexes: this.base.ssObj.biz.getIndexes() } }); Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().autoSave(args); this.applyInsertShiftDown(range, args); var selectedRange = this.base.ssObj.getActiveSheet().selectedRange; this.base.ssObj.selectRange(selectedRange); Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args); } applyInsertShiftDown(range, args) { let rngIndexes = this.base.getIndexesFromAddress(range); let sheet = this.ssObj.biz.getActiveSheet(); let len = rngIndexes[2] - rngIndexes[0] + 1; for (let i = sheet.rows.length + len - 1; i >= rngIndexes[0]; i--) { if (i <= rngIndexes[2]) { for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) { this.ssObj.biz.setCell(i, j, sheet, {}); delete sheet.rows[i].cells[j]; } continue; } if (!this.ssObj.biz.isRowAvailable(i - len, sheet)) { if (this.ssObj.biz.isRowAvailable(i, sheet)) { for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) { this.ssObj.biz.setCell(i, j, sheet, {}); delete sheet.rows[i].cells[j]; } } continue; } else { for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) { let destObj = ej.spreadsheet.getCell(i - len, j, sheet); let srcObj = ej.spreadsheet.getCell(i, j, sheet); if (destObj) { destObj = ej.base.extend({}, destObj); srcObj = destObj; this.ssObj.biz.setCell(i, j, sheet, srcObj); } else { if (srcObj) { this.ssObj.biz.setCell(i, j, sheet, {}); delete sheet.rows[i].cells[j]; } } } } } Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args); } insertShiftRight(range) { let args = { range: this.base.ssObj.biz.getRange(), action: 'insertshiftright', origin: 'biz', sheetIndex: this.base.getSheetIndex() }; this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'insertshiftright', range: args.range, indexes: this.base.ssObj.biz.getIndexes() } }); this.applyInsertShiftRight(range); var selectedRange = this.base.ssObj.getActiveSheet().selectedRange; this.base.ssObj.selectRange(selectedRange); Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().autoSave(args); Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args); } applyInsertShiftRight(range) { let rngIndexes = this.base.getIndexesFromAddress(range); let sheet = this.ssObj.biz.getActiveSheet(); let len = rngIndexes[3] - rngIndexes[1] + 1; for (let i = rngIndexes[0]; i <= rngIndexes[2]; i++) { if (this.ssObj.biz.isRowAvailable(i, sheet)) { for (let j = sheet.rows[i].cells.length + len - 1; j >= rngIndexes[1]; j--) { let destObj = ej.spreadsheet.getCell(i, j - len, sheet); let srcObj = ej.spreadsheet.getCell(i, j, sheet); if (j <= rngIndexes[3]) { this.ssObj.biz.setCell(i, j, sheet, {}); delete sheet.rows[i].cells[j]; continue; } if (destObj) { destObj = ej.base.extend({}, destObj); srcObj = destObj; this.ssObj.biz.setCell(i, j, sheet, srcObj); } else { if (srcObj) { this.ssObj.biz.setCell(i, j, sheet, {}); delete sheet.rows[i].cells[j]; } } } } } } renderConfirmDlg() { let elem = this.ssObj.element.querySelector('.biz-delete-con') || ej.base.createElement('div', { className: 'biz-delete-con' }); this.confirmObj = new ej.popups.Dialog({ target: this.ssObj.element, content: 'Are you sure you want to delete this sheet', isModal: true, width: '400px', animationSettings: { effect: 'None' }, showCloseIcon: false, buttons: [{ click: this.deleteActiveSheet.bind(this), buttonModel: { content: 'OK', isPrimary: true } }, { click: this.destroyConfirm.bind(this), buttonModel: { content: 'Cancel' } }] }); this.ssObj.element.appendChild(elem); this.confirmObj.appendTo(elem); } deleteActiveSheet() { this.destroyConfirm(); let sheetIdx = this.base.getSheetIndex(); this.base.ssObj.delete(sheetIdx, sheetIdx, "Sheet"); Unibase.Apps.Collaboration.Components.Common.Download.Instance().ssAutoSave({ action: "removeSheet", sheetIndex: sheetIdx }, this.base, true); } destroyConfirm() { this.confirmObj.destroy(); } renderAlert(content) { let alertElem = this.ssObj.element.querySelector('.biz-split-alert') || ej.base.createElement('div', { className: 'biz-split-alert' }); this.alertObj = new ej.popups.Dialog({ target: this.ssObj.element, content: content, isModal: true, width: '400px', animationSettings: { effect: 'None' }, showCloseIcon: false, buttons: [{ click: this.destroyAlert.bind(this), buttonModel: { content: 'OK', isPrimary: true } }] }); this.ssObj.element.appendChild(alertElem); this.alertObj.appendTo(alertElem); } destroyAlert() { this.alertObj.destroy(); } appenChildrens(parent, elements) { for (let i = 0; i < elements.length; i++) { parent.appendChild(elements[i]); } } createCBoxWithWrap(elem) { let div = ej.base.createElement('div'); div.appendChild(elem); return div; } initSplitDialog() { let rngIndexes = this.ssObj.biz.getIndexes(); if (rngIndexes[1] !== rngIndexes[3]) { this.renderAlert('Text to Columns feature can convert only one column at a time, Try again selecting cells in one column only'); return; } this.values = []; this.hasValue = false; this.setData(); this.hasValue ? this.renderSplitDialog() : this.renderAlert('No data was selected to parse'); } renderSplitDialog() { let dlgElem = ej.base.createElement('div', { className: 'biz-split-dlg' }); this.tabElem = this.createCBoxWithWrap(ej.buttons.createCheckBox(this.ssObj.createElement, false, { checked: false, label: 'Tab', cssClass: 'biz-st-cbox' })); this.semicolonElem = this.createCBoxWithWrap(ej.buttons.createCheckBox(this.ssObj.createElement, false, { checked: false, label: 'Semicolon', cssClass: 'biz-st-cbox' })); this.commaElem = this.createCBoxWithWrap(ej.buttons.createCheckBox(this.ssObj.createElement, false, { checked: false, label: 'Comma', cssClass: 'biz-st-cbox' })); this.spaceElem = this.createCBoxWithWrap(ej.buttons.createCheckBox(this.ssObj.createElement, false, { checked: false, label: 'Space', cssClass: 'biz-st-cbox' })); this.otherElem = this.createCBoxWithWrap(ej.buttons.createCheckBox(this.ssObj.createElement, false, { checked: false, label: 'Other', cssClass: 'biz-st-cbox biz-st-other' })); let other = ej.base.createElement('div'); this.otherElem.style.display = 'inline'; other.appendChild(this.otherElem); this.otherInElem = ej.base.createElement('input', { attrs: { type: 'text' }, className: 'biz-sp-input' }); other.appendChild(this.otherInElem); this.appenChildrens(dlgElem, [ ej.base.createElement('div', { innerHTML: 'Delimiters', styles: 'margin-bottom: 10px;' }), this.tabElem, this.semicolonElem, this.commaElem, this.spaceElem, other, ej.base.createElement('div', { innerHTML: 'Data Preview', styles: 'margin: 10px 0;' }), ej.base.createElement('div', { id: this.ssObj.element.id + '_split' }) ]); this.ssObj.element.appendChild(dlgElem); this.inputObj = new ej.inputs.TextBox({ width: '50px', floatLabelType: 'Auto', enabled: false, change: this.refreshST.bind(this) }); this.inputObj.appendTo(this.otherInElem); this.splitDlgObj = new ej.popups.Dialog({ header: 'Convert Text to Columns', target: this.ssObj.element, animationSettings: { effect: 'None' }, isModal: true, showCloseIcon: false, width: '550px', buttons: [{ click: this.applySplitValues.bind(this), buttonModel: { content: 'OK', isPrimary: true } }, { click: this.destroySTDialog.bind(this), buttonModel: { content: 'Cancel' } }], open: this.splitDialogOpen.bind(this), }); this.splitDlgObj.appendTo(dlgElem); } splitDialogOpen() { this.detectAndUpdate(); this.setSplitedData(); this.renderGrid(); } refreshST() { this.setSplitedData(); this.refreshGrid(); } refreshGrid() { let obj = this.convertDS(); this.gridObj.dataSource = obj.data; this.gridObj.columns = obj.cols; this.gridObj.refreshColumns(); } applySplitValues() { let indexes = this.base.ssObj.biz.getIndexes(); let args = { range: this.range, stValues: JSON.parse(JSON.stringify(this.stValues)), action: 'splittext', origin: 'biz', sheetIndex: this.base.getSheetIndex() }; this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'splittext', stValues: this.stValues, range: indexes, oldCells: this.base.getCellsFromIndexes(indexes, this.stValues) } }); this.applySplitText(indexes, this.stValues); this.destroySTDialog(); Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args); } applySplitText(range, stValues) { let sheet = this.ssObj.biz.getActiveSheet(); let cellObj; let k = 0; let l = 0; for (let i = range[0]; i <= range[2]; i++) { k = 0; for (let j = range[1]; j < range[1] + stValues[l].length; j++) { cellObj = ej.spreadsheet.getCell(i, j, sheet) || {}; cellObj.value = stValues[l][k]; delete cellObj.formula; this.ssObj.biz.setCell(i, j, sheet, cellObj); k++; } l++; } } destroySTDialog() { this.inputObj.destroy(); this.gridObj.destroy(); this.splitDlgObj.destroy(); this.ssObj.element.querySelector('.biz-split-dlg').remove(); } setData() { let rngIndexes = this.base.getIndexesFromAddress(this.range); let sheet = this.ssObj.biz.getActiveSheet(); for (let i = rngIndexes[0]; i <= rngIndexes[2]; i++) { let cellObj = ej.spreadsheet.getCell(i, rngIndexes[1], sheet); if (cellObj && cellObj.value) { this.values.push(cellObj.value.toString()); this.hasValue = true; } else { this.values.push(''); } } } getOperators() { let obj = {}; obj['comma'] = this.isChecked(this.commaElem); obj['semicolon'] = this.isChecked(this.semicolonElem); obj['space'] = this.isChecked(this.spaceElem); obj['tab'] = this.isChecked(this.tabElem); obj['custom'] = this.isChecked(this.otherElem) && this.inputObj.value && this.inputObj.value.length; return obj; } isChecked(ele) { return ele.firstElementChild.firstElementChild.classList.contains('e-check'); } setSplitedData() { this.stValues = []; let obj = this.getOperators(); let value; let res; for (let i = 0; i < this.values.length; i++) { value = this.values[i]; if (obj.comma) { value = this.splitText(value, ','); } if (obj.semicolon) { value = this.splitText(value, ';'); } if (obj.space) { value = this.splitText(value, ' '); } if (obj.tab) { value = this.splitText(value, '\t'); } if (obj.custom) { value = this.splitText(value, this.inputObj.value); } if (Array.isArray(value)) { value = this.trimText(value); } else if (value === null || value === undefined || value === '') { value = []; } else { value = [value]; } this.stValues.push(value); } } renderGrid() { let obj = this.convertDS(); this.gridObj = new ej.grids.Grid({ allowPaging: this.values.length > 8, pageSettings: { pageSize: 8 }, dataSource: obj.data, gridLines: 'Both', allowSelection: false, rowHeight: 20, enableHover: false, columns: obj.cols, dataBound: () => { this.gridObj.autoFitColumns(); }, }); this.gridObj.appendTo('#' + this.ssObj.element.id + '_split'); } convertDS() { let data = []; let count = 0; let cols = []; for (let i = 0; i < this.stValues.length; i++) { let obj = {}; for (let j = 0; j < this.stValues[i].length; j++) { obj[j] = this.stValues[i][j]; if (count < this.stValues[i].length) { count = this.stValues[i].length; } } data.push(obj); } for (let i = 0; i < count; i++) { cols.push({ field: i.toString() }); } return { data: data, cols: cols, width: 100 }; } splitText(value, operator) { if (Array.isArray(value)) { let res = []; for (let i = 0; i < value.length; i++) { res = res.concat(this.splitText(value[i], operator)); } return res; } else { return value.split(operator); } } trimText(values) { return values.filter(function (e) { return e.trim() != ''; }); } detectAndUpdate() { let isComma, isSpace, isSemiColon; for (let i = 0; i < this.values.length; i++) { if (!isSemiColon && this.values[i].indexOf(';') > -1) { isSemiColon = true; this.semicolonElem.firstElementChild.firstElementChild.classList.add('e-check'); } if (this.values[i].indexOf(',') > -1) { isComma = true; this.commaElem.firstElementChild.firstElementChild.classList.add('e-check'); this.semicolonElem.firstElementChild.firstElementChild.classList.remove('e-check'); } if (!isSpace && this.values[i].indexOf(' ') > -1) { isSpace = true; this.spaceElem.firstElementChild.firstElementChild.classList.add('e-check'); this.semicolonElem.firstElementChild.firstElementChild.classList.remove('e-check'); this.commaElem.firstElementChild.firstElementChild.classList.remove('e-check'); } if (isSpace && isComma) { break; } } } mouseMoveHandler(e) { let target = e.target; let sheet = this.ssObj.biz.getActiveSheet(); let ranges = this.base.getIndexesFromAddress(sheet.selectedRange); this.mMove1(e); } mdown(e) { let target = e.target; let sheet = this.ssObj.biz.getActiveSheet(); let ranges = this.base.getIndexesFromAddress(sheet.selectedRange); } mouseUp(e) { let tab = ej.base.closest(e.target, '.biz-dd-active'); if (tab) { let event = new MouseEvent("contextmenu", { bubbles: true, cancelable: false, view: window, button: 2, buttons: 0, clientX: tab.getBoundingClientRect().x, clientY: tab.getBoundingClientRect().y }); if (window.CustomEvent) { tab.dispatchEvent(new CustomEvent('contextmenu')); } else if (document.createEvent) { tab.dispatchEvent(event); } else { tab.fireEvent('oncontextmenu'); } tab.dispatchEvent(event); } } renderComment(ranges, isExisting) { let div = document.createElement('div'); div.classList.add('biz-comment'); div.setAttribute('contenteditable', 'true'); div.setAttribute('rowidx', ranges[0].toString()); div.setAttribute('colidx', ranges[1].toString()); let sheet = this.ssObj.biz.getActiveSheet(); let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {}; if (cell.comment) { div.innerHTML = cell.comment; } let freezeRow = this.ssObj.frozenRowCount(sheet); let freezeCol = this.ssObj.frozenColCount(sheet); let positon = ej.spreadsheet.getCellPosition(sheet, [ranges[0], ranges[1]], freezeRow, freezeCol); let height = sheet.rows[ranges[0]] ? sheet.rows[ranges[0]].height || 20 : 20; let width = sheet.columns[ranges[1]] ? sheet.columns[ranges[1]].width || 64 : 64; let scrollTopElem = this.ssObj.element.querySelector('.e-main-panel'); let scrollLeftElem = this.ssObj.getScrollElement(); if (scrollTopElem.offsetHeight + scrollTopElem.scrollTop > positon.top + height + 75) { div.style.top = positon.top + 'px'; } else { div.style.top = positon.top - 75 + 'px'; } if (scrollLeftElem.offsetWidth + scrollLeftElem.scrollLeft > positon.left + width + 175) { div.style.left = positon.left + width + 'px'; } else { div.style.left = positon.left - 175 + 'px'; } let content = this.ssObj.element.querySelector('.e-sheet-content'); content.appendChild(div); this.lastCmtElem = div; if (!isExisting) { this.ssObj.allowEditing = false; this.ssObj.dataBind(); this.isCommentEdit = true; setTimeout(() => { div.focus(); }, 0); this.renderCommentEdge(ranges, positon); } else { this.lastCmtHoverElem = div; } } commentTimer(target) { setTimeout((elem) => { if (document.activeElement !== elem) { console.log('sdaf'); elem && elem.remove(); this.lastCmtElem = null; } else { this.commentTimer(elem); } }, 3000, target); } renderCommentEdge(ranges, position) { let div = document.createElement('div'); div.classList.add('biz-comment-edge'); div.setAttribute('id', ('cmt_' + ranges[0] + '_' + ranges[1])); this.positionCommentEdge(ranges, div, position); let content = this.ssObj.element.querySelector('.e-sheet-content'); content.appendChild(div); } positionCommentEdge(ranges, div, position) { let sheet = this.ssObj.biz.getActiveSheet(); let height = sheet.rows[ranges[0]] ? sheet.rows[ranges[0]].height || 20 : 20; let width = sheet.columns[ranges[1]] ? sheet.columns[ranges[1]].width || 64 : 64; if (!position) { let freezeRow = this.ssObj.frozenRowCount(sheet); let freezeCol = this.ssObj.frozenColCount(sheet); position = ej.spreadsheet.getCellPosition(sheet, [ranges[0], ranges[1]], freezeRow, freezeCol); } div.style.top = position.top + 'px'; div.style.left = position.left + width - 5 + 'px'; } mdown2(e) { let target = e.target; if (this.lastCmtElem) { if (target !== this.lastCmtElem) { this.commentTimer(this.lastCmtElem); } this.updateComment(this.lastCmtElem); } if (target.classList.contains('biz-comment')) { this.isCommentEdit = true; this.ssObj.isEdit && this.ssObj.endEdit(); this.ssObj.allowEditing = false; this.ssObj.dataBind(); this.lastCmtElem = target; } else if (this.isCommentEdit) { this.isCommentEdit = false; this.ssObj.allowEditing = true; this.ssObj.dataBind(); } } mMove1(e) { let target = e.target; if (target.classList.contains('e-cell') && !this.isCommentEdit) { let rowIdx = parseInt(target.parentElement.getAttribute('aria-rowindex')) - 1; let colIdx = parseInt(target.getAttribute('aria-colindex')) - 1; let sheet = this.ssObj.biz.getActiveSheet(); let cell = ej.spreadsheet.getCell(rowIdx, colIdx, sheet) || {}; if (cell === this.lastCmtObj) { return; } else { this.lastCmtObj = null; this.removeCommentPopup(); } if (cell.comment) { this.lastCmtObj = cell; this.removeCommentPopup(); this.renderComment([rowIdx, colIdx], true); } } } updateComment(target) { let rowIdx = parseInt(target.getAttribute('rowidx')); let colIdx = parseInt(target.getAttribute('colidx')); let sheet = this.ssObj.biz.getActiveSheet(); let cell = ej.spreadsheet.getCell(rowIdx, colIdx, sheet) || {}; cell.comment = target.innerText; this.setComment([rowIdx, colIdx], target.innerText); this.ssObj.biz.setCell(rowIdx, colIdx, sheet, cell); } removeComment(ranges) { let sheet = this.ssObj.biz.getActiveSheet(); let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {}; delete cell.comment; this.removeCommentPopup(); this.removeCommentEdge(ranges); } removeCommentPopup() { let popup = this.ssObj.element.querySelector('.biz-comment'); popup && popup.remove(); } getEdgeElem(ranges) { return this.ssObj.element.querySelector('#cmt_' + ranges[0] + '_' + ranges[1]); } removeCommentEdge(ranges) { let edge = this.getEdgeElem(ranges); edge && edge.remove(); } setComment(ranges, value) { let sheet = this.ssObj.biz.getActiveSheet(); if (!sheet.comments) { sheet.comments = { rows: {} }; } let row = sheet.comments.rows[ranges[0]]; if (!row) { sheet.comments.rows[ranges[0]] = {}; sheet.comments.rows[ranges[0]].cells = {}; } sheet.comments.rows[ranges[0]].cells[ranges[1]] = value; } updateEdgesOnBound() { this.refreshEdges(true); } clearComment() { let addr1 = this.base.ssObj.getActiveSheet().activeCell; let ranges1 = ej.spreadsheet.getIndexesFromAddress(addr1); this.removeComment(ranges1); } insertNote() { let addr = this.base.ssObj.getActiveSheet().activeCell; let ranges = ej.spreadsheet.getIndexesFromAddress(addr); this.renderComment(ranges); } refreshEdges(fromScratch, rowIdx, colIdx, size) { let sheet = this.ssObj.biz.getActiveSheet(); if (sheet.comments) { let rows = Object.keys(sheet.comments.rows); for (let i = 0; i < rows.length; i++) { let cols = Object.keys(sheet.comments.rows[rows[i]].cells); for (let j = 0; j < cols.length; j++) { let range = [parseInt(rows[i]), parseInt(cols[j])]; if (size == undefined) { fromScratch ? this.renderCommentEdge(range) : this.positionCommentEdge(range, this.getEdgeElem(range)); } else { let div = this.getEdgeElem(range); if (rowIdx != undefined) { range[0] > rowIdx && (div.style.top = (parseInt(div.style.top) + size) + 'px'); } else { range[1] >= colIdx && (div.style.left = (parseInt(div.style.left) + size) + 'px'); } } } } } } getRotationElem() { this.textRotationObj = new ej.splitbuttons.DropDownButton({ cssClass: 'e-align-ddb', iconCss: 'e-icons e-left-icon', items: [{ iconCss: 'e-icons biz_rotate_0', tooltipText: 'sadfdas' }, { iconCss: 'e-icons biz_rotate_45' }, { iconCss: 'e-icons biz_rotate_-45' }, { iconCss: 'e-icons biz_rotate_90' }, { iconCss: 'e-icons biz_rotate_-90' }, { iconCss: 'biz-deg-dd' }], beforeOpen: (args) => { let children = args.element.children; let range = this.ssObj.biz.getIndexes(); let sheet = this.ssObj.biz.getActiveSheet(); let cellObj = ej.spreadsheet.getCell(range[0], range[1], sheet) || {}; let rotation = cellObj.rotation || 0; let lastchild = args.element.lastElementChild; children[0].title = 'None'; children[1].title = 'Tilt up'; children[2].title = 'Tilt down'; children[3].title = 'Rotate up'; children[4].title = 'Rotate down'; children[5].title = 'Custom angle'; let elemMap = { '0': children[0], '45': children[1], '-45': children[2], '90': children[3], '-90': children[4] }; elemMap[rotation.toString()] && elemMap[rotation].classList.add('e-selected'); let data = ['-90', '-75', '-60', '-45', '-30', '-15', '0', '15', '30', '45', '60', '75', '90']; lastchild.innerHTML = ''; this.textRotationddObj = new ej.dropdowns.DropDownList({ dataSource: data, width: '70px', value: rotation.toString(), select: (e) => { this.setRotation(this.ssObj.biz.getIndexes(), parseInt(e.itemData.value)); this.textRotationddObj.destroy(); this.lastSelectedDeg = null; this.textRotationObj.toggle(); }, }); this.textRotationddObj.appendTo(lastchild.firstElementChild); lastchild.style.display = "inline-block"; lastchild.firstElementChild.style.top = "-3px"; }, select: (args) => { this.lastSelectedDeg = args.item.iconCss; if (args.item.iconCss !== 'biz-deg-dd') { let action = args.item.iconCss.split('e-icons ')[1].split('biz_rotate_')[1]; this.setRotation(this.ssObj.biz.getIndexes(), parseInt(action)); } }, beforeClose: (e) => { if (this.lastSelectedDeg === 'biz-deg-dd') { e.cancel = true; } else { this.textRotationddObj.destroy(); } } }); this.textRotationObj.createElement = this.ssObj.createElement; this.textRotationObj.appendTo(this.ssObj.createElement('button', { id: this.ssObj.element.id + '_text_rotate' })); return this.textRotationObj.element; } setRotation(range, deg) { let sheet = this.ssObj.biz.getActiveSheet(); for (let i = range[0]; i <= range[2]; i++) { if (!sheet.rows[i]) { return; } for (let j = range[1]; j <= range[3]; j++) { let cellObj = ej.spreadsheet.getCell(i, j, sheet) || {}; if (cellObj.value) { let td = this.ssObj.getCell(i, j); let obj = this.generateRotElem(cellObj, deg, td); this.ssObj.setRowHeight(obj.height, i); td.innerHTML = ''; td.appendChild(obj.element); } cellObj.rotation = deg; this.ssObj.biz.setCell(i, j, sheet, cellObj); this.setRotationObj([i, j], deg); } } this.base.autofill.updateAutofill(); } generateRotElem(cellObj, deg, td) { let root = ej.base.createElement('div', { className: 'biz-text-of-root' }); let text = ej.base.createElement('div', { className: 'biz-text-of' }); text.innerHTML = cellObj.value; root.appendChild(text); text.style.transform = 'rotate(' + (deg * -1) + 'deg)'; this.setStyles(text, td, cellObj); document.body.appendChild(root); let pos = text.getBoundingClientRect(); let parentPos = text.parentElement.getBoundingClientRect(); let left = (parentPos.width - pos.width) / 2; root.remove(); root = ej.base.createElement('div', { className: 'biz-text-rotate-root' }); root.style.height = pos.height + 3 + 'px'; root.style.width = pos.width + 3 + 'px'; text = ej.base.createElement('div', { className: 'biz-text-rotate' }); text.innerHTML = cellObj.value; this.setStyles(text, td, cellObj); if (deg < 0) { root.classList.add('biz-text-rev'); } root.appendChild(text); text.style.transform = 'rotate(' + (deg * -1) + 'deg)'; text.style.lineHeight = pos.height + 3 + 'px'; text.style.marginLeft = left * -1 + 2 + 'px'; return { element: root, height: pos.height + 2, width: pos.width + 2 }; } setStyles(element, td, cellObj) { let styles = ['fontFamily', 'fontSize', 'fontWeight']; let computed = getComputedStyle(td); styles.forEach((s) => { element.style[s] = computed[s]; }); cellObj.style && Object.keys(cellObj.style).forEach((s) => { element.style[s] = cellObj.style[s]; }); } removeRotation(ranges) { let sheet = this.ssObj.biz.getActiveSheet(); let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {}; delete cell.rotation; } setRotationObj(ranges, value) { let sheet = this.ssObj.biz.getActiveSheet(); if (!sheet.rotation) { sheet.rotation = { rows: {} }; } let row = sheet.rotation.rows[ranges[0]]; if (!row) { sheet.rotation.rows[ranges[0]] = {}; sheet.rotation.rows[ranges[0]].cells = {}; } sheet.rotation.rows[ranges[0]].cells[ranges[1]] = value; } bfCellRender(args) { this.bfCellRender1(args); } cellEdit(args) { let editElem = this.ssObj.element.querySelector('.e-spreadsheet-edit'); this.isFormulaEdit = false; let content = this.ssObj.element.querySelector('.e-sheet-content'); let newElem = ej.base.createElement('div', { spellcheck: 'false', className: 'biz-m-edit', id: this.ssObj.element.id + '_rte' }); let sheet = this.ssObj.biz.getActiveSheet(); let ranges = this.ssObj.biz.getIndexes(); let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {}; this.prevEditStyle = cell.style ? JSON.parse(JSON.stringify(cell.style)) : null; let formatValue = cell.value || ''; let isFormat = !this.isSingleFormat(formatValue); let formula = cell.formula && cell.formula.length; if (isFormat && !formula) { editElem.textContent = ""; } newElem.style.top = (parseInt(editElem.style.top)) + 'px'; newElem.style.left = (parseInt(editElem.style.left, 10)) + 'px'; newElem.style.minWidth = editElem.style.minWidth; newElem.style.maxWidth = editElem.style.maxWidth; newElem.style.minHeight = editElem.style.minHeight; newElem.style.maxHeight = editElem.style.maxHeight; newElem.setAttribute('spellcheck', 'false'); content.appendChild(newElem); this.rteObj = new ej.richtexteditor.RichTextEditor({ cssClass: 'biz-rte', fontFamily: { default: 'Calibri', }, fontSize: { default: '11pt' }, width: 'auto', height: '17px', toolbarSettings: { items: ['Bold', 'Italic', 'Underline', 'StrikeThrough', 'FontName', 'FontSize', 'FontColor', 'BackgroundColor' ] }, created: () => { let rteContent = newElem.querySelector('.e-content'); setTimeout(() => { if (parseInt(editElem.style.height)) { rteContent.style.minHeight = editElem.style.height; rteContent.style.height = editElem.style.height + 1; } let value = editElem.innerHTML; let styles = this.getStyles(cell); if (value.length) { this.rteObj.value = '

' + value + '

'; } else if (isFormat) { this.rteObj.value = formatValue.startsWith('' + formatValue + '

'; } else { this.setRTEStyles(cell, rteContent); let styles = this.getStyles(cell); this.rteObj.value = styles ? '

' + formatValue + '

' : '

' + formatValue + '

'; } this.rteObj.dataBind(); editElem.textContent = this.rteObj.getText(); let el = this.rteObj.element.querySelector('.e-content'); !formula && this.setCaret(el); formula && this.rteObj.element.classList.add('biz-hide'); this.rteObj.on("toolbar-updated", this.rteToolbarUpdate, this); }, 10); this.rteObj.element.addEventListener('keydown', this.keyRTDown.bind(this)); this.rteObj.element.addEventListener('keyup', this.keyRTUp.bind(this)); } }); this.rteObj.appendTo(newElem); this.clearRTCell(ranges); } rteToolbarUpdate(args) { let id = this.ssObj.element.id + '_'; let elem = this.ssObj.element.querySelector('#' + id + 'italic'); args.italic ? elem.classList.add('e-active') : elem.classList.remove('e-active'); elem = this.ssObj.element.querySelector('#' + id + 'bold'); args.bold ? elem.classList.add('e-active') : elem.classList.remove('e-active'); elem = this.ssObj.element.querySelector('#' + id + 'underline'); args.underline ? elem.classList.add('e-active') : elem.classList.remove('e-active'); elem = this.ssObj.element.querySelector('#' + id + 'line-through'); args.strikethrough ? elem.classList.add('e-active') : elem.classList.remove('e-active'); if (args.fontname) { } if (args.fontsize) { } } cellSave(args) { if (this.rteObj && !this.rteObj.isDestroyed) { let editElem = this.ssObj.element.querySelector('.e-spreadsheet-edit'); let sheet = this.ssObj.biz.getActiveSheet(); let ranges = this.ssObj.biz.getIndexes(); let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {}; let rteValue = this.rteObj.getHtml(); let value = rteValue; let hardCode = false; let spt = value.split('
'); if (spt.length > 1 && spt[spt.length - 1] === '

') { value = this.replaceLast('
', '', value); } if (rteValue === '


') { value = editElem.textContent; hardCode = true; } if (!(cell.formula && cell.formula.length)) { if (this.isSingleFormat(value)) { value = this.rteObj.getText(); cell.value = value; this.ssObj.biz.setCell(ranges[0], ranges[1], sheet, cell); } else { cell.style = this.prevEditStyle; value = this.replaceAll(value, '', ''); value = this.replaceAll(value, '', ''); args.value = value; cell.value = value; this.ssObj.biz.setCell(ranges[0], ranges[1], sheet, cell); this.refreshMultiCellValue(ranges); this.base.download.ssAutoSave({ action: "imageincell", changedValues: [{ row: ranges[0], cell: ranges[1], cellinfo: cell }] }, this.base, true); } } this.rteObj.off("toolbar-updated", this.rteToolbarUpdate); this.rteObj.element.classList.remove('biz-hide'); this.rteObj.destroy(); this.rteObj.element.removeEventListener('keydown', this.keyRTDown.bind(this)); this.rteObj.element.removeEventListener('keyup', this.keyRTUp.bind(this)); this.ssObj.element.querySelector('.biz-m-edit').remove(); } else { if (!this.isSingleFormat(args.value)) { this.refreshMultiCellValue(ej.spreadsheet.getIndexesFromAddress(args.address)); } } } replaceLast(find, replace, string) { var lastIndex = string.lastIndexOf(find); if (lastIndex === -1) { return string; } var beginString = string.substring(0, lastIndex); var endString = string.substring(lastIndex + find.length); return beginString + replace + endString; } escapeRegExp(string) { return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); } replaceAll(str, find, replace) { return str.replace(new RegExp(this.escapeRegExp(find), 'g'), replace); } rtDragnDrop(args) { } keyRTDown(e) { if (this.ssObj.isEdit) { let editElem = this.ssObj.element.querySelector('.e-spreadsheet-edit'); if (!this.isFormulaEdit) { let value = this.rteObj.getText(); editElem.innerHTML = value; } } } keyRTUp(e) { if (this.ssObj.isEdit) { let editElem = this.ssObj.element.querySelector('.e-spreadsheet-edit'); if (!this.isFormulaEdit) { let value = this.rteObj.getText(); editElem.innerHTML = value; if (value != '\n') { editElem.innerHTML = value; } } } } keyUp(e) { if (this.ssObj.isEdit && this.isFormulaEdit) { let editElem = this.ssObj.element.querySelector('.e-spreadsheet-edit'); if (editElem.innerHTML.charAt(0) !== '=') { this.isFormulaEdit = false; this.rteObj.element.classList.remove('biz-hide'); this.rteObj.value = '

' + editElem.innerHTML + '

'; let el = this.rteObj.element.querySelector('.e-content'); this.setCaret(el); } } if (e.target.classList.contains('e-text-findNext-short')) { let value = e.target.value; let ranges = this.ssObj.biz.getIndexes(); let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], this.ssObj.biz.getActiveSheet()) || {}; let cellValue = cell.value ? cell.value : ''; if (value.length && cellValue.indexOf(value) < 0) { let findObj = { "findOpt": "next", "isCSen": false, "isEMatch": false, "mode": "Sheet", "name": "findNext", "searchBy": "By Row", "sheetIndex": 0 }; findObj.value = value; this.ssObj.workbookfindAndReplaceModule.findNext(findObj); } } } applyCustomCellSave(ranges, value) { let sheet = this.ssObj.getActive; } actionComplete(args) { if (args.eventArgs && args.eventArgs.address) { this.refreshMultiCellValue(ej.spreadsheet.getIndexesFromAddress(args.eventArgs.address)); } if (args.action == "clipboard" && args.eventArgs.copiedInfo.isCut) { this.refreshMultiCellValue(args.eventArgs.copiedInfo.range); } if (args.action == "autofill") { let rngIndexes = this.base.getIndexesFromAddress(args.eventArgs.fillRange); this.refreshMultiCellValue(rngIndexes); } } refreshMultiCellValue(ranges) { let sheet = this.ssObj.biz.getActiveSheet(); for (let i = ranges[0]; i <= ranges[2]; i++) { for (let j = ranges[1]; j <= ranges[3]; j++) { let td = this.ssObj.getCell(ranges[0], ranges[1]); let cellObj = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {}; if (cellObj && cellObj.value && !this.isSingleFormat(cellObj.value)) { td.innerHTML = cellObj.value; td.removeAttribute('style'); } else if (!cellObj.value) { td.innerHTML = ''; } } } } clearRTCell(range) { var td = this.ssObj.getCell(range[0], range[1]); td.innerHTML = ""; } updateRTCell(ranges, value) { var td = this.ssObj.getCell(ranges[0], ranges[1]); if (value) { this.renderRTCell(td, value); } } bfCellRender1(args) { let value; if (args && args.cell && args.cell.value) { value = args.cell.value; if (value && !this.isSingleFormat(value)) { this.renderRTCell(args.element, value); } } } afterCellRender(rowIdx, colIdx, sheet, cellObj) { let value = cellObj.value; var td = this.ssObj.getCell(rowIdx, colIdx); if (value && !this.isSingleFormat(value)) { this.renderRTCell(td, value); } else if (!value) { td.innerHTML = ''; } } renderRTCell(element, value) { if (value.indexOf(''; } } getStyles(cell) { if (cell.style) { let str = ''; let styles = Object.keys(cell.style); for (let i = 0; i < styles.length; i++) { str = str + ' ' + this.camelToSnake(styles[i]) + ' : ' + cell.style[styles[i]] + ' ;'; } return str; } return null; } setRTEStyles(cell, elem) { if (cell.style) { let styles = Object.keys(cell.style); for (let i = 0; i < styles.length; i++) { elem.style[this.camelToSnake(styles[i])] = cell.style[styles[i]]; } } } camelToSnake(string) { return string.replace(/([a-z]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase(); } mdown3(e) { let target = ej.base.closest(e.target, '.e-toolbar-item'); let id = this.ssObj.element.id + '_rte_toolbar_'; if (this.ssObj.isEdit && target) { let btn = target.firstElementChild; let action = btn.id.split(this.ssObj.element.id + '_')[1]; switch (action) { case 'bold': this.rteObj.element.querySelector('#' + id + 'Bold').click(); break; case 'italic': this.rteObj.element.querySelector('#' + id + 'Italic').click(); break; case 'line-through': this.rteObj.element.querySelector('#' + id + 'StrikeThrough').click(); break; case 'underline': this.rteObj.element.querySelector('#' + id + 'Underline').click(); break; case 'wrap': case 'currencyformat': case 'percentageformat': this.ssObj.endEdit(); break; } } } actionBegin(args) { if (this.ssObj.isEdit && args.action === 'format' && args.args.eventArgs.requestType === 'NumberFormat') { this.ssObj.endEdit(); } } ssCreated() { setTimeout(() => { this.ssObj.ribbonModule.fontNameDdb.addEventListener('select', this.fontChange.bind(this)); this.ssObj.ribbonModule.fontSizeDdb.addEventListener('select', this.fontSizeChange.bind(this)); this.ssObj.on('biz-dd', this.rtDragnDrop, this); this.ssObj.on('setCellFormat', this.formatChange, this); }, 500); } fontChange(args) { (this.ssObj.isEdit) && (this.rteObj.formatter.editorManager.execCommand('Font', 'FontName', undefined, () => { }, args.item.text, null, "#" + this.ssObj.element.id + "_rte iframe")); } fontSizeChange(args) { (this.ssObj.isEdit) && (this.rteObj.formatter.editorManager.execCommand('Font', 'FontSize', undefined, () => { }, args.item.text + 'pt', null, "#" + this.ssObj.element.id + "_rte iframe")); } hexToRgb(hex) { var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : null; } formatChange(args) { if (this.ssObj.isEdit) { let key = Object.keys(args.style)[0]; if (args.style.color) { let rgb = this.hexToRgb(args.style.color); this.rteObj.formatter.editorManager.execCommand('Font', 'FontColor', undefined, () => { }, "rgba(" + rgb.r + "," + rgb.g + "," + rgb.b + ",1)", null, "#" + this.ssObj.element.id + "_rte iframe"); } if (args.style.backgroundColor || key.indexOf('border') > -1 || args.style.textAlign || args.style.verticalAlign) { this.stopAndApply(args, key); } } } stopAndApply(args, key) { this.ssObj.endEdit(); let ranges = this.ssObj.biz.getIndexes(); let sheet = this.ssObj.biz.getActiveSheet(); let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {}; if (!cell.style) { cell.style = {}; } cell.style[key] = args.style[key]; this.ssObj.biz.setCell(ranges[0], ranges[1], sheet, cell); } getFormatValue(ranges) { let sheet = this.ssObj.biz.getActiveSheet(); return sheet.richtexts && sheet.richtexts.rows[ranges[0]] && sheet.richtexts.rows[ranges[0]].cells[ranges[1]] && sheet.richtexts.rows[ranges[0]].cells[ranges[1]]; } removeRTData(ranges) { let sheet = this.ssObj.biz.getActiveSheet(); delete sheet.richtexts.rows[ranges[0]].cells[ranges[1]]; } addRTData(ranges, value) { let sheet = this.ssObj.biz.getActiveSheet(); if (!sheet.richtexts) { sheet.richtexts = { rows: {} }; } let row = sheet.richtexts.rows[ranges[0]]; if (!row) { sheet.richtexts.rows[ranges[0]] = {}; sheet.richtexts.rows[ranges[0]].cells = {}; } sheet.richtexts.rows[ranges[0]].cells[ranges[1]] = value; } isSingleFormat(value) { let tags = value ? value.toString().split('