Constructor
new ScheduleTable(fromDate, toDate, prefillWithDefaultDayParts)
Initializes a table with the provided date range.
These dates should be obtained through getScheduleDate.
prefillWithDefaultDayParts should not be set until the toggle is implemented.
You must run insertTableToDOM to finish table setup.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
fromDate |
* | The start date of this schedule. | |
toDate |
* | The end date of this schedule, inclusive. | |
prefillWithDefaultDayParts |
* | true | Whether to add a list of default dayparts to the table. |
Methods
buildTable(element) → {HTMLDivElement}
Creates and wraps a table, then returns it.
Parameters:
| Name | Type | Description |
|---|---|---|
element |
HTMLElement | The closest element with the ".generate-new-schedule" tag. |
Returns:
A container div for the table, containing the table date range and the table itself.
- Type
- HTMLDivElement
calculateAndUpdateTotalsForRow(singleRow, rowIndex)
Calculates all necessary totals for a row and updates this.rowTotals with an array containing each column value including the final total.
Runs updateTotalsForRow to update the ads/week and cost fields with the new totals.
Example addition to this.rowTotals:
ads/week, length, mon, tues, wed, thur, fri, sat, sun, rate, cost
[19, 1.0, 1, 5, 2, 1, 1, 5, 4, 5, 95]
Parameters:
| Name | Type | Description |
|---|---|---|
singleRow |
HTMLTableRowElement | A row (td element) from the table. |
rowIndex |
number | The index of the row within the table. |
createAdLengthDropdown()
Creates a dropdown menu for ad length.
createTrElements()
Creates the table rows.
createWholeTable(generateScheduleElement) → {HTMLTableElement}
Creates and returns the table.
Parameters:
| Name | Type | Description |
|---|---|---|
generateScheduleElement |
HTMLElement | The closest element with the ".generate-new-schedule" tag. |
Returns:
The new table element.
- Type
- HTMLTableElement
displayColumnTotals()
Displays the totals for each column.
Null values in this.columnTotals are ignored.
displayTotal(target, total, moneySign)
Displays the total of a row / column.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
target |
HTMLElement | The element to display the total on. | |
total |
number | The total to display. | |
moneySign |
boolean | false | Whether to |
getAllTotals()
Calculates and displays totals for the table.
insertTableToDOM(element)
Builds and inserts the table into the DOM.
Sets this.tableElement and adds the table to activeScheduleTables.
The table is inserted above the element passed in.
Parameters:
| Name | Type | Description |
|---|---|---|
element |
HTMLElement | The closest element with the ".generate-new-schedule" tag. |
populateFirstTr(firstTrEle, generateScheduleElement)
Populates the first table row with column headings.
Parameters:
| Name | Type | Description |
|---|---|---|
firstTrEle |
HTMLTableRowElement | HTML element for the first row of the table |
generateScheduleElement |
HTMLDivElement | The closest button for generating a new schedule |
populateRow(rowToPopulate, rowIndex, isNewRow)
Populates a single row with cells
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
rowToPopulate |
HTMLElement | The row to populate. | |
rowIndex |
number | The index of the row to populate. | |
isNewRow |
boolean | false | Whether the row is being added after the table was initially built. |
Returns:
A complete row
populateTableElement(tdEle, row, col) → {void}
Populates a table cell with content.
Parameters:
| Name | Type | Description |
|---|---|---|
tdEle |
HTMLTableDataCellElement | The table cell to populate. |
row |
number | The index of the row this cell is in. |
col |
number | The index of the column this cell is in. |
Returns:
- Type
- void
updateTotalsForRow(singleRow, rowIndex)
Updates the ads/week and cost fields for the row provided.
Parameters:
| Name | Type | Description |
|---|---|---|
singleRow |
HTMLTableRowElement | A row (td element) from the table. |
rowIndex |
number | The index of the row within the table. |