in log4j-catalog/log4j-catalog-editor/src/main/resources/static/js/attributes.js [201:299]
function addEditAttributeItem(attributeId) {
var hiddenIdField = '';
var attributeData = {};
if (attributeId) {
hiddenIdField = '<input type="hidden" id="attributeId" name="id" value="' + attributeId + '" />';
} else {
attributeId = 'tempEventData';
var tempEventData = {
id: attributeId,
constraints: [],
}
localStorage.setItem('attributeItem' + attributeId, JSON.stringify(tempEventData));
}
attributeFormContent = ' \
<form id="add-edit-attribute-form" class="log4j-catalog-form" method="post"> \
' + hiddenIdField + ' \
<p> \
<label>Name</label> \
<input type="text" id="attributeName" name="name" class="required" /> \
</p> \
<p> \
<label>Display Name</label> \
<input type="text" id="attributeDisplayName" name="displayName" class="required" /> \
</p> \
<p> \
<label>Description</label> \
<input type="text" id="attributeDescription" name="description" class="required" /> \
</p> \
<p> \
<label>Data Type</label> \
<select id="attributeDataType" name="indexed" class="required"> \
</select> \
</p> \
<p> \
<label>Indexed</label> \
<select id="attributeIndexed" name="indexed" class="required"> \
<option value="false">false</option> \
<option value="true">true</option> \
</select> \
</p> \
<p> \
<label>Sortable</label> \
<select id="attributeSortable" name="sortable" class="required"> \
<option value="false">false</option> \
<option value="true">true</option> \
</select> \
</p> \
<p> \
<label>Required</label> \
<select id="attributeRequired" name="required" class="required"> \
<option value="false">false</option> \
<option value="true">true</option> \
</select> \
</p> \
<p> \
<label>Request Context</label> \
<select id="attributeRequestContext" name="requestContext" class="required"> \
<option value="false">false</option> \
<option value="true">true</option> \
</select> \
</p> \
<p> \
<label>Assigned Constraints</label> \
<span id="attributeConstraints"></span> \
</p> \
<p> \
<label>Add Constraint</label> \
<span> \
<select name="addAttributeConstraintName" id="addAttributeConstraintName"> \
<option value="">loading...</option> \
</select> \
<input type="text" name="addAttributeConstraintValue" id="addAttributeConstraintValue" /> \
<button id="addAttributeConstraintButton">+</button> \
</span> \
</p> \
</form> \
<div class="log4j-catalog-button-row"> \
<button class="log4j-catalog-button" onclick="closeLog4jModal()">Cancel</button>\
<button class="log4j-catalog-button" onclick="addEditattributeItemHandler()">Save</button> \
</div> \
';
showLog4JModal('Add / Edit Attribute Item', attributeFormContent);
var dataTypes = ['STRING', 'BIG_DECIMAL', 'DOUBLE', 'FLOAT', 'INT', 'LONG', 'BOOLEAN', 'LIST', 'MAP'];
$.each(dataTypes.sort(), function(index, value) {
$('#attributeDataType').append('<option value="' + value + '">' + value + '</option>');
});
if (localStorage.getItem('attributeItem' + attributeId)) {
attributeData = JSON.parse(localStorage.getItem('attributeItem' + attributeId));
$('#attributeName').val(attributeData.name);
$('#attributeDisplayName').val(attributeData.displayName);
$('#attributeDescription').val(attributeData.description);
$('#attributeDataType option[value="' + attributeData.dataType + '"]').attr('selected', 'selected');
$('#attributeIndexed option[value="' + attributeData.indexed + '"]').attr('selected', 'selected');
$('#attributeSortable option[value="' + attributeData.sortable + '"]').attr('selected', 'selected');
$('#attributeRequired option[value="' + attributeData.required + '"]').attr('selected', 'selected');
$('#attributeRequestContext option[value="' + attributeData.requestContext + '"]').attr('selected', 'selected');
}
populateAttributeConstraints(attributeData.constraints, attributeId);
}