source: branches/2.2/contactcenter/js/ccAddGroup.js @ 3348

Revision 3348, 6.2 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #1214 - Correcao do erro narrado no ticket em questão

  • 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                                showMessage(data['msg']);
129                                return;
130                        }
131
132                        _this.clear();
133                        _this.window.close();
134                       
135                        if (_this.afterSave)
136                        {
137                                switch (typeof(_this.afterSave))
138                                {
139                                        case 'function':
140                                                _this.afterSave();
141                                                break;
142
143                                        case 'string':
144                                                eval(_this.afterSave);
145                                                break;
146                                }
147                        }
148                }
149
150                var sdata = new Array();
151                var empty = true;
152               
153                sdata[0] = this.title.value;
154                var contacts = new Array();                             
155               
156                for (j =0; j < this.contact_in_list.length; j++)
157                        contacts[j] = this.contact_in_list.options[j].value;                   
158               
159                if(!this.title.value) {
160                        alert(Element('cc_msg_fill_field_name').value);
161                        this.title.focus();
162                        return false;
163                }
164                               
165                if(! contacts.length) {
166                        alert(Element('cc_msg_add_contact_to_group').value);
167                        return false;
168                }
169
170                sdata[1] = contacts;           
171                sdata[2] = this.group_id.value == 'undefined' ?         sdata[2] = 0 : sdata[2]  = this.group_id.value;                                                 
172                var sdata = 'add='+escape(serialize(sdata));
173                Connector.newRequest('cAddGroup.Send', CC_url+'add_group', 'POST', handler, sdata);
174        }
175
176        /*!
177
178                @method clear
179                @abstract Clear all Plugin Fields
180                @author Raphael Derosso Pereira
181
182        */
183        cAddGroup.prototype.clear = function (reload)
184        {
185                for (j =0; j < this.contact_in_list.options.length; j++) {
186                        this.contact_in_list.options[j].selected = false;
187                        this.contact_in_list.options[j--] = null;
188                }
189               
190                if(reload) {
191                        if(Element("contact_list"))
192                        for (j =0; j < Element("contact_list").options.length; j++) {
193                                        Element("contact_list").options[j].selected = false;
194                                        Element("contact_list").options[j--] = null;
195                        }
196                }
197                       
198                this.title.value = '';                         
199        }
200       
201        /* Função para remover contato da lista */     
202       
203        cAddGroup.prototype.remUser = function(){
204               
205                select_in = this.contact_in_list;                                                               
206
207                for(var i = 0;i < select_in.options.length; i++)                               
208                        if(select_in.options[i].selected)
209                                select_in.options[i--] = null;
210        }       
211       
212        /* Função para adicionar contato na lista */   
213        cAddGroup.prototype.addUser = function(){
214
215                select = Element("contact_list");
216                select_in = this.contact_in_list;                                                               
217               
218                for (i = 0 ; i < select.length ; i++) {                         
219
220                        if (select.options[i].selected) {
221                                isSelected = false;
222
223                                for(var j = 0;j < select_in.options.length; j++) {                                                                                                                                                     
224                                        if(select_in.options[j].value == select.options[i].value){
225                                                isSelected = true;                                             
226                                                break; 
227                                        }
228                                }
229
230                                if(!isSelected){
231
232                                        option = document.createElement('option');
233                                        option.value =select.options[i].value;
234                                        option.text = select.options[i].text;
235                                        option.selected = true;
236                                        select_in.options[select_in.options.length] = option;
237                                                                                       
238                                }
239                                                                                               
240                        }
241                }
242               
243                for (j =0; j < select.options.length; j++)
244                        select .options[j].selected = false;           
245        }       
246
247        /* Build the Object */
248        var ccAddGroup ;
249        var cAddGroup_pre_load = document.body.onload;
250        /* Se for IE, modifica a largura da coluna dos botoes.*/       
251        if(document.all)
252                document.getElementById('buttons').width = 140;
253
254        if (is_ie)
255        {
256                document.body.onload = function (e)
257                {
258                        cAddGroup_pre_load();
259                        ccAddGroup = new cAddGroup();
260                       
261                };
262        }
263        else
264        {
265                ccAddGroup = new cAddGroup();
266        }
Note: See TracBrowser for help on using the repository browser.