renalware-core 2.0.0.pre.beta5 → 2.0.0.pre.beta6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/renalware/session_timeout_redirect.js.erb +8 -4
  3. data/app/assets/stylesheets/renalware/partials/_navigation.scss +2 -2
  4. data/app/controllers/renalware/admin/users_controller.rb +3 -3
  5. data/app/helpers/renalware/application_helper.rb +2 -1
  6. data/app/helpers/renalware/layout_helper.rb +2 -2
  7. data/app/views/renalware/clinical/body_compositions/_form.html.slim +6 -2
  8. data/app/views/renalware/clinical/body_compositions/new.html.slim +4 -3
  9. data/app/views/renalware/clinics/clinic_visits/edit.html.slim +5 -2
  10. data/app/views/renalware/events/swabs/edit.html.slim +4 -2
  11. data/app/views/renalware/hd/historical_profiles/show.html.slim +6 -3
  12. data/app/views/renalware/patients/alerts/_form.html.slim +1 -1
  13. data/app/views/renalware/renal/profiles/edit.html.slim +5 -3
  14. data/app/views/renalware/transplants/donor_operations/edit.html.slim +7 -3
  15. data/lib/breadcrumb.rb +8 -0
  16. data/lib/renalware/version.rb +1 -1
  17. data/vendor/assets/fonts/foundation-icons.eot +0 -0
  18. data/vendor/assets/fonts/foundation-icons.scss +594 -0
  19. data/vendor/assets/fonts/foundation-icons.svg +970 -0
  20. data/vendor/assets/fonts/foundation-icons.ttf +0 -0
  21. data/vendor/assets/fonts/foundation-icons.woff +0 -0
  22. data/vendor/assets/javascripts/renalware/iframeResizer.contentWindow.js +1108 -0
  23. data/vendor/assets/javascripts/renalware/iframeResizer.js +1002 -0
  24. data/vendor/assets/javascripts/renalware/jquery-readyselector.js +17 -0
  25. data/vendor/assets/javascripts/renalware/masonry.min.js +9 -0
  26. data/vendor/assets/javascripts/renalware/modernizr.js +3 -0
  27. data/vendor/assets/javascripts/renalware/mousetrap.js +1044 -0
  28. data/vendor/assets/javascripts/renalware/print.min.js +1 -0
  29. data/vendor/assets/javascripts/renalware/rails.validations.js +660 -0
  30. data/vendor/assets/javascripts/renalware/rails.validations.simple_form.js +46 -0
  31. data/vendor/assets/stylesheets/renalware/print.min.css +1 -0
  32. data/vendor/assets/stylesheets/renalware/select2/css/select2.css +431 -0
  33. data/vendor/assets/stylesheets/renalware/select2/css/select2.min.css +1 -0
  34. data/vendor/xsd/ukrdc/README.md +9 -0
  35. data/vendor/xsd/ukrdc/Schema/Allergies/Allergy.xsd +69 -0
  36. data/vendor/xsd/ukrdc/Schema/ClinicalRelationships/ClinicalRelationship.xsd +27 -0
  37. data/vendor/xsd/ukrdc/Schema/Diagnoses/CauseOfDeath.xsd +32 -0
  38. data/vendor/xsd/ukrdc/Schema/Diagnoses/Diagnosis.xsd +41 -0
  39. data/vendor/xsd/ukrdc/Schema/Diagnoses/RenalDiagnosis.xsd +41 -0
  40. data/vendor/xsd/ukrdc/Schema/Documents/Document.xsd +72 -0
  41. data/vendor/xsd/ukrdc/Schema/Encounters/Encounter.xsd +121 -0
  42. data/vendor/xsd/ukrdc/Schema/Encounters/TransplantList.xsd +108 -0
  43. data/vendor/xsd/ukrdc/Schema/Encounters/Treatment.xsd +207 -0
  44. data/vendor/xsd/ukrdc/Schema/FamilyHistories/FamilyHistory.xsd +42 -0
  45. data/vendor/xsd/ukrdc/Schema/LabOrders/LabOrder.xsd +181 -0
  46. data/vendor/xsd/ukrdc/Schema/Medications/Medication.xsd +88 -0
  47. data/vendor/xsd/ukrdc/Schema/Observations/Observation.xsd +65 -0
  48. data/vendor/xsd/ukrdc/Schema/Patient.xsd +87 -0
  49. data/vendor/xsd/ukrdc/Schema/Procedures/DialysisSession.xsd +61 -0
  50. data/vendor/xsd/ukrdc/Schema/Procedures/Procedure.xsd +38 -0
  51. data/vendor/xsd/ukrdc/Schema/Procedures/Transplant.xsd +160 -0
  52. data/vendor/xsd/ukrdc/Schema/Procedures/VascularAccess.xsd +49 -0
  53. data/vendor/xsd/ukrdc/Schema/ProgramMemberships/ProgramMembership.xsd +46 -0
  54. data/vendor/xsd/ukrdc/Schema/README.md +1 -0
  55. data/vendor/xsd/ukrdc/Schema/SocialHistories/SocialHistory.xsd +15 -0
  56. data/vendor/xsd/ukrdc/Schema/Surveys/Survey.xsd +143 -0
  57. data/vendor/xsd/ukrdc/Schema/Types/ActionCode.xsd +37 -0
  58. data/vendor/xsd/ukrdc/Schema/Types/Address.xsd +67 -0
  59. data/vendor/xsd/ukrdc/Schema/Types/CF_DMD.xsd +27 -0
  60. data/vendor/xsd/ukrdc/Schema/Types/CF_EDTA_COD.xsd +343 -0
  61. data/vendor/xsd/ukrdc/Schema/Types/CF_EDTA_PRD.xsd +356 -0
  62. data/vendor/xsd/ukrdc/Schema/Types/CF_HL7_0004.xsd +76 -0
  63. data/vendor/xsd/ukrdc/Schema/Types/CF_HL7_00204.xsd +46 -0
  64. data/vendor/xsd/ukrdc/Schema/Types/CF_HL7_00206.xsd +41 -0
  65. data/vendor/xsd/ukrdc/Schema/Types/CF_RR1.xsd +567 -0
  66. data/vendor/xsd/ukrdc/Schema/Types/CF_RR23.xsd +82 -0
  67. data/vendor/xsd/ukrdc/Schema/Types/CF_RR7_Discharge.xsd +80 -0
  68. data/vendor/xsd/ukrdc/Schema/Types/CF_RR7_Treatment.xsd +241 -0
  69. data/vendor/xsd/ukrdc/Schema/Types/CF_SNOMED.xsd +27 -0
  70. data/vendor/xsd/ukrdc/Schema/Types/Clinician.xsd +27 -0
  71. data/vendor/xsd/ukrdc/Schema/Types/CodeTableDetail.xsd +27 -0
  72. data/vendor/xsd/ukrdc/Schema/Types/CodedField.xsd +27 -0
  73. data/vendor/xsd/ukrdc/Schema/Types/CommonMetadata.xsd +23 -0
  74. data/vendor/xsd/ukrdc/Schema/Types/ContactDetail.xsd +55 -0
  75. data/vendor/xsd/ukrdc/Schema/Types/DrugProduct.xsd +41 -0
  76. data/vendor/xsd/ukrdc/Schema/Types/EthnicGroup.xsd +114 -0
  77. data/vendor/xsd/ukrdc/Schema/Types/FamilyDoctor.xsd +21 -0
  78. data/vendor/xsd/ukrdc/Schema/Types/LabResultItem.xsd +160 -0
  79. data/vendor/xsd/ukrdc/Schema/Types/LabTestItem.xsd +24 -0
  80. data/vendor/xsd/ukrdc/Schema/Types/Language.xsd +981 -0
  81. data/vendor/xsd/ukrdc/Schema/Types/Location.xsd +27 -0
  82. data/vendor/xsd/ukrdc/Schema/Types/NV_RR14.xsd +39 -0
  83. data/vendor/xsd/ukrdc/Schema/Types/Name.xsd +51 -0
  84. data/vendor/xsd/ukrdc/Schema/Types/Occupation.xsd +75 -0
  85. data/vendor/xsd/ukrdc/Schema/Types/Order.xsd +48 -0
  86. data/vendor/xsd/ukrdc/Schema/Types/PatientNumber.xsd +90 -0
  87. data/vendor/xsd/ukrdc/Schema/Types/PersonalContactType.xsd +11 -0
  88. data/vendor/xsd/ukrdc/Schema/Types/Result.xsd +178 -0
  89. data/vendor/xsd/ukrdc/Schema/UKRDC.xsd +148 -0
  90. metadata +78 -5
  91. data/lib/renalware/breadcrumb.rb +0 -10
