Main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. MWF.xDesktop.requireApp("query.ViewDesigner", "", null, false);
  2. MWF.APPDIPD = MWF.xApplication.query.ImporterDesigner;
  3. MWF.APPDIPD.options = {
  4. "multitask": true,
  5. "executable": false
  6. };
  7. MWF.xDesktop.requireApp("query.ImporterDesigner", "Importer", null, false);
  8. MWF.xApplication.query.ImporterDesigner.Main = new Class({
  9. Extends: MWF.xApplication.query.ViewDesigner.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "name": "query.ImporterDesigner",
  14. "icon": "icon.png",
  15. "title": MWF.APPDIPD.LP.title,
  16. "appTitle": MWF.APPDIPD.LP.title,
  17. "id": "",
  18. "tooltip": {
  19. "unCategory": MWF.APPDIPD.LP.unCategory
  20. },
  21. "actions": null,
  22. "category": null
  23. },
  24. onQueryLoad: function(){
  25. this.shortcut = true;
  26. if (this.status){
  27. this.options.application = this.status.applicationId;
  28. this.application = this.status.application;
  29. this.options.id = this.status.id;
  30. }
  31. if( !this.application && this.options.application ){
  32. this.application = this.options.application;
  33. }
  34. if (!this.options.id){
  35. this.options.desktopReload = false;
  36. this.options.title = this.options.title + "-"+MWF.APPDIPD.LP.newImporter;
  37. }
  38. if (!this.actions) this.actions = MWF.Actions.get("x_query_assemble_designer");
  39. this.lp = MWF.xApplication.query.ImporterDesigner.LP;
  40. this.addEvent("queryClose", function(e){
  41. if (this.explorer){
  42. this.explorer.reload();
  43. }
  44. }.bind(this));
  45. },
  46. loadViewListNodes: function(){
  47. this.viewListTitleNode = new Element("div", {
  48. "styles": this.css.viewListTitleNode,
  49. "text": MWF.APPDIPD.LP.importer
  50. }).inject(this.viewListNode);
  51. this.viewListResizeNode = new Element("div", {"styles": this.css.viewListResizeNode}).inject(this.viewListNode);
  52. this.createListTitleNodes();
  53. this.viewListAreaSccrollNode = new Element("div", {"styles": this.css.viewListAreaSccrollNode}).inject(this.viewListNode);
  54. this.viewListAreaNode = new Element("div", {"styles": this.css.viewListAreaNode}).inject(this.viewListAreaSccrollNode);
  55. this.loadViewListResize();
  56. this.loadViewList();
  57. },
  58. openApp: function (){
  59. layout.openApplication(null, 'query.QueryManager', {
  60. application: this.application,
  61. appId: 'query.QueryManager'+this.application.id
  62. }, {
  63. "navi":4
  64. });
  65. },
  66. loadViewList: function(){
  67. if( this.itemArray && this.itemArray.length ){
  68. this.itemArray.each(function(i){
  69. if(!i.data.isNewImportModel)i.node.destroy();
  70. });
  71. }
  72. this.itemArray = [];
  73. this.actions.listImportModel(this.application.id, function (json) {
  74. this.checkSort(json.data);
  75. json.data.each(function(importer){
  76. this.createListViewItem(importer);
  77. }.bind(this));
  78. }.bind(this), null, false);
  79. },
  80. //列示所有数据表列表
  81. createListViewItem: function(importer, isNew){
  82. var _self = this;
  83. var listImporterItem = new Element("div", {"styles": this.css.listViewItem}).inject(this.viewListAreaNode, (isNew) ? "top": "bottom");
  84. var listImporterItemIcon = new Element("div", {"styles": this.css.listViewItemIcon}).inject(listImporterItem);
  85. var listImporterItemText = new Element("div", {"styles": this.css.listViewItemText, "text": (importer.name) ? importer.name+" ("+importer.alias+")" : this.lp.newImporter}).inject(listImporterItem);
  86. listImporterItem.store("importer", importer);
  87. listImporterItem.addEvents({
  88. "click": function(e){_self.loadImporterByData(this, e);},
  89. "mouseover": function(){if (_self.currentListViewItem!=this) this.setStyles(_self.css.listViewItem_over);},
  90. "mouseout": function(){if (_self.currentListViewItem!=this) this.setStyles(_self.css.listViewItem);}
  91. });
  92. if( importer.id === this.options.id ){
  93. listImporterItem.setStyles(this.css.listViewItem_current);
  94. this.currentListViewItem = listImporterItem;
  95. }
  96. var itemObj = {
  97. node: listImporterItem,
  98. data: importer
  99. };
  100. this.itemArray.push(itemObj);
  101. this.checkShow(itemObj);
  102. },
  103. //打开数据表
  104. loadImporterByData: function(node, e){
  105. var importer = node.retrieve("importer");
  106. if (!importer.isNewImportModel){
  107. var openNew = true;
  108. if (openNew){
  109. var _self = this;
  110. var options = {
  111. "appId": "query.ImporterDesigner"+importer.id,
  112. "id": importer.id,
  113. // "application": _self.application.id,
  114. "application": {
  115. "name": _self.application.name,
  116. "id": _self.application.id,
  117. },
  118. "onQueryLoad": function(){
  119. this.actions = _self.actions;
  120. this.category = _self;
  121. this.options.id = importer.id;
  122. this.application = _self.application;
  123. this.explorer = _self.explorer;
  124. }
  125. };
  126. this.desktop.openApplication(e, "query.ImporterDesigner", options);
  127. }
  128. }
  129. },
  130. //loadView------------------------------------------
  131. loadView: function(){
  132. this.getViewData(this.options.id, function(vdata){
  133. this.setTitle(this.options.appTitle + "-"+vdata.name);
  134. if(this.taskitem)this.taskitem.setText(this.options.appTitle + "-"+vdata.name);
  135. this.options.appTitle = this.options.appTitle + "-"+vdata.name;
  136. this.importer = new MWF.xApplication.query.ImporterDesigner.Importer(this, vdata);
  137. this.view = this.importer;
  138. this.importer.load();
  139. }.bind(this));
  140. },
  141. loadNewViewData: function(callback){
  142. var url = "../x_component_query_ImporterDesigner/$Importer/importer.json";
  143. MWF.getJSON(url, {
  144. "onSuccess": function(obj){
  145. this.actions.getUUID(function(id){
  146. obj.id=id;
  147. obj.isNewImportModel = true;
  148. obj.application = this.application.id;
  149. this.createListViewItem(obj, true);
  150. if (callback) callback(obj);
  151. }.bind(this));
  152. }.bind(this),
  153. "onerror": function(text){
  154. this.notice(text, "error");
  155. }.bind(this),
  156. "onRequestFailure": function(xhr){
  157. this.notice(xhr.responseText, "error");
  158. }.bind(this)
  159. });
  160. },
  161. loadViewData: function(id, callback){
  162. this.actions.getImportModel(id, function(json){
  163. if (json){
  164. var data = json.data;
  165. // data.draftData = JSON.decode(data.draftData);
  166. if (!this.application){
  167. this.actions.getApplication(data.query, function(json){
  168. this.application = {"name": json.data.name, "id": json.data.id};
  169. if (callback) callback(data);
  170. }.bind(this));
  171. }else{
  172. if (callback) callback(data);
  173. }
  174. }
  175. }.bind(this));
  176. },
  177. saveView: function(){
  178. this.view.save(function(){
  179. var name = this.view.data.name;
  180. this.setTitle(MWF.APPDIPD.LP.title + "-"+name);
  181. this.options.desktopReload = true;
  182. this.options.id = this.view.data.id;
  183. }.bind(this));
  184. },
  185. statusBuild: function(){
  186. this.view.statusBuild();
  187. },
  188. statusDraft: function(){
  189. this.view.statusDraft();
  190. },
  191. buildAllView: function(){
  192. this.view.buildAllView();
  193. }
  194. });
  195. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  196. MWF.xApplication.query.ImporterDesigner.Importer.NewNameForm = new Class({
  197. Extends: MPopupForm,
  198. Implements: [Options, Events],
  199. options: {
  200. "style": "design",
  201. "width": 700,
  202. //"height": 300,
  203. "height": "260",
  204. "hasTop": true,
  205. "hasIcon": false,
  206. "draggable": true,
  207. "title" : MWF.xApplication.query.ImporterDesigner.LP.newImporter
  208. },
  209. _createTableContent: function () {
  210. var html = "<table width='80%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin: 20px auto 0px auto; '>" +
  211. "<tr><td styles='formTableTitle' lable='selectQuery' width='25%'></td>" +
  212. " <td styles='formTableValue' item='selectQuery' colspan='3' width='75%'></td></tr>" +
  213. "<tr><td styles='formTableTitle' lable='name'></td>" +
  214. " <td styles='formTableValue' item='name' colspan='3'></td></tr>" +
  215. "</table>";
  216. this.formTableArea.set("html", html);
  217. MWF.xDesktop.requireApp("Template", "MForm", function () {
  218. this.form = new MForm(this.formTableArea, this.data || {}, {
  219. isEdited: true,
  220. style: "cms",
  221. hasColon: true,
  222. itemTemplate: {
  223. selectQuery : { text: MWF.xApplication.query.ImporterDesigner.LP.application , type : "org", orgType : "Query", defaultValue : this.data.queryName, orgWidgetOptions : {
  224. "canRemove" : false
  225. }},
  226. name: {text: MWF.xApplication.query.ImporterDesigner.LP.name, notEmpty: true}
  227. }
  228. }, this.app);
  229. this.form.load();
  230. }.bind(this),null, true)
  231. },
  232. ok: function(){
  233. var data = this.form.getResult(true,null,true,false,true);
  234. if( data ){
  235. var selectQuery = this.form.getItem("selectQuery").orgObject;
  236. if( selectQuery && selectQuery.length > 0 ){
  237. var queryData = selectQuery[0].data;
  238. data.query = queryData.id;
  239. data.queryName = queryData.name;
  240. }else{
  241. //data.query 和 data.queryName 还是传进来的值
  242. }
  243. this.fireEvent("save", [data , function(){
  244. this.close();
  245. }.bind(this)])
  246. }
  247. }
  248. });