Script.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.portal = MWF.xApplication.portal || {};
  3. MWF.xApplication.portal.PageDesigner = MWF.xApplication.portal.PageDesigner || {};
  4. MWF.xDesktop.requireApp("portal.PageDesigner", "lp."+MWF.language, null, false);
  5. MWF.require("MWF.widget.JavascriptEditor", null, false);
  6. MWF.xApplication.portal.PageDesigner.Script = new Class({
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default"
  10. },
  11. initialize: function(designer, content, data, options){
  12. this.setOptions(options);
  13. this.path = "../x_component_portal_PageDesigner/$Script/";
  14. this.stylePath = "../x_component_portal_PageDesigner/$Script/"+this.options.style+"/style.css";
  15. this.viewPath = "../x_component_portal_PageDesigner/$Script/"+this.options.style+"/view.html";
  16. this.designer = designer;
  17. this.content = content;
  18. this.data = data;
  19. this.items = [];
  20. //this.categorys = {};
  21. this.moduleCategorys = {};
  22. this.pathCategorys = {};
  23. this.loadView();
  24. },
  25. loadView: function(){
  26. this.content.show();
  27. // this.content.set("load", {"onSuccess": function(){
  28. // this.node = this.content.getElement(".node");
  29. // this.listNode = this.content.getElement(".listNode");
  30. // this.listActionNode = this.content.getElement(".listActionNode");
  31. // this.actionButtons = this.content.getElements(".listActionButton");
  32. // this.listContentNode = this.content.getElement(".listContentNode");
  33. // this.separatorNode = this.content.getElement(".separatorNode");
  34. // this.scriptNode = this.content.getElement(".scriptNode");
  35. // this.scriptAreaNode = this.content.getElement(".scriptAreaNode");
  36. // this.listAreaNode = this.content.getElement(".listAreaNode");
  37. // this.scriptTabNode = this.content.getElement(".scriptTabNode");
  38. // o2.loadCss(this.stylePath, this.content, function(){
  39. // this.load();
  40. // }.bind(this));
  41. // }.bind(this)}).loadHtml(this.viewPath,{"module": this});
  42. this.content.loadHtml(this.viewPath,{"module": this}, function(){
  43. this.node = this.content.getElement(".node");
  44. this.listNode = this.content.getElement(".listNode");
  45. this.listActionNode = this.content.getElement(".listActionNode");
  46. this.actionButtons = this.content.getElements(".listActionButton");
  47. this.listContentNode = this.content.getElement(".listContentNode");
  48. this.separatorNode = this.content.getElement(".separatorNode");
  49. this.scriptNode = this.content.getElement(".scriptNode");
  50. this.scriptAreaNode = this.content.getElement(".scriptAreaNode");
  51. this.listAreaNode = this.content.getElement(".listAreaNode");
  52. this.scriptTabNode = this.content.getElement(".scriptTabNode");
  53. o2.loadCss(this.stylePath, this.content, function(){
  54. this.load();
  55. }.bind(this));
  56. }.bind(this));
  57. },
  58. load: function(){
  59. this.actionButtons[0].set("text", this.designer.lp.byModule);
  60. this.actionButtons[1].set("text", this.designer.lp.byPath);
  61. this.categoryType = "module";
  62. MWF.require("MWF.widget.Tab", null, false);
  63. this.scriptTab = new MWF.widget.Tab(this.scriptTabNode, {"style": "script"});
  64. this.scriptTab.load();
  65. this.setEvent();
  66. //form, page
  67. debugger;
  68. if (!this.data.jsheader) this.data.jsheader = {"code": "", "html": ""};
  69. this.addScriptItem(this.data.jsheader, "code", this.data, "jsheader");
  70. this.addScriptItem(this.data.css, "code", this.data, "css", "", "css");
  71. this.addScriptItem(this.data.validationOpinion, "code", this.data, "validationOpinion");
  72. this.addScriptItem(this.data.validationRoute, "code", this.data, "validationRoute");
  73. this.addScriptItem(this.data.validationFormCustom, "code", this.data, "validationFormCustom");
  74. this.addScriptItem(this.data.languageScript, "code", this.data, "languageScript");
  75. Object.each(this.data.events, function(event, key){
  76. //this.addScriptItem(event, "code", this.data, this.designer.lp.events+"."+key);
  77. this.addModuleEventScriptItem(event, "code", key, this.data);
  78. }.bind(this));
  79. Object.each(this.data.moduleList, function(v){
  80. this.createModuleScript(v);
  81. }.bind(this));
  82. },
  83. reload: function(){
  84. debugger;
  85. this.items.forEach(function(i){
  86. i.reload();
  87. });
  88. // while (this.items.length) this.items[0].destroy();
  89. // debugger;
  90. //
  91. // if (!this.data.jsheader) this.data.jsheader = {"code": "", "html": ""};
  92. // this.addScriptItem(this.data.jsheader, "code", this.data, "jsheader");
  93. // this.addScriptItem(this.data.css, "code", this.data, "css", "", "css");
  94. // this.addScriptItem(this.data.validationOpinion, "code", this.data, "validationOpinion");
  95. // this.addScriptItem(this.data.validationRoute, "code", this.data, "validationRoute");
  96. // this.addScriptItem(this.data.validationFormCustom, "code", this.data, "validationFormCustom");
  97. // Object.each(this.data.events, function(event, key){
  98. // this.addScriptItem(event, "code", this.data, this.designer.lp.events+"."+key);
  99. // }.bind(this));
  100. //
  101. // Object.each(this.data.moduleList, function(v){
  102. // this.createModuleScript(v);
  103. // }.bind(this));
  104. },
  105. createModuleScript: function(v){
  106. switch (v.type){
  107. case "Button":
  108. this.loadButtonScript(v); break;
  109. case "Calendar":
  110. this.loadCalendarScript(v); break;
  111. case "Checkbox":
  112. this.loadCheckboxScript(v); break;
  113. case "Div":
  114. this.loadDivScript(v); break;
  115. // case "Html":
  116. // this.loadHtmlScript(v); break;
  117. case "Iframe":
  118. this.loadIframeScript(v); break;
  119. case "Image":
  120. this.loadImageScript(v); break;
  121. case "Label":
  122. this.loadLabelScript(v); break;
  123. case "Personfield":
  124. this.loadPersonfieldScript(v); break;
  125. case "Org":
  126. this.loadOrgScript(v); break;
  127. case "Radio":
  128. this.loadRadioScript(v); break;
  129. case "Select":
  130. this.loadSelectScript(v); break;
  131. case "Source":
  132. this.loadSourceScript(v); break;
  133. case "SourceText":
  134. this.loadSourceTextScript(v); break;
  135. case "Stat":
  136. this.loadStatScript(v); break;
  137. case "SubSource":
  138. this.loadSubSourceScript(v); break;
  139. case "Tab$Content":
  140. this.loadTab$ContentScript(v); break;
  141. case "Tab$Page":
  142. this.loadTab$PageScript(v); break;
  143. case "Tab":
  144. this.loadTabScript(v); break;
  145. case "Table$Td":
  146. this.loadTable$TdScript(v); break;
  147. case "Table":
  148. this.loadTableScript(v); break;
  149. case "Textarea":
  150. this.loadTextareaScript(v); break;
  151. case "Textfield":
  152. this.loadTextfieldScript(v); break;
  153. case "Tree":
  154. this.loadTreeScript(v); break;
  155. case "View":
  156. this.loadViewScript(v); break;
  157. case "Actionbar":
  158. this.loadActionbarScript(v); break;
  159. case "Address":
  160. this.loadAddressScript(v); break;
  161. case "Attachment":
  162. this.loadAttachmentScript(v); break;
  163. case "Combox":
  164. this.loadComboxScript(v); break;
  165. case "Datagrid":
  166. this.loadDatagridScript(v); break;
  167. case "Datagrid$Data":
  168. this.loadDatagrid$DataScript(v); break;
  169. case "Datagrid$Title":
  170. this.loadDatagrid$TitleScript(v); break;
  171. case "Datatable":
  172. this.loadDatatableScript(v); break;
  173. case "Datatable$Data":
  174. this.loadDatatable$DataScript(v); break;
  175. case "Datatable$Title":
  176. this.loadDatatable$TitleScript(v); break;
  177. case "Datatemplate":
  178. this.loadDatatemplateScript(v); break;
  179. case "Htmleditor":
  180. this.loadHtmleditorScript(v); break;
  181. case "TinyMCEEditor":
  182. this.loadTinyMCEEditorScript(v); break;
  183. case "ImageClipper":
  184. this.loadImageClipperScript(v); break;
  185. case "WritingBoard":
  186. this.loadWritingBoardScript(v); break;
  187. case "Log":
  188. this.loadLogScript(v); break;
  189. case "Monitor":
  190. this.loadMonitorScript(v); break;
  191. case "Number":
  192. this.loadNumberScript(v); break;
  193. case "Currency":
  194. this.loadCurrencyScript(v); break;
  195. case "Office":
  196. this.loadOfficeScript(v); break;
  197. case "Opinion":
  198. this.loadOpinionScript(v); break;
  199. case "Orgfield":
  200. this.loadOrgfieldScript(v); break;
  201. case "Sidebar":
  202. this.loadSidebarScript(v); break;
  203. case "Subform":
  204. this.loadSubformScript(v); break;
  205. case "ViewSelector":
  206. this.loadViewSelectorScript(v); break;
  207. case "Statement":
  208. this.loadStatementScript(v); break;
  209. case "StatementSelector":
  210. this.loadStatementSelectorScript(v); break;
  211. case "Importer":
  212. this.loadImporterScript(v); break;
  213. case "Relatedlink":
  214. this.loadRelatedlinkScript(v); break;
  215. case "AssociatedDocument":
  216. this.loadAssociatedDocumentScript(v); break;
  217. case "Documenteditor":
  218. this.loadDocumenteditorScript(v); break;
  219. case "Common":
  220. this.loadCommonScript(v); break;
  221. case "ReadLog":
  222. this.loadEventsScript(v); break;
  223. case "WpsOffice":
  224. this.addScriptItem(v.readScript, "code", v, "readScript");
  225. this.loadEventsScript(v);
  226. break;
  227. case "YozoOffice":
  228. this.addScriptItem(v.readScript, "code", v, "readScript");
  229. this.loadEventsScript(v);
  230. break;
  231. case "Elautocomplete":
  232. this.loadVueElementScript(v, true);
  233. this.addScriptItem(v.itemScript, "code", v, "itemScript");
  234. break;
  235. case "Elbutton":
  236. this.loadVueElementScript(v); break;
  237. case "Elcheckbox":
  238. case "Elradio":
  239. this.loadVueElementScript(v, true);
  240. this.addScriptItem(v.itemScript, "code", v, "itemScript");
  241. break;
  242. case "Elcommon":
  243. this.addScriptItem(v.vueTemplate, "code", v, "vueTemplate");
  244. this.addScriptItem(v.vueApp, "code", v, "vueApp");
  245. this.addScriptItem(v.vueCss, "code", v, "vueCss");
  246. this.loadEventsScript(v);
  247. break;
  248. case "Elcontainer":
  249. case "Elcontainer$Main":
  250. case "Elcontainer$Aside":
  251. case "Elcontainer$Footer":
  252. case "Elcontainer$Header":
  253. case "Elicon":
  254. this.loadEventsScript(v); break;
  255. case "Elinput":
  256. case "Elnumber":
  257. this.loadVueElementScript(v, true); break;
  258. case "Elselect":
  259. this.loadVueElementScript(v);
  260. this.addScriptItem(v.itemScript, "code", v, "itemScript");
  261. this.addScriptItem(v.itemGroupScript, "code", v, "itemGroupScript");
  262. this.addScriptItem(v.filterMethod, "code", v, "filterMethod");
  263. this.addScriptItem(v.remoteMethod, "code", v, "remoteMethod");
  264. break;
  265. case "Elslider":
  266. this.loadVueElementScript(v, true);
  267. this.addScriptItem(v.marksScript, "code", v, "marksScript");
  268. this.addScriptItem(v.formatTooltip, "code", v, "formatTooltip");
  269. break;
  270. case "Elswitch":
  271. this.loadVueElementScript(v, true); break;
  272. case "Eltime":
  273. this.loadVueElementScript(v, true);
  274. this.addScriptItem(v.selectableRange, "code", v, "selectableRange");
  275. break;
  276. case "Eldate":
  277. this.loadVueElementScript(v, true);
  278. this.addScriptItem(v.disabledDate, "code", v, "disabledDate");
  279. break;
  280. case "Eldatetime":
  281. this.loadVueElementScript(v, true);
  282. this.addScriptItem(v.disabledDate, "code", v, "disabledDate");
  283. break;
  284. case "Elrate":
  285. this.loadVueElementScript(v, true);
  286. break;
  287. case "Elcolorpicker":
  288. this.loadVueElementScript(v, true);
  289. break;
  290. case "Eltree":
  291. this.loadVueElementScript(v, false);
  292. this.addScriptItem(v.currentNodeKey, "code", v, "currentNodeKey");
  293. this.addScriptItem(v.defaultExpandedKeys, "code", v, "defaultExpandedKeys");
  294. this.addScriptItem(v.defaultCheckedKeys, "code", v, "defaultCheckedKeys");
  295. this.addScriptItem(v.allowDrag, "code", v, "allowDrag");
  296. this.addScriptItem(v.allowDrop, "code", v, "allowDrop");
  297. break;
  298. case "Eldropdown":
  299. this.loadVueElementScript(v, false);
  300. break;
  301. case "Elcarousel":
  302. this.loadVueElementScript(v, false);
  303. this.addScriptItem(v.dataScript, "code", v, "dataScript");
  304. this.addScriptItem(v.filterScript, "code", v, "filterScript");
  305. this.addScriptItem(v.requestBody, "code", v, "requestBody");
  306. break;
  307. }
  308. this.bindDataId(v);
  309. },
  310. createCategory: function(data, path, type){
  311. var category;
  312. var cType = type || this.categoryType;
  313. if (cType==="module"){
  314. if (data.type==="Form" || data.type==="Page"){
  315. category = new MWF.xApplication.portal.PageDesigner.Script.Category(this, data.type, 0, data, "module");
  316. this.moduleCategorys[data.type] = category;
  317. }else{
  318. category = new MWF.xApplication.portal.PageDesigner.Script.Category(this, "("+data.type+")-"+data.id, 0, data, "module");
  319. this.moduleCategorys[data.id] = category;
  320. }
  321. }else{
  322. category = new MWF.xApplication.portal.PageDesigner.Script.Category(this, path, 0, data, "path");
  323. this.pathCategorys[path] = category;
  324. }
  325. return category;
  326. },
  327. bindDataId: function(data){
  328. var id = data.id;
  329. Object.defineProperty(data, "id", {
  330. configurable : true,
  331. enumerable : true,
  332. "get": function(){return id;},
  333. "set": function(v){
  334. // this.items.each(function(item){
  335. // if (item.module.id===data.id) item.resetText(v);
  336. // });
  337. Object.each(this.moduleCategorys, function(category){
  338. if (category.module.id === data.id){
  339. category.resetName("("+data.type+")-"+v, v);
  340. }
  341. });
  342. id = v;
  343. //category.resetName(category.name.replace(/\-.*/, "-"+v));
  344. }.bind(this)
  345. });
  346. },
  347. loadButtonScript: function(data){
  348. this.loadEventsScript(data);
  349. },
  350. loadCalendarScript: function(data){
  351. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  352. this.addScriptItem(data.validation, "code", data, "validation");
  353. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  354. this.addScriptItem(data.dateTimeRangeScript, "code", data, "dateTimeRangeScript");
  355. this.addScriptItem(data.dateRangeScript, "code", data, "dateRangeScript");
  356. this.addScriptItem(data.timeRangeScript, "code", data, "timeRangeScript");
  357. this.addScriptItem(data.enableDate, "code", data, "enableDate");
  358. this.addScriptItem(data.enableHours, "code", data, "enableHours");
  359. this.addScriptItem(data.enableMinutes, "code", data, "enableMinutes");
  360. this.addScriptItem(data.enableSeconds, "code", data, "enableSeconds");
  361. this.loadEventsScript(data);
  362. },
  363. loadCheckboxScript: function(data){
  364. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  365. this.addScriptItem(data.itemScript, "code", data, "itemScript");
  366. this.addScriptItem(data.validation, "code", data, "validation");
  367. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  368. this.loadEventsScript(data);
  369. },
  370. loadDivScript: function(data){
  371. this.loadEventsScript(data);
  372. },
  373. loadIframeScript: function(data){
  374. this.addScriptItem(data.script, "code", data, "iframeScript");
  375. this.loadEventsScript(data);
  376. },
  377. loadImageScript: function(data){
  378. this.loadEventsScript(data);
  379. },
  380. loadLabelScript: function(data){
  381. this.addScriptItem(data.script, "code", data, "labelScript");
  382. this.loadEventsScript(data);
  383. },
  384. loadPersonfieldScript: function(data){
  385. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  386. this.addScriptItem(data.validation, "code", data, "validation");
  387. this.addScriptItem(data.rangeKey, "code", data, "rangeKey");
  388. this.addScriptItem(data.rangeDutyKey, "code", data, "rangeDutyKey");
  389. this.addScriptItem(data.exclude, "code", data, "exclude");
  390. this.addScriptItem(data.rangeKey, "code", data, "sectionByScript");
  391. this.loadEventsScript(data);
  392. },
  393. loadOrgScript: function(data){
  394. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  395. this.addScriptItem(data.validation, "code", data, "validation");
  396. this.addScriptItem(data.identityRangeKey, "code", data, "identityRangeKey");
  397. this.addScriptItem(data.unitRangeKey, "code", data, "unitRangeKey");
  398. this.addScriptItem(data.rangeDutyKey, "code", data, "rangeDutyKey");
  399. this.addScriptItem(data.exclude, "code", data, "exclude");
  400. this.addScriptItem(data.rangeKey, "code", data, "sectionByScript");
  401. this.loadEventsScript(data);
  402. },
  403. loadRadioScript: function(data){
  404. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  405. this.addScriptItem(data.itemScript, "code", data, "itemScript");
  406. this.addScriptItem(data.validation, "code", data, "validation");
  407. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  408. this.loadEventsScript(data);
  409. },
  410. loadSelectScript: function(data){
  411. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  412. this.addScriptItem(data.itemScript, "code", data, "itemScript");
  413. this.addScriptItem(data.validation, "code", data, "validation");
  414. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  415. this.loadEventsScript(data);
  416. },
  417. loadSourceScript: function(data){
  418. this.addScriptItem(data.cookies, "code", data, "cookies");
  419. this.addScriptItem(data.requestBody, "code", data, "requestBody");
  420. this.loadEventsScript(data);
  421. },
  422. loadSourceTextScript: function(data){
  423. this.addScriptItem(data.jsonText, "code", data, "jsonText");
  424. this.loadEventsScript(data);
  425. },
  426. loadStatScript: function(data){
  427. this.loadEventsScript(data);
  428. },
  429. loadSubSourceScript: function(data){
  430. this.loadEventsScript(data);
  431. },
  432. loadTabScript: function(data){
  433. this.loadEventsScript(data);
  434. },
  435. loadTab$PageScript: function(data){
  436. this.loadEventsScript(data);
  437. },
  438. loadTab$ContentScript: function(data){
  439. this.loadEventsScript(data);
  440. },
  441. loadTableScript: function(data){
  442. this.loadEventsScript(data);
  443. },
  444. loadTable$TdScript: function(data){
  445. this.loadEventsScript(data);
  446. },
  447. loadTextareaScript: function(data){
  448. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  449. this.addScriptItem(data.validation, "code", data, "validation");
  450. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  451. this.loadEventsScript(data);
  452. },
  453. loadTextfieldScript: function(data){
  454. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  455. this.addScriptItem(data.validation, "code", data, "validation");
  456. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  457. this.loadEventsScript(data);
  458. },
  459. loadTreeScript: function(data){
  460. this.addScriptItem(data.dataScript, "code", data, "dataScript");
  461. this.loadEventsScript(data);
  462. },
  463. loadViewScript: function(data){
  464. this.loadEventsScript(data);
  465. },
  466. loadRelatedlinkScript: function(data){
  467. this.addScriptItem(data.displayScript, "code", data, "displayScript");
  468. this.loadEventsScript(data);
  469. },
  470. loadAssociatedDocumentScript:function(data){
  471. this.addScriptItem(data.textStyleScript, "code", data, "textStyleScript");
  472. this.addScriptItem(data.displayScript, "code", data, "displayScript");
  473. this.loadEventsScript(data);
  474. },
  475. loadImporterScript: function(data){
  476. this.addScriptItem(data.excelName, "code", data, "excelName");
  477. this.loadEventsScript(data);
  478. },
  479. loadDocumenteditorScript: function(data){
  480. this.addScriptItem(data.allowEditScript, "code", data, "allowEditScript");
  481. this.addScriptItem(data.allowPrintScript, "code", data, "allowPrintScript");
  482. this.addScriptItem(data.allowHistoryScript, "code", data, "allowHistoryScript");
  483. this.addScriptItem(data.css, "code", data, "css", "css");
  484. this.addScriptItem(data.validation, "code", data, "validation");
  485. this.addScriptItem(data.ckeditConfigOptions, "code", data, "ckeditConfigOptions");
  486. this.addScriptItem(data.copiesSecretPriorityShowScript, "code", data, "copiesSecretPriorityShowScript");
  487. this.addScriptItem(data.copiesShowScript, "code", data, "copiesShowScript");
  488. this.addScriptItem(data.copiesValueScript, "code", data, "copiesValueScript");
  489. this.addScriptItem(data.secretShowScript, "code", data, "secretShowScript");
  490. this.addScriptItem(data.secretValueScript, "code", data, "secretValueScript");
  491. this.addScriptItem(data.priorityShowScript, "code", data, "priorityShowScript");
  492. this.addScriptItem(data.priorityValueScript, "code", data, "priorityValueScript");
  493. this.addScriptItem(data.redHeaderShowScript, "code", data, "redHeaderShowScript");
  494. this.addScriptItem(data.redHeaderValueScript, "code", data, "redHeaderValueScript");
  495. this.addScriptItem(data.redLineShowScript, "code", data, "redLineShowScript");
  496. this.addScriptItem(data.filenoShowScript, "code", data, "filenoShowScript");
  497. this.addScriptItem(data.filenoValueScript, "code", data, "filenoValueScript");
  498. this.addScriptItem(data.signerShowScript, "code", data, "signerShowScript");
  499. this.addScriptItem(data.signerValueScript, "code", data, "signerValueScript");
  500. this.addScriptItem(data.subjectShowScript, "code", data, "subjectShowScript");
  501. this.addScriptItem(data.subjectEditScript, "code", data, "subjectEditScript");
  502. this.addScriptItem(data.subjectValueScript, "code", data, "subjectValueScript");
  503. this.addScriptItem(data.mainSendShowScript, "code", data, "mainSendShowScript");
  504. this.addScriptItem(data.mainSendValueScript, "code", data, "mainSendValueScript");
  505. this.addScriptItem(data.attachmentShowScript, "code", data, "attachmentShowScript");
  506. this.addScriptItem(data.attachmentValueScript, "code", data, "attachmentValueScript");
  507. this.addScriptItem(data.attachmentTextEditScript, "code", data, "attachmentTextEditScript");
  508. this.addScriptItem(data.issuanceUnitShowScript, "code", data, "issuanceUnitShowScript");
  509. this.addScriptItem(data.issuanceUnitEditScript, "code", data, "issuanceUnitEditScript");
  510. this.addScriptItem(data.issuanceUnitValueScript, "code", data, "issuanceUnitValueScript");
  511. this.addScriptItem(data.issuanceDateShowScript, "code", data, "issuanceDateShowScript");
  512. this.addScriptItem(data.issuanceDateValueScript, "code", data, "issuanceDateValueScript");
  513. this.addScriptItem(data.annotationShowScript, "code", data, "annotationShowScript");
  514. this.addScriptItem(data.annotationValueScript, "code", data, "annotationValueScript");
  515. this.addScriptItem(data.copytoShowScript, "code", data, "copytoShowScript");
  516. this.addScriptItem(data.copytoValueScript, "code", data, "copytoValueScript");
  517. this.addScriptItem(data.copyto2ShowScript, "code", data, "copyto2ShowScript");
  518. this.addScriptItem(data.copyto2ValueScript, "code", data, "copyto2ValueScript");
  519. this.addScriptItem(data.editionUnitShowScript, "code", data, "editionUnitShowScript");
  520. this.addScriptItem(data.editionUnitValueScript, "code", data, "editionUnitValueScript");
  521. this.addScriptItem(data.editionDateShowScript, "code", data, "editionDateShowScript");
  522. this.addScriptItem(data.editionDateValueScript, "code", data, "editionDateValueScript");
  523. this.addScriptItem(data.meetingAttendShowScript, "code", data, "meetingAttendShowScript");
  524. this.addScriptItem(data.meetingAttendValueScript, "code", data, "meetingAttendValueScript");
  525. this.addScriptItem(data.meetingLeaveShowScript, "code", data, "meetingLeaveShowScript");
  526. this.addScriptItem(data.meetingLeaveValueScript, "code", data, "meetingLeaveValueScript");
  527. this.addScriptItem(data.meetingSitShowScript, "code", data, "meetingSitShowScript");
  528. this.addScriptItem(data.meetingSitValueScript, "code", data, "meetingSitValueScript");
  529. this.loadEventsScript(data);
  530. },
  531. loadCommonScript: function(data){
  532. this.loadEventsScript(data);
  533. },
  534. loadActionbarScript: function(data){
  535. if (data.tools){
  536. data.tools.each(function(tool){
  537. var item = this.addScriptItem(tool, "actionScript", data, "action.tools", tool.text);
  538. this.bindActionbarToolText(tool, item);
  539. }.bind(this));
  540. }
  541. },
  542. bindActionbarToolText: function(tool, item){
  543. var toolItem = item;
  544. var text = tool.text;
  545. Object.defineProperty(tool, "text", {
  546. configurable : true,
  547. enumerable : true,
  548. "get": function(){return text;},
  549. "set": function(v){
  550. if (toolItem){
  551. toolItem.par = v;
  552. toolItem.resetText();
  553. }
  554. text = v;
  555. }.bind(this)
  556. });
  557. },
  558. loadAddressScript: function(data){
  559. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  560. this.addScriptItem(data.validation, "code", data, "validation");
  561. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  562. this.loadEventsScript(data);
  563. },
  564. loadAttachmentScript: function(data){
  565. this.addScriptItem(data.validation, "code", data, "validation");
  566. this.loadEventsScript(data);
  567. },
  568. loadComboxScript: function(data){
  569. this.addScriptItem(data.itemScript, "code", data, "itemScript");
  570. this.addScriptItem(data.itemDynamic, "code", data, "itemDynamic");
  571. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  572. this.addScriptItem(data.validation, "code", data, "validation");
  573. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  574. this.loadEventsScript(data);
  575. },
  576. loadDatagridScript: function(data){
  577. this.addScriptItem(data.defaultData, "code", data, "defaultData");
  578. this.addScriptItem(data.editableScript, "code", data, "editableScript");
  579. this.addScriptItem(data.validation, "code", data, "validation");
  580. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  581. this.addScriptItem(data.excelName, "code", data, "excelName");
  582. this.loadEventsScript(data);
  583. },
  584. loadDatagrid$DataScript: function(data){ this.loadEventsScript(data); },
  585. loadDatagrid$TitleScript: function(data){ this.loadEventsScript(data); },
  586. loadDatatableScript: function(data){
  587. this.addScriptItem(data.defaultData, "code", data, "defaultData");
  588. this.addScriptItem(data.editableScript, "code", data, "editableScript");
  589. this.addScriptItem(data.validation, "code", data, "validation");
  590. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  591. this.addScriptItem(data.excelName, "code", data, "excelName");
  592. this.loadEventsScript(data);
  593. },
  594. loadDatatable$DataScript: function(data){ this.loadEventsScript(data); },
  595. loadDatatable$TitleScript: function(data){ this.loadEventsScript(data); },
  596. loadDatatemplateScript: function(data){
  597. this.addScriptItem(data.defaultData, "code", data, "defaultData");
  598. this.addScriptItem(data.editableScript, "code", data, "editableScript");
  599. this.addScriptItem(data.validation, "code", data, "validation");
  600. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  601. this.addScriptItem(data.excelName, "code", data, "excelName");
  602. this.loadEventsScript(data);
  603. },
  604. loadHtmleditorScript: function(data){
  605. this.addScriptItem(data.config, "code", data, "config");
  606. this.loadEventsScript(data);
  607. },
  608. loadTinyMCEEditorScript: function(data){
  609. this.addScriptItem(data.config, "code", data, "config");
  610. this.loadEventsScript(data);
  611. },
  612. loadImageClipperScript: function(data){ this.loadEventsScript(data); },
  613. loadWritingBoardScript: function(data){ this.loadEventsScript(data); },
  614. loadLogScript: function(data){
  615. this.addScriptItem(data.filterScript, "code", data, "filterScript");
  616. this.loadEventsScript(data);
  617. },
  618. loadMonitorScript: function(data){ this.loadEventsScript(data); },
  619. loadNumberScript: function(data){
  620. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  621. this.addScriptItem(data.validation, "code", data, "validation");
  622. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  623. this.loadEventsScript(data);
  624. },
  625. loadCurrencyScript: function(data){
  626. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  627. this.addScriptItem(data.validation, "code", data, "validation");
  628. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  629. this.loadEventsScript(data);
  630. },
  631. loadOfficeScript: function(data){
  632. this.addScriptItem(data.readScript, "code", data, "readScript");
  633. this.addScriptItem(data.fileSite, "code", data, "fileSite");
  634. this.loadEventsScript(data);
  635. },
  636. loadOpinionScript: function(data){
  637. this.addScriptItem(data.validation, "code", data, "validation");
  638. this.loadEventsScript(data);
  639. },
  640. loadOrgfieldScript: function(data){
  641. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  642. this.addScriptItem(data.validation, "code", data, "validation");
  643. this.addScriptItem(data.rangeKey, "code", data, "rangeKey");
  644. this.addScriptItem(data.exclude, "code", data, "exclude");
  645. this.addScriptItem(data.rangeKey, "code", data, "sectionByScript");
  646. this.loadEventsScript(data);
  647. },
  648. loadSidebarScript: function(data){
  649. if (data.tools){
  650. data.tools.each(function(tool){
  651. var item = this.addScriptItem(tool, "actionScript", data, "action.tools", tool.text);
  652. this.bindActionbarToolText(tool, item);
  653. }.bind(this));
  654. }
  655. },
  656. loadSubformScript: function(data){
  657. this.addScriptItem(data.subformScript, "code", data, "subformScript");
  658. this.loadEventsScript(data);
  659. },
  660. loadViewSelectorScript: function(data){
  661. this.addScriptItem(data.selectedScript, "code", data, "selectedScript");
  662. this.loadEventsScript(data);
  663. },
  664. loadStatementScript: function(data){
  665. this.loadEventsScript(data);
  666. },
  667. loadStatementSelectorScript: function(data){
  668. this.addScriptItem(data.selectedScript, "code", data, "selectedScript");
  669. },
  670. loadVueElementScript: function(data, isField){
  671. if (isField){
  672. this.addScriptItem(data.defaultValue, "code", data, "defaultValue");
  673. this.addScriptItem(data.validation, "code", data, "validation");
  674. this.addScriptItem(data.sectionByScript, "code", data, "sectionByScript");
  675. }
  676. this.addScriptItem(data.vueData, "code", data, "vueData");
  677. this.addScriptItem(data.vueMethods, "code", data, "vueMethods");
  678. this.addScriptItem(data.vueCss, "code", data, "vueCss", "css");
  679. this.loadEventsScript(data);
  680. },
  681. loadEventsScript: function(data){
  682. Object.each(data.events, function(event, key){
  683. this.addModuleEventScriptItem(event, "code", key, data);
  684. }.bind(this));
  685. },
  686. addScriptItem: function(data, key, module, path, par, mode){
  687. //if (!data) data = {};
  688. if (!module[path]) module[path] = {};
  689. data = module[path];
  690. var item = new MWF.xApplication.portal.PageDesigner.Script.Item(this, data, key, module, path, par, mode);
  691. this.items.push(item);
  692. return item;
  693. },
  694. addModuleEventScriptItem: function(event, key, eventName, data, par){
  695. var item = new MWF.xApplication.portal.PageDesigner.Script.Item(this, event, key, data, this.designer.lp.events+"."+eventName, par);
  696. this.items.push(item);
  697. return item;
  698. },
  699. deleteScriptItem: function(module, path, par){
  700. var category = this.moduleCategorys[module.id];
  701. if (category){
  702. var count = category.items.length;
  703. for (var i=0; i<count; i++){
  704. var item = category.items[i];
  705. if (item.module.id===module.id && item.path===path && ((par) ? item.par===par : true) ){
  706. item.destroy();
  707. i--; count--;
  708. }
  709. }
  710. }
  711. },
  712. setSize: function(){
  713. var size = this.content.getSize();
  714. var paddings = this.listAreaNode.getStyles("padding-top", "padding-bottom");
  715. var margins = this.listNode.getStyles("margin-top", "margin-bottom");
  716. var actionSize = this.listActionNode.getSize();
  717. var actionMargins = this.listActionNode.getStyles("margin-top", "margin-bottom");
  718. var h = size.y-paddings["padding-top"].toFloat()-paddings["padding-bottom"].toFloat()-margins["margin-top"].toFloat()-margins["margin-bottom"].toFloat()-5;
  719. this.separatorNode.setStyle("height", ""+h+"px");
  720. h = h-actionSize.y-actionMargins["margin-top"].toFloat()-actionMargins["margin-bottom"].toFloat();
  721. this.listNode.setStyle("height", ""+h+"px");
  722. //var scriptSize = this.scriptAreaNode.getSize();
  723. paddings = this.scriptAreaNode.getStyles("padding-top", "padding-bottom");
  724. margins = this.scriptNode.getStyles("margin-top", "margin-bottom");
  725. h = size.y-paddings["padding-top"].toFloat()-paddings["padding-bottom"].toFloat()-margins["margin-top"].toFloat()-margins["margin-bottom"].toFloat();
  726. this.scriptNode.setStyle("height", ""+h+"px");
  727. if (this.scriptTab) this.scriptTab.resize();
  728. // var tabSize = this.scriptTab.tabNodeContainer.getComputedSize();
  729. // var tabMarginTop = this.scriptTab.tabNodeContainer.getStyle("margin-top").toFloat();
  730. // var tabMarginBottom = this.scriptTab.tabNodeContainer.getStyle("margin-bottom").toFloat();
  731. // h = h-tabSize.totalHeight-tabMarginTop-tabMarginBottom;
  732. // this.scriptTab.contentNodeContainer.setStyle("height", ""+h+"px");
  733. },
  734. changeCategoryType: function(e){
  735. if (!e.target.hasClass("listActionButton_select")){
  736. this.actionButtons.removeClass("listActionButton_select");
  737. e.target.addClass("listActionButton_select");
  738. if (this.categoryType === "module"){
  739. this.changeCategoryTypeToPath();
  740. }else{
  741. this.changeCategoryTypeToModule();
  742. }
  743. }
  744. },
  745. changeCategoryTypeToPath: function(){
  746. this.categoryType = "path";
  747. this.items.each(function(item){ item.relocation(); }.bind(this));
  748. },
  749. changeCategoryTypeToModule: function(){
  750. this.categoryType = "module";
  751. this.items.each(function(item){ item.relocation(); }.bind(this));
  752. },
  753. setEvent: function(){
  754. this.setSize();
  755. this.setSizeFun = this.setSize.bind(this);
  756. this.designer.addEvent("resize", this.setSizeFun);
  757. this.actionButtons.addEvents({
  758. "click": function(e){
  759. this.changeCategoryType(e);
  760. }.bind(this)
  761. });
  762. new Drag(this.separatorNode, {
  763. "snap": 1,
  764. "onStart": function(el, e){
  765. var x = (Browser.name==="firefox") ? e.event.clientX : e.event.x;
  766. var y = (Browser.name==="firefox") ? e.event.clientY : e.event.y;
  767. el.store("position", {"x": x, "y": y});
  768. var size = this.listNode.getSize();
  769. el.store("initialWidth", size.x);
  770. }.bind(this),
  771. "onDrag": function(el, e){
  772. var x = (Browser.name==="firefox") ? e.event.clientX : e.event.x;
  773. // var y = e.event.y;
  774. var bodySize = this.content.getSize();
  775. var position = el.retrieve("position");
  776. var initialWidth = el.retrieve("initialWidth").toFloat();
  777. var dx =x.toFloat()- position.x.toFloat();
  778. var width = initialWidth+dx;
  779. if (width> bodySize.x/2) width = bodySize.x/2;
  780. if (width<40) width = 40;
  781. this.scriptAreaNode.setStyle("margin-left", width+3);
  782. this.listAreaNode.setStyle("width", width);
  783. if (this.jsEditor) this.jsEditor.resize();
  784. }.bind(this)
  785. });
  786. },
  787. createScriptEditor: function(callback){
  788. this.jsEditor = new MWF.widget.JavascriptEditor(this.scriptNode,{
  789. "option": {
  790. "value": "",
  791. "lineNumbers": true
  792. },
  793. "onPostLoad": function(){
  794. this.editor = this.jsEditor.editor;
  795. this.jsEditor.addEditorEvent("change", function() {
  796. this.fireEvent("change");
  797. }.bind(this));
  798. this.jsEditor.addEditorEvent("blur", function() {
  799. this.fireEvent("blur");
  800. }.bind(this));
  801. // this.editor.on("change", function() {
  802. // this.fireEvent("change");
  803. // }.bind(this));
  804. this.jsEditor.resize();
  805. if (callback) callback();
  806. this.fireEvent("postLoad");
  807. }.bind(this),
  808. "onSave": function(){
  809. this.fireEvent("change");
  810. this.fireEvent("save");
  811. }.bind(this)
  812. });
  813. this.jsEditor.load();
  814. },
  815. removeModule: function(data){
  816. var count = this.items.length;
  817. for (var i=0; i<count; i++){
  818. var item = this.items[i];
  819. if (item.module.id===data.id){
  820. item.destroy();
  821. i--; count--;
  822. }
  823. }
  824. var keys = Object.keys(this.moduleCategorys);
  825. keys.each(function(k){
  826. var category = this.moduleCategorys[k];
  827. if (category) if (category.module.id===data.id) category.destroy();
  828. }.bind(this));
  829. keys = Object.keys(this.pathCategorys);
  830. keys.each(function(k){
  831. var category = this.pathCategorys[k];
  832. if (category) if (!category.childrenNode.getFirst()) category.destroy();
  833. }.bind(this));
  834. // Object.each(this.pathCategorys, function(category){
  835. // if (!category.childrenNode.getFirst()) category.destroy();
  836. // }.bind(this));
  837. },
  838. checkCategorys: function(){
  839. var keys = Object.keys(this.moduleCategorys);
  840. keys.each(function(k){
  841. var category = this.moduleCategorys[k];
  842. if (category) if (!category.items.length) category.destroy(k);
  843. }.bind(this));
  844. keys = Object.keys(this.pathCategorys);
  845. keys.each(function(k){
  846. var category = this.pathCategorys[k];
  847. if (category) if (!category.childrenNode.getFirst()) category.destroy(k);
  848. }.bind(this));
  849. }
  850. });
  851. MWF.xApplication.portal.PageDesigner.Script.Category = new Class({
  852. initialize: function(script, name, level, module, type){
  853. this.script = script;
  854. this.name = name;
  855. this.module = module;
  856. this.level = level;
  857. this.type = type;
  858. this.items = [];
  859. this.load();
  860. },
  861. load: function(){
  862. var name = "";
  863. if (this.type==="path"){
  864. name = this.script.designer.lp.scriptTitle[this.name] || this.name;
  865. }else{
  866. var t;
  867. if (this.module.type==="Form" || this.module.type==="Page"){
  868. t = this.script.designer.lp.pageform;
  869. }else{
  870. t = this.module.type.toLowerCase();
  871. var tool = this.script.designer.toolsData[t];
  872. t = (tool) ? tool.text : t;
  873. }
  874. name = this.name.replace(/\(.*\)/, "("+t+")");
  875. }
  876. this.script.listContentNode.appendHTML("<div class='itemCategory'><div class='itemCategoryTitle'>" +
  877. "<div class='itemCategoryTitleIcon'></div><div class='itemCategoryTitleName' title='"+this.name+"'>"+name+"</div>" +
  878. "</div><div class='itemCategoryChildren'></div></div>");
  879. this.node = this.script.listContentNode.getLast();
  880. //this.blankNode = this.node.getElement(".itemCategoryTitleBlank");
  881. this.titleNode = this.node.getElement(".itemCategoryTitle");
  882. this.iconNode = this.node.getElement(".itemCategoryTitleIcon");
  883. this.nameNode = this.node.getElement(".itemCategoryTitleName");
  884. this.childrenNode = this.node.getElement(".itemCategoryChildren");
  885. var marginLeft = this.level.toInt()*10;
  886. this.node.setStyle("margin-left", ""+marginLeft+"px");
  887. this.titleNode.addEvents({
  888. "mouseover": function(){this.addClass("itemCategoryTitle_over");},
  889. "mouseout": function(){this.removeClass("itemCategoryTitle_over");},
  890. "click": function(){ this.toggle(); }.bind(this)
  891. });
  892. },
  893. hide: function(){
  894. this.node.hide();
  895. },
  896. show: function(){
  897. this.node.show();
  898. },
  899. toggle: function(){
  900. ((this.isExpand) ? this.collapse : this.expand).apply(this);
  901. },
  902. expand: function(){
  903. this.childrenNode.show();
  904. this.iconNode.addClass("itemCategoryTitleIcon_expand");
  905. this.isExpand = true;
  906. },
  907. collapse: function(){
  908. this.childrenNode.hide();
  909. this.iconNode.removeClass("itemCategoryTitleIcon_expand");
  910. this.isExpand = false;
  911. },
  912. resetName: function(name, id){
  913. delete this.script.moduleCategorys[this.module.id];
  914. this.script.moduleCategorys[id] = this;
  915. this.name = name;
  916. this.nameNode.set({"text": this.name, "title": this.name});
  917. this.items.each(function(item){
  918. item.resetText(id);
  919. }.bind(this));
  920. },
  921. destroy: function(k){
  922. delete this.script.moduleCategorys[k];
  923. delete this.script.pathCategorys[k];
  924. this.node.destroy();
  925. this.script.checkCategorys();
  926. MWF.release(this);
  927. }
  928. });
  929. MWF.xApplication.portal.PageDesigner.Script.Item = new Class({
  930. initialize: function(script, data, key, module, path, par, mode){
  931. this.script = script;
  932. this.data = data;
  933. this.key = key;
  934. this.module = module;
  935. this.path = path;
  936. this.text = path;
  937. this.par = par;
  938. this.mode = mode;
  939. this.bind();
  940. if (this.data[this.key]) this.createNode();
  941. },
  942. reload: function(){
  943. // if (this.value){
  944. if (this.data[this.key]){
  945. if (!this.node) this.createNode();
  946. //if (this.isShow)
  947. if (this.jsEditor){
  948. this.jsEditor.setValue(this.value);
  949. //this.editor.session.setValue(this.value);
  950. //this.jsEditor.node.show();
  951. }
  952. }
  953. // }else{
  954. // if (this.node) this.node.destroy();
  955. // if (this.isShow){
  956. // if (this.script.editor){
  957. // this.script.editor.setValue("");
  958. // this.script.jsEditor.node.hide();
  959. // }
  960. // this.isShow = false;
  961. // }
  962. // }
  963. },
  964. unShow: function(){
  965. if (this.script.editor){
  966. this.value.code = this.script.editor.getValue()
  967. }
  968. this.isShow = false;
  969. this.script.currentItem = null;
  970. },
  971. getCategory: function(){
  972. var category = null;
  973. if (this.script.categoryType==="module"){
  974. category = this.script.moduleCategorys[(this.module.type==="Form" || this.module.type==="Page") ? this.module.type : this.module.id];
  975. }else{
  976. category = this.script.pathCategorys[this.path];
  977. }
  978. return category || this.script.createCategory(this.module, this.path);
  979. },
  980. getText: function(id){
  981. var moduleId = id || this.module.id;
  982. var text = this.script.designer.lp.scriptTitle[this.path] || this.path;
  983. text = ((this.module.type==="Form" || this.module.type==="Page") ? this.module.type : moduleId) + ":" + text;
  984. if (this.par) text = text+"."+this.par;
  985. return text;
  986. },
  987. relocation: function(){
  988. if (this.node){
  989. if (this.category) this.category.hide();
  990. this.category = this.getCategory();
  991. this.category.show();
  992. this.text = this.getText();
  993. this.node.inject(this.category.childrenNode);
  994. }
  995. },
  996. createNode: function(){
  997. this.category = this.getCategory();
  998. this.category.show();
  999. this.text = this.getText();
  1000. this.category.childrenNode.appendHTML("<div class='item'><div class='itemIcon'></div><div class='itemText' title='"+this.text+"'>"+this.text +"</div></div>");
  1001. this.node = this.category.childrenNode.getLast();
  1002. this.node.addEvents({
  1003. "mouseover": function(){this.addClass("item_over");},
  1004. "mouseout": function(){this.removeClass("item_over");},
  1005. "click": function(){ this.selected(); }.bind(this)
  1006. });
  1007. if (this.script.categoryType==="module"){
  1008. this.category.items.push(this);
  1009. }else{
  1010. var category = this.script.moduleCategorys[(this.module.type==="Form" || this.module.type==="Page") ? this.module.type : this.module.id];
  1011. if (!category) category = this.script.createCategory(this.module, this.path, "module");
  1012. category.items.push(this);
  1013. }
  1014. },
  1015. resetText: function(id){
  1016. this.text = this.getText(id);
  1017. if (this.node) this.node.getLast().set({"text": this.text, "title": this.text});
  1018. if (this.scriptPage){
  1019. this.scriptPage.options.title = this.text;
  1020. var title = this.scriptPage.textNode.get("text");
  1021. var text = this.text;
  1022. if (title.substr(0,1)==="*") text = "*"+text;
  1023. this.scriptPage.textNode.set("text", text);
  1024. }
  1025. },
  1026. unselected: function(){
  1027. this.node.removeClass("item_select");
  1028. this.node.getLast().removeClass("itemText_select");
  1029. this.isShow = false;
  1030. this.script.currentItem = null;
  1031. },
  1032. selected: function(){
  1033. if (this.script.currentItem) this.script.currentItem.unselected();
  1034. this.node.addClass("item_select");
  1035. this.node.getLast().addClass("itemText_select");
  1036. this.isShow = true;
  1037. this.script.currentItem = this;
  1038. this.showScript();
  1039. // if (this.module.type==="Form" || this.module.type==="Page"){
  1040. // (this.script.designer.form || this.script.designer.page).selected();
  1041. // }else{
  1042. // var list = (this.script.designer.form || this.script.designer.page).moduleList;
  1043. // var module = null;
  1044. // for (var i=0; i<list.length; i++){
  1045. // if (list[i].json.id===this.module.id){
  1046. // module = list[i];
  1047. // break;
  1048. // }
  1049. // }
  1050. // if (module) module.selected();
  1051. // }
  1052. var module = this.getFormModule();
  1053. if (module) module.selected();
  1054. },
  1055. getFormModule: function(){
  1056. if (this.module.type==="Form" || this.module.type==="Page"){
  1057. return (this.script.designer.form || this.script.designer.page);
  1058. }else{
  1059. var list = (this.script.designer.form || this.script.designer.page).moduleList;
  1060. var module = null;
  1061. for (var i=0; i<list.length; i++){
  1062. if (list[i].json.id===this.module.id){
  1063. module = list[i];
  1064. break;
  1065. }
  1066. }
  1067. return module;
  1068. }
  1069. },
  1070. save: function(){
  1071. this.script.designer.saveForm();
  1072. },
  1073. change: function(){
  1074. var oldValue = Object.clone(this.data);
  1075. this.data[this.key] = this.jsEditor.getValue();
  1076. this.checkHistory(this.path, oldValue );
  1077. },
  1078. checkHistory: function(name, oldValue){
  1079. var form = (this.script.designer.form || this.script.designer.page), module;
  1080. if( form.history ){
  1081. if (this.module.type==="Form" || this.module.type==="Page"){
  1082. module = form;
  1083. }else{
  1084. var moduleNode = form.container.getElement("#"+this.module.id);
  1085. if(moduleNode) module = moduleNode.retrieve("module")
  1086. }
  1087. if(module){
  1088. if( name.indexOf(this.script.designer.lp.events+".") === 0){
  1089. name = "events." + name.replace(this.script.designer.lp.events+".", "");
  1090. }
  1091. var newValue = "";
  1092. switch (typeOf(this.data)) {
  1093. case "object":
  1094. newValue = Object.clone(this.data);
  1095. break;
  1096. case "string":
  1097. newValue = this.data;
  1098. break;
  1099. }
  1100. module.checkPropertyHistory(name, oldValue, newValue, true);
  1101. }
  1102. }
  1103. },
  1104. setSize: function(){
  1105. var size = this.script.scriptTabNode.getComputedSize();
  1106. var tabSize = this.script.scriptTab.tabNodeContainer.getComputedSize();
  1107. var tabMarginTop = this.script.scriptTab.tabNodeContainer.getStyle("margin-top").toFloat();
  1108. var tabMarginBottom = this.script.scriptTab.tabNodeContainer.getStyle("margin-bottom").toFloat();
  1109. var h = size.height-tabSize.totalHeight-tabMarginTop-tabMarginBottom;
  1110. this.scriptPageNode.setStyle("height", ""+h+"px");
  1111. if (this.jsEditor) this.jsEditor.resize();
  1112. },
  1113. createScriptEditor: function(){
  1114. this.scriptPageNode = new Element("div");
  1115. this.setSizeFun = this.setSize.bind(this);
  1116. this.setSizeFun();
  1117. this.script.designer.addEvent("resize", this.setSizeFun);
  1118. var text = this.getText();
  1119. this.scriptPage = this.script.scriptTab.addTab(this.scriptPageNode, text, true);
  1120. this.scriptPage.scriptItem = this;
  1121. this.scriptContentNode = new Element("div.scriptContentNode").inject(this.scriptPageNode);
  1122. this.jsEditor = new MWF.widget.JavascriptEditor(this.scriptContentNode,{
  1123. "option": {
  1124. "value": this.data[this.key],
  1125. "lineNumbers": true,
  1126. "mode": this.mode || "javascript"
  1127. },
  1128. "onPostLoad": function(){
  1129. this.editor = this.jsEditor.editor;
  1130. this.editor.id = "1";
  1131. this.jsEditor.addEditorEvent("change", function() {
  1132. if( this.jsEditor.silent )return;
  1133. var text = this.scriptPage.textNode.get("text");
  1134. if (text.substr(0,1)!=="*") this.scriptPage.textNode.set("text","*"+ text);
  1135. this.change();
  1136. }.bind(this));
  1137. this.jsEditor.addEditorEvent("blur", function() {
  1138. this.change();
  1139. }.bind(this));
  1140. // this.editor.on("change", function() {
  1141. // var text = this.scriptPage.textNode.get("text");
  1142. // if (text.substr(0,1)!=="*") this.scriptPage.textNode.set("text","*"+ text);
  1143. // this.change();
  1144. // }.bind(this));
  1145. this.jsEditor.resize();
  1146. }.bind(this),
  1147. "onSave": function(){
  1148. this.save();
  1149. var text = this.scriptPage.textNode.get("text");
  1150. if (text.substr(0,1)==="*"){
  1151. this.scriptPage.textNode.set("text", text.substr(1, text.length));
  1152. }
  1153. }.bind(this)
  1154. });
  1155. this.jsEditor.load();
  1156. this.scriptPage.addEvent("show", function(){
  1157. this.scriptPage.scriptItem.selected();
  1158. if (this.jsEditor) this.jsEditor.focus();
  1159. }.bind(this));
  1160. this.scriptPage.addEvent("queryClose", function(){
  1161. var idx = this.tab.pages.indexOf(this);
  1162. if (idx!==-1){
  1163. if (idx===0){ idx = 1; }else{ idx--; }
  1164. if (this.tab.pages[idx]){ this.tab.pages[idx].scriptItem.selected();} else {this.scriptItem.unselected();}
  1165. }else{
  1166. this.scriptItem.unselected();
  1167. }
  1168. this.scriptItem.scriptPage = null;
  1169. this.scriptItem.jsEditor = null;
  1170. });
  1171. var module = this.getFormModule();
  1172. if(module){
  1173. var name = this.path;
  1174. if( name.indexOf(this.script.designer.lp.events+".") === 0){
  1175. name = "events." + name.replace(this.script.designer.lp.events+".", "");
  1176. }
  1177. module.addScriptJsEditor( name, this.jsEditor );
  1178. }
  1179. //this.scriptPage.tabNode.addEvent("dblclick")
  1180. },
  1181. showScript: function(){
  1182. if (!this.scriptPage) this.createScriptEditor();
  1183. this.scriptPage.showTabIm();
  1184. // if (!this.script.jsEditor){
  1185. // this.script.createScriptEditor(function(){
  1186. // this.script.editor.setValue(this.value);
  1187. // this.script.jsEditor.node.show();
  1188. // }.bind(this));
  1189. // }else{
  1190. // if (this.script.currentItem) this.script.currentItem.unShow();
  1191. // this.script.editor.setValue(this.value);
  1192. // this.script.jsEditor.node.show();
  1193. // }
  1194. },
  1195. destroy: function(){
  1196. this.script.items.erase(this);
  1197. if (this.data.editors) this.data.editors.erase(this);
  1198. var category = this.script.moduleCategorys[(this.module.type==="Form" || this.module.type==="Page") ? this.module.type : this.module.id];
  1199. if (category) category.items.erase(this);
  1200. if (this.scriptPage) this.scriptPage.closeTab();
  1201. if (this.node) this.node.destroy();
  1202. this.script.checkCategorys();
  1203. MWF.release(this);
  1204. },
  1205. //绑定aec需要修改ace源码。
  1206. bind: function(){
  1207. this.value = this.data[this.key];
  1208. if (this.data.editors){
  1209. this.data.editors.push(this);
  1210. }else{
  1211. Object.defineProperty(this.data, "editors", {
  1212. configurable : false,
  1213. enumerable : false,
  1214. writable: true,
  1215. "value": []
  1216. });
  1217. this.data.editors.push(this);
  1218. Object.defineProperty(this.data, this.key, {
  1219. configurable : true,
  1220. enumerable : true,
  1221. "get": function(){return this.value;}.bind(this),
  1222. "set": function(v){
  1223. this.data.editors.each(function(editor){
  1224. if (editor.editor){
  1225. if (v!==editor.editor.getValue()) editor.editor.setValue(v,1);
  1226. }else{
  1227. editor.reload();
  1228. }
  1229. });
  1230. this.value = v;
  1231. }.bind(this)
  1232. });
  1233. }
  1234. // Object.defineProperty(this.data, this.key, {
  1235. // configurable : true,
  1236. // enumerable : true,
  1237. // "get": function(){return this.value;}.bind(this),
  1238. // "set": function(v){
  1239. // this.value = v;
  1240. // this.reload();
  1241. // }.bind(this)
  1242. // });
  1243. }
  1244. });