Explorer.js 14 KB

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