source: branches/2.4/contactcenter/js/ccQuickAddContact.js @ 6929

Revision 6929, 5.8 KB checked in by eduardow, 12 years ago (diff)

Ticket #2986 - Inconsistencia no container de destinatarios.

  • 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                if(!$.trim(sdata[1])){
143                alert("O campo nome é obrigatório(a)!");
144                return false;
145            }
146               
147                //Utiliza expressão regular para validar email
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-]+)+$/;
153
154                if(sdata[4] !== "" && !reEmail.test(sdata[4])){
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                }
159                               
160                var sdata = 'add='+escape(serialize(sdata));
161
162                Connector.newRequest('cQuickAdd.Send', CC_url+'quick_add', 'POST', handler, sdata);
163        }
164       
165        cQuickAddContact.prototype.fechar = function(id) {
166       
167                div = document.getElementById(id+':cc_rectQuickAddContact');
168                win = this.arrayWin[div.id];
169                win.close();
170        }
171       
172       
173/* Build the Object */
174        var ccQuickAddContact ;
175        var cQuickAddContact_pre_load = document.body.onload;
176
177        if (is_ie)
178        {
179                document.body.onload = function (e)
180                {
181                        cQuickAddContact_pre_load();
182                        ccQuickAddContact = new cQuickAddContact();
183                       
184                };
185        }
186        else
187        {
188                ccQuickAddContact = new cQuickAddContact();
189        }
Note: See TracBrowser for help on using the repository browser.