ViewExplorer.js 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. MWF.xApplication.cms.Module = MWF.xApplication.cms.Module || {};
  3. MWF.require("MWF.xAction.org.express.RestActions", null,false);
  4. MWF.require("MWF.widget.Mask", null, false);
  5. MWF.require("MWF.widget.Identity", null,false);
  6. MWF.xDesktop.requireApp("cms.Module", "lp."+MWF.language, null, false);
  7. MWF.xDesktop.requireApp("cms.Module", "package", null, false);
  8. MWF.xApplication.cms.Module.ViewExplorer = new Class({
  9. Extends: MWF.widget.Common,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "status": "published",
  14. "isAdmin": false,
  15. "searchKey" : "",
  16. "tooltip": {
  17. }
  18. },
  19. initialize: function(node, actions, columnData, categoryData, viewData, options){
  20. this.setOptions(options);
  21. this.setTooltip();
  22. this.path = "/x_component_cms_Module/$ViewExplorer/";
  23. this.cssPath = "/x_component_cms_Module/$ViewExplorer/"+this.options.style+"/css.wcss";
  24. this._loadCss();
  25. this.categoryData = categoryData;
  26. this.columnData = columnData;
  27. this.viewData = viewData;
  28. this.actions = actions;
  29. this.node = $(node);
  30. this.initData();
  31. if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  32. },
  33. setTooltip: function(tooltip){
  34. if (tooltip) this.options.tooltip = Object.merge(this.options.tooltip, tooltip);
  35. },
  36. initData: function(){
  37. this.toolItemNodes = [];
  38. },
  39. reload: function(){
  40. this.node.empty();
  41. this.load();
  42. },
  43. load: function(){
  44. //this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode});
  45. //this.toolbarNode.inject(this.node);
  46. //this.loadToolbar();
  47. //this.filterConditionNode = new Element("div", {
  48. // "styles": this.css.filterConditionNode
  49. //}).inject(this.node );
  50. this.loadContentNode();
  51. this.loadView();
  52. this.setNodeScroll();
  53. },
  54. loadToolbar: function(){
  55. var toolbarUrl = this.path+"toolbar.json";
  56. MWF.getJSON(toolbarUrl, function(json){
  57. json.each(function(tool){
  58. this.createToolbarItemNode(tool);
  59. }.bind(this));
  60. }.bind(this));
  61. //this.createSearchElementNode();
  62. },
  63. createToolbarItemNode : function( tool ){
  64. var toolItemNode = new Element("div", {
  65. "styles": (tool.styles && this.css[tool.styles]) ? this.css[tool.styles] : this.css.toolbarItemNode
  66. });
  67. toolItemNode.store("toolData", tool );
  68. var iconNode = new Element("div", {
  69. "styles": this.css.toolbarItemIconNode
  70. }).inject(toolItemNode);
  71. iconNode.setStyle("background-image", "url("+this.path+this.options.style+"/icon/"+tool.icon+")");
  72. var textNode = new Element("div", {
  73. "styles": this.css.toolbarItemTextNode,
  74. "text": tool.title
  75. });
  76. textNode.inject(toolItemNode);
  77. toolItemNode.inject(this.toolbarNode);
  78. this.toolItemNodes.push(toolItemNode);
  79. this.setToolbarItemEvent(toolItemNode);
  80. //this.setNodeCenter(this.node);
  81. },
  82. setToolbarItemEvent:function(toolItemNode){
  83. var _self = this;
  84. toolItemNode.addEvents({
  85. "click": function () {
  86. var data = this.retrieve("toolData");
  87. if( _self[data.action] )_self[data.action].apply(_self,[this]);
  88. }
  89. })
  90. },
  91. loadContentNode: function(){
  92. this.elementContentNode = new Element("div", {
  93. "styles": this.css.elementContentNode
  94. }).inject(this.node);
  95. this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  96. },
  97. loadView : function(){
  98. if( this.viewData.isAll ){
  99. this.view = new MWF.xApplication.cms.Module.ViewExplorer.ViewForALL(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  100. }else if( this.viewData.isDefault || (this.options.searchKey && this.options.searchKey!="") ){
  101. this.view = new MWF.xApplication.cms.Module.ViewExplorer.DefaultView(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  102. }else{
  103. this.view = new MWF.xApplication.cms.Module.ViewExplorer.View(this.elementContentNode, this.app,this, this.viewData );
  104. }
  105. this.view.load();
  106. this.setContentSize();
  107. },
  108. setContentSize: function(){
  109. var toolbarSize = this.toolbarNode ? this.toolbarNode.getSize() : {"x":0,"y":0};
  110. var titlebarSize = this.app.titleBar ? this.app.titleBar.getSize() : {"x":0,"y":0};
  111. var nodeSize = this.node.getSize();
  112. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  113. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  114. //var filterSize = this.filterNode.getSize();
  115. var filterConditionSize = this.filterConditionNode ? this.filterConditionNode.getSize() : {"x":0,"y":0};
  116. var height = nodeSize.y-toolbarSize.y-pt-pb-filterConditionSize.y-titlebarSize.y;
  117. this.elementContentNode.setStyle("height", ""+height+"px");
  118. this.pageCount = (height/40).toInt()+5;
  119. if (this.view.items.length<this.pageCount){
  120. this.view.loadElementList(this.pageCount-this.view.items.length);
  121. }
  122. },
  123. setNodeScroll: function(){
  124. var _self = this;
  125. MWF.require("MWF.widget.ScrollBar", function(){
  126. new MWF.widget.ScrollBar(this.elementContentNode, {
  127. "indent": false,"style":"xApp_TaskList", "where": "before", "distance": 30, "friction": 4, "axis": {"x": false, "y": true},
  128. "onScroll": function(y){
  129. var scrollSize = _self.elementContentNode.getScrollSize();
  130. var clientSize = _self.elementContentNode.getSize();
  131. var scrollHeight = scrollSize.y-clientSize.y;
  132. if (y+200>scrollHeight) {
  133. if (!_self.view.isItemsLoaded) _self.view.loadElementList();
  134. }
  135. }
  136. });
  137. }.bind(this));
  138. },
  139. loadFileter : function( actionNode ){
  140. //if(!this.filterNode)this.filterNode = new Element("div", {"styles": this.css.filterNode}).inject(this.elementContentNode);
  141. this._loadFileter( actionNode );
  142. },
  143. _loadFileter : function( actionNode ){
  144. if( !this.filter ){
  145. this.filter = new MWF.xApplication.cms.Module.Module.Filter(this.app, this,this.toolbarNode, actionNode, this.filterConditionNode, this.actions, this.css );
  146. this.filter.load();
  147. }else{
  148. this.filter.load();
  149. }
  150. }
  151. });
  152. MWF.xApplication.cms.Module.ViewExplorer.DefaultView = new Class({
  153. initialize: function( container, app,explorer, data, searchKey ){
  154. this.container = container;
  155. this.app = app;
  156. this.explorer = explorer;
  157. this.css = explorer.css;
  158. this.actions = explorer.actions;
  159. this.data = data;
  160. this.searchKey = searchKey;
  161. },
  162. initData: function(){
  163. this.items=[];
  164. this.documents = {};
  165. this.isItemsLoaded = false;
  166. this.isItemLoadding = false;
  167. this.loadItemQueue = 0;
  168. //this.controllers =[];
  169. },
  170. load : function(){
  171. this.initData();
  172. this.node = new Element("div", {
  173. "styles": this.css.elementContentListNode
  174. }).inject(this.container);
  175. this.table = new Element("table",{ "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "class" : "editTable"}).inject(this.node);
  176. this.initSortData();
  177. this.createListHead();
  178. this.loadElementList();
  179. },
  180. initSortData : function(){
  181. },
  182. clear: function(){
  183. this.documents = null;
  184. MWF.release(this.items);
  185. this.items=[];
  186. this.documents = {};
  187. this.container.empty();
  188. this.isItemsLoaded = false;
  189. this.isItemLoadding = false;
  190. this.loadItemQueue = 0;
  191. },
  192. reload: function(){
  193. this.clear();
  194. this.node = new Element("div", {
  195. "styles": this.css.elementContentListNode
  196. }).inject(this.container);
  197. this.table = new Element("table",{ "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "class" : "editTable"}).inject(this.node);
  198. this.createListHead();
  199. this.loadElementList();
  200. },
  201. createListHead : function(){
  202. var headNode = new Element("tr", {"styles": this.css.listHeadNode}).inject(this.table);
  203. var listItemUrl = this.explorer.path+"listItem.json";
  204. MWF.getJSON(listItemUrl, function(json){
  205. this.listItemTemplate = json;
  206. json.each(function(cell){
  207. var isShow = true;
  208. if( cell.access ){
  209. if( cell.access == "admin" && !this.explorer.options.isAdmin ){
  210. isShow = false;
  211. }
  212. }
  213. if(isShow) {
  214. new Element("th", {
  215. "styles": this.css[cell.headStyles],
  216. "text": cell.title,
  217. "width": cell.width
  218. }).inject(headNode)
  219. }
  220. }.bind(this));
  221. }.bind(this),false);
  222. },
  223. loadElementList: function(count){
  224. if (!this.isItemsLoaded){
  225. if (!this.isItemLoadding){
  226. this.isItemLoadding = true;
  227. this._getCurrentPageData(function(json){
  228. this.count = json.count;
  229. //if (!this.isCountShow){
  230. // this.filterAllProcessNode.getFirst("span").set("text", "("+this.count+")");
  231. // this.isCountShow = true;
  232. //}
  233. if (json.count<=this.items.length){
  234. this.isItemsLoaded = true;
  235. }
  236. json.data.each(function(data){
  237. if (!this.documents[data.id]){
  238. var item = this._createItem(data);
  239. this.items.push(item);
  240. this.documents[data.id] = item;
  241. }
  242. }.bind(this));
  243. this.isItemLoadding = false;
  244. if (this.loadItemQueue>0){
  245. this.loadItemQueue--;
  246. this.loadElementList();
  247. }
  248. }.bind(this), count);
  249. }else{
  250. this.loadItemQueue++;
  251. }
  252. }
  253. },
  254. _getCurrentPageData: function(callback, count){
  255. if(!count)count=20;
  256. var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  257. var data = {
  258. "catagoryIdList": [this.explorer.categoryData.id ],
  259. "statusList": [this.explorer.options.status]
  260. }
  261. if( this.searchKey && this.searchKey!="" ){
  262. data.titleList = [this.searchKey]
  263. }
  264. if (this.filter && this.filter.filter ){
  265. var filterResult = this.filter.getFilterResult();
  266. for(var f in filterResult ){
  267. data[f] = filterResult[f];
  268. }
  269. this.actions.listDocumentFilterNext(id, count || this.pageCount, data, function(json){
  270. if (callback) callback(json);
  271. });
  272. }else{
  273. this.actions.listDocumentFilterNext(id, count || this.pageCount, data, function(json){
  274. if (callback) callback(json);
  275. });
  276. }
  277. },
  278. removeDocument: function(document, all){
  279. var id = document.data.id;
  280. this.actions.removeDocument(id, function(json){
  281. //json.data.each(function(item){
  282. this.items.erase(this.documents[id]);
  283. this.documents[id].destroy();
  284. MWF.release(this.documents[id]);
  285. delete this.documents[id];
  286. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  287. // }.bind(this));
  288. }.bind(this));
  289. },
  290. _createItem: function(data){
  291. return new MWF.xApplication.cms.Module.ViewExplorer.DefaultDocument(this.table, data, this.explorer, this);
  292. }
  293. })
  294. MWF.xApplication.cms.Module.ViewExplorer.ViewForALL = new Class({
  295. Extends: MWF.xApplication.cms.Module.ViewExplorer.DefaultView,
  296. createListHead : function(){
  297. var headNode = new Element("tr", {"styles": this.css.listHeadNode}).inject(this.table);
  298. var listItemUrl = this.explorer.path+"listItemForAll.json";
  299. MWF.getJSON(listItemUrl, function(json){
  300. this.listItemTemplate = json;
  301. json.each(function(cell){
  302. var isShow = true;
  303. if( cell.access ){
  304. if( cell.access == "admin" && !this.explorer.options.isAdmin ){
  305. isShow = false;
  306. }
  307. }
  308. if(isShow) {
  309. new Element("th", {
  310. "styles": this.css[cell.headStyles],
  311. "text": cell.title,
  312. "width": cell.width
  313. }).inject(headNode)
  314. }
  315. }.bind(this));
  316. }.bind(this),false);
  317. },
  318. _getCurrentPageData: function(callback, count){
  319. if(!count)count=20;
  320. var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  321. var data = {
  322. "appIdList": [ this.explorer.columnData.id ],
  323. "statusList": [ this.explorer.options.status ]
  324. }
  325. if( this.searchKey && this.searchKey!="" ){
  326. data.titleList = [this.searchKey]
  327. }
  328. if (this.filter && this.filter.filter ){
  329. var filterResult = this.filter.getFilterResult();
  330. for(var f in filterResult ){
  331. data[f] = filterResult[f];
  332. }
  333. this.actions.listDocumentFilterNext(id, count || this.pageCount, data, function(json){
  334. if (callback) callback(json);
  335. });
  336. }else{
  337. this.actions.listDocumentFilterNext(id, count || this.pageCount, data, function(json){
  338. if (callback) callback(json);
  339. });
  340. }
  341. }
  342. })
  343. MWF.xApplication.cms.Module.ViewExplorer.View = new Class({
  344. Extends: MWF.xApplication.cms.Module.ViewExplorer.DefaultView,
  345. initSortData : function(){
  346. this.orderField = this.data.orderField ? this.data.orderField : "";
  347. this.orderType = this.data.orderType ? this.data.orderType : "";
  348. this.viewId = this.data.id;
  349. this.catagoryId = this.explorer.categoryData.id;
  350. this.status = this.explorer.options.status;
  351. },
  352. createListHead : function(){
  353. var _self = this;
  354. var headNode = new Element("tr", {"styles": this.css.listHeadNode}).inject(this.table);
  355. this.data.content.columns.each(function(column){
  356. var width = (column.widthType == "px" ? (column.width+"px") : (column.widthPer+"%"));
  357. var th = new Element("th",{
  358. "styles":this.css.normalThNode,
  359. "text" : column.title ? column.title : "",
  360. "width" : width
  361. }).inject(headNode);
  362. if( column.sortByClickTitle == "yes" ){
  363. th.store("field",column.value);
  364. if( this.orderField == column.value && this.orderType!="" ){
  365. th.store("orderType",this.orderType);
  366. this.sortIconNode = new Element("div",{
  367. "styles": this.orderType == "asc" ? this.css.sortIconNode_asc : this.css.sortIconNode_desc
  368. }).inject( th, "top" );
  369. }else{
  370. th.store("orderType","");
  371. this.sortIconNode = new Element("div",{"styles":this.css.sortIconNode}).inject( th, "top" );
  372. }
  373. th.setStyle("cursor","pointer");
  374. th.addEvent("click",function(){
  375. _self.resort( this );
  376. })
  377. }
  378. }.bind(this));
  379. },
  380. resort : function(th){
  381. this.orderField = th.retrieve("field");
  382. var orderType = th.retrieve("orderType");
  383. //th.eliminate(orderType);
  384. if( orderType == "" ){
  385. this.orderType = "asc";
  386. }else if( this.orderType == "asc" ){
  387. this.orderType = "desc";
  388. }else{
  389. this.orderField = this.data.orderField ? this.data.orderField : "";
  390. this.orderType = this.data.orderType ? this.data.orderType : "";
  391. }
  392. this.reload();
  393. },
  394. _getCurrentPageData: function(callback, count){
  395. if(!count)count=20;
  396. var id = (this.items.length) ? this.items[this.items.length-1].data.document.id : "(0)";
  397. var data = {
  398. "orderField":this.orderField,
  399. "orderType":this.orderType,
  400. "catagoryId":this.catagoryId,
  401. "viewId":this.viewId,
  402. "searchDocStatus":this.status
  403. }
  404. this.actions.listViewDataNext(id, count, data, function(json){
  405. json.data.each(function(d){
  406. if( !d.id )d.id = d.document.id;
  407. if( !d.title)d.title = d.document.title;
  408. })
  409. if (callback) callback(json);
  410. });
  411. },
  412. _createItem: function(data){
  413. return new MWF.xApplication.cms.Module.ViewExplorer.Document(this.table, data, this.explorer, this);
  414. }
  415. })
  416. MWF.xApplication.cms.Module.ViewExplorer.Filter = new Class({
  417. initialize: function( app,explorer,filterNode, filterActionNode, filterConditionNode, actions, css ){
  418. this.app = app;
  419. this.explorer = explorer;
  420. this.css = css;
  421. this.actions = actions;
  422. this.filterNode = $(filterNode);
  423. this.filterActionNode = $(filterActionNode);
  424. this.filterConditionNode = filterConditionNode;
  425. },
  426. load: function(){
  427. var filterItemUrl = this.explorer.path+"filterItem.json";
  428. MWF.getJSON(filterItemUrl, function(json){
  429. this.filterSetting = json;
  430. if (!this.isFilterOpen){
  431. if (!this.filterAreaMorph || !this.filterAreaMorph.isRunning()) this.showFilter();
  432. }else{
  433. if (this.filterAreaMorph || !this.filterAreaMorph.isRunning()) this.hideFilter();
  434. }
  435. }.bind(this));
  436. },
  437. showFilter: function(){
  438. //this.filterActionNode.setStyles(this.css.filterActionNode_over);
  439. if (!this.filterAreaNode) this.createFilterAreaNode();
  440. this.filterAreaTipNode.setStyle("display", "block");
  441. this.filterAreaNode.setStyle("display", "block");
  442. this.resizeFilterAreaNode();
  443. var toStyle = {
  444. "width": "460px",
  445. "height": "500px"
  446. }
  447. this.isFilterOpen = true;
  448. this.filterAreaMorph.start(toStyle).chain(function(){
  449. this.createFilterAreaTitle();
  450. this.createFilterAreaContent();
  451. this.hideFilterFun = this.hideFilter.bind(this);
  452. $(document.body).addEvent("click", this.hideFilterFun);
  453. }.bind(this));
  454. },
  455. hideFilter: function(){
  456. if (this.filterAreaNode){
  457. var toStyle = {
  458. "width": "460px",
  459. "height": "0px"
  460. }
  461. this.filterAreaNode.empty();
  462. this.isFilterOpen = false;
  463. this.filterAreaMorph.start(toStyle).chain(function(){
  464. this.filterAreaNode.eliminate("input");
  465. this.filterAreaNode.setStyle("display", "none");
  466. this.filterAreaTipNode.setStyle("display", "none");
  467. //this.filterActionNode.setStyles(this.css.filterActionNode);
  468. $(document.body).removeEvent("click", this.hideFilterFun);
  469. }.bind(this));
  470. $(document.body).removeEvent("click", this.hideFilterFun);
  471. }
  472. },
  473. createFilterAreaNode: function(){
  474. this.filterAreaNode = new Element("div", {"styles": this.css.filterAreaNode}).inject(this.app.content);
  475. this.filterAreaNode.addEvent("click", function(e){e.stopPropagation();});
  476. this.filterAreaTipNode = new Element("div", {"styles": this.css.filterAreaTipNode}).inject(this.app.content);
  477. //var size = this.filterActionNode.getSize();
  478. this.filterAreaNode.setStyles({
  479. "width": "460px",
  480. "height": "0px"
  481. });
  482. this.filterAreaNode.position({
  483. relativeTo: this.filterNode,
  484. position: 'bottomRight',
  485. edge: 'upperRight',
  486. offset: {x:-20, y: -1}
  487. });
  488. this.filterAreaTipNode.position({
  489. relativeTo: this.filterNode,
  490. position: 'bottomRight',
  491. edge: 'bottomRight',
  492. offset: {x:-38, y: 0}
  493. });
  494. this.app.addEvent("resize", function(){
  495. this.resizeFilterAreaNode();
  496. }.bind(this));
  497. this.filterAreaMorph = new Fx.Morph(this.filterAreaNode, {
  498. duration: '100',
  499. transition: Fx.Transitions.Sine.easeInOut
  500. });
  501. },
  502. resizeFilterAreaNode: function(){
  503. if (this.filterAreaNode){
  504. this.filterAreaNode.position({
  505. relativeTo: this.filterNode,
  506. position: 'bottomRight',
  507. edge: 'upperRight',
  508. offset: {x:-20, y: -1}
  509. });
  510. if (this.filterAreaTipNode){
  511. this.filterAreaTipNode.position({
  512. relativeTo: this.filterNode,
  513. position: 'bottomRight',
  514. edge: 'bottomRight',
  515. offset: {x:-38, y: 0}
  516. });
  517. }
  518. }
  519. },
  520. createFilterAreaTitle: function(){
  521. var titleNode = new Element("div", {"styles": this.css.filterAreaTitleNode}).inject(this.filterAreaNode);
  522. var okNode = new Element("div", {"styles": this.css.filterAreaTitleActionOkNode, "text": this.app.lp.ok}).inject(titleNode);
  523. var clearNode = new Element("div", {"styles": this.css.filterAreaTitleActionClearNode, "text": this.app.lp.clear}).inject(titleNode);
  524. clearNode.addEvent("click", function(){
  525. this.filterAreaNode.getElements(".filterItem").each(function(el){
  526. this.unSelectedFilterItem(el);
  527. }.bind(this));
  528. var input = this.filterAreaNode.retrieve("input");
  529. input.set("value", "");
  530. this.filter = null;
  531. this.hideFilter();
  532. this.setFilterConditions();
  533. this.explorer.reloadElementContent();
  534. }.bind(this));
  535. okNode.addEvent("click", function(){
  536. var input = this.filterAreaNode.retrieve("input");
  537. if (!this.filter) this.filter = {};
  538. var key = input.get("value");
  539. if (key && key!=this.app.lp.searchKey){
  540. this.filter.key = key;
  541. }else{
  542. this.filter.key = "";
  543. delete this.filter.key
  544. }
  545. this.hideFilter();
  546. this.setFilterConditions();
  547. this.explorer.reloadElementContent();
  548. }.bind(this));
  549. var searchNode = new Element("div", {"styles": this.css.filterAreaTitleSearchNode}).inject(titleNode);
  550. var searchIconNode = new Element("div", {"styles": this.css.filterAreaTitleSearchIconNode}).inject(searchNode);
  551. var searchInputAreaNode = new Element("div", {"styles": this.css.filterAreaTitleSearchInputAreaNode}).inject(searchNode);
  552. var searchInputNode = new Element("input", {"styles": this.css.filterAreaTitleSearchInputNode, "value": this.app.lp.searchKey}).inject(searchInputAreaNode);
  553. if (this.filter){
  554. if (this.filter.key) searchInputNode.set("value", this.filter.key);
  555. }
  556. this.filterAreaNode.store("input", searchInputNode);
  557. var key = this.app.lp.searchKey;
  558. searchInputNode.addEvents({
  559. "blur": function(){if (!this.get("value")) this.set("value", key)},
  560. "focus": function(){if (this.get("value")==key) this.set("value", "")},
  561. "keydown": function(e){
  562. if (e.code==13){
  563. var input = this.filterAreaNode.retrieve("input");
  564. if (!this.filter) this.filter = {};
  565. var key = input.get("value");
  566. if (key && key!=this.app.lp.searchKey){
  567. this.filter.key = key;
  568. }else{
  569. this.filter.key = "";
  570. delete this.filter.key
  571. }
  572. this.hideFilter();
  573. this.setFilterConditions();
  574. this.explorer.reloadElementContent();
  575. }
  576. }.bind(this)
  577. });
  578. },
  579. createFilterAreaContent: function(){
  580. var contentScrollNode = new Element("div", {"styles": this.css.applicationFilterAreaContentScrollNode}).inject(this.filterAreaNode);
  581. var contentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(contentScrollNode);
  582. MWF.require("MWF.widget.ScrollBar", function(){
  583. new MWF.widget.ScrollBar(contentScrollNode, {
  584. "style":"xApp_filter", "where": "after", "distance": 30, "friction": 4, "axis": {"x": false, "y": true}
  585. });
  586. }.bind(this));
  587. var _self = this;
  588. this._getFilterCount(function(json){
  589. Object.each(json, function(v, key){
  590. var categoryNode = new Element("div", {"styles": this.css.applicationFilterCategoryNode}).inject(contentNode);
  591. categoryNode.set("text", v.name );
  592. var itemAreaNode = new Element("div", {"styles": this.css.applicationFilterItemAreaNode}).inject(contentNode);
  593. // for (var x=0; x<10; x++){
  594. v.data.each(function(item){
  595. var itemNode = new Element("div", {"styles": this.css.applicationFilterItemNode}).inject(itemAreaNode);
  596. itemNode.set("text", item.name +"("+item.count+")");
  597. itemNode.store("value", item.value );
  598. itemNode.store("textname", item.name );
  599. itemNode.store("key", key);
  600. itemNode.store("resultItemName", item.resultItemName);
  601. itemNode.addEvent("click", function(){
  602. if (this.hasClass("applicationFilterItemNode_over")){
  603. _self.unSelectedFilterItem(this);
  604. }else{
  605. _self.selectedFilterItem(this);
  606. }
  607. });
  608. if (this.filter){
  609. if (this.filter[key]){
  610. if (item.value == this.filter[key][0].value){
  611. this.selectedFilterItem(itemNode);
  612. }
  613. }
  614. }
  615. }.bind(this));
  616. // }
  617. }.bind(this));
  618. }.bind(this));
  619. },
  620. _getFilterCount: function(callback){
  621. var fun = "listCategoryDraftFilterAttribute"
  622. if( this.explorer.options.status == "published" ){
  623. fun = "listCategoryPublishFilterAttribute"
  624. }else if( this.explorer.options.status == "archived" ){
  625. fun = "listCategoryArchiveFilterAttribute"
  626. }
  627. //this.app.options.id
  628. this.actions[fun]( this.explorer.categoryData.id , function(json){
  629. this.filterAttribute = {};
  630. Object.each(json.data, function(v, key) {
  631. var setting = this.filterSetting[key];
  632. if(setting){
  633. var dataItem = this.filterAttribute[setting.resultListKey] = {
  634. "name" : setting.categoryTitle,
  635. "data" : []
  636. };
  637. v.each(function(item){
  638. dataItem.data.push({
  639. "name" : item[setting.itemNameKey],
  640. "value" : item[setting.itemValueKey],
  641. "count" : item.count,
  642. "resultItemName": setting.resultItemName
  643. })
  644. })
  645. }
  646. }.bind(this))
  647. if (callback) callback(this.filterAttribute);
  648. }.bind(this));
  649. },
  650. unSelectedFilterItem: function(item){
  651. if (item.hasClass("applicationFilterItemNode_over")){
  652. var value = item.retrieve("value");
  653. var name = item.retrieve("textname");
  654. var key = item.retrieve("key");
  655. item.setStyles(this.css.applicationFilterItemNode);
  656. item.removeClass("applicationFilterItemNode_over");
  657. item.addClass("applicationFilterItemNode");
  658. if (!this.filter) this.filter = {};
  659. this.filter[key] = null;
  660. delete this.filter[key];
  661. item.getParent().eliminate("current");
  662. }
  663. },
  664. selectedFilterItem: function(item){
  665. if (!item.hasClass("applicationFilterItemNode_over")){
  666. var current = item.getParent().retrieve("current");
  667. if (current) this.unSelectedFilterItem(current);
  668. var value = item.retrieve("value");
  669. var key = item.retrieve("key");
  670. var name = item.retrieve("textname");
  671. var resultItemName = item.retrieve("resultItemName");
  672. item.setStyles(this.css.applicationFilterItemNode_over);
  673. item.removeClass("applicationFilterItemNode");
  674. item.addClass("applicationFilterItemNode_over");
  675. if (!this.filter) this.filter = {};
  676. this.filter[key] = [{"value": value, "name": name, "resultItemName":resultItemName}];
  677. item.getParent().store("current", item);
  678. }
  679. },
  680. searchElement: function(){
  681. if (!this.filter) this.filter = {};
  682. var key = this.searchElementInputNode.get("value");
  683. if (key && key!=this.app.lp.searchKey){
  684. this.filter.key = key;
  685. this.hideFilter();
  686. this.setFilterConditions();
  687. this.explorer.reloadElementContent();
  688. }
  689. },
  690. setFilterConditions: function(){
  691. this.filterConditionNode.empty();
  692. if (this.filter){
  693. Object.each(this.filter, function(v, key){
  694. if (key!="key"){
  695. this.createFilterItemNode(key, v[0]);
  696. }
  697. }.bind(this));
  698. if (this.filter.key){
  699. this.createFilterItemNode("key", {"name": this.filter.key});
  700. }
  701. }
  702. },
  703. createFilterItemNode: function(key, v){
  704. var _self = this;
  705. var node = new Element("div", {"styles": this.css.filterListItemNode}).inject(this.filterConditionNode);
  706. var actionNode = new Element("div", {"styles": this.css.filterListItemActionNode}).inject(node);
  707. var textNode = new Element("div", {"styles": this.css.filterListItemTextNode}).inject(node);
  708. if( key != "key" ){
  709. textNode.set("text", this.filterAttribute[key].name+": "+ v.name);
  710. }else{
  711. textNode.set("text", this.filterSetting.key.categoryTitle +": "+ v.name);
  712. }
  713. actionNode.store("key", key);
  714. node.addEvents({
  715. "mouseover": function(){
  716. this.setStyles(_self.css.filterListItemNode_over);
  717. this.getLast().setStyles(_self.css.filterListItemTextNode_over);
  718. this.getFirst().setStyles(_self.css.filterListItemActionNode_over);
  719. },
  720. "mouseout": function(){
  721. this.setStyles(_self.css.filterListItemNode);
  722. this.getLast().setStyles(_self.css.filterListItemTextNode);
  723. this.getFirst().setStyles(_self.css.filterListItemActionNode);
  724. }
  725. });
  726. actionNode.addEvent("click", function(){
  727. var key = this.retrieve("key");
  728. if (_self.filter[key]) _self.filter[key] = null;
  729. delete _self.filter[key];
  730. this.destroy();
  731. _self.setFilterConditions();
  732. _self.explorer.reloadElementContent();
  733. });
  734. },
  735. getFilterResult : function(){
  736. var result = {}
  737. Object.each(this.filter, function(v, key){
  738. if( key == "key" && this.filterSetting.key ){
  739. result[this.filterSetting.key.resultListKey] = [{
  740. "name" : this.filterSetting.key.resultItemName,
  741. "value" : v
  742. }];
  743. }else{
  744. result[key] = [{
  745. "name" : v[0].resultItemName,
  746. "value" : v[0].value
  747. }];
  748. }
  749. }.bind(this))
  750. return result;
  751. }
  752. })
  753. MWF.xApplication.cms.Module.ViewExplorer.DefaultDocument = new Class({
  754. initialize: function(container, data, explorer, view){
  755. this.explorer = explorer;
  756. this.app = explorer.app;
  757. this.data = data;
  758. this.container = container;
  759. this.view = view;
  760. this.css = this.explorer.css;
  761. this.load();
  762. },
  763. load: function(){
  764. this.node = new Element("tr", {"styles": this.css.documentItemNode});
  765. this.node.inject(this.container);
  766. //this.documentAreaNode = new Element("td", {"styles": this.css.documentItemDocumentNode}).inject(this.node);
  767. this.view.listItemTemplate.each(function(cell){
  768. var isShow = true;
  769. if( cell.access ){
  770. if( cell.access == "admin" && !this.explorer.options.isAdmin ){
  771. isShow = false;
  772. }
  773. }
  774. if(isShow){
  775. this[cell.name] = new Element("td",{
  776. "styles":this.css[cell.contentStyles],
  777. "text" : this.data[cell.item] ? this.data[cell.item] : ""
  778. }).inject(this.node);
  779. }
  780. }.bind(this));
  781. //this.setPersonData();
  782. //this.setStatusData();
  783. this.setActions();
  784. this.setEvents();
  785. },
  786. setEvents: function(){
  787. this.node.addEvents({
  788. "mouseover": function(){if (!this.readyRemove) this.node.setStyles(this.css.documentItemDocumentNode_over);}.bind(this),
  789. "mouseout": function(){if (!this.readyRemove) this.node.setStyles(this.css.documentItemDocumentNode);}.bind(this),
  790. "click": function(e){
  791. this.openDocument(e);
  792. }.bind(this)
  793. });
  794. if (this.setTopNode){
  795. this.setTopNode.addEvents({
  796. "mouseover": function(){this.setTopNode.setStyles(this.css.actionSetTopNode_over);}.bind(this),
  797. "mouseout": function(){this.setTopNode.setStyles(this.css.actionSetTopNode);}.bind(this),
  798. "mousedown": function(){this.setTopNode.setStyles(this.css.actionSetTopNode_down);}.bind(this),
  799. "mouseup": function(){this.setTopNode.setStyles(this.css.actionSetTopNode_over);}.bind(this),
  800. "click": function(e){
  801. this.setTop(e);
  802. e.stopPropagation();
  803. }.bind(this)
  804. });
  805. }
  806. if (this.shareNode){
  807. this.shareNode.addEvents({
  808. "mouseover": function(){this.shareNode.setStyles(this.css.actionShareNode_over);}.bind(this),
  809. "mouseout": function(){this.shareNode.setStyles(this.css.actionShareNode);}.bind(this),
  810. "mousedown": function(){this.shareNode.setStyles(this.css.actionShareNode_down);}.bind(this),
  811. "mouseup": function(){this.shareNode.setStyles(this.css.actionShareNode_over);}.bind(this),
  812. "click": function(e){
  813. this.share(e);
  814. e.stopPropagation();
  815. }.bind(this)
  816. });
  817. }
  818. if (this.openNode){
  819. this.openNode.addEvents({
  820. "mouseover": function(){this.openNode.setStyles(this.css.actionOpenNode_over);}.bind(this),
  821. "mouseout": function(){this.openNode.setStyles(this.css.actionOpenNode);}.bind(this),
  822. "mousedown": function(){this.openNode.setStyles(this.css.actionOpenNode_down);}.bind(this),
  823. "mouseup": function(){this.openNode.setStyles(this.css.actionOpenNode_over);}.bind(this),
  824. "click": function(e){
  825. this.openDocument(e);
  826. e.stopPropagation();
  827. }.bind(this)
  828. });
  829. }
  830. if (this.deleteNode){
  831. this.deleteNode.addEvents({
  832. "mouseover": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  833. "mouseout": function(){this.deleteNode.setStyles(this.css.actionDeleteNode);}.bind(this),
  834. "mousedown": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_down);}.bind(this),
  835. "mouseup": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  836. "click": function(e){
  837. this.remove(e);
  838. e.stopPropagation();
  839. }.bind(this)
  840. });
  841. }
  842. if (this.editNode){
  843. this.editNode.addEvents({
  844. "mouseover": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  845. "mouseout": function(){this.editNode.setStyles(this.css.actionEditNode);}.bind(this),
  846. "mousedown": function(){this.editNode.setStyles(this.css.actionEditNode_down);}.bind(this),
  847. "mouseup": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  848. "click": function(e){
  849. this.openDocument( e, true );
  850. e.stopPropagation();
  851. }.bind(this)
  852. });
  853. }
  854. //this.titleAreaNode.addEvent("click", function(){
  855. // this.loadChild();
  856. //}.bind(this));
  857. },
  858. setActions: function(){
  859. if( this.actionAreaNode ){
  860. if( this.explorer.options.isAdmin ){
  861. this.deleteNode = new Element("div", {"styles": this.css.actionDeleteNode, "title": this.explorer.app.lp.delete}).inject(this.actionAreaNode);
  862. this.editNode = new Element("div", {"styles": this.css.actionEditNode, "title": this.explorer.app.lp.edit}).inject(this.actionAreaNode);
  863. }
  864. //this.shareNode = new Element("div", {"styles": this.css.actionShareNode, "title": this.explorer.app.lp.share}).inject(this.actionAreaNode);
  865. }
  866. },
  867. openDocument: function(e, isEdited){
  868. var appId = "cms.Document"+this.data.id;
  869. if (this.app.desktop.apps[appId]){
  870. this.app.desktop.apps[appId].setCurrent();
  871. }else {
  872. var options = {
  873. "documentId": this.data.id,
  874. "appId": appId,
  875. "readonly" : !isEdited
  876. }//this.explorer.app.options.application.allowControl};
  877. this.explorer.app.desktop.openApplication(e, "cms.Document", options);
  878. }
  879. },
  880. remove: function(e){
  881. var lp = this.explorer.app.lp;
  882. var text = lp.deleteDocument.replace(/{title}/g, this.data.title);
  883. var _self = this;
  884. this.node.setStyles(this.css.documentItemDocumentNode_remove);
  885. this.readyRemove = true;
  886. this.explorer.app.confirm("warn", e, lp.deleteDocumentTitle, text, 350, 120, function(){
  887. //var inputs = this.content.getElements("input");
  888. //var flag = "";
  889. //for (var i=0; i<inputs.length; i++){
  890. // if (inputs[i].checked){
  891. // flag = inputs[i].get("value");
  892. // break;
  893. // }
  894. //}
  895. //if (flag){
  896. //if (flag=="all"){
  897. //_self.explorer.removeDocument(_self, true);
  898. //}else{
  899. _self.view.removeDocument(_self, false);
  900. //}
  901. this.close();
  902. //}else{
  903. // this.content.getElement("#deleteDocument_checkInfor").set("text", lp.deleteAllDocumentCheck).setStyle("color", "red");
  904. //}
  905. }, function(){
  906. _self.node.setStyles(_self.css.documentItemDocumentNode);
  907. _self.readyRemove = false;
  908. this.close();
  909. });
  910. },
  911. destroy: function(){
  912. this.node.destroy();
  913. },
  914. setPersonData: function(){
  915. var explorer = {
  916. "actions": this.explorer.personActions,
  917. "app": {
  918. "lp": this.explorer.app.lp
  919. }
  920. }
  921. new MWF.widget.Identity({"name": this.data.creatorIdentity}, this.personAreaNode, explorer, false, null, {"style": "work"});
  922. }
  923. });
  924. MWF.xApplication.cms.Module.ViewExplorer.Document = new Class({
  925. Extends: MWF.xApplication.cms.Module.ViewExplorer.DefaultDocument,
  926. load: function(){
  927. this.node = new Element("tr", {"styles": this.css.documentItemNode}).inject(this.container);
  928. this.view.data.content.columns.each(function(column){
  929. var value = (column.value && column.value!="") ? (this.data.document[column.value] || this.data.data[column.value] || "") : "";
  930. var td = new Element("td",{
  931. "styles":this.css.normalTdNode,
  932. "text" : value
  933. }).inject(this.node);
  934. if( column.align && column!="center" ){
  935. if( column.align == "left" ){
  936. td.setStyle("text-align","left");
  937. }else if( column.align == "right" ){
  938. td.setStyle("text-align","right");
  939. }
  940. }
  941. if( column.operation ){
  942. if( this.explorer.options.isAdmin ){
  943. if( column.operation.deleteDocument){
  944. this.deleteNode = new Element("div", {"styles": this.css.actionDeleteNode, "title": this.explorer.app.lp.delete}).inject(td);
  945. }
  946. if( column.operation.editDocument){
  947. this.editNode = new Element("div", {"styles": this.css.actionEditNode, "title": this.explorer.app.lp.edit}).inject(td);
  948. }
  949. }
  950. if( column.operation.share){
  951. this.shareNode = new Element("div", {"styles": this.css.actionShareNode, "title": this.explorer.app.lp.share}).inject(td);
  952. }
  953. }
  954. }.bind(this));
  955. //this.setActions();
  956. this.setEvents();
  957. }
  958. })