Property.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. MWF.require("MWF.widget.Common", null, false);
  2. MWF.xApplication.cms.QueryViewDesigner.Property = MWF.FVProperty = new Class({
  3. Extends: MWF.widget.Common,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "path": "/x_component_cms_FormDesigner/property/property.html"
  8. },
  9. initialize: function(module, propertyNode, designer, options){
  10. this.setOptions(options);
  11. this.module = module;
  12. this.view = module.view;
  13. this.data = module.json;
  14. this.htmlPath = this.options.path;
  15. this.designer = designer;
  16. this.propertyNode = propertyNode;
  17. },
  18. load: function(){
  19. if (this.fireEvent("queryLoad")){
  20. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  21. this.htmlString = responseText;
  22. MWF.require("MWF.widget.JsonTemplate", function(){
  23. this.fireEvent("postLoad");
  24. }.bind(this));
  25. }.bind(this));
  26. }
  27. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  28. },
  29. editProperty: function(td){
  30. },
  31. show: function(){
  32. if (!this.propertyContent){
  33. if (this.htmlString){
  34. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  35. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.propertyNode);
  36. this.propertyContent.set("html", this.JsonTemplate.load());
  37. this.setEditNodeEvent();
  38. this.setEditNodeStyles(this.propertyContent);
  39. this.loadPropertyTab();
  40. this.loadPersonInput();
  41. this.loadViewFilter();
  42. this.loadColumnExportEditor();
  43. this.loadJSONArea();
  44. }
  45. }else{
  46. this.propertyContent.setStyle("display", "block");
  47. }
  48. },
  49. hide: function(){
  50. //this.JsonTemplate = null;
  51. //this.propertyNode.set("html", "");
  52. if (this.propertyContent) this.propertyContent.setStyle("display", "none");
  53. },
  54. loadJSONArea: function(){
  55. var jsonNode = this.propertyContent.getElement(".MWFJSONArea");
  56. if (jsonNode){
  57. this.propertyTab.pages.each(function(page){
  58. if (page.contentNode == jsonNode.parentElement){
  59. page.setOptions({
  60. "onShow": function(){
  61. jsonNode.empty();
  62. MWF.require("MWF.widget.JsonParse", function(){
  63. this.json = new MWF.widget.JsonParse(this.module.json, jsonNode, null);
  64. this.json.load();
  65. }.bind(this));
  66. }.bind(this)
  67. });
  68. }
  69. }.bind(this));
  70. }
  71. },
  72. loadPropertyTab: function(){
  73. var tabNodes = this.propertyContent.getElements(".MWFTab");
  74. if (tabNodes.length){
  75. var tmpNode = this.propertyContent.getFirst();
  76. var tabAreaNode = new Element("div", {
  77. "styles": this.view.css.propertyTabNode
  78. }).inject(tmpNode, "before");
  79. MWF.require("MWF.widget.Tab", function(){
  80. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "formPropertyList"});
  81. tab.load();
  82. var tabPages = [];
  83. tabNodes.each(function(node){
  84. var page = tab.addTab(node, node.get("title"), false);
  85. tabPages.push(page);
  86. this.setScrollBar(page.contentNodeArea, "small", null, null);
  87. }.bind(this));
  88. tabPages[0].showTab();
  89. this.propertyTab = tab;
  90. this.designer.resizeNode();
  91. }.bind(this), false);
  92. }
  93. },
  94. setEditNodeEvent: function(){
  95. var property = this;
  96. // var inputs = this.process.propertyListNode.getElements(".editTableInput");
  97. var inputs = this.propertyContent.getElements("input");
  98. inputs.each(function(input){
  99. var jsondata = input.get("name");
  100. if (jsondata && jsondata.substr(0,1)!="_"){
  101. if (this.module){
  102. var id = this.module.json.id;
  103. input.set("name", id+jsondata);
  104. }
  105. if (jsondata){
  106. var inputType = input.get("type").toLowerCase();
  107. switch (inputType){
  108. case "radio":
  109. input.addEvent("change", function(e){
  110. property.setRadioValue(jsondata, this);
  111. });
  112. input.addEvent("blur", function(e){
  113. property.setRadioValue(jsondata, this);
  114. });
  115. input.addEvent("keydown", function(e){
  116. e.stopPropagation();
  117. });
  118. property.setRadioValue(jsondata, input);
  119. break;
  120. case "checkbox":
  121. input.addEvent("change", function(e){
  122. property.setCheckboxValue(jsondata, this);
  123. });
  124. input.addEvent("click", function(e){
  125. property.setCheckboxValue(jsondata, this);
  126. });
  127. input.addEvent("keydown", function(e){
  128. e.stopPropagation();
  129. });
  130. break;
  131. default:
  132. input.addEvent("change", function(e){
  133. property.setValue(jsondata, this.value, this);
  134. });
  135. input.addEvent("blur", function(e){
  136. property.setValue(jsondata, this.value, this);
  137. });
  138. input.addEvent("keydown", function(e){
  139. if (e.code==13){
  140. property.setValue(jsondata, this.value, this);
  141. }
  142. e.stopPropagation();
  143. });
  144. if (input.hasClass("editTableInputDate")){
  145. this.loadCalendar(input);
  146. }
  147. }
  148. }
  149. }
  150. }.bind(this));
  151. var selects = this.propertyContent.getElements("select");
  152. selects.each(function(select){
  153. var jsondata = select.get("name");
  154. if (jsondata){
  155. select.addEvent("change", function(e){
  156. property.setSelectValue(jsondata, this);
  157. });
  158. }
  159. });
  160. var textareas = this.propertyContent.getElements("textarea");
  161. textareas.each(function(input){
  162. var jsondata = input.get("name");
  163. if (jsondata){
  164. input.addEvent("change", function(e){
  165. property.setValue(jsondata, this.value);
  166. });
  167. input.addEvent("blur", function(e){
  168. property.setValue(jsondata, this.value);
  169. });
  170. input.addEvent("keydown", function(e){
  171. e.stopPropagation();
  172. });
  173. }
  174. }.bind(this));
  175. },
  176. loadCalendar: function(node){
  177. MWF.require("MWF.widget.Calendar", function(){
  178. this.calendar = new MWF.widget.Calendar(node, {
  179. "style": "xform",
  180. "isTime": false,
  181. "target": this.module.designer.content,
  182. "format": "%Y-%m-%d",
  183. "onComplate": function(){
  184. //this.validationMode();
  185. //this.validation();
  186. //this.fireEvent("complete");
  187. }.bind(this)
  188. });
  189. //this.calendar.show();
  190. }.bind(this));
  191. },
  192. changeStyle: function(name){
  193. this.module.setPropertiesOrStyles(name);
  194. },
  195. changeData: function(name, input, oldValue){
  196. this.module._setEditStyle(name, input, oldValue);
  197. },
  198. changeJsonDate: function(key, value){
  199. if (typeOf(key)!="array") key = [key];
  200. var o = this.data;
  201. var len = key.length-1;
  202. key.each(function(n, i){
  203. if (!o[n]) o[n] = {};
  204. if (i<len) o = o[n];
  205. }.bind(this));
  206. o[key[len]] = value;
  207. },
  208. setRadioValue: function(name, input){
  209. if (input.checked){
  210. var i = name.indexOf("*");
  211. var names = (i==-1) ? name.split(".") : name.substr(i+1, name.length).split(".");
  212. var value = input.value;
  213. if (value=="false") value = false;
  214. if (value=="true") value = true;
  215. var oldValue = this.data;
  216. for (var idx = 0; idx<names.length; idx++){
  217. if (!oldValue[names[idx]]){
  218. oldValue = null;
  219. break;
  220. }else{
  221. oldValue = oldValue[names[idx]];
  222. }
  223. }
  224. //var oldValue = this.data[name];
  225. this.changeJsonDate(names, value);
  226. this.changeData(name, input, oldValue);
  227. }
  228. },
  229. setCheckboxValue: function(name, input){
  230. var checkboxList = $$("input:[name='"+name+"']");
  231. var values = [];
  232. checkboxList.each(function(checkbox){
  233. if (checkbox.get("checked")){
  234. values.push(checkbox.value);
  235. }
  236. });
  237. var oldValue = this.data[name];
  238. //this.data[name] = values;
  239. this.changeJsonDate(name, values);
  240. this.changeData(name, input, oldValue);
  241. },
  242. setSelectValue: function(name, select){
  243. var idx = select.selectedIndex;
  244. var options = select.getElements("option");
  245. var value = "";
  246. if (options[idx]){
  247. value = options[idx].get("value");
  248. }
  249. var oldValue = this.data[name];
  250. //this.data[name] = value;
  251. this.changeJsonDate(name, value);
  252. this.changeData(name, select, oldValue);
  253. },
  254. setValue: function(name, value, obj){
  255. var names = name.split(".");
  256. var oldValue = this.data;
  257. for (var idx = 0; idx<names.length; idx++){
  258. if (!oldValue[names[idx]]){
  259. oldValue = null;
  260. break;
  261. }else{
  262. oldValue = oldValue[names[idx]];
  263. }
  264. }
  265. //var oldValue = this.data[name];
  266. //this.data[name] = value;
  267. this.changeJsonDate(names, value);
  268. this.changeData(name, obj, oldValue);
  269. },
  270. setEditNodeStyles: function(node){
  271. var nodes = node.getChildren();
  272. if (nodes.length){
  273. nodes.each(function(el){
  274. var cName = el.get("class");
  275. if (cName){
  276. if (this.view.css[cName]) el.setStyles(this.view.css[cName]);
  277. }
  278. this.setEditNodeStyles(el);
  279. }.bind(this));
  280. }
  281. },
  282. loadPersonInput: function(){
  283. var applicationNodes = this.propertyContent.getElements(".MWFSelectApplication");
  284. var categoryNodes = this.propertyContent.getElements(".MWFSelectCategory");
  285. var companyNodes = this.propertyContent.getElements(".MWFSelectCompany");
  286. var departmentNodes = this.propertyContent.getElements(".MWFSelectDepartment");
  287. var personNodes = this.propertyContent.getElements(".MWFSelectPerson");
  288. var identityNodes = this.propertyContent.getElements(".MWFSelectIdentity");
  289. MWF.xDesktop.requireApp("cms.QueryViewDesigner", "widget.PersonSelector", function(){
  290. applicationNodes.each(function(node){
  291. new MWF.xApplication.cms.QueryViewDesigner.widget.PersonSelector(node, this.view.designer, {
  292. "type": "application",
  293. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.appInfoList : [],
  294. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  295. });
  296. }.bind(this));
  297. categoryNodes.each(function(node){
  298. new MWF.xApplication.cms.QueryViewDesigner.widget.PersonSelector(node, this.view.designer, {
  299. "type": "category",
  300. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.categoryInfoList : [],
  301. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  302. });
  303. }.bind(this));
  304. companyNodes.each(function(node){
  305. new MWF.xApplication.cms.QueryViewDesigner.widget.PersonSelector(node, this.view.designer, {
  306. "type": "company",
  307. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.companyList : [],
  308. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  309. });
  310. }.bind(this));
  311. departmentNodes.each(function(node){
  312. new MWF.xApplication.cms.QueryViewDesigner.widget.PersonSelector(node, this.view.designer, {
  313. "type": "department",
  314. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.departmentList : [],
  315. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  316. });
  317. }.bind(this));
  318. personNodes.each(function(node){
  319. new MWF.xApplication.cms.QueryViewDesigner.widget.PersonSelector(node, this.view.designer, {
  320. "type": "person",
  321. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.personList : [],
  322. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  323. });
  324. }.bind(this));
  325. identityNodes.each(function(node){
  326. new MWF.xApplication.cms.QueryViewDesigner.widget.PersonSelector(node, this.view.designer, {
  327. "type": "identity",
  328. "names": (this.data.data.restrictWhereEntry) ? this.data.data.restrictWhereEntry.identityList : [],
  329. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  330. });
  331. }.bind(this));
  332. }.bind(this));
  333. },
  334. savePersonItem: function(node, ids){
  335. //this.initWhereEntryData();
  336. var values = [];
  337. ids.each(function(id){
  338. values.push({"name": id.data.name, "id": id.data.id});
  339. }.bind(this));
  340. var name = node.get("name");
  341. key = name.split(".");
  342. var o = this.data;
  343. var len = key.length-1;
  344. key.each(function(n, i){
  345. if (!o[n]) o[n] = {};
  346. if (i<len) o = o[n];
  347. }.bind(this));
  348. o[key[len]] = values;
  349. //this.data.data.restrictWhereEntry[node.get("name")] = values;
  350. },
  351. loadColumnExportEditor: function(){
  352. var _self = this;
  353. var nodes = this.propertyContent.getElements(".MWFColumnExport");
  354. nodes.each(function(node){
  355. //if (!this.data.export) this.data.export = {};
  356. //var sort = this.data.export.sort || "";
  357. //var sortOrder = this.data.export.sortOrder || "1";
  358. var select = node.getElement("select");
  359. var sortList = this.view.data.data.orderEntryList;
  360. sortList.each(function(order){
  361. if (order.column==this.data.column){
  362. if (order.orderType=="asc") select.options[1].set("selected", true);
  363. if (order.orderType=="desc") select.options[1].set("selected", false);
  364. }
  365. }.bind(this));
  366. select.addEvent("change", function(e){
  367. var v = select.options[select.selectedIndex].value;
  368. if (v!="none"){
  369. var flag = false;
  370. sortList.each(function(order){
  371. if (order.column==this.data.column){
  372. flag = true;
  373. order.orderType=select.options[select.selectedIndex].value;
  374. }
  375. }.bind(this));
  376. if (!flag) sortList.push({"column": this.data.column, "orderType": select.options[select.selectedIndex].value});
  377. }else{
  378. var deleteItem = null;
  379. sortList.each(function(order){
  380. if (order.column==this.data.column){
  381. deleteItem = order;
  382. }
  383. }.bind(this));
  384. if (deleteItem) sortList.erase(deleteItem);
  385. }
  386. }.bind(this));
  387. var radios = node.getElements("input");
  388. var group = this.view.data.data.groupEntry;
  389. if (group.column==this.data.column) radios[0].set("checked", true);
  390. radios.addEvent("click", function(e){
  391. if (this.checked){
  392. if (this.value=="true") {
  393. _self.view.data.data.groupEntry.column = _self.data.column;
  394. _self.view.items.each(function(col){
  395. if (col.property){
  396. var groupRadios = col.property.propertyContent.getElement(".MWFColumnExport").getElements("input");
  397. groupRadios.each(function(r){
  398. if (r.value=="true") r.set("checked", false);
  399. if (r.value=="false") r.set("checked", true);
  400. });
  401. }
  402. });
  403. this.set("checked", true);
  404. }else{
  405. if (group.column ==_self.data.column) _self.view.data.data.groupEntry = {};
  406. }
  407. }
  408. });
  409. }.bind(this));
  410. },
  411. loadViewFilter: function(){
  412. var nodes = this.propertyContent.getElements(".MWFViewFilter");
  413. var filtrData = this.view.data.data.restrictFilterEntryList;
  414. nodes.each(function(node){
  415. MWF.xDesktop.requireApp("cms.QueryViewDesigner", "widget.ViewFilter", function(){
  416. var _slef = this;
  417. new MWF.xApplication.cms.QueryViewDesigner.widget.ViewFilter(node, this.view.designer, filtrData, {
  418. "onChange": function(ids){
  419. var data = this.getData();
  420. _slef.changeJsonDate(["data", "restrictFilterEntryList"], data);
  421. }
  422. });
  423. }.bind(this));
  424. }.bind(this));
  425. },
  426. loadColumnFilter: function(){
  427. var nodes = this.propertyContent.getElements(".MWFColumnFilter");
  428. nodes.each(function(node){
  429. this.module.filterAreaNode = node;
  430. var table = new Element("table", {
  431. "styles": {"width": "100%"},
  432. "border": "0px",
  433. "cellPadding": "0",
  434. "cellSpacing": "0"
  435. }).inject(node);
  436. var tr = new Element("tr", {"styles": this.module.css.filterTableTitle}).inject(table);
  437. var html = "<th style='width:24px;border-right:1px solid #CCC;border-bottom:1px solid #999;'></th>" +
  438. "<th style='border-right:1px solid #CCC;border-left:1px solid #FFF;border-bottom:1px solid #999;'>逻辑</th>" +
  439. "<th style='border-right:1px solid #CCC;border-left:1px solid #FFF;border-bottom:1px solid #999;'>路径</th>" +
  440. "<th style='border-right:1px solid #CCC;border-left:1px solid #FFF;border-bottom:1px solid #999;'>比较</th>" +
  441. "<th style='border-left:1px solid #FFF;border-bottom:1px solid #999;'>值</th>";
  442. tr.set("html", html);
  443. var addActionNode = new Element("div", {"styles": this.module.css.filterAddActionNode}).inject(tr.getFirst("th"));
  444. addActionNode.addEvent("click", function(){
  445. this.addFilter(table);
  446. }.bind(this));
  447. if (this.data.filterList) {
  448. this.data.filterList.each(function (op) {
  449. new MWF.xApplication.cms.QueryViewDesigner.Property.Filter(op, table, this);
  450. }.bind(this));
  451. }
  452. }.bind(this));
  453. },
  454. addFilter: function(table){
  455. op = {
  456. "logic": "and",
  457. "comparison": "",
  458. "value": ""
  459. }
  460. if (!this.data.filterList) this.data.filterList = [];
  461. this.data.filterList.push(op);
  462. var filter = new MWF.xApplication.cms.QueryViewDesigner.Property.Filter(op, table, this);
  463. filter.editMode();
  464. }
  465. });
  466. MWF.xApplication.cms.QueryViewDesigner.Property.Filter = new Class({
  467. Implements: [Events],
  468. initialize: function(json, table, property){
  469. this.property = property;
  470. this.module = property.module;
  471. this.table = table;
  472. this.data = json;
  473. this.load();
  474. },
  475. load: function(){
  476. this.node = new Element("tr", {"styles": this.module.css.filterTableTd}).inject(this.table);
  477. var html = "<td style='widtd:24px;border-right:1px solid #CCC;border-bottom:1px solid #999;'></td>" +
  478. "<td style='padding:3px;border-right:1px solid #CCC;border-bottom:1px solid #999; width:60px'>"+this.data.logic+"</td>" +
  479. "<td style='padding:3px;border-right:1px solid #CCC;border-bottom:1px solid #999; width:30px'>列值</td>" +
  480. "<td style='padding:3px;border-right:1px solid #CCC;border-bottom:1px solid #999;'>"+this.data.comparison+"</td>" +
  481. "<td style='padding:3px;border-bottom:1px solid #999;'>"+this.data.value+"</td>";
  482. this.node.set("html", html);
  483. var tds = this.node.getElements("td");
  484. this.delActionNode = new Element("div", {"styles": this.module.css.filterDelActionNode}).inject(tds[0]);
  485. this.delActionNode.addEvent("click", function(e){
  486. this.delFilter(e);
  487. e.stopPropagation();
  488. }.bind(this));
  489. this.logicNode = tds[1];
  490. this.comparisonNode = tds[3];
  491. this.valueNode = tds[4];
  492. this.node.addEvent("click", function(){
  493. if (!this.isEditMode) this.editMode();
  494. }.bind(this));
  495. this.node.addEvent("blur", function(){
  496. if (this.isEditMode) this.readMode();
  497. }.bind(this));
  498. },
  499. delFilter: function(e){
  500. var _self = this;
  501. this.property.designer.confirm("warn", e, MWF.CMSQVD.LP.notice.deleteFilterTitle, MWF.CMSQVD.LP.notice.deleteFilter, 300, 120, function(){
  502. _self.node.destroy();
  503. _self.property.data.filterList.erase(_self.data);
  504. MWF.release(_self);
  505. this.close();
  506. }, function(){
  507. this.close();
  508. }, null);
  509. },
  510. editMode: function(){
  511. if (this.property.editModeFilter){
  512. if (this.property.editModeFilter!=this) this.property.editModeFilter.readMode();
  513. }
  514. var width = this.logicNode.getSize().x-9;
  515. this.logicNode.empty();
  516. var logicSelect = new Element("select", {"styles": {"width": "90%"}}).inject(this.logicNode);
  517. var html = "";
  518. if (this.data.logic=="and"){
  519. html = "<option value=\"and\" selected>and</option><option value=\"or\">or</option>";
  520. }else{
  521. html = "<option value=\"and\">and</option><option value=\"or\" selected>or</option>";
  522. }
  523. logicSelect.set("html", html);
  524. logicSelect.addEvent("change", function(){
  525. this.data.logic = logicSelect.options[logicSelect.selectedIndex].value;
  526. }.bind(this));
  527. width = this.comparisonNode.getSize().x-9;
  528. this.comparisonNode.empty();
  529. var comparisonSelect = new Element("select", {"styles": {"width": "90%"}}).inject(this.comparisonNode);
  530. html = "";
  531. switch (this.property.data.type){
  532. case "text":
  533. html += "<option value=''></option><option value='==' "+((this.data.comparison=="==") ? "selected": "")+">等于(==)</option>" +
  534. "<option value='!=' "+((this.data.comparison=="!=") ? "selected": "")+">不等于(!=)</option>" +
  535. "<option value='@' "+((this.data.comparison=="@") ? "selected": "")+">包含(@)</option>";
  536. break;
  537. case "date":
  538. html += "<option value=''></option><option value='&gt;' "+((this.data.comparison==">") ? "selected": "")+">大于(&gt;)</option>" +
  539. "<option value='&lt;' "+((this.data.comparison=="<") ? "selected": "")+">小于(&lt;)</option>" +
  540. "<option value='&gt;=' "+((this.data.comparison==">=") ? "selected": "")+">大于等于(&gt;=)</option>" +
  541. "<option value='&lt;=' "+((this.data.comparison=="<=") ? "selected": "")+">小于等于(&lt;=)</option>";
  542. break;
  543. case "number":
  544. html += "<option value=''></option><option value='==' "+((this.data.comparison=="==") ? "selected": "")+">等于(==)</option>" +
  545. "<option value='!=' "+((this.data.comparison=="!=") ? "selected": "")+">不等于(!=)</option>" +
  546. "<option value='&gt;' "+((this.data.comparison==">") ? "selected": "")+">大于(&gt;)</option>" +
  547. "<option value='&lt;' "+((this.data.comparison=="<") ? "selected": "")+">小于(&lt;)</option>" +
  548. "<option value='&gt;=' "+((this.data.comparison==">=") ? "selected": "")+">大于等于(&gt;=)</option>" +
  549. "<option value='&lt;=' "+((this.data.comparison=="<=") ? "selected": "")+">小于等于(&lt;=)</option>";
  550. break;
  551. case "boolean":
  552. html += "<option value=''></option><option value='==' "+((this.data.comparison=="==") ? "selected": "")+">等于(==)</option>" +
  553. "<option value='!=' "+((this.data.comparison=="!=") ? "selected": "")+">不等于(!=)</option>";
  554. break;
  555. }
  556. comparisonSelect.set("html", html);
  557. comparisonSelect.addEvent("change", function(){
  558. this.data.comparison = comparisonSelect.options[comparisonSelect.selectedIndex].value;
  559. }.bind(this));
  560. width = this.valueNode.getSize().x-9;
  561. this.valueNode.empty();
  562. var type = "text";
  563. switch (this.property.data.type){
  564. case "date":
  565. var valueInput = new Element("input", {"styles": {"width": "90%"},
  566. "type": "text",
  567. "value": this.data.value
  568. }).inject(this.valueNode);
  569. MWF.require("MWF.widget.Calendar", function(){
  570. this.calendar = new MWF.widget.Calendar(valueInput, {
  571. "style": "xform",
  572. "isTime": true,
  573. "target": this.property.designer.content,
  574. "format": "%Y-%m-%d %H:%M:%S"
  575. });
  576. //this.calendar.show();
  577. }.bind(this));
  578. break;
  579. case "number":
  580. var valueInput = new Element("input", {"styles": {"width": "90%"},
  581. "type": "number",
  582. "value": this.data.value
  583. }).inject(this.valueNode);
  584. break;
  585. case "boolean":
  586. var valueInput = new Element("select", {"styles": {"width": ""+width+"px"},
  587. "html": "<option value=\"\"></option><option value=\"true\" "+((this.data.value) ? "selected": "")+">true</option><option value=\"false\" "+((!this.data.value) ? "selected": "")+">false</option>"
  588. }).inject(this.valueNode);
  589. break;
  590. default:
  591. var valueInput = new Element("input", {"styles": {"width": "90%"},
  592. "type": "text",
  593. "value": this.data.value
  594. }).inject(this.valueNode);
  595. }
  596. if (valueInput.tagName.toLowerCase()=="select"){
  597. valueInput.addEvent("change", function(){
  598. var v = valueInput.options[valueInput.selectedIndex].value;
  599. this.data.value = (v="true") ? true : false;
  600. }.bind(this));
  601. }else{
  602. valueInput.addEvent("change", function(e){
  603. this.data.value = valueInput.get("value");
  604. }.bind(this));
  605. valueInput.addEvent("blur", function(e){
  606. this.data.value = valueInput.get("value");
  607. }.bind(this));
  608. valueInput.addEvent("keydown", function(e){
  609. if (e.code==13){
  610. this.data.value = valueInput.get("value");
  611. this.readMode();
  612. }
  613. e.stopPropagation();
  614. }.bind(this));
  615. }
  616. this.isEditMode = true;
  617. this.property.editModeFilter = this;
  618. },
  619. readMode: function(){
  620. if (this.isEditMode){
  621. var logicSelect = this.logicNode.getElement("select");
  622. this.data.logic = logicSelect.options[logicSelect.selectedIndex].value;
  623. var comparisonSelect = this.comparisonNode.getElement("select");
  624. this.data.comparison = comparisonSelect.options[comparisonSelect.selectedIndex].value;
  625. var valueInput = this.valueNode.getFirst();
  626. if (valueInput.tagName.toLowerCase()=="select"){
  627. var v = valueInput.options[valueInput.selectedIndex].value;
  628. this.data.value = (v="true") ? true : false;
  629. }else{
  630. this.data.value = valueInput.get("value");
  631. }
  632. this.logicNode.empty();
  633. this.comparisonNode.empty();
  634. this.valueNode.empty();
  635. this.logicNode.set("text", this.data.logic);
  636. this.comparisonNode.set("text", this.data.comparison);
  637. this.valueNode.set("text", this.data.value);
  638. this.isEditMode = false;
  639. this.property.editModeFilter = null;
  640. }
  641. }
  642. });