datatables, boostrap, prix
by Akram kamal
HTML
<link rel="stylesheet" href="http://eternicode.github.io/bootstrap-datepicker/bootstrap-datepicker/css/datepicker.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.0/css/jquery.dataTables.css">
<script src="https://cdn.datatables.net/1.10.0/js/jquery.dataTables.js"></script>
<script src="http://eternicode.github.io/bootstrap-datepicker/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<link rel="stylesheet" href="http://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css">
<div class="tab-pane" id="rund_tab_pri_6">
<!-- class="tab-pane" id="rund_tab_pri -->
<br/>
<div class="form-group">
<label for="pritypnum_6" class="control-label col-lg-3"><small>Type :</small></label>
<select name="pritypnum_6" id="pritypnum_6" class="form-control col-lg-6 prityp">
<option value="0" selected>Pas de vente en ligne
</option><option value="1" selected>Prix par bornes de dates
</option><option value="2" >Prix par tranches d'inscriptions
</option>
</select>
</div>
<div id="pri_blk_6" style="display:none">
<div class="form-group">
<label for="strtbuydat_6" class="control-label col-lg-3">
<small>Ouverture des achats :</small>
</label>
...
JavaScript
$(document).ready(function() {
//Init pages vars
var nowTemp = new Date();
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
var runp_idx_dyn = 0;
var formatPriTable = function (idx, val){
var table = $('#t_pri_'+idx).DataTable();
if(val==1){
table.column( 1 ).visible( true );
table.column( 2 ).visible( true );
table.column( 3 ).visible( false );
table.column( 4 ).visible( false );
}
else if(val==2){
table.column( 1 ).visible( false );
table.column( 2 ).visible( false );
table.column( 3 ).visible( true );
table.column( 4 ).visible( true );
}
}
//jQuery.fn.reverse = [].reverse;
var CheckPrices = function(table_id){
table = $('#'+table_id).DataTable();
var table_idx = table_id.substring(6);
var pritypnum = $('#pritypnum_'+table_idx).val();
var ret = true;
if(pritypnum == 0)
return true;
else if(pritypnum == 1){
var prec_date = $('#strtbuydat_'+table_idx).datepicker('getDate');
//Get prices dates
var dates = [];
table.$("tr", {"filter":"applied"}).each(function(index, row){
dates.push($(row).find('input[id^="strtbuydat_"]:first'));
dates.push($(row).find('input[id^="endbuydat_"]:first'));
});
//Loop on prices dates
for(var i=0;i<dates.length;i++){
var test_date = $(dates[i]).datepicker('getDate');
alert('rund : '+table_idx+' : '+prec_date +" vs "+test_date);
//Test 1st date
if(i==0 && test_date != prec_date){
ret = "La date de la première tranche de prix doit être égale à la date d'ouverture des achats";
break;
}
else if( test_date < prec_date){
ret = "Date n° "+(i+1)+" ne peut être inférieure à la précédente";
break;
}
//Set precdate
prec_date = test_date;
}
//Test de la présence d'un tarif
if(dates.length<2){
ret = "Vous devez renseigner au moins un tarif pour les ventes en ligne";
}
//Test de la dernière date
else if(prec_date <...