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.

130 lines
3.7 KiB

  1. package;
  2. import Common;
  3. /**
  4. * Tutorial javascript widget
  5. * @author fbarbut<francois.barbut@gmail.com>
  6. */
  7. class Tuto
  8. {
  9. var name:String;
  10. var step:Int;
  11. static var LAST_ELEMENT :String = null; //last hightlit element
  12. public function new(name:String, step:Int){
  13. this.name = name;
  14. this.step = step;
  15. TutoDatas.get(name, init);
  16. }
  17. /**
  18. * asyn init
  19. * @param tuto
  20. */
  21. function init(tuto)
  22. {
  23. var s = tuto.steps[step];
  24. //close previous popovers
  25. var p = App.jq(".popover");
  26. untyped p.popover('hide');
  27. var t = App.instance.t;
  28. if (t == null) trace("Gettext translator is null");
  29. if (s == null) {
  30. /**
  31. * tutorial is finished : display a modal window
  32. */
  33. var m = App.jq('#myModal');
  34. untyped m.modal('show');
  35. m.addClass("help");
  36. m.find(".modal-header").html("<span class='glyphicon glyphicon-hand-right'></span> "+tuto.name);
  37. m.find(".modal-body").html("<span class='glyphicon glyphicon-ok'></span> "+t._("This tutorial is over."));
  38. var bt = App.jq("<a class='btn btn-default'><span class='glyphicon glyphicon-chevron-right'></span> "+t._("Come back to tutorials page")+"</a>");
  39. bt.click(function(?_) {
  40. untyped m.modal('hide');
  41. js.Browser.location.href = "/contract?stopTuto=1";
  42. });
  43. m.find(".modal-footer").append(bt);
  44. m.find(".modal-dialog").removeClass("modal-lg"); //small window pls
  45. }else if (s.element == null) {
  46. /**
  47. * no element, make a modal window (usually its the first step of the tutorial)
  48. */
  49. var m = App.jq('#myModal');
  50. untyped m.modal('show');
  51. m.addClass("help");
  52. m.find(".modal-body").html(s.text);
  53. m.find(".modal-header").html("<span class='glyphicon glyphicon-hand-right'></span> "+tuto.name);
  54. var bt = App.jq("<a class='btn btn-default'><span class='glyphicon glyphicon-chevron-right'></span> "+t._("OK")+"</a>");
  55. bt.click(function(?_) {
  56. untyped m.modal('hide');
  57. new Tuto(name, step + 1);
  58. });
  59. m.find(".modal-footer").append(bt);
  60. m.find(".modal-dialog").removeClass("modal-lg"); //small window pls
  61. }else {
  62. //prepare Bootstrap "popover"
  63. var x = App.jq(s.element).first().attr("title", tuto.name+" <div class='pull-right'>"+(step+1)+"/"+tuto.steps.length+"</div>");
  64. var text = "<p>" + s.text + "</p>";
  65. var bt = null;
  66. switch(s.action) {
  67. case TANext :
  68. bt = App.jq("<p><a class='btn btn-default btn-sm'><span class='glyphicon glyphicon-chevron-right'></span> "+t._("Next")+"</a></p>");
  69. bt.click(function(?_) {
  70. //untyped m.modal('hide');
  71. new Tuto(name, step + 1);
  72. if(LAST_ELEMENT!=null) App.jq(s.element).removeClass("highlight");
  73. });
  74. default:
  75. }
  76. //configure and open popover
  77. var p = switch(s.placement) {
  78. case TPTop: "top";
  79. case TPBottom : "bottom";
  80. case TPLeft : "left";
  81. case TPRight : "right";
  82. default : null;
  83. }
  84. var options = { container:"body", content:text, html:true , placement:p};
  85. untyped x.popover(options).popover('show');
  86. //add a footer
  87. var footer = App.jq("<div class='footer'><div class='pull-left'></div><div class='pull-right'></div></div>");
  88. if (bt != null) footer.find(".pull-right").append(bt);
  89. footer.find(".pull-left").append(makeCloseButton(t._('Stop')));
  90. App.jq(".popover .popover-content").append(footer);
  91. //highlight
  92. App.jq(s.element).first().addClass("highlight");
  93. LAST_ELEMENT = s.element;
  94. }
  95. }
  96. /**
  97. * Make a "close" bt
  98. */
  99. function makeCloseButton(?text) {
  100. var bt = App.jq("<a class='btn btn-default btn-sm'><span class='glyphicon glyphicon-remove'></span> "+(text==null?"":text)+"</a>");
  101. bt.click(function(?_) {
  102. js.Browser.location.href = "/contract?stopTuto=1";
  103. });
  104. return bt;
  105. }
  106. }