BBS Forum (24)

BBS Forum (24)

24.1. Edit section

cms/js/banners.js

$(function () {
    $('.edit-board-btn').click(function () {
        var self = $(this);
        var tr = self.parent().parent();
        var name = tr.attr('data-name');
        var board_id = tr.attr('data-id');

        zlalert.alertOneInput({
            'title':'Edit section',
            'text':'Please enter the section name',
            'placeholder': name,
            'confirmCallback': function (inputValue) {
                zlajax.post({
                    'url':'/cms/uboards/',
                    'data': {
                        'board_id': board_id,
                        'name': inputValue
                    },
                    'success': function (data) {
                        if (data['code'] == 200) {
                            win.loc.reload();
                        } else {
                            zlalert.alertInfo(data['message'])
                        }
                    }
                });
            }
        });

    });
});

24.2. Delete section

cms/js/banners.js

$(function () {
    $('.delete-board-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var board_id = self.parent().parent().attr('data-id');
        zlalert.alertConfirm({
            'title':'Delete section',
            'msg':'Are you sure to delete this section?',
            'confirmCallback': function () {
                zlajax.post({
                    'url':'/cms/dboards/',
                    'data': {
                        'board_id': board_id
                    },
                    'success': function (data) {
                        if (data['code'] == 200) {
                            win.loc.reload();
                        } else {
                            zlalert.alertInfo(data['message']);
                        }
                    }
                });
            }
        })
    })
});

24.3. Home page dynamic display section

(1) front/views.py

@bp.route('/')
def index():
    banners = BannerModel.query.order_by(BannerModel.priority.desc()).limit(4)
    boards = BoardModel.query.all()
    context = {
        'banners':banners,
        'boards':boards
    }
    return render_template('front/front_index.html',**context)

(2) front/index.py

 <div class="sm-container">
            <div style="margin-bottom: 10px;">
                <button class="btn btn-warning btn-block">Post a post</button>
            </div>


            <div class="list-group">
                <a href="#" class="list-group-item active">All sections</a>

                {% for board in boards %}
                    <a href="#" class="list-group-item">{{ board.name }}</a>
                {% endfor %}
            </div>
        </div>
Reference: https://cloud.tencent.com/developer/article/1390492 BBS Forum (twenty-four)-Cloud + Community-Tencent Cloud