-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
feedback.js
77 lines (69 loc) · 2.3 KB
/
feedback.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
/**
* Knockout Feedback Component
*
* Include the <feedback> element on on your knockout page to add the feedback widget.
*
* Required parameters:
* featureName: The name of the feature a user is giving feedback on
*
* Optional parameters:
* url: specify the url where to submit the feedback to. By default it will use
* the submit_feedback view, which requires a login and domain being present.
*
*/
hqDefine('hqwebapp/js/components/bootstrap3/feedback', [
'knockout',
'jquery',
'hqwebapp/js/initial_page_data',
], function (
ko,
$,
initialPageData
) {
return {
viewModel: function (params) {
var self = {};
if (!params.featureName) {
throw new Error("Please specify a featureName in params.");
}
self.featureName = ko.observable(params.featureName);
self.rating = ko.observable();
self.additionalFeedback = ko.observable();
self.showSuccess = ko.observable(false);
self.rateBad = function () {
self.rating(1);
};
self.rateOk = function () {
self.rating(2);
};
self.rateGood = function () {
self.rating(3);
};
self.submit = function () {
$.ajax({
url: params.url || initialPageData.reverse('submit_feedback'),
method: 'post',
dataType: 'json',
data: {
featureName: self.featureName(),
rating: self.rating(),
additionalFeedback: self.additionalFeedback(),
},
})
.done(function (data) {
if (data.success) {
self.showSuccess(true);
}
})
.always(function () {
setTimeout(function () {
$('#modal-feedback-form-widget').modal('hide');
}, 1000);
});
};
return self;
},
template: '<div data-bind="template: { name: \'ko-feedback-template\' }"></div>',
};
});