2016-11-14 11:12:13 -08:00
|
|
|
NEWSBLUR.ReaderNotifications = function(feed_id, options) {
|
|
|
|
var defaults = {
|
|
|
|
'onOpen': function() {
|
|
|
|
$(window).trigger('resize.simplemodal');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.options = $.extend({}, defaults, options);
|
|
|
|
this.model = NEWSBLUR.assets;
|
|
|
|
this.feed_id = feed_id;
|
|
|
|
this.feed = this.model.get_feed(feed_id);
|
|
|
|
|
|
|
|
this.runner();
|
|
|
|
};
|
|
|
|
|
|
|
|
NEWSBLUR.ReaderNotifications.prototype = new NEWSBLUR.Modal;
|
|
|
|
NEWSBLUR.ReaderNotifications.prototype.constructor = NEWSBLUR.ReaderNotifications;
|
|
|
|
|
|
|
|
_.extend(NEWSBLUR.ReaderNotifications.prototype, {
|
|
|
|
|
|
|
|
runner: function() {
|
2016-11-16 21:07:19 -08:00
|
|
|
console.log(['Reader notifications', this.feed, this.feed_id]);
|
2016-11-14 11:12:13 -08:00
|
|
|
this.make_modal();
|
|
|
|
this.handle_cancel();
|
|
|
|
this.open_modal();
|
2016-11-14 19:26:09 -08:00
|
|
|
if (this.feed_id) {
|
|
|
|
this.initialize_feed(this.feed_id);
|
|
|
|
}
|
2021-02-01 14:59:24 -05:00
|
|
|
|
|
|
|
$('input[name=notification_title_only]', this.$modal).each(function() {
|
|
|
|
if ($(this).val() == NEWSBLUR.Preferences.notification_title_only) {
|
|
|
|
$(this).attr('checked', true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2016-11-14 11:12:13 -08:00
|
|
|
|
|
|
|
this.$modal.bind('click', $.rescope(this.handle_click, this));
|
|
|
|
this.$modal.bind('change', $.rescope(this.handle_change, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize_feed: function(feed_id) {
|
|
|
|
var frequency = this.feed.get('notification_frequency');
|
|
|
|
var notifications = this.feed.get('notifications');
|
|
|
|
|
2016-11-15 18:18:31 -08:00
|
|
|
NEWSBLUR.Modal.prototype.initialize_feed.call(this, feed_id);
|
|
|
|
|
|
|
|
var $site = $(".NB-modal-section-site", this.$modal);
|
|
|
|
$site.html(this.make_feed_notification(this.feed));
|
|
|
|
|
|
|
|
var $all = $(".NB-modal-section-all", this.$modal);
|
|
|
|
$all.html(this.make_feed_notifications());
|
2016-11-14 11:12:13 -08:00
|
|
|
|
|
|
|
this.resize();
|
|
|
|
},
|
|
|
|
|
|
|
|
get_feed_settings: function() {
|
|
|
|
if (this.feed.is_starred()) return;
|
|
|
|
|
|
|
|
var $loading = $('.NB-modal-loading', this.$modal);
|
|
|
|
$loading.addClass('NB-active');
|
|
|
|
|
|
|
|
var settings_fn = this.options.social_feed ? this.model.get_social_settings :
|
|
|
|
this.model.get_feed_settings;
|
|
|
|
settings_fn.call(this.model, this.feed_id, _.bind(this.populate_settings, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
populate_settings: function(data) {
|
|
|
|
var $submit = $('.NB-modal-submit-save', this.$modal);
|
|
|
|
var $loading = $('.NB-modal-loading', this.$modal);
|
|
|
|
|
|
|
|
$loading.removeClass('NB-active');
|
|
|
|
this.resize();
|
|
|
|
},
|
|
|
|
|
|
|
|
make_modal: function() {
|
|
|
|
var self = this;
|
|
|
|
|
2016-11-14 19:26:09 -08:00
|
|
|
this.$modal = $.make('div', { className: 'NB-modal-notifications NB-modal' }, [
|
2016-11-14 11:12:13 -08:00
|
|
|
(this.feed && $.make('div', { className: 'NB-modal-feed-chooser-container'}, [
|
|
|
|
this.make_feed_chooser()
|
|
|
|
])),
|
|
|
|
$.make('div', { className: 'NB-modal-loading' }),
|
2016-11-15 18:18:31 -08:00
|
|
|
$.make('h2', { className: 'NB-modal-title' }, [
|
|
|
|
$.make('div', { className: 'NB-modal-loading' }),
|
|
|
|
$.make('div', { className: 'NB-icon' }),
|
2016-11-15 20:45:59 -08:00
|
|
|
'Notifications',
|
2016-11-15 18:18:31 -08:00
|
|
|
$.make('div', { className: 'NB-icon-dropdown' })
|
|
|
|
]),
|
2021-02-01 14:59:24 -05:00
|
|
|
$.make('div', { className: 'NB-fieldset NB-modal-submit' }, [
|
|
|
|
$.make('fieldset', [
|
|
|
|
$.make('legend', 'Notification Preferences'),
|
|
|
|
$.make('div', { className: 'NB-modal-section NB-modal-section-preferences'}, [
|
|
|
|
$.make('div', { className: 'NB-preference NB-preference-notification-title-only' }, [
|
|
|
|
$.make('div', { className: 'NB-preference-options' }, [
|
|
|
|
$.make('div', [
|
|
|
|
$.make('input', { id: 'NB-preference-notificationtitleonly-1', type: 'radio', name: 'notification_title_only', value: 0 }),
|
|
|
|
$.make('label', { 'for': 'NB-preference-notificationtitleonly-1' }, [
|
|
|
|
'See the story title and a short content preview'
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', [
|
|
|
|
$.make('input', { id: 'NB-preference-notificationtitleonly-2', type: 'radio', name: 'notification_title_only', value: 1 }),
|
|
|
|
$.make('label', { 'for': 'NB-preference-notificationtitleonly-2' }, [
|
|
|
|
'Only see the full story title'
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-preference-label' }, [
|
|
|
|
'Story preview',
|
|
|
|
$.make('div', { className: 'NB-preference-sublabel' }, '')
|
|
|
|
])
|
|
|
|
])
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]),
|
2016-11-14 19:26:09 -08:00
|
|
|
(this.feed && $.make('div', { className: 'NB-fieldset NB-modal-submit' }, [
|
2016-11-15 13:32:43 -08:00
|
|
|
$.make('fieldset', [
|
|
|
|
$.make('legend', 'Site Notifications'),
|
|
|
|
$.make('div', { className: 'NB-modal-section NB-modal-section-site'}, [
|
|
|
|
this.make_feed_notification(this.feed)
|
|
|
|
])
|
2016-11-14 11:12:13 -08:00
|
|
|
])
|
|
|
|
])),
|
2016-11-14 19:26:09 -08:00
|
|
|
$.make('div', { className: 'NB-fieldset NB-modal-submit' }, [
|
2016-11-15 13:32:43 -08:00
|
|
|
$.make('fieldset', [
|
|
|
|
$.make('legend', 'All Notifications'),
|
2016-11-15 18:18:31 -08:00
|
|
|
$.make('div', { className: 'NB-modal-section NB-modal-section-all'}, [
|
2016-11-15 13:32:43 -08:00
|
|
|
this.make_feed_notifications()
|
|
|
|
])
|
2016-11-14 11:12:13 -08:00
|
|
|
])
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
|
|
|
handle_cancel: function() {
|
|
|
|
var $cancel = $('.NB-modal-cancel', this.$modal);
|
|
|
|
|
|
|
|
$cancel.click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$.modal.close();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-11-14 19:26:09 -08:00
|
|
|
make_feed_notification: function(feed) {
|
|
|
|
var $feed = new NEWSBLUR.Views.FeedNotificationView({model: feed});
|
2016-11-14 11:12:13 -08:00
|
|
|
|
2016-11-14 19:26:09 -08:00
|
|
|
return $feed.render().$el;
|
2016-11-14 11:12:13 -08:00
|
|
|
},
|
|
|
|
|
2016-11-14 19:26:09 -08:00
|
|
|
make_feed_notifications: function() {
|
2016-11-17 11:37:10 -08:00
|
|
|
var site_feed_id = this.feed && this.feed.id;
|
2016-11-15 18:18:31 -08:00
|
|
|
var notifications = this.model.get_feeds().select(function(feed) {
|
|
|
|
return feed.get('notification_types') && feed.id != site_feed_id;
|
2016-11-14 19:26:09 -08:00
|
|
|
});
|
|
|
|
var $feeds = [];
|
2016-11-14 11:12:13 -08:00
|
|
|
|
2016-11-15 18:18:31 -08:00
|
|
|
notifications.sort(function(a, b) { return a.get('feed_title') < b.get('feed_title'); });
|
2016-11-14 19:26:09 -08:00
|
|
|
for (var feed in notifications) {
|
2016-11-15 18:18:31 -08:00
|
|
|
$feeds.push(this.make_feed_notification(notifications[feed]));
|
2016-11-14 11:12:13 -08:00
|
|
|
}
|
2016-11-14 19:26:09 -08:00
|
|
|
|
|
|
|
return $feeds;
|
2016-11-14 11:12:13 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
handle_click: function(elem, e) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-modal-submit-retry' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
self.save_retry_feed();
|
|
|
|
});
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-modal-submit-delete' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
self.delete_feed();
|
|
|
|
});
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-modal-submit-address' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
self.change_feed_address();
|
|
|
|
});
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-modal-submit-link' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
self.change_feed_link();
|
|
|
|
});
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-premium-only-link' }, function($t, $p){
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
self.close(function() {
|
|
|
|
NEWSBLUR.reader.open_feedchooser_modal({premium_only: true});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
animate_saved: function() {
|
|
|
|
var $status = $('.NB-exception-option-view .NB-exception-option-status', this.$modal);
|
|
|
|
$status.text('Saved').animate({
|
|
|
|
'opacity': 1
|
|
|
|
}, {
|
|
|
|
'queue': false,
|
|
|
|
'duration': 600,
|
|
|
|
'complete': function() {
|
|
|
|
_.delay(function() {
|
|
|
|
$status.animate({'opacity': 0}, {'queue': false, 'duration': 1000});
|
|
|
|
}, 300);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
handle_change: function(elem, e) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-modal-feed-chooser' }, function($t, $p){
|
|
|
|
var feed_id = $t.val();
|
|
|
|
self.first_load = false;
|
|
|
|
self.initialize_feed(feed_id);
|
|
|
|
self.get_feed_settings();
|
|
|
|
});
|
2021-02-01 14:59:24 -05:00
|
|
|
$.targetIs(e, { tagSelector: '[name=notification_title_only]' }, function ($t, $p) {
|
|
|
|
var notification_title_only = self.$modal.find("input[name=notification_title_only]:checked").val();
|
|
|
|
console.log(['notification_title_only', notification_title_only]);
|
|
|
|
NEWSBLUR.assets.preference('notification_title_only', notification_title_only);
|
|
|
|
});
|
2016-11-14 11:12:13 -08:00
|
|
|
}
|
|
|
|
|
2021-02-01 14:59:24 -05:00
|
|
|
});
|