Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

spellcheck.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. var Unibase;
  2. (function (Unibase) {
  3. let Apps;
  4. (function (Apps) {
  5. let Collaboration;
  6. (function (Collaboration) {
  7. let Components;
  8. (function (Components) {
  9. let Sheets;
  10. (function (Sheets) {
  11. class SpellChecker {
  12. constructor() {
  13. this.dic = {};
  14. this.hederText = {};
  15. }
  16. init(base) {
  17. this.base = base;
  18. this.ssObj = this.base.ssObj;
  19. }
  20. processWords() {
  21. this.dic = {};
  22. this.words = '';
  23. let sheet = this.ssObj.biz.getActiveSheet();
  24. let rngIndexes = this.base.getIndexesFromAddress(sheet.selectedRange);
  25. for (let i = rngIndexes[0]; i <= rngIndexes[2]; i++) {
  26. if (!this.ssObj.biz.isRowAvailable(i, sheet)) {
  27. continue;
  28. }
  29. for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) {
  30. let cellObj = ej.spreadsheet.getCell(i, j, sheet);
  31. if (cellObj && cellObj.value && typeof cellObj.value !== 'number') {
  32. let value = cellObj.value.toString();
  33. let temp = value.split(' ');
  34. let values = [];
  35. for (let k = 0; k < temp.length; k++) {
  36. let val = temp[k];
  37. if (!this.dic[val]) {
  38. this.dic[val.trim()] = [{ rowIndex: i, colIndex: j }];
  39. values.push(val.trim());
  40. }
  41. else {
  42. this.dic[val.trim()].push({ rowIndex: i, colIndex: j });
  43. }
  44. }
  45. values.length && (this.words = this.words + ' ' + values.toString().replaceAll(',', ' '));
  46. }
  47. }
  48. }
  49. this.splitWords = this.words.trim().split(' ').reverse();
  50. this.requestServer();
  51. }
  52. requestServer() {
  53. var data = {
  54. LanguageID: 1033,
  55. TexttoCheck: this.words.trim(),
  56. CheckSpelling: true,
  57. CheckSuggestion: true,
  58. AddWord: false,
  59. };
  60. Unibase.Apps.Collaboration.DocumentManager.Instance().spellCheck(data).then((res) => { this.successCallback(res); });
  61. }
  62. successCallback(result) {
  63. this.ssObj.allowEditing = false;
  64. for (var i = 0; i < result.length; i++) {
  65. result[i] = JSON.parse(result[i]);
  66. }
  67. this.result = result.reverse();
  68. ej.popups.hideSpinner(this.dlgObj.element);
  69. this.dlgObj.content = `<div>
  70. <span class="biz-sc-info"></span>
  71. <div style="padding-top: 10px">
  72. <input class="biz-sc-value" type="text"/>
  73. <input type="text" class='biz-sc-sugg'/>
  74. </div>
  75. <div style="padding-top: 10px">
  76. <button type="text" class='biz-sc-change'>Change</button>
  77. <button type="text" class='biz-sc-ignore'>Ignore</button>
  78. </div>
  79. </div>`;
  80. this.dlgObj.dataBind();
  81. this.dlgObj.element.querySelector('.e-footer-content').classList.add('biz-hide');
  82. this.infoElem = this.dlgObj.element.querySelector('.biz-sc-info');
  83. this.textObj = new ej.inputs.TextBox({}, this.dlgObj.element.querySelector('.biz-sc-value'));
  84. this.ddSug = new ej.dropdowns.DropDownList({
  85. dataSource: [], select: (e) => {
  86. this.textObj.value = e.itemData.value;
  87. }
  88. }, this.dlgObj.element.querySelector('.biz-sc-sugg'));
  89. let items = [
  90. {
  91. text: 'Change all',
  92. }
  93. ];
  94. this.spanElem = this.dlgObj.element.querySelector('.biz-sc-info');
  95. this.ddChange = new ej.splitbuttons.SplitButton({ items: items, click: (e) => { this.change(); }, select: (e) => { this.changeAll(); } }, this.dlgObj.element.querySelector('.biz-sc-change'));
  96. items = [
  97. {
  98. text: 'Ignore all',
  99. }
  100. ];
  101. this.ddIgnore = new ej.splitbuttons.SplitButton({ items: items, click: (e) => { this.ignore(); }, select: (e) => { this.ignoreAll(); } }, this.dlgObj.element.querySelector('.biz-sc-ignore'));
  102. this.moveNext();
  103. }
  104. convertAsItemModel(items) {
  105. for (let i = 0; i < items.length; i++) {
  106. items[i] = { text: items[i] };
  107. }
  108. }
  109. moveNext(skipPop) {
  110. if (!this.splitWords.length) {
  111. this.dlgObj.content = 'No spelling errors';
  112. this.dlgObj.height = '95px';
  113. this.dlgObj.dataBind();
  114. this.dlgObj.element.querySelector('.e-footer-content').classList.remove('biz-hide');
  115. this.ssObj.allowEditing = true;
  116. setTimeout(() => {
  117. this.destroySpellDialog();
  118. }, 3000);
  119. return;
  120. }
  121. if (!skipPop) {
  122. this.value = this.splitWords.pop();
  123. this.spellObj = this.result.pop();
  124. this.spanElem.innerHTML = "Change <b>" + this.value + "</b> to:";
  125. }
  126. let addr = this.dic[this.value];
  127. if (this.spellObj['Suggestions'] && this.spellObj['Suggestions'].length && addr.length) {
  128. this.ssObj.selectRange(this.base.generateHeaderText(addr[0].colIndex + 1) + (addr[0].rowIndex + 1));
  129. this.ddSug.dataSource = this.spellObj['Suggestions'];
  130. this.ddSug.value = this.spellObj['Suggestions'][0];
  131. this.textObj.value = this.spellObj['Suggestions'][0];
  132. }
  133. else {
  134. delete this.dic[this.value];
  135. this.moveNext();
  136. }
  137. }
  138. change() {
  139. let addr = this.dic[this.value];
  140. let sheet = this.ssObj.biz.getActiveSheet();
  141. let cellObj = ej.spreadsheet.getCell(addr[0].rowIndex, addr[0].colIndex, sheet);
  142. let value = cellObj.value === this.value ? this.textObj.value : cellObj.value.replace(this.value, this.textObj.value);
  143. let args = { rowIdx: addr[0].rowIndex, colIdx: addr[0].colIndex, value: value, action: 'spellcheck', origin: 'biz', sheetIndex: this.base.getSheetIndex() };
  144. this.applySpellValue(addr[0].rowIndex, addr[0].colIndex, value);
  145. this.ignore();
  146. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
  147. }
  148. applySpellValue(rowIdx, colIdx, value) {
  149. let sheet = this.ssObj.biz.getActiveSheet();
  150. let cellObj = ej.spreadsheet.getCell(rowIdx, colIdx, sheet);
  151. cellObj.value = value;
  152. this.ssObj.biz.setCell(rowIdx, colIdx, sheet, cellObj);
  153. Unibase.Apps.Collaboration.Components.Common.Download.Instance().ssAutoSave({ action: "cellSave", eventArgs: { address: "sheet!" + this.base.ssObj.biz.getRange() } }, this.base, true);
  154. }
  155. changeAll() {
  156. let len = this.dic[this.value].length;
  157. for (let i = 0; i < len; i++) {
  158. this.change();
  159. }
  160. }
  161. ignore() {
  162. this.dic[this.value].shift();
  163. this.moveNext(true);
  164. }
  165. ignoreAll() {
  166. delete this.dic[this.value];
  167. this.moveNext();
  168. }
  169. renderSpellDialog() {
  170. let div = this.ssObj.element.querySelector('.biz-spelldlg') || ej.base.createElement('div', { className: 'biz-spelldlg' });
  171. this.ssObj.element.querySelector('.e-sheet-panel').appendChild(div);
  172. this.dlgObj = new ej.popups.Dialog({
  173. target: this.ssObj.element.querySelector('.e-sheet-panel'),
  174. content: '',
  175. width: '350px',
  176. height: '170px',
  177. position: { X: 'right', Y: 'top' },
  178. animationSettings: { effect: 'None' },
  179. showCloseIcon: false,
  180. buttons: [{
  181. click: this.destroySpellDialog.bind(this),
  182. buttonModel: { content: 'Close' }
  183. }],
  184. open: () => {
  185. ej.popups.createSpinner({ target: this.dlgObj.element });
  186. ej.popups.showSpinner(this.dlgObj.element);
  187. },
  188. });
  189. this.dlgObj.appendTo(div);
  190. this.processWords();
  191. }
  192. destroySpellDialog() {
  193. this.ddSug.destroy();
  194. this.ddChange.destroy();
  195. this.ddIgnore.destroy();
  196. this.dlgObj.destroy();
  197. }
  198. static Instance() {
  199. if (this.instance === undefined) {
  200. this.instance = new SpellChecker();
  201. }
  202. return this.instance;
  203. }
  204. }
  205. Sheets.SpellChecker = SpellChecker;
  206. })(Sheets = Components.Sheets || (Components.Sheets = {}));
  207. })(Components = Collaboration.Components || (Collaboration.Components = {}));
  208. })(Collaboration = Apps.Collaboration || (Apps.Collaboration = {}));
  209. })(Apps = Unibase.Apps || (Unibase.Apps = {}));
  210. })(Unibase || (Unibase = {}));