/*********************************************************************** * System : NLMRPII * Date : 2010-11-21 * Author : Livon * Description : Comment (评论、注释) 的相关通用操作 ************************************************************************/ /*********************************************************************** * Title : 获取评论数据 * Author : Livon * Date : 2010-11-22 一 ************************************************************************/ function getComment( category, id ){ table_showMessage( "comment_tbody", "Loading ... "); // @table.js category = ToUnicode(category); xhrUrl = "comment.action?actionType=select&pageSize=5" + "&category=" + category + "&recordId=" + id ; dojo.xhrPost({ //Ajax请求。 url: xhrUrl , handleAs: "json", load: function(response) { if( response.code == 0){ // alert(1); fillCommentTbody( response ); }else{ table.showMessage("Data_List_Container", response.message ); // alert( "ERROR: " + response.code + " - " + response.message ); alert( response.message ); } }, error: function(error) { alert("[ comment.js / getComment() ] :An unexpected error occurred: " + error); } }); console.info("杨力权"); } /*********************************************************************** * Title : 向评论的表格中填充数据 * Author : Livon * Date : 2010-11-22 一 ************************************************************************/ function fillCommentTbody( response ){ var list = response.commentList ; //数据列表,类型:Json 。 if( list.length > 0 ){ table_dataClear( "comment_tbody" ); for (var i=0; i< list.length; i++) { // 定义 行数据 数组。 var arrRowCells = new Array(); arrRowCells[0] = list[i].commentId; arrRowCells[1] = list[i].content; arrRowCells[2] = list[i].user; arrRowCells[3] = list[i].dateTime; arrRowCells[4] = list[i].clientIP; // 插入行。 table_insertRow( "comment_tbody", arrRowCells); // 位于 js/table.js } }else{ table_showMessage( "comment_tbody", response.message); // 提示查询结果无记录。 } dojo.publish("promptMessageTopic", [{message: "评论数据已更新。",type: "message", duration: 3000}]); } /*********************************************************************** * Title : 添加评论 * Author : Livon * Date : 2010-11-21 ************************************************************************/ function addComment( category, id, content ){ xhrUrl = "comment.action?actionType=insert" + "&category=" +ToUnicode(category) + "&recordId=" + id + "&content=" + ToUnicode(content) ; dojo.xhrPost({ //Ajax请求。 url: xhrUrl , handleAs: "json", load: function(response) { if(response.code == "0") getComment( category, id ) else alert("[ comment.js / addComment() ] " + response.message); }, error: function(error) { alert("内容过多,请拆分。" +error); } }); dojo.publish("promptMessageTopic", [{message: "数据已更新。",type: "message", duration: 3000}]); } /*********************************************************************** * Title : 更多评论 * Author : LIU.YAN * Date : 2010-12-24 * Parameters: category - 评论类别;recordId - 记录ID。 ************************************************************************/ function commentMore(category,recordId){ category=ToUnicode(category); recordId=recordId || 0; window.location.href="comment.action?actionType=more&category="+category+"&recordId="+recordId; } // js 类:Comment 评论、注释。 var Comment={ // 初始化。 // parameters: category - 类别,recordId - 记录ID,container - 容器DIV init: function( category, recordId, container ){ titlePane = new dijit.TitlePane({ id: "CommentTitlePane", title: "评论、注释:", open: false, content: '<div id="titlePaneContent" style="width:100%;"><table class="DataListTable"> <thead> <tr> <th>ID</th> <th>内容</th> <th>评论人</th> <th>时间</th> <th>IP</th> </tr> </thead> <tbody id="comment_tbody"><tr><td colspan="99">数据读取中 ...</td></tr></tbody><tfoot></tfoot> </table><br /> </div> ' }); editor = new dijit.Editor({ id: "commentContent_textarea", name: "commentContent_textarea", height: "100px", style: "border-top: 1px solid #BFBFBF;", plugins: ['bold','underline','insertOrderedList','indent','outdent','|','foreColor','|','fullscreen','viewsource'] }); saveButton = new dijit.form.Button({ label: "save", iconClass: "dijitEditorIcon dijitEditorIconSave" , style: "margin:10px 10px 0px 0px;", onClick: function(){ Comment.add( category, recordId, dijit.byId('commentContent_textarea').getValue() ); } }); moreLink = document.createElement("a"); moreLink.href = "javascript:Comment.more('" + category + "','" + recordId + "');"; moreLink.innerHTML = "more"; dojo.byId( container ).appendChild( document.createElement("br") ); dojo.byId( container ).appendChild( titlePane.domNode ); dojo.byId( container ).appendChild( document.createElement("br") ); dojo.byId( "titlePaneContent" ).appendChild( editor.domNode ); dojo.byId( "titlePaneContent" ).appendChild( saveButton.domNode ); dojo.byId( "titlePaneContent" ).appendChild( moreLink ); Comment.get( category, recordId ); }, // 读取列表 get: function( category, id ){ table_showMessage( "comment_tbody", "Loading ... "); // @table.js category = ToUnicode(category); xhrUrl = "comment.action?actionType=select&pageSize=5" + "&category=" + category + "&recordId=" + id ; dojo.xhrPost({ //Ajax请求。 url: xhrUrl , handleAs: "json", load: function(response) { if(response.code == "0"){ fillCommentTbody( response ); }else{ table_showMessage( "comment_tbody", response.message); alert( response.message ); } }, error: function(error) { alert("[ comment.js / getComment() ] :An unexpected error occurred: " + error); } }); console.info("杨力权"); }, // 添加评论。 add: function( category, id, content ){ xhrUrl = "comment.action?actionType=insert" + "&category=" + ToUnicode(category) + "&recordId=" + id + "&content=" + ToUnicode(content) ; dojo.xhrPost({ //Ajax请求。 url: xhrUrl , handleAs: "json", load: function(response) { if(response.code == "0") getComment( category, id ) else alert("[ comment.js / addComment() ] " + response.message); }, error: function(error) { alert("内容过多,请拆分。" +error); } }); dojo.publish("promptMessageTopic", [{message: "数据已更新。",type: "message", duration: 3000}]); }, // 更多评论。 more: function( category, recordId ){ category=ToUnicode(category); recordId=recordId || 0; window.location.href="comment.action?actionType=more&category="+category+"&recordId="+recordId; }, test: function(name, recordId, container){ alert( container ); } };