-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4513 from guerler/ftp_uploader
Allow users to upload multiple FTP files within a single request
- Loading branch information
Showing
38 changed files
with
469 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** Contains helpers to limit/lazy load views for backbone views */ | ||
define([], function() { | ||
return Backbone.View.extend({ | ||
initialize: function( options ) { | ||
var self = this; | ||
this.$container = options.$container; | ||
this.collection = options.collection; | ||
this.new_content = options.new_content; | ||
this.max = options.max || 50; | ||
this.content_list = {} | ||
this.$message = $( '<div/>' ).addClass( 'ui-limitloader' ).append( '...only the first ' + this.max + ' entries are visible.' ); | ||
this.$container.append( this.$message ); | ||
this.listenTo( this.collection, 'reset', this._reset, this ); | ||
this.listenTo( this.collection, 'add', this._refresh, this ); | ||
this.listenTo( this.collection, 'remove', this._remove, this ); | ||
}, | ||
|
||
/** Checks if the limit has been reached */ | ||
_done: function() { | ||
var done = _.size( this.content_list ) > this.max; | ||
this.$message[ done ? 'show' : 'hide' ](); | ||
return done; | ||
}, | ||
|
||
/** Remove all content */ | ||
_reset: function() { | ||
_.each( this.content_list, function( content ) { | ||
content.remove(); | ||
}); | ||
this.content_list = {}; | ||
this.$message.hide(); | ||
}, | ||
|
||
/** Remove content */ | ||
_remove: function( model ) { | ||
var model_id = model.id; | ||
var content = this.content_list[ model_id ]; | ||
if ( content ) { | ||
content.remove(); | ||
delete this.content_list[ model_id ]; | ||
} | ||
this._refresh(); | ||
}, | ||
|
||
/** Refreshes container content by adding new views if visible */ | ||
_refresh: function() { | ||
if ( !this._done() ) { | ||
for ( var i in this.collection.models ) { | ||
var model = this.collection.models[ i ]; | ||
var view = this.content_list[ model.id ]; | ||
if ( !this.content_list[ model.id ] ) { | ||
var content = this.new_content( model ); | ||
this.content_list[ model.id ] = content; | ||
if ( this._done() ) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.