SHARE
TWEET

Untitled

a guest Aug 14th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     handleAdvCheckboxChange = (event) => {
  2.         var checkname = event.target.name;
  3.         var checked = event.target.checked;
  4.         this.setState({[checkname]: checked}, () =>{
  5.             if(checkname == 'advancedcheck'){ //first advanced checkbox, not second one "AND"
  6.                 if(checked){ //the checkbox has just been checked
  7.                     this.setState({'advQueryTypes':this.advQueryTypes, 'advancedquery':this.advQueryTypes[0]}, () => {
  8.                         console.log("advancedquery: " + this.state.advancedquery);
  9.                         this.updateSpecificQuery(this.state.advancedquery, 'specificQueryTypes', 'specificquery', '', ''); //update specific query 1
  10.                     });
  11.                 }
  12.                 else{
  13.                     this.setState({advancedcheck2: false, advQueryTypes:[], specificQueryTypes: [], advQueryTypes2:[], specificQueryTypes2:[]});
  14.                 }
  15.             }
  16.             else{
  17.                 if(checked){ //second advanced check box just checked
  18.                     this.updateAdvQuery2();
  19.                 }
  20.                 else{
  21.                     this.setState({advQueryTypes2:[], specificQueryTypes2:[]});
  22.                 }  
  23.             }
  24.         });
  25.     }
  26.  
  27.     advQueryChange = (event) => {
  28.         var eventname = event.target.name;
  29.         this.setState({[eventname]: event.target.value}, () =>{
  30.             if(eventname == 'advancedquery'){
  31.                 this.updateSpecificQuery(this.state.advancedquery, 'specificQueryTypes', 'specificquery');
  32.                 console.log("updating adv2");
  33.                 this.updateAdvQuery2();
  34.                
  35.             }
  36.             else{
  37.                 this.updateSpecificQuery(this.state.advancedquery2, 'specificQueryTypes2', 'specificquery2', this.state.advancedquery, this.state.specificquery);      
  38.             }
  39.            
  40.         });
  41.     }
  42.  
  43.     specificQueryChange = (event) => {
  44.         this.setState({[event.target.name]: event.target.value}, () =>{
  45.             if(this.state.advancedcheck2){
  46.                 this.updateSpecificQuery(this.state.advancedquery2, 'specificQueryTypes2', 'specificquery2', this.state.advancedquery, this.state.specificquery);
  47.             }
  48.         });
  49.     }
  50.  
  51.     //This function handles updating specific query 1 and 2
  52.     // col: the advanced query selector to be pulled from
  53.     // whichspecific: the corresponding selector array to change and populate
  54.     // querytoset: the actual selector element to change to the initial value
  55.     updateSpecificQuery(col, whichspecific, querytoset, oldcol, otherquery){
  56.         fetch('/getadvanced',{
  57.             method: 'POST',
  58.             headers: {
  59.                 'Accept': 'application/json',
  60.                 'Content-Type': 'application/json',
  61.             },
  62.             body: JSON.stringify({
  63.                 origquery: this.state.querytype,
  64.                 col: col, //advanced query
  65.                 rehash: this.state.rehash,
  66.                 fromdate: this.state.fromdate,
  67.                 todate: this.state.todate,
  68.                 oldcol: oldcol,
  69.                 otherquery: otherquery
  70.             })
  71.         })
  72.         .then((res) => res.json())
  73.         .then((result) => {
  74.             console.log("result: " + JSON.stringify(result));
  75.             this.setState({[whichspecific]:result.data, [querytoset]:result.data[0]});
  76.         })
  77.         .catch((error) => {
  78.             console.error(error);
  79.         })
  80.     }
  81.  
  82.  
  83.     //When either the advanced check or advanced query 1 are changed, this should update
  84.     updateAdvQuery2(){
  85.         //remove whichever advanced query is selected in the first advanced section from the array of options
  86.         var adjustedQueryTypes = this.advQueryTypes.filter((value, index, arr) =>{
  87.             return value != this.state.advancedquery;
  88.         });
  89.         this.setState({'advQueryTypes2':adjustedQueryTypes, 'advancedquery2':adjustedQueryTypes[0]}, () => {
  90.             console.log("advancedquery2: " + this.state.advancedquery2);
  91.             this.updateSpecificQuery(this.state.advancedquery2, 'specificQueryTypes2', 'specificquery2', this.state.advancedquery, this.state.specificquery);
  92.         });
  93.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top