DictionaryExplorer.js 17 KB

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