PageRenderTime 38ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/webapp/static/js/validate.result.js

https://github.com/Hooyoo/HealtheMe
JavaScript | 173 lines | 150 code | 6 blank | 17 comment | 10 complexity | 01520a08391ca7d536ef13f9ba46e892 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Copyright (C) 2012 KRM Associates, Inc. healtheme@krminc.com
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. $.validator.methods.regexMatch = function(value, element, param) {
  17. var re = new RegExp(param);
  18. return value.match(re);
  19. };
  20. $.validator.methods.notEqualTo = function(value, element, param) {
  21. return value != $(param).val();
  22. };
  23. $.validator.methods.regexMatchOrEmpty = function(value, element, param) {
  24. if (value.length > 0) {
  25. var re = new RegExp(param);
  26. return value.match(re);
  27. } else {
  28. return true;
  29. }
  30. };
  31. $().ready(function() {
  32. $(":input").bind("onBlur" ,function(){
  33. $(this).valid()}
  34. );
  35. $("#detailform").bind("invalid-form.validate", function(e, validator) {
  36. if (validator.numberOfInvalids()) {
  37. $("#notifier").html("<strong class=\"error\">Please fix any fields highlighted in red before continuing.<\/strong>").slideDown();
  38. } else {
  39. $("#notifier").html("").slideUp();
  40. }
  41. }).validate({
  42. submitHandler: function(form) {
  43. var patientid = $("input#patientid").val();
  44. var sourceid = $("input#sourceid").val();
  45. var resultid = $("input#resultid").val();
  46. var testname = $("input#testname").val();
  47. var resultdate = $("input#resultdate").val();
  48. var result = $("input#result").val();
  49. var resultunit = $("input#resultunit").val();
  50. jsonObject = JSON.stringify({
  51. "@uri":baseuri +'/results/' + resultid,
  52. "healthRecordId":patientid,
  53. "dataSourceId":"",
  54. "sourceId":sourceid,
  55. "resultId":resultid,
  56. "testName":testname,
  57. "resultDateExact":resultdate,
  58. "result":result,
  59. "resultUnit":resultunit},null,1);
  60. /** Update (PUT) using REST API **/
  61. $.ajax({
  62. type: "PUT",
  63. url: url,
  64. data: jsonObject,
  65. contentType: "application/json",
  66. success: function() {
  67. $('#notifier')
  68. .html('Updated record.')
  69. .removeClass('ui-state-error').addClass('ui-state-highlight')
  70. .slideDown();
  71. // TODO: Add <a href="#undo">Undo</a>.
  72. },
  73. error: function() {
  74. $('#notifier').html('Unable to update.')
  75. .removeClass('ui-state-highlight').addClass('ui-state-error')
  76. .slideDown();
  77. }
  78. });
  79. return false;
  80. },
  81. errorPlacement: function(error, element) {
  82. if(error.text().length > 1){
  83. var found=false;
  84. function foundFunction (bool) { found = bool;}
  85. $(element).nextAll().each(function(){
  86. if ($(this).hasClass("errorText")) {
  87. $(this).text(error.text());
  88. foundFunction(true);
  89. }
  90. });
  91. if (!found) {
  92. element.parent()
  93. .append('<div class="errorText">' + error.text() + '</p>')
  94. .slideDown();
  95. }
  96. } else {
  97. $(element).nextAll().each(function(){
  98. if ($(this).hasClass("errorText")) {
  99. $(this).remove();
  100. }
  101. });
  102. }
  103. },
  104. success: function(label) {
  105. },
  106. highlight: function(element, errorClass) {
  107. $(element).parent().addClass(errorClass);
  108. },
  109. unhighlight: function(element, errorClass) {
  110. $(element).parent().removeClass(errorClass);
  111. },
  112. rules: {
  113. sourceid: {
  114. required:true
  115. },
  116. action: {
  117. required:true
  118. },
  119. sourceurl: {
  120. required:true,
  121. minlength:1
  122. },
  123. returnurl: {
  124. required:true,
  125. minlength:1
  126. },
  127. patientid: {
  128. required:true,
  129. digits:true
  130. },
  131. testname: {
  132. required:true,
  133. minlength:1
  134. },
  135. resultdate: {
  136. regexMatchOrEmpty: /^(([0]?[1-9])|(1[0-2]))\/(([0]?[1-9])|([1,2]\d{1})|([3][0,1]))\/[12]\d{3}$/
  137. }
  138. },
  139. messages: {
  140. sourceid: {
  141. required:'Form is invalid, please refresh and try again.'
  142. },
  143. action: {
  144. required:'Form is invalid, please refresh and try again.'
  145. },
  146. sourceurl: {
  147. required:'Form is invalid, please refresh and try again.',
  148. minlength:'Form is invalid, please refresh and try again.'
  149. },
  150. returnurl: {
  151. required:'Form is invalid, please refresh and try again.',
  152. minlength:'Form is invalid, please refresh and try again.'
  153. },
  154. patientid: {
  155. required:'Form is invalid, please refresh and try again.',
  156. digits:'Form is invalid, please refresh and try again.'
  157. },
  158. testname: {
  159. required:'Please enter a test name.',
  160. minlength:'Please enter a longer test name.'
  161. },
  162. resultdate: {
  163. regexMatchOrEmpty:'Selected date is invalid. Please use MM/DD/YYYY format.'
  164. }
  165. }
  166. });
  167. });