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

Commit

Permalink
Merge pull request #10256 from lightsofapollo/calendar-fast-delete-ac…
Browse files Browse the repository at this point in the history
…count

Bug 797788 - Calendar fast delete account
  • Loading branch information
KevinGrandon committed Jun 10, 2013
2 parents 0635706 + 9c4bc44 commit a7cc7c4
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 19 deletions.
1 change: 1 addition & 0 deletions apps/calendar/js/store/abstract.js
Expand Up @@ -328,6 +328,7 @@
var req = store.delete(id);

this._removeDependents(id, trans);
self.emit('preRemove', id);

trans.addEventListener('error', function(event) {
if (callback) {
Expand Down
2 changes: 1 addition & 1 deletion apps/calendar/js/views/advanced_settings.js
Expand Up @@ -71,7 +71,7 @@

account.on('add', this._addAccount.bind(this));
account.on('update', this._updateAccount.bind(this));
account.on('remove', this._removeAccount.bind(this));
account.on('preRemove', this._removeAccount.bind(this));

setting.on('syncFrequencyChange', this);
this.syncFrequency.addEventListener('change', this);
Expand Down
12 changes: 12 additions & 0 deletions apps/calendar/js/views/calendar_colors.js
Expand Up @@ -23,6 +23,7 @@ Calendar.ns('Views').CalendarColors = (function() {
var store = Calendar.App.store('Calendar');
store.on('persist', this);
store.on('remove', this);
store.on('preRemove', this);
},

handleEvent: function(e) {
Expand All @@ -31,6 +32,9 @@ Calendar.ns('Views').CalendarColors = (function() {
// 1 is the model
this.updateRule(e.data[1]);
break;
case 'preRemove':
this.hideCalendar(e.data[0]);
break;
case 'remove':
// 0 is an id of a model
this.removeRule(e.data[0]);
Expand Down Expand Up @@ -77,6 +81,14 @@ Calendar.ns('Views').CalendarColors = (function() {
return this.calendarId(String(id));
},

hideCalendar: function(id) {
this.updateRule({
_id: id,
localDisplayed: false,
color: '#CCC'
});
},

/**
* associates a color with a
* calendar/calendar id with a color.
Expand Down
28 changes: 17 additions & 11 deletions apps/calendar/js/views/modify_account.js
Expand Up @@ -140,22 +140,28 @@ Calendar.ns('Views').ModifyAccount = (function() {
}, this);
},

deleteRecord: function() {
deleteRecord: function(e) {
if (e) {
e.preventDefault();
}

var app = this.app;
var id = this.model._id;
var store = app.store('Account');

store.remove(id, function() {
// semi-hack clear the :target - harmless in tests
// but important in the current UI because css :target
// does not get cleared (for some reason)
window.location.replace('#');
// begin the removal (which will emit the preRemove event) but don't wait
// for it to complete...
store.remove(id);

// TODO: in the future we may want to store the entry
// url of this view and use that instead of this
// hard coded value...
app.router.show('/advanced-settings/');
});
// semi-hack clear the :target - harmless in tests
// but important in the current UI because css :target
// does not get cleared (for some reason)
window.location.replace('#');

// TODO: in the future we may want to store the entry
// url of this view and use that instead of this
// hard coded value...
app.router.show('/advanced-settings/');
},

cancel: function(event) {
Expand Down
2 changes: 2 additions & 0 deletions apps/calendar/js/views/modify_event.js
Expand Up @@ -32,6 +32,7 @@ Calendar.ns('Views').ModifyEvent = (function() {
var calendars = this.app.store('Calendar');

calendars.on('add', this._addCalendarId.bind(this));
calendars.on('preRemove', this._removeCalendarId.bind(this));
calendars.on('remove', this._removeCalendarId.bind(this));
calendars.on('update', this._updateCalendarId.bind(this));

Expand Down Expand Up @@ -161,6 +162,7 @@ Calendar.ns('Views').ModifyEvent = (function() {
option.text = calendar.remote.name;
}


if (this.oncalendarupdate) {
this.oncalendarupdate(calendar);
}
Expand Down
2 changes: 2 additions & 0 deletions apps/calendar/js/views/settings.js
Expand Up @@ -63,6 +63,7 @@
break;

// calendar removed
case 'preRemove':
case 'remove':
this._remove.apply(this, event.data);
break;
Expand All @@ -83,6 +84,7 @@
// calendar store events
store.on('update', this);
store.on('add', this);
store.on('preRemove', this);
store.on('remove', this);
},

Expand Down
8 changes: 8 additions & 0 deletions apps/calendar/test/unit/store/abstract_test.js
Expand Up @@ -257,17 +257,25 @@ suite('store/abstract', function() {
});

setup(function(done) {
var preRemoveCalled = false;
callbackCalled = false;
removeDepsCalled = false;

subject._removeDependents = function() {
removeDepsCalled = arguments;
};

subject.once('preRemove', function(_id) {
assert.equal(id, _id, 'same id');
preRemoveCalled = true;
});

subject.remove(id, function() {
callbackCalled = true;
});

assert.ok(preRemoveCalled, 'removes event');

subject.once('remove', function() {
removeEvent = arguments;
// wait until next tick so other events
Expand Down
2 changes: 1 addition & 1 deletion apps/calendar/test/unit/views/advanced_settings_test.js
Expand Up @@ -200,7 +200,7 @@ suiteGroup('Views.AdvancedSettings', function() {
assert.equal(children.length, 2);

// remove the old one
accountStore.emit('remove', object._id);
accountStore.emit('preRemove', object._id);

assert.equal(children.length, 1);

Expand Down
35 changes: 34 additions & 1 deletion apps/calendar/test/unit/views/calendar_colors_test.js
Expand Up @@ -104,7 +104,8 @@ suiteGroup('Views.CalendarColors', function() {
setup(function() {
calls = {
add: [],
remove: []
remove: [],
preremove: []
};

subject.updateRule = function(item) {
Expand All @@ -114,6 +115,10 @@ suiteGroup('Views.CalendarColors', function() {
subject.removeRule = function(item) {
calls.remove.push(item);
};

subject.hideCalendar = function(item) {
calls.preremove.push(item);
};
});

test('type: persist', function() {
Expand All @@ -122,6 +127,11 @@ suiteGroup('Views.CalendarColors', function() {
assert.deepEqual(calls.add, [model]);
});

test('type: preremove', function() {
store.emit('preRemove', model._id);
assert.deepEqual(calls.preremove, [model._id]);
});

test('type: remove', function() {
store.emit('remove', model._id);
assert.deepEqual(calls.remove, [model._id]);
Expand Down Expand Up @@ -168,6 +178,29 @@ suiteGroup('Views.CalendarColors', function() {

});

suite('#hideCalendar', function() {
setup(function() {
subject.hideCalendar(model._id);
});

test('hides display', function() {
// check that the actual style is flushed to the dom...
var bgRule = subject._styles.cssRules[0];

// it may do the RGB conversion so its not strictly equal...
assert.ok(
bgRule.style.backgroundColor,
'should have set background color'
);

var displayRule = subject._styles.cssRules[1];
assert.equal(
displayRule.style.display, 'none',
'should set display to none'
);
});
});

suite('#updateRule', function() {

test('first time', function() {
Expand Down
5 changes: 0 additions & 5 deletions apps/calendar/test/unit/views/modify_account_test.js
Expand Up @@ -246,14 +246,9 @@ suiteGroup('Views.ModifyAccount', function() {

triggerEvent(subject.deleteButton, 'click');

assert.ok(!calledShow, 'did not redirect before-removal');
assert.ok(calledRemove, 'called remove');
assert.equal(calledRemove[0], model._id, 'removes right id');

var removeCb = calledRemove[calledRemove.length - 1];

removeCb();

assert.deepEqual(
calledShow,
['/advanced-settings/']
Expand Down
2 changes: 2 additions & 0 deletions apps/calendar/test/unit/views/modify_event_test.js
Expand Up @@ -867,6 +867,7 @@ suiteGroup('Views.ModifyEvent', function() {

test('remove calendar (#_removeCalendarId)', function(done) {
subject.onremovecalendar = function() {
subject.onremovecalendar = null;
done(function() {
assert.length(element.children, 2, 'removed one');

Expand All @@ -877,6 +878,7 @@ suiteGroup('Views.ModifyEvent', function() {
});
};

calendarStore.emit('preRemove', calendars.one._id);
calendarStore.emit('remove', calendars.one._id);
});
});
Expand Down
1 change: 1 addition & 0 deletions apps/calendar/test/unit/views/settings_test.js
Expand Up @@ -221,6 +221,7 @@ suiteGroup('Views.Settings', function() {
});

test('remove', function() {
store.emit('preRemove', models.first._id);
store.emit('remove', models.first._id);
assert.equal(children.length, 0);
});
Expand Down

0 comments on commit a7cc7c4

Please sign in to comment.