Comment.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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 || this.options.anonymous;
  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 = MWF.xApplication.cms.Xform.LP.yesterday + " " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  281. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  282. result = MWF.xApplication.cms.Xform.LP.theDayBeforeYesterday + " " + 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 = MWF.xApplication.cms.Xform.LP.severalWeekAgo.replace("{count}", parseInt(weekC));
  291. } else if (dayC >= 1) {
  292. result = MWF.xApplication.cms.Xform.LP.severalDayAgo.replace("{count}", parseInt(dayC));
  293. } else if (hourC >= 1) {
  294. result = MWF.xApplication.cms.Xform.LP.severalHourAgo.replace("{count}", parseInt(hourC));
  295. } else if (minC >= 1) {
  296. result = MWF.xApplication.cms.Xform.LP.severalMintuesAgo.replace("{count}", parseInt(minC));
  297. } else
  298. result = MWF.xApplication.cms.Xform.LP.justNow;
  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. var contentNode = itemNode.getElement("[item='content']");
  476. if( layout.mobile ){
  477. this.loadLazyImage(contentNode, this.data.content, function () { //图片懒加载
  478. var images = contentNode.getElements("img");
  479. //移动端设置图片宽度为100%
  480. images.each( function( img ){
  481. if( img.hasClass("lozad") ){
  482. img.setStyles({
  483. "max-width" : "100%"
  484. });
  485. }else{
  486. img.setStyles({
  487. "height": "auto",
  488. "max-width" : "100%"
  489. });
  490. }
  491. }.bind(this));
  492. }.bind(this))
  493. }else{
  494. this.loadLazyImage(contentNode, this.data.content, function () {
  495. this.loadImageViewer(contentNode);
  496. }.bind(this));
  497. }
  498. if( itemData.parentId && itemData.parentId != "" ){
  499. var quoteContainer = itemNode.getElements( "[item='quoteContent']" )[0];
  500. this.actions.getComment( itemData.parentId, function( json ){
  501. var data = this.parentData = json.data;
  502. var quoteContent = new Element("div", { "styles" : this.css.itemQuote }).inject(quoteContainer);
  503. var content = quoteContent.set("html", data.content).get("text");
  504. quoteContent.empty();
  505. data.contentText = content;
  506. new Element( "div", {styles : this.css.quoteLeftBig} ).inject( quoteContent );
  507. var quoteArea = new Element( "div", {styles : this.css.quoteAreaBig } ).inject( quoteContent );
  508. var quoteInfor = new Element( "div", {
  509. styles : this.css.quoteInforBig,
  510. text : data.orderNumber + this.lp.floor + ":" + data.creatorName.split('@')[0] + this.lp.publishAt + data.createTime
  511. }).inject( quoteArea );
  512. quoteInfor.addEvent("click", function(){
  513. this.obj.app.gotoComment( this.index )
  514. }.bind({obj : this, index : data.orderNumber || (data.index + 2) }));
  515. new Element( "div", {
  516. styles : this.css.quoteTextBig,
  517. text : content.length > 100 ? (content.substr(0, 100) + "...") : content
  518. }).inject( quoteArea );
  519. new Element( "div", {styles : this.css.quoteRightBig} ).inject( quoteContent );
  520. }.bind(this) , function( json ){
  521. new Element( "div" , {
  522. "styles" : this.css.commentBeinngDelete,
  523. "text" : this.lp.quoteCommentBeingDeleted
  524. }).inject(quoteContainer)
  525. }.bind(this)
  526. )
  527. }
  528. },
  529. loadLazyImage: function(node, html, callback){
  530. o2.require("o2.widget.ImageLazyLoader", function(){
  531. var loadder = new o2.widget.ImageLazyLoader(node, html);
  532. loadder.load(function(){
  533. if(callback)callback();
  534. }.bind(this))
  535. }.bind(this));
  536. },
  537. loadImageViewer: function(node){
  538. o2.require("o2.widget.ImageViewer", function(){
  539. var imageViewer = new o2.widget.ImageViewer(node);
  540. imageViewer.load();
  541. }.bind(this));
  542. },
  543. sendMessage : function(itemNode, ev ){
  544. var self = this;
  545. if (layout.desktop.widgets["IMIMWidget"]) {
  546. var IM = layout.desktop.widgets["IMIMWidget"];
  547. IM.getOwner(function(){
  548. this.openChat(ev, {
  549. from : self.data.creatorName
  550. });
  551. }.bind(IM));
  552. }
  553. },
  554. createComment : function(itemNode, ev ){ // 对回复进行回复
  555. if( this.app.access.isAnonymousDynamic() ){
  556. this.app.openLoginForm( function(){ this.app.reload() }.bind(this) );
  557. }else{
  558. var form = new O2CMSComment.CommentForm(this, {}, {
  559. toMain: false,
  560. onPostOk: function (id) {
  561. this.app.postCreateComment(id)
  562. }.bind(this)
  563. });
  564. this.data.contentText = this.node.getElements("[item='content']")[0].get("text");
  565. form.mainData = this.app.data;
  566. form.parentData = this.data;
  567. form.create()
  568. }
  569. },
  570. editComment : function(itemNode, ev ){ //编辑当前回复
  571. var form = new O2CMSComment.Form(this, this.data, {
  572. documentId : this.explorer.options.documentId,
  573. toMain : (this.data.parentId && this.data.parentId!="") ? false : true,
  574. onPostOk : function( id ){
  575. MWF.Actions.get("x_cms_assemble_control").getComment( id, function( json ){
  576. var content = this.node.getElements("[item='content']")[0];
  577. content.set( "html", json.data.content );
  578. }.bind(this))
  579. }.bind(this)
  580. });
  581. //form.parentData = this.parentData;
  582. form.edit()
  583. },
  584. deleteComment : function( itemNode, ev ){
  585. var _self = this;
  586. this.view.app.confirm("warn", ev, this.lp.deleteCommentTitle, this.lp.deleteCommentText, 350, 120, function(){
  587. //_self.view._removeDocument(_self.data, false);
  588. _self.actions.deleteComment( _self.data.id, function(){
  589. _self.destroy();
  590. //_self.app.adjustCommentCount( -1 );
  591. _self.app.notice( _self.lp.deleteCommentSuccess, "ok");
  592. _self.view.fireEvent("postDeleteDocument");
  593. }.bind(this) );
  594. this.close();
  595. }, function(){
  596. this.close();
  597. });
  598. }
  599. });
  600. O2CMSComment.Form = new Class({
  601. Extends: MPopupForm,
  602. Implements: [Options, Events],
  603. options: {
  604. "style": "cms_xform",
  605. "width": "860",
  606. "height": "400",
  607. "hasTop": true,
  608. "hasIcon": false,
  609. "hasTopIcon" : true,
  610. "hasTopContent" : true,
  611. "hasBottom": true,
  612. // "title": MWF.xApplication.cms.Xform.LP.commentFormTitle,
  613. "draggable": true,
  614. "closeAction": true,
  615. "toMain" : true
  616. },
  617. _createTableContent: function(){
  618. this.lp = MWF.xApplication.cms.Xform.LP;
  619. if( this.formTopTextNode )this.formTopTextNode.set("text", this.lp.commentFormTitle);
  620. if( this.isNew ){
  621. MWF.Actions.get("x_cms_assemble_control").getUUID( function(id){
  622. this.advanceCommentId = id;
  623. this._createTableContent_();
  624. }.bind(this) )
  625. }else{
  626. this._createTableContent_()
  627. }
  628. },
  629. _createTableContent_: function () {
  630. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  631. //"<tr>" +
  632. //" <td styles='formTableValue14' item='mainSubject'></td>" +
  633. //"</tr>
  634. //"<tr>" +
  635. //" <td styles='formTableValue' item='mainContent'></td>" +
  636. //"</tr>" +
  637. "<tr>" +
  638. " <td styles='formTableValue' item='content'></td>" +
  639. "</tr>"+
  640. "</table>";
  641. this.formTableArea.set("html", html);
  642. //if( !this.options.toMain && this.parentData ){
  643. // var mainContentEl = this.formTableArea.getElements("[item='mainContent']")[0];
  644. //
  645. // var quoteTop = new Element( "div", {styles : this.css.quoteTop} ).inject( mainContentEl );
  646. // new Element( "div", {styles : this.css.quoteLeft} ).inject( quoteTop );
  647. // new Element( "div", {
  648. // styles : this.css.quoteInfor,
  649. // text : this.parentData.creatorName.split("@")[0] + this.lp.publishAt + this.parentData.createTime
  650. // }).inject( quoteTop );
  651. //
  652. // var quoteBottom = new Element( "div", {styles : this.css.quoteBottom} ).inject( mainContentEl );
  653. // var text = this.parentData.contentText;
  654. // new Element( "div", {
  655. // styles : this.css.quoteText,
  656. // text : text.length > 50 ? (text.substr(0, 50) + "...") : text
  657. // }).inject( quoteBottom );
  658. // new Element( "div", {styles : this.css.quoteRight} ).inject( quoteBottom );
  659. //}
  660. MWF.xDesktop.requireApp("Template", "MForm", function () {
  661. this.form = new MForm(this.formTableArea, this.data, {
  662. style: "cms",
  663. isEdited: true,
  664. itemTemplate: {
  665. //mainSubject: { type: "innertext", defaultValue : "RE:" + this.mainData.title },
  666. content: { type : "rtf", RTFConfig : {
  667. //skin : "bootstrapck",
  668. "resize_enabled": false,
  669. isSetImageMaxWidth : true,
  670. reference : this.advanceCommentId || this.data.id,
  671. referenceType: "forumReply",
  672. toolbar : [
  673. //{ name: 'document', items : [ 'Preview' ] },
  674. ////{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
  675. //{ name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','-','RemoveFormat' ] },
  676. ////{ name: 'paragraph', items : [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },
  677. //{ name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
  678. //{ name: 'colors', items : [ 'TextColor','BGColor' ] },
  679. //{ name: 'links', items : [ 'Link','Unlink' ] },
  680. { name: 'insert', items : [ 'Image' ] }
  681. //{ name: 'tools', items : [ 'Maximize','-','About' ] }
  682. ]
  683. }}
  684. }
  685. }, this.app, this.css);
  686. this.form.load();
  687. }.bind(this), true);
  688. },
  689. _createBottomContent: function () {
  690. this.cancelActionNode = new Element("div.formCancelActionNode", {
  691. "styles": this.css.formCancelActionNode,
  692. "text": this.lp.close
  693. }).inject(this.formBottomNode);
  694. this.cancelActionNode.addEvent("click", function (e) {
  695. this.cancel(e);
  696. }.bind(this));
  697. if (this.isNew || this.isEdited) {
  698. this.okActionNode = new Element("div.formOkActionNode", {
  699. "styles": this.css.formOkActionNode,
  700. "text": this.lp.ok
  701. }).inject(this.formBottomNode);
  702. this.okActionNode.addEvent("click", function (e) {
  703. this.ok(e);
  704. }.bind(this));
  705. }
  706. },
  707. ok: function (e) {
  708. this.fireEvent("queryOk");
  709. var data = this.form.getResult(true, ",", true, false, true);
  710. if (data) {
  711. this._ok(data, function (json) {
  712. if (json.type == "error") {
  713. this.app.notice(json.message, "error");
  714. } else {
  715. if(this.formMaskNode)this.formMaskNode.destroy();
  716. this.formAreaNode.destroy();
  717. this.app.notice(this.isNew ? this.lp.createCommentSuccess : this.lp.updateSuccess, "success");
  718. this.fireEvent("postOk", json.data.id);
  719. }
  720. }.bind(this))
  721. }
  722. },
  723. _ok: function (data, callback) {
  724. data.documentId = this.options.documentId ;
  725. if( this.advanceCommentId )data.id = this.advanceCommentId;
  726. delete data.userIcon;
  727. if( !this.options.toMain ){
  728. data.parentId = this.parentData.id ;
  729. }
  730. MWF.Actions.get("x_cms_assemble_control").saveComment( data, function(json){
  731. if( callback )callback(json);
  732. }.bind(this));
  733. }
  734. });