summaryrefslogtreecommitdiff
path: root/code/admin/admin.js
blob: 9c2536e909a6e6811479260ee11dd3ff24fe5dde (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
// Helpers
function gEBId(id) { return document.getElementById(id) };

function microAjaxJSON(query,callback) {
	microAjax(query,function (res) {
		var parsed_json;
		try {
			parsed_json = JSON.parse(res);
		} catch(err) {
			alert(res);
			return;
		}
		callback(parsed_json);
	});
}

// Admin simple actions
function select_fold(path) {
	gEBId("fold_path").value=path;
}

// Admin AJAX actions
function load_page_props(path) {
	gEBId("page_path").value=path;
	var url = "ajax.php?action=load_page_props&path=" + encodeURIComponent(path);
	microAjaxJSON(url, function (parsed_json) {
		gEBId("page_title").value = parsed_json.page_title;
		gEBId("page_description").value = parsed_json.page_description;
		gEBId("page_keywords").value = parsed_json.page_keywords;
	});
}

function load_media_props(path) {
	gEBId("media_path").value=path;
	var url = "ajax.php?action=load_media_props&path=" + encodeURIComponent(path);
	microAjaxJSON(url, function (parsed_json) {
		gEBId("media_title").value = parsed_json.media_title;
		gEBId("media_description").value = parsed_json.media_description;
		//gEBId("media_keywords").value = parsed_json.media_keywords;
	});
}

function save_page_props() {
	var path = gEBId("page_path").value;
	var page_title = gEBId("page_title").value;
	var page_description = gEBId("page_description").value;
	var page_keywords = gEBId("page_keywords").value;

	//TODO : check against regex

	var url = "ajax.php?action=save_page_props"
			+ "&path=" + encodeURIComponent(path)
			+ "&page_title=" + encodeURIComponent(page_title)
			+ "&page_description=" + encodeURIComponent(page_description)
			+ "&page_keywords=" + encodeURIComponent(page_keywords);

	microAjaxJSON(url, function (parsed_json) {
		if ( parsed_json.result != "OK" ) {
			alert("Error\nResult: " + parsed_json.result + "\nRequest: " + url);
		}
		//TODO : says to user that the work is done
	});

	load_page_props(path);
}

function save_media_props() {
	var path = gEBId("media_path").value;
	var title = gEBId("media_title").value;
	var description = gEBId("media_description").value;
	//var keywords = gEBId("media_keywords").value;

	//TODO : check against regex

	var url = "ajax.php?action=save_media_props"
			+ "&path=" + encodeURIComponent(path)
			+ "&title=" + encodeURIComponent(title)
			+ "&description=" + encodeURIComponent(description);
	//		+ "&keywords=" + encodeURIComponent(keywords);

	microAjaxJSON(url, function (parsed_json) {
		if ( parsed_json.result != "OK" ) {
			alert("Error\nResult: " + parsed_json.result + "\nRequest: " + url);
			return;
		}
		//TODO : says to user that the work is done
	});
}

function save_site_props() {
	//TODO
}

// Admin other actions (with page change or refresh)
function go_admin_page() {
	document.location = './';
}
function go_add_form(kind) {
	document.location = 'add.php?kind=' + encodeURIComponent(kind);
}

function go_add(kind,type) {
	var path = gEBId("fold_path").value;
	var name = gEBId("fold_add_name").value;
	// TODO : check name and path against regex
	var url = 'add.php?kind=' + encodeURIComponent(kind)
		+ '&action=add_' + encodeURIComponent(type)
		+ '&path=' + encodeURIComponent(path)
		+ '&name=' + encodeURIComponent(name);
	document.location = url;
}

function go_edit_page() {
	var path = gEBId("page_path").value;
	document.location = 'render.php?action=edit&page=' + encodeURIComponent(path);
}

function go_delete_page() {
	var path = gEBId("page_path").value;
	//TODO : confirmation, ajax query, if OK, confirm then refresh
}

function go_delete_media() {
	var path = gEBId("page_path").value;
	//TODO : confirmation, ajax query, if OK, confirm then refresh
}