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

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

Ticket #597 - Melhoria do FM. melhorias na interface, criação de pastas

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        var sec_key = null;
81        function encode( data )
82        {
83                if (data == null)
84                        return null;
85                ret = "";
86                for ( var i=0;i < data.length; i++ )
87                {
88                        ret += String.fromCharCode(data.charCodeAt(i) ^ sec_key.charCodeAt(i));
89                }
90                return ret;
91        }
92
93        function crypt( input )
94        {
95                sec_key = input;
96        }
97
98        crypt.prototype.encode = encode;
99        window.crypt = crypt;
100})( );
101
102/*
103 * base64.js - Base64 encoding and decoding functions
104 *
105 * Copyright (c) 2007, David Lindquist <david.lindquist@gmail.com>
106 * Released under the MIT license
107 */
108
109function base64_encode(str) {
110        var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
111        var encoded = [];
112        var c = 0;
113        while (c < str.length) {
114                var b0 = str.charCodeAt(c++);
115                var b1 = str.charCodeAt(c++);
116                var b2 = str.charCodeAt(c++);
117                var buf = (b0 << 16) + ((b1 || 0) << 8) + (b2 || 0);
118                var i0 = (buf & (63 << 18)) >> 18;
119                var i1 = (buf & (63 << 12)) >> 12;
120                var i2 = isNaN(b1) ? 64 : (buf & (63 << 6)) >> 6;
121                var i3 = isNaN(b2) ? 64 : (buf & 63);
122                encoded[encoded.length] = chars.charAt(i0);
123                encoded[encoded.length] = chars.charAt(i1);
124                encoded[encoded.length] = chars.charAt(i2);
125                encoded[encoded.length] = chars.charAt(i3);
126        }
127        return encoded.join('');
128}
129
130function base64_decode(str) {
131        var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
132        var invalid = {
133        strlen: (str.length % 4 != 0),
134        chars:  new RegExp('[^' + chars + ']').test(str),
135        equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
136        };
137        if (invalid.strlen || invalid.chars || invalid.equals)
138                throw new Error('Invalid base64 data');
139        var decoded = [];
140        var c = 0;
141        while (c < str.length) {
142                var i0 = chars.indexOf(str.charAt(c++));
143                var i1 = chars.indexOf(str.charAt(c++));
144                var i2 = chars.indexOf(str.charAt(c++));
145                var i3 = chars.indexOf(str.charAt(c++));
146                var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
147                var b0 = (buf & (255 << 16)) >> 16;
148                var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
149                var b2 = (i3 == 64) ? -1 : (buf & 255);
150                decoded[decoded.length] = String.fromCharCode(b0);
151                if (b1 >= 0) decoded[decoded.length] = String.fromCharCode(b1);
152                if (b2 >= 0) decoded[decoded.length] = String.fromCharCode(b2);
153        }
154        return decoded.join('');
155}
156
157
158function setRestricted(name){
159        var continue_set = confirm(get_lang('This property will change the visibility of all users that have access to this file, continue?'));
160        if (continue_set)
161                cExecute('./index.php?menuaction=filemanager.vfs_functions.setRestricted&file='+base64_encode(name)+'&path='+base64_encode(currentPath),handler.restricted);
162}
163
164function presetComments(el){
165        if (permissions['edit'] == 0){
166                el.blur();
167                write_error(get_lang('You have no permission to access this file'));
168        }
169        oldValue = el.value;
170}
171
172function setComments(el){
173        if (el.value == oldValue) return;
174        var filename = base64_encode(el.id);
175        cExecute('./index.php?menuaction=filemanager.vfs_functions.editComment&file='+filename+'&comment='+base64_encode(el.value),handler.updateComment);
176}
177
178function enterComments(e,el){
179        if (e.keyCode == KEY_ENTER)
180                el.blur();
181}
182
183
184function EditColumns(param){
185        if (param == 'close')
186        {
187                var menu = document.getElementById('menu_col_pref');
188                menu.parentNode.removeChild(menu);
189                return;
190        }
191        if(param == 'save')
192        {
193                var checkBoxes = document.getElementsByName('prefView');
194                var url="";
195                for (var i=0; i < checkBoxes.length; i++)
196                {
197                        if (checkBoxes[i].checked)
198                                preferences[checkBoxes[i].value] = '1';
199                        else
200                                preferences[checkBoxes[i].value] = '0';
201                }
202                cExecute('./index.php?menuaction=filemanager.user.save_preferences&preferences='+base64_encode(serialize(preferences)),function () { toolbar.control('reload'); EditColumns('close'); });
203                return;
204        }
205        var check = function(type) { if (preferences[type] =='1') return 'checked'; else return '';};
206        var inputHTML = '<input name="prefView" type="checkbox" value="';
207        form = inputHTML+'mime_type" '+check('mime_type')+'>'+get_lang('type')+'<br>'+
208                inputHTML+'size" '+check('size')+'>'+get_lang('size')+'<br>'+
209                inputHTML+'created" '+check('created')+'>'+get_lang('created')+'<br>'+
210                inputHTML+'modified" '+check('modified')+'>'+get_lang('modified')+'<br>'+
211                inputHTML+'owner" '+check('owner')+'>'+get_lang('owner')+'<br>'+
212                inputHTML+'createdby_id" '+check('createdby_id')+'>'+get_lang('created by')+'<br>'+
213                inputHTML+'modifiedby_id" '+check('modifiedby_id')+'>'+get_lang('modified by')+'<br>'+
214        //      inputHTML+'application" '+check('application')+'>'+get_lang('application')+'<br>'+
215                inputHTML+'comment" '+check('comment')+'>'+get_lang('comment')+'<br>'+
216                inputHTML+'version" '+check('version')+'>'+get_lang('version')+'<br>'+
217                '<input value="'+get_lang('save')+'" onclick="EditColumns(\'save\')" type="button">&nbsp;'+
218                '<input value="'+get_lang('cancel')+'" onclick="EditColumns(\'close\')" type="button">';
219
220                menu = document.createElement('DIV');
221                menu.id = "menu_col_pref";
222                menu.style.left = "100px";
223                menu.style.top = "200px";
224                menu.className = 'menubox';
225                menu.style.zIndex='1';
226                menu.innerHTML = form;
227                document.getElementById('divAppboxHeader').appendChild(menu);
228}
229
230
231function searchFile(){
232        var inputText = document.getElementById('em_message_search');
233        if (inputText.value.length < 4)
234        {
235                alert(get_lang('Your search must have at least 4 characters'));
236                return;
237        }
238        cExecute('./index.php?menuaction=filemanager.uifilemanager.search&text='+inputText.value,folderList.drawSearch);
239}
240function selectAll(el){
241        checkBoxes = document.getElementsByName('fileman');
242        if (el.checked)
243                for (i=0; i < checkBoxes.length; i++)
244                        checkBoxes[i].checked = true;
245        else
246                for (i=0; i < checkBoxes.length; i++)
247                        checkBoxes[i].checked = false;
248
249}
250function borkb(size){
251                kbyte = 1024;
252                mbyte = kbyte*1024;
253                gbyte = mbyte*1024;
254                if (!size)
255                        size = 0;
256                if (size < kbyte)
257                        return size + 'B';
258                else if (size < mbyte)
259                        return parseInt(size/kbyte) + 'KB';
260                else if (size < gbyte)
261                        if (size/mbyte > 100)
262                                return (size/mbyte).toFixed(0) + 'MB';
263                        else
264                                return (size/mbyte).toFixed(1) + 'MB';
265                else
266                        return parseInt(size/gbyte).toFixed(1) + 'GB';
267}
268function addNewInput(){
269        var line = document.getElementById('uploadOption');
270        var newElement = document.createElement('TR');
271        var newElement2 = document.createElement('TD');
272        var newElement3 = document.createElement('TD');
273        newElement2.innerHTML = '<input onchange="javascript:addNewInput();" maxlength="255" name="upload_file[]" type="file">';
274        newElement3.innerHTML = '<input name="upload_comment[]" type="text">';
275        newElement.appendChild(newElement2);
276        newElement.appendChild(newElement3);
277        line.parentNode.appendChild(newElement);
278        document.getElementById('show_upload_boxes').value +=1;
279}
280
281function sendFiles(){
282                cExecuteForm(document.getElementById('form_up'),handler.upload);
283                document.getElementById('button_up').style.visibility = "hidden";
284                var line = document.getElementById('uploadOption');
285                line.parentNode.innerHTML = "<img src='"+templatePath+"images/progress.gif'>";
286}
Note: See TracBrowser for help on using the repository browser.