mobile/android/chrome/content/aboutFeedback.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 "use strict";
     7 let Cc = Components.classes;
     8 let Ci = Components.interfaces;
     9 let Cu = Components.utils;
    11 Cu.import("resource://gre/modules/Services.jsm");
    12 Cu.import("resource://gre/modules/Messaging.jsm");
    13 document.addEventListener("DOMContentLoaded", init, false);
    15 function dump(a) {
    16   Services.console.logStringMessage(a);
    17 }
    19 function init() {
    20   let anchors = document.querySelectorAll(".maybe-later");
    21   for(let anchor of anchors) {
    22     anchor.addEventListener("click", maybeLater, false);
    23   }
    24   document.getElementById("happy-link").addEventListener("click", function(evt) {
    25     switchSection("happy");
    26   }, false);
    27   document.getElementById("sad-link").addEventListener("click", function(evt) {
    28     switchSection("sad");
    29   }, false);
    31   window.addEventListener("unload", uninit, false);
    33   document.getElementById("open-play-store").addEventListener("click", openPlayStore, false);
    34   document.forms[0].addEventListener("submit", sendFeedback, false);
    35   for (let anchor of document.querySelectorAll(".no-thanks")) {
    36     anchor.addEventListener("click", evt => window.close(), false);
    37   }
    39   let sumoLink = Services.urlFormatter.formatURLPref("app.support.baseURL");
    40   document.getElementById("sumo-link").href = sumoLink;
    42   window.addEventListener("popstate", function (aEvent) {
    43 	updateActiveSection(aEvent.state ? aEvent.state.section : "intro")
    44   }, false);
    46   // Fill "Last visited site" input with most recent history entry URL.
    47   Services.obs.addObserver(function observer(aSubject, aTopic, aData) {
    48 	document.getElementById("last-url").value = aData;
    49   }, "Feedback:LastUrl", false);
    51   sendMessageToJava({ type: "Feedback:LastUrl" });
    52 }
    54 function uninit() {
    55   Services.obs.removeObserver(this, "Feedback:LastUrl");
    56 }
    58 function switchSection(aSection) {
    59   history.pushState({ section: aSection }, aSection);
    60   updateActiveSection(aSection);
    61 }
    63 function updateActiveSection(aSection) {
    64   document.querySelector("section[active]").removeAttribute("active");
    65   document.getElementById(aSection).setAttribute("active", true);
    66 }
    68 function openPlayStore() {
    69   sendMessageToJava({ type: "Feedback:OpenPlayStore" });
    71   window.close();
    72 }
    74 function maybeLater() {
    75   window.close();
    77   sendMessageToJava({ type: "Feedback:MaybeLater" });
    78 }
    80 function sendFeedback(aEvent) {
    81   // Prevent the page from reloading.
    82   aEvent.preventDefault();
    84   let section = history.state.section;
    86   // Sanity check.
    87   if (section != "sad") {
    88 	Cu.reportError("Trying to send feedback from an invalid section: " + section);
    89 	return;
    90   }
    92   let sectionElement = document.getElementById(section);
    93   let descriptionElement = sectionElement.querySelector(".description");
    95   // Bail if the description value isn't valid. HTML5 form validation will take care
    96   // of showing an error message for us.
    97   if (!descriptionElement.validity.valid)
    98 	return;
   100   let data = new FormData();
   101   data.append("description", descriptionElement.value);
   102   data.append("_type", 2);
   104   let urlElement = document.getElementById("last-url");
   105   // Bail if the URL value isn't valid. HTML5 form validation will take care
   106   // of showing an error message for us.
   107   if (!urlElement.validity.valid)
   108 	return;
   110   // Only send a URL string if the user provided one.
   111   if (urlElement.value) {
   112 	data.append("add_url", true);
   113 	data.append("url", urlElement.value);
   114   }
   116   let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
   117   data.append("device", sysInfo.get("device"));
   118   data.append("manufacturer", sysInfo.get("manufacturer"));
   120   let req = new XMLHttpRequest();
   121   req.addEventListener("error", function() {
   122 	Cu.reportError("Error sending feedback to input.mozilla.org: " + req.statusText);
   123   }, false);
   124   req.addEventListener("abort", function() {
   125 	Cu.reportError("Aborted sending feedback to input.mozilla.org: " + req.statusText);
   126   }, false);
   128   let postURL = Services.urlFormatter.formatURLPref("app.feedback.postURL");
   129   req.open("POST", postURL, true);
   130   req.send(data);
   132   switchSection("thanks-" + section);
   133 }

mercurial