<div class="form-body">
	    
	    <div class="row">
			<!--# $cwidth = ceil(12/$nr_column); $nr_peer_col = ceil($nr_field/$nr_column); $idx=0;  for($i=0; $i<$nr_column; $i++) { #-->
			<div class="col-xs-$cwidth col-sm-$cwidth col-md-$cwidth col-lg-$cwidth">
			<!--# for($j=0; $j<$nr_peer_col; $j++) { $v=$fdb[$idx++]; #-->
			<div class="form-group">
		        <label class="control-label col-lg-4 col-md-4 col-sm-4 col-xs-4" title="$v[description]"> $v[title]
		             <!--# if ($v['required'] == 'true') { #-->
				    <span class="required"> * </span>
				    <!--# } if ($v['comment']) { #-->
                    <span>                            
                        <i class="fa  fa-question-circle  tooltips" 
                            data-style="default" data-placement="bottom" 
                            data-container="body" data-original-title="$v[comment]"></i>                            
                    </span>
                   <!--# } #-->                               
		        </label>
		        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 $v[clickedit]" data-fieldname="$v[name]" data-modname="$modname" data-baseurl="$_base" data-dlg='$_dlg'> 
		            <span class="form-control-static"> $v[value]</span> 
                    <span class="form-control-input hidden"> $v[input] </span> 
                    <span class="clickeditbbuttonwrapper"> <button class="btn btn-xs"><i class="fa fa-edit"></i></button></span>
		        </div>
		     </div>           
			<!--# } #-->
			
			</div>
			<!--# } #-->
		</div>
		<!--# foreach($fullfdb as $key=>$v) { #-->
		 <div class="row">
            <div class="col-sm-12 col-md-12 col-lg-12">
                <div class="form-group">
		        <label class="control-label col-lg-1 col-md-1 col-sm-1 col-xs-1" title="$v[description]"> $v[title]
		             <!--# if ($v['required'] == 'true') { #-->
				    <span class="required"> * </span>
				    <!--# } if ($v['comment']) { #-->
                    <span>                            
                        <i class="fa  fa-question-circle  tooltips" 
                            data-style="default" data-placement="bottom" 
                            data-container="body" data-original-title="$v[comment]"></i>                            
                    </span>
                   <!--# } #-->                               
		        </label>
		        <div class="col-md-10 $v[clickedit]" data-fieldname="$v[name]" data-modname="$modname" data-baseurl="$_base" data-dlg='$_dlg'> 
		            <span class="form-control-static"> $v[value]</span> 
                    <span class="form-control-input hidden"> $v[input] </span> 
                    <span class="clickeditbbuttonwrapper"> <button class="btn btn-xs"><i class="fa fa-edit"></i></button></span>
		        </div>
		     </div> 
			
			</div>
        </div>
		<!--# } #-->
		
	</div>


<script language="javascript">
     
    
    
