Skip to content

Commit ce13cdb

Browse files
author
Mohamed Meharga
committed
Added multifield parameter with UI needed for Euclid
1 parent b49ae01 commit ce13cdb

File tree

6 files changed

+205
-103
lines changed

6 files changed

+205
-103
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/.project
44
/RemoteSystemsTempFiles/
55
/add_transient_nodes.php
6+
/tempus.sql

instruments/mmoda_isgri/help_book/ibis-isgri-image-new-source.php

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

js/mmoda.common.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,20 @@ function get_waitingDialog($modal_dialog) {
696696
}
697697

698698
// A cross symbol after an input to clear it
699-
$('.clear-left-input').on('click', function(e) {
699+
$('body').on('click', 'button.plus-element', function(e) {
700+
var row = $(this).closest('tr').clone(true);
701+
$('input', row).val('');
702+
$(this).closest('tr').after(row);
703+
$(this).after($('<button>').addClass('btn btn-secondary remove-element').append($('<span>').addClass('glyphicon glyphicon-minus'))).remove();
704+
e.preventDefault(); return true;
705+
});
706+
// A cross symbol after an input to clear it
707+
$('body').on('click', 'button.remove-element', function(e) {
708+
$(this).closest('tr').remove();
709+
e.preventDefault(); return true;
710+
});
711+
712+
$('.clear-left-input').on('click', function() {
700713
$(this).parent().prev('input').val('');
701714
});
702715

js/mmoda.instrument.js

Lines changed: 155 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ function panel_title(srcname, param) {
5858
}
5959

6060
(function($) {
61-
6261
$(document).ready(commonReady);
6362
var desktop_panel_counter = 1;
6463

@@ -411,7 +410,160 @@ function panel_title(srcname, param) {
411410
return (cssClass);
412411
}
413412

413+
function current_instrument_form_set_bootstrapValidator() {
414+
415+
var validator_fields = {
416+
'scw_list': {
417+
// enabled: false,
418+
validators: {
419+
callback: {
420+
callback: function(value, validator, $field) {
421+
return (validate_scws(value, 500));
422+
}
423+
}
424+
}
425+
}
426+
};
427+
validator_fields['time_bin'] = {
428+
// enabled: false,
429+
validators: {
430+
callback: {
431+
callback: function(value, validator, $field) {
432+
return (validate_timebin(value, validator, $field));
433+
}
434+
}
435+
}
436+
};
437+
438+
validator_fields['E1_keV'] = {
439+
// enabled: false,
440+
validators: {
441+
notEmpty: {
442+
message: 'Please enter a value'
443+
},
444+
callback: {
445+
callback: function(value, validator, $field) {
446+
var E2_keV = validator.getFieldElements('E2_keV').val();
447+
if (Number(value) >= Number(E2_keV)) {
448+
return {
449+
valid: false,
450+
message: 'Energy min must be lower that energy max'
451+
}
452+
}
453+
return true;
454+
}
455+
}
456+
}
457+
};
458+
validator_fields['E2_keV'] = {
459+
// enabled: false,
460+
validators: {
461+
notEmpty: {
462+
message: 'Please enter a value'
463+
},
464+
callback: {
465+
callback: function(value, validator, $field) {
466+
var E1_keV = validator.getFieldElements('E1_keV').val();
467+
if (Number(value) <= Number(E1_keV)) {
468+
return {
469+
valid: false,
470+
message: 'Energy max must be higher that energy min'
471+
}
472+
}
473+
return true;
474+
}
475+
}
476+
}
477+
};
478+
validator_fields['filters[filter][]'] = {
479+
// enabled: false,
480+
validators: {
481+
notEmpty: {
482+
message: 'Please select filter'
483+
}
484+
}
485+
};
486+
validator_fields['filters[flux][]'] = {
487+
// enabled: false,
488+
validators: {
489+
notEmpty: {
490+
message: 'Please enter a value'
491+
}
492+
}
493+
};
494+
495+
validator_fields['filters[flux_error][]'] = {
496+
// enabled: false,
497+
validators: {
498+
notEmpty: {
499+
message: 'Please enter a value'
500+
}
501+
}
502+
};
503+
$('.instrument-panel form').bootstrapValidator('destroy');
504+
505+
current_instrument_form_validator = $('.instrument-panel form').bootstrapValidator({
506+
// live :'disabled',
507+
fields: validator_fields,
508+
feedbackIcons: {
509+
valid: 'glyphicon glyphicon-ok',
510+
invalid: 'glyphicon glyphicon-remove',
511+
validating: 'glyphicon glyphicon-refresh'
512+
}
513+
}).data('bootstrapValidator');
514+
}
515+
516+
function insert_new_multivalued_field(add_multivalued_button) {
517+
var multivalued_field = $(add_multivalued_button).closest('.multivalued-field');
518+
var current_row = $(add_multivalued_button).prev();
519+
var newVAlue = current_row.clone();
520+
$('input, select, textarea', newVAlue).val('');
521+
current_row.after(newVAlue);
522+
$('button', multivalued_field).prop('disabled', false);
523+
$('input, select, textarea', newVAlue).each(function() {
524+
current_instrument_form_validator.addField($(this));
525+
});
526+
newVAlue.show();
527+
}
528+
529+
function delete_multivalued_field(delete_multivalued_button) {
530+
multivalued_field = $(delete_multivalued_button).closest('.multivalued-field');
531+
var current_row= $(delete_multivalued_button).parent();
532+
current_row.remove();
533+
var nb_rows = $('.multivalued-value', multivalued_field).length;
534+
if (nb_rows == 1) $('button.delete-multivalued-element', multivalued_field).prop('disabled', true)
535+
}
536+
537+
414538
function commonReady() {
539+
$('.multivalued-field').removeClass('form-group');
540+
541+
current_instrument_form_set_bootstrapValidator();
542+
var add_multivalued_elt_button = $('<button>').addClass('btn btn-secondary add-multivalued-element').append($('<span>').addClass('glyphicon glyphicon-plus'));
543+
var del_multivalued_elt_button = $('<button>').addClass('btn btn-secondary delete-multivalued-element').append($('<span>').addClass('glyphicon glyphicon-minus'));
544+
$('.multivalued-field').append(add_multivalued_elt_button);
545+
$('.multivalued-field .multivalued-value').append(del_multivalued_elt_button);
546+
$('button', '.multivalued-field .multivalued-value').prop('disabled', true);
547+
548+
$('.multivalued-field .multivalued-value').each(function() {
549+
var multivalued_field = $(this).closest('.multivalued-field');
550+
var labels = $(this).clone();
551+
labels.find('input, select, textarea, button').remove();
552+
labels.removeClass('multivalued-value');
553+
$(this).find('label').remove();
554+
multivalued_field.find('label:first').after(labels);
555+
})
556+
557+
$('.multivalued-field').on('click', '.add-multivalued-element', function(e) {
558+
// Prevent form submission
559+
e.preventDefault();
560+
insert_new_multivalued_field(this);
561+
});
562+
$('.multivalued-field').on('click', '.delete-multivalued-element', function(e) {
563+
// Prevent form submission
564+
e.preventDefault();
565+
delete_multivalued_field(this);
566+
});
415567

416568
$('body').on('click', '#ldialog .close-button', function() {
417569
if (requestTimer !== null) {
@@ -425,8 +577,7 @@ function panel_title(srcname, param) {
425577

426578
if (typeof mmoda_ajax_jqxhr[$(this).data('mmoda_jqxhr_index')] !== 'undefined')
427579
mmoda_ajax_jqxhr[$(this).data('mmoda_jqxhr_index')].abort();
428-
if ($(this).data("mmoda_gallery_close") == 1)
429-
$('#mmoda-gallery-panel').data("mmoda_gallery_close", 1);
580+
if ($(this).data("mmoda_gallery_close") == 1) $('#mmoda-gallery-panel').data("mmoda_gallery_close", 1);
430581

431582
$(this).removeData('mmoda_gallery_close');
432583
$(this).removeData('mmoda_jqxhr_index');
@@ -860,70 +1011,6 @@ function panel_title(srcname, param) {
8601011
// Create validator and validate a frist time :
8611012
// This is important in Firefox when the page is refreshed
8621013
// where indeed the old values are still in the form
863-
current_instrument_form_validator = $('.instrument-panel form').bootstrapValidator({
864-
// live :'disabled',
865-
fields: {
866-
'scw_list': {
867-
// enabled: false,
868-
validators: {
869-
callback: {
870-
callback: function(value, validator, $field) {
871-
return (validate_scws(value, 500));
872-
}
873-
}
874-
}
875-
},
876-
'time_bin': {
877-
// enabled: false,
878-
validators: {
879-
callback: {
880-
callback: function(value, validator, $field) {
881-
return (validate_timebin(value, validator, $field));
882-
}
883-
}
884-
}
885-
},
886-
'E1_keV': {
887-
// enabled: false,
888-
validators: {
889-
callback: {
890-
callback: function(value, validator, $field) {
891-
var E2_keV = validator.getFieldElements('E2_keV').val();
892-
if (Number(value) >= Number(E2_keV)) {
893-
return {
894-
valid: false,
895-
message: 'Energy min must be lower that energy max'
896-
}
897-
}
898-
return true;
899-
}
900-
}
901-
}
902-
},
903-
'E2_keV': {
904-
// enabled: false,
905-
validators: {
906-
callback: {
907-
callback: function(value, validator, $field) {
908-
var E1_keV = validator.getFieldElements('E1_keV').val();
909-
if (Number(value) <= Number(E1_keV)) {
910-
return {
911-
valid: false,
912-
message: 'Energy max must be higher that energy min'
913-
}
914-
}
915-
return true;
916-
}
917-
}
918-
}
919-
},
920-
},
921-
feedbackIcons: {
922-
valid: 'glyphicon glyphicon-ok',
923-
invalid: 'glyphicon glyphicon-remove',
924-
validating: 'glyphicon glyphicon-refresh'
925-
}
926-
}).data('bootstrapValidator');// .validate();
9271014

9281015
$('[name^=time_bin_format]', '.instrument-params-panel form').on('change', function() {
9291016
var form = $(this).parents('form');
@@ -1195,6 +1282,7 @@ function panel_title(srcname, param) {
11951282
if (!common_form_validator.isValidField($(this).attr('name')))
11961283
both_forms_valid = false;
11971284
});
1285+
11981286
if (both_forms_valid) {
11991287
$('input, textarea, select', 'form.' + request_parameters.instrument + '-form').each(function() {
12001288
current_instrument_form_validator.validateField($(this).attr('name'));

mmoda.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ label.control-label {
1616
}
1717

1818
.instrument-params-panel .form-control {
19-
width: 80% !important;
19+
width: 90% !important;
2020
}
2121

2222
#formwrapper {
@@ -592,4 +592,13 @@ button.renku-publish {
592592

593593
#mmoda-gallery-iframe {
594594
border: none;
595+
}
596+
597+
.multivalued-field button {
598+
margin-top : 2px;
599+
}
600+
601+
.multivalued-field .row {
602+
margin-left: 0;
603+
margin-right: 0;
595604
}

mmoda.module

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,6 @@ function _mmoda_user_has_roles($instrument_roles)
361361
return (false);
362362
}
363363

364-
/**
365-
* Generates the actual content of the iPrayTimes block.
366-
*/
367-
function mmoda_get_settings()
368-
{
369-
$js = array();
370-
371-
return ($js);
372-
}
373-
374364
/**
375365
* Implements hook_theme().
376366
*/
@@ -881,3 +871,4 @@ function mmodahide_default_rules_configuration()
881871
return $rules;
882872
}
883873

874+

0 commit comments

Comments
 (0)