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