Div.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. MWF.xApplication.portal.PageDesigner.Module.Div = MWF.PCDiv = new Class({
  2. Extends: MWF.FCDiv,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "propertyPath": "../x_component_portal_PageDesigner/Module/Div/div.html",
  7. "actions": [
  8. {
  9. "name": "move",
  10. "icon": "move1.png",
  11. "event": "mousedown",
  12. "action": "move",
  13. "title": MWF.APPPOD.LP.formAction.move
  14. },
  15. {
  16. "name": "copy",
  17. "icon": "copy1.png",
  18. "event": "mousedown",
  19. "action": "copy",
  20. "title": MWF.APPPOD.LP.formAction.copy
  21. },
  22. {
  23. "name": "delete",
  24. "icon": "delete1.png",
  25. "event": "click",
  26. "action": "delete",
  27. "title": MWF.APPPOD.LP.formAction["delete"]
  28. },
  29. {
  30. "name" : "makeWidget",
  31. "icon": "makeWidget1.png",
  32. "event": "click",
  33. "action": "makeWidget",
  34. "title": MWF.APPPOD.LP.formAction["makeWidget"]
  35. },
  36. {
  37. "name": "selectParent",
  38. "icon": "selectParent.png",
  39. "event": "click",
  40. "action": "selectParent",
  41. "title": MWF.APPFD.LP.formAction["selectParent"]
  42. }
  43. ]
  44. },
  45. initialize: function(form, options){
  46. this.setOptions(options);
  47. this.path = "../x_component_portal_PageDesigner/Module/Div/";
  48. this.cssPath = "../x_component_portal_PageDesigner/Module/Div/"+this.options.style+"/css.wcss";
  49. this._loadCss();
  50. this.moduleType = "container";
  51. this.moduleName = "div";
  52. this.Node = null;
  53. this.form = form;
  54. this.page = form;
  55. },
  56. loadNewWidgetData: function(name, callback){
  57. var url = "../x_component_portal_PageDesigner/Module/Page/template/page.json";
  58. MWF.getJSON(url, {
  59. "onSuccess": function(obj){
  60. obj.pcData.id="";
  61. obj.pcData.isNewPage = true;
  62. obj.pcData.json = obj.pcData.json || {};
  63. obj.pcData.json.name = name; //MWF.APPPOD.LP.formAction.defaultWidgetName;
  64. obj.pcData.json.application = this.page.designer.application.id;
  65. obj.pcData.json.applicationName = this.page.designer.application.name;
  66. obj.mobileData.id="";
  67. obj.mobileData.isNewPage = true;
  68. obj.mobileData.json = obj.mobileData.json || {};
  69. obj.mobileData.json.application = this.page.designer.application.id;
  70. obj.mobileData.json.applicationName = this.page.designer.application.name;
  71. if (callback) callback( obj );
  72. }.bind(this),
  73. "onerror": function(text){
  74. this.notice(text, "error");
  75. }.bind(this),
  76. "onRequestFailure": function(xhr){
  77. this.notice(xhr.responseText, "error");
  78. }.bind(this)
  79. });
  80. },
  81. _getWidgetData: function( data ){
  82. //var data = {
  83. // json : {
  84. // name : MWF.APPPOD.LP.formAction.defaultWidgetName,
  85. // application : this.page.designer.application.id
  86. // },
  87. // isNewPage : true
  88. //};
  89. this.page.fireEvent("queryGetPageData");
  90. var copy = this.node.clone(true, true);
  91. copy.clearStyles(true);
  92. this.page.fireEvent("postGetPageData");
  93. this.page._clearNoId(copy);
  94. var html = copy.outerHTML;
  95. if( this.page.options.mode === "Mobile" ){
  96. data.mobileData.html = "<div MWFType=\"form\" id=\"\">"+html+"</div>";
  97. data.mobileData.json.moduleList = this._getWidgetModules( copy );
  98. }else{
  99. data.pcData.html = "<div MWFType=\"form\" id=\"\">"+html+"</div>";
  100. data.pcData.json.moduleList = this._getWidgetModules( copy );
  101. //data.pcData.json.mode = "PC"; //this.page.options.mode;
  102. }
  103. copy.destroy();
  104. return data;
  105. },
  106. _getWidgetModules: function( dom ){
  107. var modules = {};
  108. var json = this.page.getDomjson(dom);
  109. modules[json.id] = json;
  110. var elements = dom.getElements("[MWFtype]");
  111. elements.each( function( el ){
  112. var json = this.page.getDomjson(el);
  113. modules[json.id] = json;
  114. }.bind(this));
  115. return modules;
  116. },
  117. _getWidgetFieldList: function( moduleList ){
  118. var dataTypes = {
  119. "string": ["htmledit", "radio", "select", "textarea", "textfield"],
  120. "person": ["personfield","org"],
  121. "date": ["calender"],
  122. "number": ["number"],
  123. "array": ["checkbox"]
  124. };
  125. fieldList = [];
  126. for( var id in moduleList ){
  127. var module = moduleList[id];
  128. var key = "";
  129. for (k in dataTypes){
  130. if (dataTypes[k].indexOf( ( module.moduleName || module.type || "" ).toLowerCase())!=-1){
  131. key = k;
  132. break;
  133. }
  134. }
  135. if (key){
  136. fieldList.push({
  137. "name": module.id,
  138. "dataType": key
  139. });
  140. }
  141. }
  142. return fieldList;
  143. },
  144. makeWidget: function(){
  145. var module = this;
  146. var url = this.path+"newWidget.html";
  147. MWF.require("MWF.widget.Dialog", function(){
  148. var size = $(document.body).getSize();
  149. var x = size.x/2-180;
  150. var y = size.y/2-100;
  151. var dlg = new MWF.DL({
  152. "title": "create widget",
  153. "style": "property",
  154. "top": y,
  155. "left": x-40,
  156. "fromTop":size.y/2-65,
  157. "fromLeft": size.x/2,
  158. "width": 360,
  159. "height": 200,
  160. "url": url,
  161. "buttonList": [
  162. {
  163. "text": MWF.APPFD.LP.button.ok,
  164. "action": function(){
  165. var widgetName = module.widgetNameInput.get("value");
  166. if( !widgetName ){
  167. module.page.designer.notice(module.page.designer.lp.notice.widgetNameEmpty, "error");
  168. return;
  169. }
  170. var appname, appid = module.appSelect.options[module.appSelect.selectedIndex].value;
  171. if(appid)appname = module.appSelect.options[module.appSelect.selectedIndex].text;
  172. var flag = true;
  173. o2.Actions.get("x_portal_assemble_designer").listWidget( appid || module.page.designer.application.id, function( json ){
  174. for( var i=0; i<json.data.length; i++ ){
  175. if( json.data[i].name === widgetName ){
  176. module.page.designer.notice(module.page.designer.lp.notice.widgetNameConflict, "error");
  177. flag = false;
  178. break;
  179. }
  180. }
  181. }.bind(this), null, false);
  182. if( flag ){
  183. module._makeWidget( widgetName, appid, appname );
  184. this.close();
  185. }
  186. }
  187. },
  188. {
  189. "text": MWF.APPFD.LP.button.cancel,
  190. "action": function(){
  191. this.close();
  192. }
  193. }
  194. ],
  195. "onPostShow": function(){
  196. o2.Actions.load("x_portal_assemble_designer").PortalAction.list(function (json) {
  197. var td = dlg.node.getElementById("MWFPortalSelect");
  198. var select = module.appSelect = new Element("select").inject(td);
  199. var option = new Element("option", {"text": ""}).inject(select);
  200. json.data.each(function(app){
  201. var option = new Element("option", {
  202. "text": app.name,
  203. "value": app.id
  204. }).inject(select);
  205. }.bind(this));
  206. });
  207. this.widgetNameInput = dlg.node.getElementById("MWFNewWidgetName");
  208. }.bind(this)
  209. });
  210. dlg.show();
  211. }.bind(this));
  212. },
  213. _makeWidget : function( name, appid, appname ){
  214. //var pcData, mobileData;
  215. //if (this.pcPage){
  216. // this.pcPage._getPageData();
  217. // pcData = this.pcPage.data;
  218. //}
  219. //if (this.mobilePage){
  220. // this.mobilePage._getPageData();
  221. // mobileData = this.mobilePage.data;
  222. //}else{
  223. // if (this.pageMobileData) mobileData = this.pageMobileData;
  224. //}
  225. this.loadNewWidgetData( name, function( obj ){
  226. var data = this._getWidgetData( obj );
  227. //var pcData = {};
  228. //var mobileData = null;
  229. //if( this.page.options.mode === "Mobile" ){
  230. // mobileData = data;
  231. //}else{
  232. //pcData = data;
  233. //}
  234. var pcData, mobileData, fieldList;
  235. if( this.page.options.mode === "Mobile" ){
  236. pcData = obj.pcData;
  237. mobileData = data.mobileData;
  238. fieldList = this._getWidgetFieldList( mobileData.json.moduleList );
  239. }else{
  240. pcData = data.pcData;
  241. mobileData = obj.mobileData;
  242. fieldList = this._getWidgetFieldList( pcData.json.moduleList );
  243. }
  244. if( appid ){
  245. if(pcData && pcData.json){
  246. pcData.json.application = appid;
  247. pcData.json.applicationName = appname;
  248. }
  249. if(mobileData && mobileData.json){
  250. mobileData.json.application = appid;
  251. mobileData.json.applicationName = appname;
  252. }
  253. }
  254. debugger;
  255. this.page.designer.actions.saveWidget(pcData, mobileData, fieldList, function(responseJSON){
  256. this.page.designer.notice(MWF.APPPOD.LP.notice["widget_save_success"], "ok", null, {x: "left", y:"bottom"});
  257. //if (!this.pcPage.json.name) this.pcPage.treeNode.setText("<"+this.json.type+"> "+this.json.id);
  258. //this.pcPage.treeNode.setTitle(this.pcPage.json.id);
  259. //this.pcPage.node.set("id", this.pcPage.json.id);
  260. //
  261. //if (this.mobilePage){
  262. // if (!this.mobilePage.json.name) this.mobilePage.treeNode.setText("<"+this.mobilePage.json.type+"> "+this.mobilePage.json.id);
  263. // this.mobilePage.treeNode.setTitle(this.mobilePage.json.id);
  264. // this.mobilePage.node.set("id", this.mobilePage.json.id+"_"+this.options.mode);
  265. //}
  266. //
  267. //var name = this.pcPage.json.name;
  268. //if (this.pcPage.data.isNewPage) this.setTitle(this.options.appTitle + "-"+name);
  269. //this.pcPage.data.isNewPage = false;
  270. //if (this.mobilePage) this.mobilePage.data.isNewPage = false;
  271. //
  272. //this.options.desktopReload = true;
  273. //this.options.id = this.pcPage.json.id;
  274. //
  275. //if (pcData) pcData.isNewPage = false;
  276. //if (mobileData) mobileData.isNewPage = false;
  277. //this.isSave = false;
  278. }.bind(this), function(xhr, text, error){
  279. this.isSave = false;
  280. var errorText = error+":"+text;
  281. if (xhr) errorText = xhr.responseText;
  282. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  283. }.bind(this));
  284. }.bind(this))
  285. }
  286. });