当前位置:编程学习 > JAVA >>

jquery应用实例

地理所队列操作功能的添加记录:

将各项功能做成子菜单,总体思路:

  ../csm/conf.php中配置所有的操作命令:

// Command to handle the queue opration

$execute_to_reconfig = $shell_cgi." ".escapeshellarg("$QUEUES_BIN/badmin reconfig");

$prepare_to_setenv = $shell_cgi." ".escapeshellarg("export LSF_ENVDIR");

$list_all_queues_command = $shell_cgi." ".escapeshellarg("source /etc/profile;$QUEUES_BIN/bqueues | $ROOT_BIN/awk '{if (NR>1)print $1}'");    // 这一句如果不加 source /etc/profile 会提示某些环境变量未设置的错误

$get_user_queue = $shell_cgi." ".escapeshellarg("$USR_YPBIN/bqueueadm -u %s");

$add_user_to_queue = $shell_cgi." ".escapeshellarg("$USR_YPBIN/bqueueadm -u %s -a %s");

$del_user_from_queue = $shell_cgi." ".escapeshellarg("$USR_YPBIN/bqueueadm -u %s -d %s");

$change_user_to_queue = $shell_cgi." ".escapeshellarg("$USR_YPBIN/bqueueadm -u %s -d %s -a %s");
 

 

  在相应的tpl文件中定义显示的视图,注意仅仅是视图,不包括显示的数据。

  类似:../csm/addusertoqueue.php 是实际给tpl传递数据的,需要的用户数据,队列数据

  都是从这里传入的。

  类似:js/addusertoqueue.js 是利用ajax异步将请求发送给处理页面,并接收处理页面传 

  递回来的值。

  类似:../csm/addusertoqueue-ajax.php 是接收ajax传来的参数,实际进行命令的执行

  的。

特别注意:$list_all_queues_command这条命令,其中限制性了source /etc/profile 把环境变量读进去,

不然返回的数组里面没有值,会报错。

Js文件中的例子:

$().ready(function(){

$('#submit_change_user_to_queue').click(function(){

$.ajax({

url: '../csm/changeusertoqueue-ajax.php',

type: 'GET',

data: 'username='+$('#usernamelist option:selected').text()+'&beforqueue='+$('#queueslist_befor option:selected').text()+'&nowqueue='+$('#queueslist_now option:selected').text(),

dataType: 'text',

success: function(data){

alert(data);

},

error: function(XMLHttpRequest, textStatus, errorThrown){

   alert(XMLHttpRequest.status);

                 alert(XMLHttpRequest.readyState);

                 alert(textStatus);

}

});

});

});
 

 


Changeusertoqueue-ajax.php中的例子:

<?php

   include_once "../conf.php";

   include_once "../functions.php";

   include_once "../csm/conf.php";

  

   $username = $_GET["username"];

   $beforqueue = $_GET["beforqueue"];

   $nowqueue = $_GET["nowqueue"];

 

   $change_user_to_queue = $change_user_to_queue ;

   $execute_to_reconf = $execute_to_reconfig ;

   $change_user_to_queue_cmd = sprintf($change_user_to_queue,$username,$beforqueue,$nowqueue);

   $change_user_to_queue_cmd = ConstructShellCommand($change_user_to_queue_cmd);

   $execute_to_reconf_cmd = ConstructShellCommand($execute_to_reconf);

   //echo $execute_to_reconf_cmd ;

  

   ExecuteCommand($change_user_to_queue_cmd, $output, $return);

  

   if($return==0){

        ExecuteCommand($execute_to_reconf_cmd, $output, $return);

        if($return==0){

         echo "用户".$username."已成功从队列".$beforqueue."更改到队列".$nowqueue."中!";        

        }else{

         echo "使配置生效的命令执行失败!";

        }

   }else{

       echo "执行将用户添加到指定队列出错,请联系管理员!";

   }

?>
 

补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,