View | Details | Raw Unified | Return to bug 18595
Collapse All | Expand All

(-)a/C4/Form/MessagingPreferences.pm (-1 / +19 lines)
Lines 141-146 sub set_form_values { Link Here
141
    my ($target_params, $template) = @_;
141
    my ($target_params, $template) = @_;
142
    # walk through the options and update them with these borrower_preferences
142
    # walk through the options and update them with these borrower_preferences
143
    my $messaging_options = Koha::Patron::MessagePreferences->get_options;
143
    my $messaging_options = Koha::Patron::MessagePreferences->get_options;
144
    my $patron;
145
    if ($target_params->{borrowernumber}) {
146
        $patron = Koha::Patrons->find($target_params->{borrowernumber});
147
    }
148
144
    PREF: foreach my $option ( @$messaging_options ) {
149
    PREF: foreach my $option ( @$messaging_options ) {
145
        my $pref = Koha::Patron::MessagePreferences->find( { %{ $target_params }, message_attribute_id => $option->{'message_attribute_id'} } );
150
        my $pref = Koha::Patron::MessagePreferences->find( { %{ $target_params }, message_attribute_id => $option->{'message_attribute_id'} } );
146
        $option->{ $option->{'message_name'} } = 1;
151
        $option->{ $option->{'message_name'} } = 1;
Lines 153-161 sub set_form_values { Link Here
153
                selected   => $_ == $days_in_advance  }
158
                selected   => $_ == $days_in_advance  }
154
            } ( 0..MAX_DAYS_IN_ADVANCE );
159
            } ( 0..MAX_DAYS_IN_ADVANCE );
155
        }
160
        }
161
162
        if ($patron && $option->{'transport_email'} and !$patron->email) {
163
            $option->{'transports_email'} = 0;
164
            $option->{'transports_email_disabled'} = 1;
165
        }
166
        if ($patron && $option->{'transport_sms'} and !$patron->smsalertnumber) {
167
            $option->{'transports_sms'} = 0;
168
            $option->{'transports_sms_disabled'} = 1;
169
        }
170
156
        next unless $pref;
171
        next unless $pref;
157
        foreach my $transport ( keys %{$pref->message_transport_types} ) {
172
        foreach my $transport ( keys %{$pref->message_transport_types} ) {
158
            $option->{'transports_'.$transport} = 1;
173
            if (!$option->{'transports_'.$transport.'_disabled'}) {
174
                $option->{'transports_'.$transport.'_disabled'} = 0;
175
                $option->{'transports_'.$transport} = 1;
176
            }
159
        }
177
        }
160
        $option->{'digest'} = 1 if $pref->wants_digest;
178
        $option->{'digest'} = 1 if $pref->wants_digest;
161
    }
