summaryrefslogtreecommitdiff
path: root/code/admin/admin.js
diff options
context:
space:
mode:
authorLudovic Pouzenc <lpouzenc@gmail.com>2013-10-29 18:42:08 +0100
committerLudovic Pouzenc <lpouzenc@gmail.com>2013-10-29 18:42:08 +0100
commitc98515883097467896a3f46b755c8cb892fe8961 (patch)
treebe2e4f5450e9bc9cf692e8dfac7c9780eaa7019b /code/admin/admin.js
downloadeditablesite-c98515883097467896a3f46b755c8cb892fe8961.tar.gz
editablesite-c98515883097467896a3f46b755c8cb892fe8961.tar.bz2
editablesite-c98515883097467896a3f46b755c8cb892fe8961.zip
Import initial avec une arbrescence éclatée
Diffstat (limited to 'code/admin/admin.js')
-rw-r--r--code/admin/admin.js123
1 files changed, 123 insertions, 0 deletions
diff --git a/code/admin/admin.js b/code/admin/admin.js
new file mode 100644
index 0000000..3d0125d
--- /dev/null
+++ b/code/admin/admin.js
@@ -0,0 +1,123 @@
+// 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);
+ return;
+ }
+ //TODO : says to user that the work is done
+ });
+}
+
+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_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
+}
+