DictionaryExplorer.js 17 KB

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