Add multireddit copying to the frontend.

This commit is contained in:
Max Goodman
2013-05-07 15:43:34 -07:00
parent ac04ea4504
commit 9759934f7a
4 changed files with 92 additions and 17 deletions

View File

@@ -1827,6 +1827,7 @@ class MultiInfoBar(Templated):
Templated.__init__(self)
self.multi = wrap_things(multi)[0]
self.can_edit = multi.can_edit(user)
self.can_copy = c.user_is_loggedin
srs.sort(key=lambda sr: sr.name.lower())
self.srs = srs

View File

@@ -5141,12 +5141,12 @@ table.calendar {
vertical-align: middle;
}
label {
label, .show-copy, .delete {
margin-right: 10px;
}
.delete {
margin-left: 5px;
.visibility-group {
margin-right: 5px;
}
}
@@ -5156,6 +5156,22 @@ table.calendar {
margin-bottom: 3px;
}
form.copy-multi {
display: none;
margin-bottom: 10px;
.copy-name {
border: 1px solid #ccc;
padding: 3px;
}
button {
.light-button;
padding: 3px 4px;
background: #eeffdd;
}
}
ul, form.add-sr {
margin-left: 12px;
}
@@ -6935,6 +6951,20 @@ body.gold .buttons li.comment-save-button { display: inline; }
white-space: normal;
}
.light-button {
background: none;
border: 1px solid #777;
border-radius: 3px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .25);
opacity: .75;
&:active {
position: relative;
top: 1px;
box-shadow: none;
}
}
body.with-listing-chooser {
position: relative;
@@ -7130,15 +7160,7 @@ body.with-listing-chooser {
}
button {
opacity: .75;
background: #fcfcfc;
box-shadow: 0 1px 1px rgba(0, 0, 0, .25);
&:active {
position: relative;
top: 1px;
box-shadow: none;
}
.light-button;
}
}
}

View File

@@ -184,6 +184,8 @@ r.multi.MultiDetails = Backbone.View.extend({
events: {
'submit .add-sr': 'addSubreddit',
'change [name="visibility"]': 'setVisibility',
'click .show-copy': 'showCopyMulti',
'click .copy': 'copyMulti',
'confirm .delete': 'deleteMulti'
},
@@ -268,6 +270,40 @@ r.multi.MultiDetails = Backbone.View.extend({
})
},
showCopyMulti: function() {
this.$('form.copy-multi').show()
},
copyMulti: function(ev) {
ev.preventDefault()
var nameEl = this.$('.copy-multi .copy-name'),
multiName = $.trim(nameEl.val())
if (!multiName) {
return
}
this.$('.copy-error').css('visibility', 'hidden')
var attrs = _.clone(this.model.attributes)
delete attrs.path
attrs.name = multiName
r.multi.mine.create(attrs, {
wait: true,
success: function(multi) {
window.location = multi.get('path')
},
error: _.bind(function(multi, xhr) {
var resp = JSON.parse(xhr.responseText)
this.$('.copy-error')
.text(resp.explanation)
.css('visibility', 'visible')
.show()
}, this),
beforeSend: _.bind(r.ui.showWorkingDeferred, this, this.$el)
})
},
deleteMulti: function() {
this.model.destroy({
success: function() {

View File

@@ -33,12 +33,28 @@
<a href="${thing.multi.path}">${_('%s subreddits') % thing.multi.name}</a><div class="throbber"></div>
</h1>
<h2><a href="/user/${thing.multi.owner.name}">${_('curated by /u/%s') % thing.multi.owner.name}</a></h2>
%if thing.can_edit:
<div class="gray-buttons settings">
<label><input type="radio" name="visibility" value="private" ${'checked' if thing.multi.visibility == 'private' else ''}>${_('private')}</label>
<label><input type="radio" name="visibility" value="public" ${'checked' if thing.multi.visibility == 'public' else ''}>${_('public')}</label>
<div class="gray-buttons settings">
%if thing.can_edit:
<span class="visibility-group">
<label><input type="radio" name="visibility" value="private" ${'checked' if thing.multi.visibility == 'private' else ''}>${_('private')}</label>
<label><input type="radio" name="visibility" value="public" ${'checked' if thing.multi.visibility == 'public' else ''}>${_('public')}</label>
</span>
%if thing.can_copy:
<button class="show-copy">${_('copy')}</button>
%endif
<button class="delete">${_('delete')}</button>
</div>
%else:
%if thing.can_copy:
<button class="show-copy">${_('create a copy')}</button>
%endif
%endif
</div>
%if thing.can_copy:
<form class="copy-multi">
<input type="text" class="copy-name" placeholder="${_('copy name')}"><button class="copy">${_('copy')} &rsaquo;</button>
<div class="error copy-error"></div>
</form>
%endif
<h3>${_('subreddits in this multi:')}</h3>