179
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (+29 lines)
Lines 1603-1608 legend:hover { Link Here
1603
                                        <div id="messaging_prefs_loading" class="form-message" style="display:none">
1603
                                        <div id="messaging_prefs_loading" class="form-message" style="display:none">
1604
                                            <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading new messaging defaults
1604
                                            <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading new messaging defaults
1605
                                        </div>
1605
                                        </div>
1606
                                        [% IF !patron || ( patron && !patron.notice_email_address ) %]
1607
                                            <div class="dialog message missing-message-pref-contact">
1608
                                                <h4>Patron is missing email address</h4>
1609
                                                <p>Because of this you will be unable to select email messaging preferences. Please <a href="memberentry.pl?op=modify&borrowernumber=[% patron.borrowernumber %]">modify patron</a> and set primary email address.</p>
1610
                                            </div>
1611
                                        [% END %]
1612
                                        [% IF SMSSendDriver && ( !patron || patron && !SMSnumber ) %]
1613
                                            <div class="dialog message missing-message-pref-contact">
1614
                                                <h4>Patron is missing SMS number</h4>
1615
                                                <p>Because of this you will be unable to select SMS messaging preferences. Please provide patron's SMS number first.</p>
1616
                                            </div>
1617
                                        [% END %]
1618
                                        [% IF Koha.Preference('PhoneNotification') && ( !patron || patron && !patron.phone ) %]
1619
                                            <div class="dialog message missing-message-pref-contact">
1620
                                                <h4>Patron is missing phone number</h4>
1621
                                                <p>Because of this you will be unable to select phone messaging preferences. Please provide patron's phone number first.</p>
1622
                                            </div>
1623
                                        [% END %]
1606
                                        <input type="hidden" name="setting_messaging_prefs" value="1" />
1624
                                        <input type="hidden" name="setting_messaging_prefs" value="1" />
1607
                                        [% INCLUDE 'messaging-preference-form.inc' %]
1625
                                        [% INCLUDE 'messaging-preference-form.inc' %]
1608
                                        [% IF ( SMSSendDriver ) %]
1626
                                        [% IF ( SMSSendDriver ) %]
Lines 1660-1665 legend:hover { Link Here
1660
    [% INCLUDE 'str/members-menu.inc' %]
1678
    [% INCLUDE 'str/members-menu.inc' %]
1661
    [% Asset.js("js/members-menu.js") | $raw %]
1679
    [% Asset.js("js/members-menu.js") | $raw %]
1662
    <script>
1680
    <script>
1681
        auto_email_primary_address = "[% Koha.Preference('AutoEmailPrimaryAddress') %]";
1682
        [% IF patron.notice_email_address %]
1683
        patron_email = "[% patron.notice_email_address %]";
1684
        [% END %]
1685
        [% IF patron.phone %]
1686
        patron_phone = "[% patron.phone %]";
1687
        [% END %]
1688
        [% IF patron.smsalertnumber %]
1689
        patron_sms = "[% patron.smsalertnumber %]";
1690
        [% END %]
1691
1663
        function update_cardnumber_warning(size){
1692
        function update_cardnumber_warning(size){
1664
            var max_len = [% maxlength_cardnumber | html %];
1693
            var max_len = [% maxlength_cardnumber | html %];
1665
            if ( size >= max_len ) {
1694
            if ( size >= max_len ) {
(-)a/koha-tmpl/intranet-tmpl/prog/js/members.js (+36 lines)
Lines 293-296 $(document).ready(function(){ Link Here
293
        "right": "1%",
293
        "right": "1%",
294
        "width": "150px",
294
        "width": "150px",
295
    } );
295
    } );
296
297
    auto_email_primary_address_el = $("input#email");
298
    if ((typeof auto_email_primary_address !== "undefined")) {
299
        if (auto_email_primary_address === "OFF") {
300
            auto_email_primary_address_el = $("input#email,input#emailpro,input#B_email");
301
        } else {
302
            auto_email_primary_address_el = $("input#"+auto_email_primary_address);
303
        }
304
    }
305
306
    if ((typeof patron_email !== "undefined" && !patron_email) || auto_email_primary_address_el.length ) {
307
        auto_email_primary_address_el.each(function () {
308
            if (disableCheckboxesWithInvalidPreferences($(this), "email")) {
309
                return false;
310
            }
311
        });
312
    }
313
    if ((typeof patron_phone !== "undefined" && !patron_phone) || $("input#phone").length) {
314
        disableCheckboxesWithInvalidPreferences($("input#phone"), "phone");
315
    }
316
    if ((typeof patron_sms !== "undefined" && !patron_sms) || $("input#SMSnumber").length) {
317
        disableCheckboxesWithInvalidPreferences($("input#SMSnumber"), "sms");
318
    }
319
    auto_email_primary_address_el.on("input change", function() {
320
        auto_email_primary_address_el.each(function () {
321
            if (disableCheckboxesWithInvalidPreferences($(this), "email")) {
322
                return false;
323
            }
324
        });
325
    });
326
    $("input#phone").on("input change", function() {
327
        disableCheckboxesWithInvalidPreferences($("input#phone"), "phone");
328
    });
329
    $("input#SMSnumber").on("input change", function() {
330
        disableCheckboxesWithInvalidPreferences($("input#SMSnumber"), "sms");
331
    });
296
});
332
});
(-)a/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js (-13 / +117 lines)
Lines 54-72 $(document).ready(function(){ Link Here
54
        });
