<?php
/**
 * 
 * @author Fred
 * @version 1.0.1
 * @package Backend\SIG
 */


$context = $this->data["contextname"];
$list = $this->data['list'];
?>

<script>
    
  function update_cbx (version_name,format_name,getfeat_name) {
      $('#serviceVersion').val("");
      $('#serviceImgFormat').val("");
      $('#serviceGetFeatFormat').val("");
      
      
    if ($('#serviceType').val() == '') {
            $('#serviceVersion').prop('disabled', 'disabled');
            $('#serviceImgFormat').prop('disabled', 'disabled');
            $('#serviceGetFeatFormat').prop('disabled', 'disabled');
        } else {
            $('#serviceVersion').prop('disabled', false);
            $('#serviceImgFormat').prop('disabled', false);
            $('#serviceGetFeatFormat').prop('disabled', false);
        };
        
    $.ajax({
      url: 'websigservices',
      type: 'POST',
      dataType:'json',
   
      data: {'action': 'get_lists', 'serviceType': $('#serviceType').val()},
      
      success: function(data, status) {
          $('#serviceVersion').empty();
           for (i=0;i<data.length;i++){
               if ((data[i].version_name) !== undefined) { $('#serviceVersion').append(new Option(data[i].version_name)) };
               //$('#serviceVersion').append(new Option(data[i].version_name));
           };
           
          $('#serviceImgFormat').empty();
           for (i=0;i<data.length;i++){
               if ((data[i].format_name) !== undefined) {$('#serviceImgFormat').append(new Option(data[i].format_name))};
           }; 
           
          $('#serviceGetFeatFormat').empty();
           for (i=0;i<data.length;i++){
               if ((data[i].getfeatformat_name) !== undefined) {$('#serviceGetFeatFormat').append(new Option(data[i].getfeatformat_name))};
           }; 
           
            $('#serviceVersion').val(version_name);
            $('#serviceImgFormat').val(format_name);
            $('#serviceGetFeatFormat').val(getfeat_name);

      },
      
      error: function(xhr, desc, err) {
        console.log(xhr);
        console.log("Details: " + desc + "\nError:" + err);
      }
    });       
    };

</script>

<!--<button class="btn btn-primary btn-lg" id="btTestMapModal">
  map
</button>
<script>
    $("#btTestMapModal").click(function(e) {
        
    //showMapModal(44.55,-0.2,8,"Point tooltip text...");
    
    showMapModalArray(["45.55,-0.2","44.55,-1.2","43.55,-2.2"],true);
    });
    
</script>-->




