source: companies/serpro/contactcenter/js/ccQuickAddContact.js @ 903

Revision 903, 5.8 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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                        el.innerHTML +='<div id="ccQAFuncitons" style="border: 0px solid black; width: 220px; height: 20px">' +
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" />' +
51                                '</div>';
52                        el.innerHTML += "<br>";
53                                                               
54                        _this.showWindow(el);
55                }
56               
57                div = document.getElementById(id+':cc_rectQuickAddContact');
58                               
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        }
65       
66        cQuickAddContact.prototype.showWindow = function (div)
67        {                                               
68                if(! this.arrayWin[div.id]) {
69
70                        win = new dJSWin({                     
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',
77                                title: Element('ccQATitle').value,                                             
78                                title_text_color: 'white',
79                                button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif',
80                                border: true });
81                       
82                        this.arrayWin[div.id] = win;
83                        win.draw();                     
84                }
85                else {
86                        win = this.arrayWin[div.id];
87                }                       
88                win.open();
89        }
90       
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                        }
117                       
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                }
134       
135                var sdata = new Array();
136               
137                for (var f = 0; f < 5; f++){
138                        sdata[f] = document.getElementById('ccQuickAddCI' + f + id).value;
139                }
140               
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                }
149               
150                //Utiliza expressão regular para validar telefone
151                var rePhone = /^[0-9|(-)| |-]{0,15}$/;
152               
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;
157                }
158               
159                var sdata = 'add='+escape(serialize(sdata));
160
161                Connector.newRequest('cQuickAdd.Send', CC_url+'quick_add', 'POST', handler, sdata);
162        }
163       
164        cQuickAddContact.prototype.fechar = function(id) {
165       
166                div = document.getElementById(id+':cc_rectQuickAddContact');
167                win = this.arrayWin[div.id];
168                win.close();
169        }
170       
171       
172/* Build the Object */
173        var ccQuickAddContact ;
174        var cQuickAddContact_pre_load = document.body.onload;
175
176        if (is_ie)
177        {
178                document.body.onload = function (e)
179                {
180                        cQuickAddContact_pre_load();
181                        ccQuickAddContact = new cQuickAddContact();
182                       
183                };
184        }
185        else
186        {
187                ccQuickAddContact = new cQuickAddContact();
188        }
Note: See TracBrowser for help on using the repository browser.