Advertisement
rhuntington

Balls Deep in jQ

Aug 12th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 3.66 KB | None | 0 0
  1. $("#searchform").submit((event)=> {
  2.     // declare vars outside of scopes
  3.     let param = $("#searchval").val();
  4.     let searchby = $("#searchby").val();
  5.     let charid;
  6.     let name;
  7.     let username;
  8.     let forum;
  9.     // store JSON data here
  10.     let managechar;
  11.     if(searchby == 1) {
  12.         charid = param;
  13.     } else if(searchby == 2) {
  14.         name = param;
  15.     } else if(searchby == 3) {
  16.         username = param;
  17.     } else {
  18.         forum = param;
  19.     }
  20.  
  21.     if(charid != "" && charid != null) {
  22.         function rtChar() {
  23.             return Promise.resolve($.get("data.php?charid=" + encodeURIComponent(charid), (data)=> {
  24.                 // console.log(data);
  25.             }));
  26.         }
  27.     }
  28.     if(name != "" && name != null) {
  29.         function rtChar() {
  30.             return Promise.resolve($.get("data.php?name=" + encodeURIComponent(name), (data)=> {
  31.                 // console.log(data);
  32.             }));
  33.         }
  34.     }
  35.     if(username != "" && username != null) {
  36.         function rtChar() {
  37.             return Promise.resolve($.get("data.php?username=" + encodeURIComponent(username), (data)=> {
  38.                 // console.log(data);
  39.         }));
  40.         }
  41.                 }
  42.                 if(forum != "" && forum != null) {
  43.                     function rtChar() {
  44.                         return Promise.resolve($.get("data.php?forum=" + encodeURIComponent(forum), (data)=> {
  45.                             // console.log(data);
  46.                         }));
  47.                     }
  48.                 }
  49.     let table = rtChar();
  50.     table.then((value)=>{
  51.         let data = value;
  52.         $("#resultstbl").DataTable({
  53.             destroy: true,
  54.             paging: false,
  55.             info: false,
  56.             data: data,
  57.             columns: [
  58.                 {'data': 'username'},
  59.                 {'data': 'charid'},
  60.                 {'data': 'name'},
  61.                 {'data': 'forumaccount'},
  62.                 {'data': 'firstseen'},
  63.                 {'data': 'lastseen'},
  64.                 {
  65.                     'data': null,
  66.                     render: (data)=> {
  67.                         let hours = Math.round(data.playtime / 60) + " Hours";
  68.                         return hours;
  69.                     }
  70.                 },
  71.                 {
  72.                     'data': null,
  73.                     render: (data)=> {
  74.                         // button being set in the table and assigning unique ID's to the button
  75.                         let managebtn = '<button class="btn btn-lg btn-outline-warning" id="'+data.name+'/'+data.charid+'" >Manage
  76.                         Character</button>';
  77.                         // Hint popup triggered by mouse over button event
  78.                         new jBox('Tooltip', {
  79.                             attach: '.btn-outline-warning',
  80.                             trigger: 'mouseenter',
  81.                             onCreated: function () {
  82.                                 this.setContent('Double click to manage character!');
  83.                             },
  84.                             closeOnClick: true
  85.                         });
  86.                         return managebtn;  
  87.                     }
  88.                 }
  89.             ]
  90.         });
  91.     });
  92.     function test (setID) {
  93.         $(".btn-outline-warning").click((e)=> {
  94.             setID = e.target.id;
  95.             return setID;
  96.         });
  97.     }
  98.     console.log(test());
  99.     // jQuery plugin that triggers at click of $(".btn-outline-warning")
  100.     new jBox('Modal', {
  101.         attach: '.btn-outline-warning',
  102.         trigger: 'click',
  103.         color: 'black',
  104.         animation: 'flip',
  105.         closeButton: 'title',
  106.         onCreated: function () {
  107.             /*The intent is to capture the unique ID of the button which, when it is a single button in the table, it works flawlessly.  
  108.              However, multiple buttons in the table only returns the first button's ID. I have tried the following as well with no
  109.             results:
  110.                 $.each($parseHTML($('.btn-outline-warning').attr('id')), (i,item)=> {
  111.                     console.log(item);
  112.                 });
  113.             */
  114.             /*let btnID = $(".btn-outline-warning").attr('id');
  115.             let lightsaber = btnID.split('/');
  116.             let noBueno = lightsaber[0];
  117.             let muchoProblemo = lightsaber[1];
  118.  
  119.             this.setTitle('Manage Character: ' + muchoProblemo + ' ' + noBueno);
  120.             let actionbtns =
  121.             '<button class="btn btn-lg btn-warning" id="skinresetbtn">Skin Reset</button> '+
  122.             '<button class="btn btn-lg btn-warning" id="changenamebtn">Change Name</button> '+
  123.             '<button class="btn btn-lg btn-warning" id="changedobbtn">Change DOB</button>';
  124.             this.setContent(actionbtns);*/
  125.         }
  126.     }
  127. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement