source: branches/1.2/contactcenter/js/ccAddGroup.js @ 294

Revision 294, 6.2 KB checked in by niltonneto, 16 years ago (diff)

Correção da lista de contatos na janela de adicionar/editar grupo.
No Internet Explorer não aparecia, pois era usado o innerHTML do Select.

  • 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  *  sponsored by Thyamad - http://www.thyamad.com                            *
7  * ------------------------------------------------------------------------- *
8  *  This program is free software; you can redistribute it and/or modify it  *
9  *  under the terms of the GNU General Public License as published by the    *
10  *  Free Software Foundation; either version 2 of the License, or (at your   *
11  *  option) any later version.                                               *
12  \***************************************************************************/
13
14        /*
15         * ContactCenter API - Add Group
16         *
17         * USAGE INSTRUCTIONS
18         */
19
20        function cAddGroup ()
21        {
22                // Private
23                this._card;
24                this._button = new Array();             
25
26                // Public
27                this.window;
28                this.afterSave;
29                this.load;
30               
31                // Constructor
32                var wHeight = 0;
33               
34                // Elements
35                this.title = Element('title');
36                this.contact_in_list = Element('contact_in_list');
37                this.group_id = Element('group_id');
38                               
39                ccAGWinHeight = 'ccAGWinHeightMO';
40
41                if (is_ie)
42                        ccAGWinHeight = 'ccAGWinHeightIE';
43
44                wHeight = Element(ccAGWinHeight).value;
45
46               
47                this.window = new dJSWin({
48                        id: 'ccAddGroup DOM',
49                        content_id: 'ccAddGroupContent',
50                        width: '700px',
51                        height: wHeight+'px',
52                        title_color: '#3978d6',
53                        bg_color: '#eee',
54                        title: Element('ccAGTitle').value,
55                        title_text_color: 'white',
56                        button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif',
57                        border: true });
58
59                this.window.draw();
60               
61        }
62
63        /*!
64                @method associateAsButton
65                @abstract Associates the button functions with the spacified DOM Element
66                @author Raphael Derosso Pereira
67
68                @param div DOMElement The HTML DOM element that will "host" the
69                        plugin button.
70
71                @param func function The function that returns the data to be used
72                        to pre-populate the quickAdd fields. The return format MUST be
73                        an Array like:
74
75                                var return_data = new Array();
76                                return_data[0] = <value>;  // Value for the first field
77                                return_data[1] = <value>;  // Value for the second field
78                                ...
79               
80         */
81        cAddGroup.prototype.associateAsButton = function (div)
82        {
83                var _this = this;               
84                div.onclick = function() {
85                                       
86                        if (_this.load) {
87                                switch (typeof(_this.load)) {
88                               
89                                        case 'function':
90                                                _this.load();
91                                                break;
92
93                                        case 'string':
94                                                eval(_this.load);
95                                                break;
96                                }
97                        }
98                };
99               
100        }
101               
102        /*!
103       
104                @method send
105                @abstract Sends data to server
106                @author Raphael Derosso Pereira
107
108        */
109        cAddGroup.prototype.send = function ()
110        {
111                var _this = this;
112
113                var handler = function (responseText)
114                {
115                        Element('cc_debug').innerHTML = responseText;
116                        var data = unserialize(responseText);                           
117                       
118                        if (!data || typeof(data) != 'object')
119                        {
120                                showMessage(Element('cc_msg_err_contacting_server').value);
121                                return;
122                        }
123
124                        //showMessage(data['msg']);
125
126                        if (data['status'] != 'ok')
127                        {
128                                return;
129                        }
130
131                        _this.clear();
132                        _this.window.close();
133                       
134                        if (_this.afterSave)
135                        {
136                                switch (typeof(_this.afterSave))
137                                {
138                                        case 'function':
139                                                _this.afterSave();
140                                                break;
141
142                                        case 'string':
143                                                eval(_this.afterSave);
144                                                break;
145                                }
146                        }
147                }
148
149                var sdata = new Array();
150                var empty = true;
151               
152                sdata[0] = this.title.value;
153                var contacts = new Array();                             
154               
155                for (j =0; j < this.contact_in_list.length; j++)
156                        contacts[j] = this.contact_in_list.options[j].value;                   
157               
158                if(!this.title.value) {
159                        alert(Element('cc_msg_fill_field_name').value);
160                        this.title.focus();
161                        return false;
162                }
163                               
164                if(! contacts.length) {
165                        alert(Element('cc_msg_add_contact_to_group').value);
166                        return false;
167                }
168
169                sdata[1] = contacts;           
170                sdata[2] = this.group_id.value == 'undefined' ?         sdata[2] = 0 : sdata[2]  = this.group_id.value;                                                 
171                var sdata = 'add='+escape(serialize(sdata));
172                Connector.newRequest('cAddGroup.Send', CC_url+'add_group', 'POST', handler, sdata);
173        }
174
175        /*!
176
177                @method clear
178                @abstract Clear all Plugin Fields
179                @author Raphael Derosso Pereira
180
181        */
182        cAddGroup.prototype.clear = function (reload)
183        {
184                for (j =0; j < this.contact_in_list.options.length; j++) {
185                        this.contact_in_list.options[j].selected = false;
186                        this.contact_in_list.options[j--] = null;
187                }
188               
189                if(reload) {
190                        if(Element("contact_list"))
191                        for (j =0; j < Element("contact_list").options.length; j++) {
192                                        Element("contact_list").options[j].selected = false;
193                                        Element("contact_list").options[j--] = null;
194                        }
195                }
196                       
197                this.title.value = '';                         
198        }
199       
200        /* Função para remover contato da lista */     
201       
202        cAddGroup.prototype.remUser = function(){
203               
204                select_in = this.contact_in_list;                                                               
205
206                for(var i = 0;i < select_in.options.length; i++)                               
207                        if(select_in.options[i].selected)
208                                select_in.options[i--] = null;
209        }       
210       
211        /* Função para adicionar contato na lista */   
212        cAddGroup.prototype.addUser = function(){
213
214                select = Element("contact_list");
215                select_in = this.contact_in_list;                                                               
216               
217                for (i = 0 ; i < select.length ; i++) {                         
218
219                        if (select.options[i].selected) {
220                                isSelected = false;
221
222                                for(var j = 0;j < select_in.options.length; j++) {                                                                                                                                                     
223                                        if(select_in.options[j].value == select.options[i].value){
224                                                isSelected = true;                                             
225                                                break; 
226                                        }
227                                }
228
229                                if(!isSelected){
230
231                                        option = document.createElement('option');
232                                        option.value =select.options[i].value;
233                                        option.text = select.options[i].text;
234                                        option.selected = true;
235                                        select_in.options[select_in.options.length] = option;
236                                                                                       
237                                }
238                                                                                               
239                        }
240                }
241               
242                for (j =0; j < select.options.length; j++)
243                        select .options[j].selected = false;           
244        }       
245
246        /* Build the Object */
247        var ccAddGroup ;
248        var cAddGroup_pre_load = document.body.onload;
249        /* Se for IE, modifica a largura da coluna dos botoes.*/       
250        if(document.all)
251                document.getElementById('buttons').width = 140;
252
253        if (is_ie)
254        {
255                document.body.onload = function (e)
256                {
257                        cAddGroup_pre_load();
258                        ccAddGroup = new cAddGroup();
259                       
260                };
261        }
262        else
263        {
264                ccAddGroup = new cAddGroup();
265        }
Note: See TracBrowser for help on using the repository browser.