<div class="hw_sendpopup_box">
  <div class="hw_sendpopup_top">
    <h3 class="fl">发送</h3>
    <a href="javascript:void(0);" class="hw_sendpopup_close fr" onclick="hideModal()"></a>
    <div class="cl"></div>
  </div>
  <div class="hw_sendpopup_con">
    <div class="hw_sendpopup_tishi">
      <p>选择的题目将被发送到班级作业</p>
    </div>
    <div class="hw_sendpopup_con_innner">
      <div class="hw_search_box mb10" >
        <input class="hw_sendpopup_search_input" id="search_course_input" value="<%= @search %>"  name="search" placeholder="输入班级名称进行搜索" type="text" >
        <span class="hw_btn_search" style="margin-top: -10px;"></span>
      </div>
      <div id="send_homework_to_course_form">
        <%= render :partial => "users/send_homework_to_course_form", :locals => {:user => user, :courses => courses, :send_id => send_id} %>
      </div>
    </div>
  </div>
</div>

<script type="text/javascript">
    //全选与取消全选
    //复选框事件
    //全选、取消全选的事件
    function selectAll() {
        if ($("#SelectAll").is(":checked")) {
            $(":checkbox").attr("checked", true);
        } else {
            $(":checkbox").attr("checked", false);
        }
    }
    //子复选框的事件
    function setSelectAll() {
        //当没有选中某个子复选框时，SelectAll取消选中
        if (!$("#subcheck").checked) {
            $("#SelectAll").attr("checked", false);
        }
        var chsub = $("input[type='checkbox'][id='subcheck']").length; //获取subcheck的个数
        var checkedsub = $("input[type='checkbox'][id='subcheck']:checked").length; //获取选中的subcheck的个数
        if (checkedsub == chsub) {
            $("#SelectAll").attr("checked", true);
        }
    }

    function send_submit() {
        var checkboxs = $("input[name='course_ids[]']:checked");
        if(checkboxs.length == 0) {
            $("#choose_courses_notice").text("请先选择班级");
        } else{
            $("#choose_courses_notice").text("");
            $("#choose_course_list_form").submit();
            hideModal();
        }
    }
    var lastSearchCondition = '';
    var count = 0;
    function search_courses(e){
        if($(e.target).val().trim() == lastSearchCondition && lastSearchCondition != '')
        {
            return;
        }
        lastSearchCondition = $(e.target).val().trim();
        $.ajax({
            url: '<%= url_for(:controller => 'users', :action => 'choose_user_course') %>'+'?search='+ e.target.value+'&homework=<%=send_id %>',
            type:'get',
            data: {is_observe:true},
            success: function(data){  },
            beforeSend: function(){ $(this).addClass('ajax-loading'); },
            complete: function(){ $(this).removeClass('ajax-loading'); }
        });
    }

    function throttle(method,context,e){
        clearTimeout(method.tId);
        method.tId=setTimeout(function(){
            method.call(context,e);
        },500);
    }

    //查询项目
    $("input[name='search']").on('input', function (e) {
        throttle(search_courses,window,e);
    });

</script>