<rdoc:include file="head.htm" />

<div class="portlet box default" id='table_wrapper_$table_id'>
<div class="portlet-title">
    <div class="caption">
        <i class="fa fa-globe"></i><a href="$_base?id=0">$sys_component_name</a> $nav 
    </div>
    <div class="actions">
    
        <a href="$_base/$task" class="btn blue btn-sm tmilink">
            <i class="fa fa-refresh"></i> @T[Refresh] </a>

    </div>
    
</div>

<div class="portlet-body" >
        <form action="$_base" name="ruiform" id="formSystemMenuTree">
          <input type="hidden" name="sbt" value="$sbt" />
            <table class="table table-striped table-bordered table-hover " id="systemMenuTree">
                <thead>
                <tr class="heading">
                    <th width="100">
                        
                    </th>
                    <th>
                        <div class="th-inner">菜单名称</div>
                    </th>
                    <th>
                        <div class="th-inner">默认展开</div>
                    </th>  
                    
                </tr>
                </thead>
                <tbody>
                <!--# foreach($menus as $key=>$v) { if (empty($v['children'])) continue; $id = $v['name']; 
                    $treepid = $v['parent']?'treegrid-parent-'.$v['parent']:''; #-->        
                <tr class="treegrid-$id $treepid" data-id="$id">
                    <td title="$id">$v[pid] </td>
                    <td title="$v[title]">
                         <input class="form-control input-large" name="params[$key][title]" value="$v[title]">
                    </td> 
                     <td title="$v[title]">                         
                         <input type='checkbox' class='make-switch onoff' data-size='normal' data-on-text='是' data-off-text='否' name="params[$key][open]" value="1" $v[open_checked] />
                    </td>  
                    <td> 
                      $v[url]
                    </td>                 
                </tr>
                <!--# foreach($v['children'] as $k2=>$v2) { $id = $v2['name']; 
                    $treepid = $v2['parent']?'treegrid-parent-'.$v2['parent']:''; #-->
                     <tr class="treegrid-$id $treepid" data-id="$id">
                    <td title="$id">$v2[pid]</td>
                    <td title="$v2[title]">
                         <input class="form-control input-large" name="params[$k2][title]" value="$v2[title]">
                    </td>   
                    <td title="$v[title]"> 
                    </td>               
                </tr>


                <!--# }} #-->

                
                </tbody>
                </table>

                <div class="form-actions">
                    <div class="row">
                        <div class="col-md-offset-3 col-md-9">
                            <button type="submit" class="btn btn-primary" id="btnUpdateSystemMenu">@T[Submit]</button>

                            <button type="button" class="btn btn-danger" id="btnReset">@T[Reset]</button>

                        </div>
                    </div>
                </div>
        </form>
</div>
</div>


<script type="text/javascript">
jQuery(document).ready(function() {    
        //treeview
      $('#systemMenuTree').treegrid({
          initialState: 'collapsed',//'collapsed'|'expanded',
          treeColumn: 0
      });

      $('#btnReset').on('click', function(e){        
        $.post(G.base+'/reset', function(res) {
            if (res.status == 0) {
                rui.showTSuccess('操作成功.');  
                rui.refresh(1);             
            } else {
               rui.showTError('操作失败:'+res.status);
            }
        }).fail(function(){
              rui.showTError('系统错误！');      
        });
    });
      

      //btnUpdateSystemMenu
       $('#formSystemMenuTree').validate({
                errorElement: 'span', //default input error message container
                errorClass: 'help-block', // default input error message class
                focusInvalid: false, // do not focus the last invalid input
                rules: {
                    'params[title]': {
                        required: true,
                    },
                },
                messages: {  
                    'params[title]': {
                        required: t("The field is required."),
                    },              
                },

                invalidHandler: function (event, validator) { //display error alert on form submit   
                    $('.alert-danger', $('.login-form')).show();
                },

                highlight: function (element) { // hightlight error inputs
                    $(element)
                        .closest('.form-group').addClass('has-error'); // set error class to the control group
                },

                success: function (label) {
                    label.closest('.form-group').removeClass('has-error');
                    label.remove();
                },

                errorPlacement: function (error, element) {
                    error.insertAfter(element);
                },

                submitHandler: function (form) {
                    showWaiting("请稍后。。。");       
                       
                   var  formData = $(form).serializeArray();
                   //console.log(formData);
                   
                   $.post(form.action, formData, function(res) {
                        if (res.status == 0) {
                            rui.showTSuccess('操作成功.');  
                            rui.refresh(1);                                  
                        } else {
                           rui.showTError('操作失败:'+res.status);
                        }
                    }).fail(function(res){
                        rui.showStatus(res);      
                    }).always(function(){
                        closeWaiting();
                    });
                }
       });
});
  
</script>

<rdoc:include file="foot.htm" />
