Application.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. MWF.xApplication.portal.PageDesigner.Module.Application = MWF.PCApplication = new Class({
  2. Extends: MWF.FC$Element,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "propertyPath": "../x_component_portal_PageDesigner/Module/Application/application.html",
  7. },
  8. initialize: function(form, options){
  9. this.setOptions(options);
  10. this.path = "../x_component_portal_PageDesigner/Module/Application/";
  11. this.cssPath = "../x_component_portal_PageDesigner/Module/Application/"+this.options.style+"/css.wcss";
  12. this._loadCss();
  13. this.moduleType = "component";
  14. this.moduleName = "application";
  15. this.Node = null;
  16. this.form = form;
  17. this.page = form;
  18. },
  19. load : function(json, node, parent){
  20. this.json = json;
  21. this.node= node;
  22. this.node.store("module", this);
  23. //this.node.empty();
  24. this.node.setStyles(this.css.moduleNode);
  25. //this._loadNodeStyles();
  26. this._initModule();
  27. this.loadApplication();
  28. this._loadTreeNode(parent);
  29. this.setCustomStyles();
  30. this.parentContainer = this.treeNode.parentNode.module;
  31. this._setEditStyle_custom("id");
  32. this.parseModules();
  33. this.json.moduleName = this.moduleName;
  34. // this.node.addEvent("click", function(){
  35. // this.refreshApplication();
  36. // }.bind(this));
  37. // this.node.addEvent("dblclick", function(e){
  38. // this.openApplication(e);
  39. // }.bind(this));
  40. },
  41. _initModule: function(){
  42. if (!this.json.isSaved) this.setStyleTemplate();
  43. //this._resetModuleDomNode();
  44. this.setPropertiesOrStyles("styles");
  45. this.setPropertiesOrStyles("properties");
  46. this._setNodeProperty();
  47. if (!this.form.isWidget) this._createIconAction();
  48. this._setNodeEvent();
  49. this.json.isSaved = true;
  50. this.queryGetPageDataFun = this.queryGetPageData.bind(this);
  51. this.postGetPageDataFun = this.postGetPageData.bind(this);
  52. this.page.addEvent("queryGetPageData", this.queryGetPageDataFun);
  53. this.page.addEvent("postGetPageData", this.postGetPageDataFun);
  54. },
  55. _createMoveNode: function(){
  56. this.moveNode = new Element("div", {
  57. "MWFType": "application",
  58. "id": this.json.id,
  59. "styles": this.css.moduleNodeMove,
  60. "events": {
  61. "selectstart": function(){
  62. return false;
  63. }
  64. }
  65. }).inject(this.page.container);
  66. },
  67. _getDroppableNodes: function(){
  68. var nodes = [this.form.node].concat(this.form.moduleElementNodeList, this.form.moduleContainerNodeList, this.form.moduleComponentNodeList);
  69. this.form.moduleList.each( function(module){
  70. //不能往数据模板里拖
  71. if( module.moduleName === "datatemplate" ){
  72. var subDoms = this.form.getModuleNodes(module.node);
  73. nodes.erase( module.node );
  74. subDoms.each(function (dom) {
  75. nodes.erase( dom );
  76. })
  77. }
  78. }.bind(this));
  79. return nodes;
  80. },
  81. _createNode: function(){
  82. this.node = this.moveNode.clone(true, true);
  83. this.node.setStyles(this.css.moduleNode);
  84. this.node.set("id", this.json.id);
  85. this.node.addEvent("selectstart", function(){
  86. return false;
  87. });
  88. // debugger;
  89. // if (this.json.applicationSelected && this.json.applicationSelected!="none" && this.json.applicationType!=="script"){
  90. // this.redoSelectedApplication(this.json.applicationSelected, $(this.property.data.pid+"selectApplication").getElement("select"), "");
  91. // }else{
  92. this.loadIcon();
  93. // }
  94. // this.node.addEvent("click", function(){
  95. // this.refreshApplication();
  96. // }.bind(this));
  97. //
  98. // debugger;
  99. // this.node.addEvent("dblclick", function(e){
  100. // this.openApplication(e);
  101. // }.bind(this));
  102. },
  103. postGetPageData: function(node){
  104. if ((!node || node.contains(this.node)) && this.show) this.show();
  105. },
  106. queryGetPageData: function(node){
  107. if ((!node || node.contains(this.node)) && this.hide) this.hide();
  108. },
  109. hide: function(){
  110. this.clean();
  111. this.node.empty();
  112. },
  113. show: function(){
  114. this.loadApplication()
  115. },
  116. "delete": function(e){
  117. var module = this;
  118. this.page.designer.shortcut = false;
  119. this.page.designer.confirm("warn", module.node, MWF.APPPOD.LP.notice.deleteElementTitle, MWF.APPPOD.LP.notice.deleteElement, 300, 120, function(){
  120. if (module.queryGetPageDataFun) module.page.removeEvent("queryGetPageData", module.queryGetPageDataFun);
  121. if (module.postGetPageDataFun) module.page.removeEvent("postGetPageData", module.postGetPageDataFun);
  122. module.page.selected();
  123. module.page.designer.shortcut = true;
  124. module.destroy();
  125. this.close();
  126. }, function(){
  127. module.page.designer.shortcut = true;
  128. this.close();
  129. }, null);
  130. },
  131. refreshApplication: function(){
  132. this.loadApplication()
  133. },
  134. loadIcon: function(){
  135. this.iconNode = new Element("div", {
  136. "styles": this.css.iconNode
  137. }).inject(this.node);
  138. new Element("div", {
  139. "styles": this.css.iconNodeIcon
  140. }).inject(this.iconNode);
  141. new Element("div", {
  142. "styles": this.css.iconNodeText,
  143. "text": "Application"
  144. }).inject(this.iconNode);
  145. },
  146. _loadNodeStyles: function(){
  147. this.iconNode = this.node.getElement("div").setStyles(this.css.iconNode);
  148. this.iconNode.getFirst("div").setStyles(this.css.iconNodeIcon);
  149. this.iconNode.getLast("div").setStyles(this.css.iconNodeText);
  150. },
  151. _setEditStyle_custom: function(name, input, oldValue){
  152. if (name==="componentSelected"){
  153. if (this.json.componentSelected!==oldValue){
  154. this.loadApplication();
  155. }
  156. }
  157. if (name==="componentType"){
  158. if (this.json.componentType!==oldValue){
  159. this.loadApplication();
  160. }
  161. }
  162. },
  163. openApplication: function(e){
  164. if (this.json.componentSelected && this.json.componentSelected!=="none" && this.json.componentType!=="script"){
  165. layout.desktop.openApplication(e, this.json.componentSelected);
  166. }
  167. },
  168. clean: function(){
  169. if(this.application){
  170. try{
  171. this.application.close();
  172. }catch (e) {}
  173. this.application = null;
  174. }
  175. if( this.iframe ){
  176. this.iframe.destroy();
  177. this.iframe = null;
  178. }
  179. this.destroyMask();
  180. },
  181. loadApplication: function ( ) {
  182. if(this.node)this.node.empty();
  183. this.clean();
  184. var status = this.json.statusType === "map" ? this.json.statusMapList : {};
  185. var options = this.json.optionsType === "map" ? this.json.optionsMapList : {};
  186. if (this.json.componentSelected && this.json.componentSelected!=="none" && this.json.componentType!=="script"){
  187. var componentPath = this.json.componentSelected;
  188. if( componentPath.indexOf("@url:") === 0 ){
  189. this._loadIframe( componentPath.substring(5, componentPath.length ) );
  190. }else{
  191. this._loadApplication( componentPath, status, options );
  192. }
  193. }else{
  194. this.loadIcon();
  195. }
  196. },
  197. _loadIframe: function( src ){
  198. var attr = {
  199. "src": src,
  200. "width": "100%",
  201. "height": "100%",
  202. "frameborder": "0px",
  203. "scrolling": "auto",
  204. "seamless": "seamless"
  205. };
  206. this.iframe = new Element("iframe", attr).inject( this.node );
  207. this.loadMask();
  208. },
  209. _loadApplication: function ( app, status, options ) {
  210. var clazz = MWF.xApplication;
  211. app.split(".").each(function (a) {
  212. clazz[a] = clazz[a] || {};
  213. clazz = clazz[a];
  214. });
  215. clazz.options = clazz.options || {};
  216. var _load = function () {
  217. if( clazz.Main ){
  218. var opt = options || {};
  219. opt.embededParent = new Element("div").inject(this.node);
  220. this.application = new clazz.Main(this.form.designer.desktop, opt);
  221. this.application.status = status;
  222. this.application.load();
  223. this.application.setEventTarget(this.form.designer);
  224. this.loadMask();
  225. }else{
  226. this.form.designer.notice(this.form.designer.lp.applicationNotFound+":"+app, "error");
  227. }
  228. }.bind(this);
  229. try{
  230. MWF.xDesktop.requireApp(app, "lp."+o2.language, null, false);
  231. MWF.xDesktop.requireApp(app, "Main", null, false);
  232. if (clazz.loading && clazz.loading.then){
  233. clazz.loading.then(function(){
  234. _load();
  235. });
  236. }else{
  237. _load();
  238. }
  239. }catch (e) {
  240. this.form.designer.notice( e.message, "error" );
  241. }
  242. },
  243. loadMask: function(){
  244. this.destroyMask();
  245. this.maskIframeNode = new Element("iframe.maskNode", {styles : this.css.maskIframeNode}).inject( this.node );
  246. this.maskNode = new Element("div.maskNode", {styles : this.css.maskNode}).inject( this.node );
  247. },
  248. destroyMask: function(){
  249. if(this.maskIframeNode){
  250. this.maskIframeNode.destroy();
  251. this.maskIframeNode = null;
  252. }
  253. if(this.maskNode){
  254. this.maskNode.destroy();
  255. this.maskNode = null;
  256. }
  257. },
  258. destroy: function(){
  259. this.form.moduleList.erase(this);
  260. this.form.moduleNodeList.erase(this.node);
  261. this.form.moduleElementNodeList.erase(this.node);
  262. if (this.form.scriptDesigner){
  263. this.form.scriptDesigner.removeModule(this.json);
  264. }
  265. if (this.property) this.property.destroy();
  266. this.node.destroy();
  267. this.actionArea.destroy();
  268. delete this.form.json.moduleList[this.json.id];
  269. this.json = null;
  270. delete this.json;
  271. this.treeNode.destroy();
  272. this.clean();
  273. o2.release(this);
  274. }
  275. });