Skip to content

Commit 9e2db9b

Browse files
authored
issue/2847 Improved notify subview handling (adaptlearning#2848)
1 parent 06be58a commit 9e2db9b

3 files changed

Lines changed: 157 additions & 150 deletions

File tree

src/core/js/notify.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,29 @@ define([
55
'core/js/models/notifyModel'
66
], function(Adapt, NotifyPushCollection, NotifyView, NotifyModel) {
77

8-
var Notify = Backbone.Controller.extend({
8+
class Notify extends Backbone.Controller {
99

10-
notifyPushes: null,
11-
12-
_warnFirstOnly: true,
13-
_warn: true,
14-
_hasWarned: false,
15-
16-
initialize: function() {
10+
initialize() {
11+
this._stack = [];
1712
this.notifyPushes = new NotifyPushCollection();
1813
this.listenTo(Adapt, {
1914
'notify:popup': this._deprecated.bind(this, 'popup'),
2015
'notify:alert': this._deprecated.bind(this, 'alert'),
2116
'notify:prompt': this._deprecated.bind(this, 'prompt'),
2217
'notify:push': this._deprecated.bind(this, 'push')
2318
});
24-
},
19+
}
2520

26-
_deprecated: function(type, notifyObject) {
27-
if (this._warn && (this._warnFirstOnly && !this._hasWarned)) {
28-
Adapt.log.warn('NOTIFY DEPRECATED: Adapt.trigger(\'notify:' + type + '\', notifyObject); is no longer supported, please use Adapt.notify.' + type + '(notifyObject);');
29-
this._hasWarned = true;
30-
}
21+
get stack() {
22+
return this._stack;
23+
}
24+
25+
_deprecated(type, notifyObject) {
26+
Adapt.log.deprecated(`NOTIFY DEPRECATED: Adapt.trigger('notify:${type}', notifyObject); is no longer supported, please use Adapt.notify.${type}(notifyObject);`);
3127
return this.create(notifyObject, { _type: type });
32-
},
28+
}
3329

34-
create: function(notifyObject, defaults) {
30+
create(notifyObject, defaults) {
3531
notifyObject = _.defaults({}, notifyObject, defaults, {
3632
_type: 'popup',
3733
_isCancellable: true,
@@ -47,7 +43,7 @@ define([
4743
return new NotifyView({
4844
model: new NotifyModel(notifyObject)
4945
});
50-
},
46+
}
5147

5248
/**
5349
* Creates a 'popup' notify
@@ -59,9 +55,9 @@ define([
5955
* @param {string} [notifyObject._classes] A class name or (space separated) list of class names you'd like to be applied to the popup's `<div>`
6056
* @param {Backbone.View} [notifyObject._view] Subview to display in the popup instead of the standard view
6157
*/
62-
popup: function(notifyObject) {
58+
popup(notifyObject) {
6359
return this.create(notifyObject, { _type: 'popup' });
64-
},
60+
}
6561

6662
/**
6763
* Creates an 'alert' notify popup
@@ -75,9 +71,9 @@ define([
7571
* @param {string} [notifyObject._classes] A class name or (space separated) list of class names you'd like to be applied to the popup's `<div>`
7672
* @param {Backbone.View} [notifyObject._view] Subview to display in the popup instead of the standard view
7773
*/
78-
alert: function(notifyObject) {
74+
alert(notifyObject) {
7975
return this.create(notifyObject, { _type: 'alert' });
80-
},
76+
}
8177

8278
/**
8379
* Creates a 'prompt dialog' notify popup
@@ -93,9 +89,9 @@ define([
9389
* @param {string} [notifyObject._classes] A class name or (space separated) list of class names you'd like to be applied to the popup's `<div>`
9490
* @param {Backbone.View} [notifyObject._view] Subview to display in the popup instead of the standard view
9591
*/
96-
prompt: function(notifyObject) {
92+
prompt(notifyObject) {
9793
return this.create(notifyObject, { _type: 'prompt' });
98-
},
94+
}
9995

10096
/**
10197
* Creates a 'push notification'
@@ -106,11 +102,11 @@ define([
106102
* @param {string} notifyObject._callbackEvent Event to be triggered if the learner clicks on the push notification (not triggered if they use the close button)
107103
* @param {string} [notifyObject._classes] A class name or (space separated) list of class names you'd like to be applied to the popup's `<div>`
108104
*/
109-
push: function(notifyObject) {
105+
push(notifyObject) {
110106
return this.create(notifyObject, { _type: 'push' });
111107
}
112108

113-
});
109+
}
114110

115111
return (Adapt.notify = new Notify());
116112

0 commit comments

Comments
 (0)