<commit_before>/*
 *     Copyright (c) 2012-2013 CoNWeT Lab., Universidad Politécnica de Madrid
 *     Copyright (c) 2012-2013 Center for Open Middleware
 *
 *     This file is part of Wirecloud Platform.
 *
 *     Wirecloud Platform is free software: you can redistribute it and/or
 *     modify it under the terms of the GNU Affero General Public License as
 *     published by the Free Software Foundation, either version 3 of the
 *     License, or (at your option) any later version.
 *
 *     Wirecloud is distributed in the hope that it will be useful, but WITHOUT
 *     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 *     License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with Wirecloud Platform.  If not, see
 *     <http://www.gnu.org/licenses/>.
 *
 */

/*global Draggable, gettext, interpolate, StyledElements, Wirecloud, EzWebExt, LayoutManagerFactory */

(function () {

    "use strict";

    /*************************************************************************
     * Private functions
     *************************************************************************/

    var updateErrorInfo = function updateErrorInfo() {
        var label, errorCount = this.entity.logManager.getErrorCount();
        this.log_button.setDisabled(errorCount === 0);

        label = ngettext("%(errorCount)s error", "%(errorCount)s errors", errorCount);
        label = interpolate(label, {errorCount: errorCount}, true);
        this.log_button.setTitle(label);
    };

    /*************************************************************************
     * Constructor
     *************************************************************************/
    /**
     * GenericInterface Class
     */
    var GenericInterface = function GenericInterface(extending, wiringEditor, entity, title, manager, className, isGhost) {
        if (extending === true) {
            return;
        }
        var del_button, log_button, item, type, msg, ghostNotification;

        StyledElements.Container.call(this, {'class': className}, []);

        Object.defineProperty(this, 'entity', {value: entity});
        this.editingPos = false;
        this.targetAnchorsByName = {};
        this.sourceAnchorsByName = {};
        this.targetAnchors = [];
        this.sourceAnchors = [];
        this.wiringEditor = wiringEditor;
        this.title = title;
        this.className = className;
        this.initPos = {'x': 0, 'y': 0};
        this.draggableSources = [];
        this.draggableTargets = [];
        this.isMinimized = false;
        this.minWidth = '';
        this.movement = false;
        this.numberOfSources = 0;
        this.numberOfTargets = 0;
        this.potentialArrow = null;
        // Only for minimize maximize operators.
        this.initialPos = null;
        this.isGhost = isGhost;
        this.readOnlyEndpoints = 0;
        this.readOnly = false;

        if (manager instanceof Wirecloud.ui.WiringEditor.ArrowCreator) {
            this.isMiniInterface = false;
            this.arrowCreator = manager;
        } else {
            this.isMiniInterface = true;
            this.arrowCreator = null;
        }

        // Interface buttons, not for miniInterface
        if (!this.isMiniInterface) {
            if (className == 'iwidget') {
                type = 'widget';
            } else {
                type = 'operator';
            }

            // header, sources and targets for the widget
            this.resourcesDiv = new StyledElements.BorderLayout({'class': "geContainer"});
            this.sourceDiv = this.resourcesDiv.getEastContainer();
            this.sourceDiv.addClassName("sources");
            this.targetDiv = this.resourcesDiv.getWestContainer();
            this.targetDiv.addClassName("targets");
            this.header = this.resourcesDiv.getNorthContainer();
            this.header.addClassName('header');

            this.wrapperElement.appendChild(this.resourcesDiv.wrapperElement);

            // Ghost interface
            if (isGhost) {
                this.wrapperElement.classList.add('ghost');
                ghostNotification = document.createElement("span");
                ghostNotification.classList.add('ghostNotification');
                msg = gettext('Warning: %(type)s not found!');
                msg = interpolate(msg, {type: type}, true);
                ghostNotification.textContent = msg;
                this.header.appendChild(ghostNotification);
            }

            // Widget name
            this.nameElement = document.createElement("span");
            this.nameElement.textContent = title;
            this.header.appendChild(this.nameElement);

            // Close button
            del_button = new StyledElements.StyledButton({
                'title': gettext("Remove"),
                'class': 'closebutton icon-remove',
                'plain': true
            });
            del_button.insertInto(this.header);
            del_button.addEventListener('click', function () {
                if (this.readOnly == true) {
                    return;
                }
                if (className == 'iwidget') {
                    this.wiringEditor.removeIWidget(this);
                } else {
                    this.wiringEditor.removeIOperator(this);
                }
            }.bind(this));

            // Log button
            this.log_button = new StyledElements.StyledButton({
                'plain': true,
                'class': 'logbutton icon-warning-sign'
            });
            this.log_button.addEventListener("click",
                function () {
                    var dialog = new Wirecloud.ui.LogWindowMenu(this.entity.logManager);
                    dialog.show();
                }.bind(this));
            updateErrorInfo.call(this);
            this.entity.logManager.addEventListener('newentry', updateErrorInfo.bind(this));
            this.log_button.insertInto(this.header);

            // special icon for minimized interface
            this.iconAux = document.createElement("div");
            this.iconAux.classList.add("specialIcon");
            this.iconAux.classList.add("icon-cogs");
            this.iconAux.setAttribute('title', title);
            this.resourcesDiv.wrapperElement.appendChild(this.iconAux);
            this.iconAux.addEventListener('click', function () {
                if (!this.movement) {
                    this.restore();
                }
            }.bind(this));

            // Add a menu button except on mini interfaces
            this.menu_button = new StyledElements.PopupButton({
                'title': gettext("Menu"),
                'class': 'editPos_button icon-cog',
                'plain': true
            });
            this.menu_button.insertInto(this.header);
            this.menu_button.popup_menu.append(new Wirecloud.ui.WiringEditor.GenericInterfaceSettingsMenuItems(this));

        } else { // MiniInterface
            this.header = document.createElement("div");
            this.header.classList.add('header');
            this.wrapperElement.appendChild(this.header);
            // Widget name<commit_msg>Fix problem with ghost operator/widgets<commit_after>/*
 *     Copyright (c) 2012-2013 CoNWeT Lab., Universidad Politécnica de Madrid
 *     Copyright (c) 2012-2013 Center for Open Middleware
 *
 *     This file is part of Wirecloud Platform.
 *
 *     Wirecloud Platform is free software: you can redistribute it and/or
 *     modify it under the terms of the GNU Affero General Public License as
 *     published by the Free Software Foundation, either version 3 of the
 *     License, or (at your option) any later version.
 *
 *     Wirecloud is distributed in the hope that it will be useful, but WITHOUT
 *     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 *     License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with Wirecloud Platform.  If not, see
 *     <http://www.gnu.org/licenses/>.
 *
 */

/*global Draggable, gettext, interpolate, StyledElements, Wirecloud, EzWebExt, LayoutManagerFactory */

(function () {

    "use strict";

    /*************************************************************************
     * Private functions
     *************************************************************************/

    var updateErrorInfo = function updateErrorInfo() {
        var label, errorCount = this.entity.logManager.getErrorCount();
        this.log_button.setDisabled(errorCount === 0);

        label = ngettext("%(errorCount)s error", "%(errorCount)s errors", errorCount);
        label = interpolate(label, {errorCount: errorCount}, true);
        this.log_button.setTitle(label);
    };

    /*************************************************************************
     * Constructor
     *************************************************************************/
    /**
     * GenericInterface Class
     */
    var GenericInterface = function GenericInterface(extending, wiringEditor, entity, title, manager, className, isGhost) {
        if (extending === true) {
            return;
        }
        var del_button, log_button, item, type, msg, ghostNotification;

        StyledElements.Container.call(this, {'class': className}, []);

        Object.defineProperty(this, 'entity', {value: entity});
        this.editingPos = false;
        this.targetAnchorsByName = {};
        this.sourceAnchorsByName = {};
        this.targetAnchors = [];
        this.sourceAnchors = [];
        this.wiringEditor = wiringEditor;
        this.title = title;
        this.className = className;
        this.initPos = {'x': 0, 'y': 0};
        this.draggableSources = [];
        this.draggableTargets = [];
        this.isMinimized = false;
        this.minWidth = '';
        this.movement = false;
        this.numberOfSources = 0;
        this.numberOfTargets = 0;
        this.potentialArrow = null;
        // Only for minimize maximize operators.
        this.initialPos = null;
        this.isGhost = isGhost;
        this.readOnlyEndpoints = 0;
        this.readOnly = false;

        if (manager instanceof Wirecloud.ui.WiringEditor.ArrowCreator) {
            this.isMiniInterface = false;
            this.arrowCreator = manager;
        } else {
            this.isMiniInterface = true;
            this.arrowCreator = null;
        }

        // Interface buttons, not for miniInterface
        if (!this.isMiniInterface) {
            if (className == 'iwidget') {
                type = 'widget';
            } else {
                type = 'operator';
            }

            // header, sources and targets for the widget
            this.resourcesDiv = new StyledElements.BorderLayout({'class': "geContainer"});
            this.sourceDiv = this.resourcesDiv.getEastContainer();
            this.sourceDiv.addClassName("sources");
            this.targetDiv = this.resourcesDiv.getWestContainer();
            this.targetDiv.addClassName("targets");
            this.header = this.resourcesDiv.getNorthContainer();
            this.header.addClassName('header');

            this.wrapperElement.appendChild(this.resourcesDiv.wrapperElement);

            // Ghost interface
            if (isGhost) {
                this.wrapperElement.classList.add('ghost');
                ghostNotification = document.createElement("span");
                ghostNotification.classList.add('ghostNotification');
                msg = gettext('Warning: %(type)s not found!');
                msg = interpolate(msg, {type: type}, true);
                ghostNotification.textContent = msg;
                this.header.appendChild(ghostNotification);
            }

            // Widget name
            this.nameElement = document.createElement("span");
            this.nameElement.textContent = title;
            this.header.appendChild(this.nameElement);

            // Close button
            del_button = new StyledElements.StyledButton({
                'title': gettext("Remove"),
                'class': 'closebutton icon-remove',
                'plain': true
            });
            del_button.insertInto(this.header);
            del_button.addEventListener('click', function () {
                if (this.readOnly == true) {
                    return;
                }
                if (className == 'iwidget') {
                    this.wiringEditor.removeIWidget(this);
                } else {
                    this.wiringEditor.removeIOperator(this);
                }
            }.bind(this));

            // Log button
            this.log_button = new StyledElements.StyledButton({
                'plain': true,
                'class': 'logbutton icon-warning-sign'
            });
            if (!isGhost) {
                this.log_button.addEventListener("click",
                    function () {
                        var dialog = new Wirecloud.ui.LogWindowMenu(this.entity.logManager);
                        dialog.show();
                    }.bind(this));
                updateErrorInfo.call(this);
                this.entity.logManager.addEventListener('newentry', updateErrorInfo.bind(this));
            } else {
                this.log_button.disable();
            }
            this.log_button.insertInto(this.header);

            // special icon for minimized interface
            this.iconAux = document.createElement("div");
            this.iconAux.classList.add("specialIcon");
            this.iconAux.classList.add("icon-cogs");
            this.iconAux.setAttribute('title', title);
            this.resourcesDiv.wrapperElement.appendChild(this.iconAux);
            this.iconAux.addEventListener('click', function () {
                if (!this.movement) {
                    this.restore();
                }
            }.bind(this));

            // Add a menu button except on mini interfaces
            this.menu_button = new StyledElements.PopupButton({
                'title': gettext("Menu"),
                'class': 'editPos_button icon-cog',
                'plain': true
            });
            this.menu_button.insertInto(this.header);
            this.menu_button.popup_menu.append(new Wirecloud.ui.WiringEditor.GenericInterfaceSettingsMenuItems(this));

        } else { // MiniInterface
            this.header = document.createElement("div");
            this.header.classList.add('header');
            this.wrapperElement.appendChild(this.header);
            // Widget name
{'fraction_non_alphanumeric': 0.14163061114115738, 'fraction_numerical': 0.0031097890751757705, 'mean_word_length': 2.0413240131578947, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1921750', 'n_tokens_mistral': 3753, 'n_tokens_neox': 3563, 'n_words': 819}