diff --git a/src/main/scala/app/LabelsController.scala b/src/main/scala/app/LabelsController.scala index fca9429..9432031 100644 --- a/src/main/scala/app/LabelsController.scala +++ b/src/main/scala/app/LabelsController.scala @@ -8,7 +8,7 @@ with LabelsService with RepositoryService with AccountService with WritableRepositoryAuthenticator trait LabelsControllerBase extends ControllerBase { - self: LabelsService with WritableRepositoryAuthenticator => + self: LabelsService with RepositoryService with WritableRepositoryAuthenticator => case class LabelForm(labelName: String, color: String) @@ -26,4 +26,15 @@ redirect("/%s/%s/issues".format(owner, repository)) }) + get("/:owner/:repository/issues/label/:labelId/edit")(writableRepository { + val owner = params("owner") + val repository = params("repository") + val labelId = params("labelId").toInt + + getLabel(owner, repository, labelId) match { + case None => NotFound() + case Some(l) => issues.html.labeledit(Some(l), getRepository(owner, repository, baseUrl).get) + } + }) + } \ No newline at end of file diff --git a/src/main/scala/service/LabelsService.scala b/src/main/scala/service/LabelsService.scala index 0c5b469..8391dc6 100644 --- a/src/main/scala/service/LabelsService.scala +++ b/src/main/scala/service/LabelsService.scala @@ -16,6 +16,11 @@ .sortBy(_.labelName asc) .list + def getLabel(owner: String, repository: String, labelId: Int): Option[Label] = + Query(Labels) + .filter(l => (l.userName is owner.bind) && (l.repositoryName is repository.bind) && (l.labelId is labelId.bind)) + .firstOption + def createLabel(owner: String, repository: String, labelName: String, color: String): Unit = Labels.ins insert (owner, repository, labelName, color) diff --git a/src/main/twirl/issues/issues.scala.html b/src/main/twirl/issues/issues.scala.html index 3686767..8501f84 100644 --- a/src/main/twirl/issues/issues.scala.html +++ b/src/main/twirl/issues/issues.scala.html @@ -123,30 +123,27 @@ } }); - $('#editLabelForm').click(function(e){ - e.stopPropagation(); - }); - $('body').click(function(){ hideEditLabelForm(); }); function showEditLabelForm(element){ - var form = $('#editLabelForm'); - form.detach(); - form.find('input[name=editLabelName]').val($(element).attr('labelName')); - //form.find('input[name=editColor]').colorpicker('setValue', $(element).attr('color')); - form.find('input[name=editLabelId]').val($(element).attr('labelId')); - $(element).parent().append(form); - form.show(); - $('ul#label-edit li').css('border', '1px solid white'); - $(element).parent().css('border', '1px solid #eee'); + $('#editLabelForm').remove(); + + $.ajax({ + method: 'GET', + url: '@path/@repository.owner/@repository.name/issues/label/' + $(element).attr('labelId') + '/edit', + dataType: 'html', + success: function(data){ + $(element).parent().append(data); + $('ul#label-edit li').css('border', '1px solid white'); + $(element).parent().css('border', '1px solid #eee'); + } + }); } function hideEditLabelForm(){ - var form = $('#editLabelForm'); - form.find('input[name=editLabelId]').val(''); - form.hide(); + $('#editLabelForm').remove(); $('ul#label-edit li').css('border', '1px solid white'); } }); diff --git a/src/main/twirl/issues/labeledit.scala.html b/src/main/twirl/issues/labeledit.scala.html index b8867ba..27a3f72 100644 --- a/src/main/twirl/issues/labeledit.scala.html +++ b/src/main/twirl/issues/labeledit.scala.html @@ -1,31 +1,32 @@ @(label: Option[model.Label], repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context) @import context._ @defining((if(label.isEmpty) ("new", 190, 4) else ("edit", 180, 8))){ case (mode, width, margin) => +