Main.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. loadDictionaryList: function(){
  113. this.actions.listDictionary(function (json) {
  114. json.data.each(function(dictionary){
  115. this.createListDictionaryItem(dictionary);
  116. }.bind(this));
  117. }.bind(this), null, false);
  118. },
  119. loadDictionaryByData: function(node, e){
  120. var dictionary = node.retrieve("dictionary");
  121. var openNew = true;
  122. for (var i = 0; i<this.tab.pages.length; i++){
  123. if (dictionary.id==this.tab.pages[i].dictionary.data.id){
  124. this.tab.pages[i].showTabIm();
  125. openNew = false;
  126. break;
  127. }
  128. }
  129. if (openNew){
  130. this.loadDictionaryData(dictionary.id, function(data){
  131. var dictionary = new MWF.xApplication.service.DictionaryDesigner.Dictionary(this, data);
  132. dictionary.load();
  133. }.bind(this), true);
  134. }
  135. },
  136. //loadForm------------------------------------------
  137. loadDictionary: function(){
  138. this.getDictionaryData(this.options.id, function(ddata){
  139. this.setTitle(this.options.appTitle + "-"+ddata.name);
  140. if (this.taskitem) this.taskitem.setText(this.options.appTitle + "-"+ddata.name);
  141. this.options.appTitle = this.options.appTitle + "-"+ddata.name;
  142. if (this.options.readMode){
  143. this.dictionary = new MWF.xApplication.service.DictionaryDesigner.DictionaryReader(this, ddata);
  144. }else{
  145. this.dictionary = new MWF.xApplication.service.DictionaryDesigner.Dictionary(this, ddata);
  146. }
  147. this.dictionary.load();
  148. if (this.status){
  149. if (this.status.openDictionarys){
  150. this.status.openDictionarys.each(function(id){
  151. this.loadDictionaryData(id, function(data){
  152. var showTab = true;
  153. if (this.status.currentId){
  154. if (this.status.currentId!=data.id) showTab = false;
  155. }
  156. if (this.options.readMode){
  157. var dictionary = new MWF.xApplication.service.DictionaryDesigner.DictionaryReader(this, data, {"showTab": showTab});
  158. }else{
  159. var dictionary = new MWF.xApplication.service.DictionaryDesigner.Dictionary(this, data, {"showTab": showTab});
  160. }
  161. dictionary.load();
  162. }.bind(this), true);
  163. }.bind(this));
  164. }
  165. }
  166. }.bind(this));
  167. },
  168. loadNewDictionaryData: function(callback){
  169. var data = {
  170. "name": "",
  171. "id": "",
  172. "alias": "",
  173. "description": "",
  174. "data": {}
  175. };
  176. this.createListDictionaryItem(data, true);
  177. if (callback) callback(data);
  178. },
  179. loadDictionaryData: function(id, callback){
  180. this.actions.getDictionary(id, function(json){
  181. if (json){
  182. var data = json.data;
  183. if (callback) callback(data);
  184. }
  185. }.bind(this));
  186. },
  187. recordStatus: function(){
  188. if (this.tab){
  189. var openDictionarys = [];
  190. this.tab.pages.each(function(page){
  191. if (page.dictionary.data.id!=this.options.id) openDictionarys.push(page.dictionary.data.id);
  192. }.bind(this));
  193. var currentId = this.tab.showPage.dictionary.data.id;
  194. var status = {
  195. "id": this.options.id,
  196. "openDictionarys": openDictionarys,
  197. "currentId": currentId,
  198. "options": {
  199. "action": this.options.action,
  200. "noCreate": this.options.noCreate,
  201. "noDelete": this.options.noDelete,
  202. "noModifyName": this.options.noModifyName,
  203. "readMode": this.options.readMode
  204. }
  205. };
  206. return status;
  207. }
  208. return {"id": this.options.id, "application": application};
  209. }
  210. });