<?php
$this->ciext->load_jquery_ui();
$this->js_css->parse_js('skeleton/crud/js/crud.js', array('source: 1' => json_encode($aSource)));
?>
<?php echo form_open('', array('class' => 'form-horizontal', 'id' => 'crud_form')); ?>
<?php if ($error) : ?>
    <div class="alert alert-error">
        <button type="button" class="close" data-dismiss="alert">&times;
        </button><?php echo $this->lang->line('Generation fail'); ?></div>
<?php endif; ?>
<div class="control-group">
    <div class="row">
        <div class="span4">
            <label class="control-label" for="moduleFolder"><?php echo $this->lang->line('Module catalog'); ?></label>
            <div class="controls">
                <input type="text" id="moduleFolder" name="module_folder" required="required" placeholder="<?php echo $this->lang->line('Enter module catalog'); ?>" value="{module_folder}" />
            </div>
        </div>
        <div class="span7 offset7">
            <label class="control-label" for="table_name"><?php echo $this->lang->line('CRUD examples'); ?></label>
            <div class="controls">
                <?= form_dropdown('crud_example', $crud_examples, $this->input->post('crud_example'), ['id' => 'crud_example']) ?>
                <?= form_submit('load_examples', $this->lang->line('Load'), ['class' => 'btn', 'id' => 'load_examples']) ?>
            </div>
        </div>
    </div>
</div>
<div class="control-group">
    <label class="control-label" for="crudFile"><?php echo $this->lang->line('CRUD file name'); ?></label>
    <div class="controls">
        <input type="text" id="crudFile" name="crud_file" required="required" placeholder="<?php echo $this->lang->line('Enter CRUD file name'); ?>" value="<?php echo ($this->input->post('crud_file')) ?: 'crud'; ?>" />
    </div>
</div>
<div class="control-group">
    <label class="control-label" for="table_name"><?php echo $this->lang->line('CRUD table name'); ?></label>
    <div class="controls">
        <input type="text" id="table_name" name="table_name" required="required" placeholder="<?php echo $this->lang->line('Enter CRUD table name'); ?>" value="<?php echo $this->input->post('table_name'); ?>" />
    </div>
</div>
<table class="table table-bordered" id="crud_items">
    <tr>
        <th><?php echo $this->lang->line('Field name'); ?></th>
        <th><?php echo $this->lang->line('Display as'); ?></th>
        <th><?php echo $this->lang->line('Callback'); ?></th>
        <th><?php echo $this->lang->line('Not NULL'); ?></th>
        <th><?php echo $this->lang->line('Show in grid'); ?></th>
        <th><a href="#" class="btn add_btn"><?php echo $this->lang->line('Add'); ?></a></th>
    </tr>
    <?php foreach ($crud_items as $k => $v) : ?>
        <tr class="item">
            <td><?php echo form_input('item[' . $k . '][field]', (!empty($v['field']) ? $v['field'] : ''), 'class="autofield" required="required"'); ?></td>
            <td><?php echo form_input('item[' . $k . '][display_as]', (!empty($v['display_as']) ? $v['display_as'] : '')); ?></td>
            <td><?php echo form_dropdown('item[' . $k . '][callback]', $callbacks, (!empty($v['callback']) ? $v['callback'] : '')); ?></td>
            <td><?php echo form_checkbox('item[' . $k . '][not_null]', '1', (!empty($v['not_null']) ? $v['not_null'] : FALSE)); ?></td>
            <td><?php echo form_checkbox('item[' . $k . '][in_column]', '1', (!empty($v['in_column']) ? $v['in_column'] : FALSE)); ?></td>
            <td><a href="#" class="btn remove_btn"><?php echo $this->lang->line('Remove'); ?></a></td>
        </tr>
    <?php endforeach; ?>
</table>
<div class="form-actions">
    <input type="submit" class="btn btn-primary" value="<?php echo $this->lang->line('Generate CRUD'); ?>"/>
</div>
<?php echo form_close(); ?>