[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; |
---|
[3282] | 36 | this.actualCatalog = null; |
---|
| 37 | this.actualCatalogIsExternal = null; |
---|
[2] | 38 | this.treeAvailable = false; |
---|
| 39 | this.afterSetCatalog = params['afterSetCatalog']; |
---|
| 40 | this.catalog_perms = -1; |
---|
| 41 | this.Connector = params['connector']; |
---|
| 42 | |
---|
[285] | 43 | /* Build the Inicial Tree */ |
---|
[2] | 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 | } |
---|
[3282] | 61 | _this.actualCatalog = data['catalog'];//Atribuir o catalogo atual... |
---|
| 62 | _this.actualCatalogIsExternal = data['external']; |
---|
[2] | 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']); |
---|
[285] | 71 | |
---|
[3180] | 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) |
---|
[2] | 80 | { |
---|
| 81 | typeof(_this.afterSetCatalog) == 'function' ? _this.afterSetCatalog() : eval(_this.afterSetCatalog); |
---|
| 82 | } |
---|
[3333] | 83 | |
---|
| 84 | if(data['resetCC_actual_letter'] == 1) |
---|
| 85 | { |
---|
| 86 | |
---|
| 87 | CC_actual_letter = null; |
---|
| 88 | } |
---|
[2] | 89 | }; |
---|
[3333] | 90 | |
---|
[2] | 91 | Connector.newRequest(this.name+'catalog', CC_url+'set_catalog&catalog='+catalog, 'GET', handler); |
---|
| 92 | } |
---|
[285] | 93 | |
---|
[2] | 94 | ccCatalogTree.prototype.setCatalogSearch = function (catalog) { |
---|
[285] | 95 | |
---|
[2] | 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 | } |
---|
[285] | 107 | |
---|
[2] | 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(); |
---|
[285] | 118 | |
---|
[2] | 119 | }; |
---|
| 120 | Connector.newRequest(this.name+'catalog', CC_url+'set_catalog&catalog='+catalog, 'GET', handler); |
---|
| 121 | } |
---|
[285] | 122 | |
---|
| 123 | |
---|
[2] | 124 | ccCatalogTree.prototype.select = function(level, search) |
---|
| 125 | { |
---|
[285] | 126 | if (!search) { |
---|
[2] | 127 | this.tree.openTo(level); |
---|
| 128 | this.tree.getNodeById(level)._select(); |
---|
[285] | 129 | |
---|
[2] | 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 | \*************************************************************************/ |
---|
[285] | 146 | |
---|
[2] | 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 | } |
---|
[285] | 159 | |
---|
[2] | 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); |
---|
[285] | 193 | _this.expandTree(); |
---|
| 194 | |
---|
[2] | 195 | } |
---|
| 196 | }; |
---|
[285] | 197 | |
---|
[2] | 198 | Connector.newRequest(this.name+'actual', CC_url+'get_actual_catalog', 'GET', handler); |
---|
| 199 | } |
---|
| 200 | |
---|
[285] | 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 | |
---|
[2] | 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']); |
---|
[285] | 239 | return; |
---|
[2] | 240 | } |
---|
| 241 | |
---|
| 242 | treeData = data['data']; |
---|
[285] | 243 | |
---|
[2] | 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 | } |
---|
[285] | 278 | |
---|
[2] | 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 | } |
---|