📄 EditAttribute.cshtml Documentation

File Path:
IrbyImaging/Views/HRImaging/EditAttribute.cshtml


🎯 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Data Model & ViewModel
  4. UI Structure & Layout
  5. Client‑Side Scripts & Utilities
  6. UML & Component Diagram
  7. Usage Example
  8. Conclusion

📖 Overview & Purpose

This Razor View provides an Edit Attribute form for the HR Imaging module. It allows administrators to:

  • View read‑only metadata of a document attribute type (name, multi-value flag, required flag, linkage flags).
  • Edit a list of allowed index values.
  • Assign this attribute to one or more Document Types via a Syncfusion MultiSelect checkbox list.
  • Submit changes via a POST to the EditAttributeType action in HRImagingController.

Key goals

  • Standardize UI for updating attribute definitions
  • Support rich multi‑selection of document types
  • Leverage Syncfusion EJ2 components for enhanced UX

⚙️ Dependencies & Technologies

Technology / Library Purpose
ASP.NET Core MVC Razor Server‑side rendering & tag helpers
Syncfusion EJ2 JavaScript <ejs-multiselect> component for checkbox multi‑select UI
Newtonsoft.Json (Json.NET) Serializing ViewBag.data to JSON for client‑side filtering
HTML5 / Bootstrap 4+ Responsive grid & form styling
JavaScript Event handlers & UI enhancements (filtering, ripple effect etc.)
@model IrbyImaging.UI.Models.DocumentAttributeView
@using Syncfusion.JavaScript.Models
@using Newtonsoft.Json
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title     = "Update Attribute Type";
    ViewBag.pTitle    = "Update Attribute Types";
    ViewBag.pageTitle = "Update Attribute Types";
}

🗃 Data Model & ViewModel

ViewModel: DocumentAttributeView
Defines data required to render/edit a document attribute:

Property Type Description
Id int Unique identifier of the attribute type
AttributeName string Display name for the attribute
IsMultiValue bool Flag: multi‑value attribute?
IsRequired bool Flag: value is mandatory?
LinkEmployeeData bool Flag: link to employee records?
LinkJobData bool Flag: link to job records?
Values string Comma/newline‑separated index values

The controller populates ViewBag.data as a list of document type objects:

ViewBag.data = new List<DocumentTypeDto> {
    new { Id = 1, Type = "Invoice", Category="Finance", IsSelected = true },
    // ...
};

🏗 UI Structure & Layout

4.1 Page Titles & Layout

  • Master Layout: ~/Views/Shared/_Layout.cshtml
  • Page Titles: Rendered via ViewBag.Title, pageTitle, and <h2> header.
<h2>Update Index Type</h2>
<hr />

4.2 Form Fields

Each metadata field is rendered as read‑only text, wrapped in Syncfusion floating inputs:

Label HTML Element Bound Value
Index Name <input text> @Model.AttributeName
Is Index Multi Value? <input text> @Model.IsMultiValue
Is Index Value Required? <input text> @Model.IsRequired
Link Employee Data? <input text> @Model.LinkEmployeeData
Link Job Data? <input text> @Model.LinkJobData
Index Values <textarea> @Model.Values
<div class="form-group row mb-4">
  <div class="col-sm-4">
    <div class="e-float-input">
      <label>Index Name</label>
      <input type="text" readonly value="@Model.AttributeName" />
      <span class="e-float-line"></span>
    </div>
  </div>
</div>
...
<div class="form-group row mb-4">
  <label>Index Values</label>
  <textarea class="form-control" id="indexvalues" name="indexvalues">
    @Model.Values
  </textarea>
</div>

4.3 Document Types MultiSelect

Utilizes Syncfusion EJ2 <ejs-multiselect> with:

  • Checkbox mode
  • Filtering enabled
  • Grouping by Category
  • DataSource passed via ViewBag.data
<ejs-multiselect id="doctype"
                 placeholder="Select Document Types"
                 mode="CheckBox"
                 allowFiltering="true"
                 filtering="onfiltering"
                 actionBegin="onBegin"
                 dataBound="onBound"
                 dataSource='@Html.Raw(JsonConvert.SerializeObject(ViewBag.data))'>
  <e-multiselect-fields text="Type" value="Id" groupBy="Category"></e-multiselect-fields>
</ejs-multiselect>

4.4 Buttons & Actions

Button Type Action
Back to List <a asp-action="DocumentAttributes" ...> Navigates back to attribute listing (GET)
Update <input type="submit" ...> Posts the form to EditAttributeType (POST)

Hidden field modelId preserves the attribute’s primary key:

<input type="hidden" name="modelId" value="@Model.Id" />

🖥 Client‑Side Scripts & Utilities

5.1 MultiSelect Event Handlers

Tracks user selections programmatically:

var selected = [];

function onBegin(e) {
  // Initialize fields to ensure itemCreated hook
  this.fields = {
    text: 'Type', value: 'Id',
    itemCreated: function(evt) {
      if (evt.curData.IsSelected) {
        itemSearch(evt.curData.Id);
      }
    }
  };
}

function itemSearch(id) {
  if (selected.indexOf(id) === -1) {
    selected.push(id);
  }
}
function onBound(e) {
  // Apply stored selections on dataBound
  this.value = selected;
}

5.2 Filtering (Search) Logic

Implements server‑like filtering over local JSON using ej.data.Query:

function onfiltering(e) {
  var query = new ej.data.Query();
  if (e.text !== '') {
    query = query.where('Type', 'startswith', e.text, true);
  }
  e.updateData(@Html.Raw(JsonConvert.SerializeObject(ViewBag.data)), query);
}

5.3 Ripple Effect Enhancement

Enhances focus/blur ripple on Syncfusion float inputs:

ej.base.enableRipple(true);

var inputs = document.querySelectorAll('.e-float-input input');
inputs.forEach(function(input) {
  input.addEventListener('focus',  () => input.parentNode.classList.add('e-input-focus'));
  input.addEventListener('blur',   () => input.parentNode.classList.remove('e-input-focus'));
});

📊 UML & Component Diagram

flowchart LR
  Controller.HRImagingController -->|GET /EditAttribute/{id}| View.EditAttribute.cshtml
  View.EditAttribute.cshtml -->|POST form| Controller.EditAttributeType(id, data)
  Controller --> Service.DocumentAttributeService --> Database
  View.EditAttribute.cshtml .> Syncfusion.EJ2.MultiSelect : uses

🚀 Usage Example

  1. Navigate to the Edit page:
    GET /HRImaging/EditAttribute/5
  2. Review read‑only metadata, update the Index Values textarea.
  3. Select Document Types via the MultiSelect.
  4. Click Update to submit changes.
  5. On success, redirect back to the attribute listing.

🏁 Conclusion

This view streamlines the process of editing document attribute types by combining server‑rendered form fields with rich client‑side experiences courtesy of Syncfusion EJ2. The architecture cleanly separates concerns—ASP.NET Core MVC for data binding and routing, and JavaScript for dynamic UI behaviors—ensuring maintainability and extensibility.


Happy Coding! 🎉