source: trunk/expressoMail1_2/js/TreeShow.js @ 1386

Revision 1386, 8.6 KB checked in by amuller, 15 years ago (diff)

Ticket #620 - corrigindo problema de pegar current_folder na criação

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