source: branches/2.2/filemanager/js/common_functions.js @ 3888

Revision 3888, 13.8 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1580 - Mensagem de erro pouco amigável para arquivos grandes

Line 
1
2var Xtools      = null;
3
4function load(path,el)
5{
6        currentPath = path;
7        contentFolders = document.getElementById('content_folders');
8        for (i=0; i < contentFolders.childNodes.length; i++)
9                if (contentFolders.childNodes[i].className == "sl")
10                        contentFolders.childNodes[i].className = "l";
11        el.className = "sl";
12        current_folder = currentPath;
13        if(last_folder != current_folder){
14                lastPage = 1;
15                current_page = 1;
16                last_folder = current_folder;
17                offset = 0;
18        }
19        toolbar.control('reload');
20}
21
22function loadXtools()
23{
24        if( Xtools == null )
25                Xtools = new xtools( path_filemanager + "tp/expressowindow/" );
26}
27
28function check(element)
29{
30        element.firstChild.firstChild.checked = true;
31}
32
33function maxFileSize()
34{
35        if( arguments.length > 0 )
36        {
37                var _document           = arguments[0];
38                var _maxFileSize                = "";
39               
40                for(var i = 0 ;  i < _document.forms[0].elements.length ; i++ )
41                {
42                        if( _document.forms[0].elements[i].type == "text" )
43                        {       
44                                var _name = (_document.forms[0].elements[i].name).toLowerCase();
45                               
46                                if( _name.indexOf('filemanager_max_file_size') > - 1 )
47                                        _maxFileSize = trim(_document.forms[0].elements[i].value);
48                        }
49                }
50               
51                var handlerSubmit = function(data)
52                {
53                        _document.forms[0].submit.click();
54                }
55               
56                if( _maxFileSize != '' )
57                {
58                        cExecute_( './index.php?menuaction=filemanager.uifilemanager.setFileMaxSize', handlerSubmit,'maxFileSize=' + _maxFileSize );
59                }
60                else
61                {
62                        alert('É necessário informar um valor !');
63                        return false;
64                }
65        }
66}
67
68function trim(inputString)
69{
70        if ( typeof inputString != "string" )
71                return inputString;
72
73        var retValue    = inputString;
74        var ch          = retValue.substring(0, 1);
75       
76        while (ch == " ")
77        {
78                retValue = retValue.substring(1, retValue.length);
79                ch = retValue.substring(0, 1);
80        }
81       
82        ch = retValue.substring(retValue.length-1, retValue.length);
83       
84        while (ch == " ")
85        {
86                retValue = retValue.substring(0, retValue.length-1);
87                ch = retValue.substring(retValue.length-1, retValue.length);
88        }
89       
90        while (retValue.indexOf("  ") != -1)
91        {
92                retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
93        }
94       
95        return retValue;
96}
97
98function validateFileExtension(fileName)
99{
100        var error_flag = false;
101        var fileExtension = fileName.split(".");
102        fileExtension = fileExtension[(fileExtension.length-1)];
103        for(var i=0; i<denyFileExtensions.length; i++)
104        {
105                if(denyFileExtensions[i] == fileExtension)
106                {
107                        error_flag = true;
108                        break;
109                }
110
111        }
112
113        if ( error_flag == true )
114        {
115                write_error(get_lang('File extension forbidden or invalid file') + '.');
116                return false;
117        }
118        return true;
119}
120
121function get_lang(_key)
122{
123        var key = _key.toLowerCase();
124        if(array_lang[key])
125                var _value = array_lang[key];
126        else
127                var _value = _key+"*";
128
129        if(arguments.length > 1)
130                for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
131                        _value = _value.replace("%"+j,arguments[j]);
132        return _value;
133
134}
135
136
137function newEmptyFile()
138{
139        var name = prompt(get_lang('Enter with the name of new file/directory'), '');
140        var input_text = document.getElementById('newfile_or_dir');
141        if (name != null && name != '' && validateFileExtension(name))
142        {
143                var fileExtension = name.split(".");
144                fileExtension = fileExtension[1];
145                if (typeof(fileExtension) == 'undefined')
146                        input_text.value = name+".html";
147                else
148                        input_text.value = name;
149                address = document.location.toString();
150                address = address.split("&");
151                document.location = address[0]+"&newfile.x=1&newfile_or_dir="+input_text.value;
152
153        }
154}
155
156function newUpload( )
157{
158        if( document.getElementById("dwindownewUpload__parent") == null )
159        {
160                var _newUpload = function(data)
161                {
162                        loadXtools();
163                       
164                        var pArgs = unserialize(data);
165                                pArgs.lang_click_here   = get_lang("Click here");
166                                pArgs.lang_more_files   = get_lang("More files");
167                                pArgs.lang_send_email   = get_lang("Send email");
168                                pArgs.height                    = 210;
169                                pArgs.path_filemanager  = path_filemanager;
170                                pArgs.width                     = 500;
171               
172                        var _html = Xtools.parse( Xtools.xml("upload_files"), "upload.xsl", pArgs );
173                       
174                        draw_window( _html, 490, 350, get_lang("upload files"), "newUpload" );
175               
176                        if( pArgs.emails_to != null )
177                                sendNotification( pArgs.emails_to );
178                }
179               
180                address = document.location.toString();
181                address = address.split("?");
182                var url = address[0]+"?menuaction=filemanager.uifilemanager.showUploadboxes&path="+base64_encode(currentPath);
183                cExecute_( url, _newUpload );
184        }
185}
186
187function newAdvancedUpload()
188{
189        for ( var i = 0 ; i < navigator.plugins.length; i++ )
190        {
191                if ( navigator.plugins[i].name.match('Java') || navigator.plugins[i].name.match('libnpjp2') )
192                {
193                        _winBuild( "dwindownewUpload" , "remove" );
194
195                        loadXtools();
196                       
197                        var pArgs =
198                        {
199                                'iframe_width'          : 515,
200                                'iframe_height'         : 320,
201                                'iframe_src'            : path_filemanager + "inc/uploadApp.php?id="+parseInt(Math.random()*Math.pow(10,15))
202                        };
203                       
204                        var _html = Xtools.parse( Xtools.xml("upload_files_advanced"), "uploadAdvanced.xsl", pArgs);
205                       
206                        draw_window( _html, 530, 345, get_lang("Advanced Upload") );
207                       
208                        return;
209                }
210        }
211       
212        alert( get_lang("You do not have Java installed, plugin not loaded") + "!" );
213}
214
215
216(function( )
217{
218        // TODO: use DES, RSA, PGP, or something strong
219        var sec_key = null;
220        function encode( data )
221        {
222                if (data == null)
223                        return null;
224                ret = "";
225                for ( var i=0;(i < data.length && data.charCodeAt(i) > 31); i++ )
226                {
227                        ret += String.fromCharCode(data.charCodeAt(i) ^ sec_key.charCodeAt(i));
228                }
229                return ret;
230        }
231
232        function crypt( input )
233        {
234                sec_key = input;
235        }
236
237        crypt.prototype.encode = encode;
238        window.crypt = crypt;
239})( );
240
241/*
242 * base64.js - Base64 encoding and decoding functions
243 *
244 * Copyright (c) 2007, David Lindquist <david.lindquist@gmail.com>
245 * Released under the MIT license
246 */
247
248function base64_encode(str) {
249        var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
250        var encoded = [];
251        var c = 0;
252        try { var slen = str.length; } catch (e) { write_error(get_lang('you do not have access to %1',currentPath)); return; };
253        while (c < slen) {
254                var b0 = str.charCodeAt(c++);
255                var b1 = str.charCodeAt(c++);
256                var b2 = str.charCodeAt(c++);
257                var buf = (b0 << 16) + ((b1 || 0) << 8) + (b2 || 0);
258                var i0 = (buf & (63 << 18)) >> 18;
259                var i1 = (buf & (63 << 12)) >> 12;
260                var i2 = isNaN(b1) ? 64 : (buf & (63 << 6)) >> 6;
261                var i3 = isNaN(b2) ? 64 : (buf & 63);
262                encoded[encoded.length] = chars.charAt(i0);
263                encoded[encoded.length] = chars.charAt(i1);
264                encoded[encoded.length] = chars.charAt(i2);
265                encoded[encoded.length] = chars.charAt(i3);
266        }
267        var retBuff = escape(encoded.join(''));
268        return retBuff.replace(/\+/g,"%2B");
269}
270
271function base64_decode(str) {
272        var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
273        var invalid = {
274        strlen: (str.length % 4 != 0),
275        chars:  new RegExp('[^' + chars + ']').test(str),
276        equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
277        };
278        if (invalid.strlen || invalid.chars || invalid.equals)
279                throw new Error('Invalid base64 data');
280        var decoded = [];
281        var c = 0;
282        while (c < str.length) {
283                var i0 = chars.indexOf(str.charAt(c++));
284                var i1 = chars.indexOf(str.charAt(c++));
285                var i2 = chars.indexOf(str.charAt(c++));
286                var i3 = chars.indexOf(str.charAt(c++));
287                var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
288                var b0 = (buf & (255 << 16)) >> 16;
289                var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
290                var b2 = (i3 == 64) ? -1 : (buf & 255);
291                decoded[decoded.length] = String.fromCharCode(b0);
292                if (b1 >= 0) decoded[decoded.length] = String.fromCharCode(b1);
293                if (b2 >= 0) decoded[decoded.length] = String.fromCharCode(b2);
294        }
295        return decoded.join('');
296}
297
298
299function setRestricted(name)
300{
301        var continue_set = confirm(get_lang('This property will change the visibility of all users that have access to this file, continue?'));
302       
303        if ( continue_set )
304        {
305                cExecute_('./index.php?menuaction=filemanager.vfs_functions.setRestricted&file='
306                                + base64_encode(name)+'&path='+base64_encode(currentPath),handler.restricted);
307        }
308}
309
310function presetComments(el)
311{
312        if (permissions['edit'] == 0){
313                el.blur();
314                write_error(get_lang('You have no permission to access this file'));
315        }
316        oldValue = el.value;
317}
318
319function setComments(el)
320{
321        if ( el.value == oldValue )
322                return;
323       
324        var filename = base64_encode(el.id);
325       
326        cExecute_('./index.php?menuaction=filemanager.vfs_functions.editComment&file='
327                                + filename+'&comment='+base64_encode(el.value), handler.updateComment);
328}
329
330function enterComments(e,el)
331{
332        if ( e.keyCode == KEY_ENTER )
333        {
334                el.blur();
335        }
336}
337
338function EditColumns( args )
339{
340        if( args == 'close' )
341        {
342                _winBuild("window_tools_view","remove");
343        }
344        else if( args == 'save')
345        {
346                var checkBoxes = document.getElementById('menu_col_pref').getElementsByTagName("input");
347
348                for ( var i = 0 ; i < checkBoxes.length; i++)
349                {
350                        if( checkBoxes[i].checked === true )
351                                preferences[checkBoxes[i].value] = '1';
352                        else
353                                preferences[checkBoxes[i].value] = '0';
354                }
355
356                cExecute_('./index.php?menuaction=filemanager.user.save_preferences',function () { toolbar.control('reload'); EditColumns('close'); }, 'preferences='+serialize(preferences));
357        }
358        else
359        {
360                loadXtools();
361               
362                var pTools =
363                {
364                        'checkList'     :       preferences['viewList'],       
365                        'checkIcons':   preferences['viewIcons'],
366                        'check_created'                 : preferences['created'],
367                        'check_createdby_id'    : preferences['createdby_id'],
368                        'check_comment'                 : preferences['comment'],
369                        'check_mime_type'               : preferences['mime_type'],
370                        'check_modified'                : preferences['modified'],
371                        'check_modifiedby_id'   : preferences['modifiedby_id'],
372                        'check_owner'                   : preferences['owner'],
373                        'check_size'                    : preferences['size'],
374                        'check_version'                 : preferences['version'],
375                        'lang_cancel'                   : get_lang('cancel'),
376                        'lang_created_by'               : get_lang('created by'),                       
377                        'lang_created'                  : get_lang('created'),
378                        'lang_comment'                  : get_lang('comment'),
379                        'lang_modified_by'              : get_lang('modified by'),
380                        'lang_modified'                 : get_lang('modified'),
381                        'lang_owner'                    : get_lang('owner'),
382                        'lang_save'                             : get_lang('save'),
383                        'lang_size'                             : get_lang('size'),
384                        'lang_type'                             : get_lang('type'),
385                        'lang_version'                  : get_lang('version'),
386                        'lang_view_as_list'             : get_lang('view as list'),
387                        'lang_view_as_icons'    : get_lang('view as icons'),
388                        'onclickCancel'                 : "EditColumns(\'close\')",
389                        'onclickSave'                   : "EditColumns(\'save\')"
390                }
391               
392                var winTools =
393                {       
394                         id_window              : "window_tools_view",
395                         width                  : 250,
396                         height                 : 290,
397                         top                            : 100,
398                         left                           : 400,
399                         draggable              : true,
400                         visible                        : "display",
401                         resizable              : true,
402                         zindex                 : zIndex++,
403                         title                  : "Expresso FileManager - " + get_lang('View'),
404                         closeAction            : "remove",
405                         content                : Xtools.parse(Xtools.xml("view_config"), "view.xsl", pTools)   
406                };
407       
408                _winBuild( winTools );
409        }
410}
411
412
413function searchFile(){
414        var inputText = document.getElementById('em_message_search');
415        if (inputText.value.length < 4)
416        {
417                alert(get_lang('Your search must have at least 4 characters'));
418                return;
419        }
420        cExecute_('./index.php?menuaction=filemanager.uifilemanager.search&text='+inputText.value,folderList.drawSearch);
421}
422function selectAll(el){
423        checkBoxes = document.getElementsByName('fileman');
424        if (el.checked)
425                for (i=0; i < checkBoxes.length; i++)
426                        checkBoxes[i].checked = true;
427        else
428                for (i=0; i < checkBoxes.length; i++)
429                        checkBoxes[i].checked = false;
430
431}
432
433function borkb(size)
434{
435        var kbyte = 1024;
436        var mbyte = kbyte*1024;
437        var gbyte = mbyte*1024;
438       
439        if (!size)
440        {
441                size = 0;
442        }
443
444        if (size < kbyte)
445        {
446                return size + ' B';
447        }
448        else if (size < mbyte)
449        {
450                return parseInt(size/kbyte) + ' KB';
451        }
452        else if (size < gbyte)
453        {
454                if ( size/mbyte > 100)
455                        return (size/mbyte).toFixed(0) + ' MB';
456                else
457                        return (size/mbyte).toFixed(1) + ' MB';
458        }
459        else
460        {
461                return (size/gbyte).toFixed(1) + ' GB';
462        }
463}
464
465function addNewInput()
466{
467        var newElement = document.createElement('div');
468                newElement.innerHTML  = '<div></div>' +
469                                                                        '<input maxlength="255" name="upload_file[]" type="file" style="margin-right:5px;" />' +
470                                                                        '<input name="upload_comment[]" type="text" style="margin-right:2px;" />' +
471                                                                        '<span style="color:red; cursor:pointer;" onclick="removeInput(this);">'+get_lang('delete')+'</span>';
472       
473        document.getElementById('uploadOption').parentNode.appendChild(newElement);
474}
475
476function removeInput()
477{
478        if( arguments.length > 0 )
479        {
480                var _parent = arguments[0].parentNode;
481               
482                _parent.parentNode.removeChild(_parent);
483        }
484}
485
486function sendNotification()
487{
488        var _div = document.getElementById('sendNotifcation');
489       
490        var _SendNotification = function()
491        {
492                var pArgs =
493                {
494                        'lang_delete'                                           : get_lang('delete'),
495                        'lang_send_notification_email_to'       : get_lang("Send Notification email to:"),
496                        'value_email'                                           : ( ( arguments.length > 0 ) ? arguments[0] : "" )
497                };
498
499                loadXtools();
500               
501                _div.innerHTML += Xtools.parse( Xtools.xml("send_notification"), "send_notification.xsl", pArgs);
502        }
503       
504        if( arguments.length > 0 )
505        {
506                var emailsTo = arguments[0].split(",");
507               
508                _div.innerHTML += "<div style='margin:4 2 2 4px;'>" +
509                                              "<label style='font-weight: bold;'>" + get_lang('The following addresses will be notified') + " : </label>" +
510                                              "</div>";
511                for( var i = 0 ;  i < emailsTo.length ; i++ )
512                {
513                        _SendNotification( emailsTo[i] );
514                        _div.innerHTML += "<div style='margin:1 2 1 4px;'> - " + emailsTo[i] + "</div>";
515                }
516                _div.innerHTML += "<br/>";
517        }
518        else
519                _SendNotification();
520}
521
522function sendFiles()
523{
524        var _formUp                     = document.getElementById('form_up');
525        var _uploadFiles                = document.getElementsByTagName('input');
526        var _flagSend           = true;
527       
528        for( var i = 0 ; i < _uploadFiles.length ; i++ )
529        {
530                if( _uploadFiles[i].name.indexOf("upload_file") > -1 )
531                {
532                        if( _uploadFiles[i].value == "" )
533                        {
534                                removeInput( _uploadFiles[i] );
535                                _flagSend = false;
536                        }
537                }
538        }
539       
540        if( _flagSend )
541                cExecuteForm_( _formUp , handler.upload );
542        else
543                write_msg(get_lang("No file(s) to send") + "!");
544}
Note: See TracBrowser for help on using the repository browser.