<script type="text/javascript">

    $.ctrl('S', function () {
        return json_add('pipeline_types-add', 'x', '0', 'popupform');
    });

</script>


<link type="text/css" rel="stylesheet" media="all" href="css/fields_sortable.css"/>
<script type="text/javascript">
    $(document).ready(function () {
        $("#source_list").sortable({
            placeholder: "ui-state-highlight"
        }).disableSelection();
    });
</script>

<form action="" method="post" id="popupform" onsubmit="return json_add('pipeline_types-add','x','0','popupform');">

    <div id="popupsave">
        <input type="submit" value="Save" class="save"/>
    </div>

    <h1>Pipeline Steps</h1>
    <div class="pad24t popupbody">
        <ul id="source_list" class="popup_longlist">

            <?php
            $contact = new contact;
            $types = $contact->getTypes();

            foreach ($types as $item) {
            ?>

                <li id="td-cell-<?php echo $item['id'] ?>">

                    <span class="floatright">

                        <?php
                        if ($item['id'] != '1') {
                            ?>
                            <input type="checkbox" name="pipeline[<?php echo $item['id']; ?>][delete]" value="1" /> Delete
                            <?php
                        }
                        ?>

                    </span><input type="text" name="pipeline[<?php echo $item['id']; ?>][name]" style="width:85%;"
                               value="<?php echo $item['name'] ?>"/></span>

                    <input type="hidden" name="pipeline[<?php echo $item['id']; ?>][id]"
                           value="<?php echo $item['id'] ?>"/>

                </li>

            <?php
            }
            ?>

        </ul>


        <div class="submit">

            <a href="null.php" onclick="return add_source();">[+] Add New Pipeline Step</a>

        </div>


    </div>


</form>


<script type="text/javascript">

    function add_source() {
        var math = Math.random().toString(36).substring(7);
        html = '<li><input type="text" name="pipeline[new_' + math + '][name]" style="width:90%;" value="" /><input type="hidden" name="source[new_' + math + '][id]" value="new" /></li>';
        $('#source_list').append(html);
        return false;
    }

</script>