Advertisement
Guest User

Untitled

a guest
May 18th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. <?php
  2.  
  3. //webform
  4.  
  5. // Print out the progress bar at the top of the page
  6. print drupal_render($form['progressbar']);
  7.  
  8. // Print out the preview message if on the preview page.
  9. if (isset($form['preview_message'])) {
  10. print '<div class="messages warning">';
  11. print drupal_render($form['preview_message']);
  12. print '</div>';
  13. }
  14.  
  15. // Print out the main part of the form.
  16. // Feel free to break this up and move the pieces within the array.
  17. print drupal_render($form['submitted']);
  18.  
  19. // Always print out the entire $form. This renders the remaining pieces of the
  20. // form that haven't yet been rendered above (buttons, hidden elements, etc).
  21. print drupal_render_children($form);
  22.  
  23. $node = $form['#node'];
  24. $sid = $form_state['values']['details']['sid'] ? (int) $form_state['values']['details']['sid'] : NULL;
  25.  
  26. if (!$sid) {
  27. // Create a new submission object.
  28. $submission = (object) array(
  29. 'nid' => $node->nid,
  30. 'uid' => $form_state['values']['details']['uid'],
  31. 'data' => webform_submission_data($node, $form_state['values']['submitted']),
  32. );
  33. if (isset($_POST['submitted[approved]'])) {
  34. if (isset($_POST['op'])) {
  35. if ($sid > 0 || $sid != NULL) {
  36. $stored_procedure = "call GetAPITUData($sid)";
  37. $stored_procedure_res = db_query($stored_procedure)->fetchAssoc();
  38.  
  39. drupal_add_js('Drupal.behaviors.post1 = function($stored_procedure_res) { load(); }', 'file');
  40. }
  41. }
  42. }
  43. };
  44. ?>
  45.  
  46. var authToken;
  47. var savedAlertId;
  48.  
  49. (function ($) {
  50. Drupal.behaviors.post1 = {
  51. attach: function (tudata) {
  52.  
  53. var loginData = {
  54. grant_type: 'password',
  55. username: 'test',
  56. password: 'hooha'};
  57.  
  58. $.ajax({
  59. type: 'POST',
  60. url: 'https://webapp.mysite.com/oauth/token',
  61. data: loginData,
  62. success: function (data) {
  63. authToken = data.access_token;
  64.  
  65. var tudata1 = {
  66. // Provide when updating
  67. id: 0,
  68. description: 'this is another',
  69. alertTypeId: 1,
  70. // Optional; will default to date/time of upload
  71. reportedOn: '1/26/2016',
  72. // Optional
  73. expiresOn: '2/13/2016',
  74. latitude: -14,
  75. longitude: 126,
  76. shouldShowOnMap: true,
  77. shouldPushToUsers: false,
  78.  
  79. source: 2
  80. };
  81.  
  82. $.ajax ({
  83. type: 'POST',
  84. url: 'https://webapp.mysite.com/api/Alerts/AlertsApi/CreateOrUpdate',
  85. headers: {
  86. Authorization: 'Bearer ' + authToken
  87. },
  88. data: tudata1,
  89. success: function (data) {
  90. savedAlertId = data;
  91. console.debug('mydata:' + headers);
  92. },
  93. error: function(xhr, status, headers) {
  94. var response = $.parseJSON(xhr.responseText);
  95. console.debug('responseText: ' + response.status);
  96. }
  97. });
  98. }
  99.  
  100. });
  101. return savedAlertId;
  102. }
  103. }
  104.  
  105. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement