[795] | 1 | var vazio = " "; |
---|
| 2 | |
---|
| 3 | function expandInput(name, iid, pid) |
---|
| 4 | { |
---|
| 5 | var input = document.getElementById(name); |
---|
| 6 | var td = input.parentNode; |
---|
| 7 | var value = input.value; |
---|
| 8 | |
---|
| 9 | td.innerHTML = '<textarea id="' + name + '" cols="80" rows="10"/>' + value + '</textarea><button onclick="updateProperty(\'' + name + '\', ' + iid + ', ' + pid + '); return false;">OK</button>'; |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | function loadProperties(iid, pid, div) |
---|
| 13 | { |
---|
| 14 | function loadPropertiesResult(data) |
---|
| 15 | { |
---|
| 16 | if (handleError(data)) |
---|
| 17 | { |
---|
| 18 | var canChangeProperties = permissions[pid]['bits'][IP_CHANGE_PROPERTIES]; |
---|
| 19 | var content = '<table width="100%" align="center" border="1" class="content_table" id="tabela_propriedades">'; |
---|
| 20 | content += '<tr><th>Nome</th><th>Valor</th><th>Ações</th></tr>'; |
---|
| 21 | |
---|
| 22 | var row; |
---|
| 23 | var propertiesCount = data.length; |
---|
| 24 | for (var i = 0; i < propertiesCount; i++) |
---|
| 25 | { |
---|
| 26 | row = data[i]; |
---|
| 27 | content += '<tr>'; |
---|
| 28 | |
---|
| 29 | /* nome */ |
---|
| 30 | content += '<td>' + row['name'] + '</td>'; |
---|
| 31 | |
---|
| 32 | /* valor */ |
---|
| 33 | if (row['value'] == '') |
---|
| 34 | row['value'] = vazio; |
---|
| 35 | content += '<td>'; |
---|
| 36 | |
---|
| 37 | if (canChangeProperties) |
---|
| 38 | { |
---|
| 39 | if (row['complete'] == 1) |
---|
| 40 | content += '<a href="#" onclick="clickProperty(this, ' + data['params']['iid'] + ', ' + data['params']['pid'] + '); return false;">' + row['value'] + '</a>'; |
---|
| 41 | else |
---|
| 42 | content += '<a href="#" onclick="clickLargeProperty(this, ' + data['params']['iid'] + ', ' + data['params']['pid'] + ', \'' + row['name'] + '\'); return false;">' + row['value'] + '</a>'; |
---|
| 43 | } |
---|
| 44 | else |
---|
| 45 | content += row['value']; |
---|
| 46 | |
---|
| 47 | content += '</td>'; |
---|
| 48 | |
---|
| 49 | /* ações */ |
---|
| 50 | content += '<td>'; |
---|
| 51 | if (canChangeProperties) |
---|
| 52 | content += '<a href="#" onclick="removeProperty(this, ' + data['params']['iid'] + ', ' + data['params']['pid'] + '); return false;">remover</a>'; |
---|
| 53 | else |
---|
| 54 | content += '<i>nenhuma</i>'; |
---|
| 55 | content += '</td>'; |
---|
| 56 | |
---|
| 57 | content += '</tr>'; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | content += '</table>'; |
---|
| 61 | |
---|
| 62 | /* adiciona o botão para a criação de novas propriedades */ |
---|
| 63 | if (canChangeProperties) |
---|
| 64 | content = '<table width="75%" align="center"><tr><td><a href="#" onclick="addProperty(' + data['params']['iid'] + ', ' + data['params']['pid'] + '); return false;">Adicionar Propriedade</a></td></tr><tr><td>' + content + '</td></tr></table>'; |
---|
| 65 | div.innerHTML = content; |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | cExecute("$this.bo_monitors.listInstanceProperties", loadPropertiesResult, 'iid=' + iid + '&pid=' + pid); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | function clickProperty(link, iid, pid) |
---|
| 72 | { |
---|
| 73 | var value = link.innerHTML; |
---|
| 74 | var td = link.parentNode; |
---|
| 75 | var name = td.parentNode.childNodes[0].innerHTML; |
---|
| 76 | var minimumSize = 7; |
---|
| 77 | value = value.replace(/"/g, """); |
---|
| 78 | if (value == vazio) |
---|
| 79 | value = ""; |
---|
| 80 | |
---|
| 81 | td.innerHTML = '<input type="text" id="' + name + '" value="' + value + '" size="' + ((value.length > minimumSize) ? value.length : minimumSize) + '" /><button onclick="updateProperty(\'' + name + '\', ' + iid + ', ' + pid + '); return false;">OK</button><button onclick="expandInput(\'' + name + '\', ' + iid + ', ' + pid + '); return false;">+</button>'; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | function clickLargeProperty(link, iid, pid, name) |
---|
| 85 | { |
---|
| 86 | var td = link.parentNode; |
---|
| 87 | var name = td.parentNode.childNodes[0].innerHTML; |
---|
| 88 | |
---|
| 89 | function largePropertyResult(data) |
---|
| 90 | { |
---|
| 91 | if (handleError(data)) |
---|
| 92 | { |
---|
| 93 | data['value'] = data['value'].replace(/"/g, """); |
---|
| 94 | td.innerHTML = '<textarea id="' + name + '" cols="80" rows="10"/>' + data['value'] + '</textarea><button onclick="updateProperty(\'' + name + '\', ' + iid + ', ' + pid + '); return false;">OK</button>'; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | cExecute ("$this.bo_monitors.getCompletePropertyValue", largePropertyResult, 'iid=' + iid + '&pid=' + pid + '&name=' + name); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | function updateProperty(name, iid, pid) |
---|
| 102 | { |
---|
| 103 | function updatePropertyResult(data) |
---|
| 104 | { |
---|
| 105 | if (handleError(data)) |
---|
| 106 | { |
---|
| 107 | data['value'] = data['value'].replace(/"/g, """); |
---|
| 108 | if (data['value'] == "") |
---|
| 109 | data['value'] = vazio; |
---|
| 110 | if (data['complete'] == 1) |
---|
| 111 | document.getElementById(name).parentNode.innerHTML = '<a href="javacript:void(0)" onclick="clickProperty(this, ' + iid + ', ' + pid + '); return false;">' + data['value'] + '</a>'; |
---|
| 112 | else |
---|
| 113 | document.getElementById(name).parentNode.innerHTML = '<a href="javacript:void(0)" onclick="clickLargeProperty(this, ' + iid + ', ' + pid + '); return false;">' + data['value'] + '</a>'; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | var value = document.getElementById(name).value; |
---|
| 118 | if (value == vazio) |
---|
| 119 | value = ""; |
---|
| 120 | cExecute ("$this.bo_monitors.updateProperty", updatePropertyResult, 'iid=' + iid + '&pid=' + pid + '&name=' + name + '&value=' + escape(value)); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | function addProperty(iid, pid) |
---|
| 124 | { |
---|
| 125 | var novaPropriedade = prompt("Qual o nome da nova propriedade?"); |
---|
| 126 | if (novaPropriedade) |
---|
| 127 | { |
---|
| 128 | novaPropriedade = novaPropriedade.replace(/^[ ]+/g, ""); |
---|
| 129 | novaPropriedade = novaPropriedade.replace(/[ ]+$/g, ""); |
---|
| 130 | novaPropriedade = novaPropriedade.replace(/ /g, "_"); |
---|
| 131 | novaPropriedade = novaPropriedade.replace(/[^0-9A-Za-z\_]/g, ""); |
---|
| 132 | if (novaPropriedade.length < 1) |
---|
| 133 | { |
---|
| 134 | alert("Nome inválido, tente outro."); |
---|
| 135 | return; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | var tabela = $("tabela_propriedades"); |
---|
| 139 | for (var i = 1; i < tabela.childNodes[0].childNodes.length; i++) |
---|
| 140 | { |
---|
| 141 | if (tabela.childNodes[0].childNodes[i].childNodes[0].innerHTML == novaPropriedade) |
---|
| 142 | { |
---|
| 143 | alert("Já existe uma propriedade com este nome.\nModifique a existente ou escolha outro nome."); |
---|
| 144 | return; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | var tr = document.createElement("TR"); |
---|
| 148 | var td01 = document.createElement("TD"); |
---|
| 149 | var td02 = document.createElement("TD"); |
---|
| 150 | var td03 = document.createElement("TD"); |
---|
| 151 | td01.innerHTML = novaPropriedade; |
---|
| 152 | td02.innerHTML = '<input type="text" id="' + novaPropriedade + '" value="" size="27" /><button onclick="updateProperty(\'' + novaPropriedade + '\', ' + iid + ', ' + pid + '); return false;">OK</button><button onclick="expandInput(\'' + novaPropriedade + '\', ' + iid + ', ' + pid + '); return false;">+</button>'; |
---|
| 153 | td03.innerHTML = '<a href="#" onclick="removeProperty(this, ' + iid + ', ' + pid + '); return false;">remover</a>'; |
---|
| 154 | tr.appendChild(td01); |
---|
| 155 | tr.appendChild(td02); |
---|
| 156 | tr.appendChild(td03); |
---|
| 157 | tabela.childNodes[0].appendChild(tr); |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | function removeProperty(link, iid, pid) |
---|
| 162 | { |
---|
| 163 | function removePropertyResult(data) |
---|
| 164 | { |
---|
| 165 | if (handleError(data)) |
---|
| 166 | { |
---|
| 167 | var tr = link.parentNode.parentNode; |
---|
| 168 | tr.parentNode.removeChild(tr); |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | var name = link.parentNode.parentNode.childNodes[0].innerHTML; |
---|
| 173 | if (confirm("Tem certeza que deseja remover a propriedade \"" + name + "\"?")) |
---|
| 174 | cExecute ("$this.bo_monitors.removeProperty", removePropertyResult, 'iid=' + iid + '&pid=' + pid + '&name=' + name); |
---|
| 175 | } |
---|