/**
 * Old RTE
 */
IGDATAPOOLFE.plugins.add('rte', {
    form: null,
    initFields: function(form) {
	this.init(form);
    },
    init: function(form) {
	let $form = $(form);
	this.form = $form;
	if ($('.dp-rte', $form).length == 0)
	    return;
	var lang = $('.dp-rte', $form).data('language');
	var DefaultPlugins = $('.dp-rte-default', $form).data('plugins');
	var DefaultToolbarLine1 = $('.dp-rte-default', $form).data('toolbar1');
	var DefaultToolbarLine2 = $('.dp-rte-default', $form).data('toolbar2');
	var configs = new Array(
	    { name: 'default', plugins: 'hr', toolbar1: 'undo redo | styleselect | bold italic | hr | alignleft aligncenter alignright alignjustify', toolbar2: 'bullist numlist outdent indent' }
	);
	// Vorhandene config lesen/speicher
	$('.dp-rte').each(function () {
	    if( $(this).data('config')) {
		var found=0;
		var name=$(this).data('config');
		configs.forEach(function(config) {if(config.name==name) {found=1; alert('Overwriting RTE Configuration "'+name +'" not allowed')}});
		if( ! found )
		    configs.push( {name: name, plugins: $(this).data('plugins'), toolbar1: $(this).data('toolbar1'), toolbar2: $(this).data('toolbar2')});
	    }
	});
	configs.forEach(function(config) {
            $('.dp-rte-' + config.name +' textarea').each(function() {
	        var id = $(this).attr('id');
    		if(!/TEMP/.test(id)) {
        	    tinymce.init({
        		selector : '#' + id,
        		menubar : false,
        		statusbar : false,
        		language : lang,
        		plugins: config.plugins,
        		toolbar: [
            		    config.toolbar1,
            		    config.toolbar2
                        ],
                        style_formats_merge: true,
                        style_formats: [
                            {title: 'Roter Text', inline: 'span', classes: 'text-red'},
                            {title: 'Blauer Text', inline: 'span', classes: 'text-blue'}
                        ]
        	    });
        	    //tinymce.activeEditor.formatter.apply('custom_format');

    		}
	    });
	});
    }
});