Comment.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. MWF.xApplication.cms.Xform.widget = MWF.xApplication.cms.Xform.widget || {};
  2. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  3. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  4. var O2CMSComment = MWF.xApplication.cms.Xform.widget.Comment = new Class({
  5. Implements: [Options, Events],
  6. Extends: MWF.widget.Common,
  7. options: {
  8. "style": "simple",
  9. "documentId" : "",
  10. "anonymousAccess" : false,
  11. "countPerPage" : 10
  12. },
  13. initialize: function (app, node, options) {
  14. this.setOptions(options);
  15. this.app = app;
  16. this.node = node;
  17. this.path = "../x_component_cms_Xform/widget/$Comment/";
  18. this.cssPath = "../x_component_cms_Xform/widget/$Comment/" + this.options.style + "/css.wcss";
  19. this._loadCss();
  20. MWF.xDesktop.requireApp("cms.Xform", "lp."+MWF.language, null, false);
  21. this.lp = MWF.xApplication.cms.Xform.LP;
  22. this.actions = MWF.Actions.get("x_cms_assemble_control");
  23. },
  24. load : function(){
  25. this.items = [];
  26. this.documents = {};
  27. this.isItemsLoaded = false;
  28. this.isItemLoadding = false;
  29. this.loadItemQueue = 0;
  30. this.count = 0;
  31. this.lineHeight = this.options.mode != "text" ? 32 : 25;
  32. var countPerPage = this.options.countPerPage;
  33. if( !countPerPage || countPerPage==0 || isNaN(countPerPage) || parseInt(countPerPage) < 1 ){
  34. this.options.countPerPage = 10;
  35. }
  36. this.container = new Element("div",{styles:this.css.container}).inject( this.node );
  37. this.loadTitle();
  38. this.loadContent();
  39. //this.loadElementList();
  40. //this.loadBottom();
  41. this.loadEditor();
  42. },
  43. loadTitle : function(){
  44. this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.lp.commentTitle}).inject(this.container);
  45. },
  46. loadTotal: function(){
  47. this.titleCountNode = new Element("div", {
  48. styles : this.css.titleCountNode,
  49. text : this.lp.commentCountText.replace("{count}" , this.dataCount)
  50. }).inject(this.titleNode);
  51. },
  52. loadContent : function(){
  53. this.contentConainer = new Element("div.contentConainer",{
  54. "styles" : this.css.contentConainer
  55. }).inject( this.container );
  56. this.createPagingBar();
  57. this.viewConainer = new Element("div.viewConainer",{
  58. //"styles" : this.css.viewConainer
  59. }).inject( this.contentConainer );
  60. this.createPagingBar();
  61. this.createView();
  62. },
  63. createPagingBar: function(){
  64. var pagingArea = new Element("div",{
  65. styles : this.css.pagingArea
  66. }).inject(this.contentConainer);
  67. if( this.pagingBarTop ){
  68. this.pagingBarBottom = pagingArea;
  69. }else{
  70. this.pagingBarTop = pagingArea;
  71. }
  72. var pagingContainer = new Element("div").inject(pagingArea);
  73. if( this.pagingContainerTop ){
  74. this.pagingContainerBottom = pagingContainer;
  75. }else{
  76. this.pagingContainerTop = pagingContainer;
  77. }
  78. },
  79. //loadBottom: function(){
  80. // var bottomNode = new Element("div",{
  81. // "styles" : this.css.bottomNode
  82. // }).inject( this.container );
  83. // var resizeNode = new Element("div",{
  84. // "styles" : this.css.bottomResizeNode,
  85. // "text" : "◢"
  86. // }).inject(bottomNode);
  87. //
  88. // var xLimit = this.contentScrollNode.getSize().x;
  89. //
  90. // this.contentScrollNode.makeResizable({
  91. // "handle": resizeNode,
  92. // "limit": {x:[xLimit, xLimit], y:[50, null]},
  93. // "onDrag": function(){
  94. // var y = this.contentScrollNode.getSize().y;
  95. // if( y > ( this.lineHeight * this.countPerPage - 20 ) ){
  96. // this.countPerPage = parseInt( y / this.lineHeight ) + 2
  97. // }
  98. // this.contentScrollNode.fireEvent("resize");
  99. // }.bind(this),
  100. // "onComplete": function(){
  101. // this.scrollBar.checkScroll();
  102. // this.loadElementList();
  103. // }.bind(this)
  104. // });
  105. //},
  106. getShortName : function( dn ){
  107. if( dn && dn.contains("@") ){
  108. return dn.split("@")[0];
  109. }else{
  110. return dn;
  111. }
  112. },
  113. createView : function( ){
  114. this.view = new O2CMSComment.View( this.viewConainer, null, this, {
  115. templateUrl : this.path + this.options.style + "/listItem.json",
  116. scrollEnable : false,
  117. pagingEnable : true,
  118. documentKeyWord : "orderNumber",
  119. pagingPar : {
  120. currentPage : 1,
  121. currentItem : 1,
  122. hasReturn : false ,
  123. countPerPage : this.options.countPerPage,
  124. onPostLoad : function( pagingBar ){
  125. if(pagingBar.nextPageNode){
  126. pagingBar.nextPageNode.inject( this.pagingBarBottom, "before" );
  127. }
  128. }.bind(this)
  129. },
  130. onGotoItem : function( top ){
  131. //var t = top; // - this.content.getTop();
  132. //this.contentContainerNode.scrollTo( 0, t );
  133. }.bind(this),
  134. onPostCreateViewBody : function(){
  135. if( this.view.dataCount <= this.options.countPerPage ){
  136. this.pagingBarTop.hide();
  137. this.pagingBarBottom.hide();
  138. }else{
  139. this.pagingBarTop.show();
  140. this.pagingBarBottom.show();
  141. }
  142. if( !this.view.dataCount ){
  143. this.view.node.hide()
  144. }else{
  145. this.view.node.show();
  146. }
  147. }.bind(this),
  148. onPostDeleteDocument : function(){
  149. this.view.reload();
  150. }.bind(this)
  151. }, {
  152. app : this.app
  153. });
  154. this.view.pagingContainerTop = this.pagingContainerTop;
  155. this.view.pagingContainerBottom = this.pagingContainerBottom;
  156. //this.view.data = this.data;
  157. this.view.filterData = { "documentId" : this.options.documentId, "orderField" : "createTime", "orderType" : "ASC" };
  158. this.view.load();
  159. },
  160. loadEditor : function( ){
  161. this.editorArea = new Element("div.editorArea",{
  162. "styles" : this.css.commentArea
  163. }).inject( this.container );
  164. this.editor = new O2CMSComment.Editor( this.editorArea, this, {
  165. style : this.options.style,
  166. isNew : true,
  167. onPostOk : function( id ){
  168. this.postCreateComment( id )
  169. }.bind(this)
  170. } );
  171. this.editor.mainData = this.data;
  172. this.editor.load();
  173. },
  174. postCreateComment : function(){
  175. this.view.reload();
  176. },
  177. isAnonymous : function(){
  178. return this.options.anonymousAccess;
  179. },
  180. getUserIcon: function( name ){
  181. var icon = "";
  182. //var url = MWF.Actions.get("x_organization_assemble_personal").getIcon(name);
  183. //if( url ){
  184. // icon = url;
  185. //}else{
  186. // icon = "../x_component_ForumDocument/$Main/default/icon/noavatar_big.png";
  187. //}
  188. //return icon;
  189. this.getUserData( name, function( json ){
  190. if( json && json.data && json.data.icon ){
  191. icon = json.data.icon;
  192. }else{
  193. icon = "../x_component_cms_Xform/widget/$Comment/"+this.options.style+"/icon/noavatar_big.png";
  194. }
  195. });
  196. return icon;
  197. },
  198. getUserData : function( name, callback ){
  199. if( this.userCache && this.userCache[name] ){
  200. if( callback )callback( this.userCache[name] );
  201. return
  202. }
  203. if( !this.userCache )this.userCache = {};
  204. if( this.isAnonymous() ){
  205. var url = MWF.Actions.get("x_organization_assemble_personal").getIcon(name);
  206. if( url ){
  207. var json = { data : { icon : url } };
  208. this.userCache[ name ] = json;
  209. if( callback )callback( json );
  210. }else{
  211. var json = { data : { icon : "../x_component_cms_Xform/widget/$Comment/"+this.options.style+"/icon/noavatar_big.png" } };
  212. this.userCache[ name ] = json;
  213. if( callback )callback( json );
  214. }
  215. }else{
  216. MWF.Actions.get("x_organization_assemble_control").getPerson( function( json ){
  217. if( !json.data )json.data = {};
  218. var url = MWF.Actions.get("x_organization_assemble_personal").getIcon(name);
  219. if( url ){
  220. if( json.data ){
  221. json.data.icon = url;
  222. this.userCache[ name ] = json;
  223. if( callback )callback( json );
  224. }
  225. }else{
  226. if( json.data ){
  227. json.data.icon = "../x_component_cms_Xform/widget/$Comment/"+this.options.style+"/icon/noavatar_big.png";
  228. this.userCache[ name ] = json;
  229. if( callback )callback( json );
  230. }
  231. }
  232. //MWF.Actions.get("x_organization_assemble_control").getPersonIcon(name, function(url){
  233. // if( json.data ){
  234. // json.data.icon = url;
  235. // this.userCache[ name ] = json;
  236. // if( callback )callback( json );
  237. // }
  238. //}.bind(this), function(){
  239. // if( json.data ){
  240. // json.data.icon = "../x_component_ForumDocument/$Main/"+this.options.style+"/icon/noavatar_big.png";
  241. // this.userCache[ name ] = json;
  242. // if( callback )callback( json );
  243. // }
  244. //}.bind(this));
  245. }.bind(this), function(){
  246. var json = { data : { icon : "../x_component_cms_Xform/widget/$Comment/"+this.options.style+"/icon/noavatar_big.png" } };
  247. this.userCache[ name ] = json;
  248. if( callback )callback( json );
  249. }.bind(this), name, true )
  250. }
  251. }
  252. });
  253. O2CMSComment.getDateDiff = function (publishTime ) {
  254. if(!publishTime)return "";
  255. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  256. var minute = 1000 * 60;
  257. var hour = minute * 60;
  258. var day = hour * 24;
  259. var halfamonth = day * 15;
  260. var month = day * 30;
  261. var year = month * 12;
  262. var now = new Date().getTime();
  263. var diffValue = now - dateTimeStamp;
  264. if (diffValue < 0) {
  265. //若日期不符则弹出窗口告之
  266. //alert("结束日期不能小于开始日期!");
  267. }
  268. var yesterday = new Date().decrement('day', 1);
  269. var beforYesterday = new Date().decrement('day', 2);
  270. var yearC = diffValue / year;
  271. var monthC = diffValue / month;
  272. var weekC = diffValue / (7 * day);
  273. var dayC = diffValue / day;
  274. var hourC = diffValue / hour;
  275. var minC = diffValue / minute;
  276. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  277. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  278. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  279. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  280. } else if (yearC > 1) {
  281. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  282. } else if (monthC >= 1) {
  283. //result= parseInt(monthC) + "个月前";
  284. // s.getFullYear()+"年";
  285. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  286. } else if (weekC >= 1) {
  287. result = parseInt(weekC) + "周前";
  288. } else if (dayC >= 1) {
  289. result = parseInt(dayC) + "天前";
  290. } else if (hourC >= 1) {
  291. result = parseInt(hourC) + "小时前";
  292. } else if (minC >= 1) {
  293. result = parseInt(minC) + "分钟前";
  294. } else
  295. result = "刚才";
  296. return result;
  297. };
  298. O2CMSComment.Editor = new Class({
  299. Implements: [Options , Events],
  300. options: {
  301. "style": "default",
  302. "isNew" : true
  303. },
  304. initialize: function(node, comment, options){
  305. this.setOptions(options);
  306. this.node = node;
  307. this.comment = comment;
  308. },
  309. load: function(){
  310. this.comment.actions.getUUID( function( id ){
  311. this.advanceCommentId = id;
  312. this._load();
  313. }.bind(this))
  314. },
  315. _load: function(){
  316. var html = "<div styles='itemNode'>" +
  317. " <div styles='itemLeftNode'>" +
  318. " <div styles='itemUserFace'>" +
  319. " <div styles='itemUserIcon' item='userIcon'>" +
  320. " </div>" +
  321. " </div>" +
  322. " <div styles='commentUserName' item='creatorName'>" +
  323. " </div>" +
  324. " </div>" +
  325. " <div styles='commentRightNode'>" +
  326. " <div styles='itemRightMidle'>" +
  327. " <div styles='itemBodyComment' item='content'></div>" +
  328. " <div styles='itemBodyComment' item='action'></div>" +
  329. " </div>" +
  330. " </div>" +
  331. "</div>";
  332. this.node.set("html", html);
  333. var actionTd = this.node.getElements("[item='action']")[0];
  334. this.saveCommentAction = new Element("div",{
  335. styles : this.comment.css.actionNode,
  336. text: this.comment.lp.saveComment
  337. }).inject(actionTd);
  338. this.saveCommentAction.addEvent("click",function(){
  339. this.saveComment();
  340. }.bind(this));
  341. var rtfConfig = {
  342. //skin : "bootstrapck",
  343. "resize_enabled": false,
  344. isSetImageMaxWidth : true,
  345. reference : this.advanceCommentId,
  346. referenceType: "forumReply",
  347. //uiColor : '#9AB8F3',
  348. //toolbarCanCollapse : true,
  349. toolbar : [
  350. //{ name: 'document', items : [ 'Preview' ] },
  351. //{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
  352. //{ name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','-','RemoveFormat' ] },
  353. //{ name: 'paragraph', items : [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },
  354. //{ name: 'styles', items : [ 'Font','FontSize' ] },
  355. //{ name: 'colors', items : [ 'TextColor','BGColor' ] },
  356. //{ name: 'links', items : [ 'Link','Unlink' ] },
  357. { name: 'insert', items : [ 'Image' ] }
  358. //{ name: 'tools', items : [ 'Maximize','-','About' ] }
  359. ]
  360. };
  361. if( this.comment.options.editorProperties ){
  362. rtfConfig = Object.merge( rtfConfig, this.comment.options.editorProperties )
  363. }
  364. MWF.xDesktop.requireApp("Template", "MForm", function () {
  365. this.form = new MForm(this.node, this.data || {}, {
  366. style: "forum",
  367. isEdited: true,
  368. itemTemplate: {
  369. userIcon: { className : "itemUserIcon2", type : "img", value : function(){
  370. if( layout.session.user.icon ){
  371. return "data:image/png;base64," + layout.session.user.icon
  372. }else{
  373. return "../x_component_cms_Xform/widget/$Comment/"+this.options.style+"/icon/noavatar_big.png"
  374. }
  375. }.bind(this)},
  376. creatorName: { type : "innerText", value : layout.session.user.name },
  377. content: { type : "rtf", RTFConfig : rtfConfig }
  378. }
  379. }, this, this.comment.css);
  380. this.form.load();
  381. }.bind(this), true);
  382. },
  383. saveComment : function(){
  384. var data = this.form.getResult(true, ",", true, false, true);
  385. if (data) {
  386. data.documentId = this.comment.options.documentId;
  387. data.id = this.advanceCommentId;
  388. delete data.userIcon;
  389. this.comment.actions.saveComment(data, function (json) {
  390. if (json.type == "error") {
  391. this.comment.app.notice(json.message, "error");
  392. } else {
  393. this.comment.actions.getUUID( function( id ){
  394. this.advanceCommentId = id;
  395. }.bind(this));
  396. this.comment.app.notice( this.comment.lp.saveCommentSuccess, "ok" );
  397. this.form.getItem("content").setValue("");
  398. this.fireEvent("postOk", json.data.id);
  399. }
  400. }.bind(this))
  401. }
  402. }
  403. });
  404. O2CMSComment.View = new Class({
  405. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  406. _createDocument: function(data, index){
  407. data.index = index;
  408. return new O2CMSComment.Document(this.viewNode, data, this.explorer, this, null, data.index );
  409. },
  410. _getCurrentPageData: function(callback, count, pageNum){
  411. this.clearBody();
  412. if(!count)count=10;
  413. if(!pageNum)pageNum = 1;
  414. //page, count, filterData, success,failure, async
  415. //if( !this.page ){
  416. // this.page = 1;
  417. //}else{
  418. // this.page ++;
  419. //}
  420. //var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  421. var filter = this.filterData || {};
  422. this.actions.listCommentPageWithFilter( pageNum, count, filter, function(json){
  423. if( !json.data )json.data = [];
  424. if( !json.count )json.count=0;
  425. if( callback )callback(json);
  426. }.bind(this))
  427. },
  428. _removeDocument: function(documentData, all){
  429. this.actions.deleteComment( documentData.id, function(){
  430. this.reload();
  431. this.app.notice( this.lp.deleteCommentSuccess, "ok")
  432. }.bind(this) )
  433. },
  434. _create: function(){
  435. },
  436. _queryCreateViewNode: function(){
  437. },
  438. _postCreateViewNode: function( viewNode ){
  439. },
  440. _queryCreateViewHead:function(){
  441. },
  442. _postCreateViewHead: function( headNode ){
  443. }
  444. });
  445. O2CMSComment.Document = new Class({
  446. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  447. mouseoverSubject : function(subjectNode, ev){
  448. //var removeNode = sectionNode.getElements("[styles='sectionRemoveNode']")[0];
  449. //if( removeNode )removeNode.setStyle("opacity",1)
  450. },
  451. mouseoutSubject : function(subjectNode, ev){
  452. //var removeNode = sectionNode.getElements("[styles='sectionRemoveNode']")[0];
  453. //if( removeNode )removeNode.setStyle("opacity",0)
  454. },
  455. getUserData : function( name, callback ){
  456. this.view.explorer.getUserData( name, callback );
  457. },
  458. _queryCreateDocumentNode:function( itemData ){
  459. },
  460. _postCreateDocumentNode: function( itemNode, itemData ){
  461. var userIcon = itemNode.getElements( "[item='userIcon']" )[0];
  462. //var signatureContainer = itemNode.getElements("[item='signatureContainer']")[0];
  463. this.getUserData( itemData.creatorName, function(json ){
  464. userIcon.src = json.data.icon;
  465. //if( json.data.signature && json.data.signature!="" ){
  466. // var signatureNode = signatureContainer.getElements("[item='signature']")[0];
  467. // signatureNode.set("text", json.data.signature )
  468. //}else{
  469. // signatureContainer.destroy();
  470. //}
  471. }.bind(this) );
  472. if( itemData.parentId && itemData.parentId != "" ){
  473. var quoteContainer = itemNode.getElements( "[item='quoteContent']" )[0];
  474. this.actions.getComment( itemData.parentId, function( json ){
  475. var data = this.parentData = json.data;
  476. var quoteContent = new Element("div", { "styles" : this.css.itemQuote }).inject(quoteContainer);
  477. var content = quoteContent.set("html", data.content).get("text");
  478. quoteContent.empty();
  479. data.contentText = content;
  480. new Element( "div", {styles : this.css.quoteLeftBig} ).inject( quoteContent );
  481. var quoteArea = new Element( "div", {styles : this.css.quoteAreaBig } ).inject( quoteContent );
  482. var quoteInfor = new Element( "div", {
  483. styles : this.css.quoteInforBig,
  484. text : data.orderNumber + this.lp.floor + ":" + data.creatorName.split('@')[0] + this.lp.publishAt + data.createTime
  485. }).inject( quoteArea );
  486. quoteInfor.addEvent("click", function(){
  487. this.obj.app.gotoComment( this.index )
  488. }.bind({obj : this, index : data.orderNumber || (data.index + 2) }));
  489. new Element( "div", {
  490. styles : this.css.quoteTextBig,
  491. text : content.length > 100 ? (content.substr(0, 100) + "...") : content
  492. }).inject( quoteArea );
  493. new Element( "div", {styles : this.css.quoteRightBig} ).inject( quoteContent );
  494. }.bind(this) , function( json ){
  495. new Element( "div" , {
  496. "styles" : this.css.commentBeinngDelete,
  497. "text" : this.lp.quoteCommentBeingDeleted
  498. }).inject(quoteContainer)
  499. }.bind(this)
  500. )
  501. }
  502. },
  503. sendMessage : function(itemNode, ev ){
  504. var self = this;
  505. if (layout.desktop.widgets["IMIMWidget"]) {
  506. var IM = layout.desktop.widgets["IMIMWidget"];
  507. IM.getOwner(function(){
  508. this.openChat(ev, {
  509. from : self.data.creatorName
  510. });
  511. }.bind(IM));
  512. }
  513. },
  514. createComment : function(itemNode, ev ){ // 对回复进行回复
  515. if( this.app.access.isAnonymousDynamic() ){
  516. this.app.openLoginForm( function(){ this.app.reload() }.bind(this) );
  517. }else{
  518. var form = new O2CMSComment.CommentForm(this, {}, {
  519. toMain: false,
  520. onPostOk: function (id) {
  521. this.app.postCreateComment(id)
  522. }.bind(this)
  523. });
  524. this.data.contentText = this.node.getElements("[item='content']")[0].get("text");
  525. form.mainData = this.app.data;
  526. form.parentData = this.data;
  527. form.create()
  528. }
  529. },
  530. editComment : function(itemNode, ev ){ //编辑当前回复
  531. var form = new O2CMSComment.Form(this, this.data, {
  532. documentId : this.explorer.options.documentId,
  533. toMain : (this.data.parentId && this.data.parentId!="") ? false : true,
  534. onPostOk : function( id ){
  535. MWF.Actions.get("x_cms_assemble_control").getComment( id, function( json ){
  536. var content = this.node.getElements("[item='content']")[0];
  537. content.set( "html", json.data.content );
  538. }.bind(this))
  539. }.bind(this)
  540. });
  541. //form.parentData = this.parentData;
  542. form.edit()
  543. },
  544. deleteComment : function( itemNode, ev ){
  545. var _self = this;
  546. this.view.app.confirm("warn", ev, this.lp.deleteCommentTitle, this.lp.deleteCommentText, 350, 120, function(){
  547. //_self.view._removeDocument(_self.data, false);
  548. _self.actions.deleteComment( _self.data.id, function(){
  549. _self.destroy();
  550. //_self.app.adjustCommentCount( -1 );
  551. _self.app.notice( _self.lp.deleteCommentSuccess, "ok");
  552. _self.view.fireEvent("postDeleteDocument");
  553. }.bind(this) );
  554. this.close();
  555. }, function(){
  556. this.close();
  557. });
  558. }
  559. });
  560. O2CMSComment.Form = new Class({
  561. Extends: MPopupForm,
  562. Implements: [Options, Events],
  563. options: {
  564. "style": "cms_xform",
  565. "width": "860",
  566. "height": "400",
  567. "hasTop": true,
  568. "hasIcon": false,
  569. "hasTopIcon" : true,
  570. "hasTopContent" : true,
  571. "hasBottom": true,
  572. "title": MWF.xApplication.cms.Xform.LP.commentFormTitle,
  573. "draggable": true,
  574. "closeAction": true,
  575. "toMain" : true
  576. },
  577. _createTableContent: function(){
  578. this.lp = MWF.xApplication.cms.Xform.LP;
  579. if( this.isNew ){
  580. MWF.Actions.get("x_cms_assemble_control").getUUID( function(id){
  581. this.advanceCommentId = id;
  582. this._createTableContent_();
  583. }.bind(this) )
  584. }else{
  585. this._createTableContent_()
  586. }
  587. },
  588. _createTableContent_: function () {
  589. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  590. //"<tr>" +
  591. //" <td styles='formTableValue14' item='mainSubject'></td>" +
  592. //"</tr>
  593. //"<tr>" +
  594. //" <td styles='formTableValue' item='mainContent'></td>" +
  595. //"</tr>" +
  596. "<tr>" +
  597. " <td styles='formTableValue' item='content'></td>" +
  598. "</tr>"+
  599. "</table>";
  600. this.formTableArea.set("html", html);
  601. //if( !this.options.toMain && this.parentData ){
  602. // var mainContentEl = this.formTableArea.getElements("[item='mainContent']")[0];
  603. //
  604. // var quoteTop = new Element( "div", {styles : this.css.quoteTop} ).inject( mainContentEl );
  605. // new Element( "div", {styles : this.css.quoteLeft} ).inject( quoteTop );
  606. // new Element( "div", {
  607. // styles : this.css.quoteInfor,
  608. // text : this.parentData.creatorName.split("@")[0] + this.lp.publishAt + this.parentData.createTime
  609. // }).inject( quoteTop );
  610. //
  611. // var quoteBottom = new Element( "div", {styles : this.css.quoteBottom} ).inject( mainContentEl );
  612. // var text = this.parentData.contentText;
  613. // new Element( "div", {
  614. // styles : this.css.quoteText,
  615. // text : text.length > 50 ? (text.substr(0, 50) + "...") : text
  616. // }).inject( quoteBottom );
  617. // new Element( "div", {styles : this.css.quoteRight} ).inject( quoteBottom );
  618. //}
  619. MWF.xDesktop.requireApp("Template", "MForm", function () {
  620. this.form = new MForm(this.formTableArea, this.data, {
  621. style: "cms",
  622. isEdited: true,
  623. itemTemplate: {
  624. //mainSubject: { type: "innertext", defaultValue : "RE:" + this.mainData.title },
  625. content: { type : "rtf", RTFConfig : {
  626. //skin : "bootstrapck",
  627. "resize_enabled": false,
  628. isSetImageMaxWidth : true,
  629. reference : this.advanceCommentId || this.data.id,
  630. referenceType: "forumReply",
  631. toolbar : [
  632. //{ name: 'document', items : [ 'Preview' ] },
  633. ////{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
  634. //{ name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','-','RemoveFormat' ] },
  635. ////{ name: 'paragraph', items : [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },
  636. //{ name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
  637. //{ name: 'colors', items : [ 'TextColor','BGColor' ] },
  638. //{ name: 'links', items : [ 'Link','Unlink' ] },
  639. { name: 'insert', items : [ 'Image' ] }
  640. //{ name: 'tools', items : [ 'Maximize','-','About' ] }
  641. ]
  642. }}
  643. }
  644. }, this.app, this.css);
  645. this.form.load();
  646. }.bind(this), true);
  647. },
  648. _createBottomContent: function () {
  649. this.cancelActionNode = new Element("div.formCancelActionNode", {
  650. "styles": this.css.formCancelActionNode,
  651. "text": this.lp.close
  652. }).inject(this.formBottomNode);
  653. this.cancelActionNode.addEvent("click", function (e) {
  654. this.cancel(e);
  655. }.bind(this));
  656. if (this.isNew || this.isEdited) {
  657. this.okActionNode = new Element("div.formOkActionNode", {
  658. "styles": this.css.formOkActionNode,
  659. "text": this.lp.ok
  660. }).inject(this.formBottomNode);
  661. this.okActionNode.addEvent("click", function (e) {
  662. this.ok(e);
  663. }.bind(this));
  664. }
  665. },
  666. ok: function (e) {
  667. this.fireEvent("queryOk");
  668. var data = this.form.getResult(true, ",", true, false, true);
  669. if (data) {
  670. this._ok(data, function (json) {
  671. if (json.type == "error") {
  672. this.app.notice(json.message, "error");
  673. } else {
  674. if(this.formMaskNode)this.formMaskNode.destroy();
  675. this.formAreaNode.destroy();
  676. this.app.notice(this.isNew ? this.lp.createCommentSuccess : this.lp.updateSuccess, "success");
  677. this.fireEvent("postOk", json.data.id);
  678. }
  679. }.bind(this))
  680. }
  681. },
  682. _ok: function (data, callback) {
  683. data.documentId = this.options.documentId ;
  684. if( this.advanceCommentId )data.id = this.advanceCommentId;
  685. delete data.userIcon;
  686. if( !this.options.toMain ){
  687. data.parentId = this.parentData.id ;
  688. }
  689. MWF.Actions.get("x_cms_assemble_control").saveComment( data, function(json){
  690. if( callback )callback(json);
  691. }.bind(this));
  692. }
  693. });