diff --git a/apps/calendar/js/store/abstract.js b/apps/calendar/js/store/abstract.js index bd49c3f6b7a5..bc699d632271 100644 --- a/apps/calendar/js/store/abstract.js +++ b/apps/calendar/js/store/abstract.js @@ -328,6 +328,7 @@ var req = store.delete(id); this._removeDependents(id, trans); + self.emit('preRemove', id); trans.addEventListener('error', function(event) { if (callback) { diff --git a/apps/calendar/js/views/advanced_settings.js b/apps/calendar/js/views/advanced_settings.js index dc0234bf5b83..c9c7b286b595 100644 --- a/apps/calendar/js/views/advanced_settings.js +++ b/apps/calendar/js/views/advanced_settings.js @@ -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); diff --git a/apps/calendar/js/views/calendar_colors.js b/apps/calendar/js/views/calendar_colors.js index f6a100b45baf..0c66e1d83484 100644 --- a/apps/calendar/js/views/calendar_colors.js +++ b/apps/calendar/js/views/calendar_colors.js @@ -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) { @@ -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]); @@ -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. diff --git a/apps/calendar/js/views/modify_account.js b/apps/calendar/js/views/modify_account.js index 22079d23e8ff..c905995c0553 100644 --- a/apps/calendar/js/views/modify_account.js +++ b/apps/calendar/js/views/modify_account.js @@ -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) { diff --git a/apps/calendar/js/views/modify_event.js b/apps/calendar/js/views/modify_event.js index e9fc87fdf332..44a78911f933 100644 --- a/apps/calendar/js/views/modify_event.js +++ b/apps/calendar/js/views/modify_event.js @@ -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)); @@ -161,6 +162,7 @@ Calendar.ns('Views').ModifyEvent = (function() { option.text = calendar.remote.name; } + if (this.oncalendarupdate) { this.oncalendarupdate(calendar); } diff --git a/apps/calendar/js/views/settings.js b/apps/calendar/js/views/settings.js index 76443d7321cc..48c892f971f7 100644 --- a/apps/calendar/js/views/settings.js +++ b/apps/calendar/js/views/settings.js @@ -63,6 +63,7 @@ break; // calendar removed + case 'preRemove': case 'remove': this._remove.apply(this, event.data); break; @@ -83,6 +84,7 @@ // calendar store events store.on('update', this); store.on('add', this); + store.on('preRemove', this); store.on('remove', this); }, diff --git a/apps/calendar/test/unit/store/abstract_test.js b/apps/calendar/test/unit/store/abstract_test.js index 46b08aa6c332..0438c9294ad0 100644 --- a/apps/calendar/test/unit/store/abstract_test.js +++ b/apps/calendar/test/unit/store/abstract_test.js @@ -257,6 +257,7 @@ suite('store/abstract', function() { }); setup(function(done) { + var preRemoveCalled = false; callbackCalled = false; removeDepsCalled = false; @@ -264,10 +265,17 @@ suite('store/abstract', 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 diff --git a/apps/calendar/test/unit/views/advanced_settings_test.js b/apps/calendar/test/unit/views/advanced_settings_test.js index a89154386729..aaaea61513a4 100644 --- a/apps/calendar/test/unit/views/advanced_settings_test.js +++ b/apps/calendar/test/unit/views/advanced_settings_test.js @@ -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); diff --git a/apps/calendar/test/unit/views/calendar_colors_test.js b/apps/calendar/test/unit/views/calendar_colors_test.js index ebcba797fa29..7852221744c7 100644 --- a/apps/calendar/test/unit/views/calendar_colors_test.js +++ b/apps/calendar/test/unit/views/calendar_colors_test.js @@ -104,7 +104,8 @@ suiteGroup('Views.CalendarColors', function() { setup(function() { calls = { add: [], - remove: [] + remove: [], + preremove: [] }; subject.updateRule = function(item) { @@ -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() { @@ -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]); @@ -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() { diff --git a/apps/calendar/test/unit/views/modify_account_test.js b/apps/calendar/test/unit/views/modify_account_test.js index fb52ac263521..79d16304fcdf 100644 --- a/apps/calendar/test/unit/views/modify_account_test.js +++ b/apps/calendar/test/unit/views/modify_account_test.js @@ -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/'] diff --git a/apps/calendar/test/unit/views/modify_event_test.js b/apps/calendar/test/unit/views/modify_event_test.js index 1e4a599cc7c7..b16478587ea6 100644 --- a/apps/calendar/test/unit/views/modify_event_test.js +++ b/apps/calendar/test/unit/views/modify_event_test.js @@ -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'); @@ -877,6 +878,7 @@ suiteGroup('Views.ModifyEvent', function() { }); }; + calendarStore.emit('preRemove', calendars.one._id); calendarStore.emit('remove', calendars.one._id); }); }); diff --git a/apps/calendar/test/unit/views/settings_test.js b/apps/calendar/test/unit/views/settings_test.js index 5bb7f138f7af..c70b7ae2ae5b 100644 --- a/apps/calendar/test/unit/views/settings_test.js +++ b/apps/calendar/test/unit/views/settings_test.js @@ -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); });