function addEditCategoryItem()

in log4j-catalog/log4j-catalog-editor/src/main/resources/static/js/categories.js [147:202]


function addEditCategoryItem(categoryId) {
    var hiddenIdField = '';
    var categoryData = {};
    if (categoryId) {
        hiddenIdField = '<input type="hidden" id="categoryId" name="id" value="' + categoryId + '" />';
    } else {
        categoryId = 'tempCategoryData';
        var tempCategoryData = {
            id: categoryId,
            events: [],
        }
        localStorage.setItem('categoryItem' + categoryId, JSON.stringify(tempCategoryData));
    }
    categoryFormContent = ' \
        <form id="add-edit-category-form" class="log4j-catalog-form" method="post"> \
          ' + hiddenIdField + ' \
          <p> \
              <label>Name</label> \
              <input type="text" id="categoryName" name="name" class="required" /> \
          </p> \
          <p> \
              <label>Display Name</label> \
              <input type="text" id="categoryDisplayName" name="displayName" class="required" /> \
          </p> \
          <p> \
              <label>Description</label> \
              <input type="text" id="categoryDescription" name="description" class="required" /> \
          </p> \
          <p> \
              <label>Assigned Events</label> \
              <span id="categoryEvents"></span> \
          </p> \
          <p> \
              <label>Add Event</label> \
              <span> \
                  <select name="addCategoryEvent" id="addCategoryEvent"> \
                      <option value="">loading...</option> \
                  </select> \
                  <button id="addCategoryEventButton">+</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="addEditCategoryItemHandler()">Save</button> \
        </div> \
    ';
    showLog4JModal('Add / Edit Category Item', categoryFormContent);
    if (localStorage.getItem('categoryItem' + categoryId)) {
        categoryData = JSON.parse(localStorage.getItem('categoryItem' + categoryId));
        $('#categoryName').val(categoryData.name);
        $('#categoryDisplayName').val(categoryData.displayName);
        $('#categoryDescription').val(categoryData.description);
    }
    populateCategoryEvents(categoryData.events, categoryId);
}