From e1f2a5d4e60f431e0a94c998afc026f1136fb26b Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 11 Dec 2008 17:20:55 +0000 Subject: 1) Begins the creation of the local import module by adding the administation component to the scaffolding Actions tab. The importing functionality will follow shortly. 2) Defines a routining pattern for module administration controllers. URI's of the form admin/module/method/parameters gets remapped into module_admin/method/parameters. This will result in the lookup of the the controller Module_Admin_Controller --- .../controllers/local_import_admin.php | 56 +++++++++++++++++ modules/local_import/helpers/local_import.php | 49 +++++++++++++++ .../local_import/helpers/local_import_block.php | 30 +++++++++ .../helpers/local_import_installer.php | 41 +++++++++++++ modules/local_import/images/bin_closed.png | Bin 0 -> 363 bytes modules/local_import/js/local_import.js | 67 +++++++++++++++++++++ .../local_import/views/local_import_admin.html.php | 31 ++++++++++ .../views/local_import_dir_list.html.php | 28 +++++++++ 8 files changed, 302 insertions(+) create mode 100644 modules/local_import/controllers/local_import_admin.php create mode 100644 modules/local_import/helpers/local_import.php create mode 100644 modules/local_import/helpers/local_import_block.php create mode 100644 modules/local_import/helpers/local_import_installer.php create mode 100644 modules/local_import/images/bin_closed.png create mode 100644 modules/local_import/js/local_import.js create mode 100644 modules/local_import/views/local_import_admin.html.php create mode 100644 modules/local_import/views/local_import_dir_list.html.php (limited to 'modules') diff --git a/modules/local_import/controllers/local_import_admin.php b/modules/local_import/controllers/local_import_admin.php new file mode 100644 index 00000000..18733c22 --- /dev/null +++ b/modules/local_import/controllers/local_import_admin.php @@ -0,0 +1,56 @@ +validate()) { + $paths[$form->path->value] = 1; + module::set_var("local_import", "authorized_paths", serialize($paths)); + } + $view = new View("local_import_dir_list.html"); + $view->paths = array_keys($paths); + + print $view; + } + + public function remove() { + $path = $this->input->post("path"); + $paths = unserialize(module::get_var("local_import", "authorized_paths")); + unset($paths[$path]); + module::set_var("local_import", "authorized_paths", serialize($paths)); + + $view = new View("local_import_dir_list.html"); + $view->paths = array_keys($paths); + + print $view; + } + + public function autocomplete() { + $files = array(); + + $path_prefix = $this->input->get("q"); + foreach (glob("{$path_prefix}*") as $file) { + $files[] = $file; + } + + print implode("\n", $files); + } +} \ No newline at end of file diff --git a/modules/local_import/helpers/local_import.php b/modules/local_import/helpers/local_import.php new file mode 100644 index 00000000..045201c7 --- /dev/null +++ b/modules/local_import/helpers/local_import.php @@ -0,0 +1,49 @@ +admin) { +// throw new Exception("@todo ACCESS DENIED"); +// } + + $template = new View("local_import_admin.html"); + + $paths = unserialize(module::get_var("local_import", "authorized_paths")); + if (!empty($paths)) { + $template->dir_list = new View("local_import_dir_list.html"); + $template->dir_list->paths = array_keys($paths); + } else { + $template->dir_list = ""; + } + + $template->add_form = self::get_admin_form()->render(); + + return $template; + } + + public static function get_admin_form() { + $form = new Forge("admin/local_import/add_path", "", "post", array("id" => "gLocalImportAdminForm")); + $form->input("path")->label(true); + $form->submit(_("Add")); + + return $form; + } +} diff --git a/modules/local_import/helpers/local_import_block.php b/modules/local_import/helpers/local_import_block.php new file mode 100644 index 00000000..c337af41 --- /dev/null +++ b/modules/local_import/helpers/local_import_block.php @@ -0,0 +1,30 @@ +"; + + return implode("\n", $head); + } +} diff --git a/modules/local_import/helpers/local_import_installer.php b/modules/local_import/helpers/local_import_installer.php new file mode 100644 index 00000000..72f42c97 --- /dev/null +++ b/modules/local_import/helpers/local_import_installer.php @@ -0,0 +1,41 @@ +query("DELETE FROM `vars` WHERE `module_id` = {$module->id};"); + + module::delete("local_import"); + } +} diff --git a/modules/local_import/images/bin_closed.png b/modules/local_import/images/bin_closed.png new file mode 100644 index 00000000..afe22ba9 Binary files /dev/null and b/modules/local_import/images/bin_closed.png differ diff --git a/modules/local_import/js/local_import.js b/modules/local_import/js/local_import.js new file mode 100644 index 00000000..3ad01ce8 --- /dev/null +++ b/modules/local_import/js/local_import.js @@ -0,0 +1,67 @@ +/** + * Set up autocomplete on the server path list + * + */ +$("document").ready(function() { + var previous_search = ""; + $("#gLocalImportAdmin input").autocomplete({ + url: base_url + "admin/local_import/autocomplete", + mustMatch: true, + }); + ajaxify_form({ + form: "#gLocalImportAdmin form", + url: "admin/local_import/", + returnCode: 200, + callback: function(xhr, statusText) { + $("#gImportLocalDirList").html(xhr.responseText); + setDroppable("#gImportLocalDirList #gRemoveDir"); + setDraggable("#gImportLocalDirList li"); + } + }); + + setDroppable("#gImportLocalDirList #gRemoveDir"); + setDraggable("#gImportLocalDirList li"); +}); + +function setDraggable(selector) { + $(selector).draggable({ + helper: 'clone', +// containment: "#gImportLocalDirList", + opacity: .6, + revert: "invalid" + }); +} + +function setDroppable(selector) { + $(selector).droppable({ + accept: "#gImportLocalDirList li", + drop: function(ev, ui) { + var element = ui.draggable[0]; + + if (confirm("Do you really want to remove " + element.textContent)) { + $.ajax({ + data: "path=" + element.textContent, + url: base_url + "admin/local_import/remove", + success: function(data, textStatus) { + $("#gImportLocalDirList").html(data); + setDroppable("#gImportLocalDirList #gRemoveDir"); + setDraggable("#gImportLocalDirList li"); + }, + error: function(xhr, textStatus, errorThrown) { + alert("Text Status: " + textStatus + " Http Error Code: " + xhr.status); + }, + type: "POST" + }); + } + } + }); +} + +function ajaxify_form(options) { + $(options.form).ajaxForm({ + complete:function(xhr, statusText) { + options.callback(xhr, statusText); + $(options.form).clearForm(); + } + }); +} diff --git a/modules/local_import/views/local_import_admin.html.php b/modules/local_import/views/local_import_admin.html.php new file mode 100644 index 00000000..58daeab6 --- /dev/null +++ b/modules/local_import/views/local_import_admin.html.php @@ -0,0 +1,31 @@ + + +
+
+ +
+
+ +
+
diff --git a/modules/local_import/views/local_import_dir_list.html.php b/modules/local_import/views/local_import_dir_list.html.php new file mode 100644 index 00000000..db34d1bf --- /dev/null +++ b/modules/local_import/views/local_import_dir_list.html.php @@ -0,0 +1,28 @@ + + +Remove + + -- cgit v1.2.3