$Input.js.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: $Input.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: $Input.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  20. /** Class Input组件 */
  21. MWF.xApplication.process.Xform.$Input = MWF.APP$Input = new Class({
  22. Implements: [Events],
  23. Extends: MWF.APP$Module,
  24. iconStyle: "personfieldIcon",
  25. initialize: function(node, json, form, options){
  26. this.node = $(node);
  27. this.node.store("module", this);
  28. this.json = json;
  29. this.form = form;
  30. this.field = true;
  31. },
  32. _loadUserInterface: function(){
  33. this._loadNode();
  34. if (this.json.compute === "show"){
  35. this._setValue(this._computeValue());
  36. }else{
  37. this._loadValue();
  38. }
  39. },
  40. _loadDomEvents: function(){
  41. Object.each(this.json.events, function(e, key){
  42. if (e.code){
  43. if (this.options.moduleEvents.indexOf(key)===-1){
  44. (this.node.getFirst() || this.node).addEvent(key, function(event){
  45. return this.form.Macro.fire(e.code, this, event);
  46. }.bind(this));
  47. }
  48. }
  49. }.bind(this));
  50. },
  51. _loadEvents: function(){
  52. Object.each(this.json.events, function(e, key){
  53. if (e.code){
  54. if (this.options.moduleEvents.indexOf(key)!==-1){
  55. this.addEvent(key, function(event){
  56. return this.form.Macro.fire(e.code, this, event);
  57. }.bind(this));
  58. }else{
  59. (this.node.getFirst() || this.node).addEvent(key, function(event){
  60. return this.form.Macro.fire(e.code, this, event);
  61. }.bind(this));
  62. }
  63. }
  64. }.bind(this));
  65. },
  66. addModuleEvent: function(key, fun){
  67. if (this.options.moduleEvents.indexOf(key)!==-1){
  68. this.addEvent(key, function(event){
  69. return (fun) ? fun(this, event) : null;
  70. }.bind(this));
  71. }else{
  72. (this.node.getFirst() || this.node).addEvent(key, function(event){
  73. return (fun) ? fun(this, event) : null;
  74. }.bind(this));
  75. }
  76. },
  77. _loadNode: function(){
  78. if (this.readonly){
  79. this._loadNodeRead();
  80. }else{
  81. this._loadNodeEdit();
  82. }
  83. },
  84. _loadNodeRead: function(){
  85. this.node.empty();
  86. },
  87. loadDescription: function(){
  88. if (this.readonly || this.json.isReadonly)return;
  89. var v = this._getBusinessData();
  90. if (!v){
  91. if (this.json.description){
  92. var size = this.node.getFirst().getSize();
  93. var w = size.x-3;
  94. if( this.json.showIcon!='no' &amp;&amp; !this.form.json.hideModuleIcon ){
  95. if (COMMON.Browser.safari) w = w-20;
  96. }
  97. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  98. this.descriptionNode.setStyles({
  99. "width": ""+w+"px",
  100. "height": ""+size.y+"px",
  101. "line-height": ""+size.y+"px"
  102. });
  103. this.setDescriptionEvent();
  104. }
  105. }
  106. },
  107. setDescriptionEvent: function(){
  108. if (this.descriptionNode){
  109. this.descriptionNode.addEvents({
  110. "mousedown": function(){
  111. this.descriptionNode.setStyle("display", "none");
  112. this.clickSelect();
  113. }.bind(this)
  114. });
  115. this.node.getFirst().addEvents({
  116. "focus": function(){
  117. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  118. }.bind(this),
  119. "blur": function(){
  120. if (!this.node.getFirst().get("value")) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  121. }.bind(this)
  122. });
  123. }
  124. },
  125. checkDescription: function(){
  126. if (!this.node.getFirst().get("value")){
  127. if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  128. }else{
  129. if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  130. }
  131. },
  132. _resetNodeEdit: function(){
  133. var input = new Element("input", {
  134. "styles": {
  135. "background": "transparent",
  136. "width": "100%",
  137. "border": "0px"
  138. },
  139. "readonly": true
  140. });
  141. var node = new Element("div", {"styles": {
  142. "overflow": "hidden",
  143. "position": "relative",
  144. "margin-right": "20px",
  145. "padding-right": "4px"
  146. }}).inject(this.node, "after");
  147. input.inject(node);
  148. this.node.destroy();
  149. this.node = node;
  150. },
  151. _loadNodeEdit: function(){
  152. if (!this.json.preprocessing) this._resetNodeEdit();
  153. var input = this.node.getFirst();
  154. input.set(this.json.properties);
  155. this.node.set({
  156. "id": this.json.id,
  157. "MWFType": this.json.type,
  158. "readonly": true,
  159. "events": {
  160. "click": this.clickSelect.bind(this)
  161. }
  162. });
  163. if (this.json.showIcon!='no' &amp;&amp; !this.form.json.hideModuleIcon ){
  164. this.iconNode = new Element("div", {
  165. "styles": this.form.css[this.iconStyle],
  166. "events": {
  167. "click": this.clickSelect.bind(this)
  168. }
  169. }).inject(this.node, "before");
  170. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  171. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  172. }
  173. this.node.getFirst().addEvent("change", function(){
  174. this.validationMode();
  175. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  176. }.bind(this));
  177. },
  178. _loadStyles: function(){
  179. if (this.json.styles) this.node.setStyles(this.json.styles);
  180. if (this.json.inputStyles) if (this.node.getFirst()) this.node.getFirst().setStyles(this.json.inputStyles);
  181. if (this.iconNode &amp;&amp; this.iconNode.offsetParent !== null){
  182. var size = this.node.getSize();
  183. //if (!size.y){
  184. // var y1 = this.node.getStyle("height");
  185. // var y2 = this.node.getFirst().getStyle("height");
  186. // alert(y1+"," +y2);
  187. // var y = ((y1!="auto" &amp;&amp; y1>y2) || y2=="auto") ? y1 : y2;
  188. // size.y = (y=="auto") ? "auto" : y.toInt();
  189. // //alert(size.y)
  190. //}
  191. this.iconNode.setStyle("height", ""+size.y+"px");
  192. //alert(this.iconNode.getStyle("height"))
  193. }
  194. },
  195. _computeValue: function(value){
  196. return (this.json.defaultValue &amp;&amp; this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
  197. },
  198. getValue: function(){
  199. var value = this._getBusinessData();
  200. if (!value) value = this._computeValue();
  201. return value || "";
  202. },
  203. _setValue: function(value){
  204. this._setBusinessData(value);
  205. if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
  206. if (this.readonly || this.json.isReadonly) this.node.set("text", value);
  207. },
  208. _loadValue: function(){
  209. this._setValue(this.getValue());
  210. },
  211. clickSelect: function(){
  212. },
  213. _afterLoaded: function(){
  214. // if (this.iconNode){
  215. //// var p = this.node.getPosition();
  216. //// var s = this.node.getSize();
  217. //// var is = this.iconNode.getSize();
  218. ////
  219. //// var y = p.y;
  220. //// var x = p.x+s.x-is.x;
  221. // this.iconNode.setStyles({
  222. // "top": "5px",
  223. // "left": "-18px"
  224. // });
  225. // }
  226. if (!this.readonly &amp;&amp; !this.json.isReadonly ){
  227. this.loadDescription();
  228. }
  229. },
  230. getTextData: function(){
  231. //var value = this.node.get("value");
  232. //var text = this.node.get("text");
  233. var value = (this.node.getFirst()) ? this.node.getFirst().get("value") : this.node.get("text");
  234. var text = (this.node.getFirst()) ? this.node.getFirst().get("text") : this.node.get("text");
  235. return {"value": [value || ""] , "text": [text || value || ""]};
  236. },
  237. /**
  238. * 判断组件值是否为空.
  239. * @return {boolean}.
  240. */
  241. isEmpty : function(){
  242. var data = this.getData();
  243. return !data || !data.trim();
  244. },
  245. /**
  246. * 获取组件值.
  247. * @return {object/string}.
  248. */
  249. getData: function(when){
  250. if (this.json.compute == "save") this._setValue(this._computeValue());
  251. return this.getInputData();
  252. },
  253. getInputData: function(){
  254. if (this.node.getFirst()){
  255. return this.node.getFirst().get("value");
  256. }else{
  257. return this._getBusinessData();
  258. }
  259. },
  260. /**
  261. * 重置组件的值,如果设置了默认值,则设置为默认值,否则置空。
  262. */
  263. resetData: function(){
  264. this.setData(this.getValue());
  265. },
  266. /**
  267. * 为控件赋值。
  268. * @param {string/number/jsonObject} .
  269. */
  270. setData: function(data){
  271. this._setBusinessData(data);
  272. if (this.node.getFirst()){
  273. this.node.getFirst().set("value", data);
  274. this.checkDescription();
  275. this.validationMode();
  276. }else{
  277. this.node.set("text", data);
  278. }
  279. },
  280. createErrorNode: function(text){
  281. //var size = this.node.getFirst().getSize();
  282. //var w = size.x-3;
  283. //if (COMMON.Browser.safari) w = w-20;
  284. //node.setStyles({
  285. // "width": ""+w+"px",
  286. // "height": ""+size.y+"px",
  287. // "line-height": ""+size.y+"px",
  288. // "position": "absolute",
  289. // "top": "0px"
  290. //});
  291. var node;
  292. if( this.form.json.errorStyle ){
  293. if( this.form.json.errorStyle.type === "notice" ){
  294. if( !this.form.errorNoticing ){ //如果是弹出
  295. this.form.errorNoticing = true;
  296. this.form.notice(text, "error", this.node, null, null, {
  297. onClose : function () {
  298. this.form.errorNoticing = false;
  299. }.bind(this)
  300. });
  301. }
  302. }else{
  303. node = new Element("div",{
  304. "styles" : this.form.json.errorStyle.node,
  305. "text": text
  306. });
  307. if( this.form.json.errorStyle.close ){
  308. var closeNode = new Element("div",{
  309. "styles" : this.form.json.errorStyle.close ,
  310. "events": {
  311. "click" : function(){
  312. this.destroy();
  313. }.bind(node)
  314. }
  315. }).inject(node);
  316. }
  317. }
  318. }else{
  319. node = new Element("div");
  320. var iconNode = new Element("div", {
  321. "styles": {
  322. "width": "20px",
  323. "height": "20px",
  324. "float": "left",
  325. "background": "url("+"../x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  326. }
  327. }).inject(node);
  328. var textNode = new Element("div", {
  329. "styles": {
  330. "height": "20px",
  331. "line-height": "20px",
  332. "margin-left": "20px",
  333. "color": "red",
  334. "word-break": "keep-all"
  335. },
  336. "text": text
  337. }).inject(node);
  338. }
  339. return node;
  340. },
  341. notValidationMode: function(text){
  342. if (!this.isNotValidationMode){
  343. debugger;
  344. this.isNotValidationMode = true;
  345. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  346. this.node.setStyle("border-color", "red");
  347. this.errNode = this.createErrorNode(text);
  348. //if (this.iconNode){
  349. // this.errNode.inject(this.iconNode, "after");
  350. //}else{
  351. this.errNode.inject(this.node, "after");
  352. //}
  353. this.showNotValidationMode(this.node);
  354. var parentNode = this.node;
  355. while( parentNode.offsetParent === null ){
  356. parentNode = parentNode.getParent();
  357. }
  358. if (!parentNode.isIntoView()) parentNode.scrollIntoView();
  359. }
  360. },
  361. showNotValidationMode: function(node){
  362. var p = node.getParent("div");
  363. if (p){
  364. var mwftype = p.get("MWFtype") || p.get("mwftype");
  365. if (mwftype == "tab$Content"){
  366. if (p.getParent("div").getStyle("display")=="none"){
  367. var contentAreaNode = p.getParent("div").getParent("div");
  368. var tabAreaNode = contentAreaNode.getPrevious("div");
  369. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  370. var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
  371. tabNode.click();
  372. p = tabAreaNode.getParent("div");
  373. }
  374. }
  375. this.showNotValidationMode(p);
  376. }
  377. },
  378. validationMode: function(){
  379. if (this.isNotValidationMode){
  380. this.isNotValidationMode = false;
  381. this.node.setStyles(this.node.retrieve("borderStyle"));
  382. if (this.errNode){
  383. this.errNode.destroy();
  384. this.errNode = null;
  385. }
  386. }
  387. },
  388. validationConfigItem: function(routeName, data){
  389. var flag = (data.status==="all") ? true: (routeName === data.decision);
  390. if (flag){
  391. var n = this.getInputData();
  392. var v = (data.valueType==="value") ? n : n.length;
  393. switch (data.operateor){
  394. case "isnull":
  395. if (!v){
  396. this.notValidationMode(data.prompt);
  397. return false;
  398. }
  399. break;
  400. case "notnull":
  401. if (v){
  402. this.notValidationMode(data.prompt);
  403. return false;
  404. }
  405. break;
  406. case "gt":
  407. if (v>data.value){
  408. this.notValidationMode(data.prompt);
  409. return false;
  410. }
  411. break;
  412. case "lt":
  413. if (v&lt;data.value){
  414. this.notValidationMode(data.prompt);
  415. return false;
  416. }
  417. break;
  418. case "equal":
  419. if (v==data.value){
  420. this.notValidationMode(data.prompt);
  421. return false;
  422. }
  423. break;
  424. case "neq":
  425. if (v!=data.value){
  426. this.notValidationMode(data.prompt);
  427. return false;
  428. }
  429. break;
  430. case "contain":
  431. if (v.indexOf(data.value)!=-1){
  432. this.notValidationMode(data.prompt);
  433. return false;
  434. }
  435. break;
  436. case "notcontain":
  437. if (v.indexOf(data.value)==-1){
  438. this.notValidationMode(data.prompt);
  439. return false;
  440. }
  441. break;
  442. }
  443. }
  444. return true;
  445. },
  446. validationConfig: function(routeName, opinion){
  447. if (this.json.validationConfig){
  448. if (this.json.validationConfig.length){
  449. for (var i=0; i&lt;this.json.validationConfig.length; i++) {
  450. var data = this.json.validationConfig[i];
  451. if (!this.validationConfigItem(routeName, data)) return false;
  452. }
  453. }
  454. return true;
  455. }
  456. return true;
  457. },
  458. /**
  459. * 根据组件的校验设置进行校验。
  460. * @param {string} routeName-路由名称.
  461. * @return {boolean} 是否通过校验
  462. */
  463. validation: function(routeName, opinion){
  464. if (!this.readonly &amp;&amp; !this.json.isReadonly){
  465. if (!this.validationConfig(routeName, opinion)) return false;
  466. if (!this.json.validation) return true;
  467. if (!this.json.validation.code) return true;
  468. this.currentRouteName = routeName;
  469. var flag = this.form.Macro.exec(this.json.validation.code, this);
  470. this.currentRouteName = "";
  471. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  472. if (flag.toString()!="true"){
  473. this.notValidationMode(flag);
  474. return false;
  475. }
  476. }
  477. return true;
  478. }
  479. }); </code></pre>
  480. </article>
  481. </section>
  482. </div>
  483. <nav>
  484. <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#getData">getData</a></li><li><a href="global.html#isEmpty">isEmpty</a></li><li><a href="global.html#resetData">resetData</a></li><li><a href="global.html#setData">setData</a></li><li><a href="global.html#validation">validation</a></li></ul>
  485. </nav>
  486. <br class="clear">
  487. <footer>
  488. Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.6</a> on Mon Oct 19 2020 14:51:24 GMT+0800 (GMT+08:00)
  489. </footer>
  490. <script> prettyPrint(); </script>
  491. <script src="scripts/linenumber.js"> </script>
  492. </body>
  493. </html>