diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-03-05 02:26:39 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-03-05 02:26:39 +0000 |
commit | 64b02026ed645761e910bc31334b66171c58cb5a (patch) | |
tree | d1ca13dcbc41a333a2f93aaf05d764c2b2466848 | |
parent | ca2ddb01701179e61659b59519919f82241e5564 (diff) |
Cleanups.
- Show the "Server Add needs configuration" message whenever
there are no paths.
- Un-ajaxify the admin code to remove complexity and allow us to
update the status message as appropriate.
- Rename server_add_admin.html.php to admin_server_add.html.php
for consistency.
- Fix up form to properly display error messages
- Get rid of server_add_dir_list.html.php now that we're
non-ajaxified.
- Change delete <span> to an <a> for non-ajax world.
-rw-r--r-- | modules/server_add/controllers/admin_server_add.php | 39 | ||||
-rw-r--r-- | modules/server_add/helpers/server_add.php | 32 | ||||
-rw-r--r-- | modules/server_add/helpers/server_add_installer.php | 10 | ||||
-rw-r--r-- | modules/server_add/js/admin.js | 39 | ||||
-rw-r--r-- | modules/server_add/views/admin_server_add.html.php | 25 | ||||
-rw-r--r-- | modules/server_add/views/server_add_admin.html.php | 10 | ||||
-rw-r--r-- | modules/server_add/views/server_add_dir_list.html.php | 13 |
7 files changed, 81 insertions, 87 deletions
diff --git a/modules/server_add/controllers/admin_server_add.php b/modules/server_add/controllers/admin_server_add.php index 94dd8f74..466e5e41 100644 --- a/modules/server_add/controllers/admin_server_add.php +++ b/modules/server_add/controllers/admin_server_add.php @@ -20,11 +20,10 @@ class Admin_Server_Add_Controller extends Admin_Controller { public function index() { $view = new Admin_View("admin.html"); - $view->content = new View("server_add_admin.html"); - $view->content->add_form = $this->_get_admin_form(); - $view->content->path_list = new View("server_add_dir_list.html"); + $view->content = new View("admin_server_add.html"); + $view->content->form = $this->_get_admin_form(); $paths = unserialize(module::get_var("server_add", "authorized_paths", "a:0:{}")); - $view->content->path_list->paths = array_keys($paths); + $view->content->paths = array_keys($paths); print $view; } @@ -36,37 +35,39 @@ class Admin_Server_Add_Controller extends Admin_Controller { $paths = unserialize(module::get_var("server_add", "authorized_paths", "a:0:{}")); if ($form->validate()) { if (is_readable($form->add_path->path->value)) { - $paths[$form->add_path->path->value] = 1; + $path = $form->add_path->path->value; + $paths[$path] = 1; module::set_var("server_add", "authorized_paths", serialize($paths)); $view = new View("server_add_dir_list.html"); $view->paths = array_keys($paths); $form->add_path->inputs->path->value = ""; - print json_encode( - array("result" => "success", - "paths" => $view->__toString(), - "form" => $form->__toString())); + + message::success(t("Added path %path", array("path" => $path))); + server_add::check_config(); + url::redirect("admin/server_add"); } else { - $form->add_path->inputs->path->error("not_readable"); - print json_encode(array("result" => "error", "form" => $form->__toString())); + $form->add_path->path->add_error("not_readable", 1); } - } else { - print json_encode(array("result" => "error", "form" => $form->__toString())); } + $view = new Admin_View("admin.html"); + $view->content = new View("admin_server_add.html"); + $view->content->form = $form->render(); + $view->content->paths = array_keys($paths); + print $view; } public function remove_path() { access::verify_csrf(); - $path = $this->input->post("path"); + $path = $this->input->get("path"); $paths = unserialize(module::get_var("server_add", "authorized_paths")); unset($paths[$path]); + message::success(t("Removed path %path", array("path" => $path))); module::set_var("server_add", "authorized_paths", serialize($paths)); + server_add::check_config(); - $view = new View("server_add_dir_list.html"); - $view->paths = array_keys($paths); - - print $view; + url::redirect("admin/server_add"); } public function autocomplete() { @@ -86,7 +87,7 @@ class Admin_Server_Add_Controller extends Admin_Controller { array("id" => "gServerAddAdminForm")); $add_path = $form->group("add_path"); $add_path->input("path")->label(t("Path"))->rules("required") - ->error_messages("not_readable", t("The directory is not readable by the webserver")); + ->error_messages("not_readable", t("This directory is not readable by the webserver")); $add_path->submit("add")->value(t("Add Path")); return $form; diff --git a/modules/server_add/helpers/server_add.php b/modules/server_add/helpers/server_add.php new file mode 100644 index 00000000..e51d3d98 --- /dev/null +++ b/modules/server_add/helpers/server_add.php @@ -0,0 +1,32 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class server_add_Core { + static function check_config() { + $paths = unserialize(module::get_var("server_add", "authorized_paths")); + if (empty($paths)) { + site_status::warning( + t("Server Add needs configuration. <a href=\"%url\">Configure it now!</a>", + array("url" => url::site("/admin/server_add"))), + "server_add_configuration"); + } else { + site_status::clear("server_add_configuration"); + } + } +} diff --git a/modules/server_add/helpers/server_add_installer.php b/modules/server_add/helpers/server_add_installer.php index 0418ea15..26d8bd0d 100644 --- a/modules/server_add/helpers/server_add_installer.php +++ b/modules/server_add/helpers/server_add_installer.php @@ -28,18 +28,14 @@ class server_add_installer { module::set_version("server_add", 1); module::set_var("server_add", "authorized_paths", serialize(array())); - message::warning( - t("Server Add needs configuration. <a href=\"%url\">Configure it now!</a>", - array("url" => url::site("/admin/server_add")))); + + server_add::check_config(); } } static function uninstall() { access::delete_permission("server_add"); - $module = module::get("server_add"); - - // @todo remove this after the next alpha - module::delete("local_import"); module::delete("server_add"); + site_status::clear("server_add_configuration"); } } diff --git a/modules/server_add/js/admin.js b/modules/server_add/js/admin.js index c9654410..5440af2a 100644 --- a/modules/server_add/js/admin.js +++ b/modules/server_add/js/admin.js @@ -3,43 +3,6 @@ * */ $("document").ready(function() { - add_autocomplete(); - ajaxify_add_form(); - add_onclick(); -}); - -function add_autocomplete() { $("#gServerAddAdmin input:text").autocomplete( base_url.replace("__ARGS__", "admin/server_add/autocomplete"), {max: 256}); -} -function ajaxify_add_form(options) { - $("#gServerAddAdmin form").ajaxForm({ - dataType: "json", - success: function(data) { - if (data.form) { - $("#gServerAddAdmin form").replaceWith(data.form); - ajaxify_add_form(); - add_autocomplete(); - } - if (data.result == "success") { - $("#gNoAuthorizedPaths").css("display", "none"); - $("#gAuthorizedPath").html(data.paths); - add_onclick(); - } - } - }); -} - -function add_onclick() { - $(".gRemoveDir").click(function() { - var parent = $(this).parent(); - $.post( - base_url.replace("__ARGS__", "admin/local_import/remove_path"), - {csrf: csrf, - path: parent.text().replace(/^\s\s*/, "").replace(/\s\s*$/, "")}, - function(data, textStatus) { - $("#gAuthorizedPath").html(data); - add_onclick(); - }); - }); -} +}); diff --git a/modules/server_add/views/admin_server_add.html.php b/modules/server_add/views/admin_server_add.html.php new file mode 100644 index 00000000..e37b262c --- /dev/null +++ b/modules/server_add/views/admin_server_add.html.php @@ -0,0 +1,25 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<div id="gServerAddAdmin"> + <h2> + <?= t("Add From Server Admininstration") ?> + </h2> + <div id="gAuthorizedPath"> + <span><?= t("Authorized Paths") ?></span> + <ul id="gPathList"> + <? foreach ($paths as $id => $path): ?> + <li class="ui-icon-left"> + <a href="<?= url::site("admin/server_add/remove_path?path=$path&csrf=" . access::csrf_token()) ?>" + id="icon_<?= $id?>" + class="gRemoveDir ui-icon ui-icon-trash"> + X + </a> + <?= $path ?> + </li> + <? endforeach ?> + </ul> + <div id="gNoAuthorizedPaths" <? if (!empty($paths)): ?>style="display:none"<? endif ?>> + <span class="gWarning"><?= t("No Authorized image source paths defined") ?></span> + </div> + </div> + <?= $form ?> +</div> diff --git a/modules/server_add/views/server_add_admin.html.php b/modules/server_add/views/server_add_admin.html.php deleted file mode 100644 index 765feeb9..00000000 --- a/modules/server_add/views/server_add_admin.html.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php defined("SYSPATH") or die("No direct script access.") ?> -<div id="gServerAddAdmin"> - <h2> - <?= t("Add From Server Admininstration") ?> - </h2> - <div id="gAuthorizedPath"> - <?= $path_list ?> - </div> - <?= $add_form ?> -</div> diff --git a/modules/server_add/views/server_add_dir_list.html.php b/modules/server_add/views/server_add_dir_list.html.php deleted file mode 100644 index 762b1a4d..00000000 --- a/modules/server_add/views/server_add_dir_list.html.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php defined("SYSPATH") or die("No direct script access.") ?> -<span><?= t("Authorized Paths") ?></span> -<ul id="gPathList"> - <? foreach ($paths as $id => $path): ?> - <li class="ui-icon-left"> - <span id="icon_<?= $id?>" class="gRemoveDir ui-icon ui-icon-trash"></span> - <?= $path ?> - </li> - <? endforeach ?> -</ul> -<div id="gNoAuthorizedPaths" <? if (!empty($paths)): ?>style="display:none"<? endif ?>> - <span class="gWarning"><?= t("No Authorized image source paths defined") ?></span> -</div> |