ViewExplorer.js 43 KB

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