diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2008-12-02 21:25:15 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2008-12-02 21:25:15 +0000 |
commit | 3953dde2c698d89810661435b2602fbdb55c322e (patch) | |
tree | 37da3672e8d84d26b90a913a4c5ef0c7a3053829 | |
parent | ea11562e3270764a1083b0b7e236be5331626504 (diff) |
The rearrange module will now add an album if you drag the "new album" onto the album tree. I haven't had a chance to figure out why the form does get any styling or why a textarea is no included as a list item.
-rw-r--r-- | core/controllers/albums.php | 10 | ||||
-rw-r--r-- | core/helpers/album.php | 13 | ||||
-rw-r--r-- | core/models/item.php | 2 | ||||
-rw-r--r-- | core/views/welcome.html.php | 1 | ||||
-rw-r--r-- | modules/rearrange/css/rearrange.css | 20 | ||||
-rw-r--r-- | modules/rearrange/js/jquery.gallery.rearrange.tree.js | 39 | ||||
-rw-r--r-- | modules/rearrange/views/rearrange.html.php | 4 |
7 files changed, 83 insertions, 6 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php index ec5466a6..e684fa6b 100644 --- a/core/controllers/albums.php +++ b/core/controllers/albums.php @@ -46,4 +46,14 @@ class Albums_Controller extends Items_Controller { print $template; } + + /** + * @see Rest_Controller::_form_add($parameters) + */ + public function _form_add($parent_id) { + $parent = ORM::factory("item", $parent_id); + + print album::get_add_form($parent)->render(); + } + } diff --git a/core/helpers/album.php b/core/helpers/album.php index dd62d693..3e77d521 100644 --- a/core/helpers/album.php +++ b/core/helpers/album.php @@ -58,4 +58,17 @@ class album_Core { return $album; } + + static function get_add_form($parent) { + $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "gAddAlbumForm")); + $group = $form->group(_("Add Album to {$parent->title}")); + $group->input("name"); + $group->input("title"); + $group->input("description"); + $group->hidden("type")->value("album"); + $group->submit(_("Create")); + $form->add_rules_from(ORM::factory("item")); + return $form; + + } } diff --git a/core/models/item.php b/core/models/item.php index 99a9c32a..9d23170f 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -21,6 +21,8 @@ class Item_Model extends ORM_MPTT { protected $children = 'items'; protected $has_one = array("owner" => "user"); + var $rules = array(); + /** * Is this item an album? * @return true if it's an album diff --git a/core/views/welcome.html.php b/core/views/welcome.html.php index 18effd55..262adcfc 100644 --- a/core/views/welcome.html.php +++ b/core/views/welcome.html.php @@ -150,6 +150,7 @@ } </style> <?= html::script("lib/jquery.js") ?> + <?= html::script("lib/jquery.form.js") ?> <?= html::script("lib/jquery.cookie.js") ?> <?= html::script("lib/jquery.MultiFile.js") ?> <?= rearrange_block::head(null) ?> diff --git a/modules/rearrange/css/rearrange.css b/modules/rearrange/css/rearrange.css index 216841ea..65fff8b0 100644 --- a/modules/rearrange/css/rearrange.css +++ b/modules/rearrange/css/rearrange.css @@ -12,6 +12,26 @@ cursor: pointer; } +#gAddAlbumPopup { + display: none; + position: absolute; + border: 1px solid #6fa5fd; + z-index: 2; + background: #ffffff; +} + +#gAddAlbumPopupClose { + font-size:14px; + line-height:14px; + right:6px; + top:4px; + position:absolute; + color:#6fa5fd; + font-weight:700; + display:block; + cursor: pointer; +} + #gDeleteItem { background-image: url(../images/bin_closed.png); background-repeat: no-repeat; diff --git a/modules/rearrange/js/jquery.gallery.rearrange.tree.js b/modules/rearrange/js/jquery.gallery.rearrange.tree.js index b2ad2810..399064ff 100644 --- a/modules/rearrange/js/jquery.gallery.rearrange.tree.js +++ b/modules/rearrange/js/jquery.gallery.rearrange.tree.js @@ -71,10 +71,7 @@ if(jQuery) (function($){ accept: "#gAddAlbum", hoverClass: "droppable-hover", drop: function(ev, ui) { - source_element = ui.draggable; - source_parent = source_element.parent(); - target = ui.element; - alert(source_element.attr("rel") + "\n" + target.attr("id")); + addAlbum(ui.element); } }); if ($(c).hasClass('treeitem')) { @@ -115,8 +112,7 @@ if(jQuery) (function($){ $(this).parent().removeClass('collapsed').addClass('expanded'); } else { // Collapse - $(this).parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing }); - $(this).parent().removeClass('expanded').addClass('collapsed'); + collapse($(this).parent()); } } else { h($(this).attr('rel')); @@ -126,6 +122,37 @@ if(jQuery) (function($){ // Prevent A from triggering the # on non-click events if( o.folderEvent.toLowerCase != 'click' ) $(t).find('LI A').bind('click', function() { return false; }); } + + function addAlbum(parent) { + $("#gAddAlbumPopupClose").click(function() { + $("#gAddAlbumPopup").css({"display": "none"}); + }); + + $.get("form/add/albums/" + parent.attr("id"), {}, function(data) { + $("#gAddAlbumArea").html(data); + $("#gAddAlbumForm").ajaxForm({ + complete: function(xhr, statusText) { + //$("#gAddAlbumForm").replaceWith(xhr.responseText); + if (xhr.status == 200) { + $("#gAddAlbumPopup").css({"display": "none"}); + collapse(parent); + showTree(parent, parent.attr("id")); + } + } + }); + $("#gAddAlbumPopup").css({ + "display": "block", + "top": $("#gAddAlbum").offsetTop + $("#gAddAlbum").offsetHeight, + "left":$("#gAddAlbum").offsetLeft + }); + }); + } + + function collapse(parent) { + parent.find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing }); + parent.removeClass('expanded').addClass('collapsed'); + } + // Loading message $(this).html('<ul class="jqueryFileTree start"><li class="wait">' + o.loadMessage + '<li></ul>'); // Get the initial file list diff --git a/modules/rearrange/views/rearrange.html.php b/modules/rearrange/views/rearrange.html.php index e1c03af2..24ccfb50 100644 --- a/modules/rearrange/views/rearrange.html.php +++ b/modules/rearrange/views/rearrange.html.php @@ -8,6 +8,10 @@ $(document).ready( function() { </script> <div id="gRearrange"> <span id="gAddAlbum" rel="gAddAlbum">New Album</span> + <div id="gAddAlbumPopup"> + <a id="gAddAlbumPopupClose">x</a> + <div id="gAddAlbumArea"></div> + </div> <span id="gDeleteItem">Delete</span> <hr/> |