📁 DocumentsDirectory.cshtml Documentation

Welcome to the comprehensive documentation for IrbyImaging/Views/LegalImaging/DocumentsDirectory.cshtml. This view is the heart of the Legal Imaging module in the Irby portal, providing users with a rich interface to browse, view, upload, download, and edit documents of various types (DOCX, PDF, XLSX, etc.).


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Template Structure & Layout
  4. Key Functional Areas
  5. Controls Configuration
  6. JavaScript Helpers & Utilities
  7. API Endpoints Overview
  8. Error Handling & Return Types
  9. UML Diagrams & Flowcharts
  10. Usage Examples
  11. Conclusion

1️⃣ 1. Overview & Purpose

File: Views/LegalImaging/DocumentsDirectory.cshtml
Purpose:

  • Provide a centralized document manager for legal imaging
  • Enable file operations: create folder, upload, download, rename, delete, sort, drag‑and‑drop
  • Support in-browser viewers/editors for Word, PDF, and Excel files

Intended Audience:

  • Legal staff uploading and organizing case documents
  • Administrators reviewing, annotating, and distributing files

2️⃣ 2. Dependencies & Technologies

Technology Version/Details
ASP.NET MVC View Layout: _LegalLayout.cshtml
Syncfusion EJ2 ejs-filemanager, ejs-documenteditorcontainer, ejs-pdfviewer, ejs-spreadsheet
jQuery & AJAX For client‑side HTTP calls
CSS Custom styles at bottom of file
JSON Data interchange format for AJAX calls

Third‑Party Integrations

  • Syncfusion EJ2 Services
    • Document Editor: https://ej2services.syncfusion.com/.../documenteditor
    • PDF Viewer: https://ej2services.syncfusion.com/.../api/pdfviewer
    • Spreadsheet: https://ej2services.syncfusion.com/.../api/spreadsheet

3️⃣ 3. Template Structure & Layout

@{
    ViewData["Title"] = "Irby Legal";
    Layout = "~/Views/Shared/_LegalLayout.cshtml";
}
<div class="row">
  <div class="col-lg-14">
    <div class="card">
      <div class="card-body">
        <h4 class="card-title mb-4">Manage Documents</h4>
        <div control-section">
          <!-- ... FileManager + Viewer containers ... -->
        </div>
      </div>
    </div>
  </div>
</div>
  • ViewData & Layout

    • Sets page title (Irby Legal)
    • Uses shared legal layout (_LegalLayout.cshtml)
  • Bootstrap Card

    • Presents a titled card: “Manage Documents”
  • Containers

    • .file-container: Default file manager
    • .doc-container: Word/Document Editor
    • .pdf-container: PDF Viewer
    • .excel-container: Spreadsheet Viewer

4️⃣ 4. Key Functional Areas

  1. File Management

    • Browse, search, sort, drag‑and‑drop, context menu operations
  2. Document Editing

    • In‑browser editing of .docx, .txt, .rtf, etc.
  3. PDF Viewing

    • Render and navigate PDF files
  4. Spreadsheet Viewing

    • Open and view Excel files (.xlsx)

5️⃣ 5. Controls Configuration

5.1 FileManager

<ejs-filemanager id="file"
    fileOpen="fileOpen"
    height="650px" created="addTooltip"
    showThumbnail="true" enablePersistence="true"
    allowMultiSelection="true" view="Details"
    allowDragAndDrop="true"
    fileDragStart="onFileDragStart"
    fileDragStop="onFileDragStop"
    fileDragging="onFileDragging"
    fileDropped="onFileDropped">
  <e-filemanager-ajaxsettings
      url="/LegalImaging/FileOperations"
      downloadUrl="/LegalImaging/Download"
      uploadUrl="/LegalImaging/UploadFiles"
      getImageUrl="/LegalImaging/GetImage">
  </e-filemanager-ajaxsettings>
  <e-filemanager-contextmenusettings visible="true"></e-filemanager-contextmenusettings>
  <e-filemanager-navigationpanesettings visible="true"></e-filemanager-navigationpanesettings>
  <e-filemanager-toolbarsettings visible="true"></e-filemanager-toolbarsettings>
