includes/clientside/static/admin-menu.js
changeset 1118 e26e74d80c15
parent 1046 cfc6c30c5e2d
child 1227 bdac73ed481e
equal deleted inserted replaced
1117:4d8ffe107a0d 1118:e26e74d80c15
   214 {
   214 {
   215   text = text.replace(/\\/g, '\\\\');
   215   text = text.replace(/\\/g, '\\\\');
   216   text = text.replace(/"/g, '\\"');
   216   text = text.replace(/"/g, '\\"');
   217   return text;
   217   return text;
   218 }
   218 }
       
   219 
       
   220 // *******************************************
       
   221 //  Table collapsing
       
   222 // *******************************************
       
   223 
       
   224 function admin_table_onload(page)
       
   225 {
       
   226   if ( page != namespace_list['Admin'] + 'GeneralConfig' )
       
   227   {
       
   228     return true;
       
   229   }
       
   230   var collapse_state = admin_table_get_cookie(page);
       
   231   if ( collapse_state == 0 )
       
   232     collapse_state = 0xffffffff;
       
   233   $('#ajaxPageContainer > form > div.tblholder > table').each(function(i, table)
       
   234     {
       
   235       // skip if this is a one-row table
       
   236       if ( $('tr:first', table).get(0) == $('tr:last', table).get(0) )
       
   237         return;
       
   238       
       
   239       var open = (collapse_state >> i) & 1 > 0 ? true : false;
       
   240       
       
   241       var ypos = open ? 0 : 12;
       
   242       
       
   243       var div = document.createElement('div');
       
   244       $(div).html(gen_sprite_html(scriptPath + '/themes/admin/images/thcollapse.png', 12, 12, ypos, 0));
       
   245       $(div).click(function()
       
   246         {
       
   247           admin_table_click(this);
       
   248         }).css('cursor', 'pointer').css('float', 'right');
       
   249       div.thetable = table;
       
   250       div.index = i;
       
   251       div.thepage = page;
       
   252       div.openstate = open;
       
   253       $('tr > th:first', table).prepend(div);
       
   254       if ( !open )
       
   255         admin_table_collapse(table, true);
       
   256     });
       
   257 }
       
   258 
       
   259 function admin_table_click(mydiv)
       
   260 {
       
   261   var table = mydiv.thetable;
       
   262   var i = mydiv.index;
       
   263   var page = mydiv.thepage;
       
   264   var collapse_state = admin_table_get_cookie(page);
       
   265   
       
   266   if ( mydiv.openstate )
       
   267   {
       
   268     $('img', mydiv).css('background-position', '0px -12px');
       
   269     var new_collapse_state = collapse_state & ~Math.pow(2, i);
       
   270     console.debug(new_collapse_state);
       
   271     mydiv.openstate = false;
       
   272     admin_table_collapse(table);
       
   273   }
       
   274   else
       
   275   {
       
   276     $('img', mydiv).css('background-position', '0px 0px');
       
   277     var new_collapse_state = collapse_state | Math.pow(2, i);
       
   278     console.debug(new_collapse_state);
       
   279     mydiv.openstate = true;
       
   280     admin_table_expand(table);
       
   281   }
       
   282   createCookie('admin_th:' + page, new_collapse_state, 3650);
       
   283 }
       
   284 
       
   285 function admin_table_get_cookie(page)
       
   286 {
       
   287   var cookievalue = parseInt(readCookie('admin_th:' + page));
       
   288   if ( isNaN(cookievalue) )
       
   289     cookievalue = 0;
       
   290   return cookievalue;
       
   291 }
       
   292 
       
   293 function admin_table_collapse(table, noanim)
       
   294 {
       
   295   var targetheight = $('tr > th:first', table).height();
       
   296   $('tr', table).hide();
       
   297   $('tr:first', table).show();
       
   298 }
       
   299 
       
   300 function admin_table_expand(table)
       
   301 {
       
   302   $('tr', table).show();
       
   303 }