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

Revision 3180, 8.1 KB checked in by niltonneto, 14 years ago (diff)

Ticket #1167 - Corrigido problema ao clicar em organização vazia.

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