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