<% my $am = eval { return decode_json $settings->{'app_measures'} } || $settings->{'app_measures'} || {}; %>
<% my $gbm = $gb::pos->{$settings->{'pos'}}->{'app_measures'}; %>
<% my $gb_measures; %>
<% if ($gb::pos->{$settings->{'pos'}}->{'app_measures'} || $am ) { %>
	<% 
		if ($gbm) {
			my %gb_measures = %{$gbm};
			$gb_measures = \%gb_measures;
		}
		foreach my $ameas ( keys %{$am} ) {
			unless ($gb_measures->{$ameas}) {
				$gb_measures->{$ameas} = {};
			}
		}
	%>
	<% foreach my $meas ( sort keys %{$am}) { %>

		<% $am->{$meas} = {} unless eval { keys %{$am->{$meas}} }; %>
		<% my $m = $am->{$meas} || $gb::pos->{$settings->{'pos'}}->{'app_measures'}->{$meas}; %>
		<% next if $m->{'type'} eq 'none'; %>
		<b><%= &subs::format_name($meas) %></b><br>
		<% if ($m->{'type'} eq 'select') { %>
			<select class="app_measure" measure="<%= $meas %>" value="<%= $am->{$meas}->{'value'} %>" unit="<%= $am->{$meas}->{'unit'} %>" style="width:100%;">
				<option value=""></option>
				<% foreach my $me ( @{$m->{'options'}} ) { %>
					<option <% if ($me eq $am->{$meas}) { %>selected <% } %> value="<%= $me %>"><%= &subs::format_name($me) %></option>
				<% } %>
			</select>
		<% } elsif ($m->{'type'} eq 'range') { %>
			<input type="range" class="app_measure" measure="<%= $meas %>" min="<%= $m->{'min'} || 0 %>" max="<%= $m->{'max'} || 100 %>" value="<%= $am->{$meas}->{'value'} %>" unit="<%= $m->{'unit'} %>" style="width:80%;">
			<span class="app_measure_display"measure="<%= $meas %>"><%= $am->{$meas}->{'value'} %></span>
		<% } else { %>
			<input class="app_measure" measure="<%= $meas %>" value="<%= $am->{$meas}->{'value'} %>" placeholder="<%= &subs::format_name($meas) %>" unit="<%= $m->{'unit'} %>" style="width:98%;text-align:center;">
		<% } %><br>
		<table style="width:100%;">
		<%
		my $o = {};
		my $ia = $appts->{$a}->{'settings'}->{'ia'};
		foreach my $chip ( keys %{$ia} ) {
			foreach my $i ( keys %{$ia->{$chip}} ) {
				
				if ($ia->{$chip}->{$i}->{'measure'} eq $meas) {
					if ($ia->{$chip}->{$i}->{'threshold'}) {

						%>
						<tr>
							<td>
								<% if ($ia->{$chip}->{$i}->{'name'}) { %><b><%= &subs::format_name($ia->{$chip}->{$i}->{'name'}) %></b> <% } %>
							</td>
							<td>
								<%= $ia->{$chip}->{$i}->{'component'} %>
							</td>
							<td>
								<input type="number" min="<%= $m->{'min'} || 0 %>" max="<%= $m->{'max'} || 100 %>" step=".1" value="<%= $ia->{$chip}->{$i}->{'threshold'} %>" style="text-align:center;" chip_id="<%= $chip %>" edt="<%= $ia->{$chip}->{$i}->{'edt'} %>"
								class="watch_setting" setting="threshold" numero="<%= $i %>" component="<%= $ia->{$chip}->{$i}->{'component'} %>">
							</td>
						</tr>
						<br>
						<%
					}
				}
			}
		} %>
		</table>
		<br>
	<% } %>

<% } %>

<img src="/images/decipherable/diskette.png" class="little_thumb app_measure_save hover" style="vertical-align:bottom;" app="<%= $a %>">