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

Revision 2805, 9.0 KB checked in by amuller, 14 years ago (diff)

Ticket #1078 - corrigindo o problema trocando o caracter delimitador por outro

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 delimExp = new RegExp(cyrus_delimiter,"g");
153                newp = newp.replace(delimExp,'_');
154                var newp2 = "";
155                if( aux[0] == "root"){
156                        if(this.verify(newp)){
157                                alert(get_lang("The folder name must not contain special characters."));
158                                newp = "";
159                                return false;
160                        }else{
161                                newp2 = newp;
162                                newp = "INBOX" + cyrus_delimiter + newp;
163                        }
164                }else{
165                        if(this.verify(newp)){
166                                alert(get_lang("The folder name must not contain special characters."));
167                                newp = "";
168                                return false;
169                        }else{
170                                newp2 = newp;
171                                newp = ttree.FOLDER + cyrus_delimiter + newp;
172                        }
173                }
174
175                if(newp != ""){
176                        var handler_return = function(data){           
177                                if(data != "Ok"){
178                                        alert(get_lang(data));
179                                }else{
180                                        ttreeBox.name_folder = "root"; //or use var newpast
181                                        this.name_func = "newpast";
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.