##// END OF EJS Templates
Removed respect_order and finally removed the children dict of the containerview
Jonathan Frederic -
Show More
@@ -339,7 +339,7 b' function(WidgetManager, _, Backbone){'
339 return null;
339 return null;
340 },
340 },
341
341
342 do_diff: function(old_list, new_list, removed_callback, added_callback, respect_order) {
342 do_diff: function(old_list, new_list, removed_callback, added_callback) {
343 // Difference a changed list and call remove and add callbacks for
343 // Difference a changed list and call remove and add callbacks for
344 // each removed and added item in the new list.
344 // each removed and added item in the new list.
345 //
345 //
@@ -351,60 +351,24 b' function(WidgetManager, _, Backbone){'
351 // Callback that is called for each item removed.
351 // Callback that is called for each item removed.
352 // added_callback : Callback(item)
352 // added_callback : Callback(item)
353 // Callback that is called for each item added.
353 // Callback that is called for each item added.
354 // [respect_order] : bool [True]
355 // Whether or not the order of the list matters.
356
357 if (respect_order || respect_order===undefined) {
358 // Walk the lists until an unequal entry is found.
359 var i;
360 for (i = 0; i < new_list.length; i++) {
361 if (i < old_list.length || new_list[i] !== old_list[i]) {
362 break;
363 }
364 }
365
354
366 // Remove the non-matching items from the old list.
355 // Walk the lists until an unequal entry is found.
367 for (var j = i; j < old_list.length; j++) {
356 var i;
368 removed_callback(old_list[j]);
357 for (i = 0; i < new_list.length; i++) {
358 if (i < old_list.length || new_list[i] !== old_list[i]) {
359 break;
369 }
360 }
361 }
370
362
371 // Add the rest of the new list items.
363 // Remove the non-matching items from the old list.
372 for (i; i < new_list.length; i++) {
364 for (var j = i; j < old_list.length; j++) {
373 added_callback(new_list[i]);
365 removed_callback(old_list[j]);
374 }
375 } else {
376 // removed items
377 _.each(this.difference(old_list, new_list), function(item, index, list) {
378 removed_callback(item);
379 }, this);
380
381 // added items
382 _.each(this.difference(new_list, old_list), function(item, index, list) {
383 added_callback(item);
384 }, this);
385 }
366 }
386 },
387
367
388 difference: function(a, b) {
368 // Add the rest of the new list items.
389 // Calculate the difference of two lists by contents.
369 for (i; i < new_list.length; i++) {
390 //
370 added_callback(new_list[i]);
391 // This function is like the underscore difference function
392 // except it will not fail when given a list with duplicates.
393 // i.e.:
394 // diff([1, 2, 2, 3], [3, 2])
395 // Underscores results:
396 // [1]
397 // This method:
398 // [1, 2]
399 var contents = a.slice(0);
400 var found_index;
401 for (var i = 0; i < b.length; i++) {
402 found_index = _.indexOf(contents, b[i]);
403 if (found_index >= 0) {
404 contents.splice(found_index, 1);
405 }
406 }
371 }
407 return contents;
408 },
372 },
409
373
410 callbacks: function(){
374 callbacks: function(){
@@ -21,7 +21,6 b' define(["widgets/js/widget"], function(WidgetManager) {'
21 // Called when view is rendered.
21 // Called when view is rendered.
22 this.$el.addClass('widget-container')
22 this.$el.addClass('widget-container')
23 .addClass('vbox');
23 .addClass('vbox');
24 this.children={};
25 this.update_children([], this.model.get('children'));
24 this.update_children([], this.model.get('children'));
26 this.model.on('change:children', function(model, value, options) {
25 this.model.on('change:children', function(model, value, options) {
27 this.update_children(model.previous('children'), value);
26 this.update_children(model.previous('children'), value);
@@ -80,7 +79,6 b' define(["widgets/js/widget"], function(WidgetManager) {'
80 render: function(){
79 render: function(){
81 // Called when view is rendered.
80 // Called when view is rendered.
82 var that = this;
81 var that = this;
83 this.children={};
84
82
85 this.$el.on("remove", function(){
83 this.$el.on("remove", function(){
86 that.$backdrop.remove();
84 that.$backdrop.remove();
General Comments 0
You need to be logged in to leave comments. Login now