|
楼主 |
发表于 2013-9-16 11:33:55
|
显示全部楼层
思路:1.首先要新建自定义widget的功能模块
2.在BIZ下新建功能模块的logic/action下新建action(查询自定义widget要显示的数据)
3.要新建一个.j文件 在此文件文件中对action返回的数据进行处理 输出到自定义的widget中
4.要在UI下新建功能模块的config/function.xml中添加新建的功能模块
5.要在UI下新建功能模块的config/widget.xml中添加自定义的widget
6.给角色分配新建功能模块的功能权限
7.在首页设置/模块设置中把添加的自定义widget选上
方法:
下面的例子是调用自己写的查询待办任务的action 返回值的类型是Table(注:如果调用平台的查询待办任务的action 返回值的类型是Document)
1.在BIZ下新建自己的功能模块 \BIZ\userDefineWidget\userDefineWidget
在\BIZ\userDefineWidget\userDefineWidget\logic\action新建queryTask.action.m
在queryTask.action.m中添加queryTaskaction 代码如下:- public static Table queryTask(){
- String condition = TaskUtils.getExecutorCondition("t", ContextHelper.getPerson().getPersonMembers(), true);
-
- String query = "select t, t.sName, t.sCURL, t.sProcess, t.sActivity, t.sCreateTime, t.sExecutorFName, t.sExecutorNames, t.sEURL, t.sCreatorFName, t.sShortcut, t.sHints, t.sCreatorFID, t.sExecutorFID, t.sKindID " +
- " from SA_Task t " +
- " where (t.sKindID='tkTask' or t.sKindID='tkExecutor' or t.sKindID='tkNotice' or t.sKindID IS NULL) " +
- " and (t.sStatusID='tesReady' or t.sStatusID='tesExecuting') " +
- " and (t.sTypeID IS NULL or t.sTypeID <> 'WORKREMIND')" +
- " and " + condition +
- " order by t.sCreateTime desc " +
- " limit 0,8 ";
- return KSQL.select(query, null, "/system/data", null);
- }
复制代码 在\BIZ\userDefineWidget\userDefineWidget\process下新建defineWidget
在动作设置中刚刚写的queryTask action加上
2.切换到UI层 在\UI\userDefineWidget\userDefineWidget\process\defineWidget下新建myselfTask.j- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import com.justep.biz.client.Action;
- import com.justep.biz.client.ActionEngine;
- import com.justep.biz.client.ActionResult;
- import com.justep.biz.client.ActionUtils;
- import com.justep.ui.util.NetUtils;
- public class MyselfTask extends com.justep.ui.impl.JProcessorImpl {
- public static final String PROCESS = "/userDefineWidget/userDefineWidget/process/defineWidget/defineWidgetProcess";
- public static final String ACTIVITY = "mainActivity";
- private static final String QUERY_WAIT_TASK_ACTION = "queryTask";
- @Override
- public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- try{
- JSONObject obj=queryWaitTasks(request);
- JSONObject data = obj.getJSONObject("data");
- JSONObject value=data.getJSONObject("value");
- JSONArray array=value.getJSONArray("rows");
- JSONObject rows=null;
- request.setCharacterEncoding("utf-8");
- response.setContentType("text/html;charset=utf-8");
- PrintWriter pw = response.getWriter();
- pw.println("<html>");
- pw.println("<head>");
- pw.println("<link rel='stylesheet' type='text/css' href='/x5/UI/userDefineWidget/userDefineWidget/process/defineWidget/customer.css'>");
- pw.println("<script type='text/javascript' src='/x5/base/base.js' ></script>");
- pw.println("<script type='text/javascript' src='/x5/form/form.js' ></script>");
- pw.println("<script type='text/javascript' src='/x5/UI/userDefineWidget/userDefineWidget/process/defineWidget/customer.js'></script>");
- pw.println("</head>");
- pw.println("<body>");
- pw.println("<table width='100%'>");
- for(int i=0;i<array.length();i++){
- rows=array.getJSONObject(i);
- JSONObject sNameObj=rows.getJSONObject("sName");
- JSONObject sExecutorNamesObj=rows.getJSONObject("sExecutorNames");
- JSONObject sCreateTimeObj=rows.getJSONObject("sCreateTime");
- JSONObject sProcessObj=rows.getJSONObject("sProcess");
- JSONObject sActivityObj=rows.getJSONObject("sActivity");
- JSONObject sEURLObj=rows.getJSONObject("sEURL");
- JSONObject sKindIDObj=rows.getJSONObject("sKindID");
- JSONObject sExecutorFIDObj=rows.getJSONObject("sExecutorFID");
- JSONObject sTaskObj=rows.getJSONObject("t");
- String sName=(String) sNameObj.get("value");
- String sExecutorNames=(String) sExecutorNamesObj.get("value");
- String sCreateTime=(String) sCreateTimeObj.get("value");
- String sProcess=(String) sProcessObj.get("value");
- String sActivity=(String) sActivityObj.get("value");
- String sEURL=(String) sEURLObj.get("value");
- String sTask=(String) sTaskObj.get("value");
- String sKindID=(String) sKindIDObj.get("value");
- String sExecutorFID=(String) sExecutorFIDObj.get("value");
- String url = sEURL.contains("?") ? sEURL + "&task=" +sTask: sEURL + "?task=" + sTask;
- pw.println("<tr style='font-size:12px;'>");
- pw.println("<td style='width:12px;'>");
- pw.println("<img name='flagImg' src='/x5/UI/SA/task/taskView/images/dot.png'></img>");
- pw.println("</td>");
- pw.println("<td class='className'>");
- pw.print("<a href='javascript:void(0)' onclick="openTask(\'");
- pw.print(sProcess);
- pw.print("\',\'");
- pw.print(sActivity);
- pw.print("\',\'");
- pw.print(sName);
- pw.print("\',\'");
- pw.print(url);
- pw.print("\',\'");
- pw.print(sTask);
- pw.print("\',\'");
- pw.print(sExecutorFID);
- pw.print("\',\'");
- pw.print("\',\'");
- pw.print(sKindID);
- pw.println("\')">");
- pw.println(sName);
- pw.println("</a>");
- pw.println("</td>");
- pw.println("<td style='width:1px;'></td>");
- pw.println("<td class='className' style='width:61px;'>");
- pw.println(sExecutorNames);
- pw.println("</td>");
- pw.println("<td style='width:1px;'></td>");
- pw.println("<td class='className' style='width:63px;'>");
- pw.println(sCreateTime.substring(0, 10));
- pw.println("</td>");
- pw.println("</tr>");
- }
- pw.println("</table>");
- pw.println("</body>");
- pw.println("</html>");
- }catch(JSONException e){
- e.printStackTrace();
- }
-
- }
- private JSONObject queryWaitTasks(HttpServletRequest request){
- Action action = new Action();
- action.setProcess(PROCESS);
- action.setActivity(ACTIVITY);
- action.setName(QUERY_WAIT_TASK_ACTION);
- action.setExecutor(NetUtils.getExecutor(request));
- action.setExecuteContext(NetUtils.getExecuteContext(request));
- String bsessionID = NetUtils.getBSessionID(request);
- String language = NetUtils.getLanguage(request);
- ActionResult ar = ActionEngine.invokeAction(action, ActionUtils.JSON_CONTENT_TYPE, bsessionID, language, null);
- return (JSONObject) ar.getContent();
- }
-
- }
复制代码 3.在\UI\userDefineWidget\userDefineWidget\process\defineWidget下新建customer.js
- function openTask(sProcess, sActivity, sName, taskURL, task, executorFID, executor, sKindID){
- var pattern = "do";
- if (sKindID == 'tkNotice'){
- pattern = "detail";
- }
-
- taskURL += "&activity-pattern=" + pattern + "&process=" + sProcess + "&activity=" + sActivity;
- var param = '<parameters>' +
- '<parameter name="task">' +
- '<xbiz:simple xmlns:xbiz="http://www.justep.com/xbiz#" type="http://www.w3.org/2001/XMLSchema#string">' + task + '</xbiz:simple>' +
- '</parameter>' +
- '<parameter name="executor">' +
- '<xbiz:simple xmlns:xbiz="http://www.justep.com/xbiz#" type="http://www.w3.org/2001/XMLSchema#string">' + executorFID + '</xbiz:simple>' +
- '</parameter>' +
- '</parameters>';
- var xmlHttpRequest = justep.Request.sendBizRequest(sProcess, sActivity, "executeTaskAction", param, null, null, true);
- //执行抢占
- if (justep.Request.isSuccess(xmlHttpRequest)){
- var executor = justep.XML.getNodeText(justep.XML.eval(xmlHttpRequest.responseXML, "/root/data/*/executor", "single"));
- justep.Portal.openWindow(sName, encodeURI(taskURL), false, null, executor);
- }else{
- var message = justep.XML.eval(xmlHttpRequest.responseXML, "/root/message", "single");
- alert(justep.XML.getNodeText(message));
- }
- }
复制代码 |
|