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.

message_handler.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. var messageHandler = (function(my) {
  2. /**
  3. * Shows a message to the user.
  4. *
  5. * @param titleString the title of the message
  6. * @param messageString the text of the message
  7. */
  8. my.openMessageDialog = function(titleString, messageString) {
  9. $.prompt(messageString,
  10. {
  11. title: titleString,
  12. persistent: false
  13. }
  14. );
  15. };
  16. /**
  17. * Shows a message to the user with two buttons: first is given as a parameter and the second is Cancel.
  18. *
  19. * @param titleString the title of the message
  20. * @param msgString the text of the message
  21. * @param persistent boolean value which determines whether the message is persistent or not
  22. * @param leftButton the fist button's text
  23. * @param submitFunction function to be called on submit
  24. * @param loadedFunction function to be called after the prompt is fully loaded
  25. */
  26. my.openTwoButtonDialog = function(titleString, msgString, persistent, leftButton, submitFunction, loadedFunction) {
  27. var buttons = {};
  28. buttons[leftButton] = true;
  29. buttons.Cancel = false;
  30. $.prompt(msgString, {
  31. title: titleString,
  32. persistent: false,
  33. buttons: buttons,
  34. defaultButton: 1,
  35. loaded: loadedFunction,
  36. submit: submitFunction
  37. });
  38. };
  39. /**
  40. * Shows a message to the user with two buttons: first is given as a parameter and the second is Cancel.
  41. *
  42. * @param titleString the title of the message
  43. * @param msgString the text of the message
  44. * @param persistent boolean value which determines whether the message is persistent or not
  45. * @param buttons object with the buttons. The keys must be the name of the button and value is the value
  46. * that will be passed to submitFunction
  47. * @param submitFunction function to be called on submit
  48. * @param loadedFunction function to be called after the prompt is fully loaded
  49. */
  50. my.openDialog = function(titleString, msgString, persistent, buttons, submitFunction, loadedFunction) {
  51. $.prompt(msgString, {
  52. title: titleString,
  53. persistent: false,
  54. buttons: buttons,
  55. defaultButton: 1,
  56. loaded: loadedFunction,
  57. submit: submitFunction
  58. });
  59. };
  60. /**
  61. * Shows a dialog with different states to the user.
  62. *
  63. * @param statesObject object containing all the states of the dialog
  64. * @param loadedFunction function to be called after the prompt is fully loaded
  65. * @param stateChangedFunction function to be called when the state of the dialog is changed
  66. */
  67. my.openDialogWithStates = function(statesObject, loadedFunction, stateChangedFunction) {
  68. var myPrompt = $.prompt(statesObject);
  69. myPrompt.on('impromptu:loaded', loadedFunction);
  70. myPrompt.on('impromptu:statechanged', stateChangedFunction);
  71. };
  72. /**
  73. * Shows a dialog prompting the user to send an error report.
  74. *
  75. * @param titleString the title of the message
  76. * @param msgString the text of the message
  77. * @param error the error that is being reported
  78. */
  79. my.openReportDialog = function(titleString, msgString, error) {
  80. my.openMessageDialog(titleString, msgString);
  81. console.log(error);
  82. //FIXME send the error to the server
  83. };
  84. /**
  85. * Shows an error dialog to the user.
  86. * @param title the title of the message
  87. * @param message the text of the messafe
  88. */
  89. my.showError = function(title, message) {
  90. if(!(title || message)) {
  91. title = title || "Oops!";
  92. message = message || "There was some kind of error";
  93. }
  94. messageHandler.openMessageDialog(title, message);
  95. };
  96. return my;
  97. }(messageHandler || {}));