add.pt
5.36 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<html metal:use-macro="load: ../base.pt">
<div metal:fill-slot="content">
<script src="${home}/deform_static/scripts/deform.js"></script>
<script>
/**
* Nicer looking file inputs for bootstrap 3
* By Jeff Dairiki <dairiki@dairiki.org> based on ideas from
* http://www.abeautifulsite.net/blog/2013/08/whipping-file-inputs-into-shape-with-bootstrap-3/
*/
(function ($) {
var Upload = function (element, options) {
this.$element = $(element);
this.options = $.extend({}, Upload.DEFAULTS,
this.$element.data(),
options);
this.orig_style = this.$element.attr('style');
this.$input_group = $(this.options.template)
.replaceAll(this.$element)
.attr('style', this.orig_style)
.css({position: 'relative', overflow: 'hidden'});
this.$input_group.find(':text').before(this.$element);
this.$element
.on('change.deform.upload', $.proxy(this, 'update'))
.css(this.options.element_style);
this.update();
};
Upload.DEFAULTS = {
filename: null,
selectfile: 'Ganti file…',
changefile: 'Unggah file…',
template: '<div>'
+ '<div class="input-group">'
+ '<span class="input-group-btn">'
+ '<span class="btn btn-default btn-file"></span>'
+ '</span>'
+ '<input type="text" readonly=""'
+ ' class="form-control upload-filename"/>'
+ '</div>'
+ '</div>',
element_style: {
position: 'absolute',
/* Older FF (3.5) seems to put a margin on the bottom of
* the file input (the margin is proportional to
* font-size, so in this case it's significant.) Shift
* bottom a bit to allow for some slop.
*/
//bottom: '0',
bottom: '-40px',
right: '0',
minWidth: '100%',
minHeight: '100%',
fontSize: '999px',
textAlign: 'right',
filter: 'alpha(opacity=0)',
opacity: '0',
background: 'red',
cursor: 'inherit',
display: 'block'
}
};
Upload.prototype.update = function () {
var selected_filename = this.$element.val().replace(/.*[\\\/]/, ''),
options = this.options,
filename = selected_filename || options.filename;
this.$input_group.find(':text')
.val(filename);
this.$input_group.find('.btn-file')
.text(filename ? options.changefile : options.selectfile);
};
Upload.prototype.destroy = function () {
this.$element
.off('.deform.upload')
.attr('style', this.orig_style || null)
.replaceAll(this.$input_group)
.removeData('deform.upload');
};
////////////////////////////////////////////////////////////////
// plugin definition
var old = $.fn.upload;
$.fn.upload = function (option) {
return this.each(function () {
var $this = $(this),
data = $this.data('deform.upload');
if (!data) {
var options = typeof option == 'object' && option;
data = new Upload(this, options);
$this.data('deform.upload', data);
}
if (typeof option == 'string') {
data[option]();
}
});
};
$.fn.upload.Constructor = Upload;
$.fn.upload.noConflict = function () {
$.fn.upload = old;
return this;
};
})(window.jQuery);
</script>
<div class="row">
<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2">
<div class="well">
<form id="upload_sppt" action="" method="POST" enctype="multipart/form-data" accept-charset="utf-8" class="form-horizontal">
<div class="form-group" tal:define="field form_upload['upload']" id="form-${field.oid}">
<label for="${field.oid}" class="${field.required and 'required' or ''} control-label col-md-3" id="req-${field.oid}">
${field.title}</label>
<div class="col-md-4">
${structure:field.serialize()}
<p id="error-${field.oid}" class="help-block" tal:condition="field.error"
tal:repeat="error field.error.messages()">
${error}</p>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Import</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Tutup</button>
</div>
</form>
</div>
</div>
</div>
</div>
</html>