aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/js/share.js
blob: a8fa94107eebc48dfa887a90bfc138640d4d2475 (plain)
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
$(document).ready(function() {
	$('#dialog').live('mouseleave', function(event) {
		if ($(this).is(':visible')) {
			$(this).hide('blind', function() {
			  $(this).remove();
			});
		}
	});
	FileActions.register('all', 'Share', OC.imagePath('core', 'actions/share'), function(filename) {
		createShareDialog(filename, $('#dir').val()+'/'+filename);
	});
	$('.share').click(function(event) {
		event.preventDefault();
		var filenames = getSelectedFiles('name');
		var length = filenames.length;
		var files = '';
		for (var i = 0; i < length; i++) {
			files += $('#dir').val()+'/'+filenames[i]+';';
		}
		var lastFileName = filenames.pop();
		if (filenames.length > 0) {
			filenames = filenames.join(', ')+' and '+lastFileName;
		} else {
			filenames = lastFileName;
		}
		createShareDialog(filenames, files);
	});
	$('#uid_shared_with').live('keyup', function() {
		$(this).autocomplete({
			source: '../apps/files_sharing/ajax/userautocomplete.php'
		});
	});
	$('button.remove-uid_shared_with').live('click', function(event) {
		event.preventDefault();
		alert("remove");
		// TODO Remove corresponding row
	});
});

function createShareDialog(filenames, files) {
	var html = "<div id='dialog' style='display: none'>";
	html += "<div id='private'>";
	html += "<label for='uid_shared_with'><strong>Share with</strong></label><input placeholder='User or Group' id='uid_shared_with' />";
	html += "<input type='checkbox' name='permissions' id='permissions' value='1' /><label for='permissions'>allow editing</label><br />";
	html += "<br />";
	html += "<div id='shared_list'></div>";
	$.getJSON(OC.linkTo('files_sharing','ajax/getitem.php'), { source: files }, function(users) {
		var list = "";
		$.each(users, function(index, row) {
			list += row.uid_shared_with;
			list += "<input type='checkbox' name='share_private_permissions' value='1' /><label>allow editing</label><br />";
			if (row.permissions > 0) {
				$('share_private_permissions').prop('checked', true);
			}
		});
		$(list).appendTo('#shared_list');
	});
	html += "</div>";
	html += "<hr />";
	html += "<div id='public'>";
	html += "<input type='checkbox' name='public_link' id='public_link' value='1' /><label for='public_link'>make public</label>";
	html += "<input type='checkbox' name='public_link_write' id='public_link_write' value='1' /><label for='public_link_write'>allow upload</label>";
	html += "<div id='link'>";
	html += "</div>";
	html += "</div>";
	$('tr[data-file="'+filenames+'"]').addClass('mouseOver');
	$(html).appendTo($('tr[data-file="'+filenames+'"] td.filename'));
	$('#dialog').show('blind');

}