<commit_before>/*
 *
 * (c) Copyright Ascensio System SIA 2010-2019
 *
 * This program is a free software product. You can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License (AGPL)
 * version 3 as published by the Free Software Foundation. In accordance with
 * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
 * that Ascensio System SIA expressly excludes the warranty of non-infringement
 * of any third-party rights.
 *
 * This program is distributed WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR  PURPOSE. For
 * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
 *
 * You can contact Ascensio System SIA at 20A-12 <NAME>
 * street, Riga, Latvia, EU, LV-1050.
 *
 * The  interactive user interfaces in modified source and object code versions
 * of the Program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU AGPL version 3.
 *
 * Pursuant to Section 7(b) of the License you must retain the original Product
 * logo when distributing the program. Pursuant to Section 7(e) we decline to
 * grant you any rights under trademark law for use of our trademarks.
 *
 * All the Product's GUI elements, including illustrations and icon sets, as
 * well as technical writing content are licensed under the terms of the
 * Creative Commons Attribution-ShareAlike 4.0 International. See the License
 * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
 *
*/
if (Common === undefined)
    var Common = {};

define([
    'text!common/main/lib/template/ExtendedColorDialog.template',
    'common/main/lib/component/HSBColorPicker',
    'common/main/lib/component/MetricSpinner',
    'common/main/lib/component/MaskedField',
    'common/main/lib/component/Window'
], function (dlgTemplate) {
    'use strict';

    Common.UI.ExtendedColorDialog = Common.UI.Window.extend(_.extend({
        tpl: _.template(dlgTemplate),
        options: {},
        rendered: false,

        initialize : function(options) {
            Common.UI.Window.prototype.initialize.call(this, {
                cls: 'extended-color-dlg',
                tpl: this.tpl({
                    txtNew: this.textNew,
                    txtCurrent: this.textCurrent,
                    txtAdd: this.addButtonText,
                    txtCancel: this.cancelButtonText
                }),
                header: false,
                width: 340,
                height: 272
            });

            this.hexRe = /\s*#?([0-9a-fA-F][0-9a-fA-F]?)([0-9a-fA-F][0-9a-fA-F]?)([0-9a-fA-F][0-9a-fA-F]?)\s*/;
        },

        render: function() {
            var me = this;
            Common.UI.Window.prototype.render.call(this);

            this.colorsPicker = new Common.UI.HSBColorPicker({
                el: $('#id-hsb-colorpicker'),
                showCurrentColor: false
            });
            this.colorsPicker.on('changecolor', _.bind(this.onChangeColor, this));

            this.colorNew = $('#field-new-color');
            this.colorSaved = $('#field-start-color');

            this.spinR = new Common.UI.MetricSpinner({
                el: $('#extended-spin-r'),
                step: 1,
                width: 63,
                value: '0',
                defaultUnit : "",
                maxValue: 255,
                minValue: 0,
                tabindex: 1,
                maskExp: /[0-9]/,
                allowDecimal: false
            });

            this.spinG = new Common.UI.MetricSpinner({
                el: $('#extended-spin-g'),
                step: 1,
                width: 63,
                value: '0',
                defaultUnit : "",
                maxValue: 255,
                minValue: 0,
                tabindex: 2,
                maskExp: /[0-9]/,
                allowDecimal: false
            });

            this.spinB = new Common.UI.MetricSpinner({
                el: $('#extended-spin-b'),
                step: 1,
                width: 63,
                value: '0',
                defaultUnit : "",
                maxValue: 255,
                minValue: 0,
                tabindex: 3,
                maskExp: /[0-9]/,
                allowDecimal: false
            });

            this.textColor = new Common.UI.MaskedField({
                el: $('#extended-text-color'),
                width: 55,
                maskExp: /[a-fA-F0-9]/,
                maxLength: 6
            });

            this.spinR.on('change', _.bind(this.showColor, this, null, true)).on('changing', _.bind(this.onChangingRGB, this, 1));
            this.spinG.on('change', _.bind(this.showColor, this, null, true)).on('changing', _.bind(this.onChangingRGB, this, 2));
            this.spinB.on('change', _.bind(this.showColor, this, null, true)).on('changing', _.bind(this.onChangingRGB, this, 3));
            this.textColor.on('change', _.bind(this.onChangeMaskedField, this));
            this.textColor.on('changed', _.bind(this.onChangedMaskedField, this));
            this.textColor.$el.attr('tabindex', 4);
            this.spinR.$el.find('input').attr('maxlength', 3);
            this.spinG.$el.find('input').attr('maxlength', 3);
            this.spinB.$el.find('input').attr('maxlength', 3);

            this.on('close', function() {
                me.trigger('onmodalresult', 0);
            });

            function onBtnClick(event) {
                me.trigger('onmodalresult', parseInt(event.currentTarget.attributes['result'].value));
                me.close(true);
            }
            $(this)[0].getChild('.footer .dlg-btn').on('click', onBtnClick);

            this.rendered = true;
            if (this.color!==undefined)
                this.setColor(this.color);
            return this;
        },

        onChangeColor: function(o, color) {
            this.colorNew.css({'background-color' : color});

            this.stopevents = true;
            var values = color.match(this.hexRe);
            this.spinR.setValue(parseInt(values[1], 16));
            this.spinG.setValue(parseInt(values[2], 16));
            this.spinB.setValue(parseInt(values[3], 16));
            this.textColor.setValue((values[1]+values[2]+values[3]).toUpperCase());
            this.stopevents = false;
        },

        showColor: function (exlude, validate) {
            if (!this.stopevents) {
                var val = this.spinR.getNumberValue();
                var r = (val==null||val<0) ? 0 : (val>255 ? 255 : val);
                if (validate) this.spinR.setValue(r, true); r = r.toString(16);
                val = this.spinG.getNumberValue();<commit_msg>Bug 27088: add focus manager to Extended color dialog<commit_after>/*
 *
 * (c) Copyright Ascensio System SIA 2010-2019
 *
 * This program is a free software product. You can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License (AGPL)
 * version 3 as published by the Free Software Foundation. In accordance with
 * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
 * that Ascensio System SIA expressly excludes the warranty of non-infringement
 * of any third-party rights.
 *
 * This program is distributed WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR  PURPOSE. For
 * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
 *
 * You can contact Ascensio System SIA at 20A-12 <NAME>-Upisha
 * street, Riga, Latvia, EU, LV-1050.
 *
 * The  interactive user interfaces in modified source and object code versions
 * of the Program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU AGPL version 3.
 *
 * Pursuant to Section 7(b) of the License you must retain the original Product
 * logo when distributing the program. Pursuant to Section 7(e) we decline to
 * grant you any rights under trademark law for use of our trademarks.
 *
 * All the Product's GUI elements, including illustrations and icon sets, as
 * well as technical writing content are licensed under the terms of the
 * Creative Commons Attribution-ShareAlike 4.0 International. See the License
 * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
 *
*/
if (Common === undefined)
    var Common = {};

define([
    'text!common/main/lib/template/ExtendedColorDialog.template',
    'common/main/lib/component/HSBColorPicker',
    'common/main/lib/component/MetricSpinner',
    'common/main/lib/component/MaskedField',
    'common/main/lib/component/Window'
], function (dlgTemplate) {
    'use strict';

    Common.UI.ExtendedColorDialog = Common.UI.Window.extend(_.extend({
        tpl: _.template(dlgTemplate),
        options: {},
        rendered: false,

        initialize : function(options) {
            Common.UI.Window.prototype.initialize.call(this, {
                cls: 'extended-color-dlg',
                tpl: this.tpl({
                    txtNew: this.textNew,
                    txtCurrent: this.textCurrent,
                    txtAdd: this.addButtonText,
                    txtCancel: this.cancelButtonText
                }),
                header: false,
                width: 340,
                height: 272,
                focusManager: true
            });

            this.hexRe = /\s*#?([0-9a-fA-F][0-9a-fA-F]?)([0-9a-fA-F][0-9a-fA-F]?)([0-9a-fA-F][0-9a-fA-F]?)\s*/;
        },

        render: function() {
            var me = this;
            Common.UI.Window.prototype.render.call(this);

            this.colorsPicker = new Common.UI.HSBColorPicker({
                el: $('#id-hsb-colorpicker'),
                showCurrentColor: false
            });
            this.colorsPicker.on('changecolor', _.bind(this.onChangeColor, this));

            this.colorNew = $('#field-new-color');
            this.colorSaved = $('#field-start-color');

            this.spinR = new Common.UI.MetricSpinner({
                el: $('#extended-spin-r'),
                step: 1,
                width: 63,
                value: '0',
                defaultUnit : "",
                maxValue: 255,
                minValue: 0,
                maskExp: /[0-9]/,
                allowDecimal: false
            });

            this.spinG = new Common.UI.MetricSpinner({
                el: $('#extended-spin-g'),
                step: 1,
                width: 63,
                value: '0',
                defaultUnit : "",
                maxValue: 255,
                minValue: 0,
                maskExp: /[0-9]/,
                allowDecimal: false
            });

            this.spinB = new Common.UI.MetricSpinner({
                el: $('#extended-spin-b'),
                step: 1,
                width: 63,
                value: '0',
                defaultUnit : "",
                maxValue: 255,
                minValue: 0,
                maskExp: /[0-9]/,
                allowDecimal: false
            });

            this.textColor = new Common.UI.MaskedField({
                el: $('#extended-text-color'),
                width: 55,
                maskExp: /[a-fA-F0-9]/,
                maxLength: 6
            });

            this.spinR.on('change', _.bind(this.showColor, this, null, true)).on('changing', _.bind(this.onChangingRGB, this, 1));
            this.spinG.on('change', _.bind(this.showColor, this, null, true)).on('changing', _.bind(this.onChangingRGB, this, 2));
            this.spinB.on('change', _.bind(this.showColor, this, null, true)).on('changing', _.bind(this.onChangingRGB, this, 3));
            this.textColor.on('change', _.bind(this.onChangeMaskedField, this));
            this.textColor.on('changed', _.bind(this.onChangedMaskedField, this));
            this.spinR.$el.find('input').attr('maxlength', 3);
            this.spinG.$el.find('input').attr('maxlength', 3);
            this.spinB.$el.find('input').attr('maxlength', 3);

            this.on('close', function() {
                me.trigger('onmodalresult', 0);
            });

            function onBtnClick(event) {
                me.trigger('onmodalresult', parseInt(event.currentTarget.attributes['result'].value));
                me.close(true);
            }
            $(this)[0].getChild('.footer .dlg-btn').on('click', onBtnClick);

            this.rendered = true;
            if (this.color!==undefined)
                this.setColor(this.color);

            this.focusManager.add([this.spinR, this.spinG, this.spinB], '.form-control');
            this.focusManager.add(this.textColor, 'input');
            return this;
        },

        onChangeColor: function(o, color) {
            this.colorNew.css({'background-color' : color});

            this.stopevents = true;
            var values = color.match(this.hexRe);
            this.spinR.setValue(parseInt(values[1], 16));
            this.spinG.setValue(parseInt(values[2], 16));
            this.spinB.setValue(parseInt(values[3], 16));
            this.textColor.setValue((values[1]+values[2]+values[3]).toUpperCase());
            this.stopevents = false;
        },

        showColor: function (exlude, validate) {
            if (!this.stopevents) {
                var val = this.spinR.getNumberValue();
                var r = (val==null||val<0) ? 0 : (val>255 ? 255 : val);
                if (validate) this.spinR.setValue(r, true); r = r.toString(16);
                val = this.spinG.getNumberValue();
{'fraction_non_alphanumeric': 0.13039295493228742, 'fraction_numerical': 0.017390660845112114, 'mean_word_length': 1.874096129306678, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '927430', 'n_tokens_mistral': 4081, 'n_tokens_neox': 3752, 'n_words': 923}