source: branches/1.2/contactcenter/js/cc_email_win-0.2.0.js @ 2

Revision 2, 8.8 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  /***************************************************************************\
2  * eGroupWare - Contacts Center                                              *
3  * http://www.egroupware.org                                                 *
4  * Written by:                                                               *
5  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
6  *  - Jonas Goes <jqhcb@users.sourceforge.net>                               *
7  *  sponsored by Thyamad - http://www.thyamad.com                            *
8  * ------------------------------------------------------------------------- *
9  *  This program is free software; you can redistribute it and/or modify it  *
10  *  under the terms of the GNU General Public License as published by the    *
11  *  Free Software Foundation; either version 2 of the License, or (at your   *
12  *  option) any later version.                                               *
13  \***************************************************************************/
14
15        /*
16         * ContactCenter API - Email Gathering Window
17         */
18
19        function ccEmailWinClass(params)
20        {
21                if (typeof(params) != 'object')
22                {
23                        return false;
24                }
25
26                this.window = params['window'];
27                this.search_win = params['search'];
28               
29                this.entries = Element('cc_email_win_entries');
30                this.to  = Element('cc_email_win_to');
31                this.cc  = Element('cc_email_win_cc');
32                this.cco = Element('cc_email_win_cco');
33
34                this.to_count  = 0;
35                this.cc_count  = 0;
36                this.cco_count = 0;
37
38                this.contents = new Array();
39
40                this.onOk = null;
41
42                this.entries.style.overflow = 'auto';
43        }
44
45        ccEmailWinClass.prototype.setContents = function(data)
46        {
47                if (typeof(data) != 'object')
48                {
49                        return false;
50                }
51
52                this.clearAll();
53               
54                if (data['entries'])
55                {
56                        for (var i in data['entries'])
57                        {
58                                this.entries = new Option(data['entries'][i], i);
59                        }
60                }
61               
62                if (data['to'])
63                {
64                        for (var i in data['to'])
65                        {
66                                this.to = new Option(data['to'][i], i);
67                        }
68                }
69
70                if (data['cc'])
71                {
72                        for (var i in data['cc'])
73                        {
74                                this.cc = new Option(data['cc'][i], i);
75                        }
76                }
77
78                if (data['cco'])
79                {
80                        for (var i in data['cco'])
81                        {
82                                this.cco = new Option(data['cco'][i], i);
83                        }
84                }
85        }
86
87        ccEmailWinClass.prototype.getContents = function()
88        {
89                var i;
90               
91                this.contents = new Array();
92                this.contents['entries'] = new Array();
93                this.contents['to'] = new Array();
94                this.contents['cc'] = new Array();
95                this.contents['cco'] = new Array();
96               
97                for (i = 0; i < this.entries.options.length; i++)
98                {
99                        this.contents['entries'][this.contents['entries'].length] = this.entries.options[i].text;
100                }
101
102                for (i = 0; i < this.to.options.length; i++)
103                {
104                        this.contents['to'][this.contents['to'].length] = this.to.options[i].text;
105                }
106
107                for (i = 0; i < this.cc.options.length; i++)
108                {
109                        this.contents['cc'][this.contents['cc'].length] = this.cc.options[i].text;
110                }
111               
112                for (i = 0; i < this.cco.options.length; i++)
113                {
114                        this.contents['cco'][this.contents['cco'].length] = this.cco.options[i].text;
115                }
116               
117                return this.contents;
118        }
119
120        ccEmailWinClass.prototype.open = function()
121        {
122                this.window.open()
123        }
124       
125        ccEmailWinClass.prototype.ok = function()
126        {
127                if (this.onOk)
128                {
129                        this.onOk(this.getContents());
130                }
131
132                this.clearAll();
133                this.window.close();
134        }
135       
136        ccEmailWinClass.prototype.clearAll = function()
137        {
138                this.clearEntries();
139                this.clearTo();
140                this.clearCC();
141                this.clearCCO();
142        }
143
144        ccEmailWinClass.prototype.clearEntries = function()
145        {
146                var length;
147
148                if (this.entries.options.length)
149                {
150                        length = this.entries.options.length-1;
151                        for (var i = length; i >= 0; i--)
152                        {
153                                this.entries.removeChild(this.entries.options[i]);
154                        }
155                }
156        }
157
158        ccEmailWinClass.prototype.clearTo = function()
159        {
160                var length;
161               
162                if (this.to.options.length)
163                {
164                        length = this.to.options.length-1;
165                        for (var i = length; i >= 0; i--)
166                        {
167                                this.to.removeChild(this.to.options[i]);
168                        }
169                }
170        }
171       
172        ccEmailWinClass.prototype.clearCC = function()
173        {
174                var length;
175               
176                if (this.cc.options.length)
177                {
178                        length = this.cc.options.length-1;
179                        for (var i = length; i >= 0; i--)
180                        {
181                                this.cc.removeChild(this.cc.options[i]);
182                        }
183                }
184        }
185
186        ccEmailWinClass.prototype.clearCCO = function()
187        {
188                var length;
189               
190                if (this.cco.options.length)
191                {
192                        length = this.cco.options.length-1;
193                        for (var i = length; i >= 0; i--)
194                        {
195                                this.cco.removeChild(this.cco.options[i]);
196                        }
197                }
198        }
199       
200        ccEmailWinClass.prototype.close = function()
201        {
202                this.clearAll();
203                this.search_win.close();
204                this.window.close();
205        }
206
207        ccEmailWinClass.prototype.search = function()
208        {
209/*              if (document.all)
210                {
211                        this.search_win.onOpen  = this.window.close;
212                        this.search_win.onClose = this.window.open;
213                }
214*/             
215                this.search_win.open();
216                this.search_win.window.moveTo(this.window.x()+20, this.window.y()+20);
217
218                var window = this.window;
219                var entries = this.entries;
220                var _this = this;
221               
222                this.search_win.onSearchFinish = function (result)
223                {
224                        if (!result || typeof(result) != 'object')
225                        {
226                                showMessage('Error getting result from search');
227                                return false;
228                        }
229
230                        var sdata = new Array();
231                       
232                        sdata['ids'] = result;
233                        sdata['fields'] = new Array()
234                        sdata['fields']['names_ordered'] = true;
235                        sdata['fields']['connections'] = true;
236                       
237                        var str_data = 'data='+serialize(sdata);
238
239                        var obj = httpRequestObj();
240
241                        var handler = function ()
242                        {
243                                try
244                                {
245                                        setLoadingState(obj.readyState);
246                                        if (obj.readyState == 4 && obj.status == 200)
247                                        {
248                                                //document.all ? _this.window.open() : false;
249                                                //Element('cc_email_win_debug').innerHTML = obj.responseText;
250                                                var data = unserialize(obj.responseText);
251                                               
252                                                if (!data)
253                                                {
254                                                        //showMessage(Element('cc_msg_err_invalid_catalog').value);
255                                                        showMessage('Error getting user Info');
256                                                        return false;
257                                                }
258
259                                                _this.clearEntries();
260
261                                                if (data['status'] == 'empty')
262                                                {
263                                                        showMessage(data['msg']);
264                                                        return false;
265                                                }
266
267                                                if (data['status'] != 'ok')
268                                                {
269                                                        showMessage(data['msg']);
270                                                        return false;
271                                                }
272
273                                                //showMessage(data['msg']);
274
275                                                var name = '';
276                                                var emails = new Array();
277                                                for (var i in data['data'])
278                                                {
279                                                        emails_count = 0;
280                                                        for (var j in data['data'][i])
281                                                        {
282                                                                if (j == 'names_ordered')
283                                                                {
284                                                                        name = '"'+data['data'][i][j]+'"';
285                                                                }
286                                                                else if (j == 'connections')
287                                                                {
288                                                                        for (var k in data['data'][i][j])
289                                                                        {
290                                                                                if (data['data'][i][j][k]['id_type'] == Element('cc_email_id_type').value)
291                                                                                {
292                                                                                        emails[emails.length] = ' <'+data['data'][i][j][k]['connection_value']+'>';
293                                                                                }
294                                                                        }
295                                                                }
296                                                        }
297
298                                                        if (name != '' && emails.length)
299                                                        {
300                                                                for (var j in emails)
301                                                                {
302                                                                        entries.options[entries.options.length] = new Option(name+emails[j], i+'_'+j);
303                                                                }
304                                                        }
305                                                       
306                                                        name = '';
307                                                        emails = new Array();
308                                                }
309                                        }
310                                }
311                                catch (e)
312                                {
313                                        showMessage(e);
314                                }
315                               
316                        };
317
318                        httpRequest(obj, CC_url+'get_multiple_entries', 'POST', handler, str_data);
319                };
320        }
321       
322        ccEmailWinClass.prototype.entries_to = function()
323        {
324                var i;
325                var length = this.entries.options.length-1;
326                for (i = length; i >= 0; i--)
327                {
328                        if (this.entries.options[i].selected)
329                        {
330                                this.to.options[this.to.options.length] = new Option(this.entries.options[i].text, this.entries.options[i].value);
331                        }
332                }
333        }
334
335        ccEmailWinClass.prototype.entries_cc = function()
336        {
337                var i;
338                var length = this.entries.options.length-1;
339                for (i = length; i >= 0; i--)
340                {
341                        if (this.entries.options[i].selected)
342                        {
343                                this.cc.options[this.cc.options.length] = new Option(this.entries.options[i].text, this.entries.options[i].value);
344                        }
345                }
346        }
347
348        ccEmailWinClass.prototype.entries_cco = function()
349        {
350                var i;
351                var length = this.entries.options.length-1;
352                for (i = length; i >= 0; i--)
353                {
354                        if (this.entries.options[i].selected)
355                        {
356                                this.cco.options[this.cco.options.length] = new Option(this.entries.options[i].text, this.entries.options[i].value);
357                        }
358                }
359        }
360
361        ccEmailWinClass.prototype.to_entries = function()
362        {
363                var i;
364                var length = this.to.options.length-1;
365                for (i = length; i >= 0; i--)
366                {
367                        if (this.to.options[i].selected)
368                        {
369                                this.to.removeChild(this.to.options[i]);
370                        }
371                }
372        }
373
374        ccEmailWinClass.prototype.cc_entries = function()
375        {
376                var i;
377                var length = this.cc.options.length-1;
378                for (i = length; i >= 0; i--)
379                {
380                        if (this.cc.options[i].selected)
381                        {
382                                this.cc.removeChild(this.cc.options[i]);
383                        }
384                }
385        }
386
387        ccEmailWinClass.prototype.cco_entries = function()
388        {
389                var i;
390                var length = this.cco.options.length-1;
391                for (i = length; i >= 0; i--)
392                {
393                        if (this.cco.options[i].selected)
394                        {
395                                this.cco.removeChild(this.cco.options[i]);
396                        }
397                }
398        }
399
400        /****************************************************************************\
401         *                        Auxiliar Functions                                *
402        \****************************************************************************/
Note: See TracBrowser for help on using the repository browser.