[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 - Add Group |
---|
| 16 | * |
---|
| 17 | * USAGE INSTRUCTIONS |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | function cAddGroup () |
---|
| 21 | { |
---|
| 22 | // Private |
---|
| 23 | this._card; |
---|
| 24 | this._button = new Array(); |
---|
| 25 | |
---|
| 26 | // Public |
---|
| 27 | this.window; |
---|
| 28 | this.afterSave; |
---|
| 29 | this.load; |
---|
| 30 | |
---|
| 31 | // Constructor |
---|
| 32 | var wHeight = 0; |
---|
| 33 | |
---|
| 34 | // Elements |
---|
| 35 | this.title = Element('title'); |
---|
| 36 | this.contact_in_list = Element('contact_in_list'); |
---|
| 37 | this.contact_list = Element('contact_list'); |
---|
| 38 | this.group_id = Element('group_id'); |
---|
| 39 | |
---|
| 40 | ccAGWinHeight = 'ccAGWinHeightMO'; |
---|
| 41 | |
---|
| 42 | if (is_ie) |
---|
| 43 | ccAGWinHeight = 'ccAGWinHeightIE'; |
---|
| 44 | |
---|
| 45 | wHeight = Element(ccAGWinHeight).value; |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | this.window = new dJSWin({ |
---|
| 49 | id: 'ccAddGroup DOM', |
---|
| 50 | content_id: 'ccAddGroupContent', |
---|
| 51 | width: '700px', |
---|
| 52 | height: wHeight+'px', |
---|
| 53 | title_color: '#3978d6', |
---|
| 54 | bg_color: '#eee', |
---|
| 55 | title: Element('ccAGTitle').value, |
---|
| 56 | title_text_color: 'white', |
---|
| 57 | button_x_img: Element('cc_phpgw_img_dir').value+'/winclose.gif', |
---|
| 58 | border: true }); |
---|
| 59 | |
---|
| 60 | this.window.draw(); |
---|
| 61 | |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /*! |
---|
| 65 | @method associateAsButton |
---|
| 66 | @abstract Associates the button functions with the spacified DOM Element |
---|
| 67 | @author Raphael Derosso Pereira |
---|
| 68 | |
---|
| 69 | @param div DOMElement The HTML DOM element that will "host" the |
---|
| 70 | plugin button. |
---|
| 71 | |
---|
| 72 | @param func function The function that returns the data to be used |
---|
| 73 | to pre-populate the quickAdd fields. The return format MUST be |
---|
| 74 | an Array like: |
---|
| 75 | |
---|
| 76 | var return_data = new Array(); |
---|
| 77 | return_data[0] = <value>; // Value for the first field |
---|
| 78 | return_data[1] = <value>; // Value for the second field |
---|
| 79 | ... |
---|
| 80 | |
---|
| 81 | */ |
---|
| 82 | cAddGroup.prototype.associateAsButton = function (div) |
---|
| 83 | { |
---|
| 84 | var _this = this; |
---|
| 85 | div.onclick = function() { |
---|
| 86 | |
---|
| 87 | if (_this.load) { |
---|
| 88 | switch (typeof(_this.load)) { |
---|
| 89 | |
---|
| 90 | case 'function': |
---|
| 91 | _this.load(); |
---|
| 92 | break; |
---|
| 93 | |
---|
| 94 | case 'string': |
---|
| 95 | eval(_this.load); |
---|
| 96 | break; |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | }; |
---|
| 100 | |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /*! |
---|
| 104 | |
---|
| 105 | @method send |
---|
| 106 | @abstract Sends data to server |
---|
| 107 | @author Raphael Derosso Pereira |
---|
| 108 | |
---|
| 109 | */ |
---|
| 110 | cAddGroup.prototype.send = function () |
---|
| 111 | { |
---|
| 112 | var _this = this; |
---|
| 113 | |
---|
| 114 | var handler = function (responseText) |
---|
| 115 | { |
---|
| 116 | Element('cc_debug').innerHTML = responseText; |
---|
| 117 | var data = unserialize(responseText); |
---|
| 118 | |
---|
| 119 | if (!data || typeof(data) != 'object') |
---|
| 120 | { |
---|
| 121 | showMessage(Element('cc_msg_err_contacting_server').value); |
---|
| 122 | return; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | //showMessage(data['msg']); |
---|
| 126 | |
---|
| 127 | if (data['status'] != 'ok') |
---|
| 128 | { |
---|
| 129 | return; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | _this.clear(); |
---|
| 133 | _this.window.close(); |
---|
| 134 | |
---|
| 135 | if (_this.afterSave) |
---|
| 136 | { |
---|
| 137 | switch (typeof(_this.afterSave)) |
---|
| 138 | { |
---|
| 139 | case 'function': |
---|
| 140 | _this.afterSave(); |
---|
| 141 | break; |
---|
| 142 | |
---|
| 143 | case 'string': |
---|
| 144 | eval(_this.afterSave); |
---|
| 145 | break; |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | var sdata = new Array(); |
---|
| 151 | var empty = true; |
---|
| 152 | |
---|
| 153 | sdata[0] = this.title.value; |
---|
| 154 | var contacts = new Array(); |
---|
| 155 | |
---|
| 156 | for (j =0; j < this.contact_in_list.length; j++) |
---|
| 157 | contacts[j] = this.contact_in_list.options[j].value; |
---|
| 158 | |
---|
| 159 | if(!this.title.value) { |
---|
| 160 | alert('Preencha o campo obrigatório "Nome Completo"'); |
---|
| 161 | this.title.focus(); |
---|
| 162 | return false; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | if(! contacts.length) { |
---|
| 166 | alert('Você não adicionou nenhum contato para esse grupo'); |
---|
| 167 | return false; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | sdata[1] = contacts; |
---|
| 171 | sdata[2] = this.group_id.value == 'undefined' ? sdata[2] = 0 : sdata[2] = this.group_id.value; |
---|
| 172 | var sdata = 'add='+escape(serialize(sdata)); |
---|
| 173 | Connector.newRequest('cAddGroup.Send', CC_url+'add_group', 'POST', handler, sdata); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | /*! |
---|
| 177 | |
---|
| 178 | @method clear |
---|
| 179 | @abstract Clear all Plugin Fields |
---|
| 180 | @author Raphael Derosso Pereira |
---|
| 181 | |
---|
| 182 | */ |
---|
| 183 | cAddGroup.prototype.clear = function (reload) |
---|
| 184 | { |
---|
| 185 | for (j =0; j < this.contact_in_list.options.length; j++) { |
---|
| 186 | this.contact_in_list.options[j].selected = false; |
---|
| 187 | this.contact_in_list.options[j--] = null; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | if(reload) { |
---|
| 191 | for (j =0; j < this.contact_list.options.length; j++) { |
---|
| 192 | this.contact_list.options[j].selected = false; |
---|
| 193 | this.contact_list.options[j--] = null; |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | this.title.value = ''; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | /* Função para remover contato da lista */ |
---|
| 201 | |
---|
| 202 | cAddGroup.prototype.remUser = function(){ |
---|
| 203 | |
---|
| 204 | select = this.contact_list; |
---|
| 205 | select_in = this.contact_in_list; |
---|
| 206 | |
---|
| 207 | for(var i = 0;i < select_in.options.length; i++) |
---|
| 208 | if(select_in.options[i].selected) |
---|
| 209 | select_in.options[i--] = null; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | /* Função para adicionar contato na lista */ |
---|
| 213 | cAddGroup.prototype.addUser = function(){ |
---|
| 214 | |
---|
| 215 | select = this.contact_list; |
---|
| 216 | select_in = this.contact_in_list; |
---|
| 217 | |
---|
| 218 | for (i = 0 ; i < select.length ; i++) { |
---|
| 219 | |
---|
| 220 | if (select.options[i].selected) { |
---|
| 221 | isSelected = false; |
---|
| 222 | |
---|
| 223 | for(var j = 0;j < select_in.options.length; j++) { |
---|
| 224 | if(select_in.options[j].value == select.options[i].value){ |
---|
| 225 | isSelected = true; |
---|
| 226 | break; |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | if(!isSelected){ |
---|
| 231 | |
---|
| 232 | option = document.createElement('option'); |
---|
| 233 | option.value =select.options[i].value; |
---|
| 234 | option.text = select.options[i].text; |
---|
| 235 | option.selected = true; |
---|
| 236 | select_in.options[select_in.options.length] = option; |
---|
| 237 | |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | for (j =0; j < select.options.length; j++) |
---|
| 244 | select .options[j].selected = false; |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | /* Build the Object */ |
---|
| 248 | var ccAddGroup ; |
---|
| 249 | var cAddGroup_pre_load = document.body.onload; |
---|
| 250 | /* Se for IE, modifica a largura da coluna dos botoes.*/ |
---|
| 251 | if(document.all) |
---|
| 252 | document.getElementById('buttons').width = 140; |
---|
| 253 | |
---|
| 254 | if (is_ie) |
---|
| 255 | { |
---|
| 256 | document.body.onload = function (e) |
---|
| 257 | { |
---|
| 258 | cAddGroup_pre_load(); |
---|
| 259 | ccAddGroup = new cAddGroup(); |
---|
| 260 | |
---|
| 261 | }; |
---|
| 262 | } |
---|
| 263 | else |
---|
| 264 | { |
---|
| 265 | ccAddGroup = new cAddGroup(); |
---|
| 266 | } |
---|