blob: 660338e3aeb0cd89f917d425873ca95912274f59 [file] [log] [blame]
hebasta75cfca52019-02-19 13:15:27 +01001/**
2 * Guided Tour to explain the UI
3 *
4 * @author Helge Stallkamp
5 */
6
7define(['lib/intro', 'vc'], function(introClass, vcClass) {
hebasta5df796f2019-05-21 15:27:12 +02008
hebasta75cfca52019-02-19 13:15:27 +01009 //needed for localization of labels and contents of the tour
10 const loc = KorAP.Locale;
hebasta5df796f2019-05-21 15:27:12 +020011
hebasta75cfca52019-02-19 13:15:27 +010012 //labels for nextStep, previousStep, done and abort
13 loc.TOUR_lskip = loc.TOUR_lskip || "Abort";
14 loc.TOUR_lprev = loc.TOUR_lprev || "Back";
15 loc.TOUR_lnext = loc.TOUR_lnext || "Next";
16 loc.TOUR_ldone = loc.TOUR_ldone || "Done";
hebasta5df796f2019-05-21 15:27:12 +020017
18 //localization guided tour gTstartSearch
hebasta75cfca52019-02-19 13:15:27 +010019 loc.TOUR_sear1 = loc.TOUR_sear1 || "Enter your search enquiry here.";
hebastad090a512019-07-10 16:36:01 +020020 loc.TOUR_sear2 = loc.TOUR_sear2 || "For example the search for '" + loc.TOUR_Qexample + "'.";
hebasta75cfca52019-02-19 13:15:27 +010021 loc.TOUR_searAnnot = loc.TOUR_searAnnot || "Annotation helper: By clicking here, the annotations of the differents layers are displayed and can be selected.";
22 loc.TOUR_annotAss = loc.TOUR_annotAss || "The annoation assistant helps to formulate queries with annotations";
23 loc.TOUR_vccho1 = loc.TOUR_vccho1 || "Choose corpus by clicking here.";
24 loc.TOUR_vccho2 = loc.TOUR_vccho2 || "Define your corpus here.";
25 loc.TOUR_vcStat = loc.TOUR_vcStat || "Display corpus statistic.";
26 loc.TOUR_qlfield = loc.TOUR_qlfield|| "You can use KorAP with different query languages, select the query language here.";
27 loc.TOUR_help = loc.TOUR_help || "Help and more information about KorAP.";
28 loc.TOUR_glimpse = loc.TOUR_glimpse || "Select to show only the first hits in arbitrary order.";
29 loc.TOUR_seargo = loc.TOUR_seargo || "Start the search.";
hebasta5df796f2019-05-21 15:27:12 +020030 //localization guided Tour gTshowResults
31 loc.TOUR_result = loc.TOUR_result || "Have fun with KorAP!";
hebasta75cfca52019-02-19 13:15:27 +010032
33 //localization of button labels
hebasta5df796f2019-05-21 15:27:12 +020034 let labelOptions = {
35 'skipLabel': loc.TOUR_lskip,
36 'prevLabel': loc.TOUR_lprev,
37 'nextLabel': loc.TOUR_lnext,
38 'doneLabel': loc.TOUR_ldone,
39 'showStepNumbers': false,
hebasta75cfca52019-02-19 13:15:27 +010040 };
hebasta5df796f2019-05-21 15:27:12 +020041
hebasta75cfca52019-02-19 13:15:27 +010042 return{
hebasta5df796f2019-05-21 15:27:12 +020043
hebasta75cfca52019-02-19 13:15:27 +010044 /**
hebasta5df796f2019-05-21 15:27:12 +020045 * Guided Tour gTstartSearch: Explains the search functionality
hebasta75cfca52019-02-19 13:15:27 +010046 */
hebasta5df796f2019-05-21 15:27:12 +020047 gTstartSearch:function(elparam){
48
49 let intro = introClass();
50 intro.setOptions(labelOptions);
51 intro.setOption('doneLabel', loc.TOUR_seargo);
52
53 //for testing purposes
hebasta75cfca52019-02-19 13:15:27 +010054 var doe = document;
55 if(elparam){
56 doe = elparam;
57 }
hebasta5df796f2019-05-21 15:27:12 +020058
hebasta75cfca52019-02-19 13:15:27 +010059 let input = doe.querySelector("#q-field");
60 input.value="";
61
hebasta5df796f2019-05-21 15:27:12 +020062
hebasta75cfca52019-02-19 13:15:27 +010063 //steps of the example tour
64 let Steps =[
65 {
66 element: '#searchbar',
67 intro: loc.TOUR_sear1,
68 position: 'bottom'
69 },
70 {
71 element: '#searchbar',
72 intro: loc.TOUR_sear2,
73 position: 'bottom'
74 },
75 {
76 element: '#hint',
77 intro: loc.TOUR_searAnnot,
78 position: 'bottom'
hebasta5df796f2019-05-21 15:27:12 +020079 },
80 {
hebasta75cfca52019-02-19 13:15:27 +010081 element:'#vc-choose',
82 intro: loc.TOUR_vccho1,
83 position: "bottom",
hebasta5df796f2019-05-21 15:27:12 +020084 },
85 {
86 element:'#vc-view',
87 intro: loc.TOUR_vccho2,
88 position: "bottom",
89 },
90 {
hebastad090a512019-07-10 16:36:01 +020091 element: doe.querySelector('.statistic'),
92 intro: loc.TOUR_vcStat,
93 position: "left",
94 },
95 {
hebasta5df796f2019-05-21 15:27:12 +020096 element: doe.querySelector('#ql-field').parentNode,
97 intro: loc.TOUR_qlfield,
98 position: "bottom",
99 },
100 {
101 element:'#glimpse',
102 intro: loc.TOUR_glimpse,
103 position: "bottom",
104 },
105 {
106 element:'#view-tutorial',
107 intro: loc.TOUR_help,
108 position: "bottom",
109 },
110 {
111 element: '#qsubmit',
112 intro: loc.TOUR_seargo,
113 position: "bottom",
114 },
115 ];
116
hebasta75cfca52019-02-19 13:15:27 +0100117 //pass in the Steps array created earlier
118 intro.setOptions({steps: Steps});
hebasta5df796f2019-05-21 15:27:12 +0200119
hebasta75cfca52019-02-19 13:15:27 +0100120 //total number of steps, needed for jasmine tests
hebasta5df796f2019-05-21 15:27:12 +0200121 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
hebasta75cfca52019-02-19 13:15:27 +0100122 intro.stepCount = Steps.length;
hebasta5df796f2019-05-21 15:27:12 +0200123
hebasta75cfca52019-02-19 13:15:27 +0100124 //array of intro content needed for efficient testing
125 intro.testIntros = [];
hebasta5df796f2019-05-21 15:27:12 +0200126
127 for(let i = 0; i< Steps.length; i++){
hebasta75cfca52019-02-19 13:15:27 +0100128 intro.testIntros.push(Steps[i].intro);
hebasta5df796f2019-05-21 15:27:12 +0200129 }
130
131 //changes before executing the single steps
132 intro.onbeforechange(function(targetedElement){
133 switch(targetedElement.id){
134 case "searchbar":
hebastad090a512019-07-10 16:36:01 +0200135 /*
136 * TODO:
137 * #268 is not merged at the time beeing:
138 * introJs.currentStep() merge requested https://github.com/usablica/intro.js/pull/268/files
139 */
hebasta5df796f2019-05-21 15:27:12 +0200140 if(this._currentStep == 1){
141 input = doe.querySelector('#q-field');
142 input.value= loc.TOUR_Qexample;
143 }
144 break;
145
146 case "vc-view":
147 vchoo = doe.querySelector("#vc-choose");
148 vcv = doe.querySelector("#vc-view");
149 KorAP._delete.apply(KorAP.vc.root());
150 KorAP.vc.root().key("creationDate").update();
151 KorAP.vc.root().value("1820").update();
152 if(!(vcv.querySelector(".active"))){
153 vchoo.click();
hebastad090a512019-07-10 16:36:01 +0200154 /*
155 * Intro.js caches elements at the beginning, so element and position has to be set again.
156 */
157 intro._introItems[5].element = doe.querySelector(".statistic");
158 intro._introItems[5].position = "bottom";
hebasta5df796f2019-05-21 15:27:12 +0200159 }
160 break;
hebasta75cfca52019-02-19 13:15:27 +0100161
hebasta5df796f2019-05-21 15:27:12 +0200162 /*
163 * Sets button labels for the last step of the tour
164 * Because Kalamar is a multipage webapplication, this tours starts by
165 * completion the gTshowResults Tour. Therefore, the skip-button is removed
166 * and the label of the done button changed.
167 */
168
169 case "qsubmit":
170 intro.setOption('hideNext', true);
171 break;
172 }
hebasta75cfca52019-02-19 13:15:27 +0100173 });
hebasta5df796f2019-05-21 15:27:12 +0200174
175
176 // Execute at the end of the tour (By clicking at the done-Button)
177 intro.oncomplete(function(){
178 KorAP.session.set("tour", true);
179 let form = doe.getElementById("searchform");
180 form.submit();
181 //input.value="";
182 //KorAP._delete.apply(KorAP.vc.root());
183 });
184
185 return intro;
hebasta75cfca52019-02-19 13:15:27 +0100186 },
hebasta5df796f2019-05-21 15:27:12 +0200187
188
189 /* Guided Tour to explain the different views of the results */
190 gTshowResults: function(elparam){
191 if(elparam){
192 doe = elparam;
193 }
194 let tourR = introClass();
195 let StepsSR = [
196 {
197 intro: loc.TOUR_result,
198 }
199 ]
200 tourR.setOptions({steps:StepsSR});
201 tourR.setOptions(labelOptions);
202
203 tourR.onbeforechange(function (){
204 KorAP.session.set("tour", false);
205 });
206
207 return tourR;
208 },
209
hebasta75cfca52019-02-19 13:15:27 +0100210 }
211});