Main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. MWF.xApplication.process = MWF.xApplication.process || {};
  2. MWF.xApplication.process.DictionaryDesigner = MWF.xApplication.process.DictionaryDesigner || {};
  3. MWF.xDesktop.requireApp("process.DictionaryDesigner", "Main", null, false);
  4. MWF.xApplication.service.DictionaryDesigner.options = {
  5. "multitask": true,
  6. "executable": false
  7. };
  8. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", null, false);
  9. MWF.xDesktop.requireApp("service.DictionaryDesigner", "Dictionary", null, false);
  10. MWF.xApplication.service.DictionaryDesigner.Main = new Class({
  11. Extends: MWF.xApplication.process.DictionaryDesigner.Main,
  12. Implements: [Options, Events],
  13. options: {
  14. "style": "default",
  15. "name": "service.DictionaryDesigner",
  16. "icon": "icon.png",
  17. "title": MWF.APPDD.LP.title,
  18. "appTitle": MWF.APPDD.LP.title,
  19. "id": "",
  20. "width": "1200",
  21. "height": "600",
  22. "actions": null,
  23. "category": null
  24. },
  25. onQueryLoad: function(){
  26. this.shortcut = true;
  27. if (this.status){
  28. this.options.id = this.status.id;
  29. this.setOptions(this.status.options);
  30. }
  31. if (!this.options.id){
  32. this.options.desktopReload = false;
  33. this.options.title = this.options.title + "-"+MWF.APPDD.LP.newDictionary;
  34. }
  35. if (!this.actions){
  36. this.actions = MWF.Actions.get("x_program_center");
  37. }
  38. this.lp = MWF.xApplication.process.DictionaryDesigner.LP;
  39. this.addEvent("queryClose", function(e){
  40. if (this.explorer && this.explorer.reload){
  41. this.explorer.reload();
  42. }
  43. }.bind(this));
  44. },
  45. pasteModule: function(){
  46. if (this.shortcut) {
  47. if (MWF.clipboard.data) {
  48. if (MWF.clipboard.data.type == "dictionary") {
  49. if (this.tab.showPage) {
  50. var dictionary = this.tab.showPage.dictionary;
  51. if (dictionary) {
  52. if (dictionary.currentSelectedItem) {
  53. var item = dictionary.currentSelectedItem;
  54. var key = MWF.clipboard.data.data.key;
  55. var value = (typeOf(MWF.clipboard.data.data.value)=="object") ? Object.clone(MWF.clipboard.data.data.value) : MWF.clipboard.data.data.value;
  56. var level = item.level;
  57. var parent = item;
  58. var nextSibling = null;
  59. if (!item.parent){//top level
  60. level = 1;
  61. }else{
  62. if (item.type!="array" && item.type!="object"){
  63. parent = item.parent;
  64. nextSibling = item;
  65. }else{
  66. if (item.exp){
  67. level = item.level+1;
  68. }else{
  69. parent = item.parent;
  70. nextSibling = item;
  71. }
  72. }
  73. }
  74. var idx = parent.children.length;
  75. if (item.type=="array"){
  76. if (nextSibling){
  77. key = nextSibling.key;
  78. parent.value.splice(nextSibling.key, 0, value);
  79. for (var i=nextSibling.key; i<parent.children.length; i++){
  80. subItem = parent.children[i];
  81. subItem.key = subItem.key+1;
  82. subItem.setNodeText();
  83. }
  84. }else{
  85. var key = parent.value.length;
  86. parent.value.push(value);
  87. }
  88. idx = key;
  89. }else{
  90. var oldKey = key;
  91. var i = 0;
  92. while (parent.value[key] != undefined) {
  93. i++;
  94. key = oldKey + i;
  95. }
  96. parent.value[key] = value;
  97. if (nextSibling) var idx = parent.children.indexOf(nextSibling);
  98. }
  99. var item = new MWF.xApplication.service.DictionaryDesigner.Dictionary.item(key, value, parent, level, this.dictionary, true, nextSibling);
  100. if (idx) parent.children[idx-1].nextSibling = item;
  101. parent.children.splice(idx, 0, item);
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. },
  109. getApplication:function(callback){
  110. if (callback) callback();
  111. },
  112. getUd: function ( callback ){
  113. MWF.UD.getDataJson(this.options.name, function (data){
  114. if( data ){
  115. this.options.sortKey = data.sortKey;
  116. this.options.listToolbarExpanded = data.listToolbarExpanded || false;
  117. }
  118. callback();
  119. }.bind(this));
  120. },
  121. setUd: function (){
  122. var data = {
  123. sortKey: this.options.sortKey,
  124. listToolbarExpanded: this.options.listToolbarExpanded
  125. };
  126. MWF.UD.putData(this.options.name, data);
  127. },
  128. openApp: function (){
  129. layout.openApplication(null, 'service.ServiceManager', {
  130. appId: 'service.ServiceManager'
  131. }, {
  132. "navi":2
  133. });
  134. },
  135. loadDictionaryList: function(){
  136. if( this.currentListDictionaryItem ){
  137. var d = this.currentListDictionaryItem.retrieve('dictionary');
  138. this.options.id = d.id;
  139. }
  140. if( this.itemArray && this.itemArray.length ){
  141. this.itemArray = this.itemArray.filter(function(i){
  142. if(i.data.id)i.node.destroy();
  143. return !i.data.id;
  144. });
  145. }else{
  146. this.itemArray = [];
  147. }
  148. this.actions.listDictionary(function (json) {
  149. this.checkSort(json.data);
  150. json.data.each(function(dictionary){
  151. this.createListDictionaryItem(dictionary);
  152. }.bind(this));
  153. }.bind(this), null, false);
  154. },
  155. loadDictionaryByData: function(node, e){
  156. var dictionary = node.retrieve("dictionary");
  157. var openNew = true;
  158. for (var i = 0; i<this.tab.pages.length; i++){
  159. if (dictionary.id==this.tab.pages[i].dictionary.data.id){
  160. this.tab.pages[i].showTabIm();
  161. openNew = false;
  162. break;
  163. }
  164. }
  165. if (openNew){
  166. this.loadDictionaryData(dictionary.id, function(data){
  167. var dictionary = new MWF.xApplication.service.DictionaryDesigner.Dictionary(this, data);
  168. dictionary.load();
  169. }.bind(this), true);
  170. }
  171. },
  172. //loadForm------------------------------------------
  173. loadDictionary: function(){
  174. this.getDictionaryData(this.options.id, function(ddata){
  175. this.setTitle(this.options.appTitle + "-"+ddata.name);
  176. if (this.taskitem) this.taskitem.setText(this.options.appTitle + "-"+ddata.name);
  177. this.options.appTitle = this.options.appTitle + "-"+ddata.name;
  178. if (this.options.readMode){
  179. this.dictionary = new MWF.xApplication.service.DictionaryDesigner.DictionaryReader(this, ddata);
  180. }else{
  181. this.dictionary = new MWF.xApplication.service.DictionaryDesigner.Dictionary(this, ddata);
  182. }
  183. this.dictionary.load();
  184. if (this.status){
  185. if (this.status.openDictionarys){
  186. this.status.openDictionarys.each(function(id){
  187. this.loadDictionaryData(id, function(data){
  188. var showTab = true;
  189. if (this.status.currentId){
  190. if (this.status.currentId!=data.id) showTab = false;
  191. }
  192. if (this.options.readMode){
  193. var dictionary = new MWF.xApplication.service.DictionaryDesigner.DictionaryReader(this, data, {"showTab": showTab});
  194. }else{
  195. var dictionary = new MWF.xApplication.service.DictionaryDesigner.Dictionary(this, data, {"showTab": showTab});
  196. }
  197. dictionary.load();
  198. }.bind(this), true);
  199. }.bind(this));
  200. this.status.openDictionarys = [];
  201. }
  202. }
  203. }.bind(this));
  204. },
  205. loadNewDictionaryData: function(callback){
  206. var data = {
  207. "name": "",
  208. "id": "",
  209. "alias": "",
  210. "description": "",
  211. "data": {}
  212. };
  213. this.createListDictionaryItem(data, true);
  214. if (callback) callback(data);
  215. },
  216. loadDictionaryData: function(id, callback){
  217. this.actions.getDictionary(id, function(json){
  218. if (json){
  219. var data = json.data;
  220. if (callback) callback(data);
  221. }
  222. }.bind(this));
  223. },
  224. recordStatus: function(){
  225. if (this.tab){
  226. var openDictionarys = [];
  227. this.tab.pages.each(function(page){
  228. if (page.dictionary.data.id!=this.options.id) openDictionarys.push(page.dictionary.data.id);
  229. }.bind(this));
  230. var currentId = this.tab.showPage.dictionary.data.id;
  231. var status = {
  232. "id": this.options.id,
  233. "openDictionarys": openDictionarys,
  234. "currentId": currentId,
  235. "options": {
  236. "action": this.options.action,
  237. "noCreate": this.options.noCreate,
  238. "noDelete": this.options.noDelete,
  239. "noModifyName": this.options.noModifyName,
  240. "readMode": this.options.readMode
  241. }
  242. };
  243. return status;
  244. }
  245. return {"id": this.options.id, "application": application};
  246. }
  247. });