πŸ“ FormsDirectory.cshtml Documentation

Location: IrbyImaging/Views/IrbyForms/FormsDirectory.cshtml


πŸ—‚ Table of Contents

  1. Overview & Purpose
  2. Layout & Page Structure
  3. Dependencies & Technologies
  4. UI Components
    4.1 FileManager
    4.2 Document Editor
    4.3 PDF Viewer
    4.4 Spreadsheet
  5. Event Handlers & Helper Functions
  6. AJAX Endpoints & Controller Integration
  7. Third-Party Integrations
  8. Styling & Layout CSS
  9. UML Sequence Diagram
  10. Usage Examples
  11. Conclusion

1. Overview & Purpose

This Razor View provides a centralized interface to manage, view, and edit various document types (Word, PDF, Excel, Text) in the Irby Imaging application.

  • 🎯 Key Goals
    • File operations (upload, download, create folder, move, rename, delete).
    • In-browser viewing/editing of supported documents using Syncfusion EJ2 controls.
    • Seamless integration with server-side endpoints for persistence.

2. Layout & Page Structure

@* ViewData & Layout *@
@*{ 
    ViewData["Title"] = "Irby Forms Page"; 
    Layout = "~/Views/Shared/_HDLayout.cshtml"; 
}*@
  • The ViewData title and Layout are currently commented out.
  • The page is organized into a Bootstrap card containing a primary file manager and three hidden viewer containers:
    • .file-container
    • .doc-container
    • .pdf-container
    • .excel-container

3. Dependencies & Technologies

Technology Purpose
Syncfusion EJ2 Components FileManager, DocumentEditor, PDFViewer, Spreadsheet
jQuery AJAX Server communication for file/document operations
Bootstrap (Grid & Card) Responsive layout
Razor (cshtml) Server-side view

4. UI Components

4.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="/IrbyForms/FileOperations"
      downloadUrl="/IrbyForms/Download"
      uploadUrl="/IrbyForms/Upload"
      getImageUrl="/IrbyForms/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>

Features:

  • CRUD operations on files/folders
  • Context menu & toolbar enabled
  • Drag & drop support
  • Thumbnail previews

4.2 Document Editor

<div class="doc-container">
  <div class="title-container">
    <span class="doc-title title"></span>
    <button class="close-button" onclick="onClicked()">βœ–οΈ</button>
  </div>
  <ejs-documenteditorcontainer
      id="document"
      enableToolbar="true"
      style="display:block;height:calc(100% - 22px)">
  </ejs-documenteditorcontainer>
</div>
  • Renders .docx, .txt, .rtf, etc. with full editing capabilities.

4.3 PDF Viewer

<div class="pdf-container">
  <div class="title-container">
    <span class="pdf-title title"></span>
    <button class="close-button" onclick="onClicked()">βœ–οΈ</button>
  </div>
  <ejs-pdfviewer 
      id="pdfViewer"
      serviceUrl="https://ej2services.syncfusion.com/production/web-services/api/pdfviewer"
      style="height:calc(100% - 22px);display:block">
  </ejs-pdfviewer>
</div>
  • Loads .pdf files via a remote service.
  • Viewing only (printing, zooming, navigation).

4.4 Spreadsheet

<div class="excel-container">
  <div class="title-container">
    <span class="excel-title title"></span>
    <button class="close-button" onclick="onClicked()">βœ–οΈ</button>
  </div>
  <div id="customvalue"></div>
  <ejs-spreadsheet 
      id="spreadsheet"
      openUrl="/IrbyForms/OpenExcel"
      allowOpen="true"
      saveUrl="/IrbyForms/SaveExcel"
      select="onSelect"
      openComplete="onOpenComplete">
  </ejs-spreadsheet>
</div>
  • Displays .xlsx sheets.
  • Custom logic on cell selection to show metadata.

5. Event Handlers & Helper Functions

5.1 Drag & Drop Callbacks

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

Simple console.log stubsβ€”extend for custom drag/drop UX.


5.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) {
  // Map toolbar-button IDs ➑️ human-friendly descriptions
  // Builds `this.content` dynamically based on `buttonId`
}

Purpose: Enhance native Syncfusion tooltips with longer, formatted descriptions.


5.3 File Load / Open Logic

