all files / common/conditionalformatting/ conditional-formatting.js

99.39% Statements 326/328
89.92% Branches 107/119
100% Functions 30/30
99.39% Lines 326/328
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 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663   24× 24× 24× 24× 24× 24×   1847×   22×   22×       22× 22×                                                       22× 22×                   15×               22× 22×   44×                             15× 13× 13×     13× 13× 13×   13× 13×       19× 20×           18×   18×     17×   28× 28× 34×   28×         28× 28× 28× 34× 34×     38×     38× 34× 34×       34× 34× 34×     34× 34× 34×     34× 34× 34× 34× 34× 34× 34× 34×       34× 34× 34× 34× 34× 34×       34× 34× 34× 34×           34×   34×         34×           34×                 34× 34× 34×         34× 34×           34×                 34× 34× 34× 34× 34× 34× 34×     34× 34× 34× 34×           34× 34× 34× 34× 34×     34× 34× 34×     34× 34× 34× 34× 34× 34× 34× 34×     34× 34× 34× 34× 34× 34×     34× 34× 34× 34×   34× 34×     34× 34×     34× 34× 34× 34×           34× 34× 34× 34× 34×   38×   34× 34× 34× 34× 34×       34× 69×   69× 69×           34× 34× 34×             34× 34× 34×                   34× 34× 34×             34× 34× 34×   34×           34× 34× 34×           34× 34× 34×               34× 34× 34×           34× 34× 34×             34× 34× 34×       34× 34× 34×             34× 34×                     34× 34× 34× 34× 34× 34× 34×         34× 34× 34× 34× 34× 34× 34× 34× 34×         34× 34× 34× 34×         34× 34× 34×             19677× 19677× 55278×   19677×   904× 904×           68×                                                                               68× 65×                     19× 19× 19× 19× 19×   19× 19×   19× 19× 19×   25× 31× 31×   31× 31×       22× 22× 26×   22× 22× 22×   48× 48× 48×     47×          
define(["require", "exports", "@syncfusion/ej2-popups", "@syncfusion/ej2-base", "@syncfusion/ej2-buttons", "@syncfusion/ej2-inputs", "@syncfusion/ej2-dropdowns", "@syncfusion/ej2-buttons", "../../common/base/css-constant", "../../common/base/constant"], function (require, exports, ej2_popups_1, ej2_base_1, ej2_buttons_1, ej2_inputs_1, ej2_dropdowns_1, ej2_buttons_2, cls, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ConditionalFormatting = (function () {
        function ConditionalFormatting(parent) {
            this.parent = parent;
            this.parent.conditionalFormattingModule = this;
            this.parentID = this.parent.element.id;
            this.fontColor = [];
            this.backgroundColor = [];
            this.newFormat = [];
        }
        ConditionalFormatting.prototype.getModuleName = function () {
            return 'conditionalFormatting';
        };
        ConditionalFormatting.prototype.createDialog = function () {
            if (ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document) !== null) {
                ej2_base_1.remove(ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document));
            }
            var conditionalFormattingElement = ej2_base_1.createElement('div', {
                id: this.parentID + 'conditionalformatting',
                className: cls.FORMAT_DIALOG
            });
            this.parent.element.appendChild(conditionalFormattingElement);
            var buttonModel = [
                {
                    click: this.addButtonClick.bind(this),
                    isFlat: false,
                    buttonModel: {
                        cssClass: (this.parent.isAdaptive ? (cls.FORMAT_ROUND_BUTTON + ' ' + cls.FORMAT_CONDITION_BUTTON) :
                            cls.FORMAT_CONDITION_BUTTON) + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                        iconCss: cls.ICON + ' ' + cls.ADD_ICON_CLASS,
                        content: this.parent.isAdaptive ? '' : this.parent.localeObj.getConstant('condition')
                    }
                },
                {
                    click: this.applyButtonClick.bind(this),
                    isFlat: false,
                    buttonModel: {
                        isPrimary: true, cssClass: cls.FORMAT_APPLY_BUTTON + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                        content: this.parent.localeObj.getConstant('apply')
                    }
                },
                {
                    click: this.cancelButtonClick.bind(this),
                    isFlat: false,
                    buttonModel: {
                        cssClass: cls.FORMAT_CANCEL_BUTTON + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''),
                        content: this.parent.localeObj.getConstant('cancel')
                    }
                }
            ];
            var dialog;
            if (this.parent.isAdaptive) {
                dialog = new ej2_popups_1.Dialog({
                    animationSettings: { effect: 'Zoom' }, isModal: true, width: '100%', height: '100%',
                    showCloseIcon: false, closeOnEscape: false, enableRtl: this.parent.enableRtl, locale: this.parent.locale,
                    enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                    position: { X: 'center', Y: 'center' }, allowDragging: true, buttons: buttonModel,
                    beforeOpen: this.beforeOpen.bind(this), close: this.removeDialog.bind(this),
                    cssClass: this.parent.cssClass, header: this.parent.localeObj.getConstant('conditionalFormatting'), target: document.body
                });
            }
            else {
                dialog = new ej2_popups_1.Dialog({
                    allowDragging: true, position: { X: 'center', Y: this.parent.element.offsetTop }, buttons: buttonModel,
                    beforeOpen: this.beforeOpen.bind(this), close: this.removeDialog.bind(this),
                    cssClass: this.parent.cssClass, isModal: true, closeOnEscape: true,
                    enableRtl: this.parent.enableRtl, locale: this.parent.locale, enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
                    showCloseIcon: true, header: this.parent.localeObj.getConstant('conditionalFormatting'), target: this.parent.element
                });
            }
            dialog.isStringTemplate = true;
            dialog.appendTo(conditionalFormattingElement);
        };
        ConditionalFormatting.prototype.beforeOpen = function () {
            ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document).querySelector('.' + cls.DIALOG_HEADER)
                .setAttribute('title', this.parent.localeObj.getConstant('conditionalFormatting'));
        };
        ConditionalFormatting.prototype.addButtonClick = function () {
            var _this = this;
            var format = {
                conditions: 'LessThan',
                value1: 0,
                applyGrandTotals: true,
                style: {
                    backgroundColor: 'white',
                    color: 'black',
                    fontFamily: 'Arial',
                    fontSize: '12px'
                }
            };
            var conditionalFormating = this;
            this.parent.trigger(events.conditionalFormatting, format, function (observedArgs) {
                conditionalFormating.refreshConditionValues();
                _this.destroyColorPickers();
                conditionalFormating.newFormat.push(observedArgs);
                conditionalFormating.addFormat();
            });
        };
        ConditionalFormatting.prototype.applyButtonClick = function () {
            if (this.refreshConditionValues()) {
                this.parent.setProperties({ dataSourceSettings: { conditionalFormatSettings: this.newFormat } }, true);
                var actionInfo = {
                    conditionalFormattingInfo: this.parent.dataSourceSettings.conditionalFormatSettings
                };
                this.parent.actionObj.actionInfo = actionInfo;
                Eif (this.parent.dataSourceSettings.values.length > 0) {
                    this.parent.renderPivotGrid();
                }
                var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document), ej2_popups_1.Dialog);
                dialog.close();
            }
        };
        ConditionalFormatting.prototype.cancelButtonClick = function () {
            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document), ej2_popups_1.Dialog);
            dialog.close();
            this.newFormat = [];
        };
        ConditionalFormatting.prototype.refreshConditionValues = function () {
            for (var i = 0; i < this.newFormat.length; i++) {
                if (ej2_base_1.select('#' + this.parentID + 'conditionvalue1' + i, document).value === '' ||
                    ej2_base_1.select('#' + this.parentID + 'conditionvalue2' + i, document).value === '') {
                    if (ej2_base_1.select('#' + this.parentID + 'conditionvalue1' + i, document).value === '') {
                        ej2_base_1.select('#' + this.parentID + 'conditionvalue1' + i, document).focus();
                    }
                    else {
                        ej2_base_1.select('#' + this.parentID + 'conditionvalue2' + i, document).focus();
                    }
                    return false;
                }
                this.newFormat[i].value1 =
                    Number(ej2_base_1.select('#' + this.parentID + 'conditionvalue1' + i, document).value);
                this.newFormat[i].value2 =
                    Number(ej2_base_1.select('#' + this.parentID + 'conditionvalue2' + i, document).value);
            }
            return true;
        };
        ConditionalFormatting.prototype.addFormat = function () {
            var format = ej2_base_1.createElement('div', { id: this.parentID + 'formatDiv', className: cls.FORMAT_NEW });
            for (var i = 0; i < this.newFormat.length; i++) {
                format.appendChild(this.createDialogElements(i));
            }
            if (this.newFormat.length === 0) {
                var outerDiv = this.createDialogElements();
                var element = ej2_base_1.createElement('p', {
                    id: this.parentID + 'emptyFormat',
                    className: cls.EMPTY_FORMAT
                });
                element.innerText = this.parent.localeObj.getConstant('emptyFormat');
                outerDiv.appendChild(element);
                format.appendChild(outerDiv);
            }
            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document), ej2_popups_1.Dialog);
            dialog.setProperties({ 'content': format }, false);
            for (var i = 0; i < this.newFormat.length; i++) {
                this.renderDropDowns(i);
                this.renderColorPicker(i);
            }
        };
        ConditionalFormatting.prototype.createDialogElements = function (i) {
            var outerDiv = ej2_base_1.createElement('div', {
                id: this.parentID + 'outerDiv' + i, className: cls.FORMAT_OUTER
            });
            if (i !== undefined) {
                var format = this.newFormat[i];
                var button = ej2_base_1.createElement('button', {
                    id: this.parentID + 'removeButton' + i, className: cls.FORMAT_DELETE_BUTTON,
                    attrs: { type: 'button', 'title': this.parent.localeObj.getConstant('delete') }
                });
                outerDiv.appendChild(button);
                var innerDiv = ej2_base_1.createElement('div', { id: this.parentID + 'innerDiv' + i, className: cls.FORMAT_INNER });
                var valueTable = ej2_base_1.createElement('table', {
                    id: this.parentID + '_valueTable' + i, className: cls.FORMAT_TABLE, attrs: { 'role': 'table' }
                });
                var valueTableRow = ej2_base_1.createElement('tr');
                var valueTableElements = ej2_base_1.createElement('td');
                var valuelabel = ej2_base_1.createElement('span', {
                    id: this.parentID + 'valuelabel' + i, className: cls.FORMAT_VALUE_LABEL
                });
                valuelabel.innerText = this.parent.localeObj.getConstant('value');
                valueTableElements.appendChild(valuelabel);
                valueTableRow.appendChild(valueTableElements);
                valueTable.appendChild(valueTableRow);
                valueTableRow = ej2_base_1.createElement('tr');
                valueTableElements = ej2_base_1.createElement('td');
                var measureDropdown = ej2_base_1.createElement('div', { id: this.parentID + 'measure' + i });
                var measureInput = ej2_base_1.createElement('input', {
                    id: this.parentID + 'measureinput' + i,
                    attrs: { 'type': 'text', 'tabindex': '0' }
                });
                measureDropdown.appendChild(measureInput);
                valueTableElements.appendChild(measureDropdown);
                valueTableRow.appendChild(valueTableElements);
                valueTableElements = ej2_base_1.createElement('td');
                var conditionDropdown = ej2_base_1.createElement('div', { id: this.parentID + 'condition' + i });
                var conditionInput = ej2_base_1.createElement('input', {
                    id: this.parentID + 'conditioninput' + i,
                    attrs: { 'type': 'text', 'tabindex': '0' }
                });
                conditionDropdown.appendChild(conditionInput);
                valueTableElements.appendChild(conditionDropdown);
                valueTableRow.appendChild(valueTableElements);
                valueTableElements = ej2_base_1.createElement('td', {
                    attrs: {
                        style: 'display:table'
                    },
                    className: cls.FORMAT_INPUT_VALUE
                });
                var formatValueClassName = !(format.conditions === 'Between' || format.conditions === 'NotBetween') ?
                    cls.HIDDEN : '';
                var conditionValueParentDiv = ej2_base_1.createElement('div', {
                    attrs: {
                        style: 'display: table-row;'
                    }
                });
                var conditionValue1WrapperDiv = ej2_base_1.createElement('div', {
                    id: this.parentID + 'ConditionValue1' + i,
                    attrs: {
                        style: 'display: table-cell;'
                    }
                });
                var value1 = ej2_base_1.createElement('input', {
                    id: this.parentID + 'conditionvalue1' + i,
                    attrs: {
                        'type': 'text',
                        'tabindex': '0',
                        'value': !ej2_base_1.isNullOrUndefined(format.value1) ? format.value1.toString() : '0',
                        'placeholder': this.parent.localeObj.getConstant('emptyInput')
                    }
                });
                conditionValue1WrapperDiv.appendChild(value1);
                conditionValueParentDiv.appendChild(conditionValue1WrapperDiv);
                var valuespan = ej2_base_1.createElement('span', {
                    id: this.parentID + 'valuespan' + i,
                    className: cls.FORMAT_VALUE_SPAN + ' ' + formatValueClassName,
                    innerHTML: '&'
                });
                conditionValueParentDiv.appendChild(valuespan);
                var conditionValue2WrapperDiv = ej2_base_1.createElement('div', {
                    id: this.parentID + 'ConditionValue2' + i,
                    attrs: {
                        style: 'display: table-cell;'
                    }
                });
                var value2 = ej2_base_1.createElement('input', {
                    id: this.parentID + 'conditionvalue2' + i,
                    attrs: {
                        'type': 'text',
                        'tabindex': '0',
                        'value': !ej2_base_1.isNullOrUndefined(format.value2) ? format.value2.toString() : '0',
                        'placeholder': this.parent.localeObj.getConstant('emptyInput')
                    }
                });
                conditionValue2WrapperDiv.appendChild(value2);
                conditionValueParentDiv.appendChild(conditionValue2WrapperDiv);
                valueTableElements.appendChild(conditionValueParentDiv);
                valueTableRow.appendChild(valueTableElements);
                valueTable.appendChild(valueTableRow);
                innerDiv.appendChild(valueTable);
                var grandTotalTable = ej2_base_1.createElement('table', {
                    id: this.parentID + '_grandTotalTable' + i, className: cls.FORMAT_TABLE + ' ' + cls.GRANDTOTAL_CHECKBOX_TABLE, attrs: { 'role': 'table' }
                });
                var grandTotalTableRow = ej2_base_1.createElement('tr');
                var grandTotalTableElements = ej2_base_1.createElement('td');
                grandTotalTable.appendChild(grandTotalTableRow);
                var checkBoxInput = ej2_base_1.createElement('input', {
                    id: this.parentID + 'grandtotalcheckbox' + i,
                    attrs: {
                        'type': 'checkbox', 'tabindex': '0'
                    }
                });
                grandTotalTableElements.appendChild(checkBoxInput);
                grandTotalTableRow.appendChild(grandTotalTableElements);
                grandTotalTable.appendChild(grandTotalTableRow);
                innerDiv.appendChild(grandTotalTable);
                var formatTable = ej2_base_1.createElement('table', {
                    id: this.parentID + '_formatTable' + i, className: cls.FORMAT_TABLE, attrs: { 'role': 'table' }
                });
                var formatTableRow = ej2_base_1.createElement('tr');
                var formatTableElements = ej2_base_1.createElement('td');
                var formatlabel = ej2_base_1.createElement('span', {
                    id: this.parentID + 'formatlabel' + i, className: cls.FORMAT_LABEL
                });
                formatlabel.innerText = this.parent.localeObj.getConstant('formatLabel');
                formatTableElements.appendChild(formatlabel);
                formatTableRow.appendChild(formatTableElements);
                formatTable.appendChild(formatTableRow);
                formatTableRow = ej2_base_1.createElement('tr');
                formatTableElements = ej2_base_1.createElement('td');
                var fontNameDropdown = ej2_base_1.createElement('div', { id: this.parentID + 'fontname' + i });
                var fontNameInput = ej2_base_1.createElement('input', {
                    id: this.parentID + 'fontnameinput' + i, attrs: { 'type': 'text', 'tabindex': '0' }
                });
                fontNameDropdown.appendChild(fontNameInput);
                formatTableElements.appendChild(fontNameDropdown);
                formatTableRow.appendChild(formatTableElements);
                formatTableElements = ej2_base_1.createElement('td');
                var fontSizeDropdown = ej2_base_1.createElement('div', { id: this.parentID + 'fontsize' + i });
                var fontSizeInput = ej2_base_1.createElement('input', {
                    id: this.parentID + 'fontsizeinput' + i, attrs: { 'type': 'text', 'tabindex': '0' }
                });
                fontSizeDropdown.appendChild(fontSizeInput);
                formatTableElements.appendChild(fontSizeDropdown);
                formatTableRow.appendChild(formatTableElements);
                if (this.parent.isAdaptive) {
                    formatTable.appendChild(formatTableRow);
                    formatTableRow = ej2_base_1.createElement('tr');
                    formatTable.appendChild(formatTableRow);
                    formatTableRow = ej2_base_1.createElement('tr');
                }
                formatTableElements = ej2_base_1.createElement('td');
                var colorPicker1 = ej2_base_1.createElement('input', {
                    id: this.parentID + 'fontcolor' + i, attrs: { 'type': 'color', 'tabindex': '0' }, className: cls.FORMAT_FONT_COLOR
                });
                formatTableElements.appendChild(colorPicker1);
                var colorPicker2 = ej2_base_1.createElement('input', {
                    id: this.parentID + 'backgroundcolor' + i, attrs: { 'type': 'color', 'tabindex': '0' }, className: cls.FORMAT_BACK_COLOR
                });
                formatTableElements.appendChild(colorPicker2);
                formatTableRow.appendChild(formatTableElements);
                formatTableElements = ej2_base_1.createElement('td');
                var valuePreview = ej2_base_1.createElement('input', {
                    id: this.parentID + 'valuepreview' + i, className: cls.INPUT + ' ' + cls.FORMAT_VALUE_PREVIEW,
                    attrs: {
                        'tabindex': '-1', 'readonly': 'true', 'value': '123.45'
                    }
                });
                formatTableElements.appendChild(valuePreview);
                formatTableRow.appendChild(formatTableElements);
                formatTable.appendChild(formatTableRow);
                innerDiv.appendChild(formatTable);
                outerDiv.appendChild(innerDiv);
            }
            return outerDiv;
        };
        ConditionalFormatting.prototype.renderDropDowns = function (i) {
            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document), ej2_popups_1.Dialog);
            var dialogElement = dialog.element;
            var format = this.newFormat[i];
            var fields = [];
            fields.push({
                index: 0, name: this.parent.localeObj.getConstant('AllValues'),
                field: this.parent.localeObj.getConstant('AllValues')
            });
            for (var i_1 = 0; i_1 < this.parent.dataSourceSettings.values.length; i_1++) {
                var caption = this.parent.dataSourceSettings.values[i_1].caption ||
                    this.parent.dataSourceSettings.values[i_1].name;
                caption = this.parent.enableHtmlSanitizer ? ej2_base_1.SanitizeHtmlHelper.sanitize(caption) : caption;
                fields.push({
                    index: i_1 + 1,
                    name: caption,
                    field: this.parent.dataSourceSettings.values[i_1].name
                });
            }
            var value = ej2_base_1.isNullOrUndefined(format.measure) ? this.parent.localeObj.getConstant('AllValues') : format.measure;
            var fieldsDropDown = [];
            fieldsDropDown[i] = new ej2_dropdowns_1.DropDownList({
                dataSource: fields, fields: { text: 'name', value: 'field' },
                value: value, width: '100%',
                cssClass: this.parent.cssClass,
                popupHeight: '200px', popupWidth: 'auto', locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                change: this.measureChange.bind(this, i)
            });
            fieldsDropDown[i].isStringTemplate = true;
            fieldsDropDown[i].appendTo(ej2_base_1.select('#' + this.parentID + 'measureinput' + i, dialogElement));
            var conditions = [
                { value: 'LessThan', name: this.parent.localeObj.getConstant('LessThan') },
                { value: 'LessThanOrEqualTo', name: this.parent.localeObj.getConstant('LessThanOrEqualTo') },
                { value: 'GreaterThan', name: this.parent.localeObj.getConstant('GreaterThan') },
                { value: 'GreaterThanOrEqualTo', name: this.parent.localeObj.getConstant('GreaterThanOrEqualTo') },
                { value: 'Equals', name: this.parent.localeObj.getConstant('Equals') },
                { value: 'NotEquals', name: this.parent.localeObj.getConstant('NotEquals') },
                { value: 'Between', name: this.parent.localeObj.getConstant('Between') },
                { value: 'NotBetween', name: this.parent.localeObj.getConstant('NotBetween') }
            ];
            value = ej2_base_1.isNullOrUndefined(format.conditions) ? 'LessThan' : format.conditions;
            var conditionsDropDown = [];
            conditionsDropDown[i] = new ej2_dropdowns_1.DropDownList({
                dataSource: conditions, fields: { value: 'value', text: 'name' },
                value: value, width: '100%',
                cssClass: this.parent.cssClass,
                popupHeight: '200px', popupWidth: 'auto', locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                change: this.conditionChange.bind(this, i)
            });
            conditionsDropDown[i].isStringTemplate = true;
            conditionsDropDown[i].appendTo(ej2_base_1.select('#' + this.parentID + 'conditioninput' + i, dialogElement));
            var formatValueClassName = !(this.newFormat[i].conditions === 'Between' || this.newFormat[i].conditions === 'NotBetween') ?
                cls.HIDDEN : '';
            var conditionValue1 = new ej2_inputs_1.TextBox({
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                cssClass: cls.FORMAT_VALUE1 + ' ' + this.parent.cssClass,
                width: 'auto'
            });
            conditionValue1.isStringTemplate = true;
            conditionValue1.appendTo(ej2_base_1.select('#' + this.parentID + 'conditionvalue1' + i, dialogElement));
            var conditionValue2 = new ej2_inputs_1.TextBox({
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                cssClass: cls.FORMAT_VALUE2 + ' ' + formatValueClassName + ' ' + this.parent.cssClass,
                width: 'auto'
            });
            conditionValue2.isStringTemplate = true;
            conditionValue2.appendTo(ej2_base_1.select('#' + this.parentID + 'conditionvalue2' + i, dialogElement));
            var grandTotalCheckBox = new ej2_buttons_2.CheckBox({
                label: this.parent.localeObj.getConstant('applyToGrandTotal'),
                checked: this.newFormat[i].applyGrandTotals,
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                change: this.onCheckChange.bind(this, i),
                cssClass: this.parent.cssClass
            });
            grandTotalCheckBox.isStringTemplate = true;
            grandTotalCheckBox.appendTo(ej2_base_1.select('#' + this.parentID + 'grandtotalcheckbox' + i, dialogElement));
            var fontNames = [
                { index: 0, name: 'Arial' }, { index: 1, name: 'San Serif' }, { index: 2, name: 'Impact' },
                { index: 3, name: 'Trebuchet MS' }, { index: 4, name: 'Serif' }, { index: 5, name: 'Verdana' },
                { index: 6, name: 'Courier New' }, { index: 7, name: 'Times New Roman' }, { index: 8, name: 'Tahoma' },
                { index: 9, name: 'Gerogia' }
            ];
            value = ej2_base_1.isNullOrUndefined(format.style.fontFamily) ? 'Arial' : format.style.fontFamily;
            var fontNameDropDown = [];
            fontNameDropDown[i] = new ej2_dropdowns_1.DropDownList({
                dataSource: fontNames, fields: { text: 'name' },
                value: value, width: '100%',
                cssClass: this.parent.cssClass,
                popupHeight: '200px', popupWidth: 'auto', locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                change: this.fontNameChange.bind(this, i)
            });
            fontNameDropDown[i].isStringTemplate = true;
            fontNameDropDown[i].appendTo(ej2_base_1.select('#' + this.parentID + 'fontnameinput' + i, dialogElement));
            var fontSize = [
                { index: 0, name: '9px' }, { index: 1, name: '10px' }, { index: 2, name: '11px' }, { index: 3, name: '12px' },
                { index: 4, name: '13px' }, { index: 5, name: '14px' }, { index: 6, name: '15px' }, { index: 6, name: '16px' }
            ];
            value = ej2_base_1.isNullOrUndefined(format.style.fontSize) ? '12px' : format.style.fontSize;
            var fontSizeDropDown = [];
            fontSizeDropDown[i] = new ej2_dropdowns_1.DropDownList({
                dataSource: fontSize, fields: { text: 'name' }, popupHeight: '200px', popupWidth: 'auto',
                value: value, width: '100%',
                change: this.fontSizeChange.bind(this, i),
                locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                cssClass: this.parent.cssClass
            });
            fontSizeDropDown[i].isStringTemplate = true;
            fontSizeDropDown[i].appendTo(ej2_base_1.select('#' + this.parentID + 'fontsizeinput' + i, dialogElement));
        };
        ConditionalFormatting.prototype.conditionChange = function (i, args) {
            this.newFormat[i].conditions = args.value;
            var valuespan = ej2_base_1.select('#' + this.parentID + 'valuespan' + i, document);
            var conditionvalue2 = ej2_base_1.select('#' + this.parentID + 'conditionvalue2' + i, document);
            if (args.value === 'Between' || args.value === 'NotBetween') {
                valuespan.classList.remove(cls.HIDDEN);
                conditionvalue2.parentElement.classList.remove(cls.HIDDEN);
            }
            else {
                valuespan.classList.add(cls.HIDDEN);
                conditionvalue2.parentElement.classList.add(cls.HIDDEN);
            }
        };
        ConditionalFormatting.prototype.onCheckChange = function (i, args) {
            this.newFormat[i].applyGrandTotals = args.checked;
        };
        ConditionalFormatting.prototype.fontNameChange = function (i, args) {
            this.newFormat[i].style.fontFamily = args.value.toString();
            ej2_base_1.select('#' + this.parentID + 'valuepreview' + i, document).style.fontFamily = args.value;
        };
        ConditionalFormatting.prototype.fontSizeChange = function (i, args) {
            this.newFormat[i].style.fontSize = args.value.toString();
            ej2_base_1.select('#' + this.parentID + 'valuepreview' + i, document).style.fontSize = args.value;
        };
        ConditionalFormatting.prototype.measureChange = function (i, args) {
            this.newFormat[i].measure = args.value.toString() === this.parent.localeObj.getConstant('AllValues') ?
                undefined : args.value.toString();
        };
        ConditionalFormatting.prototype.renderColorPicker = function (i) {
            var dialog = ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document), ej2_popups_1.Dialog);
            var dialogElement = dialog.element;
            var format = this.newFormat[i];
            var value = ej2_base_1.isNullOrUndefined(format.style.color) ? 'black' : format.style.color;
            var color = value.charAt(0) === '#' && this.isHex(value.substr(1)) ? value : this.colourNameToHex(value);
            ej2_base_1.select('#' + this.parentID + 'valuepreview' + i, document).style.color = color;
            this.fontColor[i] = new ej2_inputs_1.ColorPicker({
                cssClass: cls.FORMAT_COLOR_PICKER + ' ' + cls.FORMAT_FONT_COLOR_PICKER +
                    (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''), value: color, mode: 'Palette',
                change: this.fontColorChange.bind(this, i), locale: this.parent.locale, enableRtl: this.parent.enableRtl
            });
            this.fontColor[i].isStringTemplate = true;
            this.fontColor[i].appendTo(ej2_base_1.select('#' + this.parentID + 'fontcolor' + i, dialogElement));
            ej2_base_1.addClass([this.fontColor[i].element.nextElementSibling.querySelector('.' + cls.SELECTED_COLOR)], cls.ICON);
            value = ej2_base_1.isNullOrUndefined(format.style.backgroundColor) ? 'white' : format.style.backgroundColor;
            color = value.charAt(0) === '#' && this.isHex(value.substr(1)) ? value : this.colourNameToHex(value);
            ej2_base_1.select('#' + this.parentID + 'valuepreview' + i, document).style.backgroundColor = color;
            ej2_base_1.select('#' + this.parentID + 'valuepreview' + i, document).style.fontFamily = format.style.fontFamily;
            ej2_base_1.select('#' + this.parentID + 'valuepreview' + i, document).style.fontSize = format.style.fontSize;
            this.backgroundColor[i] = new ej2_inputs_1.ColorPicker({
                cssClass: cls.FORMAT_COLOR_PICKER + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''), value: color, mode: 'Palette',
                change: this.backColorChange.bind(this, i),
                locale: this.parent.locale, enableRtl: this.parent.enableRtl
            });
            this.backgroundColor[i].isStringTemplate = true;
            this.backgroundColor[i].appendTo(ej2_base_1.select('#' + this.parentID + 'backgroundcolor' + i, dialogElement));
            ej2_base_1.addClass([this.backgroundColor[i].element.nextElementSibling.querySelector('.e-selected-color')], cls.ICON);
            var toggleBtn = new ej2_buttons_1.Button({
                iconCss: cls.ICON + ' ' + cls.FORMAT_DELETE_ICON,
                cssClass: cls.FLAT + (this.parent.cssClass ? (' ' + this.parent.cssClass) : ''), locale: this.parent.locale, enableRtl: this.parent.enableRtl,
                enableHtmlSanitizer: this.parent.enableHtmlSanitizer
            });
            toggleBtn.isStringTemplate = true;
            toggleBtn.appendTo(ej2_base_1.select('#' + this.parentID + 'removeButton' + i, dialogElement));
            toggleBtn.element.onclick = this.toggleButtonClick.bind(this, i);
        };
        ConditionalFormatting.prototype.backColorChange = function (i, args) {
            this.newFormat[i].style.backgroundColor = args.currentValue.hex;
            ej2_base_1.select('#' + this.parentID + 'valuepreview' + i, document).style.backgroundColor =
                args.currentValue.hex;
        };
        ConditionalFormatting.prototype.fontColorChange = function (i, args) {
            this.newFormat[i].style.color = args.currentValue.hex;
            ej2_base_1.select('#' + this.parentID + 'valuepreview' + i, document).style.color =
                args.currentValue.hex;
        };
        ConditionalFormatting.prototype.toggleButtonClick = function (i) {
            this.destroyColorPickers();
            this.newFormat.splice(i, 1);
            this.addFormat();
        };
        ConditionalFormatting.prototype.isHex = function (h) {
            var a = parseInt(h, 16);
            while (h.charAt(0) === '0') {
                h = h.substr(1);
            }
            return (a.toString(16) === h.toLowerCase() || (a === 0 && h === ''));
        };
        ConditionalFormatting.prototype.hexToRgb = function (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;
        };
        ConditionalFormatting.prototype.colourNameToHex = function (colour) {
            var colours = {
                'aliceblue': '#f0f8ff', 'antiquewhite': '#faebd7', 'aqua': '#00ffff', 'aquamarine': '#7fffd4',
                'azure': '#f0ffff', 'beige': '#f5f5dc', 'bisque': '#ffe4c4', 'black': '#000000',
                'blanchedalmond': '#ffebcd', 'blue': '#0000ff',
                'blueviolet': '#8a2be2', 'brown': '#a52a2a', 'burlywood': '#deb887', 'cadetblue': '#5f9ea0',
                'chartreuse': '#7fff00', 'chocolate': '#d2691e',
                'coral': '#ff7f50', 'cornflowerblue': '#6495ed', 'cornsilk': '#fff8dc', 'crimson': '#dc143c', 'cyan': '#00ffff',
                'darkblue': '#00008b', 'darkcyan': '#008b8b', 'darkgoldenrod': '#b8860b', 'darkgray': '#a9a9a9', 'darkgreen': '#006400',
                'darkkhaki': '#bdb76b', 'darkmagenta': '#8b008b', 'darkolivegreen': '#556b2f',
                'darkorange': '#ff8c00', 'darkorchid': '#9932cc', 'darkred': '#8b0000', 'darksalmon': '#e9967a', 'darkseagreen': '#8fbc8f',
                'darkslateblue': '#483d8b', 'darkslategray': '#2f4f4f', 'darkturquoise': '#00ced1',
                'darkviolet': '#9400d3', 'deeppink': '#ff1493', 'deepskyblue': '#00bfff', 'dimgray': '#696969', 'dodgerblue': '#1e90ff',
                'firebrick': '#b22222', 'floralwhite': '#fffaf0', 'forestgreen': '#228b22', 'fuchsia': '#ff00ff',
                'gainsboro': '#dcdcdc', 'ghostwhite': '#f8f8ff', 'gold': '#ffd700', 'goldenrod': '#daa520',
                'gray': '#808080', 'green': '#008000',
                'greenyellow': '#adff2f', 'honeydew': '#f0fff0', 'hotpink': '#ff69b4', 'indianred ': '#cd5c5c',
                'indigo': '#4b0082', 'ivory': '#fffff0',
                'khaki': '#f0e68c', 'lavender': '#e6e6fa', 'lavenderblush': '#fff0f5', 'lawngreen': '#7cfc00', 'lemonchiffon': '#fffacd',
                'lightblue': '#add8e6', 'lightcoral': '#f08080', 'lightcyan': '#e0ffff', 'lightgoldenrodyellow': '#fafad2',
                'lightgrey': '#d3d3d3', 'lightgreen': '#90ee90', 'lightpink': '#ffb6c1', 'lightsalmon': '#ffa07a', 'lightseagreen': '#20b2aa',
                'lightskyblue': '#87cefa', 'lightslategray': '#778899', 'lightsteelblue': '#b0c4de',
                'lightyellow': '#ffffe0', 'lime': '#00ff00', 'limegreen': '#32cd32', 'linen': '#faf0e6',
                'magenta': '#ff00ff', 'maroon': '#800000', 'mediumaquamarine': '#66cdaa', 'mediumblue': '#0000cd', 'mediumorchid': '#ba55d3',
                'mediumpurple': '#9370d8', 'mediumseagreen': '#3cb371', 'mediumslateblue': '#7b68ee',
                'mediumspringgreen': '#00fa9a', 'mediumturquoise': '#48d1cc', 'mediumvioletred': '#c71585', 'midnightblue': '#191970',
                'mintcream': '#f5fffa', 'mistyrose': '#ffe4e1', 'moccasin': '#ffe4b5', 'navajowhite': '#ffdead', 'navy': '#000080',
                'oldlace': '#fdf5e6', 'olive': '#808000', 'olivedrab': '#6b8e23', 'orange': '#ffa500', 'orangered': '#ff4500',
                'orchid': '#da70d6',
                'palegoldenrod': '#eee8aa', 'palegreen': '#98fb98', 'paleturquoise': '#afeeee', 'palevioletred': '#d87093',
                'papayawhip': '#ffefd5',
                'peachpuff': '#ffdab9', 'peru': '#cd853f', 'pink': '#ffc0cb', 'plum': '#dda0dd', 'powderblue': '#b0e0e6', 'purple': '#800080',
                'rebeccapurple': '#663399', 'red': '#ff0000', 'rosybrown': '#bc8f8f', 'royalblue': '#4169e1',
                'saddlebrown': '#8b4513', 'salmon': '#fa8072', 'sandybrown': '#f4a460', 'seagreen': '#2e8b57',
                'seashell': '#fff5ee', 'sienna': '#a0522d',
                'silver': '#c0c0c0', 'skyblue': '#87ceeb', 'slateblue': '#6a5acd', 'slategray': '#708090', 'snow': '#fffafa',
                'springgreen': '#00ff7f',
                'steelblue': '#4682b4', 'tan': '#d2b48c', 'teal': '#008080', 'thistle': '#d8bfd8', 'tomato': '#ff6347', 'turquoise': '#40e0d0',
                'violet': '#ee82ee', 'wheat': '#f5deb3', 'white': '#ffffff', 'whitesmoke': '#f5f5f5', 'yellow': '#ffff00',
                'yellowgreen': '#9acd32'
            };
            if (typeof colours[colour.toLowerCase()] !== 'undefined') {
                return colours[colour.toLowerCase()];
            }
            else if (colour.search('rgba') === 0) {
                var value = colour.substr(5).split(')')[0].split(',');
                var rgb = '';
                var a = '';
                for (var i = 0; i < value.length - 1; i++) {
                    value[i] = (+value[i]).toString(16);
                    Iif (value[i].length === 1) {
                        value[i] = '0' + value[i];
                    }
                    rgb = rgb + value[i];
                }
                a = (Math.round(+value[3] * 255)).toString(16);
                return '#' + rgb + a;
            }
            else if (colour.search('rgb') === 0) {
                var value = colour.substr(4).split(')')[0].split(',');
                var rgb = '';
                for (var i = 0; i < value.length; i++) {
                    value[i] = (+value[i]).toString(16);
                    Iif (value[i].length === 1) {
                        value[i] = '0' + value[i];
                    }
                    rgb = rgb + value[i];
                }
                return '#' + rgb;
            }
            return '#d5d5d5';
        };
        ConditionalFormatting.prototype.removeDialog = function () {
            var element = ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document);
            var dialog = element ? ej2_base_1.getInstance(element, ej2_popups_1.Dialog) : null;
            Eif (dialog && !dialog.isDestroyed) {
                this.destroyColorPickers();
                dialog.destroy();
            }
            Eif (element) {
                ej2_base_1.remove(element);
            }
            this.fontColor = [];
            this.backgroundColor = [];
            this.newFormat = [];
        };
        ConditionalFormatting.prototype.destroyColorPickers = function () {
            for (var i = 0; i < (this.newFormat ? this.newFormat.length : 0); i++) {
                Eif (this.fontColor && this.fontColor[i] && !this.fontColor[i].isDestroyed) {
                    this.fontColor[i].destroy();
                }
                Eif (this.backgroundColor && this.backgroundColor[i] && !this.backgroundColor[i].isDestroyed) {
                    this.backgroundColor[i].destroy();
                }
            }
        };
        ConditionalFormatting.prototype.showConditionalFormattingDialog = function () {
            this.newFormat = [];
            for (var i = 0; i < this.parent.dataSourceSettings.conditionalFormatSettings.length; i++) {
                this.newFormat.push(ej2_base_1.extend({}, this.parent.dataSourceSettings.conditionalFormatSettings[i].properties, null, true));
            }
            this.createDialog();
            ej2_base_1.getInstance(ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document), ej2_popups_1.Dialog).refresh();
            this.addFormat();
        };
        ConditionalFormatting.prototype.destroy = function () {
            var element = ej2_base_1.select('#' + this.parentID + 'conditionalformatting', document);
            var dialog = element ? ej2_base_1.getInstance(element, ej2_popups_1.Dialog) : null;
            if (dialog && !dialog.isDestroyed) {
                dialog.close();
            }
            else {
                return;
            }
        };
        return ConditionalFormatting;
    }());
    exports.ConditionalFormatting = ConditionalFormatting;
});