Skip to content

Commit 8dd1794

Browse files
author
Emmanouil Konstantinidis
committed
Select the method from the radio buttons
1 parent d7f31bb commit 8dd1794

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

rest_framework_docs/static/rest_framework_docs/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest_framework_docs/static/rest_framework_docs/js/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,32 @@ $( document ).ready(function() {
7676
var setupForm = function (data) {
7777
$('#urlInput').val(data.path);
7878

79+
// List Methods (Radio Buttons)
80+
// FIXME: Use regex - conver to JSON
81+
var methods = data.methods.replace("[", "").replace("]", "").replace(/'/g, "").replace(/\s/g, "").split(',');
82+
83+
$.each( methods, function( i, method ) {
84+
var methodClass = "radio-inline method " + method.toLowerCase();
85+
$('#methods').append("" +
86+
"<label class='" + methodClass + "'>"+
87+
"<input type='radio' name='methodRadio' value='" + method + "'>" + method +
88+
"</label>" +
89+
"")
90+
});
91+
92+
$(".radio-inline.method").off().on('click', function (evt) {
93+
// Prevent the event firing twice
94+
evt.stopPropagation();
95+
evt.preventDefault();
96+
97+
// Uncheck all checkboxes and
98+
// Check the clicked radio
99+
$('.radio-inline.method').removeClass('active');
100+
$('.radio-inline.method').children('input').attr('checked', false);
101+
$(this).addClass("active");
102+
$(this).children('input').first().attr('checked', true);
103+
});
104+
79105
$('#requestForm').submit(function (e) {
80106
// Prevent Submit
81107
e.preventDefault();

rest_framework_docs/static/rest_framework_docs/less/style.less

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,29 @@ body {
172172

173173
.request {
174174

175+
176+
.methods {
177+
178+
.method {
179+
padding: 4px 8px;
180+
color: #FFF;
181+
182+
&.get { background-color: @GetColor; }
183+
&.post { background-color: @PostColor; }
184+
&.patch { background-color: @PutColor; }
185+
&.put { background-color: @PatchColor; }
186+
&.delete { background-color: @DeleteColor; }
187+
&.options { background-color: @OptionsColor; }
188+
189+
&.active {
190+
border: 2px solid red;
191+
}
192+
193+
input[type='radio'] {
194+
display: none;
195+
}
196+
}
197+
}
175198
}
176199

177200
.response {

rest_framework_docs/templates/rest_framework_docs/home.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ <h3>Request</h3>
106106
<input type="text" class="form-control" id="urlInput" placeholder="Url">
107107
</div>
108108

109+
<div id="methods" class="methods"></div>
110+
109111
<h5>Headers</h5>
110112
<div class="form-group">
111113
<label for="exampleInputPassword1">Authorization</label>

0 commit comments

Comments
 (0)