Script.js 56 KB

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