ViewExplorer.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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. resort : function(th){
  202. this.orderField = th.retrieve("field");
  203. var orderType = th.retrieve("orderType");
  204. //th.eliminate(orderType);
  205. if( orderType == "" ){
  206. this.orderType = "asc";
  207. }else if( this.orderType == "asc" ){
  208. this.orderType = "desc";
  209. }else{
  210. this.orderField = ""; //this.data.orderField ? this.data.orderField : "";
  211. this.orderType = ""; //this.data.orderType ? this.data.orderType : "";
  212. }
  213. this.reload();
  214. },
  215. createListHead : function(){
  216. var _self = this;
  217. var headNode = new Element("tr", {"styles": this.css.listHeadNode}).inject(this.table);
  218. var listItemUrl = this.explorer.path+"listItem.json";
  219. MWF.getJSON(listItemUrl, function(json){
  220. this.listItemTemplate = json;
  221. json.each(function(cell){
  222. var isShow = true;
  223. if( cell.access ){
  224. if( cell.access == "admin" && !this.explorer.options.isAdmin ){
  225. isShow = false;
  226. }
  227. }
  228. if(isShow) {
  229. var th = new Element("th", {
  230. "styles": this.css[cell.headStyles],
  231. "text": cell.title,
  232. "width": cell.width
  233. }).inject(headNode)
  234. if( cell.sortByClickTitle == "yes" ){
  235. th.store("field",cell.item);
  236. if( this.orderField == cell.item && this.orderType!="" ){
  237. th.store("orderType",this.orderType);
  238. this.sortIconNode = new Element("div",{
  239. "styles": this.orderType == "asc" ? this.css.sortIconNode_asc : this.css.sortIconNode_desc
  240. }).inject( th, "top" );
  241. }else{
  242. th.store("orderType","");
  243. this.sortIconNode = new Element("div",{"styles":this.css.sortIconNode}).inject( th, "top" );
  244. }
  245. th.setStyle("cursor","pointer");
  246. th.addEvent("click",function(){
  247. _self.resort( this );
  248. })
  249. }
  250. }
  251. }.bind(this));
  252. }.bind(this),false);
  253. },
  254. loadElementList: function(count){
  255. if (!this.isItemsLoaded){
  256. if (!this.isItemLoadding){
  257. this.isItemLoadding = true;
  258. this._getCurrentPageData(function(json){
  259. this.count = json.count;
  260. //if (!this.isCountShow){
  261. // this.filterAllProcessNode.getFirst("span").set("text", "("+this.count+")");
  262. // this.isCountShow = true;
  263. //}
  264. if (json.count<=this.items.length){
  265. this.isItemsLoaded = true;
  266. }
  267. json.data.each(function(data){
  268. if (!this.documents[data.id]){
  269. var item = this._createItem(data);
  270. this.items.push(item);
  271. this.documents[data.id] = item;
  272. }
  273. }.bind(this));
  274. this.isItemLoadding = false;
  275. if (this.loadItemQueue>0){
  276. this.loadItemQueue--;
  277. this.loadElementList();
  278. }
  279. }.bind(this), count);
  280. }else{
  281. this.loadItemQueue++;
  282. }
  283. }
  284. },
  285. _getCurrentPageData: function(callback, count){
  286. if(!count)count=20;
  287. var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  288. var data = {
  289. "categoryIdList": [this.explorer.categoryData.id ],
  290. "statusList": [this.explorer.options.status],
  291. "orderField" : this.orderField || null,
  292. "orderType" : this.orderType || null
  293. };
  294. if( this.searchKey && this.searchKey!="" ){
  295. data.titleList = [this.searchKey];
  296. }
  297. if (this.filter && this.filter.filter ){
  298. var filterResult = this.filter.getFilterResult();
  299. for(var f in filterResult ){
  300. data[f] = filterResult[f];
  301. }
  302. this.actions.listDocumentFilterNext(id, count || this.pageCount, data, function(json){
  303. if (callback) callback(json);
  304. });
  305. }else{
  306. this.actions.listDocumentFilterNext(id, count || this.pageCount, data, function(json){
  307. if (callback) callback(json);
  308. });
  309. }
  310. },
  311. removeDocument: function(document, all){
  312. var id = document.data.id;
  313. this.actions.removeDocument(id, function(json){
  314. //json.data.each(function(item){
  315. this.items.erase(this.documents[id]);
  316. this.documents[id].destroy();
  317. MWF.release(this.documents[id]);
  318. delete this.documents[id];
  319. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  320. // }.bind(this));
  321. }.bind(this));
  322. },
  323. _createItem: function(data){
  324. return new MWF.xApplication.cms.Module.ViewExplorer.DefaultDocument(this.table, data, this.explorer, this);
  325. }
  326. });
  327. MWF.xApplication.cms.Module.ViewExplorer.ViewForALL = new Class({
  328. Extends: MWF.xApplication.cms.Module.ViewExplorer.DefaultView,
  329. createListHead : function(){
  330. var _self = this;
  331. var headNode = new Element("tr", {"styles": this.css.listHeadNode}).inject(this.table);
  332. var listItemUrl = this.explorer.path+"listItemForAll.json";
  333. MWF.getJSON(listItemUrl, function(json){
  334. this.listItemTemplate = json;
  335. json.each(function(cell){
  336. var isShow = true;
  337. if( cell.access ){
  338. if( cell.access == "admin" && !this.explorer.options.isAdmin ){
  339. isShow = false;
  340. }
  341. }
  342. if(isShow) {
  343. var th = new Element("th", {
  344. "styles": this.css[cell.headStyles],
  345. "text": cell.title,
  346. "width": cell.width
  347. }).inject(headNode)
  348. }
  349. if( cell.sortByClickTitle == "yes" ){
  350. th.store("field",cell.item);
  351. if( this.orderField == cell.item && this.orderType!="" ){
  352. th.store("orderType",this.orderType);
  353. this.sortIconNode = new Element("div",{
  354. "styles": this.orderType == "asc" ? this.css.sortIconNode_asc : this.css.sortIconNode_desc
  355. }).inject( th, "top" );
  356. }else{
  357. th.store("orderType","");
  358. this.sortIconNode = new Element("div",{"styles":this.css.sortIconNode}).inject( th, "top" );
  359. }
  360. th.setStyle("cursor","pointer");
  361. th.addEvent("click",function(){
  362. _self.resort( this );
  363. })
  364. }
  365. }.bind(this));
  366. }.bind(this),false);
  367. },
  368. _getCurrentPageData: function(callback, count){
  369. if(!count)count=20;
  370. var id = (this.items.length) ? this.items[this.items.length-1].data.id : "(0)";
  371. var data = {
  372. "appIdList": [ this.explorer.columnData.id ],
  373. "statusList": [ this.explorer.options.status ],
  374. "orderField" : this.orderField || null,
  375. "orderType" : this.orderType || null
  376. };
  377. if( this.searchKey && this.searchKey!="" ){
  378. data.titleList = [this.searchKey]
  379. }
  380. if (this.filter && this.filter.filter ){
  381. var filterResult = this.filter.getFilterResult();
  382. for(var f in filterResult ){
  383. data[f] = filterResult[f];
  384. }
  385. this.actions.listDocumentFilterNext(id, count || this.pageCount, data, function(json){
  386. if (callback) callback(json);
  387. });
  388. }else{
  389. this.actions.listDocumentFilterNext(id, count || this.pageCount, data, function(json){
  390. if (callback) callback(json);
  391. });
  392. }
  393. }
  394. });
  395. MWF.xApplication.cms.Module.ViewExplorer.View = new Class({
  396. Extends: MWF.xApplication.cms.Module.ViewExplorer.DefaultView,
  397. initSortData : function(){
  398. this.orderField = this.data.orderField ? this.data.orderField : "";
  399. this.orderType = this.data.orderType ? this.data.orderType : "";
  400. this.viewId = this.data.id;
  401. this.categoryId = this.explorer.categoryData.id;
  402. this.status = this.explorer.options.status;
  403. },
  404. createListHead : function(){
  405. var _self = this;
  406. var headNode = new Element("tr", {"styles": this.css.listHeadNode}).inject(this.table);
  407. this.data.content.columns.each(function(column){
  408. var width = (column.widthType == "px" ? (column.width+"px") : (column.widthPer+"%"));
  409. var th = new Element("th",{
  410. "styles":this.css.normalThNode,
  411. "text" : column.title ? column.title : "",
  412. "width" : width
  413. }).inject(headNode);
  414. if( column.sortByClickTitle == "yes" ){
  415. th.store("field",column.value);
  416. if( this.orderField == column.value && this.orderType!="" ){
  417. th.store("orderType",this.orderType);
  418. this.sortIconNode = new Element("div",{
  419. "styles": this.orderType == "asc" ? this.css.sortIconNode_asc : this.css.sortIconNode_desc
  420. }).inject( th, "top" );
  421. }else{
  422. th.store("orderType","");
  423. this.sortIconNode = new Element("div",{"styles":this.css.sortIconNode}).inject( th, "top" );
  424. }
  425. th.setStyle("cursor","pointer");
  426. th.addEvent("click",function(){
  427. _self.resort( this );
  428. })
  429. }
  430. }.bind(this));
  431. },
  432. resort : function(th){
  433. this.orderField = th.retrieve("field");
  434. var orderType = th.retrieve("orderType");
  435. //th.eliminate(orderType);
  436. if( orderType == "" ){
  437. this.orderType = "asc";
  438. }else if( this.orderType == "asc" ){
  439. this.orderType = "desc";
  440. }else{
  441. this.orderField = this.data.orderField ? this.data.orderField : "";
  442. this.orderType = this.data.orderType ? this.data.orderType : "";
  443. }
  444. this.reload();
  445. },
  446. _getCurrentPageData: function(callback, count){
  447. if(!count)count=20;
  448. var id = (this.items.length) ? this.items[this.items.length-1].data.document.id : "(0)";
  449. var data = {
  450. "orderField":this.orderField,
  451. "orderType":this.orderType,
  452. "categoryId":this.categoryId,
  453. "viewId":this.viewId,
  454. "searchDocStatus":this.status
  455. }
  456. this.actions.listViewDataNext(id, count, data, function(json){
  457. json.data.each(function(d){
  458. if( !d.id )d.id = d.document.id;
  459. if( !d.title)d.title = d.document.title;
  460. })
  461. if (callback) callback(json);
  462. });
  463. },
  464. _createItem: function(data){
  465. return new MWF.xApplication.cms.Module.ViewExplorer.Document(this.table, data, this.explorer, this);
  466. }
  467. })
  468. MWF.xApplication.cms.Module.ViewExplorer.Filter = new Class({
  469. initialize: function( app,explorer,filterNode, filterActionNode, filterConditionNode, actions, css ){
  470. this.app = app;
  471. this.explorer = explorer;
  472. this.css = css;
  473. this.actions = actions;
  474. this.filterNode = $(filterNode);
  475. this.filterActionNode = $(filterActionNode);
  476. this.filterConditionNode = filterConditionNode;
  477. },
  478. load: function(){
  479. var filterItemUrl = this.explorer.path+"filterItem.json";
  480. MWF.getJSON(filterItemUrl, function(json){
  481. this.filterSetting = json;
  482. if (!this.isFilterOpen){
  483. if (!this.filterAreaMorph || !this.filterAreaMorph.isRunning()) this.showFilter();
  484. }else{
  485. if (this.filterAreaMorph || !this.filterAreaMorph.isRunning()) this.hideFilter();
  486. }
  487. }.bind(this));
  488. },
  489. showFilter: function(){
  490. //this.filterActionNode.setStyles(this.css.filterActionNode_over);
  491. if (!this.filterAreaNode) this.createFilterAreaNode();
  492. this.filterAreaTipNode.setStyle("display", "block");
  493. this.filterAreaNode.setStyle("display", "block");
  494. this.resizeFilterAreaNode();
  495. var toStyle = {
  496. "width": "460px",
  497. "height": "500px"
  498. }
  499. this.isFilterOpen = true;
  500. this.filterAreaMorph.start(toStyle).chain(function(){
  501. this.createFilterAreaTitle();
  502. this.createFilterAreaContent();
  503. this.hideFilterFun = this.hideFilter.bind(this);
  504. $(document.body).addEvent("click", this.hideFilterFun);
  505. }.bind(this));
  506. },
  507. hideFilter: function(){
  508. if (this.filterAreaNode){
  509. var toStyle = {
  510. "width": "460px",
  511. "height": "0px"
  512. }
  513. this.filterAreaNode.empty();
  514. this.isFilterOpen = false;
  515. this.filterAreaMorph.start(toStyle).chain(function(){
  516. this.filterAreaNode.eliminate("input");
  517. this.filterAreaNode.setStyle("display", "none");
  518. this.filterAreaTipNode.setStyle("display", "none");
  519. //this.filterActionNode.setStyles(this.css.filterActionNode);
  520. $(document.body).removeEvent("click", this.hideFilterFun);
  521. }.bind(this));
  522. $(document.body).removeEvent("click", this.hideFilterFun);
  523. }
  524. },
  525. createFilterAreaNode: function(){
  526. this.filterAreaNode = new Element("div", {"styles": this.css.filterAreaNode}).inject(this.app.content);
  527. this.filterAreaNode.addEvent("click", function(e){e.stopPropagation();});
  528. this.filterAreaTipNode = new Element("div", {"styles": this.css.filterAreaTipNode}).inject(this.app.content);
  529. //var size = this.filterActionNode.getSize();
  530. this.filterAreaNode.setStyles({
  531. "width": "460px",
  532. "height": "0px"
  533. });
  534. this.filterAreaNode.position({
  535. relativeTo: this.filterNode,
  536. position: 'bottomRight',
  537. edge: 'upperRight',
  538. offset: {x:-20, y: -1}
  539. });
  540. this.filterAreaTipNode.position({
  541. relativeTo: this.filterNode,
  542. position: 'bottomRight',
  543. edge: 'bottomRight',
  544. offset: {x:-38, y: 0}
  545. });
  546. this.app.addEvent("resize", function(){
  547. this.resizeFilterAreaNode();
  548. }.bind(this));
  549. this.filterAreaMorph = new Fx.Morph(this.filterAreaNode, {
  550. duration: '100',
  551. transition: Fx.Transitions.Sine.easeInOut
  552. });
  553. },
  554. resizeFilterAreaNode: function(){
  555. if (this.filterAreaNode){
  556. this.filterAreaNode.position({
  557. relativeTo: this.filterNode,
  558. position: 'bottomRight',
  559. edge: 'upperRight',
  560. offset: {x:-20, y: -1}
  561. });
  562. if (this.filterAreaTipNode){
  563. this.filterAreaTipNode.position({
  564. relativeTo: this.filterNode,
  565. position: 'bottomRight',
  566. edge: 'bottomRight',
  567. offset: {x:-38, y: 0}
  568. });
  569. }
  570. }
  571. },
  572. createFilterAreaTitle: function(){
  573. var titleNode = new Element("div", {"styles": this.css.filterAreaTitleNode}).inject(this.filterAreaNode);
  574. var okNode = new Element("div", {"styles": this.css.filterAreaTitleActionOkNode, "text": this.app.lp.ok}).inject(titleNode);
  575. var clearNode = new Element("div", {"styles": this.css.filterAreaTitleActionClearNode, "text": this.app.lp.clear}).inject(titleNode);
  576. clearNode.addEvent("click", function(){
  577. this.filterAreaNode.getElements(".filterItem").each(function(el){
  578. this.unSelectedFilterItem(el);
  579. }.bind(this));
  580. var input = this.filterAreaNode.retrieve("input");
  581. input.set("value", "");
  582. this.filter = null;
  583. this.hideFilter();
  584. this.setFilterConditions();
  585. this.explorer.reloadElementContent();
  586. }.bind(this));
  587. okNode.addEvent("click", function(){
  588. var input = this.filterAreaNode.retrieve("input");
  589. if (!this.filter) this.filter = {};
  590. var key = input.get("value");
  591. if (key && key!=this.app.lp.searchKey){
  592. this.filter.key = key;
  593. }else{
  594. this.filter.key = "";
  595. delete this.filter.key
  596. }
  597. this.hideFilter();
  598. this.setFilterConditions();
  599. this.explorer.reloadElementContent();
  600. }.bind(this));
  601. var searchNode = new Element("div", {"styles": this.css.filterAreaTitleSearchNode}).inject(titleNode);
  602. var searchIconNode = new Element("div", {"styles": this.css.filterAreaTitleSearchIconNode}).inject(searchNode);
  603. var searchInputAreaNode = new Element("div", {"styles": this.css.filterAreaTitleSearchInputAreaNode}).inject(searchNode);
  604. var searchInputNode = new Element("input", {"styles": this.css.filterAreaTitleSearchInputNode, "value": this.app.lp.searchKey}).inject(searchInputAreaNode);
  605. if (this.filter){
  606. if (this.filter.key) searchInputNode.set("value", this.filter.key);
  607. }
  608. this.filterAreaNode.store("input", searchInputNode);
  609. var key = this.app.lp.searchKey;
  610. searchInputNode.addEvents({
  611. "blur": function(){if (!this.get("value")) this.set("value", key)},
  612. "focus": function(){if (this.get("value")==key) this.set("value", "")},
  613. "keydown": function(e){
  614. if (e.code==13){
  615. var input = this.filterAreaNode.retrieve("input");
  616. if (!this.filter) this.filter = {};
  617. var key = input.get("value");
  618. if (key && key!=this.app.lp.searchKey){
  619. this.filter.key = key;
  620. }else{
  621. this.filter.key = "";
  622. delete this.filter.key
  623. }
  624. this.hideFilter();
  625. this.setFilterConditions();
  626. this.explorer.reloadElementContent();
  627. }
  628. }.bind(this)
  629. });
  630. },
  631. createFilterAreaContent: function(){
  632. var contentScrollNode = new Element("div", {"styles": this.css.applicationFilterAreaContentScrollNode}).inject(this.filterAreaNode);
  633. var contentNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(contentScrollNode);
  634. MWF.require("MWF.widget.ScrollBar", function(){
  635. new MWF.widget.ScrollBar(contentScrollNode, {
  636. "style":"xApp_filter", "where": "after", "distance": 30, "friction": 4, "axis": {"x": false, "y": true}
  637. });
  638. }.bind(this));
  639. var _self = this;
  640. this._getFilterCount(function(json){
  641. Object.each(json, function(v, key){
  642. var categoryNode = new Element("div", {"styles": this.css.applicationFilterCategoryNode}).inject(contentNode);
  643. categoryNode.set("text", v.name );
  644. var itemAreaNode = new Element("div", {"styles": this.css.applicationFilterItemAreaNode}).inject(contentNode);
  645. // for (var x=0; x<10; x++){
  646. v.data.each(function(item){
  647. var itemNode = new Element("div", {"styles": this.css.applicationFilterItemNode}).inject(itemAreaNode);
  648. itemNode.set("text", item.name +"("+item.count+")");
  649. itemNode.store("value", item.value );
  650. itemNode.store("textname", item.name );
  651. itemNode.store("key", key);
  652. itemNode.store("resultItemName", item.resultItemName);
  653. itemNode.addEvent("click", function(){
  654. if (this.hasClass("applicationFilterItemNode_over")){
  655. _self.unSelectedFilterItem(this);
  656. }else{
  657. _self.selectedFilterItem(this);
  658. }
  659. });
  660. if (this.filter){
  661. if (this.filter[key]){
  662. if (item.value == this.filter[key][0].value){
  663. this.selectedFilterItem(itemNode);
  664. }
  665. }
  666. }
  667. }.bind(this));
  668. // }
  669. }.bind(this));
  670. }.bind(this));
  671. },
  672. _getFilterCount: function(callback){
  673. var fun = "listCategoryDraftFilterAttribute"
  674. if( this.explorer.options.status == "published" ){
  675. fun = "listCategoryPublishFilterAttribute"
  676. }else if( this.explorer.options.status == "archived" ){
  677. fun = "listCategoryArchiveFilterAttribute"
  678. }
  679. //this.app.options.id
  680. this.actions[fun]( this.explorer.categoryData.id , function(json){
  681. this.filterAttribute = {};
  682. Object.each(json.data, function(v, key) {
  683. var setting = this.filterSetting[key];
  684. if(setting){
  685. var dataItem = this.filterAttribute[setting.resultListKey] = {
  686. "name" : setting.categoryTitle,
  687. "data" : []
  688. };
  689. v.each(function(item){
  690. dataItem.data.push({
  691. "name" : item[setting.itemNameKey],
  692. "value" : item[setting.itemValueKey],
  693. "count" : item.count,
  694. "resultItemName": setting.resultItemName
  695. })
  696. })
  697. }
  698. }.bind(this))
  699. if (callback) callback(this.filterAttribute);
  700. }.bind(this));
  701. },
  702. unSelectedFilterItem: function(item){
  703. if (item.hasClass("applicationFilterItemNode_over")){
  704. var value = item.retrieve("value");
  705. var name = item.retrieve("textname");
  706. var key = item.retrieve("key");
  707. item.setStyles(this.css.applicationFilterItemNode);
  708. item.removeClass("applicationFilterItemNode_over");
  709. item.addClass("applicationFilterItemNode");
  710. if (!this.filter) this.filter = {};
  711. this.filter[key] = null;
  712. delete this.filter[key];
  713. item.getParent().eliminate("current");
  714. }
  715. },
  716. selectedFilterItem: function(item){
  717. if (!item.hasClass("applicationFilterItemNode_over")){
  718. var current = item.getParent().retrieve("current");
  719. if (current) this.unSelectedFilterItem(current);
  720. var value = item.retrieve("value");
  721. var key = item.retrieve("key");
  722. var name = item.retrieve("textname");
  723. var resultItemName = item.retrieve("resultItemName");
  724. item.setStyles(this.css.applicationFilterItemNode_over);
  725. item.removeClass("applicationFilterItemNode");
  726. item.addClass("applicationFilterItemNode_over");
  727. if (!this.filter) this.filter = {};
  728. this.filter[key] = [{"value": value, "name": name, "resultItemName":resultItemName}];
  729. item.getParent().store("current", item);
  730. }
  731. },
  732. searchElement: function(){
  733. if (!this.filter) this.filter = {};
  734. var key = this.searchElementInputNode.get("value");
  735. if (key && key!=this.app.lp.searchKey){
  736. this.filter.key = key;
  737. this.hideFilter();
  738. this.setFilterConditions();
  739. this.explorer.reloadElementContent();
  740. }
  741. },
  742. setFilterConditions: function(){
  743. this.filterConditionNode.empty();
  744. if (this.filter){
  745. Object.each(this.filter, function(v, key){
  746. if (key!="key"){
  747. this.createFilterItemNode(key, v[0]);
  748. }
  749. }.bind(this));
  750. if (this.filter.key){
  751. this.createFilterItemNode("key", {"name": this.filter.key});
  752. }
  753. }
  754. },
  755. createFilterItemNode: function(key, v){
  756. var _self = this;
  757. var node = new Element("div", {"styles": this.css.filterListItemNode}).inject(this.filterConditionNode);
  758. var actionNode = new Element("div", {"styles": this.css.filterListItemActionNode}).inject(node);
  759. var textNode = new Element("div", {"styles": this.css.filterListItemTextNode}).inject(node);
  760. if( key != "key" ){
  761. textNode.set("text", this.filterAttribute[key].name+": "+ v.name);
  762. }else{
  763. textNode.set("text", this.filterSetting.key.categoryTitle +": "+ v.name);
  764. }
  765. actionNode.store("key", key);
  766. node.addEvents({
  767. "mouseover": function(){
  768. this.setStyles(_self.css.filterListItemNode_over);
  769. this.getLast().setStyles(_self.css.filterListItemTextNode_over);
  770. this.getFirst().setStyles(_self.css.filterListItemActionNode_over);
  771. },
  772. "mouseout": function(){
  773. this.setStyles(_self.css.filterListItemNode);
  774. this.getLast().setStyles(_self.css.filterListItemTextNode);
  775. this.getFirst().setStyles(_self.css.filterListItemActionNode);
  776. }
  777. });
  778. actionNode.addEvent("click", function(){
  779. var key = this.retrieve("key");
  780. if (_self.filter[key]) _self.filter[key] = null;
  781. delete _self.filter[key];
  782. this.destroy();
  783. _self.setFilterConditions();
  784. _self.explorer.reloadElementContent();
  785. });
  786. },
  787. getFilterResult : function(){
  788. var result = {}
  789. Object.each(this.filter, function(v, key){
  790. if( key == "key" && this.filterSetting.key ){
  791. result[this.filterSetting.key.resultListKey] = [{
  792. "name" : this.filterSetting.key.resultItemName,
  793. "value" : v
  794. }];
  795. }else{
  796. result[key] = [{
  797. "name" : v[0].resultItemName,
  798. "value" : v[0].value
  799. }];
  800. }
  801. }.bind(this))
  802. return result;
  803. }
  804. })
  805. MWF.xApplication.cms.Module.ViewExplorer.DefaultDocument = new Class({
  806. initialize: function(container, data, explorer, view){
  807. this.explorer = explorer;
  808. this.app = explorer.app;
  809. this.data = data;
  810. this.container = container;
  811. this.view = view;
  812. this.css = this.explorer.css;
  813. this.load();
  814. },
  815. load: function(){
  816. this.node = new Element("tr", {"styles": this.css.documentItemNode});
  817. this.node.inject(this.container);
  818. //this.documentAreaNode = new Element("td", {"styles": this.css.documentItemDocumentNode}).inject(this.node);
  819. this.view.listItemTemplate.each(function(cell){
  820. var isShow = true;
  821. if( cell.access ){
  822. if( cell.access == "admin" && !this.explorer.options.isAdmin ){
  823. isShow = false;
  824. }
  825. }
  826. if(isShow){
  827. this[cell.name] = new Element("td",{
  828. "styles":this.css[cell.contentStyles],
  829. "text" : this.data[cell.item] ? this.data[cell.item] : ""
  830. }).inject(this.node);
  831. }
  832. }.bind(this));
  833. //this.setPersonData();
  834. //this.setStatusData();
  835. this.setActions();
  836. this.setEvents();
  837. },
  838. setEvents: function(){
  839. this.node.addEvents({
  840. "mouseover": function(){if (!this.readyRemove) this.node.setStyles(this.css.documentItemDocumentNode_over);}.bind(this),
  841. "mouseout": function(){if (!this.readyRemove) this.node.setStyles(this.css.documentItemDocumentNode);}.bind(this),
  842. "click": function(e){
  843. this.openDocument(e);
  844. }.bind(this)
  845. });
  846. if (this.setTopNode){
  847. this.setTopNode.addEvents({
  848. "mouseover": function(){this.setTopNode.setStyles(this.css.actionSetTopNode_over);}.bind(this),
  849. "mouseout": function(){this.setTopNode.setStyles(this.css.actionSetTopNode);}.bind(this),
  850. "mousedown": function(){this.setTopNode.setStyles(this.css.actionSetTopNode_down);}.bind(this),
  851. "mouseup": function(){this.setTopNode.setStyles(this.css.actionSetTopNode_over);}.bind(this),
  852. "click": function(e){
  853. this.setTop(e);
  854. e.stopPropagation();
  855. }.bind(this)
  856. });
  857. }
  858. if (this.shareNode){
  859. this.shareNode.addEvents({
  860. "mouseover": function(){this.shareNode.setStyles(this.css.actionShareNode_over);}.bind(this),
  861. "mouseout": function(){this.shareNode.setStyles(this.css.actionShareNode);}.bind(this),
  862. "mousedown": function(){this.shareNode.setStyles(this.css.actionShareNode_down);}.bind(this),
  863. "mouseup": function(){this.shareNode.setStyles(this.css.actionShareNode_over);}.bind(this),
  864. "click": function(e){
  865. this.share(e);
  866. e.stopPropagation();
  867. }.bind(this)
  868. });
  869. }
  870. if (this.openNode){
  871. this.openNode.addEvents({
  872. "mouseover": function(){this.openNode.setStyles(this.css.actionOpenNode_over);}.bind(this),
  873. "mouseout": function(){this.openNode.setStyles(this.css.actionOpenNode);}.bind(this),
  874. "mousedown": function(){this.openNode.setStyles(this.css.actionOpenNode_down);}.bind(this),
  875. "mouseup": function(){this.openNode.setStyles(this.css.actionOpenNode_over);}.bind(this),
  876. "click": function(e){
  877. this.openDocument(e);
  878. e.stopPropagation();
  879. }.bind(this)
  880. });
  881. }
  882. if (this.deleteNode){
  883. this.deleteNode.addEvents({
  884. "mouseover": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  885. "mouseout": function(){this.deleteNode.setStyles(this.css.actionDeleteNode);}.bind(this),
  886. "mousedown": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_down);}.bind(this),
  887. "mouseup": function(){this.deleteNode.setStyles(this.css.actionDeleteNode_over);}.bind(this),
  888. "click": function(e){
  889. this.remove(e);
  890. e.stopPropagation();
  891. }.bind(this)
  892. });
  893. }
  894. if (this.editNode){
  895. this.editNode.addEvents({
  896. "mouseover": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  897. "mouseout": function(){this.editNode.setStyles(this.css.actionEditNode);}.bind(this),
  898. "mousedown": function(){this.editNode.setStyles(this.css.actionEditNode_down);}.bind(this),
  899. "mouseup": function(){this.editNode.setStyles(this.css.actionEditNode_over);}.bind(this),
  900. "click": function(e){
  901. this.openDocument( e, true );
  902. e.stopPropagation();
  903. }.bind(this)
  904. });
  905. }
  906. //this.titleAreaNode.addEvent("click", function(){
  907. // this.loadChild();
  908. //}.bind(this));
  909. },
  910. setActions: function(){
  911. if( this.actionAreaNode ){
  912. if( this.explorer.options.isAdmin ){
  913. this.deleteNode = new Element("div", {"styles": this.css.actionDeleteNode, "title": this.explorer.app.lp.delete}).inject(this.actionAreaNode);
  914. this.editNode = new Element("div", {"styles": this.css.actionEditNode, "title": this.explorer.app.lp.edit}).inject(this.actionAreaNode);
  915. }
  916. //this.shareNode = new Element("div", {"styles": this.css.actionShareNode, "title": this.explorer.app.lp.share}).inject(this.actionAreaNode);
  917. }
  918. },
  919. openDocument: function(e, isEdited){
  920. var appId = "cms.Document"+this.data.id;
  921. if (this.app.desktop.apps[appId]){
  922. this.app.desktop.apps[appId].setCurrent();
  923. }else {
  924. var options = {
  925. "documentId": this.data.id,
  926. "appId": appId,
  927. "readonly" : !isEdited,
  928. "postDelete" : function(){
  929. this.view.reload();
  930. }.bind(this)
  931. };
  932. this.explorer.app.desktop.openApplication(e, "cms.Document", options);
  933. }
  934. },
  935. remove: function(e){
  936. var lp = this.explorer.app.lp;
  937. var text = lp.deleteDocument.replace(/{title}/g, this.data.title);
  938. var _self = this;
  939. this.node.setStyles(this.css.documentItemDocumentNode_remove);
  940. this.readyRemove = true;
  941. this.explorer.app.confirm("warn", e, lp.deleteDocumentTitle, text, 350, 120, function(){
  942. //var inputs = this.content.getElements("input");
  943. //var flag = "";
  944. //for (var i=0; i<inputs.length; i++){
  945. // if (inputs[i].checked){
  946. // flag = inputs[i].get("value");
  947. // break;
  948. // }
  949. //}
  950. //if (flag){
  951. //if (flag=="all"){
  952. //_self.explorer.removeDocument(_self, true);
  953. //}else{
  954. _self.view.removeDocument(_self, false);
  955. //}
  956. this.close();
  957. //}else{
  958. // this.content.getElement("#deleteDocument_checkInfor").set("text", lp.deleteAllDocumentCheck).setStyle("color", "red");
  959. //}
  960. }, function(){
  961. _self.node.setStyles(_self.css.documentItemDocumentNode);
  962. _self.readyRemove = false;
  963. this.close();
  964. });
  965. },
  966. destroy: function(){
  967. this.node.destroy();
  968. },
  969. setPersonData: function(){
  970. var explorer = {
  971. "actions": this.explorer.personActions,
  972. "app": {
  973. "lp": this.explorer.app.lp
  974. }
  975. }
  976. new MWF.widget.Identity({"name": this.data.creatorIdentity}, this.personAreaNode, explorer, false, null, {"style": "work"});
  977. }
  978. });
  979. MWF.xApplication.cms.Module.ViewExplorer.Document = new Class({
  980. Extends: MWF.xApplication.cms.Module.ViewExplorer.DefaultDocument,
  981. load: function(){
  982. this.node = new Element("tr", {"styles": this.css.documentItemNode}).inject(this.container);
  983. this.view.data.content.columns.each(function(column){
  984. var value = (column.value && column.value!="") ? (this.data.document[column.value] || this.data.data[column.value] || "") : "";
  985. var td = new Element("td",{
  986. "styles":this.css.normalTdNode,
  987. "text" : value
  988. }).inject(this.node);
  989. if( column.align && column!="center" ){
  990. if( column.align == "left" ){
  991. td.setStyle("text-align","left");
  992. }else if( column.align == "right" ){
  993. td.setStyle("text-align","right");
  994. }
  995. }
  996. if( column.operation ){
  997. if( this.explorer.options.isAdmin ){
  998. if( column.operation.deleteDocument){
  999. this.deleteNode = new Element("div", {"styles": this.css.actionDeleteNode, "title": this.explorer.app.lp.delete}).inject(td);
  1000. }
  1001. if( column.operation.editDocument){
  1002. this.editNode = new Element("div", {"styles": this.css.actionEditNode, "title": this.explorer.app.lp.edit}).inject(td);
  1003. }
  1004. }
  1005. if( column.operation.share){
  1006. this.shareNode = new Element("div", {"styles": this.css.actionShareNode, "title": this.explorer.app.lp.share}).inject(td);
  1007. }
  1008. }
  1009. }.bind(this));
  1010. //this.setActions();
  1011. this.setEvents();
  1012. }
  1013. });