📄 EditAttribute.cshtml Documentation

Path: IrbyImaging/Views/AccountingImaging/EditAttribute.cshtml
Purpose: Razor view for editing an index‐type attribute in the Accounting Imaging module of the IrbyImaging application.


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. ViewModel & Data Models
  4. Key Functional Areas
  5. Form Structure & Fields
  6. Syncfusion MultiSelect Integration
  7. Helper Scripts & Utilities
  8. Workflow & Sequence (UML)
  9. Sample Usage
  10. Conclusion & Next Steps

1. Overview & Purpose

This Razor view renders a form allowing administrators to update an existing Document Attribute (often called an “Index Type”) in the Accounting section.

  • It displays the attribute’s core properties (read‐only)
  • Allows editing of its possible values
  • Lets users link the attribute to one or more Document Types
  • Posts updates back to the controller action EditAttributeType

🎯 Intended Use:

When a user navigates to the Accounting Imaging > Edit Attribute screen, this view presents current attribute metadata and facilitates safe updates.


2. Dependencies & Technologies

Technology Role
ASP.NET Core MVC Server-side rendering, routing, model‐binding
Razor (.cshtml) Templating engine
Syncfusion EJ2 Rich UI components (MultiSelect dropdown)
JavaScript (+ES6) Client‐side interactivity (filtering, event handling, ripple effects)
Newtonsoft.Json Serializing server‐side data into JavaScript
Bootstrap 4 (CSS) Responsive grid & basic styling

3. ViewModel & Data Models

DocumentAttributeView (Model)

namespace IrbyImaging.UI.Models
{
    public class DocumentAttributeView
    {
        public int    Id               { get; set; }
        public string AttributeName    { get; set; }
        public bool   IsMultiValue     { get; set; }
        public bool   IsRequired       { get; set; }
        public bool   LinkEmployeeData { get; set; }
        public bool   LinkJobData      { get; set; }
        public string Values           { get; set; }
        public ImagingType ImagingType { get; set; }

        // Convenience flags set by controller:
        public bool IsLegal, IsSafety, IsIT, IsAccounting, IsBidding;
    }
}

Document Type DTO (for MultiSelect)

Property Type Description
Id int Unique identifier
Type string Display name of document type
Category string Grouping category (e.g., “Legal”, “Safety”)
IsSelected bool Pre‐selected state in the dropdown

4. Key Functional Areas

  1. Category Determination

    var category = "";
    if (Model.ImagingType == ImagingType.Accounting) category = "accounting";
    // ...similar for Legal, Safety, IT, Bidding
    

    • Used in the Back to List link.

  2. Form Rendering

    • Hidden fields to preserve flags & IDs
    • Readonly inputs for immutable properties
    • Editable textarea for comma‑separated Values
  3. Document Types MultiSelect

    • Syncfusion EJ2 ejs-multiselect
    • Checkbox mode, grouping by Category, with on‑the‑fly filtering
  4. JavaScript Utilities

    • Filtering: live search on “Type”
    • Selection Management: track checked IDs (via onBegin, onBound)
    • Ripple Effect: adds focus styling to inputs

5. Form Structure & Fields

Field Element Type Model Binding Attributes Purpose
Attribute Name <input> @Model.AttributeName readonly, required Display only
Is Multi Value? <input> @Model.IsMultiValue.ToString() readonly, required Display only
Is Value Required? <input> @Model.IsRequired.ToString() readonly, required Display only
Link Employee Data? <input> @Model.LinkEmployeeData.ToString() readonly, required Display only
Link Job Data? <input> @Model.LinkJobData.ToString() readonly, required Display only
Index Values <textarea> @Model.Values editable Comma‐separated list of values
Document Types <ejs-multiselect> dataSource="@ViewBag.data" CheckBox mode, filtering Associate with document types
Hidden Flags & Id @Html.HiddenFor(...) various — Postback context preservation

Back / Submit Buttons

<a asp-action="DocumentAttributes"
   asp-controller="LegalImaging"
   asp-route-category="@category"
   class="btn btn-danger irby-red">Back to List</a>

