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.

708 lines
24 KiB

  1. // First screen class
  2. enyo.kind({
  3. name: "Sugar.FirstScreen",
  4. kind: enyo.Control,
  5. components: [
  6. {name: "helpbutton", kind: "Sugar.Icon", size: constant.sizeEmpty, icon: {directory: "icons", icon: "help.svg"}, colorized: true, colorizedColor: {stroke: "#666666", fill: "#ffffff"}, ontap: "startTutorial", classes: "first-help"},
  7. {name: "namebox", classes: "first-namebox", onresize: "resize", showing: false, components: [
  8. {name: "nameline", classes: "first-nameline", components: [
  9. {name: "nametext", content: "xxx", classes: "first-nametext"},
  10. {classes: "first-input", components: [
  11. {name: "name", kind: "Input", classes: "first-namevalue", onkeydown: "enterclick"}
  12. ]}
  13. ]},
  14. ]},
  15. {name: "serverbox", classes: "first-serverbox", onresize: "resize", showing: false, components: [
  16. {name: "serverline", classes: "first-serverline", components: [
  17. {name: "servertext", content: "xxx", classes: "first-servertext"},
  18. {classes: "first-input", components: [
  19. {name: "server", kind: "Input", classes: "first-servervalue", onkeydown: "enterclick"}
  20. ]},
  21. {name: "qrbutton", kind: "Sugar.Icon", size: constant.sizeEmpty, icon: {directory: "icons", icon: "qrcode.svg"}, ontap: "scanQR", classes: "first-qr"}
  22. ]},
  23. ]},
  24. {name: "passbox", classes: "first-passbox", onresize: "resize", showing: false, components: [
  25. {name: "password", kind: "Sugar.Password", onEnter: "enterPassword"}
  26. ]},
  27. {name: "historybox", classes: "first-historybox", kind: "Repeater", onSetupItem: "setupHistory", onresize: "resize", showing: false, components:[
  28. {name: "history", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "owner-icon.svg"}, classes: "first-historybutton", ontap: "historyClicked"}
  29. ]},
  30. {name: "previous", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "go-left.svg"}, classes: "first-leftbutton", ontap: "previous", showing: false},
  31. {name: "next", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "go-right.svg"}, classes: "first-rightbutton", ontap: "next", showing: false},
  32. {name: "colortext", content: "xxx", classes: "first-colortext", showing: false},
  33. {name: "owner", kind: "Sugar.Icon", size: constant.sizeOwner, colorized: true, classes: "first-owner-icon", showing: false, onresize: "resize", ontap: "nextcolor"},
  34. {name: "newuser", kind: "Sugar.Icon", size: constant.sizeNewUser, colorized: false, classes: "first-owner-icon", showing: true, onresize: "resize", ontap: "newUser"},
  35. {name: "newusertext", content: "xxx", classes: "newuser-text"},
  36. {name: "login", kind: "Sugar.Icon", size: constant.sizeNewUser, colorized: false, classes: "first-owner-icon", showing: true, onresize: "resize", ontap: "login"},
  37. {name: "logintext", content: "xxx", classes: "newuser-text"},
  38. {name: "spinner", kind: "Image", src: "images/spinner-light.gif", classes: "spinner", showing: false},
  39. {name: "warningmessage", content: "xxx", classes: "first-warningmessage", showing: true}
  40. ],
  41. // Constructor
  42. create: function() {
  43. // Init screen
  44. app = this;
  45. this.inherited(arguments);
  46. this.$.nametext.setContent(l10n.get("Name"));
  47. this.$.servertext.setContent(l10n.get("ServerUrl"));
  48. this.$.password.setLabel(l10n.get("Password"));
  49. this.$.previous.setText(l10n.get("Back"));
  50. this.$.next.setText(l10n.get("Next"));
  51. this.$.newusertext.setContent(l10n.get("NewUser"));
  52. this.$.logintext.setContent(l10n.get("Login"));
  53. this.$.owner.setIcon({directory: "icons", icon: "owner-icon.svg"});
  54. this.$.colortext.setContent(l10n.get("ClickToColor"));
  55. this.history = preferences.getHistory();
  56. if (!this.history || !this.history.length) {
  57. this.history = [];
  58. }
  59. this.$.historybox.set("count", this.history.length, true);
  60. this.resize();
  61. this.ownerColor = Math.floor(Math.random()*xoPalette.colors.length);
  62. this.$.owner.setColorizedColor(xoPalette.colors[this.ownerColor]);
  63. this.$.newuser.setIcon({directory: "icons", icon: "newuser-icon.svg"});
  64. this.$.login.setIcon({directory: "icons", icon: "login.svg"});
  65. if (l10n.language.direction == "rtl") {
  66. this.$.name.addClass("rtl-10");
  67. }
  68. this.createnew = true;
  69. this.step = 0;
  70. this.displayStep();
  71. util.updateFavicon();
  72. // Get server information
  73. this.$.server.setValue((util.getClientType() == constant.appType) ? constant.defaultServer : util.getCurrentServerUrl());
  74. if (util.getClientType() == constant.webAppType) {
  75. var that = this;
  76. myserver.getServerInformation(myserver.getServerUrl(), function(inSender, inResponse) {
  77. inResponse.url = util.getCurrentServerUrl();
  78. preferences.setServer(inResponse);
  79. that.$.server.setValue(inResponse.url);
  80. });
  81. }
  82. // Hide toolbar
  83. var toolbar = document.getElementById("toolbar");
  84. this.backgroundColor = toolbar.style.backgroundColor;
  85. toolbar.style.backgroundColor = "white";
  86. document.getElementById("canvas").style.overflowY = "hidden";
  87. util.hideNativeToolbar();
  88. },
  89. // Render
  90. rendered: function() {
  91. this.inherited(arguments);
  92. // At first launch, display tutorial
  93. var that = this;
  94. window.setTimeout(function() {
  95. if (that.history.length == 0) {
  96. that.startTutorial();
  97. }
  98. }, constant.timerBeforeTutorial);
  99. },
  100. getView: function() {
  101. return constant.initView;
  102. },
  103. setupHistory: function(inSender, inEvent) {
  104. var user = this.history[this.history.length-inEvent.index-1];
  105. inEvent.item.$.history.setColorizedColor(xoPalette.colors[user.color]);
  106. inEvent.item.$.history.setColorized(true);
  107. inEvent.item.$.history.setText(user.name);
  108. },
  109. // Display current step items
  110. displayStep: function() {
  111. var vlogin = false,
  112. vlogintext = false,
  113. vnewuser = false,
  114. vnewusertext = false,
  115. vserverbox = false,
  116. vnamebox = false,
  117. vpassbox = false,
  118. vcolortext = false,
  119. vowner = false,
  120. vnext = false,
  121. vprevious = false,
  122. vwarning = false,
  123. vhistory = false;
  124. var currentserver;
  125. var serverurl;
  126. this.$.password.stopInputListening();
  127. switch(this.step) {
  128. case 0: // Choose between New User/Login
  129. this.scrollToTop();
  130. vlogin = vlogintext = vnewuser = vnewusertext = true;
  131. vhistory = true;
  132. break;
  133. case 1: // Server name
  134. this.scrollToField(this.$.serverbox);
  135. vserverbox = vnext = vprevious = true;
  136. this.$.qrbutton.setShowing(enyo.platform.ios || enyo.platform.android || enyo.platform.androidChrome);
  137. this.$.next.setText(l10n.get("Next"));
  138. break;
  139. case 2: // Type name
  140. this.scrollToField(this.$.namebox);
  141. vnamebox = vnext = vprevious = true;
  142. this.$.nametext.setContent(l10n.get(this.createnew ? "ChooseName" : "Name"));
  143. this.$.next.setText(l10n.get("Next"));
  144. break;
  145. case 3: // Type password
  146. this.scrollToTop();
  147. vpassbox = vprevious = vnext = true;
  148. this.$.password.setLabel(l10n.get(this.createnew ? "ChoosePassword" : "Password", {min: util.getMinPasswordSize()}));
  149. this.$.next.setText(l10n.get(this.createnew ? "Next" : "Done"));
  150. this.$.password.startInputListening();
  151. break;
  152. case 4: // Choose color
  153. this.scrollToTop();
  154. vcolortext = vprevious = vnext = vowner = true;
  155. this.$.next.setText(l10n.get("Done"));
  156. break;
  157. case 5: // Go to home view
  158. this.createOrLogin();
  159. return;
  160. }
  161. this.$.login.setShowing(vlogin);
  162. this.$.logintext.setShowing(vlogintext);
  163. this.$.newuser.setShowing(vnewuser);
  164. this.$.newusertext.setShowing(vnewusertext);
  165. this.$.namebox.setShowing(vnamebox);
  166. this.$.name.setAttribute("readOnly", !vnamebox);
  167. if (vnamebox) {
  168. this.$.name.focus();
  169. this.$.name.hasNode().select();
  170. }
  171. this.$.serverbox.setShowing(vserverbox);
  172. if (vserverbox) {
  173. this.$.server.focus();
  174. this.$.server.hasNode().select();
  175. }
  176. this.$.passbox.setShowing(vpassbox);
  177. this.$.colortext.setShowing(vcolortext);
  178. this.$.owner.setShowing(vowner);
  179. this.$.previous.setShowing(vprevious);
  180. this.$.next.setShowing(vnext);
  181. this.$.historybox.setShowing(vhistory && this.history.length);
  182. this.$.warningmessage.setShowing(vwarning);
  183. },
  184. // Event handling
  185. newUser: function() {
  186. this.createnew = true;
  187. this.step++;
  188. this.step++;
  189. this.displayStep();
  190. },
  191. login: function() {
  192. this.createnew = false;
  193. this.step++;
  194. if (util.getClientType() == constant.webAppType) {
  195. this.step++;
  196. }
  197. this.displayStep();
  198. },
  199. next: function() {
  200. if (this.$.spinner.getShowing()) {
  201. return;
  202. }
  203. if (this.step == 1 && this.$.server.getValue()) {
  204. // Retrieve server information
  205. this.$.spinner.setShowing(true);
  206. var that = this;
  207. myserver.getServerInformation(this.$.server.getValue(), function(inSender, inResponse) {
  208. var server = inResponse;
  209. server.url = that.$.server.getValue();
  210. if (server.secure) {
  211. server.url = server.url.replace(constant.http, constant.https);
  212. } else {
  213. server.url = server.url.replace(constant.https, constant.http);
  214. }
  215. preferences.setServer(server);
  216. that.step++;
  217. that.displayStep();
  218. that.$.spinner.setShowing(false);
  219. that.$.warningmessage.setShowing(false);
  220. }, function() {
  221. that.$.warningmessage.setContent(l10n.get("ErrorLoadingRemote"));
  222. that.$.warningmessage.setShowing(true);
  223. that.$.spinner.setShowing(false);
  224. });
  225. } else if (this.step == 2) {
  226. var name = this.$.name.getValue().trim();
  227. if (name.length == 0) {
  228. return;
  229. }
  230. this.step++;
  231. if (util.getClientType() == constant.appType && (this.createnew || !this.$.server.getValue())) { // No password for the app when create new or server is null
  232. this.step++;
  233. }
  234. this.displayStep();
  235. } else if (this.step == 3) {
  236. var pass = this.$.password.getPassword();
  237. if (pass.length == 0 || pass.length < util.getMinPasswordSize()) {
  238. return;
  239. }
  240. this.step++;
  241. if (!this.createnew) { // No color when login
  242. this.step++;
  243. }
  244. this.displayStep();
  245. } else {
  246. this.step++;
  247. this.displayStep();
  248. }
  249. },
  250. previous: function() {
  251. if (this.$.spinner.getShowing()) {
  252. return;
  253. }
  254. this.step--;
  255. var clientType = util.getClientType();
  256. if ((this.step == 3 && clientType == constant.appType && this.createnew) // No password for app
  257. || (this.step == 4 && !this.createnew) // No color in login mode
  258. || (this.step == 1 && (clientType == constant.webAppType || this.createnew)) // No way to update server for webapp
  259. ) {
  260. this.step--;
  261. }
  262. this.displayStep();
  263. },
  264. enterclick: function(inSender, inEvent) {
  265. if (inEvent.keyCode === 13) {
  266. this.next();
  267. return true;
  268. }
  269. },
  270. enterPassword: function() {
  271. this.next();
  272. },
  273. scrollToField: function(inSender) {
  274. // HACK: Scroll screen on Android to avoid to be hide by the touch keyboard
  275. var nodeName = inSender.hasNode();
  276. if (nodeName && (enyo.platform.android || enyo.platform.androidChrome)) {
  277. setTimeout(function() {
  278. nodeName.scrollIntoView();
  279. }, 100);
  280. }
  281. },
  282. scrollToTop: function() {
  283. var nodeName = this.$.helpbutton.hasNode();
  284. if (nodeName && (enyo.platform.android || enyo.platform.androidChrome)) {
  285. setTimeout(function() {
  286. nodeName.scrollIntoView(true);
  287. }, 100);
  288. }
  289. },
  290. nextcolor: function() {
  291. if (this.$.spinner.getShowing()) {
  292. return;
  293. }
  294. this.ownerColor = this.ownerColor + 1;
  295. if (this.ownerColor >= xoPalette.colors.length)
  296. this.ownerColor = 0;
  297. this.$.owner.setColorizedColor(xoPalette.colors[this.ownerColor]);
  298. this.$.owner.render();
  299. },
  300. resize: function() {
  301. var canvas_center = util.getCanvasCenter();
  302. this.$.owner.applyStyle("margin-left", (canvas_center.x-constant.sizeOwner/2)+"px");
  303. var middletop = (canvas_center.y-constant.sizeOwner/2);
  304. this.$.nameline.applyStyle("margin-top", (middletop-15)+"px");
  305. this.$.serverline.applyStyle("margin-top", (middletop-15)+"px");
  306. this.$.passbox.applyStyle("margin-top", (middletop/2)+"px");
  307. this.$.owner.applyStyle("margin-top", middletop+"px");
  308. this.$.warningmessage.applyStyle("left", (canvas_center.x-100)+"px");
  309. this.$.colortext.applyStyle("margin-top", (middletop-15)+"px");
  310. var newUserPosition = (middletop-constant.sizeNewUser/2);
  311. this.$.newuser.applyStyle("margin-top", newUserPosition+"px");
  312. this.$.login.applyStyle("margin-top", newUserPosition+"px");
  313. this.$.historybox.applyStyle("margin-top", (newUserPosition+20)+"px");
  314. this.$.newusertext.applyStyle("margin-top", (newUserPosition+constant.sizeNewUser+20)+"px");
  315. this.$.newusertext.applyStyle("width", constant.sizeNewUser+"px");
  316. this.$.logintext.applyStyle("margin-top", (newUserPosition+constant.sizeNewUser+20)+"px");
  317. this.$.logintext.applyStyle("width", constant.sizeNewUser+"px");
  318. if (this.history.length) {
  319. var left = (canvas_center.x-(constant.sizeNewUser*1.5)-30);
  320. this.$.newuser.applyStyle("margin-left", left+"px");
  321. this.$.newusertext.applyStyle("margin-left", left+"px");
  322. left += constant.sizeNewUser+30;
  323. this.$.login.applyStyle("margin-left", left+"px");
  324. this.$.logintext.applyStyle("margin-left", left+"px");
  325. left += constant.sizeNewUser+30;
  326. this.$.historybox.applyStyle("margin-left", left+"px");
  327. } else {
  328. this.$.newuser.applyStyle("margin-left", (canvas_center.x-constant.sizeNewUser-25)+"px");
  329. this.$.newusertext.applyStyle("margin-left", (canvas_center.x-constant.sizeNewUser-25)+"px");
  330. this.$.login.applyStyle("margin-left", (canvas_center.x+25)+"px");
  331. this.$.logintext.applyStyle("margin-left", (canvas_center.x+25)+"px");
  332. }
  333. },
  334. historyClicked: function(inSender, inEvent) {
  335. var user = this.history[this.history.length-inEvent.index-1];
  336. this.$.name.setValue(user.name);
  337. this.$.server.setValue(user.server ? user.server.url: "");
  338. if (user.server && user.server.url) {
  339. // Retrieve the server in history and go to login
  340. var that = this;
  341. myserver.getServerInformation(this.$.server.getValue(), function(inSender, inResponse) {
  342. inResponse.url = that.$.server.getValue();
  343. preferences.setServer(inResponse);
  344. });
  345. this.createnew = false;
  346. this.step = 3;
  347. this.displayStep();
  348. } else {
  349. // No server in history, create a new local user
  350. preferences.setName(user.name);
  351. preferences.setColor(user.color);
  352. this.launchDesktop();
  353. }
  354. },
  355. // Account handling
  356. createOrLogin: function() {
  357. // Save settings
  358. preferences.setColor(this.ownerColor);
  359. preferences.setName(this.$.name.getValue().trim());
  360. // Not connected
  361. if (util.getClientType() != constant.webAppType && (this.createnew || !this.$.server.getValue())) {
  362. this.launchDesktop();
  363. return;
  364. }
  365. // Pause UI
  366. this.$.spinner.setShowing(true);
  367. // Create a new user on the network
  368. if (this.createnew) {
  369. this.createUser();
  370. }
  371. // Log user
  372. else {
  373. this.loginUser();
  374. }
  375. },
  376. createUser: function() {
  377. var that = this;
  378. myserver.postUser(
  379. {
  380. name: preferences.getName(),
  381. color: preferences.getColor(),
  382. language: preferences.getLanguage(),
  383. role: "student",
  384. password: this.$.password.getPassword(),
  385. options: { sync: preferences.getOptions("sync"), stats: preferences.getOptions("stats") }
  386. },
  387. function(inSender, inResponse) {
  388. // Auto log user after creation to get token
  389. that.loginUser();
  390. },
  391. function(response, error) {
  392. that.$.spinner.setShowing(false);
  393. if (error == 22) {
  394. that.$.warningmessage.setContent(l10n.get("UserAlreadyExist"));
  395. } else {
  396. that.$.warningmessage.setContent(l10n.get("ServerError", {code: error}));
  397. }
  398. that.$.warningmessage.setShowing(true);
  399. that.step--;
  400. }
  401. );
  402. },
  403. loginUser: function() {
  404. var that = this;
  405. var user = {
  406. "name": preferences.getName(),
  407. "password": this.$.password.getPassword()
  408. };
  409. myserver.loginUser(user, function(loginSender, loginResponse) {
  410. preferences.setToken({'x_key': loginResponse.user._id, 'access_token': loginResponse.token});
  411. myserver.getUser(
  412. loginResponse.user._id,
  413. function(inSender, inResponse) {
  414. preferences.setNetworkId(inResponse._id);
  415. preferences.setPrivateJournal(inResponse.private_journal);
  416. preferences.setSharedJournal(inResponse.shared_journal);
  417. preferences.setConnected(true);
  418. l10n.language.code = inResponse.language;
  419. var changed = preferences.merge(inResponse);
  420. if (changed) {
  421. preferences.save();
  422. }
  423. that.$.spinner.setShowing(false);
  424. that.launchDesktop();
  425. },
  426. function(response, code) {
  427. that.$.warningmessage.setContent(l10n.get("ServerError", {code: code}));
  428. that.$.warningmessage.setShowing(true);
  429. that.$.spinner.setShowing(false);
  430. that.step--;
  431. }
  432. );
  433. },
  434. function(response, error) {
  435. if (error == 1) {
  436. that.$.warningmessage.setContent(l10n.get("UserLoginInvalid"));
  437. } else {
  438. that.$.warningmessage.setContent(l10n.get("ServerError", {code: error}));
  439. }
  440. that.$.warningmessage.setShowing(true);
  441. that.$.spinner.setShowing(false);
  442. that.step--;
  443. if (that.step == 4 && (util.getClientType() == constant.webAppType || (util.getClientType() == constant.appType && this.createnew))) {
  444. that.$.password.startInputListening();
  445. }
  446. });
  447. },
  448. // Handle QR Code scanner
  449. scanQR: function() {
  450. var that = this;
  451. that.scrollToField(that.$.helpbutton);
  452. util.scanQRCode(function(code) {
  453. that.$.server.setValue(code);
  454. }, function() {
  455. that.scrollToField(that.$.serverbox);
  456. that.$.server.focus();
  457. that.$.server.hasNode().select()
  458. });
  459. },
  460. // Display tutorial
  461. startTutorial: function() {
  462. tutorial.setElement("newuser", this.$.newuser.getAttribute("id"));
  463. tutorial.setElement("login", this.$.login.getAttribute("id"));
  464. tutorial.setElement("historybox", this.$.historybox.getAttribute("id"));
  465. tutorial.setElement("helpbutton", this.$.helpbutton.getAttribute("id"));
  466. tutorial.setElement("serverbox", this.$.server.getAttribute("id"));
  467. tutorial.setElement("qrcode", this.$.qrbutton.getAttribute("id"));
  468. tutorial.setElement("namebox", this.$.name.getAttribute("id"));
  469. tutorial.setElement("passbox", this.$.password.getAttribute("id"));
  470. tutorial.setElement("previous", this.$.previous.getAttribute("id"));
  471. tutorial.setElement("next", this.$.next.getAttribute("id"));
  472. tutorial.setElement("owner", this.$.owner.getAttribute("id"));
  473. tutorial.setElement("createnew", this.createnew);
  474. tutorial.setElement("currentstep", this.step);
  475. tutorial.start();
  476. },
  477. // Launch desktop
  478. launchDesktop: function() {
  479. document.getElementById("toolbar").style.backgroundColor = this.backgroundColor;
  480. document.getElementById("canvas").style.overflowY = "auto";
  481. isFirstLaunch = (this.history.length == 0 && this.createnew);
  482. app = new Sugar.Desktop();
  483. app.renderInto(document.getElementById("canvas"));
  484. preferences.save();
  485. }
  486. });
  487. // EE screen handle
  488. enyo.kind({
  489. name: "Sugar.EE",
  490. kind: enyo.Control,
  491. published: { mode: 1 },
  492. components: [
  493. {name: "endscreen", kind: "Image", src: "images/uiwarning.png", classes: "shutdownimage", showing: false, ontap: "reload"},
  494. {name: "audio", kind: "Sugar.Audio"},
  495. {name: "owner", kind: "Sugar.Icon", size: constant.sizeOwner, icon: {directory: "icons", icon: "owner-icon.svg"}, colorized: true, colorizedColor: {stroke: "#666666", fill: "#FFFFFF"}, classes: "owner-icon", showing: false},
  496. {name: "dots"},
  497. {name: "lab", kind: "Image", src: "images/eelab.svg", classes: "eelab", showing: false},
  498. {name: "fed", kind: "Image", src: "images/eefed.jpg", classes: "eefed", showing: false},
  499. ],
  500. // Constructor
  501. create: function() {
  502. this.inherited(arguments);
  503. this.timer = null;
  504. this.step = 0;
  505. app.noresize = true;
  506. },
  507. // Render
  508. rendered: function() {
  509. this.inherited(arguments);
  510. this.draw();
  511. },
  512. modeChanged: function() {
  513. this.draw();
  514. },
  515. reload: function() {
  516. location.reload();
  517. },
  518. // Draw screen
  519. draw: function() {
  520. this.addRemoveClass("eedownscreen", false);
  521. this.addRemoveClass("shutdownscreen", false);
  522. if (this.mode == 1) {
  523. if (this.step) {
  524. return;
  525. }
  526. this.addRemoveClass("eescreen", true);
  527. this.$.audio.play("audio/eeboot");
  528. this.step = 1;
  529. this.timer = window.setInterval(enyo.bind(this, "processStep"), 1000);
  530. } else if (this.mode == 2) {
  531. this.addRemoveClass("shutdownscreen", true);
  532. this.$.endscreen.setShowing(true);
  533. }
  534. },
  535. processStep: function() {
  536. var lightgray = {stroke: "#000000", fill: "#999999"};
  537. var darkgray = {stroke: "#000000", fill: "#666666"};
  538. switch(this.step++) {
  539. case 1: {
  540. var canvas_center = util.getCanvasCenter();
  541. this.$.owner.setX(canvas_center.x-constant.sizeOwner/2);
  542. this.$.owner.setY(canvas_center.y-constant.sizeOwner/2);
  543. this.$.owner.setShowing(true);
  544. break;
  545. }
  546. case 11: {
  547. this.dots = [];
  548. var dotsize = 24;
  549. var ownersize = this.$.owner.getSize();
  550. var centerx = this.$.owner.getX() + ownersize/2 - dotsize/2;
  551. var centery = this.$.owner.getY() + ownersize/2 - dotsize/2;
  552. var PI2 = Math.PI*2.0;
  553. var radius = ownersize*1.5;
  554. var angle = Math.PI/2.0;
  555. var base_angle = PI2/parseFloat(24);
  556. for (var i = 0 ; i < 24 ; i++) {
  557. x = (centerx+Math.cos(angle)*radius);
  558. y = (centery+Math.sin(angle)*radius);
  559. var dot = this.$.dots.createComponent({
  560. kind: "Sugar.Icon",
  561. icon: {directory: "icons", icon: "dot.svg"},
  562. size: dotsize,
  563. x: x,
  564. y: y,
  565. colorizedColor: lightgray,
  566. colorized: true,
  567. showing: (i==0)},
  568. {owner: this});
  569. dot.render();
  570. this.dots.push(dot);
  571. angle += base_angle;
  572. }
  573. break;
  574. }
  575. case 20: {
  576. for (var i = 0 ; i < 24 ; i++) {
  577. this.dots[i].setShowing(true);
  578. }
  579. this.$.fed.setShowing(true);
  580. this.$.lab.setShowing(true);
  581. break;
  582. }
  583. case 21: {
  584. for (var i = 0 ; i < 24 ; i += 4) {
  585. this.dots[i].setColorizedColor(darkgray);
  586. }
  587. break;
  588. }
  589. case 22:
  590. case 23:
  591. case 24:
  592. case 25:
  593. case 26: {
  594. var colors = [];
  595. for (var i = 0 ; i < 24 ; i++) {
  596. colors.push(this.dots[i].getColorizedColor());
  597. }
  598. for (var i = 0 ; i < 24 ; i++) {
  599. this.dots[i].setColorizedColor(colors[(i == 0 ? 23 : i-1)]);
  600. }
  601. break;
  602. }
  603. case 27: {
  604. for (var i = 0 ; i < 24 ; i++) {
  605. this.dots[i].setColorizedColor(darkgray);
  606. }
  607. break;
  608. }
  609. case 39: {
  610. window.clearInterval(this.timer);
  611. this.reload();
  612. }
  613. default: {
  614. }
  615. }
  616. },
  617. encoded: "\
  618. 5118425f65645b621642576961df1822183a57645f5b62164457686c575b701822183d6564705762\
  619. 6516455a5f57685a1822184357646b5b6216476b5fe765645b69182218395e685f696a5f57641649\
  620. 6a68655b6a635764641822184057696564164d5b576a5e5b6869586f182218466b645b5b6a164157\
  621. 6b68182218465f5b68685b164c5768626f1822184457605f1638656b6370656b5d5e182218495e5f\
  622. 68695e16505f58586b182218465f656a681637646a6569701822184a6f63656416462448575a705f\
  623. 6118221843576ae35769164357686ae3645b70182218395e5768625b691639656969df1822184c5f\
  624. 596a6568164a576157615f18221838685f576416495f626c5b68635764182218435764615f68576a\
  625. 16495f645d5e1822183b685f59164f656564182218625b656457685a59601822183c685b5a5a5f5b\
  626. 441822186457655c6b63182218416b6457621643655e6a571822183c685b5b163b5a6b59576a5f65\
  627. 6457621649655c6a6d57685b165c6568164365585f625b163a5b6c5f595b691623164a6857646962\
  628. 576a5f656469166a6516386857705f625f5764164665686a6b5d6b5b695b1822185959682a581822\
  629. 18395e685f696a65665e163a5b68645a65685c5b681822183f5d6457595f651648655a68e35d6b5b\
  630. 701822183857696a5f5b64182218495764576a57641822184357686a5f641637585b646a5b164257\
  631. 5e576f5b1822184065685d5b163762585b686a65163de9635b701642e9665b70182218385b686a16\
  632. 3c685b6b5a5b64585b685d182218496b68576018221837645a685b57163d65647057625b69182218\
  633. 445f616562576f163d656966655a5f64656c1822183b6a5e576416445b6269656423436565685b18\
  634. 2218495764595e5f6a164157666565681822183c685764596516396568685b571822184857605b5b\
  635. 6c1648576c5f645a685764182218495b5857696a5f576416495f626c571822186023695e6b585e18\
  636. 2218435f595e57e16216455e576f656418221837686f576416435b5a5f68576a6a57182218695a70\
  637. 5f6b5a5718221838576a595e6b164c5b6461576a164c5f695e576218221849576b68576c16466857\
  638. 6a5f5e57681822184d57626a5b6816385b645a5b68182218486569571637645f62163d5b65685d5b\
  639. 1822183b6b57641645645d1822183a5f645b695e16395e656b5a5e57686f1822186a68575a705f61\
  640. 1822186266276a5b61182218615f685f5a5f6e1822186c6068601822183e5768685f696564424157\
  641. 6a70182218435f595e575b6216466b1822184957635b5b6816416b6357681649576a6f575a576869\
  642. 5e5f1822183762576416375d6b5f57681822184957636f656116445b665762182218465f656a6816\
  643. 37646a656970182218495763696564163d655a5a6f18221846576b6265163c685764595f69596516\
  644. 49626563661822183a576c5b1639686569696257645a1853\
  645. ",
  646. contributors: function() {
  647. var json = "";
  648. for(var i = 0 ; i < this.encoded.length ; i+=2) {
  649. var hex = parseInt(this.encoded.substr(i, 2), 16);
  650. json += String.fromCharCode(hex+10);
  651. }
  652. var contribs = JSON.parse(json);
  653. var list = [];
  654. for (var i = 0 ; i < contribs.length ; i++) {
  655. var color = !i ? {stroke:"#005FE4",fill:"#FF2B34"}: xoPalette.colors[Math.floor(Math.random()*xoPalette.colors.length)];
  656. list.push({networkId: "nxx"+i, name: contribs[i], colorvalue: color});
  657. }
  658. return list;
  659. }
  660. });