source: trunk/expressoMail1_2/js/jscode/TreeShow.js @ 2752

Revision 2752, 8.9 KB checked in by amuller, 14 years ago (diff)

Ticket #911 - unificação do cache do connector

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