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