This repository has been archived by the owner on Jul 15, 2020. It is now read-only.
/
show.js
74 lines (63 loc) · 1.81 KB
/
show.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
64
65
66
67
68
69
70
71
72
73
74
Verlag.View.Asset = Backbone.View.extend({
el: 'body',
tagName: 'div',
events: {
'click input#save-asset' : 'update'
},
initialize: function(options, callback) {
var id = options.id,
self = this,
folder_id = options.folder_id;
this.asset = new Verlag.Model.Asset({ id: id });
this.asset.fetch({
success: function(asset, response){
self.render();
if(callback){
callback(asset)
}
}
});
$(this.el).undelegate();
},
render: function() {
var asset = this.asset,
template = HoganTemplates['assets/edit'],
data = {
asset: function(){
var attr = asset.toJSON();
attr.is_image = asset.isImage();
attr.image_path = '/images/' + asset.id + '/' + asset.get('file_name') + '?w=240&h=180&c=t&g=North';;
attr.admin_path = asset.adminPath();
return attr;
}
};
$(template.render(data)).appendTo(this.$el).modal().on('hidden', function() {
$(this).remove();
var path = asset.get('parent_id') ? '/admin/folders/' + asset.get('parent_id') : '/admin/folders'
Verlag.router.navigate(path, {
trigger: false
});
});
$('a.tab').removeClass('active');
$('a#assets-tab').addClass('active');
},
update: function(e){
e.preventDefault();
var target = $(e.currentTarget),
form = target.parents('form'),
tag_list = form.find('#asset_tag_list').val(),
title = form.find('#asset_title').val(),
asset = this.asset;
asset = asset.save({
title: title,
tag_list: tag_list
}, {
success: function(response){
Verlag.notify('Asset saved')
},
error: function(){
alert('error')
}
});
}
});