source: trunk/contactcenter/js/cc_tree.js @ 4717

Revision 4717, 8.8 KB checked in by airton, 13 years ago (diff)

Ticket #2113 - Falha na criacao de um contato compartilhado

  • 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 - Tree Management Class
16         */
17
18        if (!dFTree)
19        {
20                throw('dFTree lib must be loaded!');
21        }
22       
23        function ccCatalogTree(params)
24        {
25                if (!params || !params['name'] || !params['id_destination'])
26                {
27                        throw('Must specify the tree name!');
28                }
29
30                var _tree = this;
31               
32                /* This is the property that holds the Tree Object */
33                this.name = params['name'];
34                this.tree = new dFTree({'name': params['name']+'_tree'});
35                this.actualLevel = null;
36                this.actualCatalog = null;
37                this.actualCatalogIsExternal = null;
38                this.treeAvailable = false;
39                this.afterSetCatalog = params['afterSetCatalog'];
40                this.catalog_perms = -1;
41                this.Connector = params['connector'];
42
43                /* Build the Inicial Tree */
44                //this._getActualLevel();
45                setTimeout(function(){ _tree._updateTree('0', true);}, 100);
46                this.tree.draw(Element(params['id_destination']));
47        }
48
49        ccCatalogTree.prototype.setCatalog = function(catalog) {
50                var _this = this;
51                var _catalog = catalog;
52                       
53                if(catalog.length >= 2) {
54                        if( parseInt( catalog.charAt(2) ) < 2 ){
55                                document.getElementById( 'advanced' ).style.display = 'none';
56                        }
57                        else
58                                document.getElementById( 'advanced' ).style.display = '';
59                }
60
61                var handler = function (responseText)
62                {
63                        Element('cc_debug').innerHTML = responseText;
64                        var data = unserialize(responseText);
65
66                        if (!data)
67                        {
68                                showMessage(Element('cc_msg_err_contacting_server').value);
69                                return;
70                        }
71                        _this.actualCatalog = data['catalog'];//Atribuir o catalogo atual...
72                        _this.actualCatalogIsExternal = data['external'];
73                        if (data['status'] != 'ok')
74                        {
75                                showMessage(data['msg']);
76                                _this._getActualLevel(true);
77                                return;
78                        }
79                        _this.actualLevel = _catalog;
80
81                        _this.catalog_perms = parseInt(data['perms']);
82                       
83                        if(_this.catalog_perms == 0){
84                                if(CC_visual == 'cards')
85                                        drawCards(0);
86                                else if(CC_visual == 'table')
87                                        drawTable(0);
88                                setPages(0,0);
89                        }
90                        else if (_this.afterSetCatalog)
91                        {
92                                typeof(_this.afterSetCatalog) == 'function' ? _this.afterSetCatalog() : eval(_this.afterSetCatalog);
93                        }
94
95                        if(data['resetCC_actual_letter'] == 1)
96                        {
97
98                            CC_actual_letter = null;
99                        }
100                };
101               
102                Connector.newRequest(this.name+'catalog', CC_url+'set_catalog&catalog='+catalog, 'GET', handler);
103        }
104       
105        ccCatalogTree.prototype.setCatalogSearch = function (catalog) {
106       
107                var _this = this;
108                var _catalog = catalog;
109
110                var handler = function (responseText)
111                {
112                        Element('cc_debug').innerHTML = responseText;
113                        var data = unserialize(responseText);
114
115                        if (!data)
116                        {
117                                showMessage(Element('cc_msg_err_contacting_server').value);
118                                return;
119                        }
120                       
121                        if (data['status'] != 'ok')
122                        {
123                                showMessage(data['msg']);
124                                _this._getActualLevel(true);
125                                return;
126                        }
127                        _this.actualLevel = _catalog;
128
129                        _this.catalog_perms = parseInt(data['perms']);
130
131                        this.afterSetCatalog = ccEmailWin.search.go();
132                       
133                };
134                Connector.newRequest(this.name+'catalog', CC_url+'set_catalog&catalog='+catalog, 'GET', handler);
135        }
136               
137       
138        ccCatalogTree.prototype.select = function(level, search)
139        {
140                if (!search) {
141                        this.tree.openTo(level);
142                        this.tree.getNodeById(level)._select();
143               
144                        if (level != this.actualLevel)
145                        {
146                                this.setCatalog(level);
147                                return;
148                        }
149                } else {
150                        this.tree.openTo(level);
151                        this.tree.getNodeById(level)._select();
152                        this.setCatalogSearch(level);
153                        return;
154                }
155        }
156
157        /*************************************************************************\
158         *                    Methods For Internal Use                           *
159        \*************************************************************************/
160       
161        ccCatalogTree.prototype._waitForTree = function(level, rlevel)
162        {
163                if (this.treeAvailable)
164                {
165                        this.setCatalog(level);
166                        return;
167                }
168
169                if (rlevel >= 100)
170                {
171                        return;
172                }
173               
174                setTimeout(this.name+'._waitForTree(\''+level+'\', '+rlevel+')', 100);
175        }
176
177        ccCatalogTree.prototype._getActualLevel = function(set)
178        {
179                var _this = this;
180                this.treeAvailable = false;
181
182                var handler = function (responseText)
183                {
184                        Element('cc_debug').innerHTML = responseText;
185                        var data = unserialize(responseText);
186
187                        if (!data)
188                        {
189                                showMessage(Element('cc_msg_err_contacting_server').value);
190                                return;
191                        }
192
193                        if (data['status'] != 'ok')
194                        {
195                                showMessage(data['msg']);
196                                return;
197                        }
198
199                        _this.actualLevel = data['data'];
200
201                        if (set)
202                        {
203                        //      _this.select(data['data']);
204                                _this.tree.openTo(_this.actualLevel);
205                                _this.tree.getNodeById(_this.actualLevel)._select();
206                                _this.setCatalog(_this.actualLevel);
207                                _this.expandTree();
208
209                        }
210                };
211               
212                Connector.newRequest(this.name+'actual', CC_url+'get_actual_catalog', 'GET', handler);
213        }
214
215        ccCatalogTree.prototype.expandTree = function() {
216                for (i=0; i < this.tree._aNodes.length; i++)
217                        this._expandSubTree(this.tree._aNodes[i]);
218        }
219
220        ccCatalogTree.prototype._expandSubTree = function(node) {
221                if ( node._children == '' ) {
222                        return;
223                }
224                if (node._children != '') {
225                        for (i = 0; i <= node._children.length; i++) {
226                                if ( node._io == false )
227                                        node.changeState();
228                                this._expandSubTree(node._children[i]);
229                        }
230                }
231        }
232
233
234        ccCatalogTree.prototype._updateTree = function(level, open)
235        {
236                var _this = this;
237                this.treeAvailable = false;
238
239                var handler = function (responseText)
240                {
241                        var data = unserialize(responseText);
242                        var treeData;
243
244                        if (!data)
245                        {
246                                showMessage(Element('cc_msg_err_contacting_server').value);
247                                return;
248                        }
249
250                        if (data['status'] != 'ok')
251                        {
252                                showMessage(data['msg']);
253                                return;
254                        }
255
256                        treeData = data['data'];
257                       
258                        var timeout = 10;
259                        var limit = 0;
260                        for (var i in treeData)
261                        {
262                                if (i == 'length')
263                                {
264                                        continue;
265                                }
266
267                                switch (treeData[i]['type'])
268                                {
269                                        case 'unknown':
270                                                setTimeout(_this.name+".tree.add(new dNode({id: '"+treeData[i]['id']+"', caption: '"+treeData[i]['caption']+"', onFirstOpen: '"+_this.name+"._updateTree(\\'"+treeData[i]['id']+"\\')', onClick: '"+_this.name+"._updateTree(\\'"+treeData[i]['id']+"\\');"+_this.name+"._waitForTree(\\'"+treeData[i]['id']+"\\',0)'}), '"+treeData[i]['pid']+"');", timeout);
271                                                break;
272
273                                        case 'catalog_group':
274                                                //setTimeout(_this.name+".tree.add(new dNode({id: '"+treeData[i]['id']+"', caption: '"+treeData[i]['caption']+"', onFirstOpen: '', onClick: '"+_this.name+".tree.getNodeById(\\'"+treeData[i]['id']+"\\').open();"+_this.name+"._getActualLevel(true);'}), '"+treeData[i]['pid']+"');", timeout);
275                                                setTimeout(_this.name+".tree.add(new dNode({id: '"+treeData[i]['id']+"', caption: '"+treeData[i]['caption']+"', onFirstOpen: '', onClick: '"+_this.name+".setCatalog(\\'"+treeData[i]['id']+"\\');'}), '"+treeData[i]['pid']+"');", timeout);
276                                                break;
277
278                                        case 'catalog':
279                                                setTimeout(_this.name+".tree.add(new dNode({id: '"+treeData[i]['id']+"', caption: '"+treeData[i]['caption']+"', onFirstOpen: '', onClick: '"+_this.name+".setCatalog(\\'"+treeData[i]['id']+"\\');'}), '"+treeData[i]['pid']+"');", timeout);
280                                                break;
281
282                                        case 'mixed_catalog_group':
283                                                setTimeout(_this.name+".tree.add(new dNode({id: '"+treeData[i]['id']+"', caption: '"+treeData[i]['caption']+"', onFirstOpen: '', onClick: '"+_this.name+".setCatalog(\\'"+treeData[i]['id']+"\\');'}), '"+treeData[i]['pid']+"');", timeout);
284                                                break;
285
286                                        case 'empty':
287                                                setTimeout(_this.name+".tree.add(new dNode({id: '"+treeData[i]['id']+"', caption: '"+treeData[i]['caption']+"', onFirstOpen: '', onClick: '"+_this.name+".setCatalog(\\'"+treeData[i]['id']+"\\');'}), '"+treeData[i]['pid']+"');", timeout);
288                                }
289
290                                timeout += 5;
291                        }
292                       
293                        _this.treeAvailable = true;
294
295                        if (open)
296                        {
297                                setTimeout(_this.name+"._getActualLevel(true)", timeout+10);
298                                //setTimeout(_this.name+".tree.openTo("+_this.name+".actualLevel);", timeout+100);
299                                //setTimeout(_this.name+".tree.getNodeById("+_this.name+".actualLevel)._select();", timeout+100);
300                        }
301                };
302                Connector.newRequest(this.name+'update', CC_url+'get_catalog_tree&level='+level, 'GET', handler);
303        }
Note: See TracBrowser for help on using the repository browser.