Jquery saves selected user _ jquery

Source: Internet
Author: User
This article describes how to save selected users by using jquery. For more information, see section 1.

Functional requirements:

1. Select the user interface and display it in a pop-up box.

2. Dynamic Loading of page options (department and user)

3. Save the selected user

Implementation Analysis:

Save the selected user logic:

Delete the previously selected user record list (equivalent to clearing)
Add a list of newly selected user records
Page

1. Save shared files

// Save the shared file function using file () {// parameter var signid = chooseObj. id; var objtype = chooseObj. type; var userlist = ""; $ ("input [name = Your userid]"). each (function () {// this is the checkbox object in the html. So through // this. if ($ (this ). attr ('checked') {userlist = userlist + $ (this ). val () + ","}); if (userlist. length> 0) {userlist = userlist. substring (0, userlist. length-1)} $. ajax ({url :'.. /share/upload file. do ', // url:' $ {ctx}/index. jsp ', cache: false, type: 'post', ype: '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 your own"); return;} else if (ret = 2) {handleWarm ("sub-directories cannot be moved"); return ;}// closeflowcontent ('fxcontentflow'); refreshThisContent ();}})}

Html reference of page option content (for reference only, no need to implement)

School leader

  • Xiao Lin
  • Wang Shuo
  • Wang shengyang
  • Qi Feng
  • Tang Yiwen
  • Zhang Lisheng
  • Zheng

Office

  • Lu Jianping
  • Guo shunlan
  • Fang Ying
  • Jiao Xiaojun
  • Song weilei
  • Zhang Xinmin
  • Li Jing
  • Wang Kaiyu

Background code
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();     }         } 

Service Layer

/*** Specify shared files and folders ** @ param signid folder id/file id * @ param objtype operation object type (1: file, 2: folder) * @ param userlist shared user range * @ return 0 indicates operation failed/1 indicates operation succeeded **/public int shareFile (String signid, String objtype, String userlist, String sharer) {// Delete the shared record fileShareDao. deleteFileshare (signid, objtype); // create a 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. setincluuser (users [I]); wpFileshare. setSharetime (new Date (); fileShareDao. saveFileshare (wpFileshare );}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.