Comment.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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. MWF.xDesktop.requireApp("Template", "MForm", function () {
  342. this.form = new MForm(this.node, this.data || {}, {
  343. style: "forum",
  344. isEdited: true,
  345. itemTemplate: {
  346. userIcon: { className : "itemUserIcon2", type : "img", value : function(){
  347. if( layout.session.user.icon ){
  348. return "data:image/png;base64," + layout.session.user.icon
  349. }else{
  350. return "/x_component_cms_Xform/widget/$Comment/"+this.options.style+"/icon/noavatar_big.png"
  351. }
  352. }.bind(this)},
  353. creatorName: { type : "innerText", value : layout.session.user.name },
  354. content: { type : "rtf", RTFConfig : {
  355. //skin : "bootstrapck",
  356. "resize_enabled": false,
  357. isSetImageMaxWidth : true,
  358. reference : this.advanceCommentId,
  359. referenceType: "forumReply",
  360. //uiColor : '#9AB8F3',
  361. //toolbarCanCollapse : true,
  362. toolbar : [
  363. //{ name: 'document', items : [ 'Preview' ] },
  364. //{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
  365. //{ name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','-','RemoveFormat' ] },
  366. //{ name: 'paragraph', items : [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },
  367. //{ name: 'styles', items : [ 'Font','FontSize' ] },
  368. //{ name: 'colors', items : [ 'TextColor','BGColor' ] },
  369. //{ name: 'links', items : [ 'Link','Unlink' ] },
  370. { name: 'insert', items : [ 'Image' ] }
  371. //{ name: 'tools', items : [ 'Maximize','-','About' ] }
  372. ]
  373. }}
  374. }
  375. }, this, this.comment.css);
  376. this.form.load();
  377. }.bind(this), true);
  378. },
  379. saveComment : function(){
  380. var data = this.form.getResult(true, ",", true, false, true);
  381. if (data) {
  382. data.documentId = this.comment.options.documentId;
  383. data.id = this.advanceCommentId;
  384. delete data.userIcon;
  385. this.comment.actions.saveComment(data, function (json) {
  386. if (json.type == "error") {
  387. this.comment.app.notice(json.message, "error");
  388. } else {
  389. this.comment.actions.getUUID( function( id ){
  390. this.advanceCommentId = id;
  391. }.bind(this));
  392. this.comment.app.notice( this.comment.lp.saveCommentSuccess, "ok" );
  393. this.form.getItem("content").setValue("");
  394. this.fireEvent("postOk", json.data.id);
  395. }
  396. }.bind(this))
  397. }
  398. }
  399. });
  400. O2CMSComment.View = new Class({
  401. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  402. _createDocument: function(data, index){
  403. data.index = index;
  404. return new O2CMSComment.Document(this.viewNode, data, this.explorer, this, null, data.index );
  405. },
  406. _getCurrentPageData: function(callback, count, pageNum){
  407. this.clearBody();
  408. if(!count)count=10;
  409. if(!pageNum)pageNum = 1;
  410. //page, count, filterData, success,failure, async
  411. //if( !this.page ){
  412. // this.page = 1;
  413. //}else{
  414. // this.page ++;
  415. //}
  416. //var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  417. var filter = this.filterData || {};
  418. this.actions.listCommentPageWithFilter( pageNum, count, filter, function(json){
  419. if( !json.data )json.data = [];
  420. if( !json.count )json.count=0;
  421. if( callback )callback(json);
  422. }.bind(this))
  423. },
  424. _removeDocument: function(documentData, all){
  425. this.actions.deleteComment( documentData.id, function(){
  426. this.reload();
  427. this.app.notice( this.lp.deleteCommentSuccess, "ok")
  428. }.bind(this) )
  429. },
  430. _create: function(){
  431. },
  432. _queryCreateViewNode: function(){
  433. },
  434. _postCreateViewNode: function( viewNode ){
  435. },
  436. _queryCreateViewHead:function(){
  437. },
  438. _postCreateViewHead: function( headNode ){
  439. }
  440. });
  441. O2CMSComment.Document = new Class({
  442. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  443. mouseoverSubject : function(subjectNode, ev){
  444. //var removeNode = sectionNode.getElements("[styles='sectionRemoveNode']")[0];
  445. //if( removeNode )removeNode.setStyle("opacity",1)
  446. },
  447. mouseoutSubject : function(subjectNode, ev){
  448. //var removeNode = sectionNode.getElements("[styles='sectionRemoveNode']")[0];
  449. //if( removeNode )removeNode.setStyle("opacity",0)
  450. },
  451. getUserData : function( name, callback ){
  452. this.view.explorer.getUserData( name, callback );
  453. },
  454. _queryCreateDocumentNode:function( itemData ){
  455. },
  456. _postCreateDocumentNode: function( itemNode, itemData ){
  457. var userIcon = itemNode.getElements( "[item='userIcon']" )[0];
  458. //var signatureContainer = itemNode.getElements("[item='signatureContainer']")[0];
  459. this.getUserData( itemData.creatorName, function(json ){
  460. userIcon.src = json.data.icon;
  461. //if( json.data.signature && json.data.signature!="" ){
  462. // var signatureNode = signatureContainer.getElements("[item='signature']")[0];
  463. // signatureNode.set("text", json.data.signature )
  464. //}else{
  465. // signatureContainer.destroy();
  466. //}
  467. }.bind(this) );
  468. if( itemData.parentId && itemData.parentId != "" ){
  469. var quoteContainer = itemNode.getElements( "[item='quoteContent']" )[0];
  470. this.actions.getComment( itemData.parentId, function( json ){
  471. var data = this.parentData = json.data;
  472. var quoteContent = new Element("div", { "styles" : this.css.itemQuote }).inject(quoteContainer);
  473. var content = quoteContent.set("html", data.content).get("text");
  474. quoteContent.empty();
  475. data.contentText = content;
  476. new Element( "div", {styles : this.css.quoteLeftBig} ).inject( quoteContent );
  477. var quoteArea = new Element( "div", {styles : this.css.quoteAreaBig } ).inject( quoteContent );
  478. var quoteInfor = new Element( "div", {
  479. styles : this.css.quoteInforBig,
  480. text : data.orderNumber + this.lp.floor + ":" + data.creatorName.split('@')[0] + this.lp.publishAt + data.createTime
  481. }).inject( quoteArea );
  482. quoteInfor.addEvent("click", function(){
  483. this.obj.app.gotoComment( this.index )
  484. }.bind({obj : this, index : data.orderNumber || (data.index + 2) }));
  485. new Element( "div", {
  486. styles : this.css.quoteTextBig,
  487. text : content.length > 100 ? (content.substr(0, 100) + "...") : content
  488. }).inject( quoteArea );
  489. new Element( "div", {styles : this.css.quoteRightBig} ).inject( quoteContent );
  490. }.bind(this) , function( json ){
  491. new Element( "div" , {
  492. "styles" : this.css.commentBeinngDelete,
  493. "text" : this.lp.quoteCommentBeingDeleted
  494. }).inject(quoteContainer)
  495. }.bind(this)
  496. )
  497. }
  498. },
  499. sendMessage : function(itemNode, ev ){
  500. var self = this;
  501. if (layout.desktop.widgets["IMIMWidget"]) {
  502. var IM = layout.desktop.widgets["IMIMWidget"];
  503. IM.getOwner(function(){
  504. this.openChat(ev, {
  505. from : self.data.creatorName
  506. });
  507. }.bind(IM));
  508. }
  509. },
  510. createComment : function(itemNode, ev ){ // 对回复进行回复
  511. if( this.app.access.isAnonymousDynamic() ){
  512. this.app.openLoginForm( function(){ this.app.reload() }.bind(this) );
  513. }else{
  514. var form = new O2CMSComment.CommentForm(this, {}, {
  515. toMain: false,
  516. onPostOk: function (id) {
  517. this.app.postCreateComment(id)
  518. }.bind(this)
  519. });
  520. this.data.contentText = this.node.getElements("[item='content']")[0].get("text");
  521. form.mainData = this.app.data;
  522. form.parentData = this.data;
  523. form.create()
  524. }
  525. },
  526. editComment : function(itemNode, ev ){ //编辑当前回复
  527. var form = new O2CMSComment.Form(this, this.data, {
  528. documentId : this.explorer.options.documentId,
  529. toMain : (this.data.parentId && this.data.parentId!="") ? false : true,
  530. onPostOk : function( id ){
  531. MWF.Actions.get("x_cms_assemble_control").getComment( id, function( json ){
  532. var content = this.node.getElements("[item='content']")[0];
  533. content.set( "html", json.data.content );
  534. }.bind(this))
  535. }.bind(this)
  536. });
  537. //form.parentData = this.parentData;
  538. form.edit()
  539. },
  540. deleteComment : function( itemNode, ev ){
  541. var _self = this;
  542. this.view.app.confirm("warn", ev, this.lp.deleteCommentTitle, this.lp.deleteCommentText, 350, 120, function(){
  543. //_self.view._removeDocument(_self.data, false);
  544. _self.actions.deleteComment( _self.data.id, function(){
  545. _self.destroy();
  546. //_self.app.adjustCommentCount( -1 );
  547. _self.app.notice( _self.lp.deleteCommentSuccess, "ok");
  548. _self.view.fireEvent("postDeleteDocument");
  549. }.bind(this) );
  550. this.close();
  551. }, function(){
  552. this.close();
  553. });
  554. }
  555. });
  556. O2CMSComment.Form = new Class({
  557. Extends: MPopupForm,
  558. Implements: [Options, Events],
  559. options: {
  560. "style": "cms_xform",
  561. "width": "860",
  562. "height": "400",
  563. "hasTop": true,
  564. "hasIcon": false,
  565. "hasTopIcon" : true,
  566. "hasTopContent" : true,
  567. "hasBottom": true,
  568. "title": MWF.xApplication.cms.Xform.LP.commentFormTitle,
  569. "draggable": true,
  570. "closeAction": true,
  571. "toMain" : true
  572. },
  573. _createTableContent: function(){
  574. this.lp = MWF.xApplication.cms.Xform.LP;
  575. if( this.isNew ){
  576. MWF.Actions.get("x_cms_assemble_control").getUUID( function(id){
  577. this.advanceCommentId = id;
  578. this._createTableContent_();
  579. }.bind(this) )
  580. }else{
  581. this._createTableContent_()
  582. }
  583. },
  584. _createTableContent_: function () {
  585. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  586. //"<tr>" +
  587. //" <td styles='formTableValue14' item='mainSubject'></td>" +
  588. //"</tr>
  589. //"<tr>" +
  590. //" <td styles='formTableValue' item='mainContent'></td>" +
  591. //"</tr>" +
  592. "<tr>" +
  593. " <td styles='formTableValue' item='content'></td>" +
  594. "</tr>"+
  595. "</table>";
  596. this.formTableArea.set("html", html);
  597. //if( !this.options.toMain && this.parentData ){
  598. // var mainContentEl = this.formTableArea.getElements("[item='mainContent']")[0];
  599. //
  600. // var quoteTop = new Element( "div", {styles : this.css.quoteTop} ).inject( mainContentEl );
  601. // new Element( "div", {styles : this.css.quoteLeft} ).inject( quoteTop );
  602. // new Element( "div", {
  603. // styles : this.css.quoteInfor,
  604. // text : this.parentData.creatorName.split("@")[0] + this.lp.publishAt + this.parentData.createTime
  605. // }).inject( quoteTop );
  606. //
  607. // var quoteBottom = new Element( "div", {styles : this.css.quoteBottom} ).inject( mainContentEl );
  608. // var text = this.parentData.contentText;
  609. // new Element( "div", {
  610. // styles : this.css.quoteText,
  611. // text : text.length > 50 ? (text.substr(0, 50) + "...") : text
  612. // }).inject( quoteBottom );
  613. // new Element( "div", {styles : this.css.quoteRight} ).inject( quoteBottom );
  614. //}
  615. MWF.xDesktop.requireApp("Template", "MForm", function () {
  616. this.form = new MForm(this.formTableArea, this.data, {
  617. style: "cms",
  618. isEdited: true,
  619. itemTemplate: {
  620. //mainSubject: { type: "innertext", defaultValue : "RE:" + this.mainData.title },
  621. content: { type : "rtf", RTFConfig : {
  622. //skin : "bootstrapck",
  623. "resize_enabled": false,
  624. isSetImageMaxWidth : true,
  625. reference : this.advanceCommentId || this.data.id,
  626. referenceType: "forumReply",
  627. toolbar : [
  628. //{ name: 'document', items : [ 'Preview' ] },
  629. ////{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
  630. //{ name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','-','RemoveFormat' ] },
  631. ////{ name: 'paragraph', items : [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },
  632. //{ name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
  633. //{ name: 'colors', items : [ 'TextColor','BGColor' ] },
  634. //{ name: 'links', items : [ 'Link','Unlink' ] },
  635. { name: 'insert', items : [ 'Image' ] }
  636. //{ name: 'tools', items : [ 'Maximize','-','About' ] }
  637. ]
  638. }}
  639. }
  640. }, this.app, this.css);
  641. this.form.load();
  642. }.bind(this), true);
  643. },
  644. _createBottomContent: function () {
  645. this.cancelActionNode = new Element("div.formCancelActionNode", {
  646. "styles": this.css.formCancelActionNode,
  647. "text": this.lp.close
  648. }).inject(this.formBottomNode);
  649. this.cancelActionNode.addEvent("click", function (e) {
  650. this.cancel(e);
  651. }.bind(this));
  652. if (this.isNew || this.isEdited) {
  653. this.okActionNode = new Element("div.formOkActionNode", {
  654. "styles": this.css.formOkActionNode,
  655. "text": this.lp.ok
  656. }).inject(this.formBottomNode);
  657. this.okActionNode.addEvent("click", function (e) {
  658. this.ok(e);
  659. }.bind(this));
  660. }
  661. },
  662. ok: function (e) {
  663. this.fireEvent("queryOk");
  664. var data = this.form.getResult(true, ",", true, false, true);
  665. if (data) {
  666. this._ok(data, function (json) {
  667. if (json.type == "error") {
  668. this.app.notice(json.message, "error");
  669. } else {
  670. if(this.formMaskNode)this.formMaskNode.destroy();
  671. this.formAreaNode.destroy();
  672. this.app.notice(this.isNew ? this.lp.createCommentSuccess : this.lp.updateSuccess, "success");
  673. this.fireEvent("postOk", json.data.id);
  674. }
  675. }.bind(this))
  676. }
  677. },
  678. _ok: function (data, callback) {
  679. data.documentId = this.options.documentId ;
  680. if( this.advanceCommentId )data.id = this.advanceCommentId;
  681. delete data.userIcon;
  682. if( !this.options.toMain ){
  683. data.parentId = this.parentData.id ;
  684. }
  685. MWF.Actions.get("x_cms_assemble_control").saveComment( data, function(json){
  686. if( callback )callback(json);
  687. }.bind(this));
  688. }
  689. });