name: events
label: Event
icon: event
enable_search: true
version: 2
fields:
  name:
    label: Name
    type: text
    required: true
    is_wide: true
    searchable: true
    index: true
    name: name
  start:
    label: Start Timne
    type: datetime
    required: true
    defaultValue: !<tag:yaml.org,2002:js/function> |-
      function () {
              var now, reValue;
              now = new Date();
              reValue = new Date(now.getTime() + 1 * 60 * 60 * 1000);
              reValue.setMinutes(0);
              reValue.setSeconds(0);
              return reValue;
            }
    sortable: true
    name: start
  end:
    label: End Time
    type: datetime
    required: true
    defaultValue: !<tag:yaml.org,2002:js/function> |-
      function () {
              var now, reValue;
              now = new Date();
              reValue = new Date(now.getTime() + 2 * 60 * 60 * 1000);
              reValue.setMinutes(0);
              reValue.setSeconds(0);
              return reValue;
            }
    name: end
  assignees:
    label: Assignees
    type: lookup
    reference_to: users
    defaultValue: "{userId}"
    multiple: true
    name: assignees
    filterable: true
  related_to:
    label: Related to
    type: lookup
    index: true
    reference_to: !<tag:yaml.org,2002:js/function> |-
      function () {
             try{
              let objects = [];
              var queryResult = Steedos.authRequest(`/graphql`, {
                  type: 'POST', async: false, 
                  data: JSON.stringify({
                    query: `{ objects(filters: ["enable_events","=",true]){ name,space,enable_events } }`
                  })
              });
              objects = queryResult && queryResult.data && queryResult.data.objects;
              return _.map(objects, 'name') ;
            }catch(e){
              return []
            }
      }
    name: related_to
    filterable: true
  is_all_day:
    label: All Day Event
    type: boolean
    name: is_all_day
  location:
    label: Location
    type: text
    name: location
  description:
    label: Description
    type: textarea
    is_wide: true
    name: description
list_views:
  calendar_view:
    type: calendar
    label: Calendar View
    filter_scope: space
    filters:
    - - owner 
      - = 
      - '{userId}'
    - or 
    - - assignees
      - = 
      - '{userId}'
    options:
      startDateExpr: start
      endDateExpr: end
      allDayExpr: is_all_day
      textExpr: name
      title:
        - name
        - start
        - end
        - assignees
        - related_to
      currentView: week
      startDayHour: 8
      endDayHour: 18
  all:
    label: All Events
    filter_scope: space
    filters:
    - - owner 
      - = 
      - '{userId}'
    - or 
    - - assignees
      - = 
      - '{userId}'
    columns:
      - name
      - start
      - end
      - assignees
      - related_to
permission_set:
  user:
    allowCreate: true
    allowDelete: true
    allowEdit: true
    allowRead: true
    modifyAllRecords: false
    viewAllRecords: true
  admin:
    allowCreate: true
    allowDelete: true
    allowEdit: true
    allowRead: true
    modifyAllRecords: true
    viewAllRecords: true
