📄 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

  1. Overview & Purpose
  2. Layout & Structure
  3. Dependencies & Technologies
  4. ViewModel & Data Models
  5. Key Functional Areas
  6. Helper Methods & Utilities
  7. Error Handling & Logging
  8. API Endpoints Overview
  9. Third-party Integrations
  10. Sample Code Snippets
  11. Usage Examples
  12. UML Diagrams
  13. 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 CrewViewModel binds the view to the server-side data.
  • Layout references a shared layout for header/footer.
  • Containers:
    • Employees in #employeesSection
    • Equipment in #equipmentSection

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:

  1. Serializes Model.* properties into window.CrewModel (global JS object).
  2. Initializes the Job dropdown with pre-selected value.
  3. 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:
    1. Employee
    2. Cost Code
    3. Class
    4. Per Diem Type
    5. Per Diem Rate
    6. Start Time (Syncfusion TimePicker)
  • Equipment: addEquipmentRow() inserts 3 columns:
    1. Equipment
    2. Cost Code
    3. Worked Hours

Rows can be removed via a “Remove” button.

5.4 Form Submission & API Interaction 📨

On submit (#editCrewForm):

  1. Prevent default form post
  2. Disable button & show spinner
  3. Assemble crew object:
    {
      CrewId: $("#crewId").val(),
      CrewName: $("#crewName").val(),
      JobId: ej.base.getComponent("#jobSelect").value,
      CrewEmployees: [ /* ...extracted from rows... */ ],
      CrewEquipment: [ /* ...extracted from rows... */ ]
    }
    
  4. AJAX POST to /TimeEntry/EditCrew
  5. 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.error statements 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 for CrewEmployees & CrewEquipment.

9. Third-party Integrations 🔗

  • Syncfusion EJ2 for:
    • DropDownList
    • TimePicker
  • 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 🖥️

  1. Navigate to /TimeEntry/EditCrew?crewId={GUID}
  2. Edit the Crew Name or Job
  3. Modify employee rows:
    • Click “Add Employee”, select Employee, Cost Code, Class, Per Diem, Start Time
    • Click “Remove” to delete a row
  4. Modify equipment rows similarly
  5. Click “Update Crew”
  6. 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!