diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-04-21 06:04:03 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-04-21 06:04:03 +0000 |
commit | c94fc344e853ac00b83414f2f9175dad8aebba97 (patch) | |
tree | 51d677a6efa0bcc2f0624a13e82bd77168fe5f2c | |
parent | 201e8cdf7046937eef0e53542d777bf67c496054 (diff) |
Added progress bar and pause and continue functionality to rearrange
-rw-r--r-- | modules/organize/controllers/organize.php | 18 | ||||
-rw-r--r-- | modules/organize/helpers/organize_task.php | 7 | ||||
-rw-r--r-- | modules/organize/js/organize.js | 35 | ||||
-rw-r--r-- | modules/organize/views/organize.html.php | 9 |
4 files changed, 39 insertions, 30 deletions
diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index ec685353..58ca73a2 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -21,7 +21,7 @@ class Organize_Controller extends Controller { private static $_MICRO_THUMB_SIZE = 90; private static $_MICRO_THUMB_PADDING = 5; - public function index($item_id=1) { + function index($item_id=1) { $item = ORM::factory("item", $item_id); $root = ($item->id == 1) ? $item : ORM::factory("item", 1); @@ -36,7 +36,7 @@ class Organize_Controller extends Controller { print $v; } - public function content($item_id) { + function content($item_id) { $item = ORM::factory("item", $item_id); $width = $this->input->get("width"); $height = $this->input->get("height"); @@ -54,14 +54,14 @@ class Organize_Controller extends Controller { "data" => $v->__toString())); } - public function header($item_id) { + function header($item_id) { $item = ORM::factory("item", $item_id); print json_encode(array("title" => $item->title, "description" => empty($item->description) ? "" : $item->description)); } - public function tree($item, $parent) { + function tree($item, $parent) { $albums = ORM::factory("item") ->where(array("parent_id" => $parent->id, "type" => "album")) ->orderby(array("title" => "ASC")) @@ -105,6 +105,7 @@ class Organize_Controller extends Controller { } function rearrangeRun($id, $task_id) { + Kohana::log("debug", "rearrangeRun($id, $task_id)"); access::verify_csrf(); $task = task::run($task_id); @@ -118,14 +119,15 @@ class Organize_Controller extends Controller { } function rearrangeFinish($id, $task_id) { + Kohana::log("debug", "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; + if ($task->done) { + $item = ORM::factory("item", $id); + $item->sort_column = "weight"; + $item->save(); } batch::stop(); diff --git a/modules/organize/helpers/organize_task.php b/modules/organize/helpers/organize_task.php index 735a0831..f923fdc7 100644 --- a/modules/organize/helpers/organize_task.php +++ b/modules/organize/helpers/organize_task.php @@ -28,13 +28,10 @@ class organize_task_Core { 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)) { - $db = Database::instance()->query($sql); + Database::instance() + ->query("Update {items} set weight = {$context["position"]} where id=$id;"); } $task->state = "success"; } catch(Exception $e) { diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js index 51d5fea9..095641e9 100644 --- a/modules/organize/js/organize.js +++ b/modules/organize/js/organize.js @@ -176,14 +176,18 @@ var getMicroThumbsCallback = function(json, textStatus) { }; var startRearrangeCallback = function (data, textStatus) { - // @todo Show progressbar and pause/cancel - task = data.task; + if (!paused) { + $("#gDialog #ft").css("visibility", "visible"); + $(".gProgressBar").progressbar("value", 0); + task = data.task; + } var done = false; + paused = false; while (!done && !paused) { $.ajax({async: false, success: function(data, textStatus) { - //$(".gProgressBar").progressbar("value", data.task.percent_complete); - done = data.task.done; + $(".gProgressBar").progressbar("value", data.task.percent_complete); + done = data.task.done; }, error: function(XMLHttpRequest, textStatus, errorThrown) { paused = true; @@ -195,6 +199,7 @@ var startRearrangeCallback = function (data, textStatus) { }); } if (!paused) { + $("#gDialog #ft").css("visibility", "hidden"); $.ajax({async: false, success: function(data, textStatus) { }, @@ -202,9 +207,6 @@ var startRearrangeCallback = function (data, textStatus) { type: "POST", url: get_url("organize/rearrangeFinish", task.id) }); - } else { - //$("#gServerAdd #gServerAddButton").show(); @todo change to continue button. - //$("#gServerAdd #gServerPauseButton").hide(); } }; @@ -254,6 +256,18 @@ function organize_dialog_init() { $("#gMicroThumbPanel").droppable(droppable); $("#gMicroThumbGrid").selectable(selectable); + + $(".gProgressBar").progressbar(); + $("#gOrganizeTaskPause").click(function(event) { + pause = true; + $("#gOrganizeTaskPause").hide(); + $("#gOrganizeTaskResume").show(); + }); + $("#gOrganizeTaskResume").click(function(event) { + $("#gOrganizeTaskPause").show(); + $("#gOrganizeTaskResume").hide(); + startRearrangeCallback(); + }); } function retrieveMicroThumbs() { @@ -269,13 +283,6 @@ function retrieveMicroThumbs() { $.getJSON(url_data, getMicroThumbsCallback); } -function isOver(selector, pageX, pageY) { - var top = $(selector).offset().top; - var left = $(selector).offset().left; - return this.left <= pageX && pageX <= this.left + 100 && - this.top <= pageY && pageY <= this.top + 100; -} - function organizeToggleChildren(event) { var id = $(this).attr("ref"); var span_children = $("#gOrganizeChildren-" + id); diff --git a/modules/organize/views/organize.html.php b/modules/organize/views/organize.html.php index c2b2070e..5a3ace95 100644 --- a/modules/organize/views/organize.html.php +++ b/modules/organize/views/organize.html.php @@ -33,7 +33,10 @@ <?= $album_tree ?> </div> </div> - <!-- div id="ft"> - <div class="gProgressBar" style="visibility: hidden"></div> - </div --> + <div id="ft" style="visibility: hidden"> + <a id="gOrganizeTaskPause" href="#" class="submit"><?= t("Pause") ?></a> + <a id="gOrganizeTaskResume" href="#" style="display: none" class="submit"><?= t("Resume") ?></a> + <div class="gProgressBar"> + </div> + </div> </div> |