3112: add ajax event handling
authorradhika <radhika@curoverse.com>
Fri, 15 Aug 2014 17:22:18 +0000 (13:22 -0400)
committerradhika <radhika@curoverse.com>
Fri, 15 Aug 2014 17:22:18 +0000 (13:22 -0400)
apps/workbench/app/views/application/_report_issue_popup.html.erb
apps/workbench/app/views/application/report_issue.js.erb
apps/workbench/app/views/application/report_issue_popup.js.erb

index 31c76d09d9dedb545e7184b3c8b8e8524961c08f..260059395d2d52d2be724ac2f6d831b8646c8699 100644 (file)
@@ -7,7 +7,8 @@
   support_email = Rails.configuration.support_email_address
 
   additional_info = {}
-  additional_info['Current Location'] = @popup_params[:current_location]
+  additional_info['Current location'] = @popup_params[:current_location]
+  additional_info['User UUID'] = current_user.uuid if current_user
   additional_info['User email'] = current_user.email if current_user
 
   additional_info_str = additional_info.map {|k,v| "#{k}=#{v}"}.join("\n")
@@ -25,7 +26,7 @@
 <div class="modal-dialog modal-with-loading-spinner">
   <div class="modal-content">
 
-    <%= form_tag report_issue_path, {id: 'report-issue-form', name: 'report-issue-form', method: 'post',
+    <%= form_tag report_issue_path, {name: 'report-issue-form', method: 'post',
         class: 'form-horizontal', remote: true} do %>
 
       <%
@@ -97,8 +98,8 @@
 
       <div class="modal-footer">
         <% if @popup_params[:popup_type] == 'report' %>
-          <button type="submit" id="register" class="btn btn-primary" autofocus>Report issue</button>
-          <button class="btn btn-default" onClick="reset_form()" data-dismiss="modal" aria-hidden="true">Cancel</button>
+          <button type="submit" id="report-issue-submit" class="btn btn-primary report-issue-submit" autofocus>Report issue</button>
+          <button class="btn btn-default report-issue-cancel" id="report-issue-cancel" onClick="reset_form()" data-dismiss="modal" aria-hidden="true">Cancel</button>
         <% else %>
           <button class="btn btn-default" onClick="reset_form()" data-dismiss="modal" aria-hidden="true">Close</button>
         <% end %>
index 6247a3c62f3b9c9a2b5b7e5ccc6386b4b6cd8ef6..26113a9b8ea3ccd0057f2add6c437e06e4779c29 100644 (file)
@@ -1,2 +1 @@
-$("#report-issue-modal-window").modal("hide");
-document.location.reload();
+// Let ajax events handle hiding of the popup.
index 59aedbcf6e585484983715753f55596f97df08e4..48b66dcb9ef00ff7ef0e6e3e785723f6b0886936 100644 (file)
@@ -5,3 +5,44 @@ function reset_form() {
   $('#report_issue_text').val("");
   $('#additional_info').val("");
 }
+
+// ajax handling for report-issue function
+$(document).
+  on('ajax:send', function() {
+    var sendButton = document.getElementById('report-issue-submit');
+    if (sendButton) {
+      var text = document.getElementById('report-issue-submit').firstChild;
+      text.data = "Sending...";
+      sendButton.disabled = true;
+    }
+    var cancelButton = document.getElementById('report-issue-cancel');
+    if (cancelButton) {
+      var text = document.getElementById('report-issue-cancel').firstChild;
+      text.data = "Close";
+    }
+    $('div').remove('.modal-footer-status');
+  }).
+  on('ajax:success', function() {
+    var sendButton = document.getElementById('report-issue-submit');
+    if (sendButton && sendButton.disabled) {
+      var text = document.getElementById('report-issue-submit').firstChild;
+      text.data = "Report sent";
+      $('div').remove('.modal-footer-status');
+      $('.modal-footer').append('<div class="modal-footer-status pull-left"><div><p>Thanks for reporting this issue!</p></div></div>');
+    }
+  }).
+  on('ajax:failure', function() {
+    var sendButton = document.getElementById('report-issue-submit');
+    if (sendButton && sendButton.disabled) {
+      $('div').remove('.modal-footer-status');
+      $('.modal-footer').append('<div class="modal-footer-status pull-left"></br><p>We are sorry. We could not submit your report! We really want this to work, though -- please try again.</p></div>');
+      var text = document.getElementById('report-issue-submit').firstChild;
+      text.data = "Report issue";
+      sendButton.disabled = false;
+    }
+    var cancelButton = document.getElementById('report-issue-cancel');
+    if (cancelButton) {
+      var text = document.getElementById('report-issue-cancel').firstChild;
+      text.data = "Cancel";
+    }
+  });