id == 1) ? $item : ORM::factory("item", 1); $v = new View("organize.html"); $v->root = $root; $v->item = $item; $v->album_tree = $this->tree($item, $root); $v->edit_form = new View("organize_edit.html"); $v->edit_form->button_pane = new View("organize_button_pane.html"); print $v; } public function content($item_id) { $item = ORM::factory("item", $item_id); $width = $this->input->get("width"); $height = $this->input->get("height"); $offset = $this->input->get("offset", 0); $thumbsize = self::$_MICRO_THUMB_SIZE + 2 * self::$_MICRO_THUMB_PADDING; $page_size = ceil($width / $thumbsize) * ceil($height / $thumbsize); $v = new View("organize_thumb_grid.html"); $v->children = $item->children($page_size, $offset); $v->thumbsize = self::$_MICRO_THUMB_SIZE; $v->padding = self::$_MICRO_THUMB_PADDING; $v->offset = $offset; print json_encode(array("count" => $v->children->count(), "data" => $v->__toString())); } public 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) { $albums = ORM::factory("item") ->where(array("parent_id" => $parent->id, "type" => "album")) ->orderby(array("title" => "ASC")) ->find_all(); $v = new View("organize_album.html"); $v->album = $parent; $v->selected = $parent->id == $item->id; if ($albums->count()) { $v->album_icon = $parent->id == 1 || $v->selected ? "ui-icon-minus" : "ui-icon-plus"; } else { $v->album_icon = ""; } $v->children = ""; foreach ($albums as $album) { $v->children .= $this->tree($item, $album); } 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")); } }