Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

message_handler.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 dialog with different states to the user.
  41. *
  42. * @param statesObject object containing all the states of the dialog
  43. * @param loadedFunction function to be called after the prompt is fully loaded
  44. * @param stateChangedFunction function to be called when the state of the dialog is changed
  45. */
  46. my.openDialogWithStates = function(statesObject, loadedFunction, stateChangedFunction) {
  47. var myPrompt = $.prompt(statesObject);
  48. myPrompt.on('impromptu:loaded', loadedFunction);
  49. myPrompt.on('impromptu:statechanged', stateChangedFunction);
  50. };
  51. /**
  52. * Shows a dialog prompting the user to send an error report.
  53. *
  54. * @param titleString the title of the message
  55. * @param msgString the text of the message
  56. * @param error the error that is being reported
  57. */
  58. my.openReportDialog = function(titleString, msgString, error) {
  59. my.openMessageDialog(titleString, msgString);
  60. console.log(error);
  61. //FIXME send the error to the server
  62. };
  63. /**
  64. * Shows an error dialog to the user.
  65. * @param title the title of the message
  66. * @param message the text of the messafe
  67. */
  68. my.showError = function(title, message) {
  69. if(!(title || message)) {
  70. title = title || "Oops!";
  71. message = message || "There was some kind of error";
  72. }
  73. messageHandler.openMessageDialog(title, message);
  74. };
  75. return my;
  76. }(messageHandler || {}));