1 | function cQuickAddContact () |
---|
2 | { |
---|
3 | this.arrayWin = new Array(); |
---|
4 | this.el; |
---|
5 | this._nFields = 5; |
---|
6 | } |
---|
7 | |
---|
8 | |
---|
9 | cQuickAddContact.prototype.showList = function(data){ |
---|
10 | _this = this; |
---|
11 | |
---|
12 | var cc_data = (typeof data) == 'object' ? data : data.split(','); |
---|
13 | |
---|
14 | if (document.getElementById('cc_rectQuickAddContact') == null){ |
---|
15 | el = document.createElement("DIV"); |
---|
16 | el.style.visibility = "hidden"; |
---|
17 | el.style.position = "absolute"; |
---|
18 | el.style.left = "0px"; |
---|
19 | el.style.top = "0px"; |
---|
20 | el.style.width = "0px"; |
---|
21 | wHeight = 165; |
---|
22 | el.style.height = wHeight + 'px'; |
---|
23 | el.className = "div_cc_rectQuickAddContact"; |
---|
24 | el.id = 'cc_rectQuickAddContact'; |
---|
25 | document.body.appendChild(el); |
---|
26 | } |
---|
27 | else { |
---|
28 | el = document.getElementById('cc_rectQuickAddContact'); |
---|
29 | } |
---|
30 | el.innerHTML = ""; |
---|
31 | var fieldsTop = 10; |
---|
32 | var fieldsSpace = 30; |
---|
33 | var lang_save = get_lang('Save'); |
---|
34 | var lang_cancel = get_lang('Cancel'); |
---|
35 | |
---|
36 | //função lang |
---|
37 | fields = new Array(get_lang('Nickname')+":", get_lang('First Name')+":", get_lang('Last Name')+":", 'E-mail:'); |
---|
38 | for (i=0; i<fields.length; i++) { |
---|
39 | el.innerHTML += '<span id="ccQuickAddCT' + i + '" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 5px; width: 100px; text-align: right; border: 0px solid #999;">' + fields[i] + '</span>'; |
---|
40 | el.innerHTML += '<input id="ccQuickAddCI' + i + '" type="text" value="' + cc_data[i] + '" maxlength="50" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 110px; width: 135px;">'; |
---|
41 | } |
---|
42 | el.innerHTML +='<div id="ccQAFunctions" style="border: 0px solid black; width: 220px; height: 20px">' + |
---|
43 | '<input title="'+lang_save+'" type="button" onclick="ccQuickAddOne.send(\''+data+'\');" value="'+lang_save+'" style="position: absolute; top: ' + (fieldsTop+(i*fieldsSpace)) + 'px; left: 75px; width: 60px" />' + |
---|
44 | '<input title="'+lang_cancel+'" type="button" onclick="ccQuickAddOne.fechar(\'' + id + '\');" value="'+lang_cancel+'" style="position: absolute; top: ' + (fieldsTop+(i*fieldsSpace)) + 'px; left: 140px; width: 60px" />' + |
---|
45 | '</div>'; |
---|
46 | el.innerHTML += "<br>"; |
---|
47 | _this.showWindow(el); |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | cQuickAddContact.prototype.showWindow = function (div) |
---|
52 | { |
---|
53 | if(! this.arrayWin[div.id]) { |
---|
54 | win = new dJSWin({ |
---|
55 | id: 'ccQuickAddOne_'+div.id, |
---|
56 | content_id: div.id, |
---|
57 | width: '255px', |
---|
58 | height: wHeight+'px', |
---|
59 | title_color: '#3978d6', |
---|
60 | bg_color: '#eee', |
---|
61 | title: get_lang("Quick Add"), |
---|
62 | title_text_color: 'white', |
---|
63 | button_x_img: '../phpgwapi/images/winclose.gif', |
---|
64 | border: true }); |
---|
65 | this.arrayWin[div.id] = win; |
---|
66 | win.draw(); |
---|
67 | } |
---|
68 | else { |
---|
69 | win = this.arrayWin[div.id]; |
---|
70 | } |
---|
71 | win.open(); |
---|
72 | } |
---|
73 | |
---|
74 | cQuickAddContact.prototype.send = function (data) |
---|
75 | { |
---|
76 | |
---|
77 | var handler = function (responseText) |
---|
78 | { |
---|
79 | var data = responseText; |
---|
80 | if (!data || typeof(data) != 'object') |
---|
81 | { |
---|
82 | write_msg("Problema ao contactar servidor"); |
---|
83 | return; |
---|
84 | } |
---|
85 | else if (data['status'] == 'alreadyExists') |
---|
86 | { |
---|
87 | alert(data['msg']); |
---|
88 | return; |
---|
89 | } |
---|
90 | else if (data['status'] != 'ok') |
---|
91 | { |
---|
92 | return; |
---|
93 | } |
---|
94 | contacts += ',' + full_name + ';' + email; |
---|
95 | write_msg("Contato adicionado com sucesso."); |
---|
96 | win.close(); |
---|
97 | |
---|
98 | if (_this.afterSave) |
---|
99 | { |
---|
100 | switch (typeof(_this.afterSave)) |
---|
101 | { |
---|
102 | case 'function': |
---|
103 | _this.afterSave(); |
---|
104 | break; |
---|
105 | |
---|
106 | case 'string': |
---|
107 | eval(_this.afterSave); |
---|
108 | break; |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | var _this = this; |
---|
114 | var sdata = data.split(","); |
---|
115 | var temp = sdata[3]; |
---|
116 | sdata[3]=''; |
---|
117 | sdata[4]=temp; |
---|
118 | sdata = new Array(); |
---|
119 | |
---|
120 | for (i=0; i< fields.length; i++) { |
---|
121 | if(i == 3){ |
---|
122 | sdata[i] = ''; |
---|
123 | sdata[i+1] = document.getElementById("ccQuickAddCI" + i).value; |
---|
124 | } |
---|
125 | else |
---|
126 | sdata[i] = document.getElementById("ccQuickAddCI" + i).value; |
---|
127 | } |
---|
128 | |
---|
129 | var full_name = trim(sdata[1]) + ' ' + trim(sdata[2]); |
---|
130 | var email = trim(sdata[4]); |
---|
131 | //Utiliza expressão regular para validar email |
---|
132 | 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}\])$/; |
---|
133 | |
---|
134 | if(!reEmail.test(email)){ |
---|
135 | alert("O endereco de email '" + email + "' nao e valido!\n" + |
---|
136 | "Por favor informe um endereco valido."); |
---|
137 | return false; |
---|
138 | } |
---|
139 | |
---|
140 | var sdata = 'add='+escape(connector.serialize(sdata)); |
---|
141 | var CC_url = '../index.php?menuaction=contactcenter.ui_data.data_manager&method='; |
---|
142 | connector.newRequest('cQuickAdd.Send', CC_url+'quick_add', 'POST', handler, sdata); |
---|
143 | } |
---|
144 | |
---|
145 | cQuickAddContact.prototype.fechar = function(id) { |
---|
146 | var div = document.getElementById('cc_rectQuickAddContact'); |
---|
147 | win = this.arrayWin[div.id]; |
---|
148 | win.close(); |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | /* Build the Object */ |
---|
153 | var ccQuickAddOne = new cQuickAddContact(); |
---|