sub common_min_load_params { for my $p ($q->param) { my $val = $q->param($p) ; $val =~ s/\"//g ; $i{$p} = $val ; # &common_min_debug("$p - $val") ; } } #------------------------------------------------------------------------------------------ sub common_min_alert_type { if ($error) { $alert = &common_min_alert('danger',"$error",'remove-sign') ; } elsif ($warning) { $alert = &common_min_alert('warning',"$warning") ; } elsif ($success) { $alert = &common_min_alert('success',"$success",'ok') ; } } #------------------------------------------------------------------------------------------ sub common_min_alert { my ($type,$msg,$glyphicon,$id) = @_ ; unless ($id) { $id = 'alertmsg'; } unless ($glyphicon) { $glyphicon = 'exclamation-sign'; } my $alert = qq() ; return ($alert) ; } #------------------------------------------------------------------------------------------ sub common_min_add_form { my ($table,$action,$label_col,$field_col,$ignore_colpart,$skip) = @_ ; our ($lcol,$fcol) = &common_min_columns($label_col,$field_col) ; my $form = '' ; $form .= &common_min_forms_start($table,$skip) ; if (%sort_field) { foreach my $cnt (sort {$a <=> $b} keys %sort_field) { $col = $sort_field{$cnt} ; &common_debug("common_min_add_form [sort_field] = $col [$cnt]") ; $form .= &common_min_forms_loop('',$table,$ignore_colpart) ; } } else { foreach (sort { $col_name{$a} cmp $col_name{$b} } keys %col_name) { $col = $col_name{$_} ; &common_debug("common_min_add_form = $col [$_]") ; $form .= &common_min_forms_loop('',$table,$ignore_colpart) ; } } $form .= &common_min_forms_end('',$table,$action,$skip) ; return ($form) ; } #------------------------------------------------------------------------------------------ sub common_min_edit_form { my ($iid,$table,$action,$label_col,$field_col,$ignore_colpart,$skip) = @_ ; our ($lcol,$fcol) = &common_min_columns($label_col,$field_col) ; my $form = '' ; $form .= &common_min_forms_start($table,$skip) ; if (%sort_field) { foreach my $cnt (sort {$a <=> $b} keys %sort_field) { $col = $sort_field{$cnt} ; $form .= &common_min_forms_loop($iid,$table,$ignore_colpart) ; } } else { foreach $col (sort keys %{$db{$table}{$iid}}) { $form .= &common_min_forms_loop($iid,$table,$ignore_colpart) ; } } $form .= &common_min_forms_end($iid,$table,$action,$skip) ; return ($form) ; } #------------------------------------------------------------------------------------------ sub common_min_forms_start { my ($table,$skip) = @_ ; if ($skip) { return ; } my $form = qq(
) ; $form .= $extra_form_fields_start ; return ($form) ; } #------------------------------------------------------------------------------------------ sub common_min_forms_loop { my ($iid,$table,$ignore_colpart) = @_ ; unless ($col) { return('') ; } if ($hidden{$col}) { return('') ; } if ($ignore{$col}) { return('') ; } my ($colpart) = split(/\_/,$col) ; if (($ignore_colpart) and ($ignore{$colpart})) { return('') ; } $ucfirst_col = ucfirst $col ; my $val = $db{$table}{$iid}{$col} ; # $tindex++ ; my $form = '' ; if ($checkbox{$col}) { if ($val) { $checked = 'CHECKED'; } else { $checked = ''; } $form .= &common_min_form_checkbox($col,$val,$checked) ; return ($form) ; } if ($radio{$col}) { $form .= &common_min_form_radio($col,$val) ; return ($form) ; } &common_min_forms_required ; # $req_glyph = '' ; # if ($required{$col}) { # if ($required{$col} == 1){ $required{$col} = 'data-validation="required"' ; } # elsif ($required{$col} == 2){ $required{$col} = 'data-validation="length alphanumeric" data-validation-length="6-6"' ; } # elsif ($required{$col} == 3){ $required{$col} = 'data-validation="alphanumeric"' ; } # elsif ($required{$col} == 4){ $required{$col} = 'data-validation="number"' ; } # elsif ($required{$col} == 5){ $required{$col} = 'data-validation="number" data-validation-allowing="range[0;1]"' ; } # elsif ($required{$col} == 6){ $required{$col} = 'data-validation="email"' ; } # elsif ($required{$col} == 7){ $required{$col} = 'data-validation="url"' ; } # $req_glyph = qq() ; # } if ($datetimepicker{$col}) { unless ($val) { $val = $now_ccyy_mm_dd . " $now_hour:$now_min:$now_sec" ; } $form .= &common_min_form_datetimepicker($col,$val) ; return ($form) ; } if ($datepicker{$col}) { unless ($val) { $val = $now_ccyy_mm_dd ; } $form .= &common_min_form_datepicker($col,$val) ; return ($form) ; } if ($select{$col}) { $form .= &common_min_form_select($col,$val) ; return ($form) ; } if ($textarea{$col}) { $form .= &common_min_form_textarea($col,$val) ; return ($form) ; } if ($label{$col}) { $form .= &common_min_form_label($col,$val) ; return ($form) ; } if ($add_col{$col}) { $form .= &common_min_form_input_col($col,$val) ; } else { $form .= &common_min_form_input($col,$val) ; } return ($form) ; } #------------------------------------------------------------------------------------------ sub common_min_forms_required { $req_glyph{$col} = '' ; if ($required{$col}) { if ($required{$col} == 1){ $required{$col} = 'data-validation="required"' ; } elsif ($required{$col} == 2){ $required{$col} = 'data-validation="length alphanumeric" data-validation-length="6-6"' ; } elsif ($required{$col} == 3){ $required{$col} = 'data-validation="alphanumeric"' ; } elsif ($required{$col} == 4){ $required{$col} = 'data-validation="number"' ; } elsif ($required{$col} == 5){ $required{$col} = 'data-validation="number" data-validation-allowing="range[0;1]"' ; } elsif ($required{$col} == 6){ $required{$col} = 'data-validation="email"' ; } elsif ($required{$col} == 7){ $required{$col} = 'data-validation="url"' ; } elsif ($required{$col} == 8){ $required{$col} = 'data-validation="" data-validation-allowing="" data-validation-decimal-separator=""' ; } elsif ($required{$col} == 9){ $required{$col} = 'data-validation="custom" data-validation-regexp="^\d+(\.\d{1,2})?$"' ; } # New condition elsif ($required{$col} == 10) { $required{$col} = 'data-validation="length number" data-validation-length="10-20"' ; } # 0846758345 or 27846758345 $req_glyph{$col} = qq() ; } } #------------------------------------------------------------------------------------------ sub common_min_forms_end { my ($iid,$table,$action,$skip) = @_ ; if ($skip) { return ; } my $form = '' ; $form .= $extra_form_fields ; foreach (keys %hidden) { $form .= qq~~ ; } if ($dialog) { $varbtn = qq~ ~ ; } else { $varbtn = qq~ ~ ; } # if ($savjqy) { $savbtn = qq() ;} else { $savbtn = qq() ; } if ($savjqy) { my $custom_class = ($invoice_exists && !$useropts{super}{$username} && !$useropts{it}{$username}) ? "custom" : "primary" ; my $custom_tooltip = ($invoice_exists) ? qq~title data-toggle="tooltip" data-placement="top" data-original-title="Invoice Nr Exists!!!"~ : qq~~ ; $savbtn = qq~  ~ ; } elsif ($srchjqy) { $savbtn = qq~ ~ ; } elsif ($srchscr) { $savbtn = qq~ ~ ; } else { $savbtn = qq~ ~ ; } if ($addbkb) { $bakbtn = qq~ ~; } else { $bakbtn = qq~~ ; } if ($addcpb) { $cpybtn = qq~ ~; &common_min_footer('id',"$lcpage\s"); } else { $cpybtn = qq~~ ; } my $custom_class = ($cancel_butt & $invoice_exists && !$useropts{super}{$username} && !$useropts{it}{$username}) ? "custom" : "danger" ; my $custom_tooltip = ($invoice_exists) ? qq~title data-toggle="tooltip" data-placement="top" data-original-title="Invoice Nr Exists!!!"~ : qq~~ ; $canxbtn = ($cancel_butt) ? qq~  ~ : '' ; $varbtn = $custom_back_button if $custom_back_button ; $savbtn = qq~~ if $skip_save_btn ; $form .= qq~
 
$savbtn$canxbtn$cpybtn$varbtn$bakbtn
 
~ ; return ($form) ; } #------------------------------------------------------------------------------------------ sub common_min_columns { my ($label_col,$field_col) = @_ ; unless ($label_col) { $lcol = 2 ; } else { $lcol = $label_col ; } unless ($field_col) { $fcol = 4 ; } else { $fcol = $field_col ; } return ($lcol,$fcol) ; } #------------------------------------------------------------------------------------------ sub common_min_status { my ($closed,$deleted) = @_ ; my ($class,$txt) ; if ($deleted == 1) { $class = 'danger' ; $txt = 'DELETED' ; $del{$iaction} = 1 ; } elsif ($closed == 1) { $class = 'success' ; $txt = 'CLOSED' ; $clo{$iaction} = 1 ; } elsif ($closed == 0) { $class = 'warning' ; $txt = 'ACTIVE' ; $act{$iaction} = 1 ; } return ($class,$txt) ; } #------------------------------------------------------------------------------------------ sub common_min_form_view { my ($field,$val,$type,$addclass,$dont_end_row) = @_ ; my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } # $vrowcnt++; if ($vrowcnt % 2 == 0) { $bgcolor = '#cecbcb' ; } else { $bgcolor = '#eeeeee' ; } $bgcolor = '#eeeeee' ; unless ($val) { $val = ' ' ; } my $row = qq(
$val
) ; unless ($dont_end_row) { $row .= qq(
) ; } $row = qq~$row

