{% extends 'obj_form.html' %}
{% load i18n %}
{% load tj_filters %}


    {% block js %}
        {{ block.super }}
        $('.btn-save').click(function(){            
            var a=[];
            $("#sel2-company option").each(function(){
                a.push(
                    {'id':$(this).val(),
                    'name':$(this).text()
                    }
                );
            });            
            $('#id_companys_only').val(JSON.stringify(a));

            $.SubmitForm('#obj_form form','{{request.path}}');
        });  



        $('.select2_multiple').on('dblclick','option',function(){
            $(this).remove();
        });



        $('#obj_form .btn-add-company').click(function(){
            var c=$('#sel-company').val();
            var label=$('#sel-company').find("option:selected").text();
            if (c==''){
                toastr.error(label+"请先选择公司！", "操作错误：",
                        {timeOut: 800, positionClass: "toast-center-center"}
                );  
                return;
            }else{
                var e=false;
                $("#sel2-company option").each(function(){
                    if($(this).val() == c){
                        e=true;
                        return false;          
                    }
                });
                if(e){
                    toastr.error(label+"已在列表中！", "操作错误：",
                        {timeOut: 800, positionClass: "toast-center-center"}
                    );
                    return;
                }else{
                    $('#sel2-company').append("<option value='"+c+"'>"+label+"</option>");
                }            
            };
        });

    {% endblock %}   



{% block form_content %}
    {{ block.super }}    
    <div class="form-group ">
        <label class="col-sm-2 control-label ">菜单标题</label>
        <div class="col-sm-10">{{ form.title }}</div>
    </div>   

    <div class="form-group ">
        <label class="col-sm-2 control-label ">上级菜单</label>
        <div class="col-sm-10">{{form.instance.parent.title}}</div>
    </div>

    <div class="form-group ">
        <label class="col-sm-2 control-label ">菜单图标</label>
        <div class="col-sm-10">{{ form.icon }}</div>
    </div>
    
    <div class="form-group ">
        <label class="col-sm-2 control-label ">URL地址</label>
        <div class="col-sm-10">{{ form.url }}</div>
    </div>
    
    <div class="form-group ">
        <label class="col-sm-2 control-label ">顺序序号</label>
        <div class="col-sm-10">{{ form.priority }}</div>
    </div>
    <div class="form-group ">
        <label class="col-sm-2 control-label ">备注说明</label>
        <div class="col-sm-10">{{ form.remark }}</div>
    </div>

    <div class="form-group ">
        <label class="col-sm-2 control-label ">公司限定</label>
        <div class='col-md-10'>  
        <div class="input-group"> 
            <select id="sel-company" class="form-control">              
                {% for c in companys %}
                    <option value="{{c.0}}">{{c.1}}</option>
                {% endfor %}
                <option value="" selected="selected">------------------</option>
            </select>
            <span class="input-group-btn"><button type="button" class="btn btn-success btn-add-company">
                <span class='glyphicon glyphicon-arrow-down'></span></button></span>
        </div>
        </div>
    </div>

    <div class="form-group" style='margin-top:-28px;'>        
        <div class='col-sm-10 col-md-offset-2'>
            <select class="select2_multiple form-control" id='sel2-company' multiple="multiple">
                {% for o in form.instance.companys_only %}
                    <option value='{{o.id}}'>{{o.name}}</option>
                {% endfor %}   
                                  
            </select>        
        </div>       
    </div> 






    
    <div>
        <a class="btn btn-primary btn-save" type="button" style="float:right;">{% trans '保存' %}</a>
    </div>
{% endblock %}
