📄 Documentation: DocumentTypes.cshtml


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Model Binding & ViewModel
  4. UI Layout & Components
  5. Scripts & Event Handlers
  6. Sample Usage & Code Snippets
  7. UML Sequence Diagram
  8. Conclusion & Next Steps

1. Overview & Purpose

DocumentTypes.cshtml is an ASP.NET Core Razor View under IrbyImaging/Views/AccountingImaging/. It provides an interactive Document Types management page for the Accounting Imaging module, featuring:

  • A Syncfusion EJ2 TreeGrid to display hierarchical document-type data.
  • CRUD navigation (Add, Edit, Delete) links.
  • Search, filtering, sorting, paging & export (Excel, CSV, PDF, Print).
  • AJAX‑driven modal details for viewing index lists.

🎯 Intended Use: Empower accounting administrators to create, view, and manage document type hierarchies and their associated indexes.


2. Dependencies & Technologies

Category Libraries / Frameworks
Front-end Syncfusion EJ2 TreeGrid, DataTables, jQuery, Bootstrap
Scripting JavaScript / jQuery
Server-side ASP.NET Core MVC Razor Views
AJAX & Utilities $.ajax, Syncfusion JavaScript Models
Export Engines jszip, pdfmake, DataTables Buttons

3. Model Binding & ViewModel

@model IrbyImaging.UI.Models.DocumentTypeView

DocumentTypeView supplies:

  • DocList: A collection (List<DocumentTypeDTO>) of root document types, each possibly with Children.
  • ImagingType & flags (IsLegal, IsSafety, etc.): Routing context to filter or tag types.
  • Id: Used for editing/deleting current context.

4. UI Layout & Components

Header & Actions

<h2>Document Types</h2>
  • Page Title bound via ViewBag: ensures consistency with layout.
  • Add New Document Type button triggers CreateType action.

Add‑New‑Type Form

<form asp-action="CreateType">
  @Html.HiddenFor(Model => Model.ImagingType)
  @*... other hidden flags *@
  <input type="submit" value="Add New Document Type" class="btn btn-success irby-green" />
</form>
  • Hidden fields preserve context (e.g., whether this is IsAccounting).
  • Submit navigates to AccountingImaging/CreateType.

Syncfusion TreeGrid

<ejs-treegrid id="TreeGrid"
    dataSource="Model.DocList"
    childMapping="Children"
    allowSorting="true"
    allowPaging="true"
    toolbar="@(new List<string> { "ExcelExport", "CsvExport", "PdfExport", "Print" })"
    ... >
  <!-- Column Definitions -->
</ejs-treegrid>

Key features:

  • Hierarchical data via childMapping="Children".
  • Toolbar with Export & Print.
  • Filtering, Sorting, Paging & Reordering.
  • Frozen Columns for quick reference.

Column Summary

