1
|
|
|
/* global Handlebars, moment */ |
2
|
|
|
|
3
|
|
|
(function () { |
4
|
|
|
|
5
|
|
|
OCA.File_Retention = OCA.File_Retention || {}; |
6
|
|
|
|
7
|
|
|
var TEMPLATE_RETENTION = |
8
|
|
|
'<tr data-id="{{id}}">' |
9
|
|
|
+ '<td><span>{{tagName}}</span></td>' |
|
|
|
|
10
|
|
|
+ '<td><span>{{timeAmount}}</span></td>' |
|
|
|
|
11
|
|
|
+ '<td><span>{{timeUnit}}</span></td>' |
|
|
|
|
12
|
|
|
+ '<td><a class="icon-delete has-tooltip" title="' + t('files_retention', 'Delete') + '"></a></td>' |
|
|
|
|
13
|
|
|
+ '<tr>'; |
|
|
|
|
14
|
|
|
|
15
|
|
|
var RetentionView = OC.Backbone.View.extend({ |
16
|
|
|
collection: null, |
17
|
|
|
tagCollection: null, |
18
|
|
|
|
19
|
|
|
initialize: function(options) { |
20
|
|
|
this.collection = options.collection; |
21
|
|
|
this.tagCollection = options.tagCollection; |
22
|
|
|
|
23
|
|
|
var $el = $('#retention-list'); |
24
|
|
|
$el.on('click', 'a.icon-delete', _.bind(this._onDeleteRetention, this)); |
25
|
|
|
}, |
26
|
|
|
|
27
|
|
|
template: function (data) { |
28
|
|
|
if (_.isUndefined(this._template)) { |
29
|
|
|
this._template = Handlebars.compile(TEMPLATE_RETENTION); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return this._template(data); |
33
|
|
|
}, |
34
|
|
|
|
35
|
|
|
render: function () { |
36
|
|
|
var _this = this; |
37
|
|
|
var list = $('#retention-list'); |
38
|
|
|
list.html(''); |
39
|
|
|
|
40
|
|
|
if (this.collection.length > 0) { |
41
|
|
|
$('#retention-list-header').toggleClass('hidden', false); |
42
|
|
|
} else { |
43
|
|
|
$('#retention-list-header').toggleClass('hidden', true); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
this.collection.forEach(function (model) { |
47
|
|
|
var data = { |
48
|
|
|
id: model.attributes.id, |
49
|
|
|
tagName: _this.tagCollection.get(model.attributes.tagid).attributes.name, |
50
|
|
|
timeAmount: model.attributes.timeamount, |
51
|
|
|
timeUnit: OCA.File_Retention.RETENTION_UNIT_MAP[model.attributes.timeunit] |
52
|
|
|
}; |
53
|
|
|
var html = _this.template(data); |
54
|
|
|
var $html = $(html); |
55
|
|
|
list.append($html); |
56
|
|
|
}); |
57
|
|
|
}, |
58
|
|
|
|
59
|
|
|
_onDeleteRetention: function(event) { |
60
|
|
|
var $target = $(event.target); |
61
|
|
|
var $row = $target.closest('tr'); |
62
|
|
|
var id = $row.data('id'); |
63
|
|
|
|
64
|
|
|
var retention = this.collection.get(id); |
65
|
|
|
|
66
|
|
|
if (_.isUndefined(retention)) { |
67
|
|
|
// Ignore event |
68
|
|
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
var destroyingRetention = retention.destroy(); |
72
|
|
|
|
73
|
|
|
$row.find('.icon-delete').tooltip('hide'); |
74
|
|
|
|
75
|
|
|
var _this = this; |
76
|
|
|
$.when(destroyingRetention).fail(function () { |
77
|
|
|
OC.Notification.showTemporary(t('files_retention', 'Error while deleting the retention rule')); |
78
|
|
|
}); |
79
|
|
|
$.when(destroyingRetention).always(function () { |
80
|
|
|
_this.render(); |
81
|
|
|
}); |
82
|
|
|
} |
83
|
|
|
}); |
84
|
|
|
|
85
|
|
|
OCA.File_Retention.RetentionView = RetentionView; |
86
|
|
|
})(); |
87
|
|
|
|