📄 EditCrew.cshtml Documentation
Welcome to the comprehensive documentation for IrbyImaging/Views/FieldLog/EditCrew.cshtml. This Razor view enables editing a Crew entity—managing its name, associated job, employees, equipment, rates, times, and cost codes—via a rich UI powered by Tailwind CSS, jQuery, and Syncfusion EJ2 controls.
📑 Table of Contents
- Overview & Purpose
- Layout & Structure
- Dependencies & Technologies
- ViewModel & Data Models
- Key Functional Areas
- Helper Methods & Utilities
- Error Handling & Logging
- API Endpoints Overview
- Third-party Integrations
- Sample Code Snippets
- Usage Examples
- UML Diagrams
- Conclusion
1. Overview & Purpose
This Razor view renders an Edit Crew form, allowing users to:
- Update Crew Name and associated Job
- Add / Remove Employees, specifying:
- Employee
- Cost Code
- Job Classification
- Per Diem Type & Rate
- Start Time
- Add / Remove Equipment, specifying:
- Equipment
- Cost Code
- Worked Hours
- Submit the assembled data via AJAX to the server for persistence.
🔑 Primary Goal: Provide an interactive, responsive UI for managing complex nested data (crew → employees & equipment) with rich filtering logic.
2. Layout & Structure
@model CrewViewModel
@{
ViewData["Title"] = "Edit Crew";
Layout = "~/Views/Shared/_TimeLayout.cshtml";
}
<!-- Stylesheets & Scripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet"/>
<script src="//cdn.syncfusion.com/ej2/ej2-inputs/dist/global/ej2-inputs.min.js"></script>
<div class="container mx-auto p-6">
<h1 class="text-2xl font-bold mb-4">Edit Crew</h1>
<form id="editCrewForm">
<!-- Hidden CrewId -->
<input type="hidden" id="crewId" value="@Model.CrewId" />
<!-- Crew Name -->
<div class="mb-4">
<label for="crewName">Crew Name</label>
<input id="crewName" name="crewName" value="@Model.CrewName" required/>
</div>
<!-- Job Dropdown -->
<div class="mb-4">
<label for="jobSelect">Select Job</label>
<div id="jobSelect"></div>
</div>
<!-- Employees & Equipment Sections -->
<div id="employeesSection"></div>
<button id="addEmployeeRow">Add Employee</button>
<div id="equipmentSection"></div>
<button id="addEquipmentRow">Add Equipment</button>
<!-- Submit -->
<button type="submit">Update Crew</button>
</form>
</div>
@model CrewViewModelbinds the view to the server-side data.Layoutreferences a shared layout for header/footer.- Containers:
- Employees in
#employeesSection - Equipment in
#equipmentSection
- Employees in
3. Dependencies & Technologies
| Library / Framework | Version | Purpose |
|---|---|---|
| jQuery | 3.7.1 | DOM manipulation, event binding |
| Tailwind CSS | 2.2.19 | Utility-first styling |
| Font Awesome | 6.4.0 | Iconography |
| Syncfusion EJ2 Dropdowns | Latest | Rich dropdown & time-picker components |
| ASP.NET Core Razor | — | Server-side view rendering |
4. ViewModel & Data Models
CrewViewModel (server-side C# model) provides:
| Property | Type | Description |
|---|---|---|
string CrewId |
string (GUID) | Unique identifier for the Crew |
string CrewName |
string | Name of the Crew |
string JobId |
string | Selected Job identifier |
List<Job> Jobs |
List of key/value pairs | Available jobs |
List<Employee> Employees |
List of key/value pairs | Available employees |
List<CostCode> CostCodes |
List of key/value pairs | All cost codes |
List<Class> Classes |
List of key/value pairs | Job classifications |
List<CrewEmployee> CrewEmployees |
Prepopulated crew employees | Existing rows |
List<Equipment> Equipment |
All equipment items | Equipment master data |
List<CrewEquipment> CrewEquipment |
Prepopulated equipment | Existing equipment rows |
5. Key Functional Areas
5.1 Initialization & Model Loading 🏗️
On document ready, the view:
- Serializes
Model.*properties intowindow.CrewModel(global JS object). - Initializes the Job dropdown with pre-selected value.
- Populates pre-existing employee & equipment rows (or adds an empty one if none).
$(document).ready(function(){
window.CrewModel = {
Jobs: @Html.Raw(Json.Serialize(Model.Jobs)),
Employees: @Html.Raw(Json.Serialize(Model.Employees)),
CostCodes: @Html.Raw(Json.Serialize(Model.CostCodes)),
Classes: @Html.Raw(Json.Serialize(Model.Classes)),
CrewEmployees: @Html.Raw(Json.Serialize(Model.CrewEmployees)),
Equipment: @Html.Raw(Json.Serialize(Model.Equipment)),
CrewEquipment: @Html.Raw(Json.Serialize(Model.CrewEquipment))
};
initDropdown("#jobSelect", {/* ...options... */});
// Initialize rows...
});
5.2 Dropdown Initialization & Filtering 🔽
A generic initDropdown(selector, options):
- Reuses existing Syncfusion instance if present
- Destroys & re-creates when data source changes
- Applies
allowFiltering,virtualization,showClearButton, etc.
Filtering functions:
filterEmployeeCostCode(dropdown, jobId):- Shows only cost codes of type 1 (employee) for a given job
filterEmployeeClass(dropdown, jobId, costCodeNumber):- Shows job classes matching job & cost code, prioritizing “JDEC”/“BESS”
filterEquipmentCostCode(dropdown, jobId):- Filters type 2 (equipment) cost codes
function filterEmployeeCostCode(dropdown, jobId) {
let filtered = window.CrewModel.CostCodes.filter(cc => cc.JobId == jobId && cc.CostCodeType === 1);
// Fallback if empty...
dropdown.dataSource = filtered; dropdown.dataBind();
}
5.3 Dynamic Row Management ➕
- Employees:
addEmployeeRow()inserts a new row of 6 columns:- Employee
- Cost Code
- Class
- Per Diem Type
- Per Diem Rate
- Start Time (Syncfusion TimePicker)
- Equipment:
addEquipmentRow()inserts 3 columns:- Equipment
- Cost Code
- Worked Hours
Rows can be removed via a “Remove” button.
5.4 Form Submission & API Interaction 📨
On submit (#editCrewForm):
- Prevent default form post
- Disable button & show spinner
- Assemble
crewobject:{ CrewId: $("#crewId").val(), CrewName: $("#crewName").val(), JobId: ej.base.getComponent("#jobSelect").value, CrewEmployees: [ /* ...extracted from rows... */ ], CrewEquipment: [ /* ...extracted from rows... */ ] } - AJAX POST to
/TimeEntry/EditCrew - Handle success/error, re-enable button
$.ajax({
url: '/TimeEntry/EditCrew',
type: 'POST',
data: JSON.stringify(crew),
contentType: 'application/json',
success: resp => alert(resp.message),
error: (xhr, status, err) => alert("Error: " + err)
});
6. Helper Methods & Utilities 🛠️
| Function | Purpose |
|---|---|
initDropdown(selector, options) |
Create/update a Syncfusion DropDownList |
filterEmployeeCostCode(...) |
Restrict cost codes to employees for the selected job |
filterEmployeeClass(...) |
Restrict job classifications, with priority sorting |
filterEquipmentCostCode(...) |
Restrict cost codes to equipment for the selected job |
addEmployeeRow() |
Dynamically append a new employee row |
addEquipmentRow() |
Dynamically append a new equipment row |
7. Error Handling & Logging 🚨
- Extensive
console.log,console.warn,console.errorstatements throughout - Try/catch blocks in:
- Dropdown filtering
- Row initialization
- Form submission
- Fallback logic when prepopulated data is missing (e.g., empty rows)
8. API Endpoints Overview 🌐
| HTTP Method | Endpoint | Payload | Response |
|---|---|---|---|
| POST | /TimeEntry/EditCrew |
JSON Crew object |
{ success, message } |
- Sends the full crew definition for update.
- Expects JSON with
CrewId,CrewName,JobId, arrays forCrewEmployees&CrewEquipment.
9. Third-party Integrations 🔗
- Syncfusion EJ2 for:
DropDownListTimePicker
- Tailwind CSS for layout & styling
- Font Awesome for loading spinner:
<i class="fas fa-spinner fa-spin"></i> - jQuery for DOM ready, event binding, AJAX
10. Sample Code Snippets 📊
Initializing the Job Dropdown
initDropdown("#jobSelect", {
dataSource: window.CrewModel.Jobs,
fields: { text: 'Text', value: 'Value' },
placeholder: 'Select Job',
value: preselectedJobId.toUpperCase(),
change: onJobChanged
});
Adding a New Employee Row
$("#addEmployeeRow").click(function () {
addEmployeeRow();
});
Filtering Classes on Cost Code Change
change: function(e) {
let costNumber = e.itemData.CostCodeNumber;
let jobId = ej.base.getComponent("#jobSelect").value;
let classDropdown = ej.base.getComponent("#classSelect_row_123", "dropdownlist");
filterEmployeeClass(classDropdown, jobId, costNumber);
}
11. Usage Examples 🖥️
- Navigate to
/TimeEntry/EditCrew?crewId={GUID} - Edit the Crew Name or Job
- Modify employee rows:
- Click “Add Employee”, select Employee, Cost Code, Class, Per Diem, Start Time
- Click “Remove” to delete a row
- Modify equipment rows similarly
- Click “Update Crew”
- Observe success/error alert
12. UML Diagrams 📈
Class Diagram
classDiagram
class CrewViewModel {
+string CrewId
+string CrewName
+string JobId
+List~Job~ Jobs
+List~Employee~ Employees
+List~CostCode~ CostCodes
+List~Class~ Classes
+List~CrewEmployee~ CrewEmployees
+List~Equipment~ Equipment
+List~CrewEquipment~ CrewEquipment
}
Sequence Diagram
sequenceDiagram
participant User
participant Browser
participant Server
User->>Browser: Fill form & click Update Crew
Browser->>Server: POST /TimeEntry/EditCrew { crew JSON }
Server-->>Browser: { success, message }
Browser->>User: Alert(message)
13. Conclusion 🎉
This EditCrew.cshtml view offers a robust, user-friendly interface to manage complex Crew data—leveraging powerful third‑party components, dynamic row generation, and extensive filtering logic. The modular helper methods, comprehensive logging, and clear data-binding pattern make it easy to extend and maintain.
Feel free to explore and customize the logic to fit your evolving business requirements!