OSDN Git Service

Implementation of the Appendix Attach on Reply
[open-pdm-light/PartList.git] / PartsList / PartsList / app / controllers / ReplyController.scala
index cfe5dbe..80f0d32 100644 (file)
@@ -14,7 +14,10 @@ object ReplyController extends Controller{
           "message" -> nonEmptyText,
           "users" -> mapping (
               "name" -> nonEmptyText
-            )(UserForm.apply)(UserForm.unapply)
+            )(UserForm.apply)(UserForm.unapply),
+            "atach" -> mapping {
+                "grpName" -> text
+              }(AtachForm.apply)(AtachForm.unapply)
         )(ReplyForm.apply)(ReplyForm.unapply)
    )
    
@@ -22,13 +25,17 @@ object ReplyController extends Controller{
     Ok(views.html.createReplyForm(replyRegistForm, notifyId, replyId, replyType, partId, notifyType, state))
   }
   
-  def replyRegistration(notifyId: Long, replyId: Long, partId: Long, notifyType: Long, state: Long) = Action { implicit request =>
+  def replyRegistration(notifyId: Long, replyId: Long, partId: Long, notifyType: Long, state: Long) = Action(parse.multipartFormData) { implicit request =>
     replyRegistForm.bindFromRequest.fold(
         formWithErrors => BadRequest(views.html.createReplyForm(formWithErrors, notifyId, replyId, 0, partId, notifyType, state)),
         reply => {
           inTransaction {
             val replyUser = PartsListDb.users.where(u => u.name like reply.users.name + "%").head
-            PartsListDb.replies.insert(Reply(reply.message, replyUser.id, notifyId, replyId))
+            val newReply = PartsListDb.replies.insert(Reply(reply.message, replyUser.id, notifyId, replyId, reply.atach))
+            val uploadAtach = UploadAtach()
+            request.body.file("atach").map { atach =>
+               uploadAtach.uploadAtach(atach, newReply.atach.grpName, 0, 0, newReply.id)
+              }
             var notify: Notify = null
             if(notifyId!=0) {
                // 通知直下のreplyの場合、notifyより対象Partを割り出し、プロジェクトユーザー抽出。メイル通知。
@@ -54,8 +61,8 @@ object ReplyController extends Controller{
   def showReply(id: Long, partId: Long, notifyType: Long, replyType: Long, state: Long) = Action { implicit request =>
     inTransaction {
       val reply = PartsListDb.replies.where(r => r.id === id).head
-      val replyForm = ReplyForm(reply.message, UserForm(reply.user.assign(reply.user.head).name))
-      Ok(views.html.showReplyForm(replyRegistForm.fill(replyForm), id, partId, notifyType, replyType, state))
+      val replyForm = ReplyForm(reply.message, UserForm(reply.user.assign(reply.user.head).name), null)
+      Ok(views.html.showReplyForm(replyRegistForm.fill(replyForm), id, partId, notifyType, replyType, state, reply))
     }
   }
   
@@ -67,4 +74,20 @@ object ReplyController extends Controller{
       upRecursion(reply.parentReply.head)
     }
   }
+  
+  def appendAtach(id: Long, partId: Long, notifyType: Long, replyType: Long, state: Long) = Action(parse.multipartFormData) { implicit request =>
+    replyRegistForm.bindFromRequest.fold(
+        formWithErrors => BadRequest(views.html.showReplyForm(formWithErrors, id, partId, notifyType, replyType, state, null)),
+//        formWithErrors => BadRequest(views.html.error(formWithErrors)),
+        reply => {
+          inTransaction {
+            val uploadAtach = UploadAtach()
+            request.body.file("atach").map { atach =>
+               uploadAtach.uploadAtach(atach, "PICTUE", 0, 0, id)
+              }
+            Redirect(routes.ReplyController.showReply(id, partId, notifyType, replyType, state))
+            }
+          }
+     )
+  }
 }
\ No newline at end of file