[795] | 1 | function constructTable(header, content, atributes) |
---|
| 2 | { |
---|
| 3 | /*** constrói a tabela ***/ |
---|
| 4 | var table = document.createElement("TABLE"); |
---|
| 5 | |
---|
[2042] | 6 | table.style.marginTop = "10px"; |
---|
| 7 | |
---|
[795] | 8 | /* configura a tabela */ |
---|
| 9 | if (atributes) |
---|
| 10 | for (i in atributes) |
---|
| 11 | if (typeof atributes[i] != "function") |
---|
| 12 | table.setAttribute(i, atributes[i]); |
---|
| 13 | |
---|
| 14 | var tbody = document.createElement("TBODY"); |
---|
| 15 | var tr; |
---|
| 16 | var td; |
---|
| 17 | |
---|
| 18 | /* cabeçalho */ |
---|
| 19 | tr = document.createElement("TR"); |
---|
| 20 | for (i in header) |
---|
| 21 | { |
---|
| 22 | if (typeof header[i] != "function") |
---|
| 23 | { |
---|
| 24 | td = document.createElement("TH"); |
---|
| 25 | td.innerHTML = header[i]; |
---|
| 26 | tr.appendChild(td); |
---|
| 27 | } |
---|
| 28 | } |
---|
| 29 | tbody.appendChild(tr); |
---|
| 30 | |
---|
| 31 | /* elementos da tabela */ |
---|
| 32 | for (var i = 0; i < content.length; i++) |
---|
| 33 | { |
---|
| 34 | /* atributos da linha (TR) */ |
---|
| 35 | tr = document.createElement("TR"); |
---|
| 36 | if (content[i]['tr_attributes']) |
---|
| 37 | for (j in content[i]['tr_attributes']) |
---|
| 38 | if (typeof content[i]['tr_attributes'][j] != "function") |
---|
| 39 | tr.setAttribute(j, content[i]['tr_attributes'][j]); |
---|
| 40 | |
---|
| 41 | /* dados da tabela */ |
---|
| 42 | for (j in header) |
---|
| 43 | { |
---|
| 44 | if (typeof header[j] != "function") |
---|
| 45 | { |
---|
| 46 | td = document.createElement("TD"); |
---|
| 47 | td.innerHTML = content[i][j]; |
---|
| 48 | tr.appendChild(td); |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | tbody.appendChild(tr); |
---|
| 52 | } |
---|
| 53 | table.appendChild(tbody); |
---|
| 54 | |
---|
| 55 | return table; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /* constrói select boxes */ |
---|
| 59 | function constructSelectBox(name, items, selected) |
---|
| 60 | { |
---|
| 61 | var output = ''; |
---|
| 62 | |
---|
| 63 | output = '<select name="' + name + '" id="' + name + '">'; |
---|
| 64 | for (i in items) |
---|
| 65 | if (typeof items[i] != "function") |
---|
| 66 | output += '<option value="' + i + '"' + ((i == selected) ? ' selected' : '') + '>' + items[i] + '</option>'; |
---|
| 67 | output += '</select>'; |
---|
| 68 | |
---|
| 69 | return output; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /* gerencia possíveis erros oriundos do método chamado via Ajax */ |
---|
| 73 | function handleError(data) |
---|
| 74 | { |
---|
| 75 | if (typeof(data) == "string") |
---|
| 76 | { |
---|
| 77 | write_errors(data); |
---|
| 78 | return false; |
---|
| 79 | } |
---|
| 80 | else |
---|
| 81 | return true; |
---|
| 82 | } |
---|