ui.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * User interface objects.
  3. */
  4. var message = {};
  5. message.update = function(data){
  6. var text = typeof(data)=='string' ? data : data.message;
  7. $('#messages').html(text);
  8. }
  9. message.error = function(data){
  10. text = typeof(data)=='string' ? data : data.message;
  11. if(! text){
  12. return;
  13. }
  14. $('#messages').html('<div class="error-message">' + text + '</div>');
  15. }
  16. message.info = function(data){
  17. text = typeof(data)=='string' ? data : data.message;
  18. if(! text){
  19. return;
  20. }
  21. $('#messages').html('<div class="normal-message">' + text + '</div>');
  22. }
  23. message.confirmation = function(data){
  24. text = typeof(data)=='string' ? data : data.message;
  25. if(! text){
  26. return;
  27. }
  28. $('#messages').html('<div class="confirmation-message">' + text + '</div>');
  29. }
  30. message.warning = function(data){
  31. text = typeof(data)=='string' ? data : data.message;
  32. if(! text){
  33. return;
  34. }
  35. $('#messages').html('<div class="warning-message">' + text + '</div>');
  36. }
  37. var ui = {};
  38. ui.message = message;
  39. ui.loading = function(btn){
  40. $(btn).addClass("loading");
  41. };
  42. ui.done = function(btn){
  43. $(btn).removeClass("loading");
  44. };
  45. ui.confirm = function(){
  46. if(!window.confirm(lang.ConfirmYourChoice)){
  47. return false;
  48. } else {
  49. return true;
  50. }
  51. };
  52. ui.remove = function(name, btn){
  53. if(!this.confirm()){
  54. return false;
  55. }
  56. var item = $('#'+name);
  57. var id = item.attr('data-id');
  58. var c_id = item.attr('data-c_id');
  59. var f = function(data){
  60. if(data.success){
  61. item.remove();
  62. }
  63. message.update(data);
  64. ui.done(btn);
  65. };
  66. ui.loading(btn);
  67. ui.proxy.remove(c_id, id, f);
  68. };
  69. ui.remove_by_course = function(name, btn){
  70. if(!this.confirm()){
  71. return false;
  72. }
  73. var item = $('#'+name);
  74. var c_id = item.attr('data-c_id');
  75. var session_id = item.attr('data-session_id');
  76. var f = function(data){
  77. if(data.success){
  78. item.remove();
  79. var wrapper = $('.dataTables_wrapper');
  80. wrapper.remove();
  81. }
  82. message.update(data);
  83. ui.done(btn);
  84. };
  85. ui.loading(btn);
  86. ui.proxy.remove_by_course(c_id, session_id, f);
  87. };