Main.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. MWF.APPPJD = MWF.xApplication.process.ProjectionDesigner;
  2. MWF.APPPJD.options = {
  3. "multitask": true,
  4. "executable": false
  5. };
  6. MWF.xDesktop.requireApp("process.ProjectionDesigner", "Projection", null, false);
  7. MWF.xApplication.process.ProjectionDesigner.Main = new Class({
  8. Extends: MWF.xApplication.Common.Main,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default",
  12. "name": "process.ProjectionDesigner",
  13. "icon": "icon.png",
  14. "title": MWF.APPPJD.LP.title,
  15. "appTitle": MWF.APPPJD.LP.title,
  16. "id": "",
  17. "actions": null,
  18. "category": null,
  19. "processData": null
  20. },
  21. onQueryLoad: function(){
  22. if (this.status){
  23. this.options.application = this.status.applicationId;
  24. this.application = this.status.application;
  25. this.options.id = this.status.id;
  26. }
  27. if (!this.options.id){
  28. this.options.desktopReload = false;
  29. this.options.title = this.options.title + "-"+MWF.APPPJD.LP.newProjection;
  30. }
  31. this.actions = MWF.Actions.get("x_processplatform_assemble_designer");
  32. this.lp = MWF.xApplication.process.ProjectionDesigner.LP;
  33. this.addEvent("queryClose", function(e){
  34. if (this.explorer){
  35. this.explorer.reload();
  36. }
  37. }.bind(this));
  38. },
  39. loadApplication: function(callback){
  40. this.createNode();
  41. if (!this.options.isRefresh){
  42. this.maxSize(function(){
  43. this.openProjection();
  44. }.bind(this));
  45. }else{
  46. this.openProjection();
  47. }
  48. if (callback) callback();
  49. },
  50. createNode: function(){
  51. this.content.setStyle("overflow", "hidden");
  52. this.node = new Element("div", {
  53. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  54. }).inject(this.content);
  55. },
  56. getApplication:function(callback){
  57. if (!this.application){
  58. this.actions.getApplication(this.options.application, function(json){
  59. this.application = {"name": json.data.name, "id": json.data.id};
  60. if (callback) callback();
  61. }.bind(this));
  62. }else{
  63. if (callback) callback();
  64. }
  65. },
  66. openProjection: function(){
  67. this.getApplication(function(){
  68. this.loadNodes();
  69. this.loadProjectionListNodes();
  70. this.loadContentNode(function(){
  71. this.loadProperty();
  72. // this.loadTools();
  73. this.resizeNode();
  74. this.addEvent("resize", this.resizeNode.bind(this));
  75. this.loadProjection();
  76. if (this.toolbarContentNode){
  77. this.setScrollBar(this.toolbarContentNode, null, {
  78. "V": {"x": 0, "y": 0},
  79. "H": {"x": 0, "y": 0}
  80. });
  81. this.setScrollBar(this.propertyDomArea, null, {
  82. "V": {"x": 0, "y": 0},
  83. "H": {"x": 0, "y": 0}
  84. });
  85. }
  86. }.bind(this));
  87. }.bind(this));
  88. },
  89. loadNodes: function(){
  90. this.projectionListNode = new Element("div", {
  91. "styles": this.css.projectionListNode
  92. }).inject(this.node);
  93. this.propertyNode = new Element("div", {
  94. "styles": this.css.propertyNode
  95. }).inject(this.node);
  96. this.contentNode = new Element("div", {
  97. "styles": this.css.contentNode
  98. }).inject(this.node);
  99. },
  100. //loadScriptList-------------------------------
  101. loadProjectionListNodes: function(){
  102. this.projectionListTitleNode = new Element("div", {
  103. "styles": this.css.projectionListTitleNode,
  104. "text": MWF.APPPJD.LP.projectionLibrary
  105. }).inject(this.projectionListNode);
  106. this.projectionListResizeNode = new Element("div", {"styles": this.css.projectionListResizeNode}).inject(this.projectionListNode);
  107. this.projectionListAreaSccrollNode = new Element("div", {"styles": this.css.projectionListAreaSccrollNode}).inject(this.projectionListNode);
  108. this.projectionListAreaNode = new Element("div", {"styles": this.css.projectionListAreaNode}).inject(this.projectionListAreaSccrollNode);
  109. this.loadProjectionListResize();
  110. this.loadProjectionList();
  111. },
  112. loadProjectionListResize: function(){
  113. // var size = this.propertyNode.getSize();
  114. // var position = this.propertyResizeBar.getPosition();
  115. this.projectionListResize = new Drag(this.projectionListResizeNode,{
  116. "snap": 1,
  117. "onStart": function(el, e){
  118. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  119. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  120. el.store("position", {"x": x, "y": y});
  121. var size = this.projectionListAreaSccrollNode.getSize();
  122. el.store("initialWidth", size.x);
  123. }.bind(this),
  124. "onDrag": function(el, e){
  125. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  126. // var y = e.event.y;
  127. var bodySize = this.content.getSize();
  128. var position = el.retrieve("position");
  129. var initialWidth = el.retrieve("initialWidth").toFloat();
  130. var dx = x.toFloat() - position.x.toFloat();
  131. var width = initialWidth+dx;
  132. if (width> bodySize.x/2) width = bodySize.x/2;
  133. if (width<40) width = 40;
  134. this.contentNode.setStyle("margin-left", width+1);
  135. this.projectionListNode.setStyle("width", width);
  136. }.bind(this)
  137. });
  138. },
  139. loadProjectionList: function() {
  140. this.actions.listProjection(this.application.id, function (json) {
  141. json.data.each(function(projection){
  142. this.createListProjectionItem(projection);
  143. }.bind(this));
  144. }.bind(this), null, false);
  145. },
  146. createListProjectionItem: function(projection, isNew){
  147. var _self = this;
  148. var listProjectionItem = new Element("div", {"styles": this.css.listProjectionItem}).inject(this.projectionListAreaNode, (isNew) ? "top": "bottom");
  149. var listProjectionItemIcon = new Element("div", {"styles": this.css.listProjectionItemIcon}).inject(listProjectionItem);
  150. var listProjectionItemText = new Element("div", {"styles": this.css.listProjectionItemText, "text": (projection.name) ? projection.name+" ("+projection.alias+")" : this.lp.newProjection}).inject(listProjectionItem);
  151. listProjectionItem.store("projection", projection);
  152. listProjectionItem.addEvents({
  153. "dblclick": function(e){_self.loadProjectionByData(this, e);},
  154. "mouseover": function(){if (_self.currentListProjectionItem!=this) this.setStyles(_self.css.listProjectionItem_over);},
  155. "mouseout": function(){if (_self.currentListProjectionItem!=this) this.setStyles(_self.css.listProjectionItem);}
  156. });
  157. },
  158. loadScriptByData: function(node, e){
  159. var projection = node.retrieve("projection");
  160. var openNew = true;
  161. for (var i = 0; i<this.projectionTab.pages.length; i++){
  162. if (projection.id==this.projectionTab.pages[i].projection.data.id){
  163. this.projectionTab.pages[i].showTabIm();
  164. openNew = false;
  165. break;
  166. }
  167. }
  168. if (openNew){
  169. this.loadProjectionData(projection.id, function(data){
  170. var projection = new MWF.xApplication.process.ProjectionDesigner.Projection(this, data);
  171. projection.load();
  172. }.bind(this), true);
  173. }
  174. },
  175. //loadContentNode------------------------------
  176. loadContentNode: function(toolbarCallback, contentCallback){
  177. this.contentToolbarNode = new Element("div", {
  178. "styles": this.css.contentToolbarNode
  179. }).inject(this.contentNode);
  180. this.loadContentToolbar(toolbarCallback);
  181. this.editContentNode = new Element("div", {
  182. "styles": this.css.editContentNode
  183. }).inject(this.contentNode);
  184. this.loadEditContent(function(){
  185. // if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  186. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  187. if (contentCallback) contentCallback();
  188. }.bind(this));
  189. },
  190. loadContentToolbar: function(callback){
  191. this.getFormToolbarHTML(function(toolbarNode){
  192. var spans = toolbarNode.getElements("span");
  193. spans.each(function(item, idx){
  194. var img = item.get("MWFButtonImage");
  195. if (img){
  196. item.set("MWFButtonImage", this.path+""+this.options.style+"/toolbar/"+img);
  197. }
  198. }.bind(this));
  199. $(toolbarNode).inject(this.contentToolbarNode);
  200. MWF.require("MWF.widget.Toolbar", function(){
  201. this.toolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  202. this.toolbar.load();
  203. if (callback) callback();
  204. }.bind(this));
  205. }.bind(this));
  206. },
  207. getFormToolbarHTML: function(callback){
  208. var toolbarUrl = this.path+this.options.style+"/toolbars.html";
  209. var r = new Request.HTML({
  210. url: toolbarUrl,
  211. method: "get",
  212. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  213. var toolbarNode = responseTree[0];
  214. if (callback) callback(toolbarNode);
  215. }.bind(this),
  216. onFailure: function(xhr){
  217. this.notice("request projectionToolbars error: "+xhr.responseText, "error");
  218. }.bind(this)
  219. });
  220. r.send();
  221. },
  222. loadEditContent: function(callback){
  223. this.designNode = new Element("div", {
  224. "styles": this.css.designNode
  225. }).inject(this.editContentNode);
  226. MWF.require("MWF.widget.Tab", function(){
  227. this.projectionTab = new MWF.widget.Tab(this.designNode, {"style": "script"});
  228. this.projectionTab.load();
  229. }.bind(this), false);
  230. },
  231. //loadProperty------------------------
  232. loadProperty: function(){
  233. this.propertyTitleNode = new Element("div", {
  234. "styles": this.css.propertyTitleNode,
  235. "text": MWF.APPPJD.LP.property
  236. }).inject(this.propertyNode);
  237. this.propertyResizeBar = new Element("div", {
  238. "styles": this.css.propertyResizeBar
  239. }).inject(this.propertyNode);
  240. this.loadPropertyResize();
  241. this.propertyContentNode = new Element("div", {
  242. "styles": this.css.propertyContentNode
  243. }).inject(this.propertyNode);
  244. this.propertyContentArea = new Element("div", {
  245. "styles": this.css.propertyContentArea
  246. }).inject(this.propertyContentNode);
  247. this.setPropertyContent();
  248. },
  249. setPropertyContent: function(){
  250. var node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.id+":"}).inject(this.propertyContentArea);
  251. this.propertyIdNode = new Element("div", {"styles": this.css.propertyTextNode, "text": ""}).inject(this.propertyContentArea);
  252. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.name+":"}).inject(this.propertyContentArea);
  253. this.propertyNameNode = new Element("input", {"styles": this.css.propertyInputNode, "value": ""}).inject(this.propertyContentArea);
  254. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.description+":"}).inject(this.propertyContentArea);
  255. this.propertyDescriptionNode = new Element("textarea", {"styles": this.css.propertyInputAreaNode, "value": ""}).inject(this.propertyContentArea);
  256. node = new Element("div", {"styles": this.css.propertyItemTitleNode, "text": this.lp.enable+":"}).inject(this.propertyContentArea);
  257. this.propertyEnableNode = new Element("select", {
  258. "styles": this.css.propertyInputNode,
  259. "html": "<option value='true'>是</option><option value='false' selected>否</option>"
  260. }).inject(this.propertyContentArea);
  261. },
  262. loadPropertyResize: function(){
  263. // var size = this.propertyNode.getSize();
  264. // var position = this.propertyResizeBar.getPosition();
  265. this.propertyResize = new Drag(this.propertyResizeBar,{
  266. "snap": 1,
  267. "onStart": function(el, e){
  268. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  269. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  270. el.store("position", {"x": x, "y": y});
  271. var size = this.propertyNode.getSize();
  272. el.store("initialWidth", size.x);
  273. }.bind(this),
  274. "onDrag": function(el, e){
  275. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  276. // var y = e.event.y;
  277. var bodySize = this.content.getSize();
  278. var position = el.retrieve("position");
  279. var initialWidth = el.retrieve("initialWidth").toFloat();
  280. var dx = position.x.toFloat()-x.toFloat();
  281. var width = initialWidth+dx;
  282. if (width> bodySize.x/2) width = bodySize.x/2;
  283. if (width<40) width = 40;
  284. this.contentNode.setStyle("margin-right", width+1);
  285. this.propertyNode.setStyle("width", width);
  286. }.bind(this)
  287. });
  288. },
  289. //resizeNode------------------------------------------------
  290. resizeNode: function(){
  291. if (!this.isMax){
  292. var nodeSize = this.node.getSize();
  293. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  294. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  295. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  296. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  297. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  298. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  299. this.editContentNode.setStyle("height", ""+y+"px");
  300. if (this.designNode){
  301. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  302. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  303. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  304. this.designNode.setStyle("height", ""+y+"px");
  305. }
  306. titleSize = this.propertyTitleNode.getSize();
  307. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  308. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  309. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  310. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  311. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  312. y = nodeSize.y-y;
  313. this.propertyContentNode.setStyle("height", ""+y+"px");
  314. this.propertyResizeBar.setStyle("height", ""+y+"px");
  315. //this.setPropertyContentResize();
  316. titleSize = this.projectionListTitleNode.getSize();
  317. titleMarginTop = this.projectionListTitleNode.getStyle("margin-top").toFloat();
  318. titleMarginBottom = this.projectionListTitleNode.getStyle("margin-bottom").toFloat();
  319. titlePaddingTop = this.projectionListTitleNode.getStyle("padding-top").toFloat();
  320. titlePaddingBottom = this.projectionListTitleNode.getStyle("padding-bottom").toFloat();
  321. nodeMarginTop = this.projectionListAreaSccrollNode.getStyle("margin-top").toFloat();
  322. nodeMarginBottom = this.projectionListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  323. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  324. y = nodeSize.y-y;
  325. this.projectionListAreaSccrollNode.setStyle("height", ""+y+"px");
  326. this.projectionListResizeNode.setStyle("height", ""+y+"px");
  327. }
  328. },
  329. //loadProjection------------------------------------------
  330. loadProjection: function(){
  331. this.getProjectionData(this.options.id, function(data){
  332. this.projection = new MWF.xApplication.process.ProjectionDesigner.Projection(this, data);
  333. this.projection.load();
  334. if (this.status){
  335. if (this.status.openProjections){
  336. this.status.openProjections.each(function(id){
  337. this.loadProjectionData(id, function(data){
  338. var showTab = true;
  339. if (this.status.currentId){
  340. if (this.status.currentId!==data.id) showTab = false;
  341. }
  342. var projection = new MWF.xApplication.process.ProjectionDesigner.Projection(this, data, {"showTab": showTab});
  343. projection.load();
  344. }.bind(this), true);
  345. }.bind(this));
  346. }
  347. }
  348. }.bind(this));
  349. },
  350. getProjectionData: function(id, callback){
  351. if (!id){
  352. this.loadNewProjectionData(callback);
  353. }else{
  354. this.loadProjectionData(id, callback);
  355. }
  356. },
  357. loadNewProjectionData: function(callback){
  358. this.actions.getUUID(function(id){
  359. var data = {
  360. "name": "",
  361. "id": id,
  362. "application": this.application.id,
  363. "process": "",
  364. "enable": false,
  365. "description": "",
  366. "type": "",
  367. "data": [],
  368. "isNewProjection": true,
  369. };
  370. this.createListProjectionItem(data, true);
  371. if (callback) callback(data);
  372. }.bind(this))
  373. },
  374. loadProjectionData: function(id, callback, notSetTile){
  375. this.actions.getScript(id, function(json){
  376. if (json){
  377. var data = json.data;
  378. if (!notSetTile){
  379. this.setTitle(this.options.appTitle + "-"+data.name);
  380. this.taskitem.setText(this.options.appTitle + "-"+data.name);
  381. this.options.appTitle = this.options.appTitle + "-"+data.name;
  382. }
  383. if (!this.application){
  384. this.actions.getApplication(this.data.application, function(json){
  385. this.application = {"name": json.data.name, "id": json.data.id};
  386. if (callback) callback(data);
  387. }.bind(this));
  388. }else{
  389. if (callback) callback(data);
  390. }
  391. }
  392. }.bind(this));
  393. },
  394. saveProjection: function(){
  395. if (this.scriptTab.showPage){
  396. var script = this.scriptTab.showPage.script;
  397. script.save(function(){
  398. if (script==this.script){
  399. var name = script.data.name;
  400. this.setTitle(MWF.APPPJD.LP.title + "-"+name);
  401. this.options.desktopReload = true;
  402. this.options.id = script.data.id;
  403. }
  404. }.bind(this));
  405. }
  406. },
  407. execProjection: function(){
  408. },
  409. saveDictionaryAs: function(){
  410. this.dictionary.saveAs();
  411. },
  412. dictionaryExplode: function(){
  413. this.dictionary.explode();
  414. },
  415. dictionaryImplode: function(){
  416. this.dictionary.implode();
  417. },
  418. recordStatus: function(){
  419. if (this.scriptTab){
  420. var openScripts = [];
  421. this.scriptTab.pages.each(function(page){
  422. if (page.script.data.id!=this.options.id) openScripts.push(page.script.data.id);
  423. }.bind(this));
  424. var currentId = this.scriptTab.showPage.script.data.id;
  425. var status = {
  426. "id": this.options.id,
  427. "application": this.application,
  428. "openScripts": openScripts,
  429. "currentId": currentId
  430. };
  431. return status;
  432. }
  433. return {"id": this.options.id, "application": this.application};
  434. }
  435. });