Skip to content
Permalink
Newer
Older
100644 904 lines (831 sloc) 28 KB
1
2
// Sugar Libraries (initialized by require)
3
var app = null;
4
var toolbar = null;
5
var mouse = {position: {x: -1, y: -1}};
6
var isFirstLaunch = false;
7
var iconLib;
8
var xoPalette;
9
var radioButtonsGroup;
10
var datastore;
11
var presence;
January 1, 2014 11:24
12
var l10n;
13
var preferences;
14
var util;
15
var myserver;
April 30, 2017 21:20
17
var tutorial;
August 19, 2017 22:18
18
var stats;
January 12, 2018 23:01
19
var autosync;
May 25, 2021 22:21
20
var historic;
June 22, 2021 22:00
21
var activities;
22
23
24
25
// Main app class
26
enyo.kind({
27
name: "Sugar.Desktop",
28
kind: enyo.Control,
29
components: [
30
{name: "owner", kind: "Sugar.Icon", size: constant.sizeOwner, colorized: true, classes: "owner-icon", showing: false},
August 11, 2014 07:59
31
{name: "journal", kind: "Sugar.Icon", size: constant.sizeJournal, ontap: "showJournal", classes: "journal-icon", showing: false},
32
{name: "desktop", showing: true, onresize: "resize", components: []},
33
{name: "otherview", showing: true, components: []},
June 22, 2021 22:00
34
{name: "activityPopup", kind: "Sugar.Popup", showing: false}
35
],
37
// Constructor
38
create: function() {
39
// Init screen
November 11, 2018 22:25
40
app = this;
41
this.inherited(arguments);
42
this.timer = null;
January 4, 2014 22:33
43
this.otherview = null;
44
this.toolbar = null;
45
util.setToolbar(this.getToolbar());
46
this.$.owner.setIcon({directory: "icons", icon: "owner-icon.svg"});
January 2, 2014 18:23
47
this.$.owner.setPopupShow(enyo.bind(this, "showBuddyPopup"));
48
this.$.owner.setPopupHide(enyo.bind(this, "hideBuddyPopup"));
49
this.$.journal.setIcon({directory: "icons", icon: "activity-journal.svg"});
50
this.restrictedModeInfo = { start: 0 };
51
util.hideNativeToolbar();
52
this.tutorialActivity = null;
October 26, 2021 22:14
53
this.eeMode = null;
55
// Load and sort journal
56
this.loadJournal();
57
this.isJournalFull = false;
58
this.testJournalSize();
December 17, 2022 22:00
59
this.changeAssignmentIconVisibility();
61
// Check change on preferences from server
June 22, 2021 22:00
62
var that = this;
63
var isConnected = preferences.isConnected();
June 22, 2021 22:00
64
if (that.getToolbar() && that.getToolbar().showServerWarning) {
65
that.getToolbar().showServerWarning(!isConnected);
66
}
67
if (isConnected) {
68
this.connectToServer(function(success) {
69
if (that.getToolbar() && that.getToolbar().showServerWarning) {
70
that.getToolbar().showServerWarning(!success);
71
}
June 22, 2021 22:00
72
that.init();
73
});
74
} else {
75
util.updateFavicon();
June 22, 2021 22:00
76
that.init();
77
}
78
79
// Init SugarizerOS
80
if (window.sugarizerOS){
81
sugarizerOS.isWifiEnabled(function(value){
82
if (value != 0) {
83
sugarizerOS.scanWifi();
84
}
85
});
86
sugarizerOS.popupTimer = 0;
87
if (sugarizerOS.launches == 2 && sugarizerOS.launcherPackageName != sugarizerOS.packageName &&
88
!sugarizerOS.isSetup){
89
that.doResetLauncher();
90
sugarizerOS.putInt("IS_SETUP", 1);
91
}
92
}
November 11, 2018 22:25
94
// Launch tutorial at first launch
95
window.setTimeout(function() {
96
if (isFirstLaunch) {
97
that.getToolbar().startTutorial();
98
}
99
}, constant.timerBeforeTutorial);
100
},
102
// Load and sort journal
103
loadJournal: function() {
104
this.loadAssignment();
105
this.journal = datastore.find();
106
this.journal = this.journal.sort(function(e0, e1) {
107
return parseInt(e1.metadata.timestamp) - parseInt(e0.metadata.timestamp);
108
});
109
},
110
111
loadAssignment: function() {
112
this.showAssignments = datastore.find();
113
this.showAssignments = this.showAssignments.filter(function(entry) {
114
return entry.metadata.assignmentId != undefined;
115
});
116
},
117
// Test Journal size to ensure it's not full
118
testJournalSize: function() {
119
this.isJournalFull = false;
120
var that = this;
121
util.computeDatastoreSize(function(size) {
122
var percentremain = ((size.remain/size.total)*100);
123
if (percentremain < constant.minStorageSizePercent) {
124
console.log("WARNING: Journal almost full");
125
that.isJournalFull = true;
126
}
127
});
128
},
129
130
// Try to connect to the server: update preferences, sync journal, ...
131
connectToServer: function(callback) {
132
var networkId = preferences.getNetworkId();
133
var that = this;
134
myserver.getUser(
135
networkId,
136
function(inSender, inResponse) {
137
var changed = preferences.merge(inResponse);
138
util.updateFavicon();
139
if (changed) {
February 11, 2023 22:42
140
preferences.saveToServer(myserver);
June 22, 2021 22:00
141
that.draw();
142
that.render();
143
} else if (that.currentView == constant.journalView) {
144
that.otherview.updateNetworkBar();
145
}
146
presence.joinNetwork(function (error, user) {
147
if (error) {
148
console.log("WARNING: Can't connect to presence server");
149
}
150
presence.onConnectionClosed(function (event) {
151
console.log("Disconnected");
152
var message = l10n.get((event.code == 4999) ? "YouveGotDisconnectedAutomatically" : "YouveGotDisconnected");
153
if (message) humane.log(message);
154
});
155
});
156
callback(true);
157
autosync.synchronizeJournal(
158
function(count) {
159
if (count) {
160
setTimeout(function() {
161
var message = l10n.get("RetrievingJournal");
162
if (message) humane.log(message);
163
}, 100);
164
var toolbar = that.getToolbar();
165
if (toolbar.showSync) {
166
toolbar.showSync(true);
167
}
168
}
169
},
170
function(locale, remote, error) {
171
var toolbar = that.getToolbar();
172
if (toolbar.showSync) {
173
toolbar.showSync(false);
174
}
175
176
// Locale journal has changed, update display
177
if (locale && !error) {
178
that.loadJournal();
179
that.testJournalSize();
June 22, 2021 22:00
180
activities.loadEntries();
181
that.changeAssignmentIconVisibility();
182
that.draw();
183
that.render();
184
}
185
}
186
);
187
},
188
function() {
189
console.log("WARNING: Can't read network user settings");
190
callback(false);
191
}
192
);
193
},
194
195
// Get linked toolbar
196
getToolbar: function() {
197
if (this.toolbar == null) {
August 11, 2014 07:59
198
this.toolbar = new Sugar.DesktopToolbar();
199
}
February 4, 2018 10:55
200
if (this.currentView != constant.listView && this.otherview != null) {
201
return this.otherview.getToolbar();
202
}
203
return this.toolbar;
204
},
November 1, 2014 22:29
206
// Get linked popup
207
getPopup: function() {
208
return this.$.activityPopup;
209
},
211
// Init desktop
212
init: function() {
213
if (preferences.getView()) {
214
this.showView(preferences.getView());
June 22, 2021 22:00
215
} else {
216
this.currentView = constant.radialView;
217
}
218
this.draw();
219
},
November 11, 2018 22:25
221
localize: function() {
222
if (this.otherview && this.otherview.localize) {
223
this.otherview.localize();
224
}
225
},
226
227
// Draw desktop
228
draw: function() {
229
// Clean desktop
230
var items = [];
231
enyo.forEach(this.$.desktop.getControls(), function(item) { items.push(item); });
232
for (var i = 0 ; i < items.length ; i++) { items[i].destroy(); };
233
this.tutorialActivity = null;
235
// Compute center and radius
236
var canvas_center = util.getCanvasCenter();
237
var icon_size = constant.iconSizeStandard;
September 19, 2015 16:25
238
var icon_padding = icon_size*constant.iconSpacingFactor;
239
var semi_size = icon_size/2;
240
var jdeltay = (canvas_center.dy < 480) ? -12 : 0;
242
// Draw XO owner
243
this.$.owner.applyStyle("margin-left", (canvas_center.x-constant.sizeOwner/2)+"px");
244
this.$.owner.applyStyle("margin-top", (canvas_center.y-constant.sizeOwner/2)+"px");
245
this.$.journal.setColorized(this.journal.length > 0);
246
this.$.journal.applyStyle("margin-left", (canvas_center.x-constant.sizeJournal/2)+"px");
247
this.$.journal.applyStyle("margin-top", (canvas_center.y+constant.sizeOwner-constant.sizeJournal+jdeltay)+"px");
248
this.$.owner.setShowing(this.currentView == constant.radialView);
249
this.$.journal.setShowing(this.currentView == constant.radialView);
250
September 19, 2015 16:25
251
// Compute ring size and shape
June 22, 2021 22:00
252
var activitiesList = activities.getFavorites();
September 19, 2015 16:25
253
var activitiesCount = activitiesList.length;
254
var activitiesIndex = 0;
255
var radiusx, radiusy, base_angle, spiralMode, restrictedMode;
September 19, 2015 16:25
256
var PI2 = Math.PI*2.0;
257
radiusx = radiusy = Math.max(constant.ringMinRadiusSize, Math.min(canvas_center.x-icon_size,canvas_center.y-icon_size));
September 19, 2015 16:25
258
var circumference = PI2*radiusx;
May 23, 2020 10:43
259
var spiralPositions = [];
260
if ((circumference/activitiesList.length) >= constant.iconSpacingFactor*icon_padding) {
261
spiralMode = restrictedMode = false;
February 27, 2022 09:16
262
base_angle = (PI2/parseFloat(activitiesList.length));
May 23, 2020 10:43
264
if (this.hasRoomForSpiral(canvas_center, icon_size, spiralPositions)) {
265
spiralMode = true; restrictedMode = false;
266
radiusx = radiusy = icon_padding*constant.ringInitSpaceFactor;
267
activitiesCount = parseInt((PI2*radiusx)/icon_padding);
268
base_angle = PI2/activitiesCount;
269
} else {
270
restrictedMode = true; spiralMode = false;
February 27, 2022 09:16
271
activitiesCount = parseInt(circumference/icon_padding);
272
while((circumference/activitiesCount) <= constant.ringSpaceFactor*constant.iconSpacingFactor*icon_padding){
February 27, 2022 09:16
273
activitiesCount--;
274
}
275
this.restrictedModeInfo.count = activitiesCount;
276
this.restrictedModeInfo.length = activitiesList.length;
277
base_angle = (PI2/parseFloat(activitiesCount+1));
278
}
September 19, 2015 16:25
279
}
September 19, 2015 16:25
281
// Draw activity icons
May 23, 2020 10:43
282
var angle = -Math.PI/2.0-base_angle;
283
for (var i = 0 ; i < activitiesList.length ; i++) {
284
// Compute icon position
285
var activity = activitiesList[i];
September 19, 2015 16:25
286
var ix, iy;
287
var previousAngle = angle;
September 19, 2015 16:25
288
if (!spiralMode) {
289
angle += base_angle;
290
ix = (canvas_center.x+Math.cos(angle)*radiusx-semi_size);
291
iy = (canvas_center.y+Math.sin(angle)*radiusy-semi_size);
292
} else {
May 23, 2020 10:43
293
ix = spiralPositions[i].x;
294
iy = spiralPositions[i].y;
September 19, 2015 16:25
295
}
296
297
// Restricted mode for small device: integrate a way to scroll on the circle
298
if (restrictedMode) {
299
if (i < this.restrictedModeInfo.start) {
300
angle = previousAngle;
301
continue;
302
} else if (i > 0 && i == this.restrictedModeInfo.start) {
303
this.$.desktop.createComponent({
304
kind: "Sugar.Icon",
305
icon: {directory: "icons", icon: "activity-etc.svg", name: l10n.get("ListView")},
306
size: icon_size,
307
x: ix,
308
y: iy,
309
ontap: "showPreviousRestrictedList"
310
},
311
{owner: this}).render();
312
continue;
313
} else if (i >= this.restrictedModeInfo.start+activitiesCount-1 && this.restrictedModeInfo.start + activitiesCount < activitiesList.length) {
314
this.$.desktop.createComponent({
315
kind: "Sugar.Icon",
316
icon: {directory: "icons", icon: "activity-etc.svg", name: l10n.get("ListView")},
317
size: icon_size,
318
x: ix,
319
y: iy,
320
ontap: "showNextRestrictedList"
321
},
322
{owner: this}).render();
323
break;
324
}
326
327
// Draw icon
August 28, 2016 16:21
328
if (activity.type != null && activity.type == "native") {
329
activity.isNative = true;
330
}
April 30, 2017 21:20
331
var newIcon = this.$.desktop.createComponent({
September 3, 2016 16:03
332
kind: "Sugar.Icon",
333
icon: activity, // HACK: Icon characteristics are embedded in activity object
334
size: icon_size,
335
x: ix,
336
y: iy,
337
colorized: activity.instances !== undefined && activity.instances.length > 0,
338
colorizedColor: (activity.instances !== undefined && activity.instances.length > 0 && activity.instances[0].metadata.buddy_color) ? activity.instances[0].metadata.buddy_color : null,
339
ontap: "runMatchingActivity",
340
popupShow: enyo.bind(this, "showActivityPopup"),
341
popupHide: enyo.bind(this, "hideActivityPopup")
342
},
343
{owner: this}
April 30, 2017 21:20
344
);
345
newIcon.render();
September 19, 2015 16:25
346
activitiesIndex++;
April 30, 2017 21:20
347
348
// Set tutorial
349
if (!this.tutorialActivity) {
350
this.tutorialActivity = newIcon;
April 30, 2017 21:20
351
}
352
}
353
},
355
// Redraw, for example after a resized event
356
redraw: function() {
357
this.draw();
358
if (this.currentView == constant.radialView || this.currentView == constant.listView) {
359
this.filterActivities();
360
}
361
this.render();
362
},
364
resize: function() {
365
if (this.noresize) {
366
return;
367
}
June 29, 2022 22:21
368
if (tutorial.isLaunched()) {
369
tutorial.stop();
370
}
371
this.redraw();
372
},
May 23, 2020 10:43
374
hasRoomForSpiral: function(canvas_center, icon_size, spiralPositions) {
June 22, 2021 22:00
375
var activitiesList = activities.getFavorites();
376
var activitiesCount = activitiesList.length;
May 22, 2020 22:24
377
var radiusx = icon_size*constant.iconSpacingFactor*constant.ringInitSpaceFactor;
378
var icon_spacing = Math.sqrt(Math.pow(icon_size,2) * 2) * constant.spiralInitSpaceFactor;
379
var angle = Math.PI;
380
var PI2 = Math.PI*2.0;
381
var semi_size = icon_size/2;
382
var spiral_spacing = icon_spacing * constant.spiralSpaceFactor;
383
var maxX = 0, maxY = 0, minX = canvas_center.dx, minY = canvas_center.dy;
384
while (activitiesCount-- > 0) {
385
var circumference = PI2*radiusx;
386
n = circumference / icon_spacing;
387
radiusx += (spiral_spacing / n);
388
var ix = canvas_center.x-semi_size+Math.sin(angle) * radiusx;
389
var iy = canvas_center.y+Math.cos(angle) * radiusx - semi_size;
May 23, 2020 10:43
390
spiralPositions.push({x: ix, y: iy});
May 22, 2020 22:24
391
maxX = Math.max(maxX, ix+icon_size); maxY = Math.max(maxY, iy+icon_size);
392
minX = Math.min(minX, ix); minY = Math.min(minY, iy);
393
angle -= (PI2 / n);
395
return (maxX <= canvas_center.dx && maxY <= canvas_center.dy-5 && minX >= 0 && minY >= 0);
398
showPreviousRestrictedList: function() {
399
this.getPopup().hidePopup();
400
var newStart = this.restrictedModeInfo.start - this.restrictedModeInfo.count;
401
if (newStart < 0) {
402
newStart = 0;
403
}
404
this.restrictedModeInfo.start = newStart;
405
this.draw();
406
},
407
408
showNextRestrictedList: function() {
409
this.getPopup().hidePopup();
410
var newStart = this.restrictedModeInfo.start + this.restrictedModeInfo.count - 2;
411
if (newStart > this.restrictedModeInfo.length-1) {
412
return;
413
} else if (newStart+this.restrictedModeInfo.count > this.restrictedModeInfo.length) {
414
newStart = this.restrictedModeInfo.length - this.restrictedModeInfo.count;
415
}
416
this.restrictedModeInfo.start = newStart;
417
this.draw();
418
},
419
420
// Switch between radial and other views (list or journal)
421
showView: function(newView) {
422
if (this.currentView == newView) {
423
return;
424
}
425
var oldView = this.currentView;
426
this.currentView = newView;
August 19, 2017 22:18
427
stats.trace(constant.viewNames[oldView], 'change_view', constant.viewNames[newView]);
428
429
// Show desktop
430
if (newView == constant.radialView) {
431
this.otherview = null;
432
util.setToolbar(this.getToolbar());
433
toolbar.setActiveView(constant.radialView);
434
this.$.otherview.hide();
435
this.$.desktop.show();
436
this.$.owner.show();
437
this.$.journal.show();
December 17, 2022 22:00
439
this.changeAssignmentIconVisibility();
440
return;
441
}
443
// Hide desktop
444
this.$.owner.hide();
445
this.$.journal.hide();
446
this.$.desktop.hide();
447
this.clearView();
449
// Show list
450
if (newView == constant.listView) {
451
util.setToolbar(this.getToolbar());
452
var filter = toolbar.getSearchText().toLowerCase();
453
toolbar.setActiveView(constant.listView);
June 22, 2021 22:00
454
this.otherview = this.$.otherview.createComponent({kind: "Sugar.DesktopListView", activities: activities.getByName(filter)});
455
}
457
// Show journal
458
else if (newView == constant.journalView) {
459
if (this.timer != null) {
November 1, 2014 22:29
460
this.getPopup().hidePopup();
461
window.clearInterval(this.timer);
January 4, 2014 22:33
463
this.otherview = this.$.otherview.createComponent({kind: "Sugar.Journal", journal: this.journal});
464
util.setToolbar(this.otherview.getToolbar());
465
}
467
//show assignment_view
468
else if (newView == constant.assignmentView) {
469
this.otherview = this.$.otherview.createComponent({kind: "Sugar.Journal", journal: this.journal});
470
util.setToolbar(this.otherview.getToolbar());
471
}
472
November 1, 2014 22:29
473
// Show neighborhood
474
else if (newView == constant.neighborhoodView) {
475
this.otherview = this.$.otherview.createComponent({kind: "Sugar.NeighborhoodView"});
476
toolbar.setActiveView(constant.neighborhoodView);
477
util.setToolbar(this.otherview.getToolbar());
November 1, 2014 22:29
478
}
December 17, 2022 22:00
480
this.changeAssignmentIconVisibility();
481
this.$.otherview.show();
482
this.$.otherview.render();
483
},
December 16, 2013 21:30
485
getView: function() {
486
return this.currentView;
487
},
489
clearView: function() {
490
var controls = this.$.otherview.getControls();
491
for (var i = 0, c; c = controls[i]; i++) c.destroy();
492
},
494
showListView: function() {
495
this.showView(constant.listView);
496
},
December 17, 2022 22:00
498
changeAssignmentIconVisibility: function() {
499
//get assignments which are not completed and duedate is not passed
500
if (!this.getToolbar().showAssignments) {
501
return;
502
}
503
this.loadAssignment();
December 17, 2022 22:00
504
if (this.showAssignments.length > 0 && this.getToolbar().showAssignments) {
505
var assignments = this.showAssignments.filter(function(assignment){
506
return assignment.metadata.isSubmitted == false && assignment.metadata.dueDate > new Date().getTime();
507
});
508
this.getToolbar().showAssignments(assignments.length);
509
} else {
510
this.getToolbar().showAssignments(0);
511
}
512
},
513
514
// Render
515
rendered: function() {
516
this.inherited(arguments);
517
this.$.owner.colorize(preferences.getColor());
August 28, 2016 16:21
518
if (this.journal.length > 0) {
519
this.$.journal.colorize(preferences.getColor());
August 28, 2016 16:21
520
}
December 17, 2022 22:00
521
if (this.isJournalFull && l10n.get("JournalAlmostFull")) {
522
humane.log(l10n.get("JournalAlmostFull"));
523
this.isJournalFull = false;
525
},
527
// Initialize information for tutorial
528
beforeHelp: function() {
529
tutorial.setElement("owner", app.$.owner.getAttribute("id"));
530
tutorial.setElement("journal", app.$.journal.getAttribute("id"));
531
if (this.tutorialActivity) {
532
tutorial.setElement("activity", this.tutorialActivity.getAttribute("id"));
533
}
534
},
535
536
// Run activity
537
runMatchingActivity: function(icon) {
538
if (!icon.getDisabled() && !this.getPopup().showing){
539
this.hideActivityPopup(icon);
540
util.vibrate();
541
this.runActivity(icon.icon);
August 28, 2016 16:21
542
}
543
},
544
runActivity: function(activity) {
545
// Run the last activity instance in the context
546
util.vibrate();
547
var help = activity.id == tutorial.activityId;
548
preferences.runActivity(activity, undefined, null, null, help);
April 9, 2019 16:03
549
this.postRunActivity(activity.isNative);
550
},
551
runOldActivity: function(activity, instance) {
552
// Run an old activity instance
January 24, 2017 22:42
553
this.getPopup().hidePopup()
554
util.vibrate();
555
var help = tutorial.isLaunched() && activity.id == tutorial.activityId;
556
preferences.runActivity(activity, instance.objectId, instance.metadata.title, null, help);
558
runNewActivity: function(activity) {
559
// Start a new activity instance
January 24, 2017 22:42
560
this.getPopup().hidePopup()
561
util.vibrate();
562
var help = tutorial.isLaunched() && activity.id == tutorial.activityId;
563
preferences.runActivity(activity, null, null, null, help);
April 9, 2019 16:03
564
this.postRunActivity(activity.isNative);
April 9, 2019 16:03
566
postRunActivity: function(isNative) {
567
// When run a native activity, should update journal and view to reflect journal change
April 9, 2019 16:03
568
if (window.sugarizerOS && isNative) {
August 28, 2016 16:21
569
sugarizerOS.popupTimer = new Date();
570
this.loadJournal();
June 22, 2021 22:00
571
activities.loadEntries();
572
this.draw();
August 28, 2016 16:21
573
}
576
// Display journal
577
showJournal: function() {
578
this.showView(constant.journalView);
579
},
January 2, 2014 18:23
581
// Popup menu for activities handling
582
showActivityPopup: function(icon) {
583
// Create popup
August 28, 2016 16:21
584
if (window.sugarizerOS) {
585
var now = new Date();
586
if (sugarizerOS.popupTimer && now.getTime() - sugarizerOS.popupTimer.getTime() < 3000) {
August 28, 2016 16:21
587
return;
588
}
589
sugarizerOS.popupTimer = now;
590
}
591
var title;
592
var activity = icon.icon; // HACK: activity is stored as an icon
593
if (activity.instances !== undefined && activity.instances.length > 0 && activity.instances[0].metadata.title !== undefined) {
594
title = activity.instances[0].metadata.title;
595
} else {
596
title = l10n.get('NameActivity', {name: activity.name});
597
}
November 1, 2014 22:29
598
this.getPopup().setHeader({
599
icon: activity,
600
colorized: activity.instances !== undefined && activity.instances.length > 0,
601
colorizedColor: (activity.instances !== undefined && activity.instances.length > 0 && activity.instances[0].metadata.buddy_color) ? activity.instances[0].metadata.buddy_color : null,
602
name: activity.name,
603
title: title,
604
action: enyo.bind(this, "runActivity"),
605
data: [activity, null]
606
});
607
var items = [];
608
if (activity.instances) {
609
for(var i = 0 ; i < activity.instances.length && i < constant.maxPopupHistory; i++) {
610
items.push({
611
icon: activity,
612
colorized: true,
613
colorizedColor: (activity.instances[i].metadata.buddy_color ? activity.instances[i].metadata.buddy_color : null),
614
name: activity.instances[i].metadata.title,
615
action: enyo.bind(this, "runOldActivity"),
616
data: [activity, activity.instances[i]]
617
});
618
}
August 28, 2016 16:21
620
this.getPopup().setItems(items);
621
this.getPopup().setFooter([{
622
icon: activity,
623
colorized: false,
624
name: l10n.get("StartNew"),
625
action: enyo.bind(this, "runNewActivity"),
626
data: [activity, null]
627
}]);
629
// Show popup
November 1, 2014 22:29
630
this.getPopup().showPopup();
631
},
632
hideActivityPopup: function(icon) {
633
// Hide popup
634
if (this.getPopup().cursorIsInside() || icon.cursorIsInside()) {
635
return false;
636
}
November 1, 2014 22:29
637
this.getPopup().hidePopup();
638
return true;
January 2, 2014 18:23
639
},
January 2, 2014 18:23
641
// Popup menu for buddy handling
642
showBuddyPopup: function(icon) {
643
// Create popup
November 1, 2014 22:29
644
this.getPopup().setHeader({
645
icon: icon.icon,
January 2, 2014 18:23
646
colorized: true,
647
name: preferences.getName(),
648
title: null,
649
action: enyo.bind(this, "doSettings")
January 2, 2014 18:23
650
});
651
this.getPopup().setItems(null);
January 2, 2014 18:23
652
var items = [];
653
items.push({
654
icon: {directory: "icons", icon: "preferences-system.svg"},
January 2, 2014 18:23
655
colorized: false,
656
name: l10n.get("MySettings"),
657
action: enyo.bind(this, "doSettings"),
January 2, 2014 18:23
658
data: null
659
});
660
items.push({
661
icon: {directory: "icons", icon: "system-shutdown.svg"},
January 2, 2014 18:23
662
colorized: false,
663
name: l10n.get("Logoff"),
664
action: enyo.bind(this, "doLogoff"),
January 2, 2014 18:23
665
data: null
666
});
667
if (util.platform.electron || constant.noServerMode) {
668
items.push({
669
icon: {directory: "lib/sugar-web/graphics/icons/actions", icon: "activity-stop.svg"},
670
colorized: false,
671
name: l10n.get("Quit"),
672
action: enyo.bind(this, "doQuit"),
673
data: null
674
});
675
}
November 1, 2014 22:29
676
this.getPopup().setFooter(items);
January 2, 2014 18:23
678
// Show popup
679
this.getPopup().showPopup();
January 2, 2014 18:23
680
},
681
hideBuddyPopup: function(icon) {
682
if (this.getPopup().cursorIsInside() || icon.cursorIsInside()) {
683
return false;
684
}
November 1, 2014 22:29
685
this.getPopup().hidePopup();
686
return true;
January 2, 2014 18:23
687
},
October 3, 2017 22:40
688
doLogoff: function() {
689
stats.trace(constant.viewNames[this.getView()], 'click', 'logoff');
November 1, 2014 22:29
690
this.getPopup().hidePopup();
691
if (!preferences.isConnected() || (preferences.isConnected() && !preferences.getOptions("sync"))) {
692
this.otherview = this.$.otherview.createComponent({kind: "Sugar.DialogWarningMessage"}, {owner:this});
693
this.otherview.show();
694
} else {
695
util.cleanDatastore(null, function() {
696
util.restartApp();
697
});
January 2, 2014 18:23
699
},
700
doQuit: function() {
701
stats.trace(constant.viewNames[this.getView()], 'click', 'quit');
702
util.quitApp();
January 2, 2014 18:23
703
},
704
doSettings: function() {
August 19, 2017 22:18
705
stats.trace(constant.viewNames[this.getView()], 'click', 'my_settings');
November 1, 2014 22:29
706
this.getPopup().hidePopup();
August 11, 2014 07:59
707
this.otherview = this.$.otherview.createComponent({kind: "Sugar.DialogSettings"}, {owner:this});
January 17, 2014 21:05
708
this.otherview.show();
January 3, 2014 11:50
709
},
August 28, 2016 16:21
710
doResetLauncher: function() {
711
this.otherview = this.$.otherview.createComponent({kind: "Sugar.DialogSetLauncher"}, {owner:this});
712
this.otherview.show();
713
},
January 3, 2014 11:50
715
// Filter activities handling
January 4, 2014 22:33
716
filterActivities: function() {
717
var filter = toolbar.getSearchText().toLowerCase();
October 26, 2021 22:14
719
// EE mode pong
720
var currentcolor = preferences.getColor();
721
if (this.currentView == constant.radialView && currentcolor.stroke == "#00A0FF" && currentcolor.fill == "#F8E800" && toolbar.getSearchText() == "Launch Sugarizer Pong!") {
722
this.eeMode = new Sugar.EE({mode: 4});
723
this.eeMode.startPong(this);
724
return;
725
}
726
if (this.eeMode) {
727
this.eeMode.stopPong();
728
this.draw();
729
}
730
January 4, 2014 22:33
731
// In radial view, just disable activities
January 3, 2014 11:50
732
enyo.forEach(this.$.desktop.getControls(), function(item) {
733
item.setDisabled(item.icon.name.toLowerCase().indexOf(filter) == -1 && filter.length != 0);
January 3, 2014 11:50
734
});
January 4, 2014 22:33
736
// In list view display only matching activities
737
if (this.currentView == constant.listView) {
October 26, 2021 22:28
738
this.otherview.setActivities(activities.getByName(filter));
January 4, 2014 22:33
739
}
741
});
742
743
744
745
746
747
// Class for desktop toolbar
748
enyo.kind({
August 11, 2014 07:59
749
name: "Sugar.DesktopToolbar",
750
kind: enyo.Control,
751
components: [
752
{name: "searchtext", kind: "Sugar.SearchField", classes: "homeview-filter-text", onTextChanged: "filterActivities"},
April 30, 2017 21:20
753
{name: "helpbutton", kind: "Button", classes: "toolbutton help-button", title:"Help", ontap: "startTutorial"},
February 4, 2018 10:00
754
{name: "syncbutton", classes: "sync-button sync-home sync-gear sync-gear-home", showing: false},
755
{name: "offlinebutton", kind: "Button", classes: "toolbutton offline-button", title:"Not connected", ontap: "doServerSettings", showing: false},
756
{name: "showAssignments", kind: "Sugar.Icon", showing:false, x: 0, y: 5, size: constant.iconSizeList, classes: "assignment-button", icon: {directory: "icons", icon: "assignment.svg"}, title:"Assignments", colorized:true, ontap:"showJournal",},
757
{name: "assignmentCount", tag:"p", classes: " assignment-count ", title:"count",},
August 11, 2014 07:59
758
{name: "radialbutton", kind: "Button", classes: "toolbutton view-radial-button active", title:"Home", ontap: "showRadialView"},
November 1, 2014 22:29
759
{name: "neighborbutton", kind: "Button", classes: "toolbutton view-neighbor-button", title:"Home", ontap: "showNeighborView"},
August 11, 2014 07:59
760
{name: "listbutton", kind: "Button", classes: "toolbutton view-list-button", title:"List", ontap: "showListView"}
763
// Constructor
764
create: function() {
765
this.inherited(arguments);
766
this.needRedraw = false;
January 18, 2014 18:35
768
rendered: function() {
769
this.inherited(arguments);
770
this.localize();
771
},
772
773
localize: function() {
774
// Localize items
775
this.$.searchtext.setPlaceholder(l10n.get("SearchHome"));
January 18, 2014 18:35
776
this.$.radialbutton.setNodeProperty("title", l10n.get("FavoritesView"));
777
this.$.listbutton.setNodeProperty("title", l10n.get("ListView"));
778
this.$.neighborbutton.setNodeProperty("title", l10n.get("NeighborhoodView"));
April 30, 2017 21:20
779
this.$.helpbutton.setNodeProperty("title", l10n.get("Tutorial"));
780
this.$.offlinebutton.setNodeProperty("title", l10n.get("NotConnected"));
November 11, 2018 22:25
781
if (app.localize) {
782
app.localize();
783
}
January 18, 2014 18:35
784
},
786
askRedraw: function() {
787
this.needRedraw = true;
788
},
789
790
// Handle search text content
791
getSearchText: function() {
792
return this.$.searchtext.getText();
793
},
795
setSearchText: function(value) {
796
this.$.searchtext.setText(value);
797
},
798
// Display journal
799
showJournal: function() {
800
//open journal view
801
app.showView(constant.assignmentView);
803
// Handle active button
804
setActiveView: function(view) {
805
if (view == constant.radialView) {
806
this.$.radialbutton.addRemoveClass('active', true);
November 1, 2014 22:29
807
this.$.neighborbutton.addRemoveClass('active', false);
808
this.$.listbutton.addRemoveClass('active', false);
809
} else if (view == constant.listView) {
810
this.$.radialbutton.addRemoveClass('active', false);
November 1, 2014 22:29
811
this.$.neighborbutton.addRemoveClass('active', false);
812
this.$.listbutton.addRemoveClass('active', true);
November 1, 2014 22:29
813
} else if (view == constant.neighborhoodView) {
814
this.$.radialbutton.addRemoveClass('active', false);
815
this.$.neighborbutton.addRemoveClass('active', true);
816
this.$.listbutton.addRemoveClass('active', false);
817
}
818
},
820
// Handle events
821
filterActivities: function() {
822
stats.trace(constant.viewNames[app.getView()], 'search', 'q='+this.getSearchText(), null);
823
app.filterActivities();
824
},
826
showRadialView: function() {
827
util.vibrate();
828
app.showView(constant.radialView);
829
if (this.needRedraw) {
830
this.needRedraw = false;
831
app.redraw();
832
}
835
showListView: function() {
836
util.vibrate();
837
app.showView(constant.listView);
838
if (this.needRedraw) {
839
this.needRedraw = false;
840
app.redraw();
841
}
November 1, 2014 22:29
842
},
843
844
showNeighborView: function() {
845
util.vibrate();
November 1, 2014 22:29
846
app.showView(constant.neighborhoodView);
847
if (this.needRedraw) {
848
this.needRedraw = false;
849
app.redraw();
850
}
April 30, 2017 21:20
851
},
852
January 14, 2018 12:06
853
showSync: function(showing) {
854
this.$.syncbutton.setShowing(showing);
855
},
856
857
showServerWarning: function(showing) {
858
this.$.offlinebutton.setShowing(showing);
859
},
860
December 17, 2022 22:00
861
showAssignments: function(number) {
862
if(app.getView() != constant.listView && number > 0){
863
this.$.showAssignments.setShowing(true);
864
this.$.assignmentCount.setContent(number);
865
} else {
866
this.$.showAssignments.setShowing(false);
867
this.$.assignmentCount.setContent("");
868
}
869
},
870
871
doServerSettings: function() {
872
if (preferences.isConnected()) {
873
var token = preferences.getToken();
874
if (token && !token.expired) {
875
// No need to show settings, connection issue, just try to reconnect
876
var that = app;
877
app.connectToServer(function(success) {
878
if (that.getToolbar() && that.getToolbar().showServerWarning) {
879
that.getToolbar().showServerWarning(!success);
880
}
881
});
882
return;
883
}
884
}
885
var otherview = app.$.otherview.createComponent({kind: "Sugar.DialogServer", standalone: true}, {owner:this});
886
otherview.show();
887
},
888
April 30, 2017 21:20
889
startTutorial: function() {
890
tutorial.setElement("radialbutton", this.$.radialbutton.getAttribute("id"));
891
tutorial.setElement("listbutton", this.$.listbutton.getAttribute("id"));
892
tutorial.setElement("neighborbutton", this.$.neighborbutton.getAttribute("id"));
893
tutorial.setElement("searchtext", this.$.searchtext.getAttribute("id"));
894
tutorial.setElement("showAssignments", this.$.showAssignments.getAttribute("id"));
895
tutorial.setElement("offlinebutton", this.$.offlinebutton.getAttribute("id"));
896
if (app.otherview && app.otherview.beforeHelp) {
897
app.otherview.beforeHelp();
898
} else {
899
app.beforeHelp();
900
}
August 19, 2017 22:18
901
stats.trace(constant.viewNames[app.getView()], 'tutorial', 'start', null);
April 30, 2017 21:20
902
tutorial.start();
November 1, 2014 22:29
903
}
904
});