Skip to content

Commit 55eb1ec

Browse files
committed
File Manager stuff
1 parent cad1405 commit 55eb1ec

File tree

5 files changed

+131
-12
lines changed

5 files changed

+131
-12
lines changed

bin/v-get-fs-file-type

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# info: get file type
3+
# options: USER FILE
4+
#
5+
# The function shows file type
6+
7+
user=$1
8+
path=$2
9+
10+
# Checking arguments
11+
if [ -z "$path" ]; then
12+
echo "Usage: USER FILE"
13+
exit 1
14+
fi
15+
16+
# Checking vesta user
17+
if [ ! -e "$VESTA/data/users/$user" ]; then
18+
echo "Error: vesta user $user doesn't exist"
19+
exit 3
20+
fi
21+
22+
# Checking user homedir
23+
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
24+
if [ -z $homedir ]; then
25+
echo "Error: user home directory doesn't exist"
26+
exit 12
27+
fi
28+
29+
# Checking path
30+
rpath=$(readlink -f "$path")
31+
if [ -z "$(echo $rpath |grep $homedir)" ]; then
32+
echo "Error: invalid path $path"
33+
exit 2
34+
fi
35+
36+
# Listing file type
37+
sudo -u $user file -i -b $path 2>/dev/null
38+
39+
# Exiting
40+
exit $?

web/file_manager/fm_api.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
$dir = $_REQUEST['dir'];
3232
print json_encode($fm->ls($dir));
3333
break;
34+
case 'check_file_type':
35+
$dir = $_REQUEST['dir'];
36+
37+
print json_encode($fm->checkFileType($dir));
38+
break;
3439
case 'rename_file':
3540
$dir = $_REQUEST['dir'];
3641
$item = $_REQUEST['item'];

web/file_manager/fm_core.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ public function __construct($user) {
4242
);
4343
}*/
4444

