31 Oct #1

Alert Modal Read/Delete Buttons

Ultimate subscriber
Shade, this is kinda unrelated to the plugin but can I get a peek at your Alert Modal Content template or can you help me figure out how you got the read/delete check mark and X in there?
Shade 31 Oct Edited
#2
Sure thing, here's the relevant links for that part:

<a href="{$mybb->settings['bburl']}/alerts.php?action=markread&amp;id={$alert['id']}&amp;my_post_key={$mybb->post_code}" class="markReadAlertButton" id="markread_alert_{$alert['id']}" title="Mark as read" uk-tooltip uk-icon="icon: check"></a>
<a href="{$mybb->settings['bburl']}/alerts.php?action=delete&amp;id={$alert['id']}&amp;my_post_key={$mybb->post_code}" class="deleteAlertButton uk-text-danger" id="delete_alert_{$alert['id']}" title="{$lang->myalerts_delete}" uk-tooltip uk-icon="icon: close"></a>
RocketFoot 31 Oct Edited
#3
Awesome! Thanks!

Thats weird...I used the codes above but nothing happened except the original delete links at the bottom of my modal disappeared.
RocketFoot 1 Nov Edited
#4
Shade, I managed to add the read/delete font awesome icons in my alert popup but it closes every time I click one of the new inline icons...do you have any idea what I am missing?
<tr class="alert {$alert['alert_status']} alert--{$alert['alert_code']}"
    id="alert_row_popup_{$alert['id']}">
    <td class="{$altbg} align-center alert__avatar" align="center">
        <a class="avatar" href="{$alert['from_user_raw_profilelink']}"><img
                src="{$alert['avatar']['image']}"
                alt="{$alert['username']}'s avatar" {$alert['avatar']['width_height']}/></a>
    </td>
    <td class="{$altbg} alert__content">
        <a href="{$mybb->settings['bburl']}/alerts.php?action=view&amp;id={$alert['id']}">
            {$alert['message']}
        </a>
       </td>
    <td class="{$altbg} alert__time">
        {$alert['received_at']}
        
        <a href="{$mybb->settings['bburl']}/alerts.php?action=markread&amp;id={$alert['id']}&amp;my_post_key={$mybb->post_code}" id="markread_alert_{$alert['id']}" <i class="fa fa-fw fa-check"></i></a>
        
        <a href="{$mybb->settings['bburl']}/alerts.php?action=delete&amp;id={$alert['id']}&amp;my_post_key={$mybb->post_code}" id="delete_alert_{$alert['id']}" title="{$lang->myalerts_delete}" <i class="fa fa-fw fa-times"></i></a>    
    </td>
</tr>
Shade 1 Nov
#5
Classes must be retained. Those buttons are missing crucial classes which are necessary for MyAlerts' script to execute AJAX functions.
RocketFoot 1 Nov
#6
Are those classes built in or did you add them?

class="markReadAlertButton"

class="deleteAlertButton
Shade 1 Nov
#7
The deleteAlertButton one is core to MyAlerts. For the other one, I checked my files and I have altered the plugin as follows. jscripts/myalerts.js, add after deleteAlert() function:

module.prototype.markReadAlert = function markReadAlert(event) {
            event.preventDefault();

            var button = $(event.currentTarget),
                alertId = button.attr("id").substring(15);

            $.getJSON('xmlhttp.php?action=myalerts_mark_read', {
                accessMethod: 'js',
                id: alertId,
                my_post_key: my_post_key
            }, function (data) {
                if (data.success) {
                    $(button.parents('tr').get(0)).removeClass('alert--unread').addClass('alert--read');
                }
                else {
                    for (var i = 0; i < data.errors.length; ++i) {
                        console.log(data.errors[i]);
                    }
                    alert(data.errors[0]);
                }
            });

            return false;
        };
inc/plugins/myalerts.php, add after line 1520:

if ($mybb->get_input('action') == 'myalerts_mark_read') {
        header('Content-Type: application/json');

        $id = $mybb->get_input('id', MyBB::INPUT_INT);
        $userId = (int) $mybb->user['uid'];

        $toReturn = array();

        if ($id > 0) {
            if (!verify_post_check($mybb->get_input('my_post_key'), true)) {
                $toReturn = array(
                    'errors' => array($lang->invalid_post_code),
                );
            } else {
                MybbStuff_MyAlerts_AlertManager::getInstance()->markRead([$id]);

                $toReturn = array(
                    'success'  => true
                );
            }
        } else {
            $toReturn = array(
                'errors' => array($lang->myalerts_error_alert_not_found),
            );
        }

        echo json_encode($toReturn);
    }
RocketFoot 1 Nov
#8
My code seems different...what version of My Alerts are you running? I have 2.0.4
Shade 1 Nov
#9
Those pieces of code are not in the core, you have to add them. I am also running 2.0.4.
RocketFoot 1 Nov Edited
#10
I understand but myjscripts/myalerts.js, file doesn't have: deleteAlert() function:

Also, when I add the class for delete button, it disappears on my forum.