DictionaryExplorer.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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);
  206. },
  207. _getItemObject: function(item){
  208. return new MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary(this, item)
  209. },
  210. setTooltip: function(){
  211. this.options.tooltip = {
  212. "create": MWF.APPPM.LP.dictionary.create,
  213. "search": MWF.APPPM.LP.dictionary.search,
  214. "searchText": MWF.APPPM.LP.dictionary.searchText,
  215. "noElement": MWF.APPPM.LP.dictionary.noDictionaryNoticeText
  216. };
  217. },
  218. loadElementList: function(){
  219. this._loadItemDataList(function(json){
  220. if (json.data.length){
  221. json.data.each(function(item){
  222. var itemObj = this._getItemObject(item);
  223. itemObj.load()
  224. }.bind(this));
  225. }else{
  226. var noElementNode = new Element("div.noElementNode", {
  227. "styles": this.css.noElementNode,
  228. "text": (this.options.noCreate) ? MWF.APPPM.LP.dictionary.noDictionaryNoCreateNoticeText : this.options.noElement
  229. }).inject(this.elementContentListNode);
  230. if (!this.options.noCreate){
  231. noElementNode.addEvent("click", function(e){
  232. this._createElement(e);
  233. }.bind(this));
  234. }
  235. }
  236. }.bind(this));
  237. },
  238. deleteItems: function(){
  239. this.hideDeleteAction();
  240. while (this.deleteMarkItems.length){
  241. var item = this.deleteMarkItems.shift();
  242. if (this.deleteMarkItems.length){
  243. item.deleteDictionary();
  244. }else{
  245. item.deleteDictionary(function(){
  246. // this.reloadItems();
  247. // this.hideDeleteAction();
  248. }.bind(this));
  249. }
  250. }
  251. }
  252. });
  253. MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary = new Class({
  254. Extends: MWF.xApplication.process.ProcessManager.Explorer.Item,
  255. load: function(){
  256. this.node = new Element("div", {
  257. "styles": this.explorer.css.itemNode,
  258. "events": {
  259. "mouseover": function(){
  260. if (this.deleteActionNode) this.deleteActionNode.fade("in");
  261. if (this.saveasActionNode) this.saveasActionNode.fade("in");
  262. }.bind(this),
  263. "mouseout": function(){
  264. if (this.deleteActionNode) this.deleteActionNode.fade("out");
  265. if (this.saveasActionNode) this.saveasActionNode.fade("out");
  266. }.bind(this)
  267. }
  268. }).inject(this.container);
  269. if (this.data.name.icon) this.icon = this.data.name.icon;
  270. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  271. var itemIconNode = new Element("div", {
  272. "styles": this.explorer.css.itemIconNode
  273. }).inject(this.node);
  274. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  275. //new Element("img", {
  276. // "src": iconUrl, "border": "0"
  277. //}).inject(itemIconNode);
  278. itemIconNode.addEvent("click", function(e){
  279. this.toggleSelected();
  280. e.stopPropagation();
  281. }.bind(this));
  282. itemIconNode.makeLnk({
  283. "par": this._getLnkPar()
  284. });
  285. if (!this.explorer.options.noDelete){
  286. this._createActions();
  287. }
  288. var inforNode = new Element("div", {
  289. "styles": this.explorer.css.itemInforNode
  290. }).inject(this.node);
  291. var inforBaseNode = new Element("div", {
  292. "styles": this.explorer.css.itemInforBaseNode
  293. }).inject(inforNode);
  294. new Element("div", {
  295. "styles": this.explorer.css.itemTextTitleNode,
  296. "text": this.data.name,
  297. "title": this.data.name,
  298. "events": {
  299. "click": function(e){this._open(e);e.stopPropagation();}.bind(this)
  300. }
  301. }).inject(inforBaseNode);
  302. new Element("div", {
  303. "styles": this.explorer.css.itemTextAliasNode,
  304. "text": this.data.alias,
  305. "title": this.data.alias
  306. }).inject(inforBaseNode);
  307. new Element("div", {
  308. "styles": this.explorer.css.itemTextDateNode,
  309. "text": (this.data.updateTime || "")
  310. }).inject(inforBaseNode);
  311. new Element("div", {
  312. "styles": this.explorer.css.itemTextDescriptionNode,
  313. "text": this.data.description || "",
  314. "title": this.data.description || ""
  315. }).inject(inforNode);
  316. this._customNodes();
  317. this._isNew();
  318. },
  319. _createActions: function(){
  320. this.deleteActionNode = new Element("div", {
  321. "styles": this.explorer.css.deleteActionNode
  322. }).inject(this.node);
  323. this.deleteActionNode.addEvent("click", function(e){
  324. this.deleteItem(e);
  325. }.bind(this));
  326. this.saveasActionNode = new Element("div", {
  327. "styles": this.css.saveasActionNode,
  328. "title": this.explorer.app.lp.copy
  329. }).inject(this.node);
  330. this.saveasActionNode.addEvent("click", function(e){
  331. this.saveas(e);
  332. }.bind(this));
  333. },
  334. _customNodes: function(){},
  335. _open: function(e){
  336. var _self = this;
  337. var options = {
  338. "appId": "process.DictionaryDesigner"+_self.data.id,
  339. "onQueryLoad": function(){
  340. this.actions = _self.explorer.actions;
  341. this.category = _self;
  342. this.options.id = _self.data.id;
  343. this.application = _self.explorer.app.options.application;
  344. this.options.noModifyName = _self.explorer.options.noModifyName;
  345. this.options.readMode = _self.explorer.options.readMode;
  346. this.explorer = _self.explorer;
  347. }
  348. };
  349. this.explorer.app.desktop.openApplication(e, "process.DictionaryDesigner", options);
  350. },
  351. _getIcon: function(){
  352. //var x = (Math.random()*33).toInt();
  353. //return "process_icon_"+x+".png";
  354. return "dictionary.png";
  355. },
  356. _getLnkPar: function(){
  357. return {
  358. "icon": this.explorer.path+this.explorer.options.style+"/dictionaryIcon/lnk.png",
  359. "title": this.data.name,
  360. "par": "process.DictionaryDesigner#{\"id\": \""+this.data.id+"\", \"applicationId\": \""+this.explorer.app.options.application.id+"\"}"
  361. };
  362. },
  363. // deleteItem: function(e){
  364. // var _self = this;
  365. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  366. // _self.deleteForm();
  367. // this.close();
  368. // },function(){
  369. // this.close();
  370. // });
  371. // },
  372. deleteDictionary: function(callback){
  373. this.explorer.app.restActions.deleteDictionary(this.data.id, function(){
  374. this.node.destroy();
  375. if (callback) callback();
  376. }.bind(this));
  377. },
  378. saveItemAs: function(item){
  379. var id = item.id;
  380. var name = item.name;
  381. this.explorer.app.restActions.getDictionary(this.data.id, function(json){
  382. var data = json.data;
  383. var oldName = data.name;
  384. this.explorer.app.restActions.listDictionary(id, function(dJson){
  385. var i=1;
  386. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  387. data.name = oldName+"_copy"+i;
  388. data.alias = oldName+"_copy"+i;
  389. i++;
  390. }
  391. data.id = "";
  392. data.application = id;
  393. data.applicationName = name;
  394. this.explorer.app.restActions.saveDictionary(data, function(){
  395. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  396. }.bind(this));
  397. }.bind(this));
  398. }.bind(this));
  399. }
  400. });