45+
public function checkFileType($dir) {
46+
$dir = $this->formatFullPath($dir);
47+
48+
exec(VESTA_CMD . "v-delete-fs-file {$this->user} {$dir}", $output, $return_var);
49+
50+
$error = self::check_return_code($return_var, $output);
51+
52+
if (empty($error)) {
53+
return array(
54+
'result' => true
55+
);
56+
}
57+
else {
58+
return array(
59+
'result' => false,
60+
'message' => $error
61+
);
62+
}
63+
}
64+
4565
public function formatFullPath($path_part = '') {
4666
if (substr($path_part, 0, strlen($this->ROOT_DIR)) === $this->ROOT_DIR) {
4767
$path = $path_part;

web/js/file_manager.js

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,26 @@ FM.setSecondInactive = function(index, box) {
164164
FM.BG_TAB = box;
165165
}
166166

167+
FM.goToTop = function() {
168+
var tab = FM.getTabLetter(FM.CURRENT_TAB);
169+
var index = 0;
170+
171+
FM.setActive(index, FM.CURRENT_TAB);
172+
}
173+
174+
FM.goToBottom = function() {
175+
var tab = FM.getTabLetter(FM.CURRENT_TAB);
176+
var index = $(FM.CURRENT_TAB).find('.dir').length - 1;
177+
178+
FM.setActive(index, FM.CURRENT_TAB);
179+
}
180+
167181
FM.goUp = function() {
168182
var tab = FM.getTabLetter(FM.CURRENT_TAB);
169183
var index = FM['CURRENT_' + tab + '_LINE'];
170184
index -= 1;
171185
if (index < 0) {
172-
index = $(FM.CURRENT_TAB).find('li').length - 1;
186+
index = $(FM.CURRENT_TAB).find('li.dir').length - 1;
173187
}
174188

175189
FM.setActive(index, FM.CURRENT_TAB);
@@ -179,7 +193,7 @@ FM.goDown = function() {
179193
var tab = FM.getTabLetter(FM.CURRENT_TAB);
180194
var index = FM['CURRENT_' + tab + '_LINE'];
181195
index += 1;
182-
if (index > ($(FM.CURRENT_TAB).find('li').length - 1)) {
196+
if (index > ($(FM.CURRENT_TAB).find('li.dir').length - 1)) {
183197
index = 0;
184198
}
185199

@@ -196,6 +210,7 @@ FM.open = function(dir, box, callback) {
196210
'dir': dir
197211
};
198212
App.Ajax.request('cd', params, function(reply) {
213+
var tab = FM.getTabLetter(FM.CURRENT_TAB);
199214
FM.preselectedItems[tab] = [];
200215
if (reply.result == true) {
201216
var html = FM.generate_listing(reply.listing, box);
@@ -216,6 +231,9 @@ FM.open = function(dir, box, callback) {
216231
var url = '/list/directory/?dir_a='+path_a+'&dir_b='+path_b;
217232
history.pushState({}, null, url);
218233

234+
if (FM['CURRENT_' + tab + '_LINE'] == -1) {
235+
FM.setActive(0, FM.CURRENT_TAB);
236+
}
219237
});
220238
}
221239

@@ -401,7 +419,7 @@ FM.openFile = function(dir, box, elm) {
401419

402420
var elm = $(elm).hasClass('dir') ? $(elm) : $(elm).closest('.dir');
403421
var src = $.parseJSON($(elm).find('.source').val());
404-
console.log(elm);
422+
405423
if (FM.isItemPseudo(src)) {
406424
FM.open(FM['TAB_' + tab + '_CURRENT_PATH'], FM['TAB_' + tab]);
407425
}
@@ -552,7 +570,7 @@ FM.fotoramaOpen = function(tab, img_index) {
552570
});
553571

554572
$('.fotorama').on('fotorama:fullscreenexit', function (e, fotorama) {
555-
$('.fotorama').data('fotorama').destroy();
573+
$('.fotorama').data('fotorama').destroy();
556574
});
557575

558576
$('.fotorama').fotorama().data('fotorama').requestFullScreen();
@@ -587,7 +605,7 @@ FM.checkBulkStatus = function(bulkStatuses, acc) {
587605
}
588606

589607
if (status == true) {
590-
$('#popup .results').html(msg);
608+
$('#popup .results').html('Done');
591609
$('.controls p').replaceWith('<p class="ok" onClick="FM.bulkPopupClose();">close</p>');
592610
}
593611
else {
@@ -637,7 +655,7 @@ FM.bulkCopy = function() {
637655
var cfr_html = '';
638656

639657
$.each(acc, function(i, o) {
640-
var ref = $(o).parents('.dir');
658+
var ref = $(o);
641659
var src = $(ref).find('.source').val();
642660
src = $.parseJSON(src);
643661

@@ -654,7 +672,7 @@ FM.bulkCopy = function() {
654672

655673
var bulkStatuses = [];
656674
$.each(acc, function(i, o) {
657-
var ref = $(o).parents('.dir');
675+
var ref = $(o);
658676
var src = $(ref).find('.source').val();
659677
src = $.parseJSON(src);
660678

@@ -712,7 +730,7 @@ FM.bulkRemove = function() {
712730
var cfr_html = '';
713731

714732
$.each(acc, function(i, o) {
715-
var ref = $(o).parents('.dir');
733+
var ref = $(o);
716734
var src = $(ref).find('.source').val();
717735
src = $.parseJSON(src);
718736

@@ -729,7 +747,7 @@ FM.bulkRemove = function() {
729747

730748
var bulkStatuses = [];
731749
$.each(acc, function(i, o) {
732-
var ref = $(o).parents('.dir');
750+
var ref = $(o);
733751
var src = $(ref).find('.source').val();
734752
src = $.parseJSON(src);
735753

@@ -784,6 +802,10 @@ FM.toggleAllItemsSelected = function() {
784802
$(box).find('.dir').removeClass('selected');
785803
var index = FM['CURRENT_' + tab + '_LINE'];
786804
$(box).find('.dir:eq(' + index + ')').addClass('selected');
805+
806+
$(FM.preselectedItems[tab]).each(function(i, index) {
807+
$(box).find('.dir:eq(' + index + ')').addClass('selected');
808+
});
787809
}
788810
else {
789811
$(box).find('.dir').addClass('selected');
@@ -1010,6 +1032,10 @@ FM.setTabActive = function(box, action) {
10101032
if (FM.CURRENT_TAB == FM.TAB_A) {
10111033
$(FM.TAB_B).find('.selected').addClass('selected-inactive').removeClass('selected');
10121034
$(FM.TAB_A).find('.selected-inactive').addClass('selected').removeClass('selected-inactive');
1035+
1036+
if ($(FM.TAB_A).find('.selected-inactive').length == 0 && $(FM.TAB_A).find('.selected').length == 0) {
1037+
1038+
}
10131039
}
10141040
else {
10151041
$(FM.TAB_A).find('.selected').addClass('selected-inactive').removeClass('selected');
@@ -1277,7 +1303,7 @@ FM.confirmCopyItems = function () {
12771303
App.Ajax.request(action, params, function(reply) {
12781304
if (reply.result == true) {
12791305
FM.popupClose();
1280-
FM.open(FM['TAB_' + tab + '_CURRENT_PATH'], FM['TAB_' + tab]);
1306+
// FM.open(FM['TAB_' + tab + '_CURRENT_PATH'], FM['TAB_' + tab]);
12811307
FM.open(FM['TAB_' + opposite_tab + '_CURRENT_PATH'], FM['TAB_' + opposite_tab]);
12821308
}
12831309
else {
@@ -1638,6 +1664,11 @@ $(document).ready(function() {
16381664

16391665
shortcut.add("Left",function() {
16401666
FM.setTabActive(FM.TAB_A);
1667+
1668+
var tab = FM.getTabLetter(FM.CURRENT_TAB);
1669+
if (FM['CURRENT_' + tab + '_LINE'] == -1) {
1670+
FM.setActive(0, FM.CURRENT_TAB);
1671+
}
16411672
},{
16421673
'type': 'keydown',
16431674
'propagate': false,
@@ -1647,6 +1678,29 @@ $(document).ready(function() {
16471678

16481679
shortcut.add("Right",function() {
16491680
FM.setTabActive(FM.TAB_B);
1681+
1682+
var tab = FM.getTabLetter(FM.CURRENT_TAB);
1683+
if (FM['CURRENT_' + tab + '_LINE'] == -1) {
1684+
FM.setActive(0, FM.CURRENT_TAB);
1685+
}
1686+
},{
1687+
'type': 'keydown',
1688+
'propagate': false,
1689+
'disable_in_input': false,
1690+
'target': document
1691+
});
1692+
1693+
shortcut.add("Home",function() {
1694+
FM.goToTop();
1695+
},{
1696+
'type': 'keydown',
1697+
'propagate': false,
1698+
'disable_in_input': false,
1699+
'target': document
1700+
});
1701+
1702+
shortcut.add("End",function() {
1703+
FM.goToBottom();
16501704
},{
16511705
'type': 'keydown',
16521706
'propagate': false,

web/js/templates.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ App.Templates.html = {
2424
<span class="size-value">~!:SIZE_VALUE~!</span>\
2525
<span class="date">~!:DATE~!</span>\
2626
<span class="time">~!:TIME~!</span>\
27-
<span class="subcontext-control ~!:SUBMENU_CLASS~!" onClick="FM.toggleSubContextMenu(this)">&#8226;&#8226;&#8226;&nbsp;\
27+
<!-- span class="subcontext-control ~!:SUBMENU_CLASS~!" onClick="FM.toggleSubContextMenu(this)">&#8226;&#8226;&#8226;&nbsp;\
2828
<ul class="subcontext-menu subcontext-menu-hidden"><li onClick="FM.downloadFileFromSubcontext(this);">Download</li><li onClick="FM.editFileFromSubcontext(this);">Edit</li></ul>\
29-
</span>\
29+
</span -->\
3030
</li>'],
3131
popup_alert: ['<div class="confirm-box alarm popup-box">\
3232
<div class="message">~!:TEXT~!</div>\

0 commit comments

Comments
 (0)