function fileOpen(args) {
  var { name, filterPath, type } = args.fileDetails;
  var filePath = filterPath.replace(/\\/g, "/") + name;

  switch(type.toLowerCase()) {
    case ".docx": case ".txt": case ".rtf": case ".html": case ".xml":
      getFileStream(filePath, false);
      break;
    case ".pdf":
      getFileStream(filePath, true);
      break;
    case ".xlsx":
      showExcelViewer(name);
      getBlob(name, filePath);
      break;
  }
}
  • getFileStream: Fetches base64 document or PDF and opens in new window with Syncfusion viewer/editor.
  • getBlob: Downloads Excel as Blob β†’ loads into EJ2 Spreadsheet control.

5.4 Viewer Toggle

function onClicked() {
  // Hide all viewers, show file manager
  document.querySelector(".file-container").style.visibility   = "visible";
  document.querySelector(".doc-container").style.visibility    = "hidden";
  document.querySelector(".pdf-container").style.visibility    = "hidden";
  document.querySelector(".excel-container").style.visibility  = "hidden";
}

5.5 Spreadsheet Custom Methods

var customArgs;

function onOpenComplete(args) {
  customArgs = args.response.data.customArgs;
}

function onSelect(args) {
  var sheetIndex = document.getElementById("spreadsheet")
                  .ej2_instances[0].activeSheetTab - 1;

  customArgs.forEach(item => {
    if (item.sheetIndex === sheetIndex
     && args.range === `${item.address}:${item.address}`) {
      document.getElementById("customvalue").innerHTML = item.customValue;
    }
  });
}

On cell-click, show related metadata below the sheet.


6. AJAX Endpoints & Controller Integration

Endpoint HTTP Method Description
/IrbyForms/FileOperations POST CRUD on file system (Syncfusion FileManager)
/IrbyForms/Download GET Download selected file(s)
/IrbyForms/Upload POST Upload file(s)
/IrbyForms/GetImage GET Thumbnail/image retrieval
/IrbyForms/GetDocument POST Β Fetch base64 for Doc/PDF viewers
/IrbyForms/GetExcel GET Fetch .xlsx blob for Spreadsheet
/IrbyForms/OpenExcel GET EJ2 Spreadsheet open URL
/IrbyForms/SaveExcel POST EJ2 Spreadsheet save URL
/api/IrbyForms POST PDF Web API service for Syncfusion

7. Third-Party Integrations

  • Syncfusion EJ2
    • ejs-filemanager
    • ejs-documenteditorcontainer
    • ejs-pdfviewer
    • ejs-spreadsheet
  • jQuery for AJAX requests.
  • ej.popups.Tooltip (Syncfusion popup module)

8. Styling & Layout CSS

.file-container { width:100%; height:100%; }
.doc-container, .pdf-container, .excel-container {
  position:absolute; top:0; visibility:hidden;
}
.title-container { background:#eee; height:22px; }
.close-button { float:right; }
body, html { margin:0; width:100%; height:100%; }
  • Hide/Show logic anchored on .visibility toggles.
  • Containers overlap via absolute positioning.

9. UML Sequence Diagram

sequenceDiagram
  participant U as User
  participant FM as FileManager
  participant VC as ViewContainer
  participant S as Server

  U->>FM: Double-click file
  FM-->>JS: fileOpen(args)
  alt Document/PDF
    JS->>S: POST /IrbyForms/GetDocument {FileName, Action}
    S-->>JS: base64 Data
    JS->>VC: open new window + render Document/PDF
  else Excel
    JS->>VC: showExcelViewer()
    JS->>S: GET /IrbyForms/GetExcel?FileName=...
    S-->>JS: Blob
    JS->>Spreadsheet: open(blob)
  end

10. Usage Examples

Open a PDF in the Viewer

  1. Double-click a .pdf file in the FileManager.
  2. AJAX GetDocument β†’ new browser window opens.
  3. PDF loads in Syncfusion PDFViewer.

Edit a Word Document

// from fileOpen:
getFileStream("Forms/MyDoc.docx", false);
  • Opens a new window with EJ2 DocumentEditor for full WYSIWYG editing.

11. Conclusion

This FormsDirectory.cshtml view is a powerful file-management and document-handling interface, leveraging Syncfusion EJ2 components for a seamless in-browser experience. With well-defined AJAX endpoints and helper methods, it enables users to view, edit, and manage multiple file types from a single UI.

Feel free to extend:

  • Additional file-types (e.g., images, CSV).
  • Enhanced error-handling (user alerts, toasts).
  • Custom UI theming to match the Irby corporate style.

Happy coding! πŸš€