Browse Source

Improved Firebase synchronization and fixed bugs on service changed in second PC

pull/367/head
Ramiro Saenz 9 years ago
parent
commit
7fe39ba6fe
  1. 44
      app/ux/Firebase.js
  2. 8
      app/ux/WebView.js

44
app/ux/Firebase.js

@ -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) {

8
app/ux/WebView.js

@ -129,11 +129,13 @@ Ext.define('Rambox.ux.WebView',{
me.callParent(config);
}
,webViewConstructor: function() {
,webViewConstructor: function( enabled ) {
var me = this;
var cfg;
if ( !me.record.get('enabled') ) {
enabled = enabled || me.record.get('enabled');
if ( !enabled ) {
cfg = {
xtype: 'container'
,html: '<h3>Service Disabled</h3>'
@ -362,7 +364,7 @@ Ext.define('Rambox.ux.WebView',{
me.tab.setBadgeText('');
me.removeAll();
me.add(me.webViewConstructor());
me.add(me.webViewConstructor(enabled));
if ( enabled ) {
me.resumeEvent('afterrender');
me.show();

Loading…
Cancel
Save