Explorer.js 16 KB

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