~jlungo/zhris/trunk

« back to all changes in this revision

Viewing changes to interface/html5/global/widgets/feedback/TFeedback.js

  • Committer: Juma Lungo
  • Date: 2017-11-16 08:54:53 UTC
  • Revision ID: juma.lungo@zalongwa.com-20171116085453-q3jxht0gcab8jbya
codebase commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(function( $ ) {
 
2
 
 
3
        $.fn.TFeedback = function( options ) {
 
4
                var opts = $.extend( {}, $.fn.TFeedback.defaults, options );
 
5
                var message_container;
 
6
                var $this = this;
 
7
                var feedback_rating;
 
8
                var message_box;
 
9
                var message_email;
 
10
                var message_phone;
 
11
                this.api = null;
 
12
                this.user_api = new (APIFactory.getAPIClass( 'APIUser' ))();
 
13
                this.feedback_submitted = false;
 
14
 
 
15
                this.removeMessageContainer = function() {
 
16
                        if ( Global.isSet( message_container ) ) {
 
17
                                message_container.remove();
 
18
                        }
 
19
                };
 
20
 
 
21
                this.saveIconSelection = function(){
 
22
                        if ( this.feedback_submitted == false || this.feedback_submitted == undefined ) {
 
23
                                this.feedback_submitted = true;
 
24
                                var message = '';
 
25
                                if (message_box.val().length > 0) {
 
26
                                        message = message_box.val() + '\nEmail: ' + message_email.val() + "\nPhone: " + message_phone.val();
 
27
                                }
 
28
                                $this.api['setUserFeedbackRating'](feedback_rating, message, {
 
29
                                        onResult: function (res) {
 
30
                                                if (res.isValid()) {
 
31
                                                        $this.parent().find('img').each(function () {
 
32
                                                                $(this).removeClass('current').attr('src', $(this).attr('src').replace(/^(.*\/)[^\/]+$/, '$1') + $(this).attr('alt') + '.png');
 
33
                                                        });
 
34
                                                        $this.addClass('current').attr('src', $this.attr('src').replace(/^(.*\/)[^\/]+$/, '$1') + $this.attr('alt') + '_light.png');
 
35
                                                        $this.removeMessageContainer();
 
36
                                                        $this.user_api['getUser']({filter_data: {id: LocalCacheData.getLoginUser().id}}, {
 
37
                                                                onResult: function (res) {
 
38
                                                                        if (res.isValid()) {
 
39
                                                                                LocalCacheData.setLoginUser(res.getResult()[0]);
 
40
                                                                        }
 
41
                                                                }
 
42
                                                        })
 
43
                                                }
 
44
                                        }
 
45
                                });
 
46
                        }
 
47
                };
 
48
 
 
49
                this.each( function() {
 
50
                        var o = $.meta ? $.extend( {}, opts, $( this ).data() ) : opts;
 
51
 
 
52
                        $this.api = new (APIFactory.getAPIClass( 'APIUser' ))();
 
53
 
 
54
                        var current_user_api = new (APIFactory.getAPIClass( 'APICurrentUser' ))();
 
55
                        var user = current_user_api.getCurrentUser({async:false});
 
56
                        user = user.getResult();
 
57
                        var user_email;
 
58
                        if ( user.work_email != false  && user.work_email != '' ) {
 
59
                                user_email = user.work_email;
 
60
                        } else if ( user.home_email != false ) {
 
61
                                user_email = user.home_email;
 
62
                        }
 
63
                        var user_phone;
 
64
                        if ( user.work_phone != false &&  user.work_phone != '' ) {
 
65
                                user_phone = user.work_phone;
 
66
                        } else if ( user.home_phone != false ) {
 
67
                                user_phone = user.home_phone;
 
68
                        }
 
69
                        message_container = Global.loadWidgetByName( FormItemType.FEEDBACK_BOX );
 
70
 
 
71
                        message_box = message_container.find('.feedback-messagebox');
 
72
                        message_email = message_container.find('.feedback-email');
 
73
                        message_phone = message_container.find('.feedback-phone');
 
74
 
 
75
                        message_email.val(user_email);
 
76
                        message_phone.val(user_phone);
 
77
 
 
78
                        feedback_rating = $this.attr('data-feedback');
 
79
 
 
80
                        if ( $(this ).attr('alt') == 'happy' ) {
 
81
                                $( message_container.find('.title' ) ).text( $.i18n._( 'Glad to hear that you are happy with your TimeTrex experience! But we don\'t want to rest on our laurels, so let us know what we are doing right, or what we can do to make further improvements, we will listen, promise.' ) )
 
82
                        } else if ( $(this ).attr('alt') == 'neutral' ) {
 
83
                                $( message_container.find('.title' ) ).text( $.i18n._( 'Sorry to hear that you are not satisfied with your TimeTrex experience, please let us know how we can improve, we will listen, promise.' ) )
 
84
                        } else if ( $(this ).attr('alt') == 'sad' ) {
 
85
                                $( message_container.find('.title' ) ).text( $.i18n._( 'Oh no! Sorry to hear that you are unhappy with your TimeTrex experience, please let us know how we can improve, we will listen, promise.' ) )
 
86
                        }
 
87
 
 
88
                        message_container.find('.sendButton').html($.i18n._( 'Send' ) );
 
89
                        message_container.find('.cancelButton').html($.i18n._( 'Cancel' ) );
 
90
                        message_container.find('.top-bar-title').html( $.i18n._( 'Feedback' ) );
 
91
                        message_container.find('.email-label-text').html( $.i18n._( 'Email' ) );
 
92
                        message_container.find('.phone-label-text').html( $.i18n._( 'Phone' ) );
 
93
                        message_container.find('.contact-notice-text').html( $.i18n._( 'If you would like to be contacted regarding your feedback, please provide') +':' );
 
94
 
 
95
                        message_container.find('.sendButton' ).bind('click', $this.saveIconSelection);
 
96
 
 
97
                        message_container.find('.cancelButton' ).bind('click', $this.removeMessageContainer);
 
98
 
 
99
                        if ( $('body' ).children('.message-container' ).length == 0 ) {
 
100
                                $('body' ).append( message_container );
 
101
                        }
 
102
 
 
103
                } );
 
104
 
 
105
                return this;
 
106
 
 
107
        };
 
108
 
 
109
        $.fn.TFeedback.defaults = {
 
110
 
 
111
        };
 
112
 
 
113
})( jQuery );
 
 
b'\\ No newline at end of file'