mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Add support for batch adding subreddits to a multi.
This commit is contained in:
@@ -93,8 +93,26 @@ r.multi.MultiReddit = Backbone.Model.extend({
|
|||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|
||||||
addSubreddit: function(name, options) {
|
addSubreddit: function(names, options) {
|
||||||
this.subreddits.create({name: name}, options)
|
names = r.utils.tup(names)
|
||||||
|
if (names.length == 1) {
|
||||||
|
this.subreddits.create({name: names[0]}, options)
|
||||||
|
} else {
|
||||||
|
// batch add by syncing the entire multi
|
||||||
|
var subreddits = this.subreddits,
|
||||||
|
tmp = subreddits.clone()
|
||||||
|
tmp.add(_.map(names, function(srName) {
|
||||||
|
return {name: srName}
|
||||||
|
}))
|
||||||
|
|
||||||
|
// temporarily swap out the subreddits collection so we can
|
||||||
|
// serialize and send the new data without updating the UI
|
||||||
|
// this is similar to how the "wait" option is handled in
|
||||||
|
// Backbone.Model.set
|
||||||
|
this.subreddits = tmp
|
||||||
|
this.save(null, options)
|
||||||
|
this.subreddits = subreddits
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
removeSubreddit: function(name, options) {
|
removeSubreddit: function(name, options) {
|
||||||
@@ -261,25 +279,19 @@ r.multi.MultiDetails = Backbone.View.extend({
|
|||||||
delete this.itemViews[sr.id]
|
delete this.itemViews[sr.id]
|
||||||
},
|
},
|
||||||
|
|
||||||
addAll: function() {
|
|
||||||
this.itemViews = {}
|
|
||||||
this.$('.subreddits').empty()
|
|
||||||
this.model.subreddits.each(this.addOne, this)
|
|
||||||
},
|
|
||||||
|
|
||||||
addSubreddit: function(ev) {
|
addSubreddit: function(ev) {
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
|
|
||||||
var nameEl = this.$('.add-sr .sr-name'),
|
var nameEl = this.$('.add-sr .sr-name'),
|
||||||
srName = $.trim(nameEl.val())
|
srNames = nameEl.val()
|
||||||
srName = srName.split('r/').pop()
|
srNames = _.compact(srNames.split(/[\/+,\s]+(?:r\/)?/))
|
||||||
if (!srName) {
|
if (!srNames.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nameEl.val('')
|
nameEl.val('')
|
||||||
this.$('.add-error').css('visibility', 'hidden')
|
this.$('.add-error').css('visibility', 'hidden')
|
||||||
this.model.addSubreddit(srName, {
|
this.model.addSubreddit(srNames, {
|
||||||
wait: true,
|
wait: true,
|
||||||
success: _.bind(function() {
|
success: _.bind(function() {
|
||||||
this.$('.add-error').hide()
|
this.$('.add-error').hide()
|
||||||
|
|||||||
Reference in New Issue
Block a user