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

Revision 197, 8.0 KB checked in by niltonneto, 16 years ago (diff)

Ticket #147: Revisão da internacionalização
Ticket #152: Melhoria no Fora de Escritório
Implementação da funcao write_msg com a opção de não apagar aviso.
Implementação da funcao clean_msg para limpar aviso.

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