Module: deluge
Branch: master
Commit: 8414b9cfa951401d90f15eb4302130efd26c814c

Author: Damien Churchill <[email protected]>
Date:   Wed Apr 28 01:06:28 2010 +0100

fire only one event per check, pass an array of nodes
implement #1161 for the webui

---

 deluge/ui/web/js/deluge-all/add/FilesTab.js     |   12 +++-
 deluge/ui/web/js/deluge-all/add/OptionsPanel.js |   61 ++++++++++++-----------
 2 files changed, 40 insertions(+), 33 deletions(-)

diff --git a/deluge/ui/web/js/deluge-all/add/FilesTab.js 
b/deluge/ui/web/js/deluge-all/add/FilesTab.js
index 128ff3a..e1eccc0 100644
--- a/deluge/ui/web/js/deluge-all/add/FilesTab.js
+++ b/deluge/ui/web/js/deluge-all/add/FilesTab.js
@@ -84,18 +84,24 @@ Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, {
                });
        },
 
-       setDownload: function(node, value) {
+       setDownload: function(node, value, suppress) {
                node.attributes.download = value;
                node.ui.updateColumns();
 
                if (node.isLeaf()) {
-                       return this.fireEvent('filechecked', node, value, 
!value);
+                       if (!suppress) {
+                               return this.fireEvent('fileschecked', [node], 
value, !value);
+                       }
                } else {
+                       var nodes = [node];
                        node.cascade(function(n) {
                                n.attributes.download = value;
                                n.ui.updateColumns();
-                               return this.fireEvent('filechecked', n, value, 
!value);
+                               nodes.push(n);
                        }, this);
+                       if (!suppress) {
+                               return this.fireEvent('fileschecked', nodes, 
value, !value);
+                       }
                }
        },
 
diff --git a/deluge/ui/web/js/deluge-all/add/OptionsPanel.js 
b/deluge/ui/web/js/deluge-all/add/OptionsPanel.js
index b6e1a55..2d37bde 100644
--- a/deluge/ui/web/js/deluge-all/add/OptionsPanel.js
+++ b/deluge/ui/web/js/deluge-all/add/OptionsPanel.js
@@ -46,7 +46,7 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
                this.files = this.add(new Deluge.add.FilesTab());
                this.form = this.add(new Deluge.add.OptionsTab());
 
-               this.files.on('filechecked', this.onFileChecked, this);
+               this.files.on('fileschecked', this.onFilesChecked, this);
        },
 
        addTorrent: function(torrent) {
@@ -125,34 +125,35 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
                }
        },
 
-       onFileChecked: function(node, newValue, oldValue) {
-               if (!Ext.isNumber(node.attributes.fileindex)) return;
-
-//             if (this.form.optionsManager.get('compact_allocation')) {
-//                     Ext.Msg.show({
-//                             title: _('Unable to set file priority!'),
-//                             msg:   _('File prioritization is unavailable 
when using Compact allocation. Would you like to switch to Full allocation?'),
-//                             buttons: Ext.Msg.YESNO,
-//                             fn: function(result) {
-//                                     if (result == 'yes') {
-//                                             var priorities = 
this.form.optionsManager.get('file_priorities');
-//                                             
priorities[node.attributes.fileindex] = (result) ? newValue : oldValue;
-//                                             
this.form.optionsManager.update('file_priorities', priorities);
-//                                     } else {
-//                                             node.attributes.download = 
oldValue;
-//                                             node.ui.updateColumns();
-//                                     }       
-//                             },
-//                             scope: this,
-//                             icon: Ext.MessageBox.QUESTION
-//                     });
-//             } else {
-//                     var priorities = 
this.form.optionsManager.get('file_priorities');
-//                     priorities[node.attributes.fileindex] = newValue;
-//                     this.form.optionsManager.update('file_priorities', 
priorities);
-//             }
-               var priorities = 
this.form.optionsManager.get('file_priorities');
-               priorities[node.attributes.fileindex] = newValue;
-               this.form.optionsManager.update('file_priorities', priorities);
+       onFilesChecked: function(nodes, newValue, oldValue) {
+               if (this.form.optionsManager.get('compact_allocation')) {
+                       Ext.Msg.show({
+                               title: _('Unable to set file priority!'),
+                               msg:   _('File prioritization is unavailable 
when using Compact allocation. Would you like to switch to Full allocation?'),
+                               buttons: Ext.Msg.YESNO,
+                               fn: function(result) {
+                                       if (result == 'yes') {
+                                               
this.form.optionsManager.update('compact_allocation', false);
+                                               Ext.each(nodes, function(node) {
+                                                       if 
(node.attributes.fileindex < 0) return;
+                                                       var priorities = 
this.form.optionsManager.get('file_priorities');
+                                                       
priorities[node.attributes.fileindex] = newValue;
+                                                       
this.form.optionsManager.update('file_priorities', priorities);
+                                               }, this);
+                                       } else {
+                                               
this.files.setDownload(nodes[0], oldValue, true);
+                                       }       
+                               },
+                               scope: this,
+                               icon: Ext.MessageBox.QUESTION
+                       });
+               } else {
+                       Ext.each(nodes, function(node) {
+                               if (node.attributes.fileindex < 0) return;
+                               var priorities = 
this.form.optionsManager.get('file_priorities');
+                               priorities[node.attributes.fileindex] = 
newValue;
+                               
this.form.optionsManager.update('file_priorities', priorities);
+                       }, this);
+               }
        }
 });

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to