Explorer.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. "tooltip": {
  11. "create": MWF.CMSCM.LP.category.create,
  12. "search": MWF.CMSCM.LP.category.search,
  13. "searchText": MWF.CMSCM.LP.category.searchText,
  14. "noElement": MWF.CMSCM.LP.category.noCategoryNoticeText
  15. }
  16. },
  17. initialize: function(node, actions, options){
  18. this.setOptions(options);
  19. this.setTooltip();
  20. this.path = "/x_component_cms_ColumnManager/$Explorer/";
  21. this.cssPath = "/x_component_cms_ColumnManager/$Explorer/"+this.options.style+"/css.wcss";
  22. this._loadCss();
  23. this.actions = actions;
  24. this.node = $(node);
  25. this.initData();
  26. },
  27. setTooltip: function(tooltip){
  28. if (tooltip) this.options.tooltip = Object.merge(this.options.tooltip, tooltip);
  29. },
  30. initData: function(){
  31. //this.categoryLoadFirst = true;
  32. //this.isLoaddingCategory = false;
  33. //this.categoryLoaded = false;
  34. //this.categorys = [];
  35. //this.dragItem = false;
  36. //this.dragCategory = false;
  37. //this.currentCategory = null;
  38. //this.loadCategoryQueue = 0;
  39. this.itemArray = [];
  40. this.itemObject = {};
  41. this.deleteMarkItems = [];
  42. },
  43. reload: function(){
  44. this.initData();
  45. this.node.empty();
  46. this.load();
  47. },
  48. load: function(){
  49. this.loadToolbar();
  50. this.loadContentNode();
  51. this.setNodeScroll();
  52. this.loadElementList();
  53. },
  54. loadToolbar: function(){
  55. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode});
  56. this.createCreateElementNode();
  57. this.createIconElementNode();
  58. this.createTitleElementNode();
  59. this.createSearchElementNode();
  60. this.toolbarNode.inject(this.node);
  61. },
  62. createIconElementNode: function(){
  63. this.iconElementNode = new Element("div", {
  64. "styles": this.css.iconElementNode
  65. }).inject(this.toolbarNode);
  66. if (this.app.options.column){
  67. var icon = this.app.options.column.icon || this.app.options.column.appIcon;
  68. if (icon){
  69. this.iconElementNode.setStyle("background-image", "url(data:image/png;base64,"+icon+")");
  70. }else{
  71. this.iconElementNode.setStyle("background-image", "url("+"/x_component_cms_Column/$Main/default/icon/column.png)");
  72. }
  73. }
  74. },
  75. createCreateElementNode: function(){
  76. this.createElementNode = new Element("div", {
  77. "styles": this.css.createElementNode,
  78. "title": this.options.tooltip.create
  79. }).inject(this.toolbarNode);
  80. this.createElementNode.addEvent("click", function(e){
  81. this._createElement(e);
  82. }.bind(this));
  83. },
  84. createTitleElementNode: function() {
  85. this.titleElementNode = new Element("div", {
  86. "styles": this.css.titleElementNode,
  87. "text": this.app.options.column.name || this.app.options.column.appName
  88. }).inject(this.toolbarNode);
  89. },
  90. createSearchElementNode: function(){
  91. this.searchElementNode = new Element("div", {
  92. "styles": this.css.searchElementNode
  93. }).inject(this.toolbarNode);
  94. //@todo
  95. return false
  96. this.searchElementButtonNode = new Element("div", {
  97. "styles": this.css.searchElementButtonNode,
  98. "title": this.options.tooltip.search
  99. }).inject(this.searchElementNode);
  100. this.searchElementInputAreaNode = new Element("div", {
  101. "styles": this.css.searchElementInputAreaNode
  102. }).inject(this.searchElementNode);
  103. this.searchElementInputBoxNode = new Element("div", {
  104. "styles": this.css.searchElementInputBoxNode
  105. }).inject(this.searchElementInputAreaNode);
  106. this.searchElementInputNode = new Element("input", {
  107. "type": "text",
  108. "value": this.options.tooltip.searchText,
  109. "styles": this.css.searchElementInputNode,
  110. "x-webkit-speech": "1"
  111. }).inject(this.searchElementInputBoxNode);
  112. var _self = this;
  113. this.searchElementInputNode.addEvents({
  114. "focus": function(){
  115. if (this.value==_self.options.tooltip.searchText) this.set("value", "");
  116. },
  117. "blur": function(){if (!this.value) this.set("value", _self.options.tooltip.searchText);},
  118. "keydown": function(e){
  119. if (e.code==13){
  120. this.searchElement();
  121. e.preventDefault();
  122. }
  123. }.bind(this),
  124. "selectstart": function(e){
  125. e.preventDefault();
  126. }
  127. });
  128. this.searchElementButtonNode.addEvent("click", function(){this.searchElement();}.bind(this));
  129. },
  130. searchElement: function(){
  131. //-----------------------------------------
  132. //-----------------------------------------
  133. //-----search category---------------------
  134. //-----------------------------------------
  135. //-----------------------------------------
  136. alert("search Element");
  137. },
  138. loadContentNode: function(){
  139. this.elementContentNode = new Element("div", {
  140. "styles": this.css.elementContentNode
  141. }).inject(this.node);
  142. this.elementContentListNode = new Element("div", {
  143. "styles": this.css.elementContentListNode
  144. }).inject(this.elementContentNode);
  145. this.setContentSize();
  146. this.app.addEvent("resize", function(){this.setContentSize();}.bind(this));
  147. },
  148. setContentSize: function(){
  149. var toolbarSize = this.toolbarNode ? this.toolbarNode.getSize() : { x : 0 , y : 0 };
  150. var nodeSize = this.node.getSize();
  151. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  152. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  153. var height = nodeSize.y-toolbarSize.y-pt-pb;
  154. this.elementContentNode.setStyle("height", ""+height+"px");
  155. var count = (nodeSize.x/282).toInt();
  156. var x = count*282;
  157. var m = (nodeSize.x-x)/2-10;
  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(){
  172. this._loadItemDataList(function(json){
  173. if (json.data.length){
  174. json.data.each(function(item){
  175. var itemObj = this._getItemObject(item);
  176. itemObj.load()
  177. this.itemObject[ item.id ] = itemObj;
  178. this.itemArray.push( itemObj );
  179. }.bind(this));
  180. }else{
  181. var noElementNode = this.noElementNode = new Element("div", {
  182. "styles": this.css.noElementNode,
  183. "text": this.options.tooltip.noElement
  184. }).inject(this.elementContentListNode);
  185. noElementNode.addEvent("click", function(e){
  186. this._createElement(e);
  187. }.bind(this));
  188. }
  189. }.bind(this));
  190. },
  191. showDeleteAction: function(){
  192. if (!this.deleteItemsAction){
  193. this.deleteItemsAction = new Element("div", {
  194. "styles": this.css.deleteItemsAction,
  195. "text": this.app.lp.deleteItems
  196. }).inject(this.node);
  197. this.deleteItemsAction.fade("in");
  198. this.deleteItemsAction.position({
  199. relativeTo: this.elementContentListNode,
  200. position: 'centerTop',
  201. edge: 'centerTop'
  202. });
  203. this.deleteItemsAction.addEvent("click", function(){
  204. var _self = this;
  205. this.app.confirm("warn", this.deleteItemsAction, MWF.CMSCM.LP.deleteElementTitle, MWF.CMSCM.LP.deleteElement, 300, 120, function(){
  206. _self.deleteItems();
  207. this.close();
  208. }, function(){
  209. this.close();
  210. });
  211. }.bind(this));
  212. }
  213. },
  214. hideDeleteAction: function(){
  215. if (this.deleteItemsAction) this.deleteItemsAction.destroy();
  216. delete this.deleteItemsAction;
  217. },
  218. _createElement: function(e){
  219. },
  220. _loadItemDataList: function(callback){
  221. this.app.restActions.listCategory(this.app.options.column.id,callback);
  222. },
  223. _getItemObject: function(item){
  224. return MWF.xApplication.cms.ColumnManager.Explorer.Item(this, item)
  225. }
  226. });
  227. MWF.xApplication.cms.ColumnManager.Explorer.Item = new Class({
  228. Implements: [Options],
  229. options: {
  230. "where": "bottom"
  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. this.node = new Element("div", {
  241. "styles": this.explorer.css.itemNode,
  242. "events": {
  243. "mouseover": function(){this.deleteActionNode.fade("in");}.bind(this),
  244. "mouseout": function(){this.deleteActionNode.fade("out");}.bind(this)
  245. }
  246. }).inject(this.container,this.options.where);
  247. if (this.data.icon) this.icon = this.data.icon;
  248. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  249. var itemIconNode = new Element("div", {
  250. "styles": this.explorer.css.itemIconNode
  251. }).inject(this.node);
  252. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  253. //new Element("img", {
  254. // "src": iconUrl, "border": "0"
  255. //}).inject(itemIconNode);
  256. itemIconNode.makeLnk({
  257. "par": this._getLnkPar()
  258. });
  259. this.deleteActionNode = new Element("div", {
  260. "styles": this.explorer.css.deleteActionNode
  261. }).inject(this.node);
  262. this.deleteActionNode.addEvent("click", function(e){
  263. this.deleteItem(e);
  264. }.bind(this));
  265. new Element("div", {
  266. "styles": this.explorer.css.itemTextTitleNode,
  267. "text": this.data.name,
  268. "title": this.data.name,
  269. "events": {
  270. "click": function(e){this._open(e);}.bind(this)
  271. }
  272. }).inject(this.node);
  273. new Element("div", {
  274. "styles": this.explorer.css.itemTextDescriptionNode,
  275. "text": this.data.description || "",
  276. "title": this.data.description || ""
  277. }).inject(this.node);
  278. new Element("div", {
  279. "styles": this.explorer.css.itemTextDateNode,
  280. "text": (this.data.updateTime || "")
  281. }).inject(this.node);
  282. this._isNew();
  283. },
  284. deleteItem: function(){
  285. if (!this.deleteMode){
  286. this.deleteMode = true;
  287. this.node.setStyle("background-color", "#ffb7b7");
  288. this.deleteActionNode.setStyle("background-image", "url("+"/x_component_cms_ColumnManager/$Explorer/default/processIcon/deleteProcess_red1.png)");
  289. this.node.removeEvents("mouseover");
  290. this.node.removeEvents("mouseout");
  291. this.explorer.deleteMarkItems.push(this);
  292. }else{
  293. this.deleteMode = false;
  294. this.node.setStyle("background", "#FFF");
  295. this.deleteActionNode.setStyle("background-image", "url("+"/x_component_cms_ColumnManager/$Explorer/default/processIcon/deleteProcess.png)");
  296. this.node.addEvents({
  297. "mouseover": function(){this.deleteActionNode.fade("in");}.bind(this),
  298. "mouseout": function(){this.deleteActionNode.fade("out");}.bind(this)
  299. });
  300. this.explorer.deleteMarkItems.erase(this);
  301. }
  302. if (this.explorer.deleteMarkItems.length){
  303. this.explorer.showDeleteAction();
  304. }else{
  305. this.explorer.hideDeleteAction();
  306. }
  307. },
  308. deleteItems: function(){},
  309. _open: function(e){
  310. var _self = this;
  311. var options = {
  312. "onQueryLoad": function(){
  313. this.actions = _self.explorer.actions;
  314. this.category = _self;
  315. this.options.id = _self.data.id;
  316. this.column = _self.explorer.app.options.column;
  317. this.application = _self.explorer.app.options.column;
  318. }
  319. };
  320. this.explorer.app.desktop.openApplication(e, "cms.ProcessDesigner", options);
  321. },
  322. _getIcon: function(){
  323. var x = (Math.random()*33).toInt();
  324. return "process_icon_"+x+".png";
  325. },
  326. _getLnkPar: function(){
  327. return {
  328. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  329. "title": this.data.name,
  330. "par": "ProcessDesigner#{\"id\": \""+this.data.id+"\"}"
  331. };
  332. },
  333. _isNew: function(){
  334. if (this.data.updateTime){
  335. var createDate = Date.parse(this.data.updateTime);
  336. var currentDate = new Date();
  337. if (createDate.diff(currentDate, "hour")<12) {
  338. this.newNode = new Element("div", {
  339. "styles": this.explorer.css.itemNewNode
  340. }).inject(this.node);
  341. }
  342. }
  343. }
  344. });