summaryrefslogtreecommitdiffstats
path: root/admin/survey/script/aapor.js
blob: bbf631503e3e24958da230e2623ad93ac760a97c (plain) (blame)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/**
 * Created by Andraž Gregorčič on 3.11.2014.
 */

$(function(){
    $( ".main_aapor, .read_aapor" ).qtip({
        content: lang['srv_aapor_automatic'],
        show: 'mouseover',
        hide: 'mouseout',
        position: {
            corner: {
                target: 'rightMiddle',
                tooltip: 'leftMiddle'
            }
        },
        style: {
            width: 200,
            padding: 5,
            background: 'red',
            color: 'black',
            textAlign: 'center',
            border: {
                width: 7,
                radius: 5,
                color: '#A2D959'
            },
            tip: {
                corner: 'leftMiddle',
                color: false
            },
            name: 'blue' // Inherit the rest of the attributes from the preset dark style
        }
    });
});

function prikazi(id){
    if($("#prikazipriblizek").prop('checked')){
        console.log(id);
        $.post("ajax.php?t=aaporCalculation&m=priblizek",{'anketa':id},function(data,status){
            if(data.usable != 'undefined' && data.unusable != 'undefined' && data.partusable != 'undefined' && data.status34 != 'undefined' && data.status02 != 'undefined' && data.status != 'undefined'){
                var obj = JSON.parse(data);
                $( "input" ).val(0);
                $( "input[name='complete']" ).val(obj.usable);
                $( "input[name='partial']" ).val(obj.partusable);
                $( "input[name='breakOff']" ).val(obj.unusable);
                $( "input[name='loggedNotComplete']" ).val(obj.status34);
                $( "input[name='noInvitation']" ).val(obj.status02);
                $( "input[name='nothingReturned']" ).val(obj.status1);
                $( "input[name='e']" ).val(100);
                $(".totalSubDatabaseSpan").text(obj.skupaj/*+obj.status02*/);
                calculateReturne();
                calculateRefusalIm();
                calculateEligible();
                calculateNothingKnownRespondent();
            }
        });
    }else{
        $( "input[name='rq']" ).val('');
        $( "input[name='complete']" ).val('');
        $( "input[name='partial']" ).val('');
        $( "input[name='refusalIm']" ).val('');
        $( "input[name='breakOff']" ).val('');
        $( "input[name='loggedNotComplete']" ).val('');
        $( "input[name='nothingKnown']" ).val('');
        $( "input[name='noInvitation']" ).val('');
        $( "input[name='nothingReturned']" ).val('');
        $(".totalSubDatabaseSpan").text('');
        calculateReturne();
        calculateEligible();
    }
}
function calculateReturne(){
    var com = $( "input[name='complete']" ).val();
    var par = $( "input[name='partial']" ).val();

    if($.trim(com) && $.trim(par)){
        var test = (parseInt(com)+parseInt(par));
        console.log(test);
        $( "input[name='rq']" ).val(test);
        calculateAll();
    }
}

function calculateRefusal(){
    var refusalEx = $( "input[name='refusalEx']").val();
    var refusalIm = $( "input[name='refusalIm']").val();

    if($.trim(refusalEx) && $.trim(refusalIm)){
        var test = parseInt(refusalEx) + parseInt(refusalIm);
        console.log(test);
        $( "input[name='refusal']").val(test);
        calculateAll();
    }
}
function calculateRefusalIm(){
    var loggedNotComplete = $( "input[name='loggedNotComplete']" ).val();
    var readReceiptConfirmation = $( "input[name='readReceiptConfirmation']" ).val();
    console.log(loggedNotComplete+readReceiptConfirmation);
    if($.trim(loggedNotComplete) && $.trim(readReceiptConfirmation)){
        var test = (parseInt(loggedNotComplete) + parseInt(readReceiptConfirmation));
        console.log(test);
        $( "input[name='refusalIm']" ).val(test);
        calculateRefusal();
    }
}
function calculateNonContact(){
    var respondentUnavailable =  $( "input[name='respondentUnavailable']" ).val();
    var completedNotReturned =  $( "input[name='completedNotReturned']" ).val();
    if($.trim(respondentUnavailable) && $.trim(completedNotReturned)){
        var test = (parseInt(respondentUnavailable) + parseInt(completedNotReturned));
        $( "input[name='nonContact']" ).val(test);
        calculateEligible();
    }
}
function calculateOtherEligible(){
    var languageBarrier = $( "input[name='languageBarrier']" ).val();

    if($.trim(languageBarrier)){
        $( "input[name='otherEligible']" ).val(parseInt(languageBarrier));
        calculateEligible();
    }
}
function calculateEligible(){
    var refusal = $( "input[name='refusal']" ).val();
    var breakOff = $( "input[name='breakOff']" ).val();
    var nonContact = $( "input[name='nonContact']" ).val();
    var otherEligible = $( "input[name='otherEligible']" ).val();

    if($.trim(refusal) && $.trim(breakOff) && $.trim(nonContact) && $.trim(otherEligible)){
        var test = parseInt(refusal) + parseInt(breakOff) + parseInt(nonContact) + parseInt(otherEligible);
        console.log(test);
        $( "input[name='eligible']" ).val(test);
        calculateAll();
    }
}
function calculateNothingKnownRespondent(){
    var noInvitation = $( "input[name='noInvitation']" ).val();
    var nothingReturned = $( "input[name='nothingReturned']" ).val();

    if($.trim(noInvitation) && $.trim(nothingReturned)){
        var test = (parseInt(noInvitation) + parseInt(nothingReturned));
        $( "input[name='nothingKnown']" ).val(test);
        calculateUnknownEligibility();
    }
}

