Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/survey.js

Issue 8382011: Applied changes from emailed code review (Closed)
Patch Set: Created Sept. 18, 2012, 2:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 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, 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/. */ 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 Cu.import("resource://gre/modules/Services.jsm"); 5 Cu.import("resource://gre/modules/Services.jsm");
6 6
7 let {Prefs} = require("prefs"); 7 let {Prefs} = require("prefs");
8 8
9 let win = null;
10 let surveyLang = null; 9 let surveyLang = null;
11 let surveyUrl = "http://urlfixer.org"; //"http://adblockplus.org/usersurvey/inde x.php?sid=68316"; 10 let surveyUrl = "http://urlfixer.org"; //"http://adblockplus.org/usersurvey/inde x.php?sid=68316";
12 11
13 let langData = { 12 exports.incrementCorrectionsCounter = incrementCorrectionsCounter;
14 en: { 13 function incrementCorrectionsCounter()
15 title: "Tell us your opinion", 14 {
16 question: "We would like to ask you a few questions about URL Fixer to help us improve it. If you can spare 5 minutes please click the button below to take the survey.", 15 // Only users with 5 URL corrections
17 note: "This is a one-time message and will not appear again.", 16 if (++Prefs.corrections_count == 5)
18 accept: "Take the survey", 17 {
19 decline: "Maybe some other time" 18 initSurvey();
20 },
21 de: {
22 title: "Sagen Sie uns Ihre Meinung",
23 question: "Wir w\xFCrden Ihnen gerne einige Fragen zu URL Fixer stellen, um es verbessern zu k\xF6nnen. Falls Sie gerade 5 Minuten haben, dr\xFCcken Sie bit te die Taste unten, um an der Nutzerumfrage teilzunehmen.",
24 note: "Das ist eine einmalige Nachricht, die nicht wieder erscheinen wird.",
25 accept: "An der Umfrage teilnehmen",
26 decline: "Vielleicht ein anderes Mal"
27 },
28 ru: {
29 title: decodeURIComponent("%D0%9F%D0%BE%D0%B4%D0%B5%D0%BB%D0%B8%D1%82%D0%B5% D1%81%D1%8C%20%D1%81%20%D0%BD%D0%B0%D0%BC%D0%B8%20%D1%81%D0%B2%D0%BE%D0%B8%D0%BC %20%D0%BC%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5%D0%BC"),
30 question: decodeURIComponent("%D0%9C%D1%8B%20%D1%85%D0%BE%D1%82%D0%B5%D0%BB% D0%B8%20%D0%B1%D1%8B%20%D0%B7%D0%B0%D0%B4%D0%B0%D1%82%D1%8C%20%D0%B2%D0%B0%D0%BC %20%D0%BD%D0%B5%D0%BA%D0%BE%D1%82%D0%BE%D1%80%D1%8B%D0%B5%20%D0%B2%D0%BE%D0%BF%D 1%80%D0%BE%D1%81%D1%8B%20%D0%BE%D0%B1%20URL%20Fixer%2C%20%D1%87%D1%82%D0%BE%D0%B 1%D1%8B%20%D0%BB%D1%83%D1%87%D1%88%D0%B5%20%D0%BE%D0%BF%D1%80%D0%B5%D0%B4%D0%B5% D0%BB%D0%B8%D1%82%D1%8C%20%D0%BD%D0%B0%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD %D0%B8%D0%B5%20%D0%B4%D0%BB%D1%8F%20%D0%B5%D0%B3%D0%BE%20%D0%B4%D0%B0%D0%BB%D1%8 C%D0%BD%D0%B5%D0%B9%D1%88%D0%B5%D0%B3%D0%BE%20%D1%80%D0%B0%D0%B7%D0%B2%D0%B8%D1% 82%D0%B8%D1%8F.%20%D0%95%D1%81%D0%BB%D0%B8%20%D1%83%20%D0%B2%D0%B0%D1%81%20%D0%B 5%D1%81%D1%82%D1%8C%20%D1%81%D0%B2%D0%BE%D0%B1%D0%BE%D0%B4%D0%BD%D1%8B%D0%B5%205 %20%D0%BC%D0%B8%D0%BD%D1%83%D1%82%2C%20%D1%82%D0%BE%20%D0%BD%D0%B0%D0%B6%D0%BC%D 0%B8%D1%82%D0%B5%2C%20%D0%BF%D0%BE%D0%B6%D0%B0%D0%BB%D1%83%D0%B9%D1%81%D1%82%D0% B0%2C%20%D0%BD%D0%B0%20%D0%BA%D0%BD%D0%BE%D0%BF%D0%BA%D1%83%2C%20%D1%87%D1%82%D0 %BE%D0%B1%D1%8B%20%D0%BF%D1%80%D0%B8%D0%BD%D1%8F%D1%82%D1%8C%20%D1%83%D1%87%D0%B 0%D1%81%D1%82%D0%B8%D0%B5%20%D0%B2%20%D0%BE%D0%BF%D1%80%D0%BE%D1%81%D0%B5."),
31 note: decodeURIComponent("%D0%AD%D1%82%D0%BE%20%D0%BE%D0%B4%D0%BD%D0%BE%D1%8 0%D0%B0%D0%B7%D0%BE%D0%B2%D0%BE%D0%B5%20%D1%81%D0%BE%D0%BE%D0%B1%D1%89%D0%B5%D0% BD%D0%B8%D0%B5%2C%20%D0%BE%D0%BD%D0%BE%20%D0%B1%D0%BE%D0%BB%D1%8C%D1%88%D0%B5%20 %D0%BD%D0%B5%20%D0%B1%D1%83%D0%B4%D0%B5%D1%82%20%D0%BF%D0%BE%D0%BA%D0%B0%D0%B7%D 1%8B%D0%B2%D0%B0%D1%82%D1%8C%D1%81%D1%8F."),
32 accept: decodeURIComponent("%D0%9F%D1%80%D0%B8%D0%BD%D1%8F%D1%82%D1%8C%20%D1 %83%D1%87%D0%B0%D1%81%D1%82%D0%B8%D0%B5%20%D0%B2%20%D0%BE%D0%BF%D1%80%D0%BE%D1%8 1%D0%B5"),
33 decline: decodeURIComponent("%D0%9C%D0%BE%D0%B6%D0%B5%D1%82%20%D0%B2%20%D0%B 4%D1%80%D1%83%D0%B3%D0%BE%D0%B9%20%D1%80%D0%B0%D0%B7")
34 } 19 }
35 };
36
37 exports.incrementCorrectionsCounter = incrementCorrectionsCounter;
38 function incrementCorrectionsCounter(window)
39 {
40 let count = typeof(Prefs.corrections_count)!="undefined" && JSON.parse(Prefs.c orrections_count) || 0;
41
42 // Only users with 5 URL corrections
43 if(++count == 5)
44 {
45 initSurvey(window);
46 }
47
48 Prefs.corrections_count = count;
49 } 20 }
50 21
51 function initSurvey(window) 22 function initSurvey()
52 { 23 {
53 // Don't do anything on Fennec.
54 if ("Browser" in window || "BrowserApp" in window)
55 return;
56
57 // Don't ask after 2012-10-15 24 // Don't ask after 2012-10-15
58 if (Date.now() > 1350259200000) 25 if (Date.now() > 1350259200000)
59 return; 26 return;
60 27
61 // Only Firefox users 28 // Only Firefox users
62 if (Services.appinfo.ID != "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}") 29 let {application} = require("info");
30 if (application != "firefox")
63 return; 31 return;
64 32
65 // Only Firefox 4 and higher 33 // Only Firefox 4 and higher
66 if (Services.vc.compare(Services.appinfo.platformVersion, "2.0") < 0) 34 if (Services.vc.compare(Services.appinfo.platformVersion, "2.0") < 0)
67 return; 35 return;
68 36
69 // Survey is only available in English/German/Russian 37 // Survey is only available in English/German/Russian
70 if (!/^(en|de|ru)\b/.test(Services.locale.getApplicationLocale().getCategory(" NSILOCALE_CTYPE"))) 38 if (!/^(en|de|ru)\b/.test(Services.locale.getApplicationLocale().getCategory(" NSILOCALE_CTYPE")))
71 return; 39 return;
72 surveyLang = RegExp.$1; 40 surveyLang = RegExp.$1;
73 41
74 // Delay survey question by 5 seconds 42 // Delay survey question by 5 seconds
75 surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 43 surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
76 surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT); 44 surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT);
77
78 win = window;
79 } 45 }
80 46
81 function runSurvey() 47 function runSurvey()
82 { 48 {
83 win.openDialog("chrome://url-fixer/content/survey.xul", "survey", "top=100,lef t=300,chrome,dialog,dependent"); 49 Services.wm.getMostRecentWindow("navigator:browser").openDialog("chrome://url- fixer/content/survey.xul", "survey", "top=100,left=300,chrome,dialog,dependent") ;
Wladimir Palant 2012/09/21 14:40:25 a) I'm not insisting on using 80 characters as lin
84 } 50 }
85 51
86 exports.openSurvey = openSurvey; 52 exports.openSurvey = openSurvey;
87 function openSurvey() 53 function openSurvey()
88 { 54 {
89 require("appIntegration").getBrowser(win).loadOneTab(surveyUrl + "&lang=" + su rveyLang, { 55 require("appIntegration").getBrowser(Services.wm.getMostRecentWindow("navigato r:browser")).loadOneTab(surveyUrl + "&lang=" + surveyLang, {
Wladimir Palant 2012/09/21 14:40:25 Same here - line too long and result of getMostRec
90 referrerURI: Services.io.newURI("http://url.fixer/", null, null), 56 referrerURI: Services.io.newURI("http://url.fixer/", null, null),
91 inBackground: false 57 inBackground: false
92 }); 58 });
93 } 59 }
94
95 exports.getSurveyDialogTexts = getSurveyDialogTexts;
96 function getSurveyDialogTexts()
97 {
98 return langData[surveyLang];
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld