PageRenderTime 32ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/assets/js/custom/calendarscript.js

https://gitlab.com/sylver.gocloud/demo-sw-k12-enrollment
JavaScript | 207 lines | 181 code | 17 blank | 9 comment | 18 complexity | e9ebc721b77253161fa2fb9eb6895de0 MD5 | raw file
  1. $(document).ready(function(){
  2. //higlight a selected cell in a calendar
  3. $(".this_day").click(function(){
  4. $(".this_day").removeClass("selected");
  5. $(this).addClass("selected");
  6. });
  7. //adds data in database.
  8. $("#button").click(function()
  9. {
  10. var selected = $(".selected .day_num").text(); // gets the numerical "day" in the calendar.
  11. var event = $("#new_event").val(); // gets the event. input by user
  12. if((selected == '') || (event == '')){ //checks if "day" or event is empty and performs proper window alert.
  13. if(selected == ''){
  14. alert("Choose proper day.");
  15. $(".this_day").removeClass("selected");
  16. exit;
  17. }
  18. if(event == ''){
  19. alert("Enter event.");
  20. }
  21. }else{
  22. $.ajax({ // if data is OK, ajax is performed.
  23. url: window.location, // data passed to same page.
  24. type: "POST",
  25. data:{
  26. day : selected,
  27. event : event
  28. },
  29. success: function(msg){
  30. alert(selected + " " + event);
  31. location.reload(); // if successful, page is reloaded
  32. }
  33. });
  34. }
  35. });
  36. //deletes data from database.
  37. $("#delete").click(function()
  38. {
  39. var selected = $(".selected .day_num").text(); // gets the numerical "day" in the calendar.
  40. if(selected == ''){
  41. alert("No date selected.");
  42. }else{
  43. var f = confirm("Are you sure?");
  44. if(f == true){
  45. $.ajax({
  46. url:window.location, // data passed to same page.
  47. type:"POST",
  48. data:{
  49. flag : f,
  50. a_day : selected
  51. },
  52. success: function(msg){
  53. location.reload(); // if successful, page is reloaded
  54. }
  55. });
  56. }
  57. }
  58. });
  59. $('#birthdate').datepicker({
  60. dateFormat: 'yy-mm-dd',
  61. changeMonth: true,
  62. changeYear: true,
  63. onSelect: function(dateText, inst)
  64. {
  65. $(this).val(dateText);
  66. alert($(this).val());
  67. }
  68. });
  69. // datepicker for attendance
  70. $('#datepicker').datepicker({
  71. dateFormat: 'MM dd, yy',
  72. changeMonth: true,
  73. showButtonPanel: true,
  74. onSelect: function(dateText, inst)
  75. {
  76. $(this).val(dateText);
  77. }
  78. });
  79. // function for deleting attendance in m.k12/teacher/attendance
  80. $(".confirm_btns").on("click", function(e){
  81. var link = this;
  82. e.preventDefault();
  83. $("<div title='Delete'>Are you sure you want to continue?</div>").dialog({
  84. buttons: {
  85. "OK" : function(){
  86. window.location = link.href;
  87. },
  88. "Cancel" : function(){
  89. $(this).dialog("close");
  90. }
  91. }
  92. });
  93. });
  94. //for viewing subjects of teachers
  95. $(function(){
  96. $("#subj_accordion").accordion({
  97. collapsible: true,
  98. icons: false,
  99. heightStyle: "content"
  100. });
  101. });
  102. //for submitting remarks in report card
  103. $("input.remarks_in").blur(function(){
  104. $("form.remarks_form").submit();
  105. });
  106. //for username generation in hrd or admin (employee_settings/change_settings)
  107. var charArray = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  108. $('#gen_uname').click(function(){
  109. var rand_uname = "";
  110. while(rand_uname.length != 10)
  111. {
  112. rand_uname += charArray.charAt(Math.floor(Math.random()*62)+1);
  113. }
  114. $("<div title='Generated Username'>Use " + rand_uname + " as username?</div>").dialog({
  115. resizable: false,
  116. buttons: {
  117. "OK" : function(){
  118. $('#username').val(rand_uname);
  119. $(this).dialog("close");
  120. },
  121. "Cancel" : function(){
  122. $(this).dialog("close");
  123. }
  124. }
  125. });
  126. });
  127. //for password generation in hrd or admin (employee_settings/change_settings)
  128. $('#gen_pword').click(function(){
  129. var rand_pword = "";
  130. while(rand_pword.length != 7)
  131. {
  132. rand_pword += charArray.charAt(Math.floor(Math.random()*62)+1);
  133. }
  134. $("<div title='Generated Password'>Use " + rand_pword + " as password?</div>").dialog({
  135. resizable: false,
  136. buttons: {
  137. "OK" : function(){
  138. $('#password').val(rand_pword);
  139. $(this).dialog("close");
  140. },
  141. "Cancel" : function(){
  142. $(this).dialog("close");
  143. }
  144. }
  145. });
  146. });
  147. $('#submit_changes').click(function(){
  148. if($('#username').val() == '' && $('#password').val() == ''){
  149. $("<div title='No entry found'>Please enter at least one entry</div>").dialog({
  150. resizable: false,
  151. modal: true,
  152. buttons: {
  153. "OK" : function(){
  154. $(this).dialog("close");
  155. }
  156. }
  157. });
  158. }else
  159. {
  160. $("<div title='Settings Changed'><p>Are you sure?</p><br /><p>Note: Please give changes to employee concerned IMMEDIATELY.</p></div>").dialog({
  161. resizable: false,
  162. modal: true,
  163. buttons: {
  164. "Yes" : function(){
  165. $('#settings_form').submit();
  166. $(this).dialog("close");
  167. },
  168. "Cancel" : function(){
  169. $(this).dialog("close");
  170. }
  171. }
  172. });
  173. }
  174. });
  175. $('.submit_btns').click(function(){
  176. $("<div title='Submit'>Are you sure?</div>").dialog({
  177. resizable: false,
  178. modal: true,
  179. buttons: {
  180. "Yes" : function(){
  181. $(".submit_forms").submit();
  182. $(this).dialog("close");
  183. },
  184. "Cancel" : function(){
  185. $(this).dialog("close");
  186. }
  187. }
  188. });
  189. });
  190. });