UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

475 lines 18.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDatePickerSections = exports.getDatePickerFields = exports.showDatePicker = void 0; /* Custom modules */ const defaultDatepickerFunction_1 = require("../../../../../helper/defaultDatepickerFunction"); /** * Displays a Date Picker quick reply with the selected config */ const showDatePicker = (cognigy, config) => { const { api } = cognigy; const eventName = config.datepicker_eventName; const locale = config.datepicker_locale; const enableTime = config.datepicker_enableTime; const dateFormat = config.datepicker_dateFormat; const time24Hours = config.datepicker_time24Hours; const mode = config.datepicker_mode; const wantEnableDisable = config.datepicker_wantEnableDisable; const disableEnableRange = config.datepicker_disableEnableRange; const enabledDates = config.datepicker_enabledDates; const disabledDates = config.datepicker_disabledDates; const defaultDate = config.datepicker_defaultDate; const minDate = config.datepicker_minDate; const maxDate = config.datepicker_maxDate; const openPickerButtonText = config.datepicker_openPickerButtonText; const cancelButtonText = config.datepicker_cancelButtonText; const submitButtonText = config.datepicker_submitButtonText; const defaultHour = config.datepicker_defaultHour; const defaultMinute = config.datepicker_defaultMinute; const enableSeconds = config.datepicker_enableSeconds; const hourIncrement = config.datepicker_hourIncrement; const minuteIncrement = config.datepicker_minuteIncrement; const noCalendar = config.datepicker_noCalendar; const weekNumbers = config.datepicker_weekNumbers; const functionEnable = config.datepicker_functionEnable; const functionDisable = config.datepicker_functionDisable; const wantDisable = (wantEnableDisable === "disable") ? true : ((wantEnableDisable === "enable") ? false : null); const functionToExecute = wantDisable === null ? null : (wantDisable ? functionDisable : functionEnable); api.say("", { _plugin: { type: "date-picker", data: { eventName, locale, enableTime, defaultDate, mode, wantDisable, enable_disable: getDisabledEnabledDates(wantEnableDisable, disableEnableRange, enabledDates, disabledDates), function_enable_disable: api.validateDatepickerFunctionInSecureContext(functionToExecute), minDate, maxDate, openPickerButtonText, cancelButtonText, submitButtonText, time_24hr: time24Hours, dateFormat, defaultHour, defaultMinute, enableSeconds, hourIncrement, minuteIncrement, noCalendar, weekNumbers } } }); }; exports.showDatePicker = showDatePicker; /** * Enables or disables dates */ const getDisabledEnabledDates = (wantEnableDisable, disableEnableRange, enabledDates, disabledDates) => { if (wantEnableDisable === "enable" && Array.isArray(enabledDates)) { enabledDates = enabledDates.filter((value) => (value && value !== "")); if (disableEnableRange) { return [ { from: enabledDates[0], to: enabledDates[1] } ]; } return enabledDates; } else if (wantEnableDisable === "disable" && Array.isArray(disabledDates)) { disabledDates = disabledDates.filter((value) => (value && value !== "")); if (disableEnableRange) { return [ { from: disabledDates[0], to: disabledDates[1] } ]; } return disabledDates; } else return null; }; /** * All necessary fields for the datePicker * @param condition Node Field Condition to hide fields or not, optional */ const getDatePickerFields = (condition) => [{ key: "datepicker_eventName", type: "cognigyText", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_EVENTNAME__LABEL", description: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_EVENTNAME__DESCRIPTION", defaultValue: "", condition }, { key: "datepicker_locale", type: "select", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_LOCALE__LABEL", defaultValue: "en", description: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_LOCALE__DESCRIPTION", params: { required: true, options: [ { label: "ar", value: "ar" }, { label: "at", value: "at" }, { label: "az", value: "az" }, { label: "be", value: "be" }, { label: "bg", value: "bg" }, { label: "bn", value: "bn" }, { label: "bs", value: "bs" }, { label: "cat", value: "cat" }, { label: "cs", value: "cs" }, { label: "cy", value: "cy" }, { label: "da", value: "da" }, { label: "de", value: "de" }, { label: "en", value: "en" }, { label: "en_gb", value: "gb" }, { label: "eo", value: "eo" }, { label: "es", value: "es" }, { label: "et", value: "et" }, { label: "fa", value: "fa" }, { label: "fi", value: "fi" }, { label: "fo", value: "fo" }, { label: "fr", value: "fr" }, { label: "gr", value: "gr" }, { label: "he", value: "he" }, { label: "hi", value: "hi" }, { label: "hr", value: "hr" }, { label: "hu", value: "hu" }, { label: "id", value: "id" }, { label: "is", value: "is" }, { label: "it", value: "it" }, { label: "ja", value: "ja" }, { label: "ka", value: "ka" }, { label: "ko", value: "ko" }, { label: "km", value: "km" }, { label: "kz", value: "kz" }, { label: "lt", value: "lt" }, { label: "lv", value: "lv" }, { label: "mk", value: "mk" }, { label: "mn", value: "mn" }, { label: "ms", value: "ms" }, { label: "my", value: "my" }, { label: "nl", value: "nl" }, { label: "no", value: "no" }, { label: "pa", value: "pa" }, { label: "pl", value: "pl" }, { label: "pt", value: "pt" }, { label: "ro", value: "ro" }, { label: "ru", value: "ru" }, { label: "si", value: "si" }, { label: "sk", value: "sk" }, { label: "sl", value: "sl" }, { label: "sq", value: "sq" }, { label: "sr", value: "sr" }, { label: "sv", value: "sv" }, { label: "th", value: "th" }, { label: "tr", value: "tr" }, { label: "uk", value: "uk" }, { label: "vn", value: "vn" }, { label: "zh", value: "zh" }, { label: "zh_tw", value: "zh_tw" } ] }, condition: condition }, { key: "datepicker_mode", type: "select", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_MODE__LABEL", defaultValue: "single", params: { required: true, options: [ { label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_MODE__OPTIONS__SINGLE__LABEL", value: "single" }, { label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_MODE__OPTIONS__MULTIPLE__LABEL", value: "multiple" }, { label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_MODE__OPTIONS__RANGE__LABEL", value: "range" } ] }, condition }, { key: "datepicker_dateFormat", type: "cognigyText", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_DATEFORMAT__LABEL", defaultValue: "" }, { key: "datepicker_enableTime", type: "toggle", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_ENABLE_TIME__LABEL", }, { key: "datepicker_time24Hours", type: "toggle", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_TIME24__LABEL", condition: { key: "datepicker_enableTime", value: true } }, { key: "datepicker_defaultDate", type: "date", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_DEFAULT_DATE__LABEL", }, { key: "datepicker_minDate", type: "date", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_MIN_DATE__LABEL", params: { enableNamedDates: true, } }, { key: "datepicker_maxDate", type: "date", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_MAX_DATE__LABEL", params: { enableNamedDates: true, } }, { key: "datepicker_wantEnableDisable", type: "select", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_WANT_ENABLE_DISABLE__LABEL", defaultValue: "none", params: { required: true, options: [ { "label": "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_WANT_ENABLE_DISABLE__OPTIONS__NONE__LABEL", "value": "none" }, { "label": "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_WANT_ENABLE_DISABLE__OPTIONS__ENABLE__LABEL", "value": "enable" }, { "label": "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_WANT_ENABLE_DISABLE__OPTIONS__DISABLE__LABEL", "value": "disable" } ] } }, { key: "datepicker_disableEnableRange", type: "toggle", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_DISABLE_ENABLE_RANGE__LABEL", condition: { key: "datepicker_wantEnableDisable", value: "none", negate: true } }, { key: "datepicker_enabledDates", type: "textArray", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_ENABLE_DATES__LABEL", condition: { key: "datepicker_wantEnableDisable", value: "enable" } }, { key: "datepicker_disabledDates", type: "textArray", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_DISABLE_DATES__LABEL", condition: { key: "datepicker_wantEnableDisable", value: "disable" } }, { key: "datepicker_functionDisable", type: "code", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_FUNCTION_DISABLE__LABEL", defaultValue: (0, defaultDatepickerFunction_1.defaultDatepickerFunction)("disable"), condition: { key: "datepicker_wantEnableDisable", value: "disable" } }, { key: "datepicker_functionEnable", type: "code", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_FUNCTION_ENABLE__LABEL", defaultValue: (0, defaultDatepickerFunction_1.defaultDatepickerFunction)("enable"), condition: { key: "datepicker_wantEnableDisable", value: "enable" } }, { key: "datepicker_openPickerButtonText", type: "cognigyText", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_OPEN_PICKER_BUTTON_TEXT__LABEL", }, { key: "datepicker_cancelButtonText", type: "cognigyText", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_CANCEL_BUTTON_TEXT__LABEL", }, { key: "datepicker_submitButtonText", type: "cognigyText", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_SUBMIT_BUTTON_TEXT__LABEL", }, { key: "datepicker_defaultHour", type: "slider", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_DEFAULT_HOUR__LABEL", defaultValue: 12, params: { min: 0, max: 23, step: 1 }, condition: { key: "datepicker_enableTime", value: true } }, { key: "datepicker_defaultMinute", type: "slider", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_DEFAULT_MINUTE__LABEL", defaultValue: 30, params: { min: 0, max: 59, step: 1 }, condition: { key: "datepicker_enableTime", value: true } }, { key: "datepicker_enableSeconds", type: "toggle", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_ENABLE_SECONDS__LABEL", defaultValue: false, condition: { key: "datepicker_enableTime", value: true } }, { key: "datepicker_hourIncrement", type: "number", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_HOUR_INCREMENT__LABEL", defaultValue: 1, condition: { key: "datepicker_enableTime", value: true } }, { key: "datepicker_minuteIncrement", type: "number", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_MINUTE_INCREMENT__LABEL", defaultValue: 5, condition: { key: "datepicker_enableTime", value: true } }, { key: "datepicker_noCalendar", type: "toggle", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_NO_CALENDAR__LABEL", defaultValue: false }, { key: "datepicker_weekNumbers", type: "toggle", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_WEEK_NUMBERS__LABEL", defaultValue: false }, { key: "datepicker_hidePicker", type: "toggle", label: "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_HIDE_PICKER__LABEL", defaultValue: false }]; exports.getDatePickerFields = getDatePickerFields; /** * All necessary sections for the datePicker * @param condition Node Field Condition to hide fields or not, optional */ const getDatePickerSections = (prefix, condition) => [{ key: "datepicker_config", label: prefix + "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_CONFIG__LABEL", defaultCollapsed: true, fields: [ "datepicker_eventName", "datepicker_locale", "datepicker_mode" ], condition }, { key: "datepicker_texts", label: prefix + "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_TEXTS__LABEL", defaultCollapsed: true, fields: [ "datepicker_openPickerButtonText", "datepicker_cancelButtonText", "datepicker_submitButtonText", ], condition }, { key: "datepicker_datesettings", label: prefix + "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_DATE_SETTINGS__LABEL", defaultCollapsed: true, fields: [ "datepicker_defaultDate", "datepicker_minDate", "datepicker_maxDate" ], condition }, { key: "datepicker_timesettings", label: prefix + "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_TIME_SETTINGS__LABEL", defaultCollapsed: true, fields: [ "datepicker_enableTime", "datepicker_time24Hours", "datepicker_defaultHour", "datepicker_defaultMinute", "datepicker_hourIncrement", "datepicker_minuteIncrement", "datepicker_enableSeconds" ], condition }, { key: "datepicker_enableDisable", label: prefix + "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_ENABLE_DISABLE__LABEL", defaultCollapsed: true, fields: [ "datepicker_wantEnableDisable", "datepicker_disableEnableRange", "datepicker_enabledDates", "datepicker_disabledDates", "datepicker_functionEnable", "datepicker_functionDisable", ], condition }, { key: "datepicker_advanced", label: prefix + "UI__NODE_EDITOR__MESSAGE__QUESTION__UTILS__DATE_PICKER_UTILS__DATE_PICKER_ADVANCED__LABEL", defaultCollapsed: true, fields: [ "datepicker_dateFormat", "datepicker_noCalendar", "datepicker_weekNumbers", "datepicker_hidePicker" ], condition }]; exports.getDatePickerSections = getDatePickerSections; //# sourceMappingURL=datepickerUtils.js.map