all files / document-editor-container/ribbon/developer-tab/ form-fields-group.js

95.74% Statements 45/47
78.57% Branches 11/14
100% Functions 10/10
95.74% Lines 45/47
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   14× 14×     141×         14× 14× 14×                               14× 14× 14×                                                                     68×   68× 68× 68×     67×       14×       14× 14×        
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.FORM_FIELDS_GROUP = '_form_fields_group';
    exports.FORM_FIELDS_ID = '_form_fields';
    exports.TEXT_FORM = '_text_form';
    exports.CHECKBOX = '_checkbox';
    exports.DROPDOWN = '_dropdown';
    var FormFieldsGroup = (function () {
        function FormFieldsGroup(container) {
            this.container = container;
            this.ribbonId = this.container.element.id + '_ribbon';
        }
        Object.defineProperty(FormFieldsGroup.prototype, "documentEditor", {
            get: function () {
                return this.container.documentEditor;
            },
            enumerable: true,
            configurable: true
        });
        FormFieldsGroup.prototype.getGroupModel = function () {
            var locale = this.container.localObj;
            var id = this.ribbonId + exports.FORM_FIELDS_GROUP;
            return {
                id: id,
                header: locale.getConstant('Form Fields'),
                orientation: 'Row',
                cssClass: 'e-formfields-group',
                enableGroupOverflow: true,
                overflowHeader: locale.getConstant('Form Fields'),
                collections: [
                    {
                        items: [
                            this.getFormFieldsDropDownModel()
                        ]
                    }
                ]
            };
        };
        FormFieldsGroup.prototype.getFormFieldsDropDownModel = function () {
            var locale = this.container.localObj;
            var id = this.ribbonId;
            return {
                type: 'DropDown',
                id: id + exports.FORM_FIELDS_ID,
                dropDownSettings: {
                    iconCss: 'e-icons e-de-formfield',
                    content: locale.getConstant('Form Fields'),
                    items: [
                        {
                            text: locale.getConstant('Text Form'),
                            iconCss: 'e-icons e-de-textform',
                            id: id + exports.TEXT_FORM
                        },
                        {
                            text: locale.getConstant('Check Box'),
                            iconCss: 'e-icons e-de-checkbox-form',
                            id: id + exports.CHECKBOX
                        },
                        {
                            text: locale.getConstant('DropDown'),
                            iconCss: 'e-icons e-de-dropdownform',
                            id: id + exports.DROPDOWN
                        }
                    ],
                    select: this.onFormFieldsDropDownSelect.bind(this)
                },
                ribbonTooltipSettings: {
                    content: locale.getConstant('Insert form fields')
                }
            };
        };
        FormFieldsGroup.prototype.onFormFieldsDropDownSelect = function (args) {
            var _this = this;
            var id = this.ribbonId;
            if (args.item.id === id + exports.TEXT_FORM) {
                this.documentEditor.editorModule.insertFormField('Text');
            }
            else if (args.item.id === id + exports.CHECKBOX) {
                this.documentEditor.editorModule.insertFormField('CheckBox');
            }
            else Eif (args.item.id === id + exports.DROPDOWN) {
                this.documentEditor.editorModule.insertFormField('DropDown');
            }
            setTimeout(function () {
                _this.documentEditor.focusIn();
            }, 30);
        };
        FormFieldsGroup.prototype.updateSelection = function () {
            var isHeaderFooter = this.documentEditor.selection.contextType.indexOf('Header') >= 0 ||
                this.documentEditor.selection.contextType.indexOf('Footer') >= 0;
            var ribbon = this.container.ribbon.ribbon;
            Eif (ribbon) {
                if (isHeaderFooter) {
                    ribbon.disableItem(this.ribbonId + exports.FORM_FIELDS_ID);
                }
                else {
                    ribbon.enableItem(this.ribbonId + exports.FORM_FIELDS_ID);
                }
            }
        };
        FormFieldsGroup.prototype.destroy = function () {
            Iif (this.formFieldDropDown) {
                this.formFieldDropDown.destroy();
                this.formFieldDropDown = undefined;
            }
            this.container = undefined;
            this.ribbonId = undefined;
        };
        return FormFieldsGroup;
    }());
    exports.FormFieldsGroup = FormFieldsGroup;
});