package; import Common; /** * Tutorial javascript widget * @author fbarbut */ class Tuto { var name:String; var step:Int; static var LAST_ELEMENT :String = null; //last hightlit element public function new(name:String, step:Int){ this.name = name; this.step = step; TutoDatas.get(name, init); } /** * asyn init * @param tuto */ function init(tuto) { var s = tuto.steps[step]; //close previous popovers var p = App.jq(".popover"); untyped p.popover('hide'); var t = App.instance.t; if (t == null) trace("Gettext translator is null"); if (s == null) { /** * tutorial is finished : display a modal window */ var m = App.jq('#myModal'); untyped m.modal('show'); m.addClass("help"); m.find(".modal-header").html(" "+tuto.name); m.find(".modal-body").html(" "+t._("This tutorial is over.")); var bt = App.jq(" "+t._("Come back to tutorials page")+""); bt.click(function(?_) { untyped m.modal('hide'); js.Browser.location.href = "/contract?stopTuto=1"; }); m.find(".modal-footer").append(bt); m.find(".modal-dialog").removeClass("modal-lg"); //small window pls }else if (s.element == null) { /** * no element, make a modal window (usually its the first step of the tutorial) */ var m = App.jq('#myModal'); untyped m.modal('show'); m.addClass("help"); m.find(".modal-body").html(s.text); m.find(".modal-header").html(" "+tuto.name); var bt = App.jq(" "+t._("OK")+""); bt.click(function(?_) { untyped m.modal('hide'); new Tuto(name, step + 1); }); m.find(".modal-footer").append(bt); m.find(".modal-dialog").removeClass("modal-lg"); //small window pls }else { //prepare Bootstrap "popover" var x = App.jq(s.element).first().attr("title", tuto.name+"
"+(step+1)+"/"+tuto.steps.length+"
"); var text = "

" + s.text + "

"; var bt = null; switch(s.action) { case TANext : bt = App.jq("

"+t._("Next")+"

"); bt.click(function(?_) { //untyped m.modal('hide'); new Tuto(name, step + 1); if(LAST_ELEMENT!=null) App.jq(s.element).removeClass("highlight"); }); default: } //configure and open popover var p = switch(s.placement) { case TPTop: "top"; case TPBottom : "bottom"; case TPLeft : "left"; case TPRight : "right"; default : null; } var options = { container:"body", content:text, html:true , placement:p}; untyped x.popover(options).popover('show'); //add a footer var footer = App.jq(""); if (bt != null) footer.find(".pull-right").append(bt); footer.find(".pull-left").append(makeCloseButton(t._('Stop'))); App.jq(".popover .popover-content").append(footer); //highlight App.jq(s.element).first().addClass("highlight"); LAST_ELEMENT = s.element; } } /** * Make a "close" bt */ function makeCloseButton(?text) { var bt = App.jq(" "+(text==null?"":text)+""); bt.click(function(?_) { js.Browser.location.href = "/contract?stopTuto=1"; }); return bt; } }