-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy path_Detachable.js
More file actions
63 lines (49 loc) · 1.14 KB
/
_Detachable.js
File metadata and controls
63 lines (49 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Detachable model
*
* @package LifterLMS/Scripts
*
* @since 3.16.12
* @version 3.16.12
*/
define( [], function() {
return {
/**
* DOM Events
*
* @type {Object}
* @since 3.16.12
* @version 3.16.12
*/
events: {
'click a[href="#llms-detach-model"]': 'detach_model',
'click button.llms-detach-model': 'detach_model',
},
/**
* Detaches a model from it's parent (doesn't delete)
*
* @param obj event js event object
* @return void
* @since 3.16.12
* @version 3.16.12
*/
detach_model: function( event ) {
if ( event ) {
event.preventDefault();
event.stopPropagation();
}
var msg = LLMS.l10n.replace( 'Are you sure you want to detach this %s?', {
'%s': this.model.get_l10n_type(),
} );
if ( window.confirm( msg ) ) {
if ( this.model.collection ) {
this.model.collection.remove( this.model );
}
// publish global event
Backbone.pubSub.trigger( 'model-detached', this.model );
// trigger local event so extending views can run other actions where necessary
this.trigger( 'model-trashed', this.model );
}
},
}
} );