ViewExplorer.js 45 KB

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