~ if $val =~ /
/ ; return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_view_col { my ($val) = @_ ; # my $ucfirst_field = ucfirst $field ; # my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } # $vrowcnt++; if ($vrowcnt % 2 == 0) { $bgcolor = '#cecbcb' ; } else { $bgcolor = '#eeeeee' ; }
unless ($val) { $val = ' ' ; } my $row = qq~
$val
~ ; return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_input { my ($field,$val,$type,$addclass,$dont_end_row) = @_ ; if ($field eq 'password') { $type = 'password' ; } unless ($type) { $type = 'text' ; } if ($cust_class{$field}) { $addclass = $cust_class{$field} ; } my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } if ($type eq 'hidden') { return ("") ; } my $labelid = '' ; if ($label_id{$field}) { $labelid = $label_id{$field} ; } $tindex++ ; $fcol = $fcol{$field} if $fcol{$field} ; my $row = '' ; if ($add_finish_div{$field}) { $row .= qq~
~ ; } $row .= qq~
$dlg{$field}~ ; if (not $dont_end_row and not $dont_end_row{$field}) { $row .= qq~
~ ; } return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_input_col { my ($field,$val) = @_ ; unless ($type) { $type = 'text' ; } my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } my $placeholder = $print_field ; if ($preferred_placeholder{$field}) { $placeholder = $preferred_placeholder{$field} ; } my $field_id = "input$ucfirst_field" ; # unless ($excl_on_change{$field}) { push @jquery_workings_trigger_fields, $field_id ; } unless ($excl_on_change{$field}) { push @jquery_trigger_fields, $field_id ; } if ($type eq 'hidden') { return ("") ; } $tindex++ ; $fcol = $fcol{$field} if $fcol{$field} ; my $row = qq~
$dlg{$field}~ ; return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_label { my ($field,$val) = @_ ; $hidden{$field} = 1 ; my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } my $field_id = "label$ucfirst_field" ; my $row .= qq~
$val
$dlg{$field}~ ; return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_label_col { my ($field) = @_ ; my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } my $field_id = "label$ucfirst_field" ; my $row = qq~
~; unless ($excl_on_change{$field}) { push @jquery_trigger_fields, $field_id ; } # unless ($excl_on_change{$field}) { push @jquery_workings_trigger_fields, $field_id ; } return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_textarea { my ($field,$val,$height) = @_ ; if ($textarea_height{$field}) { $height = $textarea_height{$field}; } unless ($height) { $height = 100; } my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } $tindex++ ; my $row = qq~
~ ; return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_textarea_col { my ($field,$val,$height,$hide) = @_ ; if ($textarea_height{$field}) { $height = $textarea_height{$field}; } unless ($height) { $height = 100; } my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } $tindex++ ; my $hide = ($hide) ? "none" : "" ; my $row = qq~
~ ; return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_checkbox { my ($field,$val,$checked,$classic) = @_ ; my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } my $check_class = ($classic) ? 'class="iphone-toggle"' : '' ; # $tindex++ ; my $row = qq(
) ; # return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_checkbox_col { my ($field,$val,$checked,$classic) = @_ ; my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } my $field_id = "checkbox$ucfirst_field" ; my $check_class = ($classic) ? 'class="iphone-toggle"' : '' ; my $label = '' ; if ($label{$field}) { $label = "" ; } $tindex++ ; my $row = qq(
$label
) ; unless ($excl_on_change{$field}) { push @jquery_trigger_fields, $field_id ; } # unless ($excl_on_change{$field}) { push @jquery_workings_trigger_fields, $field_id ; } return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_radio { my ($field,$val,$opts) = @_ ; my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } my @opts = split(/\+/,$radio_opts{$field}); foreach (@opts) { if ($_ eq $val) { $checked = 'CHECKED'; } else { $checked = ''; } $print_radios .= qq( $_) ; } my $row = qq(
) ; return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_select { my ($field,$val,$dont_end_row) = @_ ; if ($multiple{$field}) { $setmultiple = 'multiple' ; } else { $setmultiple = '' ; } my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } $tindex++ ; my $row = qq~
$dlg{$field}~ ; unless ($dont_end_row) { $row .= qq~
~ ; } if ($allow_deselect{$field}) { if ($minify_jquery) { push @all_select_ids,"#select$ucfirst_field" if $ucfirst_field ; } else { $trigger_jquery_raw .= qq~\$("#select$ucfirst_field").chosen({ allow_single_deselect:true,search_contains:true });~ ; } } # if ($val) { # $trigger_jquery_raw .= qq~\$("#select$ucfirst_field").val($val) ; \$("#select$ucfirst_field").trigger("chosen:updated"); ~ ; # } return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_select_col { my ($field,$val) = @_ ; my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } if ($multiple{$field}) { $setmultiple = 'multiple' ; } else { $setmultiple = '' ; } $tindex++ ; my $row = qq~
$dlg_operator{$field}
$dlg{$field}~ ; if ($allow_deselect{$field}) { if ($minify_jquery) { push @all_select_ids,"#select$ucfirst_field" if $ucfirst_field ; } else { $trigger_jquery_raw .= qq~\$("#select$ucfirst_field").chosen({ allow_single_deselect:true });~ ; } } # if ($val) { # $trigger_jquery_raw .= qq~\$("#select$ucfirst_field").val($val) ; \$("#select$ucfirst_field").trigger("chosen:updated"); ~ ; # } return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_datetimepicker { my ($field,$val,$diff) = @_ ; $diff = 10 unless $diff ; my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } $tindex++ ; # if ($field eq 'date_from') { $val = "$now_ccyy_mm_dd $now_hour:00:00" unless $val ; } if ($field eq 'date_from') { $val = "$now_ccyy_mm_dd 08:00:00" unless $val ; } if ($field eq 'date_to') { my $hr = sprintf("%02s", $now_hour + 2) ; $val = "$now_ccyy_mm_dd $hr:00:00" unless $val ; } my $row = qq(
) ; $trigger_jquery_raw .= qq(\$('#datetimepicker$ucfirst_field').datetimepicker({language: 'pt-BR'}); ) ; my @field_name_parts = split(/\_/,$field) ; if ($field_name_parts[-1] eq 'from' && !($ENV{'SCRIPT_NAME'} =~ /event_quotes/ && ($ENV{'QUERY_STRING'} =~ /edit/ || $ENV{'QUERY_STRING'} =~ /add/))) { pop @field_name_parts ; my $field_prefix = join("_",@field_name_parts) ; my $ucfirst_field_prefix = ucfirst $field_prefix ; if ($ENV{'QUERY_STRING'} =~ /filter/ || $ENV{'QUERY_STRING'} =~ /search/ || $ENV{'SCRIPT_NAME'} =~ /report/) { $trigger_jquery_raw .= qq~ \$('#datetimepicker$ucfirst_field_prefix\_from').on('changeDate', function(e) { var datetimepickerDate_from = \$("input[name='$field_prefix\_from']").val(); var datetimepickerDate_to = \$("input[name='$field_prefix\_to']").val(); var newDatetimepickerDate_from = new Date(datetimepickerDate_from); var newDatetimepickerDate_to = new Date(datetimepickerDate_to); if (newDatetimepickerDate_from > newDatetimepickerDate_to) { newDatetimepickerDate_to = new Date(datetimepickerDate_from); } console.log("datetimepickerDate_from="+datetimepickerDate_from) ; newDatetimepickerDate_from.setHours(+2); newDatetimepickerDate_from.setMinutes(0); newDatetimepickerDate_from.setSeconds(0); newDatetimepickerDate_from.setMilliseconds(0); console.log("newDatetimepickerDate_from="+newDatetimepickerDate_from) ; \$("#datetimepicker$ucfirst_field_prefix\_from").datetimepicker("setDate", newDatetimepickerDate_from); console.log("datetimepickerDate_to="+newDatetimepickerDate_to) ; newDatetimepickerDate_to.setHours(23+2); newDatetimepickerDate_to.setMinutes(59); newDatetimepickerDate_to.setSeconds(59); newDatetimepickerDate_to.setMilliseconds(59); console.log("newDatetimepickerDate_to="+newDatetimepickerDate_to) ; \$("#datetimepicker$ucfirst_field_prefix\_to").datetimepicker("setDate", newDatetimepickerDate_to); }) ; \$('#datetimepicker$ucfirst_field_prefix\_to').on('changeDate', function(e) { var datetimepickerDate_to = \$("input[name='$field_prefix\_to']").val(); var newDatetimepickerDate_to = new Date(datetimepickerDate_to); console.log("datetimepickerDate_to="+datetimepickerDate_to) ; newDatetimepickerDate_to.setHours(23+2); newDatetimepickerDate_to.setMinutes(59); newDatetimepickerDate_to.setSeconds(59); newDatetimepickerDate_to.setMilliseconds(59); console.log("newDatetimepickerDate_to="+newDatetimepickerDate_to) ; \$("#datetimepicker$ucfirst_field_prefix\_to").datetimepicker("setDate", newDatetimepickerDate_to); }) ; ~; } else { $trigger_jquery_raw .= qq~ if (\$("#datetimepicker$ucfirst_field_prefix\_to").length) { \$('#datetimepicker$ucfirst_field_prefix\_from').on('changeDate', function(e) { var datetimepickerDate_from = \$("input[name='$field_prefix\_from']").val(); console.log("datetimepickerDate_from="+datetimepickerDate_from) ; if (datetimepickerDate_from) { // Parse datetimepickerDate_from value to a Date object var datetimepickerDate_to = new Date(datetimepickerDate_from); console.log("datetimepickerDate_to="+datetimepickerDate_to) ; // Add 2 hours to datetimepickerDate_from value // datetimepickerDate_to.setHours(datetimepickerDate_to.getHours() + $diff); datetimepickerDate_to.setHours(datetimepickerDate_to.getHours() + $diff); console.log("datetimepickerDate_to="+datetimepickerDate_to) ; \$("#datetimepicker$ucfirst_field_prefix\_to").datetimepicker("setDate", datetimepickerDate_to); } }) ; } ~; } } return ($row) ; # } #------------------------------------------------------------------------------------------ sub common_min_form_datepicker { my ($field,$val,$label,$dont_end_row) = @_ ; my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($label) { $print_field = $label ; } if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } if ($val eq '0000-00-00') { $val = '' ; } $tindex++ ; my $row = qq~
~ ; unless ($dont_end_row) { $row .= qq~
~ ; } &common_min_form_datepicker_jquery($ucfirst_field); return ($row) ; # } #------------------------------------------------------------------------------------------ sub common_min_form_datepicker_col { my ($field,$val,$end_row) = @_ ; my $ucfirst_field = ucfirst $field ; my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } $tindex++ ; if ($val eq '0000-00-00') { $val = '' ; } my $row = qq(
) ; $row .= qq~
~ if $end_row ; &common_min_form_datepicker_jquery($ucfirst_field); return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_form_datepicker_jquery { my ($ucfirst_field) = @_ ; $trigger_jquery_raw .= qq~ \$('#datepicker$ucfirst_field').datepicker({ format: "yyyy-mm-dd"}).on('changeDate', function (ev) { \$('.datepicker').hide(); }) ; ~ ; my $lc_field = lc $ucfirst_field ; my @field_name_parts = split(/\_/,$lc_field) ; # if ($field_name_parts[-1] eq 'from') { # pop @field_name_parts ; my $field_prefix = join("_",@field_name_parts) ; my $ucfirst_field_prefix = ucfirst $field_prefix ; # $trigger_jquery_raw .= qq~ # if (\$("#datepicker$ucfirst_field_prefix\_to").length) { # // \$('#datepicker$ucfirst_field_prefix\_from').on('changeDate', function(e) { # // var datepickerDate_from = \$("input[name='$field_prefix\_from']").val(); # // console.log("datepickerDate_from [$field_prefix\_from]="+datepickerDate_from) ; # // if (datepickerDate_from) { # // // Parse datepickerDate_from value to a Date object # // var datepickerDate_to = new Date(datepickerDate_from); # // console.log("datepickerDate_to="+datepickerDate_to) ; # // // Add 1 month to datepickerDate_from value # // datepickerDate_to.setMonth(datepickerDate_to.getMonth() + 1); # // // var formattedDate = \$("#datepicker$ucfirst_field_prefix\_to").formatDate("yyyy-mm-dd", new Date(datepickerDate_to)); # // // console.log("datepickerDate_to [datepicker$ucfirst_field_prefix\_to]="+datepickerDate_to+" ["+formattedDate+"]") ; # // console.log("datepickerDate_to [datepicker$ucfirst_field_prefix\_to]="+datepickerDate_to) ; # // // \$("#datepicker$ucfirst_field_prefix\_to").datepicker("setDate", new Date(datepickerDate_to)); # // // \$("#datepicker$ucfirst_field_prefix\_to").setDate(datepickerDate_to); # // } # // }) ; # var nowTemp = new Date(); # var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0); # var from = \$('#datepicker$ucfirst_field_prefix\_from').datepicker({ # format: "yyyy-mm-dd", # onRender: function (date) { # return date.valueOf() < now.valueOf() ? 'disabled' : ''; # } # }).on('changeDate', function (ev) { # if (ev.date.valueOf() > to.date.valueOf()) { # var newDate = new Date(ev.date) # newDate.setDate(newDate.getDate() + 30); # to.setValue(newDate); # } # // from.hide(); # \$('#datepicker$ucfirst_field_prefix\_to')[0].focus(); # }).data('datepicker'); # var to = \$('#datepicker$ucfirst_field_prefix\_to').datepicker({ # format: "yyyy-mm-dd", # onRender: function (date) { # return (date.valueOf() < now.valueOf()) && (date.valueOf() >= from.date.valueOf()) ? 'disabled' : ''; # } # }).on('changeDate', function (ev) { # // to.hide(); # }).data('datepicker'); # } # ~; # } } #------------------------------------------------------------------------------------------ # sub common_min_form_datepicker { # my ($field,$val) = @_ ; # my $ucfirst_field = ucfirst $field ; # my $print_field = &common_min_print_field($field) ; # my $row = qq(
#
#
#
#
# # # # # #
#
#
#
) ; # $trigger_jquery_raw .= qq(\$('#datetimepicker$ucfirst_field').datetimepicker({language: 'pt-BR'}); ) ; # # $trigger_jquery_raw .= qq( # # \$('#datepicker$ucfirst_field').datepicker({ # # format: "yyyy-mm-dd"}).on('changeDate', function (ev) { # # \$('.datepicker').hide(); # # }) ; # # ) ; # return ($row) ; # } #------------------------------------------------------------------------------------------ sub common_min_form_timepicker_col { my ($field,$val,$diff) = @_; $diff = 10 unless $diff; my $ucfirst_field = ucfirst $field; my $print_field = ($preferred_title{$field}) ? $preferred_title{$field} : &common_min_print_field($field) ; $tindex++; my $row = qq~
~ ; $trigger_jquery_raw .= qq(\$('#timepicker$ucfirst_field').datetimepicker({language:'pt-BR',pickDate:false});) ; return $row ; } #------------------------------------------------------------------------------------------ # # sub common_min_form_radio_col { # # my ($field,$val,$opts) = @_ ; # # my $ucfirst_field = ucfirst $field ; # # my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } # # my @opts = split(/\+/,$radio_opts{$field}); my $cnt = 0 ; # # foreach (@opts) { # # my $value = $_ ; $value = lc $value ; $value =~ s/ /\_/g ; $cnt++ ; # # if ($value eq $val) { $checked = 'CHECKED'; } else { $checked = ''; } # # $print_radios .= qq~
 $_
~ ; #### WHY NOT class="radio col-md-$fcol" ????????????? # # } # # my $row = qq~
# # # # # #
# # $print_radios~ ; # # for (1 .. $cnt) { # # $trigger_jquery_raw .= qq~ # # \$("#radio_$_").change(function () { # # if(\$(this).is(":checked")) { # # let sel_val = \$("#radio_$_").val() ; # # console.log("sel_val : "+sel_val) ; # # \$("#selected_$field").val(sel_val) ; # # } # # }) ; # # ~ ; # # } # # return ($row) ; # # } #------------------------------------------------------------------------------------------ sub common_min_form_radio_col { my ($field,$val,$opts,$columns,$nr_of_columns_to_display,$radio_row_id,$row_cnt,$display_horizontally) = @_ ; # my $print_field = &common_min_print_field($field) ; if ($preferred_title{$field}) { $print_field = $preferred_title{$field} ; } $nr_of_columns_to_display = $columns unless $nr_of_columns_to_display ; $row_cnt = 1 unless $row_cnt ; my %display = () ; for ($nr_of_columns_to_display+1 .. 10) { $display{$_} = qq~style="display:none;"~ ; } $display{row} = qq~style="display:none;"~ if $nr_of_columns_to_display < 0 ; ## HIDE SECOND ROW BY DEFAULT my @default_checked = split(/\;/,$val) ; my $print_radios = qq~~ ; my @opts = split(/\+/,$radio_opts{$field}); my $cnt = 0 ; my $ucfirst_field = ucfirst $field ; $print_radios .= qq~
~ if $display_horizontally ; foreach my $option (@opts) { $cnt++ ; my $row_id = ($radio_row_id) ? "$radio_row_id\_$cnt" : "" ; # my $print_field = ucfirst $option; $print_radios .= qq~
~ unless $display_horizontally ; my $align = qq~align='right'~ if $display_horizontally ; $print_radios .= qq~
~ ; for (1 .. $columns) { my $value = $option; $value = lc $value ; $value =~ s/ /\_/g ; my $radio_nr = ($display_horizontally) ? $display_horizontally : ($row_cnt*$columns - $columns) + $_ ; if ($value eq $default_checked[$radio_nr - 1]) { $checked = 'CHECKED'; } else { $checked = ''; } $print_radios .= qq~~ if $cnt == 1 ; $print_radios .= qq~
~ ; } $print_radios .= qq~
~ unless $display_horizontally ; #### WHY NOT class="radio col-md-$fcol" ????????????? } $print_radios .= qq~
~ if $display_horizontally ; my $row = qq~$print_radios~ ; my @radio_ids = () ; my $radio_to_selected = qq~~ ; for my $option_cnt (1 .. $cnt) { for (1 .. $columns) { push @radio_ids,"#radio_$_\_$option_cnt" ; $radio_to_selected .= qq~"radio_$_\_$option_cnt":"selected_$_\_$option_cnt",~ ; } } chop $radio_to_selected if $radio_to_selected ; my $radio_ids_string = join(",",@radio_ids) ; $trigger_jquery_raw .= qq~ \$("$radio_ids_string").change(function () { if (\$(this).is(":checked")) { const id = this.id ; const radio_to_selected = {$radio_to_selected} ; let sel_val = \$(this).val() ; // console.log("sel_val : "+sel_val) ; \$("#"+radio_to_selected[id]).val(sel_val) ; } }) ; ~ ; return ($row) ; } #------------------------------------------------------------------------------------------ sub common_min_print_field { my ($txt) = @_ ; if (($testing == 1) and ($username eq 'rory')) { return($txt) ; } if ($addid{$txt}) { $addtxt = ' ID' ; } else { $addtxt = '' ; } $txt =~ s/\_id/ /gi ; @strings = split(/\_/,$txt) ; @strings_ucf = map(ucfirst, map(lc,@strings)); $txt = join(' ', @strings_ucf); $txt .= $addtxt ; return ($txt) ; } #------------------------------------------------------------------------------------------ sub common_min_table { my ($id,$page,$list,$sort_col,$do_not_auto_sort_table) = @_ ; unless ($sort_col) { $sort_col = 0 ; } if ($fnsortcol) { $sort_col = $fnsortcol ; } my $sort_order = ($do_not_auto_sort_table) ? '' : 'desc' ; if ($fnsortorder) { $sort_order = $fnsortorder; } $print_box_content_rows .= qq~ $print_thead $print_tbody
~ ; if ($list) { $trigger_jquery .= qq~var oTable = \$('#itv-table').dataTable(); oTable.fnSort( [ [$sort_col,'$sort_order'] ] );~ ; } &common_min_footer($id,$page); } #------------------------------------------------------------------------------------------ sub common_min_footer { my ($id,$page) = @_ ; if ($uniq_id) { $id = $uniq_id ; } $print_footer_jscript = qq( ) ; if ($page && $ENV{SCRIPT_NAME} =~ /\_test/) { $page .= '-test' ; } if ($page) { $action_delete = qq(delete-$page) ; $action_edit = qq(edit-$page) ; $action_view = qq(view-$page) ; $action_copy = qq(copy-$page) ; } else { $action_delete = '' ; $action_edit = '' ; $action_view = '' ; $action_copy = '' ; } if ($blank_action) { $action_delete = '' ; $action_edit = '' ; $action_view = '' ; $action_copy = '' ; } $print_footer_forms .= qq~
$extra_edit_hidden_inputs
$extra_edit_hidden_inputs
~ ; } #------------------------------------------------------------------------------------------ # sub common_min_select_opts { # my ($field,$table,$valfield,$fid,$required,$addfield,$where) = @_ ; # $select{$field} = 1 ; # if ($required) { $required{$field} = 1 ; } # &db_min_ro($table,'*',$where,'','') ; # foreach my $id (keys %{$db{$table}}) { # if ($fid == $id) { $selected = 'selected="selected"'; } else { $selected = ''; } # # &common_min_debug("common_min_select_opts - $fid == $id [$valfield] [$table] [$db{$table}{$id}{$valfield}] [[$table][$id][$valfield]]") ; # if ($db{$table}{$id}{$addfield}) { $disp_addfield = " ($db{$table}{$id}{$addfield})" ; } else { $disp_addfield = '' ; } # if ($extra{$table}{$id}{$addfield}) { $disp_addfield = " $extra{$table}{$id}{$addfield}" ; } else { $disp_addfield = '' ; } # $opts{$field} .= qq() ; # } # } #------------------------------------------------------------------------------------------ sub common_min_select_opts { my ($field,$table,$dispfield,$fid,$required,$addfield,$where,$valfield,$addmore,$select,$order_dropdown) = @_ ; $select{$field} = 1 ; my $val = '' ; # $select = '*' unless $select; unless ($select) { $select = '*' ; } # &common_min_debug("common_min_select_opts:$field,$table,$dispfield,$fid,$required,$addfield,$where,$valfield,$addmore,$select") ; if ($required) { $required{$field} = 1 ; } # if ($dispfield){ # my $orderby = "' $dispfield '" ; # } else { # my $orderby = ' id DESC ' ; # } my $orderby = ($dispfield) ? "' $dispfield '" : ' id DESC' ; &db_min_ro($table,$select,$where,$orderby,'') ; $order_dropdown = $dispfield if $dispfield and not $order_dropdown ; unless ($order_dropdown) { foreach my $id (keys %{$db{$table}}) { foreach (keys %{$db{$table}{$id}}) { $order_dropdown = $_ ; last ; } last ; } } foreach my $id (sort {$db{$table}{$a}{$order_dropdown} cmp $db{$table}{$b}{$order_dropdown}}keys %{$db{$table}}) { $selected = ($fid && ($fid eq $db{$table}{$id}{$valfield} || $fid == $id)) ? 'SELECTED' : '' ; # if ($table eq 'regions') { &common_debug("$selected = ($fid and ($fid eq $db{$table}{$id}{$valfield} || $fid == $id)) ? 'SELECTED' : '' ;") ; } if ($db{$table}{$id}{$addfield} && $db{$table}{$id}{$dispfield} ne $db{$table}{$id}{$addfield}) { $disp_addfield = " [$db{$table}{$id}{$addfield}]" ; } else { $disp_addfield = '' ; } my $disp_addmore = '' ; if ($display_addmore{$table}{$addmore}) { my $glyph = '' ; if ($db{$table}{$id}{$addmore} == 1) { # $glyph = qq(); $disp_addmore = " - $addmore" ; } } if ($valfield) { $val = $db{$table}{$id}{$valfield} ; } else { $val = $id ; } # if ($table eq 'regions') { &common_debug("filter_select_opts = $filter_select_opts{$table}, filter_val = $filter_val{$table}{$val} [$val] valfield=$valfield") ; } if ($filter_select_opts{$table} == 1) { next unless $filter_val{$table}{$val} == 1 ; } # if ($table eq 'countries') { &common_debug("$field : [$val] $db{$table}{$id}{$dispfield}$disp_addfield$disp_addmore") ; } # &common_debug("table=$table, id=$id, val=$val, dispfield=$dispfield [$db{$table}{$id}{$dispfield}]") ; $opts{$field} .= qq~~ ; } } #------------------------------------------------------------------------------------------ sub common_min_box_top { my ($glyphicon,$title,$bgcolor,$boxicon,$chevronid) = @_ ; # f5af19 if ($bgcolor) { $box_header_style = qq~style="background:#$bgcolor;color:#ffffff;"~ ; } else { $box_header_style = '' ; } if ($chevronid) { $box_chevron_id = qq~id="$chevronid"~ ; } else { $box_chevron_id = '' ; } my $box = qq~

$title

$boxicon
~ ; return($box) ; } #------------------------------------------------------------------------------------------ sub common_min_box_foot { my $box = qq(
) ; return ($box) ; } #------------------------------------------------------------------------------------------ sub common_min_extra_crumb { my ($crumb_url,$crumb_txt) = @_ ; $crumb_txt =~ s/\-/ /g; my @crumbs = split(/ /,$crumb_txt); my @crumbs_ucf = map ucfirst, @crumbs; $crumb_txt = join(' ',@crumbs_ucf) ; $insert_crumbs .= qq(
  • $crumb_txt
  • ) ; &config_set_breadcrumbs ; } #------------------------------------------------------------------------------------------ sub common_min_dialog { $dialog{'common'}{'head'} = qq( $useropts{title} $extra_dialog_js ) ; # table>thead>tr>th, .table>thead>tr>th, table>tbody>tr>th, .table>tbody>tr>th, table>tfoot>tr>th, .table>tfoot>tr>th, table>thead>tr>td, .table>thead>tr>td, table>tbody>tr>td, .table>tbody>tr>td, table>tfoot>tr>td, .table>tfoot>tr>td { border: 1px solid black; } # .table>caption+thead>tr:first-child>th, .table>colgroup+thead>tr:first-child>th, .table>thead:first-child>tr:first-child>th, .table>caption+thead>tr:first-child>td, .table>colgroup+thead>tr:first-child>td, .table>thead:first-child>tr:first-child>td { border-top: 1px solid black; } $dialog{'common'}{'js'} = qq( ) ; } #------------------------------------------------------------------------------------ sub common_min_commify { local($_) = shift; 1 while s/^(-?\d+)(\d{3})/$1,$2/; return $_; } #------------------------------------------------------------------------------- sub common_min_debug { my ($msg) = @_ ; unless ($username eq 'rory') { return ; } unless (($testing == 1) or ($debug == 1)) { return ; } print "\n" . $msg ; } #------------------------------------------------------------------------------------------ sub common_min_action { if ($iaction eq 'add'){ &common_min_add_screen; &common_min_screen1; } if ($iaction eq 'list' or $iaction eq 'detailed' or $iaction eq 'summary' or $iaction eq 'accepted' or $iaction eq 'pending' or $iaction eq 'closed' or $iaction eq 'all' or $iaction eq 'open' or $iaction eq 'active') { &list_screen ; &common_min_screen3; } if ($iaction eq 'display'){ &list_screen ; &common_min_screen3; } if ($iaction eq 'view'){ &common_min_load_params ; &common_min_view_screen ; &common_min_screen1; } if ($iaction eq 'edit'){ &common_min_load_params ; &common_min_edit_screen ; &common_min_screen1; } if ($iaction eq 'save'){ &common_min_load_params ; &validate ; &insert ; &common_min_screen2; } if ($iaction eq 'update'){ &common_min_load_params ; &update ; &common_min_screen2; } if ($iaction eq 'delete'){ &common_min_load_params ; &common_min_delete ; &common_min_screen2; } if ($iaction eq 'copy'){ &common_min_load_params ; &duplicate ; ### Will cause error if using use File::Copy;, do not use sub copy { .. } ... &common_min_edit_screen; &common_min_screen1; } if ($iaction eq 'search'){ $srchscr = 1 ; &report_screen ; } if ($iaction eq 'filter'){ $srchscr = 1 ; &filter_screen ; } if ($iaction eq 'report'){ &common_min_load_params ; &report_ifields; &list_screen ; &common_min_screen3; } } #------------------------------------------------------------------------------------------ sub common_min_add_screen { &add_screen; %col_name = () ; my $dbid = 'id' ; if ($uniq_id) { $dbid = $uniq_id ; } &db_min_ro($table,'*',"$dbid > 0 AND $dbid < 10",'','') ; $page_title = 'Add' ; &add_db_fields ; unless ($double_box_layout) { $print_box_content_rows = &common_min_add_form($table,'save') ; } } #------------------------------------------------------------------------------------------ sub common_min_error_screen { $page_title = ($iaction eq 'save') ? 'Add' : "Edit $i{id}" ; foreach (keys %i) { $db{$table}{''}{$_} = $i{$_} ; } # reset other fields after &db_common_ro($table,'*','','id DESC',1) ; ## ALSO CHECK THAT THIS INCLUDES ALL THE FIELD IN ON SCREEN!!! &add_screen; # must occur before %col_name set to blank otherwise will include all previous columns %col_name = () ; &add_db_fields ; unless ($double_box_layout) { $print_box_content_rows = &common_min_add_form($table,'save') ; } } #------------------------------------------------------------------------------------------ sub common_min_edit_screen { my $dbid = 'id' ; if ($uniq_id) { $dbid = $uniq_id ; } unless ($i{$dbid}) { $warning = uc "NO $dbid" ; return ; } &db_min_ro($table,'*',"`$dbid`='$i{$dbid}'",'','') ; $page_title = 'Edit' ; $page_title .= " : $i{$dbid}" ; &edit_db_fields ; &edit_screen; unless ($double_box_layout) { $print_box_content_rows = &common_min_edit_form($i{$dbid},$table,'update') ; } } #------------------------------------------------------------------------------------------ sub common_min_view_screen { my $dbid = 'id' ; if ($uniq_id) { $dbid = $uniq_id ; } unless ($i{$dbid}) { $warning = uc "NO $dbid" ; return ; } &db_min_ro($table,'*',"`$dbid`='$i{$dbid}'",'','') ; $page_title = 'View' ; $page_title .= " : $i{$dbid}" ; &view_db_fields ; &view_screen($i{$dbid}); } #------------------------------------------------------------------------------------------ sub common_min_delete { my $dbid = 'id' ; if ($uniq_id) { $dbid = $uniq_id ; } unless ($i{$dbid}) { $error = uc "NO $dbid" ; return ; } &db_min_delete($table,"$dbid='$i{$dbid}'") ; } #------------------------------------------------------------------------------------------ sub common_min_search_screen { &thead; &common_min_alert_type ; require _blank ; exit ; } #------------------------------------------------------------------------------------------ sub common_min_thead { $print_thead = qq() ; foreach (@sql_col_display) { my $coltitle = $_ ; $coltitle =~ s/\_id//g ; $coltitle =~ s/\_/ /g ; $coltitle = uc $coltitle ; $coltitle = $replace_blank_table_top_right if $coltitle eq '' and $replace_blank_table_top_right ; # $custom_column_styles{$_} = qq~style="min-width:120px;"~ unless $custom_column_styles{$_} ; $print_thead .= qq($coltitle); } if ($add_th_row) { $print_thead .= $add_th_row ; } # used in agent_commission_report.pl and cruiseline_commission_report.pl $print_thead .= qq() ; } #------------------------------------------------------------------------------- sub common_min_split_sql_date_time { my ($datetime) = @_ ; my ($date,$time) = split(/ /,$datetime) ; my $dy = substr($date,0,4) ; my $dm = substr($date,5,2) ; my $dd = substr($date,8,2) ; my ($th,$tm,$ts) = split(/:/,$time) ; return($dy,$dm,$dd,$th,$tm,$ts) ; } #------------------------------------------------------------------------------- sub common_min_convert_sql_date_time { my ($datetime) = @_ ; my ($date,$time) = split(/ /,$datetime) ; my $dy = substr($date,0,4) ; my $dm = substr($date,5,2) ; my $dd = substr($date,8,2) ; my ($th,$tm,$ts) = split(/:/,$time) ; my $return = "$dy$dm$dd" ; if ($time) { $return .= "$th$tm$ts" ; } return($return) ; } #------------------------------------------------------------------------------- sub common_min_restriction_super { unless ($useropts{super}{lc $username}){ print "This page is restricted!" ; exit ; } } #------------------------------------------------------------------------------- sub common_min_add_extras { my $page = "$lcpage\s" ; if ($s{no}) { $page = $lcpage ; } $box_icon = qq(
    ) ; $useropts{'common'}{'css'} .= qq(.box-icon a i { top:1px; } .iPhoneCheckContainer { margin:2px 0 2px 0; } .iPhoneCheckContainer label { font-size: 14px; line-height: 14px; padding-top:7px; } .iPhoneCheckLabelOff { padding-right:5px; } ) ; # $extra_css .= qq~~ ; } #------------------------------------------------------------------------------------------ sub common_min_add_box_icon { my $page = "$lcpage\s" ; if ($s{no}) { $page = $lcpage ; } $box_icon = qq(
    ) ; } #------------------------------------------------------------------------------------------ sub common_min_screen1 { &thead; &common_min_alert_type ; my $page = "$lcpage\s" ; if ($s{no}) { $page = $lcpage ; } my $ucfpage = "$ucfirstpage\s" ; if ($s{no}) { $ucfpage = $ucfirstpage ; } unless ($redirtype) { $redirtype = 'list' ; } my $pname = ucfirst $redirtype ; &common_min_extra_crumb("$redirtype-$page","$pname $ucfpage") ; # &common_min_extra_crumb("list-$page","List $ucfpage") ; if ($cust_cols or $double_box_layout) { require _blank_3 ; } else { require _blank ; } exit ; } #------------------------------------------------------------------------------------------ sub common_min_screen2 { my $page = "$lcpage\s" ; if ($s{no}) { $page = $lcpage ; } unless ($redirsave) { $redirsave = 'list' ; } # unless ($redirsave) { $redirsave = 'edit' ; } if ($i{id} and $iaction ne 'delete') { &common_min_edit_screen ; &common_min_screen1; # $input_hidden_id = qq~~ ; } # # if ($i{id} && $redirsave eq 'edit') { # if ($redirsave eq 'edit') { # $input_hidden_id = qq~~ ; # } # my $doc_ready_jquery = qq~\$(document).ready(function(){ \$('#$redirsave-form').submit(); })~ unless $username eq 'rory' ; my $form_name = $redirsave . 'form' ; &common_min_alert_type ; print < $useropts{title}
    $input_hidden_id
    ENDOFTEXT # exit ; } #------------------------------------------------------------------------------------------ sub common_min_screen3 { &thead; if ($isaved) { $alert = &common_min_alert('success',"$ucpage $isaved!",'ok') ; } else { &common_min_alert_type ; } my $page = "$lcpage\s" ; if ($s{no}) { $page = $lcpage ; } &common_min_table('id',$page,'list') ; # &common_min_extra_crumb("manage-$lcpage\s","Manage $ucfirstpage\s") ; require _blank ; exit ; } #------------------------------------------------------------------------------------------ sub common_min_opts { my ($whichone,$field,$deselect) = @_ ; if ($whichone eq 'leave_type') { $required{$field} = 1 ; $select{$field} = 1 ; $opts{$field} = qq( ) ; } my $ucfirst_field = ucfirst $field ; if ($deselect){ $trigger_jquery_raw .= qq(\$("#select$ucfirst_field").chosen({ allow_single_deselect:true });) ; } } #------------------------------------------------------------------------------------------ sub common_min_dialog_load_screen { &dialog_common ; print < $alert
    $print_box_content_rows
    ENDOFTEXT # exit; } #------------------------------------------------------------------------------------------ sub common_min_dialog_save_screen { print < ITV Admin ENDOFTEXT # exit ; } #------------------------------------------------------------------------------------------ sub common_min_table_validate_date_inputs_jquery { my $date_value_ids_str = join(",",@date_value_ids) ; return unless $date_value_ids_str ; $trigger_jquery_raw .= qq~ function isLeapYear(year) { return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0); } function isValidDate(dateString) { let count_comp = 0 ; let found_non_int = 0 ; for (let key in dateString.split('-').map(Number)) { count_comp++ ; if (dateString.split('-').map(Number)[key] != parseInt(dateString.split('-').map(Number)[key])) { found_non_int = 1 ; } } if (count_comp != 3 || found_non_int) { return false } else { return true ; } } \$("$date_value_ids_str").change( function () { // console.log("date_value_ids_str : $date_value_ids_str") ; const dateInput = \$(this).val() ; if (!dateInput) { return ; } let result = "" ; if (!isValidDate(dateInput)) { result = "Invalid Date Format!!!"; } let [inputYear,inputMonth,inputDay] = dateInput.split("-").map(Number); if (inputYear > 2100 || inputYear < 2000) { if (result) { result = result + "
    "; } result = result + "Invalid Year!!!"; } if (inputMonth < 1 || inputMonth > 12) { if (result) { result = result + "
    "; } result = result + "Invalid Month!!!"; } const daysInMonth = [31, (isLeapYear(inputYear) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; if (inputDay < 1 || inputDay > daysInMonth[inputMonth - 1]) { if (result) { result = result + "
    "; } result = result + "Invalid Day!!!"; } if (result) { noty({text:result,layout:"center",type:"error",timeout:3000}) ; } else { let correct_day_or_month_format = 0 ; if (inputMonth > 0 && inputMonth < 10) { inputMonth = inputMonth.toString() ; inputMonth = inputMonth.padStart(2,'0'); correct_day_or_month_format = 1 ; } if (inputDay > 0 && inputDay < 10) { inputDay = inputDay.toString() ; inputDay = inputDay.padStart(2,'0'); correct_day_or_month_format = 1 ; } if (correct_day_or_month_format) { \$("#"+this.id).val(inputYear+"-"+inputMonth+"-"+inputDay) ; } } }) ; ~ ; } #------------------------------------------------------------------------------------------ sub common_min_table_update_checkbox_col_default { my $default_javascript_by_id_str = join ",", @default_javascript_by_id ; if ($default_javascript_by_id_str) { $trigger_jquery_raw .= qq~ let all_def_vals = {$default_javascript_by_id_str} ; ~ ; } } #------------------------------------------------------------------------------------------ sub common_min_table_update_checkbox_col_jquery { my ($nr_of_characters_in_id_to_determine_row,$content_id,$update_fields_short_1,$update_fields_short_2) = @_ ; $content_id = "content" unless $content_id ; $nr_of_characters_in_id_to_determine_row = 1 unless $nr_of_characters_in_id_to_determine_row ; my $jquery_on_change_1 = "" ; my $jquery_on_change_2 = "" ; if ($update_fields_short_1 || $update_fields_short_2) { ## NEW WAY $jquery_on_change_1 = qq~\$("#$content_id").on("change","$update_fields_short_1", function (event) {~ if $update_fields_short_1 ; # EXAMPLE: [id^='selectFixture_check_'],[id^='selectStatus_'] $jquery_on_change_2 = qq~\$("#$content_id").on("changeDate","$update_fields_short_2", function (event) {~ if $update_fields_short_2 ; } else { ## OLD WAY my @all_update_field_ids_1 = () ; my @all_update_field_ids_2 = () ; foreach my $fields (@all_update_field_ids) { foreach (split(/\,/,$fields)) { if ($_ =~ /#datepicker/ || $_ =~ /#datetimepicker/ || $_ =~ /#timepicker/) { push @all_update_field_ids_2,$_ ; } else { push @all_update_field_ids_1,$_ ; } } } # my $all_update_field_ids_str = join "," , @all_update_field_ids ; my $all_update_field_ids_str_1 = join "," , @all_update_field_ids_1 ; my $all_update_field_ids_str_2 = join "," , @all_update_field_ids_2 ; $jquery_on_change_1 = qq~\$("$all_update_field_ids_str_1").change( function (event) {~ if $all_update_field_ids_str_1 ; $jquery_on_change_2 = qq~\$("$all_update_field_ids_str_2").on('changeDate',function() {~ if $all_update_field_ids_str_2 ; } chop $multi_select_ids if $multi_select_ids ; if ($jquery_on_change_1 || $jquery_on_change_2) { $trigger_jquery_raw .= qq~ function get_row_nr (id,nr_of_characters_in_id_to_determine_row) { // console.log("get_row_nr : "+id) ; // console.log("nr_of_characters_in_id_to_determine_row : "+nr_of_characters_in_id_to_determine_row) ; let lastIndex = id.lastIndexOf('_'); lastIndex = parseInt(lastIndex) ; let row_nr_1 = id.substring(1+lastIndex); if (!nr_of_characters_in_id_to_determine_row || nr_of_characters_in_id_to_determine_row == 1) { return row_nr_1 ; } let id_2 = id.substring(0,lastIndex); lastIndex = id_2.lastIndexOf('_'); lastIndex = parseInt(lastIndex) ; let row_nr_2 = id_2.substring(1+lastIndex); if (nr_of_characters_in_id_to_determine_row == 2) { return row_nr_2+"_"+row_nr_1 ; } let id_3 = id_2.substring(0,lastIndex); lastIndex = id_3.lastIndexOf('_'); lastIndex = parseInt(lastIndex) ; let row_nr_3 = id_3.substring(1+lastIndex); if (nr_of_characters_in_id_to_determine_row == 3) { // console.log("return : "+row_nr_3+"_"+row_nr_2+"_"+row_nr_1) ; return row_nr_3+"_"+row_nr_2+"_"+row_nr_1 ; } } function check_whether_to_update (changed_id) { let row_nr = get_row_nr(changed_id) ; $trigger_jquery_raw_default_alt let nr_of_characters_in_id_to_determine_row = "$nr_of_characters_in_id_to_determine_row" ; if (row_nr == "row") { row_nr = "add_row" ; } else if (nr_of_characters_in_id_to_determine_row == "2") { // Nothing Yet row_nr = get_row_nr(changed_id,2) ; } else if (nr_of_characters_in_id_to_determine_row == "3") { row_nr = get_row_nr(changed_id,3) ; } let def_vals = all_def_vals[row_nr] ; console.log("changed_id val : "+\$("#"+changed_id).val()) ; let tick_update = 0 ; let multi_select_ids = {$multi_select_ids} ; for (const id in def_vals) { console.log("def_vals : "+\$("#"+id).val()) ; if ((\$("#"+id).attr('type') == 'radio' && (\$("#"+id).is(":checked") !== (def_vals[id] === "true"))) || (id.includes('input[name') && def_vals[id] != \$(id).val())) { tick_update = 1 ; } else if (id.includes('datepicker') || id.includes('timepicker')) { console.log("1 tick_update : "+tick_update) ; console.log("11 def_vals : "+def_vals[id]) ; console.log("22 def_vals : "+\$("#"+id).data("date")) ; if (def_vals[id] != \$("#"+id).data("date")) { tick_update = 1 ; } console.log("2 tick_update : "+tick_update) ; } else if (\$("#"+id).attr('type') == 'checkbox') { if ((\$("#"+id).is(":checked") !== (def_vals[id] === "true")) || (!\$("#"+id).is(":checked") !== (def_vals[id] === "false"))) { tick_update = 1 ; } } else if (!multi_select_ids[id] && !id.includes('input[name') && \$("#"+id).attr('type') != 'radio') { let sel_val = \$("#"+id).val() ; if (sel_val == null) { sel_val = '' ; } if (sel_val != def_vals[id]) { tick_update = 1 ; } } else if (multi_select_ids[id]) { let select_multi = \$("#"+id).chosen().val() ; if (select_multi == null) { select_multi = "" ; } if (select_multi != def_vals[id]) { tick_update = 1 ; } } } if (tick_update && !\$("#checkboxUpdate_"+row_nr).is(":checked")) { \$("#checkboxUpdate_"+row_nr).prop("checked",true) ; } else if (!tick_update && \$("#checkboxUpdate_"+row_nr).is(":checked")) { \$("#checkboxUpdate_"+row_nr).prop("checked",false) ; } } ~ ; # $trigger_jquery_raw .= ($ids_short) ? qq~ # \$("#$content_id").on("change","$update_fields_short_1", function (event) { // EXAMPLE: [id^='selectFixture_check_'],[id^='selectStatus_'] # event.preventDefault(); # check_whether_to_update(this.id); # }); # ~ : qq~ # // \$("$all_update_field_ids_str_1").change( function (event) { # $jquery_on_change_1 # event.preventDefault(); # $trigger_jquery_raw_on_change_1 # check_whether_to_update(this.id) ; # }) ; # ~ ; $trigger_jquery_raw .= qq~ $jquery_on_change_1 event.preventDefault(); check_whether_to_update(this.id); }); ~ if $jquery_on_change_1 ; $trigger_jquery_raw .= qq~ $jquery_on_change_2 $trigger_jquery_raw_on_change_2 check_whether_to_update(this.id) ; }) ; ~ if $jquery_on_change_2 && !$no_dates_in_table ; # unless $no_dates_in_table ; } } #------------------------------------------------------------------------------------------ sub common_min_table_update_checkbox_col { my ($nr_of_characters_in_id_to_determine_row,$content_id,$ids_short_1,$ids_short_2) = @_ ; &common_min_table_update_checkbox_col_default ; &common_min_table_update_checkbox_col_jquery($nr_of_characters_in_id_to_determine_row,$content_id,$ids_short_1,$ids_short_2) ; } #------------------------------------------------------------------------------------------ sub common_min_table_checkbox { my ($field_id,$default_val,$only_display_val,$table_row,$table_col,$background_color,$default_val_is_saved) = @_ ; if (!$only_display_val) { my $ucfirstfield = ($ucfirstfield{$field_id}) ? $ucfirstfield{$field_id} : "checkbox" . ucfirst $field_id ; $val = qq~~ ; } else { $val = qq~~ ; } $val_min = '' ; return $val ; } #------------------------------------------------------------------------------------------ sub common_min_table_textarea { my ($field_id,$default_val,$only_display_val,$table_row,$table_col,$background_color,$default_val_is_saved,$col_name,$table_id,$hide_textarea) = @_ ; $val = '' ; $val_min = 'MUSTBEBLANK' ; $table_id = "itv-table" unless $table_id ; if (!$only_display_val && $table_col) { $found_editable = 1 ; # my $print_field = ($preferred_placeholder{$field_id}) ? $preferred_placeholder{$field_id} : &common_min_print_field($field_id) ; my $print_field = ($preferred_placeholder{$field_id}) ? $preferred_placeholder{$field_id} : ($preferred_title{$field_id}) ? $preferred_title{$field_id} : &common_min_print_field($field_id) ; $tindex++ ; $val_min = $default_val if $default_val ; my $ucfirstfield = ($ucfirstfield{$field_id}) ? $ucfirstfield{$field_id} : "textarea" . ucfirst $field_id ; # my $style = ($default_val && $default_val =~ /\n/) ? qq~style="height:100%;"~ : qq~~ ; # $default_val =~ s/\\n/\n/g ; $hide_textarea = ($hide_textarea) ? qq~display:none;~ : qq~~ ; $val = qq~
    ~ ; # $default_val =~ s/\n/\\n/g ; $default_val =~ s/[\n\r]+/\\n/g ; if ($default_val && $default_val_is_saved) { $background_color = "#424949" unless $background_color ; $table_with_default_ids{$background_color} .= "#$table_id tr:eq($table_row) td:nth-last-child($table_col)," ; # $trigger_jquery .= qq~ \$("#$ucfirstfield").css("width","100%") ;~ ; $default_javascript .= qq~"$ucfirstfield":"$default_val",~ ; } elsif ($default_val && !$default_val_is_saved) { $default_javascript .= qq~"$ucfirstfield":"$default_val",~ ; } else { $default_javascript .= qq~"$ucfirstfield":"",~ ; } # box-sizing:border-box;overflow:hidden; # box-sizing:border-box;overflow: hidden; # oninput="adjustHeight(this)" row="1" # $trigger_jquery .= qq~ # window.onload = function() { # var textarea = document.getElementById('$ucfirstfield'); # adjustHeight(textarea,'$ucfirstfield'); # }; # ~ ; # $trigger_jquery .= qq~ # \$("#$ucfirstfield").css("width","100%") ; # ~ ; #$trigger_jquery_raw .= qq~ # \$('#$ucfirstfield').on('input', function() { # // this.style.height = 'auto' ; # // this.style.height = (this.clientHeight) + 'px'; # }) ; # \$('#$ucfirstfield').trigger('input'); # ~ ; } elsif ($default_val) { $val = $default_val ; $val_min = $val ; $val =~ s/\n/\
    /g ; } $val_min =~ s/\\n/ /g ; return $val ; } #------------------------------------------------------------------------------------------ sub common_min_table_input { my ($field_id,$default_val,$only_display_val,$table_row,$table_col,$background_color,$default_val_is_saved,$col_name,$table_id,$hide_input_field) = @_ ; $val = '' ; $val_min = 'MUSTBEBLANK' ; if (!$only_display_val) { $found_editable = 1 ; # my $print_field = ($preferred_placeholder{$field_id}) ? $preferred_placeholder{$field_id} : &common_min_print_field($field_id) ; my $print_field = ($preferred_placeholder{$field_id}) ? $preferred_placeholder{$field_id} : ($preferred_title{$field_id}) ? $preferred_title{$field_id} : &common_min_print_field($field_id) ; $tindex++ ; my $ucfirstfield = ($ucfirstfield{$field_id}) ? $ucfirstfield{$field_id} : "input" . ucfirst $field_id ; $hide_input_field = qq~display:none;~ if $hide_input_field ; $val = qq~
    ~ ; # $trigger_jquery .= qq~ \$("#$ucfirstfield").css("width","100%") ;~ ; if ($default_val && $default_val_is_saved) { $background_color = "#424949" unless $background_color ; $table_with_default_ids{$background_color} .= "#itv-table tr:eq($table_row) td:nth-last-child($table_col)," ; $default_javascript .= qq~"$ucfirstfield":"$default_val",~ ; $val_min = $default_val ; } else { $val_min = '' ; $default_javascript .= qq~"$ucfirstfield":"",~ ; } } else { $val = $default_val ; $val_min = $val ; } return $val ; } #------------------------------------------------------------------------------------------ sub common_min_table_select { my ($field_id,$default_val,$only_display_val,$table_row,$table_col,$background_color,$default_val_is_saved,$col_name,$table_id,$tooltip_1_text) = @_ ; if ($multiple{$field_id}) { $setmultiple = 'multiple' ; } else { $setmultiple = '' ; } $table_id = "itv-table" unless $table_id ; $val = '' ; # $val_min = 'MUSTBEBLANK' ; # if (!$only_display_val && $table_col) { if (!$only_display_val) { $found_editable = 1 ; my $ucfirstfield = ($ucfirstfield{$field_id}) ? $ucfirstfield{$field_id} : "select" . ucfirst $field_id ; my $print_field = ($preferred_placeholder{$field_id}) ? $preferred_placeholder{$field_id} : ($preferred_title{$field_id}) ? "Select $preferred_title{$field_id}" : "Select " . &common_min_print_field($field_id) ; push @all_select_ids,"#$ucfirstfield" if $ucfirstfield ; if ($multiple{$field_id}) { push @all_multi_select_ids,"#$ucfirstfield" if $ucfirstfield ; $multi_select_ids .= qq~"$ucfirstfield":"1",~ if $ucfirstfield ; push @dropdown_multi_chosen_ids,"#$ucfirstfield\_chosen" if $ucfirstfield ; } # $table_select_rows{$table_row} .= qq~#itv-table tr:eq($table_row) td:nth-last-child($table_col),~ ; # $trigger_jquery_raw .= qq~ # \$("#$ucfirstfield").chosen({ allow_single_deselect:true }) ; \$("#itv-table tr:eq($table_row) td:nth-last-child($table_col)").css("z-index","$table_row") ; # ~ ; # my $tooltip_1 = qq~~ ; # if ($tooltip_1_text) { # $tooltip_1 = qq~title data-toggle='tooltip' data-placement='top' data-original-title='$tooltip_1_text'~ ; # } if ($tooltip_1_text) { $add_tooltip{$tooltip_1_text} .= "#$ucfirstfield\_chosen," ; } if (!$col_name) { $val = qq~ ~ ; } else { $val = qq~ ~ ; $opts{$col_name} = $opts{$field_id} unless $opts{$col_name} ; $col_name_select_ids{$col_name} .= "#$ucfirstfield," ; } if ($default_val) { unless ($val_min) { $val_min = $default_val ; $val_min =~ s/\_/ \[/g ; $val_min .= qq~]~ if $val_min =~ /\[/; } push @selects_with_default_ids,"#$ucfirstfield" if $ucfirstfield ; # foreach (split(/\,/,$default_val)) { $selects_by_def_val{$default_val} .= "#$ucfirstfield," if $ucfirstfield ; # } # $trigger_jquery_raw .= qq~ # \$("#$ucfirstfield").val("$default_val") ; # ~ ; # if ($default_val_is_saved) { if ($default_val_is_saved && $table_col) { $background_color = "#424949" unless $background_color ; $table_with_default_ids{$background_color} .= "#$table_id tr:eq($table_row) td:nth-last-child($table_col)," ; $default_javascript .= qq~"$ucfirstfield":"$default_val",~ ; } elsif ($default_val_is_saved && !$table_col) { $default_javascript .= qq~"$ucfirstfield":"$default_val",~ ; } else { $default_javascript .= qq~"$ucfirstfield":"",~ ; } } else { $default_javascript .= qq~"$ucfirstfield":"",~ ; } if ($ucfirstfield) { push @dropdown_chosen_ids,"#$ucfirstfield\_chosen" unless $multiple{$field_id} ; } } elsif ($default_val) { $val = $default_val ; $val_min = $default_val ; $val_min =~ s/\_/ \[/g ; $val_min .= qq~]~ if $val_min =~ /\[/; # $val =~ s/\_/\[/g ; $val =~ s/\_//g ; # $val .= qq~]~ ; # $val_min = $val unless $val_min ; $table_with_default_ids{$background_color} .= "#$table_id tr:eq($table_row) td:nth-last-child($table_col)," if $background_color && $background_color ne "#424949" ; } return $val ; } #------------------------------------------------------------------------------------------ sub common_min_table_textarea_jquery { # $trigger_jquery .= qq~ # function adjustHeight(textarea,id) { # textarea.style.height = 'auto'; // Reset height to auto to get the scroll height # // textarea.style.height = textarea.scrollHeight + 'px'; // Set the height to the scroll height # \$("#"+id).css("height",textarea.scrollHeight+"px") ; # console.log("scrollHeight : "+textarea.scrollHeight) ; # console.log("textarea : "+textarea) ; # console.log("id : "+id) ; # } # ~ ; } #------------------------------------------------------------------------------------------ sub common_min_table_select_jquery { my ($columns_with_selects,$table_id) = @_ ; &common_min_table_select_fixed_width_jquery($columns_with_selects) ; &common_min_table_select_prevent_dropdown_overlap_jquery($table_id) ; &common_min_table_select_default_values_jquery ; &common_min_table_multi_select_jquery ; } #------------------------------------------------------------------------------------------ sub common_min_table_select_fixed_width_jquery { my ($columns_with_selects) = @_ ; return unless $columns_with_selects ; $trigger_jquery_raw .= qq~ \$("$columns_with_selects").css("position","relative") ; \$("$columns_with_selects").css("text-align","center") ; ~ ; my $dropdown_chosen_ids_str = join(',',@dropdown_chosen_ids) ; my $dropdown_multi_chosen_ids_str = join(',',@dropdown_multi_chosen_ids) ; $trigger_jquery .= qq~ \$("$dropdown_multi_chosen_ids_str").css("width","100%") ;~ if $dropdown_multi_chosen_ids_str ; return unless $dropdown_chosen_ids_str ; $trigger_jquery .= qq~ \$("$dropdown_chosen_ids_str").css("position","absolute") ;~ ; $trigger_jquery .= qq~ \$("$dropdown_chosen_ids_str").css("width","90%") ;~ ; $trigger_jquery .= qq~ \$("$dropdown_chosen_ids_str").css("left","5%") ;~ ; $trigger_jquery .= qq~ \$("$dropdown_chosen_ids_str").css("top","50%") ;~ ; $trigger_jquery .= qq~ \$("$dropdown_chosen_ids_str").css("transform","translateY(-50%)") ;~ ; foreach (keys %add_tooltip) { chop $add_tooltip{$_} ; $trigger_jquery .= qq~ \$("$add_tooltip{$_}").attr({ title : '', 'data-original-title': '$_', 'data-toggle': 'tooltip', 'data-placement': 'top' }); ~ ; } } #------------------------------------------------------------------------------------------ sub common_min_table_select_prevent_dropdown_overlap_jquery_1 { my ($table_id) = @_ ; $table_id = "$useropts{table_id}" unless $table_id ; $trigger_jquery .= qq~ function prevent_drop_down_overlap (loading_page) { const table_ = \$('#$table_id').DataTable()._('tr') ; // var table_ =\$("#$table_id").find('tr') ; let row_nr = 1 ; let z_index = 1 ; for (let i = table_.length; i >= 1 ; i--) { if (loading_page) { $hide_other_column_for_logistics_report $hide_columns_by_default } if (!\$("#$table_id tr:eq("+i+") td:nth-last-child(1)").find('input').length && !\$("#$table_id tr:eq("+i+") td:nth-last-child(2)").find('input').length) { continue ; } let columns = table_[row_nr - 1]; for (let col_nr = 1; col_nr <= columns.length ; col_nr++) { if (!\$("#$table_id tr:eq("+i+") td:nth-last-child("+col_nr+")").find('select').length) { continue ; } \$("#$table_id tr:eq("+i+") td:nth-last-child("+col_nr+")").css("z-index",z_index) ; z_index++ ; } row_nr++ ; } // table_ = "" ; } \$('#$table_id th').on('click', function() { prevent_drop_down_overlap(0) ; }); // \$("#select_temp_calibrators_2_length").css("display","none"); // \$("#select_temp_calibrators_2_filter").css("display","none"); // \$("#select_temp_calibrators_2_info").css("display","none"); // \$("#select_temp_calibrators_2_paginate").css("display","none"); ~ ; } #------------------------------------------------------------------------------------------ sub common_min_table_select_prevent_dropdown_overlap_jquery_2 { $trigger_jquery .= qq~ prevent_drop_down_overlap(1) ; ~ ; } #------------------------------------------------------------------------------------------ sub common_min_table_select_prevent_dropdown_overlap_jquery { my ($table_id) = @_ ; &common_min_table_select_prevent_dropdown_overlap_jquery_1($table_id) ; &common_min_table_select_prevent_dropdown_overlap_jquery_2 ; } #------------------------------------------------------------------------------------------ sub common_min_table_select_default_values_jquery { foreach my $col_name (keys %col_name_select_ids) { chop $col_name_select_ids{$col_name} if $col_name_select_ids{$col_name} ; $opts{$col_name} =~ s/\"/\'/g ; $opts{$col_name} =~ s/\' >/\'>/g ; $opts{$col_name} =~ s/\' >/\'>/g ; $trigger_jquery_raw .= qq~ \$("$col_name_select_ids{$col_name}").html("$opts{$col_name}").trigger("chosen:updated") ; ~ ; } my $all_select_ids_str = join(",",@all_select_ids) ; $trigger_jquery_raw .= qq~\$("$all_select_ids_str").chosen({ allow_single_deselect:true }) ;~ ; # $trigger_jquery_raw .= qq~ # \$("$all_select_ids_str").on("change", function () { # console.log("FOCUS!!!!") ; # event.preventDefault() ; # }) ; # ~ ; # $trigger_jquery_raw .= qq~ # // \$("$all_select_ids_str").change( function () { # // console.log("preventDefault") ; # // event.preventDefault() ; # // let scrollContainer = \$('#itv-table_wrapper') ; # // let scrollPosition = scrollContainer.scrollLeft() ; # // console.log("scrollPosition : "+scrollPosition) ; # // scrollContainer.scrollLeft(scrollPosition) ; # // }) ; # ~ ; foreach (keys %table_with_default_ids) { chop $table_with_default_ids{$_} if $table_with_default_ids{$_} ; $trigger_jquery_raw .= qq~ \$("$table_with_default_ids{$_}").css("background-color","$_") ; ~ ; } foreach my $def_val (keys %selects_by_def_val) { chop $selects_by_def_val{$def_val} if $selects_by_def_val{$def_val} ; my $def_val2 = $def_val ; if ($def_val2 =~ /,/) { $def_val2 =~ s/\,/\','/g ; $def_val2 = qq~['$def_val2']~ ; $trigger_jquery_raw .= qq~ \$("$selects_by_def_val{$def_val}").val($def_val2).trigger("chosen:updated") ; ~ ; } else { # foreach (split(/\,/,$selects_by_def_val{$def_val})) { # $trigger_jquery_raw .= qq~ # \$("$_").val("$def_val2").trigger("chosen:updated") ; # ~ ; # } $trigger_jquery_raw .= qq~ \$("$selects_by_def_val{$def_val}").val("$def_val2").trigger("chosen:updated") ; ~ ; } } # my $selects_with_default_ids_str = join(',',@selects_with_default_ids) ; # $trigger_jquery_raw .= qq~ # \$("$selects_with_default_ids_str").trigger("chosen:updated") ; # ~ ; } #------------------------------------------------------------------------------------------ sub common_min_table_multi_select_jquery { # my $all_multi_select_ids_str = join(",",@all_multi_select_ids) ; # foreach (@all_multi_select_ids) { # $trigger_jquery_raw .= qq~set_row_height("$_") ; ~ ; # } # $trigger_jquery_raw .= qq~ # function set_row_height (multi_id) { # let row_nr = get_row_nr(multi_id) ; # let numOptions = \$(multi_id).find('option:selected').length; # var optionHeight = 25; # var padding = 40 ; # let numOptions2 = Math.floor(numOptions/3) ; # var newHeight = numOptions * optionHeight + padding; # console.log("set_row_height : "+multi_id) ; # if (numOptions == '3' || numOptions2 == '0') { # newHeight = 0 ; # } # \$("#"+row_nr).height(newHeight); # } # \$("$all_multi_select_ids_str").change( function() { # set_row_height("#"+this.id) ; # }); # ~ ; } #------------------------------------------------------------------------------------------ sub common_min_table_datepicker { my ($field_id,$default_val,$only_display_val,$table_row,$table_col,$background_color,$default_val_is_saved,$col_name,$table_id,$icon_color,$tooltip_text,$tooltip_1_text,$tooltip_2_text) = @_ ; if ($default_val eq '0000-00-00') { $default_val = '' ; } if (!$only_display_val) { my $ucfirstfield = ($ucfirstfield{$field_id}) ? $ucfirstfield{$field_id} : "datepicker" . ucfirst $field_id ; $tindex++ ; my $tooltip_1 = qq~~ ; my $tooltip_2 = qq~~ ; if ($tooltip_1_text) { $tooltip_1 = qq~title data-toggle='tooltip' data-placement='top' data-original-title='$tooltip_1_text'~ ; } if ($default_val && $add_datepicker_tooltip{$field_id}) { $tooltip_2 = qq~title data-toggle='tooltip' data-placement='top' data-original-title='$default_val'~ ; } elsif ($tooltip_2_text) { $tooltip_2 = qq~title data-toggle='tooltip' data-placement='top' data-original-title='$tooltip_2_text'~ ; } if (!$default_val) { $default_val = "$now_year-$now_mm-$now_dd" ; } ; $icon_color = (!$icon_color) ? 'black' : $icon_color ; $val = qq~
    ~ ; if ($default_val_is_saved) { $background_color = "#424949" unless $background_color ; $table_with_default_ids{$background_color} .= "#itv-table tr:eq($table_row) td:nth-last-child($table_col)," if $table_row && $table_col ; $default_javascript .= qq~"$ucfirstfield":"$default_val",~ if $ucfirstfield ; $val_min = $default_val ; } else { $default_javascript .= qq~"$ucfirstfield":"",~ if $ucfirstfield ; $val_min = '' ; } push @all_datepicker_ids,"#$ucfirstfield" if $ucfirstfield ; push @all_datepicker_names,"input[name='$field_id']" if $field_id ; } else { $val = $default_val ; $val_min = $val ; } # &common_min_form_datepicker_jquery($ucfirst_field); return ($val) ; } #------------------------------------------------------------------------------------------ sub common_min_table_datepicker_jquery { our $all_datepicker_ids_str = join(",",@all_datepicker_ids) ; $trigger_jquery_raw .= qq~ \$('$all_datepicker_ids_str').datepicker({format: "yyyy-mm-dd"}).on('changeDate', function (ev) { \$('.datepicker').hide(); \$("input[name='"+this.id.substring(10).toLowerCase()+"']").val(\$("#"+this.id).data("date")) ; }) ; ~ ; } #------------------------------------------------------------------------------------------ sub common_min_table_timepicker { my ($field_id,$default_val,$only_display_val,$table_row,$table_col,$background_color,$default_val_is_saved,$col_name,$table_id,$icon_color,$tooltip_1_text,$tooltip_2_text) = @_ ; $tindex++; $val = '' ; $val_min = '' ; if (!$only_display_val) { my $ucfirstfield = ($ucfirstfield{$field_id}) ? $ucfirstfield{$field_id} : "timepicker" . ucfirst $field_id ; if (!$default_val) { $default_val = "$now_hour:$now_min:$now_sec" ; } ; my $tooltip_1 = qq~~ ; my $tooltip_2 = qq~~ ; if ($tooltip_1_text) { $tooltip_1 = qq~title data-toggle='tooltip' data-placement='top' data-original-title='$tooltip_1_text'~ ; } if ($default_val && $add_timepicker_tooltip{$field_id}) { $tooltip_2 = qq~title data-toggle='tooltip' data-placement='top' data-original-title='$default_val'~ ; } elsif ($tooltip_2_text) { $tooltip_2 = qq~title data-toggle='tooltip' data-placement='top' data-original-title='$tooltip_2_text'~ ; } $icon_color = (!$icon_color) ? 'black' : $icon_color ; # # # # $val = qq~
    ~ ; if ($default_val && $default_val_is_saved) { $background_color = "#424949" unless $background_color ; $table_with_default_ids{$background_color} .= "#itv-table tr:eq($table_row) td:nth-last-child($table_col)," if $table_row && $table_col ; $default_javascript .= qq~"$ucfirstfield":"$default_val",~ if $ucfirstfield && $default_val ; $val_min = $default_val ; } else { $default_javascript .= qq~"$ucfirstfield":"$default_val",~ if $ucfirstfield ; $val_min = '' ; } push @all_timepicker_ids,"#$ucfirstfield" if $ucfirstfield ; push @all_timepicker_names,"input[name='$field_id']" if $field_id ; # $trigger_jquery_raw .= qq(\$('#timepicker$ucfirst_field').datetimepicker({language:'pt-BR',pickDate:false});) ; } else { $val = $default_val ; $val_min = $val ; } return $val ; } #------------------------------------------------------------------------------------------ sub common_min_table_timepicker_jquery { my ($ids_short) = @_ ; if ($ids_short) { $trigger_jquery_raw .= qq~\$("$ids_short").datetimepicker({language:'pt-BR',pickDate:false});~ ; return ; } our $all_timepicker_ids = join(",",@all_timepicker_ids) ; $trigger_jquery_raw .= qq~\$('$all_timepicker_ids').datetimepicker({language:'pt-BR',pickDate:false});~ ; } #------------------------------------------------------------------------------------------ sub common_min_get_event_quote_button { my ($event_id,$table,$page_url_part) = @_ ; $table = "event_quotes" unless $table ; return unless $event_id ; my $class = 'info' ; my $style = '' ; my $does_not_exist = 0 ; if ($db{$table}{$event_id}{demo_id}) { $style = 'style="background-color:rgb(255,64,255);border-color:rgb(255,64,255);"'; # pink $tt_txt = 'Demo' ; if ($db{$table}{$event_id}{quote_completed}) { $tt_txt = 'Completed ' . $tt_txt ; } elsif ($db{$table}{$event_id}{quote_accepted}) { $tt_txt = 'Accepted ' . $tt_txt ; } elsif ($db{$table}{$event_id}{quote_rejected}) { $tt_txt = 'Rejected ' . $tt_txt ; } elsif ($db{$table}{$event_id}{quote_cancelled}) { $tt_txt = 'Cancelled ' . $tt_txt ; } elsif ($db{$table}{$event_id}{quote_created}) { $tt_txt = 'Pending, Created by School Manager ' . $tt_txt ; } elsif ($db{$table}{$event_id}{quote_pending}) { $tt_txt = 'Pending ' . $tt_txt ; } } elsif ($analytics_events{$event_id}) { $style = 'style="background-color:rgb(255,129,0);border-color:rgb(255,129,0);"'; # pink $tt_txt = 'Analytics Event' ; if ($db{$table}{$event_id}{quote_completed}) { $tt_txt = 'Completed ' . $tt_txt ; } elsif ($db{$table}{$event_id}{quote_accepted}) { $tt_txt = 'Accepted ' . $tt_txt ; } elsif ($db{$table}{$event_id}{quote_rejected}) { $tt_txt = 'Rejected ' . $tt_txt ; } elsif ($db{$table}{$event_id}{quote_cancelled}) { $tt_txt = 'Cancelled ' . $tt_txt ; } elsif ($db{$table}{$event_id}{quote_created}) { $tt_txt = 'Pending, Created by School Manager ' . $tt_txt ; } elsif ($db{$table}{$event_id}{quote_pending}) { $tt_txt = 'Pending ' . $tt_txt ; } } elsif ($db{$table}{$event_id}{quote_completed} || $db{$table}{$event_id}{event_completed} || $quote_completed) { $class = 'success' ; # green $tt_txt = 'Completed' ; } elsif ($db{$table}{$event_id}{quote_accepted} || $db{$table}{$event_id}{event_completed} || $quote_accepted) { $class = 'info' ; # blue $tt_txt = 'Accepted' ; my @fixed_system_overall_statuses = split(/\;/,$db{$table}{$event_id}{fixed_system_overall_status}) ; my @event_system_ids = split(/\;/,$db{$table}{$event_id}{event_system_id_multiple}) ; my $event_sys_cnt = 0 ; my $event_sys_test_status = 0 ; my $got_some_fixed = 0 ; my $fixed_status_color = '164473' ; # Dark Blue foreach my $event_id (@event_system_ids) { if ($db{event_systems}{$event_id}{system_type} eq 'fixed') { $tt_txt = 'Accepted and tests show All Clear for the Fixed Systems' if $tt_txt eq 'Accepted' ; $got_some_fixed = 1 ; if ($fixed_system_overall_statuses[$event_sys_cnt] == 3) { # Not Clear $fixed_status_color = '5d09d3' ; # Dark Purple $tt_txt = 'Accepted but Not Clear on some Fixed Systems' ; } elsif ($fixed_system_overall_statuses[$event_sys_cnt] == 2) { # Sound Issue $fixed_status_color = '5d092c' ; $tt_txt = 'Accepted but Sound Issue found on some Fixed Systems' ; } } $event_sys_cnt++ ; } if ($got_some_fixed) { $style = "style='background-color:#$fixed_status_color;border-color:#$fixed_status_color'"; } } elsif ($db{$table}{$event_id}{quote_rejected} || $db{$table}{$event_id}{event_rejected} || $quote_rejected) { $style = 'style="background-color:#ca0ad3;border-color:#ca0ad3"'; # purple $tt_txt = 'Rejected' ; } elsif ($db{$table}{$event_id}{quote_cancelled} || $db{$table}{$event_id}{event_cancelled} || $quote_cancelled) { $class = 'danger' ; # red $tt_txt = 'Cancelled' ; } elsif ($db{$table}{$event_id}{quote_created} || $db{$table}{$event_id}{event_created} || $quote_created) { # create by schools_manager $style = 'style="background-color:#f6e305;border-color:#f6e305"'; # yellow $tt_txt = 'Pending, Created by School Manager' ; } elsif ($db{$table}{$event_id}{quote_pending} || $db{$table}{$event_id}{event_pending} || $quote_pending) { $class = 'warning' ; # orange $tt_txt = ($db{$table}{$event_id}{sssadmin_quote_nr}) ? 'Pending [Created by SSS platform]' : 'Pending' ; } elsif (!$db{$table}{$event_id}{id}) { $style = 'style="background-color:black;border-color:black"'; $tt_txt = 'Does not Exist!!!' ; $does_not_exist = 1 ; } my $tt = qq~data-toggle="tooltip" data-placement="right" data-title="$tt_txt"~; # ($glod_user_level < 3 && !$is_operator) my $glod_user_level_eff = ($glod_user_level == 2 && $is_operator) ? 3 : $glod_user_level ; my $href = ($page_url_part) ? qq~javascript:editMinItem('$event_id','$page_url_part');~ : qq~javascript:editMinItem('$event_id');~ ; my $event_quote_btn = ($glod_user_level_eff < 3 || $db{$table}{$event_id}{quote_cancelled} || $does_not_exist) ? qq~$event_id~ : qq~$event_id~ ; # || ($db{$table}{$event_id}{quote_completed} && $glod_user_level <= 3) return ($event_quote_btn) ; } #------------------------------------------------------------------------------------------ sub common_min_get_quote_button { my ($quote_id,$table) = @_ ; $table = "quotes" unless $table ; return unless $quote_id ; my $class = 'info' ; my $style = '' ; my $tt_txt = '' ; if ($db{$table}{$quote_id}{quote_cancelled}) { $class = 'danger' ; $tt_txt = 'Cancelled' ; } elsif ($db{$table}{$quote_id}{quote_accepted}) { $class = 'success' ; $tt_txt = 'Accepted' ; } elsif ($quote_expiry and $quote_expiry<"$now_year$now_mm$now_dd") { ### $quote_expiry must be defined $class = 'danger' ; $tt_txt = 'Expired' ; } elsif ($db{$table}{$quote_id}{quote_pending}) { $class = 'warning' ; $tt_txt = 'Pending' ; } my $tt = qq~data-toggle="tooltip" data-placement="right" data-title="$tt_txt"~; my $quote_btn = qq~$db{$table}{$quote_id}{quote_nr}~ ; return ($quote_btn) ; } #------------------------------------------------------------------------------------------ # sub common_min_date_as_string { # my ($date) = @_ ; # my ($yr,$mon,$day) = split("-",$date) ; ## our @months = ("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") ; # return ("$day-$months[$mon]-$yr") ; # } #------------------------------------------------------------------------------------------ sub common_min_date_as_string { my ($date) = @_ ; return if $date !~ /(\d+)/g ; my ($yr,$mon,$day) = split("-",substr($date,0,10)) ; ## our @months = ("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") ; if (substr($date,11,5)) { return ("$day-$months[$mon]-$yr \@ " . substr($date,11,5)) ; } else { return ("$day-$months[$mon]-$yr") ; } } #------------------------------------------------------------------------------------------ sub greater_date_time { local ($date_time_1,$date_time_2) = @_ ; return Time::Piece->strptime($date_time_1,'%Y-%m-%d %H:%M:%S') <= Time::Piece->strptime($date_time_2,'%Y-%m-%d %H:%M:%S') ; } #------------------------------------------------------------------------------------------ sub common_min_greater_date_time { local ($date_time_1,$date_time_2) = @_ ; return Time::Piece->strptime($date_time_1,'%Y-%m-%d %H:%M:%S') <= Time::Piece->strptime($date_time_2,'%Y-%m-%d %H:%M:%S') ; } #------------------------------------------------------------------------------------------ sub common_min_greater_date { local ($date_1,$date_2) = @_ ; return Time::Piece->strptime($date_1,'%Y-%m-%d') <= Time::Piece->strptime($date_2,'%Y-%m-%d') ; } #------------------------------------------------------------------------------------------ sub common_min_calc_time_diff { local ($date_time_1,$date_time_2) = @_ ; return "blank_date" if !$date_time_1 || !$date_time_2 ; return (Time::Piece->strptime($date_time_2,'%Y-%m-%d %H:%M:%S') - Time::Piece->strptime($date_time_1,'%Y-%m-%d %H:%M:%S')) ; } #------------------------------------------------------------------------------------------ sub common_min_calc_day_diff { local ($date_1,$date_2) = @_ ; return 1 + abs(Time::Piece->strptime(substr($date_2,0,10),'%Y-%m-%d') - Time::Piece->strptime(substr($date_1,0,10),'%Y-%m-%d'))->days ; } #------------------------------------------------------------------------------------------ sub common_min_delete_files { my ($dir,$file_name) = @_ ; return if !$dir || ($dir && not -d $dir) || ($file_name && not -f "$dir/$file_name") ; my @files = () ; my $dh ; if ($file_name) { push @files,$file_name ; } else { opendir($dh, $dir) or die "Cannot open directory: $!"; @files = grep { !/^\.\.?$/ } readdir($dh); } foreach my $file (@files) { my $file_path = "$dir/$file" ; if (-f $file_path) { unlink ("$file_path") or print "\n unable to unlink - $file_path : $!"; } } if (!$file_name) { closedir($dh); } } #------------------------------------------------------------------------------------------ sub common_min_copy_files { # # # # use File::Copy; Make Sure THis is called ; my ($dir_from,$dir_to,$file_name) = @_ ; return if !$dir_from || !$dir_to || not -d $dir_from || ($file_name && not -f "$dir_from/$file_name"); mkdir $dir_to if not -d $dir_to; my @files = () ; my $dh ; if ($file_name) { push @files,$file_name ; } else { opendir($dh,$dir_from) or die "Can't open $dir_from: $!"; my $file_counter = 0 ; @files = readdir($dh); } foreach my $file (@files) { next if $file =~ /^\.\.?$/ ; my $src_file = "$dir_from/$file"; my $dst_file = "$dir_to/$file"; if (-f $src_file) { copy("$src_file","$dst_file") or die "File cannot be copied." ; } } if (!$file_name) { closedir($dh); } } #------------------------------------------------------------------------------------------ 1;