📝 Edit Document Type View Documentation

File: IrbyImaging/Views/LegalImaging/EditType.cshtml


🚀 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Model & ViewModel
  4. Layout & ViewBag Configuration
  5. Razor Markup & Form Structure
  6. Client-side Scripting
  7. UML Diagram: DocumentTypeView
  8. Sample Code Blocks & Usage
  9. Conclusion

1. Overview & Purpose

This Razor View renders an Edit Document Type page for the Legal Imaging module.

  • 📌 Purpose: Allow administrators to update metadata of a document type (e.g., name, description, category, index mappings, availability).
  • 🎯 Scope: Handles three imaging contexts—Legal, Safety, IT—differentiated via the ImagingType enum.

2. Dependencies & Technologies

Category Technology / Library
Framework ASP.NET Core MVC (Razor)
UI Components Syncfusion EJ2 (DropdownList, MultiSelect)
Data Binding ASP.NET Tag Helpers (asp-for, asp-action)
JSON Serialization Newtonsoft.Json
UI Enhancements Bootstrap, MetisMenu, Simplebar, Waves.js

3. Model & ViewModel

ViewModel: IrbyImaging.UI.Models.DocumentTypeView

public class DocumentTypeView {
  public int Id { get; set; }
  public string Type { get; set; }            // e.g. "Invoice", "Report"
  public string Description { get; set; }
  public string Category { get; set; }        // Selected category
  public List<int> IndexTypes { get; set; }   // Selected index type IDs
  public bool IsAvailable { get; set; }
  public bool IsDeleted { get; set; }
  public ImagingType ImagingType { get; set; }
  public bool IsLegal { get; set; }
  public bool IsSafety { get; set; }
  public bool IsIT { get; set; }
}

4. Layout & ViewBag Configuration

@{
    ViewBag.Title     = "Edit Document Type";
    ViewBag.pTitle    = "Edit Document Types";
    ViewBag.pageTitle = "Edit Document Types";
    Layout            = "~/Views/Shared/_LegalLayout.cshtml";
    
    // Determine imaging context string for routing back
    var imagingType = Model.ImagingType switch {
        IrbyImaging.DomainClasses.ImagingType.Legal  => "legal",
        IrbyImaging.DomainClasses.ImagingType.Safety => "safety",
        IrbyImaging.DomainClasses.ImagingType.IT     => "it",
        _                                             => ""
    };
}
  • Layout: Reuses a shared Legal layout.
  • ViewBag.props: Titles used in breadcrumbs / headers.
  • imagingType: Used for “Back to List” routing.

5. Razor Markup & Form Structure

The form posts to the EditDocType action in the LegalImagingController.


6. Client-side Scripting

Enhances Syncfusion controls and general UI behavior:

6.1 onBegin: Initialize Selection

var selected = [];
function onBegin(e) {
  this.fields = {
    text: 'Type', value: 'Id',
    itemCreated: function(evt) {
      if (evt.curData.IsSelected) {
        itemSearch(evt.curData.Id);
      }
    }
  };
}
function itemSearch(id) {
  if (!selected.includes(id)) selected.push(id);
}

Purpose: When items are created in the MultiSelect dropdown, capture initially selected IDs.

6.2 onBound: Apply Pre‑selection

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

Purpose: After data is bound, set the value of MultiSelect to previously populated selected[].

6.3 onfiltering: Live Search/Filter

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

Purpose: Enables search-as-you-type behavior for Index Types.

6.4 Ripple Effect on Inputs

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

Purpose: Adds Syncfusion’s ripple-focus CSS class for better UX.


7. UML Diagram: DocumentTypeView

+-----------------------------------+
|        DocumentTypeView           |
+-----------------------------------+
| - Id: int                         |
| - Type: string                    |
| - Description: string             |
| - Category: string                |
| - IndexTypes: List<int>           |
| - IsAvailable: bool               |
| - IsDeleted: bool                 |
| - ImagingType: ImagingType (enum) |
| - IsLegal: bool                   |
| - IsSafety: bool                  |
| - IsIT: bool                      |
+-----------------------------------+

8. Sample Code Blocks & Usage

GET /LegalImaging/EditType/5?imagingType=legal

Controller Signature

[HttpGet]
public IActionResult EditType(int id, ImagingType imagingType) {
  var model = _service.GetDocumentTypeView(id, imagingType);
  ViewBag.type    = _service.GetCategories();
  ViewBag.indexes = _service.GetIndexTypes();
  ViewBag.data    = _service.GetIndexTypes(); // for filtering
  return View("EditType", model);
}

[HttpPost]
public IActionResult EditDocType(DocumentTypeView model) {
  if (ModelState.IsValid) {
    _service.UpdateDocumentType(model);
    return RedirectToAction("DocumentTypes", new { imagingType = model.ImagingType });
  }
  // re-populate ViewBag and return
  …
}

9. Conclusion

This detailed guide covers the EditType.cshtml view in the Legal Imaging module. You now have:

  • 🧩 Comprehensive Structure: Hidden fields, typed inputs, Syncfusion widgets
  • 🔄 Data Binding: Strongly-typed DocumentTypeView model
  • ⚙️ Client Logic: Selection management, live filtering, ripple focus
  • 📦 Integration Points: Controller actions, ViewBag data, Syncfusion JSON usage

With this reference, developers and UI integrators can confidently maintain, enhance, and debug the Edit Document Type functionality! 🎉