Div.js 7.9 KB

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