<div class="row" >
    <div class="col-lg-12" >
        <h3><?= $this->data['page'] == "services" ? R('page_title_websig_services_catalog') : R('page_title_websig_services_groups') ?></h3>
        <div class="panel panel-default">
            <div class="panel-body">
                <ul class="nav nav-pills">
                    <li class="<?= $this->data['page'] == "services" ? "active" : "" ?>"><a href="<?= __SITEBASE ?>/websigservices/services"><?= R("page_nav_websig_services_catalog") ?></a></li>
                    <li class="<?= $this->data['page'] == "services_groups" ? "active" : "" ?>"><a href="<?= __SITEBASE ?>/websigservices/servicesgroups"><?= R("page_nav_websig_services_groups") ?></a></li>
                </ul>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="table-responsive" >
                    <table class="table table-hover table-striped tablesorter">
                        <thead>
                            <tr>
                                <th class="header"><?= R("label_ows_name") ?> <i class="fa fa-sort"></i></th>
                                <th class="header"><?= R("label_ows_active") ?> </th>
                                <th class="header"><?= R("label_ows_ispublic") ?> </th>
                                <th class="header"><?= R("label_ows_groupname") ?> <i class="fa fa-sort"></i></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($list as $obj) { ?>
                                <tr  onclick="javascript:
                                        $action = 'edit';
                                        $('#form1').attr('action','<?= __SITEBASE ?>/websigservices/action?id=<?= $obj->id ?>');
                                        
                                        $('#in_owsgroup').val('<?= $obj->group_name ?>');
                                        
                                        $('#in_owsname').attr('value','<?= $obj->service_name ?>');
                                        $('#in_owsurl').attr('value','<?= $obj->service_url ?>');
                                        $('#in_owsdescr').attr('value','<?= $obj->description ?>');
                                        $('#in_owsactive').prop('checked','<?= $obj->active ? "checked" : "" ?>');
                                        $('#in_owspublic').prop('checked','<?= $obj->is_public ? "checked" : "" ?>');
                                        
                                        $('#in_owsurlmetadata').attr('value','<?= $obj->metadata_url ?>');
                                        $('#in_owsurlresource').attr('value','<?= $obj->online_resource ?>');
                                        
                                        $('#serviceType').val('<?= $obj->type_name ?>')
                                        update_cbx('<?= $obj->version_name ?>','<?= $obj->format_name ?>','<?= $obj->getfeatformat_name ?>');

                                        $('#showgroup').slideDown();
                                        $('#showgroupdetail').hide();
                                        $('#cancelgroupedit').show();
                                        $('#btndelete').show();
                                        $('#btnupdate').show();
                                        $('#btnsubmit').hide();

                                        $('html, body').animate({
                                            scrollTop: $('#showgroup').offset().top
                                        }, 'slow');
                                     
                                     ">
                                    

                                    
                                        <!------------------------------------------------------------------------------------------->
                                        <?php 
                                                $name = "service_name";
                                                $type = "text";
                                        ?>
                                        <td><?= print_field($obj-> $name,$type) ?></td>
                                        <!------------------------------------------------------------------------------------------->

                                        <td><input disabled="disabled" type="checkbox" name="active_<?= $obj->id ?>" <?= $obj->active ? 'checked' : '' ?>></td>
                                        <td><input disabled="disabled" type="checkbox" name="is_public_<?= $obj->id ?>" <?= $obj->is_public ? 'checked' : '' ?>></td>
                                        <!------------------------------------------------------------------------------------------->
                                        <?php 
                                                $name = "group_name";
                                                $type = "text";
                                        ?>
                                        <td><?= print_field($obj-> $name,$type) ?></td>
                                        <!------------------------------------------------------------------------------------------->
                                        
                                        
                                </tr>
                            <?php } ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

    
   <div class="form-group">
            <label class="col-sm-0 control-label"></label>
            <a href="#" class="btn btn-link" id="showgroupdetail" onclick="javascript:$('#showgroup').slideDown();
                        $action = 'new';
                        $('#form1').attr('action','<?= __SITEBASE ?>/websigservices/action') ;
                        
                        $('#serviceType').val('');
                        update_cbx ();
                        
                                        $('#in_owsname').attr('value','');
                                        $('#in_owsurl').attr('value','');
                                        $('#in_owsdescr').attr('value','');
                                        $('#in_owsactive').prop('checked','checked');
                                        $('#in_owspublic').prop('checked','');
                                        $('#in_owsurlmetadata').attr('value','');
                                        $('#in_owsurlresource').attr('value','');
                                        
                        
                                        $('#btndelete').hide();
                                        $('#btnupdate').hide();
                                        $('#btnsubmit').show();
                        $(this).hide();
                        $('#cancelgroupedit').show();"><?= R("label_addnewservice") ?></a>
            <a href="#" style="display:none" class="btn btn-link" id="cancelgroupedit" onclick="javascript:$('#showgroup').slideUp();
                            $(this).hide();
                            $('#showgroupdetail').show();"><?= R("label_cancel") ?></a>
        </div>
        
        <form id="form1" class="form-horizontal" action="<?= __SITEBASE ?>/websigservices/action" method="post">
        <div class="panel panel-default" id="showgroup" style="display:none">
            <div class="panel-body">
                <div >
                    
                    <div class="form-group ">
                        <label class="col-sm-4 control-label"><?= R('label_servicegroupname') ?>:</label>
                        <div class="col-sm-4">
                            <select  name="ows_groupname" id="in_owsgroup" class="form-control">
                               <?php foreach($this->data['list_owsgroups'] as $group ) { ?>
                                <option ><?= $group->name ?></option>
                               <?php } ?>
                            </select>
                        </div>
                    </div>
                    
                    <div class="form-group ">
                        <label class="col-sm-4 control-label"><?= R('label_ows_name') ?>:</label>
                        <div class="col-sm-8">
                            <input maxlength="100"required class="form-control"  value="" name = "ows_name" id="in_owsname">
                        </div>
                    </div>
                    
                    <div class="form-group ">
                        <label class="col-sm-4 control-label"><?= R('label_ows_url') ?>:</label>
                        <div class="col-sm-8">
                            <input maxlength="150"required class="form-control"  value="" name = "ows_url" id="in_owsurl">
                        </div>
                    </div>
                    
                    <div class="form-group ">
                        <label class="col-sm-4 control-label"><?= R('label_ows_description') ?>:</label>
                        <div class="col-sm-8">
                            <input maxlength="200"  class="form-control"  value="" name = "ows_description" id="in_owsdescr">
                        </div>
                    </div>
                    
                    <div class="form-group ">
                        <label class="col-sm-4 control-label"><?= R('label_ows_active') ?>:</label>
                        <div class="col-sm-8">
                            <input type="checkbox"  value="z" name = "ows_active" id="in_owsactive">
                        </div>
                    </div>
                    <div class="form-group ">
                        <label class="col-sm-4 control-label"><?= R('label_ows_public') ?>:</label>
                        <div class="col-sm-8">
                            <input type="checkbox"  value="z" name = "ows_owspublic" id="in_owspublic">
                        </div>
                    </div>
                    <div class="form-group ">
                        <label class="col-sm-4 control-label"><?= R('label_ows_url_metadata') ?>:</label>
                        <div class="col-sm-8">
                            <input maxlength="150" class="form-control"  value="" name = "ows_url_metadata" id="in_owsurlmetadata">
                        </div>
                    </div>
                    <div class="form-group ">
                        <label class="col-sm-4 control-label"><?= R('label_ows_url_resource') ?>:</label>
                        <div class="col-sm-8">
                            <input maxlength="150" class="form-control"  value="" name = "ows_url_resource" id="in_owsurlresource">
                        </div>
                    </div>
                    
                                            <div class="row">					 
                                                <div class="col-sm-3">
                                                    <label><?= R('label_ows_type') ?>:</label>
                                                    <select id="serviceType" class="form-control" onchange="update_cbx()" name="ows_serviceType">
                                                        <option value=""></option>
                                                        <?php foreach($this->data['list_serv_type'] as $opt ) { ?>
                                                         <option ><?= $opt->type_name ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <div class="col-sm-3">
                                                    <label><?= R('label_ows_version') ?>:</label>
                                                    <select id="serviceVersion" class="form-control"  name="ows_serviceVersion">
                                                        <option value=""></option>
                                                        <?php foreach($this->data['list_serv_version'] as $opt ) { ?>
                                                         <option ><?= $opt->version_name ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <div class="col-sm-3">
                                                    <label><?= R('label_ows_img_format') ?>:</label>
                                                    <select id="serviceImgFormat" class="form-control" name="ows_serviceImgFormat">
                                                        <option value=""></option>
                                                        <?php foreach($this->data['list_serv_imgFormat'] as $opt ) { ?>
                                                         <option ><?= $opt->format_name ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <div class="col-sm-3">
                                                    <label><?= R('label_ows_getFeatInfo') ?>:</label>
                                                    <select id="serviceGetFeatFormat" class="form-control" name="ows_serviceGetFeatFormat">
                                                        <option value=""></option>
                                                        <?php foreach($this->data['list_serv_getFeatFormat'] as $opt ) { ?>
                                                         <option ><?= $opt->format_name ?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                            </div>     
                    
 
                </div>
                <p>&nbsp;</p>
                <div class="col-sm-7">
                    <button id="btnsubmit" type="submit" class="btn btn-default" name="btnAction" value='ows_save'><?= R('btn_save') ?></button>
                    <button id="btnupdate" type="submit" class="btn btn-default" name="btnAction" value='ows_update'><?= R('btn_update') ?></button>
                    <button id="btndelete" type="submit" class="btn btn-default" name="btnAction" value='ows_delete'><?= R('btn_delete') ?></button>
                </div>    
            </div>
        </div>
        </form>

    </div>
</div>
