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

87.84% Statements 130/148
70.37% Branches 38/54
100% Functions 15/15
87.84% Lines 130/148
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   153× 153× 153× 153× 153×   153×                           153×                   153×   153×   14468×                                                                                                                                       208×     208×   208×   208× 208× 208×   208×   208×   208×   208×   208×          
define(["require", "exports", "@syncfusion/ej2-inputs", "@syncfusion/ej2-base", "@syncfusion/ej2-dropdowns", "../format/section-format"], function (require, exports, ej2_inputs_1, ej2_base_1, ej2_dropdowns_1, section_format_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var NotesDialog = (function () {
        function NotesDialog(documentHelper) {
            var _this = this;
            this.list = undefined;
            this.noteNumberFormat = undefined;
            this.sectionFormat = undefined;
            this.onCancelButtonClick = function () {
                _this.documentHelper.dialog.hide();
                _this.documentHelper.updateFocus();
                _this.unWireEventsAndBindings();
            };
            this.loadFontDialog = function () {
                _this.documentHelper.updateFocus();
                var format;
                var section;
                Iif (_this.sectionFormat) {
                    section = _this.sectionFormat;
                }
                else {
                    section = _this.documentHelper.owner.selectionModule.sectionFormat;
                }
                Iif (_this.documentHelper.selection.isinFootnote) {
                    var footnotesFormat = section.footNoteNumberFormat;
                    var startAt = section.initialFootNoteNumber;
                    format = _this.reversetype(footnotesFormat);
                    _this.notesList.value = format;
                    _this.startValueTextBox.value = startAt;
                }
                else {
                    var endnotesFormat = section.endnoteNumberFormat;
                    format = _this.reversetype(endnotesFormat);
                    var startAt = section.initialEndNoteNumber;
                    _this.notesList.value = format;
                    _this.startValueTextBox.value = startAt;
                }
            };
            this.onInsertFootnoteClick = function () {
                var format = new section_format_1.WSectionFormat(undefined);
                Eif (!ej2_base_1.isNullOrUndefined(_this.notesList)) {
                    var formats = (_this.notesList.value).toString();
                    var renderFormat = _this.types(formats);
                    var startValue = _this.startValueTextBox.value;
                    Eif (!ej2_base_1.isNullOrUndefined(_this.notesList)) {
                        Iif (_this.documentHelper.selection.isinFootnote) {
                            format.footNoteNumberFormat = renderFormat;
                            format.initialFootNoteNumber = startValue;
                            _this.documentHelper.owner.editorModule.onApplySectionFormat(undefined, format);
                        }
                        else {
                            format.endnoteNumberFormat = renderFormat;
                            format.initialEndNoteNumber = startValue;
                            _this.documentHelper.owner.editorModule.onApplySectionFormat(undefined, format);
                        }
                    }
                }
                _this.documentHelper.hideDialog();
            };
            this.unWireEventsAndBindings = function () {
                _this.notesList.value = undefined;
            };
            this.documentHelper = documentHelper;
        }
        NotesDialog.prototype.getModuleName = function () {
            return 'FootNotesDialog';
        };
        NotesDialog.prototype.notesDialog = function (localValue, isRtl) {
            var idName = this.documentHelper.owner.containerId + '_insert_Footnote';
            this.target = ej2_base_1.createElement('div', { id: idName, className: 'e-de-insert-footnote' });
            this.firstDiv = ej2_base_1.createElement('div');
            this.startatValue = ej2_base_1.createElement('div');
            this.footCount = ej2_base_1.createElement('input', {
                attrs: { type: 'text' }, id: this.documentHelper.owner.containerId + 'row'
            });
            this.startatValue.appendChild(this.footCount);
            this.numberFormatDiv = ej2_base_1.createElement('div', { className: 'e-de-container-row' });
            this.formatType = ej2_base_1.createElement('select', {
                id: this.target.id + '_papersize', styles: 'padding-bottom: 20px;',
                innerHTML: '<option value="1, 2, 3, ...">' + localValue.getConstant('1, 2, 3, ...') +
                    '</option><option value="a, b, c, ...">' + localValue.getConstant('a, b, c, ...') +
                    '</option><option value="A, B, C, ...">' + localValue.getConstant('A, B, C, ...') +
                    '</option><option value="I, II, III, ...">' + localValue.getConstant('I, II, III, ...') +
                    '</option><option value="i, ii, iii, ...">' + localValue.getConstant('i, ii, iii, ...') + '</option>'
            });
            this.numberFormatDiv.appendChild(this.formatType);
            this.notesList = new ej2_dropdowns_1.DropDownList({
                enableRtl: isRtl, placeholder: localValue.getConstant('Number format'),
                floatLabelType: 'Always',
                htmlAttributes: { 'aria-labelledby': localValue.getConstant('Number format') }
            });
            this.notesList.appendTo(this.formatType);
            this.firstDiv.appendChild(this.numberFormatDiv);
            this.firstDiv.appendChild(this.startatValue);
            this.target.appendChild(this.firstDiv);
            this.startValueTextBox = new ej2_inputs_1.NumericTextBox({
                format: '#',
                min: 1,
                max: 99999,
                enablePersistence: false,
                placeholder: localValue.getConstant('Start at'),
                floatLabelType: 'Always'
            });
            this.startValueTextBox.appendTo(this.footCount);
            this.footCount.setAttribute('aria-labelledby', localValue.getConstant('Start at'));
        };
        NotesDialog.prototype.show = function () {
            var localValue = new ej2_base_1.L10n('documenteditor', this.documentHelper.owner.defaultLocale);
            localValue.setLocale(this.documentHelper.owner.locale);
            if (!this.target) {
                this.notesDialog(localValue);
            }
            Eif (this.documentHelper.selection.caret.style.display !== 'none') {
                this.documentHelper.selection.caret.style.display = 'none';
            }
            Iif (this.documentHelper.selection.isinFootnote) {
                this.documentHelper.dialog.header = localValue.getConstant('Footnote');
            }
            else {
                this.documentHelper.dialog.header = localValue.getConstant('Endnote');
            }
            this.documentHelper.dialog.height = 'auto';
            this.documentHelper.dialog.width = 'auto';
            this.documentHelper.dialog.content = this.target;
            this.documentHelper.dialog.beforeOpen = this.loadFontDialog;
            this.documentHelper.dialog.buttons = [{
                    click: this.onInsertFootnoteClick,
                    buttonModel: { content: localValue.getConstant('Apply'), cssClass: 'e-flat e-table-ok', isPrimary: true }
                },
                {
                    click: this.onCancelButtonClick,
                    buttonModel: { content: localValue.getConstant('Cancel'), cssClass: 'e-flat e-table-cancel' }
                }];
            this.startValueTextBox.value = 1;
            this.documentHelper.dialog.close = this.documentHelper.updateFocus;
            this.documentHelper.dialog.dataBind();
            this.documentHelper.dialog.show();
            Eif (this.documentHelper.selection.isinEndnote) {
                var alignValue = this.endnoteListValue(this.list);
                this.notesList.index = alignValue;
            }
        };
        NotesDialog.prototype.types = function (type) {
            switch (type) {
                case '1, 2, 3, ...':
                    return 'Arabic';
                case 'A, B, C, ...':
                    return 'UpperCaseLetter';
                case 'a, b, c, ...':
                    return 'LowerCaseLetter';
                case 'I, II, III, ...':
                    return 'LowerCaseRoman';
                case 'i, ii, iii, ...':
                    return 'UpperCaseRoman';
                default:
                    return 'Arabic';
            }
        };
        NotesDialog.prototype.reversetype = function (type) {
            switch (type) {
                case 'Arabic':
                    return '1, 2, 3, ...';
                case 'UpperCaseLetter':
                    return 'A, B, C, ...';
                case 'LowerCaseLetter':
                    return 'a, b, c, ...';
                case 'UpperCaseRoman':
                    return 'I, II, III, ...';
                case 'LowerCaseRoman':
                    return 'i, ii, iii, ...';
                default:
                    return '1, 2, 3, ...';
            }
        };
        NotesDialog.prototype.endnoteListValue = function (listFocus) {
            var value;
            Iif (listFocus === 'A, B, C, ...') {
                value = 0;
            }
            else Iif (listFocus === '1, 2, 3, ...') {
                value = 1;
            }
            else Iif (listFocus === 'a, b, c, ...') {
                value = 2;
            }
            else {
                value = 3;
            }
            return value;
        };
        NotesDialog.prototype.destroy = function () {
            if (this.footCount) {
                if (this.footCount.parentElement) {
                    this.footCount.parentElement.removeChild(this.footCount);
                }
                this.footCount = undefined;
            }
            if (this.startValueTextBox) {
                this.startValueTextBox.destroy();
                this.startValueTextBox = undefined;
            }
            if (this.notesList) {
                this.notesList.destroy();
                this.notesList = undefined;
            }
            this.removeElements();
            this.footCount = undefined;
            this.documentHelper = undefined;
        };
        NotesDialog.prototype.removeElements = function () {
            if (this.firstDiv) {
                this.firstDiv.remove();
                this.firstDiv = undefined;
            }
            if (this.startatValue) {
                this.startatValue.remove();
                this.startatValue = undefined;
            }
            if (this.numberFormatDiv) {
                this.numberFormatDiv.remove();
                this.numberFormatDiv = undefined;
            }
            if (this.formatType) {
                this.formatType.remove();
                this.formatType = undefined;
            }
            if (this.target) {
                this.target.remove();
                this.target = undefined;
            }
        };
        return NotesDialog;
    }());
    exports.NotesDialog = NotesDialog;
});