comparison src/add-one-spectrum-index.js @ 1:7e3085fc60c1 draft default tip

master branch Updating
author lain
date Wed, 30 Aug 2023 14:21:18 +0000
parents
children
comparison
equal deleted inserted replaced
0:b58b229c4cbf 1:7e3085fc60c1
1
2 var token = "{{ PF_TOKEN_PLACEHOLDER }}" ;
3 if ({{ TAB_INDEX_PLACEHOLDER }} == 1) {
4 }
5
6 context_{{ TAB_INDEX_PLACEHOLDER }} = {
7 prefix: "#accordion-{{ TAB_INDEX_PLACEHOLDER }} ",
8 name: "Context[{{ TAB_INDEX_PLACEHOLDER }}]",
9 produce_json: {{ PRODUCE_JSON_PLACEHOLDER }},
10 DEFAULT_MS_PEAK_VALUES: {{ MS_PEAK_VALUES_PLACEHOLDER }},
11 DEFAULT_DATA: {{ DEFAULT_DATA }},
12 peakforest_url: "{{ PF_URL_PLACEHOLDER }}",
13 tab_index: "{{ TAB_INDEX_PLACEHOLDER }}",
14 modeEditSpectrum: false,
15 isSeparationFlowRateInit: false,
16 isMSpeaksInit: false,
17 isLC: false,
18 isGC: false,
19 isIC: false,
20 hot_LC_SFG: null ,
21 hot_MS_Peaks: null,
22 hot_RCC_ADDED: null,
23 jsonSpectrumType: null,
24 isJsonSpectrumTypeComplete: false,
25 jsonSample: null,
26 isJsonSampleComplete: false,
27 isJsonRCCaddedComplete: false,
28 jsonChromato: null,
29 isJsonChromatoComplete: false,
30 jsonAnalyzer: null,
31 isJsonAnalyzerComplete: false,
32 jsonPeaksList: [],
33 isJsonPeaksListComplete: false,
34 jsonOtherMetadata: null,
35 isJsonOtherMetadataComplete: false,
36 jsonMolIonization: null,
37 jsonMolIonBeam: null,
38 cptPeakListTab: 0,
39 jsonAnalyzerAcquisition: [],
40 idMetadataMap: {},
41 listOfViewableSpectra: [],
42 singlePick: true,
43 multiPickLine: -1,
44 subjects: [],
45 fitlerSearchLoadlCpd: 5,
46 inchikey: null,
47 initialized: false,
48 selected_ion_index: null,
49 lock: {
50 precursor_ion: false
51 },
52
53 sent_json: null,
54
55 init: function() {
56
57 var self = this ;
58
59 $(document).ready(() => self.on_ready());
60 $(document).ready(function() {
61 console.log("adding click on open_tab_{{ TAB_INDEX_PLACEHOLDER }}.") ;
62 var activate_tab = function() {
63 if (self.initialized) {
64 return ;
65 }
66 self.auto_set_spec_type() ;
67 }
68 if (self.is_ref()) {
69 $("#open_tab_{{ TAB_INDEX_PLACEHOLDER }}").click(activate_tab) ;
70 }
71 if ({{ TAB_INDEX_PLACEHOLDER }} == 1) {
72 activate_tab() ;
73 }
74 }) ;
75
76 return (self) ;
77
78 },
79
80 on_ready: function() {
81 var self = this ;
82
83 $(self.prefix+".pickChemicalCompound").click(self.pickChemicalCompound);
84 $(self.prefix+".add1spectrum").change(
85 function(){self.add1spectrum_change_handler(this)}
86 )
87 self.attach_search() ;
88 self.add_date_check() ;
89 self.populate_selects() ;
90 self.add_change_handlers() ;
91 self.show_hide_ms_ms2_fields() ;
92 },
93
94 populate_selects: function() {
95 var self = this ;
96 var choose_in_list ;
97
98 choose_in_list = `
99 <option value="" selected="selected" disabled="disabled">
100 choose in list&hellip;
101 </option>
102 ` ;
103 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").append(choose_in_list) ;
104 $("#add1spectrum-chromatoLC-colConstructor-{{ TAB_INDEX_PLACEHOLDER }}").append(choose_in_list) ;
105 $("#add1spectrum-chromatoLC-separationSolvA-{{ TAB_INDEX_PLACEHOLDER }}").append(choose_in_list) ;
106 $("#add1spectrum-chromatoLC-separationSolvB-{{ TAB_INDEX_PLACEHOLDER }}").append(choose_in_list) ;
107 $("#add1spectrum-sample-lcmsSolvent-{{ TAB_INDEX_PLACEHOLDER }}").append(choose_in_list) ;
108 $.getJSON("{{ PF_URL_PLACEHOLDER }}/webapp/resources/json/list-lc-methods.json", self.populate_lc_methods) ;
109 $.getJSON("{{ PF_URL_PLACEHOLDER }}/webapp/resources/json/list-lc-columns.json", self.populate_lc_columns) ;
110 $.getJSON("{{ PF_URL_PLACEHOLDER }}/webapp/resources/json/list-lc-solvents.json", self.populate_lc_solvents) ;
111 $.getJSON("{{ PF_URL_PLACEHOLDER }}/webapp/resources/json/list-ms-ionization-methods.json", self.populate_ms_ionization) ;
112 $.getJSON("{{ PF_URL_PLACEHOLDER }}/webapp/resources/json/list-lcms-solvents.json", self.populate_lcms_solvents) ;
113 self.resetFromColors();
114 },
115
116 attach_search: function() {
117 var self = this ;
118
119 $("#add-one-cc-s1-value-{{ TAB_INDEX_PLACEHOLDER }}").bind("keypress", function(e) {
120 var code = e.keyCode || e.which;
121 if (code == 13) {
122 self.searchLocalCompound();
123 }
124 });
125 $("#add-one-cc-s1-value-{{ TAB_INDEX_PLACEHOLDER }}").typeahead({
126 source: function(query, process) {
127 return self.searchAjax();
128 }
129 });
130 },
131
132 add_date_check: function() {
133 var self = this ;
134
135 $("#add1spectrum-other-date-{{ TAB_INDEX_PLACEHOLDER }}").focusout(function() {
136 var element = $(this) ;
137 self.rm_warning(element);
138 self.rm_success(element) ;
139 if (element.val() == "") {
140 element.parent().addClass("has-warning");
141 } else {
142 element.parent().addClass("has-success");
143 }
144 });
145 },
146
147 populate_lc_methods: function(data) {
148 // load data from json
149 $.each(data.methods,function() {
150 if (this.name !== undefined) {
151 if (this.value !== undefined) {
152 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").append(
153 `<option value="${this.value}">${this.name}</option>`
154 );
155 } else {
156 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").append(
157 `<option disabled>${this.name}</option>`
158 );
159 }
160 }
161 });
162 },
163
164 populate_lc_columns: function(data) {
165 // load data from json
166 $.each(data.columns, function() {
167 $("#add1spectrum-chromatoLC-colConstructor-{{ TAB_INDEX_PLACEHOLDER }}").append(
168 `<option value="${this.value}">${this.name}</option>`
169 );
170 });
171 $("#add1spectrum-chromatoLC-colConstructor-{{ TAB_INDEX_PLACEHOLDER }}").append(
172 '<option value="other" >Other</option>'
173 );
174 },
175
176 populate_lc_solvents: function(data) {
177 // load data from json
178 $.each(data.solvents, function() {
179 $("#add1spectrum-chromatoLC-separationSolvA-{{ TAB_INDEX_PLACEHOLDER }}").append(
180 `<option value="${this.value}">${this.name}</option>`
181 );
182 $("#add1spectrum-chromatoLC-separationSolvB-{{ TAB_INDEX_PLACEHOLDER }}").append(
183 `<option value="${this.value}">${this.name}</option>`
184 );
185 });
186 },
187
188 populate_ms_ionization: function(data) {
189 // load data from json
190 $.each(data.methods,function() {
191 if (this.name !==undefined) {
192 if (this.value !==undefined) {
193 $("#add1spectrum-analyzserMS-ionizationMethod-pos-{{ TAB_INDEX_PLACEHOLDER }}").append(
194 `<option value="${this.value}">${this.name}</option>`
195 );
196 $("#add1spectrum-analyzserMS-ionizationMethod-neg-{{ TAB_INDEX_PLACEHOLDER }}").append(
197 `<option value="${this.value}">${this.name}</option>`
198 );
199 } else {
200 $("#add1spectrum-analyzserMS-ionizationMethod-pos-{{ TAB_INDEX_PLACEHOLDER }}").append(
201 `<option disabled>${this.name}</option>`
202 );
203 $("#add1spectrum-analyzserMS-ionizationMethod-neg-{{ TAB_INDEX_PLACEHOLDER }}").append(
204 `<option disabled>${this.name}</option>`
205 );
206 }
207 }
208 });
209 },
210
211 populate_lcms_solvents: function(data) {
212 // load data from json
213 $.each(data.solvents, function () {
214 $("#add1spectrum-sample-lcmsSolvent-{{ TAB_INDEX_PLACEHOLDER }}").append(
215 `<option value="${this.value}" class="${this.classD}">${this.name}</option>`
216 );
217 });
218 },
219
220 add_change_handlers: function() {
221 var self = this ;
222
223 $("#add1spectrum-ionTrapBeam-type-{{ TAB_INDEX_PLACEHOLDER }}").on("change", function() {
224 var v = $("#add1spectrum-ionTrapBeam-type-{{ TAB_INDEX_PLACEHOLDER }}").val();
225 $(self.prefix + ".add1spectrum-ionTrap").hide();
226 if (v == "beam") {
227 } else if (v == "trap") {
228 $(self.prefix + ".add1spectrum-ionTrap").show();
229 }
230 }) ;
231 },
232
233 show_hide_ms_ms2_fields: function() {
234 var self = this ;
235 $(self.prefix + " .disabled-if-ms").attr("disabled", self.is_ms())
236 $(self.prefix + " .disabled-if-msms").attr("disabled", self.is_ms2())
237 $(self.prefix + " .disabled-if-ms2").attr("disabled", self.is_ms2())
238 if (self.is_ms()) {
239 self.hide(self.prefix + " .hidden-if-ms") ;
240 }
241 if (self.is_ms2()) {
242 self.hide(self.prefix + " .hidden-if-msms") ;
243 self.hide(self.prefix + " .hidden-if-ms2") ;
244 }
245 },
246
247 is_mix: function() {
248 return this.DEFAULT_DATA["sample_type"] == "compound-mix" ;
249 },
250
251 is_ref: function() {
252 return this.DEFAULT_DATA["sample_type"] == "compound-ref" ;
253 },
254
255 is_ms: function() {
256 return this.DEFAULT_DATA["spectrum_type"] == "LC_MS" ;
257 },
258
259 is_ms2: function() {
260 return this.DEFAULT_DATA["spectrum_type"] == "LC_MSMS" ;
261 },
262
263 is_other_in_mix() {
264 return this.is_mix() && {{ TAB_INDEX_PLACEHOLDER }} > 1 ;
265 },
266
267 hide: function(id) {
268 if (typeof id == Array) {
269 return (id.forEach(hide)) ;
270 }
271 $(id).hide()
272 },
273
274 rm_success: function(element) {
275 return (this.rm_parent_class(element, "has-success"))
276 },
277 rm_error: function(element) {
278 return (this.rm_parent_class(element, "has-error"))
279 },
280 rm_warning: function(element) {
281 return (this.rm_parent_class(element, "has-warning"))
282 },
283 set_success: function(element) {
284 return (this.set_parent_class(element, "has-success"))
285 },
286 set_error: function(element) {
287 return (this.set_parent_class(element, "has-error"))
288 },
289 set_warning: function(element) {
290 return (this.set_parent_class(element, "has-warning"))
291 },
292 rm_parent_class: function(element, cls) {
293 var parent ;
294
295 if ((parent = element.parent()) == null) {
296 return false ;
297 }
298 return this.rm_class(parent, cls) ;
299 },
300 set_parent_class: function(element, cls) {
301 var parent ;
302
303 if ((parent = element.parent()) == null) {
304 return false ;
305 }
306 return this.set_class(parent, cls) ;
307 },
308 rm_class: function(element, cls) {
309 if (element.hasClass(cls)) {
310 element.removeClass(cls) ;
311 return true ;
312 }
313 return false ;
314 },
315 set_class: function(element, cls) {
316 if (element.hasClass(cls)) {
317 return false ;
318 }
319 element.addClass(cls) ;
320 return true ;
321 },
322 is_success: function(element) {
323 return (this.parent_has_class(element, "has-success"))
324 },
325 is_warning: function(element) {
326 return (this.parent_has_class(element, "has-warning"))
327 },
328 is_error: function(element) {
329 return (this.parent_has_class(element, "has-error"))
330 },
331 is_optional: function(element) {
332 return (element.hasClass("is-optional"))
333 },
334 is_mandatory: function(element) {
335 return (element.hasClass("is-mandatory"))
336 },
337 parent_has_class: function(element, cls) {
338 var parent ;
339
340 if ((parent = element.parent()) == null) {
341 return false ;
342 }
343 return (parent.hasClass(cls)) ;
344 },
345
346 add1spectrum_change_handler: function(element) {
347 var self = this ;
348 var idElem ;
349 var valElem ;
350 var isSuccess ;
351 var isWarning ;
352 var isError ;
353 var isOptional ;
354 var isMandatory ;
355
356 element = $(element) ;
357 idElem = element.attr("id") ;
358 valElem = element.val();
359 console.log(`Change handler called for [${idElem}]=${valElem}`) ;
360 if (idElem.split("-").slice(0, -1).join("-") == "add1spectrum-peaksMS-msPrecursorIon") {
361 var index = idElem.split("-")[3] - 1 ;
362 if (all_contexts[index] !== null && all_contexts[index] !== undefined) {
363 all_contexts[index].sync_precursor_ion() ;
364 if (all_contexts[index].hot_MS_Peaks != null) {
365 all_contexts[index].hot_MS_Peaks.render()
366 }
367 }
368 }
369 isSuccess = self.is_success(element);
370 isWarning = self.is_warning(element);
371 isError = self.is_error(element);
372 isOptional = self.is_optional(element);
373 isMandatory = self.is_mandatory(element);
374
375 switch(idElem) {
376 case "add1spectrum-sample-type-{{ TAB_INDEX_PLACEHOLDER }}":
377 if (valElem == "compound-ref") {
378 $("#add1spectrum-sample-type-compound-ref-{{ TAB_INDEX_PLACEHOLDER }}").show();
379 $("#add1spectrum-sample-type-compound-mix-{{ TAB_INDEX_PLACEHOLDER }}").hide();
380 $("#add1spectrum-sample-type-rcc-added-{{ TAB_INDEX_PLACEHOLDER }}").hide();
381 } else if (valElem == "compound-mix") {
382 $("#add1spectrum-sample-type-compound-mix-{{ TAB_INDEX_PLACEHOLDER }}").show();
383 $("#add1spectrum-sample-type-compound-ref-{{ TAB_INDEX_PLACEHOLDER }}").hide();
384 $("#add1spectrum-sample-type-rcc-added-{{ TAB_INDEX_PLACEHOLDER }}").show();
385 self.handsontableRefChemCpdAdded(null);
386 }
387 break;
388 case "add1spectrum-chromatoLC-colConstructor-{{ TAB_INDEX_PLACEHOLDER }}":
389 self.resetElemColor("add1spectrum-chromatoLC-colConstructorOther-{{ TAB_INDEX_PLACEHOLDER }}");
390 if (valElem == "" || valElem == null || valElem != "other" ) {
391 self.disableElem("add1spectrum-chromatoLC-colConstructorOther-{{ TAB_INDEX_PLACEHOLDER }}");
392 } else {
393 self.enableElem("add1spectrum-chromatoLC-colConstructorOther-{{ TAB_INDEX_PLACEHOLDER }}");
394 }
395 break;
396 case "add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}":
397 self.fulfillLCdata(valElem);
398 break;
399 case "add1spectrum-analyzserMS-ionizationMethod-pos-{{ TAB_INDEX_PLACEHOLDER }}":
400 if ($("#add1spectrum-analyzserMS-ionizationMethod-pos-{{ TAB_INDEX_PLACEHOLDER }}").val() != null) {
401 $($("#add1spectrum-peaksMS-polarity-{{ TAB_INDEX_PLACEHOLDER }} option")[1]).attr("disabled", false);
402 }
403 break;
404 case "add1spectrum-analyzserMS-ionizationMethod-neg-{{ TAB_INDEX_PLACEHOLDER }}":
405 if ($("#add1spectrum-analyzserMS-ionizationMethod-neg-{{ TAB_INDEX_PLACEHOLDER }}").val() != null) {
406 $($("#add1spectrum-peaksMS-polarity-{{ TAB_INDEX_PLACEHOLDER }} option")[2]).attr("disabled", false);
407 }
408 break;
409 }
410 if ((isMandatory || isOptional) && (valElem == "" || valElem == null)) {
411 if (isSuccess) {
412 self.rm_success(element) ;
413 } else if (isWarning) {
414 self.rm_warning(element) ;
415 } else if (isError) {
416 self.rm_error(element) ;
417 }
418 if (isMandatory) {
419 self.set_error(element) ;
420 } else {
421 self.set_warning(element) ;
422 }
423 }
424 if (isMandatory && (valElem != "" && valElem != null)) {
425 if (isError) {
426 self.rm_error(element) ;
427 }
428 self.set_success(element) ;
429 } else if (isOptional && valElem != "") {
430 if (isWarning) {
431 self.rm_warning(element) ;
432 }
433 self.set_success(element) ;
434 }
435 if (element.parent().children("input").size() == 2) {
436 if (isMandatory) {
437 if (isSuccess) {
438 self.rm_success(element) ;
439 } else if (isWarning) {
440 self.rm_warning(element) ;
441 } else if (isError) {
442 self.rm_error(element) ;
443 }
444 if (element.parent().children("input").toArray().some(
445 (el) => $(el).val() === null || $(el).val() === ""
446 )) {
447 self.set_error(element) ;
448 } else {
449 self.set_success(element) ;
450 }
451 } else if (isOptional) {
452 isSuccess = self.is_success(element);
453 isWarning = self.is_warning(element);
454 isError = self.is_error(element);
455 if (isSuccess) {
456 self.rm_success(element)
457 } else if (isWarning) {
458 self.rm_warning(element) ;
459 } else if (isError) {
460 self.rm_error(element) ;
461 }
462 if (element.parent().children("input").toArray().some(
463 (el) => ($(el).val() == null || $(el).val() == "")
464 )) {
465 self.set_warning(element) ;
466 } else {
467 self.set_success(element) ;
468 }
469 }
470 }
471 if (element.hasClass("one-or-more")) {
472 // get parent class
473 isSuccess = self.is_success(element);
474 isWarning = self.is_warning(element);
475 isError = self.is_error(element);
476 // reset class
477 if (isSuccess) {
478 self.rm_success(element) ;
479 } else if (isWarning) {
480 self.rm_warning(element) ;
481 } else if (isError) {
482 self.rm_error(element) ;
483 }
484 isTmpSuccess = false;
485 $.each(element.parent().children("input"), function(id, child){
486 if ($(child).val() != null && $(child).val() != "") {
487 isTmpSuccess = true;
488 }
489 });
490 $.each(element.parent().children("select"), function(id, child){
491 if ($(child).val() != null && $(child).val() != "") {
492 isTmpSuccess = true;
493 }
494 });
495 // end parkour
496 element.parent().addClass(
497 isTmpSuccess ? "has-success" : "has-error"
498 );
499 }
500 // CHECK IF OK STEP 2
501 if (element.hasClass("add1spectrum-sampleForm")) {
502 var isBtnStep2OK = true;
503 $.each($(self.prefix + ".add1spectrum-sampleForm"), (id, elem) => {
504 if (self.is_error($(elem)) && $(elem).is(":visible")) {
505 isBtnStep2OK = false;
506 }
507 });
508 if (isBtnStep2OK) {
509 self.rm_class($("#btnSwitch-gotoStep2-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-disabled") ;
510 self.set_class($("#btnSwitch-gotoStep2-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-primary") ;
511 $("#btnSwitch-gotoStep2-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
512 } else {
513 self.set_class($("#btnSwitch-gotoStep2-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-disabled") ;
514 self.rm_class($("#btnSwitch-gotoStep2-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-primary") ;
515 $("#btnSwitch-gotoStep2-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", true);
516 }
517 }
518 // CHECK IF OK STEP 3 - LC
519 if (
520 element.hasClass("add1spectrum-chromatoLCForm")
521 && $("#btnSwitch-gotoStep3-lc-{{ TAB_INDEX_PLACEHOLDER }}").is(":visible")
522 ) {
523 var isBtnStep3OK = true;
524 $.each($(self.prefix+".add1spectrum-chromatoLCForm"), (id, elem) => {
525 if (self.is_error($(elem)) && $(elem).is(":visible"))
526 isBtnStep3OK = false;
527 });
528 if (isBtnStep3OK) {
529 self.rm_class($("#btnSwitch-gotoStep3-lc-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-disabled") ;
530 self.set_class($("#btnSwitch-gotoStep3-lc-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-primary") ;
531 $("#btnSwitch-gotoStep3-lc-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
532 } else {
533 self.set_class($("#btnSwitch-gotoStep3-lc-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-disabled") ;
534 self.rm_class($("#btnSwitch-gotoStep3-lc-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-primary") ;
535 $("#btnSwitch-gotoStep3-lc-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", true);
536 }
537 }
538 // TODO CHECK IF OK STEP 3 - GC
539 // CHECK IF OK STEP 4 - MS ANALYZER
540 if (
541 element.hasClass("add1spectrum-analyzerMSForm")
542 && $("#btnSwitch-gotoStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}").is(":visible")
543 ) {
544 var isBtnStep4OK = true;
545 $.each($(self.prefix+".add1spectrum-analyzerMSForm"), (id, elem) => {
546 if (self.is_error($(elem)) && $(elem).is(":visible"))
547 isBtnStep4OK = false;
548 });
549 if (isBtnStep4OK) {
550 self.rm_class($("#btnSwitch-gotoStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-disabled") ;
551 self.set_class($("#btnSwitch-gotoStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-primary") ;
552 $("#btnSwitch-gotoStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
553 } else {
554 self.set_class($("#btnSwitch-gotoStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-disabled") ;
555 self.rm_class($("#btnSwitch-gotoStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-primary") ;
556 $("#btnSwitch-gotoStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", true);
557 }
558 }
559 // CHECK IF OK STEP 5 - PEAKS
560 if (
561 element.hasClass("add1spectrum-peaksMSForm-peaklist")
562 && $("#btnSwitch-gotoStep5-ms-{{ TAB_INDEX_PLACEHOLDER }}").is(":visible")
563 ) {
564 var isBtnStep5OK = true;
565 $.each($(self.prefix+".add1spectrum-peaksMSForm-peaklist"), (id, elem) => {
566 if (self.is_error($(elem)) && $(elem).is(":visible"))
567 isBtnStep5OK = false;
568 });
569 if (isBtnStep5OK && (self.is_ms() || self.a_ion_parent_is_selected())) {
570 self.rm_class($("#btnSwitch-gotoStep5-ms-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-disabled") ;
571 self.set_class($("#btnSwitch-gotoStep5-ms-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-primary") ;
572 $("#btnSwitch-gotoStep5-ms-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
573 } else {
574 self.set_class($("#btnSwitch-gotoStep5-ms-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-disabled") ;
575 self.rm_class($("#btnSwitch-gotoStep5-ms-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-primary") ;
576 $("#btnSwitch-gotoStep5-ms-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", true);
577 }
578 }
579 // CHECK IF OK STEP 6 - OTHER DATA
580 if (
581 element.hasClass("add1spectrum-otherForm")
582 && $("#btnSwitch-gotoStep6-{{ TAB_INDEX_PLACEHOLDER }}").is(":visible")
583 ) {
584 self.checkIfEnableSubmit() ;
585 }
586 },
587
588 a_ion_parent_is_selected: function() {
589 return (this.get_selected_parent_ion_mz() !== null) ;
590 },
591
592 get_selected_parent_ion_index: function() {
593 var curent_mz = this.get_selected_parent_ion_mz() ;
594 if (curent_mz === null) {
595 return null;
596 }
597 if (this.hot_MS_Peaks == undefined) {
598 return null ;
599 }
600 var data = this.hot_MS_Peaks.getData() ;
601 for (var i = 0 ; i < data.length ; i += 1) {
602 if (Math.abs(data[i][0] - curent_mz) < 0.0001) {
603 return i ;
604 }
605 }
606 return null ;
607 },
608
609 get_selected_parent_ion_mz: function() {
610 return $(
611 "#add1spectrum-peaksMS-msPrecursorIon-{{ TAB_INDEX_PLACEHOLDER }}"
612 ).val() || null ;
613 },
614
615 auto_set_spec_type: function() {
616 console.log("auto_set_spec_type...") ;
617 var self = this ;
618 var id = `#set_${self.DEFAULT_DATA["spectrum_type"]}_spectrum_button` ;
619 var element = $(self.prefix + id) ;
620 if (element.length) {
621 element.click() ;
622 console.log(`auto_set_spec_type to ${self.DEFAULT_DATA["spectrum_type"]} ok.`)
623 } else {
624 console.log(element)
625 console.log("Failed!")
626 }
627 if (self.DEFAULT_DATA["sample_type"]) {
628 self.auto_set_sample_type(self) ;
629 }
630 },
631
632 auto_set_sample_type: function() {
633 console.log("auto_set_sample_type...") ;
634 var self = this ;
635 var id = "#add1spectrum-sample-type-{{ TAB_INDEX_PLACEHOLDER }}" ;
636 var element = $(id) ;
637 if (element.length) {
638 element.val(self.DEFAULT_DATA["sample_type"]).change() ;
639 console.log(`auto_set_sample_type to ${self.DEFAULT_DATA["sample_type"]} ok.`) ;
640 if (self.DEFAULT_DATA["sample_type"] == "compound-ref") {
641 $("#add1spectrum-sample-mixSolvent-{{ TAB_INDEX_PLACEHOLDER }}").val(
642 "H2O/ethanol (75/25)"
643 ).change() ;
644 }
645 } else {
646 console.log(element)
647 console.log("Failed!")
648 }
649 if (self.DEFAULT_DATA["inchikey"]) {
650 setTimeout(() => self.auto_set_inchikey(self), 1000) ;
651 }
652 },
653
654 auto_set_inchikey: function() {
655 console.log("auto_set_inchikey...") ;
656 var self = this ;
657 var id ;
658 var element ;
659 self.inchikey = self.DEFAULT_DATA["inchikey"] ;
660 if (self.is_ref()) {
661 id = "#add1spectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}:text" ;
662 element = $(id) ;
663 if (element.length) {
664 console.log(`auto_set_inchikey to ${self.inchikey} ok.`)
665 element.val(self.inchikey).change() ;
666 console.log(`Inchikey set!`) ;
667 } else {
668 console.log(element)
669 console.log("Failed!")
670 }
671 } else {
672 for (var index = 0 ; index < all_contexts.length ; index += 1) {
673 if (all_contexts[index] === null || all_contexts[index] === undefined) {
674 continue;
675 }
676 var inchikey = all_contexts[index].DEFAULT_DATA["inchikey"] ;
677 id = `#container_RCC_ADDED-1 tbody:nth(0) tr:nth(${index}) td:nth(1)` ;
678 element = $(id) ;
679 if (element.length) {
680 console.log(`auto_set_inchikey to ${inchikey} ok.`)
681 self.hot_RCC_ADDED.setDataAtCell(index, 1, inchikey) ;
682 element.innerHTML = inchikey ;
683 element.change() ;
684 console.log(element) ;
685 console.log(`Inchikey set!`) ;
686 } else {
687 console.log(element)
688 console.log("Failed!")
689 }
690 }
691 console.log(self.hot_RCC_ADDED)
692 self.hot_RCC_ADDED.render() ;
693 }
694 $("#btnSwitch-gotoStep2-{{ TAB_INDEX_PLACEHOLDER }}").click() ;
695 if (self.DEFAULT_DATA["method"]) {
696 setTimeout(() => self.auto_set_method(self), 1000) ;
697 }
698 },
699
700 auto_set_method: function() {
701 console.log("auto_set_method...") ;
702 var self = this ;
703 var id = "#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}" ;
704 var element = $(id) ;
705 element.length && element.val(self.DEFAULT_DATA["method"]).change() ;
706 $("#btnSwitch-gotoStep3-lc-{{ TAB_INDEX_PLACEHOLDER }}").click() ;
707 setTimeout(() => {
708 (() => {
709 $("#btnSwitch-gotoStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}").click() ;
710 console.log(`auto_set_method to ${self.DEFAULT_DATA["method"]} ok.`)
711 if (self.DEFAULT_DATA["scan_type"]) {
712
713 // The scan type needs to be skipped, as it is already defined
714 // at build-time
715 // The code is kept for future modifications of this behavior
716 setTimeout(() => self.auto_set_scan_type(self, skip = true), 1000) ;
717 }
718 })(self)
719 }, 1000) ;
720 },
721
722 auto_set_scan_type: function(skip = false) {
723 var self = this ;
724 if (!skip) {
725 console.log("auto_set_scan_type...") ;
726 var id = "#add1spectrum-peaksMS-msLevel-{{ TAB_INDEX_PLACEHOLDER }}" ;
727 var element = $(id) ;
728 if (element.length) {
729 element.val(self.DEFAULT_DATA["scan_type"]).change() ;
730 console.log(`auto_set_scan_type to ${self.DEFAULT_DATA["scan_type"]} ok.`)
731 } else {
732 console.log("Failed!")
733 }
734 }
735 if (self.DEFAULT_DATA["polarity"]) {
736 self.auto_set_polarity(self) ;
737 }
738 },
739
740 auto_set_polarity: function() {
741 console.log("auto_set_polarity...") ;
742 var self = this ;
743 var id = "#add1spectrum-peaksMS-polarity-{{ TAB_INDEX_PLACEHOLDER }}" ;
744 var element = $(id) ;
745 if (element.length) {
746 element.val(self.DEFAULT_DATA["polarity"]).change() ;
747 console.log(`auto_set_polarity to ${self.DEFAULT_DATA["polarity"]} ok.`)
748 } else {
749 console.log("Failed!")
750 }
751 if (self.DEFAULT_DATA["resolution"]) {
752 self.auto_set_resolution(self) ;
753 }
754 },
755
756 auto_set_resolution: function() {
757 console.log("auto_set_resolution...") ;
758 var self = this ;
759 var id = "#add1spectrum-peaksMS-resolution-{{ TAB_INDEX_PLACEHOLDER }}" ;
760 var element = $(id) ;
761 if (element.length) {
762 element.val(self.DEFAULT_DATA["resolution"]).change() ;
763 console.log(`auto_set_resolution to ${self.DEFAULT_DATA["resolution"]} ok.`)
764 } else {
765 console.log("Failed!")
766 }
767 if (self.DEFAULT_DATA["next"] || true) {
768 setTimeout(() => self.finish_initialized(self), 1000) ;
769 }
770 },
771
772 finish_initialized: function() {
773 var self = this ;
774 if (ctx() === self) {
775 self.initialized = true ;
776 }
777 },
778
779 //USED IN HTML
780 updateLCMSspectraViewer: function() {
781 var self = this ;
782 var tab_no ;
783 console.log(`Updating spectral view for tab {{ TAB_INDEX_PLACEHOLDER }}`) ;
784 // reset current viewer
785 $("#containter-lcms-spectrum-preview-{{ TAB_INDEX_PLACEHOLDER }}").empty();
786 // reset data.
787
788 if (self.is_mix()) {
789 tab_no = 1 ;
790 } else {
791 tab_no = {{ TAB_INDEX_PLACEHOLDER }} ;
792 }
793 var range_from = $(`#add1spectrum-peaksMS-rangeFrom-${tab_no}`) ;
794 if ((spectrumMinPPM = Number(range_from.val())) == "") {
795 spectrumMinPPM = 10000;
796 }
797 var range_to = $(`#add1spectrum-peaksMS-rangeTo-${tab_no}`) ;
798 if ((spectrumMaxPPM = Number(range_to.val())) == "") {
799 spectrumMaxPPM = 0;
800 }
801 maxGraph = 0;
802 var localData = [];
803 var localDataAnnot = [];
804 // gather new data
805 // TODO switch tab in function of technic
806 $.each(self.hot_MS_Peaks.getData(), function() {
807 if(this[0] != undefined && this[0] != "") {
808 var x = (Number(this[0]));
809 var y = Number(this[2]);
810 var a = this[6];
811 localData.push([(x-0.000001),-150]);
812 localData.push([(x+0.000001),-150]);
813 localData.push([x,y]);
814 localDataAnnot[x] = a;
815 if (x < spectrumMinPPM) {
816 spectrumMinPPM = x;
817 }
818 if (x > spectrumMaxPPM) {
819 spectrumMaxPPM = x;
820 }
821 if (y > maxGraph) {
822 maxGraph = y;
823 }
824 }
825 });
826
827 // build new one
828 spectrumMinPPM = spectrumMinPPM - (0.1 * spectrumMinPPM);
829 spectrumMaxPPM = spectrumMaxPPM + (0.1 * spectrumMaxPPM);
830 maxGraph = maxGraph + (0.1 * maxGraph);
831 localData.sort();
832 console.log(localData)
833 // build graph
834 $("#containter-lcms-spectrum-preview-{{ TAB_INDEX_PLACEHOLDER }}").highcharts({
835 chart: {
836 zoomType: "x",
837 spacingRight: 10,
838 spacingLeft: 10,
839 type: "scatter"
840 },
841 title: {
842 text: "Spectrum Preview",
843 useHTML: true
844 },
845 subtitle: {
846 text: (
847 document.ontouchstart === undefined
848 ? "Select area"
849 : "Pinch the chart to zoom in"
850 )
851 },
852 xAxis: {
853 type: "number",
854 title: {text: "m/z"},
855 min: spectrumMinPPM,
856 max: spectrumMaxPPM,
857 labels: {
858 formatter: function() {
859 return (Math.abs(this.value) + "");
860 }
861 }
862 },
863 yAxis: {
864 title: {text: "Relative Intensity (%)"},
865 min: 0,
866 max: maxGraph
867 },
868 tooltip: {
869 crosshairs: true,
870 formatter: function() {
871 var compo = "";
872 return (
873 "<b>" + this.series.name
874 + "</b><br/>m/z:" + Math.abs(this.x) + ""
875 + ";<br/>Relative Intensity: " + this.y
876 + "%;<br/>Annotation: " + localDataAnnot[ this.x]
877 + ""
878 );
879 }
880 },
881 legend: {enabled: false},
882 plotOptions: {scatter: {}},
883 series: [{
884 name: "preview",
885 showInLegend: true,
886 color: "#f00",
887 lineColor: "#f00",
888 pointInterval: 10,
889 pointStart: 100,
890 lineWidth : 2,
891 marker: {
892 enabled: true,
893 radius: 2,
894 lineColor: "#f00"
895 },
896 data: localData,
897 zIndex: 10
898 }]
899 });
900 },
901
902 //USED HERE
903 fulfillLCdata: function(jsonFileName) {
904 var self = this ;
905 var url = `{{ PF_URL_PLACEHOLDER }}/webapp/resources/json/lc-methods/${jsonFileName}.json` ;
906 $.getJSON(url, function(json) {
907 // $.POST
908 console.log(json);
909 // lc chromato
910 if (json.lc_chromatography != null) {
911 [
912 ["colConstructor", "column_constructor"],
913 ["colConstructorOther", "column_constructor_other"],
914 ["colName", "column_name"],
915 ["colLength", "column_length"],
916 ["colDiameter", "column_diameter"],
917 ["colParticuleSize", "particule_size"],
918 ["colTemperature", "column_temperature"],
919 ["separationFlowRate", "separation_flow_rate"],
920 ["separationSolvA", "separation_solvent_a"],
921 ["separationSolvApH", "ph_solvent_a"],
922 ["separationSolvB", "separation_solvent_b"],
923 ["separationSolvBpH", "ph_solvent_b"]
924 ].forEach((arr) => {
925 var el ;
926 console.log(arr)
927 el = $(`#add1spectrum-chromatoLC-${arr[0]}-{{ TAB_INDEX_PLACEHOLDER }}`)
928 el.val(json.lc_chromatography[arr[1]]) ;
929 el.change()
930 })
931 try {
932 $("#add1spectrum-chromatoLC-LCMode-{{ TAB_INDEX_PLACEHOLDER }}").val(json.lc_chromatography.LC_mode);
933 $("#add1spectrum-chromatoLC-LCMode-{{ TAB_INDEX_PLACEHOLDER }}").change();
934 } catch (e) {}
935 var handsontableSeparationFlowRateData = [] ;
936 if (json.lc_chromatography.separation_flow_gradient != null) {
937 $.each(json.lc_chromatography.separation_flow_gradient, function() {
938 var e = [
939 "" + this.time,
940 "" + this.solvA,
941 "" + this.solvB
942 ];
943 handsontableSeparationFlowRateData.push(e);
944 });
945 } else {
946 handsontableSeparationFlowRateData = null;
947 }
948 self.handsontableSeparationFlowRate(handsontableSeparationFlowRateData);
949 }
950 // ms_analyzer
951 if (json.ms_analyzer != null) {
952 $("#add1spectrum-analyzer-ms-instrument-{{ TAB_INDEX_PLACEHOLDER }}").val(json.ms_analyzer.instrument);
953 $("#add1spectrum-analyzer-ms-instrument-{{ TAB_INDEX_PLACEHOLDER }}").change();
954 $("#add1spectrum-analyzer-ms-model-{{ TAB_INDEX_PLACEHOLDER }}").val(json.ms_analyzer.model);
955 $("#add1spectrum-analyzer-ms-model-{{ TAB_INDEX_PLACEHOLDER }}").change();
956 $("#add1spectrum-analyzer-ms-resolutionFWHM-{{ TAB_INDEX_PLACEHOLDER }}").val(json.ms_analyzer.resolution_FWHM);
957 $("#add1spectrum-analyzer-ms-resolutionFWHM-{{ TAB_INDEX_PLACEHOLDER }}").change();
958 $("#add1spectrum-analyzer-ms-ionAnalyzerType-{{ TAB_INDEX_PLACEHOLDER }}").val(json.ms_analyzer.ion_analyzer_type);
959 $("#add1spectrum-analyzer-ms-ionAnalyzerType-{{ TAB_INDEX_PLACEHOLDER }}").change();
960 }
961 if (json.molecule_ionization != null) {
962 ["pos", "neg"].forEach((mode) => {
963 if (json.molecule_ionization[`mode_${mode}`] != null) {
964 [
965 ["ionizationMethod", "ionisation_method"],
966 ["sprayGazFlow", "spray_gaz_flow"],
967 ["vaporizerGazFlow", "vaporizer_gaz_flow"],
968 ["vaporizerTemperature", "vaporizer_temperature"],
969 ["sourceGazFlow", "source_gaz_flow"],
970 ["ionTransferTubeTemperatureOrTransferCapillaryTemperature", "transfer_tube_or_capillary_temperature"],
971 ["highVoltageOrCoronaVoltage", "voltage"],
972 ].forEach((tuple) => {
973 var el ;
974 var id = tuple[0] ;
975 var key = tuple[1] ;
976 el = $(`#add1spectrum-analyzserMS-${id}-${mode}-{{ TAB_INDEX_PLACEHOLDER }}`) ;
977 console.log(el)
978 el.val(json.molecule_ionization[`mode_${mode}`][key]);
979 el.change() ;
980 })
981 }
982 })
983 }
984
985 if (json.molecule_beamOrTrap != null) {
986 if (json.molecule_beamOrTrap.ion_beam != null) {
987 $("#add1spectrum-ionTrapBeam-type-{{ TAB_INDEX_PLACEHOLDER }}").val("beam").change();
988 $("#add1spectrum-ionTrapBeam-ionGas-{{ TAB_INDEX_PLACEHOLDER }}").val(json.molecule_beamOrTrap.ion_beam.ion_gas).change();
989 $("#add1spectrum-ionTrapBeam-ionGasPressureValue-{{ TAB_INDEX_PLACEHOLDER }}").val(json.molecule_beamOrTrap.ion_beam.ion_pressure_value).change();
990 $("#add1spectrum-ionTrapBeam-ionGasPressureUnit-{{ TAB_INDEX_PLACEHOLDER }}").val(json.molecule_beamOrTrap.ion_beam.ion_pressure_unit).change();
991 }
992 if (json.molecule_beamOrTrap.ion_trap != null) {
993 $("#add1spectrum-ionTrapBeam-type-{{ TAB_INDEX_PLACEHOLDER }}").val("trap").change();
994 $("#add1spectrum-ionTrapBeam-ionGas-{{ TAB_INDEX_PLACEHOLDER }}").val(json.molecule_beamOrTrap.ion_trap.ion_gas).change();
995 $("#add1spectrum-ionTrapBeam-ionGasPressureValue-{{ TAB_INDEX_PLACEHOLDER }}").val(json.molecule_beamOrTrap.ion_trap.ion_pressure_value).change();
996 $("#add1spectrum-ionTrapBeam-ionGasPressureUnit-{{ TAB_INDEX_PLACEHOLDER }}").val(json.molecule_beamOrTrap.ion_trap.ion_pressure_unit).change();
997 $("#add1spectrum-ionTrapBeam-ionNumber-{{ TAB_INDEX_PLACEHOLDER }}").val(json.molecule_beamOrTrap.ion_trap.ion_number).change();
998 $("#add1spectrum-ionTrapBeam-ionFrequencyShift-{{ TAB_INDEX_PLACEHOLDER }}").val(json.molecule_beamOrTrap.ion_trap.ion_freq_shift).change();
999 }
1000 }
1001 // other
1002 if (json.other != null) {
1003 $("#add1spectrum-other-author-{{ TAB_INDEX_PLACEHOLDER }}").val(json.other.data_authors);
1004 $("#add1spectrum-other-author-{{ TAB_INDEX_PLACEHOLDER }}").change();
1005 $("#add1spectrum-other-validator-{{ TAB_INDEX_PLACEHOLDER }}").val(json.other.data_validator);
1006 $("#add1spectrum-other-validator-{{ TAB_INDEX_PLACEHOLDER }}").change();
1007 $("#add1spectrum-other-date-{{ TAB_INDEX_PLACEHOLDER }}").val(json.other.acquisition_date);
1008 $("#add1spectrum-other-date-{{ TAB_INDEX_PLACEHOLDER }}").change();
1009 $("#add1spectrum-other-owner-{{ TAB_INDEX_PLACEHOLDER }}").val(json.other.data_ownership);
1010 $("#add1spectrum-other-owner-{{ TAB_INDEX_PLACEHOLDER }}").change();
1011 }
1012 }).error(function(event, jqxhr, exception) {
1013 if (event.status == 404) {
1014 $("#alertBoxSelectTemplate-{{ TAB_INDEX_PLACEHOLDER }}").html(`
1015 <div class="alert alert-danger alert-dismissible" role="alert">
1016 <button type="button" class="close" data-dismiss="alert">
1017 <span aria-hidden="true">&times;</span>
1018 <span class="sr-only"><spring:message code="alert.close" text="Close" /></span>
1019 </button>
1020 <strong>
1021 <spring:message code="alert.strong.error" text="Error!" />
1022 </strong> unable to load pre-filled data!
1023 </div>
1024 `);
1025 }
1026 });
1027 },
1028
1029 //USED HERE
1030 resetFromColors: function() {
1031
1032 var self = this ;
1033 $.each($(self.prefix+".add1spectrum"), function(id, elem) {
1034 element = $(elem)
1035 self.rm_success(element) ;
1036 self.rm_warning(element) ;
1037 self.rm_error(element) ;
1038 if ($(elem).hasClass("is-mandatory") && ($(elem).val() == "" || $(elem).val() == null)) {
1039 self.set_error($(elem)) ;
1040 }
1041 if ($(elem).hasClass("is-optional") && ($(elem).val() == "" || $(elem).val() == null)) {
1042 self.set_warning($(elem)) ;
1043 }
1044 if ($(elem).val() != "" && $(elem).val() != null) {
1045 self.set_success($(elem)) ;
1046 }
1047 });
1048 $.each($(self.prefix+"button.switchStep"), function(id, elem) {
1049 if (!$(this).hasClass("btn-disabled")) {
1050 $(this).addClass("btn-disabled");
1051 }
1052 if ($(this).hasClass("btn-primary")) {
1053 $(this).removeClass("btn-primary");
1054 }
1055 $(this).prop("disabled", true);
1056 });
1057
1058 // peak list: no data to check
1059 $("#btnSwitch-gotoStep5-ms-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("btn-disabled");
1060 $("#btnSwitch-gotoStep5-ms-{{ TAB_INDEX_PLACEHOLDER }}").addClass("btn-primary");
1061 $("#btnSwitch-gotoStep5-ms-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
1062
1063 $("#add1spectrum-other-author-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
1064 $("#add1spectrum-other-validator-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
1065 $("#add1spectrum-other-date-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
1066 $("#add1spectrum-other-owner-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
1067 $("#add1spectrum-other-fileName-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
1068 $("#add1spectrum-other-fileSize-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
1069 },
1070
1071 //USED IN HTML
1072 switchToStep: function(step) {
1073
1074 var self = this ;
1075 switch(step) {
1076 case 2:
1077 // hide after step 2 / alt step 2
1078 $("#add1spectrum-chromatographyData-LC-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1079 $("#add1spectrum-chromatographyData-GC-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1080 $("#add1spectrum-analyserData-MS-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1081 $("#add1spectrum-peaksData-MS-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1082 $("#add1spectrum-otherData-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1083 if ($("#step1sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-question-circle")) {
1084 $("#step1sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-question-circle").addClass("fa-check-circle");
1085 }
1086 if (self.is_ms()) {
1087 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").empty();
1088 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").append(
1089 '<option value="" selected="selected" disabled="disabled">choose in list&hellip;</option>'
1090 );
1091 $.getJSON("{{ PF_URL_PLACEHOLDER }}/webapp/resources/json/list-lc-methods.json", function(data) {
1092 // load data from json
1093 $.each(data.methods,function() {
1094 if (this.name !== undefined) {
1095 if (this.value !== undefined) {
1096 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").append(
1097 `<option value="${this.value}">${this.name}</option>`
1098 );
1099 } else {
1100 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").append(
1101 `<option disabled>${this.name}</option>`
1102 );
1103 }
1104 }
1105 });
1106 });
1107 } else if (self.is_ms2()) {
1108 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").empty();
1109 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").append(
1110 '<option value="" selected="selected" disabled="disabled">choose in list&hellip;</option>'
1111 );
1112 $.getJSON(
1113 "{{ PF_URL_PLACEHOLDER }}/webapp/resources/json/list-lc-msms-methods.json",
1114 function(data) {
1115 // load data from json
1116 $.each(data.methods, function() {
1117 if (this.name !== undefined) {
1118 if (this.value !== undefined) {
1119 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").append(
1120 `<option value="${this.value}">${this.name}</option>`
1121 );
1122 } else {
1123 $("#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}").append(
1124 `<option disabled>${this.name}</option>`
1125 );
1126 }
1127 }
1128 });
1129 }
1130 );
1131 }
1132 // check panel to show
1133 if (self.isLC) {
1134 $("#add1spectrum-chromatographyData-LC-{{ TAB_INDEX_PLACEHOLDER }}").show();
1135 $("#linkActivateStep2-lc-{{ TAB_INDEX_PLACEHOLDER }}").trigger("click");
1136 var sign = $("#step2-lc-sign-{{ TAB_INDEX_PLACEHOLDER }}") ;
1137 self.rm_class(sign, "fa-check-circle") && self.set_class(sign, "fa-question-circle") ;
1138 if (!self.isSeparationFlowRateInit) {
1139 self.handsontableSeparationFlowRate(null);
1140 self.isSeparationFlowRateInit = true;
1141 }
1142 } else if (self.isGC) {
1143 $("#add1spectrum-chromatographyData-GC-{{ TAB_INDEX_PLACEHOLDER }}").show();
1144 $("#linkActivateStep2-gc-{{ TAB_INDEX_PLACEHOLDER }}").trigger("click");
1145 var sign = $("#step2-gc-sign-{{ TAB_INDEX_PLACEHOLDER }}") ;
1146 sign.removeClass("fa-check-circle").addClass("fa-question-circle");
1147 if ($("#step2-gc-sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-check-circle")) {
1148 }
1149 } else if (self.isIC) {
1150 $("#add1spectrum-chromatographyData-IC-{{ TAB_INDEX_PLACEHOLDER }}").show();
1151 $("#linkActivateStep2-ic-{{ TAB_INDEX_PLACEHOLDER }}").trigger("click");
1152 if ($("#step2-ic-sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-check-circle")) {
1153 $("#step2-ic-sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-check-circle").addClass("fa-question-circle");
1154 }
1155 }
1156 break;
1157 case 3:
1158 // hide after step 3 / alt step 3
1159 $("#add1spectrum-analyserData-MS-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1160 $("#add1spectrum-peaksData-MS-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1161 $("#add1spectrum-otherData-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1162 // step 2 ok
1163 if ($("#step2-lc-sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-question-circle")) {
1164 $("#step2-lc-sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-question-circle").addClass("fa-check-circle");
1165 }
1166 if ($("#step2-gc-sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-question-circle")) {
1167 $("#step2-gc-sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-question-circle").addClass("fa-check-circle");
1168 }
1169 // check panel to show
1170 if (self.is_ms() || self.is_ms2()) {
1171 $("#add1spectrum-analyserData-MS-{{ TAB_INDEX_PLACEHOLDER }}").show();
1172 $("#linkActivateStep3-ms-{{ TAB_INDEX_PLACEHOLDER }}").trigger('click');
1173 // debug display
1174 [
1175 "add1spectrum-analyzserMS-sprayGazFlow-pos",
1176 "add1spectrum-analyzserMS-sprayGazFlow-neg",
1177 "add1spectrum-analyzserMS-vaporizerGazFlow-pos",
1178 "add1spectrum-analyzserMS-vaporizerGazFlow-neg",
1179 "add1spectrum-analyzserMS-vaporizerTemperature-pos",
1180 "add1spectrum-analyzserMS-vaporizerTemperature-neg",
1181 "add1spectrum-analyzserMS-sourceGazFlow-pos",
1182 "add1spectrum-analyzserMS-sourceGazFlow-neg",
1183 "add1spectrum-analyzserMS-ionTransferTubeTemperatureOrTransferCapillaryTemperature-pos",
1184 "add1spectrum-analyzserMS-ionTransferTubeTemperatureOrTransferCapillaryTemperature-neg",
1185 "add1spectrum-analyzserMS-highVoltageOrCoronaVoltage-pos",
1186 "add1spectrum-analyzserMS-highVoltageOrCoronaVoltage-neg"
1187 ].forEach((id) => {
1188 var element = $(`#id-{{ TAB_INDEX_PLACEHOLDER }}`)
1189 element.height(element.parent().children("span").height())
1190 })
1191 if ($("#step3-ms-sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-check-circle")) {
1192 $("#step3-ms-sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-check-circle").addClass("fa-question-circle");
1193 }
1194 // MSMS only
1195 $(self.prefix+".enable-if-ms").attr("disabled", !self.is_ms());
1196 $(self.prefix+".enable-if-msms").attr("disabled", !self.is_ms2());
1197 }
1198 // avoid display bug
1199 $("#add1spectrum-analyzer-ms-instrument-{{ TAB_INDEX_PLACEHOLDER }}").change();
1200 break;
1201 case 4:
1202 // hide after step 4 / alt step 4
1203 $("#add1spectrum-peaksData-MS-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1204 $("#add1spectrum-otherData-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1205 // step 3 ok
1206 if ($("#step3-ms-sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-question-circle")) {
1207 $("#step3-ms-sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-question-circle").addClass("fa-check-circle");
1208 }
1209 if (self.is_ms() || self.is_ms2()) {
1210 $("#add1spectrum-peaksData-MS-{{ TAB_INDEX_PLACEHOLDER }}").show();
1211 $("#linkActivateStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}").trigger("click");
1212 if ($("#step4-ms-sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-check-circle")) {
1213 $("#step4-ms-sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-check-circle").addClass("fa-question-circle");
1214 }
1215 // LC MS
1216 if (!self.isMSpeaksInit) {
1217 console.log(`self.is_mix(): ${self.is_mix()}`)
1218 if (self.is_mix()) {
1219 all_contexts.forEach((context, index) => {
1220 if (context === null) {
1221 return;
1222 }
1223 context.handsontableMSpeaks(null) ;
1224 context.updateLCMSspectraViewer() ;
1225 context.isMSpeaksInit = true;
1226 $(context.prefix+".add1spectrum-peaksMSForm-peaklist-reset").val("").change();
1227 })
1228 } else {
1229 self.handsontableMSpeaks(null);
1230 self.isMSpeaksInit = true;
1231 $(self.prefix+".add1spectrum-peaksMSForm-peaklist-reset").val("").change();
1232 }
1233 }
1234 }
1235 // show ms tab
1236 setTimeout(() => $("#container_MS_Peaks-{{ TAB_INDEX_PLACEHOLDER }}").trigger("click"), 250);
1237 $("#add1spectrum-peaksMS-msLevel-{{ TAB_INDEX_PLACEHOLDER }}").change();
1238 break;
1239 case 5:
1240 // hide after step 5 / alt step 5
1241 $("#add1spectrum-otherData-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1242 // step 4 ok
1243 if ($("#step4-ms-sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-question-circle")) {
1244 $("#step4-ms-sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-question-circle").addClass("fa-check-circle");
1245 }
1246 if ($("#step5sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-check-circle")) {
1247 $("#step5sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-check-circle").addClass("fa-question-circle");
1248 }
1249 $("#add1spectrum-otherData-{{ TAB_INDEX_PLACEHOLDER }}").show();
1250 $("#linkActivateStep5-{{ TAB_INDEX_PLACEHOLDER }}").trigger("click");
1251 // reset step 6 button
1252 self.checkIfEnableSubmit();
1253 $("#import1SpectrumLoadingBare-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1254 $("#import1SpectrumResults-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1255 break;
1256 case 6:
1257 self.postOneSpectrumFrom();
1258 self.cptPeakListTab++;
1259 break;
1260 case 7:
1261 self.dumpOneSpectrumFrom();
1262 break;
1263 }
1264 },
1265
1266 //USED HERE
1267 resetElemColor: function(idElem) {
1268
1269 var self = this ;
1270 if ($(`#${idElem}`).parent().hasClass("has-success")) {
1271 $(`#${idElem}`).parent().removeClass("has-success") ;
1272 }
1273 if ($(`#${idElem}`).parent().hasClass("has-warning")) {
1274 $(`#${idElem}`).parent().removeClass("has-warning") ;
1275 }
1276 if ($(`#${idElem}`).parent().hasClass("has-error")) {
1277 $(`#${idElem}`).parent().removeClass("has-error") ;
1278 }
1279 },
1280
1281 //USED HERE
1282 disableElem: function(idElem) {
1283
1284 var self = this ;
1285 $(`#${idElem}`).prop("disabled", true) ;
1286 $(`#${idElem}`).val("") ;
1287 if ($(`#${idElem}`).hasClass("is-mandatory")) {
1288 $(`#${idElem}`).removeClass("is-mandatory") ;
1289 }
1290 },
1291
1292 //USED HERE
1293 enableElem: function(idElem) {
1294
1295 var self = this ;
1296 $(`#${idElem}`).prop("disabled", false) ;
1297 $(`#${idElem}`).parent().addClass("has-error") ;
1298 if (!$(`#${idElem}`).hasClass("is-mandatory")) {
1299 $(`#${idElem}`).addClass("is-mandatory") ;
1300 }
1301 },
1302
1303 //USED HERE
1304 checkIfEnableSubmit: function() {
1305
1306 var self = this ;
1307 var isBtnStep6OK = true;
1308 $.each($(self.prefix+".add1spectrum-otherForm"), (id, elem) => {
1309 if (self.is_error($(elem)) && $(elem).is(":visible")) {
1310 isBtnStep6OK = false;
1311 }
1312 });
1313 if (isBtnStep6OK) {
1314 self.rm_class($("#btnSwitch-gotoStep6-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-disabled") ;
1315 self.set_class($("#btnSwitch-gotoStep6-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-primary") ;
1316 $("#btnSwitch-gotoStep6-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
1317 self.rm_class($("#btnSwitch-gotoStep7-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-disabled") ;
1318 self.set_class($("#btnSwitch-gotoStep7-{{ TAB_INDEX_PLACEHOLDER }}"), "btn-primary") ;
1319 $("#btnSwitch-gotoStep7-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", false);
1320 } else {
1321 if (!$("#btnSwitch-gotoStep6-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("btn-disabled")) {
1322 $("#btnSwitch-gotoStep6-{{ TAB_INDEX_PLACEHOLDER }}").addClass("btn-disabled");
1323 }
1324 if ($("#btnSwitch-gotoStep6-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("btn-primary")) {
1325 $("#btnSwitch-gotoStep6-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("btn-primary");
1326 }
1327 $("#btnSwitch-gotoStep6-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", true);
1328 if (!$("#btnSwitch-gotoStep7-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("btn-disabled")) {
1329 $("#btnSwitch-gotoStep7-{{ TAB_INDEX_PLACEHOLDER }}").addClass("btn-disabled");
1330 }
1331 if ($("#btnSwitch-gotoStep7-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("btn-primary")) {
1332 $("#btnSwitch-gotoStep7-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("btn-primary");
1333 }
1334 $("#btnSwitch-gotoStep7-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", true);
1335 }
1336 },
1337
1338 //USED IN HTML
1339 addOneSpectrum: function(type) {
1340
1341 var self = this ;
1342 // unlock
1343 $(self.prefix+".add1spectrum-sampleForm").prop("disabled", false);
1344 $(self.prefix+".add1spectrum-chromatoLCForm").prop("disabled", false);
1345 $(self.prefix+".add1spectrum-analyzerMSForm").prop("disabled", false);
1346 $(self.prefix+".add1spectrum-otherForm").prop("disabled", false);
1347 $("#add1spectrum-chromatoLC-colConstructor-{{ TAB_INDEX_PLACEHOLDER }}").change();
1348 // reset
1349 self.isLC = false;
1350 self.isGC = false;
1351 self.isIC = false;
1352 $("#alertBoxSubmitSpectrum-{{ TAB_INDEX_PLACEHOLDER }}").html("");
1353 // hide in all steps
1354 $(self.prefix+".opt-ms").hide();
1355 $(self.prefix+".opt-msms").hide();
1356 // hide step 2
1357 $("#add1spectrum-chromatographyData-LC-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1358 $("#add1spectrum-chromatographyData-GC-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1359 // hide step 3
1360 $("#add1spectrum-analyserData-MS-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1361 $(self.prefix+".add1spectrum-ionTrap").hide();
1362 // hide step 4
1363 $("#add1spectrum-peaksData-MS-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1364 // hide step 5
1365 $("#add1spectrum-otherData-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1366 // reset field step 1
1367 $("#add1spectrum-sample-type-{{ TAB_INDEX_PLACEHOLDER }}").val("");
1368 $(self.prefix+".add1spectrum-sample-type-panel").hide();
1369 $(self.prefix+".add1spectrum-sampleForm").val("");
1370 $("#sample-bonus-display-{{ TAB_INDEX_PLACEHOLDER }}").html("");
1371 // reset field step 2
1372 $(self.prefix+".add1spectrum-chromatoLCForm").val("");
1373 // reset field step 3
1374 $(self.prefix+".add1spectrum-analyzerMSForm").val("");
1375 // reset field step 4
1376 // reset peak lists / all tabs
1377 self.isSeparationFlowRateInit = false;
1378 self.isMSpeaksInit = false;
1379 $(self.prefix+".handsontable").html("");
1380 // reset field step 5 => NO!
1381 // set icon
1382 $("#step0sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-question-circle").addClass("fa-check-circle");
1383 if ($("#step1sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-check-circle")) {
1384 $("#step1sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-check-circle").addClass("fa-question-circle");
1385 }
1386 // collapse step 0 / uncollaspe step 1
1387 $("#linkActivateStep1-{{ TAB_INDEX_PLACEHOLDER }}").trigger("click");
1388 // show step 1 content
1389 $("#add1spectrum-sampleData-{{ TAB_INDEX_PLACEHOLDER }}").show();
1390 switch(type) {
1391 case 1:
1392 // TODO GC-MS stuff
1393 self.isGC = true;
1394 break;
1395 case 2:
1396 // LC-MS stuff
1397 self.isLC = true;
1398 $(self.prefix+".opt-ms").show();
1399 break;
1400 case 5:
1401 // LC-MSMS stuff
1402 self.isLC = true;
1403 $(self.prefix+".opt-ms").show();
1404 $(self.prefix+".opt-msms").show();
1405 break;
1406 case 6:
1407 // IC-MS stuff
1408 self.isIC = true;
1409 $(self.prefix+".opt-ms").show();
1410 break;
1411 case 7:
1412 // IC-MSMS stuff
1413 self.isIC = true;
1414 $(self.prefix+".opt-ms").show();
1415 $(self.prefix+".opt-msms").show();
1416 break;
1417 }
1418 self.resetFromColors();
1419 // reset json obj to submit form
1420 self.jsonSpectrumType = null;
1421 self.isJsonSpectrumTypeComplete = false;
1422 self.jsonSample = null;
1423 self.isJsonSampleComplete = false;
1424 self.isJsonRCCaddedComplete = false;
1425 self.jsonChromato = null;
1426 self.isJsonChromatoComplete = false;
1427 self.jsonAnalyzer = null;
1428 self.isJsonAnalyzerComplete = false;
1429 self.jsonPeaksList = [];
1430 self.isJsonPeaksListComplete = false;
1431 self.jsonOtherMetadata = null;
1432 self.isJsonOtherMetadataComplete = false;
1433
1434 self.cptPeakListTab = 0;
1435 self.jsonAnalyzerAcquisition = [];
1436 self.idMetadataMap = {}
1437 self.listOfViewableSpectra = [];
1438
1439 // spec MS
1440 self.jsonMolIonization = null;
1441
1442 // spec MSMS
1443 self.jsonMolIonBeam = null;
1444
1445 // try load cpd
1446 if (self.inchikey !== null) {
1447 self.loadJSCompound(self.inchikey);
1448 }
1449 },
1450
1451 //USED HERE
1452 loadJSCompound: function(inchikey) {
1453 var self = this ;
1454
1455 $("#add1spectrum-sample-type-{{ TAB_INDEX_PLACEHOLDER }}").val("compound-ref");
1456 $("#add1spectrum-sample-type-{{ TAB_INDEX_PLACEHOLDER }}").change();
1457 $("#add1spectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}").val(inchikey);
1458 $("#add1spectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}").change();
1459 if (inchidata[inchikey] !== null) {
1460 return (set_inchi_data(inchidata[inchikey]), {{ TAB_INDEX_PLACEHOLDER }}) ;
1461 }
1462 $.ajax({
1463 type: "get",
1464 url: "{{ PF_URL_PLACEHOLDER }}/webapp/get-cpd-data",
1465 data: "inchikey="+inchikey,
1466 dataType: "json",
1467 success: function(data) {
1468 if (data.success) {
1469 set_inchi_data(data) ;
1470 }
1471 },
1472 error : function(data) {
1473 }
1474 }).always(function() {
1475 });
1476 },
1477
1478 //USED HERE
1479 handsontableSeparationFlowRate: function(data) {
1480 var self = this ;
1481
1482 // reset
1483 $("#container_LC_SFG-{{ TAB_INDEX_PLACEHOLDER }}").html("");
1484 // init
1485 var data_LC_SFG;
1486 if (data==null) {
1487 data_LC_SFG = [
1488 [ "", "", "" ],
1489 [ "", "", "" ],
1490 [ "", "", "" ],
1491 [ "", "", "" ],
1492 [ "", "", "" ],
1493 [ "", "", "" ],
1494 [ "", "", "" ],
1495 [ "", "", "" ],
1496 [ "", "", "" ],
1497 ];
1498 } else {
1499 data_LC_SFG = data;
1500 }
1501
1502 var container_LC_SFG = document.getElementById("container_LC_SFG-{{ TAB_INDEX_PLACEHOLDER }}");
1503 self.hot_LC_SFG = new Handsontable(container_LC_SFG, {
1504 data : data_LC_SFG,
1505 minSpareRows : 1,
1506 colHeaders : true,
1507 colHeaders: ["time (min)", "solv. A (%)", "solv. B (%)"],
1508 contextMenu : false
1509 });
1510 Handsontable.Dom.addEvent(document.body, "click", function(e) {
1511 var element = e.target || e.srcElement;
1512 if (element.nodeName == "BUTTON"&& element.name == "dump") {
1513 var name = element.getAttribute("data-dump");
1514 var instance = element.getAttribute("data-instance");
1515 self.hot_LC_SFG = window[instance];
1516 console.log("data of " + name, self.hot_LC_SFG.getData());
1517 }
1518 });
1519 $("#container_LC_SFG table.htCore-{{ TAB_INDEX_PLACEHOLDER }}").css("width","100%");
1520 },
1521
1522 //USED HERE
1523 handsontableMSpeaks: function(data) {
1524 console.log("handsontableMSpeaks")
1525 console.log(data)
1526 var self = this ;
1527 var data_MS_Peaks ;
1528 var container_MS_Peaks ;
1529
1530 if (data != null) {
1531 data_MS_Peaks = data;
1532 } else {
1533 data_MS_Peaks = JSON.parse(JSON.stringify(self.DEFAULT_MS_PEAK_VALUES));
1534 }
1535 $("#container_MS_Peaks-{{ TAB_INDEX_PLACEHOLDER }}").html("");
1536 container_MS_Peaks = document.getElementById(
1537 "container_MS_Peaks-{{ TAB_INDEX_PLACEHOLDER }}"
1538 );
1539 var colHeaders = [
1540 "m/z", "absolute intensity", "relative intensity (%)", "delta (ppm)",
1541 "composition", "attribution", "Validated"
1542 ]
1543 var columns = [
1544 {type: "numeric", format: "0.0000"},
1545 {type: "numeric", format: "0.00"},
1546 {type: "numeric", format: "0.00"},
1547 {type: "numeric", format: "0.0000"},
1548 {type: "text"},
1549 {type: "text"},
1550 {type: "checkbox"}
1551 ] ;
1552 if (self.is_ms2()) {
1553 colHeaders.push("Parent ion") ;
1554 columns.push({type: "checkbox"}) ;
1555 }
1556 self.hot_MS_Peaks = new Handsontable(container_MS_Peaks, {
1557 data: data_MS_Peaks,
1558 minSpareRows: 1,
1559 colHeaders: true,
1560 colHeaders: colHeaders,
1561 contextMenu: false,
1562 maxRows: data_MS_Peaks.length,
1563 minRows: data_MS_Peaks.length,
1564 columns: columns,
1565 afterChange: function(changes) {
1566 if (self.lock.precursor_ion) {
1567 return ;
1568 }
1569 self.lock.precursor_ion = true ;
1570 try {
1571 changes?.forEach(([row, prop, old, value]) => {
1572 var data ;
1573 var precursor_ion ;
1574
1575 var data = self.hot_MS_Peaks.getData() ;
1576 if (prop !== 7 || value !== true || data === undefined) {
1577 return ;
1578 }
1579 for (var i = 0; i < data.length ; i += 1) {
1580 data[i][7] = false ;
1581 }
1582 data[row][7] = true ;
1583 precursor_ion = $(`#add1spectrum-peaksMS-msPrecursorIon-{{ TAB_INDEX_PLACEHOLDER }}`) ;
1584 console.log(`setting preco ion to ${data[row][0]}`) ;
1585 precursor_ion.val(data[row][0]) ;
1586 precursor_ion.change() ;
1587 self.hot_MS_Peaks.render() ;
1588 })
1589 } finally {
1590 self.lock.precursor_ion = false ;
1591 }
1592 }
1593 });
1594 Handsontable.Dom.addEvent(document.body, "click", (e) => {
1595 var element ;
1596 var name ;
1597 var instance ;
1598
1599 element = e.target || e.srcElement ;
1600 if (element.nodeName == "BUTTON" && element.name == "dump") {
1601 name = element.getAttribute("data-dump") ;
1602 instance = element.getAttribute("data-instance") ;
1603 self.hot_MS_Peaks = window[instance] ;
1604 console.log("data of " + name, self.hot_MS_Peaks.getData()) ;
1605 }
1606 }) ;
1607
1608 $("#container_MS_Peaks-{{ TAB_INDEX_PLACEHOLDER }} table.htCore").css(
1609 "width","100%"
1610 ) ;
1611 if (self.is_ms2()) {
1612 setTimeout(() => self.select_precursor_ion(), 200) ;
1613 }
1614 },
1615
1616 change_tab: function() {
1617 var self = this ;
1618 setTimeout(() => self.auto_select_ion_parent(), 1000) ;
1619 },
1620
1621 auto_select_ion_parent: function() {
1622 var self = this ;
1623 if (!self.a_ion_parent_is_selected()) {
1624 setTimeout(() => self.select_precursor_ion(), 1000) ;
1625 }
1626 },
1627
1628 select_precursor_ion: function() {
1629 var self = this ;
1630 var data ;
1631 var precuirsor_ion ;
1632
1633 if (self.hot_MS_Peaks == null) {
1634 return setTimeout(() => self.select_precursor_ion(), 200) ;
1635 }
1636 console.log("Selecting ion preco for tab {{ TAB_INDEX_PLACEHOLDER }}")
1637 data = self.hot_MS_Peaks.getData() ;
1638 for (var i = 0 ; i < data.length ; i += 1) {
1639 if (data[i][5] === "[M+H]+" || data[i][5] === "[M+H]-" || data[i][2] == 100.0) {
1640 precursor_ion = $("#add1spectrum-peaksMS-msPrecursorIon-{{ TAB_INDEX_PLACEHOLDER }}") ;
1641 precursor_ion.val(data[i][0]) ;
1642 precursor_ion.change() ;
1643 return ;
1644 }
1645 }
1646 },
1647
1648 sync_precursor_ion: function() {
1649 var self = this ;
1650 var data ;
1651
1652 if (self.lock.precursor_ion || self.hot_MS_Peaks == undefined) {
1653 return ;
1654 }
1655 self.lock.precursor_ion = true ;
1656 console.log("Syncing precursor ion")
1657 var val = $("#add1spectrum-peaksMS-msPrecursorIon-{{ TAB_INDEX_PLACEHOLDER }}").val() ;
1658 var data = self.hot_MS_Peaks.getData() ;
1659 for (var i = 0; i < data.length ; i += 1) {
1660 if (Math.abs(data[i][0] - val) < 0.0001) {
1661 for (var j = 0; j < data.length ; j += 1) {
1662 data[j][7] = false ;
1663 }
1664 data[i][7] = true ;
1665 self.hot_MS_Peaks.render() ;
1666 return ;
1667 }
1668 }
1669 self.lock.precursor_ion = false ;
1670 },
1671
1672 // USED HERE
1673 handsontableRefChemCpdAdded: function(data) {
1674 var self = this ;
1675 // reset
1676 $("#container_RCC_ADDED-{{ TAB_INDEX_PLACEHOLDER }}").html("");
1677 $("#sample-bonus-display-{{ TAB_INDEX_PLACEHOLDER }}").html("");
1678 // init
1679 var data_RCC_ADDED, colHeaderData, container_RCC_ADDED;
1680
1681 colHeaderData = [
1682 {data: "common name", type: "text"},
1683 {data: "<b>InChIKey</b>", type: "text"},
1684 {data: "composition", renderer: lightgrayRenderer},
1685 {data: "<b>concentration (&micro;g/ml)</b>", type: "text"},
1686 {data: "exact mass", renderer: lightgrayRenderer},
1687 {data: "(M+H)+ or (M-H)-", renderer: lightgrayRenderer}
1688 ] ;
1689
1690 if (data == null) {
1691 data_RCC_ADDED = [
1692 [ "", "", "","", "", "" ],
1693 [ "", "", "","", "", "" ],
1694 [ "", "", "","", "", "" ],
1695 [ "", "", "","", "", "" ],
1696 [ "", "", "","", "", "" ],
1697 [ "", "", "","", "", "" ],
1698 [ "", "", "","", "", "" ],
1699 [ "", "", "","", "", "" ],
1700 [ "", "", "","", "", "" ],
1701 [ "", "", "","", "", "" ],
1702 [ "", "", "","", "", "" ],
1703 [ "", "", "","", "", "" ],
1704 ];
1705 } else {
1706 container_RCC_ADDED = data;
1707 }
1708
1709 container_RCC_ADDED = document.getElementById("container_RCC_ADDED-{{ TAB_INDEX_PLACEHOLDER }}");
1710 self.hot_RCC_ADDED = new Handsontable(container_RCC_ADDED, {
1711 data: data_RCC_ADDED,
1712 minSpareRows : 1,
1713 colHeaders : true,
1714 colHeaders: [
1715 "common name",
1716 "<b>InChIKey</b>",
1717 "composition",
1718 "<b>concentration (&micro;g/ml)</b>",
1719 "exact mass",
1720 "(M+H)+ or (M-H)-"
1721 ],
1722 contextMenu : false,
1723 columns: colHeaderData
1724 });
1725 function bindDumpButton_RCC_ADDED() {
1726 Handsontable.Dom.addEvent(document.body, "click", (e) => {
1727 var element = e.target || e.srcElement;
1728 if (element.nodeName == "BUTTON"&& element.name == "dump") {
1729 var name = element.getAttribute("data-dump");
1730 var instance = element.getAttribute("data-instance");
1731 self.hot_RCC_ADDED = window[instance];
1732 console.log("data of " + name, self.hot_RCC_ADDED.getData());
1733 }
1734 });
1735 }
1736 bindDumpButton_RCC_ADDED();
1737 $("#container_RCC_ADDED-{{ TAB_INDEX_PLACEHOLDER }} table.htCore").css("width","100%");
1738 // celect cell
1739 self.hot_RCC_ADDED.selectCell(0, 0);
1740 // add select listener
1741 self.hot_RCC_ADDED.addHook("afterSelection", (r, c) => self.hookSelection(r, c));
1742 },
1743
1744 //USED HERE
1745 hookSelection: function(r, c) {
1746 var self = this ;
1747 if (c == 0 || c == 1 || c == 2)
1748 self.pickChemicalCompound4Mix(r);
1749 },
1750
1751 //USED HERE
1752 postOneSpectrumFrom: function() {
1753 var self = this ;
1754 $("#import1SpectrumLoadingBare-{{ TAB_INDEX_PLACEHOLDER }}").show();
1755
1756 // II - form data -> json object
1757 self.loadFomDataIntoJsonObjects();
1758 // II.A - check if json object complete
1759 var alertMsg = self.getFormErrorMessage();
1760
1761 if (alertMsg != "") {
1762 $("#alertBoxSubmitSpectrum-{{ TAB_INDEX_PLACEHOLDER }}").html(alertMsg);
1763 $("#import1SpectrumLoadingBare-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1764 return false;
1765 }
1766 // all OK: lock!
1767 // lock sample
1768 $(self.prefix+".add1spectrum-sampleForm").prop("disabled", true);
1769 // lock chromato
1770 $(self.prefix+".add1spectrum-chromatoLCForm").prop("disabled", true);
1771 if (!$("#container_LC_SFG-{{ TAB_INDEX_PLACEHOLDER }}").is(":empty")) {
1772 self.hot_LC_SFG.updateSettings({
1773 cells: function(row, col, prop) {
1774 var cellProperties = {};
1775 cellProperties.readOnly = true;
1776 return cellProperties;
1777 }
1778 });
1779 }
1780 if (!$("#container_MS_Peaks-{{ TAB_INDEX_PLACEHOLDER }}").is(":empty")) {
1781 self.hot_MS_Peaks.updateSettings({
1782 cells: function(row, col, prop) {
1783 var cellProperties = {};
1784 cellProperties.readOnly = true;
1785 return cellProperties;
1786 }
1787 });
1788 }
1789 if (!$("#container_RCC_ADDED-{{ TAB_INDEX_PLACEHOLDER }}").is(":empty")) {
1790 self.hot_RCC_ADDED.updateSettings({
1791 cells: function(row, col, prop) {
1792 var cellProperties = {};
1793 cellProperties.readOnly = true;
1794 return cellProperties;
1795 }
1796 });
1797 self.hot_RCC_ADDED.removeHook(
1798 "afterSelection",
1799 (r, c) => self.hookSelection(r, c)
1800 );
1801 }
1802
1803 // lock analyzer
1804 $(self.prefix+".add1spectrum-analyzerMSForm").prop("disabled", true);
1805 // lock other metadata field
1806 $(self.prefix+".add1spectrum-otherForm").prop("disabled", true);
1807 // lock switch btn
1808 $("#btnSwitch-gotoStep2-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", true);
1809 $("#btnSwitch-gotoStep3-lc-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", true);
1810 $("#btnSwitch-gotoStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}").prop("disabled", true);
1811 self.postSpectrumToServer() ;
1812 },
1813
1814 postSpectrumToServer: function(jsonData, tab_index) {
1815 var self = this ;
1816 var base_peakdata ;
1817 var new_peakdata ;
1818 var is_ms2 = self.is_ms2() ;
1819
1820 if (self.is_mix()) {
1821 if ({{ TAB_INDEX_PLACEHOLDER }} != 1) {
1822 return ;
1823 }
1824 jsonData = self.gatherJsonObjects() ;
1825 all_mix_data = Object.assign({}, jsonData) ;
1826 all_mix_data["peaklists"] = [] ;
1827 base_peakdata = Object.assign({}, jsonData["peaklists"][0]) ;
1828 all_contexts.forEach((context, index) => {
1829 if (context === null) {
1830 return;
1831 }
1832 new_peakdata = Object.assign({}, base_peakdata) ;
1833 context.loadFomDataIntoJsonObjects()
1834 if (is_ms2) {
1835 new_peakdata["precursor_ion"] = context.jsonPeaksList["precursor_ion"] ;
1836 }
1837 new_peakdata["peaklist"] = context.jsonPeaksList["peaklist"] ;
1838 all_mix_data["peaklists"].push(new_peakdata)
1839 })
1840 }
1841 // II.B - rebuild json full object (with all metadata or just id if already in base)
1842 if (jsonData == null) {
1843 jsonData = self.gatherJsonObjects();
1844 }
1845 // II.C - add id metadata (if exist)
1846 var json_array = [] ;
1847 if (!tab_index) {
1848 tab_index = {{ TAB_INDEX_PLACEHOLDER }} ;
1849 }
1850 json_array[tab_index-1] = jsonData ;
1851
1852 // III - post json object
1853 // III.A - success
1854 self.sent_json = jsonData ;
1855 console.warn(
1856 "This data has been validated without going through the internal server!"
1857 )
1858 if ($("#step5sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-question-circle")) {
1859 $("#step5sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-question-circle").addClass("fa-check-circle");
1860 }
1861 if ($("#step5sign-{{ TAB_INDEX_PLACEHOLDER }}").hasClass("fa-spinner")) {
1862 $("#step5sign-{{ TAB_INDEX_PLACEHOLDER }}").removeClass("fa-spinner fa-spin").addClass("fa-check-circle");
1863 }
1864 $("#import1SpectrumLoadingBare-{{ TAB_INDEX_PLACEHOLDER }}").hide();
1865 $("#alertBoxSubmitSpectrum-{{ TAB_INDEX_PLACEHOLDER }}").html(`
1866 <div class="alert alert-success alert-dismissible" role="alert">
1867 <button type="button" class="close" data-dismiss="alert">
1868 <span aria-hidden="true">&times;</span>
1869 <span class="sr-only">
1870 <spring:message code="alert.close" text="Close" />
1871 </span>
1872 </button>
1873 <strong>
1874 <spring:message code="alert.strong.info" text="Success!" />
1875 </strong> Spectrum ready to be sent!
1876 </div>
1877 `);
1878 return true;
1879 },
1880
1881 //USED HERE
1882 loadFomDataIntoJsonObjects: function() {
1883 var self = this ;
1884 // I - Spectrum type
1885 self.isJsonSpectrumTypeComplete = false ;
1886 if (self.isGC && self.is_ms()) {
1887 self.jsonSpectrumType = "gc-ms" ;
1888 } else if (self.isLC && self.is_ms()) {
1889 self.jsonSpectrumType = "lc-ms" ;
1890 } else if (self.isLC && self.is_ms2()) {
1891 self.jsonSpectrumType = "lc-msms" ;
1892 } else if (self.isGC && self.is_ms()) {
1893 self.jsonSpectrumType = "ic-ms" ;
1894 } else if (self.isLC && self.is_ms()) {
1895 self.jsonSpectrumType = "ic-msms" ;
1896 }
1897 if (self.jsonSpectrumType != null && self.jsonSpectrumType != "") {
1898 self.isJsonSpectrumTypeComplete = true;
1899 }
1900
1901 // II - Sample
1902 self.isJsonSampleComplete = true;
1903 self.isJsonRCCaddedComplete = true;
1904 self.jsonSample = {};
1905
1906 switch($("#add1spectrum-sample-type-{{ TAB_INDEX_PLACEHOLDER }}").val()) {
1907 // II.A - chemical lib. compound
1908 case "compound-ref":
1909 if ($("#add1spectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}").val() == "") {
1910 return false;
1911 }
1912 self.jsonSample["sample_type"] = "reference-chemical-compound";
1913 self.jsonSample["inchikey"] = $("#add1spectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}").val();
1914 self.jsonSample["concentration"] = $("#add1spectrum-sample-concentration-{{ TAB_INDEX_PLACEHOLDER }}").val();
1915 if (self.is_ms()) {
1916 self.jsonSample["solvent"] = $("#add1spectrum-sample-lcmsSolvent-{{ TAB_INDEX_PLACEHOLDER }}").val();
1917 }
1918 self.isJsonSampleComplete = true;
1919 break;
1920 // II.B - chemical lib. compound mix
1921 case "compound-mix":
1922 // solvent
1923 self.jsonSample["solvent"] = $("#add1spectrum-sample-mixSolvent-{{ TAB_INDEX_PLACEHOLDER }}").val();
1924 // cpd added
1925 self.jsonSample.inchikeys_list = self.getRCCADDED();
1926 self.jsonSample.concentrations_list = self.getRCCADDEDConcentration();
1927 if (self.jsonSample.inchikeys_list.length == 0 && !self.is_other_in_mix()) {
1928 self.isJsonRCCaddedComplete = false;
1929 console.log(`isJsonRCCaddedComplete: false`)
1930 return false;
1931 }
1932 self.isJsonSampleComplete = true;
1933 break;
1934 default:
1935 if (!self.is_other_in_mix()) {
1936 return false;
1937 }
1938 }
1939
1940 // III - Chromato
1941 self.isJsonChromatoComplete = true;
1942 self.jsonChromato = {};
1943
1944 // III.A - no chromato
1945 // nope?
1946
1947 // III.B - GC
1948 if (self.isGC) {
1949 self.isJsonChromatoComplete = false;
1950 // TODO
1951 }
1952
1953 // III.C - LC
1954 if (self.isLC) {
1955 self.isJsonChromatoComplete = true;
1956 self.jsonChromato = {};
1957 // check error
1958 $.each($(self.prefix+".add1spectrum-chromatoLCForm").parent(), function() {
1959 if ($(this).hasClass("has-error"))
1960 self.isJsonChromatoComplete = false;
1961 });
1962 if (
1963 !self.isJsonChromatoComplete
1964 && !self.is_other_in_mix()
1965 ) {
1966 console.log(`isJsonChromatoComplete: false`)
1967 return false;
1968 }
1969 var id = `#add1spectrum-chromatoLC-method-{{ TAB_INDEX_PLACEHOLDER }}` ;
1970 self.jsonChromato["method"] = $(`${id} option:selected`).text();
1971 [
1972 ["column_constructor", "colConstructor"],
1973 ["column_constructor_other", "colConstructorOther"],
1974 ["column_name", "colName"],
1975 ["column_length", "colLength"],
1976 ["column_diameter", "colDiameter"],
1977 ["particule_size", "colParticuleSize"],
1978 ["column_temperature", "colTemperature"],
1979 ["mode", "LCMode"],
1980 ["separation_flow_rate", "separationFlowRate"],
1981 ["solvent_a", "separationSolvA"],
1982 ["solvent_a_ph", "separationSolvApH"],
1983 ["solvent_b", "separationSolvB"],
1984 ["solvent_b_ph", "separationSolvBApH"]
1985 ].forEach((field) => {
1986 id = `#add1spectrum-chromatoLC-${field[1]}-{{ TAB_INDEX_PLACEHOLDER }}` ;
1987 self.jsonChromato[field[0]] = $(id).val();
1988 })
1989 // fulfill json object
1990
1991 jsonSFG = [];
1992 var formatData = {
1993 time: [],
1994 solvent_a_percent: [],
1995 solvent_b_percent: []
1996 };
1997 var uniq_times = [] ;
1998 $.each(self.hot_LC_SFG.getData(), function() {
1999 var time = this[0] ;
2000 if (time != "" && time !== null) {
2001 if (
2002 !isNaN(time)
2003 && !isNaN(this[1])
2004 && !isNaN(this[2])
2005 && ! (time in uniq_times)
2006 ) {
2007 formatData["time"].push(Number(time));
2008 formatData["solvent_a_percent"].push(Number(this[1]));
2009 formatData["solvent_b_percent"].push(Number(this[2]));
2010 uniq_times.push(time) ;
2011 }
2012 }
2013 });
2014 self.jsonChromato.separation_flow_gradient = formatData;
2015 }
2016
2017 // III.D - IC
2018 if (self.isIC) {
2019 self.isJsonChromatoComplete = false;
2020 // TODO
2021 }
2022
2023 // IV - Analyzer
2024 self.isJsonAnalyzerComplete = true;
2025 self.isJsonAnalyzer = {};
2026 // IV.A - MS
2027 if (self.is_ms() || self.is_ms2()) {
2028 self.isJsonAnalyzerComplete = true;
2029 self.jsonAnalyzer = {};
2030 // check error
2031 $.each($(self.prefix+".add1spectrum-analyzerMSForm").parent(), function(){
2032 if ($(this).hasClass("has-error"))
2033 self.isJsonAnalyzerComplete = false;
2034 });
2035 if (
2036 !self.isJsonAnalyzerComplete
2037 && !self.is_other_in_mix()
2038 ) {
2039 console.log(`isJsonAnalyzerComplete: false`)
2040 return false;
2041 }
2042
2043 // fulfill json object
2044 self.jsonAnalyzer["instrument_name"] = $("#add1spectrum-analyzer-ms-instrument-{{ TAB_INDEX_PLACEHOLDER }}").val();
2045 self.jsonAnalyzer["instrument_model"] = $("#add1spectrum-analyzer-ms-model-{{ TAB_INDEX_PLACEHOLDER }}").val();
2046 self.jsonAnalyzer["instrument_brand"] = $("#add1spectrum-analyzer-ms-model-{{ TAB_INDEX_PLACEHOLDER }}").val();
2047 self.jsonAnalyzer["ion_analyzer_type"] = $("#add1spectrum-analyzer-ms-ionAnalyzerType-{{ TAB_INDEX_PLACEHOLDER }}").val();
2048
2049 if (self.is_ms2()) {
2050 // MSMS ion BEAM or TRAP
2051 self.jsonMolIonBeam = {}
2052 var jsonIonTrapBeam = {
2053 ion_gas: $("#add1spectrum-ionTrapBeam-ionGas-{{ TAB_INDEX_PLACEHOLDER }}").val(),
2054 ion_pressure_value: $("#add1spectrum-ionTrapBeam-ionGasPressureValue-{{ TAB_INDEX_PLACEHOLDER }}").val(),
2055 ion_pressure_unit: $("#add1spectrum-ionTrapBeam-ionGasPressureUnit-{{ TAB_INDEX_PLACEHOLDER }}").val()
2056 } ;
2057 var key = null ;
2058 if ($("#add1spectrum-ionTrapBeam-type-{{ TAB_INDEX_PLACEHOLDER }}").val() == "trap") {
2059 // sp
2060 jsonIonTrapBeam["ion_freq_shift"] = $("#add1spectrum-ionTrapBeam-ionFrequencyShift-{{ TAB_INDEX_PLACEHOLDER }}").val();
2061 jsonIonTrapBeam["ion_number"] = $("#add1spectrum-ionTrapBeam-ionNumber-{{ TAB_INDEX_PLACEHOLDER }}").val();
2062 key = "ion_trap" ;
2063 } else if ($("#add1spectrum-ionTrapBeam-type-{{ TAB_INDEX_PLACEHOLDER }}").val() == "beam") {
2064 key = "ion_beam_storage" ;
2065 }
2066 if (key !== null) {
2067 self.jsonMolIonBeam[key] = jsonIonTrapBeam;
2068 }
2069 }
2070
2071 self.jsonMolIonization = {};
2072 var json_mode ;
2073 ["pos", "neg"].forEach((kind) => {
2074 json_mode = {} ;
2075 [
2076 ["ionisation_method", "ionizationMethod"],
2077 ["spray_gas_flow", "sprayGazFlow"],
2078 ["vaporizer_gas_flow", "vaporizerGazFlow"],
2079 ["vaporizer_temperature", "vaporizerTemperature"],
2080 ["source_gas_flow", "sourceGazFlow"],
2081 ["transfer_tube_or_capillary_temperature", "ionTransferTubeTemperatureOrTransferCapillaryTemperature"],
2082 ["high_voltage", "highVoltageOrCoronaVoltage"]
2083 ].forEach((field) => {
2084 var id = `#add1spectrum-analyzserMS-${field[1]}-${kind}-{{ TAB_INDEX_PLACEHOLDER }}` ;
2085 json_mode[field[0]] = $(id).val() ;
2086 })
2087 self.jsonMolIonization[`mode_${kind}`] = json_mode ;
2088 })
2089 }
2090
2091 // IV.B - NMR
2092 if (self.is_ms() || self.is_ms2()) {
2093 self.isJsonPeaksListComplete = false;
2094 // init
2095 var peaklist = [];
2096 var peakdata = {};
2097 var spectrumData = {};
2098 // peaklist
2099 var ms_peak_data = self.hot_MS_Peaks.getData();
2100 $.each(ms_peak_data, function(index) {
2101 var data = ms_peak_data[index] ;
2102 var formatData = {};
2103 if (
2104 data[0] != ""
2105 && !isNaN(data[0])
2106 // && !isNaN(data[2])
2107 && (data[6] === "true" || data[6] === true)
2108 ) {
2109 peaklist.push({
2110 mz: Number(data[0]),
2111 ri: Number(data[2]),
2112 delta_ppm: Number(data[3]),
2113 composition: (data[4]),
2114 annotation: (data[5])
2115 });
2116 self.isJsonPeaksListComplete = true;
2117 }
2118 });
2119 // peak list data
2120 peakdata["scan_type"] = (
2121 self.is_ms2() ? "ms2" : "ms"
2122 );
2123 peakdata["polarity"] = $("#add1spectrum-peaksMS-polarity-{{ TAB_INDEX_PLACEHOLDER }}").val();
2124 peakdata["resolution"] = $("#add1spectrum-peaksMS-resolution-{{ TAB_INDEX_PLACEHOLDER }}").val();
2125 peakdata["curation"] = $("#add1spectrum-peaksMS-curation-{{ TAB_INDEX_PLACEHOLDER }}").val();
2126 peakdata["mz_from"] = $("#add1spectrum-peaksMS-rangeFrom-{{ TAB_INDEX_PLACEHOLDER }}").val();
2127 peakdata["mz_to"] = $("#add1spectrum-peaksMS-rangeTo-{{ TAB_INDEX_PLACEHOLDER }}").val();
2128 peakdata["retention_min_time_from"] = $("#add1spectrum-peaksMS-rtMinFrom-{{ TAB_INDEX_PLACEHOLDER }}").val();
2129 peakdata["retention_min_time_to"] = $("#add1spectrum-peaksMS-rtMinTo-{{ TAB_INDEX_PLACEHOLDER }}").val();
2130 peakdata["rt_solv_from"] = $("#add1spectrum-peaksMS-rtSolvFrom-{{ TAB_INDEX_PLACEHOLDER }}").val();
2131 peakdata["rt_solv_to"] = $("#add1spectrum-peaksMS-rtSolvTo-{{ TAB_INDEX_PLACEHOLDER }}").val();
2132 peakdata["resolution_FWHM"] = $("#add1spectrum-analyzer-ms-resolutionFWHM-{{ TAB_INDEX_PLACEHOLDER }}").val();
2133 if (self.is_ms2()) {
2134 var data = self.hot_MS_Peaks.getData() ;
2135 if (data.length != 0) {
2136 var selected_ion = self.get_selected_parent_ion_index() ;
2137 if (selected_ion !== null) {
2138 peakdata["precursor_ion"] = data[selected_ion][0] ;
2139 peakdata["precursor_spectrum_id"] = null ;
2140 } else {
2141 peakdata["precursor_ion"] = self.get_selected_parent_ion_mz() ;
2142 peakdata["precursor_spectrum_id"] = null ;
2143 }
2144 }
2145 }
2146 peakdata["peaklist"] = peaklist;
2147 self.jsonPeaksList = peakdata;
2148 }
2149
2150 self.isJsonOtherMetadataComplete = true;
2151 self.jsonOtherMetadata = {};
2152 // check error
2153 $.each($(self.prefix+".add1spectrum-otherForm").parent(), function(){
2154 if ($(this).hasClass("has-error"))
2155 self.isJsonOtherMetadataComplete = false;
2156 });
2157 if (!self.isJsonOtherMetadataComplete && !self.is_other_in_mix()) {
2158 console.log(`isJsonOtherMetadataComplete: false`)
2159 return false;
2160 }
2161 self.jsonOtherMetadata["data_authors"] = $("#add1spectrum-other-author-{{ TAB_INDEX_PLACEHOLDER }}").val();
2162 self.jsonOtherMetadata["data_validator"] = $("#add1spectrum-other-validator-{{ TAB_INDEX_PLACEHOLDER }}").val();;
2163 self.jsonOtherMetadata["acquisition_date"] = $("#add1spectrum-other-date-{{ TAB_INDEX_PLACEHOLDER }}").val();
2164 if (!self.jsonOtherMetadata["acquisition_date"]) {
2165 self.jsonOtherMetadata["acquisition_date"] = null ;
2166 }
2167 self.jsonOtherMetadata["data_ownership"] = $("#add1spectrum-other-owner-{{ TAB_INDEX_PLACEHOLDER }}").val();
2168 self.jsonOtherMetadata["raw_file_name"] = $("#add1spectrum-other-fileName-{{ TAB_INDEX_PLACEHOLDER }}").val();
2169 self.jsonOtherMetadata["raw_file_size"] = $("#add1spectrum-other-fileSize-{{ TAB_INDEX_PLACEHOLDER }}").val();
2170 return true;
2171 },
2172
2173 //USED HERE
2174 getFormErrorMessage: function() {
2175 var self = this ;
2176 var alertMsg = "";
2177 if (!self.isJsonSpectrumTypeComplete) {
2178 alertMsg = `
2179 <div class="alert alert-danger alert-dismissible" role="alert">
2180 <button type="button" class="close" data-dismiss="alert">
2181 <span aria-hidden="true">&times;</span>
2182 <span class="sr-only">
2183 <spring:message code="alert.close" text="Close" />
2184 </span>
2185 </button>
2186 <strong>
2187 <spring:message code="alert.strong.error" text="Error!" />
2188 </strong> Error processing spectrum type!
2189 </div>` ;
2190 } else if (!self.isJsonSampleComplete) {
2191 alertMsg = `
2192 <div class="alert alert-danger alert-dismissible" role="alert">
2193 <button type="button" class="close" data-dismiss="alert">
2194 <span aria-hidden="true">&times;</span>
2195 <span class="sr-only">
2196 <spring:message code="alert.close" text="Close" />
2197 </span>
2198 </button>
2199 <strong>
2200 <spring:message code="alert.strong.error" text="Error!" />
2201 </strong> Missing mandatory data into sample section!
2202 <br />
2203 <a
2204 href="#"
2205 onclick="$('#linkActivateStep1-{{ TAB_INDEX_PLACEHOLDER }}').trigger('click');"
2206 >Go to this section</a>
2207 </div>` ;
2208 } else if (!self.isJsonRCCaddedComplete) {
2209 alertMsg = `
2210 <div class="alert alert-danger alert-dismissible" role="alert">
2211 <button type="button" class="close" data-dismiss="alert">
2212 <span aria-hidden="true">&times;</span>
2213 <span class="sr-only">
2214 <spring:message code="alert.close" text="Close" />
2215 </span>
2216 </button>
2217 <strong>
2218 <spring:message code="alert.strong.error" text="Error!" />
2219 </strong> Pease enter at least ONE compound in mix into sample section!
2220 <br />
2221 <a
2222 href="#"
2223 onclick="$('#linkActivateStep1-{{ TAB_INDEX_PLACEHOLDER }}').trigger('click');"
2224 >Go to this section</a>
2225 </div>`;
2226 } else if (!self.isJsonChromatoComplete) {
2227 alertMsg = `
2228 <div class="alert alert-danger alert-dismissible" role="alert">
2229 <button type="button" class="close" data-dismiss="alert">
2230 <span aria-hidden="true">&times;</span>
2231 <span class="sr-only">
2232 <spring:message code="alert.close" text="Close" />
2233 </span>
2234 </button>
2235 <strong>
2236 <spring:message code="alert.strong.error" text="Error!" />
2237 </strong> Missing data in chromatography section!
2238 ` ;
2239 if (self.is_ms()) {
2240 alertMsg += `
2241 <br />
2242 <a
2243 href="#"
2244 onclick="$('#linkActivateStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}').trigger('click');"
2245 >Go to this section</a>`;
2246 }
2247 alertMsg += ' </div>';
2248 } else if (!self.isJsonPeaksListComplete) {
2249 alertMsg = `
2250 <div class="alert alert-danger alert-dismissible" role="alert">
2251 <button type="button" class="close" data-dismiss="alert">
2252 <span aria-hidden="true">&times;</span>
2253 <span class="sr-only">
2254 <spring:message code="alert.close" text="Close" />
2255 </span>
2256 </button>
2257 <strong>
2258 <spring:message code="alert.strong.error" text="Error!" />
2259 </strong> Missing peaklist!
2260 ` ;
2261 if (self.is_ms()) {
2262 alertMsg += `
2263 <br />
2264 <a
2265 href="#"
2266 onclick="$('#linkActivateStep4-ms-{{ TAB_INDEX_PLACEHOLDER }}').trigger('click');"
2267 >Go to this section</a>`;
2268 }
2269 alertMsg += ' </div>';
2270 } else if (self.is_mix() && self.is_ms2()) {
2271 for (var i = 0 ; i < all_contexts.length ; i += 1) {
2272 if (all_contexts[i] === null || all_contexts[i] === undefined) {
2273 continue;
2274 }
2275 if (all_contexts[i].get_selected_parent_ion_index() === null) {
2276 return alertMsg + `
2277 <div class="alert alert-danger alert-dismissible" role="alert">
2278 <button type="button" class="close" data-dismiss="alert">
2279 <span aria-hidden="true">&times;</span>
2280 <span class="sr-only">
2281 <spring:message code="alert.close" text="Close" />
2282 </span>
2283 </button>
2284 <strong>
2285 <spring:message code="alert.strong.error" text="Error!" />
2286 </strong> Select precursor ion in all peak lists!
2287 </div>
2288 `
2289 }
2290 }
2291 }
2292 // TODO other
2293 return alertMsg;
2294 },
2295
2296 //USED HERE
2297 gatherJsonObjects: function() {
2298 var self = this ;
2299 var jsonData = {};
2300 if (self.is_mix()) {
2301 jsonData["sample_type"] = "mix_of_reference_chemical_compounds" ;
2302 } else {
2303 jsonData["sample_type"] = "reference_chemical_compound" ;
2304 }
2305 jsonData["spectrum_type"] = self.jsonSpectrumType.toUpperCase().replaceAll("-", "");
2306 jsonData["sample"] = self.jsonSample;
2307 if (self.isLC) {
2308 jsonData["chromatography"] = self.jsonChromato;
2309 } else if (self.isGC) {
2310 jsonData["chromatography"] = self.jsonChromato;
2311 } else if (self.isIC) {
2312 jsonData["chromatography"] = self.jsonChromato;
2313 }
2314 if (self.is_ms()) {
2315 jsonData["analyzer"] = self.jsonAnalyzer;
2316 var molecule_ionization = self.jsonMolIonization;
2317 jsonData["ionization_mode_positive"] = molecule_ionization["mode_pos"] ;
2318 jsonData["ionization_mode_negative"] = molecule_ionization["mode_neg"] ;
2319 jsonData["peaklists"] = [self.jsonPeaksList] ;
2320 } else if (self.is_ms2()) {
2321 jsonData["analyzer"] = self.jsonAnalyzer;
2322 var molecule_ionization = self.jsonMolIonization;
2323 jsonData["ionization_mode_positive"] = molecule_ionization["mode_pos"] ;
2324 jsonData["ionization_mode_negative"] = molecule_ionization["mode_neg"] ;
2325 if (self.jsonMolIonBeam != null) {
2326 jsonData["ion_beam_storage"] = self.jsonMolIonBeam["ion_beam_storage"];
2327 }
2328 jsonData["peaklists"] = [self.jsonPeaksList] ;
2329 }
2330 jsonData["other_metadata"] = self.jsonOtherMetadata;
2331 return jsonData;
2332 },
2333
2334 //USED IN HTML
2335 pickChemicalCompound: function() {
2336 var self = this ;
2337 self.singlePick = true;
2338 $("#modalPickCompound-{{ TAB_INDEX_PLACEHOLDER }}").modal("show");
2339 $("#add-one-cc-s1-value-{{ TAB_INDEX_PLACEHOLDER }}").focus();
2340 },
2341
2342 //USED HERE
2343 pickChemicalCompound4Mix: function(rowNumber) {
2344 var self = this ;
2345 self.singlePick = false;
2346 self.multiPickLine = rowNumber;
2347 $("#modalPickCompound-{{ TAB_INDEX_PLACEHOLDER }}").modal("show");
2348 $("#add-one-cc-s1-value-{{ TAB_INDEX_PLACEHOLDER }}").focus();
2349 },
2350
2351 //USED HERE
2352 searchAjax: function() {
2353 var self = this ;
2354 var results ;
2355 var rawQuery = $('#add-one-cc-s1-value-{{ TAB_INDEX_PLACEHOLDER }}').val();
2356 if (rawQuery.length > 2) {
2357 return [] ;
2358 }
2359 results = [] ;
2360 $.ajax({
2361 type: "post",
2362 url: "{{ PF_URL_PLACEHOLDER }}/webapp/search",
2363 dataType: "json",
2364 async: false,
2365 data: "query=" + $("#add-one-cc-s1-value-{{ TAB_INDEX_PLACEHOLDER }}").val(),
2366 success: function(json) {
2367 if (json.success) {
2368 $.each(json.compoundNames, function(){
2369 results.push(this.name) ;
2370 }) ;
2371 $.each(json.compounds, function(){
2372 if (this.inChIKey.indexOf(rawQuery)) {
2373 results.push(this.inChIKey) ;
2374 }
2375 }) ;
2376 }
2377 },
2378 error : function(xhr) {
2379 self.subjects = [] ;
2380 console.log(xhr) ;
2381 }
2382 }) ;
2383 return results ;
2384 },
2385
2386 //USED HERE
2387 searchLocalCompound: function() {
2388 var self = this ;
2389 $("#load-step-1-{{ TAB_INDEX_PLACEHOLDER }}").show();
2390 $.ajax({
2391 type: "get",
2392 url: "{{ PF_URL_PLACEHOLDER }}/rest/v2/compounds",
2393 async: true,
2394 data: "limit=1&query=" + $('#add-one-cc-s1-value-{{ TAB_INDEX_PLACEHOLDER }}').val() + "&query_filter=" + self.fitlerSearchLoadlCpd+"&token={{ PF_TOKEN_PLACEHOLDER }}",
2395 success: function(data) {
2396 data = data[0] ;
2397 var id = parseInt(data["id"]) ;
2398 var name = data["name"] ;
2399 var inchikey = data["inchikey"] ;
2400 var inchi = data["inchi"] ;
2401 data = `
2402 <div class="table-responsive">
2403 <table id="tabPickCpd-{{ TAB_INDEX_PLACEHOLDER }}" class="table table-bordered table-hover table-striped tablesorter" style="cursor: pointer;">
2404 <thead>
2405 <tr>
2406 <th class="header">Chemical Name <i class="fa fa-sort"></i></th>
2407 <th class="header">Monoisotopic Mass <i class="fa fa-sort"></i></th>
2408 <th class="header">Formula <i class="fa fa-sort"></i></th>
2409 <th class="header" style="">Structure</th>
2410 </tr>
2411 </thead>
2412 <tbody>
2413 <tr class="success" onclick="loadCompoundInForm(${id}, '${inchikey}', '${inchi}', '${data["formula"]}', '${data["exactMass"]}' , 100);">
2414 <td style="vertical-align: middle;">
2415 <span id="cpt-load-name-${id}-{{ TAB_INDEX_PLACEHOLDER }}">${name}</span>
2416 <br><small style="white-space: nowrap;">${inchikey}</small>
2417 </td>
2418 <td style="vertical-align: middle;" class="compoundMass">${data["exactMass"]}</td>
2419 <td style="vertical-align: middle;" class="compoundFormula">${data["formula"]}</sub></td>
2420 <td><span class="avatar">
2421 <img class="compoundSVG" src="{{ PF_URL_PLACEHOLDER }}/webapp/image/generic/${inchikey}" alt="${name}">
2422 </span>
2423 </td>
2424 </tr>
2425 </tbody>
2426 </table>
2427 <small><sup><b>*</b></sup>: Generic Compounds (abstract "flat" compound without (+) or (-) center).</small>
2428 <` + "script" + ` type="text/javascript">
2429 $("#tabPickCpd-{{ TAB_INDEX_PLACEHOLDER }}").tablesorter();
2430 $.each($(self.prefix+".compoundFormula"), function(id, elem) {
2431 var rawFromula = $(elem).text();
2432 var formatedFormula = rawFromula;
2433 try {
2434 $.each($.unique( rawFromula.match(/\d+/g)), function(keyF, valF) {
2435 var re = new RegExp(valF,"g");
2436 formatedFormula = formatedFormula.replace(re, "<sub>" + valF + "</sub>");
2437 });
2438 } catch (e){}
2439 formatedFormula = formatedFormula.replace("</sub><sub>", "");
2440 $(elem).html(formatedFormula);
2441 });
2442 $.each($(self.prefix+".compoundMass"), function(id, elem) {
2443 var exactMass = parseFloat( $(elem).text());
2444 exactMass = roundNumber(exactMass,7)
2445 $(elem).html(exactMass);
2446 });
2447 </` + "script" + `>
2448
2449 </div>
2450 <` + "script" + ` type="text/javascript">
2451 var listOfRefCompoundsMatch = null;
2452
2453 loadCompoundInForm = function(id, inchikey, inchi, composition, exactMass, type) {
2454 if (ctx().modeEditSpectrum) {
2455 var name = $("#cpt-load-name-" + id + "-{{ TAB_INDEX_PLACEHOLDER }}").html();
2456 if (ctx().multiPickLine >= 0) {
2457 ctx().hot_RCC_ADDED.setDataAtCell(ctx().multiPickLine, 0, name);
2458
2459 // restet form
2460 setTimeout(function(){
2461 $("#add-one-cc-s1-value-{{ TAB_INDEX_PLACEHOLDER }}").val("");
2462 $("#ok-step-1-{{ TAB_INDEX_PLACEHOLDER }}").html("");
2463 }, 200);
2464 // img
2465 var typeS = "chemical";
2466 if (type == 100)
2467 typeS = "generic";
2468 else if (type == 101)
2469 typeS = "chemical";
2470 // '<img class="mixRCCadd'+ctx().multiPickLine+' compoundSVGZoom" src="{{ PF_URL_PLACEHOLDER }}/webapp/image/'+typeS+'/'+inchikey+'" alt="'+name+'">'
2471 var currentCpt = {
2472 "name": name,
2473 "type": typeS,
2474 "concentration": "?",
2475 "inchikey": inchikey
2476 };
2477 updatedCpdMixData[name] = currentCpt;
2478 }
2479 // display
2480 $("#modalPickCompound-{{ TAB_INDEX_PLACEHOLDER }}").modal("hide");
2481 $("#modalEditSpectrum-{{ TAB_INDEX_PLACEHOLDER }} .modal-dialog").show();
2482 return;
2483 } // else: add one spectrum
2484 var name = $("#cpt-load-name-" + id + "-{{ TAB_INDEX_PLACEHOLDER }}").html();
2485 if (ctx().singlePick) {
2486 $("#add1spectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}").val(inchikey);
2487 $("#add1spectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}").change();
2488 $("#add1spectrum-sample-inchi-{{ TAB_INDEX_PLACEHOLDER }}").val(inchi);
2489 $("#add1spectrum-sample-inchi-{{ TAB_INDEX_PLACEHOLDER }}").change();
2490 $("#add1spectrum-sample-commonName-{{ TAB_INDEX_PLACEHOLDER }}").val(name);
2491 $("#add1spectrum-sample-commonName-{{ TAB_INDEX_PLACEHOLDER }}").change();
2492
2493 $("#importspectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}").val(inchikey);
2494 $("#importspectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}").change();
2495 } else if (ctx().multiPickLine >= 0) {
2496 ctx().hot_RCC_ADDED.setDataAtCell(ctx().multiPickLine, 0, name);
2497 ctx().hot_RCC_ADDED.setDataAtCell(ctx().multiPickLine, 1, inchikey);
2498 ctx().hot_RCC_ADDED.setDataAtCell(ctx().multiPickLine, 2, composition);
2499 ctx().hot_RCC_ADDED.setDataAtCell(ctx().multiPickLine, 4, exactMass);
2500 // restet form
2501 setTimeout(function(){
2502 $("#add-one-cc-s1-value-{{ TAB_INDEX_PLACEHOLDER }}").val("");
2503 $("#ok-step-1-{{ TAB_INDEX_PLACEHOLDER }}").html("");
2504 }, 200);
2505 }
2506 var typeS = "chemical";
2507 if (type == 100)
2508 typeS = "generic";
2509 else if (type == 101)
2510 typeS = "chemical";
2511 if (ctx().singlePick)
2512 $("#sample-bonus-display-{{ TAB_INDEX_PLACEHOLDER }}").html('<img class="" src="{{ PF_URL_PLACEHOLDER }}/webapp/image/'+typeS+'/'+inchikey+'" alt="'+name+'">');
2513 else {
2514 // delete
2515 $(ctx().prefix+"img.mixRCCadd"+ctx().multiPickLine).remove();
2516 // add
2517 $("#sample-bonus-display-{{ TAB_INDEX_PLACEHOLDER }}").append('<img class="mixRCCadd'+ctx().multiPickLine+' compoundSVGZoom" src="{{ PF_URL_PLACEHOLDER }}/webapp/image/'+typeS+'/'+inchikey+'" alt="'+name+'">');
2518 $(ctx().prefix+"img.mixRCCadd"+ctx().multiPickLine+"").mouseenter(function() {
2519 $(this).removeClass("compoundSVGZoom");
2520 }).mouseleave(function() {
2521 $(this).addClass("compoundSVGZoom");
2522 });
2523 }
2524 $("#modalPickCompound-{{ TAB_INDEX_PLACEHOLDER }}").modal("hide");
2525 }
2526 </` + "script" + `></` + "div" + `>` ;
2527 $("#ok-step-1-{{ TAB_INDEX_PLACEHOLDER }}").html(data);
2528 },
2529 error : function(xhr) {
2530 // log
2531 console.log(xhr);
2532 // error
2533 $("#ok-step-1-{{ TAB_INDEX_PLACEHOLDER }}").html("Error: could not process request.");
2534 }
2535 }).always(function() {
2536 $("#load-step-1-{{ TAB_INDEX_PLACEHOLDER }}").hide();
2537 });
2538 },
2539
2540 //USED HERE
2541 getRCCADDED: function() {
2542 var self = this ;
2543 jsonRCC_ADDED = [];
2544 $.each(self.hot_RCC_ADDED.getData(), function(){
2545 var formatData = {};
2546 if ("<b>InChIKey</b>" in this && this["<b>InChIKey</b>"]!= undefined && this["<b>InChIKey</b>"] != "") {
2547 jsonRCC_ADDED.push(this["<b>InChIKey</b>"]);
2548 }
2549 });
2550 return jsonRCC_ADDED;
2551 },
2552
2553 //USED HERE
2554 getRCCADDEDConcentration: function() {
2555 var self = this ;
2556 jsonRCC_ADDED = [];
2557 $.each(self.hot_RCC_ADDED.getData(), function(){
2558 var formatData = {};
2559 if ("<b>InChIKey</b>" in this && this["<b>InChIKey</b>"]!= undefined && this["<b>InChIKey</b>"] != "") {
2560 jsonRCC_ADDED.push(this["<b>concentration (&micro;g/ml)</b>"]);
2561 }
2562 });
2563 return jsonRCC_ADDED;
2564 },
2565
2566 //USED IN HTML
2567 clearLine: function() {
2568 var self = this ;
2569 // restet form
2570 setTimeout(function(){
2571 $("#add-one-cc-s1-value-{{ TAB_INDEX_PLACEHOLDER }}").val("");
2572 $("#ok-step-1-{{ TAB_INDEX_PLACEHOLDER }}").html("");
2573 }, 200);
2574 $(self.prefix+"img.mixRCCadd"+self.multiPickLine).remove();
2575 if (self.singlePick) {
2576 $("#add1spectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}").val("");
2577 $("#add1spectrum-sample-inchikey-{{ TAB_INDEX_PLACEHOLDER }}").change();
2578 $("#add1spectrum-sample-inchi-{{ TAB_INDEX_PLACEHOLDER }}").val("");
2579 $("#add1spectrum-sample-inchi-{{ TAB_INDEX_PLACEHOLDER }}").change();
2580 $("#add1spectrum-sample-commonName-{{ TAB_INDEX_PLACEHOLDER }}").val("");
2581 $("#add1spectrum-sample-commonName-{{ TAB_INDEX_PLACEHOLDER }}").change();
2582 $("#sample-bonus-display-{{ TAB_INDEX_PLACEHOLDER }}").html("");
2583 } else if (self.multiPickLine >= 0) {
2584 for(var i = 0 ; i < 6 ; i += 1) {
2585 self.hot_RCC_ADDED.setDataAtCell(self.multiPickLine, i, "");
2586 }
2587 }
2588 },
2589
2590 exit: function() {
2591 $.ajax({type: "get", url: "/quit", async: true, success: ()=>window.close()});
2592 },
2593
2594 } ;
2595
2596 $.ajax({
2597 type: "get",
2598 url: "{{ PF_URL_PLACEHOLDER }}/webapp/get-cpd-data?token={{ PF_TOKEN_PLACEHOLDER }}",
2599 data: "inchikey=" + "{{ INCHIKEY_PLACEHOLDER }}",
2600 dataType: "json",
2601 success: function(data) {
2602 if (data.success) {
2603 var self = context_{{ TAB_INDEX_PLACEHOLDER }} ;
2604 console.log(`inchikey {{ INCHIKEY_PLACEHOLDER }} found!!`)
2605 inchidata["{{ INCHIKEY_PLACEHOLDER }}"] = data ;
2606 self.init() ;
2607 self.fitlerSearchLoadlCpd = 5;
2608 self.inchikey = null;
2609 all_contexts[{{ TAB_INDEX_PLACEHOLDER }}] = self ;
2610 } else {
2611 no_success(
2612 {{ TAB_INDEX_PLACEHOLDER }},
2613 "{{ INCHIKEY_PLACEHOLDER }}",
2614 {{ DEFAULT_DATA }}["name"]
2615 ) ;
2616 all_contexts[{{ TAB_INDEX_PLACEHOLDER }}] = null ;
2617 }
2618 },
2619 error : function(data) {
2620 no_success(
2621 {{ TAB_INDEX_PLACEHOLDER }},
2622 "{{ INCHIKEY_PLACEHOLDER }}",
2623 {{ DEFAULT_DATA }}["name"]
2624 ) ;
2625 all_contexts[{{ TAB_INDEX_PLACEHOLDER }}] = null ;
2626 }
2627 }).always(() => null);