Main.js 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982
  1. MWF.xApplication.Forum = MWF.xApplication.Forum || {};
  2. MWF.xApplication.ForumDocument = MWF.xApplication.ForumDocument || {};
  3. MWF.require("MWF.widget.Identity", null,false);
  4. MWF.xDesktop.requireApp("Forum", "Actions.RestActions", null, false);
  5. MWF.xDesktop.requireApp("Forum", "Attachment", null, false);
  6. MWF.xDesktop.requireApp("Forum", "lp."+MWF.language, null, false);
  7. MWF.xDesktop.requireApp("Forum", "Access", null, false);
  8. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  9. MWF.xDesktop.requireApp("Forum", "TopNode", null, false);
  10. MWF.xApplication.ForumDocument.options = {
  11. multitask: true,
  12. executable: true
  13. };
  14. MWF.xApplication.ForumDocument.Main = new Class({
  15. Extends: MWF.xApplication.Common.Main,
  16. Implements: [Options, Events],
  17. options: {
  18. "style": "default",
  19. "name": "ForumDocument",
  20. "icon": "icon.png",
  21. "width": "1210",
  22. "height": "700",
  23. "isResize": true,
  24. "isMax": true,
  25. "isNew" : false,
  26. "isEdited" : true,
  27. "index" : 1,
  28. "replyIndex" : null,
  29. "viewPageNum" : 1,
  30. "title": MWF.xApplication.ForumDocument.LP.title
  31. },
  32. onQueryLoad: function(){
  33. this.lp = MWF.xApplication.Forum.LP;
  34. },
  35. onQueryClose: function(){
  36. },
  37. loadApplication: function(callback){
  38. this.userData = layout.desktop.session.user;
  39. this.userName = this.userData.name;
  40. this.restActions = this.actions = new MWF.xApplication.Forum.Actions.RestActions();
  41. this.path = "/x_component_ForumDocument/$Main/"+this.options.style+"/";
  42. if( this.options.isNew && !this.options.id ){
  43. this.actions.getUUID( function( id ){
  44. this.advanceId = id;
  45. this.createNode();
  46. this.loadApplicationContent();
  47. }.bind(this))
  48. }else{
  49. this.createNode();
  50. this.loadApplicationContent();
  51. }
  52. },
  53. loadController: function(callback){
  54. this.access = new MWF.xApplication.Forum.Access( this.restActions, this.lp );
  55. if(callback)callback();
  56. },
  57. createNode: function(){
  58. this.content.setStyle("overflow", "hidden");
  59. this.node = new Element("div", {
  60. "styles": this.css.node
  61. }).inject(this.content);
  62. },
  63. loadApplicationContent: function(){
  64. if( this.status ){
  65. this.setOptions( this.status )
  66. }
  67. this.loadController(function(){
  68. this.access.login( function(){
  69. this.loadApplicationLayout();
  70. }.bind(this) )
  71. }.bind(this))
  72. },
  73. reload : function(oldid, appid){
  74. this.node.empty();
  75. this.pagingBarTop = null;
  76. this.pagingContainerTop = null;
  77. delete this.pagingBarTop;
  78. delete this.pagingContainerTop;
  79. this.loadApplicationLayout();
  80. //if( this.appCurrentList.indexOf( this > 0 ){
  81. // this.appCurrentList.erase(this);
  82. // this.appCurrentList.push(this)
  83. //}
  84. if( oldid && appid && (oldid != appid) ){
  85. delete this.desktop.apps[oldid];
  86. this.appId = appid;
  87. this.desktop.apps[appid] = this;
  88. }
  89. },
  90. loadApplicationLayout : function(){
  91. this.contentContainerNode = new Element("div.contentContainerNode", {
  92. "styles": this.css.contentContainerNode
  93. }).inject(this.node);
  94. if( this.options.id ){
  95. this.restActions.listSubjectPermission( this.options.id, function( permission ){
  96. this.permission = permission.data;
  97. if( this.options.isEdited ){
  98. this.restActions.getSubject( this.options.id , function( data ){
  99. this.data = data.data;
  100. this._loadApplicationLayout( this.data.sectionId , this.data.title );
  101. }.bind(this))
  102. }else{
  103. this.restActions.getSubjectView( this.options.id , function( data ){
  104. this.data = data.data.currentSubject;
  105. this.nextSubject = data.data.nextSubject;
  106. this.lastSubject = data.data.lastSubject;
  107. this._loadApplicationLayout( this.data.sectionId , this.data.title );
  108. }.bind(this))
  109. }
  110. }.bind(this) )
  111. }else{
  112. this._loadApplicationLayout( this.options.sectionId, this.lp.createSubject );
  113. }
  114. },
  115. _loadApplicationLayout : function( sectionId, title ){
  116. this.options.sectionId = sectionId;
  117. this.restActions.listSectionPermission( sectionId, function( permission ){
  118. this.sectionPermission = permission.data;
  119. this.restActions.getSection( sectionId, function( json ) {
  120. this.sectionData = json.data;
  121. //this.access.hasSectionAdminAuthority( this.sectionData , function( flag ){
  122. // this.isAdmin = flag;
  123. this.restActions.getCategory(this.sectionData.forumId, function (formData) {
  124. this.formData = formData.data;
  125. this.setTitle( title );
  126. this.createTopNode();
  127. this.createMiddleNode();
  128. }.bind(this))
  129. //}.bind(this) );
  130. }.bind(this))
  131. }.bind(this) )
  132. },
  133. createTopNode: function(){
  134. var forumColor = MWF.xApplication.Forum.ForumSetting[this.sectionData.forumId].forumColor;
  135. var topNode = this.topNode = new Element("div.topNode", {
  136. "styles": this.css.topNode
  137. }).inject(this.contentContainerNode);
  138. topNode.setStyle("border-bottom","1px solid "+forumColor);
  139. var topTitleLeftNode = new Element("div.topTitleLeftNode", {
  140. "styles": this.css.topTitleLeftNode
  141. }).inject(topNode);
  142. topTitleLeftNode.setStyle( "background-color" , forumColor )
  143. var topTitleMiddleNode = new Element("div.topTitleMiddleNode", {
  144. "styles": this.css.topTitleMiddleNode
  145. }).inject(topNode);
  146. topTitleMiddleNode.setStyle( "background-color" , forumColor )
  147. var topTitleRightNode = new Element("div.topTitleRightNode", {
  148. "styles": this.css.topTitleRightNode
  149. }).inject(topNode);
  150. topTitleRightNode.setStyle( "background-color" , forumColor )
  151. var topItemTitleNode = new Element("div.topItemTitleNode", {
  152. "styles": this.css.topItemTitleNode,
  153. "text": this.lp.title
  154. }).inject(topTitleMiddleNode);
  155. topItemTitleNode.addEvent("click", function(){
  156. var appId = "Forum";
  157. if (this.desktop.apps[appId]){
  158. this.desktop.apps[appId].setCurrent();
  159. }else {
  160. this.desktop.openApplication(null, "Forum", { "appId": appId });
  161. }
  162. if( !this.inBrowser ){
  163. this.close();
  164. }
  165. }.bind(this))
  166. var topItemSepNode = new Element("div.topItemSepNode", {
  167. "styles": this.css.topItemSepNode
  168. }).inject(topTitleMiddleNode);
  169. var topItemTitleNode = new Element("div.topItemTitleNode", {
  170. "styles": this.css.topItemTitleNode,
  171. "text": this.sectionData.forumName
  172. }).inject(topTitleMiddleNode);
  173. topItemTitleNode.addEvent("click", function(){
  174. var appId = "ForumCategory"+this.forumId;
  175. if (this.obj.desktop.apps[appId]){
  176. this.obj.desktop.apps[appId].setCurrent();
  177. }else {
  178. this.obj.desktop.openApplication(null, "ForumCategory", { "categoryId" : this.forumId ,"appId": appId });
  179. }
  180. if( !this.obj.inBrowser ){
  181. this.obj.close();
  182. }
  183. //this.obj.close();
  184. }.bind({ obj: this, forumId : this.sectionData.forumId }))
  185. var topItemSepNode = new Element("div.topItemSepNode", {
  186. "styles": this.css.topItemSepNode
  187. }).inject(topTitleMiddleNode);
  188. var topItemTitleNode = new Element("div.topItemTitleNode", {
  189. "styles": this.css.topItemTitleNode,
  190. "text": this.sectionData.sectionName
  191. }).inject(topTitleMiddleNode);
  192. topItemTitleNode.addEvent("click", function(){
  193. var appId = "ForumSection"+this.sectionData.id;
  194. if (this.desktop.apps[appId]){
  195. this.desktop.apps[appId].setCurrent();
  196. }else {
  197. this.desktop.openApplication(null, "ForumSection", {
  198. "sectionId" : this.sectionData.id,
  199. "appId": appId
  200. });
  201. }
  202. if( !this.inBrowser ){
  203. this.close();
  204. }
  205. //this.close();
  206. }.bind(this))
  207. var topItemSepNode = new Element("div.topItemSepNode", {
  208. "styles": this.css.topItemSepNode
  209. }).inject(topTitleMiddleNode);
  210. var topItemTitleNode = new Element("div.topItemTitleNode", {
  211. "styles": this.css.topItemTitleNode,
  212. "text": this.options.isNew ? (this.lp.createSubject) : ("["+ this.data.type +"]" + this.data.title )
  213. }).inject(topTitleMiddleNode);
  214. //this.topRightTextNode = new Element("div", {
  215. // "styles": this.css.topRightTextNode,
  216. // "text": this.lp.setting
  217. //}).inject(this.topRightTextNode)
  218. },
  219. createMiddleNode: function(){
  220. this.middleNode = new Element("div.middleNode", {
  221. "styles": this.css.middleNode
  222. }).inject(this.contentContainerNode);
  223. this.addEvent("resize", function () {
  224. this.setContentSize();
  225. }.bind(this));
  226. this.setContentSize();
  227. this.middleNode.addEvent("selectstart", function(e){
  228. e.stopPropagation();
  229. });
  230. //MWF.require("MWF.widget.ScrollBar", function () {
  231. // this.scrollBar = new MWF.widget.ScrollBar(this.contentContainerNode, {
  232. // "indent": false,
  233. // "style": "xApp_TaskList",
  234. // "where": "before",
  235. // "distance": 30,
  236. // "friction": 4,
  237. // "axis": {"x": false, "y": true},
  238. // "onScroll": function (y) {
  239. // }
  240. // });
  241. //}.bind(this));
  242. if( this.options.isNew || this.options.isEdited ){
  243. this._createMiddleNode_eidt();
  244. }else{
  245. this._createMiddleNode_read();
  246. }
  247. },
  248. _createMiddleNode_eidt : function(){
  249. this.data = this.data || {}
  250. var _self = this;
  251. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.middleNode);
  252. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  253. "<tr>" +
  254. " <td styles='formTableTitle' lable='title' width='10%'></td>" +
  255. " <td styles='formTableValue' item='type'width='10%'></td>" +
  256. " <td styles='formTableValue' item='title'width='80%'></td>" +
  257. "</tr><tr>" +
  258. " <td styles='formTableTitle' lable='summary'></td>" +
  259. " <td styles='formTableValue' item='summary' colspan='2'></td>" +
  260. "</tr><tr item='portalImageTr' style='display:none'>" +
  261. " <td styles='formTableTitle' lable='portalImage'></td>" +
  262. " <td styles='formTableValue' colspan='2'><div item='portalImageAre' styles='portalImageAre' ></div></td>" +
  263. "</tr><tr>" +
  264. " <td styles='formTableTitle' lable='content'></td>" +
  265. " <td styles='formTableValue' item='content' colspan='2'></td>" +
  266. "</tr><tr>" +
  267. " <td styles='formTableTitle'>"+ this.lp.attachment +"</td>" +
  268. " <td item='attachment' colspan='2'></td>" +
  269. "</tr><tr>" +
  270. " <td styles='formTableTitle' lable=''></td>" +
  271. " <td item='action' colspan='2'></td>" +
  272. "</tr>"
  273. "</table>"
  274. this.contentDiv.set("html", html);
  275. if( this.formData.indexListStyle == this.lp.indexListStyleImage ){
  276. this.contentDiv.getElements("[item='portalImageTr']")[0].setStyle("display","");
  277. }
  278. var subjectTypeSelectValue;
  279. if( this.sectionData.subjectType ){
  280. subjectTypeSelectValue = this.sectionData.subjectType.split("|");
  281. }else if( this.formData.subjectType ){
  282. subjectTypeSelectValue = this.formData.subjectType.split("|");
  283. }else{
  284. subjectTypeSelectValue = this.lp.subjectTypeDefaultValue.split("|");
  285. }
  286. MWF.xDesktop.requireApp("Template", "MForm", function () {
  287. this.form = new MForm(this.contentDiv, this.data , {
  288. style: "forum",
  289. isEdited: true || this.isEdited || this.isNew,
  290. itemTemplate: {
  291. title: {text: this.lp.subject, notEmpty : true },
  292. type: {text: this.lp.type, type : "select", selectValue : subjectTypeSelectValue , notEmpty : true },
  293. summary: {text: this.lp.summary, type : "text", event : { "keyup" : function( item, ev){
  294. if( item.getValue().length > 70 ){
  295. item.setValue( item.getValue().substr( 0, 70 ) );
  296. }
  297. } } },
  298. portalImage: {text: this.lp.portalImage },
  299. content: {text: this.lp.content, type : "rtf", notEmpty : true, RTFConfig : {
  300. isSetImageMaxWidth : true,
  301. reference : this.advanceId || this.data.id,
  302. referenceType: "forumDocument",
  303. skin : "bootstrapck" //,
  304. //filebrowserCurrentDocumentImage: function (e, callback) {
  305. // _self.selectDocImage( callback );
  306. //}
  307. }}
  308. }
  309. }, this, this.css);
  310. this.form.load();
  311. }.bind(this), true);
  312. this.createIconNode();
  313. var actionTd = this.contentDiv.getElements("[item='action']")[0];
  314. this.saveAction = new Element("div",{
  315. styles : this.css.actionNode,
  316. text: this.lp.saveSubject
  317. }).inject(actionTd);
  318. this.saveAction.addEvent("click",function(){
  319. this.saveSubject();
  320. }.bind(this))
  321. var attachmentArea = this.contentDiv.getElements("[item='attachment']")[0];
  322. this.loadAttachment(attachmentArea)
  323. },
  324. //selectDocImage : function( callback, width ){
  325. // this.selector_doc = new MWF.xApplication.Forum.Attachment(this.content, this, this.restActions, this.lp, {
  326. // //documentId : this.data ? this.data.id : "",
  327. // isNew : this.options.isNew,
  328. // isEdited : this.options.isEdited,
  329. // "onUpload" : function( attData ){
  330. // this.attachment.attachmentController.addAttachment(attData);
  331. // this.attachment.attachmentController.checkActions();
  332. // }.bind(this)
  333. // })
  334. // this.selector_doc.data = this.attachment.getAttachmentData();
  335. // this.selector_doc.loadAttachmentSelecter({
  336. // "style": "cms",
  337. // "title": "选择本文档图片",
  338. // "listStyle": "preview",
  339. // "toBase64" : true,
  340. // "base64MaxSize" : width || 800,
  341. // "selectType": "images"
  342. // }, function (url, data, base64Code ) {
  343. // if (callback)callback(url, base64Code, data);
  344. // }.bind(this));
  345. //},
  346. //selectCloudImage : function( callback, width ){
  347. // var _self = this;
  348. // MWF.xDesktop.requireApp("File", "FileSelector", function(){
  349. // _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
  350. // "style" : "default",
  351. // "title": "选择云文件图片",
  352. // "listStyle": "preview",
  353. // "toBase64" : true,
  354. // "base64Width" : width || 800,
  355. // "selectType" : "images",
  356. // "onPostSelectAttachment" : function(url, base64Code){
  357. // if(callback)callback(url, base64Code);
  358. // }
  359. // });
  360. // _self.selector_cloud.load();
  361. // }, true);
  362. //},
  363. //insertImage : function( callback ){
  364. // var form = new MWF.xApplication.ForumDocument.ImageLinkForm(this, this.data, {
  365. // onPostOk : function( data ){
  366. // if( callback )callback(data);
  367. // }.bind(this)
  368. // },{
  369. // app : this, lp : this.lp, css : this.css, actions : this.restActions
  370. // })
  371. // form.create()
  372. //},
  373. createIconNode: function(){
  374. var sectionIconArea = this.contentDiv.getElements("[item='portalImageAre']")[0];
  375. if( sectionIconArea ){
  376. this.picId = (this.data && this.data.picId) ? this.data.picId : null;
  377. if( this.picId ){
  378. this.portalImage = new Element("img", {
  379. "src" : MWF.xDesktop.getImageSrc(this.picId),
  380. "styles" : this.css.portalImageNode
  381. }).inject( sectionIconArea );
  382. };
  383. this.uploadImageAction = new Element("button.uploadActionNode",{
  384. "styles" : this.css.uploadActionNode,
  385. "text" : "设置图片"
  386. }).inject(sectionIconArea);
  387. this.uploadImageAction.addEvents({
  388. "click": function(){
  389. MWF.xDesktop.requireApp("ForumDocument", "ImageClipper",null,false);
  390. this.clipper = new MWF.xApplication.ForumDocument.ImageClipper(this.form.app, {
  391. "aspectRatio": 1.5,
  392. "imageUrl": this.picId ? MWF.xDesktop.getImageSrc(this.picId) : "",
  393. "reference": this.advanceId || this.data.id,
  394. "referenceType": "forumDocument",
  395. "onChange": function () {
  396. if( this.portalImage )this.portalImage.destroy();
  397. this.portalImage = new Element("img", {
  398. "src" : this.clipper.imageSrc,
  399. "styles" : this.css.portalImageNode
  400. }).inject( sectionIconArea, "top" );
  401. this.picId = this.clipper.imageId;
  402. }.bind(this)
  403. });
  404. this.clipper.load();
  405. }.bind(this)
  406. });
  407. }
  408. },
  409. reloadAllParents : function(){
  410. var aid = "Forum";
  411. if (this.desktop.apps[aid]){
  412. this.desktop.apps[aid].reload();
  413. }
  414. aid = "ForumCategory"+this.sectionData.forumId;
  415. if (this.desktop.apps[aid]){
  416. this.desktop.apps[aid].reload();
  417. }
  418. aid = "ForumSection"+this.sectionData.id;
  419. if (this.desktop.apps[aid]){
  420. this.desktop.apps[aid].reload();
  421. }
  422. },
  423. saveSubject : function(){
  424. var data = this.form.getResult(true, ",", true, false, true);
  425. if( this.advanceId )data.id = this.advanceId;
  426. data.attachmentList = this.attachment.getAttachmentIds();
  427. if (data) {
  428. data.sectionId = this.sectionData.id;
  429. data.picId = this.picId || ""; //this.clipper.getBase64Image() || "";
  430. this.restActions.saveSubject(data, function (json) {
  431. this.notice(this.options.isNew ? this.lp.createSuccess : this.lp.updateSuccess, "success");
  432. this.fireEvent("postPublish");
  433. this.reloadAllParents();
  434. var oldId = "ForumDocument"+ ( this.options.isNew ? "" : this.data.id );
  435. var appId = "ForumDocument"+json.data.id;
  436. this.setOptions({
  437. "id" : json.data.id,
  438. "appId": appId,
  439. "isEdited" : false,
  440. "isNew" : false //,
  441. //"index" : nextIndex
  442. });
  443. this.reload(oldId , appId );
  444. }.bind(this))
  445. }
  446. },
  447. _createMiddleNode_read: function(){
  448. this.isReplyPublisher = this.permission.replyPublishAble; //this.access.isReplyPublisher( this.sectionData );
  449. this.createPagingBar();
  450. this.createToolbar_read();
  451. this.subjectConainer = new Element("div.subjectConainer",{
  452. "styles" : this.css.subjectConainer
  453. }).inject( this.middleNode );
  454. this.replyViewConainer = new Element("div.replyViewConainer",{
  455. "styles" : this.css.replyViewConainer
  456. }).inject( this.middleNode );
  457. this.createPagingBar();
  458. this.createSubject();
  459. this.createReplyView();
  460. if( !this.data.stopReply && this.isReplyPublisher ){
  461. if( this.access.isAnonymous() ){
  462. this.createReplyEditor_Anonymous()
  463. }else{
  464. this.createReplyEditor();
  465. }
  466. }
  467. this.createTurnSubjectNode();
  468. },
  469. createPagingBar: function(){
  470. var pagingArea = new Element("div",{
  471. styles : this.css.pagingArea
  472. }).inject(this.middleNode)
  473. if( this.pagingBarTop ){
  474. this.pagingBarBottom = pagingArea;
  475. }else{
  476. this.pagingBarTop = pagingArea;
  477. }
  478. //if( this.access.isSubjectPublisher( this.sectionData ) ){
  479. if( this.sectionPermission.subjectPublishAble ){
  480. var createActionNode = new Element("div",{
  481. styles : this.css.pagingActionNode,
  482. text: this.lp.createSubject
  483. }).inject(pagingArea);
  484. createActionNode.addEvents(
  485. {
  486. "mouseover": function () {
  487. this.node.setStyles(this.obj.css.pagingActionNode_over);
  488. }.bind({obj: this, node: createActionNode}),
  489. "mouseout": function () {
  490. this.node.setStyles(this.obj.css.pagingActionNode);
  491. }.bind({obj: this, node: createActionNode}),
  492. "click": function () {
  493. if( this.access.isAnonymousDynamic() ){
  494. this.openLoginForm(
  495. function(){ this.createNewDocument(); }.bind(this)
  496. );
  497. }else{
  498. this.createNewDocument();
  499. }
  500. }.bind(this)
  501. }
  502. )
  503. }
  504. //var fileterNode = new Element("div",{
  505. // styles : this.css.fileterNode
  506. //}).inject(pagingArea);
  507. var pagingContainer = new Element("div").inject(pagingArea);
  508. if( this.pagingContainerTop ){
  509. this.pagingContainerBottom = pagingContainer;
  510. }else{
  511. this.pagingContainerTop = pagingContainer;
  512. }
  513. },
  514. setContentSize: function () {
  515. //var topSize = this.topNode ? this.topNode.getSize() : {"x": 0, "y": 0};
  516. var topSize = {"x": 0, "y": 0};
  517. var nodeSize = this.node.getSize();
  518. var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  519. var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  520. var height = nodeSize.y - topSize.y - pt - pb;
  521. this.contentContainerNode.setStyle("height", "" + height + "px");
  522. },
  523. recordStatus: function(){
  524. return {
  525. "sectionId" : this.options.sectionId,
  526. "id" : this.data.id,
  527. "appId": this.data.id ? "ForumDocument"+this.data.id : undefined,
  528. "isEdited" : this.options.isEdited,
  529. "isNew" : this.options.isNew,
  530. "viewPageNum" : this.replyView ? this.replyView.getCurrentPageNum() : 1
  531. };
  532. },
  533. loadAttachment: function( area ){
  534. this.attachment = new MWF.xApplication.Forum.Attachment( area, this, this.restActions, this.lp, {
  535. documentId : this.advanceId || this.data.id,
  536. isNew : this.options.isNew,
  537. isEdited : this.options.isEdited,
  538. "size" : "min",
  539. onQueryUploadAttachment : function(){
  540. this.attachment.isQueryUploadSuccess = true;
  541. }.bind(this),
  542. onDelete : function( data ){
  543. //if( this.pictureData && this.pictureData.id == data.id ){
  544. // this.iconNode.set( "src", "" );
  545. // this.iconNode.setStyle("display","none");
  546. // this.pictureBase64 = "";
  547. // this.pictureData = null;
  548. //}
  549. }.bind(this)
  550. })
  551. this.attachment.load();
  552. },
  553. createToolbar_read : function(){
  554. this.toolBarRead = new Element("div.toolBarRead",{
  555. "styles" : this.css.toolBarRead
  556. }).inject( this.middleNode )
  557. this.toolbarLeft = new Element("div.toolbarLeft",{
  558. "styles" : this.css.toolbarLeft
  559. }).inject( this.toolBarRead )
  560. new Element("div.toolbarLeftItem",{
  561. "styles" : this.css.toolbarLeftItem,
  562. "text" : this.data.viewTotal + this.lp.readed
  563. }).inject( this.toolbarLeft )
  564. this.replyTotal = new Element("div.toolbarLeftItem",{
  565. "styles" : this.css.toolbarLeftItem,
  566. "text" : this.data.replyTotal + this.lp.reply
  567. }).inject( this.toolbarLeft )
  568. this.toolbarRight = new Element("div.toolbarRight",{
  569. "styles" : this.css.toolbarRight
  570. }).inject( this.toolBarRead )
  571. this.createActionBar();
  572. //this.toolbarRightTitle = new Element("div.toolbarRightTitle",{
  573. // "styles" : this.css.toolbarRightTitle,
  574. // "text" : "["+ this.data.type +"]"+this.data.title
  575. //}).inject( this.toolbarRight )
  576. this.toolbarRightTools = new Element("div.toolbarRightTools",{
  577. "styles" : this.css.toolbarRightTools
  578. }).inject( this.toolbarRight )
  579. if( this.nextSubject ){
  580. this.toolbarNext = new Element("div.toolbarNext",{
  581. "styles" : this.css.toolbarNext,
  582. "title" : this.lp.nextSubject + ":" + this.nextSubject.title
  583. }).inject( this.toolbarRightTools )
  584. this.toolbarNext.addEvent("click",function(){
  585. this.gotoDocument( 1 )
  586. }.bind(this))
  587. }
  588. if( this.lastSubject ){
  589. this.toolbarPrev = new Element("div.toolbarRightTools",{
  590. "styles" : this.css.toolbarPrev,
  591. "title" : this.lp.prevSubject + ":" + this.lastSubject.title
  592. }).inject( this.toolbarRightTools )
  593. this.toolbarPrev.addEvent("click",function(){
  594. this.gotoDocument( -1 )
  595. }.bind(this))
  596. }
  597. },
  598. adjustReplyCount: function( count ){
  599. this.data.replyTotal = this.data.replyTotal + count;
  600. this.replyTotal.set("text", this.data.replyTotal + this.lp.reply)
  601. },
  602. createNewDocument: function(){
  603. var _self = this;
  604. var appId = "ForumDocument";
  605. if (_self.desktop.apps[appId]){
  606. _self.desktop.apps[appId].setCurrent();
  607. }else {
  608. this.desktop.openApplication(null, "ForumDocument", {
  609. "sectionId": this.sectionData.id,
  610. "appId": appId,
  611. "isNew" : true,
  612. "isEdited" : true,
  613. "onPostPublish" : function(){
  614. //this.view.reload();
  615. }.bind(this)
  616. });
  617. }
  618. },
  619. edit : function(){
  620. var appId = "ForumDocument"+this.data.id;
  621. this.options.isEdited = true;
  622. this.reload(appId , appId );
  623. },
  624. delete : function( ev ){
  625. var _self = this;
  626. this.confirm("warn", ev, this.lp.deleteDocumentTitle, this.lp.deleteDocument, 350, 120, function(){
  627. _self.restActions.deleteSubject( _self.data.id, function(){
  628. _self.notice( _self.lp.deleteDocumentOK, "ok")
  629. _self.reloadAllParents();
  630. _self.close();
  631. }.bind(this) )
  632. this.close();
  633. }, function(){
  634. this.close();
  635. });
  636. },
  637. postCreateReply : function( id ){
  638. this.restActions.getReply( id, function( json ){
  639. var reply = this.replyView._createDocument( json.data );
  640. this.adjustReplyCount( 1 );
  641. var t = reply.node.getTop() //- this.content.getTop();
  642. this.contentContainerNode.scrollTo( 0, t );
  643. }.bind(this))
  644. },
  645. createReply : function(){
  646. var form = new MWF.xApplication.ForumDocument.ReplyForm(this, {}, {
  647. "toMain" : true,
  648. onPostOk : function( id ){
  649. this.postCreateReply( id )
  650. }.bind(this)
  651. },{
  652. app : this, lp : this.lp, css : this.css, actions : this.restActions
  653. })
  654. form.mainData = this.data;
  655. form.create()
  656. },
  657. createActionBar : function(){
  658. this.actionBar = new Element("div", { "styles" : this.css.actionBar, "html" : "&nbsp;"}).inject(this.toolbarRight)
  659. //var action = new Element("div", {
  660. // "styles" : this.css.actionItem,
  661. // "text" : this.lp.createSubject
  662. //}).inject( this.actionBar );
  663. //action.setStyle("background-image" , "url("+this.path+"icon/action_new.png)");
  664. //action.addEvents({
  665. // "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  666. // "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  667. // "click" : function(){ this.createNewDocument() }.bind(this)
  668. //})
  669. if( this.permission.manageAble || this.data.creatorName == this.userName ){
  670. action = new Element("div", {
  671. "styles" : this.css.actionItem,
  672. "text" : this.lp.edit
  673. }).inject( this.actionBar );
  674. action.setStyle("background-image" , "url("+this.path+"icon/action_edit.png)");
  675. action.addEvents({
  676. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  677. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  678. "click" : function(){ this.edit() }.bind(this)
  679. })
  680. }
  681. if( this.permission.manageAble || this.data.creatorName == this.userName ){
  682. action = new Element("div", {
  683. "styles" : this.css.actionItem,
  684. "text" : this.lp.delete
  685. }).inject( this.actionBar );
  686. action.setStyle("background-image" , "url("+this.path+"icon/action_delete.png)");
  687. action.addEvents({
  688. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  689. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  690. "click" : function(ev){ this.delete(ev) }.bind(this)
  691. })
  692. }
  693. if( !this.data.stopReply ){
  694. if( this.isReplyPublisher ){
  695. action = new Element("div", {
  696. "styles" : this.css.actionItem,
  697. "text" : this.lp.reply
  698. }).inject( this.actionBar );
  699. action.setStyle("background-image" , "url("+this.path+"icon/action_quote.png)");
  700. action.addEvents({
  701. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  702. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  703. "click" : function(){
  704. if( this.access.isAnonymousDynamic() ){
  705. this.openLoginForm( function(){ this.reload() }.bind(this) );
  706. }else{
  707. this.createReply();
  708. }
  709. }.bind(this)
  710. })
  711. }
  712. }
  713. if( this.permission.manageAble ){
  714. //if( this.data.isTopSubject ){
  715. // action = new Element("div", {
  716. // "styles" : this.css.actionItem,
  717. // "text" : this.lp.cancelTop
  718. // }).inject( this.actionBar );
  719. // action.setStyle("background-image" , "url("+this.path+"icon/action_canceltop.png)");
  720. // action.addEvents({
  721. // "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  722. // "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  723. // "click" : function(){ this.cancelTop() }.bind(this)
  724. // })
  725. //}else{
  726. action = new Element("div", {
  727. "styles" : this.css.actionItem,
  728. "text" : this.lp.setTop
  729. }).inject( this.actionBar );
  730. action.setStyle("background-image" , "url("+this.path+ ( this.data.isTopSubject ? "icon/action_canceltop.png" : "icon/action_top.png")+ ")");
  731. action.addEvents({
  732. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  733. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  734. "click" : function(){ this.setTop() }.bind(this)
  735. })
  736. //}
  737. if( this.data.isCreamSubject ){
  738. action = new Element("div", {
  739. "styles" : this.css.actionItem,
  740. "text" : this.lp.cancelPrime
  741. }).inject( this.actionBar );
  742. action.setStyle("background-image" , "url("+this.path+"icon/action_cancelprime.png)");
  743. action.addEvents({
  744. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  745. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  746. "click" : function(){ this.cancelPrime() }.bind(this)
  747. })
  748. }else{
  749. action = new Element("div", {
  750. "styles" : this.css.actionItem,
  751. "text" : this.lp.setPrime
  752. }).inject( this.actionBar );
  753. action.setStyle("background-image" , "url("+this.path+"icon/action_prime.png)");
  754. action.addEvents({
  755. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  756. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  757. "click" : function(){ this.setPrime() }.bind(this)
  758. })
  759. }
  760. action = new Element("div", {
  761. "styles" : this.css.actionItem,
  762. "text" : this.lp.setHot
  763. }).inject( this.actionBar );
  764. action.setStyle("background-image" , "url("+this.path+ "icon/action_popular.png" + ")");
  765. action.addEvents({
  766. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  767. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  768. "click" : function(){ this.setHotPicture() }.bind(this)
  769. })
  770. if( this.data.stopReply ){
  771. action = new Element("div", {
  772. "styles" : this.css.actionItem,
  773. "text" : this.lp.unlock
  774. }).inject( this.actionBar );
  775. action.setStyle("background-image" , "url("+this.path+"icon/action_unlock.png)");
  776. action.addEvents({
  777. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  778. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  779. "click" : function(){ this.unlock() }.bind(this)
  780. })
  781. }else{
  782. action = new Element("div", {
  783. "styles" : this.css.actionItem,
  784. "text" : this.lp.lock
  785. }).inject( this.actionBar );
  786. action.setStyle("background-image" , "url("+this.path+"icon/action_lock.png)");
  787. action.addEvents({
  788. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  789. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  790. "click" : function(){ this.lock() }.bind(this)
  791. })
  792. }
  793. }
  794. //if( this.access.isRecommender( this.sectionData )){
  795. if( this.permission.recommendAble ){
  796. if( this.data.recommendToBBSIndex ){
  797. action = new Element("div", {
  798. "styles" : this.css.actionItem,
  799. "text" : this.lp.cancelRecommend
  800. }).inject( this.actionBar );
  801. action.setStyle("background-image" , "url("+this.path+"icon/action_cancelrecommend.png)");
  802. action.addEvents({
  803. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  804. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  805. "click" : function(){ this.cancelRecommend() }.bind(this)
  806. })
  807. }else if( this.sectionData.sectionVisiable == this.lp.allPerson && this.sectionData.indexRecommendable == true ){
  808. action = new Element("div", {
  809. "styles" : this.css.actionItem,
  810. "text" : this.lp.setRecommend
  811. }).inject( this.actionBar );
  812. action.setStyle("background-image" , "url("+this.path+"icon/action_recommend.png)");
  813. action.addEvents({
  814. "mouseover" : function(){ this.itemNode.setStyles( this.obj.css.actionItem_over ) }.bind({ obj : this, itemNode : action }),
  815. "mouseout" : function(){ this.itemNode.setStyles( this.obj.css.actionItem ) }.bind({ obj : this, itemNode : action }),
  816. "click" : function(){ this.setRecommend() }.bind(this)
  817. })
  818. }
  819. }
  820. },
  821. lock : function(){
  822. this.restActions.lock( this.data.id, function(){
  823. this.notice( this.lp.lockSuccess )
  824. this.reload();
  825. }.bind(this))
  826. },
  827. unlock : function(){
  828. this.restActions.unlock( this.data.id, function(){
  829. this.notice( this.lp.unlockSuccess )
  830. this.reload();
  831. }.bind(this))
  832. },
  833. setRecommend : function(){
  834. this.restActions.setRecommend( this.data.id, function(){
  835. this.notice( this.lp.setRecommendSuccess )
  836. this.reload();
  837. }.bind(this))
  838. },
  839. cancelRecommend : function(){
  840. this.restActions.cancelRecommend( this.data.id, function(){
  841. this.notice( this.lp.cancelRecommendSuccess )
  842. this.reload();
  843. }.bind(this))
  844. },
  845. setHotPicture : function(){
  846. MWF.xDesktop.requireApp("ForumDocument", "HotLinkForm", null, false);
  847. var form = new MWF.xApplication.ForumDocument.HotLinkForm(this, this.data, {
  848. documentId : this.data.id,
  849. onPostOk : function( id ){
  850. }.bind(this)
  851. },{
  852. app : this, lp : this.lp, css : this.css, actions : this.restActions
  853. })
  854. form.create()
  855. },
  856. setTop : function(){
  857. var form = new MWF.xApplication.ForumDocument.TopSettingForm(this, this.data, {
  858. onPostOk : function( id ){
  859. this.reload();
  860. }.bind(this)
  861. },{
  862. app : this, lp : this.lp, css : this.css, actions : this.restActions
  863. })
  864. form.create()
  865. //this.restActions.topToSection( this.data.id, function(){
  866. // this.notice( this.lp.setTopSuccess )
  867. // this.reload();
  868. //}.bind(this))
  869. },
  870. cancelTop : function(){
  871. this.restActions.cancelTopToSection( this.data.id, function(){
  872. this.notice( this.lp.cancelTopSuccess )
  873. this.reload();
  874. }.bind(this))
  875. },
  876. setPrime : function(){
  877. this.restActions.setCream( this.data.id, function(){
  878. this.notice( this.lp.setPrimeSuccess )
  879. this.reload();
  880. }.bind(this))
  881. },
  882. cancelPrime : function(){
  883. this.restActions.cancelCream( this.data.id, function(){
  884. this.notice( this.lp.cancelPrimeSuccess )
  885. this.reload();
  886. }.bind(this))
  887. },
  888. createSubject : function(){
  889. this.subjectView = new MWF.xApplication.ForumDocument.SubjectView( this.subjectConainer, this, this, {
  890. templateUrl : this.path + "listItemSubject.json",
  891. scrollEnable : false
  892. } )
  893. this.subjectView.data = this.data;
  894. this.subjectView.load();
  895. },
  896. openLoginForm : function( callback ){
  897. //MWF.xDesktop.requireApp("Forum", "Login", null, false);
  898. //var login = new MWF.xApplication.Forum.Login(this, {
  899. // onPostOk : function(){ if(callback)callback() }
  900. //});
  901. //login.openLoginForm();
  902. MWF.require("MWF.xDesktop.Authentication", null, false);
  903. var authentication = new MWF.xDesktop.Authentication({
  904. style : "application",
  905. onPostOk : function(){ if(callback)callback() }
  906. },this);
  907. authentication.openLoginForm();
  908. },
  909. openSignUpForm : function(callback){
  910. //MWF.xDesktop.requireApp("Forum", "Login", null, false);
  911. //var login = new MWF.xApplication.Forum.Login(this, {
  912. // onPostOk : function(){ if(callback)callback() }
  913. //});
  914. //login.openSignUpForm();
  915. MWF.require("MWF.xDesktop.Authentication", null, false);
  916. var authentication = new MWF.xDesktop.Authentication({
  917. style : "application",
  918. onPostOk : function(){ if(callback)callback() }
  919. },this);
  920. authentication.openSignUpForm();
  921. },
  922. gotoReply : function( index ){
  923. this.replyView.paging.gotoItem( index );
  924. },
  925. createReplyView : function(){
  926. this.replyView = new MWF.xApplication.ForumDocument.ReplyView( this.replyViewConainer, this, this, {
  927. templateUrl : this.path + "listItemReply.json",
  928. scrollEnable : false,
  929. pagingEnable : true,
  930. documentKeyWord : "orderNumber",
  931. pagingPar : {
  932. currentPage : this.options.viewPageNum || 1,
  933. currentItem : this.options.replyIndex,
  934. returnText : this.lp.returnToList ,
  935. countPerPage : 10,
  936. onPostLoad : function( pagingBar ){
  937. if(pagingBar.nextPageNode){
  938. pagingBar.nextPageNode.inject( this.pagingBarBottom, "before" );
  939. }
  940. }.bind(this),
  941. onPageReturn : function( pagingBar ){
  942. var appId = "ForumSection"+this.sectionData.id;
  943. if (this.desktop.apps[appId]){
  944. this.desktop.apps[appId].setCurrent();
  945. }else {
  946. this.desktop.openApplication(null, "ForumSection", {
  947. "sectionId" : this.sectionData.id,
  948. "appId": appId
  949. });
  950. }
  951. this.close();
  952. }.bind(this)
  953. },
  954. onGotoItem : function( top ){
  955. var t = top - this.content.getTop();
  956. this.contentContainerNode.scrollTo( 0, t );
  957. }.bind(this)
  958. } )
  959. this.replyView.pagingContainerTop = this.pagingContainerTop;
  960. this.replyView.pagingContainerBottom = this.pagingContainerBottom;
  961. this.replyView.data = this.data;
  962. this.replyView.filterData = { "subjectId" : this.data.id };
  963. this.replyView.load();
  964. },
  965. createReplyEditor_Anonymous: function(){
  966. this.replyArea = new Element("div.replyArea",{
  967. "styles" : this.css.replyArea
  968. }).inject( this.middleNode );
  969. new Element("div.replyLeft",{
  970. "styles" : this.css.replyLeft
  971. }).inject( this.replyArea )
  972. var replyPicture = new Element("div.replyPicture",{
  973. "styles" : this.css.replyPicture
  974. }).inject( this.replyArea )
  975. var needloginNode = new Element("div.replyNeedLogin",{
  976. "styles" : this.css.replyNeedLogin
  977. }).inject(replyPicture)
  978. new Element("div.replyNeedLogin",{
  979. "styles" : this.css.replyNeedLoginText,
  980. "text" : this.lp.replyNeedLoginText
  981. }).inject(needloginNode)
  982. var loginNode = new Element("div.replyLoginAction",{
  983. "styles" : this.css.replyLoginAction,
  984. "text" : this.lp.login
  985. }).inject(needloginNode)
  986. loginNode.addEvent("click" , function(){
  987. this.openLoginForm(
  988. function(){ this.reload() }.bind(this)
  989. )
  990. }.bind(this))
  991. if( this.access.signUpMode != "disable" ){
  992. new Element("div.replyNeedLogin",{
  993. "styles" : this.css.replyNeedLoginText,
  994. "text" : "|"
  995. }).inject(needloginNode)
  996. var signupNode = new Element("div.replyLoginAction",{
  997. "styles" : this.css.replyLoginAction,
  998. "text" : this.lp.signUp
  999. }).inject(needloginNode)
  1000. signupNode.addEvent("click" , function(){
  1001. this.openSignUpForm()
  1002. }.bind(this))
  1003. }
  1004. },
  1005. createReplyEditor : function( ){
  1006. this.replyArea = new Element("div.replyArea",{
  1007. "styles" : this.css.replyArea
  1008. }).inject( this.middleNode );
  1009. this.replyEditor = new MWF.xApplication.ForumDocument.ReplyEditor( this.replyArea, this, {
  1010. style : this.options.style,
  1011. isNew : true,
  1012. onPostOk : function( id ){
  1013. this.postCreateReply( id )
  1014. }.bind(this)
  1015. } )
  1016. this.replyEditor.mainData = this.data;
  1017. this.replyEditor.load();
  1018. },
  1019. createTurnSubjectNode : function(){
  1020. if( !this.lastSubject && !this.nextSubject )return;
  1021. var turnSubjectNode = new Element("div.turnSubjectNode", {styles : this.css.turnSubjectNode}).inject( this.middleNode );
  1022. if( this.lastSubject ){
  1023. var lastSubjectNode = new Element( "div.lastSubjectNode", {
  1024. styles : this.css.lastSubjectNode,
  1025. text : this.lp.prevSubject + ":" + this.lastSubject.title
  1026. }).inject( turnSubjectNode );
  1027. lastSubjectNode.addEvents({
  1028. "click" : function(){
  1029. this.gotoDocument(-1)
  1030. }.bind(this),
  1031. "mouseover" : function(){ this.node.setStyles( this.obj.css.lastSubjectNode_over ) }.bind({obj :this, node : lastSubjectNode}),
  1032. "mouseout" : function(){ this.node.setStyles( this.obj.css.lastSubjectNode ) }.bind({obj :this, node : lastSubjectNode})
  1033. })
  1034. }else{
  1035. var lastSubjectNode = new Element( "div.lastSubjectNode", {
  1036. styles : this.css.lastSubjectNoneNode
  1037. }).inject( turnSubjectNode );
  1038. }
  1039. if( this.nextSubject ){
  1040. var nextSubjectNode = new Element( "div.nextSubjectNode", {
  1041. styles : this.css.nextSubjectNode,
  1042. text : this.lp.nextSubject + ":" + this.nextSubject.title
  1043. }).inject( turnSubjectNode );
  1044. nextSubjectNode.addEvents({
  1045. "click" : function(){
  1046. this.gotoDocument(1)
  1047. }.bind(this),
  1048. "mouseover" : function(){ this.node.setStyles( this.obj.css.nextSubjectNode_over ) }.bind({obj :this, node : nextSubjectNode}),
  1049. "mouseout" : function(){ this.node.setStyles( this.obj.css.nextSubjectNode ) }.bind({obj :this, node : nextSubjectNode})
  1050. })
  1051. }else{
  1052. var nextSubjectNode = new Element( "div.nextSubjectNode", {
  1053. styles : this.css.nextSubjectNoneNode
  1054. }).inject( turnSubjectNode );
  1055. }
  1056. },
  1057. gotoDocument : function( count ){
  1058. if( count == 1 ){
  1059. var documentData = this.nextSubject;
  1060. }else{
  1061. var documentData = this.lastSubject;
  1062. }
  1063. var oldId = "ForumDocument"+this.data.id;
  1064. var appId = "ForumDocument"+documentData.id;
  1065. if (this.desktop.apps[appId]){
  1066. this.desktop.apps[appId].setCurrent();
  1067. //this.close();
  1068. }else {
  1069. this.setOptions({
  1070. "sectionId" : null, //this.data.sectionId,
  1071. "id" : documentData.id,
  1072. "appId": appId,
  1073. "isEdited" : false,
  1074. "isNew" : false
  1075. });
  1076. this.reload(oldId , appId );
  1077. }
  1078. //var nextIndex = this.options.index + count;
  1079. //if( nextIndex < 0 ){
  1080. // this.notice( count == -1 ? this.lp.noPrevSubject : this.lp.noNextSubject );
  1081. // return;
  1082. //}
  1083. //this.restActions.listSubjectFilterPage( nextIndex+1, 1, { sectionId : this.sectionData.id },function (json) {
  1084. // if( !json.data || json.data.length == 0 ){
  1085. // this.notice( count == -1 ? this.lp.noPrevSubject : this.lp.noNextSubject )
  1086. // }else{
  1087. // var documentData = json.data[0];
  1088. // var oldId = "ForumDocument"+this.data.id;
  1089. // var appId = "ForumDocument"+documentData.id;
  1090. // if (this.desktop.apps[appId]){
  1091. // this.desktop.apps[appId].setCurrent();
  1092. // //this.close();
  1093. // }else {
  1094. // this.setOptions({
  1095. // "sectionId" : documentData.sectionId,
  1096. // "id" : documentData.id,
  1097. // "appId": appId,
  1098. // "isEdited" : false,
  1099. // "isNew" : false,
  1100. // "index" : nextIndex
  1101. // });
  1102. // this.reload(oldId , appId );
  1103. // }
  1104. // }
  1105. //}.bind(this))
  1106. },
  1107. getDateDiff: function (publishTime) {
  1108. if(!publishTime)return "";
  1109. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  1110. var minute = 1000 * 60;
  1111. var hour = minute * 60;
  1112. var day = hour * 24;
  1113. var halfamonth = day * 15;
  1114. var month = day * 30;
  1115. var year = month * 12;
  1116. var now = new Date().getTime();
  1117. var diffValue = now - dateTimeStamp;
  1118. if (diffValue < 0) {
  1119. //若日期不符则弹出窗口告之
  1120. //alert("结束日期不能小于开始日期!");
  1121. }
  1122. var yesterday = new Date().decrement('day', 1);
  1123. var beforYesterday = new Date().decrement('day', 2);
  1124. var yearC = diffValue / year;
  1125. var monthC = diffValue / month;
  1126. var weekC = diffValue / (7 * day);
  1127. var dayC = diffValue / day;
  1128. var hourC = diffValue / hour;
  1129. var minC = diffValue / minute;
  1130. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  1131. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  1132. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  1133. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  1134. } else if (yearC > 1) {
  1135. result = dateTimeStamp.getFullYear() + "年" + (dateTimeStamp.getMonth() + 1) + "月" + dateTimeStamp.getDate() + "日";
  1136. } else if (monthC >= 1) {
  1137. //result= parseInt(monthC) + "个月前";
  1138. // s.getFullYear()+"年";
  1139. result = (dateTimeStamp.getMonth() + 1) + "月" + dateTimeStamp.getDate() + "日";
  1140. } else if (weekC >= 1) {
  1141. result = parseInt(weekC) + "周前";
  1142. } else if (dayC >= 1) {
  1143. result = parseInt(dayC) + "天前";
  1144. } else if (hourC >= 1) {
  1145. result = parseInt(hourC) + "小时前";
  1146. } else if (minC >= 1) {
  1147. result = parseInt(minC) + "分钟前";
  1148. } else
  1149. result = "刚才";
  1150. return result;
  1151. },
  1152. openPerson : function( userName ){
  1153. var appId = "ForumPerson"+userName;
  1154. if (this.desktop.apps[userName]){
  1155. this.desktop.apps[userName].setCurrent();
  1156. }else {
  1157. this.desktop.openApplication(null, "ForumPerson", {
  1158. "personName" : userName,
  1159. "appId": appId
  1160. });
  1161. }
  1162. },
  1163. createPersonNode : function( container, personName ){
  1164. var persons = personName.split(",");
  1165. persons.each( function(userName, i){
  1166. var span = new Element("span", {
  1167. "text" : userName,
  1168. "styles" : this.css.person
  1169. }).inject(container);
  1170. span.addEvents( {
  1171. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  1172. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  1173. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  1174. })
  1175. if( i != persons.length - 1 ){
  1176. new Element("span", {
  1177. "text" : ",",
  1178. }).inject(container);
  1179. }
  1180. }.bind(this))
  1181. }
  1182. });
  1183. MWF.xApplication.ForumDocument.SubjectView = new Class({
  1184. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  1185. _createDocument: function(data, index){
  1186. data.index = index;
  1187. this.getUserData( data.creatorName, function(json ){
  1188. data.userIcon = json.data.icon;
  1189. data.signature = json.data.signature;
  1190. this.actions.getUserInfor( {"userName":data.creatorName}, function( json ){
  1191. data.subject = json.data.subjectCount;
  1192. data.reply = json.data.replyCount;
  1193. data.todaySubject = json.data.subjectCountToday;
  1194. data.todayReply = json.data.replyCountToday;
  1195. data.prime = json.data.creamCount;
  1196. data.accessed = json.data.popularity;
  1197. return new MWF.xApplication.ForumDocument.SubjectDocument(this.viewNode, data, this.explorer, this, null, data.index );
  1198. }.bind(this))
  1199. }.bind(this) )
  1200. },
  1201. getUserData : function( name, callback ){
  1202. if( this.app.access.isAnonymous() ){
  1203. this.actions.getPersonIcon(name, function(url){
  1204. if( callback )callback( { data : {
  1205. icon : url
  1206. } } );
  1207. }, function(){
  1208. if( callback )callback( { data : {
  1209. icon : "/x_component_ForumDocument/$Main/"+this.options.style+"/icon/noavatar_big.gif"
  1210. } } );
  1211. }.bind(this))
  1212. }else{
  1213. this.actions.getPerson( function( json ){
  1214. if( !json.data )json.data = {};
  1215. if( json.data.icon ){
  1216. json.data.icon = 'data:image/png;base64,'+json.data.icon;
  1217. }else{
  1218. json.data.icon = "/x_component_ForumDocument/$Main/"+this.options.style+"/icon/noavatar_big.gif"
  1219. }
  1220. if( callback )callback( json );
  1221. }.bind(this), null, name, true )
  1222. }
  1223. },
  1224. _getCurrentPageData: function(callback, count){
  1225. var json = {
  1226. type: "success",
  1227. count : 1,
  1228. size : 1,
  1229. data : [this.data]
  1230. };
  1231. if (callback)callback(json)
  1232. },
  1233. _removeDocument: function(documentData, all){
  1234. this.actions.deleteSection(documentData.id, function(json){
  1235. this.reload();
  1236. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  1237. }.bind(this));
  1238. },
  1239. _create: function(){
  1240. },
  1241. _queryCreateViewNode: function(){
  1242. },
  1243. _postCreateViewNode: function( viewNode ){
  1244. },
  1245. _queryCreateViewHead:function(){
  1246. },
  1247. _postCreateViewHead: function( headNode ){
  1248. }
  1249. });
  1250. MWF.xApplication.ForumDocument.SubjectDocument = new Class({
  1251. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  1252. mouseoverSubject : function(subjectNode, ev){
  1253. //var removeNode = sectionNode.getElements("[styles='sectionRemoveNode']")[0];
  1254. //if( removeNode )removeNode.setStyle("opacity",1)
  1255. },
  1256. mouseoutSubject : function(subjectNode, ev){
  1257. //var removeNode = sectionNode.getElements("[styles='sectionRemoveNode']")[0];
  1258. //if( removeNode )removeNode.setStyle("opacity",0)
  1259. },
  1260. _queryCreateDocumentNode:function( itemData ){
  1261. },
  1262. _postCreateDocumentNode: function( itemNode, itemData ){
  1263. if( this.data.attachmentList && this.data.attachmentList.length > 0 ){
  1264. var attachmentArea = itemNode.getElements("[item='attachment']")[0];
  1265. this.app.loadAttachment(attachmentArea);
  1266. }
  1267. },
  1268. sendMessage : function(itemNode, ev ){
  1269. var self = this;
  1270. if (layout.desktop.widgets["IMIMWidget"]) {
  1271. var IM = layout.desktop.widgets["IMIMWidget"];
  1272. IM.getOwner(function(){
  1273. this.openChat(ev, {
  1274. from : self.data.creatorName
  1275. });
  1276. }.bind(IM));
  1277. }
  1278. },
  1279. createReply : function(itemNode, ev ){
  1280. if( this.app.access.isAnonymousDynamic() ){
  1281. this.app.openLoginForm( function(){ this.app.reload() }.bind(this) );
  1282. }else{
  1283. var form = new MWF.xApplication.ForumDocument.ReplyForm(this, {}, {
  1284. "toMain" : true,
  1285. onPostOk : function( id ){
  1286. this.app.postCreateReply( id );
  1287. }.bind(this)
  1288. });
  1289. form.mainData = this.data;
  1290. form.create()
  1291. }
  1292. }
  1293. })
  1294. MWF.xApplication.ForumDocument.ReplyEditor = new Class({
  1295. Implements: [Options , Events],
  1296. options: {
  1297. "style": "default",
  1298. "isNew" : true
  1299. },
  1300. initialize: function(node, app, options){
  1301. this.setOptions(options);
  1302. this.node = node;
  1303. this.app = app;
  1304. },
  1305. load: function(){
  1306. this.app.restActions.getUUID( function( id ){
  1307. this.advanceReplyId = id;
  1308. this._load();
  1309. }.bind(this))
  1310. },
  1311. _load: function(){
  1312. var html = "<div styles='itemNode'>" +
  1313. " <div styles='itemLeftNode'>" +
  1314. " <div styles='itemUserFace'>" +
  1315. " <div styles='itemUserIcon' item='userIcon'>" +
  1316. " </div>" +
  1317. " </div>" +
  1318. " <div styles='replyUserName' item='creatorName'>" +
  1319. " </div>" +
  1320. " </div>" +
  1321. " <div styles='replyRightNode'>" +
  1322. " <div styles='itemRightMidle'>" +
  1323. " <div styles='itemBody' item='content'></div>" +
  1324. " <div styles='itemBody' item='action'></div>" +
  1325. " </div>" +
  1326. " </div>" +
  1327. "</div>"
  1328. this.node.set("html", html);
  1329. var actionTd = this.node.getElements("[item='action']")[0];
  1330. this.saveReplyAction = new Element("div",{
  1331. styles : this.app.css.actionNode,
  1332. text: this.app.lp.saveReply
  1333. }).inject(actionTd);
  1334. this.saveReplyAction.addEvent("click",function(){
  1335. this.saveReply();
  1336. }.bind(this));
  1337. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1338. this.form = new MForm(this.node, this.data || {}, {
  1339. style: "forum",
  1340. isEdited: this.options.isEdited || this.options.isNew,
  1341. itemTemplate: {
  1342. userIcon: { className : "itemUserIcon2", type : "img", value : function(){
  1343. if( this.app.userData.icon ){
  1344. return "data:image/png;base64,"+ this.app.userData.icon
  1345. }else{
  1346. return "/x_component_ForumDocument/$Main/"+this.options.style+"/icon/noavatar_big.gif"
  1347. }
  1348. }.bind(this)},
  1349. creatorName: { type : "innerText", value : this.app.userName },
  1350. content: { type : "rtf", RTFConfig : {
  1351. skin : "bootstrapck",
  1352. "resize_enabled": false,
  1353. isSetImageMaxWidth : true,
  1354. reference : this.advanceReplyId,
  1355. referenceType: "forumReply",
  1356. //uiColor : '#9AB8F3',
  1357. //toolbarCanCollapse : true,
  1358. toolbar : [
  1359. { name: 'document', items : [ 'Preview' ] },
  1360. //{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
  1361. { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','-','RemoveFormat' ] },
  1362. //{ name: 'paragraph', items : [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },
  1363. { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
  1364. { name: 'colors', items : [ 'TextColor','BGColor' ] },
  1365. { name: 'links', items : [ 'Link','Unlink' ] },
  1366. { name: 'insert', items : [ 'Image' ] },
  1367. { name: 'tools', items : [ 'Maximize','-','About' ] }
  1368. ]
  1369. }}
  1370. }
  1371. }, this, this.app.css);
  1372. this.form.load();
  1373. }.bind(this), true);
  1374. },
  1375. saveReply : function(){
  1376. var data = this.form.getResult(true, ",", true, false, true);
  1377. if (data) {
  1378. data.subjectId = this.mainData.id ;
  1379. data.id = this.advanceReplyId;
  1380. this.app.restActions.saveReply(data, function (json) {
  1381. if (json.type == "error") {
  1382. this.app.notice(json.message, "error");
  1383. } else {
  1384. this.app.notice( this.app.lp.saveReplySuccess, "ok" );
  1385. this.form.getItem("content").setValue("");
  1386. this.fireEvent("postOk", json.data.id);
  1387. }
  1388. }.bind(this))
  1389. }
  1390. }
  1391. })
  1392. MWF.xApplication.ForumDocument.ReplyForm = new Class({
  1393. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  1394. Implements: [Options, Events],
  1395. options: {
  1396. "style": "default",
  1397. "width": "820",
  1398. "height": "470",
  1399. "hasTop": true,
  1400. "hasIcon": false,
  1401. "hasTopIcon" : true,
  1402. "hasTopContent" : true,
  1403. "hasBottom": true,
  1404. "title": MWF.xApplication.Forum.LP.replyFormTitle,
  1405. "draggable": true,
  1406. "closeAction": true,
  1407. "toMain" : true
  1408. },
  1409. _createTableContent: function(){
  1410. if( this.isNew ){
  1411. this.app.restActions.getUUID( function(id){
  1412. this.advanceReplyId = id;
  1413. this._createTableContent_();
  1414. }.bind(this) )
  1415. }else{
  1416. this._createTableContent_()
  1417. }
  1418. },
  1419. _createTableContent_: function () {
  1420. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1421. "<tr>" +
  1422. " <td styles='formTableValue14' item='mainSubject'></td>" +
  1423. "</tr><tr>" +
  1424. " <td styles='formTableValue' item='mainContent'></td>" +
  1425. "</tr><tr>" +
  1426. " <td styles='formTableValue' item='content'></td>" +
  1427. "</tr>"
  1428. "</table>"
  1429. this.formTableArea.set("html", html);
  1430. if( !this.options.toMain && this.parentData ){
  1431. var mainContentEl = this.formTableArea.getElements("[item='mainContent']")[0];
  1432. var quoteTop = new Element( "div", {styles : this.css.quoteTop} ).inject( mainContentEl );
  1433. new Element( "div", {styles : this.css.quoteLeft} ).inject( quoteTop );
  1434. new Element( "div", {
  1435. styles : this.css.quoteInfor,
  1436. text : this.parentData.creatorName + this.lp.publishAt + this.parentData.createTime
  1437. }).inject( quoteTop );
  1438. var quoteBottom = new Element( "div", {styles : this.css.quoteBottom} ).inject( mainContentEl );
  1439. var text = this.parentData.contentText;
  1440. new Element( "div", {
  1441. styles : this.css.quoteText,
  1442. text : text.length > 50 ? (text.substr(0, 50) + "...") : text
  1443. }).inject( quoteBottom );
  1444. new Element( "div", {styles : this.css.quoteRight} ).inject( quoteBottom );
  1445. }
  1446. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1447. this.form = new MForm(this.formTableArea, this.data, {
  1448. style: "forum",
  1449. isEdited: this.isEdited || this.isNew,
  1450. itemTemplate: {
  1451. mainSubject: { type: "innertext", defaultValue : "RE:" + this.mainData.title },
  1452. content: { type : "rtf", RTFConfig : {
  1453. skin : "bootstrapck",
  1454. "resize_enabled": false,
  1455. isSetImageMaxWidth : true,
  1456. reference : this.advanceReplyId || this.data.id,
  1457. referenceType: "forumReply",
  1458. toolbar : [
  1459. { name: 'document', items : [ 'Preview' ] },
  1460. //{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
  1461. { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','-','RemoveFormat' ] },
  1462. //{ name: 'paragraph', items : [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },
  1463. { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] },
  1464. { name: 'colors', items : [ 'TextColor','BGColor' ] },
  1465. { name: 'links', items : [ 'Link','Unlink' ] },
  1466. { name: 'insert', items : [ 'Image' ] },
  1467. { name: 'tools', items : [ 'Maximize','-','About' ] }
  1468. ]
  1469. }}
  1470. }
  1471. }, this.app, this.css);
  1472. this.form.load();
  1473. }.bind(this), true);
  1474. },
  1475. _createBottomContent: function () {
  1476. if (this.isNew || this.isEdited) {
  1477. this.okActionNode = new Element("div.formOkActionNode", {
  1478. "styles": this.css.formOkActionNode,
  1479. "text": this.app.lp.saveReply
  1480. }).inject(this.formBottomNode);
  1481. this.okActionNode.addEvent("click", function (e) {
  1482. this.ok(e);
  1483. }.bind(this));
  1484. }
  1485. this.cancelActionNode = new Element("div.formCancelActionNode", {
  1486. "styles": this.css.formCancelActionNode,
  1487. "text": this.app.lp.close
  1488. }).inject(this.formBottomNode);
  1489. this.cancelActionNode.addEvent("click", function (e) {
  1490. this.cancel(e);
  1491. }.bind(this));
  1492. },
  1493. ok: function (e) {
  1494. this.fireEvent("queryOk");
  1495. var data = this.form.getResult(true, ",", true, false, true);
  1496. if (data) {
  1497. this._ok(data, function (json) {
  1498. if (json.type == "error") {
  1499. this.app.notice(json.message, "error");
  1500. } else {
  1501. this.formMarkNode.destroy();
  1502. this.formAreaNode.destroy();
  1503. this.app.notice(this.isNew ? this.app.lp.createSuccess : this.app.lp.updateSuccess, "success");
  1504. this.fireEvent("postOk", json.data.id);
  1505. }
  1506. }.bind(this))
  1507. }
  1508. },
  1509. _ok: function (data, callback) {
  1510. data.subjectId = this.mainData.id ;
  1511. if( this.advanceReplyId )data.id = this.advanceReplyId;
  1512. if( !this.options.toMain ){
  1513. data.parentId = this.parentData.id ;
  1514. }
  1515. this.app.restActions.saveReply( data, function(json){
  1516. if( callback )callback(json);
  1517. }.bind(this));
  1518. }
  1519. });
  1520. MWF.xApplication.ForumDocument.ReplyView = new Class({
  1521. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  1522. _createDocument: function(data, index){
  1523. data.index = index;
  1524. return new MWF.xApplication.ForumDocument.ReplyDocument(this.viewNode, data, this.explorer, this, null, data.index );
  1525. },
  1526. _getCurrentPageData: function(callback, count, pageNum){
  1527. this.clearBody();
  1528. if(!count)count=10;
  1529. if(!pageNum)pageNum = 1;
  1530. if( pageNum == 1 ){
  1531. this.app.subjectConainer.setStyle("display","block");
  1532. }else{
  1533. this.app.subjectConainer.setStyle("display","none");
  1534. }
  1535. //page, count, filterData, success,failure, async
  1536. //if( !this.page ){
  1537. // this.page = 1;
  1538. //}else{
  1539. // this.page ++;
  1540. //}
  1541. //var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  1542. var filter = this.filterData || {};
  1543. this.actions.listReplyFilterPage( pageNum, count, filter, function(json){
  1544. if( !json.data )json.data = [];
  1545. if( !json.count )json.count=0;
  1546. if( callback )callback(json);
  1547. }.bind(this))
  1548. },
  1549. _removeDocument: function(documentData, all){
  1550. this.actions.deleteReply( documentData.id, function(){
  1551. this.reload();
  1552. this.app.notice( this.lp.deleteReplySuccess, "ok")
  1553. }.bind(this) )
  1554. },
  1555. _create: function(){
  1556. },
  1557. _queryCreateViewNode: function(){
  1558. },
  1559. _postCreateViewNode: function( viewNode ){
  1560. },
  1561. _queryCreateViewHead:function(){
  1562. },
  1563. _postCreateViewHead: function( headNode ){
  1564. }
  1565. });
  1566. MWF.xApplication.ForumDocument.ReplyDocument = new Class({
  1567. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  1568. mouseoverSubject : function(subjectNode, ev){
  1569. //var removeNode = sectionNode.getElements("[styles='sectionRemoveNode']")[0];
  1570. //if( removeNode )removeNode.setStyle("opacity",1)
  1571. },
  1572. mouseoutSubject : function(subjectNode, ev){
  1573. //var removeNode = sectionNode.getElements("[styles='sectionRemoveNode']")[0];
  1574. //if( removeNode )removeNode.setStyle("opacity",0)
  1575. },
  1576. getUserData : function( name, callback ){
  1577. if( this.app.access.isAnonymous() ){
  1578. this.actions.getPersonIcon(name, function(url){
  1579. if( callback )callback( { data : {
  1580. icon : url
  1581. } } );
  1582. }, function(){
  1583. if( callback )callback( { data : {
  1584. icon : "/x_component_ForumDocument/$Main/"+this.view.options.style+"/icon/noavatar_big.gif"
  1585. } } );
  1586. }.bind(this))
  1587. }else{
  1588. this.actions.getPerson( function( json ){
  1589. if( !json.data )json.data = {};
  1590. if( json.data.icon ){
  1591. json.data.icon = 'data:image/png;base64,'+json.data.icon;
  1592. }else{
  1593. json.data.icon = "/x_component_ForumDocument/$Main/"+this.view.options.style+"/icon/noavatar_big.gif"
  1594. }
  1595. if( callback )callback( json );
  1596. }.bind(this), null, name, true )
  1597. }
  1598. },
  1599. _queryCreateDocumentNode:function( itemData ){
  1600. },
  1601. _postCreateDocumentNode: function( itemNode, itemData ){
  1602. var userIcon = itemNode.getElements( "[item='userIcon']" )[0];
  1603. var signatureContainer = itemNode.getElements("[item='signatureContainer']")[0];
  1604. this.getUserData( itemData.creatorName, function(json ){
  1605. userIcon.src = json.data.icon;
  1606. if( json.data.signature && json.data.signature!="" ){
  1607. var signatureNode = signatureContainer.getElements("[item='signature']")[0];
  1608. signatureNode.set("text", json.data.signature )
  1609. }else{
  1610. signatureContainer.destroy();
  1611. }
  1612. }.bind(this) );
  1613. this.actions.getUserInfor( {"userName":itemData.creatorName}, function( json ){
  1614. var d = json.data;
  1615. itemNode.getElements( "[item='subject']" )[0].set("text", d.subjectCount);
  1616. itemNode.getElements( "[item='reply']" )[0].set("text", d.replyCount);
  1617. itemNode.getElements( "[item='prime']" )[0].set("text", d.creamCount);
  1618. itemNode.getElements( "[item='todaySubject']" )[0].set("text", d.subjectCountToday);
  1619. itemNode.getElements( "[item='todayReply']" )[0].set("text", d.replyCountToday);
  1620. }.bind(this))
  1621. if( itemData.parentId && itemData.parentId != "" ){
  1622. var quoteContainer = itemNode.getElements( "[item='quoteContent']" )[0];
  1623. this.actions.getReply( itemData.parentId, function( json ){
  1624. var data = this.parentData = json.data;
  1625. var quoteContent = new Element("div", { "styles" : this.css.itemQuote }).inject(quoteContainer)
  1626. var content = quoteContent.set("html", data.content).get("text");
  1627. quoteContent.empty();
  1628. data.contentText = content;
  1629. new Element( "div", {styles : this.css.quoteLeftBig} ).inject( quoteContent );
  1630. var quoteArea = new Element( "div", {styles : this.css.quoteAreaBig } ).inject( quoteContent );
  1631. var quoteInfor = new Element( "div", {
  1632. styles : this.css.quoteInforBig,
  1633. text : data.orderNumber + this.lp.floor + ":" + data.creatorName + this.lp.publishAt + data.createTime
  1634. }).inject( quoteArea );
  1635. quoteInfor.addEvent("click", function(){
  1636. this.obj.app.gotoReply( this.index )
  1637. }.bind({obj : this, index : data.orderNumber || (data.index + 2) }))
  1638. new Element( "div", {
  1639. styles : this.css.quoteTextBig,
  1640. text : content.length > 100 ? (content.substr(0, 100) + "...") : content
  1641. }).inject( quoteArea );
  1642. new Element( "div", {styles : this.css.quoteRightBig} ).inject( quoteContent );
  1643. }.bind(this) , function( json ){
  1644. new Element( "div" , {
  1645. "styles" : this.css.replyBeinngDelete,
  1646. "text" : this.lp.quoteReplyBeingDeleted
  1647. }).inject(quoteContainer)
  1648. }.bind(this)
  1649. )
  1650. }
  1651. },
  1652. sendMessage : function(itemNode, ev ){
  1653. var self = this;
  1654. if (layout.desktop.widgets["IMIMWidget"]) {
  1655. var IM = layout.desktop.widgets["IMIMWidget"];
  1656. IM.getOwner(function(){
  1657. this.openChat(ev, {
  1658. from : self.data.creatorName
  1659. });
  1660. }.bind(IM));
  1661. }
  1662. },
  1663. createReply : function(itemNode, ev ){ // 对回复进行回复
  1664. if( this.app.access.isAnonymousDynamic() ){
  1665. this.app.openLoginForm( function(){ this.app.reload() }.bind(this) );
  1666. }else{
  1667. var form = new MWF.xApplication.ForumDocument.ReplyForm(this, {}, {
  1668. toMain: false,
  1669. onPostOk: function (id) {
  1670. this.app.postCreateReply(id)
  1671. }.bind(this)
  1672. })
  1673. this.data.contentText = this.node.getElements("[item='content']")[0].get("text");
  1674. form.mainData = this.app.data;
  1675. form.parentData = this.data;
  1676. form.create()
  1677. }
  1678. },
  1679. editReply : function(itemNode, ev ){ //编辑当前回复
  1680. var form = new MWF.xApplication.ForumDocument.ReplyForm(this, this.data, {
  1681. toMain : (this.data.parentId && this.data.parentId!="") ? false : true,
  1682. onPostOk : function( id ){
  1683. this.actions.getReply( id, function( json ){
  1684. var content = this.node.getElements("[item='content']")[0];
  1685. content.set( "html", json.data.content );
  1686. }.bind(this))
  1687. }.bind(this)
  1688. })
  1689. form.mainData = this.app.data;
  1690. form.parentData = this.parentData;
  1691. form.edit()
  1692. },
  1693. deleteReply : function( itemNode, ev ){
  1694. var _self = this;
  1695. this.app.confirm("warn", ev, this.lp.deleteReplyTitle, this.lp.deleteReplyText, 350, 120, function(){
  1696. //_self.view._removeDocument(_self.data, false);
  1697. _self.actions.deleteReply( _self.data.id, function(){
  1698. _self.destroy();
  1699. _self.app.adjustReplyCount( -1 );
  1700. _self.app.notice( _self.lp.deleteReplySuccess, "ok")
  1701. }.bind(this) )
  1702. this.close();
  1703. }, function(){
  1704. this.close();
  1705. });
  1706. }
  1707. });
  1708. MWF.xApplication.ForumDocument.TopSettingForm = new Class({
  1709. Extends: MWF.xApplication.Template.Explorer.PopupForm,
  1710. Implements: [Options, Events],
  1711. options: {
  1712. "style": "default",
  1713. "width": "420",
  1714. "height": "250",
  1715. "hasTop": true,
  1716. "hasIcon": false,
  1717. "hasTopIcon" : true,
  1718. "hasTopContent" : true,
  1719. "hasBottom": true,
  1720. "title": MWF.xApplication.Forum.LP.topFormTitle,
  1721. "draggable": true,
  1722. "closeAction": true
  1723. },
  1724. createTopNode: function () {
  1725. if (!this.formTopNode) {
  1726. this.formTopNode = new Element("div.formTopNode", {
  1727. "styles": this.css.formTopNode
  1728. }).inject(this.formNode);
  1729. if(this.options.hasTopIcon){
  1730. this.formTopIconNode = new Element("div", {
  1731. "styles": this.css.formTopIconNodeDocument
  1732. }).inject(this.formTopNode)
  1733. }
  1734. this.formTopTextNode = new Element("div", {
  1735. "styles": this.css.formTopTextNodeTopSetting,
  1736. "text": this.options.title
  1737. }).inject(this.formTopNode)
  1738. if (this.options.closeAction) {
  1739. this.formTopCloseActionNode = new Element("div", {"styles": this.css.formTopCloseActionNode}).inject(this.formTopNode);
  1740. this.formTopCloseActionNode.addEvent("click", function () {
  1741. this.close()
  1742. }.bind(this))
  1743. }
  1744. }
  1745. },
  1746. _createTableContent: function () {
  1747. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1748. "<tr>" +
  1749. " <td styles='formTableValue' style='font-size:14px;' lable='topType'></td>" +
  1750. //"</tr><tr>" +
  1751. //" <td styles='formTableValue' item='topToBBS'></td>" +
  1752. "</tr><tr>" +
  1753. " <td styles='formTableValue' item='topToForum'></td>" +
  1754. "</tr><tr>" +
  1755. " <td styles='formTableValue' item='topToSection'></td>" +
  1756. "</tr>"
  1757. "</table>"
  1758. this.formTableArea.set("html", html);
  1759. this.topToBBS = this.data.topToBBS;
  1760. this.topToForum = this.data.topToForum;
  1761. this.topToSection = this.data.topToSection;
  1762. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1763. this.form = new MForm(this.formTableArea, this.data, {
  1764. style: "forum",
  1765. isEdited: this.isEdited || this.isNew,
  1766. itemTemplate: {
  1767. topType : { text : this.lp.topType },
  1768. //topToBBS: { type: "checkbox", selectValue : [true], selectText : [this.lp.topToBBS] },
  1769. topToForum: { type: "checkbox", selectValue : ["true"], selectText : [this.lp.topToForum]},
  1770. topToSection: { type: "checkbox", selectValue : ["true"], selectText : [this.lp.topToSection] }
  1771. }
  1772. }, this.app, this.css);
  1773. this.form.load();
  1774. }.bind(this), true);
  1775. },
  1776. _createBottomContent: function () {
  1777. if (this.isNew || this.isEdited) {
  1778. this.okActionNode = new Element("div.formOkActionNode", {
  1779. "styles": this.css.formOkActionNode,
  1780. "text": this.app.lp.ok
  1781. }).inject(this.formBottomNode);
  1782. this.okActionNode.addEvent("click", function (e) {
  1783. this.ok(e);
  1784. }.bind(this));
  1785. }
  1786. this.cancelActionNode = new Element("div.formCancelActionNode", {
  1787. "styles": this.css.formCancelActionNode,
  1788. "text": this.app.lp.close
  1789. }).inject(this.formBottomNode);
  1790. this.cancelActionNode.addEvent("click", function (e) {
  1791. this.cancel(e);
  1792. }.bind(this));
  1793. },
  1794. ok: function (e) {
  1795. this.fireEvent("queryOk");
  1796. var data = this.form.getResult(true, ",", true, false, true);
  1797. if (data) {
  1798. var flag = true;
  1799. //if( data.topToBBS === true || data.topToBBS === "true" ){
  1800. // this.actions.topToBBS( this.app.data.id , function( json ){
  1801. // if (json.type == "error") {
  1802. // this.app.notice(json.userMessage, "error");
  1803. // flag = false;
  1804. // }
  1805. // }, function(){
  1806. // flag = false;
  1807. // }, false )
  1808. //}else if( this.topToBBS === true || this.topToBBS === "true" ){
  1809. // this.actions.cancelTopToBBS( this.app.data.id , function( json ){
  1810. // if (json.type == "error") {
  1811. // this.app.notice(json.userMessage, "error");
  1812. // flag = false;
  1813. // }
  1814. // }, function(){
  1815. // flag = false;
  1816. // }, false )
  1817. //}
  1818. if( data.topToForum === true || data.topToForum === "true" ){
  1819. this.actions.topToForum( this.app.data.id , function( json ){
  1820. if (json.type == "error") {
  1821. this.app.notice(json.message, "error");
  1822. flag = false;
  1823. }
  1824. }, function(){
  1825. flag = false;
  1826. }, false )
  1827. }else if( this.topToForum === true || this.topToForum === "true" ){
  1828. this.actions.cancelTopToForum( this.app.data.id , function( json ){
  1829. if (json.type == "error") {
  1830. this.app.notice(json.message, "error");
  1831. flag = false;
  1832. }
  1833. }, function(){
  1834. flag = false;
  1835. }, false )
  1836. }
  1837. if( data.topToSection === true || data.topToSection === "true" ){
  1838. this.actions.topToSection( this.app.data.id , function( json ){
  1839. if (json.type == "error") {
  1840. this.app.notice(json.message, "error");
  1841. flag = false;
  1842. }
  1843. }, function(){
  1844. flag = false;
  1845. }, false )
  1846. }else if( this.topToSection === true || this.topToSection === "true" ){
  1847. this.actions.cancelTopToSection( this.app.data.id , function( json ){
  1848. if (json.type == "error") {
  1849. this.app.notice(json.message, "error");
  1850. flag = false;
  1851. }
  1852. }, function(){
  1853. flag = false;
  1854. }, false )
  1855. }
  1856. if( flag ){
  1857. this.formMarkNode.destroy();
  1858. this.formAreaNode.destroy();
  1859. this.app.notice( this.app.lp.setTopSuccess );
  1860. this.fireEvent("postOk");
  1861. }else{
  1862. this.app.notice( this.app.lp.setToFail , "error");
  1863. }
  1864. }
  1865. }
  1866. });