General function and Module customization system (CFCMMS)-030 Development log (create Manytomany column5)

Source: Internet
Author: User

030 Development Log (Create Manytomany's Column5)
Now for this field, there is one last function, that is, you can modify the value of the Manytomany. In the inline operation of the grid, it is possible to delete the existing value directly, but if you want to add it, you have to have a new interface.  Here's a look at the steps required to develop a modified manytomany field. 1, create a modification window, create a check in the inside of the tree; 2. Request data in the background, read all the Manytomany options for the current record, and tick the checked tab; 3. Update the tree according to the data read; 4. User operation check and uncheck; 5? Save the changes, use AJAX to send the modified manytomany to the background, to perform the Save function; 6. Refreshes the current record and displays the correct manytomany value.
As you can see in the above steps, this is the way to modify all of the Manytomany fields. The difficulty in the above steps is how to generate all the options for the manytomany of the record according to the request of the foreground and check the checked tick, and save the modified value.  For this system, all methods are as common as possible, so some functions are difficult to develop.  In the 2nd step operation, the foreground should be passed to the background parameters should have: The current module name, the current record Id,manytomany module name, the name of the intermediate module. Also, in the 5th step, pass the parameters to the 2nd step in the background, plus the values of all currently selected Manytomany.
Follow the manytomanycolumn.js in the previous section to modify what you want to do when the user clicks the Modify button.
Processevent:function (type, view, cell, Recordindex, CellIndex, E,record, row) {var me = this;if (type = = = ' click ') {var module = this.up (' Modulegrid '). Module;if (E.gettarget (). ClassName = = ' Manytomanycontext ') { App.modules.showModuleRecord (This.manytomanymodulename, E.gettarget (). getattribute (' _id '));} else if (Ext.String.startsWith (E.gettarget (). ClassName, ' Manytomanycontextclose ')) {//Click the Delete button to first locate the previous node,  It contains the information to be deleted var target = E.gettarget (). Previouselementsibling;var Text = module.tf_title + "+ record.gettitletpl () +" ' + this.manytomanymoduletitle + ' "' + target.innerhtml + '"; Ext.MessageBox.confirm (' OK to delete ', ' OK to delete ' + text + '? ', function (BTN) {if (btn = = ' yes ') {/////Use the module to delete bulk AjaxExt.Ajax.req Uest ({url: ' rest/module/removerecords.do ', params: {modulename:me.fielddefine.tf_jointable,ids: Target.getattribute (' _joinid '), titles:target.innerhtml},success:function (response) {var info = Ext.decode ( Response.responsetext, True); if (Info.resultcode = = 0) {ext.toastinfo (teXT + ' has been successfully deleted. ///delete the record and refresh the current record me.up (' Modulegrid '). Refreshselectedrecord (); else {Ext.MessageBox.show ({title: ' Delete result ', Msg:text + ' delete failed:<br/><br/> ' + info.errormessagelist,buttons: Ext.messagebox.ok,icon:ext.messagebox.error});}},failure:function () {Window.alert (' The server returns an error when deleted);}})});} else if (Ext.String.startsWith (E.gettarget (). ClassName, ' Manytomanyedit ')) {//Edit the Manytomany field of the current record; Ext.widget (' Manytomanyeditwindow ', {grid:me.up (' Modulegrid '), Title:module.tf_title + ' "' + record.gettitletpl () + '" The ' + This.manytomanymoduletitle,modulename:module.tf_modulename,idvalue:record.getidvalue (), ManyToManyModuleName : Me.manytomanymodulename,linkmodulename:me.fielddefine.tf_jointable}). Show ();}}}

As you can see in the code above, if you click the Modify button, you will create a manytomanyeditwindow. Complete the 6-step procedure above in this window.
/** * Modify the Record's Manytomany field window, complete the selection operation in the window, and save it. */ext.define (' App.module.widget.window.ManyToManyEditWindow ', {extend: ' Ext.window.Window ', alias: ' Widget.manytomanyeditwindow ', requires: [' App.lib.CheckTreePanel '],width:450,height:600,modal:true,maximizable:t Rue,layout: ' Fit ', buttons: [', ', {text: ' Save ', Iconcls: ' FA fa-save ', handler:function (button) {var window = Butto N.up (' window '); var tree = Window.down (' Treepanel '); var selected = []tree.getrootnode (). Cascadeby (function (node) {// The value of all selected Manytomany if (node.data.checked = = True && Node.data.leaf = = True) {Selected.push (Node.data.fieldvalue) ;}});/ /submit Ajax Request Background modification Ext.Ajax.request ({url: ' modulemanytomany/setmanytomanydetail.do ', params: {modulename: Window.modulename,id:window.idvalue,manytomanymodulename:window.manytomanymodulename,linkmodulename: Window.linkmodulename,selected:selected.join (', ')},success:function (response) {var info = Ext.decode ( Response.responsetext, True); if (info.success) {Ext.toaStinfo (window.titlemess + ' saved. '); Window.grid.refreshSelectedRecord (); Window.close ();} Elseext.toasterror (window.titlemess + ' save failed. <br> ' + ' cause: ' + Info.msg}}}}, {text: ' Off ', Iconcls: ' FA fa-close ', handler:function (button) {button.up (' window ' ). Close ();}, '],initcomponent:function () {var me = this;this.titlemess = This.title;this.title = ' Settings ' + this.ti Tlemess;this.items = [{xtype: ' Checktreepanel ', Autoload:false,rootvisible:false,root: {},store:ext.create (' Ext.da Ta. Treestore ', {proxy: {type: ' ajax ', url: ' modulemanytomany/getmanytomanydetail.do ', Extraparams: {moduleName:me.module Name,id:me.idvalue,manytomanymodulename:me.manytomanymodulename,linkmodulename:me.linkmodulename}})}]; This.callparent (arguments);}})

This is the front-end interface operation code, then the background to deal with the above mentioned 2nd, 5th step. A new controller class is required to receive AJAX requests. The following is the control class:
Package Com.jfok.cfcmms.controller;import Java.util.list;import Javax.annotation.resource;import Javax.servlet.http.httpservletrequest;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.bind.annotation.responsebody;import Com.jfok.cfcmms.service.ModuleManyToManyService; Import Com.jfok.cfcmms.share.treenoderecordchecked;import com.jfok.cfcmms.util.actionresult;/** * The Manytomany data used to manage the module is saved as read and modified * * @author Jiangfeng * * 2016-01-11 * */@Controller @requestmapping ("/modulemanytoma  NY ") public class Modulemanytomanycontroller {@Resource private modulemanytomanyservice modulemanytomanyservice; /** * * @param request * @param modulename * Current module name * @param ID * Current Record ID * @param manytom Anymodulename * Manytomany Module name * @param linkmodulename * Intermediate Module name * @return return all Manytomanymodulen AME records the data and checked the current record of the existing Manytomany value to true */@RequestMApping ("/getmanytomanydetail.do") public @ResponseBody list<treenoderecordchecked> Genmanytomanydetail ( HttpServletRequest request, String modulename, String ID, String manytomanymodulename, String linkmodulename) {RE  Turn modulemanytomanyservice.getmanytomanydetail (request, ModuleName, ID, manytomanymodulename, linkmodulename); }/** * * @param request * @param modulename * Current module name * @param ID * Current Record ID * @param many          Tomanymodulename * Manytomany Module name * @param linkmodulename * Intermediate Module name * @param selected * All selected values, separated by commas * @return return all Manytomanymodulename record data and set the checked of the Manytomany value that is currently logged to True */@RequestMapping ("/setma Nytomanydetail.do ") Public @ResponseBody ActionResult Setmanytomanydetail (httpservletrequest request, String Modulen AME, string ID, String manytomanymodulename, String linkmodulename, String selected) {return Modulemanytomanyserv Ice.setmanytomanydetail (Request, ModuLename, ID, manytomanymodulename, linkmodulename, Selected.split (",")); }}

The last one is the service class that is used to process the request, and this class is the key to this function. It is up to him to complete all the similar Manytomany fields in the system to read and modify the operation.
Package Com.jfok.cfcmms.service;import Java.util.arraylist;import Java.util.list;import Javax.annotation.Resource; Import Javax.servlet.http.httpservletrequest;import Org.springframework.stereotype.service;import Org.springframework.transaction.annotation.propagation;import Org.springframework.transaction.annotation.transactional;import Com.jfok.cfcmms.dao.moduledao;import Com.jfok.cfcmms.dao.systembasedao;import Com.jfok.cfcmms.core.module.sqlgenerator;import Com.jfok.cfcmms.core.module.sqlmodulefilter;import Com.jfok.cfcmms.hibernate.system.module._module;import Com.jfok.cfcmms.share.treenoderecord;import Com.jfok.cfcmms.share.treenoderecordchecked;import Com.jfok.cfcmms.share.valuetext;import Com.jfok.cfcmms.util.actionresult;import Net.sf.json.JSONArray;import  Net.sf.json.JSONObject; @Servicepublic class Modulemanytomanyservice {@Resource private Systembasedao Systembasedao;  @Resource private Moduledao Moduledao;  @Resource private ModuleService ModuleService; /** * * @paRAM Request * @param modulename * Current module name * @param ID * Current Record ID * @param manytomanymodulename * Manytomany Module Name * @param linkmodulename * Intermediate Module name * @return returns all Manytomanymodulename record data, and the current record has been Some checked of manytomany values are set to True */@Transactional (propagation = propagation.required, readOnly = true) public List<tree Noderecordchecked> Getmanytomanydetail (httpservletrequest request, String modulename, String ID, String manytomany    ModuleName, String linkmodulename) {_module Module = Systemandlogininfoservice.getmodulewithname (modulename);    _module manytomanymodule = Systemandlogininfoservice.getmodulewithname (manytomanymodulename);    list<treenoderecord> result = new arraylist<treenoderecord> (); First read all the permissions in the Manytomanymodulename visible range of data list<valuetext> Alltreeitems =    Moduledao.getmodulewithcombodatawithquery (manytomanymodulename, NULL, request); for (ValueText vt:alltreeitems) {Treenoderecordchecked record = new treenoderecordchecked ();      Record.setfieldvalue (Vt.getvalue ());      Record.settext (Vt.gettext ());      Record.setleaf (TRUE);    Result.add (record); }//Read the Manytomany value of the current ID in linkmodulename, list<sqlmodulefilter> filters = new Arraylist<sqlmodulefi within the data visual Weizhou    Lter> ();    Sqlmodulefilter moduleidfilter = new Sqlmodulefilter ();    Moduleidfilter.setmodulename (Module.gettf_modulename ());    Moduleidfilter.settableasname (Module.gettableasname ());    Moduleidfilter.setprimarykey (Module.gettf_primarykey ());    Moduleidfilter.setequalsvalue (ID);    Filters.add (Moduleidfilter);    Sqlgenerator generator = new Sqlgenerator (linkmodulename, request);    Generator.setmodulefilters (filters);    Jsonarray DataArray = Moduledao.getdata (generator,-1, 0); Generate treenoderecordchecked and add checked flag for (int i = 0; i < dataarray.size (); i++) {String Manytomanyid = data Array.getjsonobject (i). GetString (Manytomanymodule.gettableasname() + "___" + Manytomanymodule.gettf_primarykey ()); for (Treenoderecord Record:result) {if (Record.getfieldvalue (). Equals (Manytomanyid)) ((TREENODERECORDCH      ecked). Setchecked (True);    }}//Returns the result list<treenoderecordchecked> root = new arraylist<treenoderecordchecked> ();    treenoderecordchecked Rootrecord = new treenoderecordchecked ();    Rootrecord.settext (Manytomanymodule.gettf_title ());    Rootrecord.setchildren (result);    Rootrecord.setexpanded (TRUE);    Root.add (Rootrecord);  return root; Public ActionResult Setmanytomanydetail (httpservletrequest request, String modulename, String ID, String Manytoman Ymodulename, String linkmodulename, string[] selected) {_module Module = Systemandlogininfoservice.getmodulewithname (M    Odulename);    _module manytomanymodule = Systemandlogininfoservice.getmodulewithname (manytomanymodulename);    _module linkedmodule = Systemandlogininfoservice.getmodulewithname (linkmodulename); //Read the Manytomany value of the current ID in linkmodulename list<sqlmodulefilter> filters = new arraylist< within the data visual Weizhou    Sqlmodulefilter> ();    Sqlmodulefilter moduleidfilter = new Sqlmodulefilter ();    Moduleidfilter.setmodulename (Module.gettf_modulename ());    Moduleidfilter.settableasname (Module.gettableasname ());    Moduleidfilter.setprimarykey (Module.gettf_primarykey ());    Moduleidfilter.setequalsvalue (ID);    Filters.add (Moduleidfilter);    Sqlgenerator generator = new Sqlgenerator (linkmodulename, request);    Generator.setmodulefilters (filters);    Jsonarray DataArray = Moduledao.getdata (generator,-1, 0); If there is, now there is no selected inside, then it is necessary to delete the for (int i = 0; i < dataarray.size (); i++) {String Manytomanyid = dataarray.g      Etjsonobject (i). GetString (Manytomanymodule.gettableasname () + "___" + Manytomanymodule.gettf_primarykey ());      Boolean isfound = false;      for (String selectedid:selected) {if (Manytomanyid.equals (Selectedid)) {Isfound = true;    Break }} if (!isfound) {//need to delete this manytomany, call the system service remove, will determine whether the logic can be deleted, will be recorded in the Log//have not done wrong handling Modu Leservice.remove (Linkmodulename, Dataarray.getjsonobject (i). GetString (Linkedmodule.gettf_primarykey ()), request      );         }}//If not, now selected inside, then add in for (String selectedid:selected) {if (selectedid.length () > 0) {        Boolean isfound = false;              for (int i = 0; i < dataarray.size (); i++) {String Manytomanyid = Dataarray.getjsonobject (i). GetString (          Manytomanymodule.gettableasname () + "___" + Manytomanymodule.gettf_primarykey ());            if (Manytomanyid.equals (Selectedid)) {Isfound = true;          Break          }} if (!isfound) {Jsonobject object = new Jsonobject (); Object.put (Manytomanymodule.gettableasname () + "___" + manytomanymodule.gettf_primarykey (), SEL          Ectedid); Object.put (Module.gettaBleasname () + "___" + Module.gettf_primarykey (), id); Need to add this manytomany, call system service Add, will determine whether can add logic, will be recorded in the Log//has not been made error handling Moduleservice.add (Linkmodulename, Obje        Ct.tostring (), request);    }}} ActionResult result = new ActionResult ();  return result; }}

After the work of the above code, we can open the person's Set permissions window to set permissions.

Modify some user action roles, and then save.

The user's Manytomany field action role modification is complete.
The user is also a manytomany field for the action role, which is also true for this operation.

At this point the definition, display, and operation of the Manytomany field are basically complete.

Advanced assumptions: Improvements to tree selection. In my present system, in the user module, there is a button to set permissions, in fact, the completion of the Manytomany field selection and save, with this field function, this set the permissions of the button can not be. But one thing is not the same, look at the following:
In the tree of the Select Roles window, the roles are grouped by role groupings, so that they are more intuitive to choose from. The selection tree of the Manytomany field will also be made into a structure that can be configured as such.  Here I generally first write about the idea: 1? A new configuration field is added to the module configuration: Manytomany The tree module path at the time of selection, 2, when a module is selected as the Manytomany field, reads its module path and then adds the value of the current module below the corresponding node.  For example, for a character to select a person, the department can be used as the module path of the person, so that in the selection tree, first the value of the department, and then the staff will hang in the appropriate departments to choose. (This function has time to do again later)

General function and Module customization system (CFCMMS)-030 Development log (create Manytomany column5)

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.