|
|
|
@ -50,7 +50,7 @@ Ext.define('Rambox.view.main.MainController', {
|
|
|
|
|
,items: [ |
|
|
|
|
{ |
|
|
|
|
xtype: 'checkbox' |
|
|
|
|
,boxLabel: 'Separate' |
|
|
|
|
,boxLabel: 'Align to Right' |
|
|
|
|
,checked: edit ? (record.get('align') === 'right' ? true : false) : false |
|
|
|
|
,name: 'align' |
|
|
|
|
,uncheckedValue: 'left' |
|
|
|
@ -90,6 +90,8 @@ Ext.define('Rambox.view.main.MainController', {
|
|
|
|
|
text: edit ? 'Save' : 'Add service' |
|
|
|
|
,itemId: 'submit' |
|
|
|
|
,handler: function() { |
|
|
|
|
if ( !win.down('form').isValid() ) return false; |
|
|
|
|
|
|
|
|
|
var formValues = win.down('form').getValues(); |
|
|
|
|
|
|
|
|
|
if ( edit ) { |
|
|
|
@ -184,6 +186,9 @@ Ext.define('Rambox.view.main.MainController', {
|
|
|
|
|
,fieldLabel: record.get('name') + ' team' |
|
|
|
|
,name: 'url' |
|
|
|
|
,allowBlank: false |
|
|
|
|
,submitEmptyText: false |
|
|
|
|
,emptyText: record.get('url') === '___' ? 'http://' : '' |
|
|
|
|
,vtype: record.get('url') === '___' ? 'url' : '' |
|
|
|
|
,listeners: { |
|
|
|
|
specialkey: function(field, e) { |
|
|
|
|
if(e.getKey() == e.ENTER && field.up('form').isValid()) { |
|
|
|
@ -204,7 +209,7 @@ Ext.define('Rambox.view.main.MainController', {
|
|
|
|
|
,items: [ |
|
|
|
|
{ |
|
|
|
|
xtype: 'checkbox' |
|
|
|
|
,boxLabel: 'Separate' |
|
|
|
|
,boxLabel: 'Align to Right' |
|
|
|
|
,checked: false |
|
|
|
|
,name: 'align' |
|
|
|
|
,uncheckedValue: 'left' |
|
|
|
@ -244,6 +249,8 @@ Ext.define('Rambox.view.main.MainController', {
|
|
|
|
|
text: 'Add service' |
|
|
|
|
,itemId: 'submit' |
|
|
|
|
,handler: function() { |
|
|
|
|
if ( !win.down('form').isValid() ) return false; |
|
|
|
|
|
|
|
|
|
var formValues = win.down('form').getValues(); |
|
|
|
|
|
|
|
|
|
var service = Ext.create('Rambox.model.Service', { |
|
|
|
@ -299,13 +306,11 @@ Ext.define('Rambox.view.main.MainController', {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
,removeService: function( gridView, rowIndex, colIndex, col, e, rec, rowEl ) { |
|
|
|
|
Ext.Msg.confirm('Please confirm...', 'Are you sure you want to remove <b>'+rec.get('name')+'</b>?', function(btnId) { |
|
|
|
|
if ( btnId === 'yes' ) { |
|
|
|
|
var tab = Ext.getCmp('tab_'+rec.get('id')); |
|
|
|
|
,removeServiceFn: function(serviceId) { |
|
|
|
|
if ( !serviceId ) return false; |
|
|
|
|
|
|
|
|
|
// Remove record from localStorage
|
|
|
|
|
gridView.getStore().remove(rec); |
|
|
|
|
// Get Tab
|
|
|
|
|
var tab = Ext.getCmp('tab_'+serviceId); |
|
|
|
|
|
|
|
|
|
// Clear all trash data
|
|
|
|
|
tab.down('component').el.dom.getWebContents().session.clearCache(Ext.emptyFn); |
|
|
|
@ -313,8 +318,40 @@ Ext.define('Rambox.view.main.MainController', {
|
|
|
|
|
|
|
|
|
|
// Close tab
|
|
|
|
|
tab.close(); |
|
|
|
|
|
|
|
|
|
// Remove record from localStorage
|
|
|
|
|
Ext.getStore('Services').remove(Ext.getStore('Services').getById(serviceId)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
,removeService: function( gridView, rowIndex, colIndex, col, e, rec, rowEl ) { |
|
|
|
|
var me = this; |
|
|
|
|
|
|
|
|
|
Ext.Msg.confirm('Please confirm...', 'Are you sure you want to remove <b>'+rec.get('name')+'</b>?', function(btnId) { |
|
|
|
|
if ( btnId === 'yes' ) me.removeServiceFn(rec.get('id')); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
,removeAllServices: function(btn, callback) { |
|
|
|
|
var me = this; |
|
|
|
|
|
|
|
|
|
// Clear counter for unread messaging
|
|
|
|
|
document.title = 'Rambox'; |
|
|
|
|
|
|
|
|
|
if ( btn ) { |
|
|
|
|
Ext.Msg.confirm('Please confirm...', 'Are you sure you want to remove all services?', function(btnId) { |
|
|
|
|
if ( btnId === 'yes' ) { |
|
|
|
|
Ext.Array.each(Ext.getStore('Services').collect('id'), function(serviceId) { |
|
|
|
|
me.removeServiceFn(serviceId); |
|
|
|
|
}); |
|
|
|
|
if ( Ext.isFunction(callback) ) callback(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
Ext.Array.each(Ext.getStore('Services').collect('id'), function(serviceId) { |
|
|
|
|
me.removeServiceFn(serviceId); |
|
|
|
|
}); |
|
|
|
|
if ( Ext.isFunction(callback) ) callback(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
,configureService: function( gridView, rowIndex, colIndex, col, e, rec, rowEl ) { |
|
|
|
@ -385,7 +422,7 @@ Ext.define('Rambox.view.main.MainController', {
|
|
|
|
|
,items: [ |
|
|
|
|
{ |
|
|
|
|
xtype: 'checkbox' |
|
|
|
|
,boxLabel: 'Separate' |
|
|
|
|
,boxLabel: 'Align to Right' |
|
|
|
|
,checked: false |
|
|
|
|
,name: 'align' |
|
|
|
|
,uncheckedValue: 'left' |
|
|
|
@ -443,6 +480,8 @@ Ext.define('Rambox.view.main.MainController', {
|
|
|
|
|
text: 'Add service' |
|
|
|
|
,itemId: 'submit' |
|
|
|
|
,handler: function() { |
|
|
|
|
if ( !win.down('form').isValid() ) return false; |
|
|
|
|
|
|
|
|
|
var formValues = win.down('form').getValues(); |
|
|
|
|
|
|
|
|
|
var service = Ext.create('Rambox.model.Service', { |
|
|
|
@ -547,4 +586,202 @@ Ext.define('Rambox.view.main.MainController', {
|
|
|
|
|
Ext.getStore('ServicesList').getFilters().removeAll(); |
|
|
|
|
me.doTypeFilter(cg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
,dontDisturb: function(btn) { |
|
|
|
|
console.info('Dont Disturb:', btn.pressed ? 'Enabled' : 'Disabled'); |
|
|
|
|
Ext.Array.each(Ext.getStore('Services').collect('id'), function(serviceId) { |
|
|
|
|
// Get Tab
|
|
|
|
|
var tab = Ext.getCmp('tab_'+serviceId); |
|
|
|
|
|
|
|
|
|
// Mute sounds
|
|
|
|
|
tab.down('component').el.dom.getWebContents().setAudioMuted(btn.pressed); |
|
|
|
|
|
|
|
|
|
// Prevent Notifications
|
|
|
|
|
if ( btn.pressed ) { |
|
|
|
|
tab.down('component').el.dom.getWebContents().executeJavaScript('var originalNotification = Notification; (function() { Notification = function() { } })();'); |
|
|
|
|
} else { |
|
|
|
|
tab.down('component').el.dom.getWebContents().executeJavaScript('(function() { Notification = originalNotification })();'); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
btn.setText('Don\'t Disturb: ' + ( btn.pressed ? 'ON' : 'OFF' )); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
,lockRambox: function(btn) { |
|
|
|
|
var me = this; |
|
|
|
|
|
|
|
|
|
var msgbox = Ext.Msg.prompt('Lock Rambox', 'Enter a temporal password to unlock it later', function(btnId, text) { |
|
|
|
|
if ( btnId === 'ok' ) { |
|
|
|
|
me.lookupReference('disturbBtn').setPressed(true); |
|
|
|
|
me.dontDisturb(me.lookupReference('disturbBtn')); |
|
|
|
|
var winLock = Ext.create('Ext.window.Window', { |
|
|
|
|
width: '100%' |
|
|
|
|
,height: '100%' |
|
|
|
|
,closable: false |
|
|
|
|
,minimizable: false |
|
|
|
|
,maximizable: false |
|
|
|
|
,draggable: false |
|
|
|
|
,onEsc: Ext.emptyFn |
|
|
|
|
,layout: 'center' |
|
|
|
|
,bodyStyle: 'background-color:#2e658e;' |
|
|
|
|
,items: [ |
|
|
|
|
{ |
|
|
|
|
xtype: 'container' |
|
|
|
|
,layout: 'vbox' |
|
|
|
|
,items: [ |
|
|
|
|
{ |
|
|
|
|
xtype: 'image' |
|
|
|
|
,src: 'resources/Icon.png' |
|
|
|
|
,width: 256 |
|
|
|
|
,height: 256 |
|
|
|
|
} |
|
|
|
|
,{ |
|
|
|
|
xtype: 'component' |
|
|
|
|
,autoEl: { |
|
|
|
|
tag: 'h1' |
|
|
|
|
,html: 'Rambox is locked' |
|
|
|
|
,style: 'text-align:center;width:256px;' |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
,{ |
|
|
|
|
xtype: 'textfield' |
|
|
|
|
,inputType: 'password' |
|
|
|
|
,width: 256 |
|
|
|
|
} |
|
|
|
|
,{ |
|
|
|
|
xtype: 'button' |
|
|
|
|
,text: 'UNLOCK' |
|
|
|
|
,glyph: 'xf13e@FontAwesome' |
|
|
|
|
,width: 256 |
|
|
|
|
,scale: 'large' |
|
|
|
|
,handler: function() { |
|
|
|
|
if ( text === winLock.down('textfield').getValue() ) { |
|
|
|
|
winLock.close(); |
|
|
|
|
me.lookupReference('disturbBtn').setPressed(false); |
|
|
|
|
me.dontDisturb(me.lookupReference('disturbBtn')); |
|
|
|
|
} else { |
|
|
|
|
winLock.down('textfield').markInvalid('Unlock password is invalid'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}).show(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
msgbox.textField.inputEl.dom.type = 'password'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
,login: function(btn) { |
|
|
|
|
var me = this; |
|
|
|
|
|
|
|
|
|
lock.show({ |
|
|
|
|
icon: 'resources/Icon.png' |
|
|
|
|
}, function(err, profile, id_token) { |
|
|
|
|
// There was an error logging the user in
|
|
|
|
|
if (err) return console.error(err); |
|
|
|
|
|
|
|
|
|
// Display a spinner while waiting
|
|
|
|
|
Ext.Msg.wait('Please wait until we get your configuration.', 'Connecting...'); |
|
|
|
|
|
|
|
|
|
// Set the options to retreive a firebase delegation token
|
|
|
|
|
var options = { |
|
|
|
|
id_token : id_token, |
|
|
|
|
api : 'firebase', |
|
|
|
|
scope : 'openid name email displayName', |
|
|
|
|
target: 'y9am0DVawe2tvlA3ucD7OufpJHZZMjsO' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Make a call to the Auth0 '/delegate'
|
|
|
|
|
auth0.getDelegationToken(options, function(err, result) { |
|
|
|
|
if ( !err ) { |
|
|
|
|
// Exchange the delegate token for a Firebase auth token
|
|
|
|
|
firebase.auth().signInWithCustomToken(result.id_token).then(function(snapshot) { |
|
|
|
|
fireRef.database().ref('users/' + profile.user_id).once('value').then(function(snapshot) { |
|
|
|
|
me.removeAllServices(false, function() { |
|
|
|
|
if ( snapshot.val() === null || Ext.isEmpty(snapshot.val().services) ) return; |
|
|
|
|
|
|
|
|
|
Ext.each(snapshot.val().services, function(s) { |
|
|
|
|
var service = Ext.create('Rambox.model.Service', { |
|
|
|
|
id: s.id |
|
|
|
|
,position: s.position |
|
|
|
|
,type: s.type |
|
|
|
|
,logo: s.logo |
|
|
|
|
,name: s.name |
|
|
|
|
,url: s.url |
|
|
|
|
,align: s.align |
|
|
|
|
,notifications: s.notifications |
|
|
|
|
,muted: s.muted |
|
|
|
|
,js_unread: s.js_unread |
|
|
|
|
}); |
|
|
|
|
service.save(); |
|
|
|
|
Ext.getStore('Services').add(service); |
|
|
|
|
|
|
|
|
|
var tabData = { |
|
|
|
|
xtype: 'webview' |
|
|
|
|
,id: 'tab_'+service.get('id') |
|
|
|
|
,title: service.get('name') |
|
|
|
|
,icon: 'resources/icons/' + s.logo |
|
|
|
|
,src: service.get('url') |
|
|
|
|
,type: service.get('type') |
|
|
|
|
,align: s.align |
|
|
|
|
,notifications: s.notifications |
|
|
|
|
,muted: s.muted |
|
|
|
|
,record: service |
|
|
|
|
,tabConfig: { |
|
|
|
|
service: service |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if ( s.align === 'left' ) { |
|
|
|
|
var tbfill = Ext.cq1('app-main').getTabBar().down('tbfill'); |
|
|
|
|
Ext.cq1('app-main').insert(Ext.cq1('app-main').getTabBar().items.indexOf(tbfill), tabData); |
|
|
|
|
} else { |
|
|
|
|
Ext.cq1('app-main').add(tabData); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
Ext.Msg.hide(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}).catch(function(error) { |
|
|
|
|
console.error(error); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// User is logged in
|
|
|
|
|
// Save the profile and JWT.
|
|
|
|
|
localStorage.setItem('profile', JSON.stringify(profile)); |
|
|
|
|
localStorage.setItem('id_token', id_token); |
|
|
|
|
|
|
|
|
|
Ext.cq1('app-main').getViewModel().set('username', profile.name); |
|
|
|
|
Ext.cq1('app-main').getViewModel().set('avatar', profile.picture); |
|
|
|
|
}, function() { |
|
|
|
|
// Error callback
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
,logout: function(btn) { |
|
|
|
|
var me = this; |
|
|
|
|
|
|
|
|
|
Ext.Msg.confirm('Logout', 'Are you sure you want to logout?', function(btnId) { |
|
|
|
|
if ( btnId === 'yes' ) { |
|
|
|
|
localStorage.removeItem('profile'); |
|
|
|
|
localStorage.removeItem('id_token'); |
|
|
|
|
|
|
|
|
|
Ext.cq1('app-main').getViewModel().set('username', ''); |
|
|
|
|
Ext.cq1('app-main').getViewModel().set('avatar', ''); |
|
|
|
|
|
|
|
|
|
firebase.auth().signOut().then(function() { |
|
|
|
|
Ext.Array.each(Ext.getStore('Services').collect('id'), function(serviceId) { |
|
|
|
|
me.removeServiceFn(serviceId); |
|
|
|
|
}); |
|
|
|
|
}, function(error) { |
|
|
|
|
console.error(error); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|