commit | author | age
|
d2a29b
|
1 |
/** |
DC |
2 |
* quest' oggetto definisce i metodi XML |
|
3 |
* se is_editable è true la stringa XML verrà modificato dall' update massivo |
|
4 |
* @type {{sso_getWebcustomerInformation: {defaultXML: string, is_editable: boolean, actualXML: string}, sso_getSelectedMSISDNDetails: {defaultXML: string, is_editable: boolean, actualXML: string}, sso_getMSISDNDetails: {defaultXML: string, is_editable: boolean, actualXML: string}, picasso_getWebcustomerInformation: {defaultXML: string, is_editable: boolean, actualXML: string}, sso_getMSISDNList: {defaultXML: string, is_editable: boolean, actualXML: string}, sso_getInfoActivationWSC: {defaultXML: string, is_editable: boolean, actualXML: string}}} |
|
5 |
*/ |
|
6 |
let xmlMethods = { |
|
7 |
'sso_getWebcustomerInformation': { |
|
8 |
'defaultXML': sso_getWebcustomerInformation, |
|
9 |
'actualXML': sso_getWebcustomerInformation, // dopo le modifiche |
|
10 |
'is_editable': true // verrà modificato dalle modifiche massive? |
|
11 |
}, |
|
12 |
'sso_getMSISDNDetails': { |
|
13 |
'defaultXML': sso_getMSISDNDetails, |
|
14 |
'actualXML': sso_getMSISDNDetails, |
|
15 |
'is_editable': true |
|
16 |
}, |
|
17 |
'sso_getMSISDNList': { |
|
18 |
'defaultXML': sso_getMSISDNList, |
|
19 |
'actualXML': sso_getMSISDNList, |
|
20 |
'is_editable': true |
|
21 |
}, |
|
22 |
'sso_getSelectedMSISDNDetails': { |
|
23 |
'defaultXML': sso_getSelectedMSISDNDetails, |
|
24 |
'actualXML': sso_getSelectedMSISDNDetails, |
|
25 |
'is_editable': true |
|
26 |
}, |
|
27 |
'sso_getInfoActivationWSC': { |
|
28 |
'defaultXML': sso_getInfoActivationWSC, |
|
29 |
'actualXML': sso_getInfoActivationWSC, |
|
30 |
'is_editable': true |
|
31 |
}, |
|
32 |
'picasso_getWebcustomerInformation': { |
|
33 |
'defaultXML': picasso_getWebcustomerInformation, |
|
34 |
'actualXML': picasso_getWebcustomerInformation, |
|
35 |
'is_editable': true |
|
36 |
}, |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* questa è la lista di campi mostrati nella sezione di update massivo |
|
41 |
* per aggiungere un campo è necessario aggiungere un oggetto di questo tipo alla lista |
|
42 |
* @type {({defaultValue: number, inputType: string, requireCheckbox: boolean, inputName: string}|{defaultValue: string, onChangeEditFields: {custcode: {editType: string}}, inputName: string}|{defaultValue: string, inputName: string}|{defaultValue: string, inputName: string}|{defaultValue: string, inputName: string})[]} |
|
43 |
*/ |
|
44 |
let editableFields = [ |
|
45 |
{ |
|
46 |
'inputName': 'n_sim', |
|
47 |
'inputType': 'number', |
|
48 |
"defaultValue": 1, |
|
49 |
'requireCheckbox': false, |
|
50 |
}, |
|
51 |
{ |
|
52 |
'inputName': 'profile_user_name', |
|
53 |
"defaultValue": "NAME FAKESSO | DUAL TM9 RIC 5.49275", |
|
54 |
'requireCheckbox': false, |
|
55 |
}, |
|
56 |
{ |
|
57 |
'inputName': 'Custcode', |
|
58 |
'defaultValue': '5.49275', |
|
59 |
'onChangeEditFields': { |
|
60 |
'custcode': { |
|
61 |
'editType': 'copyMain' |
|
62 |
} |
|
63 |
} |
|
64 |
}, |
|
65 |
{ |
|
66 |
'inputName': 'EmailAddress', |
|
67 |
'defaultValue': 'pippo@vola.it' |
|
68 |
}, |
|
69 |
{ |
|
70 |
'inputName': 'Name', |
|
71 |
'defaultValue': 'Paola' |
|
72 |
}, |
|
73 |
{ |
|
74 |
'inputName': 'ProfileIdentifier', |
|
75 |
'defaultValue': 'BUSINESS_EMPLOYEE' |
|
76 |
}, |
|
77 |
{ |
|
78 |
'inputName': 'Surname', |
|
79 |
'defaultValue': 'Sandrelli' |
|
80 |
}, |
|
81 |
{ |
|
82 |
'inputName': 'Username', |
|
83 |
'defaultValue': 'FAKE_SSO_', |
|
84 |
'onChangeEditFields': { |
|
85 |
'username': { |
|
86 |
'editType': 'copyMain' |
|
87 |
}, |
|
88 |
} |
|
89 |
}, |
|
90 |
{ |
|
91 |
'inputName': 'IdPiano', |
|
92 |
'defaultValue': '2491' |
|
93 |
}, |
|
94 |
{ |
|
95 |
'inputName': 'OMProductId', |
|
96 |
'defaultValue': '2156' // se uno di quelli dual risulto come dual già attivo |
|
97 |
}, |
|
98 |
{ |
|
99 |
'inputName': 'tmCode', |
|
100 |
'defaultValue': '2491' |
|
101 |
}, |
|
102 |
{ |
|
103 |
'inputName': 'sim_1', |
|
104 |
'defaultValue': '3464232371', |
|
105 |
'onChangeEditFields': { |
|
106 |
'MSISDN': { |
|
107 |
'editType': 'copyMain' |
|
108 |
}, |
|
109 |
'selectedBoID': { |
|
110 |
'editType': 'copyMain' |
|
111 |
} |
|
112 |
} |
|
113 |
} |
|
114 |
// { |
|
115 |
// 'inputName': 'Type_ID', |
|
116 |
// 'defaultValue':'...', |
|
117 |
// 'labelText': 'Type_ID ex. (2)' |
|
118 |
// }, |
|
119 |
// { |
|
120 |
// 'inputName': 'providerID', |
|
121 |
// 'defaultValue':'...' |
|
122 |
// }, |
|
123 |
// { |
|
124 |
// 'inputName': 'selectedBoId', |
|
125 |
// 'defaultValue':'...' |
|
126 |
// // }, |
|
127 |
// { |
|
128 |
// 'inputName': 'selectedBoType', |
|
129 |
// 'defaultValue':'...' |
|
130 |
// }, |
|
131 |
// { |
|
132 |
// 'inputName': 'username', |
|
133 |
// 'defaultValue':'...' |
|
134 |
// }, |
|
135 |
// { |
|
136 |
// 'inputName': 'productId', |
|
137 |
// 'defaultValue':'...' |
|
138 |
// }, |
|
139 |
// { |
|
140 |
// 'inputName': 'productType', |
|
141 |
// 'defaultValue':'...' |
|
142 |
// }, |
|
143 |
// { |
|
144 |
// 'inputName': 'offerType', |
|
145 |
// 'defaultValue':'...' |
|
146 |
// }, |
|
147 |
// { |
|
148 |
// 'inputName': 'rewardID', |
|
149 |
// 'defaultValue':'...' |
|
150 |
// }, |
|
151 |
// { |
|
152 |
// 'inputName': 'groupTypeID', |
|
153 |
// 'defaultValue':'...' |
|
154 |
// } |
|
155 |
]; |
|
156 |
|
488dbe
|
157 |
|
FB |
158 |
|
|
159 |
function sendResponse() { |
|
160 |
|
|
161 |
document.getElementById('edit-all').submit(); |
|
162 |
} |
4c12f7
|
163 |
|
d2a29b
|
164 |
$(document).ready(function () { |
DC |
165 |
addEditableFieldsInputs(); |
|
166 |
$.each(xmlMethods, function (method_name) { |
|
167 |
setDefaultXML(method_name); |
|
168 |
if (xmlMethods[method_name]["is_editable"]) { |
|
169 |
$(`input[name="is_editable_${method_name}"]`).prop("checked", true); |
|
170 |
} |
|
171 |
}) |
|
172 |
serializeInputAndEditXML(true, true); |
|
173 |
$('input[name="n_sim"]').on('change', displayNInputsForNSims); |
|
174 |
$('input[name^="shouldReplace_"]').on('change', shouldReplaceOption); |
|
175 |
$(document).on('change', '#edit-all input:not([type="checkbox"])', serializeInputAndEditXML); |
4c12f7
|
176 |
$(document).on('click', '#edit-all button[name=modifica_massiva]', serializeInputAndEditXML); |
488dbe
|
177 |
$(document).on('click', '#edit-all button[name=database]', sendResponse); |
d2a29b
|
178 |
$('input[name^="is_editable_"]').on('change', changeEditOption); |
DC |
179 |
$(document).on('input', 'textarea', validateTextarea); |
|
180 |
$(document).on('click', 'button[id^="set_default_xml_"]', setDefaultXML); |
|
181 |
$(document).on('click', 'button[name="show_result"]', showResult); |
|
182 |
$(document).on('click', 'button[name="copy-result"]', copyToClipboard); |
4c12f7
|
183 |
}); |
D |
184 |
|
d2a29b
|
185 |
|
DC |
186 |
/** |
|
187 |
* partendo dalla lista di sim aggiungo tutti i tag sim all' xml del metodo getMSISDNList |
|
188 |
* @param sim_list |
|
189 |
*/ |
|
190 |
function editGetMSISDNListXML(sim_list) { |
|
191 |
let jsonMsisdn = $.xml2json(sso_getMSISDNList) |
|
192 |
let MSISDNList = jsonMsisdn["getMDISDNList"]["msisdn_list"] |
|
193 |
|
|
194 |
sim_list.forEach(function (sim_obj) { |
|
195 |
MSISDNList[sim_obj.inputName] = "" |
|
196 |
}); |
|
197 |
|
|
198 |
const newXML = $.json2xml(jsonMsisdn) |
|
199 |
let encodingValue = $.parseXML(sso_getMSISDNList)["xmlEncoding"] ?? null; |
|
200 |
const xmlHead = `<?xml version="1.0" encoding="${encodingValue}"?>`; |
|
201 |
xmlMethods.sso_getMSISDNList.actualXML = xmlHead + newXML |
|
202 |
const formattedXML = vkbeautify.xml(xmlMethods.sso_getMSISDNList.actualXML) |
|
203 |
$(`textarea#sso_getMSISDNList`).val(formattedXML) |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* aggiungo una textarea per ogni sim per il metodo selezionato |
|
208 |
* @param sim_list |
|
209 |
* @param genericMethodName valori tipo -> "sso_getSelectedMSISDNDetails", "sso_getInfoActivationWSC" |
|
210 |
*/ |
|
211 |
function add_N_areatext_sections(sim_list, genericMethodName) { |
|
212 |
let additional_methods_wrapper = $('#' + "additional_methods_" + genericMethodName) |
|
213 |
additional_methods_wrapper.empty() |
|
214 |
|
|
215 |
sim_list.forEach(function (sim_obj) { |
|
216 |
let sim_code = sim_obj.inputName |
|
217 |
let uniqueMethodName = sim_code + "_" + genericMethodName |
|
218 |
xmlMethods[uniqueMethodName] = { |
|
219 |
'defaultXML': xmlMethods.sso_getSelectedMSISDNDetails.defaultXML, |
|
220 |
'actualXML': xmlMethods.sso_getSelectedMSISDNDetails.defaultXML, |
|
221 |
'is_editable': true |
|
222 |
} |
|
223 |
let formattedXML = vkbeautify.xml(xmlMethods[uniqueMethodName]["defaultXML"]) |
|
224 |
let additionalMethodArea = ` |
|
225 |
<div class="mb-3"> |
|
226 |
<label for="${uniqueMethodName}" class="form-label text-danger font-weight-bolder">${uniqueMethodName}</label> |
|
227 |
<label> |
|
228 |
Questo metodo deve essere modificato dal replace massivo? |
|
229 |
<input type="checkbox" name="is_editable_${uniqueMethodName}" class="check-control" checked> |
|
230 |
</label> |
|
231 |
<button id="set_default_xml_${uniqueMethodName}" class="btn btn-primary btn-sm m-0 mx-3"> |
|
232 |
DEFAULT XML |
|
233 |
</button> |
|
234 |
<textarea class="form-control" id="${uniqueMethodName}" name="${uniqueMethodName}" rows="10">${formattedXML}</textarea> |
|
235 |
<div id="${uniqueMethodName}_errorBox" class="text-danger font-size-sm"></div> |
|
236 |
</div>`; |
|
237 |
additional_methods_wrapper.append(additionalMethodArea) |
|
238 |
} |
|
239 |
) |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* questo metodo viene chiamato ogni volta che cambia in numero di sim e: |
|
244 |
* |
|
245 |
* genero gli oggetti input per ogni sim |
|
246 |
* passo la lista di oggetti input a addEditableFieldsInput (aggiunti nella sezione modifica massiva) |
|
247 |
* aggiorno l' xml del metodo getMSISDNList con le nuove sim |
|
248 |
* aggiungo una nuova textarea di editing metodo per ogni sim per i metodi getSelectedMSISDNDetails getInfoActivationWSC |
|
249 |
* @return void |
|
250 |
*/ |
|
251 |
function displayNInputsForNSims() { |
|
252 |
$("[id^=sim_][id$=_wrapper]:not(#sim_1_wrapper)").remove();//rimuovo i vecchi input |
|
253 |
editableFields = editableFields.filter(field => !(field.inputName.startsWith('sim_') && (field.inputName !== "sim_1"))); |
|
254 |
let numberOfSim = $(this).val(); |
|
255 |
|
|
256 |
if (!(0 < numberOfSim) || !(numberOfSim <= 6)) { |
|
257 |
$(this).val(1) |
|
258 |
numberOfSim = 1 |
|
259 |
} |
|
260 |
|
|
261 |
const phone_number_sim_1 = $('input[name="sim_1"]').val() |
|
262 |
let sim_list = []; |
|
263 |
for (let sim_n = 2; sim_n <= numberOfSim; sim_n++) { |
|
264 |
let inputObj = { |
|
265 |
"inputName": "sim_" + sim_n, |
|
266 |
"defaultValue": phone_number_sim_1 + sim_n//qui |
|
267 |
}; |
|
268 |
sim_list.push(inputObj) |
|
269 |
editableFields.push(inputObj) |
|
270 |
} |
|
271 |
|
|
272 |
addEditableFieldsInputs(sim_list) |
|
273 |
//cambio actualXML di conseguenza inserendo dove necessario le chiavi aggiuntive di sim_1, sim_2, sim_3... |
|
274 |
// lista di xml che devono essere cambiati: |
|
275 |
// getMSISDNList (deve avere N tag sim_1, sim_2... ) |
|
276 |
editGetMSISDNListXML(sim_list) |
|
277 |
// getSelectedMSISDNDetails deve avere N textarea una per ogni sim |
|
278 |
add_N_areatext_sections(sim_list, "sso_getSelectedMSISDNDetails") |
|
279 |
// getInfoActivationWSC deve avere N textarea una per ogni sim |
|
280 |
add_N_areatext_sections(sim_list, "sso_getInfoActivationWSC") |
|
281 |
} |
|
282 |
|
|
283 |
/** |
|
284 |
* inserisco la lista di input in pagina per l' editing massivo dei campi |
|
285 |
* @param inputList |
|
286 |
*/ |
|
287 |
function addEditableFieldsInputs(inputList = editableFields) { |
|
288 |
let inputWrapper = $('#wrapper-input-list') |
|
289 |
|
|
290 |
inputList.forEach(function (inputObj, index) { |
|
291 |
|
|
292 |
let div = $("<div>", {id: inputObj["inputName"] + "_wrapper", class: "col mb-2"}); |
|
293 |
let labelText = inputObj["labelText"] ?? inputObj["inputName"]; |
|
294 |
let label = $("<label>", {for: inputObj["inputName"], class: "form-label"}).text(labelText); |
|
295 |
|
|
296 |
let checkbox = "" |
|
297 |
let input = $("<input>", { |
|
298 |
class: "form-control", |
|
299 |
type: inputObj["inputType"] ?? "text", |
|
300 |
value: inputObj["defaultValue"] ?? "", |
|
301 |
name: inputObj["inputName"], |
|
302 |
placeholder: inputObj["inputName"], |
|
303 |
id: inputObj["inputName"] |
|
304 |
}); |
|
305 |
|
|
306 |
if (inputObj.requireCheckbox !== false) { |
|
307 |
checkbox = $("<input>", { //necessaria per verificare se l' input corrispondente deve essere modificato |
|
308 |
class: "check-control mx-1", |
|
309 |
type: "checkbox", |
|
310 |
name: "shouldReplace_" + inputObj["inputName"] |
|
311 |
}); |
|
312 |
} |
|
313 |
|
|
314 |
|
|
315 |
div.append(label); |
|
316 |
div.append(checkbox); |
|
317 |
div.append(input); |
|
318 |
|
|
319 |
inputWrapper.append(div); |
|
320 |
}) |
|
321 |
|
|
322 |
} |
|
323 |
|
|
324 |
function showError(errorBox = $('#main_errorBox'), msg = "xml non formattato correttamente") { |
|
325 |
errorBox.show() |
|
326 |
const listItem = $('<li>', { |
|
327 |
text: msg |
|
328 |
}) |
|
329 |
errorBox.append(listItem) |
|
330 |
} |
|
331 |
|
|
332 |
/** |
|
333 |
* in questo metodo voglio prendere tutti gli input nella lista editableField (lista degli input edit massivo) parametrizzarli |
|
334 |
* una volta parametrizzati gli input partendo dalla struttura del vecchio xml (oggetto) |
|
335 |
* sostituisco tutte le chiavi che combaciano con i nuovi valori |
|
336 |
* @param alwaysEditable |
|
337 |
* @param updateDefaultXML |
|
338 |
*/ |
|
339 |
function serializeInputAndEditXML(alwaysEditable = false, updateDefaultXML = false) { |
488dbe
|
340 |
console.log("test serialize"); |
d2a29b
|
341 |
let serializedInputs = $('form#edit-all').serializeArray(); |
DC |
342 |
|
|
343 |
$.each(xmlMethods, function (methodName, methodObj) { |
|
344 |
if ((methodObj.is_editable) || (alwaysEditable === true)) { |
|
345 |
let encodingValue = $.parseXML(methodObj.actualXML)["xmlEncoding"] ?? null; |
|
346 |
|
|
347 |
let oldObj = $.xml2json(methodObj.actualXML) |
|
348 |
let newXML = mergeAndConvertObjInXML(oldObj, serializedInputs) |
|
349 |
|
|
350 |
if (encodingValue !== null) { |
|
351 |
const xmlHead = `<?xml version="1.0" encoding="${encodingValue}"?>`; |
|
352 |
methodObj.actualXML = xmlHead + newXML |
|
353 |
} else { |
|
354 |
methodObj.actualXML = newXML |
|
355 |
} |
|
356 |
|
|
357 |
if (updateDefaultXML === true) { |
|
358 |
methodObj.defaultXML = newXML |
|
359 |
} |
|
360 |
|
|
361 |
let isValid = $.isXmlValid(newXML) |
|
362 |
|
|
363 |
if (isValid) { |
|
364 |
const formattedXML = vkbeautify.xml(newXML) |
|
365 |
$(`textarea#${methodName}`).val(formattedXML.trim()) |
|
366 |
} else { |
|
367 |
$('#main_errorBox').empty() |
|
368 |
showError($('#' + methodName + '_errorBox')) |
|
369 |
} |
|
370 |
} |
|
371 |
} |
|
372 |
); |
|
373 |
} |
|
374 |
|
|
375 |
/** |
|
376 |
* faccio merge di tutti i valori in newValues in finalObj mantenendo invariata la struttura di finalObj |
|
377 |
* @param finalObj |
|
378 |
* @param newValues |
|
379 |
* @return {object} |
|
380 |
*/ |
|
381 |
function mergeObjects(finalObj, newValues) { |
|
382 |
let newProperties = newValues[Object.keys(newValues)[0]] |
|
383 |
|
|
384 |
$.each(newProperties, function (name, value) { |
|
385 |
findAndReplaceKeyInObj(finalObj, name, value) |
|
386 |
}) |
|
387 |
return finalObj |
|
388 |
} |
|
389 |
|
|
390 |
/** |
|
391 |
* prendo l' obj passato e cerco all' interno di esso una chiave key (a qualsiasi livello di indentazione) |
|
392 |
* se esiste la sostituisco con newValue |
|
393 |
* @param obj |
|
394 |
* @param key |
|
395 |
* @param newValue |
|
396 |
* @return {object} |
|
397 |
*/ |
|
398 |
function findAndReplaceKeyInObj(obj, key, newValue) { |
|
399 |
if (obj instanceof Object) { |
|
400 |
if (obj.hasOwnProperty(key)) { |
|
401 |
obj[key] = newValue; |
|
402 |
return; |
|
403 |
} |
|
404 |
for (let subKey in obj) { |
|
405 |
if (obj.hasOwnProperty(subKey) && obj[subKey] instanceof Object) { |
|
406 |
findAndReplaceKeyInObj(obj[subKey], key, newValue); |
|
407 |
} |
|
408 |
} |
|
409 |
} |
|
410 |
return obj |
|
411 |
} |
|
412 |
|
|
413 |
|
|
414 |
/** |
|
415 |
* group -> subEditFunction |
|
416 |
* prendo il valore del main e do alla subKey lo stesso valore |
|
417 |
*/ |
|
418 |
function copyMain() { |
|
419 |
return (subFields, obj) => { |
|
420 |
const mainName = subFields.inputName |
|
421 |
return obj[mainName] //main value |
|
422 |
} |
|
423 |
} |
|
424 |
|
|
425 |
/** |
|
426 |
* la lista di metodi aggiuntivi che se presenti in subFields.onChangeEditFields invocano delle funzioni secondarie |
|
427 |
* per il campo che è stato modificato |
|
428 |
* |
|
429 |
* ad esempio copyMain prende il valore del campo modificato e lo passa a tutti i subField |
|
430 |
* quindi nel caso di sim_1 quando viene cambiato il valore viene passato anche a MSISDN selectedBoID perché si trovano sotto il campo principale sim_1 con edit_type copyMain |
|
431 |
* @type {{copyMain: (function(*, *): *)}} |
|
432 |
*/ |
|
433 |
let subEditFunctions = { |
|
434 |
"copyMain": copyMain() |
|
435 |
} |
|
436 |
|
|
437 |
/** |
|
438 |
* se il campo principale ha delle funzioni onChangeEditFields chiamare le invoca |
|
439 |
* @param subFields |
|
440 |
* @param obj |
|
441 |
* @return {object} |
|
442 |
*/ |
|
443 |
function editSubFields(subFields, obj) { |
|
444 |
const subChanges = subFields.onChangeEditFields |
|
445 |
$.each(subChanges, function (subFieldName, subObj) { |
|
446 |
if (subObj.editType in subEditFunctions) { |
|
447 |
obj[subFieldName] = subEditFunctions[subObj.editType](subFields, obj) |
|
448 |
} |
|
449 |
}) |
|
450 |
return obj |
|
451 |
} |
|
452 |
|
|
453 |
/** |
|
454 |
* prendo un oggetto complesso e lo semplifico mettendo tutte le chiavi sullo stesso livello |
|
455 |
* @param objInputList |
|
456 |
* @param mainKey |
|
457 |
* @return {{object}} |
|
458 |
*/ |
|
459 |
function simplifyObj(objInputList, mainKey = null) { |
|
460 |
let newObj = {}; |
|
461 |
|
|
462 |
objInputList.forEach(function (objInput) { |
|
463 |
let editableField = editableFields.find(fields => fields.inputName === objInput.name); |
|
464 |
if (editableField) { |
|
465 |
newObj[objInput.name] = objInput.value; |
|
466 |
if (editableField.onChangeEditFields) { |
|
467 |
newObj = editSubFields(editableField, newObj) |
|
468 |
} |
|
469 |
} |
|
470 |
}) |
|
471 |
|
|
472 |
if (typeof mainKey == 'string') { |
|
473 |
return { |
|
474 |
[mainKey]: newObj |
|
475 |
} |
|
476 |
} |
|
477 |
|
|
478 |
return newObj; |
|
479 |
} |
|
480 |
|
|
481 |
/** |
|
482 |
* prendo i valori del vecchio oggetto xml li sostituisco con quelli nuovi e trasformo nuovamente l' obj xml in una stringa XML |
|
483 |
* @param oldObj |
|
484 |
* @param replacingValuesObj |
|
485 |
* @return {string} |
|
486 |
*/ |
|
487 |
function mergeAndConvertObjInXML(oldObj, replacingValuesObj) { |
|
488 |
const mainKey = Object.keys(oldObj)[0] |
|
489 |
let newObj = simplifyObj(replacingValuesObj, mainKey) |
|
490 |
|
|
491 |
let mergedObj = mergeObjects(oldObj, newObj) |
|
492 |
return $.json2xml(mergedObj) |
|
493 |
} |
|
494 |
|
|
495 |
/** |
|
496 |
* modifico l' editabiltà massiva di un oggetto in xmlMethods in base al valore della sua checkbox |
|
497 |
* se non è flaggata non modifico il metodo |
|
498 |
*/ |
|
499 |
function changeEditOption() { |
|
500 |
let input_name = $(this).attr('name') |
|
501 |
const isEditable = $(this).is(':checked') |
|
502 |
const methodName = input_name.split("is_editable_")[1] ?? "" |
|
503 |
|
|
504 |
if (xmlMethods[methodName]) { |
|
505 |
xmlMethods[methodName]["is_editable"] = isEditable; |
|
506 |
} |
|
507 |
} |
|
508 |
|
|
509 |
/** |
|
510 |
* setto i valori di default degli XML e li inserisco nelle rispettive textarea |
|
511 |
* se methodName === null arriva da un input event quindi prendo dinamicamente il nome del metodo a cui settare default XML |
|
512 |
* @param methodName |
|
513 |
*/ |
|
514 |
function setDefaultXML(methodName = null) { |
|
515 |
if (typeof methodName !== 'string') { // il caso in cui venga chiamato da un evento |
|
516 |
let btn_id = $(this).attr('id') |
|
517 |
methodName = btn_id.split("set_default_xml_")[1] ?? "" |
|
518 |
} |
|
519 |
|
|
520 |
if (xmlMethods[methodName]) { |
|
521 |
xmlMethods[methodName]["actualXML"] = xmlMethods[methodName]["defaultXML"] |
|
522 |
const formattedXML = vkbeautify.xml(xmlMethods[methodName]["actualXML"]) |
|
523 |
$(`textarea#${methodName}`).val(formattedXML.trim()) |
|
524 |
|
|
525 |
let errorBox = $('#' + methodName + '_errorBox'); |
|
526 |
errorBox.empty() |
|
527 |
} |
|
528 |
} |
|
529 |
|
|
530 |
/** |
|
531 |
* abilita e disabilita il singolo input per la modifica massiva |
|
532 |
* se la checkbox è flaggata il campo non verrà modificato |
|
533 |
*/ |
|
534 |
function shouldReplaceOption() { |
|
535 |
let checkbox_name = $(this).attr('name') |
|
536 |
let checkbox_value = $(this).is(':checked') |
|
537 |
const input_name = checkbox_name.split("shouldReplace_")[1] ?? "" |
|
538 |
|
|
539 |
if (checkbox_value) { |
|
540 |
$(`input[name="${input_name}"]`).prop('disabled', true); |
|
541 |
} else { |
|
542 |
$(`input[name="${input_name}"]`).removeAttr('disabled'); |
|
543 |
} |
|
544 |
} |
|
545 |
|
|
546 |
/** |
|
547 |
* verifico la validità di un valore XML nella textarea che invoca l' evento |
|
548 |
*/ |
|
549 |
function validateTextarea() { |
|
550 |
const xml = $(this).val() |
|
551 |
const methodName = $(this).attr('id') |
|
552 |
let errorBox = $('#' + methodName + '_errorBox'); |
|
553 |
errorBox.empty() |
|
554 |
if ((typeof xml === 'string') && (xml.trim() !== '')) { |
|
555 |
let isValid = $.isXmlValid(xml); |
|
556 |
if (isValid !== true) { |
|
557 |
showError(errorBox, "errore nella validazione dell' xml " + isValid) |
|
558 |
} |
|
559 |
} |
|
560 |
} |
|
561 |
|
|
562 |
/** |
|
563 |
* trasformo un oggetto JS in una stringa con sintassi array PHP |
|
564 |
* @param profileObj |
|
565 |
* @return {string} |
|
566 |
*/ |
|
567 |
function buildArrayPHP(profileObj) { |
|
568 |
const newJSON = JSON.stringify(profileObj) |
|
569 |
const prettyJson = vkbeautify.json(newJSON) |
|
570 |
let arrayPHP = prettyJson.replaceAll("{", "[") |
|
571 |
arrayPHP = arrayPHP.replaceAll("}", "]") |
|
572 |
arrayPHP = arrayPHP.replaceAll(":", "=>") |
|
573 |
return '"n" => ' + arrayPHP |
|
574 |
} |
|
575 |
|
|
576 |
/** |
|
577 |
* partendo dall' oggetto profileObj sostituisco i valori dentro parametri[param] inserendo chiavi valore corrette |
|
578 |
* chiave -> (sim_*) | valore -> (sim_*_method_name["actual"]) |
|
579 |
* @param profileObj |
|
580 |
* @param method_name |
|
581 |
* @param param_key |
|
582 |
* @return {*} |
|
583 |
*/ |
|
584 |
function set_dynamic_keys_for_profile_method(profileObj, method_name, param_key) { |
|
585 |
|
|
586 |
profileObj["sso"][method_name]["parametri"][param_key] = {} |
|
587 |
|
|
588 |
const sso_method_name = `sso_${method_name}` |
|
589 |
const main_phone_number = $(`input[name="sim_1"]`).val() |
|
590 |
const XML_sim_1 = xmlMethods[sso_method_name]["actualXML"]; |
|
591 |
let encodingValue = $.parseXML(XML_sim_1)["xmlEncoding"] ?? null; |
|
592 |
const xmlHead = `<?xml version="1.0" encoding="${encodingValue}"?>`; |
|
593 |
|
|
594 |
profileObj["sso"][method_name]["parametri"][param_key][main_phone_number] = XML_sim_1 |
|
595 |
|
|
596 |
let sim_length = $('input[name="n_sim"]').val() |
|
597 |
for (let index = 2; index <= sim_length; index++) { |
|
598 |
let sim_code = 'sim_' + index |
|
599 |
let phone_number = $(`input[name="${sim_code}"]`).val() |
|
600 |
|
|
601 |
let new_method_name = sim_code + "_" + sso_method_name |
|
602 |
profileObj["sso"][method_name]["parametri"][param_key][phone_number] = xmlHead + xmlMethods[new_method_name]["actualXML"] |
|
603 |
} |
|
604 |
|
|
605 |
return profileObj |
|
606 |
} |
|
607 |
|
|
608 |
/** |
|
609 |
* costruisco e mostro l' array (formato PHP) in pagina |
|
610 |
*/ |
|
611 |
function showResult() { |
|
612 |
let profileObj = { |
|
613 |
"name": $('input[name="profile_user_name"]').val() ?? "inserire un nome utente", |
|
614 |
"sso": { |
|
615 |
"getWebcustomerInformation": |
|
616 |
{ |
|
617 |
"parametri": { |
ca6434
|
618 |
"k": |
d2a29b
|
619 |
{ |
ca6434
|
620 |
"123456789": xmlMethods.sso_getWebcustomerInformation.actualXML |
d2a29b
|
621 |
} |
DC |
622 |
} |
|
623 |
} |
|
624 |
, |
|
625 |
"getMSISDNDetails": |
|
626 |
{ |
|
627 |
"parametri": { |
ca6434
|
628 |
"k": |
d2a29b
|
629 |
{ |
ca6434
|
630 |
"123456789": xmlMethods.sso_getMSISDNDetails.actualXML |
d2a29b
|
631 |
} |
DC |
632 |
} |
|
633 |
} |
|
634 |
, |
|
635 |
"getMSISDNList": |
|
636 |
{ |
|
637 |
"parametri": { |
ca6434
|
638 |
"k": |
d2a29b
|
639 |
{ |
ca6434
|
640 |
"123456789": xmlMethods.sso_getMSISDNList.actualXML |
d2a29b
|
641 |
} |
DC |
642 |
} |
|
643 |
} |
|
644 |
, |
|
645 |
"getSelectedMSISDNDetails": |
|
646 |
{ |
|
647 |
"parametri": { |
ca6434
|
648 |
"k": |
d2a29b
|
649 |
{ |
ca6434
|
650 |
"123456789": '<?xml version="1.0" encoding="iso-8859-1"?><getMDISDNDetails><CardType>Ric</CardType><SimSeniorityDate>15/02/2020</SimSeniorityDate><VodafoneOne>false</VodafoneOne><TopClub>false</TopClub><IdPiano>2491</IdPiano><SeniorityCluster></SeniorityCluster></getMDISDNDetails>' |
d2a29b
|
651 |
}, |
DC |
652 |
"ms": |
|
653 |
{ |
|
654 |
'3464232371': '',//deve essere gestito con un foreach |
|
655 |
'3464232372': ''//deve essere gestito con un foreach |
|
656 |
} |
|
657 |
} |
|
658 |
} |
|
659 |
, |
|
660 |
"getInfoActivationWSC": |
|
661 |
{ |
|
662 |
"parametri": { |
ca6434
|
663 |
"k": |
d2a29b
|
664 |
{ |
ca6434
|
665 |
"123456789": '<?xml version="1.0" encoding="iso-8859-1"?><getInfoActivationWSC><catalog><channel>SSO</channel><providerID></providerID><appidID></appidID><selectedBoId>3464232371</selectedBoId><selectedBoType>SIM_MOBILE</selectedBoType><username>FAKE_SSO_1</username><readOnlyCondition></readOnlyCondition><showcase><showcaseId>27</showcaseId><showcaseDescription>Vetrina Elite</showcaseDescription><tabs><tabPosition>1</tabPosition><tabDescription>new Corporate Infoattivazione Showcase</tabDescription><tabId>17</tabId><sections><collapsed>N</collapsed><sectionPosition>20</sectionPosition><sectionDescription>Tutti gli altri servizi</sectionDescription><sectionId>112</sectionId><products><productId>2583</productId><activationDate><time>1702249200000</time></activationDate><changeStateDate><time>1702249200000</time></changeStateDate><inheritanceRule></inheritanceRule><buyCost>0.0</buyCost><frequency></frequency><infoRecurringFees>N</infoRecurringFees><invertStatus>N</invertStatus><maxNumOfTry>0</maxNumOfTry><monopoliFlag>N</monopoliFlag><longDescription>Abilita la SIM alla distinzione del traffico personale da quello aziendale</longDescription><longName>Autorizzazione Dual</longName><productPosition>1</productPosition><numberOfUsedTry>0</numberOfUsedTry><numberOfTryAvailable>0</numberOfTryAvailable><OMProductId>2156</OMProductId><OMSource>CCBS</OMSource><productType>Service</productType><shortDescription>Abilita la SIM alla distinzione del traffico personale da quello aziendale</shortDescription><shortName>Autorizzazione Dual</shortName><productStateOnSim>ACTIVE</productStateOnSim><spyderId></spyderId><flagCommitment></flagCommitment><mm4MPromoId></mm4MPromoId><idJoin></idJoin><lastPaidFlag></lastPaidFlag><offerType></offerType><lastChargeZeroReason></lastChargeZeroReason></products><products><productId>3823</productId><activationDate><time>1702854000000</time></activationDate><changeStateDate><time>1702854000000</time></changeStateDate><inheritanceRule></inheritanceRule><buyCost>0.0</buyCost><frequency></frequency><infoRecurringFees>N</infoRecurringFees><invertStatus>N</invertStatus><maxNumOfTry>0</maxNumOfTry><monopoliFlag>N</monopoliFlag><longDescription></longDescription><longName>TM9 Smart Passport Extra Europa 1 Rinnovo Ricaricabile</longName><productPosition>1</productPosition><numberOfUsedTry>0</numberOfUsedTry><numberOfTryAvailable>0</numberOfTryAvailable><OMProductId>14644</OMProductId><OMSource>CCBS</OMSource><productType>Service</productType><shortDescription></shortDescription><shortName>TM9 Smart Passport Extra Europa 1 Rinnovo Ricaricabile</shortName><productStateOnSim>ACTIVE</productStateOnSim><spyderId></spyderId><flagCommitment></flagCommitment><mm4MPromoId></mm4MPromoId><idJoin></idJoin><lastPaidFlag></lastPaidFlag><offerType></offerType><lastChargeZeroReason></lastChargeZeroReason></products><____hashCodeCalc>false</____hashCodeCalc></sections><____hashCodeCalc>false</____hashCodeCalc></tabs><____hashCodeCalc>false</____hashCodeCalc></showcase><tmProduct><tmCode>2491</tmCode><description>TM9 Ricaricabile P30</description><activationDate><time>1696244062000</time></activationDate><____hashCodeCalc>false</____hashCodeCalc></tmProduct><convergentOffer><rewardID></rewardID><groupTypeID></groupTypeID><hungReasonID></hungReasonID><cli></cli><status></status></convergentOffer></catalog><operationStatus><status>OK</status><errCode>0</errCode><diagnostic>SUCCESS</diagnostic><____hashCodeCalc>false</____hashCodeCalc></operationStatus></getInfoActivationWSC>' |
d2a29b
|
666 |
}, |
DC |
667 |
"boID": |
|
668 |
{ |
|
669 |
'3464232371': '',//deve essere gestito con un foreach |
|
670 |
'3464232372': ''//deve essere gestito con un foreach |
|
671 |
} |
|
672 |
} |
|
673 |
} |
|
674 |
}, |
|
675 |
"picasso": { |
|
676 |
"getWebcustomerInformation": { |
|
677 |
"parametri": { |
ca6434
|
678 |
"k": { |
D |
679 |
"123456789": xmlMethods.picasso_getWebcustomerInformation.actualXML |
d2a29b
|
680 |
} |
DC |
681 |
} |
|
682 |
} |
|
683 |
} |
|
684 |
} |
|
685 |
|
|
686 |
|
|
687 |
profileObj = set_dynamic_keys_for_profile_method(profileObj, "getSelectedMSISDNDetails", "ms") |
|
688 |
profileObj = set_dynamic_keys_for_profile_method(profileObj, "getInfoActivationWSC", "boID") |
|
689 |
const arrayPHP = buildArrayPHP(profileObj); |
|
690 |
|
|
691 |
$('#final_result pre').text(arrayPHP); |
|
692 |
$("html, body").animate({scrollTop: $(document).height()}, "slow"); |
|
693 |
$('#final_result').show(); |
|
694 |
} |
|
695 |
|
|
696 |
function copyToClipboard() { |
|
697 |
let textToCopy = $("#final_result_text").text(); |
|
698 |
let tempInput = $("<textarea>"); |
|
699 |
$("body").append(tempInput); |
|
700 |
tempInput.val(textToCopy).select(); |
|
701 |
document.execCommand("copy"); |
|
702 |
tempInput.remove(); |
ca6434
|
703 |
} |