Explorer.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.APPPM = MWF.xApplication.process.ProcessManager = MWF.xApplication.process.ProcessManager || {};
  3. MWF.xDesktop.requireApp("process.ProcessManager", "lp."+MWF.language, null, false);
  4. MWF.xApplication.process.ProcessManager.Explorer = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "tooltip": {
  10. "create": MWF.APPPM.LP.process.create,
  11. "search": MWF.APPPM.LP.process.search,
  12. "searchText": MWF.APPPM.LP.process.searchText,
  13. "noElement": MWF.APPPM.LP.process.noProcessNoticeText
  14. }
  15. },
  16. initialize: function(node, actions, options){
  17. this.setOptions(options);
  18. this.setTooltip();
  19. this.path = "/x_component_process_ProcessManager/$Explorer/";
  20. this.cssPath = "/x_component_process_ProcessManager/$Explorer/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.actions = actions;
  23. this.node = $(node);
  24. this.initData();
  25. },
  26. setTooltip: function(tooltip){
  27. if (tooltip) this.options.tooltip = Object.merge(this.options.tooltip, tooltip);
  28. },
  29. initData: function(){
  30. //this.categoryLoadFirst = true;
  31. //this.isLoaddingCategory = false;
  32. //this.categoryLoaded = false;
  33. //this.categorys = [];
  34. //this.dragItem = false;
  35. //this.dragCategory = false;
  36. //this.currentCategory = null;
  37. //this.loadCategoryQueue = 0;
  38. this.deleteMarkItems = [];
  39. },
  40. reload: function(){
  41. this.node.empty();
  42. this.load();
  43. },
  44. load: function(){
  45. this.loadToolbar();
  46. this.loadContentNode();
  47. this.setNodeScroll();
  48. this.loadElementList();
  49. },
  50. loadToolbar: function(){
  51. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode});
  52. this.createCreateElementNode();
  53. this.createIconElementNode();
  54. this.createTitleElementNode();
  55. this.createSearchElementNode();
  56. this.toolbarNode.inject(this.node);
  57. },
  58. createIconElementNode: function(){
  59. this.iconElementNode = new Element("div", {
  60. "styles": this.css.iconElementNode
  61. }).inject(this.toolbarNode);
  62. if (this.app.options.application){
  63. if (this.app.options.application.icon){
  64. this.iconElementNode.setStyle("background-image", "url(data:image/png;base64,"+this.app.options.application.icon+")");
  65. }else{
  66. this.iconElementNode.setStyle("background-image", "url("+"/x_component_process_ApplicationExplorer/$Main/default/icon/application.png)");
  67. }
  68. }
  69. },
  70. createCreateElementNode: function(){
  71. this.createElementNode = new Element("div", {
  72. "styles": this.css.createElementNode,
  73. "title": this.options.tooltip.create
  74. }).inject(this.toolbarNode);
  75. this.createElementNode.addEvent("click", function(e){
  76. this._createElement(e);
  77. }.bind(this));
  78. },
  79. createTitleElementNode: function() {
  80. this.titleElementNode = new Element("div", {
  81. "styles": this.css.titleElementNode,
  82. "text": this.app.options.application.name
  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", {"styles": this.css.searchElementButtonNode,"title": this.options.tooltip.search}).inject(this.searchElementNode);
  92. //
  93. //this.searchElementInputAreaNode = new Element("div", {
  94. // "styles": this.css.searchElementInputAreaNode
  95. //}).inject(this.searchElementNode);
  96. //
  97. //this.searchElementInputBoxNode = new Element("div", {
  98. // "styles": this.css.searchElementInputBoxNode
  99. //}).inject(this.searchElementInputAreaNode);
  100. //
  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.getSize();
  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 count = (nodeSize.x/282).toInt();
  151. var x = count*282;
  152. var m = (nodeSize.x-x)/2-10;
  153. this.elementContentListNode.setStyles({
  154. "width": ""+x+"px",
  155. "margin-left": "" + m + "px"
  156. });
  157. },
  158. setNodeScroll: function(){
  159. MWF.require("MWF.widget.DragScroll", function(){
  160. new MWF.widget.DragScroll(this.elementContentNode);
  161. }.bind(this));
  162. MWF.require("MWF.widget.ScrollBar", function(){
  163. new MWF.widget.ScrollBar(this.elementContentNode, {"indent": false});
  164. }.bind(this));
  165. },
  166. loadElementList: function(){
  167. this._loadItemDataList(function(json){
  168. if (json.data.length){
  169. json.data.each(function(item){
  170. var itemObj = this._getItemObject(item);
  171. itemObj.load()
  172. }.bind(this));
  173. }else{
  174. var noElementNode = new Element("div", {
  175. "styles": this.css.noElementNode,
  176. "text": this.options.tooltip.noElement
  177. }).inject(this.elementContentListNode);
  178. noElementNode.addEvent("click", function(e){
  179. this._createElement(e);
  180. }.bind(this));
  181. }
  182. }.bind(this));
  183. },
  184. showDeleteAction: function(){
  185. if (!this.deleteItemsAction){
  186. this.deleteItemsAction = new Element("div", {
  187. "styles": this.css.deleteItemsAction,
  188. "text": this.app.lp.deleteItems
  189. }).inject(this.node);
  190. this.deleteItemsAction.fade("in");
  191. this.deleteItemsAction.position({
  192. relativeTo: this.elementContentListNode,
  193. position: 'centerTop',
  194. edge: 'centerTop'
  195. });
  196. this.deleteItemsAction.addEvent("click", function(){
  197. var _self = this;
  198. this.app.confirm("warn", this.deleteItemsAction, MWF.APPPM.LP.deleteElementTitle, MWF.APPPM.LP.deleteElement, 300, 120, function(){
  199. _self.deleteItems();
  200. this.close();
  201. }, function(){
  202. this.close();
  203. });
  204. }.bind(this));
  205. }
  206. },
  207. hideDeleteAction: function(){
  208. if (this.deleteItemsAction) this.deleteItemsAction.destroy();
  209. delete this.deleteItemsAction;
  210. },
  211. _createElement: function(e){
  212. },
  213. _loadItemDataList: function(callback){
  214. this.app.restActions.listProcess(this.app.options.application.id,callback);
  215. },
  216. _getItemObject: function(item){
  217. return MWF.xApplication.process.ProcessManager.Explorer.Item(this, item)
  218. }
  219. });
  220. MWF.xApplication.process.ProcessManager.Explorer.Item = new Class({
  221. initialize: function(explorer, item){
  222. this.explorer = explorer;
  223. this.data = item;
  224. this.container = this.explorer.elementContentListNode;
  225. this.css = this.explorer.css;
  226. this.icon = this._getIcon();
  227. },
  228. load: function(){
  229. this.createNode();
  230. this.createIconNode();
  231. this.createDeleteNode();
  232. this.createTextNodes();
  233. this._isNew();
  234. },
  235. createNode: function(){
  236. this.node = new Element("div", {
  237. "styles": this.css.itemNode,
  238. "events": {
  239. "mouseover": function(){this.deleteActionNode.fade("in");}.bind(this),
  240. "mouseout": function(){this.deleteActionNode.fade("out");}.bind(this)
  241. }
  242. }).inject(this.container);
  243. },
  244. createIconNode: function(){
  245. if (this.data.icon) this.icon = this.data.icon.substr(this.data.icon.lastIndexOf("/")+1, this.data.icon.length);
  246. //if (this.data.name.icon) this.icon = this.data.name.icon;
  247. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  248. var itemIconNode = new Element("div", {
  249. "styles": this.css.itemIconNode
  250. }).inject(this.node);
  251. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  252. itemIconNode.makeLnk({
  253. "par": this._getLnkPar()
  254. });
  255. },
  256. createDeleteNode: function(){
  257. this.deleteActionNode = new Element("div", {
  258. "styles": this.css.deleteActionNode
  259. }).inject(this.node);
  260. this.deleteActionNode.addEvent("click", function(e){
  261. this.deleteItem(e);
  262. }.bind(this));
  263. },
  264. createTextNodes: function(){
  265. new Element("div", {
  266. "styles": this.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.css.itemTextDescriptionNode,
  275. "text": this.data.description || "",
  276. "title": this.data.description || ""
  277. }).inject(this.node);
  278. new Element("div", {
  279. "styles": this.css.itemTextDateNode,
  280. "text": (this.data.updateTime || "")
  281. }).inject(this.node);
  282. },
  283. deleteItem: function(){
  284. if (!this.deleteMode){
  285. this.deleteMode = true;
  286. this.node.setStyle("background-color", "#ffb7b7");
  287. this.deleteActionNode.setStyle("background-image", "url("+"/x_component_process_ProcessManager/$Explorer/default/processIcon/deleteProcess_red1.png)");
  288. this.node.removeEvents("mouseover");
  289. this.node.removeEvents("mouseout");
  290. this.explorer.deleteMarkItems.push(this);
  291. }else{
  292. this.deleteMode = false;
  293. this.node.setStyle("background", "#FFF");
  294. this.deleteActionNode.setStyle("background-image", "url("+"/x_component_process_ProcessManager/$Explorer/default/processIcon/deleteProcess.png)");
  295. this.node.addEvents({
  296. "mouseover": function(){this.deleteActionNode.fade("in");}.bind(this),
  297. "mouseout": function(){this.deleteActionNode.fade("out");}.bind(this)
  298. });
  299. this.explorer.deleteMarkItems.erase(this);
  300. }
  301. if (this.explorer.deleteMarkItems.length){
  302. this.explorer.showDeleteAction();
  303. }else{
  304. this.explorer.hideDeleteAction();
  305. }
  306. },
  307. deleteItems: function(){},
  308. _open: function(e){
  309. var _self = this;
  310. var options = {
  311. "onQueryLoad": function(){
  312. this.actions = _self.explorer.actions;
  313. this.category = _self;
  314. this.options.id = _self.data.id;
  315. this.application = _self.explorer.app.options.application;
  316. }
  317. };
  318. this.explorer.app.desktop.openApplication(e, "process.ProcessDesigner", options);
  319. },
  320. _getIcon: function(){
  321. var x = (Math.random()*49).toInt();
  322. return "process_icon_"+x+".png";
  323. },
  324. _getLnkPar: function(){
  325. return {
  326. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  327. "title": this.data.name,
  328. "par": "ProcessDesigner#{\"id\": \""+this.data.id+"\"}"
  329. };
  330. },
  331. _isNew: function(){
  332. if (this.data.updateTime){
  333. var createDate = Date.parse(this.data.updateTime);
  334. var currentDate = new Date();
  335. if (createDate.diff(currentDate, "hour")<12) {
  336. this.newNode = new Element("div", {
  337. "styles": this.css.itemNewNode
  338. }).inject(this.node);
  339. }
  340. }
  341. }
  342. });