summaryrefslogtreecommitdiffstats
path: root/apps/calendar/js/loader.js
blob: 9f18ea872630aba7fb90a6d0636a776ed74a640c (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
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
/**
 * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
Calendar_Import={
	Store:{
		file: '',
		path: '',
		id: 0,
		method: '',
		calname: '',
		progresskey: '',
		percentage: 0
	},
	Dialog:{
		open: function(filename){
			OC.addStyle('calendar', 'import');
			Calendar_Import.Store.file = filename;
			Calendar_Import.Store.path = $('#dir').val();
			$('body').append('<div id="calendar_import"></div>');
			$('#calendar_import').load(OC.filePath('calendar', 'ajax/import', 'dialog.php'), {filename:Calendar_Import.Store.file, path:Calendar_Import.Store.path},function(){
					Calendar_Import.Dialog.init();
			});
		},
		close: function(){
			Calendar_Import.reset();
			$(this).dialog('destroy').remove();
			$('#calendar_import_dialog').remove();
		},
		init: function(){
			//init dialog
			$('#calendar_import_dialog').dialog({
				width : 500,
				close : function() {
					Calendar_Import.Dialog.close();
				}
			});
			//init buttons
			$('#calendar_import_done').click(function(){
				Calendar_Import.Dialog.close();
			});
			$('#calendar_import_submit').click(function(){
				Calendar_Import.Core.process();
			});
			$('#calendar_import_calendar').change(function(){
				if($('#calendar_import_calendar option:selected').val() == 'newcal'){
					$('#calendar_import_newcalform').slideDown('slow');
					Calendar_Import.Dialog.mergewarning($('#calendar_import_newcalendar').val());
				}else{
					$('#calendar_import_newcalform').slideUp('slow');
					$('#calendar_import_mergewarning').slideUp('slow');
				}
			});
			$('#calendar_import_newcalendar').keyup(function(){
				Calendar_Import.Dialog.mergewarning($('#calendar_import_newcalendar').val());
			});
			//init progressbar
			$('#calendar_import_progressbar').progressbar({value: Calendar_Import.Store.percentage});
			Calendar_Import.Store.progresskey = $('#calendar_import_progresskey').val();
		},
		mergewarning: function(newcalname){
			$.post(OC.filePath('calendar', 'ajax/import', 'calendarcheck.php'), {calname: newcalname}, function(data){
				if(data.message == 'exists'){
					$('#calendar_import_mergewarning').slideDown('slow');
				}else{
					$('#calendar_import_mergewarning').slideUp('slow');
				}
			});
		},
		update: function(){
			/*$.post(OC.filePath('calendar', 'ajax/import', 'import.php'), {progress:1,progresskey: progresskey}, function(percent){
				$('#progressbar').progressbar('option', 'value', parseInt(percent));
				if(percent < 100){
					window.setTimeout('Calendar_Import.getimportstatus(\'' + progresskey + '\')', 500);
				}else{
					$('#import_done').css('display', 'block');
				}
			});*/
		return 0;
		},
		warning: function(selector){
			$(selector).css('background-color', '#FF2626');
			$(selector).focus(function(){
				$(selector).css('background-color', '#F8F8F8');
			});
		}
	},
	Core:{
		process: function(){
			var validation = Calendar_Import.Core.prepare();
			$('#calendar_import_form').css('display', 'none');
			$('#calendar_import_process').css('display', 'block');
			if(validation){
				$('#calendar_import_newcalendar').attr('readonly', 'readonly');
				$('#calendar_import_calendar').attr('disabled', 'disabled');
				Calendar_Import.Core.send();
			}
		},
		send: function(){
			$.post(OC.filePath('calendar', 'ajax/import', 'import.php'), 
			{progresskey: Calendar_Import.Store.progresskey, method: String (Calendar_Import.Store.method), calname: String (Calendar_Import.Store.calname), path: String (Calendar_Import.Store.path), file: String (Calendar_Import.Store.file), id: String (Calendar_Import.Store.id)}, function(data){
				if(data.status == 'success'){
					$('#calendar_import_progressbar').progressbar('option', 'value', 100);
					$('#calendar_import_done').css('display', 'block');
					$('#calendar_import_status').html(data.message);
				}else{
					$('#calendar_import_progressbar').progressbar('option', 'value', 100);
					$("#calendar_import_progressbar > div").css('background-color', '#FF2626');
					$('#calendar_import_status').html(data.message);
				}
			});
			$('#form_container').css('display', 'none');
			$('#progressbar_container').css('display', 'block');
			window.setTimeout('Calendar_Import.Dialog.update', 500);
		},
		prepare: function(){
			Calendar_Import.Store.id = $('#calendar_import_calendar option:selected').val();
			if($('#calendar_import_calendar option:selected').val() == 'newcal'){
				Calendar_Import.Store.method = 'new';
				Calendar_Import.Store.calname = $.trim($('#calendar_import_newcalendar').val());
				if(Calendar_Import.Store.calname == ''){
					Calendar_Import.Dialog.warning('#calendar_import_newcalendar');
					return false;
				}
			}else{
				Calendar_Import.Store.method = 'old';
			}
			return true;
		}
	},
	reset: function(){
		Calendar_Import.Store.file = '';
		Calendar_Import.Store.path = '';
		Calendar_Import.Store.id = 0;
		Calendar_Import.Store.method = '';
		Calendar_Import.Store.calname = '';
		Calendar_Import.Store.progresskey = '';
		Calendar_Import.Store.percentage = 0;
	}
}
$(document).ready(function(){
	if(typeof FileActions !== 'undefined'){
		FileActions.register('text/calendar','importCalendar', '', Calendar_Import.Dialog.open); 
		FileActions.setDefault('text/calendar','importCalendar');
	};
});