source: trunk/expressoMail1_2/js/ccQuickAdd.js @ 2

Revision 2, 4.4 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • 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 = 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               
34                //função lang
35                fields = new Array('Apelido:', 'Nome:', 'Sobrenome:', 'E-mail:');
36                for (i=0; i<fields.length; i++) {
37                        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>';
38                        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;">';
39                }
40                el.innerHTML +='<div id="ccQAFunctions" style="border: 0px solid black; width: 220px; height: 20px">' +
41                        '<input title="Salvar" type="button" onclick="ccQuickAddOne.send(\''+data+'\');" value="Salvar" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 75px; width: 60px" />' +
42                        '<input title="Cancelar" type="button" onclick="ccQuickAddOne.fechar(\'' + id + '\');" value="Cancelar" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 140px; width: 60px" />' +
43                        '</div>';
44                el.innerHTML += "<br>";
45                _this.showWindow(el);
46
47        }
48               
49        cQuickAddContact.prototype.showWindow = function (div)
50        {                                               
51                if(! this.arrayWin[div.id]) {
52                        win = new dJSWin({                     
53                                id: 'ccQuickAddOne_'+div.id,
54                                content_id: div.id,
55                                width: '255px',
56                                height: wHeight+'px',
57                                title_color: '#3978d6',
58                                bg_color: '#eee',
59                                title: "Adi&ccedil;&atilde;o R&aacute;pida",                                           
60                                title_text_color: 'white',
61                                button_x_img: '../phpgwapi/images/winclose.gif',
62                                border: true });
63                        this.arrayWin[div.id] = win;
64                        win.draw();                     
65                }
66                else {
67                        win = this.arrayWin[div.id];
68                }                       
69                win.open();
70        }
71       
72        cQuickAddContact.prototype.send = function (data)
73        {
74               
75                var handler = function (responseText)
76                {
77                        var data = responseText;
78                        if (!data || typeof(data) != 'object')
79                        {
80                                write_msg("Problema ao contactar servidor");
81                                return;
82                        }
83                        else if (data['status'] == 'alreadyExists')
84                        {
85                                alert(data['msg']);
86                                return;
87                        }
88                        else if (data['status'] != 'ok')
89                        {
90                                return;
91                        }
92                        contacts += ',' + full_name + ';' + email;
93                        write_msg("Contato adicionado com sucesso.");
94                        win.close();
95
96                        if (_this.afterSave)
97                        {
98                                switch (typeof(_this.afterSave))
99                                {
100                                        case 'function':
101                                                _this.afterSave();
102                                                break;
103
104                                        case 'string':
105                                                eval(_this.afterSave);
106                                                break;
107                                }
108                        }
109                }
110                               
111                var _this = this;
112                var sdata = data.split(",");
113                var temp = sdata[3];
114                sdata[3]='';
115                sdata[4]=temp;
116                sdata = new Array();
117
118                for (i=0; i< fields.length; i++) {                     
119                        if(i == 3){
120                                sdata[i] = '';
121                                sdata[i+1] = document.getElementById("ccQuickAddCI" + i).value;
122                        }
123                        else
124                                sdata[i] = document.getElementById("ccQuickAddCI" + i).value;
125                }
126
127                var full_name = trim(sdata[1]) + ' ' + trim(sdata[2]);
128                var email = trim(sdata[4]);                             
129                //Utiliza expressão regular para validar email
130                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}\])$/;
131
132                if(!reEmail.test(email)){
133                        alert("O endereco de email '" + email + "' nao e valido!\n" +
134                        "Por favor informe um endereco valido.");
135                        return false;
136                }
137               
138                var sdata = 'add='+escape(connector.serialize(sdata));
139                var CC_url = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=';
140                connector.newRequest('cQuickAdd.Send', CC_url+'quick_add', 'POST', handler, sdata);
141        }
142       
143        cQuickAddContact.prototype.fechar = function(id) {
144                var div = document.getElementById('cc_rectQuickAddContact');
145                win = this.arrayWin[div.id];
146                win.close();
147        }
148       
149       
150/* Build the Object */
151        var     ccQuickAddOne = new cQuickAddContact();
Note: See TracBrowser for help on using the repository browser.