š FieldLogDraft.cshtml Documentation
š Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- View Model & Data Model
- Layout & Razor Markup
- Form: General Information Section
- Syncfusion EJ2 Grids
- Custom Styles & Themes
- JavaScript: Core Functionality
- Helper Methods & Utilities
- Integration Flows & Dialog Workflow
- Error Handling & Edge Cases
- UML Diagrams
- Sample Usage & Code Snippets
- Conclusion
1. Overview & Purpose
This FieldLogDraft.cshtml Razor view renders a Draft Field Log entry page for mechanicsā timesheets. It allows users to:
- Capture general information (date, time, status, foreman, etc.)
- Select and add Jobs, Cost Codes, Per Diem entries, Employees, and Equipment via a modal dialog
- Edit, Save, Submit, or Cancel the draft
- Automatically calculate work hours and update equipment hours based on start/stop times
:gear: Typical useācase: a foreman or supervisor drafts daily field logs, adding detailed lineāitem data before final submission.
2. Dependencies & Technologies
| Technology | Purpose | Version / Link |
|---|---|---|
| ASP.NET MVC (Razor) | Serverāside view engine | ā |
| Syncfusion EJ2 UI | Grids, DropDownList, Dialog, DatePicker⦠| 27.1.48 (CSS & JS from CDN) |
| jQuery | DOM manipulation, AJAX | 3.6.0 |
| DataTables | Clientāside exporting/printing | 1.10.25 (JS & Buttons extension) |
| Dropzone.js | File-upload support (if extended) | 5.5.1 |
| Bootstrap 4/5 & Icons | Responsive layout & icons | 4.5.2 / 1.10.5 |
| Newtonsoft.Json | JSON serialization in Razor | ā |
| IrbyImaging.DomainClasses | DomainModels (MechanicTimesheet, Job, etc.) | Internal library |
3. View Model & Data Model
@model IrbyImaging.DomainClasses.MechanicTimesheet
- MechanicTimesheet (Field Log Draft) properties used:
WorkDate,StartTime,EndTime,WorkHoursJobData,CostCodeClasses,PerDiemClasses,Employees,Equipment(populated viaViewBag)- Status tracking fields:
Status,ModifiedBy,ApprovedBy,RejectedNotes, etc.
:memo: Actual property names may differ in your domain class. This view expects the model and various ViewBag lists to be populated by the controller.
4. Layout & Razor Markup
@{
ViewData["Title"] = "Field Log Draft";
Layout = "~/Views/Shared/_TimeLayout.cshtml";
}
@using Syncfusion.EJ2;
@using Syncfusion.EJ2.Grids;
@using Syncfusion.EJ2.Popups;
@using Syncfusion.EJ2.Navigations;
@using Syncfusion.JavaScript;
@using Newtonsoft.Json;
@using IrbyImaging.DomainClasses;
- Title set to āField Log Draftā
- Shared Layout:
_TimeLayout.cshtml(provides navbar, footer, common scripts/styles) - Usings: Syncfusion EJ2 components & NewtonSoft.Json for inline serialization
5. Form: General Information Section
An expandable accordion titled General Information holds a <table> with:
| Field | Control Type | Key Attributes |
|---|---|---|
| Field Log ID | input[type=text] |
readonly, placeholder ā(New)ā |
| Status | input[type=text] |
readonly, placeholder āDraftā |
| Modified By/On | input[readonly] |
read-only user & timestamp |
| Approved By/On | input[readonly] |
|
| Rejected On/Notes | input[readonly] & input[readonly] |
|
| Work Start/Stop | <ejs-datepicker> & <ejs-timepicker> |
change="onTimeChange" |
| Foreman | <ejs-dropdownlist> |
Filtering, virtualization enabled |
| Shift Code | <ejs-dropdownlist> |
|
| Supervisor | input[type=text] |
free text |
| Work Hours | input[type=text] |
readonly, autoācalculated via JS |
| Field Office | <ejs-dropdownlist> |
|
| Notes | <textarea> |
free text |
<label>Work Start:</label>
<ejs-datepicker id="WorkDate" name="WorkDate"
format="MM/dd/yyyy" value="@ViewBag.WorkDate"></ejs-datepicker>
<ejs-timepicker id="StartTime" name="StartTime"
value="@ViewBag.StartTime" placeholder="Start Time"
change="onTimeChange"></ejs-timepicker>
6. Syncfusion EJ2 Grids
Each accordion panel below āGeneral Informationā hosts a <ejs-grid>:
- Jobs
- Cost Codes
- Per Diem
- Employees
- Equipment
All grids share:
- Toolbar: Create, Edit, Delete, Update, Cancel
- Paging, Selection (Multiple), Hover, Resizing
- Action/event handlers:
onGridLoad,onActionComplete,toolbarClick
6.1 Jobs Grid Example
<ejs-grid id="FieldLogJobGrid"
dataSource="@(ViewBag.JobData)"
toolbar="@(new List<string>{ "Create","Edit","Delete","Update","Cancel"})"
allowPaging="true" allowSelection="true" enableHover="true"
actionComplete="onActionComplete" toolbarClick="toolbarClick"
gridLines="Both" allowResizing="true" load="onGridLoad">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings>
<e-grid-selectionsettings type="Multiple"></e-grid-selectionsettings>
<e-grid-columns>
<e-grid-column type="checkbox" width="50"></e-grid-column>
<e-grid-column field="Value" headerText="Job Number" width="200" textAlign="Left" isPrimaryKey="true"></e-grid-column>
<e-grid-column field="Text" headerText="Job Name" width="200" textAlign="Left"></e-grid-column>
</e-grid-columns>
</ejs-grid>
š Other grids follow a similar pattern but include fields specific to Cost Codes, Per Diem, Employees, Equipment.
7. Custom Styles & Themes
Inline <style> blocks override default Syncfusion/Bootstrap styling:
- Fixed Top Navbar (
.fixed-top-nav,.status-bar) - Accordion (
.accordion,.panel) - Form Layout (
.form-container,.form-table) - Grid Styles (
.e-grid .e-headercell,.e-grid .e-gridcontent, toolbar button styling)
.accordion { cursor: pointer; transition: 0.4s; }
.accordion:after { content: '\002B'; float: right; }
.active:after { content: "\2212"; }
.panel { max-height: 0; overflow: hidden; transition: max-height 0.2s ease-out; }
8. JavaScript: Core Functionality
All scripts are loaded at the bottom of the view, including:
-
jQuery, DataTables, Dropzone, Syncfusion EJ2 (
ej2.min.js), Bootstrap JS, customapp.js -
Razorāembedded JSON:
dataSource="@Html.Raw(JsonConvert.SerializeObject(ViewBag.Employees))" -
Document Ready (
$(document).ready(...)) bootstraps:- Grid Instances for
FieldLogJobGrid,FieldLogEmployeeGrid,FieldLogEquipmentGrid - Dialog & Tabs (
ej.popups.Dialog,ej.navigations.Tab) for multiātab selection modal - Dialog Grids (
jobGrid,CostCodeGrid,PerDiemGrid,employeeGrid,equipmentGrid) - Event Handlers:
onTimeChangeā calculate & update work hoursonActionCompleteā refresh equipment/grid data when jobs changetoolbarClickā intercept āCreateā to open modal- Tab selection ā lazyāload grids once per tab
- Grid Instances for
var dialogObj = new ej.popups.Dialog({
header: 'Select Job Information',
isModal: true, width: '60%', height: '70%', visible: false,
buttons: [
{ click: addSelectedAndContinue, buttonModel: { content: 'Add & Continue', isPrimary: true } },
{ click: addSelectedItems, buttonModel: { content: 'Add Selected' } },
{ click: ()=> dialogObj.hide(), buttonModel: { content: 'Cancel', cssClass:'e-flat' } }
],
open: dialogOpen, close: dialogClose
});
dialogObj.appendTo('#defaultDialog');
var tabObj = new ej.navigations.Tab({
items: [
{ header:{'text':'Jobs'}, content:'#JobGrid' },
{ header:{'text':'Cost Code'}, content:'#CostCodeGrid' },
{ header:{'text':'Per Diem'}, content:'#PerDiemGrid' },
{ header:{'text':'Employees'}, content:'#EmployeeGrid' },
{ header:{'text':'Equipment'}, content:'#EquipmentGrid' }
],
selected: function(args){ currentTab = this.items[args.selectedIndex].header.text; }
});
tabObj.appendTo('#tab_default');
9. Helper Methods & Utilities
| Function | Purpose |
|---|---|
| addUnionCodeColumn(jobNumber) | Dynamically add a column under āUnion Codeā for a newly added Job |
| removeUnionCodeColumn(jobNumber) | Remove the Union Code subācolumn when a job is deleted |
| updateEquipmentBasedOnJobs() | AJAX-post selected job numbers to /TimeEntry/GetFilteredEquipment endpoint, then filter/update main equipment grid |
| processSelectedItems() | Core logic to add selected items from dialog tabs and detect duplicates |
| addSelectedJobs() | Add selected jobs to main grid, update union code columns, refresh equipment |
| addSelectedEmployees() | Add selected employees to main grid |
| addSelectedCostCodes() | Add selected cost codes to main grid |
| addSelectedPerDiem() | Add selected per diem entries |
| addSelectedEquipment() | Add selected equipment with CalcHours set to current work hours |
| clearAllSelections() | Clear selections in all dialog grids |
| dialogOpen() / dialogClose() | Show/hide the āAddā button and clear searches upon modal open/close |
| calculateHours() | Compute hours between start & end times (wraps midnight) and update controls |
| updateEquipmentGridHours() | Update all equipment rowsā CalcHours with newly calculated work hours |
10. Integration Flows & Dialog Workflow
sequenceDiagram
participant U as User
participant V as View
participant D as Dialog
participant S as Server
U->>V: Click "Add Job Information" (Create toolbar)
V->>D: dialogObj.show() with selected tab
U->>D: Select rows across tabs
U->>D: Click "Add Selected"
D->>V: processSelectedItems()
V->>V: addSelectedJobs(), addSelectedEmployees(), ... duplicates check
V->>S: AJAX /TimeEntry/GetFilteredEquipment (jobNumbers)
S-->>V: filtered equipment list
V->>V: updateEquipmentBasedOnJobs(), refresh grids
V-->>D: dialogObj.hide()
U<<--V: Updated main grids show new entries
11. Error Handling & Edge Cases
- Duplicate detection: alerts user of duplicate selections per category
- Time calculation: if end < start, wraps across midnight
- Grid reāfocus: retains search focus & selection via event hooks
- AJAX fallback: no explicit error callbackāimplement serverāside error checking in
/TimeEntry/GetFilteredEquipment
12. UML Diagrams
12.1 Class Diagram (Simplified)
classDiagram
class MechanicTimesheet {
+DateTime WorkDate
+DateTime StartTime
+DateTime EndTime
+decimal WorkHours
+string FieldOfficeId
+string Foreman
+string ShiftCode
+string Notes
+List<JobEntry> JobData
+List<CostCode> CostCodes
+List<PerDiem> PerDiemEntries
+List<Employee> Employees
+List<Equipment> EquipmentList
}
class JobEntry {
+string Value
+string Text
}
class Equipment {
+string AssetNumber
+string DisplayName
+decimal CalcHours
}
MechanicTimesheet --> JobEntry : JobData
MechanicTimesheet --> Equipment : EquipmentList
13. Sample Usage & Code Snippets
13.1 Controller Action
public IActionResult FieldLogDraft(int? id)
{
var model = id.HasValue
? _service.GetMechanicTimesheet(id.Value)
: new MechanicTimesheet();
ViewBag.Jobs = _jobService.GetSelectList();
ViewBag.CostCodeClasses= _costCodeService.GetSelectList();
ViewBag.PerDiemClasses = _perDiemService.GetSelectList();
ViewBag.Employees = _empService.GetSelectList();
ViewBag.Equipment = _equipService.GetAll();
ViewBag.WorkDate = DateTime.Today;
ViewBag.StartTime = DateTime.Today.AddHours(7);
ViewBag.EndTime = DateTime.Today.AddHours(16);
return View(model);
}
13.2 Razor DropdownList Setup
@{
var JobDropDownList = new Syncfusion.EJ2.DropDowns.DropDownList() {
DataSource = ViewBag.Jobs,
AllowFiltering = true,
Placeholder = "Select a Job",
Fields = new DropDownListFieldSettings { Text = "Text", Value = "Value" }
};
}
@Html.EJS().DropDownList("jobSearch", JobDropDownList)
14. Conclusion
This Field Log Draft view merges rich clientāside UI components (Syncfusion EJ2 Grids, Dialogs, Date/Time pickers) with serverāside Razor data binding to deliver a featureācomplete timesheet drafting interface.
Key takeaways:
- Modular grids for each data category with ināplace editing & selection dialog
- Realātime calculations for work and equipment hours
- Dynamic column management (Union Code stacking)
- Scalable architecture: new tabs or grid types can be added with minimal changes
:rocket: With this documentation, developers can understand, extend, and maintain the FieldLogDraft.cshtml viewāensuring seamless timesheet management for field operations.