54
        });
55
    }
55
    }
56
56
57
    function toggle_digest(id){
58
        let phone_checked = TalkingTechItivaPhoneNotification ? false : PhoneNotification ? $("#phone"+id).prop("checked") : false;
59
        if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") || phone_checked ) {
60
            if ($("#forcedigest"+id).length === 0) {
61
                $("#digest"+id).attr("disabled", false).tooltip('disable');
62
            }
63
        } else {
64
            if ($("#forcedigest"+id).length === 0) {
65
                $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable');
66
            }
67
        }
68
69
    }
70
    // At load time, we want digest disabled if no digest using transport is enabled
57
    // At load time, we want digest disabled if no digest using transport is enabled
71
    $(".pmp_email").each(function(){
58
    $(".pmp_email").each(function(){
72
        toggle_digest(Number($(this).attr("id").replace("email", "")));
59
        toggle_digest(Number($(this).attr("id").replace("email", "")));
Lines 85-87 $(document).ready(function(){ Link Here
85
72
86
//    $('#memberentry_messaging_prefs [data-toggle="tooltip"][disabled]').tooltip();
73
//    $('#memberentry_messaging_prefs [data-toggle="tooltip"][disabled]').tooltip();
87
});
74
});
75
76
function toggle_digest(id){
77
    let phone_checked = TalkingTechItivaPhoneNotification ? false : PhoneNotification ? $("#phone"+id).prop("checked") : false;
78
    if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") || phone_checked ) {
79
        if ($("#forcedigest"+id).length === 0) {
80
            $("#digest"+id).attr("disabled", false).tooltip('disable');
81
82
        }
83
    } else {
84
        if ($("#forcedigest"+id).length === 0) {
85
            $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable');
86
        }
87
    }
88
89
}
90
91
var patron_messaging_checkbox_preferences = {
92
    email: {
93
        checked_checkboxes: null,
94
        is_enabled: true,
95
        disabled_checkboxes: null
96
    },
97
    sms: {
98
        checked_checkboxes: null,
99
        is_enabled: true,
100
        disabled_checkboxes: null
101
    },
102
    phone: {
103
        checked_checkboxes: null,
104
        is_enabled: true,
105
        disabled_checkboxes: null
106
    },
107
};
108
109
function disableCheckboxesWithInvalidPreferences(elem, id_attr) {
110
111
    if (!$(elem).length && typeof window["patron_" + id_attr] !== "undefined") {
112
        return;
113
    }
114
115
    // Get checkbox preferences for the element
116
    var checkbox_prefs = patron_messaging_checkbox_preferences[id_attr];
117
118
    // Check if element is empty or not valid
119
    if (!$(elem).length || $(elem).val().length == 0 || !$(elem).valid()) {
120
121
        if (checkbox_prefs.is_enabled) {
122
123
            if ($("input[type='checkbox'][id^=" + id_attr + "]").length === 0) {
124
                return;
125
            }
126
127
            // Save the state of checked checkboxes
128
            checkbox_prefs.checked_checkboxes = $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]:checked,input[type='checkbox'][id^=digest]:checked");
129
130
            // Clear patron messaging preferences checkboxes
131
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").removeAttr("checked");
132
133
            // Then disable checkboxes from patron messaging perferences
134
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").prop("disabled", "disabled");
135
136
            // Color table cell's background emphasize the disabled state of the checkbox
137
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").parent().css("background-color", "#E8F0F8");
138
139
            disable_digest = true;
140
            $.each(patron_messaging_checkbox_preferences, function(key, obj) {
141
                if (key === id_attr) {
142
                    return;
143
                }
144
                if ($("input[type='checkbox'][id^=" + key + "]:not(:disabled)").length) {
145
                    disable_digest = false;
146
                }
147
            });
148
149
            if (disable_digest) {
150
                $("input[type='checkbox'][id^=digest]").removeAttr("checked");
151
                $("input[type='checkbox'][id^=digest]").prop("disabled", "disabled");
152
                $("input[type='checkbox'][id^=digest]").parent().css("background-color", "#E8F0F8");
153
            }
154
155
            // Remove notification of missing contact
156
            $("div.missing-message-pref-contact").css("display", "block");
157
158
            checkbox_prefs.is_enabled = false;
159
        }
160
161
        return false;
162
163
    } else {
164
165
        if (!checkbox_prefs.is_enabled) {
166
            // Enable patron messaging preferences checkboxes
167
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").prop("disabled", false);
168
169
            $("input[type='checkbox'][id^=digest]").parent().css("background-color", "");
170
171
            // Restore the state of checkboxes
172
            checkbox_prefs.checked_checkboxes.each(function() {
173
                $(this).prop("checked", "checked");
174
                if (!$("input[type='checkbox'][id='digest"+$(this).attr("data-attr-id")+"']:checked").length === 0) {
175
                    toggle_digest($(this).attr("data-attr-id"));
176
                }
177
            });
178
179
            // Remove the background color from table cell
180
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").parent().css("background-color", "");
181
182
            // Remove notification of missing contact
183
            $("div.missing-message-pref-contact").css("display", "none");
184
185
            checkbox_prefs.is_enabled = true;
186
        }
187
188
        return true;
189
190
    }
191
}
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt (-5 / +17 lines)
Lines 37-42 Link Here
37
                [% IF Koha.Preference( 'EnhancedMessagingPreferencesOPAC' ) || Koha.Preference('TranslateNotices') %]
