behavioursc_dialog.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* This file is part of AToMPM - A Tool for Multi-Paradigm Modelling
  2. * Copyright 2011 by the AToMPM team and licensed under the LGPL
  3. * See COPYING.lesser and README.md in the root of this project for full details
  4. */
  5. __dialogBehaviourStatechart = {
  6. '__STATE_OPEN' : 0,
  7. '__STATE_CLOSED': 1,
  8. '__currentState': undefined,
  9. '__entryActions':{
  10. 0:
  11. function(event)
  12. {
  13. WindowManagement.showDialog();
  14. },
  15. 1:
  16. function(event)
  17. {
  18. WindowManagement.closeDialog(event);
  19. }
  20. },
  21. '__exitActions':{},
  22. /* transition to specified state */
  23. '__T' :
  24. function(s,event)
  25. {
  26. if( this.__currentState in this.__exitActions )
  27. this.__exitActions[this.__currentState](event);
  28. this.__currentState = s;
  29. if( s in this.__entryActions )
  30. this.__entryActions[s](event);
  31. },
  32. /* initialise the statechart */
  33. 'init':
  34. function()
  35. {
  36. this.__currentState = this.__STATE_CLOSED;
  37. },
  38. /* handle an event... only discarded events are allowed to propagate to parent
  39. HTML element
  40. name: internal name of the event
  41. event: the javascript event */
  42. 'handleUserEvent':
  43. function(name,event)
  44. {
  45. if( this.__currentState == this.__STATE_OPEN )
  46. {
  47. if( name == __EVENT_KEYUP_ESC ||
  48. name == __EVENT_CANCELED_DIALOG ||
  49. name == __EVENT_KEYUP_ENTER ||
  50. name == __EVENT_OKAYED_DIALOG )
  51. // let's not look at this ever again
  52. if (__dialog_stack.length == 1)
  53. this.__T(this.__STATE_CLOSED,event);
  54. else
  55. WindowManagement.closeDialog();
  56. else if( name == __EVENT_SHOW_DIALOG )
  57. this.__T(this.__STATE_OPEN,event);
  58. else
  59. return;
  60. if( event && event.stopPropagation )
  61. {
  62. event.stopPropagation();
  63. event.preventDefault();
  64. }
  65. }
  66. else if( this.__currentState == this.__STATE_CLOSED )
  67. {
  68. if( name == __EVENT_SHOW_DIALOG )
  69. this.__T(this.__STATE_OPEN,event);
  70. else
  71. return;
  72. if( event && event.stopPropagation )
  73. {
  74. event.stopPropagation();
  75. event.preventDefault();
  76. }
  77. }
  78. }
  79. };