🗂️ DocumentCategories.cshtml Documentation


📖 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Models
  4. Layout & Page Configuration
  5. UI Components
  6. Helper Templates & Styling
  7. Client-Side Scripts & Event Handlers
  8. API Endpoints Overview
  9. Sequence Diagram: “View Types” Flow
  10. Usage Example
  11. Conclusion

1. Overview & Purpose

The DocumentCategories.cshtml Razor View is part of the LegalImaging area in the IrbyImaging project. It enables users to:

  • 📑 List document categories in a hierarchical TreeGrid.
  • ➕ Add, ✏️ Edit, and 🗑️ Delete categories.
  • 🔍 Search within categories.
  • 📤 Export grid data (Excel, CSV, PDF, Print).
  • 📦 View sub-types in a modal dialog via AJAX.

This view builds on Syncfusion EJ2 components to deliver a rich, responsive UI.


2. Dependencies & Technologies

Category Technology / Library
Server-Side Framework ASP.NET Core Razor Pages
UI Components Syncfusion.EJ2 TreeGrid & Button 🎨
AJAX & DOM jQuery 3.5.1
DataTables Exports DataTables (Buttons, JSZip, pdfmake) 📦
Modal & Layout Bootstrap 4 Modal & Grid
Custom CSS irby-green button, minor overrides
@using Syncfusion.JavaScript
@using Syncfusion.JavaScript.Models
@model IrbyImaging.UI.Models.DocumentCategoryView

3. View Model & Data Models

DocumentCategoryView (Model)

Property Type Description
Id int Current category root node ID
ImagingType string / enum Filter by imaging type (Legal/Safety/IT)
IsLegal bool Flag: Legal
IsSafety bool Flag: Safety
IsIT bool Flag: IT
DocList List<CategoryNode> Hierarchical data for TreeGrid

CategoryNode (simplified)

public class CategoryNode {
    public int Id { get; set; }
    public string Name { get; set; }
    public string TypeList { get; set; }
    public bool IsAvailable { get; set; }
    public bool IsDeleted { get; set; }
    public string AddedBy { get; set; }
    public DateTime AddedDate { get; set; }
    public string ModifiedBy { get; set; }
    public DateTime ModifiedDate { get; set; }
    public List<CategoryNode> Children { get; set; }
}

4. Layout & Page Configuration

@{
    ViewBag.Title     = "Document Categories";
    ViewBag.pTitle    = "Document Categories";
    ViewBag.pageTitle = "Document Categories";
    Layout           = "~/Views/Shared/_LegalLayout.cshtml";
}
<h2>Document Categories</h2>
  • Layout: Inherits from _LegalLayout.cshtml.
  • ViewBag: Sets dynamic titles for the page header and breadcrumbs.

5. UI Components

➕ Add New Document Category Button

<form asp-action="CreateCategory">
  @Html.HiddenFor(m => m.ImagingType)
  @Html.HiddenFor(m => m.IsLegal)
  @Html.HiddenFor(m => m.IsSafety)
  @Html.HiddenFor(m => m.IsIT)
  <div class="form-group">
    <input type="submit"
           value="Add New Document Category"
           class="btn btn-success irby-green" />
  </div>
</form>
  • asp-action: Submits to CreateCategory action in LegalImagingController.
  • Hidden Fields: Preserve current filter flags.

<div style="float:right;">
  <input type="text" id="searchText" placeholder="Search…">
  <ejs-button id="Search" content="Search" cssClass="e-primary"></ejs-button>
</div>
  • ejs-button: Syncfusion button triggers client-side search on the TreeGrid.

📊 Syncfusion EJ2 TreeGrid

<ejs-treegrid id="TreeGrid"
              dataSource="Model.DocList"
              childMapping="Children"
              treeColumnIndex="0"
              allowPaging="true"
              allowSorting="true"
              allowFiltering="true"
              allowReordering="true"
              allowTextWrap="true"
              allowExcelExport="true"
              allowPdfExport="true"
              toolbar="@(new List<string>() { "ExcelExport", "CsvExport", "PdfExport", "Print" })"
              width="auto" height="100%">
  <e-treegrid-pagesettings pageSize="10" />
  <e-treegrid-filtersettings type="Excel" />
  <e-treegrid-columns>
    <!-- Columns Configuration -->
  </e-treegrid-columns>
</ejs-treegrid>

Key Features

  • Paging (10 rows/page)
  • Sorting, Filtering, Reordering, Text Wrap
  • Export: Excel, CSV, PDF, Print
  • Child Nodes: childMapping="Children"

Column Overview

Field HeaderText Width Sorting Filtering Template
Name Name 220 ✔️ ✔️ —
TypeList Type List 150 ✔️ ✔️ #typetemplate
IsAvailable Is Available 150 ✔️ ✔️ —
IsDeleted Is Deleted 150 ✔️ ✔️ —
AddedBy Added By 150 ✔️ ✔️ —
AddedDate Added Date 150 ✔️ ✔️ Formatted (M/d/yyyy)
ModifiedBy Modified By 150 ✔️ ✔️ —
ModifiedDate Modified Date 150 ✔️ ✔️ Formatted (M/d/yyyy)
Edit Edit/Update 150 ✔️ ✔️ #edittemplate
Delete Delete 150 ✔️ ✔️ #deletetemplate

