1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/chrome/content/aboutFeedback.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,133 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +let Cc = Components.classes; 1.11 +let Ci = Components.interfaces; 1.12 +let Cu = Components.utils; 1.13 + 1.14 +Cu.import("resource://gre/modules/Services.jsm"); 1.15 +Cu.import("resource://gre/modules/Messaging.jsm"); 1.16 +document.addEventListener("DOMContentLoaded", init, false); 1.17 + 1.18 +function dump(a) { 1.19 + Services.console.logStringMessage(a); 1.20 +} 1.21 + 1.22 +function init() { 1.23 + let anchors = document.querySelectorAll(".maybe-later"); 1.24 + for(let anchor of anchors) { 1.25 + anchor.addEventListener("click", maybeLater, false); 1.26 + } 1.27 + document.getElementById("happy-link").addEventListener("click", function(evt) { 1.28 + switchSection("happy"); 1.29 + }, false); 1.30 + document.getElementById("sad-link").addEventListener("click", function(evt) { 1.31 + switchSection("sad"); 1.32 + }, false); 1.33 + 1.34 + window.addEventListener("unload", uninit, false); 1.35 + 1.36 + document.getElementById("open-play-store").addEventListener("click", openPlayStore, false); 1.37 + document.forms[0].addEventListener("submit", sendFeedback, false); 1.38 + for (let anchor of document.querySelectorAll(".no-thanks")) { 1.39 + anchor.addEventListener("click", evt => window.close(), false); 1.40 + } 1.41 + 1.42 + let sumoLink = Services.urlFormatter.formatURLPref("app.support.baseURL"); 1.43 + document.getElementById("sumo-link").href = sumoLink; 1.44 + 1.45 + window.addEventListener("popstate", function (aEvent) { 1.46 + updateActiveSection(aEvent.state ? aEvent.state.section : "intro") 1.47 + }, false); 1.48 + 1.49 + // Fill "Last visited site" input with most recent history entry URL. 1.50 + Services.obs.addObserver(function observer(aSubject, aTopic, aData) { 1.51 + document.getElementById("last-url").value = aData; 1.52 + }, "Feedback:LastUrl", false); 1.53 + 1.54 + sendMessageToJava({ type: "Feedback:LastUrl" }); 1.55 +} 1.56 + 1.57 +function uninit() { 1.58 + Services.obs.removeObserver(this, "Feedback:LastUrl"); 1.59 +} 1.60 + 1.61 +function switchSection(aSection) { 1.62 + history.pushState({ section: aSection }, aSection); 1.63 + updateActiveSection(aSection); 1.64 +} 1.65 + 1.66 +function updateActiveSection(aSection) { 1.67 + document.querySelector("section[active]").removeAttribute("active"); 1.68 + document.getElementById(aSection).setAttribute("active", true); 1.69 +} 1.70 + 1.71 +function openPlayStore() { 1.72 + sendMessageToJava({ type: "Feedback:OpenPlayStore" }); 1.73 + 1.74 + window.close(); 1.75 +} 1.76 + 1.77 +function maybeLater() { 1.78 + window.close(); 1.79 + 1.80 + sendMessageToJava({ type: "Feedback:MaybeLater" }); 1.81 +} 1.82 + 1.83 +function sendFeedback(aEvent) { 1.84 + // Prevent the page from reloading. 1.85 + aEvent.preventDefault(); 1.86 + 1.87 + let section = history.state.section; 1.88 + 1.89 + // Sanity check. 1.90 + if (section != "sad") { 1.91 + Cu.reportError("Trying to send feedback from an invalid section: " + section); 1.92 + return; 1.93 + } 1.94 + 1.95 + let sectionElement = document.getElementById(section); 1.96 + let descriptionElement = sectionElement.querySelector(".description"); 1.97 + 1.98 + // Bail if the description value isn't valid. HTML5 form validation will take care 1.99 + // of showing an error message for us. 1.100 + if (!descriptionElement.validity.valid) 1.101 + return; 1.102 + 1.103 + let data = new FormData(); 1.104 + data.append("description", descriptionElement.value); 1.105 + data.append("_type", 2); 1.106 + 1.107 + let urlElement = document.getElementById("last-url"); 1.108 + // Bail if the URL value isn't valid. HTML5 form validation will take care 1.109 + // of showing an error message for us. 1.110 + if (!urlElement.validity.valid) 1.111 + return; 1.112 + 1.113 + // Only send a URL string if the user provided one. 1.114 + if (urlElement.value) { 1.115 + data.append("add_url", true); 1.116 + data.append("url", urlElement.value); 1.117 + } 1.118 + 1.119 + let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2); 1.120 + data.append("device", sysInfo.get("device")); 1.121 + data.append("manufacturer", sysInfo.get("manufacturer")); 1.122 + 1.123 + let req = new XMLHttpRequest(); 1.124 + req.addEventListener("error", function() { 1.125 + Cu.reportError("Error sending feedback to input.mozilla.org: " + req.statusText); 1.126 + }, false); 1.127 + req.addEventListener("abort", function() { 1.128 + Cu.reportError("Aborted sending feedback to input.mozilla.org: " + req.statusText); 1.129 + }, false); 1.130 + 1.131 + let postURL = Services.urlFormatter.formatURLPref("app.feedback.postURL"); 1.132 + req.open("POST", postURL, true); 1.133 + req.send(data); 1.134 + 1.135 + switchSection("thanks-" + section); 1.136 +}