<commit_before>"use strict";

define(['js/Constants',
    'js/NodePropertyNames',
    '../../DefaultDecorator/DiagramDesigner/DefaultDecorator.DiagramDesignerWidget',
    'text!./MetaDecorator.DiagramDesignerWidget.html',
    './Attribute',
    './AttributeDetailsDialog',
    'css!./MetaDecorator.DiagramDesignerWidget'], function (CONSTANTS,
                                                          nodePropertyNames,
                                                          DefaultDecoratorDiagramDesignerWidget,
                                                          MetaDecoratorTemplate,
                                                          Attribute,
                                                          AttributeDetailsDialog) {

    var MetaDecorator,
        __parent__ = DefaultDecoratorDiagramDesignerWidget,
        __parent_proto__ = DefaultDecoratorDiagramDesignerWidget.prototype,
        DECORATOR_ID = "MetaDecorator";

    MetaDecorator = function (options) {

        var opts = _.extend( {}, options);

        __parent__.apply(this, [opts]);

        this.name = "";
        this._attributeNames = [];
        this._attributes = {};
        this._skinParts = { "$name": undefined,
                            "$attributesContainer": undefined,
                            "$addAttributeContainer": undefined };

        this.logger.debug("MetaDecorator ctor");
    };

    _.extend(MetaDecorator.prototype, __parent_proto__);
    MetaDecorator.prototype.DECORATORID = DECORATOR_ID;

    /*********************** OVERRIDE DECORATORBASE MEMBERS **************************/

    MetaDecorator.prototype.$DOMBase = $(MetaDecoratorTemplate);

    MetaDecorator.prototype.on_addTo = function () {
        var self = this;

        this._renderContent();

        // set title editable on double-click
        this._skinParts.$name.on("dblclick.editOnDblClick", null, function (event) {
            if (self.hostDesignerItem.canvas.getIsReadOnlyMode() !== true) {
                $(this).editInPlace({"class": "",
                    "onChange": function (oldValue, newValue) {
                        self._onNodeTitleChanged(oldValue, newValue);
                    }});
            }
            event.stopPropagation();
            event.preventDefault();
        });

        //set the "Add new..." editable
        this._skinParts.$addAttributeContainer.on("click", null, function (event) {
            if (self.hostDesignerItem.canvas.getIsReadOnlyMode() !== true) {
                self._onNewAttributeClick();
            }
            event.stopPropagation();
            event.preventDefault();
        });
    };

    MetaDecorator.prototype._renderContent = function () {
        var client = this._control._client,
            nodeObj = client.getNode(this._metaInfo[CONSTANTS.GME_ID]),
            self = this;

        //render GME-ID in the DOM, for debugging
        this.$el.attr({"data-id": this._metaInfo[CONSTANTS.GME_ID]});

        /* BUILD UI*/
        //find name placeholder
        this._skinParts.$name = this.$el.find(".name");
        this._skinParts.$attributesContainer = this.$el.find(".attributes");
        this._skinParts.$addAttributeContainer = this.$el.find(".add-new");

        if (this.hostDesignerItem.canvas.getIsReadOnlyMode() === true) {
            this._skinParts.$addAttributeContainer.detach();
        }

        /* FILL WITH DATA */
        if (nodeObj) {
            this.name = nodeObj.getAttribute(nodePropertyNames.Attributes.name) || "";
            this._refreshName();

            this._updateAttributes();
        }

        this._skinParts.$attributesContainer.on('dblclick', 'li', function (e) {
            var attrName = $(this).find('.n').text().replace(":", ""),
                attrNames = self._attributeNames.slice(0),
                dialog = new AttributeDetailsDialog(),
                desc = _.extend({}, nodeObj.getAttributeDescriptor(attrName));

            //pass all the other attribute names to the dialog
            attrNames.splice(self._attributeNames.indexOf(attrName), 1);

            dialog.show(desc, attrNames, function (attrDesc) {
                    self.saveAttributeDescriptor(attrName, attrDesc);
                },
                function () {
                    self.deleteAttributeDescriptor(attrName);
                }
            );

            e.stopPropagation();
            e.preventDefault();
        });
    };

    MetaDecorator.prototype.update = function () {
        var client = this._control._client,
            nodeObj = client.getNode(this._metaInfo[CONSTANTS.GME_ID]),
            newName = "";

        if (nodeObj) {
            newName = nodeObj.getAttribute(nodePropertyNames.Attributes.name) || "";

            if (this.name !== newName) {
                this.name = newName;
                this._refreshName();
            }

            this._updateAttributes();
        }<commit_msg>do not handle attribute dblclik in non-design mode<commit_after>"use strict";

define(['js/Constants',
    'js/NodePropertyNames',
    '../../DefaultDecorator/DiagramDesigner/DefaultDecorator.DiagramDesignerWidget',
    'text!./MetaDecorator.DiagramDesignerWidget.html',
    './Attribute',
    './AttributeDetailsDialog',
    'css!./MetaDecorator.DiagramDesignerWidget'], function (CONSTANTS,
                                                          nodePropertyNames,
                                                          DefaultDecoratorDiagramDesignerWidget,
                                                          MetaDecoratorTemplate,
                                                          Attribute,
                                                          AttributeDetailsDialog) {

    var MetaDecorator,
        __parent__ = DefaultDecoratorDiagramDesignerWidget,
        __parent_proto__ = DefaultDecoratorDiagramDesignerWidget.prototype,
        DECORATOR_ID = "MetaDecorator";

    MetaDecorator = function (options) {

        var opts = _.extend( {}, options);

        __parent__.apply(this, [opts]);

        this.name = "";
        this._attributeNames = [];
        this._attributes = {};
        this._skinParts = { "$name": undefined,
                            "$attributesContainer": undefined,
                            "$addAttributeContainer": undefined };

        this.logger.debug("MetaDecorator ctor");
    };

    _.extend(MetaDecorator.prototype, __parent_proto__);
    MetaDecorator.prototype.DECORATORID = DECORATOR_ID;

    /*********************** OVERRIDE DECORATORBASE MEMBERS **************************/

    MetaDecorator.prototype.$DOMBase = $(MetaDecoratorTemplate);

    MetaDecorator.prototype.on_addTo = function () {
        var self = this;

        this._renderContent();

        // set title editable on double-click
        this._skinParts.$name.on("dblclick.editOnDblClick", null, function (event) {
            if (self.hostDesignerItem.canvas.getIsReadOnlyMode() !== true) {
                $(this).editInPlace({"class": "",
                    "onChange": function (oldValue, newValue) {
                        self._onNodeTitleChanged(oldValue, newValue);
                    }});
            }
            event.stopPropagation();
            event.preventDefault();
        });

        //set the "Add new..." editable
        this._skinParts.$addAttributeContainer.on("click", null, function (event) {
            if (self.hostDesignerItem.canvas.getIsReadOnlyMode() !== true) {
                self._onNewAttributeClick();
            }
            event.stopPropagation();
            event.preventDefault();
        });
    };

    MetaDecorator.prototype._renderContent = function () {
        var client = this._control._client,
            nodeObj = client.getNode(this._metaInfo[CONSTANTS.GME_ID]),
            self = this;

        //render GME-ID in the DOM, for debugging
        this.$el.attr({"data-id": this._metaInfo[CONSTANTS.GME_ID]});

        /* BUILD UI*/
        //find name placeholder
        this._skinParts.$name = this.$el.find(".name");
        this._skinParts.$attributesContainer = this.$el.find(".attributes");
        this._skinParts.$addAttributeContainer = this.$el.find(".add-new");

        if (this.hostDesignerItem.canvas.getIsReadOnlyMode() === true) {
            this._skinParts.$addAttributeContainer.detach();
        }

        /* FILL WITH DATA */
        if (nodeObj) {
            this.name = nodeObj.getAttribute(nodePropertyNames.Attributes.name) || "";
            this._refreshName();

            this._updateAttributes();
        }

        this._skinParts.$attributesContainer.on('dblclick', 'li', function (e) {
            if (self.hostDesignerItem.canvas.getIsReadOnlyMode() !== true) {
                var attrName = $(this).find('.n').text().replace(":", ""),
                    attrNames = self._attributeNames.slice(0),
                    dialog = new AttributeDetailsDialog(),
                    desc = _.extend({}, nodeObj.getAttributeDescriptor(attrName));

                //pass all the other attribute names to the dialog
                attrNames.splice(self._attributeNames.indexOf(attrName), 1);

                dialog.show(desc, attrNames, function (attrDesc) {
                        self.saveAttributeDescriptor(attrName, attrDesc);
                    },
                    function () {
                        self.deleteAttributeDescriptor(attrName);
                    }
                );
            }

            e.stopPropagation();
            e.preventDefault();
        });
    };

    MetaDecorator.prototype.update = function () {
        var client = this._control._client,
            nodeObj = client.getNode(this._metaInfo[CONSTANTS.GME_ID]),
            newName = "";

        if (nodeObj) {
            newName = nodeObj.getAttribute(nodePropertyNames.Attributes.name) || "";

            if (this.name !== newName) {
                this.name = newName;
                this._refreshName();
            }

            this._updateAttributes();
        }
{'fraction_non_alphanumeric': 0.12576930712725828, 'fraction_numerical': 0.0003970617431010522, 'mean_word_length': 1.789313399778516, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '263312', 'n_tokens_mistral': 2537, 'n_tokens_neox': 2477, 'n_words': 396}