5 import play.api.data.Forms._
10 import org.squeryl.PrimitiveTypeMode._
11 object ReplyController extends Controller{
12 val replyRegistForm = Form(
14 "message" -> nonEmptyText,
16 "name" -> nonEmptyText
17 )(UserForm.apply)(UserForm.unapply),
20 }(AtachForm.apply)(AtachForm.unapply)
21 )(ReplyForm.apply)(ReplyForm.unapply)
24 def createReply(notifyId: Long, replyId: Long, notifyType: Long, replyType: Long, partId: Long, state: Long) = Action { implicit request =>
25 Ok(views.html.createReplyForm(replyRegistForm, notifyId, replyId, replyType, partId, notifyType, state))
28 def replyRegistration(notifyId: Long, replyId: Long, partId: Long, notifyType: Long, state: Long) = Action(parse.multipartFormData) { implicit request =>
29 replyRegistForm.bindFromRequest.fold(
30 formWithErrors => BadRequest(views.html.createReplyForm(formWithErrors, notifyId, replyId, 0, partId, notifyType, state)),
33 val replyUser = PartsListDb.users.where(u => u.name like reply.users.name + "%").head
34 val newReply = PartsListDb.replies.insert(Reply(reply.message, replyUser.id, notifyId, replyId, reply.atach))
35 val uploadAtach = UploadAtach()
36 request.body.file("atach").map { atach =>
37 uploadAtach.uploadAtach(atach, newReply.atach.grpName, 0, 0, newReply.id)
39 var notify: Notify = null
41 // 通知直下のreplyの場合、notifyより対象Partを割り出し、プロジェクトユーザー抽出。メイル通知。
42 notify = PartsListDb.notifies.where(n => n.id === notifyId).head
44 // reply配下のreplyの場合、再帰処理によりnotify抽出後、対象Partを割り出し、プロジェクトユーザー抽出。メイル通知。
45 val targetReply = PartsListDb.replies.where(tr => tr.id === replyId).head
46 val topReply = upRecursion(targetReply)
47 notify = PartsListDb.notifies.where(n => n.id === topReply.notifyId).head
49 val targetPart = notify.part.assign(notify.part.head)
50 val users = targetPart.project.assign(targetPart.project.head).users
51 val sendMail = SendMail(2, replyUser.email, targetPart.id, notifyType, state)
53 sendMail.sendMail(user.email)
56 Ok(views.html.issueresult(2))
61 def showReply(id: Long, partId: Long, notifyType: Long, replyType: Long, state: Long) = Action { implicit request =>
63 val reply = PartsListDb.replies.where(r => r.id === id).head
64 val replyForm = ReplyForm(reply.message, UserForm(reply.user.assign(reply.user.head).name), null)
65 Ok(views.html.showReplyForm(replyRegistForm.fill(replyForm), id, partId, notifyType, replyType, state, reply))
69 def upRecursion(reply: Reply):Reply = {
70 if(reply.parentReply.size == 0) {
73 println("Messages " + reply.message)
74 upRecursion(reply.parentReply.head)