<commit_before>/**
 * js/./Label.js
 * Author: <NAME> <<EMAIL>>
 * Date: 22.04.2016
 */

'use strict';

define(['../core/Utils', './Element', './Icon'], function(Utils, Element, Icon){
    var uid=0;
    function genUid(){
        return 'label_' + (uid++);
    }

    return Element.extend({
        'init': function(caption){
            this.super('label');

            if(!Utils.isSet(caption))
                caption = '';

            var captionElement = Element.new()
            .addClass('jb-label-caption');

            this.set('captionElement', captionElement);
            this.addClass('jb-label');
            this.add(captionElement);
            this.setCaption(caption);
        },

        'setBold': function(value){
            if(value)
                this.addClass('jb-label-bold');
            else
                this.removeClass('jb-label-bold');

            return this.ref
        },

        'setCaption': function(caption){
            var captionElement = this.get('captionElement').clear();
            if(caption === '') captionElement.hide();
            else captionElement.add(caption).show();

            return this.ref;
        },

        'setIcon': function(name){
            var iconElement = this.get('iconElement');

            if(iconElement)
                this.remove(iconElement);

            iconElement = Icon.new(name).addClass('jb-label-icon');
            this.prepend(iconElement);
            this.set('iconElement', iconElement);

            return this.ref;
        },

        'setDisabled': function(value){
            if(value){
                this.addClass('jb-label-disabled');
                return this.ref;
            }

            this.removeClass('jb-label-disabled');
            return this.ref;
        },

        //NORMAL, PRIMARY, DANGER, WARNING, INFO
        'setTheme': function(theme){
            this.removeClass('jb-primary jb-danger jb-warning jb-info');

            switch(theme){
                case 'PRIMARY':
                    this.addClass('jb-primary');
                    break;
                case 'SUCCESS':
                    this.addClass('jb-success');
                    break;
                case 'DANGER':
                    this.addClass('jb-danger');
                    break;
                case 'WARNING':
                    this.addClass('jb-warning');
                    break;
                case 'INFO':
                    this.addClass('jb-info');
                    break;
            }

            return this.ref;
        },

        'bound': false,
        'bind': function(input){
            var inputId = input.getAttr('id');
            if(Utils.isUnset(inputId)){
                inputId = genUid();
                input.setAttr('id', inputId);
            }
            this.setAttr('for', inputId);
            this.set('bound', true);
            return this.ref;
        },
        'isBound': function(){
            return this.get('bound');
        }
    });
});
<commit_msg>Added controls for `Label.bind` method.<commit_after>/**
 * js/./Label.js
 * Author: <NAME> <<EMAIL>>
 * Date: 22.04.2016
 */

'use strict';

define([
    '../core/Utils', './Element', './Icon',
    './Spinner', './Input', './Button', './Check', './Switch'
], function(
    Utils, Element, Icon,
    Spinner, Input, Button, Check, Switch
){
    var uid=0;
    function genUid(){
        return 'label_' + (uid++);
    }

    return Element.extend({
        'init': function(caption){
            this.super('label');

            if(!Utils.isSet(caption))
                caption = '';

            var captionElement = Element.new()
            .addClass('jb-label-caption');

            this.set('captionElement', captionElement);
            this.addClass('jb-label');
            this.add(captionElement);
            this.setCaption(caption);
        },

        'setBold': function(value){
            if(value)
                this.addClass('jb-label-bold');
            else
                this.removeClass('jb-label-bold');

            return this.ref
        },

        'setCaption': function(caption){
            var captionElement = this.get('captionElement').clear();
            if(caption === '') captionElement.hide();
            else captionElement.add(caption).show();

            return this.ref;
        },

        'setIcon': function(name){
            var iconElement = this.get('iconElement');

            if(iconElement)
                this.remove(iconElement);

            iconElement = Icon.new(name).addClass('jb-label-icon');
            this.prepend(iconElement);
            this.set('iconElement', iconElement);

            return this.ref;
        },

        'setDisabled': function(value){
            if(value){
                this.addClass('jb-label-disabled');
                return this.ref;
            }

            this.removeClass('jb-label-disabled');
            return this.ref;
        },

        //NORMAL, PRIMARY, DANGER, WARNING, INFO
        'setTheme': function(theme){
            this.removeClass('jb-primary jb-danger jb-warning jb-info');

            switch(theme){
                case 'PRIMARY':
                    this.addClass('jb-primary');
                    break;
                case 'SUCCESS':
                    this.addClass('jb-success');
                    break;
                case 'DANGER':
                    this.addClass('jb-danger');
                    break;
                case 'WARNING':
                    this.addClass('jb-warning');
                    break;
                case 'INFO':
                    this.addClass('jb-info');
                    break;
            }

            return this.ref;
        },

        'bound': false,
        'bind': function(input){
            if(input.isInstanceOf(Spinner)){
                input = input.get('input');
            }else if(
                !input.isInstanceOf(Button) &&
                !input.isInstanceOf(Switch) &&
                !input.isInstanceOf(Check) &&
                !input.isInstanceOf(Input)
            )
                return this.ref;

            var inputId = input.getAttr('id');
            if(Utils.isUnset(inputId)){
                inputId = genUid();
                input.setAttr('id', inputId);
            }
            this.setAttr('for', inputId);
            this.set('bound', true);
            return this.ref;
        },
        'isBound': function(){
            return this.get('bound');
        }
    });
});

{'fraction_non_alphanumeric': 0.14198473282442747, 'fraction_numerical': 0.002748091603053435, 'mean_word_length': 1.3641284734752797, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6151644', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1660, 'n_words': 299}