</ejs-filemanager>
  • ajaxsettings:

    • FileOperations: CRUD
    • Download, UploadFiles, GetImage
  • Events:

    • fileOpen, drag events, created → addTooltip()

5.2 DocumentEditorContainer

<ejs-documenteditorcontainer
    id="document"
    enableToolbar="true"
    style="display:block;height:calc(100% - 22px)">
</ejs-documenteditorcontainer>
  • Renders Syncfusion Document Editor
  • Toolbar enabled

5.3 PdfViewer

<ejs-pdfviewer
    id="pdfViewer"
    serviceUrl='https://ej2services.syncfusion.com/production/web-services/api/pdfviewer'
    style="height:calc(100% - 22px);display:block">
</ejs-pdfviewer>
  • Connects to Syncfusion PDF service

5.4 Spreadsheet

<ejs-spreadsheet
    id="spreadsheet"
    openUrl="/IrbyForms/OpenExcel"
    allowOpen="true"
    saveUrl="/IrbyForms/SaveExcel"
    select="onSelect"
    openComplete="onOpenComplete">
</ejs-spreadsheet>
  • Open/Save Excel via server endpoints

6️⃣ 6. JavaScript Helpers & Utilities

6.1 File Operation Event Handlers

function onFileDragStart() { console.log("Drag start"); }
function onFileDragStop() { console.log("Drag stop"); }
function onFileDragging() { console.log("File Dragging"); }
function onFileDropped() { console.log("File Dropped"); }

6.2 Tooltip Customization

function addTooltip() {
  var fileObj = document.getElementById("file").ej2_instances[0];
  var tooltip = new ej.popups.Tooltip({
    target: '#' + fileObj.element.id + '_toolbar [title]',
    beforeRender: onTooltipBeforeRender
  });
  tooltip.appendTo('#' + fileObj.element.id + '_toolbar');
}

function onTooltipBeforeRender(args) {
  var fileObjId = document.getElementById("file").ej2_instances[0].element.id;
  var buttonId  = args.target.childNodes[0].id;
  var description = '';
  switch (buttonId) {
    case fileObjId + '_tb_newfolder': description = 'Create a new folder'; break;
    case fileObjId + '_tb_upload':    description = 'Upload new files'; break;
    // ... other cases ...
  }
  this.content = args.target.getAttribute('title') + '</br>' + description;
}

6.3 File Loading & Opening

function fileOpen(args) {
  var name = args.fileDetails.name;
  var path = args.fileDetails.filterPath.replace(/\\/g, "/") + name;
  switch (args.fileDetails.type) {
    case ".docx": case ".txt": // Document
      getFileStream(path, false);
      break;
    case ".pdf":
      getFileStream(path, true);
      break;
    case ".xlsx":
      getBlob(name, path);
      break;
  }
}

6.4 Viewer Display Methods

function showDocViewer(name) {
  document.querySelector(".doc-title").textContent = name;
  toggleContainers('doc');
}
function showPDFViewer(name) {
  document.querySelector(".pdf-title").textContent = name;
  toggleContainers('pdf');
}
function showExcelViewer(name) {
  document.querySelector(".excel-title").textContent = name;
  toggleContainers('excel');
}
function onClicked() {
  toggleContainers('file');
}
function toggleContainers(active) {
  const states = ['file','doc','pdf','excel'];
  states.forEach(s => {
    document.querySelector(`.${s}-container`).style.visibility = (s === active) ? 'visible' : 'hidden';
  });
}

6.5 AJAX FileStream & Blob Retrieval

// For DOC/PDF
function getFileStream(filePath, isPDF) {
  $.ajax({
    url: '/LegalImaging/GetDocuments',
    type: 'POST',
    contentType: 'application/json',
    data: JSON.stringify({
      FileName: filePath,
      Action: isPDF ? "LoadPDF" : "ImportFile"
    }),
    success: function(data) {
      openInNewWindow(data, isPDF);
    },
    error: function(xhr) {
      alert('Exception: ' + xhr.responseText);
    }
  });
}

