2011-05-03 20:59:07 -04:00
|
|
|
NEWSBLUR.ReaderSendEmail = function(story_id, options) {
|
2011-05-03 11:40:38 -04:00
|
|
|
var defaults = {};
|
2011-05-06 10:06:13 -04:00
|
|
|
|
|
|
|
_.bindAll(this, 'close');
|
2011-05-03 11:40:38 -04:00
|
|
|
|
|
|
|
this.options = $.extend({}, defaults, options);
|
|
|
|
this.model = NEWSBLUR.AssetModel.reader();
|
2011-05-03 20:59:07 -04:00
|
|
|
this.story_id = story_id;
|
2011-05-03 11:40:38 -04:00
|
|
|
this.story = this.model.get_story(story_id);
|
2011-05-06 10:06:13 -04:00
|
|
|
this.feed_id = this.story.story_feed_id;
|
|
|
|
this.feed = this.model.get_feed(this.feed_id);
|
2011-05-03 11:40:38 -04:00
|
|
|
|
|
|
|
this.runner();
|
|
|
|
};
|
|
|
|
|
2011-05-03 20:59:07 -04:00
|
|
|
NEWSBLUR.ReaderSendEmail.prototype = _.extend({}, NEWSBLUR.Modal.prototype, {
|
2011-05-03 11:40:38 -04:00
|
|
|
|
|
|
|
runner: function() {
|
|
|
|
this.make_modal();
|
|
|
|
this.open_modal();
|
|
|
|
|
|
|
|
this.$modal.bind('click', $.rescope(this.handle_click, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
make_modal: function() {
|
|
|
|
var self = this;
|
|
|
|
|
2011-05-03 20:59:07 -04:00
|
|
|
this.$modal = $.make('div', { className: 'NB-modal-email NB-modal' }, [
|
|
|
|
$.make('h2', { className: 'NB-modal-title' }, 'Send Story by Email'),
|
|
|
|
$.make('h2', { className: 'NB-modal-subtitle' }, [
|
|
|
|
$.make('div', { className: 'NB-modal-email-story-title' }, this.story.story_title),
|
2011-05-06 10:06:13 -04:00
|
|
|
$.make('div', { className: 'NB-modal-email-feed' }, [
|
|
|
|
$.make('img', { className: 'NB-modal-feed-image feed_favicon', src: $.favicon(this.feed.favicon) }),
|
|
|
|
$.make('div', { className: 'NB-modal-feed-title' }, this.feed.feed_title)
|
|
|
|
]),
|
2011-05-03 20:59:07 -04:00
|
|
|
$.make('div', { className: 'NB-modal-email-story-permalink' }, this.story.story_permalink)
|
2011-05-03 11:40:38 -04:00
|
|
|
]),
|
2011-05-06 10:06:13 -04:00
|
|
|
$.make('div', { className: 'NB-modal-email-to-container' }, [
|
|
|
|
'» Recipient\'s email: ',
|
|
|
|
$.make('input', { className: 'NB-input NB-modal-to', name: 'to', value: "" })
|
|
|
|
]),
|
2011-05-03 20:59:07 -04:00
|
|
|
$.make('div', { className: 'NB-modal-email-explanation' }, [
|
2011-05-06 10:06:13 -04:00
|
|
|
"Add an optional comment to send with the story. The story will be sent below your comment."
|
2011-05-03 11:40:38 -04:00
|
|
|
]),
|
2011-05-03 20:59:07 -04:00
|
|
|
$.make('div', { className: 'NB-modal-email-comments-container' }, [
|
|
|
|
$.make('textarea', { className: 'NB-modal-email-comments' })
|
2011-05-03 11:40:38 -04:00
|
|
|
]),
|
2011-05-06 10:06:13 -04:00
|
|
|
$.make('div', { className: 'NB-modal-email-from-container' }, [
|
|
|
|
'» Your name: ',
|
|
|
|
$.make('input', { className: 'NB-input NB-modal-email-from', name: 'from', value: NEWSBLUR.Globals.username })
|
2011-05-03 11:40:38 -04:00
|
|
|
]),
|
2011-05-03 20:59:07 -04:00
|
|
|
$.make('form', { className: 'NB-recommend-form' }, [
|
|
|
|
$.make('div', { className: 'NB-modal-submit' }, [
|
|
|
|
$.make('input', { type: 'submit', className: 'NB-modal-submit-save NB-modal-submit-green', value: 'Send this story' }),
|
|
|
|
' or ',
|
|
|
|
$.make('a', { href: '#', className: 'NB-modal-cancel' }, 'cancel')
|
|
|
|
])
|
2011-05-03 11:40:38 -04:00
|
|
|
])
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
2011-05-06 10:06:13 -04:00
|
|
|
save: function(e) {
|
|
|
|
var from = $('input[name=from]', this.$modal).val();
|
|
|
|
var to = $('input[name=to]', this.$modal).val();
|
|
|
|
var comments = $('textarea', this.$modal).val();
|
|
|
|
var $save = $('input[type=submit]', this.$modal);
|
|
|
|
|
|
|
|
$save.addClass('NB-disabled').val('Sending...');
|
|
|
|
|
|
|
|
this.model.send_story_email({
|
|
|
|
story_id : this.story_id,
|
|
|
|
feed_id : this.feed_id,
|
|
|
|
from : from,
|
|
|
|
to : to,
|
|
|
|
comments : comments
|
|
|
|
}, this.close, function(error) {
|
|
|
|
$save.removeClass('NB-disabled').val('Send Email');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-05-03 11:40:38 -04:00
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
handle_click: function(elem, e) {
|
|
|
|
var self = this;
|
|
|
|
|
2011-05-06 10:06:13 -04:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-modal-submit-save' }, function($t, $p) {
|
2011-05-03 11:40:38 -04:00
|
|
|
e.preventDefault();
|
|
|
|
|
2011-05-06 10:06:13 -04:00
|
|
|
self.save();
|
|
|
|
return false;
|
2011-05-03 11:40:38 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|