source: branches/2.3/contactcenter/js/ccQuickAddContact.js @ 1612

Revision 1612, 5.5 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #723 - Ajustado o tamanho maximo do telefone para 30 e adicionado regex para formatar o telefone

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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                                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;">';
45                                }                               
46                        }
47
48
49                        el.innerHTML +='<div id="ccQAFuncitons" style="border: 0px solid black; width: 220px; height: 20px">' +
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" />' +
52                                '</div>';
53                        el.innerHTML += "<br>";
54                                                               
55                        _this.showWindow(el);
56                }
57               
58                div = document.getElementById(id+':cc_rectQuickAddContact');
59                               
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        }
66       
67        cQuickAddContact.prototype.showWindow = function (div)
68        {                                               
69                if(! this.arrayWin[div.id]) {
70
71                        win = new dJSWin({                     
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',
78                                title: Element('ccQATitle').value,                                             
79                                title_text_color: 'white',
80                                button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif',
81                                border: true });
82                       
83                        this.arrayWin[div.id] = win;
84                        win.draw();                     
85                }
86                else {
87                        win = this.arrayWin[div.id];
88                }                       
89                win.open();
90        }
91       
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                        }
118                       
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                }
135       
136                var sdata = new Array();
137               
138                for (var f = 0; f < 5; f++){
139                        sdata[f] = document.getElementById('ccQuickAddCI' + f + id).value;
140                }
141               
142                //Utiliza expressão regular para validar email
143                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}\])$/;
144
145                if(!reEmail.test(sdata[4])){
146                        alert("O endereço de email '" + sdata[4] + "' não é válido!\n" +
147                        "Por favor informe um endereço válido.");
148                        return false;
149                }
150                               
151                var sdata = 'add='+escape(serialize(sdata));
152
153                Connector.newRequest('cQuickAdd.Send', CC_url+'quick_add', 'POST', handler, sdata);
154        }
155       
156        cQuickAddContact.prototype.fechar = function(id) {
157       
158                div = document.getElementById(id+':cc_rectQuickAddContact');
159                win = this.arrayWin[div.id];
160                win.close();
161        }
162       
163       
164/* Build the Object */
165        var ccQuickAddContact ;
166        var cQuickAddContact_pre_load = document.body.onload;
167
168        if (is_ie)
169        {
170                document.body.onload = function (e)
171                {
172                        cQuickAddContact_pre_load();
173                        ccQuickAddContact = new cQuickAddContact();
174                       
175                };
176        }
177        else
178        {
179                ccQuickAddContact = new cQuickAddContact();
180        }
Note: See TracBrowser for help on using the repository browser.