// For Excel
function getBlob(fileName, filePath) {
  openInNewWindow(null, 'excel', fileName, filePath);
}

6.6 Spreadsheet Callbacks

function onOpenComplete(args) {
  // CustomArgs returned by server
  window.customArgs = args.response.data.customArgs;
}
function onSelect(args) {
  let sheetIdx = document.querySelector("#spreadsheet").ej2_instances[0].activeSheetTab - 1;
  let info = window.customArgs.find(c => c.sheetIndex === sheetIdx && args.range === c.address + ":" + c.address);
  document.getElementById("customvalue").innerHTML = info ? info.customValue : '';
}

7️⃣ 7. API Endpoints Overview

Endpoint Verb Description
/LegalImaging/FileOperations POST CRUD operations (create folder, delete)
/LegalImaging/Download GET Download selected file/folder
/LegalImaging/UploadFiles POST Upload new files
/LegalImaging/GetImage GET Fetch thumbnails
/LegalImaging/GetDocuments POST Retrieve file as Base64 for viewer/editor
/IrbyForms/OpenExcel POST Stream Excel for EJ2 spreadsheet
/IrbyForms/SaveExcel POST Save workbook

8️⃣ 8. Error Handling & Return Types

  • AJAX error callback: alert('Exception: ' + xhr.responseText)
  • Server returns JSON or text containing Base64 streams
  • Spreadsheet: custom data in response.data.customArgs

9️⃣ 9. UML Diagrams & Flowcharts

9.1 Sequence Diagram (Mermaid)

sequenceDiagram
    User->>FileManager: Click on file (Open)
    FileManager->>DocumentsDirectory.js: fileOpen(args)
    DocumentsDirectory.js->>Server: POST /LegalImaging/GetDocuments
    alt Response Success
        DocumentsDirectory.js->>Window: open new tab
        Window->>SyncfusionService: init DocumentEditor/PDFViewer
        SyncfusionService->>Window: render viewer
    else Error
        DocumentsDirectory.js->>Alert: show exception
    end

9.2 Component Diagram (Mermaid)

graph TD
  subgraph Browser
    FM[FileManager Control]
    DE[DocumentEditorContainer]
    PV[PDFViewer]
    SP[Spreadsheet]
    FM -->|AJAX| Server
    DE -->|ServiceUrl| SyncfusionDocService
    PV -->|ServiceUrl| SyncfusionPDFService
    SP -->|Open/SaveUrl| Server
  end
  subgraph Server
    API[/LegalImaging API/]
    IrbyFormsAPI[/IrbyForms API/]
  end
  Server --> API
  Server --> IrbyFormsAPI

🔟 10. Usage Examples

  1. Upload a file

    • Click Upload toolbar button
    • Select file(s) → Syncfusion FileManager handles POST to /LegalImaging/UploadFiles
  2. Open a PDF

    • Double‑click .pdf → fileOpen calls getFileStream(path, true)
    • AJAX returns Base64 → new window displays PDF via Syncfusion PDFViewer
  3. View & Edit DOCX

    • Double‑click .docx → getFileStream(path, false)
    • Loads DocumentEditor with editable content
  4. Inspect Custom Excel Cell

    • Open an .xlsx → onOpenComplete stores customArgs
    • Click a cell → onSelect shows metadata

1️⃣1️⃣ 11. Conclusion

DocumentsDirectory.cshtml is a feature‑rich, client‑side heavy view that leverages Syncfusion EJ2 components to deliver a seamless document management experience. Through custom JavaScript, AJAX endpoints, and third‑party services, it provides:

  • 🗂️ Full file system navigation
  • ✏️ In‑browser document editing
  • 📄 PDF rendering
  • 📊 Spreadsheet visualization

By following this documentation, developers can extend, customize, or debug the Legal Imaging module with confidence.


Happy coding! 🚀