Advertisement
hejmus

Untitled

May 31st, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.75 KB | None | 0 0
  1. {% load url from future %}
  2. <html>
  3. <head>
  4. <title>JSON-RPC Browser</title>
  5. <script type="application/x-javascript" src="{% url "jsonrpc_browser" %}?f=mochikit.js"></script>
  6. <script type="application/x-javascript" src="{% url "jsonrpc_browser" %}?f=interpreter.js"></script>
  7. <script type="application/x-javascript">
  8. METHOD_NAMES = {{method_names_str|safe}};
  9.  
  10. function nextSibling(E) {
  11. do {
  12. E = E.nextSibling;
  13. } while (E && E.nodeType != 1);
  14. return E;
  15. }
  16.  
  17. function previousSibling(E) {
  18. do {
  19. E = E.previousSibling;
  20. } while (E && E.nodeType != 1);
  21. return E;
  22. }
  23.  
  24. Accordion = function(container, options) {
  25. this.showAccordion = null;
  26. this.currentAccordion = null;
  27. this.effets = [];
  28. this.animating = false;
  29. this.container = container;
  30. this.options = merge(Accordion.defaultOptions, options || {});
  31. this.duration = ((11 - this.options.resizeSpeed) * 0.15);
  32.  
  33. var c = $(container);
  34. if (!c) throw (container + " doesnt exist");
  35.  
  36. var self = this;
  37. var accordions = $$(format("#{0} .{1}", container, this.options.classNames.toggle));
  38. forEach(accordions,
  39. function(_accordion) {
  40. connect(_accordion, self.options.onEvent, function() { self.activate(_accordion); });
  41. var opts;
  42. if (self.options.direction == 'horizontal') {
  43. opts = {width: '0px'};
  44. } else {
  45. opts = {height: '0px'};
  46. }
  47. update(opts, {display: 'none'});
  48. self.currentAccordion = nextSibling(_accordion);
  49. setStyle(self.currentAccordion, opts);
  50. }
  51. );
  52. }
  53.  
  54. Accordion.defaultOptions = {
  55. resizeSpeed: 8,
  56. classNames: {
  57. toggle: 'accordion_toggle',
  58. toggleActive: 'accordion_toggle_active',
  59. content: 'accordion_content'
  60. },
  61. defaultSize: {
  62. height: null,
  63. width: null
  64. },
  65. direction: 'vertical',
  66. onEvent: 'onclick'
  67. }
  68.  
  69. Accordion.prototype.activate = function(accordion) {
  70. if (this.animating) return false;
  71. this.effects = [];
  72. this.currentAccordion = nextSibling(accordion);
  73. setStyle(this.currentAccordion, {display: 'block'});
  74. addElementClass(previousSibling(this.currentAccordion),
  75. this.options.classNames.toggleActive);
  76. if (this.options.direction == 'horizontal') {
  77. this.scaling = {scaleX: true, scaleY: false};
  78. } else {
  79. this.scaling = {scaleX: false, scaleY: true};
  80. }
  81. if (this.currentAccordion == this.showAccordion) {
  82. this.deactivate();
  83. } else {
  84. this._handleAccordion();
  85. }
  86. }
  87.  
  88. Accordion.prototype.deactivate = function() {
  89. var self = this;
  90. var opts = {
  91. duration: this.duration,
  92. transition: 'sinoidal',
  93. queue: {position: 'end', scope: 'accordionAnimation'},
  94. scaleContent: false,
  95. scaleMode: {
  96. oringnalHeight: this.options.defaultSize.height
  97. ? this.options.defaultSize.height
  98. : this.currentAccordion.scrollHeight,
  99. originalWidth: this.options.defaultSize.height
  100. ? this.options.defaultSize.width
  101. : this.currentAccordion.scrollWidth
  102. },
  103. afterFinish: function() {
  104. setStyle(self.showAccordion, {height: 'auto', display: 'none'});
  105. self.showAccordion = null;
  106. self.animating = false;
  107. }
  108. }
  109. update(opts, this.scaling);
  110. removeElementClass(previousSibling(this.showAccordion), this.options.classNames.toggleActive);
  111. new Scale(this.showAccordion, 0, opts);
  112. }
  113.  
  114. Accordion.prototype._handleAccordion = function() {
  115. var self = this;
  116. var opts = {
  117. sync: true,
  118. scaleFrom: 0,
  119. scaleContent: false,
  120. transition: 'sinoidal',
  121. scaleMode: {
  122. oringnalHeight: this.options.defaultSize.height
  123. ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
  124. originalWidth: this.options.defaultSize.height
  125. ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
  126. }
  127. };
  128. update(opts, this.scaling);
  129. this.effects.push(new Scale(this.currentAccordion, 100, opts));
  130. if (this.showAccordion) {
  131. removeElementClass(previousSibling(this.showAccordion), this.options.classNames.toggleActive);
  132. opts = {
  133. sync: true,
  134. scaleContent: false,
  135. transition: 'sinoidal'
  136. }
  137. update(opts, this.scaling);
  138. this.effects.push(new Scale(this.showAccordion, 0, opts));
  139. }
  140. new Parallel(this.effects, {
  141. duration: this.duration,
  142. queue: {position: 'end', scope: 'accordionAnimation'},
  143. beforeStart: function() { self.animating = true; },
  144. afterFinish: function() {
  145. if (self.showAccordion) {
  146. setStyle(self.showAccordion, {display: 'none'});
  147. }
  148. setStyle(self.currentAccordion, {height: 'auto'});
  149. self.showAccordion = self.currentAccordion;
  150. self.animating = false;
  151. }
  152. });
  153. }
  154.  
  155. function jsonMethod(name) {
  156. return function() {
  157. var req = serializeJSON({
  158. 'id': 'jsonrpc',
  159. 'params': flattenArguments(arguments),
  160. 'method': name,
  161. 'jsonrpc': '1.0'
  162. });
  163. writeln('Requesting ->');
  164. writeln(SPAN({'class': 'json_req'}, req));
  165. var d = doXHR('{% url "jsonrpc_mountpoint" %}', {
  166. 'method': 'POST',
  167. 'sendContent': req,
  168. 'mimeType': 'application/x-javascript'
  169. });
  170. d.addCallback(function (req) {
  171. writeln('Got ->');
  172. writeln(SPAN({'class': 'json_req'}, req.responseText));
  173. req = evalJSONRequest(req);
  174. window.json_result = req;
  175. window.json_error = null;
  176. return req;
  177. });
  178. d.addErrback(function (err) {
  179. writeln('Error ->');
  180. req_err = err;
  181. try {
  182. err = evalJSONRequest(err.req);
  183. if (!err)
  184. throw('');
  185. } catch (e) { err = req_err; }
  186. writeln(SPAN({'class': 'json_req'}, 'STATUS: ' + req_err.number),
  187. BR(),
  188. SPAN({'class': 'json_req'}, repr(err)));
  189. window.json_result = null;
  190. window.json_error = err;
  191. return err;
  192. })
  193. return d;
  194. }
  195. }
  196. // init method accordion
  197. addLoadEvent(
  198. function() {
  199. new Accordion('method_accordion');
  200. });
  201. // bind jsonrpc methods under window.jsonrpc
  202. addLoadEvent(
  203. function() {
  204. window.json_result = null;
  205. window.json_error = null;
  206. forEach(METHOD_NAMES,
  207. function(method) {
  208. var part = 'jsonrpc';
  209. var parts = method.split('.');
  210. var ns = window;
  211. do {
  212. if (typeof ns[part] == 'undefined')
  213. ns[part] = {};
  214. ns = ns[part];
  215. part = parts.shift();
  216. } while (parts.length);
  217. ns[part] = jsonMethod(method);
  218. });
  219. });
  220. </script>
  221. <style>
  222. body {
  223. font-family: utopia, 'lucidamac bold', 'lucida grande', arial, sans-serif;
  224. background-color: #464646;
  225. }
  226. #header {
  227. font-family: Georgia, "Times New Roman", times, serif;
  228. font-size: 2em;
  229. width: 600px;
  230. height: 40px;
  231. margin: 10 auto;
  232. color: white;
  233. }
  234. #container {
  235. -webkit-border-radius:10px;
  236. background-color: #fefff1;
  237. width: 600px;
  238. /*height: 600px;*/
  239. margin: 0 auto;
  240. padding: 10px;
  241. }
  242. #container h2 { padding: 0; margin: 0 0 5px 0; }
  243. textarea.textbox {
  244. font-family: Monaco, "lucida console", Courier;
  245. border: 1px solid #CCCCCC;
  246. font-size: .60em;
  247. padding: 2px 4px;
  248. margin-top: .3em;
  249. }
  250.  
  251. input.textbox {
  252. font-family: Monaco, "lucida console", Courier;
  253. border: 1px solid #CCCCCC;
  254. font-size: .60em;
  255. padding: 2px 4px;
  256. margin-top: .3em;
  257. }
  258.  
  259. #interpreter_area {
  260. display: block;
  261. border: 1px solid #CCCCCC;
  262. padding: 2px 4px;
  263. margin-top: .3em;
  264. width: 590px;
  265. height: 300px;
  266. overflow: auto;
  267. }
  268.  
  269. #interpreter_output {
  270. display: inline;
  271. font-family: Monaco, "lucida console", Courier;
  272. font-size: .60em;
  273. }
  274.  
  275. #interpreter_output span {
  276. white-space: -moz-pre-wrap; /* Mozilla */
  277. white-space: -o-pre-wrap; /* Opera 7 */
  278. white-space: pre-wrap; /* CSS 2.1 */
  279. white-space: pre-line; /* CSS 3 (and 2.1 as well, actually) */
  280. word-wrap: break-word; /* IE */
  281. wrap-option: emergency; /* CSS 3 */
  282. }
  283.  
  284. input.textbox:focus { background-color: #FFFEE3; }
  285.  
  286. .code { color: blue; }
  287. .data { color: black; }
  288. .error { color: red; }
  289. .banner { color: green; }
  290. .invisible { display: none; }
  291.  
  292. .accordion_toggle {
  293. display: block;
  294. height: 30px;
  295. width: 580px;
  296. background-color: #a9d06a;
  297. padding: 0 10px 0 10px;
  298. line-height: 30px;
  299. color: #ffffff;
  300. font-weight: normal;
  301. text-decoration: none;
  302. outline: none;
  303. font-size: 12px;
  304. color: #000000;
  305. border-bottom: 1px solid #cde99f;
  306. cursor: pointer;
  307. margin: 0 0 0 0;
  308. }
  309.  
  310. .accordion_toggle_active {
  311. background-color: #0070b0;
  312. color: #ffffff;
  313. border-bottom: 1px solid #003c5f;
  314. }
  315.  
  316. .accordion_content {
  317. background-color: #ffffff;
  318. color: #444444;
  319. overflow: hidden;
  320. }
  321.  
  322. /*div.collapsable h3 {
  323. font-size: .9em;
  324. margin: 0 0 4px 0;
  325. padding: 1px 0 1px 0;
  326. background-color: #d9ffd9;
  327. border-width: 1px 0 1px 0;
  328. border-color: #00bd3a;
  329. border-style: solid;
  330. }*/
  331. div.collapsable table {
  332. font-size: 12px;
  333. margin-left: 6px;
  334. }
  335. div.collapsable th { text-align: left; padding: 0px; margin: 0px; }
  336. div.collapsable td { font-family: Monaco, "lucida console", Courier; padding: 0px; margin: 0px; }
  337.  
  338. span.json_req { color: #d04e00; display: inline-block; margin: 0; padding: 0 0 0 5px; }
  339.  
  340. ul.interpreter_help { padding: 0 0 0 20px; margin: 0; font-size: 12px; }
  341. ul.interpreter_help li {padding: 0; margin: 0; }
  342. div.footer { margin-top: 10px; margin-bottom: 10px; font-size: 11px; color: white; text-align: center; }
  343. div.footer a, div.footer a:visited, div.footer a:hover, div.footer a:active { color: #9affab; }
  344.  
  345. span.type { color: rgb(96,45,12); font-weight: bold; }
  346. </style>
  347. </head>
  348. <body>
  349. <div id="header">JSON-RPC Browser</div>
  350. <div id="container">
  351. <h2>Methods</h2>
  352. <div id="method_accordion" class="collapsable">
  353. {% for method in methods %}
  354. <h3 class="accordion_toggle">{{method.name}}</h3>
  355. <div class="accordion_content">
  356. <table><tbody valign="top">
  357. <tr><th>signature</th><td>
  358. {{method.name}}({% for param in method.params %}{{param.name}}{% if not forloop.last %}, {% endif %}{% endfor %})</td></tr>
  359. <tr><th>arguments</th><td>
  360. {% if method.params %}
  361. {% for param in method.params %}
  362. {{param.name}} : <span class="type">{{param.type}}</span>
  363. {% if not forloop.last %}<br /> {% endif %}
  364. {% endfor %}
  365. {% else %}
  366. <em>None Specified</em>
  367. {% endif %}
  368. </td></tr>
  369. <tr><th>returns</th><td><span class="type">{{method.return.type}}</span></td></tr>
  370. <tr><th>idempotent</th><td>{{method.idempotent}}</td></tr>
  371. <tr><th>summary</th><td>{{method.summary}}</td></tr>
  372. </tbody>
  373. </table>
  374. </div>
  375. {% endfor %}
  376. </div><br />
  377. <h2>Console</h2>
  378. <form id="interpreter_form" autocomplete="off">
  379. <div id="interpreter_area">
  380. <div id="interpreter_output"></div>
  381. </div>
  382. <div id="oneline">
  383. <input id="interpreter_text" name="input_text" type="text" class="textbox" style="width:600px;" />
  384. </div>
  385. <div id="multiline" style="display:none">
  386. <textarea id="interpreter_textarea" name="input_textarea" type="text" class="textbox" cols="97" rows="10"></textarea>
  387. <br />
  388. </div>
  389. </form>
  390. <ul class="interpreter_help">
  391. <li>JSON-RPC methods are exposed through the <strong><code>jsonrpc</code></strong> global.</li>
  392. <li>Call a method just as you would a javascript one: <code>jsonrpc.jsonrpc.test('arg1')</code></li>
  393. <li>Calling a method returns a Deferred (see the <a href="http://www.mochikit.com/doc/html/MochiKit/Async.html">MochiKit docs</a>).
  394. As soon as the deferred returns the result is available by the global variables <strong><code>json_result</code></strong> or <strong><code>json_error</code></strong></li>
  395. <li>Use <code>dir</code> to explore the namespace: <code>dir(jsonrpc)</code></li>
  396. </ul>
  397. </div>
  398. <div class="footer">Powered by <a href="http://djangoproject.com/">Django</a>,
  399. <a href="http://github.com/samuraisam/django-json-rpc">django-json-rpc</a> and <a href="http://mochikit.com/">MochiKit</a>
  400. </body>
  401. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement