Property.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. MWF.require("MWF.widget.Common", null, false);
  2. MWF.require("MWF.widget.JsonTemplate", null, false);
  3. MWF.xApplication.query.StatDesigner.Property = MWF.FVProperty = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "path": "../x_component_query_FormDesigner/property/property.html"
  9. },
  10. initialize: function(module, propertyNode, designer, options){
  11. this.setOptions(options);
  12. this.module = module;
  13. this.moduleId = module.json.id;
  14. this.view = module.view;
  15. this.data = module.json;
  16. this.htmlPath = this.options.path;
  17. this.designer = designer;
  18. this.propertyNode = propertyNode;
  19. },
  20. load: function(){
  21. if (this.fireEvent("queryLoad")){
  22. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  23. this.htmlString = responseText;
  24. this.fireEvent("postLoad");
  25. }.bind(this));
  26. }
  27. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  28. },
  29. editProperty: function(td){
  30. },
  31. getHtmlString: function(callback){
  32. if (!this.htmlString){
  33. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  34. this.htmlString = responseText;
  35. if (callback) callback();
  36. }.bind(this));
  37. }else{
  38. if (callback) callback();
  39. }
  40. },
  41. show: function(){
  42. if (!this.propertyContent){
  43. this.getHtmlString(function(){
  44. if (this.htmlString){
  45. this.htmlString = o2.bindJson(this.htmlString, {"lp": MWF.xApplication.query.StatDesigner.LP.propertyTemplate});
  46. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  47. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  48. this.propertyContent.set("html", this.JsonTemplate.load());
  49. this.setEditNodeEvent();
  50. this.setEditNodeStyles(this.propertyContent);
  51. this.loadPropertyTab();
  52. this.loadPersonInput();
  53. this.loadPersonSelectInput();
  54. this.loadViewSelect();
  55. this.loadStatColumnSelect();
  56. this.loadArrayList();
  57. this.loadScriptArea();
  58. this.loadJSONArea();
  59. //this.view.changeViewSelected();
  60. this.module.changeViewSelected();
  61. }
  62. }.bind(this));
  63. }else{
  64. this.propertyContent.setStyle("display", "block");
  65. }
  66. },
  67. hide: function(){
  68. //this.JsonTemplate = null;
  69. //this.propertyNode.set("html", "");
  70. if (this.propertyContent) this.propertyContent.setStyle("display", "none");
  71. },
  72. loadJSONArea: function(){
  73. var jsonNode = this.propertyContent.getElement(".MWFJSONArea");
  74. if (jsonNode){
  75. this.propertyTab.pages.each(function(page){
  76. if (page.contentNode == jsonNode.parentElement){
  77. page.setOptions({
  78. "onShow": function(){
  79. jsonNode.empty();
  80. MWF.require("MWF.widget.JsonParse", function(){
  81. this.json = new MWF.widget.JsonParse(this.module.json, jsonNode, null);
  82. this.json.load();
  83. }.bind(this));
  84. }.bind(this)
  85. });
  86. }
  87. }.bind(this));
  88. }
  89. },
  90. loadPropertyTab: function(){
  91. var tabNodes = this.propertyContent.getElements(".MWFTab");
  92. if (tabNodes.length){
  93. var tmpNode = this.propertyContent.getFirst();
  94. var tabAreaNode = new Element("div", {
  95. "styles": this.view.css.propertyTabNode
  96. }).inject(tmpNode, "before");
  97. MWF.require("MWF.widget.Tab", function(){
  98. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  99. tab.load();
  100. var tabPages = [];
  101. tabNodes.each(function(node){
  102. var page = tab.addTab(node, node.get("title"), false);
  103. tabPages.push(page);
  104. this.setScrollBar(page.contentNodeArea, "small", null, null);
  105. }.bind(this));
  106. tabPages[0].showTab();
  107. this.propertyTab = tab;
  108. this.designer.resizeNode();
  109. }.bind(this), false);
  110. }
  111. },
  112. setEditNodeEvent: function(){
  113. var property = this;
  114. // var inputs = this.process.propertyListNode.getElements(".editTableInput");
  115. var inputs = this.propertyContent.getElements("input");
  116. inputs.each(function(input){
  117. var jsondata = input.get("name");
  118. if (jsondata && jsondata.substr(0,1)!="_"){
  119. if (this.module){
  120. var id = this.module.json.id;
  121. input.set("name", id+jsondata);
  122. }
  123. if (jsondata){
  124. var inputType = input.get("type").toLowerCase();
  125. switch (inputType){
  126. case "radio":
  127. input.addEvent("change", function(e){
  128. property.setRadioValue(jsondata, this);
  129. });
  130. //input.addEvent("blur", function(e){
  131. // property.setRadioValue(jsondata, this);
  132. //});
  133. input.addEvent("keydown", function(e){
  134. e.stopPropagation();
  135. });
  136. property.setRadioValue(jsondata, input);
  137. break;
  138. case "checkbox":
  139. input.addEvent("change", function(e){
  140. property.setCheckboxValue(jsondata, this);
  141. });
  142. input.addEvent("click", function(e){
  143. property.setCheckboxValue(jsondata, this);
  144. });
  145. input.addEvent("keydown", function(e){
  146. e.stopPropagation();
  147. });
  148. break;
  149. default:
  150. input.addEvent("change", function(e){
  151. property.setValue(jsondata, this.value, this);
  152. });
  153. input.addEvent("blur", function(e){
  154. property.setValue(jsondata, this.value, this);
  155. });
  156. input.addEvent("keydown", function(e){
  157. if (e.code==13){
  158. property.setValue(jsondata, this.value, this);
  159. }
  160. e.stopPropagation();
  161. });
  162. if (input.hasClass("editTableInputDate")){
  163. this.loadCalendar(input);
  164. }
  165. }
  166. }
  167. }
  168. }.bind(this));
  169. var selects = this.propertyContent.getElements("select");
  170. selects.each(function(select){
  171. var jsondata = select.get("name");
  172. if (jsondata){
  173. select.addEvent("change", function(e){
  174. property.setSelectValue(jsondata, this);
  175. });
  176. //property.setSelectValue(jsondata, select);
  177. }
  178. });
  179. var textareas = this.propertyContent.getElements("textarea");
  180. textareas.each(function(input){
  181. var jsondata = input.get("name");
  182. if (jsondata){
  183. input.addEvent("change", function(e){
  184. property.setValue(jsondata, this.value);
  185. });
  186. input.addEvent("blur", function(e){
  187. property.setValue(jsondata, this.value);
  188. });
  189. input.addEvent("keydown", function(e){
  190. e.stopPropagation();
  191. });
  192. }
  193. }.bind(this));
  194. },
  195. loadCalendar: function(node){
  196. MWF.require("MWF.widget.Calendar", function(){
  197. this.calendar = new MWF.widget.Calendar(node, {
  198. "style": "xform",
  199. "isTime": false,
  200. "target": this.module.designer.content,
  201. "format": "%Y-%m-%d",
  202. "onComplate": function(){
  203. //this.validationMode();
  204. //this.validation();
  205. //this.fireEvent("complete");
  206. }.bind(this)
  207. });
  208. //this.calendar.show();
  209. }.bind(this));
  210. },
  211. changeStyle: function(name){
  212. this.module.setPropertiesOrStyles(name);
  213. },
  214. changeData: function(name, input, oldValue){
  215. this.module._setEditStyle(name, input, oldValue);
  216. },
  217. changeJsonDate: function(key, value){
  218. if (typeOf(key)!="array") key = [key];
  219. var o = this.data;
  220. var len = key.length-1;
  221. key.each(function(n, i){
  222. if (!o[n]) o[n] = {};
  223. if (i<len) o = o[n];
  224. }.bind(this));
  225. o[key[len]] = value;
  226. },
  227. setRadioValue: function(name, input){
  228. if (input.checked){
  229. var i = name.indexOf("*");
  230. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  231. var value = input.value;
  232. if (value=="false") value = false;
  233. if (value=="true") value = true;
  234. var oldValue = this.data;
  235. for (var idx = 0; idx<names.length; idx++){
  236. if (!oldValue[names[idx]]){
  237. oldValue = null;
  238. break;
  239. }else{
  240. oldValue = oldValue[names[idx]];
  241. }
  242. }
  243. //var oldValue = this.data[name];
  244. this.changeJsonDate(names, value);
  245. this.changeData(name, input, oldValue);
  246. }
  247. },
  248. setCheckboxValue: function(name, input){
  249. debugger;
  250. var i = name.indexOf("*");
  251. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  252. var id = this.moduleId || this.module.json.id;
  253. var checkboxList = $$("input[name='"+id+name+"']");
  254. var values = [];
  255. checkboxList.each(function(checkbox){
  256. if (checkbox.get("checked")){
  257. values.push(checkbox.value);
  258. }
  259. });
  260. var o = this.data;
  261. names.each(function(k){ o = o[k]; }.bind(this));
  262. var oldValue = o;
  263. this.changeJsonDate(names, values);
  264. this.changeData(name, input, oldValue);
  265. },
  266. setSelectValue: function(name, select){
  267. var idx = select.selectedIndex;
  268. var options = select.getElements("option");
  269. var value = "";
  270. if (options[idx]){
  271. value = options[idx].get("value");
  272. }
  273. var oldValue = this.data[name];
  274. //this.data[name] = value;
  275. var names = name.split(".");
  276. this.changeJsonDate(names, value);
  277. this.changeData(name, select, oldValue);
  278. },
  279. setValue: function(name, value, obj){
  280. var names = name.split(".");
  281. var oldValue = this.data;
  282. for (var idx = 0; idx<names.length; idx++){
  283. if (!oldValue[names[idx]]){
  284. oldValue = null;
  285. break;
  286. }else{
  287. oldValue = oldValue[names[idx]];
  288. }
  289. }
  290. //var oldValue = this.data[name];
  291. //this.data[name] = value;
  292. this.changeJsonDate(names, value);
  293. this.changeData(name, obj, oldValue);
  294. },
  295. setEditNodeStyles: function(node){
  296. var nodes = node.getChildren();
  297. if (nodes.length){
  298. nodes.each(function(el){
  299. var cName = el.get("class");
  300. if (cName){
  301. if (this.view.css[cName]) el.setStyles(this.view.css[cName]);
  302. }
  303. this.setEditNodeStyles(el);
  304. }.bind(this));
  305. }
  306. },
  307. loadPersonInput: function(){
  308. var personIdentityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  309. var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit");
  310. var dutyNodes = this.propertyContent.getElements(".MWFDutySelector");
  311. var dutyNameNodes = this.propertyContent.getElements(".MWFPersonDuty");
  312. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  313. var cmsviewNodes = this.propertyContent.getElements(".MWFCMSViewSelect");
  314. var queryviewNodes = this.propertyContent.getElements(".MWFQueryViewSelect");
  315. var querystatNodes = this.propertyContent.getElements(".MWFQueryStatSelect");
  316. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  317. personIdentityNodes.each(function(node){
  318. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  319. "type": "identity",
  320. "names": this.data[node.get("name")],
  321. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  322. });
  323. }.bind(this));
  324. personUnitNodes.each(function(node){
  325. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  326. "type": "unit",
  327. "names": this.data[node.get("name")],
  328. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  329. });
  330. }.bind(this));
  331. dutyNodes.each(function(node){
  332. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  333. "type": "duty",
  334. "names": this.data[node.get("name")],
  335. "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this),
  336. "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this)
  337. });
  338. }.bind(this));
  339. dutyNameNodes.each(function(node){
  340. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  341. "type": "dutyName",
  342. "names": this.data[node.get("name")],
  343. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  344. });
  345. }.bind(this));
  346. viewNodes.each(function(node){
  347. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  348. "type": "View",
  349. "count": 1,
  350. "names": [this.data[node.get("name")]],
  351. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  352. });
  353. }.bind(this));
  354. cmsviewNodes.each(function(node){
  355. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  356. "type": "CMSView",
  357. "count": 1,
  358. "names": [this.data[node.get("name")]],
  359. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  360. });
  361. }.bind(this));
  362. queryviewNodes.each(function(node){
  363. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  364. "type": "QueryView",
  365. "count": 1,
  366. "names": [this.data[node.get("name")]],
  367. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  368. });
  369. }.bind(this));
  370. querystatNodes.each(function(node){
  371. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  372. "type": "QueryStat",
  373. "count": 1,
  374. "names": [this.data[node.get("name")]],
  375. "onChange": function(ids){this.saveViewItem(node, ids);}.bind(this)
  376. });
  377. }.bind(this));
  378. }.bind(this));
  379. // var identityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  380. // var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit");
  381. //
  382. // MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  383. // identityNodes.each(function(node){
  384. // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  385. // "type": "identity",
  386. // "names": this.data[node.get("name")],
  387. // "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  388. // });
  389. // }.bind(this));
  390. //
  391. // personUnitNodes.each(function(node){
  392. // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  393. // "type": "unit",
  394. // "names": this.data[node.get("name")],
  395. // "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  396. // });
  397. // }.bind(this));
  398. // }.bind(this));
  399. },
  400. saveViewItem: function(node, ids){
  401. var oldValue = this.data[node.get("name")];
  402. if (ids[0]){
  403. var view = ids[0].data;
  404. var data = {
  405. "name": view.name,
  406. "alias": view.alias,
  407. "id": view.id,
  408. "appName" : view.appName || view.applicationName,
  409. "appId": view.appId,
  410. "application": view.application
  411. };
  412. this.data[node.get("name")] = view.id;
  413. }else{
  414. this.data[node.get("name")] = null;
  415. }
  416. this.changeData(node.get("name"), node, oldValue);
  417. //if (this.module._checkView) this.module._checkView();
  418. },
  419. removeViewItem: function(node, item){
  420. },
  421. savePersonItem: function(node, ids){
  422. var values = [];
  423. ids.each(function(id){
  424. //values.push({"name": (id.data.distinguishedName || id.data.name), "id": id.data.id});
  425. values.push((id.data.distinguishedName || id.data.id || id.data.name));
  426. }.bind(this));
  427. var name = node.get("name");
  428. key = name.split(".");
  429. var o = this.data;
  430. var len = key.length-1;
  431. key.each(function(n, i){
  432. if (!o[n]) o[n] = {};
  433. if (i<len) o = o[n];
  434. }.bind(this));
  435. o[key[len]] = values;
  436. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  437. },
  438. loadPersonSelectInput: function(){
  439. var applicationNodes = this.propertyContent.getElements(".MWFSelectApplication");
  440. var processNodes = this.propertyContent.getElements(".MWFSelectProcess");
  441. // var companyNodes = this.propertyContent.getElements(".MWFSelectCompany");
  442. // var departmentNodes = this.propertyContent.getElements(".MWFSelectDepartment");
  443. var personNodes = this.propertyContent.getElements(".MWFSelectPerson");
  444. var identityNodes = this.propertyContent.getElements(".MWFSelectIdentity");
  445. var personUnitNodes = this.propertyContent.getElements(".MWFSelectUnit");
  446. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  447. applicationNodes.each(function(node){
  448. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  449. "type": "application",
  450. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.applicationList : [],
  451. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  452. });
  453. }.bind(this));
  454. processNodes.each(function(node){
  455. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  456. "type": "process",
  457. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.processList : [],
  458. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  459. });
  460. }.bind(this));
  461. personUnitNodes.each(function(node){
  462. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  463. "type": "unit",
  464. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.unitList : [],
  465. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  466. });
  467. }.bind(this));
  468. personNodes.each(function(node){
  469. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  470. "type": "person",
  471. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.personList : [],
  472. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  473. });
  474. }.bind(this));
  475. identityNodes.each(function(node){
  476. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.view.designer, {
  477. "type": "identity",
  478. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.identityList : [],
  479. "onChange": function(ids){this.savePersonSelectItem(node, ids);}.bind(this)
  480. });
  481. }.bind(this));
  482. }.bind(this));
  483. },
  484. savePersonSelectItem: function(node, ids){
  485. //this.initWhereEntryData();
  486. var values = [];
  487. ids.each(function(id){
  488. values.push({"name": id.data.name, "id": id.data.id});
  489. }.bind(this));
  490. var name = node.get("name");
  491. key = name.split(".");
  492. var o = this.data;
  493. var len = key.length-1;
  494. key.each(function(n, i){
  495. if (!o[n]) o[n] = {};
  496. if (i<len) o = o[n];
  497. }.bind(this));
  498. o[key[len]] = values;
  499. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  500. },
  501. loadArrayList: function(){
  502. var arrays = this.propertyContent.getElements(".MWFArraylist");
  503. arrays.each(function(node){
  504. var title = node.get("title");
  505. var name = node.get("name");
  506. var names = name.split(".");
  507. var arr = this.data;
  508. for (var idx = 0; idx<names.length; idx++){
  509. if (!arr[names[idx]]){
  510. arr = null;
  511. break;
  512. }else{
  513. arr = arr[names[idx]];
  514. }
  515. }
  516. //var arr = this.data[name];
  517. if (!arr) arr = [];
  518. MWF.require("MWF.widget.Arraylist", function(){
  519. var arraylist = new MWF.widget.Arraylist(node, {
  520. "title": title,
  521. "onChange": function(){
  522. this.setValue(name, arraylist.toArray(), node);
  523. //this.data[name] = arraylist.toArray();
  524. }.bind(this)
  525. });
  526. arraylist.load(arr);
  527. }.bind(this));
  528. node.addEvent("keydown", function(e){e.stopPropagation();});
  529. }.bind(this));
  530. },
  531. loadStatColumnSelect: function(){
  532. var columnNodes = this.propertyContent.getElements(".MWFStatSelectColumn");
  533. if (columnNodes.length){
  534. columnNodes.each(function(node){
  535. var key = node.get("name");
  536. // var v = this.data[key];
  537. var names = key.split(".");
  538. var v = this.data;
  539. for (var idx = 0; idx<names.length; idx++){
  540. if (!v[names[idx]]){
  541. v = null;
  542. break;
  543. }else{
  544. v = v[names[idx]];
  545. }
  546. }
  547. node.empty();
  548. new Element("option", {
  549. "value": "",
  550. // "selected": true,
  551. "text": this.module.designer.lp.category
  552. }).inject(node);
  553. this.module.items.each(function(item){
  554. new Element("option", {
  555. "value": item.json.id,
  556. "selected": (v===item.json.id),
  557. "text": item.json.displayName
  558. }).inject(node);
  559. }.bind(this));
  560. }.bind(this));
  561. }
  562. },
  563. loadViewSelect: function(){
  564. var viewNodes = this.propertyContent.getElements(".MWFViewSelect");
  565. if (viewNodes.length){
  566. this.getViewList(function(){
  567. viewNodes.each(function(node){
  568. var select = new Element("select").inject(node);
  569. select.addEvent("change", function(e){
  570. var viewId = e.target.options[e.target.selectedIndex].value;
  571. var viewName = e.target.options[e.target.selectedIndex].get("text");
  572. this.setValue(e.target.getParent("div").get("name"), viewId);
  573. this.setValue(e.target.getParent("div").get("name")+"Name", viewName);
  574. }.bind(this));
  575. this.setViewSelectOptions(node, select);
  576. var refreshNode = new Element("div", {"styles": this.view.css.propertyRefreshFormNode}).inject(node);
  577. refreshNode.addEvent("click", function(e){
  578. this.getViewList(function(){
  579. this.setViewSelectOptions(node, select);
  580. }.bind(this), true);
  581. }.bind(this));
  582. //select.addEvent("click", function(e){
  583. // this.setFormSelectOptions(node, select);
  584. //}.bind(this));
  585. }.bind(this));
  586. }.bind(this));
  587. }
  588. },
  589. setViewSelectOptions: function(node, select){
  590. var name = node.get("name");
  591. select.empty();
  592. var option = new Element("option", {"text": "(none)"}).inject(select);
  593. this.views.each(function(view){
  594. var option = new Element("option", {
  595. "text": view.name,
  596. "value": view.id,
  597. "selected": (this.data[name]==view.id)
  598. }).inject(select);
  599. }.bind(this));
  600. },
  601. getViewList: function(callback, refresh){
  602. if (!this.views || refresh){
  603. this.view.designer.actions.listView(this.view.designer.application.id, function(json){
  604. this.views = json.data;
  605. if (callback) callback();
  606. }.bind(this));
  607. }else{
  608. if (callback) callback();
  609. }
  610. },
  611. loadScriptArea: function(){
  612. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  613. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  614. this.loadScriptEditor(scriptAreas);
  615. this.loadScriptEditor(formulaAreas, "formula");
  616. },
  617. loadScriptEditor: function(scriptAreas, style){
  618. scriptAreas.each(function(node){
  619. var title = node.get("title");
  620. var name = node.get("name");
  621. var scriptContent = this.data[name];
  622. MWF.require("MWF.widget.ScriptArea", function(){
  623. var scriptArea = new MWF.widget.ScriptArea(node, {
  624. "title": title,
  625. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  626. "maxObj": this.designer.editContentNode,
  627. "onChange": function(){
  628. this.data[name] = scriptArea.toJson().code;
  629. }.bind(this),
  630. "onSave": function(){
  631. this.designer.saveView();
  632. }.bind(this),
  633. "style": style || "default"
  634. });
  635. scriptArea.load({"code": scriptContent});
  636. }.bind(this));
  637. }.bind(this));
  638. }
  639. });