/
answer.twig
143 lines (126 loc) · 4.92 KB
/
answer.twig
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
141
142
143
{#<?php
/**
* File upload question Html
* @var $fileid
* @var $value
* @var $filecountvalue
*/
?>#}
<!-- File Upload -->
<!--answer -->
<div class="{{ coreClass }}">
<div class='upload-button'>
<a
id='upload_{{ fileid }}'
class='btn btn-primary upload'
href='{{uploadurl}}'
data-toggle="modal"
data-target="file-upload-modal-{{fileid}}"
data-showtitle="{{showTitle}}"
data-showcomment="{{showComment}}"
data-fieldname="{{basename}}"
>
<span class='fa fa-upload'></span> {{ uploadButtonLabel }}
</a>
</div>
<input type='hidden' id='java{{ fileid }}' name='{{ fileid }}' value='{{ value|escape("html_attr") }}' />
<input type='hidden' id='java{{ fileid }}_filecount' name='{{ fileid }}_filecount' value="{{ filecountvalue }}" />
<div id='{{ fileid }}_uploadedfiles' class="hidden">
<table width="100%" class="question uploadedfiles">
<thead>
<tr>
<th width="20%"> </th>
{% if showTitle %}
<th>{{ "Title" | gT }}</th>
{% endif %}
{% if showComment %}
<th>{{ "Comment" | gT }}</th>
{% endif %}
<th>{{ "File name" | gT }}</th>
<th class="edit"></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<!-- modal -->
<div id="file-upload-modal-{{fileid}}" class="modal fade file-upload-modal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header file-upload-modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<div class="h4 modal-title"> {{ ngT("Upload file|Upload files", maxFiles) }}</div>
</div>
<div class="modal-body file-upload-modal-body">
<div id="uploader{{fileid}}" name="uploader{{fileid}}" class="uploader-frame" data-src="{{uploadurl}}" title="{{gT("Upload")}}"></div>
</div>
<div class="modal-footer file-upload-modal-footer">
<button type="button" class="btn btn-success" data-dismiss="modal">{{ gT("Save changes") }}</button>
</div>
</div>
</div>
</div>
<!-- end of answer -->
<script type='text/javascript'>
var surveyid = '{{surveyId}}',
uploadLang = {
title: '{{ "Upload your files" | gT }}',
returnTxt: '{{ "Return to survey" | gT }}',
headTitle: '{{ "Title" | gT }}',
headComment: '{{ "Comment" | gT }}',
headFileName: '{{ "File name" | gT }}',
deleteFile : '{{ "Delete" | gT }}',
editFile : '{{ "Edit" | gT }}',
},
imageurl = '{{imageurl}}',
uploadurl = '{{scriptloc}}';
window.uploadQuestionController_{{ fileid }} = new UploadQuestionController('{{ fileid }}');
window.uploadQuestionController_{{ fileid }}.prepareOpenUploadModalDialog();
$(document).on("ready pjax:scriptcomplete", function(){
var fieldname = "{{fileid}}",
filecount = $("#"+fieldname+"_filecount").val(),
showTitle = "{{showTitle}}",
showComment = "{{showComment}}";
window.uploadQuestionController_{{ fileid }}.displayUploadedFiles( filecount, fieldname, showTitle, showComment);
});
$(".basic_{{fileid}}").change(function() {
var i = 1,
filecount = 0,
jsonArray = [];
for (; i <= LEMval("{{maxFiles}}"); i++) {
//Break if the file input is empty
if ($("#{{fileid}}_"+i).val() == "") { continue; }
filecount++;
var fileObject = {
title : {{showTitle ? '$("#{{fileid}}_title_"+i).val()' : '""' }},
comment: {{showComment ? '$("#{{fileid}}_comment_"+i).val()' : '""'}},
size: '',
name: '',
ext: ''
};
jsonArray.push(fileObject);
}
$("#{{fileid}}").val(JSON.stringify(jsonArray));
$("#{{fileid}}_filecount").val(filecount);
});
</script>
<script type="text/x-template" id="filerowtemplate_{{fileid}}">
<tr>
<td class="upload {imageOrPlaceholder}">{imageOrPlaceholderHtml}</td>
{% if showTitle %}
<td class="upload title">{title}</td>
{% endif %}
{% if showComment %}
<td class="upload comment">{comment}</td>
{% endif %}
<td class="upload edit">{name}</td>
<td>
<a class="btn btn-primary trigger_edit_upload_{{fileid}}" data-file="{filepointer}">
<i class="fa fa-pencil"></i> {{ "Edit" | gT }}
</a>
</td>
</tr>
</script>