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

Revision 2519, 8.9 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Permitindo que o ExpressoMail? não realize reload de página.

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