Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

message_handler.js 4.0KB

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