chayns-api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +30 -0
- package/.eslintrc +17 -0
- package/.github/workflows/deploy_docs.yml +28 -0
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/cjs/calls/dialogs/alert.js +19 -0
- package/dist/cjs/calls/dialogs/chaynsDialog.js +59 -0
- package/dist/cjs/calls/dialogs/close.js +13 -0
- package/dist/cjs/calls/dialogs/communication.js +71 -0
- package/dist/cjs/calls/dialogs/confirm.js +33 -0
- package/dist/cjs/calls/dialogs/date.js +187 -0
- package/dist/cjs/calls/dialogs/dropUpAlert.js +12 -0
- package/dist/cjs/calls/dialogs/fileSelect.js +39 -0
- package/dist/cjs/calls/dialogs/iFrame.js +43 -0
- package/dist/cjs/calls/dialogs/index.js +178 -0
- package/dist/cjs/calls/dialogs/input.js +33 -0
- package/dist/cjs/calls/dialogs/mediaSelect.js +27 -0
- package/dist/cjs/calls/dialogs/open.js +19 -0
- package/dist/cjs/calls/dialogs/select.js +55 -0
- package/dist/cjs/calls/dialogs/signature.js +24 -0
- package/dist/cjs/calls/dialogs/toast.js +18 -0
- package/dist/cjs/calls/dialogs/utils/callback.js +12 -0
- package/dist/cjs/calls/dialogs/utils/environment.js +10 -0
- package/dist/cjs/calls/dialogs/utils/is.js +21 -0
- package/dist/cjs/calls/getUserInfo.js +40 -0
- package/dist/cjs/calls/index.js +300 -0
- package/dist/cjs/calls/sendMessage.js +120 -0
- package/dist/cjs/calls/visibilityChangeListener.js +38 -0
- package/dist/cjs/client.js +93 -0
- package/dist/cjs/components/ChaynsContext.js +12 -0
- package/dist/cjs/components/ChaynsModuleProvider.js +457 -0
- package/dist/cjs/components/ChaynsProvider.js +116 -0
- package/dist/cjs/components/WaitUntil.js +31 -0
- package/dist/cjs/components/withCompatMode.js +55 -0
- package/dist/cjs/helper/apiListenerHelper.js +34 -0
- package/dist/cjs/hooks/geoLocationListener.js +50 -0
- package/dist/cjs/hooks/index.js +153 -0
- package/dist/cjs/hooks/scrollListener.js +102 -0
- package/dist/cjs/hooks/useAccessToken.js +28 -0
- package/dist/cjs/hooks/useCurrentPage.js +13 -0
- package/dist/cjs/hooks/useCustomData.js +13 -0
- package/dist/cjs/hooks/useDevice.js +13 -0
- package/dist/cjs/hooks/useEnvironment.js +13 -0
- package/dist/cjs/hooks/useFunctions.js +16 -0
- package/dist/cjs/hooks/useIsAdminMode.js +16 -0
- package/dist/cjs/hooks/useLanguage.js +13 -0
- package/dist/cjs/hooks/usePages.js +38 -0
- package/dist/cjs/hooks/useParameters.js +13 -0
- package/dist/cjs/hooks/useSite.js +13 -0
- package/dist/cjs/hooks/useUser.js +14 -0
- package/dist/cjs/hooks/useValues.js +16 -0
- package/dist/cjs/hooks/windowMetricsListener.js +58 -0
- package/dist/cjs/host/ChaynsHost.js +102 -0
- package/dist/cjs/host/iframe/HostIframe.js +133 -0
- package/dist/cjs/host/iframe/utils/useUpdateData.js +21 -0
- package/dist/cjs/host/module/ModuleHost.js +82 -0
- package/dist/cjs/host/module/PagemakerFrame.js +105 -0
- package/dist/cjs/host/module/utils/loadComponent.js +61 -0
- package/dist/cjs/host/module/utils/useDynamicScript.js +61 -0
- package/dist/cjs/index.js +117 -0
- package/dist/cjs/types/DynamicApiImport.d.js +5 -0
- package/dist/cjs/types/IChaynsReact.js +235 -0
- package/dist/cjs/types/dialog.js +5 -0
- package/dist/cjs/util/appCall.js +23 -0
- package/dist/cjs/util/deviceHelper.js +71 -0
- package/dist/cjs/util/heightHelper.js +40 -0
- package/dist/cjs/util/postIframeForm.js +32 -0
- package/dist/cjs/wrapper/AppWrapper.js +244 -0
- package/dist/cjs/wrapper/FrameWrapper.js +288 -0
- package/dist/cjs/wrapper/ModuleFederationWrapper.js +61 -0
- package/dist/cjs/wrapper/SsrWrapper.js +30 -0
- package/dist/esm/calls/dialogs/alert.js +15 -0
- package/dist/esm/calls/dialogs/chaynsDialog.js +48 -0
- package/dist/esm/calls/dialogs/close.js +7 -0
- package/dist/esm/calls/dialogs/communication.js +66 -0
- package/dist/esm/calls/dialogs/confirm.js +30 -0
- package/dist/esm/calls/dialogs/date.js +211 -0
- package/dist/esm/calls/dialogs/dropUpAlert.js +7 -0
- package/dist/esm/calls/dialogs/fileSelect.js +32 -0
- package/dist/esm/calls/dialogs/iFrame.js +37 -0
- package/dist/esm/calls/dialogs/index.js +14 -0
- package/dist/esm/calls/dialogs/input.js +26 -0
- package/dist/esm/calls/dialogs/mediaSelect.js +22 -0
- package/dist/esm/calls/dialogs/open.js +13 -0
- package/dist/esm/calls/dialogs/select.js +47 -0
- package/dist/esm/calls/dialogs/signature.js +18 -0
- package/dist/esm/calls/dialogs/toast.js +13 -0
- package/dist/esm/calls/dialogs/utils/callback.js +7 -0
- package/dist/esm/calls/dialogs/utils/environment.js +3 -0
- package/dist/esm/calls/dialogs/utils/is.js +12 -0
- package/dist/esm/calls/getUserInfo.js +33 -0
- package/dist/esm/calls/index.js +323 -0
- package/dist/esm/calls/sendMessage.js +111 -0
- package/dist/esm/calls/visibilityChangeListener.js +30 -0
- package/dist/esm/client.js +8 -0
- package/dist/esm/components/ChaynsContext.js +4 -0
- package/dist/esm/components/ChaynsModuleProvider.js +517 -0
- package/dist/esm/components/ChaynsProvider.js +109 -0
- package/dist/esm/components/WaitUntil.js +25 -0
- package/dist/esm/components/withCompatMode.js +47 -0
- package/dist/esm/helper/apiListenerHelper.js +25 -0
- package/dist/esm/hooks/geoLocationListener.js +43 -0
- package/dist/esm/hooks/index.js +16 -0
- package/dist/esm/hooks/scrollListener.js +95 -0
- package/dist/esm/hooks/useAccessToken.js +22 -0
- package/dist/esm/hooks/useCurrentPage.js +7 -0
- package/dist/esm/hooks/useCustomData.js +7 -0
- package/dist/esm/hooks/useDevice.js +6 -0
- package/dist/esm/hooks/useEnvironment.js +6 -0
- package/dist/esm/hooks/useFunctions.js +9 -0
- package/dist/esm/hooks/useIsAdminMode.js +9 -0
- package/dist/esm/hooks/useLanguage.js +6 -0
- package/dist/esm/hooks/usePages.js +32 -0
- package/dist/esm/hooks/useParameters.js +6 -0
- package/dist/esm/hooks/useSite.js +6 -0
- package/dist/esm/hooks/useUser.js +7 -0
- package/dist/esm/hooks/useValues.js +9 -0
- package/dist/esm/hooks/windowMetricsListener.js +51 -0
- package/dist/esm/host/ChaynsHost.js +95 -0
- package/dist/esm/host/iframe/HostIframe.js +124 -0
- package/dist/esm/host/iframe/utils/useUpdateData.js +14 -0
- package/dist/esm/host/module/ModuleHost.js +74 -0
- package/dist/esm/host/module/PagemakerFrame.js +97 -0
- package/dist/esm/host/module/utils/loadComponent.js +55 -0
- package/dist/esm/host/module/utils/useDynamicScript.js +50 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/types/DynamicApiImport.d.js +1 -0
- package/dist/esm/types/IChaynsReact.js +215 -0
- package/dist/esm/types/dialog.js +1 -0
- package/dist/esm/util/appCall.js +16 -0
- package/dist/esm/util/deviceHelper.js +62 -0
- package/dist/esm/util/heightHelper.js +32 -0
- package/dist/esm/util/postIframeForm.js +26 -0
- package/dist/esm/wrapper/AppWrapper.js +241 -0
- package/dist/esm/wrapper/FrameWrapper.js +279 -0
- package/dist/esm/wrapper/ModuleFederationWrapper.js +56 -0
- package/dist/esm/wrapper/SsrWrapper.js +23 -0
- package/dist/types/calls/dialogs/alert.d.ts +1 -0
- package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -0
- package/dist/types/calls/dialogs/close.d.ts +1 -0
- package/dist/types/calls/dialogs/communication.d.ts +3 -0
- package/dist/types/calls/dialogs/confirm.d.ts +13 -0
- package/dist/types/calls/dialogs/date.d.ts +96 -0
- package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -0
- package/dist/types/calls/dialogs/fileSelect.d.ts +16 -0
- package/dist/types/calls/dialogs/iFrame.d.ts +10 -0
- package/dist/types/calls/dialogs/index.d.ts +14 -0
- package/dist/types/calls/dialogs/input.d.ts +15 -0
- package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -0
- package/dist/types/calls/dialogs/open.d.ts +1 -0
- package/dist/types/calls/dialogs/select.d.ts +6 -0
- package/dist/types/calls/dialogs/signature.d.ts +7 -0
- package/dist/types/calls/dialogs/toast.d.ts +1 -0
- package/dist/types/calls/dialogs/utils/callback.d.ts +1 -0
- package/dist/types/calls/dialogs/utils/environment.d.ts +3 -0
- package/dist/types/calls/dialogs/utils/is.d.ts +4 -0
- package/dist/types/calls/getUserInfo.d.ts +9 -0
- package/dist/types/calls/index.d.ts +231 -0
- package/dist/types/calls/sendMessage.d.ts +13 -0
- package/dist/types/calls/visibilityChangeListener.d.ts +9 -0
- package/dist/types/client.d.ts +7 -0
- package/dist/types/components/ChaynsContext.d.ts +3 -0
- package/dist/types/components/ChaynsModuleProvider.d.ts +170 -0
- package/dist/types/components/ChaynsProvider.d.ts +13 -0
- package/dist/types/components/WaitUntil.d.ts +7 -0
- package/dist/types/components/withCompatMode.d.ts +13 -0
- package/dist/types/helper/apiListenerHelper.d.ts +6 -0
- package/dist/types/hooks/geoLocationListener.d.ts +18 -0
- package/dist/types/hooks/index.d.ts +16 -0
- package/dist/types/hooks/scrollListener.d.ts +28 -0
- package/dist/types/hooks/useAccessToken.d.ts +5 -0
- package/dist/types/hooks/useCurrentPage.d.ts +4 -0
- package/dist/types/hooks/useCustomData.d.ts +4 -0
- package/dist/types/hooks/useDevice.d.ts +5 -0
- package/dist/types/hooks/useEnvironment.d.ts +5 -0
- package/dist/types/hooks/useFunctions.d.ts +5 -0
- package/dist/types/hooks/useIsAdminMode.d.ts +4 -0
- package/dist/types/hooks/useLanguage.d.ts +5 -0
- package/dist/types/hooks/usePages.d.ts +14 -0
- package/dist/types/hooks/useParameters.d.ts +5 -0
- package/dist/types/hooks/useSite.d.ts +5 -0
- package/dist/types/hooks/useUser.d.ts +5 -0
- package/dist/types/hooks/useValues.d.ts +5 -0
- package/dist/types/hooks/windowMetricsListener.d.ts +11 -0
- package/dist/types/host/ChaynsHost.d.ts +27 -0
- package/dist/types/host/iframe/HostIframe.d.ts +24 -0
- package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -0
- package/dist/types/host/module/ModuleHost.d.ts +23 -0
- package/dist/types/host/module/PagemakerFrame.d.ts +22 -0
- package/dist/types/host/module/utils/loadComponent.d.ts +1 -0
- package/dist/types/host/module/utils/useDynamicScript.d.ts +9 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/types/IChaynsReact.d.ts +590 -0
- package/dist/types/types/dialog.d.ts +41 -0
- package/dist/types/util/appCall.d.ts +2 -0
- package/dist/types/util/deviceHelper.d.ts +7 -0
- package/dist/types/util/heightHelper.d.ts +1 -0
- package/dist/types/util/postIframeForm.d.ts +1 -0
- package/dist/types/wrapper/AppWrapper.d.ts +16 -0
- package/dist/types/wrapper/FrameWrapper.d.ts +15 -0
- package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -0
- package/dist/types/wrapper/SsrWrapper.d.ts +11 -0
- package/package.json +76 -0
- package/toolkit.config.js +52 -0
- package/tsconfig.json +56 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { buttonText, buttonType, dialogAction } from './chaynsDialog';
|
|
2
|
+
import { isDate, isNumber, isObject } from './utils/is';
|
|
3
|
+
import { open } from './open';
|
|
4
|
+
import { getDevice } from "../index";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The config object for date dialog
|
|
8
|
+
* @typedef {Object} dateConfig
|
|
9
|
+
* @property {Date} preSelect - The date object which should be preselected.
|
|
10
|
+
* @property {Date} minDate - The min date which you could select.
|
|
11
|
+
* @property {Date} maxDate - The max date which you could select.
|
|
12
|
+
* @property {dateDialogType} dateType - The type of dialog you want to display.
|
|
13
|
+
* @property {number} minuteIntervall - The interval for special minutes, possible are 2, 3, 4, 5, 6, 12, 15, 20, 30. Default is 1.
|
|
14
|
+
* @property {string} message - The message that is displayed above the date dialog, only in apps supported
|
|
15
|
+
* @property {string} title - The title that is displayed above the message, only in apps supported
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This call will open a date select dialog.
|
|
20
|
+
* <div>Call: 30</div>
|
|
21
|
+
* @param {dateConfig} config - Define the configuration of this call
|
|
22
|
+
* @return {Promise} contains a timestamp as result
|
|
23
|
+
* @example chayns.dialog.date({
|
|
24
|
+
* 'dateType': chayns.dialog.dateType.DATE_TIME,
|
|
25
|
+
* 'preSelect': new Date(2018, 6, 14, 0, 0, 0),
|
|
26
|
+
* 'minDate': new Date(2018, 6, 1, 15, 0, 0),
|
|
27
|
+
* 'maxDate': new Date(2019, 6, 1, 0, 23, 0),
|
|
28
|
+
* 'minuteInterval': 15
|
|
29
|
+
* ).then(function (data) {
|
|
30
|
+
* console.log(data);
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export function date() {
|
|
35
|
+
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
36
|
+
let {
|
|
37
|
+
preSelect,
|
|
38
|
+
minDate,
|
|
39
|
+
maxDate,
|
|
40
|
+
title,
|
|
41
|
+
message,
|
|
42
|
+
minuteInterval,
|
|
43
|
+
autoSelectDate
|
|
44
|
+
} = config,
|
|
45
|
+
type = config.dateType || dateType.DATE;
|
|
46
|
+
|
|
47
|
+
// This will fix the iOS problem with not preselectedDate without user interaction. That it return the wrog time.
|
|
48
|
+
const {
|
|
49
|
+
os,
|
|
50
|
+
app
|
|
51
|
+
} = getDevice();
|
|
52
|
+
if (minuteInterval && minuteInterval > 1 && os === 'iOS' && app) {
|
|
53
|
+
preSelect = roundInterval(preSelect, minuteInterval);
|
|
54
|
+
} else {
|
|
55
|
+
preSelect = validateValue(preSelect);
|
|
56
|
+
}
|
|
57
|
+
minDate = validateValue(minDate);
|
|
58
|
+
maxDate = validateValue(maxDate);
|
|
59
|
+
let buttons = [];
|
|
60
|
+
buttons = [{
|
|
61
|
+
'text': buttonText.OK,
|
|
62
|
+
'buttonType': buttonType.POSITIVE
|
|
63
|
+
}];
|
|
64
|
+
return open({
|
|
65
|
+
'callType': dialogAction.DATE,
|
|
66
|
+
type,
|
|
67
|
+
'selectedDate': preSelect,
|
|
68
|
+
minDate,
|
|
69
|
+
maxDate,
|
|
70
|
+
title,
|
|
71
|
+
message,
|
|
72
|
+
buttons,
|
|
73
|
+
minuteInterval,
|
|
74
|
+
autoSelectDate
|
|
75
|
+
}).then(data => {
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
return Promise.resolve(data.selectedDate);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export function advancedDate() {
|
|
81
|
+
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
82
|
+
let {
|
|
83
|
+
preSelect,
|
|
84
|
+
minDate,
|
|
85
|
+
maxDate,
|
|
86
|
+
title,
|
|
87
|
+
message,
|
|
88
|
+
minuteInterval,
|
|
89
|
+
buttons,
|
|
90
|
+
multiselect,
|
|
91
|
+
disabledDates,
|
|
92
|
+
textBlocks,
|
|
93
|
+
monthSelect,
|
|
94
|
+
yearSelect,
|
|
95
|
+
interval,
|
|
96
|
+
maxInterval,
|
|
97
|
+
minInterval,
|
|
98
|
+
disabledIntervals,
|
|
99
|
+
disabledWeekDayIntervals,
|
|
100
|
+
getLocalTime,
|
|
101
|
+
autoSelectDate
|
|
102
|
+
} = config,
|
|
103
|
+
// minInterval and maxInterval in minutes
|
|
104
|
+
type = config.dateType || dateType.DATE;
|
|
105
|
+
minDate = validateValue(minDate);
|
|
106
|
+
maxDate = validateValue(maxDate);
|
|
107
|
+
const {
|
|
108
|
+
os,
|
|
109
|
+
app
|
|
110
|
+
} = getDevice();
|
|
111
|
+
if (!preSelect) preSelect = {};
|
|
112
|
+
if (Array.isArray(preSelect)) {
|
|
113
|
+
preSelect = preSelect.map(p => validateValue(p));
|
|
114
|
+
} else if (isObject(preSelect)) {
|
|
115
|
+
if (preSelect.start && preSelect.end) {
|
|
116
|
+
if (minuteInterval && minuteInterval > 1 && os === 'iOS' && app) {
|
|
117
|
+
preSelect = [roundInterval(preSelect.start, minuteInterval), roundInterval(preSelect.end, minuteInterval)];
|
|
118
|
+
} else {
|
|
119
|
+
preSelect = [validateValue(preSelect.start), validateValue(preSelect.end)];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
// This will fix the iOS problem with not preselectedDate without user interaction. That it return the wrong time.
|
|
124
|
+
// eslint-disable-next-line no-lonely-if
|
|
125
|
+
if (minuteInterval && minuteInterval > 1 && os === 'iOS' && app) {
|
|
126
|
+
preSelect = roundInterval(preSelect, minuteInterval);
|
|
127
|
+
} else {
|
|
128
|
+
preSelect = validateValue(preSelect);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (Array.isArray(disabledDates)) {
|
|
132
|
+
disabledDates = disabledDates.map(d => validateValue(d));
|
|
133
|
+
}
|
|
134
|
+
if (!buttons || !Array.isArray(buttons)) {
|
|
135
|
+
buttons = [{
|
|
136
|
+
'text': buttonText.OK,
|
|
137
|
+
'buttonType': buttonType.POSITIVE
|
|
138
|
+
}];
|
|
139
|
+
}
|
|
140
|
+
return open({
|
|
141
|
+
'callType': dialogAction.ADVANCED_DATE,
|
|
142
|
+
type,
|
|
143
|
+
'selectedDate': Array.isArray(preSelect) ? undefined : preSelect,
|
|
144
|
+
minDate,
|
|
145
|
+
maxDate,
|
|
146
|
+
title,
|
|
147
|
+
message,
|
|
148
|
+
minuteInterval,
|
|
149
|
+
buttons,
|
|
150
|
+
multiselect,
|
|
151
|
+
'selectedDates': Array.isArray(preSelect) ? preSelect : undefined,
|
|
152
|
+
disabledDates,
|
|
153
|
+
textBlocks,
|
|
154
|
+
monthSelect,
|
|
155
|
+
yearSelect,
|
|
156
|
+
interval,
|
|
157
|
+
minInterval,
|
|
158
|
+
maxInterval,
|
|
159
|
+
disabledIntervals,
|
|
160
|
+
disabledWeekDayIntervals,
|
|
161
|
+
getLocalTime,
|
|
162
|
+
autoSelectDate
|
|
163
|
+
}).then(data => {
|
|
164
|
+
return Promise.resolve(data);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @typedef {number} dateDialogType
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Enum for date dialog
|
|
174
|
+
* <div>DATE will open a dialog where you can select a special day</div>
|
|
175
|
+
* <div>TIME will open a dialog where you can only select a special time</div>
|
|
176
|
+
* <div>DATE_TIME will open a dialog where you can select a special time on a special day</div>
|
|
177
|
+
* @readonly
|
|
178
|
+
* @enum {dateDialogType}
|
|
179
|
+
* @type {{DATE: number, TIME: number, DATE_TIME: number}}
|
|
180
|
+
*/
|
|
181
|
+
export const dateType = {
|
|
182
|
+
'DATE': 1,
|
|
183
|
+
'TIME': 2,
|
|
184
|
+
'DATE_TIME': 3
|
|
185
|
+
};
|
|
186
|
+
function validateValue(value) {
|
|
187
|
+
if (!isNumber(value)) {
|
|
188
|
+
if (isDate(value)) {
|
|
189
|
+
// TODO: Find out whats the purpose of parsing to int
|
|
190
|
+
return parseInt(value.getTime() / 1000 + "", 10);
|
|
191
|
+
}
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
function roundInterval() {
|
|
197
|
+
let preDate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Date();
|
|
198
|
+
let interval = arguments.length > 1 ? arguments[1] : undefined;
|
|
199
|
+
if (!isDate(preDate)) {
|
|
200
|
+
if (isNumber(preDate)) {
|
|
201
|
+
preDate = new Date(preDate);
|
|
202
|
+
} else {
|
|
203
|
+
return -1;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
let minutes = preDate.getMinutes();
|
|
207
|
+
preDate.setMinutes(minutes - minutes % interval);
|
|
208
|
+
preDate.setSeconds(0);
|
|
209
|
+
// TODO: Why?
|
|
210
|
+
return parseInt(preDate.getTime() / 1000 + "", 10);
|
|
211
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { open } from './open';
|
|
2
|
+
import { dialogAction } from './chaynsDialog';
|
|
3
|
+
export function dropUpAlert() {
|
|
4
|
+
let dialog = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5
|
+
dialog.callType = dialogAction.DROP_UP_ALERT;
|
|
6
|
+
return open(dialog);
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { buttonText, buttonType, dialogAction } from './chaynsDialog';
|
|
2
|
+
import { open } from './open';
|
|
3
|
+
import { getAccessToken, getUser, login } from "../index";
|
|
4
|
+
export const fileType = {
|
|
5
|
+
'IMAGE': 'image',
|
|
6
|
+
'VIDEO': 'video',
|
|
7
|
+
'AUDIO': 'audio',
|
|
8
|
+
'DOCUMENT': ['application/x-latex', 'application/x-tex', 'text/', 'application/json', 'application/pdf', 'application/msword', 'application/msexcel', 'application/mspowerpoint', 'application/vnd.ms-word', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument', 'application/vnd.oasis.opendocument']
|
|
9
|
+
};
|
|
10
|
+
export async function fileSelect() {
|
|
11
|
+
let dialog = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12
|
+
if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
|
|
13
|
+
dialog.buttons = [];
|
|
14
|
+
if (dialog.multiselect || dialog.directory) {
|
|
15
|
+
dialog.buttons.push({
|
|
16
|
+
'text': buttonText.OK,
|
|
17
|
+
'buttonType': buttonType.POSITIVE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
dialog.buttons.push({
|
|
21
|
+
'text': buttonText.CANCEL,
|
|
22
|
+
'buttonType': buttonType.NEGATIVE
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
dialog.callType = dialogAction.FILE_SELECT;
|
|
26
|
+
const user = getUser();
|
|
27
|
+
if (!user) {
|
|
28
|
+
return login();
|
|
29
|
+
}
|
|
30
|
+
dialog.chaynsToken = (await getAccessToken()).accessToken;
|
|
31
|
+
return open(dialog);
|
|
32
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { buttonText, buttonType, dialogAction } from './chaynsDialog';
|
|
2
|
+
import { open } from './open';
|
|
3
|
+
import { addDialogDataListener, sendData } from './communication';
|
|
4
|
+
import { getSite, invokeDialogCall } from "../index";
|
|
5
|
+
export function iFrame() {
|
|
6
|
+
let dialog = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
7
|
+
url: ""
|
|
8
|
+
};
|
|
9
|
+
if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
|
|
10
|
+
dialog.buttons = [{
|
|
11
|
+
'text': buttonText.YES,
|
|
12
|
+
'buttonType': buttonType.POSITIVE
|
|
13
|
+
}, {
|
|
14
|
+
'text': buttonText.NO,
|
|
15
|
+
'buttonType': buttonType.NEGATIVE
|
|
16
|
+
}];
|
|
17
|
+
}
|
|
18
|
+
dialog.tappIframeName = window.name;
|
|
19
|
+
dialog.callType = dialogAction.IFRAME;
|
|
20
|
+
const site = getSite();
|
|
21
|
+
dialog.url = `${dialog.url}${dialog.url.indexOf('?') >= 0 ? '&' : '?'}siteId=${site.id}`;
|
|
22
|
+
addDialogDataListener(_chaynsCallResponder, true);
|
|
23
|
+
return open(dialog);
|
|
24
|
+
}
|
|
25
|
+
export function _chaynsCallResponder(obj) {
|
|
26
|
+
if (obj.call.value.callback) {
|
|
27
|
+
const call = JSON.parse(JSON.stringify(obj)); // deep copy
|
|
28
|
+
invokeDialogCall(obj).then(result => {
|
|
29
|
+
sendData({
|
|
30
|
+
result,
|
|
31
|
+
call
|
|
32
|
+
}, true);
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
invokeDialogCall(obj);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { buttonText, buttonType } from './chaynsDialog';
|
|
2
|
+
export * from './alert';
|
|
3
|
+
export * from './confirm';
|
|
4
|
+
export * from './select';
|
|
5
|
+
export * from './date';
|
|
6
|
+
export * from './input';
|
|
7
|
+
export * from './close';
|
|
8
|
+
export * from './dropUpAlert';
|
|
9
|
+
export * from './iFrame';
|
|
10
|
+
export * from './mediaSelect';
|
|
11
|
+
export * from './fileSelect';
|
|
12
|
+
export * from './communication';
|
|
13
|
+
export * from './toast';
|
|
14
|
+
export * from './signature';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { buttonText, buttonType, dialogAction } from './chaynsDialog';
|
|
2
|
+
import { open } from './open';
|
|
3
|
+
export function input() {
|
|
4
|
+
let dialog = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5
|
+
if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
|
|
6
|
+
dialog.buttons = [{
|
|
7
|
+
'text': buttonText.YES,
|
|
8
|
+
'buttonType': buttonType.POSITIVE
|
|
9
|
+
}, {
|
|
10
|
+
'text': buttonText.NO,
|
|
11
|
+
'buttonType': buttonType.NEGATIVE
|
|
12
|
+
}];
|
|
13
|
+
}
|
|
14
|
+
if (dialog.formatter) {
|
|
15
|
+
dialog.formatter = dialog.formatter.toString();
|
|
16
|
+
}
|
|
17
|
+
dialog.callType = dialogAction.INPUT;
|
|
18
|
+
return open(dialog);
|
|
19
|
+
}
|
|
20
|
+
export const inputType = {
|
|
21
|
+
'DEFAULT': 0,
|
|
22
|
+
'PASSWORD': 1,
|
|
23
|
+
'TEXTAREA': 2,
|
|
24
|
+
'INPUT': 3,
|
|
25
|
+
'NUMBER': 4
|
|
26
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { buttonText, buttonType, dialogAction } from './chaynsDialog';
|
|
2
|
+
import { open } from './open';
|
|
3
|
+
import { getAccessToken, getUser, login } from "../index";
|
|
4
|
+
export async function mediaSelect() {
|
|
5
|
+
let dialog = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
+
if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
|
|
7
|
+
dialog.buttons = [{
|
|
8
|
+
'text': buttonText.OK,
|
|
9
|
+
'buttonType': buttonType.POSITIVE
|
|
10
|
+
}, {
|
|
11
|
+
'text': buttonText.CANCEL,
|
|
12
|
+
'buttonType': buttonType.NEGATIVE
|
|
13
|
+
}];
|
|
14
|
+
}
|
|
15
|
+
dialog.callType = dialogAction.MEDIA_SELECT;
|
|
16
|
+
const user = getUser();
|
|
17
|
+
if (!user) {
|
|
18
|
+
return login();
|
|
19
|
+
}
|
|
20
|
+
dialog.chaynsToken = (await getAccessToken()).accessToken;
|
|
21
|
+
return open(dialog);
|
|
22
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { buttonText, buttonType, dialogAction } from './chaynsDialog';
|
|
2
|
+
import { open } from './open';
|
|
3
|
+
import { isPresent } from "./utils/is";
|
|
4
|
+
export function select(config) {
|
|
5
|
+
const list = [];
|
|
6
|
+
for (let i = 0, l = config.list.length; i < l; i++) {
|
|
7
|
+
const item = config.list[i];
|
|
8
|
+
list.push({
|
|
9
|
+
name: item.name,
|
|
10
|
+
'value': isPresent(item.value) ? item.value : item.name,
|
|
11
|
+
'isSelected': !!item.isSelected,
|
|
12
|
+
'icon': item.icon,
|
|
13
|
+
'backgroundColor': item.backgroundColor,
|
|
14
|
+
'className': item.className,
|
|
15
|
+
'url': item.url
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (config.list.length === 0) {
|
|
19
|
+
return Promise.reject(new Error('Invalid Parameters'));
|
|
20
|
+
}
|
|
21
|
+
if (!config.buttons || !Array.isArray(config.buttons)) {
|
|
22
|
+
config.buttons = [{
|
|
23
|
+
'text': buttonText.OK,
|
|
24
|
+
'buttonType': buttonType.POSITIVE
|
|
25
|
+
}, {
|
|
26
|
+
'text': buttonText.CANCEL,
|
|
27
|
+
'buttonType': buttonType.CANCEL
|
|
28
|
+
}];
|
|
29
|
+
}
|
|
30
|
+
return open({
|
|
31
|
+
'callType': dialogAction.SELECT,
|
|
32
|
+
'title': config.title || '',
|
|
33
|
+
'message': config.message || '',
|
|
34
|
+
'buttons': config.buttons,
|
|
35
|
+
'links': config.links,
|
|
36
|
+
'multiselect': !!config.multiselect,
|
|
37
|
+
'quickfind': !!config.quickfind,
|
|
38
|
+
'type': config.type,
|
|
39
|
+
'preventCloseOnClick': !!config.preventCloseOnClick,
|
|
40
|
+
'selectAllButton': config.selectAllButton,
|
|
41
|
+
list
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export const selectType = {
|
|
45
|
+
'DEFAULT': 0,
|
|
46
|
+
'ICON': 1
|
|
47
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { buttonText, buttonType, dialogAction } from './chaynsDialog';
|
|
2
|
+
import { open } from './open';
|
|
3
|
+
export function signature(dialog) {
|
|
4
|
+
if (!dialog) dialog = {};
|
|
5
|
+
if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
|
|
6
|
+
dialog.buttons = [];
|
|
7
|
+
dialog.buttons.push({
|
|
8
|
+
'text': buttonText.OK,
|
|
9
|
+
'buttonType': buttonType.POSITIVE
|
|
10
|
+
});
|
|
11
|
+
dialog.buttons.push({
|
|
12
|
+
'text': buttonText.CANCEL,
|
|
13
|
+
'buttonType': buttonType.NEGATIVE
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
dialog.callType = dialogAction.SIGNATURE;
|
|
17
|
+
return open(dialog);
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getCallbackName } from "./utils/callback";
|
|
2
|
+
import { invokeDialogCall } from "../index";
|
|
3
|
+
export function toast() {
|
|
4
|
+
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
5
|
+
const callbackName = 'toastCallback';
|
|
6
|
+
return invokeDialogCall({
|
|
7
|
+
action: 276,
|
|
8
|
+
value: {
|
|
9
|
+
'callback': getCallbackName(callbackName),
|
|
10
|
+
...config
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function getCallbackName(fnName) {
|
|
2
|
+
let framePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
3
|
+
if (framePrefix !== '') {
|
|
4
|
+
return `window._chaynsCallbacks.${framePrefix}.${fnName}`;
|
|
5
|
+
}
|
|
6
|
+
return `window._chaynsCallbacks.${fnName}`;
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function isObject(value) {
|
|
2
|
+
return value !== null && typeof value === 'object';
|
|
3
|
+
}
|
|
4
|
+
export function isNumber(value) {
|
|
5
|
+
return typeof value === 'number' && !isNaN(value);
|
|
6
|
+
}
|
|
7
|
+
export function isDate(value) {
|
|
8
|
+
return Object.prototype.toString.call(value) === '[object Date]';
|
|
9
|
+
}
|
|
10
|
+
export function isPresent(value) {
|
|
11
|
+
return typeof value !== 'undefined' && value !== null;
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const getUserInfo = async (api, value) => {
|
|
2
|
+
var _value$personId;
|
|
3
|
+
const query = (_value$personId = value.personId) !== null && _value$personId !== void 0 ? _value$personId : value.userId;
|
|
4
|
+
if (!query) {
|
|
5
|
+
throw new Error('Invalid Parameters - You have to provide at least one of these Parameters: userId, personId');
|
|
6
|
+
}
|
|
7
|
+
const {
|
|
8
|
+
accessToken
|
|
9
|
+
} = await api.functions.getAccessToken();
|
|
10
|
+
if (!accessToken) {
|
|
11
|
+
throw new Error('get user info requires a user to be logged in');
|
|
12
|
+
}
|
|
13
|
+
const res = await fetch(`https://relations.chayns.net/relations/user/findUser?searchString=${query}`, {
|
|
14
|
+
'headers': {
|
|
15
|
+
'authorization': `bearer ${accessToken}`
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
if (res.ok) {
|
|
19
|
+
const data = await res.json();
|
|
20
|
+
if (data.length === 0) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
firstName: data[0].firstName,
|
|
25
|
+
lastName: data[0].lastName,
|
|
26
|
+
userId: data[0].userId,
|
|
27
|
+
personId: data[0].personId,
|
|
28
|
+
name: data[0].name
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`getUserInfo failed with status ${res.status}`);
|
|
32
|
+
};
|
|
33
|
+
export default getUserInfo;
|