Skip to content

Commit

Permalink
links add remove
Browse files Browse the repository at this point in the history
  • Loading branch information
flurdy committed Nov 30, 2012
1 parent cc72ecb commit fbc0224
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/controllers/WishController.scala
Expand Up @@ -318,7 +318,7 @@ object WishController extends Controller with Secured {
wish.addLink(url)
Redirect(routes.WishController.showWishlist(username,wishlistId)).flashing("messageSuccess" -> "Link added to wish")
}
case None => Redirect(routes.WishController.showWishlist(username,wishlistId)).flashing("messageError" -> "Invalid url")
case None => Redirect(routes.WishController.showWishlist(username,wishlistId)).flashing("messageError" -> "Invalid url. Make sure it starts with http or https?")
}
}
)
Expand Down
38 changes: 32 additions & 6 deletions app/models/Wish.scala
Expand Up @@ -11,7 +11,7 @@ case class Wish(
title:String,
description:Option[String],
wishEntries:Set[WishEntry] = Set.empty,
links:Seq[Link] = Seq.empty,
links:Seq[WishLink] = Seq.empty,
reservation:Option[Reservation] = None,
recipient:Recipient
) {
Expand Down Expand Up @@ -46,7 +46,7 @@ case class Wish(

def findLink(linkId:Long) : Option[String] = Wish.findLink(this,linkId)

def findLinks : Seq[Link] = Wish.findLinks(this)
def findLinks : List[WishLink] = WishLink.findWishLinks(this)

}

Expand Down Expand Up @@ -191,27 +191,53 @@ object Wish {
}


def findLinks(wish:Wish) = {
}





case class WishLink(
linkId : Long,
wish : Wish,
url : String
)


object WishLink {

val simple = {
get[Long]("linkid") ~
get[Long]("wishid") ~
get[String]("url") map {
case linkid~wishid~url => {
WishLink( linkid, new Wish(wishid), url )
}
}
}


def findWishLinks(wish:Wish): List[WishLink] = {
DB.withConnection { implicit connection =>
SQL(
"""
SELECT url
SELECT *
FROM wishlink
where wishid = {wishid}
ORDER BY linkid
"""
).on(
'wishid -> wish.wishId.get
).as(scalar[String] *)
).as(WishLink.simple *)
}
}


}





case class WishEntry(
wish:Wish,
wishlist:Wishlist,
Expand Down
18 changes: 3 additions & 15 deletions app/views/wishlist/wisheditmodal.scala.html
Expand Up @@ -23,7 +23,7 @@ <h3 id="wishModalLabel-@wish.wishId.get"><span>@titleCapper(wish.title)</span></
<div class="modal-links wish-read well">
<ul class="unstyled">
@wish.links.map { link =>
<li><a href="@link.url">@link.url</a></li>
<li><a href="@link.url">@if(link.url.length>60){ @link.url.substring(0,59) } else { @link.url }</a></li>
}
</ul>
</div>
Expand Down Expand Up @@ -65,24 +65,12 @@ <h3 id="wishModalLabel-@wish.wishId.get"><span>@titleCapper(wish.title)</span></
<ul class="edit-links unstyled">
@wish.links.map { link =>
<li>
@form(action = routes.WishController.deleteLinkFromWish(wishlist.recipient.username,wishlist.wishlistId.get,wish.wishId.get,link.linkId.get), 'class -> "form-inline wish-edit noshow"){
<a href="link.url">link.url</a>
@form(action = routes.WishController.deleteLinkFromWish(wishlist.recipient.username,wishlist.wishlistId.get,wish.wishId.get,link.linkId), 'class -> "form-inline wish-edit noshow"){
<a href="link.url">@if(link.url.length>40){ @link.url.substring(0,39) } else { @link.url }</a>
<button type="submit" class="wish-edit noshow btn btn-warning input-small btn-mini">remove link</button>
}
</li>
}
<li>
@form(action = routes.WishController.deleteLinkFromWish(wishlist.recipient.username,wishlist.wishlistId.get,wish.wishId.get,1L), 'class -> "form-inline wish-edit noshow"){
<a href="#">blah.blah.com/blah.html</a>
<button type="submit" class="wish-edit noshow btn btn-warning input-small btn-mini">remove link</button>
}
</li>
<li>
@form(action = routes.WishController.deleteLinkFromWish(wishlist.recipient.username,wishlist.wishlistId.get,wish.wishId.get,1L), 'class -> "form-inline wish-edit noshow"){
<a href="#">blah.blah.com/blah.html</a>
<button type="submit" class="wish-edit noshow btn btn-warning input-small btn-mini">remove link</button>
}
</li>
</ul>
</div>
}
Expand Down
10 changes: 8 additions & 2 deletions public/stylesheets/cargo.css
Expand Up @@ -105,17 +105,23 @@ ul.vertical li a { }
#cargo .modal-links ul li {
height: 1.8em;
line-height: 1.5em;
font-size: 0.9em;
}
#cargo .modal .modal-links { padding: 0; }
#cargo .modal-footer .modal-links form { float: none; }
#cargo .modal .modal-links ul li { font-size: 0.9em; }
#cargo .modal .modal-links ul { margin-bottom: 0; }
#cargo .modal .modal-links .edit-links li { padding: 0.7em 0 0.2em 0; }
#cargo .modal .modal-footer .modal-links li { text-align: left;}
#cargo .modal .modal-footer .add-link form { width: 100%; }
#cargo .modal .modal-footer .add-link form { float: left; }
#cargo .modal .add-link input { font-size: 0.8em; float: left; width:250px; }
#cargo .modal .add-link button { float: right; }
#cargo .modal .modal-links .edit-links li { margin-bottom: 0.5em; }

#cargo .modal-links ul:first-child,
#cargo .modal-footer .modal-links .edit-links:first-child ,
#cargo .modal-links .edit-links li:first-child {
border-top: 0;
}
#cargo .modal-footer form { margin-bottom: 0; }

#cargo .update-wish-form { margin-bottom: 0; }
Expand Down

0 comments on commit fbc0224

Please sign in to comment.