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