all files / document-editor/implementation/dialogs/ spellCheck-dialog.js

25.72% Statements 71/276
28.57% Branches 28/98
25.93% Functions 7/27
25.72% Lines 71/276
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372   101× 101× 101× 101× 101× 101× 101× 101×     101×       101×                 101×                 101×                     101×                     101×                                                               101× 101×               14462×                                                                                                                                                                                                                                                                                   179×       179×       179× 179×       179×       179× 179× 179×   179×     179×     179×     179×     179×     179×       179×       179×       179×       179×       179×       179×       179×       179×       179×       179×       179×       179×       179×       179×       179×       179×       179×       179×              
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-buttons", "@syncfusion/ej2-lists", "../viewer/page", "@syncfusion/ej2-popups"], function (require, exports, ej2_base_1, ej2_buttons_1, ej2_lists_1, page_1, ej2_popups_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var SpellCheckDialog = (function () {
        function SpellCheckDialog(documentHelper) {
            var _this = this;
            this.ignoreClickHandler = this.onIgnoreClick.bind(this);
            this.ignoreAllClickHandler = this.onIgnoreAllClick.bind(this);
            this.addToDictClickHandler = this.onAddToDictClick.bind(this);
            this.selectHandlerClickHandler = this.onSelectHandlerClick.bind(this);
            this.changeButtonClickHandler = this.onChangeButtonClick.bind(this);
            this.onChangeAllButtonClickHandler = this.onChangeAllButtonClick.bind(this);
            this.selectHandler = function (args) {
                _this.selectedText = args.text;
            };
            this.onCancelButtonClick = function () {
                _this.documentHelper.clearSelectionHighlight();
                _this.documentHelper.hideDialog();
            };
            this.onIgnoreClicked = function () {
                if (!ej2_base_1.isNullOrUndefined(_this.elementBox)) {
                    ej2_popups_1.showSpinner(_this.documentHelper.dialog.element);
                    _this.parent.spellCheckerModule.manageReplace('Ignore Once', _this.elementBox);
                    _this.removeErrors();
                    _this.parent.spellCheckerModule.checkForNextError();
                    ej2_popups_1.hideSpinner(_this.documentHelper.dialog.element);
                }
            };
            this.onIgnoreAllClicked = function () {
                if (!ej2_base_1.isNullOrUndefined(_this.elementBox)) {
                    ej2_popups_1.showSpinner(_this.documentHelper.dialog.element);
                    var text = _this.elementBox.text;
                    _this.parent.spellCheckerModule.handleIgnoreAllItems({ element: _this.elementBox, text: text });
                    _this.parent.spellCheckerModule.checkForNextError();
                    ej2_popups_1.hideSpinner(_this.documentHelper.dialog.element);
                }
            };
            this.addToDictClicked = function () {
                if (!ej2_base_1.isNullOrUndefined(_this.elementBox)) {
                    ej2_popups_1.showSpinner(_this.documentHelper.dialog.element);
                    _this.parent.spellCheckerModule.handleAddToDictionary({ element: _this.elementBox, text: _this.elementBox.text });
                    if (_this.parent.spellCheckerModule.errorWordCollection.containsKey(_this.errorText)) {
                        _this.parent.spellCheckerModule.errorWordCollection.remove(_this.errorText);
                    }
                    _this.parent.spellCheckerModule.checkForNextError();
                    _this.documentHelper.hideDialog();
                }
            };
            this.changeButtonClicked = function () {
                if (!ej2_base_1.isNullOrUndefined(_this.selectedText)) {
                    _this.isSpellChecking = true;
                    ej2_popups_1.showSpinner(_this.documentHelper.dialog.element);
                    _this.parent.spellCheckerModule.manageReplace(_this.selectedText, _this.elementBox);
                    _this.removeErrors();
                    _this.parent.spellCheckerModule.checkForNextError();
                    ej2_popups_1.hideSpinner(_this.documentHelper.dialog.element);
                    _this.selectedText = undefined;
                }
            };
            this.changeAllButtonClicked = function () {
                if (!ej2_base_1.isNullOrUndefined(_this.selectedText)) {
                    _this.isSpellChecking = true;
                    _this.parent.spellCheckerModule.isChangeAll = true;
                    ej2_popups_1.showSpinner(_this.documentHelper.dialog.element);
                    var elements = _this.parent.spellCheckerModule.errorWordCollection.get(_this.errorText);
                    for (var i = 0; i < elements.length; i++) {
                        if (elements[i] instanceof page_1.ErrorTextElementBox && !elements[i].ischangeDetected) {
                            _this.parent.spellCheckerModule.manageReplace(_this.selectedText, elements[i]);
                        }
                        else if (elements[i] instanceof page_1.TextElementBox) {
                            var matchResults = _this.parent.spellCheckerModule.getMatchedResultsFromElement(elements[i]);
                            var results = matchResults.textResults;
                            var markIndex = (elements[i].ischangeDetected) ?
                                elements[i].start.offset : elements[i].line.getOffset(elements[i], 0);
                            _this.parent.searchModule.textSearch.updateMatchedTextLocation(matchResults.matches, results, matchResults.elementInfo, 0, elements[i], false, null, markIndex);
                            for (var j = 0; j < results.length; j++) {
                                var element = _this.parent.spellCheckerModule.createErrorElementWithInfo(results.innerList[j], elements[i]);
                                _this.parent.spellCheckerModule.manageReplace(_this.selectedText, element);
                            }
                        }
                    }
                    if (_this.parent.spellCheckerModule.errorWordCollection.containsKey(_this.errorText)) {
                        _this.parent.spellCheckerModule.errorWordCollection.remove(_this.errorText);
                    }
                    _this.parent.spellCheckerModule.checkForNextError();
                    _this.documentHelper.hideDialog();
                    ej2_popups_1.hideSpinner(_this.documentHelper.dialog.element);
                    _this.parent.spellCheckerModule.isChangeAll = false;
                    _this.selectedText = undefined;
                }
            };
            this.documentHelper = documentHelper;
            ej2_popups_1.createSpinner({ target: this.documentHelper.dialog.element, cssClass: 'e-spin-overlay' });
        }
        Object.defineProperty(SpellCheckDialog.prototype, "parent", {
            get: function () {
                return this.documentHelper.owner;
            },
            enumerable: true,
            configurable: true
        });
        SpellCheckDialog.prototype.getModuleName = function () {
            return 'SpellCheckDialog';
        };
        SpellCheckDialog.prototype.onSelectHandlerClick = function (args) {
            this.selectHandler(args);
        };
        SpellCheckDialog.prototype.onIgnoreClick = function () {
            this.onIgnoreClicked();
        };
        SpellCheckDialog.prototype.removeErrors = function () {
            if (!ej2_base_1.isNullOrUndefined(this.errorText) && this.parent.spellCheckerModule.errorWordCollection.containsKey(this.errorText)) {
                var textElement = this.parent.spellCheckerModule.errorWordCollection.get(this.errorText);
                textElement.splice(0, 1);
                if (textElement.length === 0) {
                    this.parent.spellCheckerModule.errorWordCollection.remove(this.errorText);
                }
            }
            if (this.parent.spellCheckerModule.errorWordCollection.length === 0) {
                this.documentHelper.hideDialog();
            }
        };
        SpellCheckDialog.prototype.onIgnoreAllClick = function () {
            this.onIgnoreAllClicked();
        };
        SpellCheckDialog.prototype.onAddToDictClick = function () {
            this.addToDictClicked();
        };
        SpellCheckDialog.prototype.onChangeButtonClick = function () {
            this.changeButtonClicked();
        };
        SpellCheckDialog.prototype.onChangeAllButtonClick = function () {
            this.changeAllButtonClicked();
        };
        SpellCheckDialog.prototype.show = function (error, elementbox) {
            this.target = undefined;
            this.localValue = new ej2_base_1.L10n('documenteditor', this.documentHelper.owner.defaultLocale);
            this.localValue.setLocale(this.documentHelper.owner.locale);
            if (!this.target) {
                this.updateSuggestionDialog(error, elementbox);
            }
        };
        SpellCheckDialog.prototype.updateSuggestionDialog = function (error, elementBox) {
            var _this = this;
            this.elementBox = elementBox;
            var suggestions;
            if (this.isSpellChecking) {
                this.parent.spellCheckerModule.callSpellChecker(this.parent.spellCheckerModule.languageID, error, false, true).then(function (data) {
                    var jsonObject = JSON.parse(data);
                    suggestions = jsonObject.Suggestions;
                    _this.isSpellChecking = false;
                    _this.handleRetrievedSuggestion(error, suggestions);
                });
            }
            else {
                error = this.parent.spellCheckerModule.manageSpecialCharacters(error, undefined, true);
                suggestions = this.parent.spellCheckerModule.errorSuggestions.containsKey(error) ?
                    this.parent.spellCheckerModule.errorSuggestions.get(error) : [];
                this.handleRetrievedSuggestion(error, suggestions);
            }
        };
        SpellCheckDialog.prototype.handleRetrievedSuggestion = function (error, suggestions) {
            error = this.parent.spellCheckerModule.manageSpecialCharacters(error, undefined, true);
            this.initSpellCheckDialog(this.localValue, error, suggestions);
            if (this.documentHelper.selection.caret.style.display !== 'none') {
                this.documentHelper.selection.caret.style.display = 'none';
            }
            this.documentHelper.dialog.header = this.localValue.getConstant('Spelling Editor');
            this.documentHelper.dialog.height = 'auto';
            this.documentHelper.dialog.width = 'auto';
            this.documentHelper.dialog.content = this.target;
            this.documentHelper.dialog.beforeOpen = this.documentHelper.updateFocus;
            this.documentHelper.dialog.buttons = [{
                    click: this.onCancelButtonClick,
                    buttonModel: { content: this.localValue.getConstant('Cancel'), cssClass: 'e-control e-flat', isPrimary: true }
                }];
            this.documentHelper.dialog.dataBind();
            this.documentHelper.dialog.show();
            ej2_popups_1.hideSpinner(this.documentHelper.dialog.element);
        };
        SpellCheckDialog.prototype.initSpellCheckDialog = function (localValue, error, suggestion, isRtl) {
            var id = this.documentHelper.owner.containerId + '_add_SpellCheck';
            this.target = ej2_base_1.createElement('div', { id: id, className: 'e-de-insert-spellchecker' });
            this.errorText = error;
            this.textContainer = ej2_base_1.createElement('div', {
                className: 'e-de-dlg-sub-header', innerHTML: localValue.getConstant('Spelling')
            });
            this.target.appendChild(this.textContainer);
            this.spellContainer = ej2_base_1.createElement('div', { className: 'e-de-spellcheck-error-container' });
            this.listviewDiv = ej2_base_1.createElement('div', { className: 'e-de-dlg-spellcheck-listview' });
            this.spellContainer.appendChild(this.listviewDiv);
            this.spellingListView = new ej2_lists_1.ListView({
                dataSource: [error],
                cssClass: 'e-dlg-spellcheck-listitem'
            });
            this.spellingListView.appendTo(this.listviewDiv);
            this.buttonDiv = ej2_base_1.createElement('div', { className: 'e-de-spellcheck-btncontainer' });
            this.spellContainer.appendChild(this.buttonDiv);
            this.ignoreButtonElement = ej2_base_1.createElement('button', { innerHTML: localValue.getConstant('Ignore') });
            this.buttonDiv.appendChild(this.ignoreButtonElement);
            this.ignoreButtonElement.setAttribute('aria-label', localValue.getConstant('Ignore'));
            this.ignorebutton = new ej2_buttons_1.Button({ cssClass: 'e-control e-de-ok-button e-de-spellcheck-btn' });
            this.ignorebutton.appendTo(this.ignoreButtonElement);
            this.ignoreButtonElement.addEventListener('click', this.ignoreClickHandler);
            this.ignoreAllButtonElement = ej2_base_1.createElement('button', { innerHTML: localValue.getConstant('Ignore All') });
            this.ignoreAllButtonElement.setAttribute('aria-label', localValue.getConstant('Ignore All'));
            this.buttonDiv.appendChild(this.ignoreAllButtonElement);
            this.ignoreAllbutton = new ej2_buttons_1.Button({ cssClass: 'e-control e-de-ok-button e-de-spellcheck-btn' });
            this.ignoreAllbutton.appendTo(this.ignoreAllButtonElement);
            this.ignoreAllButtonElement.addEventListener('click', this.ignoreAllClickHandler);
            this.addDictButtonElement = ej2_base_1.createElement('button', { innerHTML: localValue.getConstant('Add to Dictionary') });
            this.addDictButtonElement.setAttribute('aria-label', localValue.getConstant('Add to Dictionary'));
            this.buttonDiv.appendChild(this.addDictButtonElement);
            this.addDictButton = new ej2_buttons_1.Button({ cssClass: 'e-control e-de-ok-button e-de-spellcheck-btn' });
            this.addDictButton.appendTo(this.addDictButtonElement);
            this.addDictButtonElement.addEventListener('click', this.addToDictClickHandler);
            this.target.appendChild(this.spellContainer);
            this.suggestionDiv = ej2_base_1.createElement('div', {
                className: 'e-de-dlg-sub-header', innerHTML: localValue.getConstant('Suggestions')
            });
            this.target.appendChild(this.suggestionDiv);
            this.suggestionContainer = ej2_base_1.createElement('div', { className: 'e-de-spellcheck-suggestion-container' });
            this.target.appendChild(this.suggestionContainer);
            this.suggestListDiv = ej2_base_1.createElement('div', { className: 'e-de-dlg-spellcheck-listview' });
            this.suggestListDiv.setAttribute('aria-label', localValue.getConstant('Suggestions'));
            this.suggestionContainer.appendChild(this.suggestListDiv);
            this.suggestionListView = new ej2_lists_1.ListView({
                dataSource: suggestion,
                cssClass: 'e-dlg-spellcheck-listitem'
            });
            this.suggestionListView.appendTo(this.suggestListDiv);
            this.suggestionListView.addEventListener('select', this.selectHandlerClickHandler);
            this.suggestBtnContainder = ej2_base_1.createElement('div', { className: 'e-de-spellcheck-btncontainer' });
            this.suggestionContainer.appendChild(this.suggestBtnContainder);
            this.changeButtonElement = ej2_base_1.createElement('button', { innerHTML: localValue.getConstant('Change') });
            this.changeButtonElement.setAttribute('aria-label', localValue.getConstant('Change'));
            this.suggestBtnContainder.appendChild(this.changeButtonElement);
            this.changeButton = new ej2_buttons_1.Button({ cssClass: 'e-control e-de-ok-button e-de-spellcheck-btn' });
            this.changeButton.appendTo(this.changeButtonElement);
            this.changeButtonElement.addEventListener('click', this.changeButtonClickHandler);
            this.changeAllButtonElement = ej2_base_1.createElement('button', { innerHTML: localValue.getConstant('Change All') });
            this.changeAllButtonElement.setAttribute('aria-label', localValue.getConstant('Change All'));
            this.suggestBtnContainder.appendChild(this.changeAllButtonElement);
            this.changeAllbutton = new ej2_buttons_1.Button({ cssClass: 'e-control e-de-ok-button e-de-spellcheck-btn' });
            this.changeAllbutton.appendTo(this.changeAllButtonElement);
            this.changeAllButtonElement.addEventListener('click', this.onChangeAllButtonClickHandler);
            if (ej2_base_1.isNullOrUndefined(suggestion) || suggestion.length === 0) {
                this.changeButton.disabled = true;
                this.changeAllbutton.disabled = true;
            }
        };
        SpellCheckDialog.prototype.destroy = function () {
            Iif (this.target) {
                this.target.remove();
                this.target = undefined;
            }
            Iif (this.elementBox) {
                this.elementBox.destroy();
                this.elementBox = undefined;
            }
            this.documentHelper = undefined;
            Iif (this.spellingListView) {
                this.spellingListView.destroy();
                this.spellingListView = undefined;
            }
            Iif (this.suggestionListView) {
                this.suggestionListView.destroy();
                this.suggestionListView = undefined;
            }
            this.selectedText = undefined;
            this.removeEvents();
            this.removeElements();
        };
        SpellCheckDialog.prototype.removeEvents = function () {
            Iif (this.ignoreButtonElement) {
                this.ignoreButtonElement.removeEventListener('click', this.ignoreClickHandler);
            }
            Iif (this.ignoreAllButtonElement) {
                this.ignoreAllButtonElement.removeEventListener('click', this.ignoreAllClickHandler);
            }
            Iif (this.addDictButtonElement) {
                this.addDictButtonElement.removeEventListener('click', this.addToDictClickHandler);
            }
            Iif (this.changeButtonElement) {
                this.changeButtonElement.removeEventListener('click', this.changeButtonClickHandler);
            }
            Iif (this.changeAllButtonElement) {
                this.changeAllButtonElement.removeEventListener('click', this.onChangeAllButtonClickHandler);
            }
            Iif (this.suggestionListView) {
                this.suggestionListView.removeEventListener('select', this.selectHandlerClickHandler);
            }
        };
        SpellCheckDialog.prototype.removeElements = function () {
            Iif (this.textContainer) {
                this.textContainer.remove();
                this.textContainer = undefined;
            }
            Iif (this.spellContainer) {
                this.spellContainer.remove();
                this.spellContainer = undefined;
            }
            Iif (this.listviewDiv) {
                this.listviewDiv.remove();
                this.listviewDiv = undefined;
            }
            Iif (this.buttonDiv) {
                this.buttonDiv.remove();
                this.buttonDiv = undefined;
            }
            Iif (this.ignoreButtonElement) {
                this.ignoreButtonElement.remove();
                this.ignoreButtonElement = undefined;
            }
            Iif (this.ignorebutton) {
                this.ignorebutton.destroy();
                this.ignorebutton = undefined;
            }
            Iif (this.ignoreAllButtonElement) {
                this.ignoreAllButtonElement.remove();
                this.ignoreAllButtonElement = undefined;
            }
            Iif (this.ignoreAllbutton) {
                this.ignoreAllbutton.destroy();
                this.ignoreAllbutton = undefined;
            }
            Iif (this.addDictButtonElement) {
                this.addDictButtonElement.remove();
                this.addDictButtonElement = undefined;
            }
            Iif (this.addDictButton) {
                this.addDictButton.destroy();
                this.addDictButton = undefined;
            }
            Iif (this.suggestionDiv) {
                this.suggestionDiv.remove();
                this.suggestionDiv = undefined;
            }
            Iif (this.suggestionContainer) {
                this.suggestionContainer.remove();
                this.suggestionContainer = undefined;
            }
            Iif (this.suggestListDiv) {
                this.suggestListDiv.remove();
                this.suggestListDiv = undefined;
            }
            Iif (this.suggestBtnContainder) {
                this.suggestBtnContainder.remove();
                this.suggestBtnContainder = undefined;
            }
            Iif (this.changeButtonElement) {
                this.changeButtonElement.remove();
                this.changeButtonElement = undefined;
            }
            Iif (this.changeButton) {
                this.changeButton.destroy();
                this.changeButton = undefined;
            }
            Iif (this.changeAllButtonElement) {
                this.changeAllButtonElement.remove();
                this.changeAllButtonElement = undefined;
            }
            Iif (this.changeAllbutton) {
                this.changeAllbutton.destroy();
                this.changeAllbutton = undefined;
            }
        };
        return SpellCheckDialog;
    }());
    exports.SpellCheckDialog = SpellCheckDialog;
});