summaryrefslogtreecommitdiff
path: root/modules/organize
diff options
context:
space:
mode:
Diffstat (limited to 'modules/organize')
-rw-r--r--modules/organize/controllers/organize.php58
-rw-r--r--modules/organize/helpers/organize_task.php51
-rw-r--r--modules/organize/js/organize.js110
-rw-r--r--modules/organize/js/organize_init.js6
-rw-r--r--modules/organize/views/organize.html.php2
-rw-r--r--modules/organize/views/organize_thumb_grid.html.php2
6 files changed, 206 insertions, 23 deletions
diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php
index 8ec3f1cf..ec685353 100644
--- a/modules/organize/controllers/organize.php
+++ b/modules/organize/controllers/organize.php
@@ -83,4 +83,62 @@ class Organize_Controller extends Controller {
}
return $v->__toString();
}
+
+ function rearrangeStart($id) {
+ access::verify_csrf();
+ $items = $this->input->post("item");
+
+ $task_def = Task_Definition::factory()
+ ->callback("organize_task::rearrange")
+ ->description(t("Rearrange the order of albums and photos"))
+ ->name(t("Rearrange"));
+ $task = task::create($task_def, array("items" => $items, "position" => 0, "batch" =>
+ ceil(count($items) * .1)));
+
+ batch::start();
+ print json_encode(array("result" => "started",
+ "task" => array(
+ "id" => $task->id,
+ "percent_complete" => $task->percent_complete,
+ "status" => $task->status,
+ "done" => $task->done)));
+ }
+
+ function rearrangeRun($id, $task_id) {
+ access::verify_csrf();
+
+ $task = task::run($task_id);
+
+ print json_encode(array("result" => $task->done ? $task->state : "in_progress",
+ "task" => array(
+ "id" => $task->id,
+ "percent_complete" => $task->percent_complete,
+ "status" => $task->status,
+ "done" => $task->done)));
+ }
+
+ function rearrangeFinish($id, $task_id) {
+ access::verify_csrf();
+
+ $task = ORM::factory("task", $task_id);
+
+ if (!$task->done) {
+ message::warning(t("Rearrange album was was cancelled prior to completion"));
+ } else {
+ // @todo set the sort order to weight;
+ }
+
+ batch::stop();
+ print json_encode(array("result" => "success"));
+ }
+
+ function rearrangePause($id, $task_id) {
+ access::verify_csrf();
+
+ $task = ORM::factory("task", $task_id);
+
+ message::warning(t("Rearrange album was cancelled prior to completion"));
+ batch::stop();
+ print json_encode(array("result" => "success"));
+ }
} \ No newline at end of file
diff --git a/modules/organize/helpers/organize_task.php b/modules/organize/helpers/organize_task.php
new file mode 100644
index 00000000..8c73acde
--- /dev/null
+++ b/modules/organize/helpers/organize_task.php
@@ -0,0 +1,51 @@
+<?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 organize_task_Core {
+ static function available_tasks() {
+ // Return empty array so nothing appears in the maintenance screen
+ return array();
+ }
+
+ static function rearrange($task) {
+ $context = unserialize($task->context);
+
+ try {
+ $stop = $context["position"] + $context["batch"];
+ $sql = "";
+ for (; $context["position"] < $stop; $context["position"]++ ) {
+ $id = $context["items"][$context["position"]];
+ $sql .= "Update {items} set weight = {$context["position"]} where id=$id;";
+ }
+ if (!empty($sql)) {
+ Kohana::log("debug", $sql);
+ $db = Database::instance()->query($sql);
+ Kohana::log("debug", Kohana::debug($db));
+ }
+ $task->state = "success";
+ } catch(Exception $e) {
+ $tast->status = $e->getMessage();
+ $task->state = "error";
+ }
+ $task->context = serialize($context);
+ $total = count($context["items"]);
+ $task->percent_complete = $context["position"] / (float)$total * 100;
+ $task->done = $context["position"] == $total;
+ }
+} \ No newline at end of file
diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js
index 7ab4d19c..51d5fea9 100644
--- a/modules/organize/js/organize.js
+++ b/modules/organize/js/organize.js
@@ -1,8 +1,11 @@
/*
* @todo Trap resize of dialog and resize the child areas (tree, grid and edit form)
+ * @todo create the dialog close method and reload the page on exit.
*/
var url;
var height;
+var paused = false;
+var task = null;
// **************************************************************************
// JQuery UI Widgets
@@ -10,8 +13,10 @@ var height;
var draggable = {
cancel: ".gMicroThumbContainer:not(.ui-selected)",
handle: ".gMicroThumbContainer.ui-selected",
+ revert: true,
zindex: 2000,
helper: function(event, ui) {
+ console.dir(ui);
$("#gMicroThumbPanel").append("<div id=\"gDragHelper\"><ul></ul></div>");
var beginTop = event.pageY;
var beginLeft = event.pageX;
@@ -49,7 +54,10 @@ var draggable = {
});
return $("#gDragHelper");
},
- stop: function(event) {
+ stop: function(event, ui) {
+ $("#gDragHelper li").each(function(i) {
+ $("#thumb_" + $(this).attr("ref")).show();
+ });
$(".gMicroThumbContainer.ui-selected").css("z-index", null);
$("#gDragHelper").remove();
$("#gPlaceHolder").remove();
@@ -61,27 +69,29 @@ var droppable = {
tolerance: "pointer",
drop: function(event, ui) {
$("#gDragHelper").hide();
- var dropTarget;
- if (event.pageX < $("#gMicroThumbGrid li:visible:first").offset().left ||
- event.pageY < $("#gMicroThumbGrid li:visible:first").offset().top) {
- dropTarget = 1;
- } else if (event.pageX > $("#gMicroThumbGrid li:visible:last").offset().left + 100 ||
- event.pageY > $("#gMicroThumbGrid li:visible:last").offset().top + 100) {
- dropTarget = 2;
- } else {
- dropTarget = 0;
- }
- $("#gDragHelper li").each(function(i) {
- switch (dropTarget) {
- case 0:
- case 1:
- $("#gPlaceHolder").before($("#thumb_" + $(this).attr("ref")).show());
- break;
- case 2:
- $("#gPlaceHolder").before($("#thumb_" + $(this).attr("ref")).show());
- break;
+ $("#gPlaceHolder").hide();
+ var newOrder = "";
+ $("#gMicroThumbGrid .gMicroThumbContainer").each(function(i) {
+ if ($(this).attr("id") == "gPlaceHolder") {
+ $("#gDragHelper li").each(function(i) {
+ newOrder += "&item[]=" + $(this).attr("ref");
+ });
+ } else if ($(this).css("display") != "none") {
+ newOrder += "&item[]=" + $(this).attr("ref");
+ } else {
+ // If its not displayed then its one of the ones being moved so ignore.
}
});
+ $("#gDragHelper li").each(function(i) {
+ $("#gPlaceHolder").before($("#thumb_" + $(this).attr("ref")).show());
+ });
+ $.ajax({
+ data: newOrder,
+ dataType: "json",
+ success: startRearrangeCallback,
+ type: "POST",
+ url: get_url("organize/rearrangeStart")
+ });
}
};
@@ -122,7 +132,7 @@ var onMicroThumbContainerClick = function(event) {
// MicroThumbContainer mousemove
var onMicroThumbContainerMousemove = function(event) {
if ($("#gDragHelper").length > 0 && $(this).attr("id") != "gPlaceHolder") {
- if (event.pageX < this.offsetLeft + this.offsetWidth / 2) {
+ if (event.pageX < $(this).offset().left + $(this).width() / 2) {
$(this).before($("#gPlaceHolder"));
} else {
$(this).after($("#gPlaceHolder"));
@@ -164,6 +174,40 @@ var getMicroThumbsCallback = function(json, textStatus) {
$(".gMicroThumbContainer").draggable(draggable);
}
};
+
+var startRearrangeCallback = function (data, textStatus) {
+ // @todo Show progressbar and pause/cancel
+ task = data.task;
+ var done = false;
+ while (!done && !paused) {
+ $.ajax({async: false,
+ success: function(data, textStatus) {
+ //$(".gProgressBar").progressbar("value", data.task.percent_complete);
+ done = data.task.done;
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
+ paused = true;
+ displayAjaxError(XMLHttpRequest.responseText);
+ },
+ dataType: "json",
+ type: "POST",
+ url: get_url("organize/rearrangeRun", task.id)
+ });
+ }
+ if (!paused) {
+ $.ajax({async: false,
+ success: function(data, textStatus) {
+ },
+ dataType: "json",
+ type: "POST",
+ url: get_url("organize/rearrangeFinish", task.id)
+ });
+ } else {
+ //$("#gServerAdd #gServerAddButton").show(); @todo change to continue button.
+ //$("#gServerAdd #gServerPauseButton").hide();
+ }
+};
+
// **************************************************************************
/**
@@ -187,6 +231,10 @@ function organize_dialog_init() {
$("#gDialog").dialog('option', 'title', $("#gDialog fieldset legend:eq(0)").html());
}
+ $("#gDialog").bind("organize_close", function(target) {
+ document.location.reload();
+ });
+
height -= 2 * parseFloat($("#gDialog").css("padding-top"));
height -= 2 * parseFloat($("#gDialog").css("padding-bottom"));
height -= $("#gMicroThumbPanel").position().top;
@@ -255,6 +303,15 @@ function organizeOpenFolder(event) {
event.preventDefault();
}
+function get_url(uri, task_id) {
+ var url = rearrangeUrl;
+ url = url.replace("__URI__", uri);
+ url = url.replace("__TASK_ID__", !task_id ? "" : "/" + task_id);
+ return url;
+}
+
+// **************************************************************************
+// Functions that should probably be in a gallery namespace
function getViewportSize() {
return {
width : function() {
@@ -270,3 +327,14 @@ function getViewportSize() {
};
}
+function displayAjaxError(error) {
+ $("body").append("<div id=\"gAjaxError\" title=\"" + FATAL_ERROR + "\">" + error + "</div>");
+ $("#gAjaxError").dialog({
+ autoOpen: true,
+ autoResize: false,
+ modal: true,
+ resizable: true,
+ width: 610,
+ height: $("#gDialog").height()
+ });
+}
diff --git a/modules/organize/js/organize_init.js b/modules/organize/js/organize_init.js
index faa725d3..efe21af4 100644
--- a/modules/organize/js/organize_init.js
+++ b/modules/organize/js/organize_init.js
@@ -10,7 +10,10 @@ $("document").ready(function() {
autoResize: false,
modal: true,
resizable: true,
- close: closeDialog,
+ close: function () {
+ $("#gDialog").trigger("organize_close");
+ $("#gDialog").dialog("destroy").remove();
+ },
zIndex: 75
});
@@ -23,3 +26,4 @@ $("document").ready(function() {
});
});
+
diff --git a/modules/organize/views/organize.html.php b/modules/organize/views/organize.html.php
index 6b9eb3c6..c2b2070e 100644
--- a/modules/organize/views/organize.html.php
+++ b/modules/organize/views/organize.html.php
@@ -1,8 +1,10 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<!-- ?= html::script("modules/organize/js/organize.js") ? -->
<script>
+ var FATAL_ERROR = "<?= t("Fatal Error") ?>";
var item_id = <?= $item->id ?>;
var csrf = "<?= $csrf ?>";
+ var rearrangeUrl = "<?= url::site("__URI__/{$item->id}__TASK_ID__?csrf=$csrf") ?>";
$("#doc3").ready(function() {
organize_dialog_init();
});
diff --git a/modules/organize/views/organize_thumb_grid.html.php b/modules/organize/views/organize_thumb_grid.html.php
index 484d1260..64d8aaf3 100644
--- a/modules/organize/views/organize_thumb_grid.html.php
+++ b/modules/organize/views/organize_thumb_grid.html.php
@@ -4,7 +4,7 @@
<? if ($child->is_album()): ?>
<? $item_class = "gAlbum"; ?>
<? endif ?>
-<li id="thumb_<?= $child->id ?>" class="gMicroThumbContainer" ref="<?= $child->id ?>" ordinal="<?= $offset + $i ?>">
+<li id="thumb_<?= $child->id ?>" class="gMicroThumbContainer" ref="<?= $child->id ?>">
<div id="gMicroThumb-<?= $child->id ?>" class="gMicroThumb <?= $item_class ?>">
<?= $child->thumb_tag(array("class" => "gThumbnail"), $thumbsize, true) ?>
</div>