From f545faa06d553750b9f4018336e810530389f88c Mon Sep 17 00:00:00 2001
From: Unknwon <u@gogs.io>
Date: Thu, 6 Dec 2018 22:58:02 -0500
Subject: templates: make state changing routes to POST method (#5541)

- pkg/context: add ParamsUser to unify the injection process
---
 public/css/gogs.css    |   6 +++
 public/js/gogs.js      | 116 +++++++++++++++++++++++++------------------------
 public/less/_base.less |   5 +++
 public/less/_user.less |   3 ++
 4 files changed, 74 insertions(+), 56 deletions(-)

(limited to 'public')

diff --git a/public/css/gogs.css b/public/css/gogs.css
index 9e60fff6..2d56467a 100644
--- a/public/css/gogs.css
+++ b/public/css/gogs.css
@@ -347,6 +347,9 @@ footer .ui.language .menu {
 .hide {
   display: none;
 }
+.display.inline {
+  display: inline;
+}
 .center {
   text-align: center;
 }
@@ -2934,6 +2937,9 @@ footer .ui.language .menu {
   margin-top: 5px;
   margin-right: 8px;
 }
+.user.profile .ui.card .profile-avatar {
+  height: 287px;
+}
 .user.profile .ui.card .header {
   word-break: break-all;
 }
diff --git a/public/js/gogs.js b/public/js/gogs.js
index e518bde4..eb161d17 100644
--- a/public/js/gogs.js
+++ b/public/js/gogs.js
@@ -9,11 +9,11 @@ function initCommentPreviewTab($form) {
     $tabMenu.find('.item[data-tab="' + $tabMenu.data('preview') + '"]').click(function () {
         var $this = $(this);
         $.post($this.data('url'), {
-                "_csrf": csrf,
-                "mode": "gfm",
-                "context": $this.data('context'),
-                "text": $form.find('.tab.segment[data-tab="' + $tabMenu.data('write') + '"] textarea').val()
-            },
+            "_csrf": csrf,
+            "mode": "gfm",
+            "context": $this.data('context'),
+            "text": $form.find('.tab.segment[data-tab="' + $tabMenu.data('write') + '"] textarea').val()
+        },
             function (data) {
                 var $previewPanel = $form.find('.tab.segment[data-tab="' + $tabMenu.data('preview') + '"]');
                 $previewPanel.html(data);
@@ -39,11 +39,11 @@ function initEditPreviewTab($form) {
         $previewTab.click(function () {
             var $this = $(this);
             $.post($this.data('url'), {
-                    "_csrf": csrf,
-                    "mode": "gfm",
-                    "context": $this.data('context'),
-                    "text": $form.find('.tab.segment[data-tab="' + $tabMenu.data('write') + '"] textarea').val()
-                },
+                "_csrf": csrf,
+                "mode": "gfm",
+                "context": $this.data('context'),
+                "text": $form.find('.tab.segment[data-tab="' + $tabMenu.data('write') + '"] textarea').val()
+            },
                 function (data) {
                     var $previewPanel = $form.find('.tab.segment[data-tab="' + $tabMenu.data('preview') + '"]');
                     $previewPanel.html(data);
@@ -63,9 +63,9 @@ function initEditDiffTab($form) {
     $tabMenu.find('.item[data-tab="' + $tabMenu.data('diff') + '"]').click(function () {
         var $this = $(this);
         $.post($this.data('url'), {
-                "_csrf": csrf,
-                "content": $form.find('.tab.segment[data-tab="' + $tabMenu.data('write') + '"] textarea').val()
-            },
+            "_csrf": csrf,
+            "content": $form.find('.tab.segment[data-tab="' + $tabMenu.data('write') + '"] textarea').val()
+        },
             function (data) {
                 var $diffPreviewPanel = $form.find('.tab.segment[data-tab="' + $tabMenu.data('diff') + '"]');
                 $diffPreviewPanel.html(data);
@@ -221,7 +221,7 @@ function initRepository() {
                 window.location.href = $choice.data('url');
                 console.log($choice.data('url'))
             },
-            message: {noResults: $dropdown.data('no-results')}
+            message: { noResults: $dropdown.data('no-results') }
         });
     }
 
@@ -346,9 +346,9 @@ function initRepository() {
             }
 
             $.post($(this).data('update-url'), {
-                    "_csrf": csrf,
-                    "title": $editInput.val()
-                },
+                "_csrf": csrf,
+                "title": $editInput.val()
+            },
                 function (data) {
                     $editInput.val(data.title);
                     $issueTitle.text(data.title);
@@ -390,10 +390,10 @@ function initRepository() {
                     $editContentZone.hide();
 
                     $.post($editContentZone.data('update-url'), {
-                            "_csrf": csrf,
-                            "content": $textarea.val(),
-                            "context": $editContentZone.data('context')
-                        },
+                        "_csrf": csrf,
+                        "content": $textarea.val(),
+                        "context": $editContentZone.data('context')
+                    },
                         function (data) {
                             if (data.length == 0) {
                                 $renderContent.html($('#no-content').html());
@@ -500,14 +500,14 @@ function initRepository() {
         initFilterSearchDropdown('.choose.branch .dropdown');
     }
     if ($('.repository.view.pull').length > 0) {
-    	$('.comment.merge.box input[name=merge_style]').change(function () {
-    		if ($(this).val() === 'create_merge_commit') {
-				$('.commit.description.field').show();
-			} else {
-				$('.commit.description.field').hide();
-			}
-		})
-	}
+        $('.comment.merge.box input[name=merge_style]').change(function () {
+            if ($(this).val() === 'create_merge_commit') {
+                $('.commit.description.field').show();
+            } else {
+                $('.commit.description.field').hide();
+            }
+        })
+    }
 }
 
 function initWikiForm() {
@@ -521,11 +521,11 @@ function initWikiForm() {
                 setTimeout(function () {
                     // FIXME: still send render request when return back to edit mode
                     $.post($editArea.data('url'), {
-                            "_csrf": csrf,
-                            "mode": "gfm",
-                            "context": $editArea.data('context'),
-                            "text": plainText
-                        },
+                        "_csrf": csrf,
+                        "mode": "gfm",
+                        "context": $editArea.data('context'),
+                        "text": plainText
+                    },
                         function (data) {
                             preview.innerHTML = '<div class="markdown">' + data + '</div>';
                             emojify.run($('.editor-preview')[0]);
@@ -603,11 +603,11 @@ function setSimpleMDE($editArea) {
             setTimeout(function () {
                 // FIXME: still send render request when return back to edit mode
                 $.post($editArea.data('url'), {
-                        "_csrf": csrf,
-                        "mode": "gfm",
-                        "context": $editArea.data('context'),
-                        "text": plainText
-                    },
+                    "_csrf": csrf,
+                    "mode": "gfm",
+                    "context": $editArea.data('context'),
+                    "text": plainText
+                },
                     function (data) {
                         preview.innerHTML = '<div class="markdown">' + data + '</div>';
                         emojify.run($('.editor-preview')[0]);
@@ -652,10 +652,10 @@ function initEditor() {
     $('.js-quick-pull-choice-option').change(function () {
         if ($(this).val() == 'commit-to-new-branch') {
             $('.quick-pull-branch-name').show();
-            $('.quick-pull-branch-name input').prop('required',true);
+            $('.quick-pull-branch-name input').prop('required', true);
         } else {
             $('.quick-pull-branch-name').hide();
-            $('.quick-pull-branch-name input').prop('required',false);
+            $('.quick-pull-branch-name input').prop('required', false);
         }
     });
 
@@ -705,7 +705,7 @@ function initEditor() {
 
         var tree_path = parts.join('/');
         $('#tree_path').val(tree_path);
-        $('#preview-tab').data('context', $('#preview-tab').data('root-context') + tree_path.substring(0, tree_path.lastIndexOf("/")+1));
+        $('#preview-tab').data('context', $('#preview-tab').data('root-context') + tree_path.substring(0, tree_path.lastIndexOf("/") + 1));
     }).trigger('keyup');
 
     var $editArea = $('.repository.editor textarea#edit_area');
@@ -775,7 +775,7 @@ function initEditor() {
         value = value.split('/');
         value = value[value.length - 1];
 
-        $.getJSON($editFilename.data('ec-url-prefix')+value, function(editorconfig) {
+        $.getJSON($editFilename.data('ec-url-prefix') + value, function (editorconfig) {
             if (editorconfig.indent_style === 'tab') {
                 codeMirrorEditor.setOption("indentWithTabs", true);
                 codeMirrorEditor.setOption('extraKeys', {});
@@ -785,7 +785,7 @@ function initEditor() {
                 // - https://github.com/codemirror/CodeMirror/issues/988
                 // - https://codemirror.net/doc/manual.html#keymaps
                 codeMirrorEditor.setOption('extraKeys', {
-                    Tab: function(cm) {
+                    Tab: function (cm) {
                         var spaces = Array(parseInt(cm.getOption("indentUnit")) + 1).join(" ");
                         cm.replaceSelection(spaces);
                     }
@@ -1131,7 +1131,7 @@ function initWebhookSettings() {
         $($(this).data('target') + ' .nohighlight').each(function () {
             var $this = $(this);
             $this.removeClass('nohighlight');
-            setTimeout(function(){ hljs.highlightBlock($this[0]) }, 500);
+            setTimeout(function () { hljs.highlightBlock($this[0]) }, 500);
         })
     })
 
@@ -1213,7 +1213,7 @@ $(document).ready(function () {
         var filenameDict = {};
         $dropzone.dropzone({
             url: $dropzone.data('upload-url'),
-            headers: {"X-Csrf-Token": csrf},
+            headers: { "X-Csrf-Token": csrf },
             maxFiles: $dropzone.data('max-file'),
             maxFilesize: $dropzone.data('max-size'),
             acceptedFiles: ($dropzone.data('accepts') === '*/*') ? null : $dropzone.data('accepts'),
@@ -1336,6 +1336,10 @@ $(document).ready(function () {
             window.location.href = $this.data('done-url');
         });
     });
+    // To make arbitrary form element to behave like a submit button
+    $('.submit-button').click(function () {
+        $($(this).data('form')).submit();
+    });
 
     // Check or select on option to enable/disable target region
     $('.enable-system').change(function () {
@@ -1459,7 +1463,7 @@ $(function () {
     $('form').areYouSure();
 });
 
- // getByteLen counts bytes in a string's UTF-8 representation.
+// getByteLen counts bytes in a string's UTF-8 representation.
 function getByteLen(normalVal) {
     // Force string type
     normalVal = String(normalVal);
@@ -1467,19 +1471,19 @@ function getByteLen(normalVal) {
     var byteLen = 0;
     for (var i = 0; i < normalVal.length; i++) {
         var c = normalVal.charCodeAt(i);
-        byteLen += c < (1 <<  7) ? 1 :
-                   c < (1 << 11) ? 2 :
-                   c < (1 << 16) ? 3 :
-                   c < (1 << 21) ? 4 :
-                   c < (1 << 26) ? 5 :
-                   c < (1 << 31) ? 6 : Number.NaN;
+        byteLen += c < (1 << 7) ? 1 :
+            c < (1 << 11) ? 2 :
+                c < (1 << 16) ? 3 :
+                    c < (1 << 21) ? 4 :
+                        c < (1 << 26) ? 5 :
+                            c < (1 << 31) ? 6 : Number.NaN;
     }
     return byteLen;
 }
 
 function showMessageMaxLength(maxLen, textElemId, counterId) {
-    var $msg = $('#'+textElemId);
-    $('#'+counterId).html(maxLen - getByteLen($msg.val()));
+    var $msg = $('#' + textElemId);
+    $('#' + counterId).html(maxLen - getByteLen($msg.val()));
 
     var onMessageKey = function (e) {
         var $msg = $(this);
@@ -1492,7 +1496,7 @@ function showMessageMaxLength(maxLen, textElemId, counterId) {
             remainder = 0;
         }
 
-        $('#'+counterId).html(remainder);
+        $('#' + counterId).html(remainder);
     };
 
     $msg.keyup(onMessageKey).keydown(onMessageKey);
diff --git a/public/less/_base.less b/public/less/_base.less
index 4f4c1ed5..a8a8f91a 100644
--- a/public/less/_base.less
+++ b/public/less/_base.less
@@ -384,6 +384,11 @@ footer {
 .hide {
 	display: none;
 }
+.display {
+	&.inline {
+		display: inline;
+	}
+}
 .center {
 	text-align: center;
 }
diff --git a/public/less/_user.less b/public/less/_user.less
index 8e52a980..3815434b 100644
--- a/public/less/_user.less
+++ b/public/less/_user.less
@@ -60,6 +60,9 @@
 
 	&.profile {
 		.ui.card {
+			.profile-avatar {
+				height: 287px;
+			}
 			.header {
 				word-break: break-all;
 			}
-- 
cgit v1.2.3