1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
|
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
var dataTable;
var my_panel_entry;
var active;
//var stopx;
var origValue;
//var newBackg;
var my_columns = [];
var dataSet = [];
var stripped_dataSet = [];
//var startInd = '';
var oldValue = '';
var s = 0;
var panel_status = 0;
//var userId = 0
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
$(document).ready(function() {
// Initialize------------------------------------------------------------//
initialize();
// DrawDataTable --------------------------------------------------------//
drawDataTable();
// Finalize -------------------------------------------------------------//
finalize();
s=1;
});
window.onresize = function(){
// Initialize------------------------------------------------------------//
initialize();
// ResetTable------------------------------------------------------------//
resetTable();
// CellStatus------------------------------------------------------------//
cellStatus();
};
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
function initialize(){
var winWidth = $(window).width();
var winHeight = $(window).height();
var nbr = $('.menu_item').length;
//Set page borders --------------------------------------------------//
$('.border_top' ).height(2); $('.border_top' ).width (winWidth );
$('.border_left' ).width (2); $('.border_left' ).height(winHeight-4);
$('.border_right' ).width (2); $('.border_right' ).height(winHeight-4);
$('.border_bottom').height(2); $('.border_bottom').width (winWidth );
//Menu items --------------------------------------------------------//
$('.menu' ).width(winWidth-4);
$('.menu_item' ).width((winWidth-155)/nbr);
$('.menu' ).fadeIn(300);
}
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
function drawDataTable(){
my_columns = [];
dataSet = [];
stripped_dataSet = [];
if(s==1){dataTable.destroy();};
getTableData();
}
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
function getTableData(){
$.ajax({
type : 'GET',
url : 'php/ajax/get_table_values.php',
data : 'value=1',
dataType: 'json',
cache : false
})
.done(function(response){
console.log("reponse :",response);
dataSet = response;
$.each(dataSet[0], function(key, value)
{
var my_item = {};
my_item.data = key ;
my_item.title = key ;
my_columns.push(my_item);
});
dataTable = $('.table_x').DataTable({
'bInfo' : false,
'paging' : false,
'scrollX' : false,
'processing': false,
'sDom' : 'ltipr',
'order' : [[0,"asc"]],
'colReorder': {realtime:true},
'data' : dataSet,
'columns' : my_columns
});
dataTable.colReorder.disable();
for(var i=0;i<= my_columns.length;i++){if(i>1){$('.table_x th:nth-child('+i+')').append('<div class="expand"></div>');};};
resetTable();
cellStatus();
})
.fail(function(response){
alert('Erreur ajax :'+response.responseText);
});
}
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
function resetTable(){
var this_text;
var this_index;
var old_th_width;
var new_th_width = 0;
var th_width = 0;
var thw = $('.table_holder').width();
if(s==0){
$('.table_x th').each(function(){
var this_text= $(this).text();
var this_html= $(this).html();
active= this_text.substr(this_text.length - 1);
if(active==0){
var tableColumn = dataTable.column($(this).index());
tableColumn.visible(false);
}
$(this).html(this_html.replace(this_text,(this_text.slice(0, -2))));
});
};
$('.table_x' ).width(thw)
$('.table_x th').css ('width','auto');
$('.table_x td:first-child').each(function(){
old_th_width = th_width;
var element=$(this).clone()
.css({'display': 'inline', 'width': 'auto', 'visibility' : 'hidden',
'font-family': 'Lato','font-size':'11px','font-weight':'400',
'position': 'absolute','top':'0px','left':'0px','padding':10
})
.appendTo('body');
var rect = element[0].getBoundingClientRect();
th_width = rect.right - rect.left;
element.remove();
if(th_width > old_th_width){new_th_width = th_width;}
});
$('.table_x th:first-child').css ('width',(new_th_width-23));
$('.expand').each(function(){var wi=$(this).parent().outerWidth()-3;$('.expand').width(wi)})
$('.panel').height($(window).height()-4);
}
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
function cellStatus(){
$(".table_x th").each(function(){
var count = 0;
var indx_th = $(this).index();
var related_th = $(this);
$(".table_x td:nth-child("+(indx_th+1)+")").each(function(){
var element = $(this)
.clone()
.css({'display': 'inline', 'width': 'auto', 'visibility' : 'hidden',
'font-family': 'Lato','font-size':'11px','font-weight':'400',
'position': 'absolute','top':'0px','left':'0px','padding':'10px'
})
.appendTo('body');
var rect1 = $(this)[0].getBoundingClientRect();
var rect2 = element[0].getBoundingClientRect();
var td_minimized_width = rect1.right - rect1.left;
var td_maximized_width = rect2.right - rect2.left;
element.remove();
if( td_maximized_width + 0.954 > td_minimized_width){if(! $(this).hasClass('truncated')){$(this).addClass('truncated');};count=1;}
else{if($(this).hasClass('truncated')){$(this).removeClass('truncated');};}
});
if(count==1){
if(!related_th.hasClass('expandable')){
related_th.addClass('expandable');
related_th.find('.expand').stop().fadeIn(400);
};
}
else{
if( related_th.hasClass('expandable')){
related_th.removeClass('expandable');
related_th.find('.expand').stop().fadeOut(400);
};
}
});
}
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
function finalize(){
//Set search and buttons --------------------------------------------------//
var ref= $('.menu').height() + $('.table_x').height()+49;
$('.affichage_biens').css ('top',ref)
$('.nouveau' ).css ('top',ref)
$('.nouveau' ).fadeIn(0);
$('.affichage_biens').fadeIn(0);
$('.searchbox' ).fadeIn(0);
//Datatable Search -------------------------------------------------//
$('.search' ).keyup (function(){dataTable.search(this.value).draw();});
$('.search' ).focus (function(){if($('.search').val()=='Recherche'){$('.search').val('');};});
$('.search' ).blur (function(){if($('.search').val()==''){$('.search').val('Recherche');};});
// Set table stuff-------------------------------------------------------//
$( 'body' ).attr ('unselectable','on').on('selectstart',false );
$( 'header' ).attr ('unselectable','on').on('selectstart',false );
$('.container' ).attr ('unselectable','on').on('selectstart',false );
$('.table_holder' ).attr ('unselectable','on').on('selectstart',false );
$('.table_x' ).attr ('unselectable','on').on('selectstart',false );
$('.table_expand' ).attr ('unselectable','on').on('selectstart',false );
}
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
function getpanelData(){
$.ajax({
type : 'GET',
url : 'php/ajax/get_panel_values.php',
data : 'value=1',
dataType: 'json',
cache : false
})
.done(function(response){
var k=0;
$('.panel_list').empty();
$.each(dataSet[0], function(key, value){
active = key.substr(key.length - 1);
key= key.slice(0, -2);
var my_item = {};
my_item.title = key ;
if(k >0){
if((k >0) && (active >0)){
my_panel_entry = '<li class= "ticked" data-columnindex="'+k+'"><div class="titre_pan">'+
my_item.title+'</div><div class="tick_pan"></div></li>';
}
else{
my_panel_entry = '<li class="unticked" data-columnindex="'+k+'"><div class="titre_pan">'+
my_item.title+'</div><div class="tick_pan"></div></li>';
}
$('.panel_list').append(my_panel_entry);
}
k++;
});
})
.fail(function(err){alert("erreur ajax getpanelData :"+err.responseText);});
}
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
function setTableOrder(str)
{
$.ajax({
type : 'POST',
url : 'php/ajax/set_table_order.php',
data : 'value='+str,
datatype: 'json',
cache : false/*,
async : false,
success : function(response){}*/
});
}
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
//panel Display ---------------------------------------------------//
$(document).on('click','.affichage_biens',function(e){e.stopPropagation();
getpanelData();
if(panel_status==0){
$('.rideau' ).css ('display','block');
$('.rideau' ).animate({opacity: 0.6}, 500, function() {});
$('.panel' ).animate({right: "0px"}, 700, function() {});
$('.affichage_biens').animate({'margin-right': '+=55'}, 700, function() {});
$('.affichage_biens').text ('Fermer');
panel_status=1;
}
else{
$('.rideau' ).animate({opacity: 0}, 500, function() {$('.rideau').css('display','none');});
$('.panel' ).animate({right: "-250px"}, 700, function() {});
$('.affichage_biens').animate({'margin-right': '-=55'}, 700, function() {});
$('.affichage_biens').text ('Affichage');
panel_status=0;
};
});
//panel Sortable --------------------------------------------------//
$( ".panel_list" ).sortable({
placeholder: 'panel_highlight',
tolerance : 'pointer',
axis : 'y',
opacity : 0.6,
cancel : '.unticked',
start: function(event, ui){
dataTable.colReorder.enable(true);
$('.table_x th').css('background',"none")
.closest('table').find('th:contains("'+ui.item.text().trim()+'")')
.css('background-color','#4c3c49');
ui.item.css('background','#6a5466');
},
change: function(event, ui){
var from_ = $('.table_x th:contains("'+ui.item.text().trim()+'")').index()
,to_ = ui.placeholder.index();
$('.table_x th').css('background',"none")
.closest('table').find('th:contains("'+ui.item.text().trim()+'")')
.css('background-color','#4c3c49');
dataTable.colReorder.move(from_,to_);
},
stop: function(event, ui){
ui.item.css({backgroundColor: "#212933" });
var str='Alias__';
$(".ticked").each(function(){str=str+$(this).text()+'__';})
setTableOrder(str);
dataTable.colReorder.disable(true);
}
});
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/ |