|
|
|
@ -14,14 +14,43 @@ Ext.define('Rambox.ux.Firebase', {
|
|
|
|
|
|
|
|
|
|
// Attach an asynchronous callback to read the data at our posts reference
|
|
|
|
|
ref.on("child_changed", function(snapshot, prevChildKey) { |
|
|
|
|
// Disable duplicate actions when user edit a service
|
|
|
|
|
var rec = Ext.getStore('Services').findRecord('firebase_key', snapshot.key); |
|
|
|
|
var recData = Ext.clone(rec.data); |
|
|
|
|
delete recData.id; |
|
|
|
|
delete recData.firebase_key; |
|
|
|
|
if ( Ext.Object.equals(recData, snapshot.val()) ) return; |
|
|
|
|
|
|
|
|
|
console.info('Firebase - Child Changed', snapshot.val(), snapshot.key, prevChildKey); |
|
|
|
|
|
|
|
|
|
// Suspend events
|
|
|
|
|
Ext.getStore('Services').suspendEvent('update'); |
|
|
|
|
var rec = Ext.getStore('Services').findRecord('firebase_key', snapshot.key); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Change the title of the Tab
|
|
|
|
|
Ext.getCmp('tab_'+rec.get('id')).setTitle(snapshot.val().name); |
|
|
|
|
|
|
|
|
|
// Change sound of the Tab
|
|
|
|
|
Ext.getCmp('tab_'+rec.get('id')).setAudioMuted(snapshot.val().muted); |
|
|
|
|
// Change notifications of the Tab
|
|
|
|
|
Ext.getCmp('tab_'+rec.get('id')).setNotifications(snapshot.val().notifications); |
|
|
|
|
// Change the icon of the Tab
|
|
|
|
|
if ( rec.get('type') === 'custom' && rec.get('logo') !== snapshot.val().logo ) Ext.getCmp('tab_'+rec.get('id')).setConfig('icon', snapshot.val().logo === '' ? 'resources/icons/custom.png' : snapshot.val().logo); |
|
|
|
|
// Change the URL of the Tab
|
|
|
|
|
if ( rec.get('url') !== snapshot.val().url ) Ext.getCmp('tab_'+rec.get('id')).setURL(snapshot.val().url); |
|
|
|
|
|
|
|
|
|
// Change the align of the Tab
|
|
|
|
|
if ( rec.get('align') !== snapshot.val().align ) { |
|
|
|
|
if ( rec.get('align') === 'left' ) { |
|
|
|
|
Ext.cq1('app-main').moveBefore(Ext.getCmp('tab_'+rec.get('id')), Ext.getCmp('tbfill')); |
|
|
|
|
} else { |
|
|
|
|
Ext.cq1('app-main').moveAfter(Ext.getCmp('tab_'+rec.get('id')), Ext.getCmp('tbfill')); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Apply the JS Code of the Tab
|
|
|
|
|
if ( rec.get('js_unread') !== snapshot.val().js_unread ) { |
|
|
|
|
Ext.Msg.confirm('CUSTOM CODE', 'Rambox needs to reload the service to execute the new JavaScript code. Do you want to do it now?', function( btnId ) { |
|
|
|
|
if ( btnId === 'yes' ) Ext.getCmp('tab_'+rec.get('id')).reloadService(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
// Position
|
|
|
|
|
if ( rec.get('position') !== snapshot.val().position ) { |
|
|
|
|
var pos = parseInt(snapshot.val().position); |
|
|
|
@ -29,11 +58,14 @@ Ext.define('Rambox.ux.Firebase', {
|
|
|
|
|
Ext.cq1('app-main').move(Ext.getCmp('tab_'+rec.get('id')), pos); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Enable/Disable
|
|
|
|
|
if ( rec.get('enable') !== snapshot.val().enable ) Ext.getCmp('tab_'+rec.get('id')).setEnabled(snapshot.val().enabled); |
|
|
|
|
|
|
|
|
|
rec.set(snapshot.val()); |
|
|
|
|
rec.save(); |
|
|
|
|
Ext.getCmp('tab_'+rec.get('id')).record = rec; |
|
|
|
|
Ext.getCmp('tab_'+rec.get('id')).tabConfig.service = rec; |
|
|
|
|
|
|
|
|
|
// Enable/Disable
|
|
|
|
|
if ( recData.enabled !== snapshot.val().enabled ) Ext.getCmp('tab_'+rec.get('id')).setEnabled(snapshot.val().enabled); |
|
|
|
|
|
|
|
|
|
Ext.getStore('Services').resumeEvent('update'); |
|
|
|
|
Ext.getStore('Services').load(); |
|
|
|
|
}, function (errorObject) { |
|
|
|
|