12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520 |
- 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 = '<input type="text" tabindex="1" id="rotate_options" />';
- 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 = '<p style="' + styles + '">' + value + '</p>';
- }
- else if (isFormat) {
- this.rteObj.value = formatValue.startsWith('<p') ? formatValue : '<p>' + formatValue + '</p>';
- }
- else {
- this.setRTEStyles(cell, rteContent);
- let styles = this.getStyles(cell);
- this.rteObj.value = styles ? '<p style="' + styles + '">' + formatValue + '</p>' : '<p style="font-size:11pt">' + formatValue + '</p>';
- }
- 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('<br>');
- if (spt.length > 1 && spt[spt.length - 1] === '</p>') {
- value = this.replaceLast('<br>', '', value);
- }
- if (rteValue === '<p><br></p>') {
- 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, '<em>', '<i>');
- value = this.replaceAll(value, '</em>', '</i>');
- 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 = '<p>' + editElem.innerHTML + '</p>';
- 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('<p') === 0) {
- element.innerHTML = value;
- element.firstElementChild.setAttribute('style', "font-size:inherit");
- }
- else {
- element.innerHTML = '<p style="font-size: inherit">' + value + '</p>';
- }
- }
- 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('</') : [];
- return tags.length <= 2 && !(value.includes('<Font'));
- }
- setCaret(el) {
- const selection = window.getSelection();
- const range = document.createRange();
- selection.removeAllRanges();
- range.selectNodeContents(el);
- range.collapse(false);
- selection.addRange(range);
- el.focus();
- }
- static Instance() {
- if (this.instance === undefined) {
- this.instance = new FormatPainter();
- }
- return this.instance;
- }
- }
- Sheets.FormatPainter = FormatPainter;
- })(Sheets = Components.Sheets || (Components.Sheets = {}));
- })(Components = Collaboration.Components || (Collaboration.Components = {}));
- })(Collaboration = Apps.Collaboration || (Apps.Collaboration = {}));
- })(Apps = Unibase.Apps || (Unibase.Apps = {}));
- })(Unibase || (Unibase = {}));
|