ResourceView
A Calendar view which encapsulates a series of child Calendar views, one for each resource (often referred to as "calendar") in the project.
The type of view displayed defaults to 'week', but this can be changed using the type property
in the view config object.
Usage :
new Calendar({
appendTo : domElement,
// Resource avatar images are loaded from this path
resourceImagePath : '../_shared/images/users/',
modes : {
// Let's not show the default views
day : null,
week : null,
month : null,
year : null,
agenda : null,
// Mode name can be anything if it contains a "type" property.
monthResourceview : {
// Type has the final say over which view type is created
type : 'resource',
// This is a config object for the subviews; one for each resource
view : {
// We show a month view for each resource in the project
type : 'month'
}
}
}
});
//<code-header>
fiddle.title = 'Resource view';
//</code-header>
const dayView = new ResourceView({
appendTo : targetElement,
height : 500,
date : new Date(2020, 8, 2),
dayStartTime : 6,
dayEndTime : 19,
visibleStartTime : 6,
resourceWidth : '30em',
hideNonWorkingDays : true,
resources : [
{
id : 1,
name : 'John',
eventColor : 'blue'
},
{
id : 2,
name : 'Mike',
eventColor : 'orange'
},
{
id : 3,
name : 'Lisa',
eventColor : 'red'
}
],
events : [
{ startDate : '2020-09-02T10:00', duration : 5, durationUnit : 'h', name : 'Studies', eventColor : 'red', resourceId : 1 },
{ startDate : '2020-09-02T07:00', duration : 5, durationUnit : 'h', name : 'Walk the dog', eventColor : 'yellow', resourceId : 2 },
{ startDate : '2020-09-03T09:00', duration : 2, durationUnit : 'h', name : 'Buy groceries', eventColor : 'orange', resourceId : 2 },
{ startDate : '2020-09-04T07:00', duration : 1, durationUnit : 'h', name : 'Zoom meeting', eventColor : 'deep-orange', resourceId : 1 },
{ startDate : '2020-09-05T09:00', duration : 1, durationUnit : 'h', name : 'Get a haircut', eventColor : 'gray', resourceId : 1 }
]
});Configs
151
Configs
151Common
Other
A function, or the name of a function in the ownership hierarchy which you can specify to customize event DOM content.
This function is called each time an event is rendered to allow developers to mutate the cell metadata, or the CSS classes to be applied to the event element.
It's called with the event record, and a eventData object which allows you to mutate event metadata
such as cls, style.
The cls property is an object whose property names will be added to the event element if the property
value is truthy.
The style property is an object containing style properties for the event element.
A non-null return value from the renderer is used as the event body content. A nullish return value causes the default renderer to be used which just uses the event name.
If a string is returned, it is used as the HTML content of the event body element.
If an object is returned, it is used as a DomConfig object to create complex content in the event body element.
eventRenderer({ eventRecord, renderData }) {
if (eventRecord.name === 'Doctors appointment') {
renderData.style.fontWeight = 'bold';
renderData.cls['custom-cls'] = 1;
return 'Special doctors appointment';
}
}
IMPORTANT: When returning content, be sure to consider how that content should be encoded to avoid XSS
(Cross-Site Scripting) attacks. This is especially important when including user-controlled data such as
the event's name. The function encodeHtml as well as
xss can be helpful in these cases.
For example:
eventRenderer({ eventRecord }) {
return StringHelper.xss`Event: ${eventRecord.name}`;
}
| Parameter | Type | Description |
|---|---|---|
detail | Object | An object that contains data about the event being rendered |
detail.view | CalendarView | The view rendering the event |
detail.eventRecord | EventModel | The event record |
detail.resourceRecord | ResourceModel | The Resource record |
detail.renderData | Object | A data object containing properties that will be used to create the event element |
detail.renderData.style | Object | The style property is an object containing style properties for the event element |
detail.renderData.cls | Object | The cls property is an object whose property names will be added to the event element if the property value is truthy |
detail.renderData.iconStyle | Object | The iconStyle property is an object containing style properties for the icon element if an icon element is to be used |
detail.renderData.iconCls | Object | The iconCls property is an object whose property names will be added to the icon element. Initially set from the event record's iconCls. Can be mutated by the renderer. If null, or no properties are set, no icon will be rendered |
detail.renderData.eventColor | String | Color to be applied to the event |
detail.renderData.dataset | Object | An object which produces the |
detail.renderData.solidBar | Boolean | This is valid for views which create event bars.
This is set to |
detail.renderData.bodyColor | String | When used in a DayView,
this color is applied to the body of the event element. Note that this must be light enough
that the text colour (From the SASS variable |
detail.renderData.showBullet | Boolean | If there is no |
Set to true to hide non-working days
When ResourceTimeRangeModels are included in the data, they are only rendered in subviews of ResourceViews and normal TimeRangeModels are not rendered in subviews of ResourceViews.
Set this to true to render normal TimeRangeModels in subviews of
this view.
A field name or a function returning a string to be displayed below resource name in the resource view headers.
const calendar = new Calendar({
modes : {
// Mode name can be anything if it contains a "type" property.
weekResources : {
type : 'resource',
// Get meta string to display
meta : resource => resource.title
}
}
});
| Parameter | Type | Description |
|---|---|---|
resource | ResourceModel | Displayed resource |
Text to be displayed below resource name
If the displayed view is a DateRangeOwner, this may be used to set the range of all child views.
The width of a resource calendar panel (view always stretches to fill window)
Display an avatar in the resource view headers, either as an image or using resource initials.
Looks for an image name in the imageUrl and image fields on the resource. Set resourceImagePath on Calendar to specify where to load images from. If no image is found, resource initials are displayed.
By default, the resource views are displayed in the order that the resources appear
in the project's resourceStore, so they will appear in a stable position, meaning
when a view is filtered out, then filtering it in will replace it in the same position.
If this config is false, re-adding a view will place it at the end.
A config object used to configure the sub views. The default type used is 'weekview'
After instantiation, while in use, changes to the view property, will be propagated
to all child views.
This property may be used to adjust properties of every child view of the resource view in one statement.
The space to leave between each subview.
Content
CSS
DOM
Float & align
Layout
misc
Misc
Scrolling
Properties
130
Properties
130Class hierarchy
Other
Returns the value of the child view's fixedDuration property.
Set to true to hide non-working days
If the displayed view is a DateRangeOwner, this may be used to set the range of all child views.
The width of a resource calendar panel (view always stretches to fill window)
A config object used to configure the sub views. The default type used is 'weekview'
After instantiation, while in use, changes to the view property, will be propagated
to all child views.
This property may be used to adjust properties of every child view of the resource view in one statement.
The space to leave between each subview.
Yields the views which this ResourceView owns.
CSS
DOM
Layout
Misc
State
Widget hierarchy
Functions
91
Functions
91Other
Executes the passed function for each child view corresponding to each resource in the resourceStore.
| Parameter | Type | Description |
|---|---|---|
fn | function | The function to call. |
args | Object[] | The arguments to pass. Defaults to the view being called followed by its index. |
thisObj | Object | The |
Configuration
Events
Misc
Widget hierarchy
Events
28
Events
28Fires when this ResourceView refreshes.
// Adding a listener using the "on" method
resourceView.on('refresh', ({ source }) => {
});| Parameter | Type | Description |
|---|---|---|
source | ResourceView | The triggering instance. |
Fires when a new sub view is created.
// Adding a listener using the "on" method
resourceView.on('viewCreate', ({ source, view }) => {
});| Parameter | Type | Description |
|---|---|---|
source | ResourceView | The triggering instance. |
view | CalendarView | The newly created sub view. |
Event handlers
28
Event handlers
28Called when this ResourceView refreshes.
new ResourceView({
onRefresh({ source }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | ResourceView | The triggering instance. |
Called when a new sub view is created.
new ResourceView({
onViewCreate({ source, view }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | ResourceView | The triggering instance. |
view | CalendarView | The newly created sub view. |
Typedefs
8
Typedefs
8CSS variables
53
CSS variables
53| Name | Description |
|---|---|
--b-resource-view-header-height | Resource header height |