Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11 from tomatohater/add_global_params

Adds global params section.
  • Loading branch information...
commit 1da2de6b8eb6ca7091db831ef00929b8c097fb9b 2 parents 201fda2 + dcd2c20
@fatiherikli fatiherikli authored
View
6 apiplayground/static/api_browser/css/screen.css
@@ -92,6 +92,12 @@ section.resource {
display: none;
}
+ section.resource ul li .global {
+ padding: 10px 0;
+ background-color: #fbfbfb;
+ border-bottom: 1px solid #e8e8e8;
+ }
+
section.resource ul li .result {
display: none;
}
View
13 apiplayground/static/api_browser/js/app.js
@@ -7,7 +7,11 @@ var APIBrowser = $.Class.extend({
selectors: {
input_fields: "input[type='text'], input[type='checkbox'], textarea, select",
+ copied_fields: "input[isacopy], textarea[isacopy], select[isacopy]",
+ // Global elements
+ global_inputs : "#global-form input[type='text'], #global-form input[type='checkbox'], #global-form textarea, #global-form select",
+
// API Resources
endpoint_form : ".endpoint form",
endpoint_anchor: ".endpoint a",
@@ -37,17 +41,26 @@ var APIBrowser = $.Class.extend({
load_rest_form: function () {
$(this.selectors.endpoint_form).restForm({
+ "presubmit": this.presubmit_form.bind(this),
"submit": this.submit_form.bind(this),
"complete": this.complete_ajax_request.bind(this)
});
},
+ presubmit_form: function (form) {
+ // Copy global paramaters to submitted form.
+ $(this.selectors.global_inputs).not(':submit').clone().hide().attr('isacopy','y').appendTo(form);
+ },
+
submit_form: function (form, request_headers) {
form.siblings(this.selectors.request).show().
find(this.selectors.code).html(request_headers.join("\n"));
},
complete_ajax_request: function (form, xhr) {
+ // Clear copied elements (prevent duplicates)
+ $(this.selectors.copied_fields).remove();
+
form.siblings(this.selectors.response_status).show().find(
this.selectors.code).html(xhr.statusText + " (" + xhr.status + ")");
View
5 apiplayground/static/api_browser/js/jquery.rest-form.js
@@ -14,6 +14,7 @@
$.fn.restForm = function (_options) {
var options = $.extend({
+ "presubmit": function () {},
"submit": function () {},
"complete": function () {}
}, _options);
@@ -32,6 +33,10 @@
this.each(function () {
$(this).submit(function () {
var form = $(this);
+
+ // firing presubmit event
+ options.presubmit.call(this, form);
+
var data = form.form2json();
var method = form.attr("method");
var url = form.attr("action");
View
2  apiplayground/templates/api_browser/base.html
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title>API Browser</title>
+ <title>{{ schema.title }}</title>
<link rel="stylesheet" href="{{ STATIC_URL }}api_browser/css/h5bp.css">
<link rel="stylesheet" href="{{ STATIC_URL }}api_browser/css/screen.css">
</head>
View
19 apiplayground/templates/api_browser/index.html
@@ -3,6 +3,25 @@
{% block content %}
{% load api_browser_tags %}
+
+{% get_global_forms schema as global_forms %}
+{% if global_forms.data_parameter_form.fields %}
+<section class="resource">
+ <ul>
+ <li>
+ <section class="global">
+ <form id="global-form">
+ <fieldset>
+ <legend>Global Parameters</legend>
+ {{ global_forms.data_parameter_form.as_p }}
+ </fieldset>
+ </form>
+ </section>
+ </li>
+ </ul>
+</section>
+{% endif %}
+
{% for resource in schema.resources %}
<section class="resource">
<header>
View
9 apiplayground/templatetags/api_browser_tags.py
@@ -5,6 +5,15 @@
@register.assignment_tag()
+def get_global_forms(schema):
+ data_parameter_form = build_data_form(schema.get("parameters", []))
+
+ return {
+ "data_parameter_form": data_parameter_form
+ }
+
+
+@register.assignment_tag()
def get_endpoint_forms(endpoint):
url_parameter_form = build_url_form(endpoint.get("url", ""))
data_parameter_form = build_data_form(endpoint.get("parameters", []))
Please sign in to comment.
Something went wrong with that request. Please try again.