37
                [% IF Koha.Preference( 'EnhancedMessagingPreferencesOPAC' ) || Koha.Preference('TranslateNotices') %]
38
                    <div id="usermessaging" class="maincontent">
38
                    <div id="usermessaging" class="maincontent">
39
                        <h1>Your messaging settings</h1>
39
                        <h1>Your messaging settings</h1>
40
                        [% IF !logged_in_user.email %]
41
                            <div class="alert alert-warning">
42
                                <h4>Cannot select email notifications</h4>
43
                                <p>Your email address is missing. We cannot send you emails before you provide your email address. Please go to <a href="opac-memberentry.pl">your personal details</a> to set primary email address.</p>
44
                            </div>
45
                        [% END %]
46
                        [% IF SMSSendDriver and !SMSnumber %]
47
                            <div class="alert alert-warning">
48
                                <h4>Cannot select SMS notifications</h4>
49
                                <p>Your SMS number is missing. We cannot send you SMS messages before you provide your SMS number. Please see the bottom of this page to set SMS number.</p>
50
                            </div>
51
                        [% END %]
40
                        [% IF ( settings_updated ) %]
52
                        [% IF ( settings_updated ) %]
41
                        <div class="alert alert-success"><p><strong>Settings updated</strong></p></div>
53
                        <div class="alert alert-success"><p><strong>Settings updated</strong></p></div>
42
                        [% END %]
54
                        [% END %]
Lines 95-104 Link Here
95
                                            [% IF ( SMSSendDriver ) %]
107
                                            [% IF ( SMSSendDriver ) %]
96
                                                [% IF ( messaging_preference.transport_sms ) %]
108
                                                [% IF ( messaging_preference.transport_sms ) %]
97
                                                    <td class="selectcol">
109
                                                    <td class="selectcol">
98
                                                        [% IF ( messaging_preference.transports_sms ) %]
