source: sandbox/2.2.0.2/contactcenter/js/cc_tree.js @ 4544

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

Ticket #1954 - Implementação de busca avançada no contactcenter

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