@@ -0,0 +1 @@
1
+ !function(e){function t(a){if(r[a])return r[a].exports;var n=r[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,t,r){Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var r=e&&e.__esModule?function(){return e["default"]}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=2)}([function(e,t,r){"use strict";function a(e){return'<div style="'+d+'">'+e+"</div>"}function n(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e}function i(e){return e.charAt(0).toUpperCase()+e.slice(1)}var o,d,s,p=r(1),l=["pdf","html","image","json"],m={printable:null,type:"pdf",header:null,maxWidth:800,font:"TimesNewRoman",font_size:"12pt",honorMarginPadding:!0,honorColor:!1,properties:null,showModal:!1,modalMessage:"Retrieving Document...",frameId:"printJS",border:!0,htmlData:""};e.exports=function(){if(void 0===arguments[0])return window.console.error("printJS expects at least 1 attribute."),!1;var e=new c(arguments);switch(o="max-width: "+e.params.maxWidth+"px !important;"+e.params.font_size+" !important;",d="font-family:"+e.params.font+" !important; font-size: "+e.params.font_size+" !important; width:100%;",s="font-weight:300;",e.params.type){case"pdf":if(p.isFirefox()){var t=window.open(e.params.printable,"_blank");t.focus(),e.params.showModal&&e.disablePrintModal()}else e.pdf();break;case"image":e.image();break;case"html":e.html();break;case"json":e.json();break;default:throw new Error("Invalid print type. Available types are: pdf, html, image and json.")}};var c=function(){var e=arguments[0],t=this;switch(t.params=n({},m),typeof e[0]){case"string":t.params.printable=encodeURI(e[0]),t.params.type=e[1]||m.type;break;case"object":t.params.printable=e[0].printable,t.params.type=e[0].type||m.type,t.params.frameId=e[0].frameId||m.frameId,t.params.header=e[0].header||m.header,t.params.maxWidth=e[0].maxWidth||m.maxWidth,t.params.font=e[0].font||m.font,t.params.font_size=e[0].font_size||m.font_size,t.params.honorMarginPadding="undefined"!=typeof e[0].honorMarginPadding?e[0].honorMarginPadding:m.honorMarginPadding,t.params.properties=e[0].properties||m.properties,t.params.showModal="undefined"!=typeof e[0].showModal?e[0].showModal:m.showModal,t.params.modalMessage=e[0].modalMessage||m.modalMessage;break;default:throw new Error('Unexpected argument type! Expected "string" or "object", got '+typeof e[0])}t.validateInput(),t.params.showModal&&t.showModal();var r=document.getElementById(t.params.frameId);r&&r.parentNode.removeChild(r),p.isIE()&&"pdf"===t.params.type?(t.printFrame=document.createElement("embed"),t.printFrame.setAttribute("type","application/pdf"),t.printFrame.setAttribute("style","width:0px;height:0px;")):(t.printFrame=document.createElement("iframe"),t.printFrame.setAttribute("style","display:none;")),t.printFrame.setAttribute("id",t.params.frameId),"pdf"!==t.params.type&&(t.printFrame.srcdoc="<html><head></head><body></body></html>")};c.prototype.pdf=function(){var e=this;if(e.params.showModal&&!p.isIE()){var t=document.createElement("img");t.src=e.params.printable;var r=new Promise(function(e,r){function a(){t.complete&&(window.clearInterval(n),e("PrintJS: PDF loaded. Read to print."))}var n=setInterval(a,100)});r.then(function(t){e.printFrame.setAttribute("src",e.params.printable),e.print()})}else e.printFrame.setAttribute("src",e.params.printable),e.print()},c.prototype.image=function(){var e=document.createElement("img");e.setAttribute("style","width:100%;"),e.setAttribute("id","printableImage"),e.src=this.params.printable;var t=this,r=document.createElement("div");r.setAttribute("style","width:100%"),r.appendChild(e),t.params.header&&t.addHeader(r),t.params.htmlData=r.outerHTML,t.print()},c.prototype.html=function(){var e=document.getElementById(this.params.printable);if(!e)return window.console.error("Invalid HTML element id: "+this.params.printable),!1;var t=document.createElement("div");t.appendChild(e.cloneNode(!0)),t.setAttribute("style","display:none;"),t.setAttribute("id","printJS-html"),e.parentNode.appendChild(t),t=document.getElementById("printJS-html"),t.setAttribute("style",this.collectStyles(t)+"margin:0 !important;");var r=t.children;this.loopNodesCollectStyles(r),this.params.header&&this.addHeader(t),t.parentNode.removeChild(t),this.params.htmlData=a(t.innerHTML),this.print()},c.prototype.json=function(){if("object"!=typeof this.params.printable)throw new Error("Invalid javascript data object (JSON).");if(!this.params.properties||"object"!=typeof this.params.properties)throw new Error("Invalid properties array for your JSON data.");var e="";this.params.header&&(e+='<h1 style="'+s+'">'+this.params.header+"</h1>"),e+=this.jsonToHTML(),this.params.htmlData=a(e),this.print()},c.prototype.print=function(){function e(){if(a.focus(),p.isIE()||p.isEdge())try{a.contentWindow.document.execCommand("print",!1,null)}catch(e){a.contentWindow.print()}else a.contentWindow.print();r.params.showModal&&r.disablePrintModal()}function t(){"undefined"==typeof a.print?setTimeout(function(){t()},1e3):(a.print(),setTimeout(function(){a.parentNode.removeChild(a)},2e3))}var r=this;document.getElementsByTagName("body")[0].appendChild(r.printFrame);var a=document.getElementById(r.params.frameId);p.isIE()&&"pdf"===r.params.type?t():r.printFrame.onload=function(){if("pdf"===r.params.type)e();else{var t=a.contentWindow||a.contentDocument;t.document&&(t=t.document),t.body.innerHTML=r.params.htmlData,"image"===r.params.type&&p.isChrome()?t.getElementById("printableImage").onload=function(){e()}:e()}}},c.prototype.collectStyles=function(e){var t=this,r=document.defaultView||window,a=[],n="";if(r.getComputedStyle){a=r.getComputedStyle(e,"");for(var i=0;i<a.length;i++){var d=["border","float","box"],s=["clear","display","width","min-width","height","min-height","max-height"];t.params.honorMarginPadding&&s.push("margin","padding"),t.params.honorColor&&s.push("color");for(var p=0;p<s.length;p++)a[i].indexOf(d[p])===-1&&0!==a[i].indexOf(s[p])||(n+=a[i]+":"+a.getPropertyValue(a[i])+";")}}else if(e.currentStyle){a=e.currentStyle;for(var l in a)a.indexOf("border")!==-1&&a.indexOf("color")!==-1&&(n+=l+":"+a[l]+";")}return n+=o},c.prototype.loopNodesCollectStyles=function(e){for(var t=this,r=0;r<e.length;r++){var a=e[r],n=a.tagName;if("INPUT"===n||"TEXTAREA"===n||"SELECT"===n){var i=t.collectStyles(a),o=a.parentNode,d="SELECT"===n?document.createTextNode(a.options[a.selectedIndex].text):document.createTextNode(a.value),s=document.createElement("div");s.appendChild(d),s.setAttribute("style",i),o.appendChild(s),o.removeChild(a)}else a.setAttribute("style",t.collectStyles(a));var p=a.children;p&&p.length&&t.loopNodesCollectStyles(p)}},c.prototype.addHeader=function(e){var t=document.createElement("h1"),r=document.createTextNode(this.params.header);t.appendChild(r),t.setAttribute("style",s),e.insertBefore(t,e.childNodes[0])},c.prototype.jsonToHTML=function(){var e=this,t=this.params.printable,r=this.params.properties,a='<div style="display:flex; flex-direction: column;">';a+='<div style="flex:1; display:flex;">';for(var n=0;n<r.length;n++)a+='<div style="flex:1; padding:5px;">'+i(r[n])+"</div>";a+="</div>";for(var o=0;o<t.length;o++){a+='<div style="flex:1; display:flex;',a+=e.params.border?"border:1px solid lightgray;":"",a+='">';for(var d=0;d<r.length;d++)a+='<div style="flex:1; padding:5px;">'+t[o][r[d]]+"</div>";a+="</div>"}return a+="</div>"},c.prototype.validateInput=function(){if(!this.params.printable)throw new Error("Missing printable information.");if(!this.params.type||"string"!=typeof this.params.type||l.indexOf(this.params.type.toLowerCase())===-1)throw new Error("Invalid print type. Available types are: pdf, html, image and json.")},c.prototype.showModal=function(){var e="font-family:sans-serif; display:table; text-align:center; font-weight:300; font-size:30px; left:0; top:0;position:fixed; z-index: 9990;color: #0460B5; width: 100%; height: 100%; background-color:rgba(255,255,255,.9);transition: opacity .3s ease;",t=document.createElement("div");t.setAttribute("style",e),t.setAttribute("id","printJS-Modal");var r=document.createElement("div");r.setAttribute("style","display:table-cell; vertical-align:middle; padding-bottom:100px;");var a=document.createElement("div");a.setAttribute("class","printClose"),a.setAttribute("id","printClose"),r.appendChild(a);var n=document.createElement("span");n.setAttribute("class","printSpinner"),r.appendChild(n);var i=document.createTextNode(this.params.modalMessage);r.appendChild(i),t.appendChild(r),document.getElementsByTagName("body")[0].appendChild(t);var o=this;document.getElementById("printClose").addEventListener("click",function(){o.disablePrintModal()})},c.prototype.disablePrintModal=function(){var e=document.getElementById("printJS-Modal");e.parentNode.removeChild(e)}},function(e,t){e.exports={isFirefox:function(){return"undefined"!=typeof InstallTrigger},isIE:function(){return!!document.documentMode},isEdge:function(){return!this.isIE()&&!!window.StyleMedia},isChrome:function(){return!!window.chrome&&!!window.chrome.webstore}}},function(e,t,r){window.printJS=r(0)}]);
@@ -0,0 +1,660 @@
1
+
2
+ /*!
3
+ * Client Side Validations - v4.2.10 (https://github.com/DavyJonesLocker/client_side_validations)
4
+ * Copyright (c) 2016 Geremia Taglialatela, Brian Cardarella
5
+ * Licensed under MIT (http://opensource.org/licenses/mit-license.php)
6
+ */
7
+
8
+ (function() {
9
+ var $, validateElement, validateForm, validatorsFor,
10
+ indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
11
+
12
+ $ = jQuery;
13
+
14
+ $.fn.disableClientSideValidations = function() {
15
+ ClientSideValidations.disable(this);
16
+ return this;
17
+ };
18
+
19
+ $.fn.enableClientSideValidations = function() {
20
+ this.filter(ClientSideValidations.selectors.forms).each(function() {
21
+ return ClientSideValidations.enablers.form(this);
22
+ });
23
+ this.filter(ClientSideValidations.selectors.inputs).each(function() {
24
+ return ClientSideValidations.enablers.input(this);
25
+ });
26
+ return this;
27
+ };
28
+
29
+ $.fn.resetClientSideValidations = function() {
30
+ this.filter(ClientSideValidations.selectors.forms).each(function() {
31
+ return ClientSideValidations.reset(this);
32
+ });
33
+ return this;
34
+ };
35
+
36
+ $.fn.validate = function() {
37
+ this.filter(ClientSideValidations.selectors.forms).each(function() {
38
+ return $(this).enableClientSideValidations();
39
+ });
40
+ return this;
41
+ };
42
+
43
+ $.fn.isValid = function(validators) {
44
+ var obj;
45
+ obj = $(this[0]);
46
+ if (obj.is('form')) {
47
+ return validateForm(obj, validators);
48
+ } else {
49
+ return validateElement(obj, validatorsFor(this[0].name, validators));
50
+ }
51
+ };
52
+
53
+ validatorsFor = function(name, validators) {
54
+ var captures, validator, validator_name;
55
+ if (captures = name.match(/\[(\w+_attributes)\].*\[(\w+)\]$/)) {
56
+ for (validator_name in validators) {
57
+ validator = validators[validator_name];
58
+ if (validator_name.match("\\[" + captures[1] + "\\].*\\[\\]\\[" + captures[2] + "\\]$")) {
59
+ name = name.replace(/\[[\da-z_]+\]\[(\w+)\]$/g, "[][$1]");
60
+ }
61
+ }
62
+ }
63
+ return validators[name] || {};
64
+ };
65
+
66
+ validateForm = function(form, validators) {
67
+ var valid;
68
+ form.trigger('form:validate:before.ClientSideValidations');
69
+ valid = true;
70
+ form.find(ClientSideValidations.selectors.validate_inputs).each(function() {
71
+ if (!$(this).isValid(validators)) {
72
+ valid = false;
73
+ }
74
+ return true;
75
+ });
76
+ if (valid) {
77
+ form.trigger('form:validate:pass.ClientSideValidations');
78
+ } else {
79
+ form.trigger('form:validate:fail.ClientSideValidations');
80
+ }
81
+ form.trigger('form:validate:after.ClientSideValidations');
82
+ return valid;
83
+ };
84
+
85
+ validateElement = function(element, validators) {
86
+ var afterValidate, destroyInputName, executeValidators, failElement, local, passElement, remote;
87
+ element.trigger('element:validate:before.ClientSideValidations');
88
+ passElement = function() {
89
+ return element.trigger('element:validate:pass.ClientSideValidations').data('valid', null);
90
+ };
91
+ failElement = function(message) {
92
+ element.trigger('element:validate:fail.ClientSideValidations', message).data('valid', false);
93
+ return false;
94
+ };
95
+ afterValidate = function() {
96
+ return element.trigger('element:validate:after.ClientSideValidations').data('valid') !== false;
97
+ };
98
+ executeValidators = function(context) {
99
+ var fn, i, kind, len, message, ref, valid, validator;
100
+ valid = true;
101
+ for (kind in context) {
102
+ fn = context[kind];
103
+ if (validators[kind]) {
104
+ ref = validators[kind];
105
+ for (i = 0, len = ref.length; i < len; i++) {
106
+ validator = ref[i];
107
+ if (message = fn.call(context, element, validator)) {
108
+ valid = failElement(message);
109
+ break;
110
+ }
111
+ }
112
+ if (!valid) {
113
+ break;
114
+ }
115
+ }
116
+ }
117
+ return valid;
118
+ };
119
+ if (element.attr('name').search(/\[([^\]]*?)\]$/) >= 0) {
120
+ destroyInputName = element.attr('name').replace(/\[([^\]]*?)\]$/, '[_destroy]');
121
+ if ($("input[name='" + destroyInputName + "']").val() === "1") {
122
+ passElement();
123
+ return afterValidate();
124
+ }
125
+ }
126
+ if (element.data('changed') === false) {
127
+ return afterValidate();
128
+ }
129
+ element.data('changed', false);
130
+ local = ClientSideValidations.validators.local;
131
+ remote = ClientSideValidations.validators.remote;
132
+ if (executeValidators(local) && executeValidators(remote)) {
133
+ passElement();
134
+ }
135
+ return afterValidate();
136
+ };
137
+
138
+ if (window.ClientSideValidations === void 0) {
139
+ window.ClientSideValidations = {};
140
+ }
141
+
142
+ if (window.ClientSideValidations.forms === void 0) {
143
+ window.ClientSideValidations.forms = {};
144
+ }
145
+
146
+ window.ClientSideValidations.selectors = {
147
+ inputs: ':input:not(button):not([type="submit"])[name]:visible:enabled',
148
+ validate_inputs: ':input:enabled:visible[data-validate]',
149
+ forms: 'form[data-validate]'
150
+ };
151
+
152
+ window.ClientSideValidations.reset = function(form) {
153
+ var $form, key;
154
+ $form = $(form);
155
+ ClientSideValidations.disable(form);
156
+ for (key in form.ClientSideValidations.settings.validators) {
157
+ form.ClientSideValidations.removeError($form.find("[name='" + key + "']"));
158
+ }
159
+ return ClientSideValidations.enablers.form(form);
160
+ };
161
+
162
+ window.ClientSideValidations.disable = function(target) {
163
+ var $target;
164
+ $target = $(target);
165
+ $target.off('.ClientSideValidations');
166
+ if ($target.is('form')) {
167
+ return ClientSideValidations.disable($target.find(':input'));
168
+ } else {
169
+ $target.removeData('valid');
170
+ $target.removeData('changed');
171
+ return $target.filter(':input').each(function() {
172
+ return $(this).removeAttr('data-validate');
173
+ });
174
+ }
175
+ };
176
+
177
+ window.ClientSideValidations.enablers = {
178
+ form: function(form) {
179
+ var $form, binding, event, ref;
180
+ $form = $(form);
181
+ form.ClientSideValidations = {
182
+ settings: window.ClientSideValidations.forms[$form.attr('id')],
183
+ addError: function(element, message) {
184
+ return ClientSideValidations.formBuilders[form.ClientSideValidations.settings.type].add(element, form.ClientSideValidations.settings, message);
185
+ },
186
+ removeError: function(element) {
187
+ return ClientSideValidations.formBuilders[form.ClientSideValidations.settings.type].remove(element, form.ClientSideValidations.settings);
188
+ }
189
+ };
190
+ ref = {
191
+ 'submit.ClientSideValidations': function(eventData) {
192
+ if (!$form.isValid(form.ClientSideValidations.settings.validators)) {
193
+ eventData.preventDefault();
194
+ eventData.stopImmediatePropagation();
195
+ }
196
+ },
197
+ 'ajax:beforeSend.ClientSideValidations': function(eventData) {
198
+ if (eventData.target === this) {
199
+ $form.isValid(form.ClientSideValidations.settings.validators);
200
+ }
201
+ },
202
+ 'form:validate:after.ClientSideValidations': function(eventData) {
203
+ ClientSideValidations.callbacks.form.after($form, eventData);
204
+ },
205
+ 'form:validate:before.ClientSideValidations': function(eventData) {
206
+ ClientSideValidations.callbacks.form.before($form, eventData);
207
+ },
208
+ 'form:validate:fail.ClientSideValidations': function(eventData) {
209
+ ClientSideValidations.callbacks.form.fail($form, eventData);
210
+ },
211
+ 'form:validate:pass.ClientSideValidations': function(eventData) {
212
+ ClientSideValidations.callbacks.form.pass($form, eventData);
213
+ }
214
+ };
215
+ for (event in ref) {
216
+ binding = ref[event];
217
+ $form.on(event, binding);
218
+ }
219
+ return $form.find(ClientSideValidations.selectors.inputs).each(function() {
220
+ return ClientSideValidations.enablers.input(this);
221
+ });
222
+ },
223
+ input: function(input) {
224
+ var $form, $input, binding, event, form, ref;
225
+ $input = $(input);
226
+ form = input.form;
227
+ $form = $(form);
228
+ ref = {
229
+ 'focusout.ClientSideValidations': function() {
230
+ $(this).isValid(form.ClientSideValidations.settings.validators);
231
+ },
232
+ 'change.ClientSideValidations': function() {
233
+ $(this).data('changed', true);
234
+ },
235
+ 'element:validate:after.ClientSideValidations': function(eventData) {
236
+ ClientSideValidations.callbacks.element.after($(this), eventData);
237
+ },
238
+ 'element:validate:before.ClientSideValidations': function(eventData) {
239
+ ClientSideValidations.callbacks.element.before($(this), eventData);
240
+ },
241
+ 'element:validate:fail.ClientSideValidations': function(eventData, message) {
242
+ var element;
243
+ element = $(this);
244
+ ClientSideValidations.callbacks.element.fail(element, message, function() {
245
+ return form.ClientSideValidations.addError(element, message);
246
+ }, eventData);
247
+ },
248
+ 'element:validate:pass.ClientSideValidations': function(eventData) {
249
+ var element;
250
+ element = $(this);
251
+ ClientSideValidations.callbacks.element.pass(element, function() {
252
+ return form.ClientSideValidations.removeError(element);
253
+ }, eventData);
254
+ }
255
+ };
256
+ for (event in ref) {
257
+ binding = ref[event];
258
+ $input.filter(':not(:radio):not([id$=_confirmation])').each(function() {
259
+ return $(this).attr('data-validate', true);
260
+ }).on(event, binding);
261
+ }
262
+ $input.filter(':checkbox').on('change.ClientSideValidations', function() {
263
+ $(this).isValid(form.ClientSideValidations.settings.validators);
264
+ });
265
+ return $input.filter('[id$=_confirmation]').each(function() {
266
+ var confirmationElement, element, ref1, results;
267
+ confirmationElement = $(this);
268
+ element = $form.find("#" + (this.id.match(/(.+)_confirmation/)[1]) + ":input");
269
+ if (element[0]) {
270
+ ref1 = {
271
+ 'focusout.ClientSideValidations': function() {
272
+ element.data('changed', true).isValid(form.ClientSideValidations.settings.validators);
273
+ },
274
+ 'keyup.ClientSideValidations': function() {
275
+ element.data('changed', true).isValid(form.ClientSideValidations.settings.validators);
276
+ }
277
+ };
278
+ results = [];
279
+ for (event in ref1) {
280
+ binding = ref1[event];
281
+ results.push($("#" + (confirmationElement.attr('id'))).on(event, binding));
282
+ }
283
+ return results;
284
+ }
285
+ });
286
+ }
287
+ };
288
+
289
+ window.ClientSideValidations.validators = {
290
+ all: function() {
291
+ return $.extend({}, ClientSideValidations.validators.local, ClientSideValidations.validators.remote);
292
+ },
293
+ local: {
294
+ absence: function(element, options) {
295
+ if (!/^\s*$/.test(element.val() || '')) {
296
+ return options.message;
297
+ }
298
+ },
299
+ presence: function(element, options) {
300
+ if (/^\s*$/.test(element.val() || '')) {
301
+ return options.message;
302
+ }
303
+ },
304
+ acceptance: function(element, options) {
305
+ var ref;
306
+ switch (element.attr('type')) {
307
+ case 'checkbox':
308
+ if (!element.prop('checked')) {
309
+ return options.message;
310
+ }
311
+ break;
312
+ case 'text':
313
+ if (element.val() !== (((ref = options.accept) != null ? ref.toString() : void 0) || '1')) {
314
+ return options.message;
315
+ }
316
+ }
317
+ },
318
+ format: function(element, options) {
319
+ var message;
320
+ message = this.presence(element, options);
321
+ if (message) {
322
+ if (options.allow_blank === true) {
323
+ return;
324
+ }
325
+ return message;
326
+ }
327
+ if (options["with"] && !new RegExp(options["with"].source, options["with"].options).test(element.val())) {
328
+ return options.message;
329
+ }
330
+ if (options.without && new RegExp(options.without.source, options.without.options).test(element.val())) {
331
+ return options.message;
332
+ }
333
+ },
334
+ numericality: function(element, options) {
335
+ var CHECKS, check, checkValue, fn, form, operator, val;
336
+ val = $.trim(element.val());
337
+ if (!ClientSideValidations.patterns.numericality.test(val)) {
338
+ if (options.allow_blank === true && this.presence(element, {
339
+ message: options.messages.numericality
340
+ })) {
341
+ return;
342
+ }
343
+ return options.messages.numericality;
344
+ }
345
+ val = val.replace(new RegExp("\\" + ClientSideValidations.number_format.delimiter, 'g'), "").replace(new RegExp("\\" + ClientSideValidations.number_format.separator, 'g'), ".");
346
+ if (options.only_integer && !/^[+-]?\d+$/.test(val)) {
347
+ return options.messages.only_integer;
348
+ }
349
+ CHECKS = {
350
+ greater_than: '>',
351
+ greater_than_or_equal_to: '>=',
352
+ equal_to: '==',
353
+ less_than: '<',
354
+ less_than_or_equal_to: '<='
355
+ };
356
+ form = $(element[0].form);
357
+ for (check in CHECKS) {
358
+ operator = CHECKS[check];
359
+ if (!(options[check] != null)) {
360
+ continue;
361
+ }
362
+ checkValue = !isNaN(parseFloat(options[check])) && isFinite(options[check]) ? options[check] : form.find("[name*=" + options[check] + "]").length === 1 ? form.find("[name*=" + options[check] + "]").val() : void 0;
363
+ if ((checkValue == null) || checkValue === '') {
364
+ return;
365
+ }
366
+ fn = new Function("return " + val + " " + operator + " " + checkValue);
367
+ if (!fn()) {
368
+ return options.messages[check];
369
+ }
370
+ }
371
+ if (options.odd && !(parseInt(val, 10) % 2)) {
372
+ return options.messages.odd;
373
+ }
374
+ if (options.even && (parseInt(val, 10) % 2)) {
375
+ return options.messages.even;
376
+ }
377
+ },
378
+ length: function(element, options) {
379
+ var CHECKS, blankOptions, check, fn, message, operator, tokenized_length, tokenizer;
380
+ tokenizer = options.js_tokenizer || "split('')";
381
+ tokenized_length = new Function('element', "return (element.val()." + tokenizer + " || '').length")(element);
382
+ CHECKS = {
383
+ is: '==',
384
+ minimum: '>=',
385
+ maximum: '<='
386
+ };
387
+ blankOptions = {};
388
+ blankOptions.message = options.is ? options.messages.is : options.minimum ? options.messages.minimum : void 0;
389
+ message = this.presence(element, blankOptions);
390
+ if (message) {
391
+ if (options.allow_blank === true) {
392
+ return;
393
+ }
394
+ return message;
395
+ }
396
+ for (check in CHECKS) {
397
+ operator = CHECKS[check];
398
+ if (!options[check]) {
399
+ continue;
400
+ }
401
+ fn = new Function("return " + tokenized_length + " " + operator + " " + options[check]);
402
+ if (!fn()) {
403
+ return options.messages[check];
404
+ }
405
+ }
406
+ },
407
+ exclusion: function(element, options) {
408
+ var lower, message, option, ref, upper;
409
+ message = this.presence(element, options);
410
+ if (message) {
411
+ if (options.allow_blank === true) {
412
+ return;
413
+ }
414
+ return message;
415
+ }
416
+ if (options["in"]) {
417
+ if (ref = element.val(), indexOf.call((function() {
418
+ var i, len, ref1, results;
419
+ ref1 = options["in"];
420
+ results = [];
421
+ for (i = 0, len = ref1.length; i < len; i++) {
422
+ option = ref1[i];
423
+ results.push(option.toString());
424
+ }
425
+ return results;
426
+ })(), ref) >= 0) {
427
+ return options.message;
428
+ }
429
+ }
430
+ if (options.range) {
431
+ lower = options.range[0];
432
+ upper = options.range[1];
433
+ if (element.val() >= lower && element.val() <= upper) {
434
+ return options.message;
435
+ }
436
+ }
437
+ },
438
+ inclusion: function(element, options) {
439
+ var lower, message, option, ref, upper;
440
+ message = this.presence(element, options);
441
+ if (message) {
442
+ if (options.allow_blank === true) {
443
+ return;
444
+ }
445
+ return message;
446
+ }
447
+ if (options["in"]) {
448
+ if (ref = element.val(), indexOf.call((function() {
449
+ var i, len, ref1, results;
450
+ ref1 = options["in"];
451
+ results = [];
452
+ for (i = 0, len = ref1.length; i < len; i++) {
453
+ option = ref1[i];
454
+ results.push(option.toString());
455
+ }
456
+ return results;
457
+ })(), ref) >= 0) {
458
+ return;
459
+ }
460
+ return options.message;
461
+ }
462
+ if (options.range) {
463
+ lower = options.range[0];
464
+ upper = options.range[1];
465
+ if (element.val() >= lower && element.val() <= upper) {
466
+ return;
467
+ }
468
+ return options.message;
469
+ }
470
+ },
471
+ confirmation: function(element, options) {
472
+ if (element.val() !== $("#" + (element.attr('id')) + "_confirmation").val()) {
473
+ return options.message;
474
+ }
475
+ },
476
+ uniqueness: function(element, options) {
477
+ var form, matches, name, name_prefix, name_suffix, valid, value;
478
+ name = element.attr('name');
479
+ if (/_attributes\]\[\d/.test(name)) {
480
+ matches = name.match(/^(.+_attributes\])\[\d+\](.+)$/);
481
+ name_prefix = matches[1];
482
+ name_suffix = matches[2];
483
+ value = element.val();
484
+ if (name_prefix && name_suffix) {
485
+ form = element.closest('form');
486
+ valid = true;
487
+ form.find(':input[name^="' + name_prefix + '"][name$="' + name_suffix + '"]').each(function() {
488
+ if ($(this).attr('name') !== name) {
489
+ if ($(this).val() === value) {
490
+ valid = false;
491
+ return $(this).data('notLocallyUnique', true);
492
+ } else {
493
+ if ($(this).data('notLocallyUnique')) {
494
+ return $(this).removeData('notLocallyUnique').data('changed', true);
495
+ }
496
+ }
497
+ }
498
+ });
499
+ if (!valid) {
500
+ return options.message;
501
+ }
502
+ }
503
+ }
504
+ }
505
+ },
506
+ remote: {
507
+ uniqueness: function(element, options) {
508
+ var data, key, message, name, ref, scope_value, scoped_element, scoped_name;
509
+ message = ClientSideValidations.validators.local.presence(element, options);
510
+ if (message) {
511
+ if (options.allow_blank === true) {
512
+ return;
513
+ }
514
+ return message;
515
+ }
516
+ data = {};
517
+ data.case_sensitive = !!options.case_sensitive;
518
+ if (options.id) {
519
+ data.id = options.id;
520
+ }
521
+ if (options.scope) {
522
+ data.scope = {};
523
+ ref = options.scope;
524
+ for (key in ref) {
525
+ scope_value = ref[key];
526
+ scoped_name = element.attr('name').replace(/\[\w+\]$/, "[" + key + "]");
527
+ scoped_element = $("[name='" + scoped_name + "']");
528
+ $("[name='" + scoped_name + "']:checkbox").each(function() {
529
+ if (this.checked) {
530
+ return scoped_element = this;
531
+ }
532
+ });
533
+ if (scoped_element[0] && scoped_element.val() !== scope_value) {
534
+ data.scope[key] = scoped_element.val();
535
+ scoped_element.unbind("change." + element.id).bind("change." + element.id, function() {
536
+ element.trigger('change.ClientSideValidations');
537
+ return element.trigger('focusout.ClientSideValidations');
538
+ });
539
+ } else {
540
+ data.scope[key] = scope_value;
541
+ }
542
+ }
543
+ }
544
+ if (/_attributes\]/.test(element.attr('name'))) {
545
+ name = element.attr('name').match(/\[\w+_attributes\]/g).pop().match(/\[(\w+)_attributes\]/).pop();
546
+ name += /(\[\w+\])$/.exec(element.attr('name'))[1];
547
+ } else {
548
+ name = element.attr('name');
549
+ }
550
+ if (options['class']) {
551
+ name = options['class'] + '[' + name.split('[')[1];
552
+ }
553
+ data[name] = element.val();
554
+ if ($.ajax({
555
+ url: ClientSideValidations.remote_validators_url_for('uniqueness'),
556
+ data: data,
557
+ async: false,
558
+ cache: false
559
+ }).status === 200) {
560
+ return options.message;
561
+ }
562
+ }
563
+ }
564
+ };
565
+
566
+ window.ClientSideValidations.remote_validators_url_for = function(validator) {
567
+ if (ClientSideValidations.remote_validators_prefix != null) {
568
+ return "//" + window.location.host + "/" + ClientSideValidations.remote_validators_prefix + "/validators/" + validator;
569
+ } else {
570
+ return "//" + window.location.host + "/validators/" + validator;
571
+ }
572
+ };
573
+
574
+ window.ClientSideValidations.disableValidators = function() {
575
+ var func, ref, results, validator;
576
+ if (window.ClientSideValidations.disabled_validators === void 0) {
577
+ return;
578
+ }
579
+ ref = window.ClientSideValidations.validators.remote;
580
+ results = [];
581
+ for (validator in ref) {
582
+ func = ref[validator];
583
+ if (indexOf.call(window.ClientSideValidations.disabled_validators, validator) >= 0) {
584
+ results.push(delete window.ClientSideValidations.validators.remote[validator]);
585
+ } else {
586
+ results.push(void 0);
587
+ }
588
+ }
589
+ return results;
590
+ };
591
+
592
+ window.ClientSideValidations.formBuilders = {
593
+ 'ActionView::Helpers::FormBuilder': {
594
+ add: function(element, settings, message) {
595
+ var form, inputErrorField, label, labelErrorField;
596
+ form = $(element[0].form);
597
+ if (element.data('valid') !== false && (form.find("label.message[for='" + (element.attr('id')) + "']")[0] == null)) {
598
+ inputErrorField = $(settings.input_tag);
599
+ labelErrorField = $(settings.label_tag);
600
+ label = form.find("label[for='" + (element.attr('id')) + "']:not(.message)");
601
+ if (element.attr('autofocus')) {
602
+ element.attr('autofocus', false);
603
+ }
604
+ element.before(inputErrorField);
605
+ inputErrorField.find('span#input_tag').replaceWith(element);
606
+ inputErrorField.find('label.message').attr('for', element.attr('id'));
607
+ labelErrorField.find('label.message').attr('for', element.attr('id'));
608
+ labelErrorField.insertAfter(label);
609
+ labelErrorField.find('label#label_tag').replaceWith(label);
610
+ }
611
+ return form.find("label.message[for='" + (element.attr('id')) + "']").text(message);
612
+ },
613
+ remove: function(element, settings) {
614
+ var errorFieldClass, form, inputErrorField, label, labelErrorField;
615
+ form = $(element[0].form);
616
+ errorFieldClass = $(settings.input_tag).attr('class');
617
+ inputErrorField = element.closest("." + (errorFieldClass.replace(/\ /g, ".")));
618
+ label = form.find("label[for='" + (element.attr('id')) + "']:not(.message)");
619
+ labelErrorField = label.closest("." + errorFieldClass);
620
+ if (inputErrorField[0]) {
621
+ inputErrorField.find("#" + (element.attr('id'))).detach();
622
+ inputErrorField.replaceWith(element);
623
+ label.detach();
624
+ return labelErrorField.replaceWith(label);
625
+ }
626
+ }
627
+ }
628
+ };
629
+
630
+ window.ClientSideValidations.patterns = {
631
+ numericality: /^(-|\+)?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d*)?$/
632
+ };
633
+
634
+ window.ClientSideValidations.callbacks = {
635
+ element: {
636
+ after: function(element, eventData) {},
637
+ before: function(element, eventData) {},
638
+ fail: function(element, message, addError, eventData) {
639
+ return addError();
640
+ },
641
+ pass: function(element, removeError, eventData) {
642
+ return removeError();
643
+ }
644
+ },
645
+ form: {
646
+ after: function(form, eventData) {},
647
+ before: function(form, eventData) {},
648
+ fail: function(form, eventData) {},
649
+ pass: function(form, eventData) {}
650
+ }
651
+ };
652
+
653
+ window.ClientSideValidations.event = (window.Turbolinks != null) && window.Turbolinks.supported ? window.Turbolinks.EVENTS != null ? 'page:change' : 'turbolinks:load' : 'ready';
654
+
655
+ $(document).bind(window.ClientSideValidations.event, function() {
656
+ ClientSideValidations.disableValidators();
657
+ return $(ClientSideValidations.selectors.forms).validate();
658
+ });
659
+
660
+ }).call(this);