Advertisement
the0938

Test receipt service.

Apr 19th, 2018
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 5.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.   <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7.   <title>Тестирование сервиса квитанций</title>
  8.   <link
  9.    rel="stylesheet"
  10.    href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css"
  11.    integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb"
  12.    crossorigin="anonymous"
  13.    >
  14.   <script
  15.    src="http://code.jquery.com/jquery-3.2.1.min.js"
  16.    integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  17.    crossorigin="anonymous"
  18.    ></script>
  19.   <script
  20.    src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
  21.    integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
  22.    crossorigin="anonymous"
  23.    ></script>
  24.   <link rel="stylesheet" href="http://esironal.github.io/cmtouch/lib/codemirror.css">
  25.   <link rel="stylesheet" href="http://esironal.github.io/cmtouch/addon/hint/show-hint.css">
  26.   <link rel="stylesheet" href="http://esironal.github.io/cmtouch/theme/neonsyntax.css">
  27.   <script src="http://esironal.github.io/cmtouch/lib/codemirror.js"></script>
  28.   <script src="http://esironal.github.io/cmtouch/addon/hint/show-hint.js"></script>
  29.   <script src="http://esironal.github.io/cmtouch/addon/hint/xml-hint.js"></script>
  30.   <script src="http://esironal.github.io/cmtouch/addon/hint/html-hint.js"></script>
  31.   <script src="http://esironal.github.io/cmtouch/mode/xml/xml.js"></script>
  32.   <script src="http://esironal.github.io/cmtouch/mode/javascript/javascript.js"></script>
  33.   <script src="http://esironal.github.io/cmtouch/mode/css/css.js"></script>
  34.   <script src="http://esironal.github.io/cmtouch/mode/htmlmixed/htmlmixed.js"></script>
  35.   <script src="http://esironal.github.io/cmtouch/addon/selection/active-line.js"></script>
  36.   <script src="http://esironal.github.io/cmtouch/addon/edit/matchbrackets.js"></script>
  37.   <style type="text/css">
  38.     #txtArgs {
  39.       /* Offset: 56+48+70+16+24+8+16+38+24 */
  40.       min-height: calc(100vh - 300px);
  41.     }
  42.     .CodeMirror {
  43.       border: 1px solid #ced4da;
  44.       border-radius: .25rem;
  45.     }
  46.   </style>
  47. </head>
  48. <body>
  49.   <nav class="navbar navbar-dark bg-dark">
  50.     <a class="navbar-brand" href="#">Тестирование сервиса квитанций</a>
  51.   </nav>
  52.   <div class="container  pt-5">
  53.     <form action="" method="post" class="form" id="testForm">
  54.       <div class="form-group">
  55.         <label for="testUrl">Адрес сервиса</label>
  56.         <input
  57.          placeholder="Введите адрес сервиса"
  58.          class="form-control"
  59.          id="testUrl"
  60.          type="text"
  61.          name="url"
  62.          required=""
  63.          value="http://localhost:8733/ReceiptService/DoReceipt"
  64.          >
  65.       </div>
  66.       <div class="form-group">
  67.         <label for="testParam">Параметр запроса</label>
  68.         <input
  69.          placeholder="Введите параметр запроса, который принимает JSON"
  70.          class="form-control"
  71.          id="testParam"
  72.          type="text"
  73.          name="url"
  74.          required=""
  75.          value="receipt"
  76.          >
  77.       </div>
  78.       <div class="form-group">
  79.         <label for="testData">Значение параметра (в JSON)</label>
  80.         <textarea
  81.          placeholder="Введите JSON со входными параметрами"
  82.          class="form-control"
  83.          id="testData"
  84.          type="text"
  85.          name="ARGS"
  86.          ></textarea>
  87.       </div>
  88.       <button type="submit" class="btn btn-primary">Отправить</button>
  89.     </form>
  90.   </div>
  91.   <script type="text/plain" id="jsonPreset">
  92.     {
  93.       "templateId": 0,
  94.       "ReceiptId": "",
  95.       "INN": "",
  96.       "Email": "fake@mail.mail",
  97.       "Phone": "+7 (987) 654-32-10",
  98.       "TotalSum": 0.0,
  99.       "PaidSum": 0.0,
  100.       "Items": [
  101.         {
  102.           "Name": "",
  103.           "Price": 0.0,
  104.           "Quantity": 0.0,
  105.           "Sum": 0.0
  106.         }
  107.       ]
  108.     }
  109.   </script>
  110.   <script type="text/javascript">
  111.     var jsonPresetNode = document.getElementById('jsonPreset');
  112.     var jsonPreset = jsonPresetNode ? jsonPresetNode.innerHTML : '';
  113.  
  114.     jsonPreset = jsonPreset.replace(/^\s{4}/gm, '').replace(/^\s+|\s+$/g, '');
  115.  
  116.     var testDataNode = document.getElementById('testData');
  117.     testDataNode.value = jsonPreset;
  118.  
  119.     var testUrlNode = document.getElementById('testUrl');
  120.     var testParamNode = document.getElementById('testParam');
  121.  
  122.     cdmArgs = CodeMirror.fromTextArea(testDataNode, {
  123.       lineNumbers: true,
  124.       mode: {
  125.           name: "javascript",
  126.           json: true
  127.       }
  128.     });
  129.  
  130.     var onSuccess = function() {
  131.       alert("Запрос прошел удачно. "
  132.         + "Чтобы посмотреть подробности, откройте браузерную консоль отладки, вкладка 'Network'.");
  133.     };
  134.  
  135.     var onError = function(xhr) {
  136.       alert("Запрос не удался. "
  137.         + "Чтобы посмотреть подробности, откройте браузерную консоль отладки, вкладка 'Network'.");
  138.     };
  139.  
  140.     var testForm = $(document.getElementById('testForm'));
  141.  
  142.     testForm.submit(function(e) {
  143.       e.preventDefault();
  144.  
  145.       var json = testDataNode.value.replace(/\s+/g, '');
  146.       var url = testUrlNode.value;
  147.       var param = testParamNode.value;
  148.  
  149.       var data = {};
  150.       data[param] = json;
  151.  
  152.       $.ajax({
  153.         type: 'post',
  154.         url: url,
  155.         data: data,
  156.         success: onSuccess,
  157.         error: onError
  158.       });
  159.     });
  160.   </script>
  161. </body>
  162. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement