You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

372 lines
8.2 KiB

  1. //Copyright (c) 2001-2016 Aspose Pty Ltd. All Rights Reserved.
  2. /*****************************************************
  3. * Aspose.Cells.GridWeb Component Script File
  4. * Copyright 2003-2011, All Rights Reserverd.
  5. * V2.4.0
  6. *****************************************************/
  7. function onselectchange(o)
  8. {
  9. o.parentNode.firstChild.value=o.options[o.selectedIndex].value;
  10. }
  11. function oncheckboxclick(o)
  12. {
  13. o.parentNode.firstChild.value = o.checked? "TRUE":"FALSE";
  14. }
  15. function savePos(gform)
  16. {
  17. var pos = document.getElementById(gform.id + "_POS");
  18. pos.value = document.body.scrollLeft + "|" + document.body.scrollTop;
  19. }
  20. function initPos(gform)
  21. {
  22. if (getattr(gform, "bodyleft") != null)
  23. document.body.scrollLeft = getattr(gform, "bodyleft");
  24. if (getattr(gform, "bodytop") != null)
  25. document.body.scrollTop = getattr(gform, "bodytop");
  26. }
  27. function formValidateAll(gform)
  28. {
  29. var vresult = true;
  30. var ftab = document.getElementById(gform.id + "_ETAB");
  31. var decimalpoint = getattr(gform, "decimalpoint");
  32. for (var r=0; r<ftab.rows.length; r++)
  33. {
  34. var row = ftab.rows[r];
  35. var cell = row.cells[1];
  36. if (cell.hasChildNodes() && cell.firstChild.hasChildNodes() && cell.firstChild.firstChild.type == "text")
  37. {
  38. if (!validateInput(cell, decimalpoint))
  39. vresult = false;
  40. }
  41. }
  42. return vresult;
  43. }
  44. function getattr(o, name)
  45. {
  46. if (o.attributes[name] != null)
  47. return o.attributes[name].nodeValue;
  48. return null;
  49. }
  50. function validateInput(o, decimalpoint)
  51. {
  52. var vtype = getattr(o, "vtype");
  53. var value = o.firstChild.firstChild.value;
  54. if (value == null || value == "")
  55. {
  56. if (getattr(o, "isrequired") == "1")
  57. {
  58. setInvalid(o);
  59. return false;
  60. }
  61. else
  62. {
  63. setValid(o);
  64. return true;
  65. }
  66. }
  67. var formula = getattr(o, "formula");
  68. var ufv = getattr(o, "ufv");
  69. var nv;
  70. if (vtype == "regex" || getattr(o, "regex") != null)
  71. {
  72. var rx = new RegExp(getattr(o, "regex"));
  73. var matches = rx.exec(value);
  74. if (matches == null || value != matches[0])
  75. {
  76. if (formula != null)
  77. {
  78. matches = rx.exec(formula);
  79. if (matches == null || formula != matches[0])
  80. {
  81. setInvalid(o);
  82. return false;
  83. }
  84. }
  85. else if (ufv != null)
  86. {
  87. matches = rx.exec(ufv);
  88. if (matches == null || ufv != matches[0])
  89. {
  90. setInvalid(o);
  91. return false;
  92. }
  93. }
  94. else
  95. {
  96. setInvalid(o);
  97. return false;
  98. }
  99. }
  100. }
  101. switch (vtype)
  102. {
  103. case "regex":
  104. setValid(o);
  105. return true;
  106. break;
  107. case "bool":
  108. var bv = value.toUpperCase();
  109. if (bv == "TRUE" || bv == "FALSE")
  110. {
  111. setValid(o);
  112. return true;
  113. }
  114. else
  115. {
  116. setInvalid(o);
  117. return false;
  118. }
  119. break;
  120. case "number":
  121. nv = validatorConvert(value, "Double", decimalpoint);
  122. if (nv == null && ufv != null)
  123. nv = validatorConvert(ufv, "Double", decimalpoint);
  124. if (nv != null)
  125. {
  126. setValid(o);
  127. return true;
  128. }
  129. else
  130. {
  131. setInvalid(o);
  132. return false;
  133. }
  134. break;
  135. case "int":
  136. nv = validatorConvert(value, "Integer", decimalpoint);
  137. if (nv == null && ufv != null)
  138. nv = validatorConvert(ufv, "Integer", decimalpoint);
  139. if (nv != null)
  140. {
  141. setValid(o);
  142. return true;
  143. }
  144. else
  145. {
  146. setInvalid(o);
  147. return false;
  148. }
  149. break;
  150. case "date":
  151. nv = validatorConvert(value, "Date", decimalpoint);
  152. if (nv == null && ufv != null)
  153. nv = validatorConvert(ufv, "Date", decimalpoint);
  154. if (nv != null)
  155. {
  156. setValid(o);
  157. return true;
  158. }
  159. else
  160. {
  161. setInvalid(o);
  162. return false;
  163. }
  164. break;
  165. case "datetime":
  166. nv = validatorConvert(value, "Date", decimalpoint);
  167. if (nv == null)
  168. nv = validatorConvert(value, "DateTime", decimalpoint);
  169. if (nv == null && ufv != null)
  170. {
  171. nv = validatorConvert(ufv, "Date", decimalpoint);
  172. if (nv == null)
  173. nv = validatorConvert(ufv, "DateTime", decimalpoint);
  174. }
  175. if (nv != null)
  176. {
  177. setValid(o);
  178. return true;
  179. }
  180. else
  181. {
  182. setInvalid(o);
  183. return false;
  184. }
  185. break;
  186. case "customfunction":
  187. var cvf = eval(getattr(o, "cvfn"));
  188. var cvfResult = cvf(o, value);
  189. if (!cvfResult)
  190. {
  191. if (formula != null)
  192. cvfResult = cvf(o, formula);
  193. else if (ufv != null)
  194. cvfResult = cvf(o, ufv);
  195. }
  196. if (cvfResult)
  197. {
  198. setValid(o);
  199. return true;
  200. }
  201. else
  202. {
  203. setInvalid(o);
  204. return false;
  205. }
  206. break;
  207. default:
  208. setValid(o);
  209. return true;
  210. }
  211. }
  212. function validatorConvert(op, dataType, decimalpoint) {
  213. var num, cleanInput, m, exp;
  214. if (dataType == "Integer") {
  215. exp = /^\s*[-\+]?\d+\s*$/;
  216. if (op.match(exp) == null)
  217. return null;
  218. num = parseInt(op, 10);
  219. return (isNaN(num) ? null : num);
  220. }
  221. else if(dataType == "Double") {
  222. if (decimalpoint == null)
  223. decimalpoint = ".";
  224. exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + decimalpoint + "(\\d+))?\\s*$");
  225. m = op.match(exp);
  226. if (m == null)
  227. return null;
  228. cleanInput = (m[1]!=null?m[1]:"") + (m[2].length>0 ? m[2] : "0") + "." + m[4];
  229. num = parseFloat(cleanInput);
  230. return (isNaN(num) ? null : num);
  231. }
  232. else if (dataType == "Date") {
  233. var yearFirstExp = /^(\d{4})-(\d{2})-(\d{2})$/;
  234. m = op.match(yearFirstExp);
  235. var day, month, year;
  236. if (m != null) {
  237. year = m[1];
  238. month = m[2];
  239. day = m[3];
  240. }
  241. else {
  242. return null;
  243. }
  244. month-=1;
  245. var date = new Date(year, month, day);
  246. return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;
  247. }
  248. else if (dataType == "DateTime") {
  249. var yearFirstExp = /^(\d{4})-(\d{2})-(\d{2}) (\d+)\:(\d+)\:(\d+)$/;
  250. m = op.match(yearFirstExp);
  251. var day, month, year, hour, minu, sec;
  252. if (m != null) {
  253. year = m[1];
  254. month = m[2];
  255. day = m[3];
  256. hour = m[4];
  257. minu = m[5];
  258. sec = m[6];
  259. }
  260. else {
  261. return null;
  262. }
  263. month-=1;
  264. var date = new Date(year, month, day, hour, minu, sec);
  265. return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate() && hour == date.getHours() && minu == date.getMinutes() && sec == date.getSeconds()) ? date.valueOf() : null;
  266. }
  267. else {
  268. return op.toString();
  269. }
  270. }
  271. function setValid(o)
  272. {
  273. o.style.border = "";
  274. }
  275. function setInvalid(o)
  276. {
  277. o.style.border = "1px dotted red";
  278. }
  279. function dateBtnClick(gform, o)
  280. {
  281. var Calendar = o.calendar;
  282. if (Calendar != null)
  283. {
  284. o.calendar = null;
  285. Calendar.removeNode(true);
  286. }
  287. else
  288. {
  289. Calendar = document.createElement("SPAN");
  290. document.body.appendChild(Calendar);
  291. Calendar.dateBtn = o;
  292. Calendar.style.position = "absolute";
  293. Calendar.style.display = "block";
  294. Calendar.style.width = 280;
  295. Calendar.style.height = 150;
  296. Calendar.style.zIndex = 99999999;
  297. o.calendar = Calendar;
  298. Calendar.style.posLeft = document.body.scrollLeft + event.clientX;
  299. Calendar.style.posTop = document.body.scrollTop + event.clientY;
  300. var left = Calendar.offsetLeft - event.offsetX - 1;
  301. if (left < 0)
  302. left = 0;
  303. var top = Calendar.offsetTop + o.offsetHeight - event.offsetY - 1;
  304. if (top < 0)
  305. top = 0;
  306. Calendar.style.posLeft = left;
  307. Calendar.style.posTop = top;
  308. Calendar.addBehavior(gform.acw_client_path+"calendar.htc");
  309. if (Calendar.readyState == "complete")
  310. Calendar.attachEvent("onpropertychange", onCalendarChange);
  311. else
  312. Calendar.onreadystatechange = onCalendarReady;
  313. }
  314. }
  315. function onCalendarReady()
  316. {
  317. var Calendar = event.srcElement;
  318. if (Calendar.readyState == "complete")
  319. Calendar.attachEvent("onpropertychange", onCalendarChange);
  320. }
  321. function onCalendarChange()
  322. {
  323. var Calendar = event.srcElement;
  324. var ActiveCell = Calendar.dateBtn.parentElement.firstChild;
  325. if (event.propertyName == "day")
  326. {
  327. var day = Calendar.day.toString();
  328. if (day.length == 1)
  329. day = '0' + day;
  330. var month = Calendar.month.toString();
  331. if (month.length == 1)
  332. month = '0' + month;
  333. var datestr = Calendar.year.toString() + '-' + month + '-' + day;
  334. ActiveCell.value = datestr;
  335. Calendar.dateBtn.calendar = null;
  336. Calendar.removeNode(true);
  337. }
  338. }
  339. function enableAll(gform)
  340. {
  341. var eles = gform.getElementsByTagName("INPUT");
  342. for (var i=0; i<eles.length; i++)
  343. {
  344. eles[i].disabled = false;
  345. }
  346. }