Skip to content

Commit

Permalink
Convert the old organize to the new flex based organize
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Almdal committed Mar 27, 2010
1 parent 7e9eca7 commit 67a8ef4
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 726 deletions.
163 changes: 17 additions & 146 deletions modules/organize/controllers/organize.php
Expand Up @@ -19,159 +19,30 @@
*/
class Organize_Controller extends Controller {
function dialog($album_id) {
$input = Input::instance();

$album = ORM::factory("item", $album_id);
access::required("view", $album);
access::required("edit", $album);

$v = new View("organize_dialog.html");
$v->album = $album;
$v->album_tree = self::_expanded_tree(ORM::factory("item", 1), $album);
$v->micro_thumb_grid = self::_get_micro_thumb_grid($album, 0);
print $v;
}

function album($album_id, $offset) {
$album = ORM::factory("item", $album_id);
access::required("view", $album);
access::required("edit", $album);

print json_encode(
array("grid" => (string)self::_get_micro_thumb_grid($album, $offset),
"sort_column" => $album->sort_column,
"sort_order" => $album->sort_order));
}

function move_to($target_album_id) {
access::verify_csrf();

$target_album = ORM::factory("item", $target_album_id);
access::required("view", $target_album);
access::required("add", $target_album);

$source_album = null;
foreach (Input::instance()->post("source_ids") as $source_id) {
$source = ORM::factory("item", $source_id);
if (empty($source_album)) { // get the source_album
$source_album = $source->parent();
}
if (!$source->contains($target_album)) {
access::required("edit", $source);
item::move($source, $target_album);
}
// @todo turn this into an api call.
$v->file_filter = json_encode(array("Images" => "*.jpg; *.jpeg; *.gif; *.png",
"Movies" => "*.flv; *.mp4"));
$v->domain = $input->server("SERVER_NAME");
// @todo figure out how to connect this w/o a dependency
$v->base_url = url::abs_site("rest") . "/";

$v->sort_order = json_encode(array("ASC" => (string)t("Ascending"), "DESC" => (string)t("Descending")));
$sort_fields = array();
foreach (album::get_sort_order_options() as $field => $description) {
$sort_fields[$field] = (string)$description;
}
$v->sort_fields = json_encode($sort_fields);

print json_encode(
array("tree" => (string)self::_expanded_tree(ORM::factory("item", 1), $source_album),
"grid" => (string)self::_get_micro_thumb_grid($source_album, 0)));
}

function rearrange($target_id, $before_or_after) {
access::verify_csrf();

$target = ORM::factory("item", $target_id);
$album = $target->parent();
access::required("view", $album);
access::required("edit", $album);

//if (locales::is_rtl()) { // invert the position if the locale is rtl
// $before_or_after = $before_or_after == "after" ? "before" : "after";
//}

$source_ids = Input::instance()->post("source_ids", array());

if ($album->sort_column != "weight") {
$i = 0;
foreach ($album->children() as $child) {
// Do this directly in the database to avoid sending notifications
db::build()
->update("items")
->set("weight", ++$i)
->where("id", "=", $child->id)
->execute();
}
$album->sort_column = "weight";
$album->sort_order = "ASC";
$album->save();
$target->reload();
}

// Find the insertion point
$target_weight = $target->weight;
if ($before_or_after == "after") {
$target_weight++;
}

// Make a hole
$count = count($source_ids);
db::build()
->update("items")
->set("weight", new Database_Expression("`weight` + $count"))
->where("weight", ">=", $target_weight)
->where("parent_id", "=", $album->id)
->execute();

// Insert source items into the hole
foreach ($source_ids as $source_id) {
db::build()
->update("items")
->set("weight", $target_weight++)
->where("id", "=", $source_id)
->execute();
}

module::event("album_rearrange", $album);

print json_encode(
array("grid" => (string)self::_get_micro_thumb_grid($album, 0),
"sort_column" => $album->sort_column,
"sort_order" => $album->sort_order));
}

public function sort_order($album_id, $col, $dir) {
access::verify_csrf();

$album = ORM::factory("item", $album_id);
access::required("view", $album);
access::required("edit", $album);

$options = album::get_sort_order_options();
if (!isset($options[$col])) {
return;
}

$album->sort_column = $col;
$album->sort_order = $dir;
$album->save();

print json_encode(
array("grid" => (string)self::_get_micro_thumb_grid($album, 0),
"sort_column" => $album->sort_column,
"sort_order" => $album->sort_order));
}

private static function _get_micro_thumb_grid(Item_Model $album, $offset) {
$v = new View("organize_thumb_grid.html");
$v->album = $album;
$v->offset = (int) $offset;
return $v;
}

public function tree($album_id) {
$album = ORM::factory("item", $album_id);
access::required("view", $album);

print self::_expanded_tree($album);
}

/**
* Create an HTML representation of the tree from the root down to the selected album. We only
* include albums along the descendant hierarchy that includes the selected album, and the
* immediate child albums.
*/
private static function _expanded_tree($root, $selected_album=null) {
$v = new View("organize_tree.html");
$v->album = $root;
$v->selected = $selected_album;
return $v;
$user = identity::active_user();
$v->api_key = rest::get_access_token($user->id)->access_key;
print $v;
}
}
156 changes: 0 additions & 156 deletions modules/organize/css/organize.css

This file was deleted.

18 changes: 10 additions & 8 deletions modules/organize/css/organize_theme.css
@@ -1,16 +1,18 @@
/** *******************************************************************
* Organize styles that are theme overrideable
*********************************************************************/
.g-organize-microthumb-grid-cell.ui-selected {
background: #DFEFFC !important;
#g-organize {
background-color: #FFFFFF;
border: 0px solid #000000;
color: #0E2B52;
}

#g-organize-microthumb-grid,
#g-organize-drop-target-marker,
.g-organize-album-text:hover {
border-color: #79B7E7;
#g-organize-hover {
background-color: #CFDEFF;
display: none;
}

#g-organize-drop-target-marker {
background-color: #79B7E7;
#g-organize-active {
background-color: #6699CC;
display: none;
}
6 changes: 0 additions & 6 deletions modules/organize/helpers/organize_theme.php
Expand Up @@ -21,12 +21,6 @@ class organize_theme {
static function head($theme) {
$item = $theme->item();
if ($item && access::can("edit", $item) && $item->is_album()) {
// @todo: Defer loading js/css until we're loading the organize dialog as <script> and
// <link> elements so that we're not forcing them to be downloaded on every page view (which
// is expensive in terms of browser latency). When we do that, we'll have to figure out an
// approach that lets us continue to use the Kohana cascading filesystem.
$theme->script("organize.js");
$theme->css("organize.css");
$theme->css("organize_theme.css");
}
}
Expand Down

0 comments on commit 67a8ef4

Please sign in to comment.