function calculateOtherUnknownEligibility(){
    var returnedUnsampledEmail = $( "input[name='returnedUnsampledEmail']" ).val();

    if($.trim(returnedUnsampledEmail)){
        var test = (parseInt(returnedUnsampledEmail));
        $( "input[name='otherUnknownEligible']" ).val(test);
        calculateUnknownEligibility();
    }
}

function calculateUnknownEligibility(){
    var nothingKnown = $( "input[name='nothingKnown']" ).val();
    var invitationReturnedUndelivered = $( "input[name='invitationReturnedUndelivered']" ).val();
    var invitationReturnedForwarding = $( "input[name='invitationReturnedForwarding']" ).val();
    var otherUnknownEligible = $( "input[name='otherUnknownEligible']" ).val();

    if($.trim(nothingKnown) && $.trim(invitationReturnedUndelivered) && $.trim(invitationReturnedForwarding) && $.trim(otherUnknownEligible)){
        var test = parseInt(nothingKnown) + parseInt(invitationReturnedUndelivered) + parseInt(invitationReturnedForwarding) + parseInt(otherUnknownEligible);
        console.log(test);
        $( "input[name='unknownEligible']" ).val(test);
        calculateAll();
    }
}
function calculateQuotaFilled(){
    var duplicateListing = $( "input[name='duplicateListing']" ).val();

    if($.trim(duplicateListing)){
        var test = (parseInt(duplicateListing));
        $( "input[name='quotaFilled']" ).val(test);
        calculateNotEligible();
    }
}

function calculateNotEligible(){
    var selectedRespondent = $( "input[name='selectedRespondent']" ).val();
    var quotaFilled = $( "input[name='quotaFilled']" ).val();
    var otherNotEligible = $( "input[name='otherNotEligible']" ).val();

    if($.trim(selectedRespondent) && $.trim(quotaFilled) && $.trim(otherNotEligible)){
        var test = parseInt(selectedRespondent) + parseInt(quotaFilled) + parseInt(otherNotEligible);
        console.log(test);
        $( "input[name='notEligible']" ).val(test);
        calculateAll();
    }
}

function calculateAll(){
    var rq = $( "input[name='rq']" ).val();
    var eligible = $( "input[name='eligible']" ).val();
    var unknownEligible = $( "input[name='unknownEligible']" ).val();
    var notEligible = $( "input[name='notEligible']" ).val();

    if($.trim(rq) && $.trim(eligible) && $.trim(unknownEligible) && $.trim(notEligible)){
        var test = parseInt(rq) + parseInt(eligible) + parseInt(unknownEligible) + parseInt(notEligible);
        console.log(test);
        $(".totalSubSpan").text(test);
    }
}

function getCallculationAapor(id){
    //var d = $("#aaporForm").serialize();
	var refusal = $( "input[name='refusal']" ).val();
	var breakOff = $( "input[name='breakOff']" ).val();
	var invitationReturnedUndelivered = $( "input[name='invitationReturnedUndelivered']" ).val();
	var invitationReturnedForwarding = $( "input[name='invitationReturnedForwarding']" ).val();
	var otherUnknownEligible = $( "input[name='otherUnknownEligible']" ).val();
	var complete = $( "input[name='complete']" ).val();
	var partial = $( "input[name='partial']" ).val();
	var nonContact = $( "input[name='nonContact']" ).val();
	var otherEligible = $( "input[name='otherEligible']" ).val();
	var nothingKnown = $( "input[name='nothingKnown']" ).val();
	var e = $( "input[name='e']" ).val();

    $.post("ajax.php?t=aaporCalculation",{anketa:id,refusal:refusal,breakoff:breakOff,invitationReturnedUndelivered:invitationReturnedUndelivered,invitationReturnedForwarding:invitationReturnedForwarding,otherUnknownEligible:otherUnknownEligible,complete:complete,partial:partial,nonContact:nonContact,otherEligible:otherEligible,nothingKnown:nothingKnown,e:e},function(data,status){
        var obj = JSON.parse(data);
        $("#rr1").text(obj.rr1);
        $("#rr2").text(obj.rr2);
        $("#rr3").text(obj.rr3);
        $("#rr4").text(obj.rr4);
        $("#rr5").text(obj.rr5);
        $("#rr6").text(obj.rr6);
    });
}