forked from phpvirtualbox/phpvirtualbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsSharedFolders.html
376 lines (294 loc) · 16.3 KB
/
settingsSharedFolders.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<!--
Shared Folders
Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
$Id: settingsSharedFolders.html 595 2015-04-17 09:50:36Z imoore76 $
-->
<table style='width: 100%' id='vboxSettingsSharedFoldersTable'>
<tr style='vertical-align: middle'>
<td style='width: 100%'>
<table class='vboxSettingsHeadingLine' style='width:100%;border-spacing:0;border:0px;margin:0px;padding:0px;'><tr style='vertical-align:middle'><td style='white-space: nowrap; width: auto;'><span class='translate'>Folders List</span></td><td style='width: 100%'><hr style='width: 100%;' class='vboxSeparatorLine'/></td></tr></table>
</td>
</tr>
<tr>
<td style='width: 100%'>
<table style='width: 100%'>
<tr>
<td style='width: 100%'>
<div style='overflow: auto;' class='vboxBordered' id='vboxSettingsSharedFolders'>
<table class='vboxHorizontal' id='vboxSettingsSharedFoldersList'>
<thead>
<tr id='vboxSettingsSharedFoldersHeading'>
<th><span class='translate'>Name</span></th>
<th style='width: 100%; white-space: nowrap;'><span class='translate'>Path</span></th>
<th><span class='translate'>Access</span></th>
<th><span class='translate'>Auto Mount</span></th>
<th><span class='translate'>At</span></th>
</tr>
</thead>
</table>
</div>
</td>
<td id='vboxSettingsSFButtons'></td>
</tr>
</table>
</td>
</tr>
</table>
<script type='text/javascript'>
/*
* Init Shared Folder buttons and toolbar
*/
var sButtons = new Array(
{
'name': 'addshared',
'label': 'Add Shared Folder',
'icon': 'sf_add',
'enabled': function (item) { return true; },
'click': function () {
var dialog = vboxSettingsSFEditDialog();
$('#vboxSettingsSFPath').val('');
$('#vboxSettingsSFName').val('');
$('#vboxSettingsSFAM').prop('checked',false);
$('#vboxSettingsSFAMPoint').val('');
$('#vboxSettingsSFRO').prop('checked',false);
$('#vboxSettingsSFPerm').prop('checked',false);
var buttons = { };
buttons[trans('OK','QIMessageBox')] = function() {
if($('#vboxSettingsSFName').val() && $('#vboxSettingsSFPath').val()) {
var f = {'name':$('#vboxSettingsSFName').val(),'hostPath':$('#vboxSettingsSFPath').val(),'autoMountPoint':$('#vboxSettingsSFAMPoint').val(),'autoMount':($('#vboxSettingsSFAM').prop('checked')),'writable':!($('#vboxSettingsSFRO').prop('checked'))};
if($('#vboxSettingsSFPerm').length) {
f['type'] = ($('#vboxSettingsSFPerm').prop('checked') ? 'machine' : '');
} else {
f['type'] = 'machine';
}
var row = vboxSettingsAddSharedFolder(f);
$(row).children('td').last().trigger('click');
}
$(dialog).empty().remove();
};
buttons[trans('Cancel','QIMessageBox')] = function() { $(dialog).empty().remove(); };
$(dialog).dialog({'buttons':buttons,'title':'<img src="images/vbox/sf_16px.png" class="vboxDialogTitleIcon" /> '+trans('Add Share','UIMachineSettingsSFDetails')}).dialog('open');
}
},
{
'name': 'editshared',
'label': 'Edit Shared Folder',
'icon': 'sf_edit',
'enabled': function (item) { return $(item).hasClass('vboxListItemSelected'); },
'click': function () {
var dialog = vboxSettingsSFEditDialog();
var def = $('#vboxSettingsSharedFoldersList').find('tr.vboxListItemSelected').first();
$('#vboxSettingsSFPath').val(($(def).data('hostPath')||''));
$('#vboxSettingsSFName').val(($(def).data('name')||''));
$('#vboxSettingsSFAM').prop('checked',($(def).data('autoMount') ? true : false));
$('#vboxSettingsSFAMPoint').val(($(def).data('autoMountPoint')||''));
$('#vboxSettingsSFRO').prop('checked',($(def).data('writable') ? false : true));
$('#vboxSettingsSFPerm').prop('checked',($(def).data('type') == 'machine' ? true : false));
var buttons = { };
buttons[trans('OK','QIMessageBox')] = function() {
if($('#vboxSettingsSFName').val() && $('#vboxSettingsSFPath').val()) {
var item = $('#vboxSettingsSharedFoldersList').find('tr.vboxListItemSelected').first();
$(item).data({
'hostPath' : $('#vboxSettingsSFPath').val(),
'name' : $('#vboxSettingsSFName').val(),
'autoMount' : ($('#vboxSettingsSFAM').prop('checked')),
'autoMountPoint' : $('#vboxSettingsSFAMPoint').val(),
'writable' : !($('#vboxSettingsSFRO').prop('checked')),
'type' : ((!$('#vboxSettingsSFPerm').length || $('#vboxSettingsSFPerm').prop('checked')) ? 'machine' : '')
}).trigger('refresh');
}
$(dialog).empty().remove();
};
buttons[trans('Cancel','QIMessageBox')] = function() { $(dialog).empty().remove(); };
$(dialog).dialog({'buttons':buttons}).dialog('open');
}
},
{
'name' : 'removeshared',
'label' : 'Remove Shared Folder',
'icon' : 'sf_remove',
'enabled' : function (item) { return $(item).hasClass('vboxListItemSelected'); },
'click' : function () {
var item = $('#vboxSettingsSharedFoldersList').find('.vboxListItemSelected').first();
var target = $(item).next();
if(!$(target).hasClass('vboxListItemSelected')) target = $(item).prev();
if(!$(target).hasClass('vboxListItemSelected')) target = $('#vboxSettingsSharedFoldersList').find('.vboxListItem').first();
$('#vboxSettingsSharedFoldersList').find('tr.vboxListItemSelected').first().remove();
if(!$(target).children().first().trigger('click').hasClass('vboxListItemSelected')) {
$('#vboxSettingsSharedFoldersList').trigger('select',null);
}
}
}
);
var sfToolbar = new vboxToolbarSmall({buttons: sButtons,
language_context: 'UIMachineSettingsSF', renderTo: 'vboxSettingsSFButtons'});
$('#vboxSettingsSharedFoldersList').on('select',function(e,el){sfToolbar.update(el);});
/* Add Shared Folder to list */
function vboxSettingsAddSharedFolder(f, noColor) {
var tr = $('<tr />').attr({'class':'vboxListItem'}).addClass(f.type == 'machine' ? 'vboxSFMachine' : 'vboxSFTransient').on('refresh',function(){
// bind refresh
$(this).children('td.vboxSettingsSFNameCell').children('span').first().html($('<div/>').text($(this).data('name')).html());
$(this).children('td.vboxSettingsSFPathCell').html($('<div/>').text($(this).data('hostPath')).html());
$(this).children('td.vboxSettingsSFAMPointCell').html($('<div/>').text($(this).data('autoMountPoint')).html());
$(this).children('td.vboxSettingsSFAMCell').html($(this).data('autoMount') ? trans('Yes','UIMachineSettingsSF') : '');
$(this).children('td.vboxSettingsSFROCell').html($(this).data('writable') ? trans('Full','UIMachineSettingsSF') : trans('Read-only','UIMachineSettingsSF'));
// Move from one type to another
if($(this).data('type') == 'machine' && $(this).hasClass('vboxSFTransient')) {
$(this).removeClass('vboxSFTransient').addClass('vboxSFMachine').detach().appendTo('#vboxSFMachineBody');
vboxColorRows($('#vboxSFMachineBody'));
vboxColorRows($('#vboxSFTransientBody'));
} else if($(this).data('type') != 'machine' && $(this).hasClass('vboxSFMachine')) {
$(this).removeClass('vboxSFMachine').addClass('vboxSFTransient').detach().appendTo('#vboxSFTransientBody');
vboxColorRows($('#vboxSFMachineBody'));
vboxColorRows($('#vboxSFTransientBody'));
}
}).hoverClass('vboxHover').disableSelection().data(f);
// Name
$('<td />').attr({'class':'vboxSettingsSFNameCell vboxHoverFirst'}).append($('<img />').attr({'src':'images/vbox/blank.gif','style':'height: 10px; width: 30px;'})).append($('<span />').html($('<div/>').text(f.name).html())).appendTo(tr);
// Path
$('<td />').attr({'class':'vboxSettingsSFPathCell vboxHoverMid'}).html($('<div/>').text(f.hostPath).html()).appendTo(tr);
// Read only?
$('<td />').attr({'class':'vboxSettingsSFROCell vboxHoverMid'}).html(f.writable ? trans('Full','UIMachineSettingsSF') : trans('Read-only','UIMachineSettingsSF')).appendTo(tr);
// auto-mount?
$('<td />').attr({'class':'vboxSettingsSFAMCell vboxHoverMid'}).html(f.autoMount ? trans('Yes','UIMachineSettingsSF') : '').appendTo(tr);
// Mount point
$('<td />').attr({'class':'vboxSettingsSFAMPointCell vboxHoverLast'}).html($('<div/>').text(f.autoMountPoint).html()).appendTo(tr);
$(tr).children().click(function(){
$('#vboxSettingsSharedFoldersList').find('tr.vboxListItemSelected').removeClass('vboxListItemSelected').addClass('vboxListItem');
$(this).parent().removeClass('vboxListItem').addClass('vboxListItemSelected');
$('#vboxSettingsSharedFoldersList').trigger('select',$(this).parent());
}).dblclick(function(e){
sfToolbar.click('editshared');
e.preventDefault();
});
if(f.type == 'machine') {
$('#vboxSFMachineBody').append(tr);
if(!noColor) vboxColorRows($('#vboxSFMachineBody'));
} else {
$('#vboxSFTransientBody').append(tr);
if(!noColor) vboxColorRows($('#vboxSFTransientBody'));
}
return tr;
}
/*
*
*
* Load SF data
*
*/
$('#vboxSettingsDialog').on('dataLoaded',function(){
/* Shared Folders */
var sfh = $('#vboxSettingsSharedFoldersList');
sfh.children('tbody').empty().remove();
/*
*
Add 'Machine Folder's
*
*/
var tb = $('<tbody />').attr({'id':'vboxSFMachineBody'}).addClass('vboxHover');
var tr = $('<tr />').attr({'class':'vboxListItemDisabled'}).disableSelection();
var td = $('<td />').attr({'class':'vboxSettingsSFNameCell'});
$('<input />').attr({'type':'button','class':'vboxImgButton','style':'background-image: url(images/vbox/arrow_down_10px.png); width: 12px; height: 12px; margin-right: 4px;'}).click(function(){
if(!$(this).data('toggleClicked')) {
$(this).data('toggleClicked', true);
$(this).css({'background-image':'url(images/vbox/arrow_right_10px.png)'});
$('#vboxSettingsSharedFoldersList').trigger('select',null);
$('#vboxSFMachineBody').children('tr.vboxSFMachine').css({'display':'none'}).removeClass('vboxListItemSelected').addClass('vboxListItem');
} else {
$(this).data('toggleClicked', false);
$(this).css({'background-image':'url(images/vbox/arrow_down_10px.png)'});
$('#vboxSettingsSharedFoldersList').trigger('select',null);
$('#vboxSFMachineBody').children('tr.vboxSFMachine').css({'display':''});
}
}).appendTo(td);
$(td).append($('<span />').html($('<div/>').text(trans(' Machine Folders','UIMachineSettingsSF')).html())).appendTo(tr);
$(tb).append($(tr).append($('<td />').attr({'class':'vboxSettingsSFPathCell'})).append($('<td />').attr({'class':'vboxSettingsSFAMPointCell'})).append($('<td />').attr({'class':'vboxSettingsSFAMCell'})).append($('<td />').attr({'class':'vboxSettingsSFROCell'}))).appendTo(sfh);
/*
*
* Add 'Transient Folders' if machine is running
*
*/
if(vboxVMStates.isRunning($('#vboxSettingsDialog').data('vboxMachineData')) || vboxVMStates.isSaved($('#vboxSettingsDialog').data('vboxMachineData')) || vboxVMStates.isPaused($('#vboxSettingsDialog').data('vboxMachineData'))) {
var tb = $('<tbody />').attr({'id':'vboxSFTransientBody'}).addClass('vboxHover');
var tr = $('<tr />').attr({'class':'vboxListItemDisabled'}).disableSelection();
$('<td />').attr({'class':'vboxSettingsSFNameCell'}).append(
$('<input />').attr({'type':'button','class':'vboxImgButton','style':'background-image: url(images/vbox/arrow_down_10px.png); width: 12px; height: 12px; margin-right: 4px;'}).click(function(){
if(!$(this).data('toggleClicked')) {
$(this).data('toggleClicked', true);
$(this).css({'background-image':'url(images/vbox/arrow_right_10px.png)'});
$('#vboxSettingsSharedFoldersList').trigger('select',null);
$('#vboxSFTransientBody').children('tr.vboxSFTransient').css({'display':'none'}).removeClass('vboxListItemSelected').addClass('vboxListItem');
} else {
$(this).data('toggleClicked', false);
$(this).css({'background-image':'url(images/vbox/arrow_down_10px.png)'});
$('#vboxSettingsSharedFoldersList').trigger('select',null);
$('#vboxSFTransientBody').children('tr.vboxSFTransient').css('display','');
}
})).append($('<span />').html($('<div/>').text(trans(' Transient Folders','UIMachineSettingsSF')).html())).appendTo(tr);
$(tr).append($('<td />').attr({'class':'vboxSettingsSFPathCell'})).append($('<td />').attr({'class':'vboxSettingsSFAMPointCell'})).append($('<td />').attr({'class':'vboxSettingsSFAMCell'})).append($('<td />').attr({'class':'vboxSettingsSFROCell'}));
$(tb).append(tr).appendTo(sfh);
// add each transient folder
for(var i = 0; i < $('#vboxSettingsDialog').data('vboxTransientSharedFolders').length; i++) {
vboxSettingsAddSharedFolder($('#vboxSettingsDialog').data('vboxTransientSharedFolders')[i]);
}
}
// add each machine folder
for(var i = 0; i < $('#vboxSettingsDialog').data('vboxMachineData').sharedFolders.length; i++) {
vboxSettingsAddSharedFolder($('#vboxSettingsDialog').data('vboxMachineData').sharedFolders[i]);
}
$('#vboxSettingsSharedFoldersList').trigger('select',null);
});
/* Update Shared Folder path and name. Callback for folder browser */
function vboxSFBrowseFolder(btn) {
vboxFileBrowser($('#vboxSettingsSFPath').val(),function(f) {
if(!f) return;
$('#vboxSettingsSFPath').val(f);
if(!$('#vboxSettingsSFName').val()) {
f = f.replace(/.*\//,'');
f = f.replace(/.*\\/,'');
if(f) $('#vboxSettingsSFName').val(f);
}
},true,trans('Folder Path:','UIMachineSettingsSFDetails').replace(':',''));
}
/*
*
*
* Shared Folder Properties Screen
*
*
*/
function vboxSettingsSFEditDialog() {
var d = $('<div />').attr({'id':'vboxSettingsSFEdit','class':'vboxNonTabbed vboxDialogContent','style':'display: none;'});
var tbl = $('<table />').attr({'style':'width: 100%','class':'vboxSettingsTable'});
// Path
$('<tr />').attr({'style':'vertical-align: middle'}).append($('<th />').attr({'style':'white-space: nowrap'}).html(trans('Folder Path:','UIMachineSettingsSFDetails'))).append(
$('<td />').attr({'style':'white-space: nowrap'}).html('<table style="width: 100%"><tr><td style="width: 100%"><input type="text" class="vboxText" id="vboxSettingsSFPath" style="width: 100%"/></td><td style="width: auto" class="vboxFileFolderInput"><input type="button" class="vboxImgButton" style="background-image: url(images/vbox/select_file_16px.png)" onClick="vboxSFBrowseFolder(this)" /></td></tr></table>')
).appendTo(tbl);
// Name
$('<tr />').append($('<th />').html(trans('Folder Name:','UIMachineSettingsSFDetails'))).append($('<td />').html('<input type="text" class="vboxText" id="vboxSettingsSFName" style="width: 100%" />')).appendTo(tbl);
// Read only
$('<tr />').append($('<th />')).append($('<td />').html('<label><input type="checkbox" class="vboxCheckbox" id="vboxSettingsSFRO" /> ' + trans('Read-only','UIMachineSettingsSFDetails')+'</label>')).appendTo(tbl);
// Auto mount
$('<tr />').append($('<th />')).append($('<td />').html('<label><input type="checkbox" class="vboxCheckbox" id="vboxSettingsSFAM" /> ' + trans('Auto-mount','UIMachineSettingsSFDetails')+'</label>')).appendTo(tbl);
// Mount point
$('<tr />').append($('<th />').html(trans('Mount point:','UIMachineSettingsSFDetails'))).append($('<td />').html('<input type="text" class="vboxText" id="vboxSettingsSFAMPoint" style="width: 100%" />')).appendTo(tbl);
// Add "Make Permanent"?
if(vboxVMStates.isRunning($('#vboxSettingsDialog').data('vboxMachineData')) || vboxVMStates.isSaved($('#vboxSettingsDialog').data('vboxMachineData')) || vboxVMStates.isPaused($('#vboxSettingsDialog').data('vboxMachineData'))) {
$('<tr />').append($('<th />')).append($('<td />').html('<label><input type="checkbox" class="vboxCheckbox" id="vboxSettingsSFPerm" /> ' + trans('Make Permanent','UIMachineSettingsSFDetails')+'</label>')).appendTo(tbl);
}
$(d).append(tbl).dialog({'width':800,'modal':true,'autoOpen':false,'dialogClass':'vboxDialogContent vboxNonTabbed','title':'<img src="images/vbox/sf_16px.png" class="vboxDialogTitleIcon" /> '+trans('Edit Share','UIMachineSettingsSFDetails')});
return $('#vboxSettingsSFEdit');
}
/* Change settings onSave() */
$('#vboxSettingsDialog').on('save',function(){
$('#vboxSettingsDialog').data('vboxMachineData').sharedFolders = new Array();
var folders = new Array();
$('#vboxSettingsSharedFoldersList').find('tr').each(function(){
// Skip headers and such
if($(this).data('name')) {
folders[folders.length] = {'name':$(this).data('name'),'hostPath':$(this).data('hostPath'),'autoMountPoint':$(this).data('autoMountPoint'),'autoMount':($(this).data('autoMount') ? true : false),'writable':($(this).data('writable') ? true : false),'type':$(this).data('type')};
}
});
$('#vboxSettingsDialog').data('vboxMachineData').sharedFolders = folders;
});
</script>