diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index f567fe223..19e972597 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -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 diff --git a/r2/r2/public/static/css/reddit.less b/r2/r2/public/static/css/reddit.less index f0e5d9ee2..2447eae9c 100755 --- a/r2/r2/public/static/css/reddit.less +++ b/r2/r2/public/static/css/reddit.less @@ -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; } } } diff --git a/r2/r2/public/static/js/multi.js b/r2/r2/public/static/js/multi.js index 888c21cfc..5ea6ebb5e 100644 --- a/r2/r2/public/static/js/multi.js +++ b/r2/r2/public/static/js/multi.js @@ -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() { diff --git a/r2/r2/templates/multiinfobar.html b/r2/r2/templates/multiinfobar.html index 79204ffa6..60013bbd9 100644 --- a/r2/r2/templates/multiinfobar.html +++ b/r2/r2/templates/multiinfobar.html @@ -33,12 +33,28 @@ ${_('%s subreddits') % thing.multi.name}

${_('curated by /u/%s') % thing.multi.owner.name}

- %if thing.can_edit: -
- - +
+ %if thing.can_edit: + + + + + %if thing.can_copy: + + %endif -
+ %else: + %if thing.can_copy: + + %endif + %endif +
+ + %if thing.can_copy: +
+ +
+
%endif

${_('subreddits in this multi:')}