/**
* Für die Bedienung der Freifelder innerhalb des Wiedervorlagen-Popups
*/
var ResubmissionTextFieldUi = (function ($) {
'use strict';
var me = {
storage: {
$content: null,
$errors: null
},
/**
* @param {Array} textfields
*
* @return void
*/
init: function (textfields) {
var $content = $('#resubmission-textfields-content');
if ($content.length !== 1) {
console.error('ResubmissionTextFieldUi: Benötigtes Element #resubmission-textfields-content fehlt');
return;
}
me.storage.$content = $content;
var $errors = $('#resubmission-textfields-errors');
if ($errors.length !== 1) {
console.error('ResubmissionTextFieldUi: Benötigtes Element #resubmission-textfields-errors fehlt');
return;
}
me.storage.$errors = $errors;
me.buildTextFieldForm(textfields);
},
/**
* @param {Array} textfields
*/
buildTextFieldForm: function (textfields) {
me.storage.$content.html('');
me.storage.$errors.html('');
if (textfields.length === 0) {
var content = '
Es sind keine Freifelder für diese Stage konfiguriert. ';
content += '
Zu den Einstellungen';
content += '
';
me.storage.$errors.html(content);
}
if (textfields.length > 0) {
var $table = $('');
$.each(textfields, function (index, textfield) {
var $row = me.generateTextFieldRow(textfield);
$row.appendTo($table);
});
me.storage.$content.html($table);
}
},
/**
* @param {Object} data
*
* @return {jQuery} jQuery-Element
*/
generateTextFieldRow: function (data) {
if (!data.hasOwnProperty('config_id') || !data.hasOwnProperty('label')) {
throw 'ResubmissionTextFieldUi: Can not generate textfield html. Data has wrong format.';
}
var template =
'' +
'' +
' | ' +
'' +
' |
';
template = template.replace('{{configId}}', data.config_id);
template = template.replace('{{configId}}', data.config_id);
template = template.replace('{{configId}}', data.content_id);
var $template = $(template);
$template.find('label.resubmission-textfield-label').text(data.label);
$template
.find('input.resubmission-textfield-content')
.data('resubmissionTextfieldConfigId', data.config_id)
.data('resubmissionTextfieldContentId', data.content_id)
.val(data.content);
return $template;
},
/**
* @param {Array} errors
*/
renderErrorMessages: function (errors) {
var errorMsg = '';
$.each(errors, function (index, textfieldError) {
errorMsg += '' + textfieldError.message + '
';
});
me.storage.$errors.html('' + errorMsg + '
');
}
};
return {
init: me.init,
renderErrorMessages: me.renderErrorMessages
};
})(jQuery);