2013-09-27 15:05:39 -04:00
|
|
|
/*global app, $, me*/
|
2013-09-26 23:19:46 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var HumanModel = require('human-model');
|
|
|
|
|
|
|
|
module.exports = HumanModel.define({
|
|
|
|
initialize: function () {
|
|
|
|
var self = this;
|
|
|
|
$(window).blur(function () {
|
|
|
|
self.focused = false;
|
|
|
|
});
|
|
|
|
$(window).focus(function () {
|
|
|
|
self.focused = true;
|
2013-09-27 15:05:39 -04:00
|
|
|
if (me._activeContact) {
|
|
|
|
me.setActiveContact(me._activeContact);
|
|
|
|
}
|
2013-09-26 23:19:46 -04:00
|
|
|
self.markActive();
|
|
|
|
});
|
2013-09-27 12:47:54 -04:00
|
|
|
|
2013-10-14 16:36:19 -04:00
|
|
|
app.desktop.on('sleep', function () {
|
|
|
|
clearTimeout(this.idleTimer);
|
|
|
|
console.log('went to sleep');
|
|
|
|
self.markInactive();
|
|
|
|
});
|
2013-10-11 18:40:42 -04:00
|
|
|
|
2014-01-07 01:01:17 -05:00
|
|
|
self.cacheStatus = app.cache.state;
|
|
|
|
app.cache.on('change', function (state) {
|
|
|
|
self.cacheStatus = state;
|
|
|
|
});
|
|
|
|
|
2014-01-23 14:11:56 -05:00
|
|
|
document.addEventListener('deviceid', function (event) {
|
|
|
|
self.deviceID = event.deviceid;
|
|
|
|
});
|
|
|
|
|
2013-09-26 23:19:46 -04:00
|
|
|
this.markActive();
|
|
|
|
},
|
|
|
|
session: {
|
2014-01-05 07:19:46 -05:00
|
|
|
focused: ['bool', false, true],
|
|
|
|
active: ['bool', false, false],
|
|
|
|
connected: ['bool', false, false],
|
|
|
|
hasConnected: ['bool', false, false],
|
|
|
|
idleTimeout: ['number', false, 600000],
|
2013-09-27 12:47:54 -04:00
|
|
|
idleSince: 'date',
|
2014-01-05 07:19:46 -05:00
|
|
|
allowAlerts: ['bool', false, false],
|
|
|
|
badge: 'string',
|
|
|
|
pageTitle: 'string',
|
2014-01-07 01:01:17 -05:00
|
|
|
hasActiveCall: ['boolean', false, false],
|
2014-01-23 14:11:56 -05:00
|
|
|
cacheStatus: 'string',
|
2015-02-23 12:24:16 -05:00
|
|
|
deviceID: ['string', false, ''],
|
|
|
|
pageChanged: ['string', false, '']
|
2013-09-27 12:47:54 -04:00
|
|
|
},
|
|
|
|
derived: {
|
|
|
|
title: {
|
|
|
|
deps: ['pageTitle', 'badge'],
|
|
|
|
fn: function () {
|
2015-04-07 10:12:28 -04:00
|
|
|
var base = this.pageTitle ? 'Kaiwa - ' + this.pageTitle : 'Kaiwa';
|
2013-09-27 12:47:54 -04:00
|
|
|
if (this.badge) {
|
|
|
|
return this.badge + ' • ' + base;
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
}
|
2014-01-23 14:11:56 -05:00
|
|
|
},
|
|
|
|
deviceIDReady: {
|
|
|
|
deps: ['connected', 'deviceID'],
|
|
|
|
fn: function () {
|
2014-01-27 17:43:28 -05:00
|
|
|
return (this.connected && !!this.deviceID);
|
2014-01-23 14:11:56 -05:00
|
|
|
}
|
2015-02-23 12:24:16 -05:00
|
|
|
},
|
|
|
|
currentPageIsSettings: {
|
|
|
|
deps: ['pageChanged'],
|
|
|
|
fn: function () {
|
|
|
|
return this.pageChanged === 'settings' ? 'active' : '';
|
|
|
|
}
|
2013-09-27 12:47:54 -04:00
|
|
|
}
|
2013-09-26 23:19:46 -04:00
|
|
|
},
|
|
|
|
markActive: function () {
|
|
|
|
clearTimeout(this.idleTimer);
|
|
|
|
|
|
|
|
var wasInactive = !this.active;
|
|
|
|
this.active = true;
|
|
|
|
this.idleSince = new Date(Date.now());
|
|
|
|
|
|
|
|
this.idleTimer = setTimeout(this.markInactive.bind(this), this.idleTimeout);
|
|
|
|
},
|
|
|
|
markInactive: function () {
|
|
|
|
if (this.focused) {
|
|
|
|
return this.markActive();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.active = false;
|
|
|
|
this.idleSince = new Date(Date.now());
|
|
|
|
}
|
|
|
|
});
|