<div id='myModal' class='modal'>
  <div class="modal-dialog">
    <div class="modal-content">
      <div id='myModalContent'></div>
    </div>
  </div>
</div>
  • ID: myModal
  • Content Region: Dynamically loaded via AJAX (#myModalContent).

6. Helper Templates & Styling

<!-- Edit Button Template -->
<script id="edittemplate" type="text/x-template">
  <a target="_blank" href="/LegalImaging/EditCategory/${Id}">Edit</a>
</script>

<!-- Delete Button Template -->
<script id="deletetemplate" type="text/x-template">
  <a href="/LegalImaging/DeleteCategory/${Id}">Delete</a>
</script>

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

<style>
  /* Ensure checkbox alignment */
  #property td div.e-checkbox-wrapper {
    padding-left: 0 !important;
    padding-top: 0 !important;
  }
</style>
  • ${Id}: Syncfusion allows inline templates to bind the row’s Id.

7. Client-Side Scripts & Event Handlers

7.1 Search Handler

document.getElementById('Search')
  .addEventListener('click', function() {
    const val = document.getElementById('searchText').value;
    const treegrid = document.getElementById('TreeGrid').ej2_instances[0];
    treegrid.search(val);
});
  • Uses TreeGrid.search() to filter rows by text.

7.2 AJAX “View Types” Handler

$(document).on('click', '.anchorDetail', function() {
  const id = $(this).data('id');
  $.ajax({
    type: "GET",
    url: '/LegalImaging/myModalCategory',
    data: { id },
    success: function(data) {
      $('#myModalContent').html(data);
      $('#myModal').modal('show');
    },
    error: function() {
      alert("Dynamic content load failed.");
    }
  });
});
  • Fetches partial view listing Types for a category.
  • Displays bootstrap modal.

7.3 TreeGrid Load Event Formatter

function load() {
  const grid = document.getElementById('TreeGrid').ej2_instances[0];
  grid.columns.forEach(col => {
    if (col.field === 'AddedDate' || col.field === 'ModifiedDate') {
      col.format = { type: 'date', format: 'M/d/yyyy' };
    }
  });
}
  • Ensures date columns display in M/d/yyyy format.

7.4 Export Toolbar Click Handler

let collapsedStatePersist = true;

function toolbarClick(args) {
  const treeGrid = document.getElementById("TreeGrid").ej2_instances[0];
  const id = args.item.id;
  if (id.endsWith('_excelexport')) {
    treeGrid.excelExport({ isCollapsedStatePersist: collapsedStatePersist });
  } else if (id.endsWith('_pdfexport')) {
    treeGrid.pdfExport({ isCollapsedStatePersist: collapsedStatePersist });
  } else if (id.endsWith('_csvexport')) {
    treeGrid.csvExport();
  }
}

function onChange(args) {
  collapsedStatePersist = args.checked;
}
  • Persist collapsed state across exports.
  • Conditional logic for Excel/CSV/PDF/Print.

7.5 Grid Lines Toggle Handler

function onChange(e) {
  const treegrid = document.getElementById("TreeGrid").ej2_instances[0];
  treegrid.gridLines = e.value; // none, both, horizontal, vertical
}
  • Dynamically switch grid line visibility.

8. API Endpoints Overview

Endpoint Method Description
/LegalImaging/CreateCategory GET/POST Render/create new category
/LegalImaging/EditCategory/{id} GET/POST Edit existing category by ID
/LegalImaging/DeleteCategory/{id} GET Delete category by ID
/LegalImaging/myModalCategory GET Return partial view of Types list

9. Sequence Diagram: “View Types” Flow

sequenceDiagram
    User->>Viewport: Click "View Types"
    Viewport->>Ajax: GET /LegalImaging/myModalCategory?id=X
    Ajax-->>Server: Request category types
    Server-->>Ajax: HTML Partial View
    Ajax->>Viewport: Inject into #myModalContent
    Viewport->>Modal: Show modal dialog

10. Usage Example

  1. Navigate to /LegalImaging/DocumentCategories?isLegal=true.
  2. Click ➕ “Add New Document Category” to open the create form.
  3. Use the Search box to quickly filter categories.
  4. Expand/Collapse tree nodes; view sub-types by clicking “View Types”.
  5. Export your data via the toolbar (Excel, CSV, PDF, Print).
  6. Edit or Delete with the inline links.

11. Conclusion

The DocumentCategories.cshtml view is a rich, interactive component designed for legal and safety document management. Leveraging Syncfusion EJ2 TreeGrid, it provides:

  • Hierarchical data visualization
  • Client-side filtering, sorting, paging
  • Powerful export options
  • Seamless AJAX modals

This comprehensive documentation should help you understand, extend, and maintain the Document Categories page with confidence! 🚀


^Generated with ❤️ by your friendly AI assistant.