{% load djblets_js %}
{% load djblets_utils %}
{% load i18n %}

{% ifuserorperm review_request.submitter "reviews.can_edit_reviewrequest" %}
<script type="text/javascript">
  $(document).ready(function() {
{%  if upload_diff_form %}
    $("#upload-diff-link").click(function() {
      $("<div/>")
        .formDlg({
          title: "{% trans "Upload Diff" %}",
          confirmLabel: "{% trans "Upload" %}",
          dataStoreObject: gReviewRequest.createDiff(),
          width: "60em",
          upload: true,
          fields: {% form_dialog_fields upload_diff_form %}
        });

      return false;
    });
{%  endif %}

    $("#upload-screenshot-link").click(function() {
      $("<div/>").formDlg({
        title: "{% trans "Upload Screenshot" %}",
        confirmLabel: "{% trans "Upload" %}",
        dataStoreObject: gReviewRequest.createScreenshot(),
        width: "50em",
        upload: true,
        fields: {% form_dialog_fields upload_screenshot_form %},
        success: function(rsp) {
            if (!$("#screenshot-thumbnails").length == 0) {
                $.newScreenshotThumbnail(rsp.screenshot);
            }

            gDraftBanner.show();
        }
      });

      return false;
    });

    $("#upload-file-link").click(function() {
      $("<div/>").formDlg({
        title: "{% trans "Upload File" %}",
        confirmLabel: "{% trans "Upload" %}",
        dataStoreObject: gReviewRequest.createFileAttachment(),
        width: "50em",
        upload: true,
        fields: {% form_dialog_fields file_attachment_form %},
        success: function(rsp) {
            if (!$("#file-list").length == 0) {
                $.newFileAttachment(rsp.file_attachment);
            }

            gDraftBanner.show();
        }
      });

      return false;
    });

   $(".file-review").click(function() {
      $("<div/>").formDlg({
        title: "{% trans "Review File" %}",
        confirmLabel: "{% trans "Save" %}",
        dataStoreObject: gReviewRequest.createReview().createFileComment(this.id),
        upload: false,
        fields: {% form_dialog_fields comment_file_form %},
        success: function(rsp) {
            gReviewBanner.show();
        }
      });

      return false;
    });
  });
</script>
{% endifuserorperm %}
