-
Notifications
You must be signed in to change notification settings - Fork 6
/
resource-upload.js
41 lines (36 loc) · 1.15 KB
/
resource-upload.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
this.CKAN || (this.CKAN = {});
this.CKAN.View || (this.CKAN.View = {});
(function (CKAN, $, _, Backbone, undefined) {
CKAN.View.ResourceUpload = Backbone.View.extend({
tagName: 'div',
// expects a client arguments in its options
initialize: function(options) {
this.el = $(this.el);
this.client = options.client;
_.bindAll(this, 'update', 'render');
},
render: function () {
this.el.empty();
tmplData = {
}
var tmpl = $.tmpl(CKAN.Templates.resourceUpload, tmplData);
this.el.html(tmpl);
return this;
},
// update with data from backend storage
update: function() {
var self = this;
var key = 'xyz/abc';
this.client.getStorageAuthForm(key, {
success: function(data) {
_tmpl = '<input type="hidden" name="${name}" value="${value}" />';
self.el.find('form').attr('action', data.action);
var $hidden = $(self.el.find('form div.hidden-inputs')[0]);
$.each(data.fields, function(idx, item) {
$hidden.append($.tmpl(_tmpl, item));
});
}
});
}
});
})(CKAN, $, _, Backbone, undefined);