datasync-dynamic-form 1.0.1 → 1.0.3
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.
|
@@ -0,0 +1,847 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DsDynamicForm = exports.CGUID = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _multiselectReactDropdown = _interopRequireDefault(require("multiselect-react-dropdown"));
|
|
9
|
+
var _reactstrap = require("reactstrap");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
// react plugin that creates an input with badges
|
|
14
|
+
{/** Blob must be defined as npm component
|
|
15
|
+
<Blob
|
|
16
|
+
import Blob from "components/Blob/Blob";*/}
|
|
17
|
+
|
|
18
|
+
//Defined as const import {saveDataTierToDatasync} from '../DataSync3/DataSync3.jsx'
|
|
19
|
+
//2DO disabled import "./DynamicForm3Tiers2.css"
|
|
20
|
+
|
|
21
|
+
// reactstrap components
|
|
22
|
+
|
|
23
|
+
const debugging = true;
|
|
24
|
+
const local = true;
|
|
25
|
+
const production = !local;
|
|
26
|
+
const globals = {
|
|
27
|
+
parameters: {
|
|
28
|
+
root_url: "/topics-page",
|
|
29
|
+
admin_url: "/authent",
|
|
30
|
+
debugging: debugging,
|
|
31
|
+
cookie_debugging: true,
|
|
32
|
+
master_detail_debugging: true,
|
|
33
|
+
local: true,
|
|
34
|
+
production: false,
|
|
35
|
+
use_navigate: false,
|
|
36
|
+
save_failed_alert: false,
|
|
37
|
+
form_version: "1.0",
|
|
38
|
+
form_modified_version: 2
|
|
39
|
+
},
|
|
40
|
+
home: {
|
|
41
|
+
...(local && {
|
|
42
|
+
url: 'http://localhost:3000'
|
|
43
|
+
}),
|
|
44
|
+
...(production && {
|
|
45
|
+
url: 'https://www.chainedeprieres.com'
|
|
46
|
+
})
|
|
47
|
+
},
|
|
48
|
+
datasync: {
|
|
49
|
+
/*DATASYNC*/
|
|
50
|
+
praychain_company_guid: local ? "36178327-E810-3A73-A833-8417F639295E" : "2EA619F2-2A23-7905-69C7-6ABA65BDF585",
|
|
51
|
+
praychain_time_table_guid: local ? "CA09A7FB-431C-29A6-A974-72E4F949EC81" : "566062CD-30F8-B1E2-DF80-6AB667F466C4",
|
|
52
|
+
invitation_table_guid: local ? "AE99F45B-9D22-D280-13DA-29B4860C7FEE" : "3F92D25C-4223-E5D2-8484-4880B6B83E9A",
|
|
53
|
+
praychain_contact_table_guid: local ? "E2AEE1AB-838F-A68A-355C-C1A912698002" : "0458D1BE-3E8D-049D-09FB-5A8E14F76A53",
|
|
54
|
+
praychain_authent_table_guid: local ? "B5A0C0AA-200F-B88B-67DE-355D222A6E52" : "21A2464D-B413-6A0C-0848-EDA45266DAC0",
|
|
55
|
+
praychain_user_table_guid: local ? "7841F7FF-1BF9-8716-7C66-BD8C5634E1F6" : "1D65037E-9A04-51EB-5CAE-06BCB7BE30AF",
|
|
56
|
+
praychain_topics_table_guid: local ? "E25E87B5-5E0C-7446-AF58-ECAE4301AE40" : "CE2A92BE-47A5-8AAE-7014-64FF5986A2BD",
|
|
57
|
+
/* MAC local */
|
|
58
|
+
...(local && {
|
|
59
|
+
syncTestUrl: "http://localhost:8888/datasync-service/test.php",
|
|
60
|
+
syncPushUrl: "http://localhost:8888/datasync-service/Sync.php",
|
|
61
|
+
syncPushSerializedUrl: "http://localhost:8888/datasync-service/Sync.php",
|
|
62
|
+
syncStartUrl: "http://localhost:8888/datasync-service/Sync.php?action=syncStart",
|
|
63
|
+
syncDeleteUrl: "http://localhost:8888/datasync-service/Sync.php?action=syncDelete",
|
|
64
|
+
syncSeekUrl: "http://localhost:8888/datasync-service/Sync.php?action=syncSeek",
|
|
65
|
+
syncStopUrl: "http://localhost:8888/datasync-service/Sync.php?action=syncStop",
|
|
66
|
+
syncPullUrl: "http://localhost:8888/datasync-service/Sync.php?action=syncPull",
|
|
67
|
+
syncPullSerializedUrl: "http://localhost:8888/datasync-service/Sync.php?action=syncPullSerialized",
|
|
68
|
+
syncMobilePullUrl: "http://localhost:8888/datasync-service/Sync.php?action=syncMobilePull",
|
|
69
|
+
syncPassThruUrl: "http://localhost:8888/datasync-service/Sync.php?action=syncPassThru"
|
|
70
|
+
}),
|
|
71
|
+
/* chainedeprieres.com Production Server */
|
|
72
|
+
...(production && {
|
|
73
|
+
syncTestUrl: "https://rest.datasync.ovh/test.php",
|
|
74
|
+
syncPushUrl: "https://rest.datasync.ovh/Sync.php",
|
|
75
|
+
syncPushSerializedUrl: "https://rest.datasync.ovh/Sync.php",
|
|
76
|
+
syncStartUrl: "https://rest.datasync.ovh/Sync.php?action=syncStart",
|
|
77
|
+
syncDeleteUrl: "http://rest.datasync.ovh/Sync.php?action=syncDelete",
|
|
78
|
+
syncSeekUrl: "https://rest.datasync.ovh/Sync.php?action=syncSeek",
|
|
79
|
+
syncStopUrl: "https://rest.datasync.ovh/Sync.php?action=syncStop",
|
|
80
|
+
syncPullUrl: "https://rest.datasync.ovh/Sync.php?action=syncPull",
|
|
81
|
+
syncPullSerializedUrl: "https://rest.datasync.ovh/Sync.php?action=syncPullSerialized",
|
|
82
|
+
syncMobilePullUrl: "https://rest.datasync.ovh/Sync.php?action=syncMobilePull",
|
|
83
|
+
syncPassThruUrl: "https://rest.datasync.ovh/Sync.php?action=syncPassThru"
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const randomize = (min, max) => {
|
|
88
|
+
return Math.floor(min + Math.random() * (max - min));
|
|
89
|
+
};
|
|
90
|
+
const cTimeStamp = () => {
|
|
91
|
+
let lDate = new Date();
|
|
92
|
+
let l_sTimeStamp = '';
|
|
93
|
+
l_sTimeStamp = 1900 + lDate.getYear();
|
|
94
|
+
l_sTimeStamp += '-';
|
|
95
|
+
l_sTimeStamp += ('0' + (lDate.getMonth() + 1)).slice(-2);
|
|
96
|
+
l_sTimeStamp += '-';
|
|
97
|
+
l_sTimeStamp += ('0' + lDate.getDate()).slice(-2);
|
|
98
|
+
l_sTimeStamp += ' ';
|
|
99
|
+
l_sTimeStamp += ('0' + lDate.getHours()).slice(-2);
|
|
100
|
+
l_sTimeStamp += ('0' + lDate.getMinutes()).slice(-2);
|
|
101
|
+
l_sTimeStamp += ('0' + lDate.getSeconds()).slice(-2);
|
|
102
|
+
return l_sTimeStamp;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/* Prototype : cGUID
|
|
106
|
+
* Purpose : Generates a Global Unique ID
|
|
107
|
+
* Return : Return GUID
|
|
108
|
+
* History : Created on 2015-02-06
|
|
109
|
+
*
|
|
110
|
+
**/
|
|
111
|
+
const CGUID = () => {
|
|
112
|
+
let d = new Date().getTime();
|
|
113
|
+
let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
114
|
+
var r = (d + Math.random() * 16) % 16 | 0;
|
|
115
|
+
d = Math.floor(d / 16);
|
|
116
|
+
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
|
|
117
|
+
});
|
|
118
|
+
return uuid;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Write data_tier form to data blob
|
|
123
|
+
*/
|
|
124
|
+
exports.CGUID = CGUID;
|
|
125
|
+
const saveDataTierToDatasync = async (p_data_guid, p_o_data_blob, p_s_company_guid, p_s_table_guid, p_dt_createstamp, p_dt_updatestamp, p_dt_deletestamp, on_save_handler, on_update_handler, on_failed_handler, p_extra_data) => {
|
|
126
|
+
if (globals.parameters.debugging_data_tier) console.log(`10/07:this.data_tier:${JSON.stringify(p_o_data_blob)}`);
|
|
127
|
+
|
|
128
|
+
//Post object using DataSyncLayer
|
|
129
|
+
//Copy datasync compliant object data from state structure
|
|
130
|
+
let formBlobObject = {
|
|
131
|
+
data_guid: p_data_guid ? p_data_guid : CGUID(),
|
|
132
|
+
data_blob: {
|
|
133
|
+
data_tier: p_o_data_blob.data_tier
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
if (p_dt_createstamp) {
|
|
137
|
+
formBlobObject.createstamp = p_dt_createstamp;
|
|
138
|
+
}
|
|
139
|
+
if (p_dt_updatestamp) {
|
|
140
|
+
formBlobObject.updatestamp = p_dt_updatestamp;
|
|
141
|
+
}
|
|
142
|
+
if (p_dt_deletestamp) {
|
|
143
|
+
formBlobObject.deletestamp = p_dt_deletestamp;
|
|
144
|
+
}
|
|
145
|
+
let l_o_datasync = Object.assign({}, formBlobObject);
|
|
146
|
+
if (globals.parameters.debugging) {
|
|
147
|
+
console.log("l_o_datasync to be stored => ", l_o_datasync);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//Set datasync container sytem properties values
|
|
151
|
+
//Set user custom data_blob properties values
|
|
152
|
+
l_o_datasync.data_blob.modified = globals.parameters.form_modified_version; //ReUse moidified flag as modified version
|
|
153
|
+
//and so on...
|
|
154
|
+
|
|
155
|
+
//Stringify whole datasync object one more time
|
|
156
|
+
let l_s_sync_object_stringified;
|
|
157
|
+
try {
|
|
158
|
+
l_s_sync_object_stringified = JSON.stringify(l_o_datasync).replace(/'/g, "'").replace(/\\n/g, '\\\\n');
|
|
159
|
+
if (globals.parameters.debugging) console.log(`l_s_sync_object_stringified succedeed :${l_s_sync_object_stringified}`);
|
|
160
|
+
} catch (err) {
|
|
161
|
+
console.error(`l_s_sync_object_stringified:${l_s_sync_object_stringified}`);
|
|
162
|
+
alert(`l_s_sync_object_stringified StringiFy failed with error:${err}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//Prepare datasync syncPush POST request
|
|
166
|
+
const POSTform = new FormData();
|
|
167
|
+
POSTform.append("action", "syncPushSerialized"); //
|
|
168
|
+
POSTform.append("company_guid", p_s_company_guid);
|
|
169
|
+
POSTform.append("table_guid", p_s_table_guid);
|
|
170
|
+
POSTform.append("data_sync", l_s_sync_object_stringified);
|
|
171
|
+
|
|
172
|
+
//SyncPush Data
|
|
173
|
+
fetch(`${globals.datasync.syncPushSerializedUrl}`, {
|
|
174
|
+
method: "POST",
|
|
175
|
+
body: POSTform
|
|
176
|
+
}).then(results => {
|
|
177
|
+
return results.text();
|
|
178
|
+
}).then(sync_server_response => {
|
|
179
|
+
let json_response = JSON.parse(sync_server_response);
|
|
180
|
+
if (globals.parameters.debugging) console.log("json_response ->", json_response);
|
|
181
|
+
if (json_response.data_blob) {
|
|
182
|
+
//Save succedeed
|
|
183
|
+
if (p_data_guid == null && on_save_handler) on_save_handler(json_response, p_extra_data);
|
|
184
|
+
//Update succedeed
|
|
185
|
+
if (p_data_guid != null && on_update_handler) on_update_handler(json_response, p_extra_data);
|
|
186
|
+
|
|
187
|
+
//debugging
|
|
188
|
+
if (globals.parameters.debugging) {
|
|
189
|
+
let data_blob = json_response.data_blob;
|
|
190
|
+
console.log("data_blob", data_blob);
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
//Save or update failed
|
|
194
|
+
console.error("DataSync::saveFormToDatasync => Save or update failed");
|
|
195
|
+
if (on_failed_handler) on_failed_handler("Internal DataSync save error", p_extra_data);
|
|
196
|
+
}
|
|
197
|
+
}).catch(err => {
|
|
198
|
+
alert(`Erreur de sauvegarde ${err}`);
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
const wScrollTo = pStargetAnchorId => {
|
|
202
|
+
let targetDomAnchor = document.getElementById(pStargetAnchorId);
|
|
203
|
+
if (targetDomAnchor) targetDomAnchor.scrollIntoView({
|
|
204
|
+
behavior: "smooth",
|
|
205
|
+
block: "start",
|
|
206
|
+
inline: "nearest"
|
|
207
|
+
});else {
|
|
208
|
+
if (globals.parameters.debugging) {
|
|
209
|
+
console.log(`wScrollTo failed => ${pStargetAnchorId} not found in DOM !`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
class DsDynamicForm extends _react.Component {
|
|
214
|
+
constructor(props) {
|
|
215
|
+
super(props);
|
|
216
|
+
if (globals.parameters.debugging) {
|
|
217
|
+
console.log("30:DynamicForm3Tiers2::this.props.data_blob", this.props.data_blob);
|
|
218
|
+
console.log("30DynamicForm3Tiers::this.props.form", this.props.form);
|
|
219
|
+
}
|
|
220
|
+
this.state = {
|
|
221
|
+
form: {}
|
|
222
|
+
};
|
|
223
|
+
//this.data_blob = {data_tier:{}}
|
|
224
|
+
//2DO debug this.data_tier = (this.props.data_blob && this.props.data_blob.data_tier)?this.props.data_blob.data_tier:{}
|
|
225
|
+
this.data_blob = this.props.data_blob && this.props.data_blob.data_tier ? this.props.data_blob : {
|
|
226
|
+
data_tier: {}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
componentDidMount = () => {
|
|
230
|
+
//Component initialization in edit mode
|
|
231
|
+
if (this.props.form) {
|
|
232
|
+
this.clearForm();
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
componentDidUpdate(prevProps) {
|
|
236
|
+
// Typical usage (don't forget to compare props):
|
|
237
|
+
if (this.props.form !== prevProps.form) {
|
|
238
|
+
//Lookup field props has changed
|
|
239
|
+
if (globals.parameters.debugging) console.log("09/07:componentDidUpdate -> props.form:has changed", this.props.form);
|
|
240
|
+
this.clearForm();
|
|
241
|
+
}
|
|
242
|
+
if (this.props.data_blob !== prevProps.data_blob) {
|
|
243
|
+
//Lookup field props has changed
|
|
244
|
+
if (globals.parameters.debugging) console.log("09/07:componentDidUpdate -> props.data_blob.data_tier:has changed", this.props.data_blob.data_tier);
|
|
245
|
+
this.clearForm();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
clearForm = () => {
|
|
249
|
+
/** Duplicate props.form */
|
|
250
|
+
let clearObject2 = JSON.parse(JSON.stringify(this.props.form));
|
|
251
|
+
|
|
252
|
+
/** set data_tier with (props.foreign_keys + props.data_tier) */
|
|
253
|
+
if (this.props.data_blob) {
|
|
254
|
+
//Set internal data_tier component property
|
|
255
|
+
//OBSOLETE this.data_tier = this.props.data_blob.data_tier
|
|
256
|
+
if (globals.parameters.debugging) console.log("01:this.props.data_blob ->", this.props.data_blob);
|
|
257
|
+
clearObject2.data_tier = this.props.data_blob.data_tier;
|
|
258
|
+
} else {
|
|
259
|
+
if (globals.parameters.debugging) console.log("01:this.props.data_blob.data_tier unDefined");
|
|
260
|
+
clearObject2.data_tier = {}; //Set empty data_tier
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Override data with foreign keys wne props.foreign_key is available */
|
|
264
|
+
if (this.props.foreign_keys) {
|
|
265
|
+
clearObject2.data_tier = Object.assign(clearObject2.data_tier, this.props.foreign_keys); //Dead code to be checked !!!
|
|
266
|
+
this.data_blob.data_tier = Object.assign(clearObject2.data_tier, this.props.foreign_keys); //Dead code to be checked !!!
|
|
267
|
+
}
|
|
268
|
+
if (globals.parameters.debugging) {
|
|
269
|
+
console.log("01:----- clearForm -----");
|
|
270
|
+
console.log("01:clearForm::this.props.form->", this.props.form);
|
|
271
|
+
console.log("01:clearForm::clearObject2 mixed with data_tier ->", clearObject2);
|
|
272
|
+
console.log("01:clearForm::internal this.data_blob ->", this.data_blob);
|
|
273
|
+
}
|
|
274
|
+
this.setState({
|
|
275
|
+
fieldError: [],
|
|
276
|
+
form: {},
|
|
277
|
+
captcha1: randomize(0, 5),
|
|
278
|
+
captcha2: randomize(0, 5)
|
|
279
|
+
},
|
|
280
|
+
//Clear forced
|
|
281
|
+
() => {
|
|
282
|
+
if (globals.parameters.debugging) console.log("09/07:DynamicForm3Tiers2 state cleansed 2:", this.state);
|
|
283
|
+
this.setState({
|
|
284
|
+
fieldError: [],
|
|
285
|
+
form: clearObject2
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
getFieldData = pFieldObject => {
|
|
290
|
+
/** Return data value form field object */
|
|
291
|
+
let nextFieldData = this.data_blob.data_tier[pFieldObject.name] ? this.data_blob.data_tier[pFieldObject.name] : "";
|
|
292
|
+
if (globals.parameters.debugging) console.log("01:getFieldData[", pFieldObject.name, "] nextFieldData->", nextFieldData);
|
|
293
|
+
return nextFieldData;
|
|
294
|
+
};
|
|
295
|
+
setFieldData = (pFieldObject, value) => {
|
|
296
|
+
this.data_blob.data_tier[pFieldObject.name] = value;
|
|
297
|
+
if (globals.parameters.debugging) console.log("01:setFieldData[", pFieldObject.name, "] value->", value);
|
|
298
|
+
console.log("01:setFieldData[", pFieldObject.name, "] this.data_blob.data_tier ->", this.data_blob.data_tier);
|
|
299
|
+
console.log("01:setFieldData[", pFieldObject.name, "] this.data_blob ->", this.data_blob);
|
|
300
|
+
};
|
|
301
|
+
getSelectedFieldValues_V1 = pFieldObject => {
|
|
302
|
+
return pFieldObject.selected_values ? pFieldObject.selected_values : "";
|
|
303
|
+
};
|
|
304
|
+
setFieldError = (pFieldObject, value) => {
|
|
305
|
+
try {
|
|
306
|
+
pFieldObject.err = value;
|
|
307
|
+
let nextFieldError = this.state.fieldError;
|
|
308
|
+
nextFieldError[pFieldObject.name] = value;
|
|
309
|
+
this.setState({
|
|
310
|
+
fieldError: nextFieldError
|
|
311
|
+
});
|
|
312
|
+
//Scroll form to first erroneous field
|
|
313
|
+
wScrollTo(pFieldObject.name);
|
|
314
|
+
} catch (e) {
|
|
315
|
+
console.log(`Error caught on ${e}`);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
getFieldError = pFieldObject => {
|
|
319
|
+
/** Return data value form field object */
|
|
320
|
+
try {
|
|
321
|
+
return pFieldObject.err ? pFieldObject.err : "";
|
|
322
|
+
} catch (e) {
|
|
323
|
+
return "";
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
_error_label = field => {
|
|
327
|
+
return /*#__PURE__*/_react.default.createElement("label", {
|
|
328
|
+
className: "dynamic-form-error"
|
|
329
|
+
}, this.getfieldErrorLabel(field));
|
|
330
|
+
};
|
|
331
|
+
getfieldErrorLabel = pFieldObject => {
|
|
332
|
+
return this.getFieldError(pFieldObject);
|
|
333
|
+
};
|
|
334
|
+
getFieldLabelTitle = pFieldObject => {
|
|
335
|
+
return /*#__PURE__*/_react.default.createElement("h6", {
|
|
336
|
+
id: pFieldObject.name
|
|
337
|
+
}, pFieldObject.title ? pFieldObject.title : pFieldObject.placeholder, pFieldObject.required && !this.props.read_only && /*#__PURE__*/_react.default.createElement("span", {
|
|
338
|
+
className: "icon-danger"
|
|
339
|
+
}, "*"));
|
|
340
|
+
};
|
|
341
|
+
getCaptchaFieldLabelTitle = pFieldObject => {
|
|
342
|
+
return /*#__PURE__*/_react.default.createElement("h6", {
|
|
343
|
+
id: pFieldObject.name
|
|
344
|
+
}, `${this.state.captcha1} + ${this.state.captcha2}`, pFieldObject.required && /*#__PURE__*/_react.default.createElement("span", {
|
|
345
|
+
className: "icon-danger"
|
|
346
|
+
}, "*"));
|
|
347
|
+
};
|
|
348
|
+
getFieldData_V1 = pFieldObject => {
|
|
349
|
+
return pFieldObject.value ? pFieldObject.value : pFieldObject.default_value ? pFieldObject.default_value : "";
|
|
350
|
+
};
|
|
351
|
+
getFieldPrompt = pFieldObject => {
|
|
352
|
+
return pFieldObject.placeholder ? pFieldObject.placeholder : pFieldObject.title;
|
|
353
|
+
};
|
|
354
|
+
_numeric_field_with_add_on = (field, fa_symbol) => {
|
|
355
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, this.getFieldLabelTitle(field), /*#__PURE__*/_react.default.createElement(_reactstrap.InputGroup, {
|
|
356
|
+
className: "border-input"
|
|
357
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
358
|
+
readOnly: this.props.read_only ? this.props.read_only : false,
|
|
359
|
+
type: field.input_type,
|
|
360
|
+
value: this.getFieldData(field),
|
|
361
|
+
placeholder: field.placeholder,
|
|
362
|
+
autocomplete: "on",
|
|
363
|
+
id: field.name,
|
|
364
|
+
name: field.name,
|
|
365
|
+
onChange: e => {
|
|
366
|
+
e.preventDefault();
|
|
367
|
+
this.dynamicInputNumericChangeHandler({
|
|
368
|
+
event: e,
|
|
369
|
+
fieldObject: field
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}), fa_symbol && /*#__PURE__*/_react.default.createElement(_reactstrap.InputGroupAddon, {
|
|
373
|
+
addonType: "append"
|
|
374
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.InputGroupText, null, /*#__PURE__*/_react.default.createElement("i", {
|
|
375
|
+
className: `fa ${fa_symbol}`
|
|
376
|
+
})))), this._error_label(field));
|
|
377
|
+
};
|
|
378
|
+
_captcha_field = (field, fa_symbol) => {
|
|
379
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, this.getCaptchaFieldLabelTitle(field), /*#__PURE__*/_react.default.createElement(_reactstrap.InputGroup, {
|
|
380
|
+
className: "border-input"
|
|
381
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
382
|
+
readOnly: this.props.read_only ? this.props.read_only : false,
|
|
383
|
+
type: field.input_type,
|
|
384
|
+
value: this.getFieldData(field),
|
|
385
|
+
placeholder: field.placeholder,
|
|
386
|
+
autocomplete: "on",
|
|
387
|
+
id: field.name,
|
|
388
|
+
name: field.name,
|
|
389
|
+
onChange: e => {
|
|
390
|
+
e.preventDefault();
|
|
391
|
+
this.dynamicInputNumericChangeHandler({
|
|
392
|
+
event: e,
|
|
393
|
+
fieldObject: field
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
})), this._error_label(field));
|
|
397
|
+
};
|
|
398
|
+
_text_field = field => {
|
|
399
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.getFieldLabelTitle(field), /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
400
|
+
readOnly: this.props.read_only ? this.props.read_only : false,
|
|
401
|
+
type: field.input_type,
|
|
402
|
+
value: this.getFieldData(field),
|
|
403
|
+
placeholder: field.placeholder,
|
|
404
|
+
autocomplete: "off",
|
|
405
|
+
onChange: e => {
|
|
406
|
+
e.preventDefault();
|
|
407
|
+
this.dynamicInputTextChangeHandler({
|
|
408
|
+
event: e,
|
|
409
|
+
fieldObject: field
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}), this._error_label(field));
|
|
413
|
+
};
|
|
414
|
+
_email_field = field => {
|
|
415
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.getFieldLabelTitle(field), /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
416
|
+
readOnly: this.props.read_only ? this.props.read_only : false,
|
|
417
|
+
type: field.input_type,
|
|
418
|
+
value: this.getFieldData(field),
|
|
419
|
+
placeholder: field.placeholder,
|
|
420
|
+
pattern: "[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$",
|
|
421
|
+
autocomplete: "on",
|
|
422
|
+
id: field.name,
|
|
423
|
+
name: field.name,
|
|
424
|
+
onChange: e => {
|
|
425
|
+
e.preventDefault();
|
|
426
|
+
this.dynamicInputTextChangeHandler({
|
|
427
|
+
event: e,
|
|
428
|
+
fieldObject: field
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}), this._error_label(field));
|
|
432
|
+
};
|
|
433
|
+
_memo_field = field => {
|
|
434
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.getFieldLabelTitle(field), /*#__PURE__*/_react.default.createElement("textarea", {
|
|
435
|
+
className: "form-control",
|
|
436
|
+
readOnly: this.props.read_only ? this.props.read_only : false,
|
|
437
|
+
type: field.input_type,
|
|
438
|
+
value: this.getFieldData(field),
|
|
439
|
+
placeholder: field.placeholder,
|
|
440
|
+
rows: field.rows,
|
|
441
|
+
onChange: e => {
|
|
442
|
+
e.preventDefault();
|
|
443
|
+
this.dynamicInputTextChangeHandler({
|
|
444
|
+
event: e,
|
|
445
|
+
fieldObject: field
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}), this._error_label(field));
|
|
449
|
+
};
|
|
450
|
+
_combo_field = field => {
|
|
451
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.getFieldLabelTitle(field), /*#__PURE__*/_react.default.createElement(_multiselectReactDropdown.default, {
|
|
452
|
+
showArrow: true,
|
|
453
|
+
options: field.combo_list,
|
|
454
|
+
isObject: false,
|
|
455
|
+
displayValue: "key",
|
|
456
|
+
selectedValues: this.getFieldData(field) ? this.getFieldData(field).split(";") : [],
|
|
457
|
+
placeholder: field.placeholder,
|
|
458
|
+
emptyRecordMsg: "",
|
|
459
|
+
onSelect: (selectedList, selectedItem) => {
|
|
460
|
+
this.setFieldData(field, selectedList.join(";"));
|
|
461
|
+
},
|
|
462
|
+
onRemove: (selectedList, selectedItem) => {
|
|
463
|
+
this.setFieldData(field, selectedList.join(";"));
|
|
464
|
+
},
|
|
465
|
+
disable: this.props.read_only,
|
|
466
|
+
singleSelect: true
|
|
467
|
+
}), this._error_label(field));
|
|
468
|
+
};
|
|
469
|
+
_multi_field = field => {
|
|
470
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.getFieldLabelTitle(field), /*#__PURE__*/_react.default.createElement(_multiselectReactDropdown.default, {
|
|
471
|
+
showArrow: true,
|
|
472
|
+
options: field.combo_list,
|
|
473
|
+
isObject: false,
|
|
474
|
+
displayValue: "key",
|
|
475
|
+
selectedValues: this.getFieldData(field) ? this.getFieldData(field).split(";") : [],
|
|
476
|
+
placeholder: field.placeholder,
|
|
477
|
+
emptyRecordMsg: "",
|
|
478
|
+
onSelect: (selectedList, selectedItem) => {
|
|
479
|
+
this.setFieldData(field, selectedList.join(";"));
|
|
480
|
+
},
|
|
481
|
+
onRemove: (selectedList, selectedItem) => {
|
|
482
|
+
this.setFieldData(field, selectedList.join(";"));
|
|
483
|
+
},
|
|
484
|
+
disable: this.props.read_only,
|
|
485
|
+
singleSelect: false
|
|
486
|
+
}), this._error_label(field));
|
|
487
|
+
};
|
|
488
|
+
saveFormToDatasyncProcess = () => {
|
|
489
|
+
//Everything sounds ok in Form, Go ahead
|
|
490
|
+
let hasDataGuid = this.props.datasync_object && this.props.datasync_object.data_guid;
|
|
491
|
+
saveDataTierToDatasync(hasDataGuid ? this.props.datasync_object.data_guid : null,
|
|
492
|
+
//data_guid
|
|
493
|
+
this.data_blob,
|
|
494
|
+
//p_o_data_blob,
|
|
495
|
+
this.props.company_guid,
|
|
496
|
+
//p_s_company_guid,
|
|
497
|
+
this.props.table_guid,
|
|
498
|
+
//p_s_table_guid,
|
|
499
|
+
hasDataGuid ? this.props.datasync_object.createstamp : cTimeStamp(),
|
|
500
|
+
//p_dt_createstamp,
|
|
501
|
+
hasDataGuid ? cTimeStamp() : null,
|
|
502
|
+
//p_dt_updatestamp,
|
|
503
|
+
null,
|
|
504
|
+
//p_dt_deletestamp,
|
|
505
|
+
this.onFormSavedLocalHandler, this.onFormUpdatedLocalHandler, this.onFormFailedLocalHandler, null);
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
/** Form Handlers */
|
|
509
|
+
onClickSubmitFormHandler = async event => {
|
|
510
|
+
if (event) event.preventDefault();
|
|
511
|
+
|
|
512
|
+
//Force all fields check
|
|
513
|
+
let canSubmit = true;
|
|
514
|
+
let iRow = 0;
|
|
515
|
+
while (iRow < this.state.form.Rows.length && canSubmit) {
|
|
516
|
+
let iCol = 0;
|
|
517
|
+
while (iCol < this.state.form.Rows[iRow].Cols.length && canSubmit) {
|
|
518
|
+
let ii = 0;
|
|
519
|
+
while (ii < this.state.form.Rows[iRow].Cols[iCol].Fields.length && (canSubmit &= this.checkValidation(this.state.form.Rows[iRow].Cols[iCol].Fields[ii]))) {
|
|
520
|
+
if (globals.parameters.debugging) console.log(`Fields[${ii}]|${this.state.form.Rows[iRow].Cols[iCol].Fields[ii].name}| canSubmit=${canSubmit}`);
|
|
521
|
+
ii++;
|
|
522
|
+
}
|
|
523
|
+
iCol++;
|
|
524
|
+
}
|
|
525
|
+
iRow++;
|
|
526
|
+
}
|
|
527
|
+
if (globals.parameters.debugging) console.log("canSubmit:", canSubmit);
|
|
528
|
+
if (!canSubmit) {
|
|
529
|
+
let err_message = "Le formulaire comporte des erreurs !";
|
|
530
|
+
if (this.props.onFormFailed) this.props.onFormFailed(err_message);else alert(`${err_message}`);
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
//Invoke onFormSubmit props
|
|
535
|
+
|
|
536
|
+
if (this.props.onFormSubmit) {
|
|
537
|
+
if (globals.parameters.debugging) alert("onFormSubmit => filter log with AsyncDebug:: prefixe");
|
|
538
|
+
//If props function return false then cancel form submit and do not save !
|
|
539
|
+
this.props.onFormSubmit(this.data_blob, this.saveFormToDatasyncProcess);
|
|
540
|
+
} else {
|
|
541
|
+
//Call save anyway
|
|
542
|
+
this.saveFormToDatasyncProcess();
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
//this.saveFormToDatasync_OLD((this.props.datasync_object && this.props.datasync_object.data_guid)?this.props.datasync_object.data_guid:null);
|
|
546
|
+
};
|
|
547
|
+
onFormSavedLocalHandler = blob => {
|
|
548
|
+
if (this.props.onFormSaved) this.props.onFormSaved(blob);else console.error("DynamicForm3Tiers2.onFormSaved props is not defined !");
|
|
549
|
+
//clear form
|
|
550
|
+
if (this.props.clearOnSave) this.clearForm();
|
|
551
|
+
//Call onTerminated if set by user
|
|
552
|
+
if (this.props.onTerminated) this.props.onTerminated();
|
|
553
|
+
};
|
|
554
|
+
onFormUpdatedLocalHandler = blob => {
|
|
555
|
+
if (this.props.onFormUpdated) this.props.onFormUpdated(blob);else console.error("DynamicForm3Tiers2.onFormUpdated props is not defined !");
|
|
556
|
+
//clear form
|
|
557
|
+
if (this.props.clearOnUpdate) this.clearForm();
|
|
558
|
+
//Call onTerminated if set by user
|
|
559
|
+
if (this.props.onTerminated) this.props.onTerminated();
|
|
560
|
+
};
|
|
561
|
+
onFormFailedLocalHandler = err => {
|
|
562
|
+
if (this.props.onFormFailed) this.props.onFormFailed(err);else {
|
|
563
|
+
console.error("DynamicForm3Tiers2.onFormFailed props is not defined !");
|
|
564
|
+
alert("Erreur de sauvegarde !!!");
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
checkValidation = pFieldObject => {
|
|
568
|
+
let fieldName = pFieldObject.name;
|
|
569
|
+
|
|
570
|
+
/** Get field properties */
|
|
571
|
+
let min = pFieldObject.min_length;
|
|
572
|
+
let max = pFieldObject.max_length;
|
|
573
|
+
let fieldValue = this.getFieldData(pFieldObject);
|
|
574
|
+
console.log("d3t3:checkValidation fieldValue->", fieldValue);
|
|
575
|
+
let errorsFieldName = `err_${fieldName}`; /** Error data displayed in dedicated error label, beside input field in Form */
|
|
576
|
+
let nextErrors = [];
|
|
577
|
+
if (globals.parameters.debugging) console.log(`d3t:min:${min} - max:${max}`);
|
|
578
|
+
|
|
579
|
+
/** Check basic field validity except combo and radio */
|
|
580
|
+
if (pFieldObject.required && fieldValue.trim().length <= 0) nextErrors.push(`obligatoire`);
|
|
581
|
+
if (min > 0 && pFieldObject.required && fieldValue.trim().length < min) nextErrors.push(`trop court.`);
|
|
582
|
+
|
|
583
|
+
//Captcha check
|
|
584
|
+
if (pFieldObject.input_type.toLowerCase() == "captcha") {
|
|
585
|
+
if (parseInt(fieldValue) !== this.state.captcha1 + this.state.captcha2) nextErrors.push(`calcul faux !`);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
//Email check
|
|
589
|
+
if (pFieldObject.input_type.toLowerCase() == "email") {
|
|
590
|
+
if (!fieldValue.match(/^([\w.%+-]+)@([\w-]+\.)+([\w]{2,})$/i)) nextErrors.push(`Format de mail incorrect !`);
|
|
591
|
+
}
|
|
592
|
+
if (max > 0 && fieldValue.trim().length > max) nextErrors.push(`trop long, ${fieldValue.trim().length - max} caractères en trop.`);
|
|
593
|
+
/* Special validation handlers
|
|
594
|
+
if (parseInt(this.state[fieldName]) !== (this.state.v1 + this.state.v2))
|
|
595
|
+
nextErrors.push(`calcul faux !`)*/
|
|
596
|
+
|
|
597
|
+
if (globals.parameters.debugging) {
|
|
598
|
+
console.log(`d3t:-----------------`);
|
|
599
|
+
console.log(`d3t:fieldName => ${fieldName}`);
|
|
600
|
+
console.log(`d3t:value => ${fieldValue}`);
|
|
601
|
+
console.log(`errorsFieldName => ${errorsFieldName}`);
|
|
602
|
+
console.log(`nextErrors => ${nextErrors}`);
|
|
603
|
+
console.log(`nextErrors.length => ${nextErrors.length}`);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
//update error field
|
|
607
|
+
if (globals.parameters.debugging) {
|
|
608
|
+
console.log("nextFieldsErrorsArray=>", nextErrors);
|
|
609
|
+
}
|
|
610
|
+
this.setFieldError(pFieldObject, nextErrors.join("/"));
|
|
611
|
+
if (globals.parameters.debugging) {
|
|
612
|
+
console.log(`new fieldError : ${this.getFieldError(pFieldObject)}`);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
//set change flag
|
|
616
|
+
//nextState.has_changed = true
|
|
617
|
+
|
|
618
|
+
//Return validation predicate
|
|
619
|
+
return nextErrors.length === 0; //returns true if no error occurs
|
|
620
|
+
};
|
|
621
|
+
dynamicInputTextChangeHandler = eventObject => {
|
|
622
|
+
if (eventObject && eventObject.event) eventObject.event.preventDefault();
|
|
623
|
+
if (globals.parameters.debugging) console.log(`d3t:dynamicInputTextChangeHandler eventObject -> `, eventObject);
|
|
624
|
+
this.setFieldData(eventObject.fieldObject, eventObject.event.target.value);
|
|
625
|
+
|
|
626
|
+
//Validate field
|
|
627
|
+
this.checkValidation(eventObject.fieldObject);
|
|
628
|
+
};
|
|
629
|
+
dynamicInputNumericChangeHandler = eventObject => {
|
|
630
|
+
if (eventObject && eventObject.event) eventObject.event.preventDefault();
|
|
631
|
+
if (globals.parameters.debugging) console.log(`d3t:dynamicInputNumericChangeHandler ${eventObject.fieldObject.name} Input field has changed`);
|
|
632
|
+
if (eventObject.event.target.value.length == 0 || !isNaN(eventObject.event.target.value) && !isNaN(parseFloat(eventObject.event.target.value))) this.setFieldData(eventObject.fieldObject, eventObject.event.target.value);else {
|
|
633
|
+
if (globals.parameters.debugging) console.log(`d3t:Value rejected -> ${eventObject.event.target.value}`);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
//Validate field
|
|
637
|
+
if (globals.parameters.debugging) console.log(`#${eventObject.fieldObject.name} => ${this.getFieldData(eventObject.fieldObject)}`);
|
|
638
|
+
this.checkValidation(eventObject.fieldObject);
|
|
639
|
+
};
|
|
640
|
+
_colRendering = col => {
|
|
641
|
+
try {
|
|
642
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.Col, null, col.Fields.map((field, ii) => {
|
|
643
|
+
return this._fieldRendering(field, ii);
|
|
644
|
+
}));
|
|
645
|
+
} catch (err) {
|
|
646
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.Col, null, "Error ", err.message);
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
_rowRendering = row => {
|
|
650
|
+
try {
|
|
651
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.Row, null, row.Cols.map((col, ii) => {
|
|
652
|
+
return this._colRendering(col);
|
|
653
|
+
}));
|
|
654
|
+
} catch (err) {
|
|
655
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.Col, null, "Error ", err.message);
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
migrate_field = (pFieldObject, migrated_value) => {
|
|
659
|
+
//Set data_tier property with former form value
|
|
660
|
+
this.data_blob.data_tier[pFieldObject.name] = migrated_value;
|
|
661
|
+
if (globals.parameters.debugging) console.log("09/07:migrate_field -> pFieldObject.name=", pFieldObject.name);
|
|
662
|
+
};
|
|
663
|
+
data_tier_migration = (field, ii) => {
|
|
664
|
+
if (!this.props.data_blob) return; //Discard migration
|
|
665
|
+
return;
|
|
666
|
+
//data_tier_migration disbled
|
|
667
|
+
console.log("09/07:data_tier_migration ### Migration check !!!");
|
|
668
|
+
console.log("09/07:this.data_blob.modified ->", this.data_blob && this.data_blob.modified ? this.data_blob.modified : "null");
|
|
669
|
+
//Check if migration required
|
|
670
|
+
if (this.data_blob && this.data_blob.modified && this.data_blob.modified < globals.parameters.form_modified_version) if (globals.parameters.debugging) console.log("09/07:field needs migration from version 1 to version 2");else {
|
|
671
|
+
if (globals.parameters.debugging) console.log("09/07:Field is up to date");
|
|
672
|
+
//Don't care migration process
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
if (globals.parameters.debugging) {
|
|
676
|
+
console.log("09/07:data_tier_migration ->", field.input_type);
|
|
677
|
+
}
|
|
678
|
+
switch (field.input_type.toLowerCase()) {
|
|
679
|
+
/** Dynamic fields */
|
|
680
|
+
case "checkbox-DISABLED":
|
|
681
|
+
case "checkbox":
|
|
682
|
+
case "blob":
|
|
683
|
+
case "email":
|
|
684
|
+
case "text":
|
|
685
|
+
case "memo":
|
|
686
|
+
case "multi":
|
|
687
|
+
case "numeric":
|
|
688
|
+
case "amount":
|
|
689
|
+
case "percent":
|
|
690
|
+
case "captcha":
|
|
691
|
+
case "textarea":
|
|
692
|
+
//Migrate single field
|
|
693
|
+
if (globals.parameters.debugging) {
|
|
694
|
+
console.log("09/07:data_tier_migration single field ->", field.name);
|
|
695
|
+
}
|
|
696
|
+
this.migrate_field(field, this.getFieldData_V1(field));
|
|
697
|
+
break;
|
|
698
|
+
case "combo":
|
|
699
|
+
case "radio":
|
|
700
|
+
//Migrate selected field
|
|
701
|
+
if (globals.parameters.debugging) {
|
|
702
|
+
console.log("09/07:data_tier_migration selected field ->", field.name);
|
|
703
|
+
}
|
|
704
|
+
this.migrate_field(field, this.getSelectedFieldValues_V1(field));
|
|
705
|
+
break;
|
|
706
|
+
default:
|
|
707
|
+
alert("data_tier_migration --> Field type not supported ->" + field.input_type);
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
_fieldRendering = (field, ii) => {
|
|
711
|
+
console.log("09/07:_fieldRendering -> data_tier_migration call");
|
|
712
|
+
this.data_tier_migration(field, ii);
|
|
713
|
+
//Do not display field if empty in read only mode
|
|
714
|
+
if (this.props.read_only && (this.getFieldData(field) == null || !this.getFieldData(field) || this.getFieldData(field).trim().length == 0)) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
715
|
+
|
|
716
|
+
//Do not display hidden field
|
|
717
|
+
if (field.hidden && !this.props.show_hidden) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
718
|
+
switch (field.input_type.toLowerCase()) {
|
|
719
|
+
/** Dynamic fields */
|
|
720
|
+
case "checkbox-DISABLED":
|
|
721
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.FormGroup, {
|
|
722
|
+
check: true
|
|
723
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Label, {
|
|
724
|
+
check: true
|
|
725
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Input, {
|
|
726
|
+
defaultValue: "",
|
|
727
|
+
type: "checkbox",
|
|
728
|
+
readOnly: this.props.read_only ? this.props.read_only : false
|
|
729
|
+
}), field.placeholder, /*#__PURE__*/_react.default.createElement("span", {
|
|
730
|
+
className: "form-check-sign"
|
|
731
|
+
})));
|
|
732
|
+
case "checkbox":
|
|
733
|
+
/* Checkbox is override with combobox */
|
|
734
|
+
return /*#__PURE__*/_react.default.createElement("div", null, this.getFieldLabelTitle(field), /*#__PURE__*/_react.default.createElement(_multiselectReactDropdown.default, {
|
|
735
|
+
showArrow: true,
|
|
736
|
+
options: ["Oui", "Non"],
|
|
737
|
+
isObject: false,
|
|
738
|
+
displayValue: "key",
|
|
739
|
+
selectedValues: this.getFieldData(field) ? this.getFieldData(field).split(";") : [],
|
|
740
|
+
placeholder: field.placeholder,
|
|
741
|
+
emptyRecordMsg: "",
|
|
742
|
+
onSelect: (selectedList, selectedItem) => {
|
|
743
|
+
this.setFieldData(field, selectedList.join(";"));
|
|
744
|
+
},
|
|
745
|
+
onRemove: (selectedList, selectedItem) => {
|
|
746
|
+
this.setFieldData(field, selectedList.join(";"));
|
|
747
|
+
},
|
|
748
|
+
disable: this.props.read_only,
|
|
749
|
+
singleSelect: true
|
|
750
|
+
}), this._error_label(field));
|
|
751
|
+
case "blob":
|
|
752
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, this.getFieldLabelTitle(field), /*#__PURE__*/_react.default.createElement("div", {
|
|
753
|
+
className: "col-md-10"
|
|
754
|
+
}, this._error_label(field)));
|
|
755
|
+
case "email":
|
|
756
|
+
return this._email_field(field);
|
|
757
|
+
case "text":
|
|
758
|
+
return this._text_field(field);
|
|
759
|
+
case "memo":
|
|
760
|
+
return this._memo_field(field);
|
|
761
|
+
case "combo":
|
|
762
|
+
case "radio":
|
|
763
|
+
return this._combo_field(field);
|
|
764
|
+
case "multi":
|
|
765
|
+
return this._multi_field(field);
|
|
766
|
+
case "numeric":
|
|
767
|
+
return this._numeric_field_with_add_on(field, "*");
|
|
768
|
+
case "amount":
|
|
769
|
+
return this._numeric_field_with_add_on(field, "fa-euro");
|
|
770
|
+
case "percent":
|
|
771
|
+
return this._numeric_field_with_add_on(field, "%");
|
|
772
|
+
case "captcha":
|
|
773
|
+
return this._captcha_field(field);
|
|
774
|
+
default:
|
|
775
|
+
console.log("alert à Malibu");
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
_cancelButton = () => {
|
|
779
|
+
let buttonIsHidden = this.props.read_only || this.props.buttons_options && this.props.buttons_options.cancel_button_hidden;
|
|
780
|
+
let buttonCaption = this.props.buttons_options && this.props.buttons_options.cancel_button_caption ? this.props.buttons_options.cancel_button_caption : "Annuler";
|
|
781
|
+
if (buttonIsHidden) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);else {
|
|
782
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.Col, {
|
|
783
|
+
md: "4",
|
|
784
|
+
sm: "4"
|
|
785
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Button, {
|
|
786
|
+
block: true,
|
|
787
|
+
className: "btn-round",
|
|
788
|
+
color: "danger",
|
|
789
|
+
outline: true,
|
|
790
|
+
type: "reset",
|
|
791
|
+
onClick: () => {
|
|
792
|
+
this.clearForm();
|
|
793
|
+
}
|
|
794
|
+
}, buttonCaption));
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
_submitButton = () => {
|
|
798
|
+
let buttonIsHidden = this.props.read_only || this.props.buttons_options && this.props.buttons_options.submit_button_hidden;
|
|
799
|
+
let buttonCaption = this.props.buttons_options && this.props.buttons_options.submit_button_caption ? this.props.buttons_options.submit_button_caption : "Soumettre";
|
|
800
|
+
if (buttonIsHidden) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);else {
|
|
801
|
+
return /*#__PURE__*/_react.default.createElement(_reactstrap.Col, {
|
|
802
|
+
md: "4",
|
|
803
|
+
sm: "4"
|
|
804
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Button, {
|
|
805
|
+
block: true,
|
|
806
|
+
className: "btn-round",
|
|
807
|
+
color: "danger",
|
|
808
|
+
outline: true,
|
|
809
|
+
type: "submit",
|
|
810
|
+
onClick: () => {
|
|
811
|
+
this.onClickSubmitFormHandler();
|
|
812
|
+
}
|
|
813
|
+
}, buttonCaption));
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
render = () => {
|
|
817
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, !this.state.form && /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("h1", null, "Form loading...")), /*#__PURE__*/_react.default.createElement("form", null, this.state.form && this.state.form.Rows && this.state.form.Rows.map(row => {
|
|
818
|
+
return this._rowRendering(row);
|
|
819
|
+
})), /*#__PURE__*/_react.default.createElement(_reactstrap.Row, {
|
|
820
|
+
className: "buttons-row"
|
|
821
|
+
}, this._cancelButton(), this._submitButton(), this.props.custom_button_caption && /*#__PURE__*/_react.default.createElement(_reactstrap.Col, {
|
|
822
|
+
md: "4",
|
|
823
|
+
sm: "4"
|
|
824
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Button, {
|
|
825
|
+
block: true,
|
|
826
|
+
className: "btn-round",
|
|
827
|
+
color: "primary",
|
|
828
|
+
type: "submit",
|
|
829
|
+
onClick: e => {
|
|
830
|
+
if (this.props.custom_button_handler) this.props.custom_button_handler(this.state.form);else console.error("custom_button_handler unset !");
|
|
831
|
+
}
|
|
832
|
+
}, this.props.custom_button_caption)), this.props.custom_button_caption2 && /*#__PURE__*/_react.default.createElement(_reactstrap.Col, {
|
|
833
|
+
md: "4",
|
|
834
|
+
sm: "4"
|
|
835
|
+
}, /*#__PURE__*/_react.default.createElement(_reactstrap.Button, {
|
|
836
|
+
block: true,
|
|
837
|
+
className: "btn-round",
|
|
838
|
+
color: "primary",
|
|
839
|
+
type: "submit",
|
|
840
|
+
onClick: e => {
|
|
841
|
+
if (this.props.custom_button_handler2) this.props.custom_button_handler2(this.state.form);else console.error("custom_button_handler2 unset !");
|
|
842
|
+
}
|
|
843
|
+
}, this.props.custom_button_caption2))));
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
exports.DsDynamicForm = DsDynamicForm;
|
|
847
|
+
;
|