<?
$formname    = "form_infopoint_presets_cardform";
$translation = \DynCom\mysyde\common\classes\Registry::get("translation");
$inputname   = "input_id";
$siteparts   = \DynCom\mysyde\common\classes\Siteparts::get();


$sorting_values = array(
    $translation->get("collection_sorting_keep"),
    $translation->get("collection_sorting_change_top"),
    $translation->get("collection_sorting_change_bottom")
);

?>

<div id="overlaycrumb">
    <?php if ($input_line["id"] == "") {
        echo $translation->get("new_preset");
    } else {
        echo $translation->get("edit_preset");
    }
    ?>
    <div id="closeoverlay" onclick="disableOverlay();"></div>
</div>

<ul class="toolbar_menu">
    <?= button("new", $translation->get("add_content2"), $formname, "toggleScrollerHeadline('" . $translation->get("add_content2") . "', 'new');"); ?>
    <?php

    // Speichern buttons
    button("save", $translation->get("save"), $formname, "loadCard('save_preset', true)");

    button("save", $translation->get("save_and_close"), $formname, "loadCard('save_preset', true, '', true)");

    if ($input_line["id"] != "") {
        echo button("delete", $translation->get("delete"), $formname, "loadCard('delete_preset', true, '{$translation->get('delete_preset')}', true)");
    }
    ?>

    <li>
        <ul>
        <?= button("delete",$translation->get("delete_content"),$formname,"loadCard('delete_line_preset', false, '{$translation->get('delete_assoc_pageline')}')","", false); ?>
        </ul>
    </li>

    <li>
        <ul>
        <?= button("up",$translation->get("go_up"),$formname,"loadCard('moveup_line_preset')", "", false); ?>
        <?= button("down",$translation->get("go_down"),$formname,"loadCard('movedown_line_preset')", "", false); ?>
        </ul>
    </li>
</ul>
<div class="clearfix"></div>

<?php
if (count($messages)) {
    echo '<div id="overlayMessages">' . join("\r\n", $messages) . '</div>';
}
?>

<form id="<?= $formname ?>" name="<?= $formname ?>" method="post">
    <input name="input_id" type="hidden" value="<?= $input_line["id"] ?>" />
    <input name="input_preset_id" type="hidden" value="<?= $input_line["id"] ?>" />
    <input name="save_and_close" id="save_and_close" type="hidden" value="0" />

    <table class="cardform" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
                <?
                input($translation->get("description"), "input_description", "text", $input_line["description"], 255);
                input_select($translation->get("collection_change_sorting"), "input_change_sorting", $values = array_keys($sorting_values), $value_names = array_values($sorting_values), "", FALSE, FALSE);
                input_select($translation->get("default_active"), "input_default_active", $values = array('1', '0'), $value_names = array($translation->get("yes"), $translation->get("no")), $input_line["default_active"]);
                ?>
            </td>

            <td>
                <?php
                if ($input_line["id"] != "") {
                    show_changed_on($input_line["id"], "main_infopoint_presets");
                    show_changed_by($input_line["id"], "main_infopoint_presets");
                }
                ?>
            </td>
        </tr>
    </table>
</form>
<form id="form_field_list" name="form_field_list" method="post">
<?
    show_preset_rows();
?>
</form>


<script type="text/javascript">
    var reorderCall = null;

    //$('.dd').nestable({ /* config options */ });
    $('ol.sortable').nestedSortable({
                                        forcePlaceholderSize: true,
                                        handle              : '.dd-icon',
                                        helper              : 'clone',
                                        items               : 'li',
                                        opacity             : .6,
                                        placeholder         : 'placeholder',
                                        revert              : 250,
                                        tabSize             : 25,
                                        tolerance           : 'pointer',
                                        toleranceElement    : '> div',
                                        maxLevels           : 3,
                                        isTree              : true,
                                        expandOnHover       : 1000,
                                        cookieIndex         : 'nestedSortable_pagecontent_expanded',
                                        startCollapsed      : true,
                                        stop                : function ( event, ui ) {
                                            reorder_navigation();
                                            store_expanded();
                                        },
                                        disabled            : false,
                                        isAllowed           : function ( placeholder, placeholderParent, originalItem ) {

                                            // gruppe in eine gruppe hinzufuegen nicht moeglich
                                            if (placeholderParent !== null &&
                                                jQuery(originalItem).hasClass("mjs-nestedSortable-no-nesting") === false &&
                                                jQuery(placeholderParent).hasClass("mjs-nestedSortable-no-nesting") === false) {
                                                return false;
                                            }
                                            return true;
                                        }
                                    });

    $('.disclose').click(function () {
        $(this).closest('li').toggleClass('mjs-nestedSortable-collapsed').toggleClass('mjs-nestedSortable-expanded');
        store_expanded();
    });

    function store_expanded() {
        var list = [];
        $('ol.sortable').find('li.mjs-nestedSortable-expanded').each(function () {
            list.push($(this).attr("id"));
        });
        $.cookie('nestedSortable_pagecontent_expanded', list.join(','));
    }

    function reorder_navigation() {
        if (reorderCall !== null) {
            reorderCall.abort();
        }

        serialized = $('ol.sortable').nestedSortable('serialize');
        arraied = $('ol.sortable').nestedSortable('toHierarchy', {startDepthCount: 0});
        var parameter = {
            list: arraied
        };
        reorderCall = jQuery.post("?action=reorder_content_page", parameter, function ( output, status, xhr ) {
            if (xhr.getResponseHeader('REQUIRES_AUTH') == 1) {
                window.location.replace("/mysyde/");
            }
        });
    }

</script>