Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Bug 1177542 - [Calendar] remove dependency on utils/account_creation r=gaye #30715

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions apps/calendar/js/bridge.js
Expand Up @@ -144,6 +144,41 @@ exports.deleteAccount = function(id) {
return accountStore.remove(id);
};

/**
* Sends a request to create an account.
*
* @param {Calendar.Models.Account} model account details.
*/
exports.createAccount = co.wrap(function *(model) {
var storeFactory = core.storeFactory;
var accountStore = storeFactory.get('Account');
var calendarStore = storeFactory.get('Calendar');

// begin by persisting the account
var [, result] = yield accountStore.verifyAndPersist(model);

// finally sync the account so when
// we exit the request the user actually
// has some calendars. This should not take
// too long (compared to event sync).
yield accountStore.sync(result);

// begin sync of calendars
var calendars = yield calendarStore.remotesByAccount(result._id);

// note we don't wait for any of this to complete
// we just begin the sync and let the event handlers
// on the sync controller do the work.
for (var key in calendars) {
core.syncController.calendar(
result,
calendars[key]
);
}

return result;
});

exports.observeAccounts = function() {
var stream = new FakeClientStream();
var accountStore = core.storeFactory.get('Account');
Expand Down
4 changes: 4 additions & 0 deletions apps/calendar/js/common/promise.js
Expand Up @@ -26,6 +26,10 @@ function denodeify(fn) {
return deferred.reject(err);
}

// we resolve with a single value (array) in case of multiple arguments
if (arguments.length > 2) {
result = Array.prototype.slice.call(arguments, 1);
}
deferred.resolve(result);
});

Expand Down
100 changes: 0 additions & 100 deletions apps/calendar/js/utils/account_creation.js

This file was deleted.

39 changes: 13 additions & 26 deletions apps/calendar/js/views/modify_account.js
Expand Up @@ -2,7 +2,6 @@ define(function(require, exports, module) {
'use strict';

var Account = require('models/account');
var AccountCreation = require('utils/account_creation');
var OAuthWindow = require('oauth_window');
var Presets = require('common/presets');
var URI = require('utils/uri');
Expand Down Expand Up @@ -31,9 +30,6 @@ function ModifyAccount(options) {
this.hideHeaderAndForm = this.hideHeaderAndForm.bind(this);
this.cancelDelete = this.cancelDelete.bind(this);

this.accountHandler = new AccountCreation();
this.accountHandler.on('authorizeError', this);

// bound so we can add remove listeners
this._boundSaveUpdateModel = this.save.bind(this, { updateModel: true });
}
Expand Down Expand Up @@ -121,18 +117,6 @@ ModifyAccount.prototype = {
return this._fields;
},

handleEvent: function(event) {
var type = event.type;
var data = event.data;

switch (type) {
case 'authorizeError':
// we only expect one argument an error object.
this.showErrors(data[0]);
break;
}
},

updateForm: function() {
var update = ['user', 'fullUrl'];

Expand Down Expand Up @@ -194,16 +178,17 @@ ModifyAccount.prototype = {
this.cancel(event);
},

save: function(options, e) {
isOffline: isOffline,

save: co.wrap(function *(options, e) {

if (e) {
e.preventDefault();
}

var list = this.element.classList;
var self = this;

if (isOffline()) {
if (this.isOffline()) {
this.showErrors([{name: 'offline'}]);
return;
}
Expand All @@ -216,13 +201,15 @@ ModifyAccount.prototype = {
this.updateModel();
}

this.accountHandler.send(this.model, function(err) {
list.remove(self.progressClass);
if (!err) {
router.go(self.completeUrl);
}
});
},
try {
yield core.bridge.createAccount(this.model);
list.remove(this.progressClass);
router.go(this.completeUrl);
} catch(err) {
list.remove(this.progressClass);
this.showErrors(err);
}
}),

hideHeaderAndForm: function() {
this.element.classList.add(this.removeDialogClass);
Expand Down