#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    6
    Rep Power
    0

    .js help needed with drop down menus


    The following .js file should hide a bunch of drop down menus until needed. Showing only the selected parents so that the children display in a logical order. It was working but then the site was updated and it no longer works. Can this be simplified?


    Code:
    plugin.includeStyles();
    plugin.configure({
      settingDefinitions:[
        { name:'ctree', label:'Categories', type:'text', defaultValue:'', example:'Category,Value,Subcategory;Category,Value1,Value2,Subcategory etc.'},
        { name:'cat', label:'Cat', type:'text', defaultValue:'', example:'This will trigger the dropdown chains.'},
        { name:'rtree', label:'Region', type:'text', defaultValue:'', example:'Region,Value,SubRegion;Region,Value1,Value2,SubRegion etc.'},
        { name:'rcat', label:'RCat', type:'text', defaultValue:'', example:'This will trigger the dropdown chains.'},
        { name:'ctreeAdmin', label:'Admin Categories (not visible on Portal)', type:'text', defaultValue:'', example:'Enter the Configuration String for the subcategories not visible on the portal. Category,Value,Subcategory;Category,Value1,Value2,Subcategory etc.'},
        { name:'bCatSub', label:'Use Category as a Sub', type:'checkbox', defaultValue: false, example:'Use the built in Category as a subcategory (if you have a custom attribute called "category", the custom attribute cannot be used as a sub)'},
        { name:'tEdit', label:'Use Subs?', type:'checkbox', defaultValue: false, example:'Use subcategories when editing tickets?'},
        { name:'remUnused', label:'Remove Unused', type:'checkbox', defaultValue: false, example:'Remove unused subcategories from the list of categories on ticket status page of the portal?'},
        { name:'defaultV', label:'Default Value', type:'string', defaultValue:'not provided', example: 'Enter the default value of the custom attribute you would like to be hidden from the ticket status page on the portal. (Does nothing if "Remove Unused" is not checked)' }
    
      ]
    });
    
    var cat = plugin.settings.cat.toLowerCase();
    var lblcat = plugin.settings.cat+':';  
    
    var rcat= plugin.settings.rcat.toLowerCase();
    var lblrcat = plugin.settings.rcat+':';  
    
    function SubCat(){
      var sub = plugin.settings.ctree.toLowerCase().split(';');
      var category = $('ticket_category');
    
    
      for (i=0;i<sub.length;i++){
        sub[i]=sub[i].split(',');
    
        var cWatch=$("ticket_c_" + sub[i][0].replace(/ /g, "_"));
        if (sub[i][0]==cat ){
          cWatch=category;
       }
    
        var trigger=false;
        var action=$("ticket_c_" + sub[i].last().replace(/ /g, "_"));
        if (plugin.settings.bCatSub ===true && sub[i].last().replace(/ /g, "_") == cat ){
          action = $('ticket_category');
        }
        for (t=1;t<sub[i].length-1;t++){
          if (cWatch.value.toLowerCase()==sub[i][t]){
            trigger=true;
            break;
          }
        }
        if (trigger===false){  
          $(action.parentNode).hide();
          action.value = '';
          action.selectedIndex=0;
      }
        if (trigger===true){
          cWatch.parentNode.parentNode.insertBefore(action.parentNode,cWatch.parentNode.nextSibling);
          $(action.parentNode).show();
          }
    
    
    
      }
    }
    
    function SubCatHDT(){
      var sub = plugin.settings.ctree.toLowerCase().split(';');
    
      if (plugin.settings.ctreeAdmin.toLowerCase() !== ''){
      var sub1 = plugin.settings.ctree.toLowerCase().split(';');
      var sub2 = plugin.settings.ctreeAdmin.toLowerCase().split(';');
      sub = sub1.concat(sub2);
    }
    
      var nRow=1;
       var category = $('ticket_category');
      for (i=0;i<sub.length;i++){
         sub[i]=sub[i].split(',');
    
        //console.log(sub[i]+"=");
        var cWatch=$("ticket_c_" + sub[i][0].replace(/ /g, "_"));
    
         if (sub[i][0]==cat ){
           cWatch=category;
        }
        var trigger=false;
        var action=$("ticket_c_" + sub[i].last().replace(/ /g, "_"));
       if (plugin.settings.bCatSub ===true && sub[i].last().replace(/ /g, "_") == cat ){
          action = $('ticket_category');
        }
        for (t=1;t<sub[i].length-1;t++){
          if (cWatch.value.toLowerCase()==sub[i][t]){
            trigger=true;
            break;
          }
       }
        if (trigger===false){
            action.value = '';
            action.selectedIndex=0;
          $(action.parentNode).hide();
          $(action.parentNode).previous().hide();
          }
        if (trigger===true && $(cWatch.parentNode.previous()) == $(cWatch.parentNode.parentNode.childNodes[1]) || trigger===true && nRow===0 ){
    
    
          cWatch.parentNode.parentNode.insertBefore(action.parentNode.previous(),cWatch.parentNode.nextSibling);
          cWatch.parentNode.parentNode.insertBefore(action.parentNode,cWatch.parentNode.nextSibling.nextSibling);
          $(action.parentNode).show();
          $(action.parentNode).previous().show();
          nRow=1;
        } else if (trigger===true && $(cWatch.parentNode.previous()) != $(cWatch.parentNode.parentNode.childNodes[1])){
          var tr = document.createElement('tr');
          tr.appendChild(action.parentNode.previous());
          tr.appendChild(action.parentNode);
    
          cWatch.parentNode.parentNode.parentNode.insertBefore(tr,cWatch.parentNode.parentNode.nextSibling);
          $(action.parentNode).show();
          $(action.parentNode).previous().show();
          nRow=0;
        }
         }
    }
    
    function SubCatNT(){
    
      // var sub = plugin.settings.ctree.toLowerCase().split(';');
      var sub = plugin.settings.ctree.toLowerCase().split(';');
    
      if (plugin.settings.ctreeAdmin.toLowerCase() !== ''){
      var sub1 = plugin.settings.ctree.toLowerCase().split(';');
      var sub2 = plugin.settings.ctreeAdmin.toLowerCase().split(';');
      sub = sub1.concat(sub2);
    }
       var category = $('ticket_form').getElementsByTagName('label');
        for (i=0;i<category.length;i++){
          if (category[i].innerHTML == lblcat ){
                   category = category[i].next();
            break;
              }
        }
    
      for (i=0;i<sub.length;i++){
         sub[i]=sub[i].split(',');
    
        var cWatch=$("c_" + sub[i][0].replace(/ /g, "_") + "_popup");
    
          if (sub[i][0]==cat){
           cWatch=category;
        }
    
        var trigger=false;
        var action=$("c_" + sub[i].last().replace(/ /g, "_") + "_popup");
       if (plugin.settings.bCatSub ===true && sub[i].last().replace(/ /g, "_") == cat){
          action = $('ticket_form').getElementsByTagName('label');
         for (c=0;c<action.length;c++){
          if (action[c].innerHTML == lblcat ){
                   action = action[c].next();
            break;
              }
        }
        }
        for (t=1;t<sub[i].length-1;t++){
          if (cWatch.value.toLowerCase()==sub[i][t]){
            trigger=true;
            break;
          }
       }
        if (trigger===false){
          if(action.parentNode)
            $(action.parentNode).hide();
          action.value = '';
          action.selectedIndex=0;
          }
        if (trigger===true){
          cWatch.parentNode.parentNode.insertBefore(action.parentNode,cWatch.parentNode.nextSibling);
          $(action.parentNode).show();     
            }    
      }
    }
    
    function clickedNT(){
     // var sub = plugin.settings.ctree.toLowerCase().split(';');
      var sub = plugin.settings.ctree.toLowerCase().split(';');
    
      if (plugin.settings.ctreeAdmin.toLowerCase() !== ''){
      var sub1 = plugin.settings.ctree.toLowerCase().split(';');
      var sub2 = plugin.settings.ctreeAdmin.toLowerCase().split(';');
      sub = sub1.concat(sub2);
    }
      var category = $('ticket_form').getElementsByTagName('label');
        for (i=0;i<category.length;i++){
          if (category[i].innerHTML == lblcat ){
                   category = category[i].next();
            break;
              }
        }
      for (i=0;i<sub.length;i++){
        sub[i]=sub[i].split(',');
    
        var cWatch=$("c_" + sub[i][0].replace(/ /g, "_") + "_popup");
        if (sub[i][0]==cat){
          cWatch=category;
       }
        var watched = "false";
        for (s=i-1;s>0;s--){
          var sameCat = sub[s][0];
          if  (sameCat==sub[i][0]){
            watched="true";
            break;        
          }
        }
    
              if (watched !=="true"){
                Event.observe(cWatch, 'change', SubCatNT);
              }
      }
    }
    
    
    function NTFormCheck(){
         document.stopObserving('ajax:completed', NTFormCheck);
    
      if ($("ticket_form")){
       clickedNT();
       SubCatNT();
       document.observe('ajax:completed', NTFormCheck);
        }
        else{
          document.observe('ajax:completed', NTFormCheck);
            }
      }
    
    
    function NTToolBar(){
      document.observe('ajax:completed', NTFormCheck);
    }
    
    function SubCatHD(){
    
      NTToolBar();
      if (plugin.settings.tEdit === true) {
        SubCatHDT();
      }
       }
    
    function clicked(){
      var sub = plugin.settings.ctree.toLowerCase().split(';');
       var category = $('ticket_category');
      for (i=0;i<sub.length;i++){
        sub[i]=sub[i].split(',');
    
        var cWatch=$("ticket_c_" + sub[i][0].replace(/ /g, "_"));
        if (sub[i][0]==cat){
          cWatch=category;
       }
        var watched = "false";
        for (s=i-1;s>0;s--){
          var sameCat = sub[s][0];
          if  (sameCat==sub[i][0]){
            watched="true";
            break;        
          }
        }
              if (watched !=="true"){
                Event.observe(cWatch, 'change', SubCat);
              }
      }
    }
    function clickedHD(){
      //var sub = plugin.settings.ctree.toLowerCase().split(';');
      var sub = plugin.settings.ctree.toLowerCase().split(';');
    
      if (plugin.settings.ctreeAdmin.toLowerCase() !== ''){
      var sub1 = plugin.settings.ctree.toLowerCase().split(';');
      var sub2 = plugin.settings.ctreeAdmin.toLowerCase().split(';');
      sub = sub1.concat(sub2);
    }
    
       var category = $('ticket_category');
      for (i=0;i<sub.length;i++){
        sub[i]=sub[i].split(',');
    
        var cWatch=$("ticket_c_" + sub[i][0].replace(/ /g, "_"));
        if (sub[i][0]==cat){
          cWatch=category;
       }
        var watched = "false";
        for (s=i-1;s>0;s--){
          var sameCat = sub[s][0];
          if  (sameCat==sub[i][0]){
            watched="true";
            break;       
          }
        }
              if (watched !=="true"){
                Event.observe(cWatch, 'change', SubCatHDT);
              }
      }
    }
    
    function hideAtts(){
      var findAtts = document.getElementsByTagName('p');
      var remove = plugin.settings.defaultV.replace(/ /g, "_");
      remove = new RegExp("<strong>\\w*?<\\/strong>:\\&nbsp;"+ remove + ",|,\\S<strong>\\w*?<\\/strong>:\\&nbsp;" + remove, "gi");
           for (i=0;i<findAtts.length;i++){
    
            if ($(findAtts[i]).className == "ticket-custom-fields"){
              findAtts[i].innerHTML = findAtts[i].innerHTML.replace(/ /g,"_");
            findAtts[i].innerHTML = findAtts[i].innerHTML.replace(/<strong>\w*?<\/strong>:\&nbsp;not_provided,|,\S<strong>\w*?<\/strong>:\&nbsp;not_provided|<strong>\w*?<\/strong>:\&nbsp;not_provided/gi, "");
            findAtts[i].innerHTML = findAtts[i].innerHTML.replace(remove, "");
             findAtts[i].innerHTML = findAtts[i].innerHTML.replace(/_/g," ");
                 }
          }
    
        }
    
    
    //====================
    
    function SubCat1()
    {
    
      var sub = plugin.settings.rtree.toLowerCase().split(';');
      var category = $('ticket_c_region');
    
    
      for (i=0;i<sub.length;i++)
      {
        sub[i]=sub[i].split(',');
    
        var cWatch=$("ticket_c_" + sub[i][0].replace(/ /g, "_"));
        if (sub[i][0]==rcat )
        {
          cWatch=category;
        }
    
        var trigger=false;
        var action=$("ticket_c_" + sub[i].last().replace(/ /g, "_"));
        if (plugin.settings.bCatSub ===true && sub[i].last().replace(/ /g, "_") == rcat )
        {
          action = $('ticket_c_region');
        }
        for (t=1;t<sub[i].length-1;t++){
          if (cWatch.value.toLowerCase()==sub[i][t]){
            trigger=true;
            break;
          }
        }
        if (trigger===false){
          $(action.parentNode).hide();
          action.value = '';
          action.selectedIndex=0;
      }
        if (trigger===true){
          cWatch.parentNode.parentNode.insertBefore(action.parentNode,cWatch.parentNode.nextSibling);
          $(action.parentNode).show();
          }
    
    
    
      }
    }
    
    function clicked1(){
      var sub = plugin.settings.rtree.toLowerCase().split(';');
       var category = $('ticket_c_region');
      for (i=0;i<sub.length;i++){
        sub[i]=sub[i].split(',');
    
        var cWatch=$("ticket_c_" + sub[i][0].replace(/ /g, "_"));
        if (sub[i][0]==rcat){
          cWatch=category;
       }
        //console.log(sub[i][0]);
        var watched = "false";
        for (s=i-1;s>0;s--){
          var sameCat = sub[s][0];
          if  (sameCat==sub[i][0]){
            watched="true";
            break;
          }
        }
              if (watched !=="true"){
                Event.observe(cWatch, 'change', SubCat1);
              }
      }
    }
    
    
    function processcustomform()
    {
    
      setTimeout(
    
        function aa()
        {
    
          var forms = document.forms;
    
          for(var i in forms)
          {
            var form = forms[i];
            var index = ($(form).id)?($(form).id).indexOf("custom_ticket_form"):-1;
            //console.log(index);
            if( index !== -1 )
            {
    
              console.log(($(form).id));
              break;
            }
          }
    
        }
      ,5000
      );
    
    }
    
    
    
    
    ​
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    6
    Rep Power
    0
    Example drop down menus that I'm working with.... need to hide everything but summary, description, category, & division.



    Code:
     <div class=" control-group"><label for="ticket_summary">Summary:</label><div class="controls"><input id="ticket_summary" name="ticket[summary]" size="30" type="text" /><span class="help-inline"></span></div></div>
        <div class=" control-group" rows="4"><label for="ticket_description">Description:</label><div class="controls"><textarea cols="40" id="ticket_description" name="ticket[description]" rows="4"></textarea><span class="help-inline"></span></div></div>
     
        <div class="ticket-custom-attrs">
     
           <div class="control-group custom "><label for="ticket[c_ai_south]" title="y South">y South:</label><div class="controls"><select id="ticket_c_y_south" name="ticket[c_y_south]"><option value=""></option>
    <option value="Washington DC">Washington DC</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_sales]" title="Sales">Sales:</label><div class="controls"><select id="ticket_c_sales" name="ticket[c_sales]"><option value=""></option>
    <option value="West Region">West Region</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_bcdh]" title="BCIH">BCIH:</label><div class="controls"><select id="ticket_c_bcdh" name="ticket[c_bcih]"><option value=""></option>
    <option value="Sales">Sales</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[category]" title="Category">Category:</label><div class="controls"><select id="ticket_category" name="ticket[category]"><option value=""></option>
    <option value="Support">Support</option>
    <option value="Project">Project</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_cell_phone]" title="Cell Phone">Cell Phone:</label><div class="controls"><select id="ticket_c_cell_phone" name="ticket[c_cell_phone]"><option value="" selected="selected"></option>
    <option value="Android">Android</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_division]" title="Division">Division:</label><div class="controls"><select id="ticket_c_division" name="ticket[c_division]"><option value=""></option>
    <option value="y South">y South</option>
    <option value="NT">NT</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_hardware]" title="Hardware">Hardware:</label><div class="controls"><select id="ticket_c_hardware" name="ticket[c_hardware]"><option value=""></option>
    <option value="Other">Other</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_nt]" title="NT">NT:</label><div class="controls"><select id="ticket_c_nt" name="ticket[c_nt]"><option value=""></option>
    <option value="Call Center">Call Center</option>
    <option value="West Region">West Region</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_pps]" title="PPS">PPS:</label><div class="controls"><select id="ticket_c_pps" name="ticket[c_pps]"><option value="" selected="selected"></option>
    <option value="ytania">ytania</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_phone]" title="Phone">Phone:</label><div class="controls"><select id="ticket_c_phone" name="ticket[c_phone]"><option value="" selected="selected"></option>
    <option value="Desk Phone">Desk Phone</option>
    <option value="Cell Phone">Cell Phone</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_resource_group]" title="Resource Group">Resource Group:</label><div class="controls"><select id="ticket_c_resource_group" name="ticket[c_resource_group]"><option value="" selected="selected"></option>
    <option value="Property Mgmt">Property Mgmt</option>
    <option value="Purchasing">Purchasing</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_software]" title="Software">Software:</label><div class="controls"><select id="ticket_c_software" name="ticket[c_software]"><option value=""></option>
    <option value="VPN">VPN</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_support]" title="Support">Support:</label><div class="controls"><select id="ticket_c_support" name="ticket[c_support]"><option value="" selected="selected"></option>
    <option value="Software">Software</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_tsp]" title="TSP">TSP:</label><div class="controls"><select id="ticket_c_tsp" name="ticket[c_tsp]"><option value=""></option>
    <option value="TSPI">TSPI</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_tablet]" title="Tablet">Tablet:</label><div class="controls"><select id="ticket_c_tablet" name="ticket[c_tablet]"><option value=""></option>
    <option value="MS Surface">MS Surface</option></select></div></div>
     
           <div class="control-group custom "><label for="ticket[c_iphone]" title="iPhone">iPhone:</label><div class="controls"><select id="ticket_c_iphone" name="ticket[c_iphone]"><option value=""></option>
    <option value="iPhone5">iPhone5</option></select></div></div>
     
        </div>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    6
    Rep Power
    0
    new to forum and wasn't sure how to move this to the .js side.

    could a moderator please move to the correct area?

    please and thank you

IMN logo majestic logo threadwatch logo seochat tools logo