Ticket #1798: diff.patch

File diff.patch, 8.0 kB (added by mbrevda, 2 years ago)

patch to implement double-dropdowns

  • common/script.legacy.js

    old new  
    180180// NOTE: <select> boxes do not support the .select method, therefore you cannot 
    181181// use this function on any <select> elements 
    182182function warnInvalid (theField, s) { 
    183     theField.focus(); 
    184     theField.select(); 
     183    if(theField){ 
     184      theField.focus(); 
     185      theField.select(); 
     186    } 
    185187    alert(s); 
    186188    return false; 
    187189} 
     
    639641function isFilenameChar (c) 
    640642{   return ( ((c >= "0") && (c <= "9")) || ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c == "_") || (c == "-") ) 
    641643} 
     644 
     645/*************************************************** 
     646 *             GLOBAL JQUERY CODE                  * 
     647 ***************************************************/ 
     648 
     649$(document).ready(function(){ 
     650 
     651    //destination double dropdown code 
     652    $('.destdropdown').bind('blur click change keypress', function(){ 
     653      var name=$(this).attr('name'); 
     654      var id=name.replace('goto',''); 
     655      var dest=$(this).val(); 
     656      $('[name$='+id+']').not(this).hide(); 
     657      $('[name='+dest+id+']').show(); 
     658  }); 
     659 
     660}); 
  • views/freepbx.php

    old new  
    9999<?php 
    100100  } else { 
    101101?> 
     102  <script type="text/javascript" src="common/jquery-1.3.2.js"></script> 
    102103  <script type="text/javascript" src="common/script.legacy.js"></script> <!-- legacy script.js.php --> 
    103   <script type="text/javascript" src="common/jquery-1.3.2.js"></script> 
    104104  <script type="text/javascript" src="common/jquery.tabs-2.7.4.js"></script> <!-- used by setup/tools menu tab --> 
    105105  <script type="text/javascript" src="common/jquery.dimensions.js"></script> <!-- used by reload/module admin --> 
    106106  <script type="text/javascript" src="common/jquery.cookie.js"></script> <!-- used by reload/module admin --> 
  • functions.inc.php

    old new  
    19611961    } 
    19621962} 
    19631963 
    1964 // $goto is the current goto destination setting 
    1965 // $i is the destination set number (used when drawing multiple destination sets in a single form ie: digital receptionist) 
    1966 // esnure that any form that includes this calls the setDestinations() javascript function on submit. 
    1967 // ie: if the form name is "edit", and drawselects has been called with $i=2 then use onsubmit="setDestinations(edit,2)" 
    1968 function drawselects($goto,$i,$show_custom=false) { 
     1964 
     1965/* 
     1966 * $goto is the current goto destination setting 
     1967 * $i is the destination set number (used when drawing multiple destination sets in a single form ie: digital receptionist) 
     1968 * esnure that any form that includes this calls the setDestinations() javascript function on submit. 
     1969 * ie: if the form name is "edit", and drawselects has been called with $i=2 then use onsubmit="setDestinations(edit,2)" 
     1970 * $table specifies if the destinations will be drawn in a new <tr> and <td> 
     1971 *  
     1972 */    
     1973function drawselects($goto,$i,$show_custom=false, $table=true) { 
    19691974  global $tabindex; 
    19701975   
    19711976  /* --- MODULES BEGIN --- */ 
     
    19731978   
    19741979  $all_destinations = array(); 
    19751980  $module_hash = array(); 
     1981  $selectHtml=$destmod=''; 
    19761982 
    1977   $selectHtml = '<tr><td colspan=2>';  
     1983  //$selectHtml.='</script>'; 
     1984  if($table){ 
     1985    $selectHtml.='<tr><td colspan=2>'; 
     1986  } 
     1987 
    19781988   
    19791989  //check for module-specific destination functions 
    19801990  foreach ($active_modules as $rawmod => $module) { 
     
    19922002      } 
    19932003    } 
    19942004  } 
     2005  ksort($all_destinations); 
     2006  ksort($module_hash); 
    19952007 
    19962008  $foundone = false; 
    19972009  $tabindex_needed = true; 
    1998   foreach ($all_destinations as $cat=>$destination) { 
    1999     // create a select option for each destination  
    2000     $options = ""; 
    2001     $checked = false; 
    2002     foreach ($destination as $dest) { 
    2003       $options .= '<option value="'.$dest['destination'].'" '.(strpos($goto,$dest['destination']) === false ? '' : 'SELECTED').'>'.($dest['description'] ? $dest['description'] : $dest['destination']); 
    2004  
    2005       // check to see if the currently selected goto matches one these destinations 
    2006       if($dest['destination'] == $goto) $checked = true; 
     2010  //get the destination module name if we have a $goto 
     2011  if($goto){ 
     2012    foreach($module_hash as $mod => $description){ 
     2013      foreach($all_destinations[$mod] as $destination){ 
     2014        if($goto==$destination['destination']){ 
     2015          $destmod=$mod; 
     2016        } 
     2017      } 
    20072018    } 
    2008  
    2009     // make a unique id to be used for the HTML id 
    2010     // This allows us to have multiple drawselect() sets on the page without 
    2011     // conflicting with each other 
    2012     $radioid = uniqid("drawselect"); 
    2013  
    2014     $cat_identifier = preg_replace('/[^a-zA-Z0-9]/','_', $cat); 
    2015  
     2019  } 
     2020  if ($tabindex_needed && ($checked || !$goto)) { 
     2021    $tabindex_txt = (isset($tabindex) && $tabindex != '') ? ' tabindex="'.++$tabindex.'" ':''; 
     2022    $tabindex_needed = false; 
     2023  } else { 
     2024    $tabindex_txt = ''; 
     2025  } 
     2026  //draw first select box 
     2027  $selectHtml.='<select name="goto'.$i.'" class="destdropdown" '.($tabindex_needed?' tabindex="'.$tabindex_txt.'"':'').'>'; 
     2028  $selectHtml.='<option value="">== '._('chose one').' ==</option>'; 
     2029  foreach($module_hash as $mod => $disc){ 
     2030    $cat_identifier = preg_replace('/[^a-zA-Z0-9]/','_', $mod); 
    20162031    // We bind to the hosting module's domain. If we find the translation there we use it, if not 
    20172032    // we try the default 'amp' domain. If still no luck, we will try the _() which is the current 
    20182033    // module's display since some old translation code may have stored it localy but should migrate 
     
    20232038    if ($label_text == $cat) { 
    20242039      $label_text = dgettext('amp',$label_text); 
    20252040    } 
    2026     if ($label_text == $cat) 
     2041    if ($label_text == $cat)
    20272042      $label_text = _($label_text); 
    20282043    } 
    2029        
    2030     if ($tabindex_needed && ($checked || ! $goto)) { 
    2031       $tabindex_txt = (isset($tabindex) && $tabindex != '') ? ' tabindex="'.++$tabindex.'" ':''; 
    2032       $tabindex_needed = false; 
    2033     } else { 
    2034       $tabindex_txt = ''; 
     2044    $selectHtml .='<option value="'.str_replace(' ','_',$mod).'" '.(($mod==$destmod)?'SELECTED':'').'>'.$mod.'</option>'; 
     2045  } 
     2046  $selectHtml .='</select> '; 
     2047   
     2048  foreach ($all_destinations as $cat=>$destination) { 
     2049    $selectHtml .='<select name="'.str_replace(' ','_',$cat).$i.'"'.(($cat==$destmod)?'':' style="display:none"').'>'; 
     2050    foreach($destination as $dest){ 
     2051      $selectHtml .='<option  value="'.$dest['destination'].'" '.(($goto==$dest['destination'])?'SELECTED':'').'>'.$dest['description'].'</option>'; 
    20352052    } 
    2036     $selectHtml .=  '<input type="radio"'.$tabindex_txt.' id="'.$radioid.'" name="goto'.$i.'" value="'.$cat_identifier.'" '. 
    2037                     //'onclick="javascript:this.form.goto'.$i.'.value=\''.$cat.'\';" '. 
    2038                     //'onkeypress="javascript:if (event.keyCode == 0 || (document.all && event.keyCode == 13)) this.form.goto'.$i.'.value=\''.$cat.'\';" '. 
    2039                     ($checked? 'CHECKED=CHECKED' : '').' /> '; 
    2040     $selectHtml .= '<label for="'.$radioid.'">'.$label_text.':</label> '; 
    2041      
    2042     // set the  
    2043 //    if ($checked) { $gotomod = $cat; }  
    2044  
    2045     $selectHtml .=  '<select name="'.$cat_identifier.$i.'" onfocus="document.getElementById(\''.$radioid.'\').checked = true; this.form.goto'.$i.'.value=\''.$cat.'\';">'; 
    2046     $selectHtml .= $options;   
    2047     $selectHtml .=  "</select><br />\n"; 
    2048  
    2049     if ($checked) $foundone = true; 
     2053    $selectHtml .='</select>'; 
    20502054  } 
    20512055  /* --- MODULES END --- */ 
    20522056   
    20532057  // This is selected if $foundone is false (and goto is not blank) - basically, a fallback 
    20542058  // The ONLY time no radio box is selected is if $goto is empty 
    2055   $custom_selected = !$foundone && !empty($goto); 
     2059  $custom_selected = !$destmod && !empty($goto); 
    20562060   
    20572061  //display a custom goto field 
    20582062  if ($custom_selected || $show_custom) { 
     
    20732077 
    20742078  //close off our row 
    20752079  } 
    2076   $selectHtml .= '</td></tr>'; 
     2080  if($table){ 
     2081    $selectHtml.='</td></tr>'; 
     2082  } 
    20772083   
    20782084  return $selectHtml; 
    20792085} 
    2080  
    20812086/* below are legacy functions required to allow pre 2.0 modules to function (ie: interact with 'extensions' table) */ 
    20822087 
    20832088  //add to extensions table - used in callgroups.php