Merge pull request #417 from colemanw/CRM-12339
[civicrm-core.git] / templates / CRM / Core / APIDoc.tpl
CommitLineData
6a488035
TO
1<html>
2<title>API Documentation</title>
3<style>
4{literal}
5#result {background:lightgrey;}
6#selector a {margin-right:10px;}
7.required {font-weight:bold;}
8.helpmsg {background:yellow;}
9.docHidden {display:none;}
10h2.entity {cursor:pointer}
11{/literal}
12</style>
6a488035
TO
13<script>
14if (!jQuery) {ldelim}
15var head= document.getElementsByTagName('head')[0];
16var script= document.createElement('script');
17script.type= 'text/javascript';
18script.src= CRM.config.resourceBase + 'js/packages/jquery/jquery.js';
19head.appendChild(script);
20{rdelim}
21restURL = '{crmURL p="civicrm/api/json"}';
22if (restURL.indexOf('?') == -1 )
23restURL = restURL + '?';
24else
25restURL = restURL + '&';
26{literal}
27if (typeof $ == "undefined") {
28 $ = cj;
29}
30
31function APIDoc(entity){
32 $detail=$('#detail_'+entity);
33 window.location.hash = entity;
34 if ($detail.length == 1) {
35 $detail.toggleClass('docHidden');
36 return;
37 } // else fetch the field list
38 return function(entity){
39 CRM.api (entity,'getFields',{version : 3}
40 ,{ success:function (data){
41 var h="<table id=detail_"+entity+"><tr><th>Attribute</th><th>Name</th><th>type</th></tr>";
42 var type="";
43 $.each(data.values, function(key, value) {
44 if (typeof value.type != 'undefined') {
45 var types={1:"integer",2:"string",4:"date",12:"date time",16:"boolean",32:"blob"}
46 type=value.type
47 if (type in types) type=types[value.type];
48 }
49 if(typeof value.title == 'undefined') {
50 value.title="";
51 }
52 if (typeof value.label != 'undefined') {
53 value.title = value.label + "&nbsp;<i>"+value.extends+"::"+value.groupTitle+"</i>";
54 type = value.data_type;
55 }
56 h=h+"<tr><td>"+key+"</td><td>"+value.title+"</td><td>"+type+"</td></td>";
57 });
58 h=h+"</table>";
59 $("#"+entity).after(h);
60 }
61 });
62 }(entity);//closure so entity is available into success.
63}
64
65
66cj(function ($) {
67 $('h2.entity').click ( function(){APIDoc($(this).attr('id'))} );
68 entity=window.location.hash;
69 if (entity.substring(0, 1) === '#') {
70 $entity=$(entity);
71 if ($entity.length == 1) {
72 $entity.click();
73 }
74 }
75 });
76{/literal}
77</script>
78<body>
79You can see the list of parameters for each entity by clicking on its name.<br>
80You can <a href='{crmURL p="civicrm/api/explorer"}'>explore and try</a> the api directly on your install.
81
82{crmAPI entity="Entity" action="get" var="entities" version=3}
83{foreach from=$entities.values item=entity}
84<h2 id="{$entity}" class="entity">{$entity}</option>
85{/foreach}
86</body>
87</html>