source: branches/2.2/contactcenter/js/cc_tree.js @ 3333

Revision 3333, 8.4 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #1292 - Ao clicar mostrar cartões no contactcenter, este dispara consulta

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