[Notice] Announcing the End of Demo Server [Read me]
Jihan Kim 2014-06-25
Review: show comment form directly on thread
@bdf9ef6f8f7ba736846d518613474607c833aa9a
app/utils/TemplateHelper.scala
--- app/utils/TemplateHelper.scala
+++ app/utils/TemplateHelper.scala
@@ -438,6 +438,32 @@
         case _ => ""
       }
     }
+
+    def urlToPostNewComment(thread: CommentThread) = {
+      if(thread.isOnPullRequest){
+        routes.PullRequestApp.newComment(thread.project.owner, thread.project.name, thread.pullRequest.id, _getCommitId(thread))
+      } else {
+        routes.CodeHistoryApp.newComment(thread.project.owner, thread.project.name, _getCommitId(thread))
+      }
+    }
+
+    def _getCommitId(thread: CommentThread) = {
+      thread match {
+        case (t: CodeCommentThread) =>
+          t.commitId
+        case (t: models.NonRangedCodeCommentThread) =>
+          t.commitId
+        case _ => ""
+      }
+    }
+
+    def getResourceType(thread: CommentThread) = {
+      if(thread.isOnPullRequest){
+        models.enumeration.ResourceType.REVIEW_COMMENT
+      } else {
+        models.enumeration.ResourceType.COMMIT_COMMENT
+      }
+    }
   }
 
   object CodeBrowser {
 
app/views/partial_comment_form_on_thread.scala.html (added)
+++ app/views/partial_comment_form_on_thread.scala.html
@@ -0,0 +1,72 @@
+@**
+* Yobi, Project Hosting SW
+*
+* Copyright 2014 NAVER Corp.
+* http://yobi.io
+*
+* @Author Jihan Kim
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+**@
+@(thread: CommentThread)
+
+@import utils.TemplateHelper._
+@import utils.TemplateHelper.DiffRenderer._
+
+@changeThreadStateButton = {
+  @if(utils.AccessControl.isAllowed(UserApp.currentUser(), thread.asResource(), Operation.UPDATE)){
+    @if(thread.state == CommentThread.ThreadState.OPEN) {
+      <button type="button" data-request-method="post" data-request-uri="@routes.CommentThreadApp.close(thread.id)" class="ybtn ybtn-default ybtn-small">@Messages("commentThread.close")</button>
+    } else {
+      <button type="button" data-request-method="post" data-request-uri="@routes.CommentThreadApp.open(thread.id)" class="ybtn ybtn-default ybtn-small">@Messages("commentThread.open")</button>
+    }
+  }
+}
+
+@defining(getResourceType(thread)) { resourceType =>
+  @if(utils.AccessControl.isProjectResourceCreatable(UserApp.currentUser(), thread.project, resourceType)){
+  <div class="write-comment-form">
+    <form action="@urlToPostNewComment(thread)" method="post" enctype="multipart/form-data" class="review-form" style="display:block;">
+      <input type="hidden" name="thread.id" value="@thread.id">
+      <div class="author-info-wrap pull-left">
+        <div class="author-info">
+          <a href="@routes.UserApp.userInfo(UserApp.currentUser().loginId)" class="avatar-wrap medium"
+             title="@UserApp.currentUser().name" data-toggle="tooltip" data-placement="top">
+            <img src="@UserApp.currentUser().avatarUrl" width="32" height="32">
+          </a>
+        </div>
+      </div>
+      <div class="write-comment-box">
+        <div class="write-comment-wrap">
+          @common.editor("contents", "" , "style=height:100px", "code-review-body")
+
+          @** fileUploader **@
+          @if(!UserApp.currentUser.isAnonymous){
+            @common.uploadForm(resourceType)
+          }
+          @** end of fileUploader **@
+
+          <div class="right-txt">
+            @changeThreadStateButton
+            <button type="submit" class="ybtn ybtn-success ybtn-small">@Messages("button.comment.new")</button>
+          </div>
+        </div>
+      </div>
+    </form>
+  </div>
+  } else {
+  <p class="thread-actrow">
+    @changeThreadStateButton
+  </p>
+  }
+}
app/views/partial_comment_thread.scala.html
--- app/views/partial_comment_thread.scala.html
+++ app/views/partial_comment_thread.scala.html
@@ -21,8 +21,6 @@
 @(thread: CommentThread)
 
 @import utils.JodaDateUtil
-@import utils.TemplateHelper._
-@import utils.TemplateHelper.DiffRenderer._
 
 <div id="thread-@thread.id" data-state="@thread.state.toString().toLowerCase()"
      class="comment-thread-wrap @thread.state.toString().toLowerCase()
@@ -79,19 +77,5 @@
         }
     </ul>
 
-    <div class="write-comment-form"></div>
-
-    <p class="thread-actrow">
-        @if(utils.AccessControl.isAllowed(UserApp.currentUser(), thread.asResource(), Operation.UPDATE)){
-            @if(thread.state == CommentThread.ThreadState.OPEN) {
-            <button type="button" data-request-method="post" data-request-uri="@routes.CommentThreadApp.close(thread.id)" class="ybtn ybtn-default ybtn-small">@Messages("commentThread.close")</button>
-            } else {
-            <button type="button" data-request-method="post" data-request-uri="@routes.CommentThreadApp.open(thread.id)" class="ybtn ybtn-default ybtn-small">@Messages("commentThread.open")</button>
-            }
-        }
-
-        @if(utils.AccessControl.isProjectResourceCreatable(UserApp.currentUser(), thread.project, ResourceType.REVIEW_COMMENT)){
-        <button type="button" class="ybtn ybtn-info ybtn-small btn-thread" data-thread-id="@thread.id">@Messages("button.comment.open")</button>
-        }
-    </p>
+    @partial_comment_form_on_thread(thread)
 </div>
public/javascripts/service/yobi.code.Diff.js
--- public/javascripts/service/yobi.code.Diff.js
+++ public/javascripts/service/yobi.code.Diff.js
@@ -293,6 +293,23 @@
                     "sUploaderId"  : oUploader.attr("data-namespace")
                 }));
             }
+
+            $("form.review-form").each(function(i, el){
+                var form = $(el);
+                var container = form.find(".upload-wrap");
+                var textarea = form.find("textarea");
+                var uploader = yobi.Files.getUploader(container, textarea);
+
+                if(uploader){
+                    (new yobi.Attachments({
+                        "elTextarea"   : textarea,
+                        "elContainer"  : container,
+                        "sTplFileItem" : htVar.sTplFileItem,
+                        "sUploaderId"  : uploader.attr("data-namespace")
+                    }));
+
+                }
+            });
         }
 
         /**
Add a comment
List