[2] | 1 | function cQuickAddContact () |
---|
| 2 | { |
---|
| 3 | this.arrayWin = new Array(); |
---|
| 4 | this.el; |
---|
| 5 | this._nFields = Element('ccQAnFields').value; |
---|
| 6 | } |
---|
| 7 | |
---|
[285] | 8 | |
---|
[2] | 9 | cQuickAddContact.prototype.showList = function(id){ |
---|
| 10 | _this = this; |
---|
| 11 | var handler = function (responseText) { |
---|
| 12 | var contacts = unserialize(responseText); |
---|
[285] | 13 | var title = contacts['names_ordered']; |
---|
| 14 | el = document.createElement("DIV"); |
---|
| 15 | el.style.visibility = "hidden"; |
---|
[2] | 16 | el.style.position = "absolute"; |
---|
| 17 | el.style.left = "0px"; |
---|
| 18 | el.style.top = "0px"; |
---|
| 19 | el.style.width = "0px"; |
---|
| 20 | wHeight = Element('ccQAWinHeight').value; |
---|
| 21 | el.style.height = wHeight + 'px'; |
---|
| 22 | el.className = "div_cc_rectQuickAddContact"; |
---|
[285] | 23 | el.id = id+':cc_rectQuickAddContact'; |
---|
| 24 | document.body.appendChild(el); |
---|
| 25 | el.innerHTML = ""; |
---|
[2] | 26 | |
---|
| 27 | var fieldsTop = 10; |
---|
| 28 | var fieldsSpace = 30; |
---|
| 29 | fields = new Array(Element('cc_qa_alias').value, Element('cc_qa_given_names').value, Element('cc_qa_family_names').value, Element('cc_qa_phone').value, Element('cc_qa_email').value); |
---|
[285] | 30 | |
---|
[2] | 31 | for (i=0; i<fields.length; i++) { |
---|
| 32 | var contact = contacts[i] != null ? contacts[i] : ''; |
---|
| 33 | el.innerHTML += '<span id="ccQuickAddCT' + i + id + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 5px; width: 100px; text-align: right; border: 0px solid #999;">' + fields[i] + '</span>'; |
---|
[284] | 34 | if (i == 0) |
---|
| 35 | { |
---|
| 36 | el.innerHTML += '<input id="ccQuickAddCI' + i + id + '" type="text" value="' + contact + '" maxlength="30" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 110px; width: 135px;">'; |
---|
| 37 | } |
---|
| 38 | else if (i == 4) |
---|
| 39 | { |
---|
| 40 | el.innerHTML += '<input id="ccQuickAddCI' + i + id + '" type="text" value="' + contact + '" maxlength="100" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 110px; width: 135px;">'; |
---|
| 41 | } |
---|
| 42 | else |
---|
| 43 | { |
---|
| 44 | el.innerHTML += '<input id="ccQuickAddCI' + i + id + '" type="text" value="' + contact + '" maxlength="50" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 110px; width: 135px;">'; |
---|
[285] | 45 | } |
---|
[2] | 46 | } |
---|
[1496] | 47 | |
---|
| 48 | |
---|
[2] | 49 | el.innerHTML +='<div id="ccQAFuncitons" style="border: 0px solid black; width: 220px; height: 20px">' + |
---|
[285] | 50 | '<input title="' + Element('cc_qa_save').value + '" type="button" onclick="ccQuickAddContact.send(\'' + id + '\');" value="' + Element('cc_qa_save').value + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 75px; width: 60px" />' + |
---|
| 51 | '<input title="' + Element('cc_qa_close').value + '" type="button" onclick="ccQuickAddContact.fechar(\'' + id + '\');" value="' + Element('cc_qa_close').value + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 140px; width: 60px" />' + |
---|
[2] | 52 | '</div>'; |
---|
| 53 | el.innerHTML += "<br>"; |
---|
[285] | 54 | |
---|
[2] | 55 | _this.showWindow(el); |
---|
| 56 | } |
---|
[285] | 57 | |
---|
[2] | 58 | div = document.getElementById(id+':cc_rectQuickAddContact'); |
---|
[285] | 59 | |
---|
[2] | 60 | if(div) |
---|
| 61 | this.showWindow(div); |
---|
| 62 | else { |
---|
| 63 | Connector.newRequest('get_catalog_add_contact', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_catalog_add_contact', 'POST', handler, 'id='+id); |
---|
| 64 | } |
---|
| 65 | } |
---|
[285] | 66 | |
---|
[2] | 67 | cQuickAddContact.prototype.showWindow = function (div) |
---|
[285] | 68 | { |
---|
[2] | 69 | if(! this.arrayWin[div.id]) { |
---|
| 70 | |
---|
[285] | 71 | win = new dJSWin({ |
---|
[2] | 72 | id: 'ccQuickAddContact_'+div.id, |
---|
| 73 | content_id: div.id, |
---|
| 74 | width: '255px', |
---|
| 75 | height: wHeight+'px', |
---|
| 76 | title_color: '#3978d6', |
---|
| 77 | bg_color: '#eee', |
---|
[285] | 78 | title: Element('ccQATitle').value, |
---|
[2] | 79 | title_text_color: 'white', |
---|
| 80 | button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif', |
---|
| 81 | border: true }); |
---|
[285] | 82 | |
---|
[2] | 83 | this.arrayWin[div.id] = win; |
---|
[285] | 84 | win.draw(); |
---|
[2] | 85 | } |
---|
| 86 | else { |
---|
| 87 | win = this.arrayWin[div.id]; |
---|
[285] | 88 | } |
---|
[2] | 89 | win.open(); |
---|
| 90 | } |
---|
[285] | 91 | |
---|
[2] | 92 | cQuickAddContact.prototype.send = function (id) |
---|
| 93 | { |
---|
| 94 | var _this = this; |
---|
| 95 | div = document.getElementById(id+':cc_rectQuickAddContact'); |
---|
| 96 | win = this.arrayWin[div.id]; |
---|
| 97 | |
---|
| 98 | var handler = function (responseText) |
---|
| 99 | { |
---|
| 100 | Element('cc_debug').innerHTML = responseText; |
---|
| 101 | |
---|
| 102 | var data = unserialize(responseText); |
---|
| 103 | |
---|
| 104 | if (!data || typeof(data) != 'object') |
---|
| 105 | { |
---|
| 106 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
| 107 | return; |
---|
| 108 | } |
---|
| 109 | else if (data['status'] == 'alreadyExists') |
---|
| 110 | { |
---|
| 111 | showMessage(data['msg']); |
---|
| 112 | return; |
---|
| 113 | } |
---|
| 114 | else if (data['status'] != 'ok') |
---|
| 115 | { |
---|
| 116 | return; |
---|
| 117 | } |
---|
[285] | 118 | |
---|
[2] | 119 | win.close(); |
---|
| 120 | |
---|
| 121 | if (_this.afterSave) |
---|
| 122 | { |
---|
| 123 | switch (typeof(_this.afterSave)) |
---|
| 124 | { |
---|
| 125 | case 'function': |
---|
| 126 | _this.afterSave(); |
---|
| 127 | break; |
---|
| 128 | |
---|
| 129 | case 'string': |
---|
| 130 | eval(_this.afterSave); |
---|
| 131 | break; |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | } |
---|
[285] | 135 | |
---|
[2] | 136 | var sdata = new Array(); |
---|
[285] | 137 | |
---|
[2] | 138 | for (var f = 0; f < 5; f++){ |
---|
| 139 | sdata[f] = document.getElementById('ccQuickAddCI' + f + id).value; |
---|
| 140 | } |
---|
[285] | 141 | |
---|
[4721] | 142 | if(!sdata[1]){ |
---|
| 143 | alert("O campo nome é obrigatório(a)!"); |
---|
| 144 | return false; |
---|
| 145 | } |
---|
| 146 | |
---|
[2] | 147 | //Utiliza expressão regular para validar email |
---|
[4720] | 148 | /* |
---|
| 149 | Expressão regular modificada para aceitar emails de email fora do padrão nome@provedor.com.br. |
---|
| 150 | Aceita casos de domínios internos como c0000@mail.empresa |
---|
| 151 | */ |
---|
| 152 | var reEmail = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[_a-z0-9-]+(\.[_a-z0-9-]+)+$/; |
---|
[2] | 153 | |
---|
[4721] | 154 | if(sdata[4] !== "" && !reEmail.test(sdata[4])){ |
---|
[2] | 155 | alert("O endereço de email '" + sdata[4] + "' não é válido!\n" + |
---|
| 156 | "Por favor informe um endereço válido."); |
---|
| 157 | return false; |
---|
| 158 | } |
---|
[1612] | 159 | |
---|
[2] | 160 | var sdata = 'add='+escape(serialize(sdata)); |
---|
| 161 | |
---|
| 162 | Connector.newRequest('cQuickAdd.Send', CC_url+'quick_add', 'POST', handler, sdata); |
---|
| 163 | } |
---|
[285] | 164 | |
---|
[2] | 165 | cQuickAddContact.prototype.fechar = function(id) { |
---|
[285] | 166 | |
---|
[2] | 167 | div = document.getElementById(id+':cc_rectQuickAddContact'); |
---|
| 168 | win = this.arrayWin[div.id]; |
---|
| 169 | win.close(); |
---|
| 170 | } |
---|
[285] | 171 | |
---|
| 172 | |
---|
[2] | 173 | /* Build the Object */ |
---|
| 174 | var ccQuickAddContact ; |
---|
| 175 | var cQuickAddContact_pre_load = document.body.onload; |
---|
| 176 | |
---|
| 177 | if (is_ie) |
---|
[285] | 178 | { |
---|
| 179 | document.body.onload = function (e) |
---|
| 180 | { |
---|
[2] | 181 | cQuickAddContact_pre_load(); |
---|
| 182 | ccQuickAddContact = new cQuickAddContact(); |
---|
[285] | 183 | |
---|
[2] | 184 | }; |
---|
| 185 | } |
---|
| 186 | else |
---|
| 187 | { |
---|
| 188 | ccQuickAddContact = new cQuickAddContact(); |
---|
| 189 | } |
---|