The jquery implementation saves the selected user

  • 2020-03-30 03:33:14
  • OfStack

1 introduction

Functional requirements:

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

2 page options dynamic loading (departments and users)

Save the checked user

Implementation analysis:

Save selected user logic:

Delete the previously selected list of user records (equivalent to an empty operation)
Adds a list of newly selected user records
page

  Save the Shared file


//Save the Shared file
  function shareFile(){
    //  parameter 
    var signid = chooseObj.id;
    var objtype = chooseObj.type;
    var userlist = "";
    $("input[name=shareUserId]").each(function(){
       //This is the checkbox object in that HTML. So through
       //It is ok to directly access the properties of 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) {
        //Exception handling
        if(ret==3){
          handleWarm(" The target folder is itself "); 
          return;
        }else if(ret==2){
          handleWarm(" Cannot move to subdirectory "); 
          return;
        } 
        // closeflowcontent('fxcontentflow');
        refreshThisContent();
      }
    })
  }

Page options content HTML reference (for reference only, no implementation required)


<div class="fxtitle"> School leadership </div>
  <ul class="fxxz">
    <li><input type="checkbox" name="shareUserId" value="xiaolin"> chorin  </li>
    <li><input type="checkbox" name="shareUserId"
      value="wangshuotong"> Wang shuo tong  </li>
    <li><input type="checkbox" name="shareUserId"
      value="wangshengyang"> Wang Shengyang  </li>
    <li><input type="checkbox" name="shareUserId" value="qifeng"> qifeng  </li>
    <li><input type="checkbox" name="shareUserId" value="tangyiwen"> Tang Yiwen  </li>
    <li><input type="checkbox" name="shareUserId"
      value="zhanglisheng"> li  </li>
    <li><input type="checkbox" name="shareUserId" value="zhengshao"> Zheng Shao  </li>
  </ul>
  <div class="fxtitle"> The office </div>
  <ul class="fxxz">
    <li><input type="checkbox" name="shareUserId" value="lujianping"> Miller ab.hoogstraten b  </li>
    <li><input type="checkbox" checked="true" name="shareUserId"
      value="guoshunlan"> Guo Shunlan  </li>
    <li><input type="checkbox" name="shareUserId" value="fangying"> coolio  </li>
    <li><input type="checkbox" name="shareUserId" value="jiaoxiaojun"> JiaoXiaoJun  </li>
    <li><input type="checkbox" checked="true" name="shareUserId"
      value="songweilei"> Song Weilei  </li>
    <li><input type="checkbox" name="shareUserId" value="zhangxinmin"> Zhang xinming  </li>
    <li><input type="checkbox" checked="true" name="shareUserId"
      value="lijing"> excavate  </li>
    <li><input type="checkbox" name="shareUserId" value="wangkaiyu"> Kai-yu wang  </li>
  </ul>

The background code
The controller layer


public void shareFile(HttpServletRequest request,HttpServletResponse response) { 
    
    String signid = request.getParameter("signid") == null? "": request.getParameter("signid"); 
    String objtype = request.getParameter("objtype") == null? "": request.getParameter("objtype"); 
    String userlist = request.getParameter("userlist") == null?"": 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(); 
    } 
      
  } 

The service layer


/** 
   *  Specify Shared files, folders  
   * 
   * @param signid  folder id/ file id      
   * @param objtype  Operation object type ( 1:file , 2 : folder )  
   * @param userlist  Share user scope  
   * @return 0 Operation failure /1 Indicates successful operation  
   * 
   */ 
  public int shareFile(String signid, String objtype, String userlist, String sharer) { 
    //Delete Shared records
    fileShareDao.deleteFileshare(signid, objtype);    
    //New Shared record
    String users[] = userlist.split(","); 
    
    //Save each Shared user
    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); 
    } 
  } 


Related articles: