aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/js/share.js
blob: 32926c6811e218d7e57c41a0efbef593d52ae524 (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
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
$(document).ready(function() {
	$('.share').click(function(event) {
		event.preventDefault();
		var html = "<div id='dialog' title='Share "+getSelectedFiles('name')+"' align='center'>";
		html += "<label><input type='radio' name='share_type' value='private' checked='checked' /> Private</label>";
		html += "<label><input type='radio' name='share_type' value='public' /> Public</label>";
		html += "<br />";
		html += "<div id='private'>";
		html += "<label>Share with <input placeholder='User or Group' class='uid_shared_with' /></label>";
		html += "<button id='hey' class='add-uid_shared_with fancybutton'>+</button>";
		html += "<br />";
		html += "<a id='toggle-private-advanced'>Advanced</a>";
		html += "<br />";
		html += "<div id='private-advanced' style='display: none; text-align: left'>";
		html += "<label><input type='checkbox' name='share_permissions' value='read' checked='checked' disabled='disable' /> Read</label><br />";
		html += "<label><input type='checkbox' name='share_permissions' value='write' /> Write</label><br />";
		html += "<label><input type='checkbox' name='share_permissions' value='rename' /> Rename</label><br />";
		html += "<label><input type='checkbox' name='share_permissions' value='delete' /> Delete</label><br />";
		html += "</div>";
		html += "</div>";
		html += "<div id='public' style='display: none'>";
		html += "TODO: Construct a public link";
		html += "<input placeholder='Expires' id='expire' />";
		html += "</div>";
		html += "<br />";
		html += "<button class='submit fancybutton'>Share</button>";
		html += "<div>";
		$(html).dialog({
			close: function(event, ui) {
				$(this).remove();
			}
		});
	});
	$("input[name=share_type]").live('change', function() {
		$('#private').toggle();
		$('#public').toggle();
	});
	$('.uid_shared_with').live('keyup', function() {
		$(this).autocomplete({
			source: "../apps/files_sharing/ajax/userautocomplete.php",
			minLength: 1
		});
	});
	$('button.add-uid_shared_with').live('click', function(event) {
		event.preventDefault();
		// TODO Make sure previous textbox has a valid user or group name
		var html = "<br />";
		html += "<label>Share with <input placeholder='User or Group' class='uid_shared_with' /></label>";
		html += "<button class='add-uid_shared_with fancybutton'>+</button>";
		$(html).insertAfter('.add-uid_shared_with');
		$(this).html("&nbsp-&nbsp&nbsp");
		$(this).removeClass("add-uid_shared_with fancybutton");
		$(this).addClass("remove-uid_shared_with fancybutton");
	});
	$('button.remove-uid_shared_with').live('click', function(event) {
		event.preventDefault();
		alert("remove");
		// TODO Remove corresponding row
	});
	$('#toggle-private-advanced').live('click', function(event) {
		event.preventDefault();
		$('#private-advanced').toggle();
	});
	$('#expire').datepicker({
		dateFormat:'MM d, yy',
		altField: "#expire_time",
		altFormat: "yy-mm-dd"
	});
	$('button.submit').live('click', function(event) {
		event.preventDefault();
		if ($("input[name=share_type]:checked").val() == 'public') {
			// TODO Construct public link
		} else {
			// TODO Check all inputs are valid
			var sources = "";
			var files = getSelectedFiles('name');
			var length = files.length;
			for (var i = 0; i < length; i++) {
				sources += "&sources[]=" + $('#dir').val() + "/" + files[i];
			}
			var uid_shared_with = $('.uid_shared_with').val();
			var permissions = 0;
			var data = sources+'&uid_shared_with[]='+uid_shared_with+'&permissions='+permissions;
			$.ajax({
				type: 'GET',
				url: '../apps/files_sharing/ajax/share.php',
				cache: false,
				data: data,
				success: function() {
					$('#dialog').dialog('close');
				}
			});
		}
	});
});