110
                                                        [% IF ( messaging_preference.transports_sms and !messaging_preference.transports_sms_disabled ) %]
99
                                                        <input type="checkbox" class="pmp_sms" id="sms[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="sms" checked="checked" />
111
                                                        <input type="checkbox" class="pmp_sms" id="sms[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="sms" checked="checked" />
100
                                                        [% ELSE %]
112
                                                        [% ELSE %]
101
                                                            <input type="checkbox" class="pmp_sms" id="sms[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="sms" />
113
                                                            <input type="checkbox" class="pmp_sms" id="sms[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="sms"[% IF messaging_preference.transports_sms_disabled %] disabled="disabled"[% END %] />
102
                                                        [% END %]
114
                                                        [% END %]
103
                                                    </td>
115
                                                    </td>
104
                                                [% ELSE %]
116
                                                [% ELSE %]
Lines 150-159 Link Here
150
162
151
                                            [% IF ( messaging_preference.transport_email ) %]
163
                                            [% IF ( messaging_preference.transport_email ) %]
152
                                                <td class="selectcol">
164
                                                <td class="selectcol">
153
                                                    [% IF ( messaging_preference.transports_email ) %]
165
                                                    [% IF ( messaging_preference.transports_email and !messaging_preference.transports_email_disabled ) %]
154
                                                        <input type="checkbox" class="pmp_email" id="email[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="email" checked="checked" />
166
                                                        <input type="checkbox" class="pmp_email" id="email[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="email" checked="checked" onclick = "document.opacmessaging.none[% messaging_preference.message_attribute_id | html %].checked=false;" />
155
                                                    [% ELSE %]
167
                                                    [% ELSE %]
156
                                                        <input type="checkbox" class="pmp_email" id="email[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="email" />
168
                                                        <input type="checkbox" class="pmp_email" id="email[% messaging_preference.message_attribute_id | html %]" name="[% messaging_preference.message_attribute_id | html %]" value="email" onclick = "document.opacmessaging.none[% messaging_preference.message_attribute_id | html %].checked=false;"[% IF messaging_preference.transports_email_disabled %] disabled="disabled"[% END %] />
157
                                                    [% END %]
169
                                                    [% END %]
158
                                                </td>
170
                                                </td>
159
                                            [% ELSE %]
171
                                            [% ELSE %]
(-)a/members/memberentry.pl (-3 / +24 lines)
Lines 23-28 use Modern::Perl; Link Here
23
23
24
# external modules
24
# external modules
25
use CGI qw ( -utf8 );
25
use CGI qw ( -utf8 );
26
use Scalar::Util qw( blessed );
27
use Try::Tiny;
26
28
27
# internal modules
29
# internal modules
28
use C4::Auth qw( get_template_and_user haspermission );
30
use C4::Auth qw( get_template_and_user haspermission );
Lines 479-485 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
479
        }
481
        }
480
482
481
        if ( $patron && (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) ) {
483
        if ( $patron && (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) ) {
482
            C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'});
484
            try {
485
                C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'});
486
            } catch {
487
                unless ( blessed $_ && $_->can('rethrow') ) {
488
                    die $_;
489
                } else {
490
                    $template->param(
491
                        error_alert => $_
492
                    );
493
                }
494
            };
483
        }
495
        }
484
496
485
        # Create HouseboundRole if necessary.
497
        # Create HouseboundRole if necessary.
Lines 560-566 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
560
572
561
            add_guarantors( $patron, $input );
573
            add_guarantors( $patron, $input );
562
            if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
574
            if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
563
                C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template);
575
                try {
576
                    C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template);
577
                } catch {
578
                    unless ( blessed $_ && $_->can('rethrow') ) {
579
                        die $_;
580
                    } else {
581
                        $template->param(
582
                            error_alert => $_
583
                        );
584
                    }
585
                };
564
            }
586
            }
565
        }
587
        }
566
    }
588
    }
567
- 

Return to bug 18595