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