2010-08-18 20:35:45 -04:00
|
|
|
NEWSBLUR.ReaderFeedException = function(feed_id, options) {
|
|
|
|
var defaults = {};
|
2011-09-26 09:22:46 -07:00
|
|
|
|
2010-08-18 20:35:45 -04:00
|
|
|
this.options = $.extend({}, defaults, options);
|
2011-09-26 09:22:46 -07:00
|
|
|
this.model = NEWSBLUR.AssetModel.reader();
|
2010-08-18 20:35:45 -04:00
|
|
|
this.feed_id = feed_id;
|
2011-09-26 09:22:46 -07:00
|
|
|
this.feed = this.model.get_feed(feed_id);
|
|
|
|
|
2010-08-18 20:35:45 -04:00
|
|
|
this.runner();
|
|
|
|
};
|
|
|
|
|
2011-09-26 09:22:46 -07:00
|
|
|
NEWSBLUR.ReaderFeedException.prototype = new NEWSBLUR.Modal;
|
|
|
|
NEWSBLUR.ReaderFeedException.prototype.constructor = NEWSBLUR.ReaderFeedException;
|
|
|
|
|
|
|
|
_.extend(NEWSBLUR.ReaderFeedException.prototype, {
|
2010-08-18 20:35:45 -04:00
|
|
|
|
|
|
|
runner: function() {
|
|
|
|
this.make_modal();
|
2010-08-26 10:04:32 -04:00
|
|
|
this.show_recommended_options_meta();
|
2010-08-18 20:35:45 -04:00
|
|
|
this.handle_cancel();
|
|
|
|
this.open_modal();
|
2011-11-12 18:19:57 -08:00
|
|
|
this.initialize_feed(this.feed_id);
|
|
|
|
|
|
|
|
_.delay(_.bind(function() {
|
|
|
|
this.get_feed_settings();
|
|
|
|
}, this), 50);
|
2010-08-18 20:35:45 -04:00
|
|
|
|
|
|
|
this.$modal.bind('click', $.rescope(this.handle_click, this));
|
2011-11-12 18:19:57 -08:00
|
|
|
this.$modal.bind('change', $.rescope(this.handle_change, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize_feed: function(feed_id) {
|
|
|
|
NEWSBLUR.Modal.prototype.initialize_feed.call(this, feed_id);
|
|
|
|
$('input[name=feed_link]', this.$modal).val(this.feed.feed_link);
|
|
|
|
$('input[name=feed_address]', this.$modal).val(this.feed.feed_address);
|
|
|
|
|
|
|
|
if (this.feed.exception_type) {
|
|
|
|
this.$modal.removeClass('NB-modal-feed-settings');
|
|
|
|
} else {
|
|
|
|
this.$modal.addClass('NB-modal-feed-settings');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get_feed_settings: function() {
|
|
|
|
var $loading = $('.NB-modal-loading', this.$modal);
|
|
|
|
$loading.addClass('NB-active');
|
|
|
|
|
|
|
|
this.model.get_feed_settings(this.feed_id, _.bind(this.populate_settings, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
populate_settings: function() {
|
|
|
|
var $submit = $('.NB-modal-submit-save', this.$modal);
|
|
|
|
var $loading = $('.NB-modal-loading', this.$modal);
|
|
|
|
$loading.removeClass('NB-active');
|
|
|
|
|
2010-08-18 20:35:45 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
make_modal: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$modal = $.make('div', { className: 'NB-modal-exception NB-modal' }, [
|
2011-11-12 18:19:57 -08:00
|
|
|
$.make('div', { className: 'NB-modal-feed-chooser-container'}, [
|
|
|
|
this.make_feed_chooser()
|
|
|
|
]),
|
2010-08-30 18:41:53 -04:00
|
|
|
$.make('div', { className: 'NB-modal-loading' }),
|
2010-08-18 20:35:45 -04:00
|
|
|
$.make('h2', { className: 'NB-modal-title' }, 'Fix a misbehaving site'),
|
|
|
|
$.make('h2', { className: 'NB-modal-subtitle' }, [
|
2011-02-17 10:32:47 -05:00
|
|
|
$.make('img', { className: 'NB-modal-feed-image feed_favicon', src: $.favicon(this.feed.favicon) }),
|
2010-08-18 20:35:45 -04:00
|
|
|
$.make('span', { className: 'NB-modal-feed-title' }, this.feed.feed_title)
|
|
|
|
]),
|
2011-11-12 18:19:57 -08:00
|
|
|
$.make('div', { className: 'NB-fieldset NB-exception-option NB-exception-option-retry NB-modal-submit NB-exception-block-only' }, [
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('h5', [
|
|
|
|
$.make('div', { className: 'NB-exception-option-meta' }),
|
2011-11-12 18:19:57 -08:00
|
|
|
$.make('span', { className: 'NB-exception-option-option NB-exception-only' }, 'Option 1:'),
|
2010-08-25 10:18:08 -04:00
|
|
|
'Retry'
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-fieldset-fields' }, [
|
|
|
|
$.make('div', [
|
|
|
|
$.make('div', { className: 'NB-loading' }),
|
2010-08-30 22:42:44 -04:00
|
|
|
$.make('input', { type: 'submit', value: 'Retry fetching and parsing', className: 'NB-modal-submit-green NB-modal-submit-retry' }),
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('div', { className: 'NB-error' })
|
|
|
|
])
|
2010-08-18 20:35:45 -04:00
|
|
|
])
|
2010-08-25 10:18:08 -04:00
|
|
|
]),
|
2011-11-13 14:08:31 -08:00
|
|
|
$.make('div', { className: 'NB-fieldset NB-exception-option NB-exception-option-feed NB-modal-submit' }, [
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('h5', [
|
2010-08-26 10:04:32 -04:00
|
|
|
$.make('div', { className: 'NB-exception-option-meta' }),
|
2011-11-12 18:19:57 -08:00
|
|
|
$.make('span', { className: 'NB-exception-option-option NB-exception-only' }, 'Option 2:'),
|
2011-11-13 14:08:31 -08:00
|
|
|
'Change RSS Feed Address'
|
2010-08-25 10:18:08 -04:00
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-fieldset-fields' }, [
|
2011-09-26 09:22:46 -07:00
|
|
|
$.make('div', { className: 'NB-exception-input-wrapper' }, [
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('div', { className: 'NB-loading' }),
|
2011-11-13 14:08:31 -08:00
|
|
|
$.make('label', { 'for': 'NB-exception-input-address', className: 'NB-exception-label' }, [
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('div', { className: 'NB-folder-icon' }),
|
2011-11-13 14:08:31 -08:00
|
|
|
'RSS/XML URL: '
|
2010-08-25 10:18:08 -04:00
|
|
|
]),
|
2011-11-13 14:08:31 -08:00
|
|
|
$.make('input', { type: 'text', id: 'NB-exception-input-address', className: 'NB-exception-input-address NB-input', name: 'feed_address', value: this.feed['feed_address'] })
|
2011-09-26 09:22:46 -07:00
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-exception-submit-wrapper' }, [
|
2011-11-13 14:08:31 -08:00
|
|
|
$.make('input', { type: 'submit', value: 'Parse this RSS/XML Feed', className: 'NB-modal-submit-green NB-modal-submit-address' }),
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('div', { className: 'NB-error' })
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]),
|
2011-11-13 14:08:31 -08:00
|
|
|
$.make('div', { className: 'NB-fieldset NB-exception-option NB-exception-option-page NB-modal-submit' }, [
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('h5', [
|
2010-08-26 10:04:32 -04:00
|
|
|
$.make('div', { className: 'NB-exception-option-meta' }),
|
2011-11-12 18:19:57 -08:00
|
|
|
$.make('span', { className: 'NB-exception-option-option NB-exception-only' }, 'Option 3:'),
|
2011-11-13 14:08:31 -08:00
|
|
|
'Change Website Address'
|
2010-08-25 10:18:08 -04:00
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-fieldset-fields' }, [
|
2011-09-26 09:22:46 -07:00
|
|
|
$.make('div', { className: 'NB-exception-input-wrapper' }, [
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('div', { className: 'NB-loading' }),
|
2011-11-13 14:08:31 -08:00
|
|
|
$.make('label', { 'for': 'NB-exception-input-link', className: 'NB-exception-label' }, [
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('div', { className: 'NB-folder-icon' }),
|
2011-11-13 14:08:31 -08:00
|
|
|
'Website URL: '
|
2010-08-25 10:18:08 -04:00
|
|
|
]),
|
2011-11-13 14:08:31 -08:00
|
|
|
$.make('input', { type: 'text', id: 'NB-exception-input-link', className: 'NB-exception-input-link NB-input', name: 'feed_link', value: this.feed['feed_link'] })
|
2011-09-26 09:22:46 -07:00
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-exception-submit-wrapper' }, [
|
2011-11-13 14:08:31 -08:00
|
|
|
$.make('input', { type: 'submit', value: 'Fetch Feed From Website', className: 'NB-modal-submit-green NB-modal-submit-link' }),
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('div', { className: 'NB-error' })
|
|
|
|
])
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-fieldset NB-exception-option NB-exception-option-delete NB-modal-submit' }, [
|
|
|
|
$.make('h5', [
|
2011-11-12 18:19:57 -08:00
|
|
|
$.make('span', { className: 'NB-exception-option-option NB-exception-only' }, 'Option 4:'),
|
2010-08-25 10:18:08 -04:00
|
|
|
'Just Delete This Feed'
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-fieldset-fields' }, [
|
|
|
|
$.make('div', [
|
|
|
|
$.make('div', { className: 'NB-loading' }),
|
2010-08-30 22:42:44 -04:00
|
|
|
$.make('input', { type: 'submit', value: 'Delete It. It Just Won\'t Work!', className: 'NB-modal-submit-red NB-modal-submit-delete' }),
|
2010-08-25 10:18:08 -04:00
|
|
|
$.make('div', { className: 'NB-error' })
|
|
|
|
])
|
|
|
|
])
|
|
|
|
])
|
2010-08-18 20:35:45 -04:00
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
2010-08-26 10:04:32 -04:00
|
|
|
show_recommended_options_meta: function() {
|
|
|
|
var $meta_retry = $('.NB-exception-option-retry .NB-exception-option-meta', this.$modal);
|
|
|
|
var $meta_page = $('.NB-exception-option-page .NB-exception-option-meta', this.$modal);
|
|
|
|
var $meta_feed = $('.NB-exception-option-feed .NB-exception-option-meta', this.$modal);
|
|
|
|
var is_400 = (400 <= this.feed.exception_code && this.feed.exception_code < 500);
|
2010-08-25 10:18:08 -04:00
|
|
|
|
2010-08-26 10:04:32 -04:00
|
|
|
if (!is_400) {
|
|
|
|
$meta_retry.addClass('NB-exception-option-meta-recommended');
|
|
|
|
$meta_retry.text('Recommended');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.feed.exception_type == 'feed') {
|
|
|
|
$meta_page.addClass('NB-exception-option-meta-recommended');
|
|
|
|
$meta_page.text('Recommended');
|
|
|
|
}
|
|
|
|
if (this.feed.exception_type == 'page') {
|
|
|
|
if (is_400) {
|
|
|
|
$meta_feed.addClass('NB-exception-option-meta-recommended');
|
|
|
|
$meta_feed.text('Recommended');
|
|
|
|
} else {
|
|
|
|
$meta_page.addClass('NB-exception-option-meta-recommended');
|
|
|
|
$meta_page.text('Recommended');
|
|
|
|
}
|
|
|
|
}
|
2010-08-25 10:18:08 -04:00
|
|
|
},
|
|
|
|
|
2010-08-18 20:35:45 -04:00
|
|
|
handle_cancel: function() {
|
|
|
|
var $cancel = $('.NB-modal-cancel', this.$modal);
|
|
|
|
|
|
|
|
$cancel.click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
$.modal.close();
|
|
|
|
});
|
|
|
|
},
|
2010-08-25 10:18:08 -04:00
|
|
|
|
|
|
|
save_retry_feed: function() {
|
|
|
|
var self = this;
|
2010-08-30 18:41:53 -04:00
|
|
|
var $loading = $('.NB-modal-loading', this.$modal);
|
|
|
|
$loading.addClass('NB-active');
|
|
|
|
|
|
|
|
$('.NB-modal-submit-retry', this.$modal).addClass('NB-disabled').attr('value', 'Fetching...');
|
|
|
|
|
2010-08-25 10:18:08 -04:00
|
|
|
this.model.save_exception_retry(this.feed_id, function() {
|
2011-02-06 15:04:21 -05:00
|
|
|
// NEWSBLUR.reader.flags['has_unfetched_feeds'] = true;
|
|
|
|
// NEWSBLUR.reader.force_instafetch_stories(self.feed_id);
|
2010-08-25 10:18:08 -04:00
|
|
|
$.modal.close();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
delete_feed: function() {
|
2010-08-30 18:41:53 -04:00
|
|
|
var $loading = $('.NB-modal-loading', this.$modal);
|
2010-08-25 10:18:08 -04:00
|
|
|
$loading.addClass('NB-active');
|
2010-08-30 18:41:53 -04:00
|
|
|
|
|
|
|
$('.NB-modal-submit-delete', this.$modal).addClass('NB-disabled').attr('value', 'Deleting...');
|
|
|
|
|
2010-08-25 10:18:08 -04:00
|
|
|
var feed_id = this.feed_id;
|
|
|
|
|
2010-10-23 10:29:35 -04:00
|
|
|
// this.model.delete_feed(feed_id, function() {
|
|
|
|
NEWSBLUR.reader.manage_menu_delete_feed(feed_id);
|
|
|
|
_.delay(function() { $.modal.close(); }, 500);
|
|
|
|
// });
|
2010-08-25 10:18:08 -04:00
|
|
|
},
|
2010-08-25 20:43:35 -04:00
|
|
|
|
|
|
|
change_feed_address: function() {
|
2010-08-30 18:41:53 -04:00
|
|
|
var $loading = $('.NB-modal-loading', this.$modal);
|
2010-08-25 20:43:35 -04:00
|
|
|
$loading.addClass('NB-active');
|
2010-08-30 18:41:53 -04:00
|
|
|
|
|
|
|
$('.NB-modal-submit-address', this.$modal).addClass('NB-disabled').attr('value', 'Parsing...');
|
|
|
|
|
2010-08-25 20:43:35 -04:00
|
|
|
var feed_id = this.feed_id;
|
|
|
|
var feed_address = $('input[name=feed_address]', this.$modal).val();
|
|
|
|
|
|
|
|
if (feed_address.length) {
|
|
|
|
this.model.save_exception_change_feed_address(feed_id, feed_address, function(code) {
|
2011-02-06 15:04:21 -05:00
|
|
|
// NEWSBLUR.reader.flags['has_unfetched_feeds'] = true;
|
|
|
|
// NEWSBLUR.reader.load_feeds();
|
2010-08-25 20:43:35 -04:00
|
|
|
$.modal.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
change_feed_link: function() {
|
2010-08-30 18:41:53 -04:00
|
|
|
var $loading = $('.NB-modal-loading', this.$modal);
|
2010-08-25 20:43:35 -04:00
|
|
|
$loading.addClass('NB-active');
|
2010-08-30 18:41:53 -04:00
|
|
|
|
|
|
|
$('.NB-modal-submit-link', this.$modal).addClass('NB-disabled').attr('value', 'Fetching...');
|
|
|
|
|
2010-08-25 20:43:35 -04:00
|
|
|
var feed_id = this.feed_id;
|
|
|
|
var feed_link = $('input[name=feed_link]', this.$modal).val();
|
|
|
|
|
|
|
|
if (feed_link.length) {
|
|
|
|
this.model.save_exception_change_feed_link(feed_id, feed_link, function(code) {
|
2011-02-06 15:04:21 -05:00
|
|
|
// NEWSBLUR.reader.flags['has_unfetched_feeds'] = true;
|
|
|
|
// NEWSBLUR.reader.load_feeds();
|
2010-08-25 20:43:35 -04:00
|
|
|
$.modal.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2010-08-18 20:35:45 -04:00
|
|
|
|
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
|
|
|
handle_click: function(elem, e) {
|
|
|
|
var self = this;
|
2010-08-25 10:18:08 -04:00
|
|
|
|
|
|
|
$.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) {
|
2010-08-18 20:35:45 -04:00
|
|
|
e.preventDefault();
|
|
|
|
|
2010-08-25 10:18:08 -04:00
|
|
|
self.delete_feed();
|
2010-08-18 20:35:45 -04:00
|
|
|
});
|
2010-08-25 20:43:35 -04:00
|
|
|
$.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();
|
|
|
|
});
|
2011-11-12 18:19:57 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
2010-08-18 20:35:45 -04:00
|
|
|
}
|
|
|
|
|
2011-09-26 09:22:46 -07:00
|
|
|
});
|