1/**
2 * @license    http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
3 * @author     Francois Merciol <dokuplugin@merciol.fr>
4 *
5 * Javascript functionality for the include plugin
6 */
7
8/* DOKUWIKI:include_once lib/scheduleForm.js */
9/* DOKUWIKI:include_once lib/scheduleTable.js */
10/* DOKUWIKI:include_once ../ol3/script.js */
11/* DOKUWIKI:include_once lib/scheduleCitiesMap.js */
12
13// ========================================
14// Ajax function
15// ========================================
16/* Clear popup message */
17function scheduleClearMsgJ (item) {
18    item.closest ("div").find ("div.popup").each (function () {
19	jQuery (this).remove ();
20    });
21}
22
23function scheduleClearCache (action, ns) {
24    jQuery.ajax ({
25	type: "POST",
26	url: DOKU_BASE+"lib/plugins/schedule/ajaxClearCache.php",
27	//success: function (response) { alert (response); },
28	cache: true,
29	async: true,
30	data: "schedule[action]="+action+"&schedule[ns]="+ns
31    });
32}
33
34/* performe ajax request to swap month */
35function scheduleAjax (form, action, md5) {
36    var params = "";
37    // XXX jquery
38    for (var idx = 0; idx < form.elements.length; idx++) {
39	var elem = form.elements[idx];
40	if (elem.type == "checkbox") {
41	    if (elem.checked)
42		params += "&"+elem.name+"="+elem.value;
43	} else if (elem.type == "select" || elem.type == "select-multiple") {
44	    while (elem.options.selectedIndex >= 0) {
45		opt = elem.options [elem.options.selectedIndex];
46		params += "&"+elem.name+"="+opt.text;
47		elem.options [elem.options.selectedIndex] = null;
48	    }
49	} else
50	    params += "&"+elem.name+"="+elem.value;
51    }
52    params += "&schd[action]="+action+"&schd[md5]="+md5;
53
54    scheduleSend (form,
55		  DOKU_BASE+"lib/plugins/schedule/ajax.php",
56		  params);
57    return false;
58}
59
60function scheduleSend (sender, uri, params) {
61    var jDiv = jQuery (sender).closest ("div");
62    scheduleClearMsgJ (jDiv);
63    jQuery ('<div class="popup">'+LANG["plugins"]["schedule"]["pleaseWait"]+'</div>').
64	insertBefore (jDiv.children ().first ());
65    jQuery.ajax ({
66	type: "POST",
67	url: uri,
68	cache: false,
69	async: true,
70	data: params,
71	success: function (response) {
72	    jDiv.html (response);
73	    scheduleInitMaps ();
74	    scheduleInitPOI ();
75	}
76    });
77}
78
79// ========================================
80