1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-17 21:26:22 -04:00

Cleanup and refactoring of Twitter notifications

Closes #301
New: Twitter Notifications
This commit is contained in:
Mark McDowall
2015-06-25 00:10:40 -07:00
parent 2fbf7a4114
commit b82e830e86
13 changed files with 429 additions and 342 deletions

View File

@@ -2,6 +2,6 @@
<label class="col-sm-3 control-label"></label>
<div class="col-sm-5">
<button class="form-control x-path {{name}}" data-value="{{value}}">{{label}}</button>
<button class="form-control {{name}}" data-value="{{value}}">{{label}}</button>
</div>
</div>

View File

@@ -16,12 +16,10 @@ var view = Marionette.ItemView.extend({
onDownloadToggle : '.x-on-download',
onUpgradeSection : '.x-on-upgrade',
tags : '.x-tags',
indicator : '.x-indicator',
modalBody : '.x-modal-body',
formTag : '.x-form-tag',
path : '.x-path',
authorizedNotificationButton : '.AuthorizeNotification'
tags : '.x-tags',
modalBody : '.modal-body',
formTag : '.x-form-tag',
path : '.x-path'
},
events : {
@@ -87,13 +85,16 @@ var view = Marionette.ItemView.extend({
}
},
_onAuthorizeNotification : function(e) {
var self = this;
self.ui.indicator.show();
this.model.connectData(this.ui.authorizedNotificationButton.data('value')).always(function(newValues) {
self.ui.indicator.hide();
});
}
_onAuthorizeNotification : function() {
var self = this;
var callbackUrl = window.location.origin + '/oauth.html';
this.ui.indicator.show();
var promise = this.model.connectData(this.ui.authorizedNotificationButton.data('value') + '?callbackUrl=' + callbackUrl);
promise.always(function() {
self.ui.indicator.hide();
});
}
});
AsModelBoundView.call(view);

View File

@@ -7,7 +7,7 @@
<h3>Add - {{implementationName}}</h3>
{{/if}}
</div>
<div class="modal-body notification-modal">
<div class="modal-body notification-modal x-modal">
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 control-label">Name</label>

View File

@@ -1,55 +1,73 @@
var $ = require('jquery');
var _ = require('underscore');
var DeepModel = require('backbone.deepmodel');
var Messenger = require('../Shared/Messenger');
module.exports = DeepModel.extend({
connectData : function(action) {
connectData : function(action, initialQueryString) {
var self = this;
this.trigger('connect:sync');
var promise = $.Deferred();
var callAction = function(action) {
var params = {};
params.url = self.collection.url + '/connectData/' + action;
params.contentType = 'application/json';
params.data = JSON.stringify(self.toJSON());
params.type = 'POST';
params.isValidatedCall = true;
var params = {
url : self.collection.url + '/connectData/' + action,
contentType : 'application/json',
data : JSON.stringify(self.toJSON()),
type : 'POST',
isValidatedCall : true
};
$.ajax(params).fail(promise.reject).success(function(response) {
if (response.action)
var ajaxPromise = $.ajax(params);
ajaxPromise.fail(promise.reject);
ajaxPromise.success(function(response) {
if (response.action)
{
if (response.action === "openwindow")
if (response.action === 'openWindow')
{
var connectResponseWindow = window.open(response.url);
window.open(response.url);
var selfWindow = window;
selfWindow.onCompleteOauth = function(query, callback) {
delete selfWindow.onCompleteOauth;
if (response.nextStep) { callAction(response.nextStep + query); }
else { promise.resolve(response); }
if (response.nextStep) {
callAction(response.nextStep + query);
}
else {
promise.resolve(response);
}
callback();
};
return;
}
else if (response.action === "updatefields")
}
else if (response.action === 'updateFields')
{
Object.keys(response.fields).forEach(function(field) {
self.set(field, response.fields[field]);
self.attributes.fields.forEach(function(fieldDef) {
if (fieldDef.name === field) { fieldDef.value = response.fields[field]; }
_.each(self.get('fields'), function (value, index) {
var fieldValue = _.find(response.fields, function (field, key) {
return key === value.name;
});
if (fieldValue) {
self.set('fields.' + index + '.value', fieldValue);
}
});
}
}
if (response.nextStep) { callAction(response.nextStep); }
else { promise.resolve(response); }
if (response.nextStep) {
callAction(response.nextStep);
}
else {
promise.resolve(response);
}
});
};
callAction(action);
callAction(action, initialQueryString);
Messenger.monitor({
promise : promise,
@@ -63,6 +81,7 @@ module.exports = DeepModel.extend({
return promise;
},
test : function() {
var self = this;