<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<object-views xmlns="http://axelor.com/xml/ns/object-views"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://axelor.com/xml/ns/object-views http://axelor.com/xml/ns/object-views/object-views_5.2.xsd">

    <grid name="calendar-event-grid" model="com.axelor.apps.base.db.ICalendarEvent" title="Events" orderBy="-startDateTime">
        <field name="calendar"/>
        <field name="typeSelect" />
        <field name="user" />
        <field name="subject" />
        <field name="startDateTime" />
        <field name="endDateTime" />
        <field name="allDay" />
    </grid>
	
    <grid name="calendar-event-calendar-grid" model="com.axelor.apps.base.db.ICalendarEvent" title="Events">
        <field name="typeSelect" />
        <field name="user" />
        <field name="subject" />
        <field name="startDateTime" />
        <field name="endDateTime" />
        <field name="allDay" />
    </grid>

    <form name="calendar-event-form" title="Event" model="com.axelor.apps.base.db.ICalendarEvent" onNew="action-icalendar-event-default-record">
        <panel name="mainPanel">
            <field name="subject" showTitle="false" colSpan="12">
            	<viewer depends="subject">
                    <![CDATA[
                        <h3>
                            <span  style="margin: 5px 0 !important; display: inline-table; line-height: initial;">{{record.subject}}</span>
                        </h3>
                    ]]>
                </viewer>
                <editor>
                    <field name="subject" showTitle="true" colSpan="12"/>
                </editor>
            </field>
            <field name="startDateTime" colSpan="5"/>
            <field name="endDateTime" colSpan="5"/>
            <field name="allDay" colSpan="2"/>
            <field name="calendar"/>
            <field name="computedAttendeeList" hidden="true"/>
        </panel>
        <panel-tabs name="mainPanelTab">
	        <panel title="Description" name="descriptionPanel">
	            <field name="description" colSpan="12" widget="html" showTitle="false"/>
	        </panel>
	        <panel title="Organization" name="organizationPanel">
	            <field name="location"/>
	            <field name="geo"/>
	            <field name="user"/>
	            <field name="organizer"/>
	        </panel>
	        <panel title="Information" name="informationPanel">
	            <field name="typeSelect"/>
	            <field name="subjectTeam"/>
	            <field name="visibilitySelect"/>
	            <field name="disponibilitySelect"/>
	            <field name="status"/>
	        </panel>
        </panel-tabs>
        <panel name="addGuestsPanel" title="Add Guests" sidebar="true">
            <field name="$guestEmail" title="Email address" colSpan="12" type="many-to-one" canNew="true" onChange="action-icalendar-event-method-add-email-guest" target="com.axelor.apps.message.db.EmailAddress"/>
        </panel>
        <panel name="guestsPanel" title="Guests" showIf="attendees.length != 0" colSpan="12" sidebar="true">
            <field name="attendees" showTitle="false" colSpan="12" canSelect="false" canNew="false">
	            <editor layout="table" x-show-titles="false">
	                <field name="name" readonly="true"/>
	                <field name="statusSelect"/>
	            </editor>
            </field>
        </panel>
    </form>
	
    <calendar name="calendar-event-all" model="com.axelor.apps.base.db.ICalendarEvent" title="Calendar"
	  eventStart="startDateTime" eventStop="endDateTime" colorBy="calendar">
        <field name="subject" />
    </calendar>
    
    <calendar name="calendar-event-leave-request" model="com.axelor.apps.base.db.ICalendarEvent" title="Calendar"
	  eventStart="startDateTime" eventStop="endDateTime" colorBy="user">
        <field name="subject" />
    </calendar>
	
    <action-view name="action-icalendar-view-ievent-dashlet" title="Events" model="com.axelor.apps.base.db.ICalendarEvent">
        <view type="grid" name="calendar-event-calendar-grid"/>
        <view type="form" name="calendar-event-form"/>
        <domain>self.calendar.id = :calendarId</domain>
        <context name="calendarId" expr="eval:id"/>
    </action-view>

    <action-method name="action-icalendar-event-method-add-email-guest">
        <call class="com.axelor.apps.base.web.ICalendarEventController" method="addEmailGuest"/>
    </action-method>

    <action-record name="action-icalendar-event-default-record" model="com.axelor.apps.base.db.ICalendarEvent">
      <field name="calendar"
        expr="eval: _calendar ?: __user__.iCalendar ?: __repo__(ICalendar).findByUser(__user__)" />
      <field name="startDateTime"
        expr="eval: __config__.app.getTodayDateTime().truncatedTo(java.time.temporal.ChronoUnit.HOURS).plusHours(1)" if="!startDateTime"/>
      <field name="endDateTime"
        expr="eval: __config__.app.getTodayDateTime().truncatedTo(java.time.temporal.ChronoUnit.HOURS).plusHours(2)" if="!endDateTime"/>
    </action-record>

</object-views>