source: timingandestimationplugin/branches/trac1.0-Permissions/timingandestimationplugin/htdocs/change_layout.js

Last change on this file was 16690, checked in by Russ Tyndall, 6 years ago

make HoursLayoutChanger respect long fields (colspan=3)

re #10547
re #11657

File size: 2.7 KB
Line 
1// Move the add hours box next to the comment box
2var TandE_MoveAddHours = function(){
3  // Couldnt find the comment box, lets just abort
4  if ($('#comment').length == 0) return;
5  var tbl, hours, colClass, tr, replacement;
6  tbl = $('<table style="border:1px solid #D7D7D7;" border="0" cellpadding="3" cellspacing="0"><tbody><tr></tr></tbody></table>');
7  $('#comment').parent().parent().after(tbl);
8  hours = $('#field-hours');
9  colClass = hours.parent().attr("class");
10  tr = hours.parent().parent();
11  $(tbl[0].rows[0]).append($('.'+colClass, tr));
12  replacement = $('<td class="'+colClass+'"></td>');
13  tr.prepend(replacement.clone()).prepend(replacement.clone());
14};
15
16/*
17 * Rewritten by Russ Tyndall when this started failing on Trac 1
18 *
19 *   Code by Josh Godsiff, for www.oxideinteractive.com.au
20 *   Email: josh@oxideinteractive.com.au
21 */
22$.prototype.cleanupTable = function() {
23  // make sure that body
24  if($(this).is('table')) {
25    var bodies = $(this).children('thead, tbody, tfoot');
26  } else if($(this).is('thead, tbody, tfoot')) {
27    var bodies = $(this);
28  } else {
29    return;
30  }
31  // helper to determine if a table cell has visible content
32  var has_contents =function has_contents(it){
33    if(!it) return it;
34    var t=$(it).text();
35    if(t && $.trim(t).length>0 ) return true;
36    return false;
37  };
38  var push = function push(l, k0, k1){
39    if(has_contents(k0) || has_contents(k1)) l.push([k0, k1]);
40  }
41  $(bodies).each(function(bodyIdx, body){
42    body = $(body);
43    var trs = $(body).children('tr');
44    var leftTds=[], rightTds=[];
45    $(trs).each(function(ind, val){
46      var kids = $(this).children();
47
48      push(leftTds, kids[0], kids[1]);
49      push(rightTds, kids[2], kids[3]);
50      $(this).detach();
51    });
52    //console.log('Reordering Fields: \nleft:', leftTds, '\nright:',rightTds);
53    while(leftTds.length>0 || rightTds.length>0){
54      var tr = $('<tr>');
55      var leftContent = leftTds.shift() || rightTds.shift();
56      tr.append(leftContent[0]).append(leftContent[1]);
57      if($(leftContent[1]).attr('colspan')!="3"){ // dont already have a full row
58        var rightContent = rightTds.shift();
59        if(rightContent) tr.append(rightContent[0]).append(rightContent[1]);
60      }
61      $(body).append(tr);
62    }
63    // console.log('Finished Reordering Fields: \nleft:', leftTds, '\nright:',rightTds);
64  });
65};
66
67$(document).ready(function() {
68  // Give other layout changing functions time to run
69
70  // move add hours input to next to the comment box
71  TandE_MoveAddHours();
72  // remove add_hours from header
73  $('#h_hours,#h_hours + td').empty();
74
75  //remove whitespace caused by the above
76  $('#properties table').cleanupTable();
77  $('table.properties').cleanupTable();
78
79});
Note: See TracBrowser for help on using the repository browser.