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.

1481 lines
50 KiB

  1. // Settings dialog
  2. enyo.kind({
  3. name: "Sugar.DialogSettings",
  4. kind: "enyo.Popup",
  5. classes: "settings-dialog",
  6. centered: false,
  7. modal: true,
  8. floating: true,
  9. components: [
  10. {name: "toolbar", classes: "toolbar", components: [
  11. {name: "settingssearch", kind: "Sugar.SearchField", onTextChanged: "filterSettings", classes: "settings-filter-text"},
  12. {name: "donebutton", kind: "Button", classes: "toolbutton settings-close-button", title:"List", ontap: "closeSettings"}
  13. ]},
  14. {name: "scroller", kind: "Scroller", horizontal: "hidden", vertical: "auto", classes: "settings-scroller", components: [
  15. {name: "content", components: [
  16. {name: "me", kind: "Sugar.DialogSettingsItem", ontap: "meClicked", text: "Me", icon: {directory: "icons", icon: "module-about_me.svg"}, colorized: true},
  17. {name: "computer", kind: "Sugar.DialogSettingsItem", ontap: "computerClicked", text: "Computer", icon: {directory: "icons", icon: "module-about_my_computer.svg"}},
  18. {name: "aboutserver", kind: "Sugar.DialogSettingsItem", ontap: "serverClicked", text: "Server", icon: {directory: "icons", icon: "cloud-settings.svg"}},
  19. {name: "security", kind: "Sugar.DialogSettingsItem", ontap: "securityClicked", icon: {directory: "icons", icon: "login-icon.svg"}, showing: false},
  20. {name: "privacy", kind: "Sugar.DialogSettingsItem", ontap: "privacyClicked", icon: {directory: "icons", icon: "privacy.svg"}, showing: false},
  21. {name: "language", kind: "Sugar.DialogSettingsItem", ontap: "languageClicked", text: "Language", icon: {directory: "icons", icon: "module-language.svg"}},
  22. {name: "androidSettings", kind: "Sugar.DialogSettingsItem", ontap: "androidSettingsClicked", text: "AndroidSettings", icon: {directory: "icons", icon: "android-preferences.svg"}, showing: false},
  23. {name: "resetLauncher", kind: "Sugar.DialogSettingsItem", ontap: "resetLauncherPopup", text: "ResetLauncher", icon: {directory: "icons", icon: "launcher-icon.svg"}, showing: false}
  24. ]},
  25. ]},
  26. {name: "subdialog"}
  27. ],
  28. // Constructor
  29. create: function() {
  30. this.inherited(arguments);
  31. this.$.settingssearch.setPlaceholder(l10n.get("SearchSettings"));
  32. this.$.me.setText(l10n.get("AboutMe"));
  33. this.$.computer.setText(l10n.get("AboutMyComputer"));
  34. this.$.security.setText(l10n.get("MySecurity"));
  35. this.$.privacy.setText(l10n.get("MyPrivacy"));
  36. this.$.language.setText(l10n.get("Language"));
  37. this.$.aboutserver.setText(l10n.get("Server"));
  38. if (util.getClientType() == constant.webAppType || preferences.isConnected()) {
  39. this.$.security.setShowing(true);
  40. this.$.privacy.setShowing(true);
  41. }
  42. if (window.sugarizerOS) {
  43. sugarizerOS.getLauncherPackageName(function(value) {sugarizerOS.launcherPackageName = value;});
  44. this.$.androidSettings.setText(l10n.get("AndroidSettings"));
  45. this.$.androidSettings.show();
  46. this.$.resetLauncher.show();
  47. this.$.resetLauncher.setText(l10n.get("ResetLauncher"));
  48. }
  49. if (l10n.language.direction == "rtl") {
  50. this.$.me.addClass("rtl-10");
  51. this.$.computer.addClass("rtl-10");
  52. this.$.security.addClass("rtl-10");
  53. this.$.privacy.addClass("rtl-10");
  54. this.$.language.addClass("rtl-10");
  55. this.$.aboutserver.addClass("rtl-10");
  56. }
  57. if (util.getClientType() == constant.webAppType) {
  58. this.$.security.setShowing(true);
  59. }
  60. this.subdialog = null;
  61. },
  62. rendered: function() {
  63. this.inherited(arguments);
  64. app.noresize = true; // HACK: Forbid home resizing when popup is displayed to avoid modal issue
  65. this.$.me.render();
  66. this.$.donebutton.setNodeProperty("title", l10n.get("Done"));
  67. var margin = this.centerDialog(this);
  68. this.$.content.applyStyle("height", (margin.height)+"px");
  69. this.$.scroller.render();
  70. },
  71. centerDialog: function(dialog) {
  72. var margin = util.computeMargin({width: 800, height: 500}, {width: 0.95, height: 0.95});
  73. dialog.applyStyle("margin-left", margin.left+"px");
  74. dialog.applyStyle("margin-top", (margin.top-55)+"px");
  75. return margin;
  76. },
  77. // Events
  78. filterSettings: function() {
  79. var filter = this.$.settingssearch.getText().toLowerCase();
  80. stats.trace('my_settings', 'search', 'q='+filter, null);
  81. enyo.forEach(this.$.content.getControls(), function(item) {
  82. item.setDisabled(item.getText().toLowerCase().indexOf(filter) == -1 && filter.length != 0);
  83. });
  84. },
  85. closeSettings: function() {
  86. this.hide();
  87. app.noresize = false;
  88. },
  89. // Display me dialog
  90. meClicked: function() {
  91. if (!this.$.me.getDisabled()) {
  92. stats.trace('my_settings', 'click', 'about_me', null);
  93. this.hide();
  94. this.subdialog = this.$.subdialog.createComponent({kind: "Sugar.DialogAboutme"}, {owner:this});
  95. this.subdialog.show();
  96. }
  97. },
  98. computerClicked: function() {
  99. if (!this.$.computer.getDisabled()) {
  100. stats.trace('my_settings', 'click', 'about_my_computer', null);
  101. this.hide();
  102. this.subdialog = this.$.subdialog.createComponent({kind: "Sugar.DialogComputer"}, {owner:this});
  103. this.subdialog.show();
  104. }
  105. },
  106. securityClicked: function() {
  107. if (!this.$.security.getDisabled()) {
  108. stats.trace('my_settings', 'click', 'security', null);
  109. this.hide();
  110. this.subdialog = this.$.subdialog.createComponent({kind: "Sugar.DialogSecurity"}, {owner:this});
  111. this.subdialog.show();
  112. }
  113. },
  114. privacyClicked: function() {
  115. if (!this.$.security.getDisabled()) {
  116. stats.trace('my_settings', 'click', 'privacy', null);
  117. this.hide();
  118. this.subdialog = this.$.subdialog.createComponent({kind: "Sugar.DialogPrivacy"}, {owner:this});
  119. this.subdialog.show();
  120. }
  121. },
  122. languageClicked: function() {
  123. if (!this.$.language.getDisabled()) {
  124. stats.trace('my_settings', 'click', 'language', null);
  125. this.hide();
  126. this.subdialog = this.$.subdialog.createComponent({kind: "Sugar.DialogLanguage"}, {owner:this});
  127. this.subdialog.show();
  128. }
  129. },
  130. serverClicked: function() {
  131. if (!this.$.aboutserver.getDisabled()) {
  132. stats.trace('my_settings', 'click', 'about_my_server', null);
  133. this.hide();
  134. this.subdialog = this.$.subdialog.createComponent({kind: "Sugar.DialogServer"}, {owner:this});
  135. this.subdialog.show();
  136. }
  137. },
  138. androidSettingsClicked: function() {
  139. if (window.sugarizerOS){
  140. sugarizerOS.runSettings();
  141. }
  142. this.hide();
  143. },
  144. resetLauncherPopup: function(){
  145. this.hide();
  146. this.subdialog = this.$.subdialog.createComponent({kind:"Sugar.DialogSetLauncher"}, {owner:this});
  147. this.subdialog.show();
  148. }
  149. });
  150. // Set Launcher dialog
  151. enyo.kind({
  152. name: "Sugar.DialogSetLauncher",
  153. kind: "enyo.Popup",
  154. classes: "module-dialog",
  155. centered: false,
  156. modal: true,
  157. floating: true,
  158. autoDismiss: false,
  159. components: [
  160. {name: "toolbar", classes: "toolbar", components: [
  161. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "module-icon", colorized: true, size: constant.sizeToolbar, icon: {directory: "icons", icon: "owner-icon.svg"}},
  162. {name: "text", content: "xxx", classes: "module-text"},
  163. {name: "cancelbutton", kind: "Button", classes: "toolbutton module-cancel-button", ontap: "cancel"},
  164. {name: "okbutton", kind: "Button", classes: "toolbutton module-ok-button", ontap: "ok"}
  165. ]},
  166. {name: "warningbox", kind: "Sugar.DialogSettingsWarningBox", showing: false, onCancel: "cancel", onRestart: "restart"},
  167. {name: "content", components: [
  168. {name: "message", content: "xxx", classes: "launcher-message" },
  169. {classes: "launcher-icons", components: [
  170. {name: "nativeIcon", kind: "Sugar.Icon", classes: "setlauncher-icon native", icon: {directory: "icons", icon: "launcher-icon.svg"}, size: 100, ontap:"changeLauncher"},
  171. {name: "sugarIcon", kind: "Sugar.Icon", classes: "setlauncher-icon sugar", icon: {directory: "icons", icon: "sugarizer.svg"}, size: 100, ontap:"changeLauncher"}
  172. ]},
  173. ]}
  174. ],
  175. // Constructor
  176. create: function() {
  177. this.inherited(arguments);
  178. this.$.text.setContent(l10n.get("SetLauncherTitle"));
  179. this.$.message.setContent(l10n.get("SetLauncherText", {launcher:sugarizerOS.launcherPackageName}));
  180. if (l10n.language.direction == "rtl") {
  181. this.$.text.addClass("rtl-10");
  182. }
  183. if (window.sugarizerOS) {
  184. if (sugarizerOS.launcherPackageName == sugarizerOS.packageName) {
  185. this.$.sugarIcon.addClass("selected");
  186. }
  187. else {
  188. this.$.nativeIcon.addClass("selected");
  189. }
  190. }
  191. },
  192. rendered: function() {
  193. this.inherited(arguments);
  194. this.$.icon.render();
  195. this.$.cancelbutton.setNodeProperty("title", l10n.get("Cancel"));
  196. this.$.okbutton.setNodeProperty("title", l10n.get("Ok"));
  197. this.owner.centerDialog(this);
  198. },
  199. // Event handling
  200. cancel: function() {
  201. this.hide();
  202. },
  203. restart: function() {
  204. sugarizerOS.chooseLauncher();
  205. this.hide();
  206. },
  207. changeLauncher: function() {
  208. this.$.warningbox.setShowing(true);
  209. }
  210. });
  211. // Enter Wireless key dialog
  212. enyo.kind({
  213. name: "Sugar.DialogNetworkKey",
  214. kind: "enyo.Popup",
  215. classes: "module-dialog-wifikey",
  216. centered: false,
  217. modal: true,
  218. floating: true,
  219. autoDismiss: false,
  220. components: [
  221. {name: "toolbar", classes: "toolbar", components: [
  222. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "module-icon", colorized: true, size: constant.sizeToolbar, icon: {directory: "icons", icon: "owner-icon.svg"}},
  223. {name: "text", content: "xxx", classes: "module-text"},
  224. {name: "cancelbutton", kind: "Button", classes: "toolbutton module-cancel-button", ontap: "cancel"},
  225. {name: "okbutton", kind: "Button", classes: "toolbutton module-ok-button", ontap: "ok"}
  226. ]},
  227. {name: "content", components: [
  228. {classes: "enterkey", components: [
  229. {name: "keyInput", kind: "Input", classes: "enterkey-input", oninput:"keychanged"}
  230. ]}
  231. ]}
  232. ],
  233. // Constructor
  234. create: function() {
  235. this.inherited(arguments);
  236. this.$.text.setContent(l10n.get("EnterKey") + " [" + sugarizerOS.NetworkBuffer.SSID + "]");
  237. if (sugarizerOS.sharedKeyBuffer) {
  238. this.$.keyInput.setValue(sugarizerOS.sharedKeyBuffer);
  239. } else {
  240. this.$.keyInput.setValue("");
  241. }
  242. if (l10n.language.direction == "rtl") {
  243. this.$.text.addClass("rtl-10");
  244. }
  245. },
  246. rendered: function() {
  247. this.inherited(arguments);
  248. this.$.icon.render();
  249. this.$.cancelbutton.setNodeProperty("title", l10n.get("Cancel"));
  250. this.$.okbutton.setNodeProperty("title", l10n.get("Ok"));
  251. this.centerDialog(this);
  252. },
  253. // Event handling
  254. cancel: function() {
  255. this.hide();
  256. },
  257. ok: function() {
  258. sugarizerOS.sharedKeyBuffer = this.$.keyInput.getValue();
  259. sugarizerOS.setKey(sugarizerOS.NetworkBuffer.SSID, sugarizerOS.sharedKeyBuffer, true);
  260. this.hide();
  261. this.$.okbutton.setDisabled(true);
  262. this.$.cancelbutton.setDisabled(true);
  263. },
  264. keychanged: function() {
  265. },
  266. connect: function() {
  267. },
  268. centerDialog: function(dialog) {
  269. var margin = util.computeMargin({width: 500, height: 150}, {width: 0.95, height: 0.25});
  270. dialog.applyStyle("margin-left", margin.left+"px");
  271. dialog.applyStyle("margin-top", (margin.top-55-40)+"px");
  272. }
  273. });
  274. // About me dialog
  275. enyo.kind({
  276. name: "Sugar.DialogAboutme",
  277. kind: "enyo.Popup",
  278. classes: "module-dialog",
  279. centered: false,
  280. modal: true,
  281. floating: true,
  282. autoDismiss: false,
  283. components: [
  284. {name: "toolbar", classes: "toolbar", components: [
  285. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "module-icon", colorized: true, size: constant.sizeToolbar, icon: {directory: "icons", icon: "owner-icon.svg"}},
  286. {name: "text", content: "xxx", classes: "module-text"},
  287. {name: "cancelbutton", kind: "Button", classes: "toolbutton module-cancel-button", ontap: "cancel"},
  288. {name: "okbutton", kind: "Button", classes: "toolbutton module-ok-button", ontap: "ok"}
  289. ]},
  290. {name: "warningbox", kind: "Sugar.DialogSettingsWarningBox", showing: false, onCancel: "cancel", onRestart: "restart"},
  291. {name: "content", components: [
  292. {name: "message", content: "xxx", classes: "aboutme-message"},
  293. {classes: "aboutme-icons", components: [
  294. {name: "psicon", kind: "Sugar.Icon", x: 0, y: 6, classes: "aboutme-icon aboutme-psicon", size: constant.sizeOwner, icon: {directory: "icons", icon: "owner-icon.svg"}, ontap:"setcolor"},
  295. {name: "nsicon", kind: "Sugar.Icon", x: -12, y: 6, classes: "aboutme-icon aboutme-nsicon", size: constant.sizeOwner, icon: {directory: "icons", icon: "owner-icon.svg"}, ontap:"setcolor"},
  296. {name: "cicon", kind: "Sugar.Icon", x: 6, y: 6, classes: "aboutme-icon aboutme-cicon", size: constant.sizeOwner, icon: {directory: "icons", icon: "owner-icon.svg"}, ontap:"setcolor"},
  297. {name: "pficon", kind: "Sugar.Icon", x: 0, y: 6, classes: "aboutme-icon aboutme-pficon", size: constant.sizeOwner, icon: {directory: "icons", icon: "owner-icon.svg"}, ontap:"setcolor"},
  298. {name: "nficon", kind: "Sugar.Icon", x: -12, y: 6, classes: "aboutme-icon aboutme-nficon", size: constant.sizeOwner, icon: {directory: "icons", icon: "owner-icon.svg"}, ontap:"setcolor"}
  299. ]},
  300. {classes: "aboutme-input", components: [
  301. {name: "name", kind: "Input", classes: "aboutme-name", oninput:"namechanged"}
  302. ]},
  303. {name: "restartmessage", content: "xxx", classes: "aboutme-restart", showing: false}
  304. ]}
  305. ],
  306. // Constructor
  307. create: function() {
  308. this.inherited(arguments);
  309. this.$.text.setContent(l10n.get("AboutMe"));
  310. this.$.message.setContent(l10n.get("ClickToChangeColor"));
  311. this.$.restartmessage.setContent(l10n.get("ChangesRequireRestart"));
  312. this.initcolor = this.currentcolor = preferences.getColor();
  313. this.initname = this.currentname = preferences.getName();
  314. this.$.name.setValue(this.initname);
  315. if (l10n.language.direction == "rtl") {
  316. this.$.text.addClass("rtl-10");
  317. this.$.name.addClass("rtl-10");
  318. this.$.message.addClass("rtl-10");
  319. this.$.restartmessage.addClass("rtl-10");
  320. }
  321. },
  322. rendered: function() {
  323. this.inherited(arguments);
  324. this.$.icon.render();
  325. this.$.cancelbutton.setNodeProperty("title", l10n.get("Cancel"));
  326. this.$.okbutton.setNodeProperty("title", l10n.get("Ok"));
  327. var xosize = (util.getCanvasCenter().dx < 515 ? constant.sizeOwner/2 : constant.sizeOwner);
  328. this.$.pficon.setSize(xosize);
  329. this.$.pficon.setColorizedColor(util.getPreviousFillColor(this.currentcolor));
  330. this.$.pficon.setColorized(true);
  331. this.$.psicon.setSize(xosize);
  332. this.$.psicon.setColorizedColor(util.getPreviousStrokeColor(this.currentcolor));
  333. this.$.psicon.setColorized(true);
  334. this.$.cicon.setSize(xosize);
  335. this.$.cicon.setColorizedColor(this.currentcolor);
  336. this.$.cicon.setColorized(true);
  337. this.$.nficon.setSize(xosize);
  338. this.$.nficon.setColorizedColor(util.getNextFillColor(this.currentcolor));
  339. this.$.nficon.setColorized(true);
  340. this.$.nsicon.setSize(xosize);
  341. this.$.nsicon.setColorizedColor(util.getNextStrokeColor(this.currentcolor));
  342. this.$.nsicon.setColorized(true);
  343. this.$.name.setValue(this.currentname);
  344. this.owner.centerDialog(this);
  345. },
  346. // Event handling
  347. cancel: function() {
  348. this.hide();
  349. this.owner.show();
  350. },
  351. ok: function() {
  352. if (this.currentcolor.stroke == "#00B20D" && this.currentcolor.fill == "#00EA11" && (this.currentname == "one laptop per child" || this.currentname == "OLPC France")) {
  353. new Sugar.EE({mode:(this.currentname.indexOf("Fr")==-1?1:2)}).renderInto(document.getElementById("body"));
  354. return;
  355. }
  356. if (this.currentcolor == this.initcolor && this.currentname == this.initname) {
  357. this.hide();
  358. this.owner.show();
  359. return;
  360. }
  361. this.$.warningbox.setShowing(true);
  362. this.$.okbutton.setDisabled(true);
  363. this.$.cancelbutton.setDisabled(true);
  364. this.$.name.addRemoveClass('aboutme-name-validate', true);
  365. },
  366. setcolor: function(icon) {
  367. var newcolor = icon.getColorizedColor();
  368. if (newcolor == this.currentcolor) {
  369. return;
  370. }
  371. this.currentcolor = newcolor;
  372. this.render();
  373. this.$.restartmessage.setShowing(true);
  374. },
  375. namechanged: function() {
  376. this.$.restartmessage.setShowing(true);
  377. this.currentname = this.$.name.getValue().trim();
  378. },
  379. restart: function() {
  380. stats.trace('my_settings_about_me', 'change', 'name_color', null);
  381. preferences.setName(this.currentname);
  382. preferences.setColor(util.getColorIndex(this.currentcolor));
  383. preferences.save();
  384. var that = this;
  385. preferences.saveToServer(myserver, function() {
  386. util.restartApp();
  387. }, function(error, code) {
  388. that.$.warningbox.setShowing(false);
  389. that.$.okbutton.setDisabled(false);
  390. that.$.cancelbutton.setDisabled(false);
  391. that.currentname = preferences.getName();
  392. if (code == 22) {
  393. that.$.restartmessage.setContent(l10n.get("UserAlreadyExist"));
  394. } else {
  395. that.$.restartmessage.setContent(l10n.get("ServerError", {code: code}));
  396. }
  397. });
  398. }
  399. });
  400. // Language dialog
  401. enyo.kind({
  402. name: "Sugar.DialogSecurity",
  403. kind: "enyo.Popup",
  404. classes: "module-dialog",
  405. centered: false,
  406. modal: true,
  407. floating: true,
  408. autoDismiss: false,
  409. components: [
  410. {name: "toolbar", classes: "toolbar", components: [
  411. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "module-icon", size: constant.sizeToolbar, icon: {directory: "icons", icon: "login-icon.svg"}},
  412. {name: "text", content: "xxx", classes: "module-text"},
  413. {name: "cancelbutton", kind: "Button", classes: "toolbutton module-cancel-button", ontap: "cancel"},
  414. {name: "okbutton", kind: "Button", classes: "toolbutton module-ok-button", ontap: "ok"}
  415. ]},
  416. {name: "content", components: [
  417. {name: "message", content: "xxx", classes: "security-message"},
  418. {name: "password", kind: "Sugar.Password", classes: "security-password", onEnter: "next"},
  419. {name: "next", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "go-right.svg"}, classes: "security-rightbutton", ontap: "next"},
  420. {name: "spinner", kind: "Image", src: "images/spinner-light.gif", classes: "security-spinner", showing: false},
  421. {name: "warningmessage", content: "xxx", classes: "security-warning", showing: false}
  422. ]}
  423. ],
  424. // Constructor
  425. create: function() {
  426. this.inherited(arguments);
  427. this.$.text.setContent(l10n.get("MySecurity"));
  428. this.$.message.setContent(l10n.get("SecurityMessage"));
  429. this.$.next.setText(l10n.get("Next"));
  430. this.$.password.startInputListening();
  431. if (l10n.language.direction == "rtl") {
  432. this.$.text.addClass("rtl-10");
  433. this.$.message.addClass("rtl-10");
  434. }
  435. this.step = 0;
  436. },
  437. rendered: function() {
  438. this.inherited(arguments);
  439. this.$.cancelbutton.setNodeProperty("title", l10n.get("Cancel"));
  440. this.$.okbutton.setNodeProperty("title", l10n.get("Ok"));
  441. this.owner.centerDialog(this);
  442. },
  443. // Event handling
  444. cancel: function() {
  445. this.$.password.stopInputListening();
  446. this.hide();
  447. this.owner.show();
  448. },
  449. ok: function() {
  450. this.$.password.stopInputListening();
  451. this.hide();
  452. this.owner.show();
  453. },
  454. next: function() {
  455. var that = this;
  456. var user = {
  457. "name": preferences.getName(),
  458. "password": this.$.password.getPassword()
  459. };
  460. if (this.step == 0) {
  461. that.$.spinner.setShowing(true);
  462. myserver.loginUser(user, function(loginSender, loginResponse) {
  463. preferences.setToken({'x_key': loginResponse.user._id, 'access_token': loginResponse.token});
  464. that.$.warningmessage.setShowing(false);
  465. that.$.password.setPassword("");
  466. that.$.next.setText(l10n.get("Done"));
  467. that.$.message.setContent(l10n.get("SecurityMessageNew", {min: util.getMinPasswordSize()}));
  468. that.step++;
  469. that.$.spinner.setShowing(false);
  470. },
  471. function(response, error) {
  472. if (error == 1) {
  473. that.$.warningmessage.setContent(l10n.get("InvalidPassword"));
  474. } else {
  475. that.$.warningmessage.setContent(l10n.get("ServerError", {code: error}));
  476. }
  477. that.$.warningmessage.setShowing(true);
  478. that.$.spinner.setShowing(false);
  479. });
  480. } else {
  481. var pass = this.$.password.getPassword();
  482. if (pass.length == 0 || pass.length < util.getMinPasswordSize()) {
  483. return;
  484. }
  485. that.$.spinner.setShowing(true);
  486. myserver.putUser(
  487. preferences.getNetworkId(),
  488. {
  489. password: this.$.password.getPassword()
  490. },
  491. function(inSender, inResponse) {
  492. that.$.message.setContent(l10n.get("SecurityMessageDone"));
  493. that.$.next.setShowing(false);
  494. that.$.password.setShowing(false);
  495. that.$.warningmessage.setShowing(false);
  496. that.$.spinner.setShowing(false);
  497. },
  498. function(response, error) {
  499. that.$.warningmessage.setContent(l10n.get("ServerError", {code: error}));
  500. that.$.warningmessage.setShowing(true);
  501. that.$.spinner.setShowing(false);
  502. }
  503. );
  504. }
  505. }
  506. });
  507. // Language dialog
  508. enyo.kind({
  509. name: "Sugar.DialogLanguage",
  510. kind: "enyo.Popup",
  511. classes: "module-dialog",
  512. centered: false,
  513. modal: true,
  514. floating: true,
  515. autoDismiss: false,
  516. components: [
  517. {name: "toolbar", classes: "toolbar", components: [
  518. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "module-icon", size: constant.sizeToolbar, icon: {directory: "icons", icon: "module-language.svg"}},
  519. {name: "text", content: "xxx", classes: "module-text"},
  520. {name: "cancelbutton", kind: "Button", classes: "toolbutton module-cancel-button", ontap: "cancel"},
  521. {name: "okbutton", kind: "Button", classes: "toolbutton module-ok-button", ontap: "ok"}
  522. ]},
  523. {name: "warningbox", kind: "Sugar.DialogSettingsWarningBox", showing: false, onCancel: "cancel", onRestart: "restart"},
  524. {name: "content", components: [
  525. {name: "message", content: "xxx", classes: "language-message"},
  526. {name: "languageselect", kind: "Sugar.SelectBox", classes: "language-select", onIndexChanged: "languageChanged"},
  527. {name: "restartmessage", content: "xxx", classes: "language-restart", showing: false}
  528. ]}
  529. ],
  530. // Constructor
  531. create: function() {
  532. this.inherited(arguments);
  533. this.$.text.setContent(l10n.get("Language"));
  534. this.$.message.setContent(l10n.get("ChooseLanguage"));
  535. this.initlanguage = this.currentlanguage = preferences.getLanguage();
  536. this.languageset = [
  537. {code: "en", icon: null, name: "English (" + l10n.get("English") +")"},
  538. {code: "es", icon: null, name: "Español (" + l10n.get("Spanish") +")"},
  539. {code: "fr", icon: null, name: "Français (" + l10n.get("French") +")"},
  540. {code: "de", icon: null, name: "Deutsch (" + l10n.get("German") +")"},
  541. {code: "pt", icon: null, name: "Português (" + l10n.get("Portuguese") +")"},
  542. {code: "ar", icon: null, name: "عربي (" + l10n.get("Arabic") +")"},
  543. {code: "ja", icon: null, name: "日本語 (" + l10n.get("Japanese") +")"},
  544. {code: "pl", icon: null, name: "Polski (" + l10n.get("Polish") +")"},
  545. {code: "ibo", icon: null, name: "Igbo (" + l10n.get("Igbo") +")"},
  546. {code: "yor", icon: null, name: "Yoruba (" + l10n.get("Yoruba") +")"}
  547. ];
  548. this.$.languageselect.setItems(this.languageset);
  549. for (var i = 0 ; i < this.languageset.length ; i++) {
  550. if (this.languageset[i].code == this.initlanguage) {
  551. this.$.languageselect.setSelected(i);
  552. break;
  553. }
  554. }
  555. this.$.restartmessage.setContent(l10n.get("ChangesRequireRestart"));
  556. if (l10n.language.direction == "rtl") {
  557. this.$.text.addClass("rtl-10");
  558. this.$.message.addClass("rtl-10");
  559. this.$.restartmessage.addClass("rtl-10");
  560. }
  561. },
  562. rendered: function() {
  563. this.inherited(arguments);
  564. this.$.cancelbutton.setNodeProperty("title", l10n.get("Cancel"));
  565. this.$.okbutton.setNodeProperty("title", l10n.get("Ok"));
  566. this.$.languageselect.setParentMargin(this);
  567. this.owner.centerDialog(this);
  568. },
  569. // Event handling
  570. cancel: function() {
  571. this.hide();
  572. this.owner.show();
  573. },
  574. ok: function() {
  575. if (this.currentlanguage == this.initlanguage) {
  576. this.hide();
  577. this.owner.show();
  578. return;
  579. }
  580. this.$.warningbox.setShowing(true);
  581. this.$.okbutton.setDisabled(true);
  582. this.$.cancelbutton.setDisabled(true);
  583. },
  584. languageChanged: function() {
  585. this.$.restartmessage.setShowing(true);
  586. this.currentlanguage = this.languageset[this.$.languageselect.getSelected()].code;
  587. },
  588. restart: function() {
  589. stats.trace('my_settings_language', 'change', 'language', null);
  590. preferences.setLanguage(this.currentlanguage);
  591. preferences.save();
  592. preferences.saveToServer(myserver, function() {
  593. util.restartApp();
  594. }, function() {
  595. util.restartApp();
  596. });
  597. }
  598. });
  599. // Computer dialog
  600. enyo.kind({
  601. name: "Sugar.DialogComputer",
  602. kind: "enyo.Popup",
  603. classes: "module-dialog",
  604. centered: false,
  605. modal: true,
  606. floating: true,
  607. autoDismiss: false,
  608. components: [
  609. {name: "toolbar", classes: "toolbar", components: [
  610. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "module-icon", size: constant.sizeToolbar, icon: {directory: "icons", icon: "module-about_my_computer.svg"}},
  611. {name: "text", content: "xxx", classes: "module-text"},
  612. {name: "cancelbutton", kind: "Button", classes: "toolbutton module-cancel-button", ontap: "cancel"},
  613. {name: "okbutton", kind: "Button", classes: "toolbutton module-ok-button", ontap: "ok"}
  614. ]},
  615. {name: "warningbox", kind: "Sugar.DialogSettingsWarningBox", showing: false, onCancel: "cancel", onRestart: "reinit"},
  616. {name: "content", kind: "Scroller", classes: "computer-content", components: [
  617. {name: "software", content: "xxx", classes: "computer-software"},
  618. {content: "Sugarizer:", classes: "computer-sugarizer"},
  619. {name: "sugarizer_value", classes: "computer-value", ontap: "version"},
  620. {classes: "computer-line"},
  621. {name: "clienttype", classes: "computer-clienttype"},
  622. {name: "clienttype_value", classes: "computer-value"},
  623. {classes: "computer-line"},
  624. {name: "browser", content: "xxx", classes: "computer-browser"},
  625. {name: "browser_value", classes: "computer-value"},
  626. {classes: "computer-line"},
  627. {name: "browserversion", content: "xxx", classes: "computer-browserversion"},
  628. {name: "browserversion_value", classes: "computer-value"},
  629. {classes: "computer-line"},
  630. {name: "useragent", content: "xxx", classes: "computer-useragent"},
  631. {name: "useragent_value", classes: "computer-value"},
  632. {name: "storage", content: "xxx", classes: "computer-storage"},
  633. {name: "storage_value", classes: "computer-value"},
  634. {classes: "computer-line"},
  635. {name: "reinitcheck", showing: false, kind: "Input", type: "checkbox", classes: "toggle computer-reinitcheck", onchange: "switchInit"},
  636. {name: "reinittext", showing: false, content: "xxx", classes: "computer-reinit"},
  637. {classes: "computer-line"},
  638. {name: "copyright", content: "xxx", classes: "computer-copyright"},
  639. {content: "© 2013-2019 Lionel Laské, Sugar Labs Inc and Contributors", classes: "computer-contributor"},
  640. {name: "license", content: "xxx", classes: "computer-licence"},
  641. {name: "licenseplus", content: "xxx", classes: "computer-licence"},
  642. {name: "warningmessage", showing: false, content: "xxx", classes: "computer-warningmessage", showing: false}
  643. ]}
  644. ],
  645. // Constructor
  646. create: function() {
  647. this.inherited(arguments);
  648. this.$.text.setContent(l10n.get("AboutMyComputer"));
  649. this.$.software.setContent(l10n.get("Software"));
  650. this.$.browser.setContent(l10n.get("Browser"));
  651. this.$.clienttype.setContent(l10n.get("ClientType"));
  652. this.$.browserversion.setContent(l10n.get("BrowserVersion"));
  653. this.$.useragent.setContent(l10n.get("UserAgent"));
  654. this.$.storage.setContent(l10n.get("Storage"));
  655. this.$.copyright.setContent(l10n.get("Copyright"));
  656. this.$.license.setContent(l10n.get("LicenseTerms"));
  657. this.$.licenseplus.setContent(l10n.get("LicenseTermsPlus"));
  658. this.$.warningmessage.setContent(l10n.get("AllDataWillBeLost"));
  659. this.$.reinittext.setContent(l10n.get("ReinitJournalAndSettings"));
  660. this.notify = humane.create({ timeout: 1000, baseCls: 'humane-libnotify' })
  661. this.clickLeft = 3;
  662. this.$.sugarizer_value.setContent(constant.sugarizerVersion);
  663. this.$.clienttype_value.setContent(util.getClientName());
  664. this.$.browser_value.setContent(util.getBrowserName());
  665. this.$.browserversion_value.setContent(util.getBrowserVersion());
  666. this.$.useragent_value.setContent(navigator.userAgent);
  667. var that = this;
  668. util.computeDatastoreSize(function(size) {
  669. that.$.storage_value.setContent(l10n.get("StorageSize", {used: size.bytes, formatted: size.formatted}));
  670. });
  671. if (l10n.language.direction == "rtl") {
  672. this.$.text.addClass("rtl-10");
  673. this.$.software.addClass("rtl-10");
  674. this.$.browser.addClass("rtl-10");
  675. this.$.clienttype.addClass("rtl-10");
  676. this.$.browserversion.addClass("rtl-10");
  677. this.$.useragent.addClass("rtl-10");
  678. this.$.storage.addClass("rtl-10");
  679. this.$.copyright.addClass("rtl-10");
  680. this.$.license.addClass("rtl-10");
  681. }
  682. },
  683. rendered: function() {
  684. this.inherited(arguments);
  685. this.$.cancelbutton.setNodeProperty("title", l10n.get("Cancel"));
  686. this.$.okbutton.setNodeProperty("title", l10n.get("Ok"));
  687. this.owner.centerDialog(this);
  688. },
  689. // Event handling
  690. cancel: function() {
  691. this.hide();
  692. this.owner.show();
  693. },
  694. ok: function() {
  695. if (this.$.reinitcheck.getNodeProperty("checked")) {
  696. this.$.warningbox.setShowing(true);
  697. this.$.okbutton.setDisabled(true);
  698. this.$.cancelbutton.setDisabled(true);
  699. } else {
  700. this.hide();
  701. this.owner.show();
  702. }
  703. },
  704. reinit: function() {
  705. util.cleanDatastore(true, function() {
  706. util.restartApp();
  707. });
  708. },
  709. switchInit: function() {
  710. this.$.warningmessage.setShowing(this.$.reinitcheck.getNodeProperty("checked"));
  711. },
  712. version: function() {
  713. this.clickLeft--;
  714. if (this.clickLeft == 0) {
  715. this.$.reinittext.setShowing(true);
  716. this.$.reinitcheck.setShowing(true);
  717. } else if (this.clickLeft > 0) {
  718. this.notify.log(l10n.get("ClickMore"));
  719. }
  720. }
  721. });
  722. // Server dialog
  723. enyo.kind({
  724. name: "Sugar.DialogServer",
  725. kind: "enyo.Popup",
  726. classes: "module-dialog",
  727. centered: false,
  728. modal: true,
  729. floating: true,
  730. autoDismiss: false,
  731. components: [
  732. {name: "toolbar", classes: "toolbar", components: [
  733. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "module-icon", size: constant.sizeToolbar, icon: {directory: "icons", icon: "cloud-settings.svg"}},
  734. {name: "text", content: "xxx", classes: "module-text"},
  735. {name: "cancelbutton", kind: "Button", classes: "toolbutton module-cancel-button", ontap: "cancel"},
  736. {name: "okbutton", kind: "Button", classes: "toolbutton module-ok-button", ontap: "ok"}
  737. ]},
  738. {name: "warningbox", kind: "Sugar.DialogSettingsWarningBox", showing: false, onCancel: "cancel", onRestart: "restart"},
  739. {name: "content", components: [
  740. {name: "connected", kind: "Input", type: "checkbox", classes: "toggle aboutserver-checkbox", onchange: "switchConnection"},
  741. {name: "textconnected", content: "xxx", classes: "aboutserver-message"},
  742. {components:[
  743. {name: "textservername", content: "xxx", classes: "aboutserver-serverlabel"},
  744. {name: "servername", kind: "Input", classes: "aboutserver-servername", onkeydown: "enterclick"},
  745. {name: "qrbutton", kind: "Sugar.Icon", size: constant.sizeEmpty, icon: {directory: "icons", icon: "qrcode.svg"}, ontap: "scanQR", classes: "aboutserver-qr", showing: false}
  746. ]},
  747. {name: "serversettingsname", classes: "aboutserver-settingsname"},
  748. {name: "serversettingsvalue", classes: "aboutserver-settingsvalue"},
  749. {name: "serverdescription", classes: "aboutserver-description"},
  750. {name: "serverdescriptionvalue", classes: "aboutserver-descriptionvalue"},
  751. {components:[
  752. {name: "textusername", content: "xxx", classes: "aboutserver-userlabel"},
  753. {name: "username", kind: "Input", classes: "aboutserver-username", oninput: "changed"}
  754. ]},
  755. {name: "passwordmessage", classes: "aboutserver-passwordmessage"},
  756. {name: "password", kind: "Sugar.Password", classes: "aboutserver-password", onEnter: "next"},
  757. {name: "next", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "go-right.svg"}, classes: "aboutserver-rightbutton", ontap: "next"},
  758. {name: "spinner", kind: "Image", src: "images/spinner-light.gif", classes: "aboutserver-spinner", showing: false},
  759. {name: "warningmessage", content: "xxx", classes: "aboutserver-warningmessage", showing: false}
  760. ]}
  761. ],
  762. // Constructor
  763. create: function() {
  764. this.inherited(arguments);
  765. this.$.text.setContent(l10n.get("Server"));
  766. this.$.textconnected.setContent(l10n.get("ConnectedToServer"));
  767. this.$.textservername.setContent(l10n.get("ServerUrl"));
  768. this.$.serversettingsname.setContent(l10n.get("ServerName"));
  769. this.$.serverdescription.setContent(l10n.get("ServerDescription"));
  770. this.$.textusername.setContent(l10n.get("UserId"));
  771. this.$.next.setText(l10n.get("Next"));
  772. this.currentserver = preferences.getServer();
  773. this.initconnected = preferences.isConnected();
  774. this.initservername = (this.currentserver && this.currentserver.url) ? this.currentserver.url : util.getCurrentServerUrl();
  775. this.initusername = preferences.getName();
  776. this.networkId = null;
  777. this.forbidcheck = false;
  778. if (l10n.language.direction == "rtl") {
  779. this.$.text.addClass("rtl-10");
  780. this.$.textconnected.addClass("rtl-10");
  781. this.$.warningmessage.addClass("rtl-10");
  782. this.$.textservername.addClass("rtl-10");
  783. this.$.textusername.addClass("rtl-10");
  784. this.$.textusermessage.addClass("rtl-10");
  785. this.$.next.addClass("rtl-10");
  786. }
  787. this.step = 0;
  788. if (util.getClientType() == constant.webAppType) {
  789. this.step = 3;
  790. } else {
  791. if (!this.initconnected) {
  792. this.step = 0;
  793. } else {
  794. var token = preferences.getToken();
  795. if (token && token.expired) {
  796. this.step = 2;
  797. } else {
  798. this.step = 3;
  799. }
  800. }
  801. }
  802. this.displayStep();
  803. },
  804. rendered: function() {
  805. this.inherited(arguments);
  806. this.$.cancelbutton.setNodeProperty("title", l10n.get("Cancel"));
  807. this.$.okbutton.setNodeProperty("title", l10n.get("Ok"));
  808. this.$.connected.setNodeProperty("checked", this.initconnected);
  809. if (util.getClientType() == constant.webAppType) {
  810. this.$.servername.setDisabled(true);
  811. this.$.username.setDisabled(true);
  812. }
  813. this.centerDialog(this);
  814. },
  815. centerDialog: function(dialog) {
  816. var margin = util.computeMargin({width: 800, height: 500}, {width: 0.95, height: 0.95});
  817. dialog.applyStyle("margin-left", margin.left+"px");
  818. dialog.applyStyle("margin-top", (margin.top-55)+"px");
  819. return margin;
  820. },
  821. displayStep: function() {
  822. var
  823. vtextservername = false,
  824. vserversettingsname = false,
  825. vserverdescription = false,
  826. vtextservername = false,
  827. vservername = false,
  828. vserversettingsvalue = false,
  829. vserverdescriptionvalue = false,
  830. vserverqr = false,
  831. vtextusername = false,
  832. vusername = false,
  833. vnext = false,
  834. vpasswordmessage = false,
  835. vpassword = false;
  836. if (this.step == 0) {
  837. this.$.passwordmessage.setContent(l10n.get("PleaseConnectMessage"));
  838. vpasswordmessage = true;
  839. } else if (this.step == 1) {
  840. this.$.servername.setValue(constant.defaultServer);
  841. vtextservername = vservername = vnext = true;
  842. vserverqr = (enyo.platform.ios || enyo.platform.android || enyo.platform.androidChrome);
  843. } else if (this.step == 2) {
  844. vpasswordmessage = vpassword = vnext = true;
  845. this.$.password.startInputListening();
  846. if (preferences.getToken() && preferences.getToken().expired) {
  847. this.$.passwordmessage.setContent(l10n.get("SecurityMessageExpired", {min: util.getMinPasswordSize()}));
  848. } else {
  849. this.$.passwordmessage.setContent(l10n.get("SecurityMessageNew", {min: util.getMinPasswordSize()}));
  850. }
  851. } else if (this.step == 3) {
  852. this.$.servername.setValue(this.initservername);
  853. this.$.username.setValue(this.initusername);
  854. this.$.serversettingsvalue.setContent(this.currentserver.name);
  855. this.$.serverdescriptionvalue.setContent(this.currentserver.description);
  856. this.$.servername.setDisabled(true);
  857. vtextservername = vserversettingsname = vserverdescription = vtextservername = vservername = vserversettingsvalue = vserverdescriptionvalue = vtextusername = vusername = true;
  858. }
  859. this.$.textservername.setShowing(vtextservername);
  860. this.$.serversettingsname.setShowing(vserversettingsname);
  861. this.$.serverdescription.setShowing(vserverdescription);
  862. this.$.textservername.setShowing(vtextservername);
  863. this.$.servername.setShowing(vservername);
  864. this.$.qrbutton.setShowing(vserverqr);
  865. this.$.serversettingsvalue.setShowing(vserversettingsvalue);
  866. this.$.serverdescriptionvalue.setShowing(vserverdescriptionvalue);
  867. this.$.textusername.setShowing(vtextusername);
  868. this.$.username.setShowing(vusername);
  869. this.$.next.setShowing(vnext);
  870. this.$.passwordmessage.setShowing(vpasswordmessage);
  871. this.$.password.setShowing(vpassword);
  872. },
  873. // Event handling
  874. cancel: function() {
  875. if (!this.initconnected && this.hasChanged()) {
  876. preferences.setServer(null);
  877. }
  878. this.hide();
  879. this.owner.show();
  880. this.$.password.stopInputListening();
  881. },
  882. ok: function() {
  883. if (!this.hasChanged() || (this.$.connected.getNodeProperty("checked") && this.step != 3)) {
  884. this.hide();
  885. this.owner.show();
  886. return;
  887. }
  888. this.$.warningbox.setShowing(true);
  889. this.$.okbutton.setDisabled(true);
  890. this.$.cancelbutton.setDisabled(true);
  891. this.$.password.stopInputListening();
  892. },
  893. switchConnection: function() {
  894. if (this.forbidcheck) {
  895. this.$.connected.setNodeProperty("checked", !this.$.connected.getNodeProperty());
  896. return;
  897. }
  898. this.forbidcheck = true;
  899. if (util.getClientType() == constant.webAppType) {
  900. this.$.connected.setNodeProperty("checked", true);
  901. return;
  902. }
  903. if (this.step == 0) {
  904. this.step++;
  905. this.displayStep();
  906. }
  907. },
  908. next: function() {
  909. if (this.step == 1) {
  910. // Retrieve server information
  911. var that = this;
  912. that.$.spinner.setShowing(true);
  913. myserver.getServerInformation(this.$.servername.getValue(), function(inSender, inResponse) {
  914. that.currentserver = inResponse;
  915. that.currentserver.url = that.$.servername.getValue();
  916. if (that.currentserver.secure) {
  917. that.currentserver.url = that.currentserver.url.replace(constant.http, constant.https);
  918. } else {
  919. that.currentserver.url = that.currentserver.url.replace(constant.https, constant.http);
  920. }
  921. preferences.setServer(that.currentserver);
  922. that.initservername = that.$.servername.getValue();
  923. that.step++;
  924. that.displayStep();
  925. that.$.spinner.setShowing(false);
  926. that.$.warningmessage.setShowing(false);
  927. }, function() {
  928. that.$.warningmessage.setContent(l10n.get("ErrorLoadingRemote"));
  929. that.$.warningmessage.setShowing(true);
  930. that.$.spinner.setShowing(false);
  931. });
  932. } else if (this.step == 2) {
  933. // Validate password size
  934. var pass = this.$.password.getPassword();
  935. if (pass.length == 0 || pass.length < util.getMinPasswordSize()) {
  936. return;
  937. }
  938. // Try first to create a new user
  939. var that = this;
  940. that.$.spinner.setShowing(true);
  941. myserver.postUser(
  942. {
  943. name: preferences.getName(),
  944. color: preferences.getColor(),
  945. language: preferences.getLanguage(),
  946. role: "student",
  947. password: this.$.password.getPassword(),
  948. options: { sync: preferences.getOptions("sync"), stats: preferences.getOptions("stats") }
  949. },
  950. function(inSender, inResponse) {
  951. that.login();
  952. },
  953. function(response, error) {
  954. // User already exist, try to login instead
  955. if (error == 22) {
  956. that.login();
  957. } else {
  958. that.$.warningmessage.setContent(l10n.get("ServerError", {code: error}));
  959. that.$.warningmessage.setShowing(true);
  960. that.$.spinner.setShowing(false);
  961. }
  962. }
  963. );
  964. }
  965. },
  966. login: function() {
  967. var that = this;
  968. var user = {
  969. name: preferences.getName(),
  970. password: that.$.password.getPassword()
  971. };
  972. myserver.loginUser(user, function(loginSender, loginResponse) {
  973. that.step++;
  974. that.displayStep();
  975. that.networkId = loginResponse.user._id;
  976. preferences.setToken({'x_key': that.networkId, 'access_token': loginResponse.token});
  977. preferences.setPrivateJournal(loginResponse.user.private_journal);
  978. preferences.setSharedJournal(loginResponse.user.shared_journal);
  979. that.$.warningmessage.setContent(l10n.get("ChangesRequireRestart"));
  980. that.$.warningmessage.setShowing(true);
  981. that.$.spinner.setShowing(false);
  982. that.$.warningbox.setShowing(true);
  983. that.$.okbutton.setDisabled(true);
  984. that.$.cancelbutton.setDisabled(true);
  985. },
  986. function(response, error) {
  987. // Login error, retry
  988. if (error == 1) {
  989. that.$.warningmessage.setContent(l10n.get("UserLoginInvalid"));
  990. } else {
  991. that.$.warningmessage.setContent(l10n.get("ServerError", {code: error}));
  992. }
  993. that.$.warningmessage.setShowing(true);
  994. that.$.spinner.setShowing(false);
  995. }
  996. );
  997. },
  998. restart: function() {
  999. // Now ConnectedToServer
  1000. var nowconnected = this.$.connected.getNodeProperty("checked");
  1001. preferences.setConnected(nowconnected);
  1002. if (nowconnected) {
  1003. preferences.setNetworkId(this.networkId);
  1004. } else {
  1005. preferences.setNetworkId(null);
  1006. preferences.setServer(null);
  1007. preferences.setToken(null);
  1008. }
  1009. preferences.save();
  1010. util.restartApp();
  1011. },
  1012. // Handle QR Code scanner
  1013. scanQR: function() {
  1014. var that = this;
  1015. var toolbar = document.getElementById("toolbar");
  1016. this.hide();
  1017. toolbar.style.visibility = 'hidden';
  1018. util.scanQRCode(function(code) {
  1019. toolbar.style.visibility = 'visible';
  1020. that.show();
  1021. that.$.servername.setValue(code);
  1022. }, function() {
  1023. toolbar.style.visibility = 'visible';
  1024. that.show();
  1025. that.$.servername.focus();
  1026. that.$.servername.hasNode().select()
  1027. });
  1028. },
  1029. // Utility
  1030. hasChanged: function() {
  1031. var currentconnected = this.$.connected.getNodeProperty("checked");
  1032. return (this.initconnected != currentconnected);
  1033. },
  1034. enterclick: function(inSender, inEvent) {
  1035. if (inEvent.keyCode === 13) {
  1036. this.next();
  1037. return true;
  1038. }
  1039. }
  1040. });
  1041. // Privacy dialog
  1042. enyo.kind({
  1043. name: "Sugar.DialogPrivacy",
  1044. kind: "enyo.Popup",
  1045. classes: "module-dialog",
  1046. centered: false,
  1047. modal: true,
  1048. floating: true,
  1049. autoDismiss: false,
  1050. components: [
  1051. {name: "toolbar", classes: "toolbar", components: [
  1052. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "module-icon", size: constant.sizeToolbar, icon: {directory: "icons", icon: "privacy.svg"}},
  1053. {name: "text", content: "xxx", classes: "module-text"},
  1054. {name: "cancelbutton", kind: "Button", classes: "toolbutton module-cancel-button", ontap: "cancel"},
  1055. {name: "okbutton", kind: "Button", classes: "toolbutton module-ok-button", ontap: "ok"}
  1056. ]},
  1057. {name: "warningbox", kind: "Sugar.DialogSettingsWarningBox", showing: false, onCancel: "cancel", onRestart: "restart"},
  1058. {name: "content", components: [
  1059. {name: "stats", kind: "Input", type: "checkbox", classes: "toggle privacy-statscheckbox"},
  1060. {name: "textstats", content: "xxx", classes: "privacy-statsmessage"},
  1061. {content: ""},
  1062. {name: "sync", kind: "Input", type: "checkbox", classes: "toggle privacy-synccheckbox"},
  1063. {name: "textsync", content: "xxx", classes: "privacy-syncmessage"},
  1064. ]}
  1065. ],
  1066. // Constructor
  1067. create: function() {
  1068. this.inherited(arguments);
  1069. this.$.text.setContent(l10n.get("MyPrivacy"));
  1070. this.$.textstats.setContent(l10n.get("PrivacyStats"));
  1071. this.$.textsync.setContent(l10n.get("PrivacySync"));
  1072. this.initstats = preferences.getOptions("stats");
  1073. this.initsync = preferences.getOptions("sync");
  1074. if (l10n.language.direction == "rtl") {
  1075. this.$.text.addClass("rtl-10");
  1076. this.$.textstats.addClass("rtl-10");
  1077. this.$.textsync.addClass("rtl-10");
  1078. }
  1079. },
  1080. rendered: function() {
  1081. this.inherited(arguments);
  1082. this.$.cancelbutton.setNodeProperty("title", l10n.get("Cancel"));
  1083. this.$.okbutton.setNodeProperty("title", l10n.get("Ok"));
  1084. this.$.stats.setNodeProperty("checked", !this.initstats);
  1085. this.$.sync.setNodeProperty("checked", !this.initsync);
  1086. this.owner.centerDialog(this);
  1087. },
  1088. // Event handling
  1089. cancel: function() {
  1090. this.hide();
  1091. this.owner.show();
  1092. },
  1093. ok: function() {
  1094. if (!this.hasChanged()) {
  1095. this.hide();
  1096. this.owner.show();
  1097. return;
  1098. }
  1099. this.$.warningbox.setShowing(true);
  1100. this.$.okbutton.setDisabled(true);
  1101. this.$.cancelbutton.setDisabled(true);
  1102. },
  1103. restart: function() {
  1104. if (this.hasChanged()) {
  1105. preferences.setOptions("stats", !this.$.stats.getNodeProperty("checked"));
  1106. preferences.setOptions("sync", !this.$.sync.getNodeProperty("checked"));
  1107. preferences.save();
  1108. preferences.saveToServer(myserver, null, null);
  1109. }
  1110. util.restartApp();
  1111. },
  1112. // Utility
  1113. hasChanged: function() {
  1114. var currentstats = !this.$.stats.getNodeProperty("checked");
  1115. var currentsync = !this.$.sync.getNodeProperty("checked");
  1116. return (this.initstats != currentstats || this.initsync != currentsync);
  1117. }
  1118. });
  1119. //-------------------------- Settings utility classes
  1120. // Class for an item in the settings dialog
  1121. enyo.kind({
  1122. name: "Sugar.DialogSettingsItem",
  1123. kind: enyo.Control,
  1124. classes: "settings-item",
  1125. published: {
  1126. icon: null,
  1127. text: null,
  1128. colorized: false,
  1129. disabled: false
  1130. },
  1131. components: [
  1132. {components: [
  1133. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "settings-item-icon", size: constant.sizeSettings, disabledBackground: "#000000"},
  1134. {name: "text", content: "xxx", classes: "settings-item-text"}
  1135. ]}
  1136. ],
  1137. // Constructor
  1138. create: function() {
  1139. this.inherited(arguments);
  1140. this.colorizedChanged();
  1141. this.iconChanged();
  1142. this.textChanged();
  1143. this.disabledChanged();
  1144. },
  1145. // Property changed
  1146. iconChanged: function() {
  1147. this.$.icon.setIcon(this.icon);
  1148. },
  1149. textChanged: function() {
  1150. this.$.text.setContent(this.text);
  1151. },
  1152. colorizedChanged: function() {
  1153. this.$.icon.setColorized(this.colorized);
  1154. },
  1155. disabledChanged: function() {
  1156. this.$.icon.setDisabled(this.disabled);
  1157. this.addRemoveClass('settings-item-text-disable', this.disabled);
  1158. this.addRemoveClass('settings-item-text-enable', !this.disabled);
  1159. }
  1160. });
  1161. // Class for a Warning box in settings
  1162. enyo.kind({
  1163. name: "Sugar.DialogSettingsWarningBox",
  1164. kind: enyo.Control,
  1165. classes: "settings-warningbox",
  1166. events: { onRestart: "", onCancel: "" },
  1167. components: [
  1168. {name: "warningtitle", content: "xxx", classes: "warningbox-title"},
  1169. {name: "warningmessage", content: "xxx", classes: "warningbox-message"},
  1170. {name: "warningcancel", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "dialog-cancel.svg"}, classes: "warningbox-cancel-button", ontap: "cancel"},
  1171. {name: "warningrestart", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "system-restart.svg"}, classes: "warningbox-refresh-button", ontap: "restart"}
  1172. ],
  1173. // Constructor
  1174. create: function() {
  1175. this.inherited(arguments);
  1176. this.$.warningtitle.setContent(l10n.get("Warning"));
  1177. this.$.warningmessage.setContent(l10n.get("ChangesRequireRestart"));
  1178. this.$.warningcancel.setText(l10n.get("CancelChanges"));
  1179. this.$.warningrestart.setText(l10n.get("RestartNow"));
  1180. if (l10n.language.direction == "rtl") {
  1181. this.$.warningtitle.addClass("rtl-10");
  1182. this.$.warningmessage.addClass("rtl-10");
  1183. }
  1184. },
  1185. // Events
  1186. cancel: function() {
  1187. this.doCancel();
  1188. },
  1189. restart: function() {
  1190. this.doRestart();
  1191. }
  1192. });
  1193. //Dialog to change launcher on a native device
  1194. enyo.kind({
  1195. name: "Sugar.DialogChangeLauncher",
  1196. kind: "enyo.Popup",
  1197. classes: "module-dialog",
  1198. centered: false,
  1199. modal: true,
  1200. floating: true,
  1201. autoDismiss: false,
  1202. components: [
  1203. {name: "toolbar", classes: "toolbar", components: [
  1204. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "module-icon", colorized: true, size: constant.sizeToolbar, icon: {directory: "icons", icon: "owner-icon.svg"}},
  1205. {name: "text", content: "xxx", classes: "module-text"},
  1206. {name: "cancelbutton", kind: "Button", classes: "toolbutton module-cancel-button", ontap: "cancel"},
  1207. {name: "okbutton", kind: "Button", classes: "toolbutton module-ok-button", ontap: "ok"}
  1208. ]},
  1209. {name: "warningbox", kind: "Sugar.DialogSettingsWarningBox", showing: false, onCancel: "cancel", onRestart: "restart"},
  1210. {name: "content", components: [
  1211. {classes: "enterkey", components: [
  1212. {name: "keyInput", kind: "Input", classes: "enterkey-input", oninput:"keychanged"}
  1213. ]},
  1214. {name: "connectButton", kind: "Button", classes: "toolbutton", ontap: "ok"}
  1215. ]}
  1216. ],
  1217. // Constructor
  1218. create: function() {
  1219. this.inherited(arguments);
  1220. this.$.text.setContent(l10n.get("EnterKey"));
  1221. if (l10n.language.direction == "rtl") {
  1222. this.$.text.addClass("rtl-10");
  1223. }
  1224. },
  1225. rendered: function() {
  1226. this.inherited(arguments);
  1227. this.$.icon.render();
  1228. this.$.cancelbutton.setNodeProperty("title", l10n.get("Cancel"));
  1229. this.$.okbutton.setNodeProperty("title", l10n.get("Ok"));
  1230. this.$.connectButton.setContent(l10n.get("Ok"));
  1231. },
  1232. // Event handling
  1233. cancel: function() {
  1234. this.hide();
  1235. },
  1236. ok: function() {
  1237. sugarizerOS.sharedKeyBuffer = this.$.keyInput.getValue();
  1238. this.hide();
  1239. this.$.okbutton.setDisabled(true);
  1240. this.$.cancelbutton.setDisabled(true);
  1241. },
  1242. keychanged: function() {
  1243. },
  1244. connect: function() {
  1245. },
  1246. centerDialog: function(dialog) {
  1247. var margin = util.computeMargin({width: 800, height: 500}, {width: 0.95, height: 0.95});
  1248. dialog.applyStyle("margin-left", margin.left+"px");
  1249. dialog.applyStyle("margin-top", (margin.top-55)+"px");
  1250. }
  1251. });
  1252. // Waring message dialog
  1253. enyo.kind({
  1254. name: "Sugar.DialogWarningMessage",
  1255. kind: "enyo.Popup",
  1256. classes: "warning-dialog",
  1257. centered: false,
  1258. modal: true,
  1259. floating: true,
  1260. autoDismiss: true,
  1261. components: [
  1262. {name: "icon", kind: "Sugar.Icon", x: 6, y: 6, classes: "warningdialog-icon", size: constant.sizeToolbar, icon: {directory: "icons", icon: "emblem-warning.svg"}},
  1263. {name: "warningtitle", content: "xxx", classes: "warningdialog-title"},
  1264. {name: "warningmessage", content: "xxx", classes: "warningdialog-message"},
  1265. {name: "warningcancel", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "dialog-cancel.svg"}, classes: "warningdialog-cancel-button", ontap: "cancel"},
  1266. {name: "warningrestart", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "system-shutdown.svg"}, classes: "warningdialog-ok-button", ontap: "ok"},
  1267. ],
  1268. // Constructor
  1269. create: function() {
  1270. this.inherited(arguments);
  1271. this.$.warningtitle.setContent(l10n.get("Warning"));
  1272. this.$.warningmessage.setContent(l10n.get("AllDataWillBeLost"));
  1273. this.$.warningcancel.setText(l10n.get("CancelChanges"));
  1274. this.$.warningrestart.setText(l10n.get("Logoff"));
  1275. },
  1276. rendered: function() {
  1277. this.inherited(arguments);
  1278. var margin = util.computeMargin({width: 800, height: 150}, {width: 0.95, height: 0.95});
  1279. this.applyStyle("margin-left", margin.left+"px");
  1280. this.applyStyle("margin-top", (margin.top-55)+"px");
  1281. },
  1282. // Event handling
  1283. cancel: function() {
  1284. this.hide();
  1285. },
  1286. ok: function() {
  1287. this.hide();
  1288. preferences.addUserInHistory();
  1289. util.cleanDatastore(null, function() {
  1290. util.restartApp();
  1291. });
  1292. }
  1293. });
  1294. // Class for a generic Warning box
  1295. enyo.kind({
  1296. name: "Sugar.GenericDialogBox",
  1297. kind: enyo.Control,
  1298. classes: "genericbox",
  1299. events: { onOk: "", onCancel: "", onShow: "", onHide: "" },
  1300. published: {
  1301. title: null,
  1302. message: null,
  1303. okText: '',
  1304. cancelText: ''
  1305. },
  1306. components: [
  1307. {name: "warningtitle", content: "xxx", classes: "genericbox-title"},
  1308. {name: "warningmessage", content: "xxx", classes: "genericbox-message"},
  1309. {name: "warningcancel", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "dialog-cancel.svg"}, classes: "genericbox-cancel-button", ontap: "cancel"},
  1310. {name: "warningok", kind: "Sugar.IconButton", icon: {directory: "icons", icon: "dialog-ok.svg"}, classes: "genericbox-ok-button", ontap: "ok"}
  1311. ],
  1312. // Constructor
  1313. create: function() {
  1314. this.inherited(arguments);
  1315. this.titleChanged();
  1316. this.messageChanged();
  1317. this.okTextChanged();
  1318. this.cancelTextChanged();
  1319. if (l10n.language.direction == "rtl") {
  1320. this.$.warningtitle.addClass("rtl-10");
  1321. this.$.warningmessage.addClass("rtl-10");
  1322. }
  1323. },
  1324. titleChanged: function() {
  1325. this.$.warningtitle.setContent(this.title);
  1326. },
  1327. messageChanged: function() {
  1328. this.$.warningmessage.setContent(this.message);
  1329. },
  1330. cancelTextChanged: function() {
  1331. this.$.warningcancel.setText(this.cancelText);
  1332. },
  1333. okTextChanged: function() {
  1334. this.$.warningok.setText(this.okText);
  1335. },
  1336. showingChanged: function() {
  1337. this.inherited(arguments);
  1338. if (this.showing) {
  1339. this.doShow();
  1340. } else {
  1341. this.doHide();
  1342. }
  1343. },
  1344. // Events
  1345. cancel: function() {
  1346. this.doCancel();
  1347. },
  1348. ok: function() {
  1349. this.doOk();
  1350. }
  1351. });