隨筆-9  評論-168  文章-266  trackbacks-0

          思路: 先查詢出所有數(shù)據(jù)的根結(jié)點(diǎn),并對每個根結(jié)點(diǎn)檢查是不是有子結(jié)點(diǎn),如果有子結(jié)點(diǎn)則在顯示時增加"+"圖片,沒有則不添加.但用戶點(diǎn)擊"+"圖片時,則通過AJAX調(diào)用邏輯流查詢觸發(fā)結(jié)點(diǎn)的所有子結(jié)點(diǎn)(采用遞歸方式,以每個子結(jié)點(diǎn)的父結(jié)點(diǎn)屬性從上向下查詢),并隱藏加載到觸發(fā)結(jié)點(diǎn)后面(以TR形式添加,并設(shè)置每個子元素的paraTaskno屬性為父結(jié)點(diǎn)taskno(其實(shí)仍是以遞歸方式,從上向下給每個子元素的paraTaskno屬性設(shè)置父元素的id)

          服務(wù)端數(shù)據(jù): 僅查詢根結(jié)點(diǎn).

          html代碼:
           
          <viewlist id="e587ead4-daa3-431e-a0ed-fac40e013850">
            <h:form name="page_form" action="com.bos.mp.taskStatistics.TaskStatistics.flow" method="post">
              <input type="hidden" name="_eosFlowAction" value="pageQuery" >
              <h:hiddendata property="criteria" />
              <h:hidden property="page/begin"/>
              <h:hidden property="page/length"/>
              <h:hidden property="page/count"/>
              <h:hidden property="page/isCount"/>
              <w:panel id="list_panel" width="100%" title="任務(wù)列表">
                <table align="center" border="0" width="100%" class="EOS_table">
                  <tr id="table_header">       
                    <th>
                      任務(wù)名稱
                    </th>
                    <th>
                      項(xiàng)目名稱
                    </th>
                    <th>
                      項(xiàng)目模塊
                    </th>
                    <th>
                      工作占項(xiàng)目比率
                    </th>
                    <th>
                      負(fù)責(zé)人
                    </th>
                 <th>
                      審核人
                    </th>
                    <th>
                      計(jì)劃開始日
                    </th>
                     <th>
                      計(jì)劃完成日
                    </th>
                    <th>
                      任務(wù)狀態(tài)
                    </th>
                    <th>
                     完成率(%)
                    </th>
                    <th>
                     更新日期
                    </th>
                    <th>
                     原因
                    </th>
                    <th>
                     實(shí)際完成率(%)
                    </th>
                    <th>
                     實(shí)際完成日
                    </th>
                    <th>
                     提前/滯后完成天數(shù)
                    </th>
                  </tr>
                  <w:checkGroup id="group1">
                    <l:iterate property="mpprojectfollows" id="id1">
                     <%
                      long temp = 0;
                      if(null != ((DataObject)pageContext.getAttribute("id1")).getString("proEndDate")){
                       DataObject t=(DataObject)pageContext.getAttribute("id1");
                       String d1 = ((DataObject)pageContext.getAttribute("id1")).getString("comDate") == null ? new SimpleDateFormat("yyyy-MM-dd").format(new Date()):((DataObject)pageContext.getAttribute("id1")).getString("comDate");
                       String d2 = ((DataObject)pageContext.getAttribute("id1")).getString("proEndDate");
                       temp = RetOrgInfo.daysDifference(d1,d2);
                      }
                      if(temp<0 && !((DataObject)pageContext.getAttribute("id1")).getString("taskStatus").equals("完成")){
                       out.print("<tr class='EOS_table_row' style='background-color:red;' id='"+((DataObject)pageContext.getAttribute("id1")).getString("taskno")+"'>");
                      }else if(temp<0 && ((DataObject)pageContext.getAttribute("id1")).getString("taskStatus").equals("完成")){
                       out.print("<tr class='EOS_table_row' style='background-color:orange;' id='"+((DataObject)pageContext.getAttribute("id1")).getString("taskno")+"'>");
                      }else if(temp>0 && ((DataObject)pageContext.getAttribute("id1")).getString("taskStatus").equals("完成")){
                       out.print("<tr class='EOS_table_row'  style='background-color:green;' id='"+((DataObject)pageContext.getAttribute("id1")).getString("taskno")+"'>");
                      }else{
                       out.print("<tr class='EOS_table_row' id='"+((DataObject)pageContext.getAttribute("id1")).getString("taskno")+"'>");
                      }
                      %>
                     
                       <td align="left" >
                       <l:present  property="childTasks" iterateId="id1">
                         <img src="<%=request.getContextPath() %>/common/skins/default/images/grouppanel/grouppanel_open.gif" onclick="node_click('<b:write iterateId="id1" property="taskno"/>');"/>
                        </l:present>
                        <h:hidden iterateId="id1" property="paraTaskno"/>

                          <a href="#" onclick="javascript:showTaskDet('<b:write iterateId="id1" property="taskno"/>');"><b:write iterateId="id1" property="taskName"/></a>
                        </td>
                        <td align="center">
                          <b:write iterateId="id1" property="projectName"/>
                        </td>
                        <td align="center">
                          <b:write iterateId="id1" property="modName"/>
                        </td>
                        <td align="center">
                          <b:write iterateId="id1" property="taskRate"/>
                          <l:notEmpty iterateId="id1" property="taskRate">
                           %
                          </l:notEmpty>
                        </td>
                        <td align="center">
                          <b:write iterateId="id1" property="planPres"/>
                        </td>
                        <td align="center">
                          <b:write iterateId="id1" property="auditorName"/>
                        </td>
                        <td align="center">
                          <b:write iterateId="id1" property="proStarDate" formatPattern="yyyy-MM-dd"/>
                        </td>
                        <td align="center">
                          <b:write iterateId="id1" property="proEndDate" formatPattern="yyyy-MM-dd"/>
                        </td>
                         <td align="center">
                          <b:write iterateId="id1" property="taskStatus"/>
                        </td>     
                        <td align="center">
                          <b:write iterateId="id1" property="actorRated"/>
                        </td>
                        <td align="center">
                          <b:write iterateId="id1" property="actorDate" formatPattern="yyyy-MM-dd"/>
                        </td>
                        <td align="center">
                          <b:write iterateId="id1" property="reason"/>
                        </td>
                        <td align="center">
                          <b:write iterateId="id1" property="auditRate"/>
                        </td>
                         <td align="center">
                          <b:write iterateId="id1" property="comDate" formatPattern="yyyy-MM-dd"/>
                        </td>
                        <td align="center">
                         <%
                          if(temp<0){
                           out.print("滯后"+Math.abs(temp)+"天");
                          }else if(temp>0 && ((DataObject)pageContext.getAttribute("id1")).getString("taskStatus").equals("完成")){
                           out.print("提前"+temp+"天");
                          }
                          %>
                        </td>
                      </tr>
                    </l:iterate>
                  </w:checkGroup>
                  <tr>
                    <td colspan="16" class="command_sort_area">
                     <div id="pageroot" align="right">
                        <l:equal property="page/isCount" targetValue="true">
                          共
                          <b:write property="page/count"/>
                          條記錄 第
                          <b:write property="page/currentPage"/>
                          頁/
                          <b:write property="page/totalPage"/>
                          頁
                        </l:equal>
                        <l:equal property="page/isCount" targetValue="false">
                          第
                          <b:write property="page/currentPage"/>
                          頁
                        </l:equal>
                        <input type="button" onclick="firstPage('page', 'pageQuery', null, null, 'page_form');" value="首頁"  <l:equal property="page/isFirst" targetValue="true">disabled</l:equal> >
                        <input type="button" onclick="prevPage('page', 'pageQuery', null, null, 'page_form');" value="上頁" <l:equal property="page/isFirst" targetValue="true">disabled</l:equal> >
                        <input type="button" onclick="nextPage('page', 'pageQuery', null, null, 'page_form');" value="下頁" <l:equal property="page/isLast" targetValue="true">disabled</l:equal> >
                        <l:equal property="page/isCount" targetValue="true">
                          <input type="button" onclick="lastPage('page', 'pageQuery', null, null, 'page_form');" value="尾頁" <l:equal property="page/isLast" targetValue="true">disabled</l:equal> >
                        </l:equal>
                      </div>
                    </td>
                  </tr>
                </table>
              </w:panel>
            </h:form>
          </viewlist>



          <script> 
          var jquery = jQuery.noConflict();
              //主結(jié)點(diǎn)展開/收起
              function node_click(taskid){
                 var el=jquery("#"+taskid).find("img")[0]//event.srcElement
                 var path=el.src.substr(el.src.lastIndexOf("/")+1)
                 var prifix=el.src.substr(0,el.src.lastIndexOf("/"))
                 if(path=="grouppanel_open.gif"){
                    //顯示結(jié)點(diǎn)
                    var tr=jquery(el).closest("tr");
                    if(jquery(el).closest("tr").next().css("display")=="none"){
                      el.src=prifix+"/grouppanel_close.gif";
                      tr.nextAll("tr[paraTaskno='"+tr.attr("id")+"']").show();
                    }else{
                      readchildnodeByAjax(taskid);
                      jquery(el).trigger("click");
                    }
                   
                 }else{
                    //隱藏結(jié)點(diǎn)
                    el.src=prifix+"/grouppanel_open.gif";
                    var tr=jquery(el).closest("tr");
                    recursion_node(tr,false);
                 }
              }
             
              //ajax讀取子結(jié)點(diǎn)
              function readchildnodeByAjax(taskid){
                 var myAjax=new Ajax("com.bos.mp.projectfollow.mpprojectfollowbiz.QueryTask.biz");
                 myAjax.addParam("criteria/_entity","com.bos.mp.projectfollow.dataset.ProTaskQryEntity");
                 myAjax.addParam("criteria/_expr[0]/paraTaskno",taskid);
                 myAjax.submit();
                 //獲取"root/data/mpprojectfollows"結(jié)點(diǎn)數(shù)組
                 var nodes=myAjax.getXMLDom().selectNodes("root/data/mpprojectfollows");
                 for(var i=0;i<nodes.length;i++){
                    addElement(jquery("#"+taskid),nodes[i]);
                 }
              }
             
              /**
               *動態(tài)增加tr結(jié)點(diǎn),以請求的服務(wù)端數(shù)據(jù)來遍歷添加結(jié)點(diǎn)
               *template:html頁面元素;node:服務(wù)端數(shù)據(jù)子實(shí)體
               */
              function addElement(template,node){
                var xml=jquery(node);
                var template=addnode(template,xml)
                var childnodes=xml.children("childTasks");
                for(var i=0;i<childnodes.length&&jquery(xml.children("childTasks")[i]).text()!="";i++){
                    addElement(template,xml.children("childTasks")[i]);
                }
              }
              
              /**
               *以服務(wù)端的子實(shí)體對象(xml)構(gòu)造一個結(jié)點(diǎn)添加到html元素(template)
               */
              function addnode(template,xml){
                     var open_gif='<%=request.getContextPath() %>/common/skins/default/images/grouppanel/grouppanel_open.gif';
                     var close_gif="<%=request.getContextPath() %>/common/skins/default/images/grouppanel/grouppanel_close.gif"
                     //從模板結(jié)點(diǎn)構(gòu)造出目標(biāo)結(jié)點(diǎn)tr
                     var curtr=template.clone().insertAfter(template).hide()
                          .attr("id",jquery(xml.find("taskno")[0]).text())
                          .attr("paraTaskno",jquery(xml.find("paraTaskno")[0]).text());
                     //首個TD結(jié)點(diǎn)     
                     var firsttd=jquery(curtr.children("td")[0]);
                     var td=jquery(curtr.children("td")[0]).css("padding-left",parseInt(firsttd.css("padding-left"))+10+"px")
                         .empty();
                         jquery("<a href='#'></a>").text(jquery(xml.find("taskName")[0]).text())
                         .bind("click",function(){
                                          showTaskDet(jquery(xml.find("taskno")[0]).text());
                                       }).appendTo(td);
                     var img=jquery("<img/>").prependTo(td);
                     if(jquery(xml.children("childTasks")[0]).text()!=""){
                        //非葉子結(jié)點(diǎn),綁定事件
                        img.attr("src",open_gif);
                        img.bind("click",function(){
                                            var path=jquery(this).attr("src");
                                            var tr=jquery(this).closest("tr");
                                            if(path==open_gif){
                                               jquery(this).attr("src",close_gif);
                                               recursion_node(tr,true);
                                            }else{
                                               jquery(this).attr("src",open_gif);
                                               recursion_node(tr,false);
                                            }
                                           })
                      }else{
                        //葉子結(jié)點(diǎn)
                        img.attr("src",close_gif);
                      }
                      td.next().empty()//text(jquery(xml.find("projectName")[0]).text())
                      .next().empty()//text(jquery(xml.find("modName")[0]).text())
                      .next().text(jquery(xml.find("taskRate")[0]).text())
                      .next().text(jquery(xml.find("planPres")[0]).text())
                      .next().text(jquery(xml.find("auditorName")[0]).text())
                      .next().text(jquery(xml.find("proStarDate")[0]).text())
                      .next().text(jquery(xml.find("proEndDate")[0]).text())
                      .next().text(jquery(xml.find("taskStatus")[0]).text())
                      .next().text(jquery(xml.find("actorRated")[0]).text())
                      .next().text(jquery(xml.find("actorDate")[0]).text())
                      .next().text(jquery(xml.find("reason")[0]).text())
                      .next().text(jquery(xml.find("auditRate")[0]).text())
                      .next().text(jquery(xml.find("comDate")[0]).text())
                      .next().text("");
                      return curtr;
                }
             
              /**
               *層疊遞歸方式顯示或隱藏結(jié)點(diǎn)
               * node:jquery對象;isshow:boolean值
               */
              function recursion_node(node,isshow){
                var open_gif='<%=request.getContextPath() %>/common/skins/default/images/grouppanel/grouppanel_open.gif';
                var close_gif="<%=request.getContextPath() %>/common/skins/default/images/grouppanel/grouppanel_close.gif"
                var nodes=node.nextAll("tr[paraTaskno='"+node.attr("id")+"']")

                for(var i=0;i<nodes.length;i++){
                    recursion_node(jquery(nodes[i]),isshow);
                    if(!isshow){
                      jquery(nodes[i]).hide();
                    }else{
                     jquery(nodes[i]).show();
                    }
                }
                if(nodes.length>0){
                jquery(node.find("img")[0]).attr("src",!isshow?open_gif:close_gif)
                }

              }

          </script>
          posted on 2011-04-01 17:39 紫蝶∏飛揚(yáng)↗ 閱讀(1386) 評論(0)  編輯  收藏 所屬分類: div+css+js代碼EOS
          主站蜘蛛池模板: 仙居县| 东乡| 汤阴县| 清原| 灵台县| 黄石市| 防城港市| 孟州市| 萨嘎县| 巴林右旗| 长垣县| 黄石市| 虞城县| 会同县| 东源县| 泽普县| 克拉玛依市| 普洱| 香港| 纳雍县| 阳朔县| 十堰市| 巴马| 洛浦县| 镇坪县| 开封县| 昔阳县| 自治县| 阿拉善左旗| 漳州市| 柯坪县| 嘉定区| 商河县| 凯里市| 岳普湖县| 北宁市| 枣阳市| 镇远县| 遵义市| 东源县| 淮滨县|