Uname: Linux webm012.cluster130.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64
Software: Apache
PHP version: 8.0.30 [ PHP INFO ] PHP os: Linux
Server Ip: 145.239.37.162
Your Ip: 216.73.216.190
User: dreampi (1009562) | Group: users (100)
Safe Mode: OFF
Disable Function:
_dyuweyrj4,_dyuweyrj4r,dl

name : customFieldMixin.js
export default {
  data: () => ({}),

  methods: {
    isCustomFieldVisible (customField, type, bookableId) {
      switch (type) {
        case 'appointment':
          return customField.services.map(service => service.id).indexOf(bookableId) !== -1 || customField.allServices
        case 'event':
          return customField.events.map(event => event.id).indexOf(bookableId) !== -1 || customField.allEvents
      }

      return false
    },

    getAllowedCustomFields (bookingCustomFields, type, entityId) {
      let allowedCustomFieldsIds = []

      this.options.entities.customFields.forEach((customField) => {
        if (type === 'services' && customField.allServices || type === 'events' && customField.allEvents) {
          allowedCustomFieldsIds.push(parseInt(customField.id))
        } else {
          customField[type].forEach((entity) => {
            if (entity.id === entityId) {
              allowedCustomFieldsIds.push(parseInt(customField.id))
            }
          })
        }
      })

      let customFields = {}

      for (let key in bookingCustomFields) {
        if (allowedCustomFieldsIds.indexOf(parseInt(key)) !== -1) {
          customFields[key] = bookingCustomFields[key]
        }
      }

      return customFields
    },

    setBookingCustomFields () {
      if (this.appointment && this.appointment.bookings && this.appointment.bookings.length) {
        // Go through all bookings
        for (let i = 0; i < this.appointment.bookings.length; i++) {
          // Go through all custom fields
          for (let j = 0; j < this.options.entities.customFields.length; j++) {
            // Add custom fields as empty object for backward compatibility
            if (this.appointment.bookings[i].customFields === null) {
              this.appointment.bookings[i].customFields = {}
            }

            if (typeof this.appointment.bookings[i].customFields[this.options.entities.customFields[j].id] !== 'undefined') {
              this.appointment.bookings[i].customFields[this.options.entities.customFields[j].id].type = this.options.entities.customFields[j].type
            }

            if (this.appointment.bookings[i].customFields[this.options.entities.customFields[j].id] !== undefined &&
              this.appointment.bookings[i].customFields[this.options.entities.customFields[j].id].type === 'datepicker' &&
              this.appointment.bookings[i].customFields[this.options.entities.customFields[j].id].value
            ) {
              this.appointment.bookings[i].customFields[this.options.entities.customFields[j].id].value = this.$moment(this.appointment.bookings[i].customFields[this.options.entities.customFields[j].id].value).toDate()
            }

            // If custom field is not content and if custom field is not already set, add it in booking
            if (this.options.entities.customFields[j].type !== 'content' &&
              typeof this.appointment.bookings[i].customFields[this.options.entities.customFields[j].id] === 'undefined'
            ) {
              let value = ''
              if (this.options.entities.customFields[j].type === 'checkbox') {
                value = []
              }

              if (this.options.entities.customFields[j].type === 'datepicker') {
                value = null
              }

              this.$set(
                this.appointment.bookings[i].customFields,
                this.options.entities.customFields[j].id,
                {
                  label: this.options.entities.customFields[j].label,
                  value: value,
                  type: this.options.entities.customFields[j].type
                }
              )
            }
          }
        }
      }
    },

    getCustomFieldOptions (customFieldOptions) {
      return customFieldOptions.map(option => option.label)
    },

    getCustomFieldValue (value, type) {
      if (Array.isArray(value)) {
        return value.join('; ')
      } else {
        return type !== 'datepicker' ? value : (value ? this.getFrontedFormattedDate(value) : null)
      }
    },

    getCustomFieldFileURL (customFieldId, bookingId, fileIndex) {
      return this.$root.getAjaxUrl + '/fields/' + customFieldId + '/' + bookingId + '/' + fileIndex + '&source=cabinet-provider'
    }
  }
}
© 2026 GrazzMean-Shell