Field Header Text Width Special Settings
Type Type 220px Default text
AttributeList Index List 150px Template (#typetemplate)
Category Category 220px —
IsAvailable Is Available 130px Center-aligned boolean
IsDeleted Is Deleted 120px Center-aligned boolean
AddedBy Added By 150px —
AddedDate Added Date 140px Date formatted via load()
ModifiedBy Modified By 150px —
ModifiedDate Modified Date 140px Date formatted via load()
Edit Edit 130px Template (#edittemplate)
Delete Delete 120px Template (#deletetemplate)
<div id="myModal" class="modal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div id="myModalContent"></div>
    </div>
  </div>
</div>
  • ID: myModal & content placeholder #myModalContent.
  • Populated via AJAX when View Indexes is clicked.

Column Templates

<script id="typetemplate" type="text/x-template">
  <a href="javascript:void(0);" class="anchorDetail" data-id=${Id}>View Indexes</a>
</script>

<script id="edittemplate" type="text/x-template">
  <a target="_blank" href="/AccountingImaging/EditType/${Id}">Edit</a>
</script>

<script id="deletetemplate" type="text/x-template">
  <a href="/AccountingImaging/DeleteType/${Id}">Delete</a>
</script>
  • Dynamic links built on ${Id}.
  • anchorDetail triggers AJAX detail load.

5. Scripts & Event Handlers

Search Functionality 🔍

document.getElementById('Search').addEventListener('click', function () {
  var val = document.getElementById('searchText').value;
  var treegrid = document.getElementById('TreeGrid').ej2_instances[0];
  treegrid.search(val);
});
  • Search button filters TreeGrid by matching text.

AJAX‑Loaded Modal Detail

var TeamDetailPostBackURL = '/AccountingImaging/myModal';

$(document.body).on('click', '.anchorDetail', function () {
  var id = $(this).data('id');
  $.ajax({
    type: "GET",
    url: TeamDetailPostBackURL,
    data: { id: id },
    success: function (data) {
      $('#myModalContent').html(data);
      $('#myModal').modal('show');
    },
    error: function () {
      alert("Dynamic content load failed.");
    }
  });
});
  • Delegated listener on .anchorDetail.
  • Loads partial view via GET to myModal endpoint, passing id.
  • Inserts HTML into modal, then .modal('show').

TreeGrid Initialization & Formatting

function load() {
  var tg = document.getElementById("TreeGrid").ej2_instances[0];
  tg.columns.forEach(col => {
    if (col.field === "AddedDate" || col.field === "ModifiedDate") {
      col.format = { type: 'date', format: 'M/d/yyyy' };
    }
  });
}
  • load event callback: formats date columns.

Toolbar Export Handlers 🚀

var collapsedStatePersist = true;

function toolbarClick(args) {
  var tg = document.getElementById("TreeGrid").ej2_instances[0];
  if (args.item.id.includes('_excelexport')) {
    tg.excelExport({ isCollapsedStatePersist: collapsedStatePersist });
  }
  else if (args.item.id.includes('_pdfexport')) {
    tg.pdfExport({ isCollapsedStatePersist: collapsedStatePersist });
  }
  else if (args.item.id.includes('_csvexport')) {
    tg.csvExport();
  }
}
  • Preserves collapse state for exports.
  • Supports Excel, PDF, CSV.

Grid Lines Toggle

function onChange(e) {
  var treegrid = document.getElementById("TreeGrid").ej2_instances[0];
  treegrid.gridLines = e.value; // e.g., 'Both', 'None', etc.
}
  • Dynamically switch grid line style.

6. Sample Usage & Code Snippets

Invoking the View from Controller

public IActionResult DocumentTypes()
{
    var model = new DocumentTypeView
    {
        ImagingType = ImagingType.Accounting,
        IsAccounting = true,
        DocList = _docService.GetAccountingDocTypes()
    };
    return View(model);
}

Partial to Render Index Details

// In AccountingImagingController
public IActionResult myModal(int id)
{
    var indexes = _docService.GetIndexesByTypeId(id);
    return PartialView("_DocumentIndexesModal", indexes);
}

7. UML Sequence Diagram

sequenceDiagram
    participant U as User
    participant V as Browser/JS
    participant TC as AccountingImagingController
    participant TS as TreeGridService

    U->>V: Load /DocumentTypes
    V->>TC: GET DocumentTypes()
    TC->>TS: GetAccountingDocTypes()
    TS-->>TC: List<DocumentTypeDTO>
    TC-->>V: Razor View + Model
    U->>V: Click "Search"
    V->>TreeGrid: treegrid.search(val)
    U->>V: Click "View Indexes"
    V->>TC: AJAX GET /myModal?id
    TC->>DataService: GetIndexesByTypeId(id)
    DataService-->>TC: List<IndexDTO>
    TC-->>V: PartialView(_DocumentIndexesModal)
    V->>V: Render Modal & Show

8. Conclusion & Next Steps

DocumentTypes.cshtml delivers a powerful tree‑structured management UI with advanced filtering, exporting, and AJAX‑driven details.

Next Steps:

  • Implement server-side API paging/filtering for large data sets.
  • Enhance error handling & loading indicators.
  • Add unit/integration tests for AJAX endpoints.

🎉 With this documentation, developers and stakeholders can confidently maintain or extend the Document Types UI in the Accounting Imaging module.