Main.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. MWF.CMSE = MWF.xApplication.cms.Index = MWF.xApplication.cms.Index ||{};
  3. MWF.require("MWF.widget.Identity", 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": "1160",
  17. "height": "700",
  18. "isResize": false,
  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 = new MWF.xApplication.cms.Index.Actions.RestActions();
  28. this.createNode();
  29. this.loadApplicationContent();
  30. },
  31. reload : function(){
  32. this.contentContainerNode.destroy();
  33. this.loadContent();
  34. },
  35. createNode: function(){
  36. this.content.setStyle("overflow", "hidden");
  37. this.node = new Element("div", {
  38. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  39. }).inject(this.content);
  40. },
  41. loadApplicationContent: function(){
  42. this.loadTitle();
  43. this.loadContent();
  44. },
  45. loadTitle : function(){
  46. this.loadTitleBar();
  47. this.loadCreateDocumentActionNode();
  48. this.loadTitleTextNode();
  49. this.loadRefreshNode();
  50. this.loadSearchNode();
  51. },
  52. loadTitleBar: function(){
  53. this.titleBar = new Element("div", {
  54. "styles": this.css.titleBar
  55. }).inject(this.node);
  56. },
  57. loadCreateDocumentActionNode: function() {
  58. this.createDocumentAction = new Element("div", {
  59. "styles": this.css.createDocumentAction
  60. }).inject(this.titleBar);
  61. this.createDocumentAction.addEvents({
  62. "click": function(e){
  63. if( this.creater ){
  64. this.creater.load();
  65. }else{
  66. MWF.xDesktop.requireApp("cms.Index", "Creater", function(){
  67. this.creater = new MWF.xApplication.cms.Index.Creater(this,null,this);
  68. this.creater.load();
  69. }.bind(this));
  70. }
  71. }.bind(this)
  72. });
  73. },
  74. loadTitleTextNode: function(){
  75. this.titleTextNode = new Element("div", {
  76. "styles": this.css.titleTextNode,
  77. "text": this.lp.title
  78. }).inject(this.titleBar);
  79. },
  80. loadSearchNode: function(){
  81. this.searchBarAreaNode = new Element("div", {
  82. "styles": this.css.searchBarAreaNode
  83. }).inject(this.titleBar);
  84. this.searchBarNode = new Element("div", {
  85. "styles": this.css.searchBarNode
  86. }).inject(this.searchBarAreaNode);
  87. this.searchBarActionNode = new Element("div", {
  88. "styles": this.css.searchBarActionNode
  89. }).inject(this.searchBarNode);
  90. this.searchBarResetActionNode = new Element("div", {
  91. "styles": this.css.searchBarResetActionNode
  92. }).inject(this.searchBarNode);
  93. this.searchBarResetActionNode.setStyle("display","none");
  94. this.searchBarInputBoxNode = new Element("div", {
  95. "styles": this.css.searchBarInputBoxNode
  96. }).inject(this.searchBarNode);
  97. this.searchBarInputNode = new Element("input", {
  98. "type": "text",
  99. "value": this.lp.searchKey,
  100. "styles": this.css.searchBarInputNode
  101. }).inject(this.searchBarInputBoxNode);
  102. var _self = this;
  103. this.searchBarActionNode.addEvent("click", function(){
  104. this.search();
  105. }.bind(this));
  106. this.searchBarResetActionNode.addEvent("click", function(){
  107. this.reset();
  108. }.bind(this));
  109. this.searchBarInputNode.addEvents({
  110. "focus": function(){
  111. if (this.value==_self.lp.searchKey) this.set("value", "");
  112. },
  113. "blur": function(){if (!this.value) this.set("value", _self.lp.searchKey);},
  114. "keydown": function(e){
  115. if (e.code==13){
  116. this.search();
  117. e.preventDefault();
  118. }
  119. }.bind(this),
  120. "selectstart": function(e){
  121. e.preventDefault();
  122. }
  123. });
  124. },
  125. loadRefreshNode : function(){
  126. this.refreshAreaNode = new Element("div", {
  127. "styles": this.css.refreshAreaNode
  128. }).inject(this.titleBar);
  129. this.refreshActionNode = new Element("div", {
  130. "styles": this.css.refreshActionNode,
  131. "title" : this.lp.refresh
  132. }).inject(this.refreshAreaNode);
  133. this.refreshActionNode.addEvent("click", function(){
  134. this.reload();
  135. }.bind(this));
  136. },
  137. loadContent: function(callback){
  138. this.contentContainerNode = new Element("div",{
  139. "styles" : this.css.contentContainerNode
  140. }).inject(this.node);
  141. this.contentNode = new Element("div", {
  142. "styles": this.css.contentNode
  143. }).inject(this.contentContainerNode);
  144. this.createColumnNodes();
  145. MWF.require("MWF.widget.ScrollBar", function(){
  146. new MWF.widget.ScrollBar(this.contentContainerNode, {
  147. "indent": false,"style":"xApp_TaskList", "where": "before", "distance": 30, "friction": 4, "axis": {"x": false, "y": true},
  148. "onScroll": function(y){
  149. //var scrollSize = _self.elementContentNode.getScrollSize();
  150. //var clientSize = _self.elementContentNode.getSize();
  151. //var scrollHeight = scrollSize.y-clientSize.y;
  152. //if (y+200>scrollHeight) {
  153. // if (!_self.view.isItemsLoaded) _self.view.loadElementList();
  154. //}
  155. }
  156. });
  157. }.bind(this));
  158. this.setContentSize();
  159. this.addEvent("resize", function(){
  160. this.setContentSize();
  161. }.bind(this));
  162. },
  163. createColumnNodes: function(){
  164. this.restActions.listColumn(function(json){
  165. if( typeOf(json.data)!="array" )return;
  166. var tmpArray = json.data;
  167. tmpArray.sort(function( a, b ){
  168. return parseFloat(a.appInfoSeq) - parseFloat(b.appInfoSeq)
  169. })
  170. json.data = tmpArray;
  171. var i = 0;
  172. json.data.each(function(column){
  173. var column = new MWF.xApplication.cms.Index.Column(this, column, {"index" : i++ });
  174. column.load();
  175. this.columns.push(column);
  176. }.bind(this));
  177. }.bind(this));
  178. },
  179. search : function( key ){
  180. if(!key)key = this.searchBarInputNode.get("value");
  181. if(key==this.lp.searchKey)key="";
  182. if( key!="" ){
  183. this.searchBarResetActionNode.setStyle("display","block");
  184. this.searchBarActionNode.setStyle("display","none");
  185. }
  186. this.columns.each(function( column ){
  187. column.search( key );
  188. }.bind(this))
  189. },
  190. reset : function(){
  191. this.searchBarInputNode.set("value",this.lp.searchKey);
  192. this.searchBarResetActionNode.setStyle("display","none");
  193. this.searchBarActionNode.setStyle("display","block");
  194. this.columns.each(function( column ){
  195. column.loadList();
  196. }.bind(this))
  197. },
  198. clearContent: function(){
  199. //if (this.indexContent){
  200. // if (this.index) delete this.index;
  201. // this.indexContent.destroy();
  202. // this.indexContent = null;
  203. //}
  204. },
  205. openManager : function(){
  206. var appId = "cms.Column";
  207. if (this.desktop.apps[appId]){
  208. this.desktop.apps[appId].setCurrent();
  209. }else {
  210. this.desktop.openApplication(null, "cms.Column", {
  211. "appId": appId,
  212. "onQueryLoad": function(){
  213. }
  214. });
  215. }
  216. },
  217. recordStatus: function(){
  218. //if (this.menu.currentNavi){
  219. // var naviType = this.menu.currentNavi.retrieve("type");
  220. // var naviData = this.menu.currentNavi.retrieve("naviData");
  221. // return {
  222. // "navi" :{ "type": naviType, "id": naviData.id, "columnId":naviData.appId},
  223. // "view" : this.index.currentViewData.id ? this.index.currentViewData.id : "default"
  224. // };
  225. //}
  226. },
  227. setContentSize: function(){
  228. var titlebarSize = this.titleBar ? this.titleBar.getSize() : {"x":0,"y":0};
  229. var nodeSize = this.node.getSize();
  230. var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  231. var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  232. var height = nodeSize.y-pt-pb-titlebarSize.y;
  233. this.contentContainerNode.setStyle("height", ""+height+"px");
  234. }
  235. });
  236. MWF.xApplication.cms.Index.Column = new Class({
  237. Implements: [Options, Events],
  238. options: {
  239. "where": "bottom",
  240. "index" : 0
  241. },
  242. initialize: function (app, data, options) {
  243. this.setOptions(options);
  244. this.app = app;
  245. this.container = this.app.contentNode;
  246. this.data = data;
  247. this.isNew = false;
  248. this.backgroundColors = ["#cde6fe","#e6f3ff","#f5f6f7","#fcfcfc"];
  249. this.defaultColumnIcon = "/x_component_cms_Index/$Main/"+this.app.options.style+"/icon/column.png";
  250. },
  251. load : function(){
  252. this.loadNode();
  253. this.loadTop();
  254. this.loadCategory();
  255. this.loadList();
  256. },
  257. loadNode : function(){
  258. this.node = new Element("div.columnItem", {
  259. "styles": this.app.css.columnItemNode
  260. }).inject(this.container,this.options.where);
  261. var topNode = this.topNode = new Element("div.columnItemTopNode", {
  262. "styles": this.app.css.columnItemTopNode
  263. }).inject(this.node);
  264. var mod = this.options.index % this.backgroundColors.length;
  265. this.color = this.backgroundColors[mod];
  266. topNode.setStyle("background-color",this.color);
  267. this.categoryContainer = new Element("div.categoryContainer",{
  268. "styles" : this.app.css.categoryContainer
  269. }).inject(this.node);
  270. this.categoryList = new Element("div.categoryList",{
  271. "styles" : this.app.css.categoryList
  272. }).inject(this.categoryContainer);
  273. this.documentList = new Element("div",{
  274. "styles" : this.app.css.documentList
  275. }).inject(this.node);
  276. },
  277. loadTop: function () {
  278. this.data.name = this.data.appName;
  279. var columnName = this.data.appName;
  280. var alias = this.data.appAlias;
  281. var memo = this.data.description;
  282. var order = this.data.appInfoSeq;
  283. var creator =this.data.creatorUid;
  284. var createTime = this.data.createTime;
  285. var topNode = this.topNode;
  286. //var iconNode = this.iconNode = new Element("div",{
  287. // "styles" : this.app.css.columnItemIconNode
  288. //}).inject(topNode);
  289. //
  290. //if (this.data.appIcon){
  291. // this.iconNode.setStyle("background-image", "url(data:image/png;base64,"+this.data.appIcon+")");
  292. //}else{
  293. // this.iconNode.setStyle("background-image", "url("+this.defaultColumnIcon+")")
  294. //}
  295. var iconAreaNode = this.iconAreaNode = new Element("div",{
  296. "styles" : this.app.css.columnItemIconAreaNode
  297. }).inject(topNode);
  298. var iconNode = this.iconNode = new Element("img",{
  299. "styles" : this.app.css.columnItemIconNode
  300. }).inject(iconAreaNode);
  301. if (this.data.appIcon){
  302. this.iconNode.set("src", "data:image/png;base64,"+this.data.appIcon+"");
  303. }else{
  304. this.iconNode.set("src", this.defaultColumnIcon)
  305. }
  306. iconNode.makeLnk({
  307. "par": this._getLnkPar()
  308. });
  309. var textNode = new Element("div",{
  310. "styles" : this.app.css.columnItemTextNode
  311. }).inject(topNode)
  312. var titleNode = new Element("div",{
  313. "styles" : this.app.css.columnItemTitleNode,
  314. "text" : columnName,
  315. "title": (alias) ? columnName+" ("+alias+") " : columnName
  316. }).inject(textNode)
  317. var description = ( memo && memo!="") ? memo : this.app.lp.noDescription;
  318. var descriptionNode = new Element("div",{
  319. "styles" : this.app.css.columnItemDescriptionNode,
  320. "text" : description,
  321. "title" : description
  322. }).inject(textNode)
  323. var _self = this;
  324. topNode.addEvents({
  325. //"mouseover": function(){if (!_self.selected) this.setStyles(_self.app.css.columnItemNode_over);},
  326. //"mouseout": function(){if (!_self.selected) this.setStyles(_self.app.css.columnItemNode);},
  327. "click": function(e){_self.clickColumnNode(_self,this,e)}
  328. });
  329. },
  330. _getLnkPar: function(){
  331. var lnkIcon = this.defaultColumnIcon;
  332. if (this.data.appIcon) lnkIcon = "data:image/png;base64,"+this.data.appIcon;
  333. var appId = "cms.Module"+this.data.id;
  334. return {
  335. "icon": lnkIcon,
  336. "title": this.data.appName,
  337. "par": "cms.Module#{\"columnId\": \""+this.data.id+"\", \"appId\": \""+appId+"\"}"
  338. };
  339. },
  340. clickColumnNode : function(_self, el, e ){
  341. this.openModule("all",e);
  342. },
  343. clickMoreLink : function(e){
  344. var key = this.app.searchBarInputNode.get("value");
  345. if(key==this.app.lp.searchKey)key="";
  346. this.openModule("all",e, key);
  347. },
  348. openModule : function( categoryId , e , searchKey, isCategory ){
  349. var appId = "cms.Module"+this.data.id;
  350. if (this.app.desktop.apps[appId]){
  351. if( searchKey ){
  352. this.app.desktop.apps[appId].close();
  353. }else{
  354. this.app.desktop.apps[appId].setCurrent();
  355. return;
  356. }
  357. }
  358. this.app.desktop.openApplication(e, "cms.Module", {
  359. "columnData": this.data,
  360. "appId": appId,
  361. "categoryId": categoryId,
  362. //"viewId" : "default",
  363. "isCategory" : isCategory || false,
  364. "searchKey" : searchKey
  365. });
  366. },
  367. loadCategory : function(){
  368. var _self = this;
  369. if( typeOf(this.data.wrapOutCategoryList) != "array" )return;
  370. var tmpArray = this.data.wrapOutCategoryList;
  371. tmpArray.sort(function( a, b ){
  372. return parseFloat(a.categorySeq) - parseFloat(b.categorySeq)
  373. });
  374. this.data.wrapOutCategoryList = tmpArray;
  375. this.data.wrapOutCategoryList.each(function(category){
  376. var categoryNode = new Element("div.categoryItem",{
  377. "text" : category.categoryName,
  378. "styles" : this.app.css.categoryItem
  379. }).inject( this.categoryList );
  380. categoryNode.store("category",category)
  381. categoryNode.addEvents({
  382. "mouseover" : function(){this.setStyles(_self.app.css.categoryItem_over)},
  383. "mouseout" : function(){this.setStyles(_self.app.css.categoryItem)},
  384. "click" : function(e){
  385. _self.openModule( this.retrieve("category").id , e , "", true)
  386. }
  387. })
  388. }.bind(this));
  389. if( this.categoryList.getScrollSize().y > this.categoryContainer.getSize().y ){
  390. this.categoryArrowNode = new Element("div.categoryArrowNode",{
  391. "styles" : this.app.css.categoryArrowNode
  392. }).inject( this.categoryContainer );
  393. this.categoryArrowNode.addEvents({
  394. "mouseover" : function(){
  395. this.categoryArrowNode.setStyles( this.categoryArrow != "down" ? this.app.css.categoryArrowNode_over : this.app.css.categoryArrowNode_down_over);
  396. }.bind(this),
  397. "mouseout" : function(){
  398. this.categoryArrowNode.setStyles( this.categoryArrow != "down" ? this.app.css.categoryArrowNode : this.app.css.categoryArrowNode_down);
  399. }.bind(this),
  400. "click" : function( e ){
  401. if( this.categoryArrow != "down" ){
  402. this.openCategoryList( e );
  403. }else{
  404. this.closeCategoryList( e )
  405. }
  406. }.bind(this)
  407. });
  408. }
  409. },
  410. openCategoryList : function( e ){
  411. this.categoryArrow = "down";
  412. this.categoryArrowNode.setStyles(this.app.css.categoryArrowNode_down_over );
  413. this.categoryList.setStyles(this.app.css.categoryList_all);
  414. window.closeCategoryList = this.closeCategoryList.bind(this);
  415. this.app.content.addEvent("click", window.closeCategoryList )
  416. e.stopPropagation();
  417. },
  418. closeCategoryList : function( e ){
  419. this.categoryArrow = "up";
  420. this.categoryArrowNode.setStyles(this.app.css.categoryArrowNode );
  421. this.categoryList.setStyles(this.app.css.categoryList);
  422. this.app.content.removeEvent("click" , window.closeCategoryList )
  423. e.stopPropagation();
  424. },
  425. destroy: function(){
  426. this.node.destroy();
  427. MWF.release(this);
  428. delete this;
  429. },
  430. search : function(key){
  431. if( !key || key==""){
  432. this.loadList();
  433. return;
  434. }
  435. if(this.documentList)this.documentList.empty();
  436. if(this.moreArea)this.moreArea.destroy();
  437. var filter = {
  438. "titleList": [key],
  439. "appIdList": [this.data.id],
  440. "statusList": ["published"]
  441. };
  442. this.getDocumentData(function(json){
  443. //json.count //栏目下文档总数
  444. //json.size //当前条数
  445. if( json.count > json.size ){
  446. this.loadMoreItem( json.count, json.size )
  447. }
  448. json.data.each(function(data){
  449. this.listDocument(data);
  450. }.bind(this))
  451. }.bind(this), null, filter );
  452. },
  453. loadList: function(){
  454. if(this.documentList)this.documentList.empty();
  455. if(this.moreArea)this.moreArea.destroy();
  456. this.getDocumentData(function(json){
  457. //json.count //栏目下文档总数
  458. //json.size //当前条数
  459. if( json.count > json.size ){
  460. this.loadMoreItem( json.count, json.size )
  461. }
  462. json.data.each(function(data){
  463. this.listDocument(data);
  464. }.bind(this))
  465. }.bind(this));
  466. },
  467. listDocument:function(data){
  468. var _self = this;
  469. var documentItem = new Element("div",{
  470. "text" : data.title,
  471. "styles" : this.app.css.documentItem
  472. }).inject(this.documentList);
  473. documentItem.store("documentId",data.id);
  474. documentItem.addEvents({
  475. "mouseover" : function(){this.setStyles(_self.app.css.documentItem_over)},
  476. "mouseout" : function(){this.setStyles(_self.app.css.documentItem)},
  477. "click" : function(){
  478. var documentId = this.retrieve("documentId");
  479. var appId = "cms.Document"+documentId;
  480. if (_self.app.desktop.apps[appId]){
  481. _self.app.desktop.apps[appId].setCurrent();
  482. }else {
  483. var options = {
  484. "documentId": documentId,
  485. "appId": appId,
  486. "readonly": true
  487. };
  488. _self.app.desktop.openApplication(null, "cms.Document", options);
  489. }
  490. }
  491. })
  492. },
  493. getDocumentData: function(callback, count, filter){
  494. if(!count)count=7;
  495. var id = "(0)";
  496. if(!filter){
  497. filter = {
  498. "appIdList": [this.data.id],
  499. "statusList": ["published"]
  500. }
  501. }
  502. this.app.restActions.listDocumentFilterNext(id, count, filter, function(json){
  503. if (callback) callback(json);
  504. });
  505. },
  506. loadMoreItem: function(total, size){
  507. var _self = this;
  508. this.moreArea = new Element("div",{
  509. "styles" : this.app.css.moreArea
  510. }).inject(this.node);
  511. this.moreLink = new Element("div",{
  512. "styles" : this.app.css.moreLink,
  513. "text" : "查看其余"+(total-size)+"份信息"
  514. }).inject(this.moreArea);
  515. this.moreLink.addEvents({
  516. "mouseover" : function(){this.setStyles(_self.app.css.moreLink_over)},
  517. "mouseout" : function(){this.setStyles(_self.app.css.moreLink)},
  518. "click" : function(e){_self.clickMoreLink( e )}
  519. })
  520. this.moreArea.setStyle("background-color",this.color)
  521. }
  522. })