<input type="submit" value="Update" class="btn btn-success irby-green" />

6. Syncfusion MultiSelect Integration

<ejs-multiselect
    id="doctype"
    width="800px"
    placeholder="Select Document Types"
    mode="CheckBox"
    allowFiltering="true"
    filtering="onfiltering"
    actionBegin="onBegin"
    dataBound="onBound"
    popupHeight="200px"
    dataSource="@ViewBag.data">
  <e-multiselect-fields
    groupBy="Category"
    text="Type"
    value="Id">
  </e-multiselect-fields>
</ejs-multiselect>
  • Grouping: by Category
  • Fields:
    • Text: Type
    • Value: Id
  • Events:
    • onBegin – initializes selected[] based on pre‑selected items
    • onBound – assigns final selected values back to the control
    • onfiltering – filters Type field live as you type

7. Helper Scripts & Utilities

7.1. MultiSelect Event Handlers

var selected = [];

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

function itemSearch(id) {
  if (selected.indexOf(id) === -1) {
    selected.push(id);
  }
}

function onBound(e) {
  this.value = selected;
}

7.2. Filtering Handler

function onfiltering(e) {
  var query = new ej.data.Query();
  query = e.text !== ''
    ? query.where('Type', 'startswith', e.text, true)
    : query;
  // Re‐feed the original data to Syncfusion
  e.updateData(
    @Html.Raw(JsonConvert.SerializeObject(ViewBag.data)),
    query
  );
}

7.3. Ripple Focus Effect

ej.base.enableRipple(true);
var inputs = document.querySelectorAll('.e-input-group .e-input, .e-float-input.e-input-group input');
inputs.forEach(function(inp) {
  inp.addEventListener('focus', function() {
    this.parentNode.classList.add('e-input-focus');
  });
  inp.addEventListener('blur', function() {
    this.parentNode.classList.remove('e-input-focus');
  });
});

8. Workflow & Sequence (UML)

User
  │
  ▼  (1) Click “Edit” on attribute list
Browser
  │
  ▼  GET /AccountingImaging/EditAttributeType/{id}
Controller (AccountingImaging)
  ├─ Loads DocumentAttributeView (with Flags)
  ├─ Loads DocumentTypes into ViewBag.data
  └─ Returns View(EditAttribute.cshtml)
  
View → Browser
  // Renders form + Syncfusion MultiSelect + scripts

User
  └─ Edits ‘Index Values’ & selects doc types

Browser
  └─ POST /AccountingImaging/EditAttributeType
       • Hidden flags & modelId
       • New Values & selected doc types

Controller
  ├─ Validates & persists changes
  └─ Redirects to DocumentAttributes list (Back to List)

9. Sample Usage

// Controller (AccountingImagingController)
public IActionResult EditAttributeType(int id) {
    var dto = _service.GetDocumentAttributeView(id);
    ViewBag.data = _service.GetAllDocumentTypes();  // returns List<DocTypeDto>
    return View("EditAttribute", dto);
}

[HttpPost]
public IActionResult EditAttributeType(DocumentAttributeView model, int[] doctype) {
    if (!ModelState.IsValid) { /* handle errors */ }
    _service.UpdateAttribute(model, doctype);
    return RedirectToAction("DocumentAttributes", new { category = model.ImagingType.ToString().ToLower() });
}

10. Conclusion & Next Steps

✅ You now have a comprehensive view of how EditAttribute.cshtml:

  • Binds a DocumentAttributeView model
  • Enforces readonly display of core metadata
  • Provides editable Values & Document Type associations
  • Integrates a rich Syncfusion MultiSelect component
  • Uses JavaScript utilities for filtering & styling

Next Steps:

  1. Review the corresponding POST action to verify validation rules.
  2. Ensure ViewBag.data contains correct IsSelected flags for pre‐selection.
  3. Customize styles or add client‐side validation if necessary.
  4. Test across browsers to confirm Syncfusion behaviors and ripple effects.

📌 Tip: Always guard against unexpected user input on the server side, even if fields are marked readonly in the UI.


Happy coding! 🚀