Home > Web Front-end > JS Tutorial > jquery implements saving selected users_jquery

jquery implements saving selected users_jquery

WBOY
Release: 2016-05-16 16:41:37
Original
1566 people have browsed it

1 Introduction

Feature Requests:

1 Select the user interface to be displayed as a pop-up box

2 Dynamic loading of page options (department and user)

3 Save checked users

Implementation analysis:

Save selected user logic:

Delete the originally selected user record list (equivalent to clearing operation)
Add new selected user record list
Page

1 Save shared file

// 保存共享文件
  function shareFile(){
    // 参数
    var signid = chooseObj.id;
    var objtype = chooseObj.type;
    var userlist = "";
    $("input[name=shareUserId]").each(function(){
       // 此时的this 就是那个 html中的 那个checkbox对象。所以通过
       // this.checked 直接访问属性都是可以的 
       if($(this).attr('checked')){
         userlist = userlist+$(this).val()+","
       }
    });
    if(userlist.length>0){
      userlist = userlist.substring(0, userlist.length-1)
    }
    $.ajax({
      url : '../share/shareFile.do',
      //url:'${ctx}/index.jsp',
      cache : false,
      type : 'post',
      dataType : 'html',
      async : false,
      contentType : "application/x-www-form-urlencoded;charset=utf-8",
      data : {
        'signid' : signid,
        'objtype' : objtype,
        'userlist':userlist
      },
      success : function(ret) {
        // 异常处理
        if(ret==3){
          handleWarm("目标文件夹是自己"); 
          return;
        }else if(ret==2){
          handleWarm("不能移动至子目录"); 
          return;
        } 
        // closeflowcontent('fxcontentflow');
        refreshThisContent();
      }
    })
  }

Copy after login

Page option content html reference (for reference only, no need to implement)

<div class="fxtitle">院领导</div>
  <ul class="fxxz">
    <li><input type="checkbox" name="shareUserId" value="xiaolin">肖林 </li>
    <li><input type="checkbox" name="shareUserId"
      value="wangshuotong">王硕佟 </li>
    <li><input type="checkbox" name="shareUserId"
      value="wangshengyang">汪胜洋 </li>
    <li><input type="checkbox" name="shareUserId" value="qifeng">齐峰 </li>
    <li><input type="checkbox" name="shareUserId" value="tangyiwen">唐忆文 </li>
    <li><input type="checkbox" name="shareUserId"
      value="zhanglisheng">张利生 </li>
    <li><input type="checkbox" name="shareUserId" value="zhengshao">郑韶 </li>
  </ul>
  <div class="fxtitle">办公室</div>
  <ul class="fxxz">
    <li><input type="checkbox" name="shareUserId" value="lujianping">陆建平 </li>
    <li><input type="checkbox" checked="true" name="shareUserId"
      value="guoshunlan">郭顺兰 </li>
    <li><input type="checkbox" name="shareUserId" value="fangying">方颖 </li>
    <li><input type="checkbox" name="shareUserId" value="jiaoxiaojun">焦晓君 </li>
    <li><input type="checkbox" checked="true" name="shareUserId"
      value="songweilei">宋维蕾 </li>
    <li><input type="checkbox" name="shareUserId" value="zhangxinmin">张新民 </li>
    <li><input type="checkbox" checked="true" name="shareUserId"
      value="lijing">李靖 </li>
    <li><input type="checkbox" name="shareUserId" value="wangkaiyu">王开宇 </li>
  </ul>
Copy after login

Backend code
controller layer

public void shareFile(HttpServletRequest request,HttpServletResponse response) { 
    
    String signid = request.getParameter("signid") == null&#63; "": request.getParameter("signid"); 
    String objtype = request.getParameter("objtype") == null&#63; "": request.getParameter("objtype"); 
    String userlist = request.getParameter("userlist") == null&#63;"": request.getParameter("userlist"); 
    User user = (User)request.getSession().getAttribute("user"); 
      
    int result = fileShareManager.shareFile(signid, objtype, userlist, user.getUserid().getValue()); 
    try{ 
      request.setCharacterEncoding("UTF-8"); 
      PrintWriter pw = response.getWriter();  
      pw.write("" + result); 
      pw.flush(); 
      pw.close(); 
    }catch (Exception e) { 
      // TODO: handle exception 
      e.printStackTrace(); 
    } 
      
  } 

Copy after login

service layer

/** 
   * 指定共享文件、文件夹 
   * 
   * @param signid 文件夹id/文件id      
   * @param objtype 操作对象类型(1:file、2:folder) 
   * @param userlist 分享用户范围 
   * @return 0表示操作失败/1表示操作成功 
   * 
   */ 
  public int shareFile(String signid, String objtype, String userlist, String sharer) { 
    // 删除共享记录 
    fileShareDao.deleteFileshare(signid, objtype);    
    // 新建共享记录 
    String users[] = userlist.split(","); 
    
    // 保存每一个共享用户 
    for (int i = 0; i < users.length && !users[0].equals(""); i++) { 
        WpFileshare wpFileshare = new WpFileshare();       
        wpFileshare.setSharer(sharer); 
        wpFileshare.setShareuser(users[i]);  
        wpFileshare.setSharetime(new Date()); 
        fileShareDao.saveFileshare(wpFileshare); 
    } 
  } 
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template