summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-02-26 16:27:23 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-02-26 16:27:23 +0000
commitf6169047b12346f82aa3214337256b41c595cb8a (patch)
treeb8a61583fddfd94c48570c2e83f96191dc524f6a
parentc3fcd3a79bd2f171b15384ea0ff44677b0c7a730 (diff)
Fix up add from server:
1) Upload requests are serialized so we don't over load the server or get race conditions occurring. 2) new albums are created based on the file structure of the authorized path that is the source directory.
-rw-r--r--modules/local_import/controllers/local_import.php26
-rw-r--r--modules/local_import/helpers/local_import_theme.php12
-rw-r--r--modules/local_import/js/local_import.js19
-rw-r--r--modules/local_import/views/local_import_tree_dialog.html.php11
4 files changed, 32 insertions, 36 deletions
diff --git a/modules/local_import/controllers/local_import.php b/modules/local_import/controllers/local_import.php
index 7f98edb5..138b61b1 100644
--- a/modules/local_import/controllers/local_import.php
+++ b/modules/local_import/controllers/local_import.php
@@ -60,16 +60,14 @@ class Local_Import_Controller extends Controller {
$parent = ORM::factory("item", $id);
access::can("local_import", $item);
- if (!$parent->loaded) {
+ if (!$parent->is_album() && !$parent->loaded ) {
throw new Exception("@todo BAD_ALBUM");
}
$path = $this->input->post("path");
- $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);
@@ -79,25 +77,15 @@ class Local_Import_Controller extends Controller {
->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;
+ $album = album::create($parent, $path[$i], $path[$i], null, user::active()->id);
}
+ $parent = $album;
} else if (in_array($pathinfo["extension"], array("flv", "mp4"))) {
- $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)));
+ $movie = movie::create($parent, $source_path, basename($source_path),
+ basename($source_path), null, user::active()->id);
} 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)));
+ $photo = photo::create($parent, $source_path, basename($source_path),
+ basename($source_path), null, user::active()->id);
}
}
}
diff --git a/modules/local_import/helpers/local_import_theme.php b/modules/local_import/helpers/local_import_theme.php
index d37b8ad3..03c4f179 100644
--- a/modules/local_import/helpers/local_import_theme.php
+++ b/modules/local_import/helpers/local_import_theme.php
@@ -33,12 +33,12 @@ class local_import_theme_Core {
return implode("\n", $head);
}
- static function head($theme) {
- $head[] = "<link media=\"screen, projection\" rel=\"stylesheet\" type=\"text/css\" href=\"" .
- url::file("modules/local_import/css/local_import.css") . "\" />";
+ //static function head($theme) {
+ //$head[] = "<link media=\"screen, projection\" rel=\"stylesheet\" type=\"text/css\" href=\"" .
+ // url::file("modules/local_import/css/local_import.css") . "\" />";
- $head[] = html::script("modules/local_import/js/local_import.js");
+ //$head[] = html::script("modules/local_import/js/local_import.js");
- return implode("\n", $head);
- }
+ //return implode("\n", $head);
+ //}
} \ No newline at end of file
diff --git a/modules/local_import/js/local_import.js b/modules/local_import/js/local_import.js
index 2e84c0d6..66952d63 100644
--- a/modules/local_import/js/local_import.js
+++ b/modules/local_import/js/local_import.js
@@ -1,3 +1,11 @@
+$("#gLocalImport").ready(function() {
+ $("#gLocalImport :submit").click(function(event) {
+ do_import(this, event);
+ });
+ $("#gProgressBar").progressbar();
+ $("#gLocalImport ul").css("display", "block");
+});
+
function open_close_branch(icon, event) {
var parent = icon.parentNode;
var children = $(parent).find(".gCheckboxTree");
@@ -15,8 +23,8 @@ function open_close_branch(icon, event) {
} else {
$(icon).addClass("ui-icon-minus");
$(icon).removeClass("ui-icon-plus");
- $(parent).children("ul").slideDown("fast");
}
+ $(parent).children("ul").slideDown("fast");
} else {
$(icon).addClass("ui-icon-plus");
$(icon).removeClass("ui-icon-minus");
@@ -96,8 +104,13 @@ function process_checkbox(checkbox) {
}
function process_file(li_element, parms) {
- var url = $("#gLocalImport form").attr("action");
- $.post(url, parms, function(data, status) {
+ $.ajax({async: false,
+ success: function(data, status) {
+ },
+ data: parms,
+ dataType: "html",
+ type: "POST",
+ url: $("#gLocalImport form").attr("action")
});
current++;
$("#gProgressBar").progressbar('value', current / process_length * 100);
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 1cd28ec6..2f432a1e 100644
--- a/modules/local_import/views/local_import_tree_dialog.html.php
+++ b/modules/local_import/views/local_import_tree_dialog.html.php
@@ -1,12 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
-<script type="text/javascript">
-$("#gLocalImport").ready(function() {
- $("#gLocalImport :submit").click(function(event) {
- do_import(this, event);
- });
- $("#gProgressBar").progressbar();
- $("#gLocalImport ul").css("display", "block");
-});</script>
+<link media="screen, projection" rel="stylesheet" type="text/css" href="<?= url::file("modules/local_import/css/local_import.css") ?>" />
+<?= html::script("modules/local_import/js/local_import.js"); ?>
+
<div id="gLocalImport">
<h1 style="display: none;"><?= sprintf(t("Import Photos to '%s'"), $album_title) ?></h1>