From c98515883097467896a3f46b755c8cb892fe8961 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Tue, 29 Oct 2013 18:42:08 +0100 Subject: Import initial avec une arbrescence éclatée MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/admin/admin.js | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 code/admin/admin.js (limited to 'code/admin/admin.js') 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 +} + -- cgit v1.2.3