/
delete_row_table_cell_view.js
63 lines (55 loc) · 1.44 KB
/
delete_row_table_cell_view.js
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
/**
* A table cell providing a button which destroys the model that the
* current row refers to.
*
* ## Attribute Translations
*
* The following attribute translation is used:
*
* - `.cell_title` - Used as title attribute.
*
* @param {function} [options.toggleDeleteButton]
* A function with boolean return value to be called on
* this.getModel(). Delete button will be visible only if the
* function returns a truthy value.
*
* @param {boolean} [options.invertToggleDeleteButton]
* Invert the return value of `toggleDeleteButton`?
*
* @since edge
*/
pageflow.DeleteRowTableCellView = pageflow.TableCellView.extend({
className: 'delete_row_table_cell',
template: 'templates/delete_row_table_cell',
ui: {
removeButton: '.remove'
},
events: {
'click .remove': 'destroy',
'click': function() {
return false;
}
},
showButton: function() {
if (this.options.toggleDeleteButton) {
var context = this.getModel();
var toggle = context[this.options.toggleDeleteButton].apply(context);
if (this.options.invertToggleDeleteButton) {
return !toggle;
}
else {
return !!toggle;
}
}
else {
return true;
}
},
update: function() {
this.ui.removeButton.toggleClass('remove', this.showButton());
this.ui.removeButton.attr('title', this.attributeTranslation('cell_title'));
},
destroy: function() {
this.getModel().destroy();
}
});