Skip to content

Commit

Permalink
change bit text inputs to radio inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
soif committed Apr 26, 2017
1 parent 4a95d15 commit f6a1e0b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 17 deletions.
75 changes: 58 additions & 17 deletions www/inc/smarty/skins/default/pages/utils_calc.tpl
Expand Up @@ -4,7 +4,8 @@
<div class='div_calc'>
<table class="table table_code">
<tr class='tr_label'>
<td class='td_name'>Label</td>
<td class='td_name'>Label :</td>
<td class='td_name2'></td>
<td class=''>1</td>
<td class=''>2</td>
<td class=''>3</td>
Expand All @@ -17,30 +18,62 @@
<td class=''>D</td>
</tr>
<tr class='tr_dip'>
<td class='td_name'>DIP Values</td>
<td class=''><input type='text' name='ab400_h[0]' value='0' size=1></td>
<td class=''><input type='text' name='ab400_h[1]' value='0' size=1></td>
<td class=''><input type='text' name='ab400_h[2]' value='0' size=1></td>
<td class=''><input type='text' name='ab400_h[3]' value='0' size=1></td>
<td class='td_name'>DIP Values :</td>
<td class='td_name2'>1<br>0</td>
<td class=''>
<input type='radio' name='ab400_h[0]' value='1'><br>
<input type='radio' name='ab400_h[0]' value='0' checked="checked">
</td>
<td class=''>
<input type='radio' name='ab400_h[1]' value='1'><br>
<input type='radio' name='ab400_h[1]' value='0' checked="checked">
</td>
<td class=''>
<input type='radio' name='ab400_h[2]' value='1'><br>
<input type='radio' name='ab400_h[2]' value='0' checked="checked">
</td>
<td class=''>
<input type='radio' name='ab400_h[3]' value='1'><br>
<input type='radio' name='ab400_h[3]' value='0' checked="checked">
</td>

<td class='td_sep'></td>
<td class=''><input type='text' name='ab400_u[1]' value='0' size=1></td>
<td class=''><input type='text' name='ab400_u[2]' value='0' size=1></td>
<td class=''><input type='text' name='ab400_u[3]' value='0' size=1></td>
<td class=''><input type='text' name='ab400_u[4]' value='0' size=1></td>
<td class=''><input type='text' name='ab400_u[0]' value='0' size=1></td>

<td class=''>
<input type='radio' name='ab400_u[1]' value='1'><br>
<input type='radio' name='ab400_u[1]' value='0' checked="checked">
</td>
<td class=''>
<input type='radio' name='ab400_u[2]' value='1'><br>
<input type='radio' name='ab400_u[2]' value='0' checked="checked">
</td>
<td class=''>
<input type='radio' name='ab400_u[3]' value='1'><br>
<input type='radio' name='ab400_u[3]' value='0' checked="checked">
</td>
<td class=''>
<input type='radio' name='ab400_u[4]' value='1'><br>
<input type='radio' name='ab400_u[4]' value='0' checked="checked">
</td>
<td class=''>
<input type='radio' name='ab400_u[0]' value='1'><br>
<input type='radio' name='ab400_u[0]' value='0' checked="checked">
</td>
</tr>
<tr class='tr_code'>
<td class='td_name'>Code</td>
<td class='td_code' colspan=4>House : <input type='text' id='ab400_house' value='' size=2></td>
<td class='td_name'>Code :</td>
<td class='td_name2'></td>
<td class='td_code' colspan=4>House <input type='text' id='ab400_house' value='' size=2></td>
<td class='td_sep'></td>
<td class='td_code' colspan=6>Unit : <input type='text' id='ab400_unit' value='' size=2></td>
<td class='td_code' colspan=6>Unit <input type='text' id='ab400_unit' value='' size=2></td>
</tr>
</table>
<span id='d'></span>
</div>


<script language=javascript>
/* --------------------------------------------- */
$(document).ready(function() {
$('#ab400_house').keyup(function(){
var val = $(this).val();
Expand All @@ -55,17 +88,22 @@ $(document).ready(function() {
ab400_BindBinaryForm('ab400_u');
});
/* --------------------------------------------- */
function ab400_BindBinaryForm(id){
$('input[name^="'+id+'["]').each(function(i) {
$("input[name='"+id+'['+i+"]']").keyup(function(){
/* $("input[name='"+id+'['+i+"]']").keyup(function(){ */
$("input[name='"+id+'['+i+"]']").change(function(){
ab400_ParseBinaryForm(id);
});
});
}
/* --------------------------------------------- */
function ab400_ParseBinaryForm(id){
var bin='';
for(i = 0; i < 7; i++){
var bit=$("input[name='"+id+'['+i+"]']");
/* var bit=$("input[name='"+id+'['+i+"]']"); */
var bit=$("input[name='"+id+'['+i+"]']:checked");
if(bit.length){
bin +=bit.val();
}
Expand All @@ -85,17 +123,20 @@ function ab400_ParseBinaryForm(id){
console.log(id+'='+bin+' --> '+val);
}
/* --------------------------------------------- */
function DecToBinForm(val, len, id){
if(isNaN(val)){
val=0
}
var bin =PadBinary(Number(val).toString(2),len);
console.log('val: '+val+', bin: '+bin);
for(i = 0; i < len; i++){
$("input[name='"+id+'['+i+"]']").val(bin[i]);
/* $("input[name='"+id+'['+i+"]']").val(bin[i]); */
$("input[name='"+id+'['+i+"]'][value="+bin[i]+"]").attr('checked', 'checked');
}
}
/* --------------------------------------------- */
function PadBinary(n, p, c) {
var pad_char = typeof c !== 'undefined' ? c : '0';
var pad = new Array(1 + p).join(pad_char);
Expand Down
4 changes: 4 additions & 0 deletions www/static/global/css/main.css
Expand Up @@ -1089,6 +1089,9 @@ html, body {
#body_utils_calc .tr_dip td{
padding-bottom: 25px;
}
#body_utils_calc .tr_dip INPUT{
margin-bottom: 3px;
}
#body_utils_calc .tr_label td,
#body_utils_calc .tr_dip input{
text-align:center
Expand All @@ -1099,6 +1102,7 @@ html, body {
}
#body_utils_calc .td_code INPUT{
margin-left: 10px;
text-align: center;
}
#body_utils_calc td.td_name{
text-align: right;
Expand Down

0 comments on commit f6a1e0b

Please sign in to comment.