Comment.js 30 KB

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