ColumnTemplate.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /**
  2. * Created by CXY on 2017/4/26.
  3. */
  4. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  5. MWF.xApplication.Forum.ColumnTemplate = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "naviMode" : false,
  10. "style": "default",
  11. "width": "1230",
  12. "type": "type_1_0",
  13. "categoryId" : ""
  14. },
  15. initialize : function( container, app, explorer, options ){
  16. this.setOptions(options);
  17. if( !this.options.type )this.options.type = "type_1_0";
  18. this.container = container;
  19. this.app = app;
  20. this.lp = app.lp;
  21. this.actions = app.restActions;
  22. this.explorer = explorer;
  23. this.path = "../x_component_Forum/$ColumnTemplate/";
  24. this.cssPath = "../x_component_Forum/$ColumnTemplate/" + this.options.style + "/css.wcss";
  25. this._loadCss();
  26. },
  27. load: function(){
  28. this.loadSetting();
  29. this.loadView();
  30. },
  31. _loadSetting: function(){
  32. var path = "../x_component_Forum/$ColumnTemplate/template/setting.json";
  33. var templateSetting;
  34. if (MWF.xApplication.Forum.ColumnTemplate.Setting){
  35. templateSetting = MWF.xApplication.Forum.ColumnTemplate.Setting;
  36. }else{
  37. var r = new Request.JSON({
  38. url: path,
  39. secure: false,
  40. async: false,
  41. method: "get",
  42. noCache: false,
  43. onSuccess: function(responseJSON, responseText){
  44. templateSetting = MWF.xApplication.Forum.ColumnTemplate.Setting = responseJSON;
  45. }.bind(this),
  46. onError: function(text, error){
  47. alert(error + text);
  48. }
  49. });
  50. r.send();
  51. }
  52. return templateSetting;
  53. },
  54. loadSetting: function(){
  55. var setting = this._loadSetting();
  56. this.setting = setting[this.options.type];
  57. },
  58. loadView: function(){
  59. this.view = new MWF.xApplication.Forum.ColumnTemplate.View(this.container, this.app, this, {
  60. setting : this.setting,
  61. templateUrl: this.setting.template,
  62. categoryId: this.options.categoryId,
  63. onPostCreateViewBody : function(){
  64. this.fireEvent("postLoad");
  65. }.bind(this)
  66. }, {
  67. css: this.css
  68. });
  69. this.view.load();
  70. }
  71. });
  72. MWF.xApplication.Forum.ColumnTemplate.View = new Class({
  73. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  74. _createDocument: function (data, index) {
  75. if( this.app.access.isSectionViewer( data ) ){
  76. return new MWF.xApplication.Forum.ColumnTemplate.Document(this.viewNode, data, this.explorer, this, null, index);
  77. }
  78. },
  79. _getCurrentPageData: function (callback, count) {
  80. if (!count)count = 20;
  81. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  82. var filter = this.filterData || {};
  83. this.actions.listSection(this.options.categoryId, function (json) {
  84. if( !json.data )json.data = [];
  85. if (callback)callback(json);
  86. }.bind(this))
  87. },
  88. _removeDocument: function (documentData, all) {
  89. //this.actions.deleteSchedule(documentData.id, function(json){
  90. // this.reload();
  91. // this.app.notice(this.app.lp.deleteDocumentOK, "success");
  92. //}.bind(this));
  93. },
  94. _create: function () {
  95. },
  96. _openDocument: function (documentData) {
  97. },
  98. _queryCreateViewNode: function () {
  99. },
  100. _postCreateViewNode: function (viewNode) {
  101. },
  102. _queryCreateViewHead: function () {
  103. },
  104. _postCreateViewHead: function (headNode) {
  105. }
  106. });
  107. MWF.xApplication.Forum.ColumnTemplate.Document = new Class({
  108. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  109. mouseoverDocument: function () {
  110. //this.node.getElements("[styles='itemTitleNode']").setStyles(this.css["itemTitleNode_over"]);
  111. //this.node.getElements("[styles='itemIconNode']").setStyles(this.css["itemIconNode_over"]);
  112. //this.node.getElements("[styles='itemStatNode']").setStyles(this.css["itemStatNode_over"]);
  113. },
  114. mouseoutDocument: function () {
  115. //this.node.getElements("[styles='itemTitleNode']").setStyles(this.css["itemTitleNode"]);
  116. //this.node.getElements("[styles='itemIconNode']").setStyles(this.css["itemIconNode"]);
  117. //this.node.getElements("[styles='itemStatNode']").setStyles(this.css["itemStatNode"]);
  118. },
  119. _queryCreateDocumentNode: function (itemData) {
  120. },
  121. _postCreateDocumentNode: function (itemNode, itemData) {
  122. var personNode = itemNode.getElements("[item='moderatorNames']")[0];
  123. if(personNode)this.createPersonNode( personNode, itemData.moderatorNames );
  124. var _self = this;
  125. var setting = this.view.options.setting;
  126. var columnCount = setting.column;
  127. if( (this.index + 1) % columnCount == 0 ){
  128. itemNode.setStyle("margin-right" , "0px" );
  129. }
  130. if( setting.hasBorder ){
  131. this.container.setStyle("padding-bottom", "10px");
  132. }
  133. if( setting.image ){
  134. this._loadImage( itemNode );
  135. }
  136. this._loadSubjectList( itemNode );
  137. },
  138. _loadSubjectList: function( itemNode ){
  139. var listNode = itemNode.getElements("[item='itemListNode']")[0];
  140. var replyListNode = itemNode.getElements("[item='itemReplyListNode']")[0];
  141. if (listNode) {
  142. this._getListData(function (json) {
  143. json.data.each(function (d,i) {
  144. var div = new Element("div", {
  145. "styles": this.css.itemListItemNode,
  146. "text": d.title,
  147. "title": d.title
  148. }).inject(listNode);
  149. div.addEvents({
  150. "mouseover": function () {
  151. this.node.setStyles(this.obj.css.itemListItemNode_over)
  152. }.bind({node: div, obj: this}),
  153. "mouseout": function () {
  154. this.node.setStyles(this.obj.css.itemListItemNode)
  155. }.bind({node: div, obj: this}),
  156. "click" : function(){
  157. var appId = "ForumDocument"+this.da.id;
  158. if (this.obj.app.desktop.apps[appId]){
  159. this.obj.app.desktop.apps[appId].setCurrent();
  160. }else {
  161. this.obj.app.desktop.openApplication(null, "ForumDocument", {
  162. "sectionId" : this.da.sectionId,
  163. "id" : this.da.id,
  164. "appId": appId,
  165. "isEdited" : false,
  166. "isNew" : false,
  167. "index" : i
  168. });
  169. }
  170. }.bind({da: d, obj: this})
  171. });
  172. if(replyListNode){
  173. var replyNode = new Element("div", {
  174. "styles": this.css.itemReplyListItemNode
  175. }).inject(replyListNode);
  176. var div = new Element("div", {
  177. "styles": this.css.itemReplyPersonNode,
  178. "text": MWFForum.getSubjectCreatorName(d),
  179. "title": MWFForum.getSubjectCreatorName(d)
  180. }).inject(replyNode);
  181. div.addEvents({
  182. "mouseover": function () {
  183. this.node.setStyles(this.obj.css.itemReplyPersonNode_over)
  184. }.bind({node: div, obj: this}),
  185. "mouseout": function () {
  186. this.node.setStyles(this.obj.css.itemReplyPersonNode)
  187. }.bind({node: div, obj: this}),
  188. "click" : function(){
  189. this.obj.app.openPerson( this.userName );
  190. }.bind( {userName : d.creatorName, obj:this} )
  191. });
  192. var div = new Element("div", {
  193. "styles": this.css.itemReplyTimeNode,
  194. "text": MWFForum.getDateDiff(d.latestReplyTime),
  195. "title": d.latestReplyTime
  196. }).inject(replyNode);
  197. }
  198. }.bind(this))
  199. }.bind(this), this.view.options.setting.itemCount)
  200. }
  201. },
  202. _loadImage: function( itemNode ){
  203. var _self = this;
  204. var imageNode = itemNode.getElements("[item='itemImage']")[0];
  205. var filterData = {
  206. "sectionId": this.data.id,
  207. "needPicture" : true
  208. };
  209. if(imageNode){
  210. this.actions.listSubjectForBBSIndex(1, 1, filterData, function( json ){
  211. if( json.data ){
  212. var d = json.data[0];
  213. this.node.set("title", d.title);
  214. if(d.picId){
  215. this.node.set("src", MWF.xDesktop.getImageSrc(d.picId) );
  216. this.node.setStyle("cursor", "pointer");
  217. }
  218. this.node.addEvents({
  219. "click": function () {
  220. var appId = "ForumDocument" + this.da.id;
  221. if (_self.app.desktop.apps[appId]) {
  222. _self.app.desktop.apps[appId].setCurrent();
  223. } else {
  224. _self.app.desktop.openApplication(null, "ForumDocument", {
  225. "sectionId": this.da.sectionId,
  226. "id": this.da.id,
  227. "appId": appId,
  228. "isEdited": false,
  229. "isNew": false
  230. });
  231. }
  232. }.bind({da: d})
  233. })
  234. }
  235. }.bind({ node : imageNode }))
  236. }
  237. },
  238. _getListData: function (callback, count) {
  239. if (!count)count = 6;
  240. var filterData = {
  241. "sectionId": this.data.id
  242. };
  243. this.actions.listSubjectForBBSIndex(1, count, filterData, function (json) {
  244. if (!json.data)json.data = [];
  245. if (callback)callback(json);
  246. }.bind(this))
  247. },
  248. removeCenterWork: function (itemData) {
  249. //if(isAdmin){
  250. // return true;
  251. //}
  252. return false;
  253. },
  254. openSection : function( el ){
  255. if( this.explorer.options.naviMode && this.explorer.forumNavi ){
  256. this.explorer.forumNavi.goto( MWFForum.NaviType.section, this.data.id );
  257. }else {
  258. var appId = "ForumSection"+ this.data.id;
  259. if (this.app.desktop.apps[appId]){
  260. this.app.desktop.apps[appId].setCurrent();
  261. }else {
  262. this.app.desktop.openApplication(el, "ForumSection", {
  263. "sectionId": this.data.id,
  264. "appId": appId
  265. });
  266. }
  267. }
  268. },
  269. openPerson : function( userName, data ){
  270. MWFForum.openPersonCenter(userName, data)
  271. },
  272. createPersonNode : function( container, personName ){
  273. var persons = typeOf(personName) === "array" ? personName : personName.split(",");
  274. persons.each( function(userName, i){
  275. Promise.resolve( MWFForum.getDisplayName( userName ) ).then(function (name) {
  276. var span = new Element("span", {
  277. "text" : name.split('@')[0],
  278. "title" : name.split('@')[0],
  279. "styles" : this.css.person
  280. }).inject(container);
  281. span.addEvents( {
  282. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  283. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  284. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  285. });
  286. if( i != persons.length - 1 ){
  287. new Element("span", {
  288. "text" : "、"
  289. }).inject(container);
  290. }
  291. }.bind(this))
  292. }.bind(this))
  293. }
  294. });