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

Revision 2, 7.5 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

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