Explorer.js 38 KB

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