not really known
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.

477 lines
14 KiB

  1. // Tutorial handling
  2. define([], function () {
  3. var tutorial = {};
  4. var tour;
  5. var launched = false;
  6. tutorial.elements = [];
  7. tutorial.icons = null;
  8. // Init tutorial
  9. tutorial.init = function() {
  10. var prevString = l10n.get("TutoPrev");
  11. var nextString = l10n.get("TutoNext");
  12. var endString = l10n.get("TutoEnd");
  13. this.activityId = "org.olpcfrance.sharednotes";
  14. var gotoStep = undefined;
  15. tour = new Tour({
  16. template: "\
  17. <div class='popover tour'>\
  18. <div class='arrow'></div>\
  19. <h3 class='popover-title tutorial-title'></h3>\
  20. <table><tr><td style='vertical-align:top;'><div id='icon-tutorial' style='visibility:hidden;display:inline-block;'></div>\
  21. </td><td><div class='popover-content'></div></td></tr></table>\
  22. <div class='popover-navigation' style='display: flex; flex-wrap:wrap; justify-content: center; align-items: center'>\
  23. <div class='tutorial-prev-icon icon-button' data-role='prev'>\
  24. <div class='tutorial-prev-icon1 web-activity'>\
  25. <div class='tutorial-prev-icon2 web-activity-icon'></div>\
  26. <div class='tutorial-prev-icon3 web-activity-disable'></div>\
  27. </div>\
  28. <div class='icon-tutorial-text'>"+prevString+"</div>\
  29. </div>\
  30. <span data-role='separator' style='margin: 4px'>|</span>\
  31. <div class='tutorial-next-icon icon-button' data-role='next'>\
  32. <div class='tutorial-next-icon1 web-activity'>\
  33. <div class='tutorial-next-icon2 web-activity-icon'></div>\
  34. <div class='tutorial-next-icon3 web-activity-disable'></div>\
  35. </div>\
  36. <div class='icon-tutorial-text'>"+nextString+"</div>\
  37. </div>\
  38. <div class='tutorial-end-icon icon-button' data-role='end'>\
  39. <div class='tutorial-end-icon1 web-activity'>\
  40. <div class='tutorial-end-icon2 web-activity-icon'></div>\
  41. <div class='tutorial-end-icon3 web-activity-disable'></div>\
  42. </div>\
  43. <div class='icon-tutorial-text'>"+endString+"</div>\
  44. </div>\
  45. </div>\
  46. </div>",
  47. storage: false,
  48. backdrop: true,
  49. steps: [],
  50. onShown: function() {
  51. if (tutorial.icons && tutorial.icons.steps && tutorial.icons.steps[tour.getCurrentStep()]) {
  52. var icon = tutorial.icons.steps[tour.getCurrentStep()];
  53. var iconElement = document.getElementById("icon-tutorial");
  54. iconElement.style.visibility = 'visible';
  55. iconElement.style.backgroundImage = "url('"+ icon.directory + "/" + icon.icon + "')";
  56. iconElement.style.backgroundSize = icon.size + "px";
  57. iconElement.style.width = icon.size + "px";
  58. iconElement.style.height = icon.size + "px";
  59. iconElement.style.marginTop = "15px";
  60. iconElement.style.marginLeft = "5px";
  61. if (icon.color) {
  62. iconLib.colorize(iconElement, icon.color, function(){});
  63. }
  64. }
  65. },
  66. onEnd: function() {
  67. tutorial.elements = [];
  68. tutorial.icons = null;
  69. }
  70. });
  71. var currentView = app.getView();
  72. if (currentView == constant.radialView) {
  73. tour.addSteps([
  74. {
  75. element: "",
  76. orphan: true,
  77. placement: "bottom",
  78. title: l10n.get("TutoInitMainTitle"),
  79. content: l10n.get("TutoInitMainContent")
  80. },
  81. {
  82. element: tutorial.getElement("owner"),
  83. placement: "right",
  84. title: l10n.get("TutoUserTitle"),
  85. content: l10n.get("TutoUserContent")
  86. },
  87. {
  88. element: tutorial.getElement("activity"),
  89. placement: "bottom",
  90. title: l10n.get("TutoActivityTitle"),
  91. content: l10n.get("TutoActivityContent")
  92. },
  93. {
  94. element: tutorial.getElement("journal"),
  95. placement: "right",
  96. title: l10n.get("TutoJournalTitle"),
  97. content: l10n.get("TutoJournalContent")
  98. },
  99. {
  100. element: tutorial.getElement("radialbutton"),
  101. placement: "bottom",
  102. title: l10n.get("TutoFavoriteTitle"),
  103. content: l10n.get("TutoFavoriteContent")
  104. },
  105. {
  106. element: tutorial.getElement("listbutton"),
  107. placement: "bottom",
  108. title: l10n.get("TutoListTitle"),
  109. content: l10n.get("TutoListContent")
  110. },
  111. {
  112. element: tutorial.getElement("searchtext"),
  113. placement: "bottom",
  114. title: l10n.get("TutoSearchTitle"),
  115. content: l10n.get("TutoSearchContent")
  116. },
  117. {
  118. element: tutorial.getElement("offlinebutton"),
  119. placement: "bottom",
  120. title: l10n.get("TutoOfflineTitle"),
  121. content: l10n.get("TutoOfflineContent")
  122. },
  123. {
  124. element: tutorial.getElement("neighborbutton"),
  125. placement: "bottom",
  126. title: l10n.get("TutoNeighborTitle"),
  127. content: l10n.get("TutoNeighborContent")
  128. },
  129. {
  130. element: "",
  131. orphan: true,
  132. placement: "bottom",
  133. title: l10n.get("TutoRunTitle"),
  134. content: l10n.get("TutoRunContent")
  135. }
  136. ]);
  137. tutorial.icons = {
  138. steps: {
  139. 0: {icon: 'owner-icon.svg', directory: 'icons', size: constant.sizeEmpty, color: preferences.getColor()},
  140. 3: {icon: 'activity-journal.svg', directory: 'icons', size: constant.sizeEmpty},
  141. 7: {icon: 'cloud-warning.svg', directory: 'icons', size: constant.sizeEmpty},
  142. 9: {icon: 'activity-icon.svg', directory: 'activities/SharedNotes.activity/activity', size: constant.sizeEmpty},
  143. }
  144. };
  145. } else if (currentView == constant.listView) {
  146. var activities = tutorial.getElementAsObject("activities");
  147. if (!activities) {
  148. tour.addSteps([
  149. {
  150. element: tutorial.getElement("radialbutton"),
  151. placement: "bottom",
  152. title: l10n.get("TutoFavoriteTitle"),
  153. content: l10n.get("TutoFavoriteContent")
  154. },
  155. {
  156. element: tutorial.getElement("listbutton"),
  157. placement: "bottom",
  158. title: l10n.get("TutoListTitle"),
  159. content: l10n.get("TutoListContent")
  160. },
  161. {
  162. element: tutorial.getElement("favoriteitembutton"),
  163. placement: "bottom",
  164. title: l10n.get("TutoFavswitchTitle"),
  165. content: l10n.get("TutoFavswitchContent")
  166. },
  167. {
  168. element: tutorial.getElement("searchtext"),
  169. placement: "bottom",
  170. title: l10n.get("TutoSearchTitle"),
  171. content: l10n.get("TutoSearchContent")
  172. },
  173. {
  174. element: tutorial.getElement("neighborbutton"),
  175. placement: "bottom",
  176. title: l10n.get("TutoNeighborTitle"),
  177. content: l10n.get("TutoNeighborContent")
  178. }
  179. ]);
  180. } else {
  181. var steps = [];
  182. tutorial.icons = {steps: {}};
  183. for (var i = 0 ; i < activities.length ; i++) {
  184. steps.push({
  185. element: "",
  186. orphan: true,
  187. placement: "bottom",
  188. title: activities[i].title,
  189. content: activities[i].description
  190. });
  191. tutorial.icons.steps[i] = activities[i].icon;
  192. }
  193. tour.addSteps(steps);
  194. gotoStep = tutorial.getElementAsObject("step");
  195. }
  196. } else if (currentView == constant.journalView) {
  197. tour.addSteps([
  198. {
  199. element: "",
  200. orphan: true,
  201. placement: "bottom",
  202. title: l10n.get("TutoJournalIntroTitle"),
  203. content: l10n.get("TutoJournalIntroContent")
  204. },
  205. {
  206. element: tutorial.getElement("activityitem"),
  207. placement: "bottom",
  208. title: l10n.get("TutoJournalActivityTitle"),
  209. content: l10n.get("TutoJournalActivityContent")
  210. },
  211. {
  212. element: tutorial.getElement("timeitem"),
  213. placement: "bottom",
  214. title: l10n.get("TutoJournalTimeTitle"),
  215. content: l10n.get("TutoJournalTimeContent")
  216. },
  217. {
  218. element: tutorial.getElement("titleitem"),
  219. placement: "bottom",
  220. title: l10n.get("TutoJournalTitleTitle"),
  221. content: l10n.get("TutoJournalTitleContent")
  222. },
  223. {
  224. element: tutorial.getElement("favoriteitem"),
  225. placement: "bottom",
  226. title: l10n.get("TutoJournalFavoriteTitle"),
  227. content: l10n.get("TutoJournalFavoriteContent")
  228. },
  229. {
  230. element: tutorial.getElement("checkitem"),
  231. placement: "bottom",
  232. title: l10n.get("TutoJournalCheckTitle"),
  233. content: l10n.get("TutoJournalCheckContent")
  234. },
  235. {
  236. element: tutorial.getElement("searchtext"),
  237. placement: "bottom",
  238. title: l10n.get("TutoJournalSearchTitle"),
  239. content: l10n.get("TutoJournalSearchContent")
  240. },
  241. {
  242. element: tutorial.getElement("favoritebutton"),
  243. placement: "bottom",
  244. title: l10n.get("TutoJournalFavButtonTitle"),
  245. content: l10n.get("TutoJournalFavButtonContent")
  246. },
  247. {
  248. element: tutorial.getElement("typeselect"),
  249. placement: "bottom",
  250. title: l10n.get("TutoJournalTypeTitle"),
  251. content: l10n.get("TutoJournalTypeContent")
  252. },
  253. {
  254. element: tutorial.getElement("timeselect"),
  255. placement: "bottom",
  256. title: l10n.get("TutoJournalTimeButtonTitle"),
  257. content: l10n.get("TutoJournalTimeButtonContent")
  258. },
  259. {
  260. element: tutorial.getElement("sortselect"),
  261. placement: "bottom",
  262. title: l10n.get("TutoJournalSortButtonTitle"),
  263. content: l10n.get("TutoJournalSortButtonContent")
  264. },
  265. {
  266. element: tutorial.getElement("fromdevicebutton"),
  267. placement: "bottom",
  268. title: l10n.get("TutoJournalFromDeviceButtonTitle"),
  269. content: l10n.get("TutoJournalFromDeviceButtonContent")
  270. },
  271. {
  272. element: tutorial.getElement("journalbutton"),
  273. placement: "top",
  274. title: l10n.get("TutoJournalLocalTitle"),
  275. content: l10n.get("TutoJournalLocalContent")
  276. },
  277. {
  278. element: tutorial.getElement("cloudonebutton"),
  279. placement: "top",
  280. title: l10n.get("TutoJournalCloudOneTitle"),
  281. content: l10n.get("TutoJournalCloudOneContent")
  282. },
  283. {
  284. element: tutorial.getElement("cloudallbutton"),
  285. placement: "top",
  286. title: l10n.get("TutoJournalCloudAllTitle"),
  287. content: l10n.get("TutoJournalCloudAllContent")
  288. },
  289. {
  290. element: tutorial.getElement("radialbutton"),
  291. placement: "bottom",
  292. title: l10n.get("TutoGotoHomeTitle"),
  293. content: l10n.get("TutoGotoHomeContent")
  294. }
  295. ]);
  296. } else if (currentView == constant.neighborhoodView) {
  297. tour.addSteps([
  298. {
  299. element: "",
  300. orphan: true,
  301. placement: "bottom",
  302. title: l10n.get("TutoNeighborIntroTitle"),
  303. content: window.sugarizerOS ? l10n.get("TutoNeighborIntroContent2") : l10n.get("TutoNeighborIntroContent")
  304. },
  305. {
  306. element: tutorial.getElement("owner"),
  307. placement: "right",
  308. title: l10n.get("TutoNeighborUserTitle"),
  309. content: l10n.get("TutoNeighborUserContent")
  310. },
  311. {
  312. element: tutorial.getElement("server"),
  313. placement: "auto",
  314. title: l10n.get("TutoNeighborServerTitle"),
  315. content: l10n.get("TutoNeighborServerContent")
  316. },
  317. {
  318. element: tutorial.getElement("other"),
  319. placement: "auto",
  320. title: l10n.get("TutoNeighborOtherTitle"),
  321. content: l10n.get("TutoNeighborOtherContent")
  322. },
  323. {
  324. element: tutorial.getElement("activity"),
  325. placement: "auto",
  326. title: l10n.get("TutoNeighborActivityTitle"),
  327. content: l10n.get("TutoNeighborActivityContent")
  328. },
  329. {
  330. element: tutorial.getElement("wifi"),
  331. placement: "auto",
  332. title: l10n.get("TutoNeighborWifiTitle"),
  333. content: l10n.get("TutoNeighborWifiContent")
  334. },
  335. {
  336. element: tutorial.getElement("radialbutton"),
  337. placement: "bottom",
  338. title: l10n.get("TutoGotoHomeTitle"),
  339. content: l10n.get("TutoGotoHomeContent")
  340. }
  341. ]);
  342. } else if (currentView == constant.initView) {
  343. var previous = {
  344. element: tutorial.getElement("previous"),
  345. placement: "top",
  346. title: l10n.get("TutoInitPreviousTitle"),
  347. content: l10n.get("TutoInitPreviousContent")
  348. };
  349. var next = {
  350. element: tutorial.getElement("next"),
  351. placement: "top",
  352. title: l10n.get("TutoInitNextTitle"),
  353. content: l10n.get("TutoInitNextContent")
  354. };
  355. var createMode = tutorial.getElementAsObject("createnew");
  356. var steps = [
  357. [
  358. {
  359. element: "",
  360. orphan: true,
  361. placement: "bottom",
  362. title: l10n.get("TutoInitIntroTitle"),
  363. content: l10n.get("TutoInitIntroTitleIntroContent")
  364. },
  365. {
  366. element: tutorial.getElement("newuser"),
  367. placement: "left",
  368. title: l10n.get("TutoInitNewUserTitle"),
  369. content: l10n.get("TutoInitNewUserContent")
  370. },
  371. {
  372. element: tutorial.getElement("login"),
  373. placement: "right",
  374. title: l10n.get("TutoInitLoginTitle"),
  375. content: l10n.get("TutoInitLoginContent")
  376. },
  377. {
  378. element: tutorial.getElement("historybox"),
  379. placement: "bottom",
  380. title: l10n.get("TutoInitHistoryTitle"),
  381. content: l10n.get("TutoInitHistoryContent")
  382. },
  383. {
  384. element: tutorial.getElement("helpbutton"),
  385. placement: "bottom",
  386. title: l10n.get("TutoInitHelpTitle"),
  387. content: l10n.get("TutoInitHelpContent")
  388. },
  389. ],
  390. [
  391. {
  392. element: tutorial.getElement("serverbox"),
  393. placement: "bottom",
  394. title: l10n.get("TutoInitServerTitle"),
  395. content: l10n.get("TutoInitServerContent")
  396. },
  397. {
  398. element: tutorial.getElement("qrcode"),
  399. placement: "bottom",
  400. title: l10n.get("TutoInitQRCodeTitle"),
  401. content: l10n.get("TutoInitQRCodeContent")
  402. },
  403. previous,
  404. next,
  405. ],
  406. [
  407. {
  408. element: tutorial.getElement("namebox"),
  409. placement: "bottom",
  410. title: (createMode ? l10n.get("TutoInitNameNewTitle") : l10n.get("TutoInitNameTitle")),
  411. content: (createMode ? l10n.get("TutoInitNameNewContent") : l10n.get("TutoInitNameContent"))
  412. },
  413. previous,
  414. next,
  415. ],
  416. [
  417. {
  418. element: tutorial.getElement("passbox"),
  419. placement: "right",
  420. title: (createMode ? l10n.get("TutoInitPasswordNewTitle") : l10n.get("TutoInitPasswordTitle")),
  421. content: (createMode ? l10n.get("TutoInitPasswordNewContent") : l10n.get("TutoInitPasswordContent"))
  422. },
  423. previous,
  424. next,
  425. ],
  426. [
  427. {
  428. element: (createMode ? tutorial.getElement("owner") : tutorial.getElement("passbox")),
  429. placement: "right",
  430. title: (createMode ? l10n.get("TutoInitColorTitle") : l10n.get("TutoInitPasswordTitle")),
  431. content: (createMode ? l10n.get("TutoInitColorContent") : l10n.get("TutoInitPasswordContent"))
  432. },
  433. previous,
  434. next,
  435. ],
  436. ];
  437. var currentstep = tutorial.getElementAsObject("currentstep");
  438. tour.addSteps(steps[currentstep]);
  439. if (currentstep == 0) {
  440. tutorial.icons = {steps: {0: {icon: 'owner-icon.svg', directory: 'icons', size: constant.sizeEmpty, color: {stroke: "#005FE4", fill: "#FF2B34"}}}};
  441. }
  442. }
  443. tour.init();
  444. if (gotoStep !== undefined) {
  445. tour.goTo(gotoStep);
  446. }
  447. }
  448. // Handle tutorial element id
  449. tutorial.setElement = function(name, id) {
  450. tutorial.elements[name] = id;
  451. }
  452. tutorial.getElement = function(name) {
  453. return "#"+tutorial.elements[name];
  454. }
  455. tutorial.getElementAsObject = function(name) {
  456. return tutorial.elements[name];
  457. }
  458. // Start tutorial
  459. tutorial.start = function() {
  460. tutorial.init();
  461. tour.start(true);
  462. launched = true;
  463. };
  464. // Test if launched
  465. tutorial.isLaunched = function() {
  466. return launched;
  467. };
  468. return tutorial;
  469. });