summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/local_import/controllers/local_import.php51
-rw-r--r--modules/local_import/css/local_import.css7
-rw-r--r--modules/local_import/js/local_import.js85
-rw-r--r--modules/local_import/views/local_import_tree.html.php4
-rw-r--r--modules/local_import/views/local_import_tree_dialog.html.php7
5 files changed, 116 insertions, 38 deletions
diff --git a/modules/local_import/controllers/local_import.php b/modules/local_import/controllers/local_import.php
index 94a86012..80dc0215 100644
--- a/modules/local_import/controllers/local_import.php
+++ b/modules/local_import/controllers/local_import.php
@@ -44,6 +44,7 @@ class Local_Import_Controller extends Controller {
access::verify_csrf();
$path = $this->input->post("path");
+ $path = implode("/", $this->input->post("path"));
if (!is_readable($path)) {
kohana::show_404();
}
@@ -64,18 +65,40 @@ class Local_Import_Controller extends Controller {
}
$path = $this->input->post("path");
- $pathinfo = pathinfo($path);
- set_time_limit(30);
- if ($pathinfo["extension"] == "flv") {
- $movie = movie::create($parent, $path, basename($path), basename($path));
- log::success("content", t("Added a movie"),
- html::anchor("movies/{$movie->id}", t("view movie")));
- message::success(t("Added movie %movie_title", array("movie_title" => $movie->title)));
- } else {
- $photo = photo::create($parent, $path, basename($path), basename($path));
- log::success("content", t("Added a photo"),
- html::anchor("photos/{$photo->id}", t("view photo")));
- message::success(t("Added photo %photo_title", array("photo_title" => $photo->title)));
+
+ $base_path = $parent->file_path();
+ $source_path = $path[0];
+ for ($i = 1; $i < count($path); $i++) { // skip the first path
+ $base_path .= "/$path[$i]";
+ $source_path .= "/$path[$i]";
+ $pathinfo = pathinfo($source_path);
+ set_time_limit(30);
+ if (is_dir($source_path)) {
+ $album = ORM::factory("item")
+ ->where("name", $path[$i])
+ ->where("parent_id", $parent->id)
+ ->find();
+ if (!$album->loaded) {
+ $parent = album::create($parent, $path[$i], $path[$i]);
+ log::success("content", t("Added album"),
+ html::anchor("albums/{$parent->id}", t("view album")));
+ message::success(t("Added album %album_title", array("album_title" => $parent->title)));
+ } else {
+ $parent = $album;
+ }
+ } else if ($pathinfo["extension"] == "flv") {
+ $movie =
+ movie::create($parent, $source_path, basename($source_path), basename($source_path));
+ log::success("content", t("Added a movie"),
+ html::anchor("movies/{$movie->id}", t("view movie")));
+ message::success(t("Added movie %movie_title", array("movie_title" => $movie->title)));
+ } else {
+ $photo =
+ photo::create($parent, $source_path, basename($source_path), basename($source_path));
+ log::success("content", t("Added a photo"),
+ html::anchor("photos/{$photo->id}", t("view photo")));
+ message::success(t("Added photo %photo_title", array("photo_title" => $photo->title)));
+ }
}
}
@@ -92,8 +115,8 @@ class Local_Import_Controller extends Controller {
$extension = strtolower(substr(strrchr($file, '.'), 1));
// Make sure the file is readable
if (is_readable($full_path) &&
- in_array($extension, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, "jpg", IMAGETYPE_PNG, "flv"))) {
- $file_list[$file] = array("path" => $full_path);
+ in_array($extension, array("IMAGETYPE_GIF", "JPEG", "jpg", "PNG", "flv"))) {
+ $file_list[$file] = array("path" => $full_path, "is_dir" => false);
}
}
}
diff --git a/modules/local_import/css/local_import.css b/modules/local_import/css/local_import.css
index f51b3d68..23c2449d 100644
--- a/modules/local_import/css/local_import.css
+++ b/modules/local_import/css/local_import.css
@@ -1,3 +1,7 @@
+.gCheckboxTree {
+ display: none;
+}
+
.gCheckboxTree input {
display: inline;
}
@@ -18,6 +22,9 @@
#gProgressBar {
visibility: hidden;
height: 1em;
+ width: 100%;
+ margin-top: 0.5em;
+ display: inline-block;
}
#gLocalImport #gLocalImportTree {
diff --git a/modules/local_import/js/local_import.js b/modules/local_import/js/local_import.js
index 8fadf926..2e84c0d6 100644
--- a/modules/local_import/js/local_import.js
+++ b/modules/local_import/js/local_import.js
@@ -1,17 +1,16 @@
function open_close_branch(icon, event) {
var parent = icon.parentNode;
- //var label = $(parent).find("label");
var children = $(parent).find(".gCheckboxTree");
var closed = $(icon).hasClass("ui-icon-plus");
if (closed) {
if (children.length == 0) {
- load_children( $(icon).attr("ref"), function(data, textStatus) {
- $(parent).append(data);
- $(icon).addClass("ui-icon-minus");
- $(icon).removeClass("ui-icon-plus");
- var checkbox = $(parent).find(":checkbox")[0];
- checkbox_click(checkbox, null);
+ load_children(icon, function(data, textStatus) {
+ $(parent).append(data);
+ $(icon).addClass("ui-icon-minus");
+ $(icon).removeClass("ui-icon-plus");
+ var checkbox = $(parent).find(":checkbox")[0];
+ checkbox_click(checkbox, null);
});
} else {
$(icon).addClass("ui-icon-minus");
@@ -29,32 +28,78 @@ function checkbox_click(checkbox, event) {
var parents = $(checkbox).parents("li");
var parent = parents.get(0);
$(parent).find(".gCheckboxTree :checkbox").attr("checked", checkbox.checked);
- var checked = $("#gLocalImport .gFile :checkbox[checked]");
+ var checked = $("#gLocalImport :checkbox[checked]");
$("#gLocalImport form :submit").attr("disabled", checked.length == 0);
}
-function load_children(path, callback) {
+function load_children(icon, callback) {
var csrf = $("#gLocalImport form :hidden[name='csrf']")[0].value;
var base_url = $("#gLocalImport form :hidden[name='base_url']")[0].value;
- $.post(base_url + "local_import/children",
- {csrf: csrf, path: path}, callback);
+ var parms = "&csrf=" + csrf;
+ var parents = $(icon).parents("li");
+ for (i=parents.length - 1; i >= 0; i--) {
+ parms += "&path[]=" + $(parents[i]).children("span").attr("ref");
+ }
+ $.ajax({async: false,
+ success: callback,
+ data: parms,
+ dataType: "html",
+ type: "POST",
+ url: base_url + "local_import/children"
+ });
}
+var current = 0;
+var process_length = 0;
function do_import(submit, event) {
event.preventDefault();
$("#gProgressBar").progressbar('value', 0);
$("#gProgressBar").css("visibility", "visible");
- var check_list = $("#gLocalImport .gFile :checkbox[checked]");
- var current = 0;
- var csrf = $("#gLocalImport form :hidden[name='csrf']")[0].value;
- var url = $("#gLocalImport form").attr("action");
+ var check_list = $("#gLocalImport :checkbox[checked]");
+ process_length = check_list.length;
+ current = 0;
$.each(check_list, function () {
- var path = $(this).val();
- $.post(url, {csrf: csrf, path: path}, function(data, status) {
- });
- current++;
- $("#gProgressBar").progressbar('value', current / check_list.length * 100);
+ process_checkbox(this);
});
document.location.reload();
return false;
}
+
+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--) {
+ parms += "&path[]=" + $(parents[i]).children("span").attr("ref");
+ }
+ parms += "&path[]=" + $(checkbox).val();
+
+ var parent = parents[0];
+ if ($(parent).hasClass("gFile")) {
+ process_file(parents[0], parms);
+ } else if ($(parent).hasClass("gDirectory") && $(parents[0]).find(".gCheckboxTree").length == 0) {
+ // If it is a directory and retrieve the children and process them
+ var icon = $(parent).children("span")[0];
+ load_children(icon, function(data, textStatus) {
+ $(parent).append(data);
+ $(icon).addClass("ui-icon-plus");
+ checkbox_click(checkbox, null);
+ var boxes = $(parent).find(".gCheckboxTree :checkbox[checked]");
+ process_length += boxes.length;
+ $.each(boxes, function () {
+ process_checkbox(this);
+ });
+ });
+ current++;
+ $("#gProgressBar").progressbar('value', current / process_length * 100);
+ }
+}
+
+function process_file(li_element, parms) {
+ var url = $("#gLocalImport form").attr("action");
+ $.post(url, parms, function(data, status) {
+ });
+ current++;
+ $("#gProgressBar").progressbar('value', current / process_length * 100);
+}
+
diff --git a/modules/local_import/views/local_import_tree.html.php b/modules/local_import/views/local_import_tree.html.php
index e515852a..b028cfa1 100644
--- a/modules/local_import/views/local_import_tree.html.php
+++ b/modules/local_import/views/local_import_tree.html.php
@@ -14,9 +14,9 @@ $("#<?= $uid ?>").ready(function() {
<? foreach ($data as $file => $file_info): ?>
<li class="<?= empty($file_info["is_dir"]) ? "gFile" : "gDirectory gCollapsed ui-icon-left" ?>">
<? if (!empty($file_info["is_dir"])): ?>
- <span class="ui-icon ui-icon-plus" ref="<?= $file_info["path"] ?>"></span>
+ <span class="ui-icon ui-icon-plus" ref="<?= $file ?>"></span>
<? endif ?>
- <?= "<label>" . form::checkbox("checkbox", $file_info["path"]) . " $file</label>" ?>
+ <?= "<label>" . form::checkbox("checkbox", $file) . " $file</label>" ?>
</li>
<? endforeach ?>
</ul>
diff --git a/modules/local_import/views/local_import_tree_dialog.html.php b/modules/local_import/views/local_import_tree_dialog.html.php
index e553b54b..1cd28ec6 100644
--- a/modules/local_import/views/local_import_tree_dialog.html.php
+++ b/modules/local_import/views/local_import_tree_dialog.html.php
@@ -5,6 +5,7 @@ $("#gLocalImport").ready(function() {
do_import(this, event);
});
$("#gProgressBar").progressbar();
+ $("#gLocalImport ul").css("display", "block");
});</script>
<div id="gLocalImport">
<h1 style="display: none;"><?= sprintf(t("Import Photos to '%s'"), $album_title) ?></h1>
@@ -21,8 +22,10 @@ $("#gLocalImport").ready(function() {
<div id="gLocalImportTree" >
<?= $tree ?>
</div>
- <?= form::submit(array("id" => "gImportButton", "name" => "import", "disabled" => true),
+ <span>
+ <?= form::submit(array("id" => "gImportButton", "name" => "import", "disabled" => true, "class" => "submit"),
t("Import")) ?>
- <div id="gProgressBar"></div>
+ </span>
<?= form::close() ?>
+ <div id="gProgressBar" ></div>
</div>