Explorer.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. MWF.xApplication.cms.ColumnManager = MWF.xApplication.cms.ColumnManager || {};
  3. MWF.xDesktop.requireApp("cms.ColumnManager", "lp."+MWF.language, null, false);
  4. MWF.xDesktop.requireApp("cms.ColumnManager", "package", null, false);
  5. MWF.xApplication.cms.ColumnManager.Explorer = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "title" : "",
  11. "tooltip": {
  12. "create": MWF.CMSCM.LP.category.create,
  13. "search": MWF.CMSCM.LP.category.search,
  14. "searchText": MWF.CMSCM.LP.category.searchText,
  15. "noElement": MWF.CMSCM.LP.category.noCategoryNoticeText
  16. }
  17. },
  18. initialize: function(node, actions, options){
  19. this.setOptions(options);
  20. this.setTooltip();
  21. this.path = "../x_component_cms_ColumnManager/$Explorer/";
  22. this.cssPath = "../x_component_cms_ColumnManager/$Explorer/"+this.options.style+"/css.wcss";
  23. this._loadCss();
  24. this.actions = actions;
  25. this.node = $(node);
  26. this.initData();
  27. },
  28. setTooltip: function(tooltip){
  29. if (tooltip) this.options.tooltip = Object.merge(this.options.tooltip, tooltip);
  30. },
  31. initData: function(){
  32. //this.categoryLoadFirst = true;
  33. //this.isLoaddingCategory = false;
  34. //this.categoryLoaded = false;
  35. //this.categorys = [];
  36. //this.dragItem = false;
  37. //this.dragCategory = false;
  38. //this.currentCategory = null;
  39. //this.loadCategoryQueue = 0;
  40. this.itemArray = [];
  41. this.itemObject = {};
  42. this.deleteMarkItems = [];
  43. this.selectMarkItems = [];
  44. },
  45. reload: function(){
  46. if( !this.node )return;
  47. this.initData();
  48. this.node.empty();
  49. this.load();
  50. },
  51. load: function(){
  52. this.loadToolbar();
  53. this.loadContentNode();
  54. this.setNodeScroll();
  55. this.loadElementList();
  56. },
  57. loadToolbar: function(){
  58. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode});
  59. this.createTitleElementNode();
  60. this.createCreateElementNode();
  61. this.createSearchElementNode();
  62. this.toolbarNode.inject(this.node);
  63. },
  64. createCreateElementNode: function(){
  65. this.createElementNode = new Element("div", {
  66. "styles": this.css.createElementNode,
  67. "title": this.options.tooltip.create
  68. }).inject(this.toolbarNode);
  69. this.createElementNode.addEvents({
  70. "click": function(e){ this._createElement(e); }.bind(this),
  71. "mouseover" : function(e){
  72. this.createElementNode.setStyles(this.css.createElementNode_over);
  73. }.bind(this),
  74. "mouseout" : function(ev){
  75. this.createElementNode.setStyles(this.css.createElementNode);
  76. }.bind(this)
  77. });
  78. },
  79. createTitleElementNode: function() {
  80. this.titleElementNode = new Element("div", {
  81. "styles": this.css.titleElementNode,
  82. "text": this.options.title
  83. }).inject(this.toolbarNode);
  84. },
  85. createSearchElementNode: function(){
  86. this.searchElementNode = new Element("div", {
  87. "styles": this.css.searchElementNode
  88. }).inject(this.toolbarNode);
  89. //@todo
  90. return false;
  91. this.searchElementButtonNode = new Element("div", {
  92. "styles": this.css.searchElementButtonNode,
  93. "title": this.options.tooltip.search
  94. }).inject(this.searchElementNode);
  95. this.searchElementInputAreaNode = new Element("div", {
  96. "styles": this.css.searchElementInputAreaNode
  97. }).inject(this.searchElementNode);
  98. this.searchElementInputBoxNode = new Element("div", {
  99. "styles": this.css.searchElementInputBoxNode
  100. }).inject(this.searchElementInputAreaNode);
  101. this.searchElementInputNode = new Element("input", {
  102. "type": "text",
  103. "value": this.options.tooltip.searchText,
  104. "styles": this.css.searchElementInputNode,
  105. "x-webkit-speech": "1"
  106. }).inject(this.searchElementInputBoxNode);
  107. var _self = this;
  108. this.searchElementInputNode.addEvents({
  109. "focus": function(){
  110. if (this.value==_self.options.tooltip.searchText) this.set("value", "");
  111. },
  112. "blur": function(){if (!this.value) this.set("value", _self.options.tooltip.searchText);},
  113. "keydown": function(e){
  114. if (e.code==13){
  115. this.searchElement();
  116. e.preventDefault();
  117. }
  118. }.bind(this),
  119. "selectstart": function(e){
  120. e.preventDefault();
  121. }
  122. });
  123. this.searchElementButtonNode.addEvent("click", function(){this.searchElement();}.bind(this));
  124. },
  125. searchElement: function(){
  126. //-----------------------------------------
  127. //-----------------------------------------
  128. //-----search category---------------------
  129. //-----------------------------------------
  130. //-----------------------------------------
  131. //alert("search Element");
  132. },
  133. loadContentNode: function(){
  134. this.elementContentNode = new Element("div", {
  135. "styles": this.css.elementContentNode
  136. }).inject(this.node);
  137. this.elementContentListNode = new Element("div", {
  138. "styles": this.css.elementContentListNode
  139. }).inject(this.elementContentNode);
  140. this.setContentSize();
  141. this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  142. },
  143. setContentSize: function(){
  144. var toolbarSize = this.toolbarNode ? this.toolbarNode.getSize() : { x : 0 , y : 0 };
  145. var nodeSize = this.node.getSize();
  146. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  147. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  148. var height = nodeSize.y-toolbarSize.y-pt-pb;
  149. this.elementContentNode.setStyle("height", ""+height+"px");
  150. var contentSize = this.app.content.getSize();
  151. var menuSize = this.app.leftContentNode.getSize();
  152. var width = contentSize.x - menuSize.x;
  153. this.elementContentNode.setStyle("width", ""+(width-10)+"px");
  154. if (this.options.noCreate) this.createElementNode.destroy();
  155. //var count = (nodeSize.x/282).toInt();
  156. //var x = count*282;
  157. //var m = (nodeSize.x-x)/2-10;
  158. //
  159. //this.elementContentListNode.setStyles({
  160. // "width": ""+x+"px",
  161. // "margin-left": "" + m + "px"
  162. //});
  163. },
  164. setNodeScroll: function(){
  165. MWF.require("MWF.widget.DragScroll", function(){
  166. new MWF.widget.DragScroll(this.elementContentNode);
  167. }.bind(this));
  168. MWF.require("MWF.widget.ScrollBar", function(){
  169. new MWF.widget.ScrollBar(this.elementContentNode, {"indent": false});
  170. }.bind(this));
  171. },
  172. loadElementList: function( callback ){
  173. this._loadItemDataList(function(json){
  174. if (json.data.length){
  175. json.data.each(function(item){
  176. var itemObj = this._getItemObject(item, this.itemArray.length + 1 );
  177. itemObj.load();
  178. this.itemObject[ item.id ] = itemObj;
  179. this.itemArray.push( itemObj );
  180. }.bind(this));
  181. if( callback )callback();
  182. }else{
  183. var noElementNode = this.noElementNode = new Element("div", {
  184. "styles": this.css.noElementNode,
  185. "text": this.options.tooltip.noElement
  186. }).inject(this.elementContentListNode);
  187. noElementNode.addEvent("click", function(e){
  188. this._createElement(e);
  189. }.bind(this));
  190. }
  191. }.bind(this));
  192. },
  193. showDeleteAction: function(){
  194. if (!this.deleteItemsAction){
  195. this.deleteItemsAction = new Element("div", {
  196. "styles": this.css.deleteItemsAction,
  197. "text": this.app.lp.deleteItems
  198. }).inject(this.node);
  199. this.deleteItemsAction.fade("in");
  200. this.deleteItemsAction.position({
  201. relativeTo: this.elementContentListNode
  202. });
  203. this.deleteItemsAction.setStyle("top","50%");
  204. this.deleteItemsAction.addEvent("click", function(){
  205. var _self = this;
  206. this.app.confirm("warn", this.deleteItemsAction, MWF.CMSCM.LP.deleteElementTitle, MWF.CMSCM.LP.deleteElement, 300, 120, function(){
  207. _self.deleteItems();
  208. this.close();
  209. }, function(){
  210. this.close();
  211. });
  212. }.bind(this));
  213. }
  214. },
  215. hideDeleteAction: function(){
  216. if (this.deleteItemsAction) this.deleteItemsAction.destroy();
  217. delete this.deleteItemsAction;
  218. },
  219. _createElement: function(e){
  220. },
  221. _loadItemDataList: function(callback){
  222. this.app.restActions.listCategory(this.app.options.column.id,callback);
  223. },
  224. _getItemObject: function(item, index){
  225. return MWF.xApplication.cms.ColumnManager.Explorer.Item(this, item, {index : index })
  226. }
  227. });
  228. MWF.xApplication.cms.ColumnManager.Explorer.Item = new Class({
  229. Implements: [Options],
  230. options: {
  231. "where": "bottom",
  232. "index" : 1
  233. },
  234. initialize: function(explorer, item, options ){
  235. this.setOptions(options);
  236. this.explorer = explorer;
  237. this.data = item;
  238. this.container = this.explorer.elementContentListNode;
  239. this.icon = this._getIcon();
  240. },
  241. load: function(){
  242. if( this.options.index % 2 == 0 ){
  243. this.itemNodeCss = this.explorer.css.itemNode_even
  244. }else{
  245. this.itemNodeCss = this.explorer.css.itemNode
  246. }
  247. this.node = new Element("div", {
  248. "styles": this.itemNodeCss,
  249. "events": {
  250. "click": function(e){this._open(e);e.stopPropagation();}.bind(this),
  251. "mouseover": function(){
  252. if( !this.isSelected )this.node.setStyles( this.explorer.css.itemNode_over )
  253. }.bind(this),
  254. "mouseout": function(){
  255. if( !this.isSelected )this.node.setStyles( this.itemNodeCss )
  256. }.bind(this)
  257. }
  258. }).inject(this.container,this.options.where);
  259. if (this.data.icon) this.icon = this.data.icon;
  260. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  261. var itemIconNode = new Element("div", {
  262. "styles": this.explorer.css.itemIconNode
  263. }).inject(this.node);
  264. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  265. //new Element("img", {
  266. // "src": iconUrl, "border": "0"
  267. //}).inject(itemIconNode);
  268. itemIconNode.makeLnk({
  269. "par": this._getLnkPar()
  270. });
  271. itemIconNode.addEvent("click", function(e){
  272. this.toggleSelected();
  273. e.stopPropagation();
  274. }.bind(this));
  275. this.actionsArea = new Element("div.actionsArea",{
  276. styles : this.explorer.css.actionsArea
  277. }).inject(this.node);
  278. this.saveasActionNode = new Element("div", {
  279. "styles": this.explorer.css.saveasActionNode,
  280. "title": this.explorer.app.lp.copy
  281. }).inject(this.actionsArea);
  282. this.saveasActionNode.addEvent("click", function(e){
  283. this.saveas(e);
  284. e.stopPropagation();
  285. }.bind(this));
  286. this.saveasActionNode.addEvents({
  287. "mouseover" : function(ev){
  288. this.saveasActionNode.setStyles( this.explorer.css.saveasActionNode_over )
  289. }.bind(this),
  290. "mouseout" : function(ev){
  291. this.saveasActionNode.setStyles( this.explorer.css.saveasActionNode )
  292. }.bind(this)
  293. });
  294. if (!this.explorer.options.noDelete){
  295. this.deleteActionNode = new Element("div.deleteAction", {
  296. "styles": this.explorer.css.deleteAction
  297. }).inject(this.actionsArea);
  298. this.deleteActionNode.addEvent("click", function(e){
  299. this.deleteItem(e);
  300. e.stopPropagation();
  301. }.bind(this));
  302. this.deleteActionNode.addEvents({
  303. "mouseover" : function(ev){
  304. this.deleteActionNode.setStyles( this.explorer.css.deleteAction_over )
  305. }.bind(this),
  306. "mouseout" : function(ev){
  307. this.deleteActionNode.setStyles( this.explorer.css.deleteAction )
  308. }.bind(this)
  309. })
  310. }
  311. var inforNode = new Element("div.itemInforNode", {
  312. "styles": this.explorer.css.itemInforNode
  313. }).inject(this.node);
  314. var inforBaseNode = new Element("div.itemInforBaseNode", {
  315. "styles": this.explorer.css.itemInforBaseNode
  316. }).inject(inforNode);
  317. new Element("div.itemTextTitleNode", {
  318. "styles": this.explorer.css.itemTextTitleNode,
  319. "text": this.data.name,
  320. "title": this.data.name
  321. }).inject(inforBaseNode);
  322. new Element("div.itemTextAliasNode", {
  323. "styles": this.explorer.css.itemTextAliasNode,
  324. "text": this.data.alias,
  325. "title": this.data.alias
  326. }).inject(inforBaseNode);
  327. new Element("div.itemTextDateNode", {
  328. "styles": this.explorer.css.itemTextDateNode,
  329. "text": (this.data.updateTime || "")
  330. }).inject(inforBaseNode);
  331. new Element("div.itemTextDescriptionNode", {
  332. "styles": this.explorer.css.itemTextDescriptionNode,
  333. "text": this.data.description || "",
  334. "title": this.data.description || ""
  335. }).inject(inforBaseNode);
  336. //new Element("div", {
  337. // "styles": this.explorer.css.itemTextTitleNode,
  338. // "text": this.data.name,
  339. // "title": this.data.name,
  340. // "events": {
  341. // "click": function(e){this._open(e);}.bind(this)
  342. // }
  343. //}).inject(this.node);
  344. //
  345. //new Element("div", {
  346. // "styles": this.explorer.css.itemTextDescriptionNode,
  347. // "text": this.data.description || "",
  348. // "title": this.data.description || ""
  349. //}).inject(this.node);
  350. //
  351. //new Element("div", {
  352. // "styles": this.explorer.css.itemTextDateNode,
  353. // "text": (this.data.updateTime || "")
  354. //}).inject(this.node);
  355. },
  356. deleteItem: function(){
  357. if (!this.deleteMode){
  358. this.deleteMode = true;
  359. this.node.setStyle("background-color", "#ffb7b7");
  360. this.deleteActionNode.setStyle("background-image", "url("+"../x_component_cms_ColumnManager/$Explorer/default/processIcon/deleteProcess_red1.png)");
  361. this.deleteActionNode.removeEvents("mouseover");
  362. this.deleteActionNode.removeEvents("mouseout");
  363. this.node.removeEvents("mouseover");
  364. this.node.removeEvents("mouseout");
  365. this.explorer.deleteMarkItems.push(this);
  366. }else{
  367. this.deleteMode = false;
  368. this.node.setStyle("background", "#FFF");
  369. this.deleteActionNode.setStyles( this.explorer.css.deleteAction );
  370. this.deleteActionNode.addEvents({
  371. "mouseover" : function(ev){
  372. this.deleteActionNode.setStyles( this.explorer.css.deleteAction_over )
  373. }.bind(this),
  374. "mouseout" : function(ev){
  375. this.deleteActionNode.setStyles( this.explorer.css.deleteAction )
  376. }.bind(this)
  377. });
  378. this.node.addEvents({"mouseover": function(){
  379. this.node.setStyles( this.explorer.css.itemNode_over )
  380. }.bind(this),
  381. "mouseout": function(){
  382. this.node.setStyles( this.itemNodeCss )
  383. }.bind(this)
  384. });
  385. this.explorer.deleteMarkItems.erase(this);
  386. }
  387. if (this.explorer.deleteMarkItems.length){
  388. this.explorer.showDeleteAction();
  389. }else{
  390. this.explorer.hideDeleteAction();
  391. }
  392. },
  393. deleteItems: function(){},
  394. _open: function(e){
  395. var _self = this;
  396. var options = {
  397. "onQueryLoad": function(){
  398. this.actions = _self.explorer.actions;
  399. this.category = _self;
  400. this.options.id = _self.data.id;
  401. this.column = _self.explorer.app.options.column;
  402. this.application = _self.explorer.app.options.column;
  403. }
  404. };
  405. this.explorer.app.desktop.openApplication(e, "cms.ProcessDesigner", options);
  406. },
  407. _getIcon: function(){
  408. var x = (Math.random()*33).toInt();
  409. return "process_icon_"+x+".png";
  410. },
  411. _getLnkPar: function(){
  412. return {
  413. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  414. "title": this.data.name,
  415. "par": "ProcessDesigner#{\"id\": \""+this.data.id+"\"}"
  416. };
  417. },
  418. _isNew: function(){
  419. if (this.data.updateTime){
  420. var createDate = Date.parse(this.data.updateTime);
  421. var currentDate = new Date();
  422. if (createDate.diff(currentDate, "hour")<12) {
  423. this.newNode = new Element("div", {
  424. "styles": this.explorer.css.itemNewNode
  425. }).inject(this.node);
  426. }
  427. }
  428. },
  429. toggleSelected: function(){
  430. if (this.isSelected){
  431. this.unSelected();
  432. }else{
  433. this.selected();
  434. }
  435. },
  436. checkShowCopyInfor: function(){
  437. if (this.explorer.selectMarkItems.length===1){
  438. this.explorer.app.notice(this.explorer.app.lp.copyInfor, "infor");
  439. }
  440. },
  441. selected: function(){
  442. if (this.deleteMode) this.deleteItem();
  443. this.isSelected = true;
  444. this.node.setStyles(this.explorer.css.itemNode_selected);
  445. this.explorer.selectMarkItems.push(this);
  446. this.checkShowCopyInfor();
  447. },
  448. unSelected: function(){
  449. this.isSelected = false;
  450. this.node.setStyles(this.explorer.css.itemNode);
  451. this.explorer.selectMarkItems.erase(this);
  452. },
  453. saveas: function(){
  454. MWF.xDesktop.requireApp("Selector", "package", function(){
  455. var app = this.explorer.app.options.application;
  456. app.name = app.appName;
  457. var selector = new MWF.O2Selector(this.explorer.app.content, {
  458. "title": this.explorer.app.lp.copyto,
  459. "type": "CMSApplication",
  460. "values": [app],
  461. "onComplete": function(items){
  462. items.each(function(item){
  463. this.saveItemAs(item.data);
  464. }.bind(this));
  465. }.bind(this),
  466. });
  467. }.bind(this));
  468. }
  469. });