From 75b44c9f5f19ec9403c08550d44013c3c23a3d2e Mon Sep 17 00:00:00 2001
From: RaNaN <Mast3rRaNaN@hotmail.de>
Date: Sat, 20 Jul 2013 13:53:19 +0200
Subject: small fixes

---
 pyload/web/app/scripts/collections/FileList.js          | 10 ++++++++++
 pyload/web/app/scripts/views/dashboard/dashboardView.js | 14 +++++++++-----
 pyload/web/app/scripts/views/dashboard/filterView.js    |  1 +
 3 files changed, 20 insertions(+), 5 deletions(-)

(limited to 'pyload/web/app/scripts')

diff --git a/pyload/web/app/scripts/collections/FileList.js b/pyload/web/app/scripts/collections/FileList.js
index 873f4c0e3..112dc5e51 100644
--- a/pyload/web/app/scripts/collections/FileList.js
+++ b/pyload/web/app/scripts/collections/FileList.js
@@ -9,6 +9,16 @@ define(['jquery', 'backbone', 'underscore', 'models/File'], function($, Backbone
             return file.get('fileorder');
         },
 
+        isEqual: function(fileList) {
+            if (this.length !== fileList.length) return false;
+
+            // Assuming same order would be faster in false case
+            var diff = _.difference(this.models, fileList.models);
+
+            // If there is a difference models are unequal
+            return diff.length > 0;
+        },
+
         initialize: function() {
 
         }
diff --git a/pyload/web/app/scripts/views/dashboard/dashboardView.js b/pyload/web/app/scripts/views/dashboard/dashboardView.js
index a7779230b..8a0446203 100644
--- a/pyload/web/app/scripts/views/dashboard/dashboardView.js
+++ b/pyload/web/app/scripts/views/dashboard/dashboardView.js
@@ -1,6 +1,6 @@
-define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection',
+define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', 'collections/FileList',
     './packageView', './fileView', 'hbs!tpl/dashboard/layout', 'select2'],
-    function($, Backbone, _, App, TreeCollection, PackageView, FileView, template) {
+    function($, Backbone, _, App, TreeCollection, FileList, PackageView, FileView, template) {
         'use strict';
         // Renders whole dashboard
         return Backbone.Marionette.ItemView.extend({
@@ -159,10 +159,14 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection',
                 // this works with ids and object TODO: not anymore
                 var file = this.files.get(fid);
                 if (file)
-                    if (_.isObject(data)) // update directly
+                    if (_.isObject(data)) { // update directly
                         file.set(data);
-                    else // fetch from server
-                        file.fetch();
+                        App.vent.trigger('dashboard:updated');
+                    } else { // fetch from server
+                        file.fetch({success: function() {
+                            App.vent.trigger('dashboard:updated');
+                        }});
+                    }
             }
         });
     });
\ No newline at end of file
diff --git a/pyload/web/app/scripts/views/dashboard/filterView.js b/pyload/web/app/scripts/views/dashboard/filterView.js
index 79257547c..ad72cf926 100644
--- a/pyload/web/app/scripts/views/dashboard/filterView.js
+++ b/pyload/web/app/scripts/views/dashboard/filterView.js
@@ -38,6 +38,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'models/Pac
 
                 // Apply the filter before the content is shown
                 this.listenTo(App.vent, 'dashboard:contentReady', this.apply_filter);
+                this.listenTo(App.vent, 'dashboard:updated', this.apply_filter);
                 this.listenTo(App.vent, 'dashboard:updated', this.updateName);
             },
 
-- 
cgit v1.2.3