Changeset 4389

Show
Ignore:
Timestamp:
07/13/07 13:02:04 (6 years ago)
Author:
gregmac
Message:

Add AJAX-style module admin processing

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.3/amp_conf/htdocs/admin/page.modules.php

    r4170 r4389  
    3535 
    3636 
    37  
    38 ?> 
    39 <script type="text/javascript" src="common/tabber-minimized.js"></script> 
    40 <script type="text/javascript"> 
    41 function toggleInfoPane(pane) { 
    42   var style = document.getElementById(pane).style; 
    43   if (style.display == 'none' || style.display == '') { 
    44     style.display = 'block'; 
    45   } else { 
    46     style.display = 'none'; 
    47   } 
    48 
    49  
    50 function check_upgrade_all() { 
    51   var re = /^moduleaction\[([a-z0-9_\-]+)\]$/; 
    52   for(i=0; i<document.modulesGUI.elements.length; i++) { 
    53     if (document.modulesGUI.elements[i].value == 'upgrade' || document.modulesGUI.elements[i].value == 'install' ) { 
    54       if (match = document.modulesGUI.elements[i].name.match(re)) { 
    55         // check the box 
    56         document.modulesGUI.elements[i].checked = true; 
    57         // expand info pane 
    58         document.getElementById('infopane_'+match[1]).style.display = 'block'; 
    59       } 
    60     } 
    61   } 
    62 
    63  
    64 function check_download_all() { 
    65   var re = /^moduleaction\[([a-z0-9_\-]+)\]$/; 
    66   for(i=0; i<document.modulesGUI.elements.length; i++) { 
    67     if (document.modulesGUI.elements[i].value == 'downloadinstall') { 
    68       if (match = document.modulesGUI.elements[i].name.match(re)) { 
    69         // check the box 
    70         document.modulesGUI.elements[i].checked = true; 
    71         // expand info pane 
    72         document.getElementById('infopane_'+match[1]).style.display = 'block'; 
    73       } 
    74     } 
    75   } 
    76 
    77  
    78  
    79 function showhide_upgrades() { 
    80   var upgradesonly = document.getElementById('show_upgradable_only').checked; 
    81    
    82   var module_re = /^module_([a-z0-9_]+)$/;   // regex to match a module element id 
    83   var cat_re = /^category_([a-zA-Z0-9_]+)$/; // regex to match a category element id 
    84  
    85   var elements = document.getElementById('modulelist').getElementsByTagName('li'); 
    86  
    87   // loop through all modules, check if there is an upgrade_<module> radio box  
    88   for(i=0; i<elements.length; i++) { 
    89     if (match = elements[i].id.match(module_re)) { 
    90       if (!document.getElementById('upgrade_'+match[1])) { 
    91         // not upgradable 
    92         document.getElementById('module_'+match[1]).style.display = upgradesonly ? 'none' : 'block'; 
    93       } 
    94     } 
    95   } 
    96    
    97    
    98    
    99   // hide category headings that don't have any visible modules 
    100    
    101   var elements = document.getElementById('modulelist').getElementsByTagName('div'); 
    102   // loop through category items 
    103   for(i=0; i<elements.length; i++) { 
    104     if (elements[i].id.match(cat_re)) { 
    105       var subelements = elements[i].getElementsByTagName('li'); 
    106       var display = false; 
    107       for(j=0; j<subelements.length; j++) { 
    108         // loop through children <li>'s, find names that are module element id's  
    109         if (subelements[j].id.match(module_re) && subelements[j].style.display != 'none') { 
    110           // if at least one is visible, we're displaying this element 
    111           display = true; 
    112           break; // no need to go further 
     37if (!$quietmode) { 
     38  ?> 
     39  <script type="text/javascript" src="common/tabber-minimized.js"></script> 
     40  <script type="text/javascript"> 
     41  function toggleInfoPane(pane) { 
     42    var style = document.getElementById(pane).style; 
     43    if (style.display == 'none' || style.display == '') { 
     44      style.display = 'block'; 
     45    } else { 
     46      style.display = 'none'; 
     47    } 
     48  } 
     49 
     50  function check_upgrade_all() { 
     51    var re = /^moduleaction\[([a-z0-9_\-]+)\]$/; 
     52    for(i=0; i<document.modulesGUI.elements.length; i++) { 
     53      if (document.modulesGUI.elements[i].value == 'upgrade' || document.modulesGUI.elements[i].value == 'install' ) { 
     54        if (match = document.modulesGUI.elements[i].name.match(re)) { 
     55          // check the box 
     56          document.modulesGUI.elements[i].checked = true; 
     57          // expand info pane 
     58          document.getElementById('infopane_'+match[1]).style.display = 'block'; 
    11359        } 
    11460      } 
    115        
    116       document.getElementById(elements[i].id).style.display = display ? 'block' : 'none'; 
    117     } 
    118   } 
    119    
    120 
    121  
    122 </script> 
    123 <?php 
    124  
    125 echo "<h2>" . _("Module Administration") . "</h2>"; 
     61    } 
     62  } 
     63 
     64  function check_download_all() { 
     65    var re = /^moduleaction\[([a-z0-9_\-]+)\]$/; 
     66    for(i=0; i<document.modulesGUI.elements.length; i++) { 
     67      if (document.modulesGUI.elements[i].value == 'downloadinstall') { 
     68        if (match = document.modulesGUI.elements[i].name.match(re)) { 
     69          // check the box 
     70          document.modulesGUI.elements[i].checked = true; 
     71          // expand info pane 
     72          document.getElementById('infopane_'+match[1]).style.display = 'block'; 
     73        } 
     74      } 
     75    } 
     76  } 
     77 
     78 
     79  function showhide_upgrades() { 
     80    var upgradesonly = document.getElementById('show_upgradable_only').checked; 
     81     
     82    var module_re = /^module_([a-z0-9_]+)$/;   // regex to match a module element id 
     83    var cat_re = /^category_([a-zA-Z0-9_]+)$/; // regex to match a category element id 
     84 
     85    var elements = document.getElementById('modulelist').getElementsByTagName('li'); 
     86 
     87    // loop through all modules, check if there is an upgrade_<module> radio box  
     88    for(i=0; i<elements.length; i++) { 
     89      if (match = elements[i].id.match(module_re)) { 
     90        if (!document.getElementById('upgrade_'+match[1])) { 
     91          // not upgradable 
     92          document.getElementById('module_'+match[1]).style.display = upgradesonly ? 'none' : 'block'; 
     93        } 
     94      } 
     95    } 
     96     
     97     
     98     
     99    // hide category headings that don't have any visible modules 
     100     
     101    var elements = document.getElementById('modulelist').getElementsByTagName('div'); 
     102    // loop through category items 
     103    for(i=0; i<elements.length; i++) { 
     104      if (elements[i].id.match(cat_re)) { 
     105        var subelements = elements[i].getElementsByTagName('li'); 
     106        var display = false; 
     107        for(j=0; j<subelements.length; j++) { 
     108          // loop through children <li>'s, find names that are module element id's  
     109          if (subelements[j].id.match(module_re) && subelements[j].style.display != 'none') { 
     110            // if at least one is visible, we're displaying this element 
     111            display = true; 
     112            break; // no need to go further 
     113          } 
     114        } 
     115         
     116        document.getElementById(elements[i].id).style.display = display ? 'block' : 'none'; 
     117      } 
     118    } 
     119     
     120  } 
     121 
     122  function process_module_actions(actions) { 
     123    freepbx_modal_show('moduleBox'); 
     124    urlStr = "config.php?type=tool&amp;display=modules&amp;extdisplay=process&amp;quietmode=1"; 
     125    for (var i in actions) { 
     126      urlStr += "&amp;moduleaction["+i+"]="+actions[i]; 
     127    } 
     128    $('#moduleBox').html('<iframe src="'+urlStr+'"></iframe>'); 
     129  } 
     130  function close_module_actions(goback) { 
     131    //freepbx_modal_close('moduleBox'); 
     132    freepbx_modal_hide('moduleBox'); 
     133    if (goback) { 
     134      location.href = 'config.php?display=modules&amp;type=tool&amp;online=<?php echo ($_REQUEST['online']?1:0); ?>'; 
     135    } 
     136  } 
     137 
     138  </script> 
     139  <div id="moduleBox" style="display:none;"> 
     140  </div> 
     141  <?php 
     142 
     143  echo "<h2>" . _("Module Administration") . "</h2>"; 
     144} else { 
     145  // $quietmode==true 
     146  ?> 
     147  <html><head> 
     148    <link href="common/mainstyle.css" rel="stylesheet" type="text/css" /> 
     149  </head><body> 
     150  <?php 
     151
    126152 
    127153 
     
    339365    } 
    340366    echo "</div>"; 
    341     echo "\t<input type=\"button\" value=\""._("Return")."\" onclick=\"location.href = 'config.php?display=modules&amp;type=tool&amp;online=".($_REQUEST['online']?1:0)."';\" />"; 
     367    if ($quietmode) { 
     368      echo "\t<a href=\"#\" onclick=\"parent.close_module_actions(true);\" />"._("Return")."</a>"; 
     369    } else { 
     370      echo "\t<input type=\"button\" value=\""._("Return")."\" onclick=\"location.href = 'config.php?display=modules&amp;type=tool&amp;online=".($_REQUEST['online']?1:0)."';\" />"; 
     371    } 
    342372  break; 
    343373  case 'confirm': 
     
    350380    echo "<input type=\"hidden\" name=\"extdisplay\" value=\"process\" />"; 
    351381     
     382    echo "\t<script type=\"text/javascript\"> var moduleActions = new Array(); </script>\n"; 
     383     
    352384    $actionstext = array(); 
    353385    $errorstext = array(); 
     
    359391        $modules[$module]['name'] = $module; 
    360392      } 
    361  
     393       
    362394      switch ($action) { 
    363395        case 'upgrade': 
     
    429461        break; 
    430462      } 
    431       echo "\t<input type=\"hidden\" name=\"moduleaction[".$module."]\" value=\"".$action."\" />\n"; 
     463      //echo "\t<input type=\"hidden\" name=\"moduleaction[".$module."]\" value=\"".$action."\" />\n"; 
     464      echo "\t<script type=\"text/javascript\"> moduleActions['".$module."'] = '".$action."'; </script>\n"; 
    432465    } 
    433466     
     
    448481      echo "</ul>"; 
    449482       
    450       echo "\t<input type=\"submit\" value=\"Confirm\" name=\"process\" />"; 
     483      //echo "\t<input type=\"submit\" value=\"Confirm\" name=\"process\" />"; 
     484      echo "\t<input type=\"button\" value=\"Confirm\" name=\"process\" onclick=\"process_module_actions(moduleActions);\" />"; 
    451485    } else { 
    452486      echo "<h4>"._("No actions to perform")."</h4>\n"; 
     
    788822} 
    789823 
     824if ($quietmode) { 
     825  echo '</body></html>'; 
     826} 
     827 
    790828?>