diff options
Diffstat (limited to 'modules/organize/controllers/organize.php')
| -rw-r--r-- | modules/organize/controllers/organize.php | 165 | 
1 files changed, 139 insertions, 26 deletions
| diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php index 2b6e4186..35e4cd66 100644 --- a/modules/organize/controllers/organize.php +++ b/modules/organize/controllers/organize.php @@ -18,43 +18,156 @@   * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.   */  class Organize_Controller extends Controller { +  function frame($album_id) { +    $album = ORM::factory("item", $album_id); +    access::required("view", $album); +    access::required("edit", $album); + +    $v = new View("organize_frame.html"); +    $v->album = $album; +    print $v; +  } +    function dialog($album_id) { +    $album = ORM::factory("item", $album_id); +    access::required("view", $album); +    access::required("edit", $album); + +    $v = new View("organize_dialog.html"); +    $v->album = $album; +    print $v; +  } + +  function tree($selected_album_id) { +    $root = ORM::factory("item", Input::instance()->post("root_id", 1)); +    $selected_album = ORM::factory("item", $selected_album_id); +    access::required("view", $root); +    access::required("view", $selected_album); + +    $tree = $this->_get_tree($root, $selected_album); +    json::reply($tree); +  } + +  function album_info($album_id) { +    $album = ORM::factory("item", $album_id); +    access::required("view", $album); + +    $data = array( +      "sort_column" => $album->sort_column, +      "sort_order" => $album->sort_order, +      "children" => array()); + +    foreach ($album->viewable()->children() as $child) { +      $dims = $child->scale_dimensions(120); +      $data["children"][] = array( +        "id" => $child->id, +        "thumb_url" => $child->thumb_url(), +        "width" => $dims[1], +        "height" => $dims[0], +        "type" => $child->type, +        "title" => $child->title); +    } +    json::reply($data); +  } + +  function reparent() { +    access::verify_csrf(); +      $input = Input::instance(); +    $new_parent = ORM::factory("item", $input->post("target_id")); +    access::required("edit", $new_parent); + +    foreach (explode(",", $input->post("source_ids")) as $source_id) { +      $source = ORM::factory("item", $source_id); +      access::required("edit", $source->parent()); + +      $source->parent_id = $new_parent->id; +      $source->save(); +    } +    json::reply(null); +  } +  function set_sort($album_id) { +    access::verify_csrf();      $album = ORM::factory("item", $album_id);      access::required("view", $album);      access::required("edit", $album); -    $user = identity::active_user(); -    $sort_fields = array(); -    foreach (album::get_sort_order_options() as $field => $description) { -      $sort_fields[$field] = (string)$description; +    foreach (array("sort_column", "sort_order") as $key) { +      if ($val = Input::instance()->post($key)) { +        $album->$key = $val; +      }      } -    $sort_order = array("ASC" => (string)t("Ascending"), "DESC" => (string)t("Descending")); -    $file_filter = json_encode(array( -      "photo" => array("label" => "Images", "types" => array("*.jpg", "*.jpeg", "*.png", "*.gif")), -      "movie" => array("label" => "Movies", "types" => array("*.flv", "*.mp4", "*.m4v")))); +    $album->save(); -    $v = new View("organize_dialog.html"); -    $v->album = $album; -    $v->domain = $input->server("HTTP_HOST"); -    $v->access_key = rest::access_key(); -    $v->file_filter = addslashes($file_filter); -    $v->sort_order = addslashes(json_encode($sort_order)); -    $v->sort_fields = addslashes(json_encode($sort_fields)); -    $v->selected_id = Input::instance()->get("selected_id", null); -    $v->rest_uri = url::site("rest") . "/"; -    $v->controller_uri = url::site("organize") . "/"; -    $v->swf_uri = url::file("modules/organize/lib/Gallery3WebClient.swf?") . -      filemtime(MODPATH . "organize/lib/Gallery3WebClient.swf"); -    print $v; +    json::reply(null);    } -  function add_album_fields() { -    json::reply(array("title" => (string)t("Title"), -                      "description" => (string)t("Description"), -                      "name" => (string)t("Directory name"), -                      "slug" => (string)t("Internet Address"))); +  function move_before() { +    access::verify_csrf(); + +    $input = Input::instance(); +    $target = ORM::factory("item", $input->post("target_id")); +    $album = $target->parent(); +    access::required("edit", $album); + +    if ($album->sort_column != "weight") { +      // Force all the weights into the current order before changing the order to manual +      $weight = 0; +      foreach ($album->children() as $child) { +        $child->weight = ++$weight; +        $child->save(); +      } + +      $album->sort_column = "weight"; +      $album->sort_order = "ASC"; +      $album->save(); +    } + +    $source_ids = explode(",", $input->post("source_ids")); +    if ($source_ids) { +      // Make a hole the right size +      db::build() +        ->update("items") +        ->set("weight", db::expr("`weight` + " . count($source_ids))) +        ->where("parent_id", "=", $album->id) +        ->where("weight", ">=", $target->weight) +        ->execute(); + +      // Move all the source items to the right spots. +      for ($i = 0; $i < count($source_ids); $i++) { +        $source = ORM::factory("item", $source_ids[$i]); +        if ($source->parent_id = $album->id) { +          $source->weight = $target->weight + $i; +          $source->save(); +        } +      } +    } +    json::reply(null);    } +  private function _get_tree($item, $selected) { +    $tree = array(); +    $children = $item->viewable() +      ->children(null, null, array(array("type", "=", "album"))) +      ->as_array(); +    foreach ($children as $child) { +      $node = array( +        "allowChildren" => true, +        "editable" => false, +        "expandable" => true, +        "id" => $child->id, +        "leaf" => false, +        "text" => $child->title, +        "nodeType" => "async"); + +      // If the child is in the selected path, open it now.  Else, mark it async. +      if ($child->contains($selected)) { +        $node["children"] = $this->_get_tree($child, $selected); +        $node["expanded"] = true; +      } +      $tree[] = $node; +    } +    return $tree; +  }  } | 
