View source with formatted comments or as raw
    1/*  Part of ClioPatria
    2
    3    Author:        Michiel Hildebrand
    4    WWW:           http://www.swi-prolog.org
    5    Copyright (c)  2010-2012 University of Amsterdam
    6		             CWI, Asterdam
    7		             VU University Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36:- module(doc_components,
   37	  [ api_tester//1,		% +Path
   38	    api_tester//2,		% Path, Parameters
   39	    init_api_tester//0
   40	  ]).   41
   42/** <module> Documentation page utilities
   43
   44@author	Michiel Hildebrand
   45*/
   46
   47:- use_module(library(http/html_write)).   48:- use_module(library(http/html_head)).   49:- use_module(library(settings)).   50
   51/***************************************************
   52* required html resources
   53***************************************************/
   54
   55:- html_resource(js('api_test.js'),
   56		 [ requires([ js('parameters.js'),
   57			      yui('button/button.js'),
   58			      yui('container/container.js'),
   59			      yui('dragdrop/dragdrop.js'),
   60			      yui('container/assets/skins/sam/container.css')
   61			    ])
   62		 ]).   63
   64
   65/***************************************************
   66* api tester
   67***************************************************/
   68
   69%%	api_tester(+Path) is det.
   70%%	api_tester(+Path, +Parameters) is det.
   71%
   72%	Write HTML component with input field and interaction to test an
   73%	API request.
   74
   75api_tester(Path) -->
   76	api_tester(Path, ?).
   77
   78api_tester(Path, []) --> !,
   79	html_requires(js('api_test.js')),
   80	init_api_tester,
   81	html([ div(class('api_test'),
   82		   [ table(tbody(tr([ td([ span(class(path), [a(href(Path), Path)])]),
   83				      td([ input([type(submit), id(submit),
   84						  value(test),
   85						  onClick('apiTest(false,"'+Path+'");')])
   86					 ])
   87				    ])))
   88		   ])
   89	     ]).
   90api_tester(Path, _) -->
   91	html_requires(js('api_test.js')),
   92	init_api_tester,
   93	html([ div([class('api_test'), width('100%')],
   94		   [ table(tbody(tr([ td([span(class(path), [Path]), '?']),
   95				      td(class(input), input([id(api_input), type(text)])),
   96				      td([ input([type(submit), id(submit), value(test),
   97						  onClick('apiTest("api_input","'+Path+'");')])
   98					 ])
   99				    ]))),
  100		     p(['Enter key value pairs and separate each by a ', strong('&'),'. ',
  101		        'In this test field encoding of the values is not needed, \c
  102			as we do it for you. But, don\'t forget to encode in you \c
  103			own application.'])
  104		   ])
  105	     ]).
  106
  107
  108init_api_tester -->
  109	html(script(type('text/javascript'),
  110		    'initApiPanel();\n'))