Main.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.portal.DictionaryDesigner.options = {
  5. "multitask": true,
  6. "executable": false
  7. };
  8. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", null, false);
  9. MWF.xDesktop.requireApp("portal.DictionaryDesigner", "Dictionary", null, false);
  10. MWF.xApplication.portal.DictionaryDesigner.Main = new Class({
  11. Extends: MWF.xApplication.process.DictionaryDesigner.Main,
  12. Implements: [Options, Events],
  13. options: {
  14. "style": "default",
  15. "name": "portal.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. "portalData": null
  25. },
  26. onQueryLoad: function(){
  27. this.shortcut = true;
  28. if (this.status){
  29. this.options.application = this.status.applicationId;
  30. this.application = this.status.application || this.status.applicationId;
  31. this.options.id = this.status.id;
  32. this.setOptions(this.status.options);
  33. }
  34. if( !this.application && this.options.application ){
  35. this.application = this.options.application;
  36. }
  37. if (!this.options.id){
  38. this.options.desktopReload = false;
  39. this.options.title = this.options.title + "-"+MWF.APPDD.LP.newDictionary;
  40. }
  41. if (!this.actions){
  42. this.actions = MWF.Actions.get("x_portal_assemble_designer");
  43. this.actions.application = this.application;
  44. }
  45. this.lp = MWF.xApplication.portal.DictionaryDesigner.LP;
  46. this.addEvent("queryClose", function(e){
  47. if (this.explorer){
  48. this.explorer.reload();
  49. }
  50. }.bind(this));
  51. },
  52. pasteModule: function(){
  53. if (this.shortcut) {
  54. if (MWF.clipboard.data) {
  55. if (MWF.clipboard.data.type == "dictionary") {
  56. if (this.tab.showPage) {
  57. var dictionary = this.tab.showPage.dictionary;
  58. if (dictionary) {
  59. if (dictionary.currentSelectedItem) {
  60. var item = dictionary.currentSelectedItem;
  61. var key = MWF.clipboard.data.data.key;
  62. var value = (typeOf(MWF.clipboard.data.data.value)=="object") ? Object.clone(MWF.clipboard.data.data.value) : MWF.clipboard.data.data.value;
  63. var level = item.level;
  64. var parent = item;
  65. var nextSibling = null;
  66. if (!item.parent){//top level
  67. level = 1;
  68. }else{
  69. if (item.type!="array" && item.type!="object"){
  70. parent = item.parent;
  71. nextSibling = item;
  72. }else{
  73. if (item.exp){
  74. level = item.level+1;
  75. }else{
  76. parent = item.parent;
  77. nextSibling = item;
  78. }
  79. }
  80. }
  81. var idx = parent.children.length;
  82. if (item.type=="array"){
  83. if (nextSibling){
  84. key = nextSibling.key;
  85. parent.value.splice(nextSibling.key, 0, value);
  86. for (var i=nextSibling.key; i<parent.children.length; i++){
  87. subItem = parent.children[i];
  88. subItem.key = subItem.key+1;
  89. subItem.setNodeText();
  90. }
  91. }else{
  92. var key = parent.value.length;
  93. parent.value.push(value);
  94. }
  95. idx = key;
  96. }else{
  97. var oldKey = key;
  98. var i = 0;
  99. while (parent.value[key] != undefined) {
  100. i++;
  101. key = oldKey + i;
  102. }
  103. parent.value[key] = value;
  104. if (nextSibling) var idx = parent.children.indexOf(nextSibling);
  105. }
  106. var item = new MWF.xApplication.portal.DictionaryDesigner.Dictionary.item(key, value, parent, level, this.dictionary, true, nextSibling);
  107. if (idx) parent.children[idx-1].nextSibling = item;
  108. parent.children.splice(idx, 0, item);
  109. }
  110. }
  111. }
  112. }
  113. }
  114. }
  115. },
  116. getApplication:function(callback){
  117. if (!this.application){
  118. this.actions.getApplication(this.options.application, function(json){
  119. this.application = {"name": json.data.name, "id": json.data.id};
  120. if (callback) callback();
  121. }.bind(this));
  122. }else{
  123. if (callback) callback();
  124. }
  125. },
  126. loadDictionaryList: function(){
  127. this.actions.listDictionary(this.application.id || this.application, function (json) {
  128. json.data.each(function(dictionary){
  129. this.createListDictionaryItem(dictionary);
  130. }.bind(this));
  131. }.bind(this), null, false);
  132. },
  133. loadDictionaryByData: function(node, e){
  134. var dictionary = node.retrieve("dictionary");
  135. var openNew = true;
  136. for (var i = 0; i<this.tab.pages.length; i++){
  137. if (dictionary.id==this.tab.pages[i].dictionary.data.id){
  138. this.tab.pages[i].showTabIm();
  139. openNew = false;
  140. break;
  141. }
  142. }
  143. if (openNew){
  144. this.loadDictionaryData(dictionary.id, function(data){
  145. var dictionary = new MWF.xApplication.portal.DictionaryDesigner.Dictionary(this, data);
  146. dictionary.load();
  147. }.bind(this), true);
  148. }
  149. },
  150. //loadForm------------------------------------------
  151. loadDictionary: function(){
  152. this.getDictionaryData(this.options.id, function(ddata){
  153. this.setTitle(this.options.appTitle + "-"+ddata.name);
  154. if (this.taskitem) this.taskitem.setText(this.options.appTitle + "-"+ddata.name);
  155. this.options.appTitle = this.options.appTitle + "-"+ddata.name;
  156. if (this.options.readMode){
  157. this.dictionary = new MWF.xApplication.portal.DictionaryDesigner.DictionaryReader(this, ddata);
  158. }else{
  159. this.dictionary = new MWF.xApplication.portal.DictionaryDesigner.Dictionary(this, ddata);
  160. }
  161. this.dictionary.load();
  162. if (this.status){
  163. if (this.status.openDictionarys){
  164. this.status.openDictionarys.each(function(id){
  165. this.loadDictionaryData(id, function(data){
  166. var showTab = true;
  167. if (this.status.currentId){
  168. if (this.status.currentId!=data.id) showTab = false;
  169. }
  170. if (this.options.readMode){
  171. var dictionary = new MWF.xApplication.portal.DictionaryDesigner.DictionaryReader(this, data, {"showTab": showTab});
  172. }else{
  173. var dictionary = new MWF.xApplication.portal.DictionaryDesigner.Dictionary(this, data, {"showTab": showTab});
  174. }
  175. dictionary.load();
  176. }.bind(this), true);
  177. }.bind(this));
  178. }
  179. }
  180. }.bind(this));
  181. },
  182. loadDictionaryData: function(id, callback){
  183. this.actions.getDictionary(id, function(json){
  184. if (json){
  185. var data = json.data;
  186. if (!this.application){
  187. this.actions.getApplication(data.application, function(json){
  188. this.application = {"name": json.data.name, "id": json.data.id};
  189. if (callback) callback(data);
  190. }.bind(this));
  191. }else{
  192. if (callback) callback(data);
  193. }
  194. }
  195. }.bind(this));
  196. }
  197. });