jQuery(document).ready(function() {

    $('#btnClose').on("click", function(e){
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭  
    });  

    //dlg
    if ($dlg) {
        parent.$(".layui-layer-title")[0].innerText = '$sys_position';//'$mi18n[modelname]$str_task';    
    }
    
    
    var doSubmit=function(form) {
        if (typeof CKEDITOR != "undefined") { //CKEDITOR提交空值 ？？
            for ( instance in CKEDITOR.instances )
                CKEDITOR.instances[instance].updateElement(); 
        }

       var  formData = $(form).serializeArray();
       
       $.post(form.action, formData, function(res) {
            rui.showStatus(res);
        }).fail(function(res){
              rui.showStatus(res);  
        });
    }

	$('#$table_id').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: {
                <!--# foreach($fields as $key=>$v) { if (!$v['edit']) continue; #-->
                    'params[$key]': {
                        required: $v[required]
                    },
                <!--# } #-->
                },

                messages: {
                <!--# foreach($fields as $key=>$v) { if (!$v['edit']) continue; #-->
                    'params[$key]': {
                        required: "$key 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) {
                    doSubmit(form);
                }
            });    
            

            var doTmiLinkButton = function(el, url)
            {
                var id = "$id";
                
                url += '?id='+id;
                rui.redirect(url);
                return true;
            }

            

            var doTmiLinkSubmit = function(el, url)
            {
                var msg = el.attr('msg');
                var name = el.attr('data-name');
                var id = el.attr('data-id');

                if (_.isString(msg) && msg != '') {
                    bootbox.confirm(msg, function(result) {
                        if (result) {
                           $.post(url, {id:id}, function(res) {
                                if (res.status == 0) {
                                    rui.showStatus(res);
                                   //console.log(res.data);
                                   if (!_.isUndefined(res.data.refresh)) {
                                       rui.refresh(1); 
                                   }
                                   if (!_.isUndefined(res.data.redirect)) {
                                       rui.redirect(res.data.redirect); 
                                   }
                                    
                                   //rui.refresh(1);         
                                    //parent refresh
                                   if (_.isFunction(parent.reload)) {
                                        parent.reload();
                                    } 
                                    if (name == 'del') {
                                        $('.tmilink').hide(); 
                                    } else {
                                        rui.refresh(1);
                                    }
                                } else {
                                     rui.showStatus(res);
                                }
                            })
                            .fail(function(res) { 
                                  rui.showStatus(res);
                            });
                        }
                    });
                } else {
                    $.post(url, {id:id}, function(res) {
                        if (res.status >= 0) {
                          rui.showStatus(res);
                           rui.refresh(1);
                        } else {
                            rui.showStatus(res);
                        }
                    })
                    .fail(function(res) { 
                         rui.showStatus(res);
                    });                    
                }
                
                return true;
            }
            
            var showTmbox = function(el, url)
            {
                var title = el.attr("title");
                if (_.isUndefined(title))
                    title = "详细";

                if (url.indexOf('?') < 0) // eg : '/files/file/download'
                     url += '?';
                else if (url.charAt(url.length-1) !== '&') // eg : '/files/file/download?file=a.jpg'
                    url += '&';

                url +='dlg=1&';


                
                
                top.layer.open({
                    type: 2, 
                    title: title, 
                        shadeClose: false,
                        maxmin:true,
                        shade: 0.2,
                        shift:10,
                        area: ['70%', '65%'],
                        content: url
                });
           }
           

            $('.tmilink').on('click', function(e) {
                var el = $(this);
                e.preventDefault(); 
                var url = el.attr('href');
                var action = el.attr('action');
                //console.log(action);
                if (action == 'alink') {
                    rui.redirect(url);
                    return true;
                }  
                
                
                if (action == 'linkbutton') {
                    res = doTmiLinkButton(el, url);
                    return true;
                } else if (action == 'submit' || action == 'button') {
                    res = doTmiLinkSubmit(el, url);
                }  else if (action == 'tmbox') {
                    res = showTmbox(el, url);
                    return true;
                } else {
                    rui.redirect(url);
                    return true;
                }

                return true;
            });  

            //clickedit
            $('.clickedit2 .clickeditbbuttonwrapper2').on('click', function(e){
                var elPanel = $(this).closest('.clickedit');
                var fieldname = elPanel.data('id');

                var elStaticSpan = elPanel.find('.form-control-static');
                var elInputSpan = elPanel.find('.form-control-input');
                var elClickeditButtonSpan = $(this);
                elClickeditButtonSpan.addClass('hidden');

                var oldval = elStaticSpan.html().trim();
                elStaticSpan.hide();

                elInputSpan.removeClass('hidden');
                elInputSpan.show();

                var elInput = $('#param_'+fieldname, elInputSpan);
                elInput.focus();


                var resetStatic = function (newval) {
                    elStaticSpan.show();
                    elInputSpan.hide();
                    elClickeditButtonSpan.removeClass('hidden');
                    elInput.off();
                }

                elInput.on('blur', function(e){
                    resetStatic();
                });

                elInput.on('change', function(e){
                    var newval = $(this).val();

                    resetStatic();

                    var id = "$id";
                    var url = '$_base/clickedit?id='+id;
                    $.post(url, {id:id,modname:'$modname', field:fieldname,value:newval}, function(res) {
                        if (res.status >= 0) {
                           //rui.showSuccess('操作成功.'); 
                           if ( fieldname == 'id') {
                                rui.redirect('$_base/detail?id='+newval);
                            } else {
                                rui.refresh();
                            }
                           if (_.isFunction(parent.reload))
                                parent.reload();
                        } else {
                             rui.showStatus(res);
                        }
                    })
                    .fail(function(res) { 
                          rui.showStatus(res);
                    });
                });
            });
});

jQuery(document).ready(function() {
	$.fn.select2.defaults.set("theme", "bootstrap");
    var placeholder = "请选择";
    $(".select2me, .select2-multiple").select2({
        placeholder: placeholder,
        width: null,
    });
});
    
</script>
