Article

Add signature in field Notes

1) Create client module

define("GlbHtmlEditModule", ["ext-base", "terrasoft", "HtmlEditModule"], function(Ext, Terrasoft) {
    Ext.define("Terrasoft.controls.GlbHtmlEdit", {
        extend: "Terrasoft.HtmlEdit",
        alternateClassName: "Terrasoft.GlbHtmlEdit",
 
        tplSignature: "<br><div><span style=\"color:#7f2910;\"><i>{0}: {1}</i></span><hr></div>",
 
        signature: false,
 
        setSignature: function(value) {
            if (this.signature === value) {
                return;
            }
            this.signature = value;
        },
 
        onContentDom: function() {
            this.callParent(arguments);
            this.setSignature(false);
            var editor = this.editor;
            if (editor) {
                var editorDocument = this.editor.document;
                if (editorDocument) {
                    var el = editorDocument.$;
                    Ext.EventManager.on(el, "keypress", this.onKeyPress, this);
                }
            }
        },
 
        destroy: function() {
            var editor = this.editor;
            if (editor) {
                var editorDocument = this.editor.document;
                if (editorDocument) {
                    var el = editorDocument.$;
                    Ext.EventManager.removeListener(el, "keypress", this.onKeyPress, this);
                }
            }
            this.callParent(arguments);
        },
 
        onKeyPress: function(e) {
            if (!this.enabled || this.readonly) {
                return;
            }
            if (!this.signature && !e.isNavKeyPress() && !e.isSpecialKey()) {
                this.setSignature(true);
                var editor = this.editor;
                var selection = editor.getSelection();
                var ranges = selection.getRanges();
                var range = ranges[0];
                var currentContact = Terrasoft.SysValue.CURRENT_USER_CONTACT.displayValue;
                var date = new Date();
                var culture = Terrasoft.SysValue.CURRENT_USER_CULTURE ?
                    Terrasoft.SysValue.CURRENT_USER_CULTURE.displayValue : "";
                var signatureHtml = Ext.String.format(this.tplSignature, currentContact,
                    date.toLocaleString(culture));
                var signatureNode = CKEDITOR.dom.element.createFromHtml(signatureHtml);
                range.deleteContents();
                range.select();
                range.insertNode(signatureNode);
                var cursorNode = range.getNextNode();
                range.selectNodeContents(cursorNode);
                selection.selectRanges(ranges);
            }
        }
    });
});

 

2) On the poge add dependency GlbHtmlEditModule and in diff section change className for your field (Example: Field Notes on Contact page):

{
    "operation": "merge",
    "parentName": "NotesControlGroup",
    "propertyName": "items",
    "name": "Notes",
    "values": {
        "className": "Terrasoft.GlbHtmlEdit"
    }
}

 

3) Result

Like 1

Like

Share

0 comments
Show all comments