Main.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. MWF.CMSE = MWF.xApplication.cms.Index = MWF.xApplication.cms.Index ||{};
  3. MWF.require("MWF.widget.O2Identity", null,false);
  4. //MWF.xDesktop.requireApp("cms.Index", "Actions.RestActions", null, false);
  5. MWF.xApplication.cms.Index.options = {
  6. multitask: false,
  7. executable: true
  8. };
  9. MWF.xApplication.cms.Index.Main = new Class({
  10. Extends: MWF.xApplication.Common.Main,
  11. Implements: [Options, Events],
  12. options: {
  13. "style": "default",
  14. "name": "cms.Index",
  15. "icon": "icon.png",
  16. "width": "1220",
  17. "height": "680",
  18. "isResize": true,
  19. "isMax": true,
  20. "title": MWF.CMSE.LP.title
  21. },
  22. onQueryLoad: function(){
  23. this.lp = MWF.xApplication.cms.Index.LP;
  24. },
  25. loadApplication: function(callback){
  26. this.columns = [];
  27. this.restActions = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Index.Actions.RestActions();
  28. this.createNode();
  29. this.loadApplicationContent();
  30. },
  31. reload : function(){
  32. this.scrollNode.destroy();
  33. this.loadContent();
  34. },
  35. createNode: function(){
  36. this.content.setStyle("overflow", "hidden");
  37. this.node = new Element("div", {
  38. "styles": this.css.container
  39. }).inject(this.content);
  40. },
  41. loadApplicationContent: function(){
  42. this.loadTitle();
  43. this.loadContent();
  44. this.setCurrentAppType( "all", this.allTypeNode );
  45. },
  46. loadTitle : function(){
  47. this.loadTitleBar();
  48. this.loadAllTypeNode();
  49. this.loadCreateDocumentActionNode();
  50. this.loadSearchNode();
  51. this.loadAppType();
  52. },
  53. loadTitleBar: function(){
  54. this.titleBarContainer = new Element("div", {
  55. "styles": this.css.titleBarContainer
  56. }).inject(this.node);
  57. this.titleBar = new Element("div", {
  58. "styles": this.css.titleBar
  59. }).inject(this.titleBarContainer);
  60. },
  61. loadAllTypeNode : function(){
  62. this.allTypeNode = new Element("div.columnTop_All",{
  63. "styles" : this.css.columnTop_All,
  64. "text" : "全部栏目"
  65. }).inject( this.titleBar );
  66. this.allTypeNode.addEvents({
  67. "mouseover" : function(){
  68. if( this.currentAppTypeNode !== this.allTypeNode )this.allTypeNode.setStyles( this.css.columnTop_All_over );
  69. }.bind(this),
  70. "mouseout" : function(){
  71. if( this.currentAppTypeNode !== this.allTypeNode )this.allTypeNode.setStyles( this.css.columnTop_All );
  72. }.bind(this),
  73. "click": function () {
  74. this.setCurrentAppType( "all", this.allTypeNode );
  75. }.bind(this)
  76. });
  77. },
  78. loadCreateDocumentActionNode: function() {
  79. this.createDocumentAction = new Element("div", {
  80. "styles": this.css.createDocumentAction,
  81. "text" : this.lp.start
  82. }).inject(this.titleBar);
  83. this.createDocumentAction.addEvents({
  84. "click": function(e){
  85. MWF.xDesktop.requireApp("cms.Index", "Newer", function(){
  86. this.creater = new MWF.xApplication.cms.Index.Newer(null,null,this,this);
  87. this.creater.load();
  88. }.bind(this));
  89. }.bind(this),
  90. "mouseover" : function(e){
  91. this.createDocumentAction.setStyles( this.css.createDocumentAction_over )
  92. }.bind(this),
  93. "mouseout" : function(e){
  94. this.createDocumentAction.setStyles( this.css.createDocumentAction )
  95. }.bind(this)
  96. });
  97. },
  98. //loadTitleTextNode: function(){
  99. // this.titleTextNode = new Element("div", {
  100. // "styles": this.css.titleTextNode,
  101. // "text": this.lp.title
  102. // }).inject(this.titleBar);
  103. //},
  104. loadSearchNode: function(){
  105. this.searchBarAreaNode = new Element("div", {
  106. "styles": this.css.searchBarAreaNode
  107. }).inject(this.titleBar);
  108. this.searchBarNode = new Element("div", {
  109. "styles": this.css.searchBarNode
  110. }).inject(this.searchBarAreaNode);
  111. this.searchBarActionNode = new Element("div", {
  112. "styles": this.css.searchBarActionNode,
  113. "title" : "搜索"
  114. }).inject(this.searchBarNode);
  115. this.searchBarResetActionNode = new Element("div", {
  116. "styles": this.css.searchBarResetActionNode,
  117. "title" : "重置"
  118. }).inject(this.searchBarNode);
  119. this.searchBarResetActionNode.setStyle("display","none");
  120. this.searchBarInputBoxNode = new Element("div", {
  121. "styles": this.css.searchBarInputBoxNode
  122. }).inject(this.searchBarNode);
  123. this.searchBarInputNode = new Element("input", {
  124. "type": "text",
  125. "value": this.lp.searchKey,
  126. "styles": this.css.searchBarInputNode
  127. }).inject(this.searchBarInputBoxNode);
  128. var _self = this;
  129. this.searchBarActionNode.addEvent("click", function(){
  130. this.search();
  131. }.bind(this));
  132. this.searchBarResetActionNode.addEvent("click", function(){
  133. this.reset();
  134. }.bind(this));
  135. this.searchBarInputNode.addEvents({
  136. "focus": function(){
  137. if (this.value==_self.lp.searchKey) this.set("value", "");
  138. },
  139. "blur": function(){if (!this.value) this.set("value", _self.lp.searchKey);},
  140. "keydown": function(e){
  141. if (e.code==13){
  142. this.search();
  143. e.preventDefault();
  144. }
  145. }.bind(this),
  146. "selectstart": function(e){
  147. e.preventDefault();
  148. }
  149. });
  150. },
  151. loadAppType : function(){
  152. var _self = this;
  153. this.typeListContainer = new Element("div.columnTop_category", {
  154. "styles": this.css.columnTop_category
  155. }).inject(this.titleBar);
  156. this.restActions.listAllAppType( function( json ){
  157. (json.data || []).each( function( typeObject ){
  158. new Element( "div.columnTop_category", {
  159. "styles" : this.css.columnTop_categoryItem,
  160. "text" : typeObject.appType + "(" + typeObject.count + ")",
  161. "events" : {
  162. "mouseover" : function( ev ){
  163. if( this.currentAppTypeNode !== ev.target )ev.target.setStyles( this.css.columnTop_categoryItem_over );
  164. }.bind(this),
  165. "mouseout" : function( ev ){
  166. if( this.currentAppTypeNode !== ev.target )ev.target.setStyles( this.css.columnTop_categoryItem );
  167. }.bind(this),
  168. "click": function ( ev ) {
  169. _self.setCurrentAppType( this, ev.target );
  170. }.bind( typeObject.appType )
  171. }
  172. }).inject( this.typeListContainer )
  173. }.bind(this))
  174. if (this.typeListContainer.getScrollSize().y> Math.round(this.typeListContainer.getSize().y) && !this.columnTypeExpandNode ) this.createTypeExpandButton();
  175. }.bind(this))
  176. },
  177. createTypeExpandButton : function(){
  178. this.columnTypeExpandNode = new Element("div.columnTop_categoryExpandButton",{
  179. "styles" : this.css.columnTop_categoryExpandButton
  180. }).inject( this.typeListContainer, "before" );
  181. this.columnTypeExpandNode.addEvent("click", this.expandOrCollapseCategory.bind(this));
  182. },
  183. expandOrCollapseCategory : function(e){
  184. if (!this.categoryMorph) this.categoryMorph = new Fx.Morph(this.typeListContainer, {"duration": 100});
  185. if( !this.expand ){
  186. this.typeListContainer.setStyle( "width", this.typeListContainer.getSize().x + "px" );
  187. this.typeListContainer.setStyles( this.css.columnTop_category_more );
  188. this.categoryMorph.start({"height": ""+this.typeListContainer.getScrollSize().y+"px"});
  189. this.expandOrCollapseCategoryFun = this.expandOrCollapseCategory.bind(this);
  190. this.content.addEvent("click", this.expandOrCollapseCategoryFun);
  191. this.expand = true;
  192. }else{
  193. this.typeListContainer.setStyle( "width", "auto" );
  194. this.typeListContainer.setStyles( this.css.columnTop_category );
  195. this.categoryMorph.start({"height": ""+this.titleBar.getSize().y+"px"});
  196. if (this.expandOrCollapseCategoryFun) this.content.removeEvent("click", this.expandOrCollapseCategoryFun);
  197. this.expand = false;
  198. }
  199. e.stopPropagation();
  200. },
  201. setCurrentAppType : function( appType, target ){
  202. if( this.currentAppType ){
  203. if( this.currentAppType === "all" ){
  204. this.currentAppTypeNode.setStyles( this.css.columnTop_All )
  205. }else{
  206. this.currentAppTypeNode.setStyles( this.css.columnTop_categoryItem )
  207. }
  208. }
  209. if( appType === "all" ){
  210. target.setStyles( this.css.columnTop_All_current )
  211. }else{
  212. target.setStyles( this.css.columnTop_categoryItem_current )
  213. }
  214. this.currentAppType = appType;
  215. this.currentAppTypeNode = target;
  216. this.createColumnNodes();
  217. },
  218. //loadRefreshNode : function(){
  219. // this.refreshAreaNode = new Element("div", {
  220. // "styles": this.css.refreshAreaNode
  221. // }).inject(this.titleBar);
  222. //
  223. // this.refreshActionNode = new Element("div", {
  224. // "styles": this.css.refreshActionNode,
  225. // "title" : this.lp.refresh
  226. // }).inject(this.refreshAreaNode);
  227. // this.refreshActionNode.addEvent("click", function(){
  228. // this.reload();
  229. // }.bind(this));
  230. //},
  231. loadContent: function(callback){
  232. //this.container = new Element("div", {
  233. // "styles": this.css.container
  234. //}).inject(this.node);
  235. this.scrollNode = new Element("div", {
  236. "styles": this.css.scrollNode
  237. }).inject(this.node);
  238. this.contentWarpNode = new Element("div", {
  239. "styles": this.css.node
  240. }).inject(this.scrollNode);
  241. this.contentContainerNode = new Element("div",{
  242. "styles" : this.css.contentContainerNode
  243. }).inject(this.contentWarpNode);
  244. this.contentNode = new Element("div", {
  245. "styles": this.css.contentNode
  246. }).inject(this.contentContainerNode);
  247. //this.createColumnNodes();
  248. //MWF.require("MWF.widget.ScrollBar", function(){
  249. // new MWF.widget.ScrollBar(this.contentContainerNode, {
  250. // "indent": false,"style":"xApp_TaskList", "where": "before", "distance": 30, "friction": 4, "axis": {"x": false, "y": true},
  251. // "onScroll": function(y){
  252. // //var scrollSize = _self.elementContentNode.getScrollSize();
  253. // //var clientSize = _self.elementContentNode.getSize();
  254. // //var scrollHeight = scrollSize.y-clientSize.y;
  255. // //if (y+200>scrollHeight) {
  256. // // if (!_self.view.isItemsLoaded) _self.view.loadElementList();
  257. // //}
  258. // }
  259. // });
  260. //}.bind(this));
  261. //
  262. this.setContentSize();
  263. this.addEvent("resize", function(){
  264. this.setContentSize();
  265. }.bind(this));
  266. },
  267. createColumnNodes: function(){
  268. this.contentNode.empty();
  269. if( this.currentAppType === "all" ){
  270. this.restActions.listColumn( function(json){
  271. this._createColumnNodes( json )
  272. }.bind(this));
  273. }else{
  274. this.restActions.listWhatICanViewWithAppType(this.currentAppType, function(json){
  275. this._createColumnNodes( json )
  276. }.bind(this));
  277. }
  278. },
  279. _createColumnNodes : function( json ){
  280. if( typeOf(json.data)!="array" )return;
  281. var tmpArray = json.data;
  282. tmpArray.sort(function( a, b ){
  283. return parseFloat(a.appInfoSeq) - parseFloat(b.appInfoSeq)
  284. });
  285. json.data = tmpArray;
  286. var i = 0;
  287. json.data.each(function(column){
  288. var column = new MWF.xApplication.cms.Index.Column(this, column, {"index" : i++ });
  289. column.load();
  290. this.columns.push(column);
  291. }.bind(this));
  292. },
  293. search : function( key ){
  294. if(!key)key = this.searchBarInputNode.get("value");
  295. if(key==this.lp.searchKey)key="";
  296. if( key!="" ){
  297. this.searchBarResetActionNode.setStyle("display","block");
  298. this.searchBarActionNode.setStyle("display","none");
  299. }
  300. this.columns.each(function( column ){
  301. column.search( key );
  302. }.bind(this))
  303. },
  304. reset : function(){
  305. this.searchBarInputNode.set("value",this.lp.searchKey);
  306. this.searchBarResetActionNode.setStyle("display","none");
  307. this.searchBarActionNode.setStyle("display","block");
  308. this.columns.each(function( column ){
  309. column.loadList();
  310. }.bind(this))
  311. },
  312. clearContent: function(){
  313. //if (this.indexContent){
  314. // if (this.index) delete this.index;
  315. // this.indexContent.destroy();
  316. // this.indexContent = null;
  317. //}
  318. },
  319. openManager : function(){
  320. var appId = "cms.Column";
  321. if (this.desktop.apps[appId]){
  322. this.desktop.apps[appId].setCurrent();
  323. }else {
  324. this.desktop.openApplication(null, "cms.Column", {
  325. "appId": appId,
  326. "onQueryLoad": function(){
  327. }
  328. });
  329. }
  330. },
  331. recordStatus: function(){
  332. //if (this.menu.currentNavi){
  333. // var naviType = this.menu.currentNavi.retrieve("type");
  334. // var naviData = this.menu.currentNavi.retrieve("naviData");
  335. // return {
  336. // "navi" :{ "type": naviType, "id": naviData.id, "columnId":naviData.appId},
  337. // "view" : this.index.currentViewData.id ? this.index.currentViewData.id : "default"
  338. // };
  339. //}
  340. },
  341. setContentSize: function(){
  342. //var titlebarSize = this.titleBar ? this.titleBar.getSize() : {"x":0,"y":0};
  343. //var nodeSize = this.node.getSize();
  344. //var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  345. //var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  346. //
  347. //var height = nodeSize.y-pt-pb-titlebarSize.y;
  348. //this.contentContainerNode.setStyle("height", ""+height+"px");
  349. var nodeSize = this.content.getSize();
  350. var titlebarSize = this.titleBarContainer ? this.titleBarContainer.getSize() : {"x":0,"y":0};
  351. this.scrollNode.setStyle("height", ""+(nodeSize.y-titlebarSize.y)+"px");
  352. if (this.contentWarpNode){
  353. var count = (nodeSize.x/550).toInt();
  354. var x = 550 * count;
  355. var m = (nodeSize.x-x)/2-10;
  356. this.contentWarpNode.setStyles({
  357. "width": ""+x+"px",
  358. "margin-left": ""+m+"px"
  359. });
  360. //this.titleBar.setStyles({
  361. // "margin-left": ""+(m+10)+"px",
  362. // "margin-right": ""+(m+10)+"px"
  363. //});
  364. if( this.typeListContainer ){
  365. if ( this.typeListContainer.getScrollSize().y> Math.round(this.typeListContainer.getSize().y)) {
  366. if( !this.columnTypeExpandNode ){
  367. this.createTypeExpandButton();
  368. }else{
  369. this.columnTypeExpandNode.setStyle("display","")
  370. }
  371. }else{
  372. if(this.columnTypeExpandNode)this.columnTypeExpandNode.setStyle("display","none");
  373. }
  374. }
  375. }
  376. }
  377. });
  378. MWF.xApplication.cms.Index.Column = new Class({
  379. Implements: [Options, Events],
  380. options: {
  381. "where": "bottom",
  382. "index" : 0
  383. },
  384. initialize: function (app, data, options) {
  385. this.setOptions(options);
  386. this.app = app;
  387. this.container = this.app.contentNode;
  388. this.data = data;
  389. this.isNew = false;
  390. this.defaultColumnIcon = "/x_component_cms_Index/$Main/"+this.app.options.style+"/icon/column.png";
  391. },
  392. load : function(){
  393. this.loadNode();
  394. this.loadTop();
  395. this.loadCategory();
  396. this.loadList();
  397. },
  398. loadNode : function(){
  399. this.node = new Element("div.columnItem", {
  400. "styles": this.app.css.columnItemNode
  401. }).inject(this.container,this.options.where);
  402. //if( this.options.index % 2 == 1 ){
  403. // this.node.setStyles({
  404. // "margin-left" : "0px",
  405. // "margin-right" : "0px"
  406. // })
  407. //}else{
  408. // this.node.setStyles({
  409. // "margin-left" : "0px",
  410. // "margin-right" : "10px"
  411. // })
  412. //}
  413. var leftNode = this.leftNode = new Element("div.columnItemLeftNode", {
  414. "styles": this.app.css.columnItemLeftNode
  415. }).inject(this.node);
  416. var rightNode = this.rightNode = new Element("div.columnItemRightNode", {
  417. "styles": this.app.css.columnItemRightNode
  418. }).inject(this.node);
  419. this.categoryContainer = new Element("div.categoryContainer",{
  420. "styles" : this.app.css.categoryContainer
  421. }).inject(this.rightNode);
  422. this.categoryList = new Element("div.categoryList",{
  423. "styles" : this.app.css.categoryList
  424. }).inject(this.categoryContainer);
  425. this.documentList = new Element("div",{
  426. "styles" : this.app.css.documentList
  427. }).inject(this.rightNode);
  428. },
  429. loadTop: function () {
  430. this.data.name = this.data.appName;
  431. var columnName = this.data.appName;
  432. var alias = this.data.appAlias;
  433. var memo = this.data.description;
  434. var order = this.data.appInfoSeq;
  435. var creator =this.data.creatorUid;
  436. var createTime = this.data.createTime;
  437. var leftNode = this.leftNode;
  438. //var iconNode = this.iconNode = new Element("div",{
  439. // "styles" : this.app.css.columnItemIconNode
  440. //}).inject(topNode);
  441. //
  442. //if (this.data.appIcon){
  443. // this.iconNode.setStyle("background-image", "url(data:image/png;base64,"+this.data.appIcon+")");
  444. //}else{
  445. // this.iconNode.setStyle("background-image", "url("+this.defaultColumnIcon+")")
  446. //}
  447. var iconAreaNode = this.iconAreaNode = new Element("div",{
  448. "styles" : this.app.css.columnItemIconAreaNode
  449. }).inject(leftNode);
  450. //var mod = this.options.index % this.backgroundColors.length;
  451. //this.color = this.backgroundColors[mod];
  452. //iconAreaNode.setStyle("background-color",this.color);
  453. var iconNode = this.iconNode = new Element("img",{
  454. "styles" : this.app.css.columnItemIconNode
  455. }).inject(iconAreaNode);
  456. if (this.data.appIcon){
  457. this.iconNode.set("src", "data:image/png;base64,"+this.data.appIcon+"");
  458. }else{
  459. this.iconNode.set("src", this.defaultColumnIcon)
  460. }
  461. iconNode.makeLnk({
  462. "par": this._getLnkPar()
  463. });
  464. var textNode = new Element("div",{
  465. "styles" : this.app.css.columnItemTextNode
  466. }).inject(leftNode);
  467. var titleNode = new Element("div",{
  468. "styles" : this.app.css.columnItemTitleNode,
  469. "text" : columnName,
  470. "title": (alias) ? columnName+" ("+alias+") " : columnName
  471. }).inject(textNode);
  472. var description = ( memo && memo!="") ? memo : this.app.lp.noDescription;
  473. var descriptionNode = new Element("div",{
  474. "styles" : this.app.css.columnItemDescriptionNode,
  475. "text" : description,
  476. "title" : description
  477. }).inject(textNode);
  478. var _self = this;
  479. leftNode.addEvents({
  480. //"mouseover": function(){if (!_self.selected) this.setStyles(_self.app.css.columnItemNode_over);},
  481. //"mouseout": function(){if (!_self.selected) this.setStyles(_self.app.css.columnItemNode);},
  482. "click": function(e){_self.clickColumnNode(_self,this,e)}
  483. });
  484. },
  485. _getLnkPar: function(){
  486. var lnkIcon = this.defaultColumnIcon;
  487. if (this.data.appIcon) lnkIcon = "data:image/png;base64,"+this.data.appIcon;
  488. var appId = "cms.Module"+this.data.id;
  489. return {
  490. "icon": lnkIcon,
  491. "title": this.data.appName,
  492. "par": "cms.Module#{\"columnId\": \""+this.data.id+"\", \"appId\": \""+appId+"\"}"
  493. };
  494. },
  495. clickColumnNode : function(_self, el, e ){
  496. this.openModule("all",e);
  497. },
  498. clickMoreLink : function(e){
  499. var key = this.app.searchBarInputNode.get("value");
  500. if(key==this.app.lp.searchKey)key="";
  501. this.openModule("all",e, key);
  502. },
  503. openModule : function( categoryId , e , searchKey, isCategory ){
  504. var appId = "cms.Module"+this.data.id;
  505. if (this.app.desktop.apps[appId]){
  506. if( searchKey ){
  507. this.app.desktop.apps[appId].close();
  508. }else{
  509. this.app.desktop.apps[appId].setCurrent();
  510. return;
  511. }
  512. }
  513. this.app.desktop.openApplication(e, "cms.Module", {
  514. "columnData": this.data,
  515. "appId": appId,
  516. "categoryId": categoryId,
  517. //"viewId" : "default",
  518. "isCategory" : isCategory || false,
  519. "searchKey" : searchKey
  520. });
  521. },
  522. loadCategory : function(){
  523. var _self = this;
  524. if( typeOf(this.data.wrapOutCategoryList) != "array" )return;
  525. var tmpArray = this.data.wrapOutCategoryList;
  526. tmpArray.sort(function( a, b ){
  527. return parseFloat(a.categorySeq) - parseFloat(b.categorySeq)
  528. });
  529. this.data.wrapOutCategoryList = tmpArray;
  530. this.data.wrapOutCategoryList.each(function(category){
  531. var categoryNode = new Element("div.categoryItem",{
  532. "text" : category.categoryName,
  533. "styles" : this.app.css.categoryItem
  534. }).inject( this.categoryList, "top" );
  535. categoryNode.store("category",category);
  536. categoryNode.addEvents({
  537. "mouseover" : function(){this.setStyles(_self.app.css.categoryItem_over)},
  538. "mouseout" : function(){this.setStyles(_self.app.css.categoryItem)},
  539. "click" : function(e){
  540. _self.openModule( this.retrieve("category").id , e , "", true)
  541. }
  542. })
  543. }.bind(this));
  544. if( this.categoryList.getScrollSize().y > this.categoryContainer.getSize().y ){
  545. this.categoryArrowNode = new Element("div.categoryArrowNode",{
  546. "styles" : this.app.css.categoryArrowNode
  547. }).inject( this.categoryContainer );
  548. this.categoryArrowNode.addEvents({
  549. "mouseover" : function(){
  550. this.categoryArrowNode.setStyles( this.categoryArrow != "down" ? this.app.css.categoryArrowNode_over : this.app.css.categoryArrowNode_down_over);
  551. }.bind(this),
  552. "mouseout" : function(){
  553. this.categoryArrowNode.setStyles( this.categoryArrow != "down" ? this.app.css.categoryArrowNode : this.app.css.categoryArrowNode_down);
  554. }.bind(this),
  555. "click" : function( e ){
  556. if( this.categoryArrow != "down" ){
  557. this.openCategoryList( e );
  558. }else{
  559. this.closeCategoryList( e )
  560. }
  561. }.bind(this)
  562. });
  563. }
  564. },
  565. openCategoryList : function( e ){
  566. this.categoryArrow = "down";
  567. this.categoryArrowNode.setStyles(this.app.css.categoryArrowNode_down_over );
  568. this.categoryList.setStyles(this.app.css.categoryList_all);
  569. window.closeCategoryList = this.closeCategoryList.bind(this);
  570. this.app.content.addEvent("click", window.closeCategoryList );
  571. e.stopPropagation();
  572. },
  573. closeCategoryList : function( e ){
  574. this.categoryArrow = "up";
  575. this.categoryArrowNode.setStyles(this.app.css.categoryArrowNode );
  576. this.categoryList.setStyles(this.app.css.categoryList);
  577. this.app.content.removeEvent("click" , window.closeCategoryList );
  578. e.stopPropagation();
  579. },
  580. destroy: function(){
  581. this.node.destroy();
  582. MWF.release(this);
  583. delete this;
  584. },
  585. search : function(key){
  586. if( !key || key==""){
  587. this.loadList();
  588. return;
  589. }
  590. if(this.documentList)this.documentList.empty();
  591. if(this.moreArea)this.moreArea.destroy();
  592. var filter = {
  593. "title": key,
  594. "appIdList": [this.data.id],
  595. "statusList": ["published"]
  596. };
  597. this.getDocumentData(function(json){
  598. //json.count //栏目下文档总数
  599. //json.size //当前条数
  600. if( json.count > json.size ){
  601. this.loadMoreItem( json.count, json.size )
  602. }
  603. json.data.each(function(data){
  604. this.listDocument(data);
  605. }.bind(this))
  606. }.bind(this), null, filter );
  607. },
  608. loadList: function(){
  609. if(this.documentList)this.documentList.empty();
  610. if(this.moreArea)this.moreArea.destroy();
  611. this.getDocumentData(function(json){
  612. //json.count //栏目下文档总数
  613. //json.size //当前条数
  614. //if( json.count > json.size ){
  615. // this.loadMoreItem( json.count, json.size )
  616. //}
  617. json.data.each(function(data){
  618. this.listDocument(data);
  619. }.bind(this))
  620. }.bind(this));
  621. },
  622. listDocument:function(data){
  623. var _self = this;
  624. var documentItem = new Element("div",{
  625. "text" : data.title,
  626. "title" : data.title,
  627. "styles" : this.app.css.documentItem
  628. }).inject(this.documentList);
  629. documentItem.store("documentId",data.id);
  630. documentItem.addEvents({
  631. "mouseover" : function(){this.setStyles(_self.app.css.documentItem_over)},
  632. "mouseout" : function(){this.setStyles(_self.app.css.documentItem)},
  633. "click" : function(){
  634. var documentId = this.retrieve("documentId");
  635. var appId = "cms.Document"+documentId;
  636. if (_self.app.desktop.apps[appId]){
  637. _self.app.desktop.apps[appId].setCurrent();
  638. }else {
  639. var options = {
  640. "documentId": documentId,
  641. "appId": appId,
  642. "readonly": true
  643. };
  644. _self.app.desktop.openApplication(null, "cms.Document", options);
  645. }
  646. }
  647. })
  648. },
  649. getDocumentData: function(callback, count, filter){
  650. if(!count)count=6;
  651. var id = "(0)";
  652. if(!filter){
  653. filter = {
  654. "appIdList": [this.data.id],
  655. "statusList": ["published"]
  656. }
  657. }
  658. this.app.restActions.listDocumentFilterNext(id, count, filter, function(json){
  659. if (callback) callback(json);
  660. });
  661. },
  662. loadMoreItem: function(total, size){
  663. var _self = this;
  664. this.moreArea = new Element("div",{
  665. "styles" : this.app.css.moreArea
  666. }).inject(this.rightNode);
  667. this.moreLinkText = new Element("div",{
  668. "styles" : this.app.css.moreLinkText,
  669. "text" : "更多("+(total-size)+")"
  670. }).inject(this.moreArea);
  671. this.moreLinkImage = new Element("div",{
  672. "styles" : this.app.css.moreLinkImage
  673. }).inject(this.moreArea);
  674. this.moreArea.addEvents({
  675. "mouseover" : function(){
  676. this.moreLinkText.setStyles(_self.app.css.moreLinkText_over);
  677. this.moreLinkImage.setStyles(_self.app.css.moreLinkImage_over)
  678. }.bind(this),
  679. "mouseout" : function(){
  680. this.moreLinkText.setStyles(_self.app.css.moreLinkText);
  681. this.moreLinkImage.setStyles(_self.app.css.moreLinkImage)
  682. }.bind(this),
  683. "click" : function(e){_self.clickMoreLink( e )}
  684. });
  685. //this.moreArea.setStyle("background-color",this.color)
  686. }
  687. });