DictionaryExplorer.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. MWF.xDesktop.requireApp("process.ProcessManager", "Explorer", null, false);
  2. MWF.xApplication.process.ProcessManager.DictionaryExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.Explorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "create": MWF.APPPM.LP.dictionary.create,
  7. "search": MWF.APPPM.LP.dictionary.search,
  8. "searchText": MWF.APPPM.LP.dictionary.searchText,
  9. "noElement": MWF.APPPM.LP.dictionary.noDictionaryNoticeText
  10. },
  11. initialize: function(node, actions, options){
  12. this.setOptions(options);
  13. this.setTooltip();
  14. this.path = "../x_component_process_ProcessManager/$DictionaryExplorer/";
  15. this.cssPath = "../x_component_process_ProcessManager/$DictionaryExplorer/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.actions = actions;
  18. this.node = $(node);
  19. this.initData();
  20. },
  21. setContentSize: function(){
  22. var toolbarSize = this.toolbarNode.getSize();
  23. var nodeSize = this.node.getSize();
  24. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  25. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  26. var height = nodeSize.y-toolbarSize.y-pt-pb;
  27. this.elementContentNode.setStyle("height", ""+height+"px");
  28. if (this.options.noCreate) this.createElementNode.destroy();
  29. },
  30. showDeleteAction: function(){
  31. if (!this.deleteItemsAction){
  32. this.deleteItemsAction = new Element("div", {
  33. "styles": this.css.deleteItemsAction,
  34. "text": this.app.lp.deleteItems
  35. }).inject(this.node);
  36. this.deleteItemsAction.fade("in");
  37. this.deleteItemsAction.position({
  38. relativeTo: this.elementContentListNode,
  39. position: 'centerTop',
  40. edge: 'centerTop',
  41. "offset": {"y": this.elementContentNode.getScroll().y}
  42. });
  43. this.deleteItemsAction.addEvent("click", function(){
  44. var _self = this;
  45. this.app.confirm("warn", this.deleteItemsAction, MWF.APPPM.LP.deleteElementTitle, MWF.APPPM.LP.deleteElement, 300, 120, function(){
  46. _self.deleteItems();
  47. this.close();
  48. }, function(){
  49. this.close();
  50. });
  51. }.bind(this));
  52. }
  53. },
  54. keyCopy: function(e){
  55. if (this.selectMarkItems.length){
  56. var items = [];
  57. var i = 0;
  58. var checkItems = function(e){
  59. if (i>=this.selectMarkItems.length){
  60. if (items.length){
  61. var str = JSON.encode(items);
  62. if (e){
  63. e.clipboardData.setData('text/plain', str);
  64. }else {
  65. window.clipboardData.setData("Text", str);
  66. }
  67. this.app.notice(this.app.lp.copyed, "success");
  68. }
  69. }
  70. }.bind(this);
  71. this.selectMarkItems.each(function(item){
  72. this.app.restActions.getDictionary(item.data.id, function(json){
  73. json.data.elementType = "dictionary";
  74. items.push(json.data);
  75. i++;
  76. checkItems(e);
  77. }.bind(this), null, false)
  78. }.bind(this));
  79. if (e) e.preventDefault();
  80. }
  81. },
  82. keyPaste: function(e){
  83. var dataStr = "";
  84. if (e){
  85. dataStr = e.clipboardData.getData('text/plain');
  86. }else{
  87. dataStr = window.clipboardData.getData("Text");
  88. }
  89. var data = JSON.decode(dataStr);
  90. this.pasteItem(data, 0);
  91. // data.each(function(item){
  92. // if (item.elementType==="dictionary"){
  93. // this.saveItemAs(this.app.options.application, item);
  94. // }
  95. // }.bind(this));
  96. },
  97. pasteItem: function(data, i){
  98. if (i<data.length){
  99. var item = data[i];
  100. if (item.elementType==="dictionary"){
  101. this.saveItemAs(item, function(){
  102. i++;
  103. this.pasteItem(data, i);
  104. }.bind(this), function(){
  105. i++;
  106. this.pasteItem(data, i);
  107. }.bind(this), function(){
  108. this.reload();
  109. }.bind(this));
  110. }else{
  111. i++;
  112. this.pasteItem(data, i);
  113. }
  114. }else{
  115. this.reload();
  116. }
  117. },
  118. saveItemAs: function(data, success, failure, cancel){
  119. this.app.restActions.listDictionary(this.app.options.application.id, function(dJson){
  120. var i=1;
  121. var someItems = dJson.data.filter(function(d){ return d.id===data.id });
  122. if (someItems.length){
  123. var someItem = someItems[0];
  124. var lp = this.app.lp;
  125. var _self = this;
  126. var d1 = new Date().parse(data.updateTime);
  127. var d2 = new Date().parse(someItem.updateTime);
  128. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  129. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'><div style='font-weight: bold; font-size:14px;'>"+lp.copySource+" "+someItem.name+"</div>";
  130. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.updateTime+"</div>" +
  131. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'></div>" +
  132. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  133. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'><div style='clear: both;font-weight: bold; font-size:14px;'>"+lp.copyTarget+" "+data.name+"</div>";
  134. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.updateTime+"</div>" +
  135. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'></div>" +
  136. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  137. // html += "<>"
  138. this.app.dlg("inofr", null, this.app.lp.copyConfirmTitle, {"html": html}, 500, 290, [
  139. {
  140. "text": lp.copyConfirm_overwrite,
  141. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  142. },
  143. {
  144. "text": lp.copyConfirm_new,
  145. "action": function(){_self.saveItemAsNew(dJson, data, success, failure);this.close();}
  146. },
  147. {
  148. "text": lp.copyConfirm_skip,
  149. "action": function(){/*nothing*/ this.close(); if (success) success();}
  150. },
  151. {
  152. "text": lp.copyConfirm_cancel,
  153. "action": function(){this.close(); if (cancel) cancel();}
  154. }
  155. ]);
  156. }else{
  157. this.saveItemAsNew(dJson, data, success, failure)
  158. }
  159. }.bind(this), function(){if (failure) failure();}.bind(this));
  160. },
  161. saveItemAsUpdate: function(someItem, data, success, failure){
  162. data.id = someItem.id;
  163. data.application = someItem.application;
  164. data.applicationName = someItem.applicationName;
  165. data.name = someItem.name;
  166. data.alias = someItem.alias;
  167. this.app.restActions.saveDictionary(data, function(){
  168. if (success) success();
  169. }.bind(this), function(){
  170. if (failure) failure();
  171. }.bind(this));
  172. },
  173. saveItemAsNew: function(dJson, data, success, failure){
  174. var item = this.app.options.application;
  175. var id = item.id;
  176. var name = item.name;
  177. var oldName = data.name;
  178. var i=1;
  179. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  180. data.name = oldName+"_copy"+i;
  181. data.alias = oldName+"_copy"+i;
  182. i++;
  183. }
  184. data.id = "";
  185. data.application = id;
  186. data.applicationName = name;
  187. this.app.restActions.saveDictionary(data, function(){
  188. if (success) success();
  189. }.bind(this), function(){
  190. if (failure) failure();
  191. }.bind(this));
  192. },
  193. _createElement: function(e){
  194. var _self = this;
  195. var options = {
  196. "onQueryLoad": function(){
  197. this.actions = _self.app.restActions;
  198. this.application = _self.app.options.application;
  199. this.explorer = _self;
  200. }
  201. };
  202. this.app.desktop.openApplication(e, "process.DictionaryDesigner", options);
  203. },
  204. _loadItemDataList: function(callback){
  205. this.actions.listDictionary(this.app.options.application.id,callback, function () {
  206. }.bind(this));
  207. },
  208. _getItemObject: function(item){
  209. return new MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary(this, item)
  210. },
  211. setTooltip: function(){
  212. this.options.tooltip = {
  213. "create": MWF.APPPM.LP.dictionary.create,
  214. "search": MWF.APPPM.LP.dictionary.search,
  215. "searchText": MWF.APPPM.LP.dictionary.searchText,
  216. "noElement": MWF.APPPM.LP.dictionary.noDictionaryNoticeText
  217. };
  218. },
  219. loadElementList: function(){
  220. this._loadItemDataList(function(json){
  221. if (json.data.length){
  222. json.data.each(function(item){
  223. var itemObj = this._getItemObject(item);
  224. itemObj.load()
  225. }.bind(this));
  226. }else{
  227. var noElementNode = new Element("div.noElementNode", {
  228. "styles": this.css.noElementNode,
  229. "text": (this.options.noCreate) ? MWF.APPPM.LP.dictionary.noDictionaryNoCreateNoticeText : this.options.noElement
  230. }).inject(this.elementContentListNode);
  231. if (!this.options.noCreate){
  232. noElementNode.addEvent("click", function(e){
  233. this._createElement(e);
  234. }.bind(this));
  235. }
  236. }
  237. }.bind(this));
  238. },
  239. deleteItems: function(){
  240. this.hideDeleteAction();
  241. while (this.deleteMarkItems.length){
  242. var item = this.deleteMarkItems.shift();
  243. if (this.deleteMarkItems.length){
  244. item.deleteDictionary();
  245. }else{
  246. item.deleteDictionary(function(){
  247. // this.reloadItems();
  248. // this.hideDeleteAction();
  249. }.bind(this));
  250. }
  251. }
  252. }
  253. });
  254. MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary = new Class({
  255. Extends: MWF.xApplication.process.ProcessManager.Explorer.Item,
  256. load: function(){
  257. this.node = new Element("div", {
  258. "styles": this.explorer.css.itemNode,
  259. "events": {
  260. "mouseover": function(){
  261. if (this.deleteActionNode) this.deleteActionNode.fade("in");
  262. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  263. }.bind(this),
  264. "mouseout": function(){
  265. if (this.deleteActionNode) this.deleteActionNode.fade("out");
  266. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  267. }.bind(this)
  268. }
  269. }).inject(this.container);
  270. if (this.data.name.icon) this.icon = this.data.name.icon;
  271. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  272. var itemIconNode = new Element("div", {
  273. "styles": this.explorer.css.itemIconNode
  274. }).inject(this.node);
  275. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  276. //new Element("img", {
  277. // "src": iconUrl, "border": "0"
  278. //}).inject(itemIconNode);
  279. itemIconNode.addEvent("click", function(e){
  280. this.toggleSelected();
  281. e.stopPropagation();
  282. }.bind(this));
  283. itemIconNode.makeLnk({
  284. "par": this._getLnkPar()
  285. });
  286. if (!this.explorer.options.noDelete){
  287. this._createActions();
  288. }
  289. var inforNode = new Element("div", {
  290. "styles": this.explorer.css.itemInforNode
  291. }).inject(this.node);
  292. var inforBaseNode = new Element("div", {
  293. "styles": this.explorer.css.itemInforBaseNode
  294. }).inject(inforNode);
  295. new Element("div", {
  296. "styles": this.explorer.css.itemTextTitleNode,
  297. "text": this.data.name,
  298. "title": this.data.name,
  299. "events": {
  300. "click": function(e){this._open(e);e.stopPropagation();}.bind(this)
  301. }
  302. }).inject(inforBaseNode);
  303. new Element("div", {
  304. "styles": this.explorer.css.itemTextAliasNode,
  305. "text": this.data.alias,
  306. "title": this.data.alias
  307. }).inject(inforBaseNode);
  308. new Element("div", {
  309. "styles": this.explorer.css.itemTextDateNode,
  310. "text": (this.data.updateTime || "")
  311. }).inject(inforBaseNode);
  312. new Element("div", {
  313. "styles": this.explorer.css.itemTextDescriptionNode,
  314. "text": this.data.description || "",
  315. "title": this.data.description || ""
  316. }).inject(inforNode);
  317. this._customNodes();
  318. this._isNew();
  319. },
  320. _createActions: function(){
  321. this.deleteActionNode = new Element("div", {
  322. "styles": this.explorer.css.deleteActionNode
  323. }).inject(this.node);
  324. this.deleteActionNode.addEvent("click", function(e){
  325. this.deleteItem(e);
  326. }.bind(this));
  327. this.saveasActionNode = new Element("div", {
  328. "styles": this.css.saveasActionNode,
  329. "title": this.explorer.app.lp.copy
  330. }).inject(this.node);
  331. this.saveasActionNode.addEvent("click", function(e){
  332. this.saveas(e);
  333. }.bind(this));
  334. },
  335. _customNodes: function(){},
  336. _open: function(e){
  337. var _self = this;
  338. var options = {
  339. "appId": "process.DictionaryDesigner"+_self.data.id,
  340. "onQueryLoad": function(){
  341. this.actions = _self.explorer.actions;
  342. this.category = _self;
  343. this.options.id = _self.data.id;
  344. this.application = _self.explorer.app.options.application;
  345. this.options.noModifyName = _self.explorer.options.noModifyName;
  346. this.options.readMode = _self.explorer.options.readMode;
  347. this.explorer = _self.explorer;
  348. }
  349. };
  350. this.explorer.app.desktop.openApplication(e, "process.DictionaryDesigner", options);
  351. },
  352. _getIcon: function(){
  353. //var x = (Math.random()*33).toInt();
  354. //return "process_icon_"+x+".png";
  355. return "dictionary.png";
  356. },
  357. _getLnkPar: function(){
  358. return {
  359. "icon": this.explorer.path+this.explorer.options.style+"/dictionaryIcon/lnk.png",
  360. "title": this.data.name,
  361. "par": "process.DictionaryDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.explorer.app.options.application.id+"\"}"
  362. };
  363. },
  364. // deleteItem: function(e){
  365. // var _self = this;
  366. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  367. // _self.deleteForm();
  368. // this.close();
  369. // },function(){
  370. // this.close();
  371. // });
  372. // },
  373. deleteDictionary: function(callback){
  374. this.explorer.app.restActions.deleteDictionary(this.data.id, function(){
  375. this.node.destroy();
  376. if (callback) callback();
  377. }.bind(this));
  378. },
  379. saveItemAs: function(item){
  380. var id = item.id;
  381. var name = item.name;
  382. this.explorer.app.restActions.getDictionary(this.data.id, function(json){
  383. var data = json.data;
  384. var oldName = data.name;
  385. this.explorer.app.restActions.listDictionary(id, function(dJson){
  386. var i=1;
  387. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  388. data.name = oldName+"_copy"+i;
  389. data.alias = oldName+"_copy"+i;
  390. i++;
  391. }
  392. data.id = "";
  393. data.application = id;
  394. data.applicationName = name;
  395. this.explorer.app.restActions.saveDictionary(data, function(){
  396. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  397. }.bind(this));
  398. }.bind(this));
  399. }.bind(this));
  400. }
  401. });