aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/js/settings-admin.js
blob: fa9b236ea98d4bd7d485f7bc616f618cc1e87173 (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
$(document).ready(function() {

	var loadTemplate = function (theme, template) {
		$.get(
			OC.generateUrl('apps/files_sharing/settings/mailtemplate'),
			{ theme: theme, template: template }
		).done(function( result ) {
			$( '#mailTemplateSettings textarea' ).val(result);
		}).fail(function( result ) {
			OC.dialogs.alert(result.message, t('files_sharing', 'Could not load template'));
		});
	};

	// load default template
	var theme = $( '#mts-theme' ).val();
	var template = $( '#mts-template' ).val();
	loadTemplate(theme, template);

	$( '#mts-template' ).change(
		function() {
			var theme = $( '#mts-theme' ).val();
			var template = $( this ).val();
			loadTemplate(theme, template);
		}
	);

	$( '#mts-theme' ).change(
		function() {
			var theme = $( this ).val();
			var template = $( '#mts-template' ).val();
			loadTemplate(theme, template);
		}
	);

	$( '#mailTemplateSettings .actions' ).on('click', '.save',
		function() {
			var theme = $( '#mts-theme' ).val();
			var template = $( '#mts-template' ).val();
			var content = $( '#mailTemplateSettings textarea' ).val();
			OC.msg.startSaving('#mts-msg');
			$.post(
				OC.generateUrl('apps/files_sharing/settings/mailtemplate'),
				{ theme: theme, template: template, content: content }
			).done(function() {
				var data = { status:'success', data:{message:t('files_sharing', 'Saved')} };
				OC.msg.finishedSaving('#mts-msg', data);
			}).fail(function(result) {
				var data = { status: 'error', data:{message:result.responseJSON.message} };
				OC.msg.finishedSaving('#mts-msg', data);
			});
		}
	);

	$( '#mailTemplateSettings .actions' ).on('click', '.reset',
		function() {
			var theme = $( '#mts-theme' ).val();
			var template = $( '#mts-template' ).val();
			OC.msg.startSaving('#mts-msg');
			$.ajax({
				type: "DELETE",
				url: OC.generateUrl('apps/files_sharing/settings/mailtemplate'),
				data: { theme: theme, template: template }
			}).done(function() {
				var data = { status:'success', data:{message:t('files_sharing', 'Reset')} };
				OC.msg.finishedSaving('#mts-msg', data);

				// load default template
				var theme = $( '#mts-theme' ).val();
				var template = $( '#mts-template' ).val();
				loadTemplate(theme, template);
			}).fail(function(result) {
				var data = { status: 'error', data:{message:result.responseJSON.message} };
				OC.msg.finishedSaving('#mts-msg', data);
			});
		}
	);

});