<link rel="stylesheet" href="/libraries/codemirror/lib/codemirror.css" />
<link rel="stylesheet" href="/libraries/codemirror/theme/material.css" />
<script type="text/javascript" src="/libraries/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/libraries/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript" src="/libraries/codemirror/lib/codemirror.js"></script>
<script type="text/javascript" src="/libraries/codemirror/mode/css/css.js"></script>
<script type="text/javascript" src="/libraries/codemirror/mode/xml/xml.js"></script>
<script type="text/javascript" src="/libraries/codemirror/mode/javascript/javascript.js"></script>
<script type="text/javascript" src="/libraries/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script type="text/javascript" src="/libraries/codemirror/addon/mode/multiplex.js"></script>
<?
global $db;

ob_start();
?>
  <div id="settings-tabs">
    <ul class="resp-tabs-list settings-tabs">
      <li><i class="fa fa-file"></i>Treść</li>
      <li><i class="fa fa-wrench"></i>Ustawienia</li>
    </ul>
    <div class="resp-tabs-container settings-tabs">
      <div>
        <div id="languages-main">
          <ul class="resp-tabs-list languages-main">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg['status'] ):?>
                <li><?= $lg['name'];?></a></li>
              <? endif;?>
            <? endforeach; endif;?>
          </ul>
          <div class="resp-tabs-container languages-main">
            <? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
              <? if ( $lg['status'] ):?>
                <div>
                  <?= \Html::input(
                              array(
                                'label'   => 'Tytuł',
                                'name'    => 'title',
                                'id'      => 'title_' . $lg['id'],
                                'value'   => $this -> container['languages'][ $lg['id'] ]['title'],
                                'inline'  => true
                              )
                          );?>
                  <?= \Html::textarea(
                              array(
                                'label'   => 'Treść',
                                'name'    => 'text',
                                'id'      => 'text_' . $lg['id'],
                                'value'   => $this -> container['languages'][ $lg['id'] ]['text'],
                                'inline'  => true
                              )
                          );?>
                  <?= \Html::textarea(
                              array(
                                'label'   => 'Kod HTML',
                                'name'    => 'html',
                                'id'      => 'html_' . $lg['id'],
                                'value'   => $this -> container['languages'][ $lg['id'] ]['html'],
                                'inline'  => true
                              )
                          );?>
                  <script type="text/javascript">
                    $( function() 
                    {
                      $( '#text_<?= $lg['id'];?>' ).ckeditor(
                      {
                        toolbar : 'MyToolbar',
                        height:'300'
                      });
                      var code_html = CodeMirror.fromTextArea( document.getElementById( "html_<?= $lg['id'];?>" ),{
                        lineWrapping: true,
                        mode: "text/html"
                      });
                      code_html.on( 'change', function(cm) {
                        $( '#html_<?= $lg['id'];?>' ).val( cm.getValue() );
                      });
                      code_html.setOption( "theme", 'material' );
                    });
                  </script>
                </div>
              <? endif;?>
            <? endforeach; endif;?>
          </div>
          <div class="clear"></div>
        </div>
      </div>
      <div>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Aktywny',
                      'name'    => 'status',
                      'checked' => $this -> container['status'] == 1 or !$this -> container['id'] ? true : false
                    )
                );
        ?>
        <?= \Html::input_switch(
                    array(
                      'label'   => 'Pokaż tytuł',
                      'name'    => 'show_title',
                      'checked' => $this -> container['show_title'] == 1 ? true : false
                    )
                );
        ?>
        <?= \Html::input_icon(
                    array(
                        'label' => 'Tło kontenera',
                        'name' => 'src',
                        'id' => 'src',
                        'value' => $this->container['src'],
                        'icon_content' => 'przeglądaj',
                        'icon_js' => "window.open ( 'http://" . $_SERVER['SERVER_NAME'] . "/libraries/filemanager-9.14.0/dialog.php?type=1&popup=1&field_id=src&akey=c3cb2537d25c0efc9e573d059d79c3b8', 'mywindow', 'location=1,status=1,scrollbars=1, width=1100,height=700');"
                    )
            );
        ?>
      </div>
    </div>
  </div>
<?
$out = ob_get_clean();

$grid = new \gridEdit;
$grid -> id               = 'container-edit';
$grid -> gdb_opt          = $gdb;
$grid -> include_plugins  = true;
$grid -> title            = 'Edycja kontenera statycznego';
$grid -> fields           = [
                              [
                                'db' => 'id',
                                'type' => 'hidden',
                                'value' => $this -> container['id']
                              ]
                            ];
$grid -> actions          = [ 
                              'save' => [ 'url' => '/admin/scontainers/container_save/', 'back_url' => '/admin/scontainers/view_list/' ], 
                              'cancel' => [ 'url' => '/admin/scontainers/view_list/' ] 
                            ];
$grid -> external_code    = $out;
$grid -> persist_edit     = true;
$grid -> id_param         = 'id';

echo $grid -> draw();
?>
<script type="text/javascript">  
  $( function() 
  {    
    disable_menu();
    
    $( '#settings-tabs' ).easyResponsiveTabs({
      width: 'auto',
      fit: true,
      tabidentify: 'settings-tabs',
      type: 'vertical'
    });
    
    $( '#languages-main' ).easyResponsiveTabs({
      width: 'auto',
      fit: true,
      tabidentify: 'languages-main'
    });
    
    $( '#g-menu' ).attr( 'data-spy', 'affix' );
    $( '#g-menu' ).attr( 'data-offset-top', '135' );   
    
  });
</script>
<script>CKEDITOR.dtd.$removeEmpty['span'] = false;</script>