<?
$translation = \DynCom\mysyde\common\classes\Registry::get("translation");
$formname    = "form_page_list";

?>

<script type="text/javascript">
    function filter_page() {
        jQuery('#form_page_list .requestLoader').show();

		var filter_id = jQuery('#page_filter').val();
		var include_sub = jQuery('#include_children').is(':checked') ? 1 : 0;

		jQuery('#form_page_list').attr("action", "?filter_id=" + filter_id + "&include_sub=" + include_sub).submit();

		return;

        var formData = {
            filter_id       : jQuery('#page_filter').val(),
            include_children: jQuery('#include_children').is(':checked') ? 1 : 0
        };

        $.ajax({
                   url    : "?action=filter_page",
                   type   : 'POST',
                   data   : formData,
                   success: function ( output, status, xhr ) {
                       if (xhr.getResponseHeader('REQUIRES_AUTH') == 1) {
                           window.location.replace("/mysyde/");
                       } else {
                           jQuery('#form_page_list .requestLoader').hide();
                           jQuery('#page_linklist').html(output);

                           initForm();
                           initLinklist();
                       }
                   }
               });
    }

    function preview_page() {
        var currentMarkedLinklistRow = jQuery('.linklist_active', jQuery('#' + dc.current_formname));
        var input_id = currentMarkedLinklistRow.data('inputid');
		var current_location = String(document.location).replace(/\?.*$/, '');
		window.open(current_location + "?preview_page=true&input_page_id=" + input_id);
    }
</script>
 
<ul class="toolbar_menu">
    <?= button("new", $translation->get("new"), $formname, "loadCard('new_page', true)"); ?>
</ul>

<div id="mainContent">
    <?php echo current_website_language($site, $language); ?>
    <h1><?php echo get_translation('left_sites'); ?></h1>

    <form id="<?= $formname ?>" name="<?= $formname ?>" method="post" enctype="multipart/form-data">
        <?php
        page_filter($GLOBALS["site"]['id'],$GLOBALS["language"]['id'], (int)$_REQUEST['filter_id'], (isset($_REQUEST['include_sub']) ? (int)$_REQUEST['include_sub'] : 1));
        ?>
        <div class="clearfix"></div>


        <input type="hidden" class="selected_linklist_row" name="input_page_id" value="" />
        <div class="requestLoader"></div>
        <div id="page_linklist">
            <?
            filter_page();
            ?>
        </div>
    </form>

</div>
