diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-02-28 20:12:54 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-02-28 20:12:54 +0000 |
commit | bed1bb48f33c1c20decb6b592b1d713f5c9fb48e (patch) | |
tree | 24ede306b64a9cc56634680bb504b1092ccb6145 | |
parent | c04ff8e02f01691dc2e325efc523e43f3aebaf95 (diff) |
The scaffolding, simple_uploader and local_import now call two new
events: start_add_batch and end_add_batch. The parameter is a batch
id which is generated on the first add request. The protocol is call
the add_photo as many times as required and then call finish when
done.
Also renamed the add method in local_import to add_photo so it is
consistent with simple_uploader
-rw-r--r-- | core/controllers/scaffold.php | 6 | ||||
-rw-r--r-- | core/controllers/simple_uploader.php | 10 | ||||
-rw-r--r-- | modules/local_import/controllers/local_import.php | 18 | ||||
-rw-r--r-- | modules/local_import/js/local_import.js | 14 |
4 files changed, 43 insertions, 5 deletions
diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php index cdbe0f95..2cdff2d3 100644 --- a/core/controllers/scaffold.php +++ b/core/controllers/scaffold.php @@ -218,6 +218,8 @@ class Scaffold_Controller extends Template_Controller { throw new Exception("@todo BAD_ALBUM"); } + $batch_id = mt_rand(); + module::event("start_add_batch", $batch_id); cookie::set("add_photos_path", $path); $photo_count = 0; foreach (glob("$path/*.[Jj][Pp][Gg]") as $file) { @@ -225,6 +227,7 @@ class Scaffold_Controller extends Template_Controller { photo::create($parent, $file, basename($file), basename($file)); $photo_count++; } + module::event("end_add_batch", $batch_id); if ($photo_count > 0) { log::success("content", "(scaffold) Added $photo_count photos", @@ -241,6 +244,8 @@ class Scaffold_Controller extends Template_Controller { $test_images = glob(APPPATH . "tests/images/*.[Jj][Pp][Gg]"); + $batch_id = mt_rand(); + module::event("start_add_batch", $batch_id); $album_count = $photo_count = 0; for ($i = 0; $i < $count; $i++) { set_time_limit(30); @@ -264,6 +269,7 @@ class Scaffold_Controller extends Template_Controller { $photo_count++; } } + module::event("end_add_batch", $batch_id); if ($photo_count > 0) { log::success("content", "(scaffold) Added $photo_count photos"); diff --git a/core/controllers/simple_uploader.php b/core/controllers/simple_uploader.php index b56bce16..005071b0 100644 --- a/core/controllers/simple_uploader.php +++ b/core/controllers/simple_uploader.php @@ -48,6 +48,12 @@ class Simple_Uploader_Controller extends Controller { $file_validation = new Validation($_FILES); $file_validation->add_rules("file", "upload::valid", "upload::type[gif,jpg,png,flv,mp4]"); if ($file_validation->validate()) { + $batch_id = Session::instance()->get("batch_id"); + if (empty($batch_id)) { + $batch_id = mt_rand(); + module::event("start_add_batch", $batch_id); + Session::instance()->set("batch_id", $batch_id); + } $temp_filename = upload::save("file"); $title = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds $path_info = pathinfo($temp_filename); @@ -64,6 +70,10 @@ class Simple_Uploader_Controller extends Controller { } public function finish() { + $batch_id = Session::instance()->get_once("batch_id"); + if (!empty($batch_id)) { + module::event("end_add_batch", $batch_id); + } print json_encode(array("result" => "success")); } } diff --git a/modules/local_import/controllers/local_import.php b/modules/local_import/controllers/local_import.php index 138b61b1..2b8248a4 100644 --- a/modules/local_import/controllers/local_import.php +++ b/modules/local_import/controllers/local_import.php @@ -25,7 +25,7 @@ class Local_Import_Controller extends Controller { access::can("local_import", $item); $view = new View("local_import_tree_dialog.html"); - $view->action = url::site("local_import/add/$id"); + $view->action = url::site("local_import/add_photo/$id"); $view->hidden = array("csrf" => access::csrf_token(), "base_url" => url::base(true)); $view->parents = $item->parents(); $view->album_title = $item->title; @@ -55,7 +55,7 @@ class Local_Import_Controller extends Controller { print $tree; } - function add($id) { + function add_photo($id) { access::verify_csrf(); $parent = ORM::factory("item", $id); @@ -65,6 +65,12 @@ class Local_Import_Controller extends Controller { } $path = $this->input->post("path"); + $batch_id = Session::instance()->get("batch_id"); + if (empty($batch_id)) { + $batch_id = mt_rand(); + module::event("start_add_batch", $batch_id); + Session::instance()->set("batch_id", $batch_id); + } $source_path = $path[0]; for ($i = 1; $i < count($path); $i++) { // skip the first path @@ -90,6 +96,14 @@ class Local_Import_Controller extends Controller { } } + public function finish() { + $batch_id = Session::instance()->get_once("batch_id"); + if (!empty($batch_id)) { + module::event("end_add_batch", $batch_id); + } + print json_encode(array("result" => "success")); + } + private function _get_children($path) { $file_list = array(); $files = scandir($path); diff --git a/modules/local_import/js/local_import.js b/modules/local_import/js/local_import.js index 66952d63..0fd37b00 100644 --- a/modules/local_import/js/local_import.js +++ b/modules/local_import/js/local_import.js @@ -45,7 +45,7 @@ function load_children(icon, callback) { var base_url = $("#gLocalImport form :hidden[name='base_url']")[0].value; var parms = "&csrf=" + csrf; var parents = $(icon).parents("li"); - for (i=parents.length - 1; i >= 0; i--) { + for (var i=parents.length - 1; i >= 0; i--) { parms += "&path[]=" + $(parents[i]).children("span").attr("ref"); } $.ajax({async: false, @@ -69,7 +69,15 @@ function do_import(submit, event) { $.each(check_list, function () { process_checkbox(this); }); - document.location.reload(); + var base_url = $("#gLocalImport form :hidden[name='base_url']")[0].value; + $.ajax({async: false, + success: function(data, textStatus) { + document.location.reload(); + }, + dataType: "json", + type: "POST", + url: base_url + "local_import/finish" + }); return false; } @@ -77,7 +85,7 @@ function process_checkbox(checkbox) { var parents = $(checkbox).parents("li"); var csrf = $("#gLocalImport form :hidden[name='csrf']")[0].value; var parms = "&csrf=" + csrf; - for (i=parents.length - 1; i > 0; i--) { + for (var i=parents.length - 1; i > 0; i--) { parms += "&path[]=" + $(parents[i]).children("span").attr("ref"); } parms += "&path[]=" + $(checkbox).val(); |