[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 | } |
---|
[285] | 47 | |
---|
[2] | 48 | el.innerHTML +='<div id="ccQAFuncitons" style="border: 0px solid black; width: 220px; height: 20px">' + |
---|
[285] | 49 | '<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" />' + |
---|
| 50 | '<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] | 51 | '</div>'; |
---|
| 52 | el.innerHTML += "<br>"; |
---|
[285] | 53 | |
---|
[2] | 54 | _this.showWindow(el); |
---|
| 55 | } |
---|
[285] | 56 | |
---|
[2] | 57 | div = document.getElementById(id+':cc_rectQuickAddContact'); |
---|
[285] | 58 | |
---|
[2] | 59 | if(div) |
---|
| 60 | this.showWindow(div); |
---|
| 61 | else { |
---|
| 62 | Connector.newRequest('get_catalog_add_contact', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_catalog_add_contact', 'POST', handler, 'id='+id); |
---|
| 63 | } |
---|
| 64 | } |
---|
[285] | 65 | |
---|
[2] | 66 | cQuickAddContact.prototype.showWindow = function (div) |
---|
[285] | 67 | { |
---|
[2] | 68 | if(! this.arrayWin[div.id]) { |
---|
| 69 | |
---|
[285] | 70 | win = new dJSWin({ |
---|
[2] | 71 | id: 'ccQuickAddContact_'+div.id, |
---|
| 72 | content_id: div.id, |
---|
| 73 | width: '255px', |
---|
| 74 | height: wHeight+'px', |
---|
| 75 | title_color: '#3978d6', |
---|
| 76 | bg_color: '#eee', |
---|
[285] | 77 | title: Element('ccQATitle').value, |
---|
[2] | 78 | title_text_color: 'white', |
---|
| 79 | button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif', |
---|
| 80 | border: true }); |
---|
[285] | 81 | |
---|
[2] | 82 | this.arrayWin[div.id] = win; |
---|
[285] | 83 | win.draw(); |
---|
[2] | 84 | } |
---|
| 85 | else { |
---|
| 86 | win = this.arrayWin[div.id]; |
---|
[285] | 87 | } |
---|
[2] | 88 | win.open(); |
---|
| 89 | } |
---|
[285] | 90 | |
---|
[2] | 91 | cQuickAddContact.prototype.send = function (id) |
---|
| 92 | { |
---|
| 93 | var _this = this; |
---|
| 94 | div = document.getElementById(id+':cc_rectQuickAddContact'); |
---|
| 95 | win = this.arrayWin[div.id]; |
---|
| 96 | |
---|
| 97 | var handler = function (responseText) |
---|
| 98 | { |
---|
| 99 | Element('cc_debug').innerHTML = responseText; |
---|
| 100 | |
---|
| 101 | var data = unserialize(responseText); |
---|
| 102 | |
---|
| 103 | if (!data || typeof(data) != 'object') |
---|
| 104 | { |
---|
| 105 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
| 106 | return; |
---|
| 107 | } |
---|
| 108 | else if (data['status'] == 'alreadyExists') |
---|
| 109 | { |
---|
| 110 | showMessage(data['msg']); |
---|
| 111 | return; |
---|
| 112 | } |
---|
| 113 | else if (data['status'] != 'ok') |
---|
| 114 | { |
---|
| 115 | return; |
---|
| 116 | } |
---|
[285] | 117 | |
---|
[2] | 118 | win.close(); |
---|
| 119 | |
---|
| 120 | if (_this.afterSave) |
---|
| 121 | { |
---|
| 122 | switch (typeof(_this.afterSave)) |
---|
| 123 | { |
---|
| 124 | case 'function': |
---|
| 125 | _this.afterSave(); |
---|
| 126 | break; |
---|
| 127 | |
---|
| 128 | case 'string': |
---|
| 129 | eval(_this.afterSave); |
---|
| 130 | break; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|
[285] | 134 | |
---|
[2] | 135 | var sdata = new Array(); |
---|
[285] | 136 | |
---|
[2] | 137 | for (var f = 0; f < 5; f++){ |
---|
| 138 | sdata[f] = document.getElementById('ccQuickAddCI' + f + id).value; |
---|
| 139 | } |
---|
[285] | 140 | |
---|
[2] | 141 | //Utiliza expressão regular para validar email |
---|
| 142 | var reEmail = /^[A-Za-z\d_-]+(\.[A-Za-z\d_-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/; |
---|
| 143 | |
---|
| 144 | if(!reEmail.test(sdata[4])){ |
---|
| 145 | alert("O endereço de email '" + sdata[4] + "' não é válido!\n" + |
---|
| 146 | "Por favor informe um endereço válido."); |
---|
| 147 | return false; |
---|
| 148 | } |
---|
[285] | 149 | |
---|
[2] | 150 | //Utiliza expressão regular para validar telefone |
---|
| 151 | var rePhone = /^[0-9|(-)| |-]{0,15}$/; |
---|
[285] | 152 | |
---|
[2] | 153 | if (!rePhone.test(sdata[3])){ |
---|
| 154 | alert("O número de telefone '" + sdata[3] + "' não é valido! Utilize apenas números.\n" + |
---|
| 155 | "Parenteses, traços ou espaços em branco podem ser usados como carácter separador."); |
---|
| 156 | return false; |
---|
[285] | 157 | } |
---|
| 158 | |
---|
[2] | 159 | var sdata = 'add='+escape(serialize(sdata)); |
---|
| 160 | |
---|
| 161 | Connector.newRequest('cQuickAdd.Send', CC_url+'quick_add', 'POST', handler, sdata); |
---|
| 162 | } |
---|
[285] | 163 | |
---|
[2] | 164 | cQuickAddContact.prototype.fechar = function(id) { |
---|
[285] | 165 | |
---|
[2] | 166 | div = document.getElementById(id+':cc_rectQuickAddContact'); |
---|
| 167 | win = this.arrayWin[div.id]; |
---|
| 168 | win.close(); |
---|
| 169 | } |
---|
[285] | 170 | |
---|
| 171 | |
---|
[2] | 172 | /* Build the Object */ |
---|
| 173 | var ccQuickAddContact ; |
---|
| 174 | var cQuickAddContact_pre_load = document.body.onload; |
---|
| 175 | |
---|
| 176 | if (is_ie) |
---|
[285] | 177 | { |
---|
| 178 | document.body.onload = function (e) |
---|
| 179 | { |
---|
[2] | 180 | cQuickAddContact_pre_load(); |
---|
| 181 | ccQuickAddContact = new cQuickAddContact(); |
---|
[285] | 182 | |
---|
[2] | 183 | }; |
---|
| 184 | } |
---|
| 185 | else |
---|
| 186 | { |
---|
| 187 | ccQuickAddContact = new cQuickAddContact(); |
---|
| 188 | } |
---|