[2] | 1 | /**************************************************************************\ |
---|
| 2 | Início |
---|
| 3 | \**************************************************************************/ |
---|
| 4 | |
---|
| 5 | function Tree_Box(){ |
---|
| 6 | |
---|
| 7 | this.name_folder = ""; |
---|
| 8 | this.name_func = ""; |
---|
| 9 | connector.loadScript("TreeS"); |
---|
| 10 | } |
---|
[3750] | 11 | Tree_Box.prototype.update_folder = function(expand_local_root){ |
---|
| 12 | |
---|
[2] | 13 | var handler_update_folders = function(data){ |
---|
| 14 | folders = data; |
---|
| 15 | // update element dftree_folders_tree; |
---|
| 16 | ttree.make_tree(data,"div_tree","folders_tree","ttree.get_folder(\"root\")",ttreeBox.name_folder,ttreeBox.name_folder,false); |
---|
| 17 | |
---|
| 18 | // update element dftree_tree_folders; |
---|
| 19 | if(Element('content_folders')){Element('content_folders').innerHTML = "";} |
---|
| 20 | draw_tree_folders(folders); |
---|
| 21 | |
---|
| 22 | // update element dftree_wfolders_tree; |
---|
| 23 | if (Element('dftree_wfolders_tree')){ |
---|
| 24 | Element('dftree_wfolders_tree').innerHTML = ''; |
---|
| 25 | ttree.make_tree(data,"wfolders_content_tree","wfolders_tree","","","",false); |
---|
| 26 | } |
---|
| 27 | ttree.FOLDER = ttreeBox.name_folder; |
---|
[1478] | 28 | if (tree_folders.getNodeById(ttree.FOLDER)) |
---|
| 29 | tree_folders.getNodeById(ttree.FOLDER)._select(); |
---|
[3750] | 30 | |
---|
| 31 | if(expand_local_root) |
---|
| 32 | tree_folders.getNodeById('local_root').changeState(); |
---|
[1386] | 33 | /* |
---|
[320] | 34 | if (tree_folders.getNodeById(get_current_folder())) |
---|
| 35 | tree_folders.getNodeById(get_current_folder())._select(); |
---|
[1386] | 36 | */ |
---|
[2] | 37 | } |
---|
[1121] | 38 | if(!expresso_offline) |
---|
| 39 | cExecute ("$this.imap_functions.get_folders_list&folder="+current_folder, handler_update_folders); |
---|
| 40 | else |
---|
| 41 | handler_update_folders(''); |
---|
[2] | 42 | } |
---|
| 43 | |
---|
| 44 | Tree_Box.prototype.verify_children = function(param){ |
---|
| 45 | var aux; |
---|
| 46 | var aux1; |
---|
| 47 | var cont = parseInt(0); |
---|
| 48 | for(var i=0 ; i < folders.length; i++){ |
---|
| 49 | aux = folders[i].folder_id.split(cyrus_delimiter); |
---|
| 50 | aux.pop(); |
---|
| 51 | for(var j=0; j < aux.length; j++){ |
---|
| 52 | if(j == 0) |
---|
| 53 | aux1 = aux[j]; |
---|
| 54 | else |
---|
| 55 | aux1 += cyrus_delimiter + aux[j]; |
---|
| 56 | } |
---|
| 57 | if( aux1 == param){ |
---|
| 58 | cont++; |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | if( cont == 0){ |
---|
| 62 | ttreeBox.del_past(param); |
---|
| 63 | }else{ |
---|
[79] | 64 | alert(get_lang("Delete your sub-folders first")); |
---|
[2] | 65 | } |
---|
| 66 | cont = parseInt(0); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | Tree_Box.prototype.verify = function(exp) |
---|
| 70 | { |
---|
[1335] | 71 | // IE does not understand regExp!!! |
---|
| 72 | if (is_ie) |
---|
| 73 | var reTipo = /^[a-z0-9 \-_+=]*$/i; |
---|
| 74 | else |
---|
| 75 | eval('var reTipo = /^[a-z0-9 \-_+=áéíóúàèìòùâêôãõÃÕÁÉÍÓÚÀÈÌÒÙÂÊÔçÇüñ]*$/i'); |
---|
| 76 | return reTipo.test(exp); |
---|
[2] | 77 | } |
---|
| 78 | |
---|
| 79 | // Função para verificar o nome da caixa; |
---|
| 80 | Tree_Box.prototype.verify_names = function(name_folder){ |
---|
[197] | 81 | var arr_nm_folder = new Array("INBOX",trashfolder,draftsfolder,sentfolder,spamfolder); |
---|
[2] | 82 | for(var i=0 ; i < arr_nm_folder.length; i++){ |
---|
| 83 | if(name_folder == arr_nm_folder[i]){ |
---|
| 84 | ttree.FOLDER = ""; |
---|
| 85 | return true; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | return false; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | // Valida os nomes das pastas |
---|
| 92 | Tree_Box.prototype.validate = function(func){ |
---|
| 93 | var aux = ttree.FOLDER.split(cyrus_delimiter); |
---|
| 94 | var aux2; |
---|
| 95 | if(ttree.FOLDER != ""){ |
---|
[1370] | 96 | if(aux.length > 1) |
---|
| 97 | { |
---|
| 98 | aux2 = aux[1]; |
---|
| 99 | } |
---|
| 100 | else |
---|
| 101 | { |
---|
| 102 | aux2 = aux[0]; |
---|
| 103 | } |
---|
[1368] | 104 | if(func == "rename" && this.verify_names(aux2)){ |
---|
[3884] | 105 | alert(get_lang("It's not possible rename the folder: ") + lang_folder(aux2) + '.'); |
---|
[1368] | 106 | return false; |
---|
[2] | 107 | }else{ |
---|
[1368] | 108 | if(func == "newpast"){ |
---|
| 109 | var button = prompt(get_lang('Enter the name of the new folder:'),""); |
---|
[689] | 110 | if (button.indexOf("local_") != -1 || button.toUpperCase() == "INBOX") { |
---|
| 111 | alert(get_lang("cannot create folder. try other folder name")); |
---|
| 112 | return false; //Não posso criar pastas contendo a string local_ |
---|
| 113 | } |
---|
[3390] | 114 | if(button.match(/[\/\\\!\@\#\$\%\&\*\(\)]/gi)){ |
---|
| 115 | alert(get_lang("cannot create folder. try other folder name")); |
---|
| 116 | return false; |
---|
| 117 | } |
---|
[689] | 118 | |
---|
[2] | 119 | if(trim(button) == "" || trim(button) == null){ |
---|
| 120 | return false; |
---|
| 121 | }else{ |
---|
| 122 | ttreeBox.new_past(button); |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | if(func == "rename"){ |
---|
| 126 | if(ttree.FOLDER == "root"){ |
---|
[128] | 127 | alert(get_lang("It's not possible rename this folder!")); |
---|
[2] | 128 | return false; |
---|
| 129 | } |
---|
[69] | 130 | if(ttree.FOLDER == get_current_folder()){ |
---|
[197] | 131 | alert(get_lang("It's not possible rename this folder, because it is being used in the moment!")); |
---|
[69] | 132 | return false; |
---|
| 133 | } |
---|
[128] | 134 | var button1 = prompt(get_lang("Enter a name for the box"), ""); |
---|
[689] | 135 | if (button1.indexOf("local_") != -1 || button1.toUpperCase() == "INBOX") { |
---|
| 136 | alert(get_lang("cannot create folder. try other folder name")); |
---|
| 137 | return false; //Não posso criar pastas contendo a string local_ |
---|
| 138 | } |
---|
[3390] | 139 | |
---|
| 140 | if(button1.match(/[\/\\\!\@\#\$\%\&\*\(\)]/gi)){ |
---|
| 141 | alert(get_lang("It's not possible rename this folder. try other folder name")); |
---|
| 142 | return false; |
---|
| 143 | } |
---|
| 144 | |
---|
[2] | 145 | if(trim(button1) == "" || trim(button1) == null){ |
---|
| 146 | return false; |
---|
| 147 | }else{ |
---|
| 148 | ttreeBox.rename(button1); |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | }else{ |
---|
[128] | 153 | alert(get_lang("Select a folder!")); |
---|
[2] | 154 | return false; |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
[1368] | 158 | // Para criar a nova pasta; |
---|
| 159 | Tree_Box.prototype.new_past = function(newp){ |
---|
| 160 | |
---|
| 161 | var aux = ttree.FOLDER.split(cyrus_delimiter); |
---|
[3213] | 162 | var delimExp = new RegExp('\\'+cyrus_delimiter,"g"); |
---|
[3018] | 163 | newp = newp.replace(delimExp,'_'); |
---|
[1368] | 164 | var newp2 = ""; |
---|
| 165 | if( aux[0] == "root"){ |
---|
| 166 | if(!this.verify(newp)){ |
---|
| 167 | alert(get_lang("Type without spaces, dots or special characters!")); |
---|
| 168 | newp = ""; |
---|
| 169 | return false; |
---|
| 170 | }else{ |
---|
| 171 | newp2 = newp; |
---|
| 172 | newp = "INBOX" + cyrus_delimiter + newp; |
---|
| 173 | } |
---|
[2] | 174 | }else{ |
---|
[1368] | 175 | if(!this.verify(newp)){ |
---|
| 176 | alert(get_lang("Type without spaces, dots or special characters!")); |
---|
| 177 | newp = ""; |
---|
| 178 | return false; |
---|
[2] | 179 | }else{ |
---|
[1368] | 180 | newp2 = newp; |
---|
| 181 | newp = ttree.FOLDER + cyrus_delimiter + newp; |
---|
[2] | 182 | } |
---|
| 183 | } |
---|
[1368] | 184 | |
---|
[2] | 185 | if(newp != ""){ |
---|
| 186 | var handler_return = function(data){ |
---|
| 187 | if(data != "Ok"){ |
---|
[1371] | 188 | alert(get_lang(data)); |
---|
[2] | 189 | }else{ |
---|
[1374] | 190 | ttreeBox.name_folder = "root"; //or use var newpast |
---|
[2] | 191 | this.name_func = "newpast"; |
---|
[1443] | 192 | connector.purgeCache(); |
---|
[2] | 193 | ttreeBox.update_folder(); |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | var args = "$this.imap_functions.create_mailbox"; |
---|
| 197 | var params = "newp="+newp; |
---|
| 198 | cExecute(args,handler_return,params); |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | // Funcao para renomear a pasta; |
---|
| 203 | Tree_Box.prototype.rename = function(rename){ |
---|
| 204 | var old_box = ttree.FOLDER; |
---|
| 205 | var aux = old_box.split(cyrus_delimiter); |
---|
| 206 | var rename_new = ""; |
---|
| 207 | |
---|
| 208 | if(old_box == "root"){ |
---|
[128] | 209 | alert(get_lang("Select a folder!")); |
---|
[2] | 210 | return false; |
---|
| 211 | } |
---|
| 212 | if(aux.length == 1){ |
---|
[3884] | 213 | alert(get_lang("It's not possible rename the folder: ") + aux[0] + '.'); |
---|
[2] | 214 | rename = ""; |
---|
| 215 | return false; |
---|
| 216 | }else{ |
---|
| 217 | if(this.verify_names(aux[1])){ |
---|
[3884] | 218 | alert(get_lang("It's not possible rename the folder: ") + aux[1] + '.'); |
---|
[2] | 219 | rename = ""; |
---|
| 220 | return false; |
---|
| 221 | }else{ |
---|
| 222 | if(!this.verify(rename)){ |
---|
[128] | 223 | alert(get_lang("Type without spaces, dots or special characters!")); |
---|
[2] | 224 | rename = ""; |
---|
| 225 | return false; |
---|
| 226 | }else{ |
---|
| 227 | aux.pop(); |
---|
| 228 | aux.push(rename); |
---|
| 229 | for(var i=0; i< aux.length; i++){ |
---|
| 230 | if( i == 0) |
---|
| 231 | rename_new = aux[i]; |
---|
| 232 | else |
---|
| 233 | rename_new += cyrus_delimiter + aux[i]; |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | } |
---|
| 238 | if(rename != ""){ |
---|
| 239 | var handler_return = function(data) |
---|
[1372] | 240 | { |
---|
[1443] | 241 | connector.purgeCache(); |
---|
[1372] | 242 | ttreeBox.name_folder = "root"; |
---|
| 243 | ttreeBox.update_folder(); |
---|
[2] | 244 | } |
---|
| 245 | var args = "$this.imap_functions.ren_mailbox"; |
---|
| 246 | var params = "rename="+rename_new+"¤t="+old_box; |
---|
| 247 | cExecute(args,handler_return,params); |
---|
| 248 | } |
---|
| 249 | } |
---|
| 250 | // |
---|
| 251 | Tree_Box.prototype.export_all_msg = function(){ |
---|
| 252 | |
---|
| 253 | if(ttree.FOLDER == "root"){return false;} |
---|
| 254 | var nm_bx = ttree.FOLDER.split(cyrus_delimiter); |
---|
| 255 | var name_f = nm_bx[nm_bx.length -1]; |
---|
| 256 | var hand_export = function(data){ |
---|
| 257 | if(!data){ |
---|
| 258 | write_msg(get_lang('Error compressing messages (ZIP). Contact the administrator.')) |
---|
[1558] | 259 | }else if(data["empty_folder"]){ |
---|
| 260 | write_msg(get_lang("The selected folder is empty.")); |
---|
| 261 | alert(get_lang("The selected folder is empty.")); |
---|
[2] | 262 | }else |
---|
| 263 | download_attachments(null, null, data, null,null, name_f +'.zip'); |
---|
| 264 | } |
---|
| 265 | cExecute("$this.exporteml.export_all",hand_export,"folder="+ttree.FOLDER); |
---|
[53] | 266 | write_msg(get_lang('You must wait while the messages will be exported...')); |
---|
[2] | 267 | } |
---|
| 268 | |
---|
| 269 | // Função para deletar a pasta; |
---|
| 270 | Tree_Box.prototype.del = function(){ |
---|
[1368] | 271 | var folder_name = ttree.FOLDER; |
---|
[2] | 272 | var aux = ttree.FOLDER.split(cyrus_delimiter); |
---|
| 273 | |
---|
| 274 | if(aux[0] == "root" || ttree.FOLDER == ""){ |
---|
[79] | 275 | alert(get_lang("Select a folder!")); |
---|
[2] | 276 | return false; |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | if(aux.length == 1){ |
---|
[3884] | 280 | alert(get_lang("It's not possible delete the folder: ") + get_lang("Inbox") + '.'); |
---|
[2] | 281 | return false; |
---|
| 282 | }else{ |
---|
[1368] | 283 | if(this.verify_names(aux[1]) && typeof(aux[2]) == 'undefined'){ |
---|
[3884] | 284 | alert(get_lang("It's not possible delete the folder: ") + get_lang(special_folders[aux[1]]) + '.'); |
---|
[128] | 285 | return false; |
---|
[2] | 286 | }else{ |
---|
[1368] | 287 | this.verify_children(folder_name); |
---|
[2] | 288 | } |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | Tree_Box.prototype.del_past = function(param){ |
---|
| 293 | var aux = param.split(cyrus_delimiter); |
---|
| 294 | var aux1 = aux.pop(); |
---|
[69] | 295 | |
---|
| 296 | if(ttree.FOLDER == get_current_folder()){ |
---|
[1374] | 297 | alert(get_lang("It's not possible delete this folder, because it is being used in the moment!")); |
---|
[69] | 298 | return false; |
---|
| 299 | } |
---|
[128] | 300 | if(confirm(get_lang("Do you wish to exclude the folder ") + aux1+ "?")){ |
---|
[2] | 301 | var handler_return = function(data) |
---|
| 302 | { |
---|
| 303 | if(data != "Ok") |
---|
| 304 | { |
---|
| 305 | alert(data); |
---|
| 306 | }else{ |
---|
[1443] | 307 | connector.purgeCache(); |
---|
[1368] | 308 | ttreeBox.name_folder = "root"; |
---|
[2] | 309 | ttreeBox.update_folder(); |
---|
[1372] | 310 | write_msg(get_lang("The folder %1 was successfully removed", aux1)); |
---|
[2] | 311 | } |
---|
| 312 | } |
---|
| 313 | var args = "$this.imap_functions.delete_mailbox"; |
---|
| 314 | var params = "del_past="+param; |
---|
| 315 | cExecute(args,handler_return,params); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | } |
---|
| 319 | /* - Build Object -*/ |
---|
| 320 | var ttreeBox; |
---|
[689] | 321 | ttreeBox = new Tree_Box(); |
---|