Main.js 72 KB

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