/**
 * FanPress CM Article list Namespace
 * @article Stefan Seehafer <sea75300@yahoo.de>
 * @copyright (c) 2015-2025, Stefan Seehafer
 * @license http://www.gnu.org/licenses/gpl.txt GPLv3
 */
if (fpcm === undefined) {
    var fpcm = {};
}

fpcm.search = {

    _dlg: false,

    init: function() {

       if (!fpcm.ui.langvarExists('ARTICLES_SEARCH')) {
            return;
        }

        if (!fpcm.search._dlg) {
            fpcm.search._dlg = new fpcm.ui.forms.searchDialog(fpcm.ui_dialogs.getConfig('search'));
        }

        fpcm.dom.bindClick('#btnOpensearch', function ()
        {
            fpcm.ui_dialogs.search(
                'articles',
                function(_ui, _bsObj) {

                    if (((new Date()).getTime() - fpcm.vars.jsvars.articlesLastSearch) < 10000) {
                        fpcm.ui.addMessage({
                            type: 'error',
                            txt : fpcm.ui.translate('SEARCH_WAITMSG')
                        });
                        return false;
                    }

                    let _filter = fpcm.search._dlg.getValues();
                    if (_filter === null) {
                        return;
                    }

                    fpcm.articles.loadItems({
                        filter: _filter
                    });
                },
                function() {
                    fpcm.ui.relocate('self');
                }
            );
        });

    }

};