summaryrefslogtreecommitdiffstats
path: root/admin/survey/script/timeProfiles.js
blob: 50833ad9165cce68e508f4bd2755ce60b3156246 (plain) (blame)
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
function timeProfiles_init() {

	$("#link_time_profile_remove").live("click", function(event) {
		var pid = '0';
		$.post( 'ajax.php?t=timeProfile&a=changeProfile', { anketa : srv_meta_anketa_id, meta_akcija : srv_meta_akcija, podstran : srv_meta_podstran,pid:pid }, function() {
			return reloadData('interval');
		});
	});
	$("#link_time_profile_edit").live("click", function(event) {
		timeProfileAction('showProfiles');
	});
	
	
	$("#time_profile").live('click', function(event) {
		var $target = $(event.target);
		if ($target.hasClass('option')) {
			pid = $target.attr('value');
			$.post( 'ajax.php?t=timeProfile&a=changeProfile', { anketa : srv_meta_anketa_id, meta_akcija : srv_meta_akcija, podstran : srv_meta_podstran,pid:pid }, function() {
				changeViewTimeProfile(pid);
			});
		}
	});
};

function changeViewTimeProfile(pid) {
	$("#div_time_profiles").load( 'ajax.php?t=timeProfile&a=showProfile', { anketa : srv_meta_anketa_id, meta_akcija : srv_meta_akcija, podstran : srv_meta_podstran, pid:pid });	
}

function changeTimeProfileType(what) {
	if (what == 'interval') {
		$("#time_date_interval").attr('checked', true);
	} else {
		$("#time_date_type").attr('checked', true);
	}
	
}

function timeProfileAction(action) {
	if (action == 'showProfiles') {
		$('#fade').fadeTo('slow', 1);
		// poiščemo center strani
		$("#div_time_profiles").load( 'ajax.php?t=timeProfile&a=showProfile', { anketa : srv_meta_anketa_id, meta_akcija : srv_meta_akcija, podstran : srv_meta_podstran }, function() {
			var msg = $('#div_time_profiles');
			var height = $(window).height();
			var width = $(document).width();
			var left = width - (msg.width()) - 42;
			var top = height / 2 - (msg.height() / 2);
		}).show(200); 
		//.draggable( { delay : 100, cancel : 'input, .buttonwrapper, .select, #time_profile_left_right' });
	} else if (action == 'cancel'){
		reloadData('interval');
		$("#div_time_profiles").hide(200);
		//$('#fade').fadeOut('slow');
		$("#div_time_profiles").html('');
	} else if (action == 'change_profile'){
		var pid = $("#current_time_profile").val();
		$.post( 'ajax.php?t=timeProfile&a=changeProfile', { anketa : srv_meta_anketa_id, meta_akcija : srv_meta_akcija, podstran : srv_meta_podstran,pid:pid }, function() {
			return reloadData('interval');
		});
	} else if (action == 'show_create'){
		$("#timeProfileCoverDiv").show();
		$("#newProfileDiv").show();
	} else if (action == 'cancel_create'){
		$("#timeProfileCoverDiv").hide();
		$("#newProfileDiv").hide();
	} else if (action == 'do_create'){
		var profileName = $("#newProfileName").val();
		$("#div_time_profiles").load('ajax.php?t=timeProfile&a=createProfile', {anketa: srv_meta_anketa_id, podstran: srv_meta_podstran, profileName:profileName}, function(newId) {
			$("#div_time_profiles").load( 'ajax.php?t=timeProfile&a=showProfile', { anketa : srv_meta_anketa_id, meta_akcija : srv_meta_akcija, podstran : srv_meta_podstran , pid:newId});
		});
	} else if (action == 'show_rename'){
		$("#timeProfileCoverDiv").show();
		$("#renameProfileDiv").show();
	} else if (action == 'cancel_rename'){
		$("#timeProfileCoverDiv").hide();
		$("#renameProfileDiv").hide();
	} else if (action == 'do_rename'){
		var pid = $("#time_profile .active").attr('value');
		var name = $("#renameProfileName").val();
		$.post('ajax.php?t=timeProfile&a=renameProfile', { anketa : srv_meta_anketa_id, pid : pid, name:name  }, function() {
			$("#div_time_profiles").load( 'ajax.php?t=timeProfile&a=showProfile', {
				anketa : srv_meta_anketa_id,
				meta_akcija : srv_meta_akcija,
				podstran : srv_meta_podstran
			}, function () {
				$("#renameProfileDiv").hide();
				$("#timeProfileCoverDiv").fadeOut();
			});
		});
	} else if (action == 'show_delete'){
		$("#timeProfileCoverDiv").show();
		$("#deleteProfileDiv").show();
	} else if (action == 'cancel_delete'){
		$("#timeProfileCoverDiv").hide();
		$("#deleteProfileDiv").hide();
	} else if (action == 'do_delete'){
		var pid = $("#time_profile .active").attr('value');
		$.post('ajax.php?t=timeProfile&a=deleteProfile', { anketa : srv_meta_anketa_id, pid : pid }, function() {
			$("#div_time_profiles").load('ajax.php?t=timeProfile&a=showProfile', {
						anketa : srv_meta_anketa_id,
						meta_akcija : srv_meta_akcija,
						podstran : srv_meta_podstran
					});
		});
		$("#deleteProfileDiv").hide();
		$("#timeProfileCoverDiv").fadeOut();
	} else if (action == 'run_profile' || action == 'run_session_profile'){
		// poiščemo id izbranega profila
		if (action == 'run_profile') {
			var pid = $("#time_profile .active").attr('value');
		} else {
			var pid = -1;
		}
		var type = $('input[name=type]:checked').val();
		var startDate  = $("#startDate").val();
		var endDate = $("#endDate").val();
		var stat_interval = $("#stat_interval").val();
		if (type == 1 && stat_interval == '') {
			// če je type 1 (intervalni način) in interval ni izbran, damo opozorilo
			genericAlertPopup('srv_time_profile_error_interval');
			return false;
		} else {
			$.post("ajax.php?t=timeProfile&a=saveProfile", {anketa:srv_meta_anketa_id, pid:pid, type:type, startDate:startDate,endDate:endDate,stat_interval:stat_interval}, function(response) {
				return reloadData('interval');
			});
		}
	} else {
		genericAlertPopup('alert_parameter_action',action);
		return false;
	}
}