source: sandbox/filemanager/js/common_functions.js @ 1889

Revision 1889, 9.1 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Melhoria do FM. melhorias na interface, melhoria na cópia, ao mover e etc...

Line 
1function load(path,el){
2        currentPath = path;
3        contentFolders = document.getElementById('content_folders');
4        for (i=0; i < contentFolders.childNodes.length; i++)
5                if (contentFolders.childNodes[i].className == "sl")
6                        contentFolders.childNodes[i].className = "l";
7        el.className = "sl";
8        toolbar.control('reload');
9}
10
11function validateFileExtension(fileName){
12        var error_flag = false;
13        var fileExtension = fileName.split(".");
14        fileExtension = fileExtension[(fileExtension.length-1)];
15        for(var i=0; i<denyFileExtensions.length; i++)
16        {
17                if(denyFileExtensions[i] == fileExtension)
18                {
19                        error_flag = true;
20                        break;
21                }
22
23        }
24
25        if ( error_flag == true )
26        {
27                write_error(get_lang('File extension forbidden or invalid file') + '.');
28                return false;
29        }
30        return true;
31}
32
33function get_lang(_key){
34        var key = _key.toLowerCase();
35        if(array_lang[key])
36                var _value = array_lang[key];
37        else
38                var _value = _key+"*";
39
40        if(arguments.length > 1)
41                for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
42                        _value = _value.replace("%"+j,arguments[j]);
43        return _value;
44
45}
46
47
48function newEmptyFile(){
49        var name = prompt(get_lang('Enter with the name of new file/directory'), '');
50        var input_text = document.getElementById('newfile_or_dir');
51        if (name != null && name != '' && validateFileExtension(name))
52        {
53                var fileExtension = name.split(".");
54                fileExtension = fileExtension[1];
55                if (typeof(fileExtension) == 'undefined')
56                        input_text.value = name+".html";
57                else
58                        input_text.value = name;
59                address = document.location.toString();
60                address = address.split("&");
61                document.location = address[0]+"&newfile.x=1&newfile_or_dir="+input_text.value;
62
63        }
64}
65function newUpload(data){
66        if (data == null)
67        {
68                address = document.location.toString();
69                address = address.split("?");
70                var url = address[0]+"?menuaction=filemanager.uifilemanager.showUploadboxes&path="+base64_encode(currentPath);
71                cExecute(url,newUpload);
72        }
73        else{
74                draw_window(data);
75        }
76}
77
78(function( )
79{
80        // TODO: use DES, RSA, PGP, or something strong
81        var sec_key = null;
82        function encode( data )
83        {
84                if (data == null)
85                        return null;
86                ret = "";
87                for ( var i=0;(i < data.length && data.charCodeAt(i) > 31); i++ )
88                {
89                        ret += String.fromCharCode(data.charCodeAt(i) ^ sec_key.charCodeAt(i));
90                }
91                return ret;
92        }
93
94        function crypt( input )
95        {
96                sec_key = input;
97        }
98
99        crypt.prototype.encode = encode;
100        window.crypt = crypt;
101})( );
102
103/*
104 * base64.js - Base64 encoding and decoding functions
105 *
106 * Copyright (c) 2007, David Lindquist <david.lindquist@gmail.com>
107 * Released under the MIT license
108 */
109
110function base64_encode(str) {
111        var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
112        var encoded = [];
113        var c = 0;
114        while (c < str.length) {
115                var b0 = str.charCodeAt(c++);
116                var b1 = str.charCodeAt(c++);
117                var b2 = str.charCodeAt(c++);
118                var buf = (b0 << 16) + ((b1 || 0) << 8) + (b2 || 0);
119                var i0 = (buf & (63 << 18)) >> 18;
120                var i1 = (buf & (63 << 12)) >> 12;
121                var i2 = isNaN(b1) ? 64 : (buf & (63 << 6)) >> 6;
122                var i3 = isNaN(b2) ? 64 : (buf & 63);
123                encoded[encoded.length] = chars.charAt(i0);
124                encoded[encoded.length] = chars.charAt(i1);
125                encoded[encoded.length] = chars.charAt(i2);
126                encoded[encoded.length] = chars.charAt(i3);
127        }
128        return encoded.join('');
129}
130
131function base64_decode(str) {
132        var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/=';
133        var invalid = {
134        strlen: (str.length % 4 != 0),
135        chars:  new RegExp('[^' + chars + ']').test(str),
136        equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
137        };
138        if (invalid.strlen || invalid.chars || invalid.equals)
139                throw new Error('Invalid base64 data');
140        var decoded = [];
141        var c = 0;
142        while (c < str.length) {
143                var i0 = chars.indexOf(str.charAt(c++));
144                var i1 = chars.indexOf(str.charAt(c++));
145                var i2 = chars.indexOf(str.charAt(c++));
146                var i3 = chars.indexOf(str.charAt(c++));
147                var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
148                var b0 = (buf & (255 << 16)) >> 16;
149                var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
150                var b2 = (i3 == 64) ? -1 : (buf & 255);
151                decoded[decoded.length] = String.fromCharCode(b0);
152                if (b1 >= 0) decoded[decoded.length] = String.fromCharCode(b1);
153                if (b2 >= 0) decoded[decoded.length] = String.fromCharCode(b2);
154        }
155        return decoded.join('');
156}
157
158
159function setRestricted(name){
160        var continue_set = confirm(get_lang('This property will change the visibility of all users that have access to this file, continue?'));
161        if (continue_set)
162                cExecute('./index.php?menuaction=filemanager.vfs_functions.setRestricted&file='+base64_encode(name)+'&path='+base64_encode(currentPath),handler.restricted);
163}
164
165function presetComments(el){
166        if (permissions['edit'] == 0){
167                el.blur();
168                write_error(get_lang('You have no permission to access this file'));
169        }
170        oldValue = el.value;
171}
172
173function setComments(el){
174        if (el.value == oldValue) return;
175        var filename = base64_encode(el.id);
176        cExecute('./index.php?menuaction=filemanager.vfs_functions.editComment&file='+filename+'&comment='+base64_encode(el.value),handler.updateComment);
177}
178
179function enterComments(e,el){
180        if (e.keyCode == KEY_ENTER)
181                el.blur();
182}
183
184
185function EditColumns(param){
186        if (param == 'close')
187        {
188                var menu = document.getElementById('menu_col_pref');
189                menu.parentNode.removeChild(menu);
190                return;
191        }
192        if(param == 'save')
193        {
194                var checkBoxes = document.getElementsByName('prefView');
195                var url="";
196                for (var i=0; i < checkBoxes.length; i++)
197                {
198                        if (checkBoxes[i].checked)
199                                preferences[checkBoxes[i].value] = '1';
200                        else
201                                preferences[checkBoxes[i].value] = '0';
202                }
203                cExecute('./index.php?menuaction=filemanager.user.save_preferences&preferences='+base64_encode(serialize(preferences)),function () { toolbar.control('reload'); EditColumns('close'); });
204                return;
205        }
206        var check = function(type) { if (preferences[type] =='1') return 'checked'; else return '';};
207        var inputHTML = '<input name="prefView" type="checkbox" value="';
208        form = inputHTML+'mime_type" '+check('mime_type')+'>'+get_lang('type')+'<br>'+
209                inputHTML+'size" '+check('size')+'>'+get_lang('size')+'<br>'+
210                inputHTML+'created" '+check('created')+'>'+get_lang('created')+'<br>'+
211                inputHTML+'modified" '+check('modified')+'>'+get_lang('modified')+'<br>'+
212                inputHTML+'owner" '+check('owner')+'>'+get_lang('owner')+'<br>'+
213                inputHTML+'createdby_id" '+check('createdby_id')+'>'+get_lang('created by')+'<br>'+
214                inputHTML+'modifiedby_id" '+check('modifiedby_id')+'>'+get_lang('modified by')+'<br>'+
215        //      inputHTML+'application" '+check('application')+'>'+get_lang('application')+'<br>'+
216                inputHTML+'comment" '+check('comment')+'>'+get_lang('comment')+'<br>'+
217                inputHTML+'version" '+check('version')+'>'+get_lang('version')+'<br>'+
218                '<input value="'+get_lang('save')+'" onclick="EditColumns(\'save\')" type="button">&nbsp;'+
219                '<input value="'+get_lang('cancel')+'" onclick="EditColumns(\'close\')" type="button">';
220
221                menu = document.createElement('DIV');
222                menu.id = "menu_col_pref";
223                menu.style.left = "100px";
224                menu.style.top = "200px";
225                menu.className = 'menubox';
226                menu.style.zIndex='1';
227                menu.innerHTML = form;
228                document.getElementById('divAppboxHeader').appendChild(menu);
229}
230
231
232function searchFile(){
233        var inputText = document.getElementById('em_message_search');
234        if (inputText.value.length < 4)
235        {
236                alert(get_lang('Your search must have at least 4 characters'));
237                return;
238        }
239        cExecute('./index.php?menuaction=filemanager.uifilemanager.search&text='+inputText.value,folderList.drawSearch);
240}
241function selectAll(el){
242        checkBoxes = document.getElementsByName('fileman');
243        if (el.checked)
244                for (i=0; i < checkBoxes.length; i++)
245                        checkBoxes[i].checked = true;
246        else
247                for (i=0; i < checkBoxes.length; i++)
248                        checkBoxes[i].checked = false;
249
250}
251function borkb(size){
252                kbyte = 1024;
253                mbyte = kbyte*1024;
254                gbyte = mbyte*1024;
255                if (!size)
256                        size = 0;
257                if (size < kbyte)
258                        return size + 'B';
259                else if (size < mbyte)
260                        return parseInt(size/kbyte) + 'KB';
261                else if (size < gbyte)
262                        if (size/mbyte > 100)
263                                return (size/mbyte).toFixed(0) + 'MB';
264                        else
265                                return (size/mbyte).toFixed(1) + 'MB';
266                else
267                        return parseInt(size/gbyte).toFixed(1) + 'GB';
268}
269function addNewInput(){
270        var line = document.getElementById('uploadOption');
271        var newElement = document.createElement('TR');
272        var newElement2 = document.createElement('TD');
273        var newElement3 = document.createElement('TD');
274        newElement2.innerHTML = '<input onchange="javascript:addNewInput();" maxlength="255" name="upload_file[]" type="file">';
275        newElement3.innerHTML = '<input name="upload_comment[]" type="text">';
276        newElement.appendChild(newElement2);
277        newElement.appendChild(newElement3);
278        line.parentNode.appendChild(newElement);
279        document.getElementById('show_upload_boxes').value +=1;
280}
281
282function sendFiles(){
283                cExecuteForm(document.getElementById('form_up'),handler.upload);
284                document.getElementById('button_up').style.visibility = "hidden";
285                var line = document.getElementById('uploadOption');
286                line.parentNode.innerHTML = "<img src='"+templatePath+"images/progress.gif'>";
287}
Note: See TracBrowser for help on using the repository browser.