Main.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 && this.explorer.reload){
  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. openApp: function (){
  127. layout.openApplication(null, 'portal.PortalManager', {
  128. application: this.application,
  129. appId: 'portal.PortalManager'+this.application.id
  130. }, {
  131. "navi":2
  132. });
  133. },
  134. loadDictionaryList: function(){
  135. if( this.currentListDictionaryItem ){
  136. var d = this.currentListDictionaryItem.retrieve('dictionary');
  137. this.options.id = d.id;
  138. }
  139. if( this.itemArray && this.itemArray.length ){
  140. this.itemArray = this.itemArray.filter(function(i){
  141. if(i.data.id)i.node.destroy();
  142. return !i.data.id;
  143. });
  144. }else{
  145. this.itemArray = [];
  146. }
  147. this.actions.listDictionary(this.application.id || this.application, function (json) {
  148. this.checkSort(json.data);
  149. json.data.each(function(dictionary){
  150. this.createListDictionaryItem(dictionary);
  151. }.bind(this));
  152. }.bind(this), null, false);
  153. },
  154. loadDictionaryByData: function(node, e){
  155. var dictionary = node.retrieve("dictionary");
  156. var openNew = true;
  157. for (var i = 0; i<this.tab.pages.length; i++){
  158. if (dictionary.id==this.tab.pages[i].dictionary.data.id){
  159. this.tab.pages[i].showTabIm();
  160. openNew = false;
  161. break;
  162. }
  163. }
  164. if (openNew){
  165. this.loadDictionaryData(dictionary.id, function(data){
  166. var dictionary = new MWF.xApplication.portal.DictionaryDesigner.Dictionary(this, data);
  167. dictionary.load();
  168. }.bind(this), true);
  169. }
  170. },
  171. //loadForm------------------------------------------
  172. loadDictionary: function(){
  173. this.getDictionaryData(this.options.id, function(ddata){
  174. this.setTitle(this.options.appTitle + "-"+ddata.name);
  175. if (this.taskitem) this.taskitem.setText(this.options.appTitle + "-"+ddata.name);
  176. this.options.appTitle = this.options.appTitle + "-"+ddata.name;
  177. if (this.options.readMode){
  178. this.dictionary = new MWF.xApplication.portal.DictionaryDesigner.DictionaryReader(this, ddata);
  179. }else{
  180. this.dictionary = new MWF.xApplication.portal.DictionaryDesigner.Dictionary(this, ddata);
  181. }
  182. this.dictionary.load();
  183. if (this.status){
  184. if (this.status.openDictionarys){
  185. this.status.openDictionarys.each(function(id){
  186. this.loadDictionaryData(id, function(data){
  187. var showTab = true;
  188. if (this.status.currentId){
  189. if (this.status.currentId!=data.id) showTab = false;
  190. }
  191. if (this.options.readMode){
  192. var dictionary = new MWF.xApplication.portal.DictionaryDesigner.DictionaryReader(this, data, {"showTab": showTab});
  193. }else{
  194. var dictionary = new MWF.xApplication.portal.DictionaryDesigner.Dictionary(this, data, {"showTab": showTab});
  195. }
  196. dictionary.load();
  197. }.bind(this), true);
  198. }.bind(this));
  199. this.status.openDictionarys = [];
  200. }
  201. }
  202. }.bind(this));
  203. },
  204. loadDictionaryData: function(id, callback){
  205. this.actions.getDictionary(id, function(json){
  206. if (json){
  207. var data = json.data;
  208. if (!this.application){
  209. this.actions.getApplication(data.application, function(json){
  210. this.application = {"name": json.data.name, "id": json.data.id};
  211. if (callback) callback(data);
  212. }.bind(this));
  213. }else{
  214. if (callback) callback(data);
  215. }
  216. }
  217. }.bind(this));
  218. }
  219. });