|
@@ -0,0 +1,214 @@
|
|
1
|
+/**
|
|
2
|
+ * Created by ystamcheva on 2/10/15.
|
|
3
|
+ */
|
|
4
|
+/* jshint -W101 */
|
|
5
|
+var messageHandler = require("./util/MessageHandler");
|
|
6
|
+var callStats = require("../statistics/CallStats");
|
|
7
|
+var APP = require("../../app");
|
|
8
|
+
|
|
9
|
+/**
|
|
10
|
+ * Constructs the html for the overall feedback window.
|
|
11
|
+ *
|
|
12
|
+ * @returns {string} the constructed html string
|
|
13
|
+ */
|
|
14
|
+var constructOverallFeedbackHtml = function() {
|
|
15
|
+ var feedbackQuestion = (Feedback.feedbackScore < 0)
|
|
16
|
+ ? '<br/><br/>' + APP.translation
|
|
17
|
+ .translateString("dialog.feedbackQuestion")
|
|
18
|
+ : '';
|
|
19
|
+
|
|
20
|
+ var message = '<div class="feedback"><div>' +
|
|
21
|
+ '<div class="feedbackTitle">' +
|
|
22
|
+ APP.translation.translateString("dialog.thankYou",
|
|
23
|
+ {appName:interfaceConfig.APP_NAME}) +
|
|
24
|
+ '</div>' +
|
|
25
|
+ feedbackQuestion +
|
|
26
|
+ '</div><br/><br/>' +
|
|
27
|
+ '<div id="stars">' +
|
|
28
|
+ '<a><i class="fa fa-star-o fa fa-star"></i></a>' +
|
|
29
|
+ '<a><i class="fa fa-star-o fa fa-star"></i></a>' +
|
|
30
|
+ '<a><i class="fa fa-star-o fa fa-star"></i></a>' +
|
|
31
|
+ '<a><i class="fa fa-star-o fa fa-star"></i></a>' +
|
|
32
|
+ '<a><i class="fa fa-star-o fa fa-star"></i></a>' +
|
|
33
|
+ '</div></div>';
|
|
34
|
+
|
|
35
|
+ return message;
|
|
36
|
+};
|
|
37
|
+
|
|
38
|
+/**
|
|
39
|
+ * Constructs the html for the detailed feedback window.
|
|
40
|
+ *
|
|
41
|
+ * @returns {string} the contructed html string
|
|
42
|
+ */
|
|
43
|
+var constructDetailedFeedbackHtml = function() {
|
|
44
|
+ // Construct the html, which will be served as a dialog message.
|
|
45
|
+ var message = '<div class="feedback">' +
|
|
46
|
+ '<div class="feedbackTitle">' +
|
|
47
|
+ APP.translation.translateString("dialog.sorryFeedback") +
|
|
48
|
+ '</div><br/><br/>' +
|
|
49
|
+ '<div class="feedbackDetails">' +
|
|
50
|
+ '<textarea id="feedbackTextArea" rows="10" cols="50" autofocus>' +
|
|
51
|
+ '</textarea>' +
|
|
52
|
+ '</div></div>';
|
|
53
|
+
|
|
54
|
+ return message;
|
|
55
|
+};
|
|
56
|
+
|
|
57
|
+/**
|
|
58
|
+ * The callback function corresponding to the openFeedbackWindow parameter.
|
|
59
|
+ *
|
|
60
|
+ * @type {function}
|
|
61
|
+ */
|
|
62
|
+var feedbackWindowCallback = null;
|
|
63
|
+
|
|
64
|
+/**
|
|
65
|
+ * Defines all methods in connection to the Feedback window.
|
|
66
|
+ *
|
|
67
|
+ * @type {{feedbackScore: number, openFeedbackWindow: Function,
|
|
68
|
+ * toggleStars: Function, hoverStars: Function, unhoverStars: Function}}
|
|
69
|
+ */
|
|
70
|
+var Feedback = {
|
|
71
|
+ /**
|
|
72
|
+ * The feedback score. -1 indicates no score has been given for now.
|
|
73
|
+ */
|
|
74
|
+ feedbackScore: -1,
|
|
75
|
+ /**
|
|
76
|
+ * Opens the feedback window.
|
|
77
|
+ */
|
|
78
|
+ openFeedbackWindow: function (callback) {
|
|
79
|
+ feedbackWindowCallback = callback;
|
|
80
|
+ // Add all mouse and click listeners.
|
|
81
|
+ var onLoadFunction = function (event) {
|
|
82
|
+ $('#stars >a').each(function(index) {
|
|
83
|
+ // On star mouse over.
|
|
84
|
+ $(this).get(0).onmouseover = function(){
|
|
85
|
+ Feedback.hoverStars(index);
|
|
86
|
+ };
|
|
87
|
+ // On star mouse leave.
|
|
88
|
+ $(this).get(0).onmouseleave = function(){
|
|
89
|
+ Feedback.unhoverStars(index);
|
|
90
|
+ };
|
|
91
|
+ // On star click.
|
|
92
|
+ $(this).get(0).onclick = function(){
|
|
93
|
+ Feedback.toggleStars(index);
|
|
94
|
+ Feedback.feedbackScore = index+1;
|
|
95
|
+
|
|
96
|
+ // If the feedback is less than 3 stars we're going to
|
|
97
|
+ // ask the user for more information.
|
|
98
|
+ if (Feedback.feedbackScore > 3) {
|
|
99
|
+ callStats.sendFeedback(Feedback.feedbackScore, "");
|
|
100
|
+ if (feedbackWindowCallback)
|
|
101
|
+ feedbackWindowCallback();
|
|
102
|
+ else
|
|
103
|
+ APP.UI.messageHandler.closeDialog();
|
|
104
|
+ }
|
|
105
|
+ else {
|
|
106
|
+ feedbackDialog.goToState('detailed_feedback');
|
|
107
|
+ }
|
|
108
|
+ };
|
|
109
|
+ // Initialise stars to correspond to previously entered feedback.
|
|
110
|
+ if (Feedback.feedbackScore > 0
|
|
111
|
+ && index < Feedback.feedbackScore) {
|
|
112
|
+ Feedback.hoverStars(index);
|
|
113
|
+ Feedback.toggleStars(index);
|
|
114
|
+ }
|
|
115
|
+ });
|
|
116
|
+ };
|
|
117
|
+
|
|
118
|
+ // Defines the different states of the feedback window.
|
|
119
|
+ var states = {
|
|
120
|
+ overall_feedback: {
|
|
121
|
+ html: constructOverallFeedbackHtml(),
|
|
122
|
+ persistent: true,
|
|
123
|
+ buttons: {},
|
|
124
|
+ closeText: '',
|
|
125
|
+ focus: "div[id='stars']",
|
|
126
|
+ position: {width: 500}
|
|
127
|
+ },
|
|
128
|
+ detailed_feedback: {
|
|
129
|
+ html: constructDetailedFeedbackHtml(),
|
|
130
|
+ buttons: {"Submit": true, "Cancel": false},
|
|
131
|
+ closeText: '',
|
|
132
|
+ focus: "textarea[id='feedbackTextArea']",
|
|
133
|
+ position: {width: 500},
|
|
134
|
+ submit: function(e,v,m,f) {
|
|
135
|
+ e.preventDefault();
|
|
136
|
+ if (v) {
|
|
137
|
+ var feedbackDetails
|
|
138
|
+ = document.getElementById("feedbackTextArea").value;
|
|
139
|
+
|
|
140
|
+ if (feedbackDetails && feedbackDetails.length > 0)
|
|
141
|
+ callStats.sendFeedback( Feedback.feedbackScore,
|
|
142
|
+ feedbackDetails);
|
|
143
|
+
|
|
144
|
+ if (feedbackWindowCallback)
|
|
145
|
+ feedbackWindowCallback();
|
|
146
|
+ else
|
|
147
|
+ APP.UI.messageHandler.closeDialog();
|
|
148
|
+ } else {
|
|
149
|
+ // User cancelled
|
|
150
|
+ if (feedbackWindowCallback)
|
|
151
|
+ feedbackWindowCallback();
|
|
152
|
+ else
|
|
153
|
+ APP.UI.messageHandler.closeDialog();
|
|
154
|
+ }
|
|
155
|
+ }
|
|
156
|
+ }
|
|
157
|
+ };
|
|
158
|
+
|
|
159
|
+ // Create the feedback dialog.
|
|
160
|
+ var feedbackDialog
|
|
161
|
+ = APP.UI.messageHandler.openDialogWithStates(
|
|
162
|
+ states,
|
|
163
|
+ { persistent: true,
|
|
164
|
+ buttons: {},
|
|
165
|
+ closeText: '',
|
|
166
|
+ loaded: onLoadFunction,
|
|
167
|
+ position: {width: 500}}, null);
|
|
168
|
+ },
|
|
169
|
+ /**
|
|
170
|
+ * Toggles the appropriate css class for the given number of stars, to
|
|
171
|
+ * indicate that those stars have been clicked/selected.
|
|
172
|
+ *
|
|
173
|
+ * @param starCount the number of stars, for which to toggle the css class
|
|
174
|
+ */
|
|
175
|
+ toggleStars: function (starCount)
|
|
176
|
+ {
|
|
177
|
+ $('#stars >a >i').each(function(index) {
|
|
178
|
+ if (index <= starCount) {
|
|
179
|
+ $(this).removeClass("fa-star-o");
|
|
180
|
+ }
|
|
181
|
+ else
|
|
182
|
+ $(this).addClass("fa-star-o");
|
|
183
|
+ });
|
|
184
|
+ },
|
|
185
|
+ /**
|
|
186
|
+ * Toggles the appropriate css class for the given number of stars, to
|
|
187
|
+ * indicate that those stars have been hovered.
|
|
188
|
+ *
|
|
189
|
+ * @param starCount the number of stars, for which to toggle the css class
|
|
190
|
+ */
|
|
191
|
+ hoverStars: function (starCount)
|
|
192
|
+ {
|
|
193
|
+ $('#stars >a >i').each(function(index) {
|
|
194
|
+ if (index <= starCount)
|
|
195
|
+ $(this).addClass("starHover");
|
|
196
|
+ });
|
|
197
|
+ },
|
|
198
|
+ /**
|
|
199
|
+ * Toggles the appropriate css class for the given number of stars, to
|
|
200
|
+ * indicate that those stars have been un-hovered.
|
|
201
|
+ *
|
|
202
|
+ * @param starCount the number of stars, for which to toggle the css class
|
|
203
|
+ */
|
|
204
|
+ unhoverStars: function (starCount)
|
|
205
|
+ {
|
|
206
|
+ $('#stars >a >i').each(function(index) {
|
|
207
|
+ if (index <= starCount && $(this).hasClass("fa-star-o"))
|
|
208
|
+ $(this).removeClass("starHover");
|
|
209
|
+ });
|
|
210
|
+ }
|
|
211
|
+};
|
|
212
|
+
|
|
213
|
+// Exports the Feedback class.
|
|
214
|
+module.exports = Feedback;
|